From: Apple Date: Mon, 15 Jul 2002 23:57:42 +0000 (+0000) Subject: Libc-262.tar.gz X-Git-Tag: mac-os-x-102^0 X-Git-Url: https://git.saurik.com/apple/libc.git/commitdiff_plain/5b2abdfbf4211b6592cdd02b9507555a0ecbb04b Libc-262.tar.gz --- diff --git a/APPLE_LICENSE b/APPLE_LICENSE new file mode 100644 index 0000000..a0a8416 --- /dev/null +++ b/APPLE_LICENSE @@ -0,0 +1,372 @@ +APPLE PUBLIC SOURCE LICENSE +Version 1.1 - April 19,1999 + +Please read this License carefully before downloading this software. +By downloading and using this software, you are agreeing to be bound +by the terms of this License. If you do not or cannot agree to the +terms of this License, please do not download or use the software. + +1. General; Definitions. This License applies to any program or other +work which Apple Computer, Inc. ("Apple") publicly announces as +subject to this Apple Public Source License and which contains a +notice placed by Apple identifying such program or work as "Original +Code" and stating that it is subject to the terms of this Apple Public +Source License version 1.1 (or subsequent version thereof), as it may +be revised from time to time by Apple ("License"). As used in this +License: + +1.1 "Affected Original Code" means only those specific portions of +Original Code that allegedly infringe upon any party's intellectual +property rights or are otherwise the subject of a claim of +infringement. + +1.2 "Applicable Patent Rights" mean: (a) in the case where Apple is +the grantor of rights, (i) claims of patents that are now or hereafter +acquired, owned by or assigned to Apple and (ii) that cover subject +matter contained in the Original Code, but only to the extent +necessary to use, reproduce and/or distribute the Original Code +without infringement; and (b) in the case where You are the grantor of +rights, (i) claims of patents that are now or hereafter acquired, +owned by or assigned to You and (ii) that cover subject matter in Your +Modifications, taken alone or in combination with Original Code. + +1.3 "Covered Code" means the Original Code, Modifications, the +combination of Original Code and any Modifications, and/or any +respective portions thereof. + +1.4 "Deploy" means to use, sublicense or distribute Covered Code other +than for Your internal research and development (R&D), and includes +without limitation, any and all internal use or distribution of +Covered Code within Your business or organization except for R&D use, +as well as direct or indirect sublicensing or distribution of Covered +Code by You to any third party in any form or manner. + +1.5 "Larger Work" means a work which combines Covered Code or portions +thereof with code not governed by the terms of this License. + +1.6 "Modifications" mean any addition to, deletion from, and/or change +to, the substance and/or structure of Covered Code. When code is +released as a series of files, a Modification is: (a) any addition to +or deletion from the contents of a file containing Covered Code; +and/or (b) any new file or other representation of computer program +statements that contains any part of Covered Code. + +1.7 "Original Code" means (a) the Source Code of a program or other +work as originally made available by Apple under this License, +including the Source Code of any updates or upgrades to such programs +or works made available by Apple under this License, and that has been +expressly identified by Apple as such in the header file(s) of such +work; and (b) the object code compiled from such Source Code and +originally made available by Apple under this License. + +1.8 "Source Code" means the human readable form of a program or other +work that is suitable for making modifications to it, including all +modules it contains, plus any associated interface definition files, +scripts used to control compilation and installation of an executable +(object code). + +1.9 "You" or "Your" means an individual or a legal entity exercising +rights under this License. For legal entities, "You" or "Your" +includes any entity which controls, is controlled by, or is under +common control with, You, where "control" means (a) the power, direct +or indirect, to cause the direction or management of such entity, +whether by contract or otherwise, or (b) ownership of fifty percent +(50%) or more of the outstanding shares or beneficial ownership of +such entity. + +2. Permitted Uses; Conditions & Restrictions. Subject to the terms +and conditions of this License, Apple hereby grants You, effective on +the date You accept this License and download the Original Code, a +world-wide, royalty-free, non- exclusive license, to the extent of +Apple's Applicable Patent Rights and copyrights covering the Original +Code, to do the following: + +2.1 You may use, copy, modify and distribute Original Code, with or +without Modifications, solely for Your internal research and +development, provided that You must in each instance: + +(a) retain and reproduce in all copies of Original Code the copyright +and other proprietary notices and disclaimers of Apple as they appear +in the Original Code, and keep intact all notices in the Original Code +that refer to this License; + +(b) include a copy of this License with every copy of Source Code of +Covered Code and documentation You distribute, and You may not offer +or impose any terms on such Source Code that alter or restrict this +License or the recipients' rights hereunder, except as permitted under +Section 6; and + +(c) completely and accurately document all Modifications that you have +made and the date of each such Modification, designate the version of +the Original Code you used, prominently include a file carrying such +information with the Modifications, and duplicate the notice in +Exhibit A in each file of the Source Code of all such Modifications. + +2.2 You may Deploy Covered Code, provided that You must in each + instance: + +(a) satisfy all the conditions of Section 2.1 with respect to the +Source Code of the Covered Code; + +(b) make all Your Deployed Modifications publicly available in Source +Code form via electronic distribution (e.g. download from a web site) +under the terms of this License and subject to the license grants set +forth in Section 3 below, and any additional terms You may choose to +offer under Section 6. You must continue to make the Source Code of +Your Deployed Modifications available for as long as you Deploy the +Covered Code or twelve (12) months from the date of initial +Deployment, whichever is longer; + +(c) if You Deploy Covered Code containing Modifications made by You, +inform others of how to obtain those Modifications by filling out and +submitting the information found at +http://www.apple.com/publicsource/modifications.html, if available; +and + +(d) if You Deploy Covered Code in object code, executable form only, +include a prominent notice, in the code itself as well as in related +documentation, stating that Source Code of the Covered Code is +available under the terms of this License with information on how and +where to obtain such Source Code. + +3. Your Grants. In consideration of, and as a condition to, the +licenses granted to You under this License: + +(a) You hereby grant to Apple and all third parties a non-exclusive, +royalty-free license, under Your Applicable Patent Rights and other +intellectual property rights owned or controlled by You, to use, +reproduce, modify, distribute and Deploy Your Modifications of the +same scope and extent as Apple's licenses under Sections 2.1 and 2.2; +and + +(b) You hereby grant to Apple and its subsidiaries a non-exclusive, +worldwide, royalty-free, perpetual and irrevocable license, under Your +Applicable Patent Rights and other intellectual property rights owned +or controlled by You, to use, reproduce, execute, compile, display, +perform, modify or have modified (for Apple and/or its subsidiaries), +sublicense and distribute Your Modifications, in any form, through +multiple tiers of distribution. + +4. Larger Works. You may create a Larger Work by combining Covered +Code with other code not governed by the terms of this License and +distribute the Larger Work as a single product. In each such +instance, You must make sure the requirements of this License are +fulfilled for the Covered Code or any portion thereof. + +5. Limitations on Patent License. Except as expressly stated in +Section 2, no other patent rights, express or implied, are granted by +Apple herein. Modifications and/or Larger Works may require +additional patent licenses from Apple which Apple may grant in its +sole discretion. + +6. Additional Terms. You may choose to offer, and to charge a fee +for, warranty, support, indemnity or liability obligations and/or +other rights consistent with the scope of the license granted herein +("Additional Terms") to one or more recipients of Covered +Code. However, You may do so only on Your own behalf and as Your sole +responsibility, and not on behalf of Apple. You must obtain the +recipient's agreement that any such Additional Terms are offered by +You alone, and You hereby agree to indemnify, defend and hold Apple +harmless for any liability incurred by or claims asserted against +Apple by reason of any such Additional Terms. + +7. Versions of the License. Apple may publish revised and/or new +versions of this License from time to time. Each version will be +given a distinguishing version number. Once Original Code has been +published under a particular version of this License, You may continue +to use it under the terms of that version. You may also choose to use +such Original Code under the terms of any subsequent version of this +License published by Apple. No one other than Apple has the right to +modify the terms applicable to Covered Code created under this +License. + +8. NO WARRANTY OR SUPPORT. The Original Code may contain in whole or +in part pre-release, untested, or not fully tested works. The +Original Code may contain errors that could cause failures or loss of +data, and may be incomplete or contain inaccuracies. You expressly +acknowledge and agree that use of the Original Code, or any portion +thereof, is at Your sole and entire risk. THE ORIGINAL CODE IS +PROVIDED "AS IS" AND WITHOUT WARRANTY, UPGRADES OR SUPPORT OF ANY KIND +AND APPLE AND APPLE'S LICENSOR(S) (FOR THE PURPOSES OF SECTIONS 8 AND +9, APPLE AND APPLE'S LICENSOR(S) ARE COLLECTIVELY REFERRED TO AS +"APPLE") EXPRESSLY DISCLAIM ALL WARRANTIES AND/OR CONDITIONS, EXPRESS +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +AND/OR CONDITIONS OF MERCHANTABILITY OR SATISFACTORY QUALITY AND +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY +RIGHTS. APPLE DOES NOT WARRANT THAT THE FUNCTIONS CONTAINED IN THE +ORIGINAL CODE WILL MEET YOUR REQUIREMENTS, OR THAT THE OPERATION OF +THE ORIGINAL CODE WILL BE UNINTERRUPTED OR ERROR- FREE, OR THAT +DEFECTS IN THE ORIGINAL CODE WILL BE CORRECTED. NO ORAL OR WRITTEN +INFORMATION OR ADVICE GIVEN BY APPLE OR AN APPLE AUTHORIZED +REPRESENTATIVE SHALL CREATE A WARRANTY OR IN ANY WAY INCREASE THE +SCOPE OF THIS WARRANTY. You acknowledge that the Original Code is not +intended for use in the operation of nuclear facilities, aircraft +navigation, communication systems, or air traffic control machines in +which case the failure of the Original Code could lead to death, +personal injury, or severe physical or environmental damage. + +9. Liability. + +9.1 Infringement. If any portion of, or functionality implemented by, +the Original Code becomes the subject of a claim of infringement, +Apple may, at its option: (a) attempt to procure the rights necessary +for Apple and You to continue using the Affected Original Code; (b) +modify the Affected Original Code so that it is no longer infringing; +or (c) suspend Your rights to use, reproduce, modify, sublicense and +distribute the Affected Original Code until a final determination of +the claim is made by a court or governmental administrative agency of +competent jurisdiction and Apple lifts the suspension as set forth +below. Such suspension of rights will be effective immediately upon +Apple's posting of a notice to such effect on the Apple web site that +is used for implementation of this License. Upon such final +determination being made, if Apple is legally able, without the +payment of a fee or royalty, to resume use, reproduction, +modification, sublicensing and distribution of the Affected Original +Code, Apple will lift the suspension of rights to the Affected +Original Code by posting a notice to such effect on the Apple web site +that is used for implementation of this License. If Apple suspends +Your rights to Affected Original Code, nothing in this License shall +be construed to restrict You, at Your option and subject to applicable +law, from replacing the Affected Original Code with non-infringing +code or independently negotiating for necessary rights from such third +party. + +9.2 LIMITATION OF LIABILITY. UNDER NO CIRCUMSTANCES SHALL APPLE BE +LIABLE FOR ANY INCIDENTAL, SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES +ARISING OUT OF OR RELATING TO THIS LICENSE OR YOUR USE OR INABILITY TO +USE THE ORIGINAL CODE, OR ANY PORTION THEREOF, WHETHER UNDER A THEORY +OF CONTRACT, WARRANTY, TORT (INCLUDING NEGLIGENCE), PRODUCTS LIABILITY +OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES AND NOTWITHSTANDING THE FAILURE OF ESSENTIAL PURPOSE OF +ANY REMEDY. In no event shall Apple's total liability to You for all +damages under this License exceed the amount of fifty dollars +($50.00). + +10. Trademarks. This License does not grant any rights to use the +trademarks or trade names "Apple", "Apple Computer", "Mac OS X", "Mac +OS X Server" or any other trademarks or trade names belonging to Apple +(collectively "Apple Marks") and no Apple Marks may be used to endorse +or promote products derived from the Original Code other than as +permitted by and in strict compliance at all times with Apple's third +party trademark usage guidelines which are posted at +http://www.apple.com/legal/guidelinesfor3rdparties.html. + +11. Ownership. Apple retains all rights, title and interest in and to +the Original Code and any Modifications made by or on behalf of Apple +("Apple Modifications"), and such Apple Modifications will not be +automatically subject to this License. Apple may, at its sole +discretion, choose to license such Apple Modifications under this +License, or on different terms from those contained in this License or +may choose not to license them at all. Apple's development, use, +reproduction, modification, sublicensing and distribution of Covered +Code will not be subject to this License. + +12. Termination. + +12.1 Termination. This License and the rights granted hereunder will + terminate: + +(a) automatically without notice from Apple if You fail to comply with +any term(s) of this License and fail to cure such breach within 30 +days of becoming aware of such breach; (b) immediately in the event of +the circumstances described in Section 13.5(b); or (c) automatically +without notice from Apple if You, at any time during the term of this +License, commence an action for patent infringement against Apple. + +12.2 Effect of Termination. Upon termination, You agree to +immediately stop any further use, reproduction, modification, +sublicensing and distribution of the Covered Code and to destroy all +copies of the Covered Code that are in your possession or control. +All sublicenses to the Covered Code which have been properly granted +prior to termination shall survive any termination of this License. +Provisions which, by their nature, should remain in effect beyond the +termination of this License shall survive, including but not limited +to Sections 3, 5, 8, 9, 10, 11, 12.2 and 13. Neither party will be +liable to the other for compensation, indemnity or damages of any sort +solely as a result of terminating this License in accordance with its +terms, and termination of this License will be without prejudice to +any other right or remedy of either party. + +13. Miscellaneous. + +13.1 Government End Users. The Covered Code is a "commercial item" as +defined in FAR 2.101. Government software and technical data rights +in the Covered Code include only those rights customarily provided to +the public as defined in this License. This customary commercial +license in technical data and software is provided in accordance with +FAR 12.211 (Technical Data) and 12.212 (Computer Software) and, for +Department of Defense purchases, DFAR 252.227-7015 (Technical Data -- +Commercial Items) and 227.7202-3 (Rights in Commercial Computer +Software or Computer Software Documentation). Accordingly, all U.S. +Government End Users acquire Covered Code with only those rights set +forth herein. + +13.2 Relationship of Parties. This License will not be construed as +creating an agency, partnership, joint venture or any other form of +legal association between You and Apple, and You will not represent to +the contrary, whether expressly, by implication, appearance or +otherwise. + +13.3 Independent Development. Nothing in this License will impair +Apple's right to acquire, license, develop, have others develop for +it, market and/or distribute technology or products that perform the +same or similar functions as, or otherwise compete with, +Modifications, Larger Works, technology or products that You may +develop, produce, market or distribute. + +13.4 Waiver; Construction. Failure by Apple to enforce any provision +of this License will not be deemed a waiver of future enforcement of +that or any other provision. Any law or regulation which provides +that the language of a contract shall be construed against the drafter +will not apply to this License. + +13.5 Severability. (a) If for any reason a court of competent +jurisdiction finds any provision of this License, or portion thereof, +to be unenforceable, that provision of the License will be enforced to +the maximum extent permissible so as to effect the economic benefits +and intent of the parties, and the remainder of this License will +continue in full force and effect. (b) Notwithstanding the foregoing, +if applicable law prohibits or restricts You from fully and/or +specifically complying with Sections 2 and/or 3 or prevents the +enforceability of either of those Sections, this License will +immediately terminate and You must immediately discontinue any use of +the Covered Code and destroy all copies of it that are in your +possession or control. + +13.6 Dispute Resolution. Any litigation or other dispute resolution +between You and Apple relating to this License shall take place in the +Northern District of California, and You and Apple hereby consent to +the personal jurisdiction of, and venue in, the state and federal +courts within that District with respect to this License. The +application of the United Nations Convention on Contracts for the +International Sale of Goods is expressly excluded. + +13.7 Entire Agreement; Governing Law. This License constitutes the +entire agreement between the parties with respect to the subject +matter hereof. This License shall be governed by the laws of the +United States and the State of California, except that body of +California law concerning conflicts of law. + +Where You are located in the province of Quebec, Canada, the following +clause applies: The parties hereby confirm that they have requested +that this License and all related documents be drafted in English. Les +parties ont exige que le present contrat et tous les documents +connexes soient rediges en anglais. + +EXHIBIT A. + +"Portions Copyright (c) 1999-2000 Apple Computer, Inc. All Rights +Reserved. This 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.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. + +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." diff --git a/CLIB-LIST b/CLIB-LIST new file mode 100644 index 0000000..7b30a40 --- /dev/null +++ b/CLIB-LIST @@ -0,0 +1,679 @@ +CIRCLEQ_ENTRY M +CIRCLEQ_HEAD M +CIRCLEQ_INIT M +CIRCLEQ_INSERT_AFTER M +CIRCLEQ_INSERT_BEFORE M +CIRCLEQ_INSERT_HEAD M +CIRCLEQ_INSERT_TAIL M +CIRCLEQ_REMOVE M +LIST_ENTRY M +LIST_HEAD M +LIST_INIT M +LIST_INSERT_AFTER M +LIST_REMOVE M +TAILQ_ENTRY M +TAILQ_HEAD M +TAILQ_INIT M +TAILQ_INSERT_AFTER M +TAILQ_INSERT_HEAD M +TAILQ_INSERT_TAIL M +TAILQ_REMOVE M +_longjmp +_setjmp +abort +abs +acl_add +acl_canocicalize_principal +acl_check +acl_delete +acl_exact_match +acl_initialize +acos +acosh +addch +addstr +alarm +alloca +alphasort +arc +asctime +asin +asinh +assert +atan +atan2 +atanh +atexit +atof +atoi +atol +bcmp +bcopy +bit_alloc M +bit_clear M +bit_decl M +bit_ffc M +bit_ffs M +bit_nclear M +bit_nset M +bit_test M +bitstr_size M +box +bsearch +bypot +bzero +cabs +calloc +cbreak +cbrt +ceil +cfgetispeed +cfgetospeed +cfmakeraw +cfsetispeed +cfsetospeed +cfsetspeed +cgetcap +cgetclose +cgetent +cgetfirst +cgetmatch +cgetnext +cgetnum +cgetset +cgetstr +cgetustr +circle +clear +clearerr +clearok +clock +closedir +closelog +closepl +clrtobot +clrtoeol +confstr +cont +copysign +cos +cosh +crypt +ctermid +ctime +daemon +dbopen +delch +delwin +des_cbc_cksum +des_cbc_encrypt +des_cipher +des_ecb_encrypt +des_pcbc_encrypt +des_quad_cksum +des_random_key +des_read_password +des_set_key +des_setkey +des_string_to_key +devanme +diffti8me +dirfd +div +dleteln +dn_comp +dn_expand +drem +echo +ectv +edata +encrypt +end +endfsent +endgrent +endhostent +endnetent +endnetgrent +endprotoent +endpwent +endservent +endttyent +endusershell +endwin +er +erase +erf +erfc +err +errx +etext +etfc +execl +execle +execlp +exect +execv +execvp +exit +exp +expm1 +fabs +fclose +fctv +fdopen +feof +ferror +fflush +ffs +fgetc +fgetline +fgetln +fgetpos +fgets +fileno +finite +floor +flusok +fmin MP +fmod +fmount MP +fnmatch +fopen +fprintf +fpurge +fputc +fputs +fread +free +freopen +frexp +fropen +fscanf +fseek +fsetpos +ftell +ftime +fts_children +fts_close +fts_open +fts_read +fts_set +funopen +fwopen +fwrite +gamma +gcd MP +gctv +getbsize +getc +getcap +getch +getchar +getcwd +getdiskbyname +getenv +getfsent +getfsfile +getfsspec +getgrent +getgrgid +getgrnam +getgrouplist +gethostbyaddr +gethostbyname +gethostent +gethostid +gethostname +getloadavg +getmntinfo +getmntopts +getmode +getnetbyaddr +getnetbyname +getnetent +getnetgrent +getopt +getpagesize +getpass +getprotobyname +getprotobynumber +getprotoent +getpw +getpwent +getpwnam +getpwuid +gets +getservbyname +getservbyport +getservent +getstr +getsubopt +gettmode +getttyent +getttynam +getusershell +getw +getwd +getyx +glob +globfree +gmtime +group_from_gid +gtty +heapsort +herror +htonl +htons +hypot +inch +index +inet_addr +inet_aton +inet_lnaof +inet_makeaddr +inet_netof +inet_network +inet_ntoa +infnan +initgroups +initscr +initstate +innetgr +insch +insetln +insque +invert MP +isalnum +isalpha +isascii +isatty +isblank +iscntrl +isdigit +isgraph +isinf +islower +isnan +iso_addr +iso_ntoa +isprint +ispunct +isspace +isupper +isxdigit +itom MP +j0 +j1 +jn +krb_err_txt +krb_get_admhst +krb_get_cred +krb_get_krbhst +krb_get_lrealm +krb_get_phost +krb_kntoln +krb_mk_err +krb_mk_priv +krb_mk_req +krb_mk_safe +krb_net_read +krb_net_write +krb_rd_err +krb_rd_priv +krb_rd_req +krb_rd_safe +krb_realmofhost +krb_recvauth +krb_sendauth +krb_set_key +krb_set_tkt_string +kuserok +kvm_close +kvm_getargv +kvm_getenvv +kvm_geterr +kvm_getfiles +kvm_getloadavg +kvm_getprocs +kvm_nlist +kvm_open +kvm_openfiles +kvm_read +kvm_write +label +labs +ldexp +ldiv +leaveok +lfind +lgamma +line +linemod +link_addr +link_ntoa +localeconv +localtime +log +log10 +log1p +logb +longjmp +longjmperror +longname +lsearch +m_in MP +m_out MP +madd MP +malloc +mamcpy +mblen +mbmb +mbrrune +mbrune +mbstowcs +mbtowc +mcmp MP +mdiv MP +memccpy +memchr +memcmp +memcpy +memmove +memset +mergesort +min MP +mkstemp +mktemp +mktime +modf +moncontrol +monstartup +mount MP +move +move MP +mpool_close +mpool_filter +mpool_get +mpool_new +mpool_open +mpool_put +mpool_sync +msqrt MP +msub MP +mult MP +mvcur +newein +nice +nl +nlist +nocbreak +noecho +nonl +noraw +ns_addr +ns_ntoa +ntohl +ntohs +omin MP +omount MP +opendir +openlog +openpl +optarg +opterr +optind +optopt +optreset +overlay +overwrite +pause +pclose +perror +point +popen +pow +pow MP +printf +printw +psignal +putc +putchar +putenv +puts +putw +qsort +radixsort +raise +rand +random +raw +rcmd +re_comp +re_exec +readdir +realloc +realpath +refresh +regcomp +regerror +regexec +regfree +regsub +remove +remque +res_init +res_mkquery +res_query +res_send +res_serach +resetty +rewind +rewinddir +rexec +rindex +rint +rpow MP +rresvport +ruserok +savetty +scalb +scandir +scanf +scanw +scroll +scrollok +sdiv MP +seekdir +setbuf +setbuffer +setenv +setfsent +setgrent +setgroupent +sethostent +sethostid +sethostname +setinvalidrunt +setjmp +setkey +setlinebuf +setlocale +setlogmask +setmode +setnetent +setnetgrent +setpassent +setprotoent +setpwent +setrgid +setruid +setrunelocale +setservent +setstate +setterm +setttyent +setusershell +setvbuf +sgetrune +sigaddset +sigdelset +sigemptyset +sigfillset +siginterrupt +sigismember +siglongjmp +signal +signgam +sigsetjmp +sin +sinh +sleep +snprintf +space +sprintf +sputrune +sqrt +sradixsort +srand +sreandom +sscanf +standend +standout +stderr +stdin +stdout +strcasecmp +strcat +strchr +strcmp +strcoll +strcpy +strcspn +strdup +strerror +strftime +strlen +strmode +strncasecmp +strncat +strncmp +strncpy +strpbrk +strrchr +strsep +strspc +strspn +strstr +strtod +strtok +strtol +strtoq +strtoul +strtouq +strunvis +strvis +strvisx +strxfrm +stty +subwin +swab +sys_errlist +sys_nerr +sys_siglist +sys_signame +sysconf +sysctl +syslog +system +tan +tanh +tcdrain +tcflow +tcflush +tcgetattr +tcgetpgrp +tcsendbreak +tcsetattr +tcsetpgrp +telldir +tempnam +tf_close +tf_get_cred +tf_get_pinst +tf_get_pname +tf_init +tgetent +tgetflag +tgetnum +tgetstr +tgoto +time +times +timezone +tmpfile +tmpnam +toascii +tolower +touchline +touchoverlap +touchwin +toupper +tputs +ttynam +ttyslot +tzset +tzsetwall +ualarm +uname +unctrl +ungetc +unsetenv +unvis +user_from_uid +usleep +utime +va_arg M +va_end M +va_start M +valloc +verr +verrx +vfprintf +vfscanf +vis +vlimit +vprintf +vscanf +vsnprintf +vsprintf +vsscanf +vsyslog +vtimes +vwarn +vwarnx +waddch +waddstr +warn +warnx +wclear +wclreol +wclrtobot +wcstombs +wctomb +wdelch +wdeleteln +werase +wgetch +wgetstr +winch +winsch +winsertln +wmove +wprintw +wrefreash +wscanw +wstandend +wstandout +y0 +y1 +yn diff --git a/GNUmakefile b/GNUmakefile new file mode 100644 index 0000000..36f4c91 --- /dev/null +++ b/GNUmakefile @@ -0,0 +1,211 @@ +ifndef $(OBJROOT) +OBJROOT = . +endif +ifndef $(SYMROOT) +SYMROOT = . +endif +ARCH = $(shell arch) +ifndef RC_ppc +ifndef RC_i386 +RC_ppc = 1 +endif +endif + +# Remove the arch stuff, since we know better here. +LOCAL_CFLAGS = $(filter-out -arch ppc -arch i386,$(RC_CFLAGS)) + +all: build +# These are the non B&I defaults +ifndef RC_ProjectName +installhdrs: installhdrs-real +build: build-static build-profile build-debug build-dynamic +install: installhdrs install-all +endif + +# And these are to deal with B&I building libc differently +# based on RC_ProjectName. +ifeq ($(RC_ProjectName),Libc) +installhdrs: installhdrs-real +build: build-man build-dynamic +install: installhdrs-real BI-install-dynamic install-man +endif +ifeq ($(RC_ProjectName),Libc_static) +installhdrs: +build: build-static +install: BI-install-static +endif +ifeq ($(RC_ProjectName),Libc_debug) +installhdrs: +build: build-debug +install: BI-install-debug +endif +ifeq ($(RC_ProjectName),Libc_profile) +installhdrs: +build: build-profile +install: BI-install-profile +endif + +build-man: + MAKEOBJDIR="$(OBJROOT)" MACHINE_ARCH="$(shell arch)" \ + MAKEFLAGS="" bsdmake buildman +build-static: build-ppc-static build-i386-static + @echo "Checking for libc_static.a" + @if [ -f "$(OBJROOT)/obj.ppc/libc_static.a" -a -f "$(OBJROOT)/obj.i386/libc_static.a" ]; then\ + lipo -create -arch ppc "$(OBJROOT)/obj.ppc/libc_static.a" \ + -arch i386 "$(OBJROOT)/obj.i386/libc_static.a" \ + -output $(SYMROOT)/libc_static.a;\ + elif [ -f "$(OBJROOT)/obj.ppc/libc_static.a" ]; then \ + cp -p "$(OBJROOT)/obj.ppc/libc_static.a" "$(SYMROOT)"; \ + elif [ -f "$(OBJROOT)/obj.i386/libc_static.a" ]; then \ + cp -p "$(OBJROOT)/obj.i386/libc_static.a" "$(SYMROOT)"; \ + fi +build-profile: build-ppc-profile build-i386-profile + @echo "Checking for libc_profile.a" + @if [ -f "$(OBJROOT)/obj.ppc/libc_profile.a" -a -f "$(OBJROOT)/obj.i386/libc_profile.a" ]; then\ + lipo -create -arch ppc "$(OBJROOT)/obj.ppc/libc_profile.a" \ + -arch i386 "$(OBJROOT)/obj.i386/libc_profile.a" \ + -output $(SYMROOT)/libc_profile.a;\ + elif [ -f "$(OBJROOT)/obj.ppc/libc_profile.a" ]; then \ + cp -p "$(OBJROOT)/obj.ppc/libc_profile.a" "$(SYMROOT)"; \ + elif [ -f "$(OBJROOT)/obj.i386/libc_profile.a" ]; then \ + cp -p "$(OBJROOT)/obj.i386/libc_profile.a" "$(SYMROOT)"; \ + fi +build-debug: build-ppc-debug build-i386-debug + @echo "Checking for libc_debug.a" + @if [ -f "$(OBJROOT)/obj.ppc/libc_debug.a" -a -f "$(OBJROOT)/obj.i386/libc_debug.a" ]; then\ + lipo -create -arch ppc "$(OBJROOT)/obj.ppc/libc_debug.a" \ + -arch i386 "$(OBJROOT)/obj.i386/libc_debug.a" \ + -output $(SYMROOT)/libc_debug.a;\ + elif [ -f "$(OBJROOT)/obj.ppc/libc_debug.a" ]; then \ + cp -p "$(OBJROOT)/obj.ppc/libc_debug.a" "$(SYMROOT)"; \ + elif [ -f "$(OBJROOT)/obj.i386/libc_debug.a" ]; then \ + cp -p "$(OBJROOT)/obj.i386/libc_debug.a" "$(SYMROOT)"; \ + fi +build-dynamic: build-ppc-dynamic build-i386-dynamic + @echo "Checking for libc.a" + @if [ -f "$(OBJROOT)/obj.ppc/libc.a" -a -f "$(OBJROOT)/obj.i386/libc.a" ]; then\ + echo "Creating FAT libc.a"; \ + lipo -create -arch ppc "$(OBJROOT)/obj.ppc/libc.a" -arch i386 \ + "$(OBJROOT)/obj.i386/libc.a" -output $(SYMROOT)/libc.a;\ + elif [ -f "$(OBJROOT)/obj.ppc/libc.a" ]; then \ + echo "Using thin PPC libc.a" ;\ + cp -p "$(OBJROOT)/obj.ppc/libc.a" "$(SYMROOT)"; \ + elif [ -f "$(OBJROOT)/obj.i386/libc.a" ]; then \ + echo "Using thin i386 libc.a" ;\ + cp -p "$(OBJROOT)/obj.i386/libc.a" "$(SYMROOT)"; \ + fi +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 +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 +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 +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 +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 +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 +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 +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 + +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 +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 +installsrc: + $(_v) pax -rw . "$(SRCROOT)" +installhdrs-real: + MAKEOBJDIR="$(OBJROOT)" DESTDIR="$(DSTROOT)" \ + MACHINE_ARCH="$(shell arch)" MAKEFLAGS="" bsdmake installhdrs + +BI-install-static: build-static + mkdir -p $(DSTROOT)/usr/local/lib/system + if [ -f "$(SYMROOT)/libc_static.a" ]; then \ + echo "Installing libc_static.a" ; \ + install -c -m 444 "$(SYMROOT)/libc_static.a" \ + $(DSTROOT)/usr/local/lib/system; \ + ranlib "$(DSTROOT)/usr/local/lib/system/libc_static.a"; \ + fi +BI-install-profile: build-profile + mkdir -p $(DSTROOT)/usr/local/lib/system + if [ -f "$(SYMROOT)/libc_profile.a" ]; then \ + echo "Installing libc_profile.a" ; \ + install -c -m 444 "$(SYMROOT)/libc_profile.a" \ + $(DSTROOT)/usr/local/lib/system; \ + ranlib "$(DSTROOT)/usr/local/lib/system/libc_profile.a"; \ + fi +BI-install-debug: build-debug + mkdir -p $(DSTROOT)/usr/local/lib/system + if [ -f "$(SYMROOT)/libc_debug.a" ]; then \ + echo "Installing libc_debug.a" ; \ + install -c -m 444 "$(SYMROOT)/libc_debug.a" \ + $(DSTROOT)/usr/local/lib/system; \ + ranlib "$(DSTROOT)/usr/local/lib/system/libc_debug.a"; \ + fi +BI-install-dynamic: build-dynamic + mkdir -p $(DSTROOT)/usr/local/lib/system + if [ -f "$(SYMROOT)/libc.a" ]; then \ + echo "Installing libc.a" ; \ + install -c -m 444 "$(SYMROOT)/libc.a" \ + $(DSTROOT)/usr/local/lib/system; \ + ranlib "$(DSTROOT)/usr/local/lib/system/libc.a"; \ + fi + +install-man: + mkdir -p $(DSTROOT)/usr/share/man/man2 + mkdir -p $(DSTROOT)/usr/share/man/man3 + mkdir -p $(DSTROOT)/usr/share/man/man4 + mkdir -p $(DSTROOT)/usr/share/man/man5 + mkdir -p $(DSTROOT)/usr/share/man/man7 + MAKEOBJDIR="$(OBJROOT)" DESTDIR="$(DSTROOT)" NOMANCOMPRESS=1 \ + MACHINE_ARCH="$(shell arch)" MAKEFLAGS="" bsdmake maninstall + +install-all: build install-man BI-install-dynamic BI-install-static BI-install-profile + +clean: + rm -rf $(OBJROOT)/obj.ppc $(OBJROOT)/obj.i386 $(OBJROOT)/libc.a \ + $(OBJROOT)/libc_static.a $(OBJROOT)/libc_debug.a \ + $(OBJROOT)/libc_profile.a diff --git a/Info.plist b/Info.plist new file mode 100644 index 0000000..2b4e967 --- /dev/null +++ b/Info.plist @@ -0,0 +1 @@ +{NSExecutable = net; NSExtensions = {}; } diff --git a/MISSING-MANPAGE b/MISSING-MANPAGE new file mode 100644 index 0000000..6aa16bd --- /dev/null +++ b/MISSING-MANPAGE @@ -0,0 +1,9 @@ +creat (obsoleted by open) +killpg +ptarce +setregid +setreuid +sigblock (obsoleted by sigprocmask) +sigpause (obsoleted by sigsuspend) +sigsetmask (obsoleted by sigprocmask) +sigvec (obsoleted by sigaction) diff --git a/MISSING_SYSCALLS b/MISSING_SYSCALLS new file mode 100644 index 0000000..2cb3246 --- /dev/null +++ b/MISSING_SYSCALLS @@ -0,0 +1,8 @@ +madvise UNIX +mincore UNIX +mlock UNIX +mprotect UNIX +msync UNIX +munlock UNIX +sigpending POSIX +sigstack compat[sigaltstack] diff --git a/Makefile b/Makefile index 8e603be..069ccc4 100644 --- a/Makefile +++ b/Makefile @@ -1,65 +1,40 @@ +# @(#)Makefile 8.2 (Berkeley) 2/3/94 +# $FreeBSD: src/lib/libc/Makefile,v 1.31 2001/08/13 21:48:43 peter Exp $ # -# Generated by the Apple Project Builder. +# All library objects contain rcsid strings by default; they may be +# excluded as a space-saving measure. To produce a library that does +# not contain these strings, delete -DLIBC_RCS and -DSYSLIBC_RCS +# from CFLAGS below. To remove these strings from just the system call +# stubs, remove just -DSYSLIBC_RCS from CFLAGS. # -# NOTE: Do NOT change this file -- Project Builder maintains it. +# Yes, we build everything with -g, and strip it out later... # -# Put all of your customizations in files called Makefile.preamble -# and Makefile.postamble (both optional), and Makefile will include them. -# - -NAME = c - -PROJECTVERSION = 2.8 -PROJECT_TYPE = Library - -CFILES = crt_externs.c -HFILES = - -SUBPROJECTS = compat43.subproj db.subproj gen.subproj headers.subproj\ - internat.subproj locale.subproj mach.subproj net.subproj\ - pthreads.subproj regex.subproj stdio.subproj\ - stdlib.subproj string.subproj sys.subproj threads.subproj\ - util.subproj - -OTHERSRCS = Makefile.preamble Makefile Makefile.postamble - - -MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles -CURRENTLY_ACTIVE_VERSION = YES -DEPLOY_WITH_VERSION_NAME = A -CODE_GEN_STYLE = DYNAMIC -MAKEFILE = library.make -NEXTSTEP_INSTALLDIR = /usr/local/lib/system -WINDOWS_INSTALLDIR = /Developer/Libraries -PDO_UNIX_INSTALLDIR = /lib -LIBS = -DEBUG_LIBS = $(LIBS) -PROF_LIBS = $(LIBS) - - - - -NEXTSTEP_BUILD_OUTPUT_DIR = /Users/Shared/$(USER)/BUILD/$(NAME) - -NEXTSTEP_PUBLIC_HEADERS_DIR = /usr/include - -WINDOWS_PUBLIC_HEADERS_DIR = $(HOMEDRIVE)$(LOCAL_DEVELOPER_DIR)/Headers/$(NAME) - -PDO_UNIX_PUBLIC_HEADERS_DIR = $(LOCAL_DEVELOPER_DIR)/Headers/$(NAME) - -NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc -WINDOWS_OBJCPLUS_COMPILER = $(DEVDIR)/gcc -PDO_UNIX_OBJCPLUS_COMPILER = $(NEXTDEV_BIN)/gcc -NEXTSTEP_JAVA_COMPILER = /usr/bin/javac -WINDOWS_JAVA_COMPILER = $(JDKBINDIR)/javac.exe -PDO_UNIX_JAVA_COMPILER = $(JDKBINDIR)/javac - -include $(MAKEFILEDIR)/platform.make - --include Makefile.preamble - -include $(MAKEFILEDIR)/$(MAKEFILE) - --include Makefile.postamble - --include Makefile.dependencies +LIB=c +SHLIB_MAJOR= 1 +SHLIB_MINOR= 0 +.if (${MACHINE_ARCH} == unknown) +MACHINE_ARCH = ppc +.endif +.if (${MACHINE_ARCH} == ppc) +CFLAGS += -faltivec -DALTIVEC +.endif +CFLAGS += -DNOID -DALL_STATE -I${.CURDIR}/include -I${.CURDIR}/include/objc +CFLAGS += -DLIBC_MAJOR=${SHLIB_MAJOR} -no-cpp-precomp -force_cpusubtype_ALL +CFLAGS += -arch ${MACHINE_ARCH} -fno-common -pipe -Wmost -g +CFLAGS += -finline-limit=5000 +AINC= -I${.CURDIR}/${MACHINE_ARCH} -no-cpp-precomp -force_cpusubtype_ALL +AINC+=-arch ${MACHINE_ARCH} -g +CLEANFILES+=tags +INSTALL_PIC_ARCHIVE= yes +PRECIOUSLIB= yes + +# If these aren't set give it expected defaults +DSTROOT ?= / +OBJROOT ?= . +SRCROOT ?= ${.CURDIR} +DESTDIR ?= ${DSTROOT} +MAKEOBJDIR ?= ${OBJROOT} + +.include "${.CURDIR}/Makefile.inc" +.include "Makefile.xbs" +.include diff --git a/Makefile.inc b/Makefile.inc new file mode 100644 index 0000000..e05962e --- /dev/null +++ b/Makefile.inc @@ -0,0 +1,66 @@ +# $FreeBSD: src/lMakefile.inc,v 1.7 2001/04/04 18:17:25 tmm Exp $ +# +# This file contains make rules that are shared by libc and libc_r. +# +# Define (empty) variables so that make doesn't give substitution +# errors if the included makefiles don't change these: +MDSRCS= +MISRCS= +MDASM= +MIASM= +NOASM= + +# +# If there is a machine dependent makefile, use it: +# +.if exists(${.CURDIR}/${MACHINE_ARCH}/Makefile.inc) +.include "${.CURDIR}/${MACHINE_ARCH}/Makefile.inc" +.endif + +.include "${.CURDIR}/db/Makefile.inc" +.include "${.CURDIR}/compat-43/Makefile.inc" +.include "${.CURDIR}/gen/Makefile.inc" +.include "${.CURDIR}/gmon/Makefile.inc" +.include "${.CURDIR}/include/Makefile.inc" +.include "${.CURDIR}/internat/Makefile.inc" +.include "${.CURDIR}/locale/Makefile.inc" +.include "${.CURDIR}/mach/Makefile.inc" +.include "${.CURDIR}/net/Makefile.inc" +#.include "${.CURDIR}/nls/Makefile.inc" +#.include "${.CURDIR}/posix1e/Makefile.inc" +.include "${.CURDIR}/pthreads/Makefile.inc" +.if !defined(NO_QUAD) +#.include "${.CURDIR}/quad/Makefile.inc" +.endif +.include "${.CURDIR}/regex/Makefile.inc" +.include "${.CURDIR}/stdio/Makefile.inc" +.include "${.CURDIR}/stdlib/Makefile.inc" +.include "${.CURDIR}/stdtime/Makefile.inc" +.include "${.CURDIR}/string/Makefile.inc" +.include "${.CURDIR}/sys/Makefile.inc" +.include "${.CURDIR}/threads/Makefile.inc" +.include "${.CURDIR}/util/Makefile.inc" +#.include "${.CURDIR}/rpc/Makefile.inc" +#.include "${.CURDIR}/xdr/Makefile.inc" +.if !defined(NO_YP_LIBC) +CFLAGS+= -DYP +#.include "${.CURDIR}/yp/Makefile.inc" +.endif +.if !defined(NO_HESIOD_LIBC) +CFLAGS+= -DHESIOD +.endif + +# If there are no machine dependent sources, append all the +# machine-independent sources: +.if empty(MDSRCS) +SRCS+= ${MISRCS} +.else +# Append machine-dependent sources, then append machine-independent sources +# for which there is no machine-dependent variant. +SRCS+= ${MDSRCS} +.for _src in ${MISRCS} +.if ${MDSRCS:R:M${_src:R}} == "" +SRCS+= ${_src} +.endif +.endfor +.endif diff --git a/Makefile.postamble b/Makefile.postamble deleted file mode 100644 index 2083c13..0000000 --- a/Makefile.postamble +++ /dev/null @@ -1,12 +0,0 @@ -override DEBUG_SUFFIX = _debug -override OPTIMIZE_BUILD_CFLAGS = -O3 -STATIC_SUFFIX = _static -PRODUCTS += $(LIBRARY_PREFIX)$(NAME)$(DEBUG_SUFFIX)$(LIBRARY_EXT) -PRODUCTS += $(LIBRARY_PREFIX)$(NAME)$(PROFILE_SUFFIX)$(LIBRARY_EXT) -PRODUCTS += $(LIBRARY_PREFIX)$(NAME)$(STATIC_SUFFIX)$(LIBRARY_EXT) -RECURSIVE_FLAGS += "LINK_SUBPROJECTS = NO" -OTHER_CFLAGS += -no-cpp-precomp -force_cpusubtype_ALL - -static: - $(SILENT) unset $(CUMULATIVE_VARIABLES) ||: ; \ - $(MAKE) BUILD_TYPE=$@ BUILD_TYPE_SUFFIX=$(STATIC_SUFFIX) diff --git a/Makefile.preamble b/Makefile.preamble deleted file mode 100644 index 438e0bb..0000000 --- a/Makefile.preamble +++ /dev/null @@ -1,12 +0,0 @@ -LIBRARY_STYLE = STATIC -STRIP_ON_INSTALL = NO -BEFORE_INSTALL += static debug profile -ifeq "$(BUILD_TYPE)" "static" -RECURSIVE_CFLAGS += -static -OFILE_DIR_SUFFIX := $(OFILE_DIR_SUFFIX)-static -#OTHER_LIBS = $(NEXT_ROOT)/usr/local/lib/libcc.a -else -#OTHER_LIBS = $(NEXT_ROOT)/usr/local/lib/libcc_noc++.a -endif -PRIVATE_HDR_INSTALLDIR = $(SYSTEM_LIBRARY_DIR)/Frameworks/System.framework/Versions/B/PrivateHeaders -override LINK_SUBPROJECTS = NO diff --git a/Makefile.xbs b/Makefile.xbs new file mode 100644 index 0000000..7409a24 --- /dev/null +++ b/Makefile.xbs @@ -0,0 +1,125 @@ +# This is a replacement for bsd.lib.mk for the libc project to get it +# doing the Right Thing in XBS, which is substantially different than +# the BSD build system. +# +# The main problems arise when libc.a isn't meant to be static, but +# libc_static.a is. We also build a debug version of the library +# in addition to shared, static, and profile. Also, we build all +# versions of libc with debugging enabled, unstripped. The BSD style +# is to strip every object file after it is built but here, libc.a +# will get merged into the larger libSystem.dylib, which will eventually +# be stripped. We also don't build a libc.dylib, since it will be +# munged into libSystem.dylib. +# +# And another difference, B&I wishes to build the 4 incarnations of Libc +# in parallel on different machines. To do this, we must look at the +# RC_ProjectName variable (which B&I sets) to determine which of the 4 +# versions of Libc we will be building. Remember that the installhdrs +# pass should only be invoked on one of the 4 versions, and man pages +# should only be installed once as well. Both of these get done when +# we're invoked as "Libc". + +.PATH: . +.MAIN: all +all: libc.a libc_static.a libc_debug.a libc_profile.a +install: installhdrs install_libc.a install_libc_static.a \ + install_libc_profile.a install_libc_debug.a maninstall + +.SUFFIXES: +.SUFFIXES: .o .po .So .do .S .s .c .cc .cpp .cxx .m .C .f .y .l .defs .h + +OBJS+= ${SRCS:N*.h:R:S/$/.o/g} +POBJS+= ${OBJS:.o=.po} ${STATICOBJS:.o=.po} +SOBJS+= ${OBJS:.o=.So} + +.c.o: + ${CC} -static ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET} +.c.po: + ${CC} -pg -DPROFILE ${CFLAGS} -Os -c ${.IMPSRC} -o ${.TARGET} +.c.So: + ${CC} ${CFLAGS} -Os -c ${.IMPSRC} -o ${.TARGET} +.c.do: + ${CC} -g -DDEBUG ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET} +.s.o: + ${CC} -x assembler-with-cpp ${CFLAGS:M-[BID]*} -static ${AINC} -c \ + ${.IMPSRC} -o ${.TARGET} +.s.po: + ${CC} -pg -DPROFILE -x assembler-with-cpp ${CFLAGS:M-[BID]*} -Os \ + ${AINC} -c ${.IMPSRC} -o ${.TARGET} +.s.So: + ${CC} -x assembler-with-cpp \ + ${CFLAGS:M-[BID]*} -Os ${AINC} -c ${.IMPSRC} -o ${.TARGET} +.s.do: + ${CC} -DDEBUG -g -x assembler-with-cpp ${CFLAGS:M-[BID]*} ${AINC} -c \ + ${.IMPSRC} -o ${.TARGET} +.defs.h: + mig -user ${.TARGET:S/.h$/User.c/} \ + -server ${.TARGET:S/.h$/Server.c/} -header ${.TARGET} ${.IMPSRC} + +gen_mig_defs: ${SRVMIGHDRS} ${MIGHDRS} +lib${LIB}_static.a:: ${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} + ${RANLIB} lib${LIB}_static.a + +lib${LIB}_profile.a:: ${POBJS} + @${ECHO} building profiled ${LIB} library + @rm -f lib${LIB}_profile.a + @${AR} cq lib${LIB}_profile.a `lorder ${POBJS} | tsort -q` ${ARADD} + ${RANLIB} lib${LIB}_profile.a + +DOBJS+= ${OBJS:.o=.do} +lib${LIB}_debug.a:: ${DOBJS} + @${ECHO} building debug ${LIB} library + @rm -f lib${LIB}_debug.a + @${AR} cq lib${LIB}_debug.a `lorder ${DOBJS} | tsort -q` ${ARADD} + ${RANLIB} lib${LIB}_debug.a + +lib${LIB}.a:: ${SOBJS} + @${ECHO} building standard ${LIB} library + @rm -f lib${LIB}.a + @${AR} cq lib${LIB}.a `lorder ${SOBJS} | tsort -q` ${ARADD} + ${RANLIB} lib${LIB}.a + +CLEANFILES += ${DOBJS} libc_static.a libc_profile.a libc_debug.a + +installhdrs: gen_mig_defs + mkdir -p ${DESTDIR}/usr/include/arpa + mkdir -p ${DESTDIR}/usr/include/protocols + mkdir -p ${DESTDIR}/usr/include/mach + mkdir -p ${DESTDIR}/usr/include/objc + mkdir -p ${DESTDIR}/usr/include/servers + ${INSTALL} -c -m 444 ${INSTHDRS} ${DESTDIR}/usr/include + ${INSTALL} -c -m 444 ${ARPA_INSTHDRS} ${DESTDIR}/usr/include/arpa + ${INSTALL} -c -m 444 ${PROTO_INSTHDRS} ${DESTDIR}/usr/include/protocols + ${INSTALL} -c -m 444 ${MACH_INSTHDRS} ${DESTDIR}/usr/include/mach + ${INSTALL} -c -m 444 ${OBJC_INSTHDRS} ${DESTDIR}/usr/include/objc + ${INSTALL} -c -m 444 ${SRVHDRS} ${DESTDIR}/usr/include/servers + mv ${DESTDIR}/usr/include/servers/srvbootstrap.h ${DESTDIR}/usr/include/servers/bootstrap.h + mkdir -p ${DESTDIR}/System/Library/Frameworks/System.framework/Versions/B/PrivateHeaders/ + mkdir -p ${DESTDIR}/System/Library/Frameworks/System.framework/Versions/B/PrivateHeaders/architecture + mkdir -p ${DESTDIR}/System/Library/Frameworks/System.framework/Versions/B/PrivateHeaders/architecture/ppc + mkdir -p ${DESTDIR}/System/Library/Frameworks/System.framework/Versions/B/PrivateHeaders/btree + mkdir -p ${DESTDIR}/System/Library/Frameworks/System.framework/Versions/B/PrivateHeaders/machine + mkdir -p ${DESTDIR}/System/Library/Frameworks/System.framework/Versions/B/PrivateHeaders/objc + install -c -m 444 ${SRCROOT}/db/btree/btree.h ${DESTDIR}/System/Library/Frameworks/System.framework/Versions/B/PrivateHeaders/btree + install -c -m 444 ${SRCROOT}/db/btree/bt_extern.h ${DESTDIR}/System/Library/Frameworks/System.framework/Versions/B/PrivateHeaders/btree + install -c -m 444 ${SRCROOT}/ppc/sys/processor_facilities.h ${DESTDIR}/System/Library/Frameworks/System.framework/Versions/B/PrivateHeaders/architecture/ppc + install -c -m 444 ${SRCROOT}/internat/NXCType.h ${DESTDIR}/System/Library/Frameworks/System.framework/Versions/B/PrivateHeaders/objc + install -c -m 444 ${SRCROOT}/gen/stack_logging.h ${DESTDIR}/System/Library/Frameworks/System.framework/Versions/B/PrivateHeaders/ + mv ${DESTDIR}/usr/include/asm.h ${DESTDIR}/System/Library/Frameworks/System.framework/Versions/B/PrivateHeaders/machine + +install_lib${LIB}_static.a: + ${INSTALL} -c -m 444 lib${LIB}_static.a ${DESTDIR}/usr/local/lib/system/ +install_lib${LIB}_profile.a: + ${INSTALL} -c -m 444 lib${LIB}_profile.a ${DESTDIR}/usr/local/lib/system +install_lib${LIB}_debug.a: + ${INSTALL} -c -m 444 lib${LIB}_debug.a ${DESTDIR}/usr/local/lib/system/ +install_lib${LIB}.a: + ${INSTALL} -c -m 444 lib${LIB}.a ${DESTDIR}/usr/local/lib/system/ + +clean: + rm -f ${OBJS} ${POBJS} ${DOBJS} ${SOBJS} ${CLEANFILES} + rm -f lib${LIB}.a lib${LIB}_static.a lib${LIB}_profile.a \ + lib${LIB}_debug.a diff --git a/PB.project b/PB.project deleted file mode 100644 index ef095b6..0000000 --- a/PB.project +++ /dev/null @@ -1,50 +0,0 @@ -{ - CURRENTLY_ACTIVE_VERSION = YES; - DEPLOY_WITH_VERSION_NAME = A; - DYNAMIC_CODE_GEN = YES; - FILESTABLE = { - FRAMEWORKS = (); - H_FILES = (); - OTHER_LINKED = (crt_externs.c); - OTHER_SOURCES = (Makefile.preamble, Makefile, Makefile.postamble); - SUBPROJECTS = ( - compat43.subproj, - db.subproj, - gen.subproj, - headers.subproj, - internat.subproj, - locale.subproj, - mach.subproj, - net.subproj, - pthreads.subproj, - regex.subproj, - stdio.subproj, - stdlib.subproj, - string.subproj, - sys.subproj, - threads.subproj, - util.subproj - ); - }; - LANGUAGE = English; - MAKEFILEDIR = "$(MAKEFILEPATH)/pb_makefiles"; - NEXTSTEP_BUILDDIR = "/Users/Shared/$(USER)/BUILD/$(NAME)"; - NEXTSTEP_BUILDTOOL = /bin/gnumake; - NEXTSTEP_INSTALLDIR = /usr/local/lib/system; - NEXTSTEP_JAVA_COMPILER = /usr/bin/javac; - NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc; - NEXTSTEP_PUBLICHEADERSDIR = /usr/include; - PDO_UNIX_BUILDTOOL = $NEXT_ROOT/Developer/bin/make; - PDO_UNIX_INSTALLDIR = /lib; - PDO_UNIX_JAVA_COMPILER = "$(JDKBINDIR)/javac"; - PDO_UNIX_OBJCPLUS_COMPILER = "$(NEXTDEV_BIN)/gcc"; - PDO_UNIX_PUBLICHEADERSDIR = "$(LOCAL_DEVELOPER_DIR)/Headers/$(NAME)"; - PROJECTNAME = c; - PROJECTTYPE = Library; - PROJECTVERSION = 2.8; - WINDOWS_BUILDTOOL = $NEXT_ROOT/Developer/Executables/make; - WINDOWS_INSTALLDIR = /Developer/Libraries; - WINDOWS_JAVA_COMPILER = "$(JDKBINDIR)/javac.exe"; - WINDOWS_OBJCPLUS_COMPILER = "$(DEVDIR)/gcc"; - WINDOWS_PUBLICHEADERSDIR = "$(HOMEDRIVE)$(LOCAL_DEVELOPER_DIR)/Headers/$(NAME)"; -} diff --git a/REQUIRED-MACROS b/REQUIRED-MACROS new file mode 100644 index 0000000..4482b7a --- /dev/null +++ b/REQUIRED-MACROS @@ -0,0 +1,3 @@ +sigmask +WCOREDUMP + diff --git a/SYSCALL-LIST b/SYSCALL-LIST new file mode 100644 index 0000000..d9b9511 --- /dev/null +++ b/SYSCALL-LIST @@ -0,0 +1,142 @@ +accept +access +acct +adjtime +bind +brk +sbrk +chdir +fchdir +chflags +creat +fchflags +chmod +fchmod +chown +fchown +chroot +close +connect +dup +dup2 +execve +_exit +fcntl +flock +fork +fsync +getdirentries +getdtablesize +getfh +getfsstat +getgid +getegid +getgroups +getitimer +setitimer +getlogin +setlogin +getpeername +getpgrp +getpid +getppid +getpriority +setpriority +getrlimit +setrlimit +getrusage +getsockname +getsockopt +setsockopt +gettimeofday +settimeofday +getuid +geteuid +ioctl +kill +killpg +ktrace +link +listen +lseek +madvise +mincore +mkdir +mkfifo +mknod +mlock +munlock +mmap +mount +unmount +mprotect +msync +munmap +nfssvc +open +pathconf +fpathconf +pipe +profil +ptrace +quotactl +read +readv +readlink +reboot +recv +recvfrom +recvmsg +rename +revoke +rmdir +select +send +sendto +sendmsg +setgroups +setpgid +setpgrp +setregid +setreuid +setsid +setuid +seteuid +setgid +setegid +shutdown +sigaction +sigaltstack +sigblock +sigpause +sigpending +sigprocmask +sigreturn +sigsetmask +sigstack +sigsuspend +sigvec +socket +socketpair +stat +lstat +fstat +statfs +fstatfs +swapon +symlink +sync +syscall +__syscall +truncate +ftruncate +umask +unlink +utimes +vfork +wait +waitpid +wait3 +wait4 +write +writev diff --git a/compat-43/Makefile.inc b/compat-43/Makefile.inc new file mode 100644 index 0000000..8d6a7e0 --- /dev/null +++ b/compat-43/Makefile.inc @@ -0,0 +1,18 @@ +# @(#)Makefile.inc 8.1 (Berkeley) 6/2/93 +# $FreeBSD: src/lib/libc/compat-43/Makefile.inc,v 1.11 2001/03/27 17:26:46 ru Exp $ + +# compat-43 sources +.PATH: ${.CURDIR}/${MACHINE_ARCH}/compat-43 ${.CURDIR}/compat-43 + +SRCS+= creat.c getwd.c send.c setpgrp.c setreuid.c setruid.c \ + gethostid.c killpg.c sethostid.c setregid.c setrgid.c sigcompat.c + + +.if ${LIB} == "c" +MAN2+= creat.2 killpg.2 sigpause.2 sigvec.2 +MAN3+= gethostid.3 setruid.3 + +MLINKS+=gethostid.3 sethostid.3 +MLINKS+=setruid.3 setrgid.3 + +.endif diff --git a/compat-43/creat.2 b/compat-43/creat.2 new file mode 100644 index 0000000..a6e1828 --- /dev/null +++ b/compat-43/creat.2 @@ -0,0 +1,64 @@ +.\" Copyright (c) 1989, 1990, 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. +.\" +.\" @(#)creat.2 8.1 (Berkeley) 6/2/93 +.\" $FreeBSD: src/lib/libc/compat-43/creat.2,v 1.6.2.3 2001/12/14 18:33:49 ru Exp $ +.\" +.Dd June 2, 1993 +.Dt CREAT 2 +.Os +.Sh NAME +.Nm creat +.Nd create a new file +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In fcntl.h +.Ft int +.Fn creat "const char *path" "mode_t mode" +.Sh DESCRIPTION +.Bf -symbolic +This interface is made obsolete by: +.Ef +.Xr open 2 . +.Pp +.Fn Creat +is the same as: +.Bd -literal -offset indent +open(path, O_CREAT | O_TRUNC | O_WRONLY, mode); +.Ed +.Sh SEE ALSO +.Xr open 2 +.Sh HISTORY +The +.Fn creat +function call appeared in +.At v6 . diff --git a/compat-43/creat.c b/compat-43/creat.c new file mode 100644 index 0000000..03a1b34 --- /dev/null +++ b/compat-43/creat.c @@ -0,0 +1,66 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1983, 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 + +#if __STDC__ +int creat(const char *path, mode_t mode) +#else +int creat(path, mode) + char *path; + mode_t mode; +#endif +{ + return(open(path, O_WRONLY|O_CREAT|O_TRUNC, mode)); +} diff --git a/compat-43/gethostid.3 b/compat-43/gethostid.3 new file mode 100644 index 0000000..9ab2e09 --- /dev/null +++ b/compat-43/gethostid.3 @@ -0,0 +1,78 @@ +.\" Copyright (c) 1983, 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. +.\" +.\" @(#)gethostid.3 8.1 (Berkeley) 6/2/93 +.\" $FreeBSD: src/lib/libc/compat-43/gethostid.3,v 1.5.2.5 2001/12/14 18:33:49 ru Exp $ +.\" +.Dd June 2, 1993 +.Dt GETHOSTID 3 +.Os +.Sh NAME +.Nm gethostid , +.Nm sethostid +.Nd get/set unique identifier of current host +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In unistd.h +.Ft long +.Fn gethostid void +.Ft void +.Fn sethostid "long hostid" +.Sh DESCRIPTION +.Fn Sethostid +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 +super-user and is normally performed at boot time. +.Pp +.Fn Gethostid +returns the 32-bit identifier for the current processor. +.Pp +This function has been deprecated. +The hostid should be set or retrieved by use of +.Xr sysctl 3 . +.Sh SEE ALSO +.Xr gethostname 3 , +.Xr sysctl 3 , +.Xr sysctl 8 +.Sh BUGS +32 bits for the identifier is too small. +.Sh HISTORY +The +.Fn gethostid +and +.Fn sethostid +syscalls appeared in +.Bx 4.2 +and were dropped in +.Bx 4.4 . diff --git a/compat-43/gethostid.c b/compat-43/gethostid.c new file mode 100644 index 0000000..cb5c5f4 --- /dev/null +++ b/compat-43/gethostid.c @@ -0,0 +1,76 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1983, 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 +#include + +#if __STDC__ +long +gethostid(void) +#else +long +gethostid() +#endif +{ + int mib[2]; + size_t size; + long value; + + mib[0] = CTL_KERN; + mib[1] = KERN_HOSTID; + size = sizeof value; + if (sysctl(mib, 2, &value, &size, NULL, 0) == -1) + return (-1); + return (value); +} diff --git a/compat-43/getwd.c b/compat-43/getwd.c new file mode 100644 index 0000000..9369837 --- /dev/null +++ b/compat-43/getwd.c @@ -0,0 +1,73 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1983, 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 +#include +#include +#include +#include + +char * +getwd(buf) + char *buf; +{ + char *p; + char buf2[MAXPATHLEN]; + if (p = getcwd(buf2, MAXPATHLEN)) { + (void)strcpy(buf, buf2); + return(buf); + } + (void)strcpy(buf, strerror(errno)); + return((char *)NULL); +} diff --git a/compat-43/killpg.2 b/compat-43/killpg.2 new file mode 100644 index 0000000..3e4d963 --- /dev/null +++ b/compat-43/killpg.2 @@ -0,0 +1,96 @@ +.\" 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. +.\" +.\" @(#)killpg.2 8.1 (Berkeley) 6/2/93 +.\" $FreeBSD: src/lib/libc/compat-43/killpg.2,v 1.6.2.3 2001/12/14 18:33:49 ru Exp $ +.\" +.Dd June 2, 1993 +.Dt KILLPG 2 +.Os +.Sh NAME +.Nm killpg +.Nd send signal to a process group +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In sys/types.h +.In signal.h +.Ft int +.Fn killpg "pid_t pgrp" "int sig" +.Sh DESCRIPTION +.Fn Killpg +sends the signal +.Fa sig +to the process group +.Fa pgrp . +See +.Xr sigaction 2 +for a list of signals. +If +.Fa pgrp +is 0, +.Fn killpg +sends the signal to the sending process's process group. +.Pp +The sending process and members of the process group must +have the same effective user ID, or +the sender must be the super-user. +As a single special case the continue signal SIGCONT may be sent +to any process that is a descendant of the current process. +.Sh RETURN VALUES +.Rv -std killpg +.Sh ERRORS +.Fn Killpg +will fail and no signal will be sent if: +.Bl -tag -width Er +.It Bq Er EINVAL +.Fa Sig +is not a valid signal number. +.It Bq Er ESRCH +No process can be found in the process group specified by +.Fa pgrp . +.It Bq Er ESRCH +The process group was given as 0 +but the sending process does not have a process group. +.It Bq Er EPERM +The sending process is not the super-user and one or more +of the target processes has an effective user ID different from that +of the sending process. +.El +.Sh SEE ALSO +.Xr getpgrp 2 , +.Xr kill 2 , +.Xr sigaction 2 +.Sh HISTORY +The +.Fn killpg +function call appeared in +.Bx 4.0 . diff --git a/compat-43/killpg.c b/compat-43/killpg.c new file mode 100644 index 0000000..b57e9f8 --- /dev/null +++ b/compat-43/killpg.c @@ -0,0 +1,75 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1983, 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 +#include +#include + +/* + * Backwards-compatible killpg(). + */ +#if __STDC__ +int killpg(pid_t pgid, int sig) +#else +int killpg(pgid, sig) + pid_t pgid; + int sig; +#endif +{ + if (pgid == 1) { + errno = ESRCH; + return (-1); + } + return (kill(-pgid, sig)); +} diff --git a/compat-43/send.c b/compat-43/send.c new file mode 100644 index 0000000..410dee5 --- /dev/null +++ b/compat-43/send.c @@ -0,0 +1,67 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1988, 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 +#include + +#include + +ssize_t +send(s, msg, len, flags) + int s, flags; + size_t len; + const void *msg; +{ + return (sendto(s, msg, len, flags, NULL, 0)); +} diff --git a/compat-43/sethostid.c b/compat-43/sethostid.c new file mode 100644 index 0000000..841607a --- /dev/null +++ b/compat-43/sethostid.c @@ -0,0 +1,75 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1989, 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 +#include + +#if __STDC__ +long +sethostid(long hostid) +#else +long +sethostid(hostid) + long hostid; +#endif +{ + int mib[2]; + + mib[0] = CTL_KERN; + mib[1] = KERN_HOSTID; + if (sysctl(mib, 2, NULL, NULL, &hostid, sizeof hostid) == -1) + return (-1); + return (0); +} diff --git a/compat-43/setpgrp.c b/compat-43/setpgrp.c new file mode 100644 index 0000000..197340b --- /dev/null +++ b/compat-43/setpgrp.c @@ -0,0 +1,67 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 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 +#include + +#if __STDC__ +int setpgrp(pid_t pid, pid_t pgid) +#else +int setpgrp(pid, pgid) + pid_t pid, pgid; +#endif +{ + return(setpgid(pid, pgid)); +} diff --git a/compat-43/setregid.c b/compat-43/setregid.c new file mode 100644 index 0000000..7a01282 --- /dev/null +++ b/compat-43/setregid.c @@ -0,0 +1,80 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1983, 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 +#include +#include + +int +setregid(rgid, egid) + gid_t rgid, egid; +{ + static gid_t savedgid = -1; + + if (savedgid == -1) + savedgid = getegid(); + /* + * we assume that the intent here is to be able to + * get back rgid priviledge. So we make sure that + * we will be able to do so, but do not actually + * set the rgid. + */ + if (rgid != -1 && rgid != getgid() && rgid != savedgid) { + errno = EPERM; + return (-1); + } + if (egid != -1 && setegid(egid) < 0) + return (-1); + return (0); +} diff --git a/compat-43/setreuid.c b/compat-43/setreuid.c new file mode 100644 index 0000000..db0d515 --- /dev/null +++ b/compat-43/setreuid.c @@ -0,0 +1,81 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * 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. + */ + + +#include +#include +#include + +int +setreuid(ruid, euid) + uid_t ruid, euid; +{ + static uid_t saveduid = -1; + + if (saveduid == -1) + saveduid = geteuid(); + /* + * we assume that the intent here is to be able to + * get back ruid priviledge. So we make sure that + * we will be able to do so, but do not actually + * set the ruid. + */ + if (ruid != -1 && ruid != getuid() && ruid != saveduid) { + errno = EPERM; + return (-1); + } + if (euid != -1 && seteuid(euid) < 0) + return (-1); + return (0); +} diff --git a/compat-43/setrgid.c b/compat-43/setrgid.c new file mode 100644 index 0000000..a6dee28 --- /dev/null +++ b/compat-43/setrgid.c @@ -0,0 +1,68 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1983, 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 + +int +#ifdef __STDC__ +setrgid(gid_t rgid) +#else +setrgid(rgid) + int rgid; +#endif +{ + + return (setregid(rgid, -1)); +} diff --git a/compat-43/setruid.3 b/compat-43/setruid.3 new file mode 100644 index 0000000..4ab8b72 --- /dev/null +++ b/compat-43/setruid.3 @@ -0,0 +1,84 @@ +.\" Copyright (c) 1983, 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. +.\" +.\" @(#)setruid.3 8.1 (Berkeley) 6/2/93 +.\" $FreeBSD: src/lib/libc/compat-43/setruid.3,v 1.5.2.5 2001/12/14 18:33:49 ru Exp $ +.\" +.Dd June 2, 1993 +.Dt SETRUID 3 +.Os +.Sh NAME +.Nm setruid , +.Nm setrgid +.Nd set user and group ID +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In unistd.h +.Ft int +.Fn setruid "uid_t ruid" +.Ft int +.Fn setrgid "gid_t rgid" +.Sh DESCRIPTION +The +.Fn setruid +function +.Pq Fn setrgid +sets the real user ID (group ID) of the +current process. +.Sh RETURN VALUES +.Rv -std +.Sh ERRORS +The functions fail if: +.Bl -tag -width Er +.It Bq Er EPERM +The user is not the super user and the ID +specified is not the real or effective ID. +.El +.Sh COMPATIBILITY +The use of these calls is not portable. +Their use is discouraged; they will be removed in the future. +.Sh SEE ALSO +.Xr getgid 2 , +.Xr getuid 2 , +.Xr setegid 2 , +.Xr seteuid 2 , +.Xr setgid 2 , +.Xr setuid 2 +.Sh HISTORY +The +.Fn setruid +and +.Fn setrgid +syscalls appeared in +.Bx 4.2 +and were dropped in +.Bx 4.4 . diff --git a/compat-43/setruid.c b/compat-43/setruid.c new file mode 100644 index 0000000..70775bf --- /dev/null +++ b/compat-43/setruid.c @@ -0,0 +1,68 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1983, 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 + +int +#ifdef __STDC__ +setruid(uid_t ruid) +#else +setruid(ruid) + int ruid; +#endif +{ + + return (setreuid(ruid, -1)); +} diff --git a/compat-43/sigblock.2 b/compat-43/sigblock.2 new file mode 100644 index 0000000..43920c7 --- /dev/null +++ b/compat-43/sigblock.2 @@ -0,0 +1,87 @@ +.\" Copyright (c) 1983, 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. +.\" +.\" @(#)sigblock.2 8.1 (Berkeley) 6/2/93 +.\" $FreeBSD: src/lib/libc/compat-43/sigblock.2,v 1.5.2.2 2001/12/21 10:07:08 ru Exp $ +.\" +.Dd June 2, 1993 +.Dt SIGBLOCK 2 +.Os +.Sh NAME +.Nm sigblock +.Nd block signals +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In signal.h +.Ft int +.Fn sigblock "int mask" +.Ft int +.Fn sigmask signum +.Sh DESCRIPTION +.Bf -symbolic +This interface is made obsolete by +.Xr sigprocmask 2 . +.Ef +.Pp +.Fn Sigblock +adds the signals specified in +.Fa mask +to the set of signals currently +being blocked from delivery. +Signals are blocked if the +corresponding bit in +.Fa mask +is a 1; the macro +.Fn sigmask +is provided to construct the mask for a given +.Fa signum . +.Pp +It is not possible to block +.Dv SIGKILL +or +.Dv SIGSTOP ; +this restriction is silently +imposed by the system. +.Sh RETURN VALUES +The previous set of masked signals is returned. +.Sh SEE ALSO +.Xr kill 2 , +.Xr sigaction 2 , +.Xr sigprocmask 2 , +.Xr sigsetmask 2 , +.Xr sigsetops 3 +.Sh HISTORY +The +.Fn sigblock +function call appeared in +.Bx 4.2 +and has been deprecated. diff --git a/compat-43/sigcompat.c b/compat-43/sigcompat.c new file mode 100644 index 0000000..a0f5721 --- /dev/null +++ b/compat-43/sigcompat.c @@ -0,0 +1,149 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1989, 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 +#include +#include + +static int sigvec__(signo, sv, osv, bind) + int signo; + struct sigvec *sv, *osv; + int bind; +{ + int ret; + + if (sv) + sv->sv_flags ^= SV_INTERRUPT; /* !SA_INTERRUPT */ +#if defined(__DYNAMIC__) + if (bind) { +#endif + ret = sigaction(signo, (struct sigaction *)sv, (struct sigaction *)osv); +#if defined(__DYNAMIC__) + } else { + ret = _sigaction_nobind(signo, (struct sigaction *)sv, (struct sigaction *)osv); + } +#endif + if (ret == 0 && osv) + osv->sv_flags ^= SV_INTERRUPT; /* !SA_INTERRUPT */ + return (ret); +} + +int sigvec(signo, sv, osv) + int signo; + struct sigvec *sv, *osv; +{ + return sigvec__(signo, sv, osv, 1); +} + +#if defined(__DYNAMIC__) +int _sigvec_nobind(signo, sv, osv) + int signo; + struct sigvec *sv, *osv; +{ + return sigvec__(signo, sv, osv, 0); +} +#endif + +int sigsetmask(mask) + int mask; +{ + int omask, n; + + n = sigprocmask(SIG_SETMASK, (sigset_t *) &mask, (sigset_t *) &omask); + if (n) + return (n); + return (omask); +} + +int sigblock(mask) + int mask; +{ + int omask, n; + + n = sigprocmask(SIG_BLOCK, (sigset_t *) &mask, (sigset_t *) &omask); + if (n) + return (n); + return (omask); +} + +int sigpause(mask) + int mask; +{ + return (sigsuspend((sigset_t *)&mask)); +} + +int sighold(sig) + int sig; +{ + sigset_t mask; + + if ((sig < 0) || (sig > NSIG)) + return(EINVAL); + sigemptyset(&mask); + sigaddset(&mask, sig); + return(sigprocmask(SIG_BLOCK, &mask,(sigset_t *)0)); +} +int sigrelse(sig) + int sig; +{ + sigset_t mask; + + if ((sig < 0) || (sig > NSIG)) + return(EINVAL); + sigemptyset(&mask); + sigaddset(&mask, sig); + return(sigprocmask(SIG_UNBLOCK, &mask,(sigset_t *)0)); +} + diff --git a/compat-43/sigpause.2 b/compat-43/sigpause.2 new file mode 100644 index 0000000..cd39071 --- /dev/null +++ b/compat-43/sigpause.2 @@ -0,0 +1,77 @@ +.\" Copyright (c) 1983, 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. +.\" +.\" @(#)sigpause.2 8.1 (Berkeley) 6/2/93 +.\" $FreeBSD: src/lib/libc/compat-43/sigpause.2,v 1.5.2.5 2001/12/14 18:33:49 ru Exp $ +.\" +.Dd June 2, 1993 +.Dt SIGPAUSE 2 +.Os +.Sh NAME +.Nm sigpause +.Nd atomically release blocked signals and wait for interrupt +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In signal.h +.Ft int +.Fn sigpause "int sigmask" +.Sh DESCRIPTION +.Sy This interface is made obsolete by +.Xr sigsuspend 2 . +.Pp +.Fn Sigpause +assigns +.Fa sigmask +to the set of masked signals +and then waits for a signal to arrive; +on return the set of masked signals is restored. +.Fa Sigmask +is usually 0 to indicate that no +signals are to be blocked. +.Fn Sigpause +always terminates by being interrupted, returning -1 with +.Va errno +set to +.Er EINTR +.Sh SEE ALSO +.Xr kill 2 , +.Xr sigaction 2 , +.Xr sigblock 2 , +.Xr sigprocmask 2 , +.Xr sigsuspend 2 , +.Xr sigvec 2 +.Sh HISTORY +The +.Fn sigpause +function call appeared in +.Bx 4.2 +and has been deprecated. diff --git a/compat-43/sigsetmask.2 b/compat-43/sigsetmask.2 new file mode 100644 index 0000000..96ae7d3 --- /dev/null +++ b/compat-43/sigsetmask.2 @@ -0,0 +1,85 @@ +.\" Copyright (c) 1983, 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. +.\" +.\" @(#)sigsetmask.2 8.1 (Berkeley) 6/2/93 +.\" $FreeBSD: src/lib/libc/compat-43/sigsetmask.2,v 1.7.2.4 2001/12/14 18:33:49 ru Exp $ +.\" +.Dd June 2, 1993 +.Dt SIGSETMASK 2 +.Os +.Sh NAME +.Nm sigsetmask +.Nd set current signal mask +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In signal.h +.Ft int +.Fn sigsetmask "int mask" +.Fn sigmask signum +.Sh DESCRIPTION +.Bf -symbolic +This interface is made obsolete by: +.Ef +.Xr sigprocmask 2 . +.Pp +.Fn Sigsetmask +sets the current signal mask. Signals +are blocked from delivery if the +corresponding bit in +.Fa mask +is a 1; the macro +.Fn sigmask +is provided to construct the mask for a given +.Fa signum . +.Pp +The system +quietly disallows +.Dv SIGKILL +or +.Dv SIGSTOP +to be blocked. +.Sh RETURN VALUES +The previous set of masked signals is returned. +.Sh SEE ALSO +.Xr kill 2 , +.Xr sigaction 2 , +.Xr sigblock 2 , +.Xr sigprocmask 2 , +.Xr sigsuspend 2 , +.Xr sigvec 2 , +.Xr sigsetops 3 +.Sh HISTORY +The +.Fn sigsetmask +function call appeared in +.Bx 4.2 +and has been deprecated. diff --git a/compat-43/sigvec.2 b/compat-43/sigvec.2 new file mode 100644 index 0000000..dbbcf2c --- /dev/null +++ b/compat-43/sigvec.2 @@ -0,0 +1,327 @@ +.\" 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. +.\" +.\" @(#)sigvec.2 8.2 (Berkeley) 4/19/94 +.\" $FreeBSD: src/lib/libc/compat-43/sigvec.2,v 1.9.2.7 2001/12/14 18:33:49 ru Exp $ +.\" +.Dd April 19, 1994 +.Dt SIGVEC 2 +.Os +.Sh NAME +.Nm sigvec +.Nd software signal facilities +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In signal.h +.Bd -literal +struct sigvec { + void (*sv_handler)(); + int sv_mask; + int sv_flags; +}; +.Ed +.Ft int +.Fn sigvec "int sig" "struct sigvec *vec" "struct sigvec *ovec" +.Sh DESCRIPTION +.Bf -symbolic +This interface is made obsolete by +.Xr sigaction 2 . +.Ef +.Pp +The system defines a set of signals that may be delivered to a process. +Signal delivery resembles the occurrence of a hardware interrupt: +the signal is blocked from further occurrence, the current process +context is saved, and a new one is built. A process may specify a +.Em handler +to which a signal is delivered, or specify that a signal is to be +.Em blocked +or +.Em ignored . +A process may also specify that a default action is to be taken +by the system when a signal occurs. +Normally, signal handlers execute on the current stack +of the process. This may be changed, on a per-handler basis, +so that signals are taken on a special +.Em "signal stack" . +.Pp +All signals have the same +.Em priority . +Signal routines execute with the signal that caused their +invocation +.Em blocked , +but other signals may yet occur. +A global +.Em "signal mask" +defines the set of signals currently blocked from delivery +to a process. The signal mask for a process is initialized +from that of its parent (normally 0). It +may be changed with a +.Xr sigblock 2 +or +.Xr sigsetmask 2 +call, or when a signal is delivered to the process. +.Pp +When a signal +condition arises for a process, the signal is added to a set of +signals pending for the process. If the signal is not currently +.Em blocked +by the process then it is delivered to the process. When a signal +is delivered, the current state of the process is saved, +a new signal mask is calculated (as described below), +and the signal handler is invoked. The call to the handler +is arranged so that if the signal handling routine returns +normally the process will resume execution in the context +from before the signal's delivery. +If the process wishes to resume in a different context, then it +must arrange to restore the previous context itself. +.Pp +When a signal is delivered to a process a new signal mask is +installed for the duration of the process' signal handler +(or until a +.Xr sigblock 2 +or +.Xr sigsetmask 2 +call is made). +This mask is formed by taking the current signal mask, +adding the signal to be delivered, and +.Em or Ns 'ing +in the signal mask associated with the handler to be invoked. +.Pp +.Fn Sigvec +assigns a handler for a specific signal. If +.Fa vec +is non-zero, it +specifies a handler routine and mask +to be used when delivering the specified signal. +Further, if the +.Dv SV_ONSTACK +bit is set in +.Fa sv_flags , +the system will deliver the signal to the process on a +.Em "signal stack" , +specified with +.Xr sigaltstack 2 . +If +.Fa ovec +is non-zero, the previous handling information for the signal +is returned to the user. +.Pp +The following is a list of all signals +with names as in the include file +.Aq Pa signal.h : +.Bl -column SIGVTALARMXX "create core imagexxx" +.It Sy "NAME Default Action Description" +.It Dv SIGHUP No " terminate process" " terminal line hangup" +.It Dv SIGINT No " terminate process" " interrupt program" +.It Dv SIGQUIT No " create core image" " quit program" +.It Dv SIGILL No " create core image" " illegal instruction" +.It Dv SIGTRAP No " create core image" " trace trap" +.It Dv SIGABRT No " create core image" Ta Xr abort 3 +call (formerly +.Dv SIGIOT ) +.It Dv SIGEMT No " create core image" " emulate instruction executed" +.It Dv SIGFPE No " create core image" " floating-point exception" +.It Dv SIGKILL No " terminate process" " kill program" +.It Dv SIGBUS No " create core image" " bus error" +.It Dv SIGSEGV No " create core image" " segmentation violation" +.It Dv SIGSYS No " create core image" " non-existent system call invoked" +.It Dv SIGPIPE No " terminate process" " write on a pipe with no reader" +.It Dv SIGALRM No " terminate process" " real-time timer expired" +.It Dv SIGTERM No " terminate process" " software termination signal" +.It Dv SIGURG No " discard signal" " urgent condition present on socket" +.It Dv SIGSTOP No " stop process" " stop (cannot be caught or ignored)" +.It Dv SIGTSTP No " stop process" " stop signal generated from keyboard" +.It Dv SIGCONT No " discard signal" " continue after stop" +.It Dv SIGCHLD No " discard signal" " child status has changed" +.It Dv SIGTTIN No " stop process" " background read attempted from control terminal" +.It Dv SIGTTOU No " stop process" " background write attempted to control terminal" +.It Dv SIGIO No " discard signal" Tn " I/O" +is possible on a descriptor (see +.Xr fcntl 2 ) +.It Dv SIGXCPU No " terminate process" " cpu time limit exceeded (see" +.Xr setrlimit 2 ) +.It Dv SIGXFSZ No " terminate process" " file size limit exceeded (see" +.Xr setrlimit 2 ) +.It Dv SIGVTALRM No " terminate process" " virtual time alarm (see" +.Xr setitimer 2 ) +.It Dv SIGPROF No " terminate process" " profiling timer alarm (see" +.Xr setitimer 2 ) +.It Dv SIGWINCH No " discard signal" " Window size change" +.It Dv SIGINFO No " discard signal" " status request from keyboard" +.It Dv SIGUSR1 No " terminate process" " User defined signal 1" +.It Dv SIGUSR2 No " terminate process" " User defined signal 2" +.El +.Pp +Once a signal handler is installed, it remains installed +until another +.Fn sigvec +call is made, or an +.Xr execve 2 +is performed. +A signal-specific default action may be reset by +setting +.Fa sv_handler +to +.Dv SIG_DFL . +The defaults are process termination, possibly with core dump; +no action; stopping the process; or continuing the process. +See the above signal list for each signal's default action. +If +.Fa sv_handler +is +.Dv SIG_IGN +current and pending instances +of the signal are ignored and discarded. +.Pp +If a signal is caught during the system calls listed below, +the call is normally restarted. +The call can be forced to terminate prematurely with an +.Er EINTR +error return by setting the +.Dv SV_INTERRUPT +bit in +.Fa sv_flags . +The affected system calls include +.Xr read 2 , +.Xr write 2 , +.Xr sendto 2 , +.Xr recvfrom 2 , +.Xr sendmsg 2 +and +.Xr recvmsg 2 +on a communications channel or a slow device (such as a terminal, +but not a regular file) +and during a +.Xr wait 2 +or +.Xr ioctl 2 . +However, calls that have already committed are not restarted, +but instead return a partial success (for example, a short read count). +.Pp +After a +.Xr fork 2 +or +.Xr vfork 2 +all signals, the signal mask, the signal stack, +and the restart/interrupt flags are inherited by the child. +.Pp +.Xr Execve 2 +reinstates the default +action for all signals which were caught and +resets all signals to be caught on the user stack. +Ignored signals remain ignored; +the signal mask remains the same; +signals that interrupt system calls continue to do so. +.Sh NOTES +The mask specified in +.Fa vec +is not allowed to block +.Dv SIGKILL +or +.Dv SIGSTOP . +This is done silently by the system. +.Pp +The +.Dv SV_INTERRUPT +flag is not available in +.Bx 4.2 , +hence it should not be used if backward compatibility is needed. +.Sh RETURN VALUES +.Rv -std sigvec +.Sh ERRORS +.Fn Sigvec +will fail and no new signal handler will be installed if one +of the following occurs: +.Bl -tag -width Er +.It Bq Er EFAULT +Either +.Fa vec +or +.Fa ovec +points to memory that is not a valid part of the process +address space. +.It Bq Er EINVAL +.Fa Sig +is not a valid signal number. +.It Bq Er EINVAL +An attempt is made to ignore or supply a handler for +.Dv SIGKILL +or +.Dv SIGSTOP . +.El +.Sh SEE ALSO +.Xr kill 1 , +.Xr kill 2 , +.Xr ptrace 2 , +.Xr sigaction 2 , +.Xr sigaltstack 2 , +.Xr sigblock 2 , +.Xr sigpause 2 , +.Xr sigprocmask 2 , +.Xr sigsetmask 2 , +.Xr sigsuspend 2 , +.Xr setjmp 3 , +.Xr siginterrupt 3 , +.Xr signal 3 , +.Xr sigsetops 3 , +.Xr tty 4 +.Sh EXAMPLES +On the +.Tn VAX\-11 +The handler routine can be declared: +.Bd -literal -offset indent +void handler(sig, code, scp) +int sig, code; +struct sigcontext *scp; +.Ed +.Pp +Here +.Fa sig +is the signal number, into which the hardware faults and traps are +mapped as defined below. +.Fa Code +is a parameter that is either a constant +as given below or, for compatibility mode faults, the code provided by +the hardware (Compatibility mode faults are distinguished from the +other +.Dv SIGILL +traps by having +.Dv PSL_CM +set in the psl). +.Fa Scp +is a pointer to the +.Fa sigcontext +structure (defined in +.Aq Pa signal.h ) , +used to restore the context from before the signal. +.Sh BUGS +This manual page is still confusing. diff --git a/compat43.subproj/Makefile b/compat43.subproj/Makefile deleted file mode 100644 index 5e7d581..0000000 --- a/compat43.subproj/Makefile +++ /dev/null @@ -1,47 +0,0 @@ -# -# Generated by the NeXT Project Builder. -# -# NOTE: Do NOT change this file -- Project Builder maintains it. -# -# Put all of your customizations in files called Makefile.preamble -# and Makefile.postamble (both optional), and Makefile will include them. -# - -NAME = compat43 - -PROJECTVERSION = 2.8 -PROJECT_TYPE = Component - -CFILES = creat.c gethostid.c getwd.c killpg.c send.c sethostid.c\ - setpgrp.c setregid.c setreuid.c setrgid.c setruid.c\ - sigcompat.c - -OTHERSRCS = Makefile.preamble Makefile Makefile.postamble - - -MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles -CODE_GEN_STYLE = DYNAMIC -MAKEFILE = subproj.make -LIBS = -DEBUG_LIBS = $(LIBS) -PROF_LIBS = $(LIBS) - - - - -NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc -WINDOWS_OBJCPLUS_COMPILER = $(DEVDIR)/gcc -PDO_UNIX_OBJCPLUS_COMPILER = $(NEXTDEV_BIN)/gcc -NEXTSTEP_JAVA_COMPILER = /usr/bin/javac -WINDOWS_JAVA_COMPILER = $(JDKBINDIR)/javac.exe -PDO_UNIX_JAVA_COMPILER = $(JDKBINDIR)/javac - -include $(MAKEFILEDIR)/platform.make - --include Makefile.preamble - -include $(MAKEFILEDIR)/$(MAKEFILE) - --include Makefile.postamble - --include Makefile.dependencies diff --git a/compat43.subproj/Makefile.postamble b/compat43.subproj/Makefile.postamble deleted file mode 100644 index 411cde6..0000000 --- a/compat43.subproj/Makefile.postamble +++ /dev/null @@ -1,100 +0,0 @@ -############################################################################### -# Makefile.postamble -# Copyright 1997, Apple Computer, Inc. -# -# Use this makefile, which is imported after all other makefiles, to -# override attributes for a project's Makefile environment. This allows you -# to take advantage of the environment set up by the other Makefiles. -# You can also define custom rules at the end of this file. -# -############################################################################### -# -# These variables are exported by the standard makefiles and can be -# used in any customizations you make. They are *outputs* of -# the Makefiles and should be used, not set. -# -# PRODUCTS: products to install. All of these products will be placed in -# the directory $(DSTROOT)$(INSTALLDIR) -# GLOBAL_RESOURCE_DIR: The directory to which resources are copied. -# LOCAL_RESOURCE_DIR: The directory to which localized resources are copied. -# OFILE_DIR: Directory into which .o object files are generated. -# DERIVED_SRC_DIR: Directory used for all other derived files -# -# ALL_CFLAGS: flags to pass when compiling .c files -# ALL_MFLAGS: flags to pass when compiling .m files -# ALL_CCFLAGS: flags to pass when compiling .cc, .cxx, and .C files -# ALL_MMFLAGS: flags to pass when compiling .mm, .mxx, and .M files -# ALL_PRECOMPFLAGS: flags to pass when precompiling .h files -# ALL_LDFLAGS: flags to pass when linking object files -# ALL_LIBTOOL_FLAGS: flags to pass when libtooling object files -# ALL_PSWFLAGS: flags to pass when processing .psw and .pswm (pswrap) files -# ALL_RPCFLAGS: flags to pass when processing .rpc (rpcgen) files -# ALL_YFLAGS: flags to pass when processing .y (yacc) files -# ALL_LFLAGS: flags to pass when processing .l (lex) files -# -# NAME: name of application, bundle, subproject, palette, etc. -# LANGUAGES: langages in which the project is written (default "English") -# English_RESOURCES: localized resources (e.g. nib's, images) of project -# GLOBAL_RESOURCES: non-localized resources of project -# -# SRCROOT: base directory in which to place the new source files -# SRCPATH: relative path from SRCROOT to present subdirectory -# -# INSTALLDIR: Directory the product will be installed into by 'install' target -# PUBLIC_HDR_INSTALLDIR: where to install public headers. Don't forget -# to prefix this with DSTROOT when you use it. -# PRIVATE_HDR_INSTALLDIR: where to install private headers. Don't forget -# to prefix this with DSTROOT when you use it. -# -# EXECUTABLE_EXT: Executable extension for the platform (i.e. .exe on Windows) -# -############################################################################### - -# Some compiler flags can be overridden here for certain build situations. -# -# WARNING_CFLAGS: flag used to set warning level (defaults to -Wmost) -# DEBUG_SYMBOLS_CFLAGS: debug-symbol flag passed to all builds (defaults -# to -g) -# DEBUG_BUILD_CFLAGS: flags passed during debug builds (defaults to -DDEBUG) -# OPTIMIZE_BUILD_CFLAGS: flags passed during optimized builds (defaults -# to -O) -# PROFILE_BUILD_CFLAGS: flags passed during profile builds (defaults -# to -pg -DPROFILE) -# LOCAL_DIR_INCLUDE_DIRECTIVE: flag used to add current directory to -# the include path (defaults to -I.) -# DEBUG_BUILD_LDFLAGS, OPTIMIZE_BUILD_LDFLAGS, PROFILE_BUILD_LDFLAGS: flags -# passed to ld/libtool (defaults to nothing) - - -# Library and Framework projects only: -# INSTALL_NAME_DIRECTIVE: This directive ensures that executables linked -# against the framework will run against the correct version even if -# the current version of the framework changes. You may override this -# to "" as an alternative to using the DYLD_LIBRARY_PATH during your -# development cycle, but be sure to restore it before installing. - - -# Ownership and permissions of files installed by 'install' target - -#INSTALL_AS_USER = root - # User/group ownership -#INSTALL_AS_GROUP = wheel - # (probably want to set both of these) -#INSTALL_PERMISSIONS = - # If set, 'install' chmod's executable to this - - -# Options to strip. Note: -S strips debugging symbols (executables can be stripped -# down further with -x or, if they load no bundles, with no options at all). - -#STRIPFLAGS = -S - - -######################################################################### -# Put rules to extend the behavior of the standard Makefiles here. Include them in -# the dependency tree via cvariables like AFTER_INSTALL in the Makefile.preamble. -# -# You should avoid redefining things like "install" or "app", as they are -# owned by the top-level Makefile API and no context has been set up for where -# derived files should go. -# diff --git a/compat43.subproj/Makefile.preamble b/compat43.subproj/Makefile.preamble deleted file mode 100644 index c1624b4..0000000 --- a/compat43.subproj/Makefile.preamble +++ /dev/null @@ -1,137 +0,0 @@ -############################################################################### -# Makefile.preamble -# Copyright 1997, Apple Computer, Inc. -# -# Use this makefile for configuring the standard application makefiles -# associated with ProjectBuilder. It is included before the main makefile. -# In Makefile.preamble you set attributes for a project, so they are available -# to the project's makefiles. In contrast, you typically write additional rules or -# override built-in behavior in the Makefile.postamble. -# -# Each directory in a project tree (main project plus subprojects) should -# have its own Makefile.preamble and Makefile.postamble. -############################################################################### -# -# Before the main makefile is included for this project, you may set: -# -# MAKEFILEDIR: Directory in which to find $(MAKEFILE) -# MAKEFILE: Top level mechanism Makefile (e.g., app.make, bundle.make) - -# Compiler/linker flags added to the defaults: The OTHER_* variables will be -# inherited by all nested sub-projects, but the LOCAL_ versions of the same -# variables will not. Put your -I, -D, -U, and -L flags in ProjectBuilder's -# Build Attributes inspector if at all possible. To override the default flags -# that get passed to ${CC} (e.g. change -O to -O2), see Makefile.postamble. The -# variables below are *inputs* to the build process and distinct from the override -# settings done (less often) in the Makefile.postamble. -# -# OTHER_CFLAGS, LOCAL_CFLAGS: additional flags to pass to the compiler -# Note that $(OTHER_CFLAGS) and $(LOCAL_CFLAGS) are used for .h, ...c, .m, -# .cc, .cxx, .C, and .M files. There is no need to respecify the -# flags in OTHER_MFLAGS, etc. -# OTHER_MFLAGS, LOCAL_MFLAGS: additional flags for .m files -# OTHER_CCFLAGS, LOCAL_CCFLAGS: additional flags for .cc, .cxx, and ...C files -# OTHER_MMFLAGS, LOCAL_MMFLAGS: additional flags for .mm and .M files -# OTHER_PRECOMPFLAGS, LOCAL_PRECOMPFLAGS: additional flags used when -# precompiling header files -# OTHER_LDFLAGS, LOCAL_LDFLAGS: additional flags passed to ld and libtool -# OTHER_PSWFLAGS, LOCAL_PSWFLAGS: additional flags passed to pswrap -# OTHER_RPCFLAGS, LOCAL_RPCFLAGS: additional flags passed to rpcgen -# OTHER_YFLAGS, LOCAL_YFLAGS: additional flags passed to yacc -# OTHER_LFLAGS, LOCAL_LFLAGS: additional flags passed to lex - -# These variables provide hooks enabling you to add behavior at almost every -# stage of the make: -# -# BEFORE_PREBUILD: targets to build before installing headers for a subproject -# AFTER_PREBUILD: targets to build after installing headers for a subproject -# BEFORE_BUILD_RECURSION: targets to make before building subprojects -# BEFORE_BUILD: targets to make before a build, but after subprojects -# AFTER_BUILD: targets to make after a build -# -# BEFORE_INSTALL: targets to build before installing the product -# AFTER_INSTALL: targets to build after installing the product -# BEFORE_POSTINSTALL: targets to build before postinstalling every subproject -# AFTER_POSTINSTALL: targts to build after postinstalling every subproject -# -# BEFORE_INSTALLHDRS: targets to build before installing headers for a -# subproject -# AFTER_INSTALLHDRS: targets to build after installing headers for a subproject -# BEFORE_INSTALLSRC: targets to build before installing source for a subproject -# AFTER_INSTALLSRC: targets to build after installing source for a subproject -# -# BEFORE_DEPEND: targets to build before building dependencies for a -# subproject -# AFTER_DEPEND: targets to build after building dependencies for a -# subproject -# -# AUTOMATIC_DEPENDENCY_INFO: if YES, then the dependency file is -# updated every time the project is built. If NO, the dependency -# file is only built when the depend target is invoked. - -# Framework-related variables: -# FRAMEWORK_DLL_INSTALLDIR: On Windows platforms, this variable indicates -# where to put the framework's DLL. This variable defaults to -# $(INSTALLDIR)/../Executables - -# Library-related variables: -# PUBLIC_HEADER_DIR: Determines where public exported header files -# should be installed. Do not include $(DSTROOT) in this value -- -# it is prefixed automatically. For library projects you should -# set this to something like /Developer/Headers/$(NAME). Do not set -# this variable for framework projects unless you do not want the -# header files included in the framework. -# PRIVATE_HEADER_DIR: Determines where private exported header files -# should be installed. Do not include $(DSTROOT) in this value -- -# it is prefixed automatically. -# LIBRARY_STYLE: This may be either STATIC or DYNAMIC, and determines -# whether the libraries produced are statically linked when they -# are used or if they are dynamically loadable. This defaults to -# DYNAMIC. -# LIBRARY_DLL_INSTALLDIR: On Windows platforms, this variable indicates -# where to put the library's DLL. This variable defaults to -# $(INSTALLDIR)/../Executables -# -# INSTALL_AS_USER: owner of the intalled products (default root) -# INSTALL_AS_GROUP: group of the installed products (default wheel) -# INSTALL_PERMISSIONS: permissions of the installed product (default o+rX) -# -# OTHER_RECURSIVE_VARIABLES: The names of variables which you want to be -# passed on the command line to recursive invocations of make. Note that -# the values in OTHER_*FLAGS are inherited by subprojects automatically -- -# you do not have to (and shouldn't) add OTHER_*FLAGS to -# OTHER_RECURSIVE_VARIABLES. - -# Additional headers to export beyond those in the PB.project: -# OTHER_PUBLIC_HEADERS -# OTHER_PROJECT_HEADERS -# OTHER_PRIVATE_HEADERS - -# Additional files for the project's product: <> -# OTHER_RESOURCES: (non-localized) resources for this project -# OTHER_OFILES: relocatables to be linked into this project -# OTHER_LIBS: more libraries to link against -# OTHER_PRODUCT_DEPENDS: other dependencies of this project -# OTHER_SOURCEFILES: other source files maintained by .pre/postamble -# OTHER_GARBAGE: additional files to be removed by `make clean' - -# Set this to YES if you don't want a final libtool call for a library/framework. -# BUILD_OFILES_LIST_ONLY - -# To include a version string, project source must exist in a directory named -# $(NAME).%d[.%d][.%d] and the following line must be uncommented. -# OTHER_GENERATED_OFILES = $(VERS_OFILE) - -# This definition will suppress stripping of debug symbols when an executable -# is installed. By default it is YES. -# STRIP_ON_INSTALL = NO - -# Uncomment to suppress generation of a KeyValueCoding index when installing -# frameworks (This index is used by WOB and IB to determine keys available -# for an object). Set to YES by default. -# PREINDEX_FRAMEWORK = NO - -# Change this definition to install projects somewhere other than the -# standard locations. NEXT_ROOT defaults to "C:/Apple" on Windows systems -# and "" on other systems. -DSTROOT = $(HOME) diff --git a/compat43.subproj/PB.project b/compat43.subproj/PB.project deleted file mode 100644 index 846afeb..0000000 --- a/compat43.subproj/PB.project +++ /dev/null @@ -1,36 +0,0 @@ -{ - DYNAMIC_CODE_GEN = YES; - FILESTABLE = { - H_FILES = (); - OTHER_LINKED = ( - creat.c, - gethostid.c, - getwd.c, - killpg.c, - send.c, - sethostid.c, - setpgrp.c, - setregid.c, - setreuid.c, - setrgid.c, - setruid.c, - sigcompat.c - ); - OTHER_SOURCES = (Makefile.preamble, Makefile, Makefile.postamble); - SUBPROJECTS = (); - }; - LANGUAGE = English; - MAKEFILEDIR = "$(MAKEFILEPATH)/pb_makefiles"; - NEXTSTEP_BUILDTOOL = /bin/gnumake; - NEXTSTEP_JAVA_COMPILER = /usr/bin/javac; - NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc; - PDO_UNIX_BUILDTOOL = $NEXT_ROOT/Developer/bin/make; - PDO_UNIX_JAVA_COMPILER = "$(JDKBINDIR)/javac"; - PDO_UNIX_OBJCPLUS_COMPILER = "$(NEXTDEV_BIN)/gcc"; - PROJECTNAME = compat43; - PROJECTTYPE = Component; - PROJECTVERSION = 2.8; - WINDOWS_BUILDTOOL = $NEXT_ROOT/Developer/Executables/make; - WINDOWS_JAVA_COMPILER = "$(JDKBINDIR)/javac.exe"; - WINDOWS_OBJCPLUS_COMPILER = "$(DEVDIR)/gcc"; -} diff --git a/compat43.subproj/creat.c b/compat43.subproj/creat.c deleted file mode 100644 index 03a1b34..0000000 --- a/compat43.subproj/creat.c +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1983, 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 - -#if __STDC__ -int creat(const char *path, mode_t mode) -#else -int creat(path, mode) - char *path; - mode_t mode; -#endif -{ - return(open(path, O_WRONLY|O_CREAT|O_TRUNC, mode)); -} diff --git a/compat43.subproj/gethostid.c b/compat43.subproj/gethostid.c deleted file mode 100644 index cb5c5f4..0000000 --- a/compat43.subproj/gethostid.c +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1983, 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 -#include - -#if __STDC__ -long -gethostid(void) -#else -long -gethostid() -#endif -{ - int mib[2]; - size_t size; - long value; - - mib[0] = CTL_KERN; - mib[1] = KERN_HOSTID; - size = sizeof value; - if (sysctl(mib, 2, &value, &size, NULL, 0) == -1) - return (-1); - return (value); -} diff --git a/compat43.subproj/getwd.c b/compat43.subproj/getwd.c deleted file mode 100644 index 9369837..0000000 --- a/compat43.subproj/getwd.c +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1983, 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 -#include -#include -#include -#include - -char * -getwd(buf) - char *buf; -{ - char *p; - char buf2[MAXPATHLEN]; - if (p = getcwd(buf2, MAXPATHLEN)) { - (void)strcpy(buf, buf2); - return(buf); - } - (void)strcpy(buf, strerror(errno)); - return((char *)NULL); -} diff --git a/compat43.subproj/killpg.c b/compat43.subproj/killpg.c deleted file mode 100644 index b57e9f8..0000000 --- a/compat43.subproj/killpg.c +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1983, 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 -#include -#include - -/* - * Backwards-compatible killpg(). - */ -#if __STDC__ -int killpg(pid_t pgid, int sig) -#else -int killpg(pgid, sig) - pid_t pgid; - int sig; -#endif -{ - if (pgid == 1) { - errno = ESRCH; - return (-1); - } - return (kill(-pgid, sig)); -} diff --git a/compat43.subproj/send.c b/compat43.subproj/send.c deleted file mode 100644 index 410dee5..0000000 --- a/compat43.subproj/send.c +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1988, 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 -#include - -#include - -ssize_t -send(s, msg, len, flags) - int s, flags; - size_t len; - const void *msg; -{ - return (sendto(s, msg, len, flags, NULL, 0)); -} diff --git a/compat43.subproj/sethostid.c b/compat43.subproj/sethostid.c deleted file mode 100644 index 841607a..0000000 --- a/compat43.subproj/sethostid.c +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1989, 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 -#include - -#if __STDC__ -long -sethostid(long hostid) -#else -long -sethostid(hostid) - long hostid; -#endif -{ - int mib[2]; - - mib[0] = CTL_KERN; - mib[1] = KERN_HOSTID; - if (sysctl(mib, 2, NULL, NULL, &hostid, sizeof hostid) == -1) - return (-1); - return (0); -} diff --git a/compat43.subproj/setpgrp.c b/compat43.subproj/setpgrp.c deleted file mode 100644 index 197340b..0000000 --- a/compat43.subproj/setpgrp.c +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 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 -#include - -#if __STDC__ -int setpgrp(pid_t pid, pid_t pgid) -#else -int setpgrp(pid, pgid) - pid_t pid, pgid; -#endif -{ - return(setpgid(pid, pgid)); -} diff --git a/compat43.subproj/setregid.c b/compat43.subproj/setregid.c deleted file mode 100644 index 7a01282..0000000 --- a/compat43.subproj/setregid.c +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1983, 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 -#include -#include - -int -setregid(rgid, egid) - gid_t rgid, egid; -{ - static gid_t savedgid = -1; - - if (savedgid == -1) - savedgid = getegid(); - /* - * we assume that the intent here is to be able to - * get back rgid priviledge. So we make sure that - * we will be able to do so, but do not actually - * set the rgid. - */ - if (rgid != -1 && rgid != getgid() && rgid != savedgid) { - errno = EPERM; - return (-1); - } - if (egid != -1 && setegid(egid) < 0) - return (-1); - return (0); -} diff --git a/compat43.subproj/setreuid.c b/compat43.subproj/setreuid.c deleted file mode 100644 index db0d515..0000000 --- a/compat43.subproj/setreuid.c +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * 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. - */ - - -#include -#include -#include - -int -setreuid(ruid, euid) - uid_t ruid, euid; -{ - static uid_t saveduid = -1; - - if (saveduid == -1) - saveduid = geteuid(); - /* - * we assume that the intent here is to be able to - * get back ruid priviledge. So we make sure that - * we will be able to do so, but do not actually - * set the ruid. - */ - if (ruid != -1 && ruid != getuid() && ruid != saveduid) { - errno = EPERM; - return (-1); - } - if (euid != -1 && seteuid(euid) < 0) - return (-1); - return (0); -} diff --git a/compat43.subproj/setrgid.c b/compat43.subproj/setrgid.c deleted file mode 100644 index a6dee28..0000000 --- a/compat43.subproj/setrgid.c +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1983, 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 - -int -#ifdef __STDC__ -setrgid(gid_t rgid) -#else -setrgid(rgid) - int rgid; -#endif -{ - - return (setregid(rgid, -1)); -} diff --git a/compat43.subproj/setruid.c b/compat43.subproj/setruid.c deleted file mode 100644 index 70775bf..0000000 --- a/compat43.subproj/setruid.c +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1983, 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 - -int -#ifdef __STDC__ -setruid(uid_t ruid) -#else -setruid(ruid) - int ruid; -#endif -{ - - return (setreuid(ruid, -1)); -} diff --git a/compat43.subproj/sigcompat.c b/compat43.subproj/sigcompat.c deleted file mode 100644 index 827075b..0000000 --- a/compat43.subproj/sigcompat.c +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1989, 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 -#include - -static int sigvec__(signo, sv, osv, bind) - int signo; - struct sigvec *sv, *osv; - int bind; -{ - int ret; - - if (sv) - sv->sv_flags ^= SV_INTERRUPT; /* !SA_INTERRUPT */ -#if defined(__DYNAMIC__) - if (bind) { -#endif - ret = sigaction(signo, (struct sigaction *)sv, (struct sigaction *)osv); -#if defined(__DYNAMIC__) - } else { - ret = _sigaction_nobind(signo, (struct sigaction *)sv, (struct sigaction *)osv); - } -#endif - if (ret == 0 && osv) - osv->sv_flags ^= SV_INTERRUPT; /* !SA_INTERRUPT */ - return (ret); -} - -int sigvec(signo, sv, osv) - int signo; - struct sigvec *sv, *osv; -{ - return sigvec__(signo, sv, osv, 1); -} - -#if defined(__DYNAMIC__) -int _sigvec_nobind(signo, sv, osv) - int signo; - struct sigvec *sv, *osv; -{ - return sigvec__(signo, sv, osv, 0); -} -#endif - -int sigsetmask(mask) - int mask; -{ - int omask, n; - - n = sigprocmask(SIG_SETMASK, (sigset_t *) &mask, (sigset_t *) &omask); - if (n) - return (n); - return (omask); -} - -int sigblock(mask) - int mask; -{ - int omask, n; - - n = sigprocmask(SIG_BLOCK, (sigset_t *) &mask, (sigset_t *) &omask); - if (n) - return (n); - return (omask); -} - -int sigpause(mask) - int mask; -{ - return (sigsuspend((sigset_t *)&mask)); -} diff --git a/crt_externs.c b/crt_externs.c deleted file mode 100644 index 04ec529..0000000 --- a/crt_externs.c +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* -** This file contains interfaces to the symbols defined int the crt modules. -** 3 April 1995 -** Matt Watson (mwatson@next.com) -** -*/ - -#if defined(__DYNAMIC__) -#include "mach-o/dyld.h" /* defines _dyld_lookup_and_bind() */ -#define STRINGIFY(a) # a -#define DECLARE_VAR(var, type) \ - static type * var ## _pointer = 0 -#define SETUP_VAR(var) \ - if ( var ## _pointer == 0) { \ - _dyld_lookup_and_bind( STRINGIFY(_ ## var), \ - (unsigned long *) & var ## _pointer, 0); \ - } -#define USE_VAR(var) (var ## _pointer) -#else -#define DECLARE_VAR(var, type) extern type var -#define SETUP_VAR(var) -#define USE_VAR(var) (& var) -#endif - -char ***_NSGetArgv(void) { - DECLARE_VAR(NXArgv, char **); - SETUP_VAR(NXArgv); - return(USE_VAR(NXArgv)); -} - -int *_NSGetArgc(void) { - DECLARE_VAR(NXArgc, int); - SETUP_VAR(NXArgc); - return(USE_VAR(NXArgc)); -} - -char ***_NSGetEnviron(void) { - DECLARE_VAR(environ, char **); - SETUP_VAR(environ); - return(USE_VAR(environ)); -} - -struct mach_header *_NSGetMachExecuteHeader(void) { - DECLARE_VAR(_mh_execute_header, struct mach_header); - SETUP_VAR(_mh_execute_header); - return(USE_VAR(_mh_execute_header)); -} - -/* - * Fix for Radar bug 2200596 -- - * EH symbol definitions for gcc 2.7.2.x implementation of - * C++ exception handling. The problem: the EH implementation - * has "throw" store stuff into these pointers, and then as the - * stack is unwound, the code generated into each function (for - * checking whether this function contains a relevant "catch" - * clause and for calling destructors for local variables) looks - * at these globals to find the type and value thrown. - * - * The problem was that the compiler generated the symbols as - * "common" symbols, and common symbols cannot be placed in - * dynamic shared libraries. So we must put these guys as - * "data" symbols into crt0.o or the System Framework (library), - * and the compiler must generate code that defines the symbols - * as external references instead of common. - * - * I changed the symbol names (added the "_272") to be utterly - * paranoid about any possible future use of similar names by - * any future versions of gcc. - * -- D. Landauer, Jan. 1998 - */ - -void *__eh_pc_gcc_272 = (void *)0; -void *__eh_type_gcc_272 = (void *)0; -void *__eh_value_gcc_272 = (void *)0; - -/* This is what egcs uses for its global data pointer */ -void *__eh_global_dataptr = (void *)0; - -void *__keymgr_global[3] = { (void *)0 }; diff --git a/db.subproj/Makefile b/db.subproj/Makefile deleted file mode 100644 index 7ce1eb5..0000000 --- a/db.subproj/Makefile +++ /dev/null @@ -1,51 +0,0 @@ -# -# Generated by the NeXT Project Builder. -# -# NOTE: Do NOT change this file -- Project Builder maintains it. -# -# Put all of your customizations in files called Makefile.preamble -# and Makefile.postamble (both optional), and Makefile will include them. -# - -NAME = db - -PROJECTVERSION = 2.8 -PROJECT_TYPE = Component - -SUBPROJECTS = btree.subproj db.subproj hash.subproj mpool.subproj\ - recno.subproj - -OTHERSRCS = Makefile.preamble Makefile Makefile.postamble - -MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles -CODE_GEN_STYLE = DYNAMIC -MAKEFILE = subproj.make -NEXTSTEP_INSTALLDIR = /Local/Developer/System -LIBS = -DEBUG_LIBS = $(LIBS) -PROF_LIBS = $(LIBS) - - -NEXTSTEP_PB_CFLAGS = -D__DBINTERFACE_PRIVATE - - -NEXTSTEP_BUILD_OUTPUT_DIR = /Local/Public/Sandbox/$(USER)/BUILD/$(NAME) - -NEXTSTEP_PUBLIC_HEADERS_DIR = /usr/include - -NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc -WINDOWS_OBJCPLUS_COMPILER = $(DEVDIR)/gcc -PDO_UNIX_OBJCPLUS_COMPILER = $(NEXTDEV_BIN)/gcc -NEXTSTEP_JAVA_COMPILER = /usr/bin/javac -WINDOWS_JAVA_COMPILER = $(JDKBINDIR)/javac.exe -PDO_UNIX_JAVA_COMPILER = $(JDKBINDIR)/javac - -include $(MAKEFILEDIR)/platform.make - --include Makefile.preamble - -include $(MAKEFILEDIR)/$(MAKEFILE) - --include Makefile.postamble - --include Makefile.dependencies diff --git a/db.subproj/Makefile.postamble b/db.subproj/Makefile.postamble deleted file mode 100644 index 411cde6..0000000 --- a/db.subproj/Makefile.postamble +++ /dev/null @@ -1,100 +0,0 @@ -############################################################################### -# Makefile.postamble -# Copyright 1997, Apple Computer, Inc. -# -# Use this makefile, which is imported after all other makefiles, to -# override attributes for a project's Makefile environment. This allows you -# to take advantage of the environment set up by the other Makefiles. -# You can also define custom rules at the end of this file. -# -############################################################################### -# -# These variables are exported by the standard makefiles and can be -# used in any customizations you make. They are *outputs* of -# the Makefiles and should be used, not set. -# -# PRODUCTS: products to install. All of these products will be placed in -# the directory $(DSTROOT)$(INSTALLDIR) -# GLOBAL_RESOURCE_DIR: The directory to which resources are copied. -# LOCAL_RESOURCE_DIR: The directory to which localized resources are copied. -# OFILE_DIR: Directory into which .o object files are generated. -# DERIVED_SRC_DIR: Directory used for all other derived files -# -# ALL_CFLAGS: flags to pass when compiling .c files -# ALL_MFLAGS: flags to pass when compiling .m files -# ALL_CCFLAGS: flags to pass when compiling .cc, .cxx, and .C files -# ALL_MMFLAGS: flags to pass when compiling .mm, .mxx, and .M files -# ALL_PRECOMPFLAGS: flags to pass when precompiling .h files -# ALL_LDFLAGS: flags to pass when linking object files -# ALL_LIBTOOL_FLAGS: flags to pass when libtooling object files -# ALL_PSWFLAGS: flags to pass when processing .psw and .pswm (pswrap) files -# ALL_RPCFLAGS: flags to pass when processing .rpc (rpcgen) files -# ALL_YFLAGS: flags to pass when processing .y (yacc) files -# ALL_LFLAGS: flags to pass when processing .l (lex) files -# -# NAME: name of application, bundle, subproject, palette, etc. -# LANGUAGES: langages in which the project is written (default "English") -# English_RESOURCES: localized resources (e.g. nib's, images) of project -# GLOBAL_RESOURCES: non-localized resources of project -# -# SRCROOT: base directory in which to place the new source files -# SRCPATH: relative path from SRCROOT to present subdirectory -# -# INSTALLDIR: Directory the product will be installed into by 'install' target -# PUBLIC_HDR_INSTALLDIR: where to install public headers. Don't forget -# to prefix this with DSTROOT when you use it. -# PRIVATE_HDR_INSTALLDIR: where to install private headers. Don't forget -# to prefix this with DSTROOT when you use it. -# -# EXECUTABLE_EXT: Executable extension for the platform (i.e. .exe on Windows) -# -############################################################################### - -# Some compiler flags can be overridden here for certain build situations. -# -# WARNING_CFLAGS: flag used to set warning level (defaults to -Wmost) -# DEBUG_SYMBOLS_CFLAGS: debug-symbol flag passed to all builds (defaults -# to -g) -# DEBUG_BUILD_CFLAGS: flags passed during debug builds (defaults to -DDEBUG) -# OPTIMIZE_BUILD_CFLAGS: flags passed during optimized builds (defaults -# to -O) -# PROFILE_BUILD_CFLAGS: flags passed during profile builds (defaults -# to -pg -DPROFILE) -# LOCAL_DIR_INCLUDE_DIRECTIVE: flag used to add current directory to -# the include path (defaults to -I.) -# DEBUG_BUILD_LDFLAGS, OPTIMIZE_BUILD_LDFLAGS, PROFILE_BUILD_LDFLAGS: flags -# passed to ld/libtool (defaults to nothing) - - -# Library and Framework projects only: -# INSTALL_NAME_DIRECTIVE: This directive ensures that executables linked -# against the framework will run against the correct version even if -# the current version of the framework changes. You may override this -# to "" as an alternative to using the DYLD_LIBRARY_PATH during your -# development cycle, but be sure to restore it before installing. - - -# Ownership and permissions of files installed by 'install' target - -#INSTALL_AS_USER = root - # User/group ownership -#INSTALL_AS_GROUP = wheel - # (probably want to set both of these) -#INSTALL_PERMISSIONS = - # If set, 'install' chmod's executable to this - - -# Options to strip. Note: -S strips debugging symbols (executables can be stripped -# down further with -x or, if they load no bundles, with no options at all). - -#STRIPFLAGS = -S - - -######################################################################### -# Put rules to extend the behavior of the standard Makefiles here. Include them in -# the dependency tree via cvariables like AFTER_INSTALL in the Makefile.preamble. -# -# You should avoid redefining things like "install" or "app", as they are -# owned by the top-level Makefile API and no context has been set up for where -# derived files should go. -# diff --git a/db.subproj/Makefile.preamble b/db.subproj/Makefile.preamble deleted file mode 100644 index c1624b4..0000000 --- a/db.subproj/Makefile.preamble +++ /dev/null @@ -1,137 +0,0 @@ -############################################################################### -# Makefile.preamble -# Copyright 1997, Apple Computer, Inc. -# -# Use this makefile for configuring the standard application makefiles -# associated with ProjectBuilder. It is included before the main makefile. -# In Makefile.preamble you set attributes for a project, so they are available -# to the project's makefiles. In contrast, you typically write additional rules or -# override built-in behavior in the Makefile.postamble. -# -# Each directory in a project tree (main project plus subprojects) should -# have its own Makefile.preamble and Makefile.postamble. -############################################################################### -# -# Before the main makefile is included for this project, you may set: -# -# MAKEFILEDIR: Directory in which to find $(MAKEFILE) -# MAKEFILE: Top level mechanism Makefile (e.g., app.make, bundle.make) - -# Compiler/linker flags added to the defaults: The OTHER_* variables will be -# inherited by all nested sub-projects, but the LOCAL_ versions of the same -# variables will not. Put your -I, -D, -U, and -L flags in ProjectBuilder's -# Build Attributes inspector if at all possible. To override the default flags -# that get passed to ${CC} (e.g. change -O to -O2), see Makefile.postamble. The -# variables below are *inputs* to the build process and distinct from the override -# settings done (less often) in the Makefile.postamble. -# -# OTHER_CFLAGS, LOCAL_CFLAGS: additional flags to pass to the compiler -# Note that $(OTHER_CFLAGS) and $(LOCAL_CFLAGS) are used for .h, ...c, .m, -# .cc, .cxx, .C, and .M files. There is no need to respecify the -# flags in OTHER_MFLAGS, etc. -# OTHER_MFLAGS, LOCAL_MFLAGS: additional flags for .m files -# OTHER_CCFLAGS, LOCAL_CCFLAGS: additional flags for .cc, .cxx, and ...C files -# OTHER_MMFLAGS, LOCAL_MMFLAGS: additional flags for .mm and .M files -# OTHER_PRECOMPFLAGS, LOCAL_PRECOMPFLAGS: additional flags used when -# precompiling header files -# OTHER_LDFLAGS, LOCAL_LDFLAGS: additional flags passed to ld and libtool -# OTHER_PSWFLAGS, LOCAL_PSWFLAGS: additional flags passed to pswrap -# OTHER_RPCFLAGS, LOCAL_RPCFLAGS: additional flags passed to rpcgen -# OTHER_YFLAGS, LOCAL_YFLAGS: additional flags passed to yacc -# OTHER_LFLAGS, LOCAL_LFLAGS: additional flags passed to lex - -# These variables provide hooks enabling you to add behavior at almost every -# stage of the make: -# -# BEFORE_PREBUILD: targets to build before installing headers for a subproject -# AFTER_PREBUILD: targets to build after installing headers for a subproject -# BEFORE_BUILD_RECURSION: targets to make before building subprojects -# BEFORE_BUILD: targets to make before a build, but after subprojects -# AFTER_BUILD: targets to make after a build -# -# BEFORE_INSTALL: targets to build before installing the product -# AFTER_INSTALL: targets to build after installing the product -# BEFORE_POSTINSTALL: targets to build before postinstalling every subproject -# AFTER_POSTINSTALL: targts to build after postinstalling every subproject -# -# BEFORE_INSTALLHDRS: targets to build before installing headers for a -# subproject -# AFTER_INSTALLHDRS: targets to build after installing headers for a subproject -# BEFORE_INSTALLSRC: targets to build before installing source for a subproject -# AFTER_INSTALLSRC: targets to build after installing source for a subproject -# -# BEFORE_DEPEND: targets to build before building dependencies for a -# subproject -# AFTER_DEPEND: targets to build after building dependencies for a -# subproject -# -# AUTOMATIC_DEPENDENCY_INFO: if YES, then the dependency file is -# updated every time the project is built. If NO, the dependency -# file is only built when the depend target is invoked. - -# Framework-related variables: -# FRAMEWORK_DLL_INSTALLDIR: On Windows platforms, this variable indicates -# where to put the framework's DLL. This variable defaults to -# $(INSTALLDIR)/../Executables - -# Library-related variables: -# PUBLIC_HEADER_DIR: Determines where public exported header files -# should be installed. Do not include $(DSTROOT) in this value -- -# it is prefixed automatically. For library projects you should -# set this to something like /Developer/Headers/$(NAME). Do not set -# this variable for framework projects unless you do not want the -# header files included in the framework. -# PRIVATE_HEADER_DIR: Determines where private exported header files -# should be installed. Do not include $(DSTROOT) in this value -- -# it is prefixed automatically. -# LIBRARY_STYLE: This may be either STATIC or DYNAMIC, and determines -# whether the libraries produced are statically linked when they -# are used or if they are dynamically loadable. This defaults to -# DYNAMIC. -# LIBRARY_DLL_INSTALLDIR: On Windows platforms, this variable indicates -# where to put the library's DLL. This variable defaults to -# $(INSTALLDIR)/../Executables -# -# INSTALL_AS_USER: owner of the intalled products (default root) -# INSTALL_AS_GROUP: group of the installed products (default wheel) -# INSTALL_PERMISSIONS: permissions of the installed product (default o+rX) -# -# OTHER_RECURSIVE_VARIABLES: The names of variables which you want to be -# passed on the command line to recursive invocations of make. Note that -# the values in OTHER_*FLAGS are inherited by subprojects automatically -- -# you do not have to (and shouldn't) add OTHER_*FLAGS to -# OTHER_RECURSIVE_VARIABLES. - -# Additional headers to export beyond those in the PB.project: -# OTHER_PUBLIC_HEADERS -# OTHER_PROJECT_HEADERS -# OTHER_PRIVATE_HEADERS - -# Additional files for the project's product: <> -# OTHER_RESOURCES: (non-localized) resources for this project -# OTHER_OFILES: relocatables to be linked into this project -# OTHER_LIBS: more libraries to link against -# OTHER_PRODUCT_DEPENDS: other dependencies of this project -# OTHER_SOURCEFILES: other source files maintained by .pre/postamble -# OTHER_GARBAGE: additional files to be removed by `make clean' - -# Set this to YES if you don't want a final libtool call for a library/framework. -# BUILD_OFILES_LIST_ONLY - -# To include a version string, project source must exist in a directory named -# $(NAME).%d[.%d][.%d] and the following line must be uncommented. -# OTHER_GENERATED_OFILES = $(VERS_OFILE) - -# This definition will suppress stripping of debug symbols when an executable -# is installed. By default it is YES. -# STRIP_ON_INSTALL = NO - -# Uncomment to suppress generation of a KeyValueCoding index when installing -# frameworks (This index is used by WOB and IB to determine keys available -# for an object). Set to YES by default. -# PREINDEX_FRAMEWORK = NO - -# Change this definition to install projects somewhere other than the -# standard locations. NEXT_ROOT defaults to "C:/Apple" on Windows systems -# and "" on other systems. -DSTROOT = $(HOME) diff --git a/db.subproj/PB.project b/db.subproj/PB.project deleted file mode 100644 index 3a69a6c..0000000 --- a/db.subproj/PB.project +++ /dev/null @@ -1,26 +0,0 @@ -{ - DYNAMIC_CODE_GEN = YES; - FILESTABLE = { - H_FILES = (); - OTHER_SOURCES = (Makefile.preamble, Makefile, Makefile.postamble); - SUBPROJECTS = (btree.subproj, db.subproj, hash.subproj, mpool.subproj, recno.subproj); - }; - LANGUAGE = English; - MAKEFILEDIR = "$(MAKEFILEPATH)/pb_makefiles"; - NEXTSTEP_BUILDDIR = "/Local/Public/Sandbox/$(USER)/BUILD/$(NAME)"; - NEXTSTEP_BUILDTOOL = /bin/gnumake; - NEXTSTEP_COMPILEROPTIONS = "-D__DBINTERFACE_PRIVATE"; - NEXTSTEP_INSTALLDIR = /Local/Developer/System; - NEXTSTEP_JAVA_COMPILER = /usr/bin/javac; - NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc; - NEXTSTEP_PUBLICHEADERSDIR = /usr/include; - PDO_UNIX_BUILDTOOL = $NEXT_ROOT/Developer/bin/make; - PDO_UNIX_JAVA_COMPILER = "$(JDKBINDIR)/javac"; - PDO_UNIX_OBJCPLUS_COMPILER = "$(NEXTDEV_BIN)/gcc"; - PROJECTNAME = db; - PROJECTTYPE = Component; - PROJECTVERSION = 2.8; - WINDOWS_BUILDTOOL = $NEXT_ROOT/Developer/Executables/make; - WINDOWS_JAVA_COMPILER = "$(JDKBINDIR)/javac.exe"; - WINDOWS_OBJCPLUS_COMPILER = "$(DEVDIR)/gcc"; -} diff --git a/db.subproj/btree.subproj/Makefile b/db.subproj/btree.subproj/Makefile deleted file mode 100644 index c185508..0000000 --- a/db.subproj/btree.subproj/Makefile +++ /dev/null @@ -1,56 +0,0 @@ -# -# Generated by the NeXT Project Builder. -# -# NOTE: Do NOT change this file -- Project Builder maintains it. -# -# Put all of your customizations in files called Makefile.preamble -# and Makefile.postamble (both optional), and Makefile will include them. -# - -NAME = btree - -PROJECTVERSION = 2.8 -PROJECT_TYPE = Component - -HFILES = bt_extern.h btree.h - -CFILES = bt_close.c bt_conv.c bt_debug.c bt_delete.c bt_get.c\ - bt_open.c bt_overflow.c bt_page.c bt_put.c bt_search.c\ - bt_seq.c bt_split.c bt_stack.c bt_utils.c - -OTHERSRCS = Makefile.preamble Makefile Makefile.postamble - - -MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles -CODE_GEN_STYLE = DYNAMIC -MAKEFILE = subproj.make -NEXTSTEP_INSTALLDIR = /Local/Developer/System -LIBS = -DEBUG_LIBS = $(LIBS) -PROF_LIBS = $(LIBS) - - -PROJECT_HEADERS = btree.h bt_extern.h - - - -NEXTSTEP_BUILD_OUTPUT_DIR = /Local/Public/Sandbox/$(USER)/BUILD/$(NAME) - -NEXTSTEP_PUBLIC_HEADERS_DIR = /usr/include - -NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc -WINDOWS_OBJCPLUS_COMPILER = $(DEVDIR)/gcc -PDO_UNIX_OBJCPLUS_COMPILER = $(NEXTDEV_BIN)/gcc -NEXTSTEP_JAVA_COMPILER = /usr/bin/javac -WINDOWS_JAVA_COMPILER = $(JDKBINDIR)/javac.exe -PDO_UNIX_JAVA_COMPILER = $(JDKBINDIR)/javac - -include $(MAKEFILEDIR)/platform.make - --include Makefile.preamble - -include $(MAKEFILEDIR)/$(MAKEFILE) - --include Makefile.postamble - --include Makefile.dependencies diff --git a/db.subproj/btree.subproj/Makefile.postamble b/db.subproj/btree.subproj/Makefile.postamble deleted file mode 100644 index 411cde6..0000000 --- a/db.subproj/btree.subproj/Makefile.postamble +++ /dev/null @@ -1,100 +0,0 @@ -############################################################################### -# Makefile.postamble -# Copyright 1997, Apple Computer, Inc. -# -# Use this makefile, which is imported after all other makefiles, to -# override attributes for a project's Makefile environment. This allows you -# to take advantage of the environment set up by the other Makefiles. -# You can also define custom rules at the end of this file. -# -############################################################################### -# -# These variables are exported by the standard makefiles and can be -# used in any customizations you make. They are *outputs* of -# the Makefiles and should be used, not set. -# -# PRODUCTS: products to install. All of these products will be placed in -# the directory $(DSTROOT)$(INSTALLDIR) -# GLOBAL_RESOURCE_DIR: The directory to which resources are copied. -# LOCAL_RESOURCE_DIR: The directory to which localized resources are copied. -# OFILE_DIR: Directory into which .o object files are generated. -# DERIVED_SRC_DIR: Directory used for all other derived files -# -# ALL_CFLAGS: flags to pass when compiling .c files -# ALL_MFLAGS: flags to pass when compiling .m files -# ALL_CCFLAGS: flags to pass when compiling .cc, .cxx, and .C files -# ALL_MMFLAGS: flags to pass when compiling .mm, .mxx, and .M files -# ALL_PRECOMPFLAGS: flags to pass when precompiling .h files -# ALL_LDFLAGS: flags to pass when linking object files -# ALL_LIBTOOL_FLAGS: flags to pass when libtooling object files -# ALL_PSWFLAGS: flags to pass when processing .psw and .pswm (pswrap) files -# ALL_RPCFLAGS: flags to pass when processing .rpc (rpcgen) files -# ALL_YFLAGS: flags to pass when processing .y (yacc) files -# ALL_LFLAGS: flags to pass when processing .l (lex) files -# -# NAME: name of application, bundle, subproject, palette, etc. -# LANGUAGES: langages in which the project is written (default "English") -# English_RESOURCES: localized resources (e.g. nib's, images) of project -# GLOBAL_RESOURCES: non-localized resources of project -# -# SRCROOT: base directory in which to place the new source files -# SRCPATH: relative path from SRCROOT to present subdirectory -# -# INSTALLDIR: Directory the product will be installed into by 'install' target -# PUBLIC_HDR_INSTALLDIR: where to install public headers. Don't forget -# to prefix this with DSTROOT when you use it. -# PRIVATE_HDR_INSTALLDIR: where to install private headers. Don't forget -# to prefix this with DSTROOT when you use it. -# -# EXECUTABLE_EXT: Executable extension for the platform (i.e. .exe on Windows) -# -############################################################################### - -# Some compiler flags can be overridden here for certain build situations. -# -# WARNING_CFLAGS: flag used to set warning level (defaults to -Wmost) -# DEBUG_SYMBOLS_CFLAGS: debug-symbol flag passed to all builds (defaults -# to -g) -# DEBUG_BUILD_CFLAGS: flags passed during debug builds (defaults to -DDEBUG) -# OPTIMIZE_BUILD_CFLAGS: flags passed during optimized builds (defaults -# to -O) -# PROFILE_BUILD_CFLAGS: flags passed during profile builds (defaults -# to -pg -DPROFILE) -# LOCAL_DIR_INCLUDE_DIRECTIVE: flag used to add current directory to -# the include path (defaults to -I.) -# DEBUG_BUILD_LDFLAGS, OPTIMIZE_BUILD_LDFLAGS, PROFILE_BUILD_LDFLAGS: flags -# passed to ld/libtool (defaults to nothing) - - -# Library and Framework projects only: -# INSTALL_NAME_DIRECTIVE: This directive ensures that executables linked -# against the framework will run against the correct version even if -# the current version of the framework changes. You may override this -# to "" as an alternative to using the DYLD_LIBRARY_PATH during your -# development cycle, but be sure to restore it before installing. - - -# Ownership and permissions of files installed by 'install' target - -#INSTALL_AS_USER = root - # User/group ownership -#INSTALL_AS_GROUP = wheel - # (probably want to set both of these) -#INSTALL_PERMISSIONS = - # If set, 'install' chmod's executable to this - - -# Options to strip. Note: -S strips debugging symbols (executables can be stripped -# down further with -x or, if they load no bundles, with no options at all). - -#STRIPFLAGS = -S - - -######################################################################### -# Put rules to extend the behavior of the standard Makefiles here. Include them in -# the dependency tree via cvariables like AFTER_INSTALL in the Makefile.preamble. -# -# You should avoid redefining things like "install" or "app", as they are -# owned by the top-level Makefile API and no context has been set up for where -# derived files should go. -# diff --git a/db.subproj/btree.subproj/Makefile.preamble b/db.subproj/btree.subproj/Makefile.preamble deleted file mode 100644 index c9fa330..0000000 --- a/db.subproj/btree.subproj/Makefile.preamble +++ /dev/null @@ -1,3 +0,0 @@ -OTHER_PRIVATE_HEADERS = btree.h bt_extern.h -PUBLIC_HEADER_DIR_SUFFIX = /btree -PRIVATE_HEADER_DIR_SUFFIX = /btree diff --git a/db.subproj/btree.subproj/PB.project b/db.subproj/btree.subproj/PB.project deleted file mode 100644 index 8de9a71..0000000 --- a/db.subproj/btree.subproj/PB.project +++ /dev/null @@ -1,42 +0,0 @@ -{ - DYNAMIC_CODE_GEN = YES; - FILESTABLE = { - H_FILES = (bt_extern.h, btree.h); - OTHER_LINKED = ( - bt_close.c, - bt_conv.c, - bt_debug.c, - bt_delete.c, - bt_get.c, - bt_open.c, - bt_overflow.c, - bt_page.c, - bt_put.c, - bt_search.c, - bt_seq.c, - bt_split.c, - bt_stack.c, - bt_utils.c - ); - OTHER_SOURCES = (Makefile.preamble, Makefile, Makefile.postamble); - PROJECT_HEADERS = (btree.h, bt_extern.h); - SUBPROJECTS = (); - }; - LANGUAGE = English; - MAKEFILEDIR = "$(MAKEFILEPATH)/pb_makefiles"; - NEXTSTEP_BUILDDIR = "/Local/Public/Sandbox/$(USER)/BUILD/$(NAME)"; - NEXTSTEP_BUILDTOOL = /bin/gnumake; - NEXTSTEP_INSTALLDIR = /Local/Developer/System; - NEXTSTEP_JAVA_COMPILER = /usr/bin/javac; - NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc; - NEXTSTEP_PUBLICHEADERSDIR = /usr/include; - PDO_UNIX_BUILDTOOL = $NEXT_ROOT/Developer/bin/make; - PDO_UNIX_JAVA_COMPILER = "$(JDKBINDIR)/javac"; - PDO_UNIX_OBJCPLUS_COMPILER = "$(NEXTDEV_BIN)/gcc"; - PROJECTNAME = btree; - PROJECTTYPE = Component; - PROJECTVERSION = 2.8; - WINDOWS_BUILDTOOL = $NEXT_ROOT/Developer/Executables/make; - WINDOWS_JAVA_COMPILER = "$(JDKBINDIR)/javac.exe"; - WINDOWS_OBJCPLUS_COMPILER = "$(DEVDIR)/gcc"; -} diff --git a/db.subproj/btree.subproj/bt_close.c b/db.subproj/btree.subproj/bt_close.c deleted file mode 100644 index 9cbbf8a..0000000 --- a/db.subproj/btree.subproj/bt_close.c +++ /dev/null @@ -1,222 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Mike Olson. - * - * 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 - -#include -#include -#include -#include -#include - -#include -#include "btree.h" - -static int bt_meta __P((BTREE *)); - -/* - * BT_CLOSE -- Close a btree. - * - * Parameters: - * dbp: pointer to access method - * - * Returns: - * RET_ERROR, RET_SUCCESS - */ -int -__bt_close(dbp) - DB *dbp; -{ - BTREE *t; - int fd; - - t = dbp->internal; - - /* Toss any page pinned across calls. */ - if (t->bt_pinned != NULL) { - mpool_put(t->bt_mp, t->bt_pinned, 0); - t->bt_pinned = NULL; - } - - /* - * Delete any already deleted record that we've been saving - * because the cursor pointed to it. - */ - if (ISSET(t, B_DELCRSR) && __bt_crsrdel(t, &t->bt_bcursor)) - return (RET_ERROR); - - if (__bt_sync(dbp, 0) == RET_ERROR) - return (RET_ERROR); - - if (mpool_close(t->bt_mp) == RET_ERROR) - return (RET_ERROR); - - if (t->bt_stack) - free(t->bt_stack); - if (t->bt_kbuf) - free(t->bt_kbuf); - if (t->bt_dbuf) - free(t->bt_dbuf); - - fd = t->bt_fd; - free(t); - free(dbp); - return (close(fd) ? RET_ERROR : RET_SUCCESS); -} - -/* - * BT_SYNC -- sync the btree to disk. - * - * Parameters: - * dbp: pointer to access method - * - * Returns: - * RET_SUCCESS, RET_ERROR. - */ -int -__bt_sync(dbp, flags) - const DB *dbp; - u_int flags; -{ - BTREE *t; - int status; - PAGE *h; - void *p; - - t = dbp->internal; - - /* Toss any page pinned across calls. */ - if (t->bt_pinned != NULL) { - mpool_put(t->bt_mp, t->bt_pinned, 0); - t->bt_pinned = NULL; - } - - /* Sync doesn't currently take any flags. */ - if (flags != 0) { - errno = EINVAL; - return (RET_ERROR); - } - - if (ISSET(t, B_INMEM | B_RDONLY) || !ISSET(t, B_MODIFIED)) - return (RET_SUCCESS); - - if (ISSET(t, B_METADIRTY) && bt_meta(t) == RET_ERROR) - return (RET_ERROR); - - /* - * Nastiness. If the cursor has been marked for deletion, but not - * actually deleted, we have to make a copy of the page, delete the - * key/data item, sync the file, and then restore the original page - * contents. - */ - if (ISSET(t, B_DELCRSR)) { - if ((p = (void *)malloc(t->bt_psize)) == NULL) - return (RET_ERROR); - if ((h = mpool_get(t->bt_mp, t->bt_bcursor.pgno, 0)) == NULL) - return (RET_ERROR); - memmove(p, h, t->bt_psize); - if ((status = - __bt_dleaf(t, h, t->bt_bcursor.index)) == RET_ERROR) - goto ecrsr; - mpool_put(t->bt_mp, h, MPOOL_DIRTY); - } - - if ((status = mpool_sync(t->bt_mp)) == RET_SUCCESS) - CLR(t, B_MODIFIED); - -ecrsr: if (ISSET(t, B_DELCRSR)) { - if ((h = mpool_get(t->bt_mp, t->bt_bcursor.pgno, 0)) == NULL) - return (RET_ERROR); - memmove(h, p, t->bt_psize); - free(p); - mpool_put(t->bt_mp, h, MPOOL_DIRTY); - } - return (status); -} - -/* - * BT_META -- write the tree meta data to disk. - * - * Parameters: - * t: tree - * - * Returns: - * RET_ERROR, RET_SUCCESS - */ -static int -bt_meta(t) - BTREE *t; -{ - BTMETA m; - void *p; - - if ((p = mpool_get(t->bt_mp, P_META, 0)) == NULL) - return (RET_ERROR); - - /* Fill in metadata. */ - m.m_magic = BTREEMAGIC; - m.m_version = BTREEVERSION; - m.m_psize = t->bt_psize; - m.m_free = t->bt_free; - m.m_nrecs = t->bt_nrecs; - m.m_flags = t->bt_flags & SAVEMETA; - - memmove(p, &m, sizeof(BTMETA)); - mpool_put(t->bt_mp, p, MPOOL_DIRTY); - return (RET_SUCCESS); -} diff --git a/db.subproj/btree.subproj/bt_conv.c b/db.subproj/btree.subproj/bt_conv.c deleted file mode 100644 index 41d9530..0000000 --- a/db.subproj/btree.subproj/bt_conv.c +++ /dev/null @@ -1,239 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Mike Olson. - * - * 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 - -#include - -#include -#include "btree.h" - -static void mswap __P((PAGE *)); - -/* - * __BT_BPGIN, __BT_BPGOUT -- - * Convert host-specific number layout to/from the host-independent - * format stored on disk. - * - * Parameters: - * t: tree - * pg: page number - * h: page to convert - */ -void -__bt_pgin(t, pg, pp) - void *t; - pgno_t pg; - void *pp; -{ - PAGE *h; - indx_t i, top; - u_char flags; - char *p; - - if (!ISSET(((BTREE *)t), B_NEEDSWAP)) - return; - if (pg == P_META) { - mswap(pp); - return; - } - - h = pp; - M_32_SWAP(h->pgno); - M_32_SWAP(h->prevpg); - M_32_SWAP(h->nextpg); - M_32_SWAP(h->flags); - M_16_SWAP(h->lower); - M_16_SWAP(h->upper); - - top = NEXTINDEX(h); - if ((h->flags & P_TYPE) == P_BINTERNAL) - for (i = 0; i < top; i++) { - M_16_SWAP(h->linp[i]); - p = (char *)GETBINTERNAL(h, i); - P_32_SWAP(p); - p += sizeof(size_t); - P_32_SWAP(p); - p += sizeof(pgno_t); - if (*(u_char *)p & P_BIGKEY) { - p += sizeof(u_char); - P_32_SWAP(p); - p += sizeof(pgno_t); - P_32_SWAP(p); - } - } - else if ((h->flags & P_TYPE) == P_BLEAF) - for (i = 0; i < top; i++) { - M_16_SWAP(h->linp[i]); - p = (char *)GETBLEAF(h, i); - P_32_SWAP(p); - p += sizeof(size_t); - P_32_SWAP(p); - p += sizeof(size_t); - flags = *(u_char *)p; - if (flags & (P_BIGKEY | P_BIGDATA)) { - p += sizeof(u_char); - if (flags & P_BIGKEY) { - P_32_SWAP(p); - p += sizeof(pgno_t); - P_32_SWAP(p); - } - if (flags & P_BIGDATA) { - p += sizeof(size_t); - P_32_SWAP(p); - p += sizeof(pgno_t); - P_32_SWAP(p); - } - } - } -} - -void -__bt_pgout(t, pg, pp) - void *t; - pgno_t pg; - void *pp; -{ - PAGE *h; - indx_t i, top; - u_char flags; - char *p; - - if (!ISSET(((BTREE *)t), B_NEEDSWAP)) - return; - if (pg == P_META) { - mswap(pp); - return; - } - - h = pp; - top = NEXTINDEX(h); - if ((h->flags & P_TYPE) == P_BINTERNAL) - for (i = 0; i < top; i++) { - p = (char *)GETBINTERNAL(h, i); - P_32_SWAP(p); - p += sizeof(size_t); - P_32_SWAP(p); - p += sizeof(pgno_t); - if (*(u_char *)p & P_BIGKEY) { - p += sizeof(u_char); - P_32_SWAP(p); - p += sizeof(pgno_t); - P_32_SWAP(p); - } - M_16_SWAP(h->linp[i]); - } - else if ((h->flags & P_TYPE) == P_BLEAF) - for (i = 0; i < top; i++) { - p = (char *)GETBLEAF(h, i); - P_32_SWAP(p); - p += sizeof(size_t); - P_32_SWAP(p); - p += sizeof(size_t); - flags = *(u_char *)p; - if (flags & (P_BIGKEY | P_BIGDATA)) { - p += sizeof(u_char); - if (flags & P_BIGKEY) { - P_32_SWAP(p); - p += sizeof(pgno_t); - P_32_SWAP(p); - } - if (flags & P_BIGDATA) { - p += sizeof(size_t); - P_32_SWAP(p); - p += sizeof(pgno_t); - P_32_SWAP(p); - } - } - M_16_SWAP(h->linp[i]); - } - - M_32_SWAP(h->pgno); - M_32_SWAP(h->prevpg); - M_32_SWAP(h->nextpg); - M_32_SWAP(h->flags); - M_16_SWAP(h->lower); - M_16_SWAP(h->upper); -} - -/* - * MSWAP -- Actually swap the bytes on the meta page. - * - * Parameters: - * p: page to convert - */ -static void -mswap(pg) - PAGE *pg; -{ - char *p; - - p = (char *)pg; - P_32_SWAP(p); /* m_magic */ - p += sizeof(u_int32_t); - P_32_SWAP(p); /* m_version */ - p += sizeof(u_int32_t); - P_32_SWAP(p); /* m_psize */ - p += sizeof(u_int32_t); - P_32_SWAP(p); /* m_free */ - p += sizeof(u_int32_t); - P_32_SWAP(p); /* m_nrecs */ - p += sizeof(u_int32_t); - P_32_SWAP(p); /* m_flags */ - p += sizeof(u_int32_t); -} diff --git a/db.subproj/btree.subproj/bt_debug.c b/db.subproj/btree.subproj/bt_debug.c deleted file mode 100644 index e64187c..0000000 --- a/db.subproj/btree.subproj/bt_debug.c +++ /dev/null @@ -1,349 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Mike Olson. - * - * 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 - -#include -#include -#include - -#include -#include "btree.h" - -#ifdef DEBUG -/* - * BT_DUMP -- Dump the tree - * - * Parameters: - * dbp: pointer to the DB - */ -void -__bt_dump(dbp) - DB *dbp; -{ - BTREE *t; - PAGE *h; - pgno_t i; - char *sep; - - t = dbp->internal; - (void)fprintf(stderr, "%s: pgsz %d", - ISSET(t, B_INMEM) ? "memory" : "disk", t->bt_psize); - if (ISSET(t, R_RECNO)) - (void)fprintf(stderr, " keys %lu", t->bt_nrecs); -#undef X -#define X(flag, name) \ - if (ISSET(t, flag)) { \ - (void)fprintf(stderr, "%s%s", sep, name); \ - sep = ", "; \ - } - if (t->bt_flags) { - sep = " flags ("; - X(B_DELCRSR, "DELCRSR"); - X(R_FIXLEN, "FIXLEN"); - X(B_INMEM, "INMEM"); - X(B_NODUPS, "NODUPS"); - X(B_RDONLY, "RDONLY"); - X(R_RECNO, "RECNO"); - X(B_SEQINIT, "SEQINIT"); - X(B_METADIRTY,"METADIRTY"); - (void)fprintf(stderr, ")\n"); - } -#undef X - - for (i = P_ROOT; (h = mpool_get(t->bt_mp, i, 0)) != NULL; ++i) { - __bt_dpage(h); - (void)mpool_put(t->bt_mp, h, 0); - } -} - -/* - * BT_DMPAGE -- Dump the meta page - * - * Parameters: - * h: pointer to the PAGE - */ -void -__bt_dmpage(h) - PAGE *h; -{ - BTMETA *m; - char *sep; - - m = (BTMETA *)h; - (void)fprintf(stderr, "magic %lx\n", m->m_magic); - (void)fprintf(stderr, "version %lu\n", m->m_version); - (void)fprintf(stderr, "psize %lu\n", m->m_psize); - (void)fprintf(stderr, "free %lu\n", m->m_free); - (void)fprintf(stderr, "nrecs %lu\n", m->m_nrecs); - (void)fprintf(stderr, "flags %lu", m->m_flags); -#undef X -#define X(flag, name) \ - if (m->m_flags & flag) { \ - (void)fprintf(stderr, "%s%s", sep, name); \ - sep = ", "; \ - } - if (m->m_flags) { - sep = " ("; - X(B_NODUPS, "NODUPS"); - X(R_RECNO, "RECNO"); - (void)fprintf(stderr, ")"); - } -} - -/* - * BT_DNPAGE -- Dump the page - * - * Parameters: - * n: page number to dump. - */ -void -__bt_dnpage(dbp, pgno) - DB *dbp; - pgno_t pgno; -{ - BTREE *t; - PAGE *h; - - t = dbp->internal; - if ((h = mpool_get(t->bt_mp, pgno, 0)) != NULL) { - __bt_dpage(h); - (void)mpool_put(t->bt_mp, h, 0); - } -} - -/* - * BT_DPAGE -- Dump the page - * - * Parameters: - * h: pointer to the PAGE - */ -void -__bt_dpage(h) - PAGE *h; -{ - BINTERNAL *bi; - BLEAF *bl; - RINTERNAL *ri; - RLEAF *rl; - indx_t cur, top; - char *sep; - - (void)fprintf(stderr, " page %d: (", h->pgno); -#undef X -#define X(flag, name) \ - if (h->flags & flag) { \ - (void)fprintf(stderr, "%s%s", sep, name); \ - sep = ", "; \ - } - sep = ""; - X(P_BINTERNAL, "BINTERNAL") /* types */ - X(P_BLEAF, "BLEAF") - X(P_RINTERNAL, "RINTERNAL") /* types */ - X(P_RLEAF, "RLEAF") - X(P_OVERFLOW, "OVERFLOW") - X(P_PRESERVE, "PRESERVE"); - (void)fprintf(stderr, ")\n"); -#undef X - - (void)fprintf(stderr, "\tprev %2d next %2d", h->prevpg, h->nextpg); - if (h->flags & P_OVERFLOW) - return; - - top = NEXTINDEX(h); - (void)fprintf(stderr, " lower %3d upper %3d nextind %d\n", - h->lower, h->upper, top); - for (cur = 0; cur < top; cur++) { - (void)fprintf(stderr, "\t[%03d] %4d ", cur, h->linp[cur]); - switch(h->flags & P_TYPE) { - case P_BINTERNAL: - bi = GETBINTERNAL(h, cur); - (void)fprintf(stderr, - "size %03d pgno %03d", bi->ksize, bi->pgno); - if (bi->flags & P_BIGKEY) - (void)fprintf(stderr, " (indirect)"); - else if (bi->ksize) - (void)fprintf(stderr, - " {%.*s}", (int)bi->ksize, bi->bytes); - break; - case P_RINTERNAL: - ri = GETRINTERNAL(h, cur); - (void)fprintf(stderr, "entries %03d pgno %03d", - ri->nrecs, ri->pgno); - break; - case P_BLEAF: - bl = GETBLEAF(h, cur); - if (bl->flags & P_BIGKEY) - (void)fprintf(stderr, - "big key page %lu size %u/", - *(pgno_t *)bl->bytes, - *(size_t *)(bl->bytes + sizeof(pgno_t))); - else if (bl->ksize) - (void)fprintf(stderr, "%s/", bl->bytes); - if (bl->flags & P_BIGDATA) - (void)fprintf(stderr, - "big data page %lu size %u", - *(pgno_t *)(bl->bytes + bl->ksize), - *(size_t *)(bl->bytes + bl->ksize + - sizeof(pgno_t))); - else if (bl->dsize) - (void)fprintf(stderr, "%.*s", - (int)bl->dsize, bl->bytes + bl->ksize); - break; - case P_RLEAF: - rl = GETRLEAF(h, cur); - if (rl->flags & P_BIGDATA) - (void)fprintf(stderr, - "big data page %lu size %u", - *(pgno_t *)rl->bytes, - *(size_t *)(rl->bytes + sizeof(pgno_t))); - else if (rl->dsize) - (void)fprintf(stderr, - "%.*s", (int)rl->dsize, rl->bytes); - break; - } - (void)fprintf(stderr, "\n"); - } -} -#endif - -#ifdef STATISTICS -/* - * BT_STAT -- Gather/print the tree statistics - * - * Parameters: - * dbp: pointer to the DB - */ -void -__bt_stat(dbp) - DB *dbp; -{ - extern u_long bt_cache_hit, bt_cache_miss, bt_pfxsaved, bt_rootsplit; - extern u_long bt_sortsplit, bt_split; - BTREE *t; - PAGE *h; - pgno_t i, pcont, pinternal, pleaf; - u_long ifree, lfree, nkeys; - int levels; - - t = dbp->internal; - pcont = pinternal = pleaf = 0; - nkeys = ifree = lfree = 0; - for (i = P_ROOT; (h = mpool_get(t->bt_mp, i, 0)) != NULL; ++i) { - switch(h->flags & P_TYPE) { - case P_BINTERNAL: - case P_RINTERNAL: - ++pinternal; - ifree += h->upper - h->lower; - break; - case P_BLEAF: - case P_RLEAF: - ++pleaf; - lfree += h->upper - h->lower; - nkeys += NEXTINDEX(h); - break; - case P_OVERFLOW: - ++pcont; - break; - } - (void)mpool_put(t->bt_mp, h, 0); - } - - /* Count the levels of the tree. */ - for (i = P_ROOT, levels = 0 ;; ++levels) { - h = mpool_get(t->bt_mp, i, 0); - if (h->flags & (P_BLEAF|P_RLEAF)) { - if (levels == 0) - levels = 1; - (void)mpool_put(t->bt_mp, h, 0); - break; - } - i = ISSET(t, R_RECNO) ? - GETRINTERNAL(h, 0)->pgno : - GETBINTERNAL(h, 0)->pgno; - (void)mpool_put(t->bt_mp, h, 0); - } - - (void)fprintf(stderr, "%d level%s with %ld keys", - levels, levels == 1 ? "" : "s", nkeys); - if (ISSET(t, R_RECNO)) - (void)fprintf(stderr, " (%ld header count)", t->bt_nrecs); - (void)fprintf(stderr, - "\n%lu pages (leaf %ld, internal %ld, overflow %ld)\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", - bt_split, bt_rootsplit, bt_sortsplit); - pleaf *= t->bt_psize - BTDATAOFF; - if (pleaf) - (void)fprintf(stderr, - "%.0f%% leaf fill (%ld bytes used, %ld bytes free)\n", - ((double)(pleaf - lfree) / pleaf) * 100, - pleaf - lfree, lfree); - pinternal *= t->bt_psize - BTDATAOFF; - if (pinternal) - (void)fprintf(stderr, - "%.0f%% internal fill (%ld bytes used, %ld bytes free\n", - ((double)(pinternal - ifree) / pinternal) * 100, - pinternal - ifree, ifree); - if (bt_pfxsaved) - (void)fprintf(stderr, "prefix checking removed %lu bytes.\n", - bt_pfxsaved); -} -#endif diff --git a/db.subproj/btree.subproj/bt_delete.c b/db.subproj/btree.subproj/bt_delete.c deleted file mode 100644 index 90f049d..0000000 --- a/db.subproj/btree.subproj/bt_delete.c +++ /dev/null @@ -1,342 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Mike Olson. - * - * 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 - -#include -#include -#include - -#include -#include "btree.h" - -static int bt_bdelete __P((BTREE *, const DBT *)); - -/* - * __BT_DELETE -- Delete the item(s) referenced by a key. - * - * Parameters: - * dbp: pointer to access method - * key: key to delete - * flags: R_CURSOR if deleting what the cursor references - * - * Returns: - * RET_ERROR, RET_SUCCESS and RET_SPECIAL if the key not found. - */ -int -__bt_delete(dbp, key, flags) - const DB *dbp; - const DBT *key; - u_int flags; -{ - BTREE *t; - int status; - - t = dbp->internal; - - /* Toss any page pinned across calls. */ - if (t->bt_pinned != NULL) { - mpool_put(t->bt_mp, t->bt_pinned, 0); - t->bt_pinned = NULL; - } - - if (ISSET(t, B_RDONLY)) { - errno = EPERM; - return (RET_ERROR); - } - - switch(flags) { - case 0: - status = bt_bdelete(t, key); - break; - case R_CURSOR: - /* - * If flags is R_CURSOR, delete the cursor; must already have - * started a scan and not have already deleted the record. For - * the delete cursor bit to have been set requires that the - * scan be initialized, so no reason to check. - */ - if (!ISSET(t, B_SEQINIT)) - goto einval; - status = ISSET(t, B_DELCRSR) ? - RET_SPECIAL : __bt_crsrdel(t, &t->bt_bcursor); - break; - default: -einval: errno = EINVAL; - return (RET_ERROR); - } - if (status == RET_SUCCESS) - SET(t, B_MODIFIED); - return (status); -} - -/* - * BT_BDELETE -- Delete all key/data pairs matching the specified key. - * - * Parameters: - * tree: tree - * key: key to delete - * - * Returns: - * RET_ERROR, RET_SUCCESS and RET_SPECIAL if the key not found. - */ -static int -bt_bdelete(t, key) - BTREE *t; - const DBT *key; -{ - EPG *e, save; - PAGE *h; - pgno_t cpgno, pg; - indx_t cindex; - int deleted, dirty1, dirty2, exact; - - /* Find any matching record; __bt_search pins the page. */ - if ((e = __bt_search(t, key, &exact)) == NULL) - return (RET_ERROR); - if (!exact) { - mpool_put(t->bt_mp, e->page, 0); - return (RET_SPECIAL); - } - - /* - * Delete forward, then delete backward, from the found key. The - * ordering is so that the deletions don't mess up the page refs. - * The first loop deletes the key from the original page, the second - * unpins the original page. In the first loop, dirty1 is set if - * the original page is modified, and dirty2 is set if any subsequent - * pages are modified. In the second loop, dirty1 starts off set if - * the original page has been modified, and is set if any subsequent - * pages are modified. - * - * If find the key referenced by the cursor, don't delete it, just - * flag it for future deletion. The cursor page number is P_INVALID - * unless the sequential scan is initialized, so no reason to check. - * A special case is when the already deleted cursor record was the - * only record found. If so, then the delete opertion fails as no - * records were deleted. - * - * Cycle in place in the current page until the current record doesn't - * match the key or the page is empty. If the latter, walk forward, - * skipping empty pages and repeating until a record doesn't match - * the key or the end of the tree is reached. - */ - cpgno = t->bt_bcursor.pgno; - cindex = t->bt_bcursor.index; - save = *e; - dirty1 = 0; - for (h = e->page, deleted = 0;;) { - dirty2 = 0; - do { - if (h->pgno == cpgno && e->index == cindex) { - if (!ISSET(t, B_DELCRSR)) { - SET(t, B_DELCRSR); - deleted = 1; - } - ++e->index; - } else { - if (__bt_dleaf(t, h, e->index)) { - if (h->pgno != save.page->pgno) - mpool_put(t->bt_mp, h, dirty2); - mpool_put(t->bt_mp, save.page, dirty1); - return (RET_ERROR); - } - if (h->pgno == save.page->pgno) - dirty1 = MPOOL_DIRTY; - else - dirty2 = MPOOL_DIRTY; - deleted = 1; - } - } while (e->index < NEXTINDEX(h) && __bt_cmp(t, key, e) == 0); - - /* - * Quit if didn't find a match, no next page, or first key on - * the next page doesn't match. Don't unpin the original page - * unless an error occurs. - */ - if (e->index < NEXTINDEX(h)) - break; - for (;;) { - if ((pg = h->nextpg) == P_INVALID) - goto done1; - if (h->pgno != save.page->pgno) - mpool_put(t->bt_mp, h, dirty2); - if ((h = mpool_get(t->bt_mp, pg, 0)) == NULL) { - mpool_put(t->bt_mp, save.page, dirty1); - return (RET_ERROR); - } - if (NEXTINDEX(h) != 0) { - e->page = h; - e->index = 0; - break; - } - } - - if (__bt_cmp(t, key, e) != 0) - break; - } - - /* - * Reach here with the original page and the last page referenced - * pinned (they may be the same). Release it if not the original. - */ -done1: if (h->pgno != save.page->pgno) - mpool_put(t->bt_mp, h, dirty2); - - /* - * Walk backwards from the record previous to the record returned by - * __bt_search, skipping empty pages, until a record doesn't match - * the key or reach the beginning of the tree. - */ - *e = save; - for (;;) { - if (e->index) - --e->index; - for (h = e->page; e->index; --e->index) { - if (__bt_cmp(t, key, e) != 0) - goto done2; - if (h->pgno == cpgno && e->index == cindex) { - if (!ISSET(t, B_DELCRSR)) { - SET(t, B_DELCRSR); - deleted = 1; - } - } else { - if (__bt_dleaf(t, h, e->index) == RET_ERROR) { - mpool_put(t->bt_mp, h, dirty1); - return (RET_ERROR); - } - if (h->pgno == save.page->pgno) - dirty1 = MPOOL_DIRTY; - deleted = 1; - } - } - - if ((pg = h->prevpg) == P_INVALID) - goto done2; - mpool_put(t->bt_mp, h, dirty1); - dirty1 = 0; - if ((e->page = mpool_get(t->bt_mp, pg, 0)) == NULL) - return (RET_ERROR); - e->index = NEXTINDEX(e->page); - } - - /* - * Reach here with the last page that was looked at pinned. Release - * it. - */ -done2: mpool_put(t->bt_mp, h, dirty1); - return (deleted ? RET_SUCCESS : RET_SPECIAL); -} - -/* - * __BT_DLEAF -- Delete a single record from a leaf page. - * - * Parameters: - * t: tree - * index: index on current page to delete - * - * Returns: - * RET_SUCCESS, RET_ERROR. - */ -int -__bt_dleaf(t, h, index) - BTREE *t; - PAGE *h; - indx_t index; -{ - register BLEAF *bl; - register indx_t cnt, *ip, offset; - register size_t nbytes; - char *from; - void *to; - - /* - * Delete a record from a btree leaf page. Internal records are never - * deleted from internal pages, regardless of the records that caused - * them to be added being deleted. Pages made empty by deletion are - * not reclaimed. They are, however, made available for reuse. - * - * Pack the remaining entries at the end of the page, shift the indices - * down, overwriting the deleted record and its index. If the record - * uses overflow pages, make them available for reuse. - */ - to = bl = GETBLEAF(h, index); - if (bl->flags & P_BIGKEY && __ovfl_delete(t, bl->bytes) == RET_ERROR) - return (RET_ERROR); - if (bl->flags & P_BIGDATA && - __ovfl_delete(t, bl->bytes + bl->ksize) == RET_ERROR) - return (RET_ERROR); - nbytes = NBLEAF(bl); - - /* - * Compress the key/data pairs. Compress and adjust the [BR]LEAF - * offsets. Reset the headers. - */ - from = (char *)h + h->upper; - memmove(from + nbytes, from, (char *)to - from); - h->upper += nbytes; - - offset = h->linp[index]; - for (cnt = index, ip = &h->linp[0]; cnt--; ++ip) - if (ip[0] < offset) - ip[0] += nbytes; - for (cnt = NEXTINDEX(h) - index; --cnt; ++ip) - ip[0] = ip[1] < offset ? ip[1] + nbytes : ip[1]; - h->lower -= sizeof(indx_t); - return (RET_SUCCESS); -} diff --git a/db.subproj/btree.subproj/bt_extern.h b/db.subproj/btree.subproj/bt_extern.h deleted file mode 100644 index 9a3839b..0000000 --- a/db.subproj/btree.subproj/bt_extern.h +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * 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. - */ - -int __bt_close __P((DB *)); -int __bt_cmp __P((BTREE *, const DBT *, EPG *)); -int __bt_crsrdel __P((BTREE *, EPGNO *)); -int __bt_defcmp __P((const DBT *, const DBT *)); -size_t __bt_defpfx __P((const DBT *, const DBT *)); -int __bt_delete __P((const DB *, const DBT *, u_int)); -int __bt_dleaf __P((BTREE *, PAGE *, int)); -int __bt_fd __P((const DB *)); -EPG *__bt_first __P((BTREE *, const DBT *, int *)); -int __bt_free __P((BTREE *, PAGE *)); -int __bt_get __P((const DB *, const DBT *, DBT *, u_int)); -PAGE *__bt_new __P((BTREE *, pgno_t *)); -void __bt_pgin __P((void *, pgno_t, void *)); -void __bt_pgout __P((void *, pgno_t, void *)); -int __bt_push __P((BTREE *, pgno_t, int)); -int __bt_put __P((const DB *dbp, DBT *, const DBT *, u_int)); -int __bt_ret __P((BTREE *, EPG *, DBT *, DBT *)); -EPG *__bt_search __P((BTREE *, const DBT *, int *)); -int __bt_seq __P((const DB *, DBT *, DBT *, u_int)); -int __bt_split __P((BTREE *, PAGE *, - const DBT *, const DBT *, int, size_t, indx_t)); -int __bt_sync __P((const DB *, u_int)); - -int __ovfl_delete __P((BTREE *, void *)); -int __ovfl_get __P((BTREE *, void *, size_t *, char **, size_t *)); -int __ovfl_put __P((BTREE *, const DBT *, pgno_t *)); - -#ifdef DEBUG -void __bt_dnpage __P((DB *, pgno_t)); -void __bt_dpage __P((PAGE *)); -void __bt_dump __P((DB *)); -#endif -#ifdef STATISTICS -void __bt_stat __P((DB *)); -#endif diff --git a/db.subproj/btree.subproj/bt_get.c b/db.subproj/btree.subproj/bt_get.c deleted file mode 100644 index e62c7ac..0000000 --- a/db.subproj/btree.subproj/bt_get.c +++ /dev/null @@ -1,256 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Mike Olson. - * - * 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 - -#include -#include -#include - -#include -#include "btree.h" - -/* - * __BT_GET -- Get a record from the btree. - * - * Parameters: - * dbp: pointer to access method - * key: key to find - * data: data to return - * flag: currently unused - * - * Returns: - * RET_ERROR, RET_SUCCESS and RET_SPECIAL if the key not found. - */ -int -__bt_get(dbp, key, data, flags) - const DB *dbp; - const DBT *key; - DBT *data; - u_int flags; -{ - BTREE *t; - EPG *e; - int exact, status; - - t = dbp->internal; - - /* Toss any page pinned across calls. */ - if (t->bt_pinned != NULL) { - mpool_put(t->bt_mp, t->bt_pinned, 0); - t->bt_pinned = NULL; - } - - /* Get currently doesn't take any flags. */ - if (flags) { - errno = EINVAL; - return (RET_ERROR); - } - - if ((e = __bt_search(t, key, &exact)) == NULL) - return (RET_ERROR); - if (!exact) { - mpool_put(t->bt_mp, e->page, 0); - return (RET_SPECIAL); - } - - /* - * A special case is if we found the record but it's flagged for - * deletion. In this case, we want to find another record with the - * same key, if it exists. Rather than look around the tree we call - * __bt_first and have it redo the search, as __bt_first will not - * return keys marked for deletion. Slow, but should never happen. - */ - if (ISSET(t, B_DELCRSR) && e->page->pgno == t->bt_bcursor.pgno && - e->index == t->bt_bcursor.index) { - mpool_put(t->bt_mp, e->page, 0); - if ((e = __bt_first(t, key, &exact)) == NULL) - return (RET_ERROR); - if (!exact) - return (RET_SPECIAL); - } - - status = __bt_ret(t, e, NULL, data); - /* - * If the user is doing concurrent access, we copied the - * key/data, toss the page. - */ - if (ISSET(t, B_DB_LOCK)) - mpool_put(t->bt_mp, e->page, 0); - else - t->bt_pinned = e->page; - return (status); -} - -/* - * __BT_FIRST -- Find the first entry. - * - * Parameters: - * t: the tree - * key: the key - * - * Returns: - * The first entry in the tree greater than or equal to key. - */ -EPG * -__bt_first(t, key, exactp) - BTREE *t; - const DBT *key; - int *exactp; -{ - register PAGE *h; - register EPG *e; - EPG save; - pgno_t cpgno, pg; - indx_t cindex; - int found; - - /* - * Find any matching record; __bt_search pins the page. Only exact - * matches are tricky, otherwise just return the location of the key - * if it were to be inserted into the tree. - */ - if ((e = __bt_search(t, key, exactp)) == NULL) - return (NULL); - if (!*exactp) - return (e); - - if (ISSET(t, B_DELCRSR)) { - cpgno = t->bt_bcursor.pgno; - cindex = t->bt_bcursor.index; - } else { - cpgno = P_INVALID; - cindex = 0; /* GCC thinks it's uninitialized. */ - } - - /* - * Walk backwards, skipping empty pages, as long as the entry matches - * and there are keys left in the tree. Save a copy of each match in - * case we go too far. A special case is that we don't return a match - * on records that the cursor references that have already been flagged - * for deletion. - */ - save = *e; - h = e->page; - found = 0; - do { - if (cpgno != h->pgno || cindex != e->index) { - if (save.page->pgno != e->page->pgno) { - mpool_put(t->bt_mp, save.page, 0); - save = *e; - } else - save.index = e->index; - found = 1; - } - /* - * Make a special effort not to unpin the page the last (or - * original) match was on, but also make sure it's unpinned - * if an error occurs. - */ - while (e->index == 0) { - if (h->prevpg == P_INVALID) - goto done1; - if (h->pgno != save.page->pgno) - mpool_put(t->bt_mp, h, 0); - if ((h = mpool_get(t->bt_mp, h->prevpg, 0)) == NULL) { - if (h->pgno == save.page->pgno) - mpool_put(t->bt_mp, save.page, 0); - return (NULL); - } - e->page = h; - e->index = NEXTINDEX(h); - } - --e->index; - } while (__bt_cmp(t, key, e) == 0); - - /* - * Reach here with the last page that was looked at pinned, which may - * or may not be the same as the last (or original) match page. If - * it's not useful, release it. - */ -done1: if (h->pgno != save.page->pgno) - mpool_put(t->bt_mp, h, 0); - - /* - * If still haven't found a record, the only possibility left is the - * next one. Move forward one slot, skipping empty pages and check. - */ - if (!found) { - h = save.page; - if (++save.index == NEXTINDEX(h)) { - do { - pg = h->nextpg; - mpool_put(t->bt_mp, h, 0); - if (pg == P_INVALID) { - *exactp = 0; - return (e); - } - if ((h = mpool_get(t->bt_mp, pg, 0)) == NULL) - return (NULL); - } while ((save.index = NEXTINDEX(h)) == 0); - save.page = h; - } - if (__bt_cmp(t, key, &save) != 0) { - *exactp = 0; - return (e); - } - } - *e = save; - *exactp = 1; - return (e); -} diff --git a/db.subproj/btree.subproj/bt_open.c b/db.subproj/btree.subproj/bt_open.c deleted file mode 100644 index 0eb86d3..0000000 --- a/db.subproj/btree.subproj/bt_open.c +++ /dev/null @@ -1,458 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Mike Olson. - * - * 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. - */ - - -/* - * Implementation of btree access method for 4.4BSD. - * - * The design here was originally based on that of the btree access method - * used in the Postgres database system at UC Berkeley. This implementation - * is wholly independent of the Postgres code. - */ - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include "btree.h" - -static int byteorder __P((void)); -static int nroot __P((BTREE *)); -static int tmp __P((void)); - -/* - * __BT_OPEN -- Open a btree. - * - * Creates and fills a DB struct, and calls the routine that actually - * opens the btree. - * - * Parameters: - * fname: filename (NULL for in-memory trees) - * flags: open flag bits - * mode: open permission bits - * b: BTREEINFO pointer - * - * Returns: - * NULL on failure, pointer to DB on success. - * - */ -DB * -__bt_open(fname, flags, mode, openinfo, dflags) - const char *fname; - int flags, mode, dflags; - const BTREEINFO *openinfo; -{ - struct stat sb; - BTMETA m; - BTREE *t; - BTREEINFO b; - DB *dbp; - pgno_t ncache; - ssize_t nr; - int machine_lorder; - - t = NULL; - - /* - * Intention is to make sure all of the user's selections are okay - * here and then use them without checking. Can't be complete, since - * we don't know the right page size, lorder or flags until the backing - * file is opened. Also, the file's page size can cause the cachesize - * to change. - */ - machine_lorder = byteorder(); - if (openinfo) { - b = *openinfo; - - /* Flags: R_DUP. */ - if (b.flags & ~(R_DUP)) - goto einval; - - /* - * Page size must be indx_t aligned and >= MINPSIZE. Default - * page size is set farther on, based on the underlying file - * transfer size. - */ - if (b.psize && - (b.psize < MINPSIZE || b.psize > MAX_PAGE_OFFSET + 1 || - b.psize & sizeof(indx_t) - 1)) - goto einval; - - /* Minimum number of keys per page; absolute minimum is 2. */ - if (b.minkeypage) { - if (b.minkeypage < 2) - goto einval; - } else - b.minkeypage = DEFMINKEYPAGE; - - /* If no comparison, use default comparison and prefix. */ - if (b.compare == NULL) { - b.compare = __bt_defcmp; - if (b.prefix == NULL) - b.prefix = __bt_defpfx; - } - - if (b.lorder == 0) - b.lorder = machine_lorder; - } else { - b.compare = __bt_defcmp; - b.cachesize = 0; - b.flags = 0; - b.lorder = machine_lorder; - b.minkeypage = DEFMINKEYPAGE; - b.prefix = __bt_defpfx; - b.psize = 0; - } - - /* Check for the ubiquitous PDP-11. */ - if (b.lorder != BIG_ENDIAN && b.lorder != LITTLE_ENDIAN) - goto einval; - - /* Allocate and initialize DB and BTREE structures. */ - if ((t = (BTREE *)malloc(sizeof(BTREE))) == NULL) - goto err; - memset(t, 0, sizeof(BTREE)); - t->bt_bcursor.pgno = P_INVALID; - t->bt_fd = -1; /* Don't close unopened fd on error. */ - t->bt_lorder = b.lorder; - t->bt_order = NOT; - t->bt_cmp = b.compare; - t->bt_pfx = b.prefix; - t->bt_rfd = -1; - - if ((t->bt_dbp = dbp = (DB *)malloc(sizeof(DB))) == NULL) - goto err; - t->bt_flags = 0; - if (t->bt_lorder != machine_lorder) - SET(t, B_NEEDSWAP); - - dbp->type = DB_BTREE; - dbp->internal = t; - dbp->close = __bt_close; - dbp->del = __bt_delete; - dbp->fd = __bt_fd; - dbp->get = __bt_get; - dbp->put = __bt_put; - dbp->seq = __bt_seq; - dbp->sync = __bt_sync; - - /* - * If no file name was supplied, this is an in-memory btree and we - * open a backing temporary file. Otherwise, it's a disk-based tree. - */ - if (fname) { - switch(flags & O_ACCMODE) { - case O_RDONLY: - SET(t, B_RDONLY); - break; - case O_RDWR: - break; - case O_WRONLY: - default: - goto einval; - } - - if ((t->bt_fd = open(fname, flags, mode)) < 0) - goto err; - - } else { - if ((flags & O_ACCMODE) != O_RDWR) - goto einval; - if ((t->bt_fd = tmp()) == -1) - goto err; - SET(t, B_INMEM); - } - - if (fcntl(t->bt_fd, F_SETFD, 1) == -1) - goto err; - - if (fstat(t->bt_fd, &sb)) - goto err; - if (sb.st_size) { - nr = read(t->bt_fd, &m, sizeof(BTMETA)); - if (nr < 0) - goto err; - if (nr != sizeof(BTMETA)) - goto eftype; - - /* - * Read in the meta-data. This can change the notion of what - * the lorder, page size and flags are, and, when the page size - * changes, the cachesize value can change too. If the user - * specified the wrong byte order for an existing database, we - * don't bother to return an error, we just clear the NEEDSWAP - * bit. - */ - if (m.m_magic == BTREEMAGIC) - CLR(t, B_NEEDSWAP); - else { - SET(t, B_NEEDSWAP); - M_32_SWAP(m.m_magic); - M_32_SWAP(m.m_version); - M_32_SWAP(m.m_psize); - M_32_SWAP(m.m_free); - M_32_SWAP(m.m_nrecs); - M_32_SWAP(m.m_flags); - } - if (m.m_magic != BTREEMAGIC || m.m_version != BTREEVERSION) - goto eftype; - if (m.m_psize < MINPSIZE || m.m_psize > MAX_PAGE_OFFSET + 1 || - m.m_psize & sizeof(indx_t) - 1) - goto eftype; - if (m.m_flags & ~SAVEMETA) - goto eftype; - b.psize = m.m_psize; - t->bt_flags |= m.m_flags; - t->bt_free = m.m_free; - t->bt_nrecs = m.m_nrecs; - } else { - /* - * Set the page size to the best value for I/O to this file. - * Don't overflow the page offset type. - */ - if (b.psize == 0) { - b.psize = sb.st_blksize; - if (b.psize < MINPSIZE) - b.psize = MINPSIZE; - if (b.psize > MAX_PAGE_OFFSET + 1) - b.psize = MAX_PAGE_OFFSET + 1; - } - - /* Set flag if duplicates permitted. */ - if (!(b.flags & R_DUP)) - SET(t, B_NODUPS); - - t->bt_free = P_INVALID; - t->bt_nrecs = 0; - SET(t, B_METADIRTY); - } - - t->bt_psize = b.psize; - - /* Set the cache size; must be a multiple of the page size. */ - if (b.cachesize && b.cachesize & b.psize - 1) - b.cachesize += (~b.cachesize & b.psize - 1) + 1; - if (b.cachesize < b.psize * MINCACHE) - b.cachesize = b.psize * MINCACHE; - - /* Calculate number of pages to cache. */ - ncache = (b.cachesize + t->bt_psize - 1) / t->bt_psize; - - /* - * The btree data structure requires that at least two keys can fit on - * a page, but other than that there's no fixed requirement. The user - * specified a minimum number per page, and we translated that into the - * number of bytes a key/data pair can use before being placed on an - * overflow page. This calculation includes the page header, the size - * of the index referencing the leaf item and the size of the leaf item - * structure. Also, don't let the user specify a minkeypage such that - * a key/data pair won't fit even if both key and data are on overflow - * pages. - */ - t->bt_ovflsize = (t->bt_psize - BTDATAOFF) / b.minkeypage - - (sizeof(indx_t) + NBLEAFDBT(0, 0)); - if (t->bt_ovflsize < NBLEAFDBT(NOVFLSIZE, NOVFLSIZE) + sizeof(indx_t)) - t->bt_ovflsize = - NBLEAFDBT(NOVFLSIZE, NOVFLSIZE) + sizeof(indx_t); - - /* Initialize the buffer pool. */ - if ((t->bt_mp = - mpool_open(NULL, t->bt_fd, t->bt_psize, ncache)) == NULL) - goto err; - if (!ISSET(t, B_INMEM)) - mpool_filter(t->bt_mp, __bt_pgin, __bt_pgout, t); - - /* Create a root page if new tree. */ - if (nroot(t) == RET_ERROR) - goto err; - - /* Global flags. */ - if (dflags & DB_LOCK) - SET(t, B_DB_LOCK); - if (dflags & DB_SHMEM) - SET(t, B_DB_SHMEM); - if (dflags & DB_TXN) - SET(t, B_DB_TXN); - - return (dbp); - -einval: errno = EINVAL; - goto err; - -eftype: errno = EFTYPE; - goto err; - -err: if (t) { - if (t->bt_dbp) - free(t->bt_dbp); - if (t->bt_fd != -1) - (void)close(t->bt_fd); - free(t); - } - return (NULL); -} - -/* - * NROOT -- Create the root of a new tree. - * - * Parameters: - * t: tree - * - * Returns: - * RET_ERROR, RET_SUCCESS - */ -static int -nroot(t) - BTREE *t; -{ - PAGE *meta, *root; - pgno_t npg; - - if ((meta = mpool_get(t->bt_mp, 0, 0)) != NULL) { - mpool_put(t->bt_mp, meta, 0); - return (RET_SUCCESS); - } - if (errno != EINVAL) - return (RET_ERROR); - - if ((meta = mpool_new(t->bt_mp, &npg)) == NULL) - return (RET_ERROR); - - if ((root = mpool_new(t->bt_mp, &npg)) == NULL) - return (RET_ERROR); - - if (npg != P_ROOT) - return (RET_ERROR); - root->pgno = npg; - root->prevpg = root->nextpg = P_INVALID; - root->lower = BTDATAOFF; - root->upper = t->bt_psize; - root->flags = P_BLEAF; - memset(meta, 0, t->bt_psize); - mpool_put(t->bt_mp, meta, MPOOL_DIRTY); - mpool_put(t->bt_mp, root, MPOOL_DIRTY); - return (RET_SUCCESS); -} - -static int -tmp() -{ - sigset_t set, oset; - int fd; - char *envtmp; - char path[MAXPATHLEN]; - - envtmp = getenv("TMPDIR"); - (void)snprintf(path, - sizeof(path), "%s/bt.XXXXXX", envtmp ? envtmp : "/tmp"); - - (void)sigfillset(&set); - (void)sigprocmask(SIG_BLOCK, &set, &oset); - if ((fd = mkstemp(path)) != -1) - (void)unlink(path); - (void)sigprocmask(SIG_SETMASK, &oset, NULL); - return(fd); -} - -static int -byteorder() -{ - u_int32_t x; - u_char *p; - - x = 0x01020304; - p = (u_char *)&x; - switch (*p) { - case 1: - return (BIG_ENDIAN); - case 4: - return (LITTLE_ENDIAN); - default: - return (0); - } -} - -int -__bt_fd(dbp) - const DB *dbp; -{ - BTREE *t; - - t = dbp->internal; - - /* Toss any page pinned across calls. */ - if (t->bt_pinned != NULL) { - mpool_put(t->bt_mp, t->bt_pinned, 0); - t->bt_pinned = NULL; - } - - /* In-memory database can't have a file descriptor. */ - if (ISSET(t, B_INMEM)) { - errno = ENOENT; - return (-1); - } - return (t->bt_fd); -} diff --git a/db.subproj/btree.subproj/bt_overflow.c b/db.subproj/btree.subproj/bt_overflow.c deleted file mode 100644 index dc73942..0000000 --- a/db.subproj/btree.subproj/bt_overflow.c +++ /dev/null @@ -1,242 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Mike Olson. - * - * 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 - -#include -#include -#include - -#include -#include "btree.h" - -/* - * Big key/data code. - * - * Big key and data entries are stored on linked lists of pages. The initial - * reference is byte string stored with the key or data and is the page number - * and size. The actual record is stored in a chain of pages linked by the - * nextpg field of the PAGE header. - * - * The first page of the chain has a special property. If the record is used - * by an internal page, it cannot be deleted and the P_PRESERVE bit will be set - * in the header. - * - * XXX - * A single DBT is written to each chain, so a lot of space on the last page - * is wasted. This is a fairly major bug for some data sets. - */ - -/* - * __OVFL_GET -- Get an overflow key/data item. - * - * Parameters: - * t: tree - * p: pointer to { pgno_t, size_t } - * buf: storage address - * bufsz: storage size - * - * Returns: - * RET_ERROR, RET_SUCCESS - */ -int -__ovfl_get(t, p, ssz, buf, bufsz) - BTREE *t; - void *p; - size_t *ssz; - char **buf; - size_t *bufsz; -{ - PAGE *h; - pgno_t pg; - size_t nb, plen, sz; - - memmove(&pg, p, sizeof(pgno_t)); - memmove(&sz, (char *)p + sizeof(pgno_t), sizeof(size_t)); - *ssz = sz; - -#ifdef DEBUG - if (pg == P_INVALID || sz == 0) - abort(); -#endif - /* Make the buffer bigger as necessary. */ - if (*bufsz < sz) { - if ((*buf = (char *)realloc(*buf, sz)) == NULL) - return (RET_ERROR); - *bufsz = sz; - } - - /* - * Step through the linked list of pages, copying the data on each one - * into the buffer. Never copy more than the data's length. - */ - plen = t->bt_psize - BTDATAOFF; - for (p = *buf;; p = (char *)p + nb, pg = h->nextpg) { - if ((h = mpool_get(t->bt_mp, pg, 0)) == NULL) - return (RET_ERROR); - - nb = MIN(sz, plen); - memmove(p, (char *)h + BTDATAOFF, nb); - mpool_put(t->bt_mp, h, 0); - - if ((sz -= nb) == 0) - break; - } - return (RET_SUCCESS); -} - -/* - * __OVFL_PUT -- Store an overflow key/data item. - * - * Parameters: - * t: tree - * data: DBT to store - * pgno: storage page number - * - * Returns: - * RET_ERROR, RET_SUCCESS - */ -int -__ovfl_put(t, dbt, pg) - BTREE *t; - const DBT *dbt; - pgno_t *pg; -{ - PAGE *h, *last; - void *p; - pgno_t npg; - size_t nb, plen, sz; - - /* - * Allocate pages and copy the key/data record into them. Store the - * number of the first page in the chain. - */ - plen = t->bt_psize - BTDATAOFF; - for (last = NULL, p = dbt->data, sz = dbt->size;; - p = (char *)p + plen, last = h) { - if ((h = __bt_new(t, &npg)) == NULL) - return (RET_ERROR); - - h->pgno = npg; - h->nextpg = h->prevpg = P_INVALID; - h->flags = P_OVERFLOW; - h->lower = h->upper = 0; - - nb = MIN(sz, plen); - memmove((char *)h + BTDATAOFF, p, nb); - - if (last) { - last->nextpg = h->pgno; - mpool_put(t->bt_mp, last, MPOOL_DIRTY); - } else - *pg = h->pgno; - - if ((sz -= nb) == 0) { - mpool_put(t->bt_mp, h, MPOOL_DIRTY); - break; - } - } - return (RET_SUCCESS); -} - -/* - * __OVFL_DELETE -- Delete an overflow chain. - * - * Parameters: - * t: tree - * p: pointer to { pgno_t, size_t } - * - * Returns: - * RET_ERROR, RET_SUCCESS - */ -int -__ovfl_delete(t, p) - BTREE *t; - void *p; -{ - PAGE *h; - pgno_t pg; - size_t plen, sz; - - memmove(&pg, p, sizeof(pgno_t)); - memmove(&sz, (char *)p + sizeof(pgno_t), sizeof(size_t)); - -#ifdef DEBUG - if (pg == P_INVALID || sz == 0) - abort(); -#endif - if ((h = mpool_get(t->bt_mp, pg, 0)) == NULL) - return (RET_ERROR); - - /* Don't delete chains used by internal pages. */ - if (h->flags & P_PRESERVE) { - mpool_put(t->bt_mp, h, 0); - return (RET_SUCCESS); - } - - /* Step through the chain, calling the free routine for each page. */ - for (plen = t->bt_psize - BTDATAOFF;; sz -= plen) { - pg = h->nextpg; - __bt_free(t, h); - if (sz <= plen) - break; - if ((h = mpool_get(t->bt_mp, pg, 0)) == NULL) - return (RET_ERROR); - } - return (RET_SUCCESS); -} diff --git a/db.subproj/btree.subproj/bt_page.c b/db.subproj/btree.subproj/bt_page.c deleted file mode 100644 index c9c1b44..0000000 --- a/db.subproj/btree.subproj/bt_page.c +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 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 - -#include - -#include -#include "btree.h" - -/* - * __BT_FREE -- Put a page on the freelist. - * - * Parameters: - * t: tree - * h: page to free - * - * Returns: - * RET_ERROR, RET_SUCCESS - */ -int -__bt_free(t, h) - BTREE *t; - PAGE *h; -{ - /* Insert the page at the start of the free list. */ - h->prevpg = P_INVALID; - h->nextpg = t->bt_free; - t->bt_free = h->pgno; - - /* Make sure the page gets written back. */ - return (mpool_put(t->bt_mp, h, MPOOL_DIRTY)); -} - -/* - * __BT_NEW -- Get a new page, preferably from the freelist. - * - * Parameters: - * t: tree - * npg: storage for page number. - * - * Returns: - * Pointer to a page, NULL on error. - */ -PAGE * -__bt_new(t, npg) - BTREE *t; - pgno_t *npg; -{ - PAGE *h; - - if (t->bt_free != P_INVALID && - (h = mpool_get(t->bt_mp, t->bt_free, 0)) != NULL) { - *npg = t->bt_free; - t->bt_free = h->nextpg; - return (h); - } - return (mpool_new(t->bt_mp, npg)); -} diff --git a/db.subproj/btree.subproj/bt_put.c b/db.subproj/btree.subproj/bt_put.c deleted file mode 100644 index 403d16b..0000000 --- a/db.subproj/btree.subproj/bt_put.c +++ /dev/null @@ -1,336 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Mike Olson. - * - * 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 - -#include -#include -#include -#include - -#include -#include "btree.h" - -static EPG *bt_fast __P((BTREE *, const DBT *, const DBT *, int *)); - -/* - * __BT_PUT -- Add a btree item to the tree. - * - * Parameters: - * dbp: pointer to access method - * key: key - * data: data - * flag: R_NOOVERWRITE - * - * Returns: - * RET_ERROR, RET_SUCCESS and RET_SPECIAL if the key is already in the - * tree and R_NOOVERWRITE specified. - */ -int -__bt_put(dbp, key, data, flags) - const DB *dbp; - DBT *key; - const DBT *data; - u_int flags; -{ - BTREE *t; - DBT tkey, tdata; - EPG *e; - PAGE *h; - indx_t index, nxtindex; - pgno_t pg; - size_t nbytes; - int dflags, exact, status; - char *dest, db[NOVFLSIZE], kb[NOVFLSIZE]; - - t = dbp->internal; - - /* Toss any page pinned across calls. */ - if (t->bt_pinned != NULL) { - mpool_put(t->bt_mp, t->bt_pinned, 0); - t->bt_pinned = NULL; - } - - switch (flags) { - case R_CURSOR: - if (!ISSET(t, B_SEQINIT)) - goto einval; - if (ISSET(t, B_DELCRSR)) - goto einval; - break; - case 0: - case R_NOOVERWRITE: - break; - default: -einval: errno = EINVAL; - return (RET_ERROR); - } - - if (ISSET(t, B_RDONLY)) { - errno = EPERM; - return (RET_ERROR); - } - - /* - * If the key/data won't fit on a page, store it on indirect pages. - * Only store the key on the overflow page if it's too big after the - * data is on an overflow page. - * - * XXX - * If the insert fails later on, these pages aren't recovered. - */ - dflags = 0; - if (key->size + data->size > t->bt_ovflsize) { - if (key->size > t->bt_ovflsize) { -storekey: if (__ovfl_put(t, key, &pg) == RET_ERROR) - return (RET_ERROR); - tkey.data = kb; - tkey.size = NOVFLSIZE; - memmove(kb, &pg, sizeof(pgno_t)); - memmove(kb + sizeof(pgno_t), - &key->size, sizeof(size_t)); - dflags |= P_BIGKEY; - key = &tkey; - } - if (key->size + data->size > t->bt_ovflsize) { - if (__ovfl_put(t, data, &pg) == RET_ERROR) - return (RET_ERROR); - tdata.data = db; - tdata.size = NOVFLSIZE; - memmove(db, &pg, sizeof(pgno_t)); - memmove(db + sizeof(pgno_t), - &data->size, sizeof(size_t)); - dflags |= P_BIGDATA; - data = &tdata; - } - if (key->size + data->size > t->bt_ovflsize) - goto storekey; - } - - /* Replace the cursor. */ - if (flags == R_CURSOR) { - if ((h = mpool_get(t->bt_mp, t->bt_bcursor.pgno, 0)) == NULL) - return (RET_ERROR); - index = t->bt_bcursor.index; - goto delete; - } - - /* - * Find the key to delete, or, the location at which to insert. Bt_fast - * and __bt_search pin the returned page. - */ - if (t->bt_order == NOT || (e = bt_fast(t, key, data, &exact)) == NULL) - if ((e = __bt_search(t, key, &exact)) == NULL) - return (RET_ERROR); - h = e->page; - index = e->index; - - /* - * Add the specified key/data pair to the tree. If an identical key - * is already in the tree, and R_NOOVERWRITE is set, an error is - * returned. If R_NOOVERWRITE is not set, the key is either added (if - * duplicates are permitted) or an error is returned. - * - * Pages are split as required. - */ - switch (flags) { - case R_NOOVERWRITE: - if (!exact) - break; - /* - * One special case is if the cursor references the record and - * it's been flagged for deletion. Then, we delete the record, - * leaving the cursor there -- this means that the inserted - * record will not be seen in a cursor scan. - */ - if (ISSET(t, B_DELCRSR) && t->bt_bcursor.pgno == h->pgno && - t->bt_bcursor.index == index) { - CLR(t, B_DELCRSR); - goto delete; - } - mpool_put(t->bt_mp, h, 0); - return (RET_SPECIAL); - default: - if (!exact || !ISSET(t, B_NODUPS)) - break; -delete: if (__bt_dleaf(t, h, index) == RET_ERROR) { - mpool_put(t->bt_mp, h, 0); - return (RET_ERROR); - } - break; - } - - /* - * If not enough room, or the user has put a ceiling on the number of - * keys permitted in the page, split the page. The split code will - * insert the key and data and unpin the current page. If inserting - * into the offset array, shift the pointers up. - */ - nbytes = NBLEAFDBT(key->size, data->size); - if (h->upper - h->lower < nbytes + sizeof(indx_t)) { - if ((status = __bt_split(t, h, key, - data, dflags, nbytes, index)) != RET_SUCCESS) - return (status); - goto success; - } - - if (index < (nxtindex = NEXTINDEX(h))) - memmove(h->linp + index + 1, h->linp + index, - (nxtindex - index) * sizeof(indx_t)); - h->lower += sizeof(indx_t); - - h->linp[index] = h->upper -= nbytes; - dest = (char *)h + h->upper; - WR_BLEAF(dest, key, data, dflags); - - if (t->bt_order == NOT) - if (h->nextpg == P_INVALID) { - if (index == NEXTINDEX(h) - 1) { - t->bt_order = FORWARD; - t->bt_last.index = index; - t->bt_last.pgno = h->pgno; - } - } else if (h->prevpg == P_INVALID) { - if (index == 0) { - t->bt_order = BACK; - t->bt_last.index = 0; - t->bt_last.pgno = h->pgno; - } - } - - mpool_put(t->bt_mp, h, MPOOL_DIRTY); - -success: - if (flags == R_SETCURSOR) { - t->bt_bcursor.pgno = e->page->pgno; - t->bt_bcursor.index = e->index; - } - SET(t, B_MODIFIED); - return (RET_SUCCESS); -} - -#ifdef STATISTICS -u_long bt_cache_hit, bt_cache_miss; -#endif - -/* - * BT_FAST -- Do a quick check for sorted data. - * - * Parameters: - * t: tree - * key: key to insert - * - * Returns: - * EPG for new record or NULL if not found. - */ -static EPG * -bt_fast(t, key, data, exactp) - BTREE *t; - const DBT *key, *data; - int *exactp; -{ - PAGE *h; - size_t nbytes; - int cmp; - - if ((h = mpool_get(t->bt_mp, t->bt_last.pgno, 0)) == NULL) { - t->bt_order = NOT; - return (NULL); - } - t->bt_cur.page = h; - t->bt_cur.index = t->bt_last.index; - - /* - * If won't fit in this page or have too many keys in this page, have - * to search to get split stack. - */ - nbytes = NBLEAFDBT(key->size, data->size); - if (h->upper - h->lower < nbytes + sizeof(indx_t)) - goto miss; - - if (t->bt_order == FORWARD) { - if (t->bt_cur.page->nextpg != P_INVALID) - goto miss; - if (t->bt_cur.index != NEXTINDEX(h) - 1) - goto miss; - if ((cmp = __bt_cmp(t, key, &t->bt_cur)) < 0) - goto miss; - t->bt_last.index = cmp ? ++t->bt_cur.index : t->bt_cur.index; - } else { - if (t->bt_cur.page->prevpg != P_INVALID) - goto miss; - if (t->bt_cur.index != 0) - goto miss; - if ((cmp = __bt_cmp(t, key, &t->bt_cur)) > 0) - goto miss; - t->bt_last.index = 0; - } - *exactp = cmp == 0; -#ifdef STATISTICS - ++bt_cache_hit; -#endif - return (&t->bt_cur); - -miss: -#ifdef STATISTICS - ++bt_cache_miss; -#endif - t->bt_order = NOT; - mpool_put(t->bt_mp, h, 0); - return (NULL); -} diff --git a/db.subproj/btree.subproj/bt_search.c b/db.subproj/btree.subproj/bt_search.c deleted file mode 100644 index aa1151a..0000000 --- a/db.subproj/btree.subproj/bt_search.c +++ /dev/null @@ -1,253 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Mike Olson. - * - * 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 - -#include - -#include -#include "btree.h" - -static int bt_snext __P((BTREE *, PAGE *, const DBT *, int *)); -static int bt_sprev __P((BTREE *, PAGE *, const DBT *, int *)); - -/* - * __BT_SEARCH -- Search a btree for a key. - * - * Parameters: - * t: tree to search - * key: key to find - * exactp: pointer to exact match flag - * - * Returns: - * The EPG for matching record, if any, or the EPG for the location - * of the key, if it were inserted into the tree, is entered into - * the bt_cur field of the tree. A pointer to the field is returned. - */ -EPG * -__bt_search(t, key, exactp) - BTREE *t; - const DBT *key; - int *exactp; -{ - PAGE *h; - indx_t base, index, lim; - pgno_t pg; - int cmp; - - BT_CLR(t); - for (pg = P_ROOT;;) { - if ((h = mpool_get(t->bt_mp, pg, 0)) == NULL) - return (NULL); - - /* Do a binary search on the current page. */ - t->bt_cur.page = h; - for (base = 0, lim = NEXTINDEX(h); lim; lim >>= 1) { - t->bt_cur.index = index = base + (lim >> 1); - if ((cmp = __bt_cmp(t, key, &t->bt_cur)) == 0) { - if (h->flags & P_BLEAF) { - *exactp = 1; - return (&t->bt_cur); - } - goto next; - } - if (cmp > 0) { - base = index + 1; - --lim; - } - } - - /* - * If it's a leaf page, and duplicates aren't allowed, we're - * done. If duplicates are allowed, it's possible that there - * were duplicate keys on duplicate pages, and they were later - * deleted, so we could be on a page with no matches while - * there are matches on other pages. If we're at the start or - * end of a page, check on both sides. - */ - if (h->flags & P_BLEAF) { - t->bt_cur.index = base; - *exactp = 0; - if (!ISSET(t, B_NODUPS)) { - if (base == 0 && - bt_sprev(t, h, key, exactp)) - return (&t->bt_cur); - if (base == NEXTINDEX(h) && - bt_snext(t, h, key, exactp)) - return (&t->bt_cur); - } - return (&t->bt_cur); - } - - /* - * No match found. Base is the smallest index greater than - * key and may be zero or a last + 1 index. If it's non-zero, - * decrement by one, and record the internal page which should - * be a parent page for the key. If a split later occurs, the - * inserted page will be to the right of the saved page. - */ - index = base ? base - 1 : base; - -next: if (__bt_push(t, h->pgno, index) == RET_ERROR) - return (NULL); - pg = GETBINTERNAL(h, index)->pgno; - mpool_put(t->bt_mp, h, 0); - } -} - -/* - * BT_SNEXT -- Check for an exact match after the key. - * - * Parameters: - * t: tree to search - * h: current page. - * key: key to find - * exactp: pointer to exact match flag - * - * Returns: - * If an exact match found. - */ -static int -bt_snext(t, h, key, exactp) - BTREE *t; - PAGE *h; - const DBT *key; - int *exactp; -{ - EPG e; - PAGE *tp; - pgno_t pg; - - /* Skip until reach the end of the tree or a key. */ - for (pg = h->nextpg; pg != P_INVALID;) { - if ((tp = mpool_get(t->bt_mp, pg, 0)) == NULL) { - mpool_put(t->bt_mp, h, 0); - return (NULL); - } - if (NEXTINDEX(tp) != 0) - break; - pg = tp->prevpg; - mpool_put(t->bt_mp, tp, 0); - } - /* - * The key is either an exact match, or not as good as - * the one we already have. - */ - if (pg != P_INVALID) { - e.page = tp; - e.index = NEXTINDEX(tp) - 1; - if (__bt_cmp(t, key, &e) == 0) { - mpool_put(t->bt_mp, h, 0); - t->bt_cur = e; - *exactp = 1; - return (1); - } - } - return (0); -} - -/* - * BT_SPREV -- Check for an exact match before the key. - * - * Parameters: - * t: tree to search - * h: current page. - * key: key to find - * exactp: pointer to exact match flag - * - * Returns: - * If an exact match found. - */ -static int -bt_sprev(t, h, key, exactp) - BTREE *t; - PAGE *h; - const DBT *key; - int *exactp; -{ - EPG e; - PAGE *tp; - pgno_t pg; - - /* Skip until reach the beginning of the tree or a key. */ - for (pg = h->prevpg; pg != P_INVALID;) { - if ((tp = mpool_get(t->bt_mp, pg, 0)) == NULL) { - mpool_put(t->bt_mp, h, 0); - return (NULL); - } - if (NEXTINDEX(tp) != 0) - break; - pg = tp->prevpg; - mpool_put(t->bt_mp, tp, 0); - } - /* - * The key is either an exact match, or not as good as - * the one we already have. - */ - if (pg != P_INVALID) { - e.page = tp; - e.index = NEXTINDEX(tp) - 1; - if (__bt_cmp(t, key, &e) == 0) { - mpool_put(t->bt_mp, h, 0); - t->bt_cur = e; - *exactp = 1; - return (1); - } - } - return (0); -} diff --git a/db.subproj/btree.subproj/bt_seq.c b/db.subproj/btree.subproj/bt_seq.c deleted file mode 100644 index fcbfd2c..0000000 --- a/db.subproj/btree.subproj/bt_seq.c +++ /dev/null @@ -1,398 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Mike Olson. - * - * 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 - -#include -#include -#include -#include - -#include -#include "btree.h" - -static int bt_seqadv __P((BTREE *, EPG *, int)); -static int bt_seqset __P((BTREE *, EPG *, DBT *, int)); - -/* - * Sequential scan support. - * - * The tree can be scanned sequentially, starting from either end of the tree - * or from any specific key. A scan request before any scanning is done is - * initialized as starting from the least node. - * - * Each tree has an EPGNO which has the current position of the cursor. The - * cursor has to survive deletions/insertions in the tree without losing its - * position. This is done by noting deletions without doing them, and then - * doing them when the cursor moves (or the tree is closed). - */ - -/* - * __BT_SEQ -- Btree sequential scan interface. - * - * Parameters: - * dbp: pointer to access method - * key: key for positioning and return value - * data: data return value - * flags: R_CURSOR, R_FIRST, R_LAST, R_NEXT, R_PREV. - * - * Returns: - * RET_ERROR, RET_SUCCESS or RET_SPECIAL if there's no next key. - */ -int -__bt_seq(dbp, key, data, flags) - const DB *dbp; - DBT *key, *data; - u_int flags; -{ - BTREE *t; - EPG e; - int status; - - t = dbp->internal; - - /* Toss any page pinned across calls. */ - if (t->bt_pinned != NULL) { - mpool_put(t->bt_mp, t->bt_pinned, 0); - t->bt_pinned = NULL; - } - - /* - * If scan unitialized as yet, or starting at a specific record, set - * the scan to a specific key. Both bt_seqset and bt_seqadv pin the - * page the cursor references if they're successful. - */ - switch(flags) { - case R_NEXT: - case R_PREV: - if (ISSET(t, B_SEQINIT)) { - status = bt_seqadv(t, &e, flags); - break; - } - /* FALLTHROUGH */ - case R_CURSOR: - case R_FIRST: - case R_LAST: - status = bt_seqset(t, &e, key, flags); - break; - default: - errno = EINVAL; - return (RET_ERROR); - } - - if (status == RET_SUCCESS) { - status = __bt_ret(t, &e, key, data); - - /* Update the actual cursor. */ - t->bt_bcursor.pgno = e.page->pgno; - t->bt_bcursor.index = e.index; - - /* - * If the user is doing concurrent access, we copied the - * key/data, toss the page. - */ - if (ISSET(t, B_DB_LOCK)) - mpool_put(t->bt_mp, e.page, 0); - else - t->bt_pinned = e.page; - SET(t, B_SEQINIT); - } - return (status); -} - -/* - * BT_SEQSET -- Set the sequential scan to a specific key. - * - * Parameters: - * t: tree - * ep: storage for returned key - * key: key for initial scan position - * flags: R_CURSOR, R_FIRST, R_LAST, R_NEXT, R_PREV - * - * Side effects: - * Pins the page the cursor references. - * - * Returns: - * RET_ERROR, RET_SUCCESS or RET_SPECIAL if there's no next key. - */ -static int -bt_seqset(t, ep, key, flags) - BTREE *t; - EPG *ep; - DBT *key; - int flags; -{ - EPG *e; - PAGE *h; - pgno_t pg; - int exact; - - /* - * Delete any already deleted record that we've been saving because - * the cursor pointed to it. Since going to a specific key, should - * delete any logically deleted records so they aren't found. - */ - if (ISSET(t, B_DELCRSR) && __bt_crsrdel(t, &t->bt_bcursor)) - return (RET_ERROR); - - /* - * Find the first, last or specific key in the tree and point the cursor - * at it. The cursor may not be moved until a new key has been found. - */ - switch(flags) { - case R_CURSOR: /* Keyed scan. */ - /* - * Find the first instance of the key or the smallest key which - * is greater than or equal to the specified key. If run out - * of keys, return RET_SPECIAL. - */ - if (key->data == NULL || key->size == 0) { - errno = EINVAL; - return (RET_ERROR); - } - e = __bt_first(t, key, &exact); /* Returns pinned page. */ - if (e == NULL) - return (RET_ERROR); - /* - * If at the end of a page, skip any empty pages and find the - * next entry. - */ - if (e->index == NEXTINDEX(e->page)) { - h = e->page; - do { - pg = h->nextpg; - mpool_put(t->bt_mp, h, 0); - if (pg == P_INVALID) - return (RET_SPECIAL); - if ((h = mpool_get(t->bt_mp, pg, 0)) == NULL) - return (RET_ERROR); - } while (NEXTINDEX(h) == 0); - e->index = 0; - e->page = h; - } - *ep = *e; - break; - case R_FIRST: /* First record. */ - case R_NEXT: - /* Walk down the left-hand side of the tree. */ - for (pg = P_ROOT;;) { - if ((h = mpool_get(t->bt_mp, pg, 0)) == NULL) - return (RET_ERROR); - if (h->flags & (P_BLEAF | P_RLEAF)) - break; - pg = GETBINTERNAL(h, 0)->pgno; - mpool_put(t->bt_mp, h, 0); - } - - /* Skip any empty pages. */ - while (NEXTINDEX(h) == 0 && h->nextpg != P_INVALID) { - pg = h->nextpg; - mpool_put(t->bt_mp, h, 0); - if ((h = mpool_get(t->bt_mp, pg, 0)) == NULL) - return (RET_ERROR); - } - - if (NEXTINDEX(h) == 0) { - mpool_put(t->bt_mp, h, 0); - return (RET_SPECIAL); - } - - ep->page = h; - ep->index = 0; - break; - case R_LAST: /* Last record. */ - case R_PREV: - /* Walk down the right-hand side of the tree. */ - for (pg = P_ROOT;;) { - if ((h = mpool_get(t->bt_mp, pg, 0)) == NULL) - return (RET_ERROR); - if (h->flags & (P_BLEAF | P_RLEAF)) - break; - pg = GETBINTERNAL(h, NEXTINDEX(h) - 1)->pgno; - mpool_put(t->bt_mp, h, 0); - } - - /* Skip any empty pages. */ - while (NEXTINDEX(h) == 0 && h->prevpg != P_INVALID) { - pg = h->prevpg; - mpool_put(t->bt_mp, h, 0); - if ((h = mpool_get(t->bt_mp, pg, 0)) == NULL) - return (RET_ERROR); - } - - if (NEXTINDEX(h) == 0) { - mpool_put(t->bt_mp, h, 0); - return (RET_SPECIAL); - } - - ep->page = h; - ep->index = NEXTINDEX(h) - 1; - break; - } - return (RET_SUCCESS); -} - -/* - * BT_SEQADVANCE -- Advance the sequential scan. - * - * Parameters: - * t: tree - * flags: R_NEXT, R_PREV - * - * Side effects: - * Pins the page the new key/data record is on. - * - * Returns: - * RET_ERROR, RET_SUCCESS or RET_SPECIAL if there's no next key. - */ -static int -bt_seqadv(t, e, flags) - BTREE *t; - EPG *e; - int flags; -{ - EPGNO *c, delc; - PAGE *h; - indx_t index; - pgno_t pg; - - /* Save the current cursor if going to delete it. */ - c = &t->bt_bcursor; - if (ISSET(t, B_DELCRSR)) - delc = *c; - - if ((h = mpool_get(t->bt_mp, c->pgno, 0)) == NULL) - return (RET_ERROR); - - /* - * Find the next/previous record in the tree and point the cursor at it. - * The cursor may not be moved until a new key has been found. - */ - index = c->index; - switch(flags) { - case R_NEXT: /* Next record. */ - if (++index == NEXTINDEX(h)) { - do { - pg = h->nextpg; - mpool_put(t->bt_mp, h, 0); - if (pg == P_INVALID) - return (RET_SPECIAL); - if ((h = mpool_get(t->bt_mp, pg, 0)) == NULL) - return (RET_ERROR); - } while (NEXTINDEX(h) == 0); - index = 0; - } - break; - case R_PREV: /* Previous record. */ - if (index-- == 0) { - do { - pg = h->prevpg; - mpool_put(t->bt_mp, h, 0); - if (pg == P_INVALID) - return (RET_SPECIAL); - if ((h = mpool_get(t->bt_mp, pg, 0)) == NULL) - return (RET_ERROR); - } while (NEXTINDEX(h) == 0); - index = NEXTINDEX(h) - 1; - } - break; - } - - e->page = h; - e->index = index; - - /* - * Delete any already deleted record that we've been saving because the - * cursor pointed to it. This could cause the new index to be shifted - * down by one if the record we're deleting is on the same page and has - * a larger index. - */ - if (ISSET(t, B_DELCRSR)) { - CLR(t, B_DELCRSR); /* Don't try twice. */ - if (c->pgno == delc.pgno && c->index > delc.index) - --c->index; - if (__bt_crsrdel(t, &delc)) - return (RET_ERROR); - } - return (RET_SUCCESS); -} - -/* - * __BT_CRSRDEL -- Delete the record referenced by the cursor. - * - * Parameters: - * t: tree - * - * Returns: - * RET_ERROR, RET_SUCCESS - */ -int -__bt_crsrdel(t, c) - BTREE *t; - EPGNO *c; -{ - PAGE *h; - int status; - - CLR(t, B_DELCRSR); /* Don't try twice. */ - if ((h = mpool_get(t->bt_mp, c->pgno, 0)) == NULL) - return (RET_ERROR); - status = __bt_dleaf(t, h, c->index); - mpool_put(t->bt_mp, h, MPOOL_DIRTY); - return (status); -} diff --git a/db.subproj/btree.subproj/bt_split.c b/db.subproj/btree.subproj/bt_split.c deleted file mode 100644 index d11c37f..0000000 --- a/db.subproj/btree.subproj/bt_split.c +++ /dev/null @@ -1,843 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Mike Olson. - * - * 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 - -#include -#include -#include -#include - -#include -#include "btree.h" - -static int bt_broot __P((BTREE *, PAGE *, PAGE *, PAGE *)); -static PAGE *bt_page - __P((BTREE *, PAGE *, PAGE **, PAGE **, indx_t *, size_t)); -static int bt_preserve __P((BTREE *, pgno_t)); -static PAGE *bt_psplit - __P((BTREE *, PAGE *, PAGE *, PAGE *, indx_t *, size_t)); -static PAGE *bt_root - __P((BTREE *, PAGE *, PAGE **, PAGE **, indx_t *, size_t)); -static int bt_rroot __P((BTREE *, PAGE *, PAGE *, PAGE *)); -static recno_t rec_total __P((PAGE *)); - -#ifdef STATISTICS -u_long bt_rootsplit, bt_split, bt_sortsplit, bt_pfxsaved; -#endif - -/* - * __BT_SPLIT -- Split the tree. - * - * Parameters: - * t: tree - * sp: page to split - * key: key to insert - * data: data to insert - * flags: BIGKEY/BIGDATA flags - * ilen: insert length - * skip: index to leave open - * - * Returns: - * RET_ERROR, RET_SUCCESS - */ -int -__bt_split(t, sp, key, data, flags, ilen, skip) - BTREE *t; - PAGE *sp; - const DBT *key, *data; - int flags; - size_t ilen; - indx_t skip; -{ - BINTERNAL *bi; - BLEAF *bl, *tbl; - DBT a, b; - EPGNO *parent; - PAGE *h, *l, *r, *lchild, *rchild; - indx_t nxtindex; - size_t n, nbytes, nksize; - int parentsplit; - char *dest; - - /* - * Split the page into two pages, l and r. The split routines return - * a pointer to the page into which the key should be inserted and with - * skip set to the offset which should be used. Additionally, l and r - * are pinned. - */ - h = sp->pgno == P_ROOT ? - bt_root(t, sp, &l, &r, &skip, ilen) : - bt_page(t, sp, &l, &r, &skip, ilen); - if (h == NULL) - return (RET_ERROR); - - /* - * Insert the new key/data pair into the leaf page. (Key inserts - * always cause a leaf page to split first.) - */ - h->linp[skip] = h->upper -= ilen; - dest = (char *)h + h->upper; - if (ISSET(t, R_RECNO)) - WR_RLEAF(dest, data, flags) - else - WR_BLEAF(dest, key, data, flags) - - /* If the root page was split, make it look right. */ - if (sp->pgno == P_ROOT && - (ISSET(t, R_RECNO) ? - bt_rroot(t, sp, l, r) : bt_broot(t, sp, l, r)) == RET_ERROR) - goto err2; - - /* - * Now we walk the parent page stack -- a LIFO stack of the pages that - * were traversed when we searched for the page that split. Each stack - * entry is a page number and a page index offset. The offset is for - * the page traversed on the search. We've just split a page, so we - * have to insert a new key into the parent page. - * - * If the insert into the parent page causes it to split, may have to - * continue splitting all the way up the tree. We stop if the root - * splits or the page inserted into didn't have to split to hold the - * new key. Some algorithms replace the key for the old page as well - * as the new page. We don't, as there's no reason to believe that the - * first key on the old page is any better than the key we have, and, - * in the case of a key being placed at index 0 causing the split, the - * key is unavailable. - * - * There are a maximum of 5 pages pinned at any time. We keep the left - * and right pages pinned while working on the parent. The 5 are the - * two children, left parent and right parent (when the parent splits) - * and the root page or the overflow key page when calling bt_preserve. - * This code must make sure that all pins are released other than the - * root page or overflow page which is unlocked elsewhere. - */ - while ((parent = BT_POP(t)) != NULL) { - lchild = l; - rchild = r; - - /* Get the parent page. */ - if ((h = mpool_get(t->bt_mp, parent->pgno, 0)) == NULL) - goto err2; - - /* - * The new key goes ONE AFTER the index, because the split - * was to the right. - */ - skip = parent->index + 1; - - /* - * Calculate the space needed on the parent page. - * - * Prefix trees: space hack when inserting into BINTERNAL - * pages. Retain only what's needed to distinguish between - * the new entry and the LAST entry on the page to its left. - * If the keys compare equal, retain the entire key. Note, - * we don't touch overflow keys, and the entire key must be - * retained for the next-to-left most key on the leftmost - * page of each level, or the search will fail. Applicable - * ONLY to internal pages that have leaf pages as children. - * Further reduction of the key between pairs of internal - * pages loses too much information. - */ - switch (rchild->flags & P_TYPE) { - case P_BINTERNAL: - bi = GETBINTERNAL(rchild, 0); - nbytes = NBINTERNAL(bi->ksize); - break; - case P_BLEAF: - bl = GETBLEAF(rchild, 0); - nbytes = NBINTERNAL(bl->ksize); - if (t->bt_pfx && !(bl->flags & P_BIGKEY) && - (h->prevpg != P_INVALID || skip > 1)) { - tbl = GETBLEAF(lchild, NEXTINDEX(lchild) - 1); - a.size = tbl->ksize; - a.data = tbl->bytes; - b.size = bl->ksize; - b.data = bl->bytes; - nksize = t->bt_pfx(&a, &b); - n = NBINTERNAL(nksize); - if (n < nbytes) { -#ifdef STATISTICS - bt_pfxsaved += nbytes - n; -#endif - nbytes = n; - } else - nksize = 0; - } else - nksize = 0; - break; - case P_RINTERNAL: - case P_RLEAF: - nbytes = NRINTERNAL; - break; - default: - abort(); - } - - /* Split the parent page if necessary or shift the indices. */ - if (h->upper - h->lower < nbytes + sizeof(indx_t)) { - sp = h; - h = h->pgno == P_ROOT ? - bt_root(t, h, &l, &r, &skip, nbytes) : - bt_page(t, h, &l, &r, &skip, nbytes); - if (h == NULL) - goto err1; - parentsplit = 1; - } else { - if (skip < (nxtindex = NEXTINDEX(h))) - memmove(h->linp + skip + 1, h->linp + skip, - (nxtindex - skip) * sizeof(indx_t)); - h->lower += sizeof(indx_t); - parentsplit = 0; - } - - /* Insert the key into the parent page. */ - switch(rchild->flags & P_TYPE) { - case P_BINTERNAL: - h->linp[skip] = h->upper -= nbytes; - dest = (char *)h + h->linp[skip]; - memmove(dest, bi, nbytes); - ((BINTERNAL *)dest)->pgno = rchild->pgno; - break; - case P_BLEAF: - h->linp[skip] = h->upper -= nbytes; - dest = (char *)h + h->linp[skip]; - WR_BINTERNAL(dest, nksize ? nksize : bl->ksize, - rchild->pgno, bl->flags & P_BIGKEY); - memmove(dest, bl->bytes, nksize ? nksize : bl->ksize); - if (bl->flags & P_BIGKEY && - bt_preserve(t, *(pgno_t *)bl->bytes) == RET_ERROR) - goto err1; - break; - case P_RINTERNAL: - /* - * Update the left page count. If split - * added at index 0, fix the correct page. - */ - if (skip > 0) - dest = (char *)h + h->linp[skip - 1]; - else - dest = (char *)l + l->linp[NEXTINDEX(l) - 1]; - ((RINTERNAL *)dest)->nrecs = rec_total(lchild); - ((RINTERNAL *)dest)->pgno = lchild->pgno; - - /* Update the right page count. */ - h->linp[skip] = h->upper -= nbytes; - dest = (char *)h + h->linp[skip]; - ((RINTERNAL *)dest)->nrecs = rec_total(rchild); - ((RINTERNAL *)dest)->pgno = rchild->pgno; - break; - case P_RLEAF: - /* - * Update the left page count. If split - * added at index 0, fix the correct page. - */ - if (skip > 0) - dest = (char *)h + h->linp[skip - 1]; - else - dest = (char *)l + l->linp[NEXTINDEX(l) - 1]; - ((RINTERNAL *)dest)->nrecs = NEXTINDEX(lchild); - ((RINTERNAL *)dest)->pgno = lchild->pgno; - - /* Update the right page count. */ - h->linp[skip] = h->upper -= nbytes; - dest = (char *)h + h->linp[skip]; - ((RINTERNAL *)dest)->nrecs = NEXTINDEX(rchild); - ((RINTERNAL *)dest)->pgno = rchild->pgno; - break; - default: - abort(); - } - - /* Unpin the held pages. */ - if (!parentsplit) { - mpool_put(t->bt_mp, h, MPOOL_DIRTY); - break; - } - - /* If the root page was split, make it look right. */ - if (sp->pgno == P_ROOT && - (ISSET(t, R_RECNO) ? - bt_rroot(t, sp, l, r) : bt_broot(t, sp, l, r)) == RET_ERROR) - goto err1; - - mpool_put(t->bt_mp, lchild, MPOOL_DIRTY); - mpool_put(t->bt_mp, rchild, MPOOL_DIRTY); - } - - /* Unpin the held pages. */ - mpool_put(t->bt_mp, l, MPOOL_DIRTY); - mpool_put(t->bt_mp, r, MPOOL_DIRTY); - - /* Clear any pages left on the stack. */ - return (RET_SUCCESS); - - /* - * If something fails in the above loop we were already walking back - * up the tree and the tree is now inconsistent. Nothing much we can - * do about it but release any memory we're holding. - */ -err1: mpool_put(t->bt_mp, lchild, MPOOL_DIRTY); - mpool_put(t->bt_mp, rchild, MPOOL_DIRTY); - -err2: mpool_put(t->bt_mp, l, 0); - mpool_put(t->bt_mp, r, 0); - __dbpanic(t->bt_dbp); - return (RET_ERROR); -} - -/* - * BT_PAGE -- Split a non-root page of a btree. - * - * Parameters: - * t: tree - * h: root page - * lp: pointer to left page pointer - * rp: pointer to right page pointer - * skip: pointer to index to leave open - * ilen: insert length - * - * Returns: - * Pointer to page in which to insert or NULL on error. - */ -static PAGE * -bt_page(t, h, lp, rp, skip, ilen) - BTREE *t; - PAGE *h, **lp, **rp; - indx_t *skip; - size_t ilen; -{ - PAGE *l, *r, *tp; - pgno_t npg; - -#ifdef STATISTICS - ++bt_split; -#endif - /* Put the new right page for the split into place. */ - if ((r = __bt_new(t, &npg)) == NULL) - return (NULL); - r->pgno = npg; - r->lower = BTDATAOFF; - r->upper = t->bt_psize; - r->nextpg = h->nextpg; - r->prevpg = h->pgno; - r->flags = h->flags & P_TYPE; - - /* - * If we're splitting the last page on a level because we're appending - * a key to it (skip is NEXTINDEX()), it's likely that the data is - * sorted. Adding an empty page on the side of the level is less work - * and can push the fill factor much higher than normal. If we're - * wrong it's no big deal, we'll just do the split the right way next - * time. It may look like it's equally easy to do a similar hack for - * reverse sorted data, that is, split the tree left, but it's not. - * Don't even try. - */ - if (h->nextpg == P_INVALID && *skip == NEXTINDEX(h)) { -#ifdef STATISTICS - ++bt_sortsplit; -#endif - h->nextpg = r->pgno; - r->lower = BTDATAOFF + sizeof(indx_t); - *skip = 0; - *lp = h; - *rp = r; - return (r); - } - - /* Put the new left page for the split into place. */ - if ((l = (PAGE *)malloc(t->bt_psize)) == NULL) { - mpool_put(t->bt_mp, r, 0); - return (NULL); - } - l->pgno = h->pgno; - l->nextpg = r->pgno; - l->prevpg = h->prevpg; - l->lower = BTDATAOFF; - l->upper = t->bt_psize; - l->flags = h->flags & P_TYPE; - - /* Fix up the previous pointer of the page after the split page. */ - if (h->nextpg != P_INVALID) { - if ((tp = mpool_get(t->bt_mp, h->nextpg, 0)) == NULL) { - free(l); - /* XXX mpool_free(t->bt_mp, r->pgno); */ - return (NULL); - } - tp->prevpg = r->pgno; - mpool_put(t->bt_mp, tp, 0); - } - - /* - * Split right. The key/data pairs aren't sorted in the btree page so - * it's simpler to copy the data from the split page onto two new pages - * instead of copying half the data to the right page and compacting - * the left page in place. Since the left page can't change, we have - * to swap the original and the allocated left page after the split. - */ - tp = bt_psplit(t, h, l, r, skip, ilen); - - /* Move the new left page onto the old left page. */ - memmove(h, l, t->bt_psize); - if (tp == l) - tp = h; - free(l); - - *lp = h; - *rp = r; - return (tp); -} - -/* - * BT_ROOT -- Split the root page of a btree. - * - * Parameters: - * t: tree - * h: root page - * lp: pointer to left page pointer - * rp: pointer to right page pointer - * skip: pointer to index to leave open - * ilen: insert length - * - * Returns: - * Pointer to page in which to insert or NULL on error. - */ -static PAGE * -bt_root(t, h, lp, rp, skip, ilen) - BTREE *t; - PAGE *h, **lp, **rp; - indx_t *skip; - size_t ilen; -{ - PAGE *l, *r, *tp; - pgno_t lnpg, rnpg; - -#ifdef STATISTICS - ++bt_split; - ++bt_rootsplit; -#endif - /* Put the new left and right pages for the split into place. */ - if ((l = __bt_new(t, &lnpg)) == NULL || - (r = __bt_new(t, &rnpg)) == NULL) - return (NULL); - l->pgno = lnpg; - r->pgno = rnpg; - l->nextpg = r->pgno; - r->prevpg = l->pgno; - l->prevpg = r->nextpg = P_INVALID; - l->lower = r->lower = BTDATAOFF; - l->upper = r->upper = t->bt_psize; - l->flags = r->flags = h->flags & P_TYPE; - - /* Split the root page. */ - tp = bt_psplit(t, h, l, r, skip, ilen); - - *lp = l; - *rp = r; - return (tp); -} - -/* - * BT_RROOT -- Fix up the recno root page after it has been split. - * - * Parameters: - * t: tree - * h: root page - * l: left page - * r: right page - * - * Returns: - * RET_ERROR, RET_SUCCESS - */ -static int -bt_rroot(t, h, l, r) - BTREE *t; - PAGE *h, *l, *r; -{ - char *dest; - - /* Insert the left and right keys, set the header information. */ - h->linp[0] = h->upper = t->bt_psize - NRINTERNAL; - dest = (char *)h + h->upper; - WR_RINTERNAL(dest, - l->flags & P_RLEAF ? NEXTINDEX(l) : rec_total(l), l->pgno); - - h->linp[1] = h->upper -= NRINTERNAL; - dest = (char *)h + h->upper; - WR_RINTERNAL(dest, - r->flags & P_RLEAF ? NEXTINDEX(r) : rec_total(r), r->pgno); - - h->lower = BTDATAOFF + 2 * sizeof(indx_t); - - /* Unpin the root page, set to recno internal page. */ - h->flags &= ~P_TYPE; - h->flags |= P_RINTERNAL; - mpool_put(t->bt_mp, h, MPOOL_DIRTY); - - return (RET_SUCCESS); -} - -/* - * BT_BROOT -- Fix up the btree root page after it has been split. - * - * Parameters: - * t: tree - * h: root page - * l: left page - * r: right page - * - * Returns: - * RET_ERROR, RET_SUCCESS - */ -static int -bt_broot(t, h, l, r) - BTREE *t; - PAGE *h, *l, *r; -{ - BINTERNAL *bi; - BLEAF *bl; - size_t nbytes; - char *dest; - - /* - * If the root page was a leaf page, change it into an internal page. - * We copy the key we split on (but not the key's data, in the case of - * a leaf page) to the new root page. - * - * The btree comparison code guarantees that the left-most key on any - * level of the tree is never used, so it doesn't need to be filled in. - */ - nbytes = NBINTERNAL(0); - h->linp[0] = h->upper = t->bt_psize - nbytes; - dest = (char *)h + h->upper; - WR_BINTERNAL(dest, 0, l->pgno, 0); - - switch(h->flags & P_TYPE) { - case P_BLEAF: - bl = GETBLEAF(r, 0); - nbytes = NBINTERNAL(bl->ksize); - h->linp[1] = h->upper -= nbytes; - dest = (char *)h + h->upper; - WR_BINTERNAL(dest, bl->ksize, r->pgno, 0); - memmove(dest, bl->bytes, bl->ksize); - - /* - * If the key is on an overflow page, mark the overflow chain - * so it isn't deleted when the leaf copy of the key is deleted. - */ - if (bl->flags & P_BIGKEY && - bt_preserve(t, *(pgno_t *)bl->bytes) == RET_ERROR) - return (RET_ERROR); - break; - case P_BINTERNAL: - bi = GETBINTERNAL(r, 0); - nbytes = NBINTERNAL(bi->ksize); - h->linp[1] = h->upper -= nbytes; - dest = (char *)h + h->upper; - memmove(dest, bi, nbytes); - ((BINTERNAL *)dest)->pgno = r->pgno; - break; - default: - abort(); - } - - /* There are two keys on the page. */ - h->lower = BTDATAOFF + 2 * sizeof(indx_t); - - /* Unpin the root page, set to btree internal page. */ - h->flags &= ~P_TYPE; - h->flags |= P_BINTERNAL; - mpool_put(t->bt_mp, h, MPOOL_DIRTY); - - return (RET_SUCCESS); -} - -/* - * BT_PSPLIT -- Do the real work of splitting the page. - * - * Parameters: - * t: tree - * h: page to be split - * l: page to put lower half of data - * r: page to put upper half of data - * pskip: pointer to index to leave open - * ilen: insert length - * - * Returns: - * Pointer to page in which to insert. - */ -static PAGE * -bt_psplit(t, h, l, r, pskip, ilen) - BTREE *t; - PAGE *h, *l, *r; - indx_t *pskip; - size_t ilen; -{ - BINTERNAL *bi; - BLEAF *bl; - RLEAF *rl; - EPGNO *c; - PAGE *rval; - void *src; - indx_t full, half, nxt, off, skip, top, used; - size_t nbytes; - int bigkeycnt, isbigkey; - - /* - * Split the data to the left and right pages. Leave the skip index - * open. Additionally, make some effort not to split on an overflow - * key. This makes internal page processing faster and can save - * space as overflow keys used by internal pages are never deleted. - */ - bigkeycnt = 0; - skip = *pskip; - full = t->bt_psize - BTDATAOFF; - half = full / 2; - used = 0; - for (nxt = off = 0, top = NEXTINDEX(h); nxt < top; ++off) { - if (skip == off) { - nbytes = ilen; - isbigkey = 0; /* XXX: not really known. */ - } else - switch (h->flags & P_TYPE) { - case P_BINTERNAL: - src = bi = GETBINTERNAL(h, nxt); - nbytes = NBINTERNAL(bi->ksize); - isbigkey = bi->flags & P_BIGKEY; - break; - case P_BLEAF: - src = bl = GETBLEAF(h, nxt); - nbytes = NBLEAF(bl); - isbigkey = bl->flags & P_BIGKEY; - break; - case P_RINTERNAL: - src = GETRINTERNAL(h, nxt); - nbytes = NRINTERNAL; - isbigkey = 0; - break; - case P_RLEAF: - src = rl = GETRLEAF(h, nxt); - nbytes = NRLEAF(rl); - isbigkey = 0; - break; - default: - abort(); - } - - /* - * If the key/data pairs are substantial fractions of the max - * possible size for the page, it's possible to get situations - * where we decide to try and copy too much onto the left page. - * Make sure that doesn't happen. - */ - if (skip <= off && used + nbytes >= full) { - --off; - break; - } - - /* Copy the key/data pair, if not the skipped index. */ - if (skip != off) { - ++nxt; - - l->linp[off] = l->upper -= nbytes; - memmove((char *)l + l->upper, src, nbytes); - } - - used += nbytes; - if (used >= half) { - if (!isbigkey || bigkeycnt == 3) - break; - else - ++bigkeycnt; - } - } - - /* - * Off is the last offset that's valid for the left page. - * Nxt is the first offset to be placed on the right page. - */ - l->lower += (off + 1) * sizeof(indx_t); - - /* - * If splitting the page that the cursor was on, the cursor has to be - * adjusted to point to the same record as before the split. If the - * cursor is at or past the skipped slot, the cursor is incremented by - * one. If the cursor is on the right page, it is decremented by the - * number of records split to the left page. - * - * Don't bother checking for the B_SEQINIT flag, the page number will - * be P_INVALID. - */ - c = &t->bt_bcursor; - if (c->pgno == h->pgno) { - if (c->index >= skip) - ++c->index; - if (c->index < nxt) /* Left page. */ - c->pgno = l->pgno; - else { /* Right page. */ - c->pgno = r->pgno; - c->index -= nxt; - } - } - - /* - * If the skipped index was on the left page, just return that page. - * Otherwise, adjust the skip index to reflect the new position on - * the right page. - */ - if (skip <= off) { - skip = 0; - rval = l; - } else { - rval = r; - *pskip -= nxt; - } - - for (off = 0; nxt < top; ++off) { - if (skip == nxt) { - ++off; - skip = 0; - } - switch (h->flags & P_TYPE) { - case P_BINTERNAL: - src = bi = GETBINTERNAL(h, nxt); - nbytes = NBINTERNAL(bi->ksize); - break; - case P_BLEAF: - src = bl = GETBLEAF(h, nxt); - nbytes = NBLEAF(bl); - break; - case P_RINTERNAL: - src = GETRINTERNAL(h, nxt); - nbytes = NRINTERNAL; - break; - case P_RLEAF: - src = rl = GETRLEAF(h, nxt); - nbytes = NRLEAF(rl); - break; - default: - abort(); - } - ++nxt; - r->linp[off] = r->upper -= nbytes; - memmove((char *)r + r->upper, src, nbytes); - } - r->lower += off * sizeof(indx_t); - - /* If the key is being appended to the page, adjust the index. */ - if (skip == top) - r->lower += sizeof(indx_t); - - return (rval); -} - -/* - * BT_PRESERVE -- Mark a chain of pages as used by an internal node. - * - * Chains of indirect blocks pointed to by leaf nodes get reclaimed when the - * record that references them gets deleted. Chains pointed to by internal - * pages never get deleted. This routine marks a chain as pointed to by an - * internal page. - * - * Parameters: - * t: tree - * pg: page number of first page in the chain. - * - * Returns: - * RET_SUCCESS, RET_ERROR. - */ -static int -bt_preserve(t, pg) - BTREE *t; - pgno_t pg; -{ - PAGE *h; - - if ((h = mpool_get(t->bt_mp, pg, 0)) == NULL) - return (RET_ERROR); - h->flags |= P_PRESERVE; - mpool_put(t->bt_mp, h, MPOOL_DIRTY); - return (RET_SUCCESS); -} - -/* - * REC_TOTAL -- Return the number of recno entries below a page. - * - * Parameters: - * h: page - * - * Returns: - * The number of recno entries below a page. - * - * XXX - * These values could be set by the bt_psplit routine. The problem is that the - * entry has to be popped off of the stack etc. or the values have to be passed - * all the way back to bt_split/bt_rroot and it's not very clean. - */ -static recno_t -rec_total(h) - PAGE *h; -{ - recno_t recs; - indx_t nxt, top; - - for (recs = 0, nxt = 0, top = NEXTINDEX(h); nxt < top; ++nxt) - recs += GETRINTERNAL(h, nxt)->nrecs; - return (recs); -} diff --git a/db.subproj/btree.subproj/bt_stack.c b/db.subproj/btree.subproj/bt_stack.c deleted file mode 100644 index 528299b..0000000 --- a/db.subproj/btree.subproj/bt_stack.c +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Mike Olson. - * - * 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 - -#include -#include -#include - -#include -#include "btree.h" - -/* - * When a page splits, a new record has to be inserted into its parent page. - * This page may have to split as well, all the way up to the root. Since - * parent pointers in each page would be expensive, we maintain a stack of - * parent pages as we descend the tree. - * - * XXX - * This is a concurrency problem -- if user a builds a stack, then user b - * splits the tree, then user a tries to split the tree, there's a new level - * in the tree that user a doesn't know about. - */ - -/* - * __BT_PUSH -- Push parent page info onto the stack (LIFO). - * - * Parameters: - * t: tree - * pgno: page - * index: page index - * - * Returns: - * RET_ERROR, RET_SUCCESS - */ -int -__bt_push(t, pgno, index) - BTREE *t; - pgno_t pgno; - indx_t index; -{ - if (t->bt_sp == t->bt_maxstack) { - t->bt_maxstack += 50; - if ((t->bt_stack = (EPGNO *)realloc(t->bt_stack, - t->bt_maxstack * sizeof(EPGNO))) == NULL) { - t->bt_maxstack -= 50; - return (RET_ERROR); - } - } - - t->bt_stack[t->bt_sp].pgno = pgno; - t->bt_stack[t->bt_sp].index = index; - ++t->bt_sp; - return (RET_SUCCESS); -} diff --git a/db.subproj/btree.subproj/bt_utils.c b/db.subproj/btree.subproj/bt_utils.c deleted file mode 100644 index 17093b8..0000000 --- a/db.subproj/btree.subproj/bt_utils.c +++ /dev/null @@ -1,265 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Mike Olson. - * - * 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 - -#include -#include -#include - -#include -#include "btree.h" - -/* - * __BT_RET -- Build return key/data pair as a result of search or scan. - * - * Parameters: - * t: tree - * d: LEAF to be returned to the user. - * key: user's key structure (NULL if not to be filled in) - * data: user's data structure - * - * Returns: - * RET_SUCCESS, RET_ERROR. - */ -int -__bt_ret(t, e, key, data) - BTREE *t; - EPG *e; - DBT *key, *data; -{ - register BLEAF *bl; - register void *p; - - bl = GETBLEAF(e->page, e->index); - - /* - * We always copy big keys/data to make them contigous. Otherwise, - * we leave the page pinned and don't copy unless the user specified - * concurrent access. - */ - if (bl->flags & P_BIGDATA) { - if (__ovfl_get(t, bl->bytes + bl->ksize, - &data->size, &t->bt_dbuf, &t->bt_dbufsz)) - return (RET_ERROR); - data->data = t->bt_dbuf; - } else if (ISSET(t, B_DB_LOCK)) { - /* Use +1 in case the first record retrieved is 0 length. */ - if (bl->dsize + 1 > t->bt_dbufsz) { - if ((p = - (void *)realloc(t->bt_dbuf, bl->dsize + 1)) == NULL) - return (RET_ERROR); - t->bt_dbuf = p; - t->bt_dbufsz = bl->dsize + 1; - } - memmove(t->bt_dbuf, bl->bytes + bl->ksize, bl->dsize); - data->size = bl->dsize; - data->data = t->bt_dbuf; - } else { - data->size = bl->dsize; - data->data = bl->bytes + bl->ksize; - } - - if (key == NULL) - return (RET_SUCCESS); - - if (bl->flags & P_BIGKEY) { - if (__ovfl_get(t, bl->bytes, - &key->size, &t->bt_kbuf, &t->bt_kbufsz)) - return (RET_ERROR); - key->data = t->bt_kbuf; - } else if (ISSET(t, B_DB_LOCK)) { - if (bl->ksize > t->bt_kbufsz) { - if ((p = - (void *)realloc(t->bt_kbuf, bl->ksize)) == NULL) - return (RET_ERROR); - t->bt_kbuf = p; - t->bt_kbufsz = bl->ksize; - } - memmove(t->bt_kbuf, bl->bytes, bl->ksize); - key->size = bl->ksize; - key->data = t->bt_kbuf; - } else { - key->size = bl->ksize; - key->data = bl->bytes; - } - return (RET_SUCCESS); -} - -/* - * __BT_CMP -- Compare a key to a given record. - * - * Parameters: - * t: tree - * k1: DBT pointer of first arg to comparison - * e: pointer to EPG for comparison - * - * Returns: - * < 0 if k1 is < record - * = 0 if k1 is = record - * > 0 if k1 is > record - */ -int -__bt_cmp(t, k1, e) - BTREE *t; - const DBT *k1; - EPG *e; -{ - BINTERNAL *bi; - BLEAF *bl; - DBT k2; - PAGE *h; - void *bigkey; - - /* - * The left-most key on internal pages, at any level of the tree, is - * guaranteed by the following code to be less than any user key. - * This saves us from having to update the leftmost key on an internal - * page when the user inserts a new key in the tree smaller than - * anything we've yet seen. - */ - h = e->page; - if (e->index == 0 && h->prevpg == P_INVALID && !(h->flags & P_BLEAF)) - return (1); - - bigkey = NULL; - if (h->flags & P_BLEAF) { - bl = GETBLEAF(h, e->index); - if (bl->flags & P_BIGKEY) - bigkey = bl->bytes; - else { - k2.data = bl->bytes; - k2.size = bl->ksize; - } - } else { - bi = GETBINTERNAL(h, e->index); - if (bi->flags & P_BIGKEY) - bigkey = bi->bytes; - else { - k2.data = bi->bytes; - k2.size = bi->ksize; - } - } - - if (bigkey) { - if (__ovfl_get(t, bigkey, - &k2.size, &t->bt_dbuf, &t->bt_dbufsz)) - return (RET_ERROR); - k2.data = t->bt_dbuf; - } - return ((*t->bt_cmp)(k1, &k2)); -} - -/* - * __BT_DEFCMP -- Default comparison routine. - * - * Parameters: - * a: DBT #1 - * b: DBT #2 - * - * Returns: - * < 0 if a is < b - * = 0 if a is = b - * > 0 if a is > b - */ -int -__bt_defcmp(a, b) - const DBT *a, *b; -{ - register size_t len; - register u_char *p1, *p2; - - /* - * XXX - * If a size_t doesn't fit in an int, this routine can lose. - * What we need is a integral type which is guaranteed to be - * larger than a size_t, and there is no such thing. - */ - len = MIN(a->size, b->size); - for (p1 = a->data, p2 = b->data; len--; ++p1, ++p2) - if (*p1 != *p2) - return ((int)*p1 - (int)*p2); - return ((int)a->size - (int)b->size); -} - -/* - * __BT_DEFPFX -- Default prefix routine. - * - * Parameters: - * a: DBT #1 - * b: DBT #2 - * - * Returns: - * Number of bytes needed to distinguish b from a. - */ -size_t -__bt_defpfx(a, b) - const DBT *a, *b; -{ - register u_char *p1, *p2; - register size_t cnt, len; - - cnt = 1; - len = MIN(a->size, b->size); - for (p1 = a->data, p2 = b->data; len--; ++p1, ++p2, ++cnt) - if (*p1 != *p2) - return (cnt); - - /* a->size must be <= b->size, or they wouldn't be in this order. */ - return (a->size < b->size ? a->size + 1 : a->size); -} diff --git a/db.subproj/btree.subproj/btree.h b/db.subproj/btree.subproj/btree.h deleted file mode 100644 index aa62d01..0000000 --- a/db.subproj/btree.subproj/btree.h +++ /dev/null @@ -1,372 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1991, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Mike Olson. - * - * 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 - -#define DEFMINKEYPAGE (2) /* Minimum keys per page */ -#define MINCACHE (5) /* Minimum cached pages */ -#define MINPSIZE (512) /* Minimum page size */ - -/* - * Page 0 of a btree file contains a copy of the meta-data. This page is also - * used as an out-of-band page, i.e. page pointers that point to nowhere point - * to page 0. Page 1 is the root of the btree. - */ -#define P_INVALID 0 /* Invalid tree page number. */ -#define P_META 0 /* Tree metadata page number. */ -#define P_ROOT 1 /* Tree root page number. */ - -/* - * There are five page layouts in the btree: btree internal pages (BINTERNAL), - * btree leaf pages (BLEAF), recno internal pages (RINTERNAL), recno leaf pages - * (RLEAF) and overflow pages. All five page types have a page header (PAGE). - * This implementation requires that values within structures NOT be padded. - * (ANSI C permits random padding.) If your compiler pads randomly you'll have - * to do some work to get this package to run. - */ -typedef struct _page { - pgno_t pgno; /* this page's page number */ - pgno_t prevpg; /* left sibling */ - pgno_t nextpg; /* right sibling */ - -#define P_BINTERNAL 0x01 /* btree internal page */ -#define P_BLEAF 0x02 /* leaf page */ -#define P_OVERFLOW 0x04 /* overflow page */ -#define P_RINTERNAL 0x08 /* recno internal page */ -#define P_RLEAF 0x10 /* leaf page */ -#define P_TYPE 0x1f /* type mask */ -#define P_PRESERVE 0x20 /* never delete this chain of pages */ - u_int32_t flags; - - indx_t lower; /* lower bound of free space on page */ - indx_t upper; /* upper bound of free space on page */ - indx_t linp[1]; /* indx_t-aligned VAR. LENGTH DATA */ -} PAGE; - -/* First and next index. */ -#define BTDATAOFF (sizeof(pgno_t) + sizeof(pgno_t) + sizeof(pgno_t) + \ - sizeof(u_int32_t) + sizeof(indx_t) + sizeof(indx_t)) -#define NEXTINDEX(p) (((p)->lower - BTDATAOFF) / sizeof(indx_t)) - -/* - * For pages other than overflow pages, there is an array of offsets into the - * rest of the page immediately following the page header. Each offset is to - * an item which is unique to the type of page. The h_lower offset is just - * past the last filled-in index. The h_upper offset is the first item on the - * page. Offsets are from the beginning of the page. - * - * If an item is too big to store on a single page, a flag is set and the item - * is a { page, size } pair such that the page is the first page of an overflow - * chain with size bytes of item. Overflow pages are simply bytes without any - * external structure. - * - * The page number and size fields in the items are pgno_t-aligned so they can - * be manipulated without copying. (This presumes that 32 bit items can be - * manipulated on this system.) - */ -#define LALIGN(n) \ - (((n) + sizeof(pgno_t) - 1) & ~(sizeof(pgno_t) - 1)) -#define NOVFLSIZE (sizeof(pgno_t) + sizeof(size_t)) - -/* - * For the btree internal pages, the item is a key. BINTERNALs are {key, pgno} - * pairs, such that the key compares less than or equal to all of the records - * on that page. For a tree without duplicate keys, an internal page with two - * consecutive keys, a and b, will have all records greater than or equal to a - * and less than b stored on the page associated with a. Duplicate keys are - * somewhat special and can cause duplicate internal and leaf page records and - * some minor modifications of the above rule. - */ -typedef struct _binternal { - size_t ksize; /* key size */ - pgno_t pgno; /* page number stored on */ -#define P_BIGDATA 0x01 /* overflow data */ -#define P_BIGKEY 0x02 /* overflow key */ - u_char flags; - char bytes[1]; /* data */ -} BINTERNAL; - -/* Get the page's BINTERNAL structure at index indx. */ -#define GETBINTERNAL(pg, indx) \ - ((BINTERNAL *)((char *)(pg) + (pg)->linp[indx])) - -/* Get the number of bytes in the entry. */ -#define NBINTERNAL(len) \ - LALIGN(sizeof(size_t) + sizeof(pgno_t) + sizeof(u_char) + (len)) - -/* Copy a BINTERNAL entry to the page. */ -#define WR_BINTERNAL(p, size, pgno, flags) { \ - *(size_t *)p = size; \ - p += sizeof(size_t); \ - *(pgno_t *)p = pgno; \ - p += sizeof(pgno_t); \ - *(u_char *)p = flags; \ - p += sizeof(u_char); \ -} - -/* - * For the recno internal pages, the item is a page number with the number of - * keys found on that page and below. - */ -typedef struct _rinternal { - recno_t nrecs; /* number of records */ - pgno_t pgno; /* page number stored below */ -} RINTERNAL; - -/* Get the page's RINTERNAL structure at index indx. */ -#define GETRINTERNAL(pg, indx) \ - ((RINTERNAL *)((char *)(pg) + (pg)->linp[indx])) - -/* Get the number of bytes in the entry. */ -#define NRINTERNAL \ - LALIGN(sizeof(recno_t) + sizeof(pgno_t)) - -/* Copy a RINTERAL entry to the page. */ -#define WR_RINTERNAL(p, nrecs, pgno) { \ - *(recno_t *)p = nrecs; \ - p += sizeof(recno_t); \ - *(pgno_t *)p = pgno; \ -} - -/* For the btree leaf pages, the item is a key and data pair. */ -typedef struct _bleaf { - size_t ksize; /* size of key */ - size_t dsize; /* size of data */ - u_char flags; /* P_BIGDATA, P_BIGKEY */ - char bytes[1]; /* data */ -} BLEAF; - -/* Get the page's BLEAF structure at index indx. */ -#define GETBLEAF(pg, indx) \ - ((BLEAF *)((char *)(pg) + (pg)->linp[indx])) - -/* Get the number of bytes in the entry. */ -#define NBLEAF(p) NBLEAFDBT((p)->ksize, (p)->dsize) - -/* Get the number of bytes in the user's key/data pair. */ -#define NBLEAFDBT(ksize, dsize) \ - LALIGN(sizeof(size_t) + sizeof(size_t) + sizeof(u_char) + \ - (ksize) + (dsize)) - -/* Copy a BLEAF entry to the page. */ -#define WR_BLEAF(p, key, data, flags) { \ - *(size_t *)p = key->size; \ - p += sizeof(size_t); \ - *(size_t *)p = data->size; \ - p += sizeof(size_t); \ - *(u_char *)p = flags; \ - p += sizeof(u_char); \ - memmove(p, key->data, key->size); \ - p += key->size; \ - memmove(p, data->data, data->size); \ -} - -/* For the recno leaf pages, the item is a data entry. */ -typedef struct _rleaf { - size_t dsize; /* size of data */ - u_char flags; /* P_BIGDATA */ - char bytes[1]; -} RLEAF; - -/* Get the page's RLEAF structure at index indx. */ -#define GETRLEAF(pg, indx) \ - ((RLEAF *)((char *)(pg) + (pg)->linp[indx])) - -/* Get the number of bytes in the entry. */ -#define NRLEAF(p) NRLEAFDBT((p)->dsize) - -/* Get the number of bytes from the user's data. */ -#define NRLEAFDBT(dsize) \ - LALIGN(sizeof(size_t) + sizeof(u_char) + (dsize)) - -/* Copy a RLEAF entry to the page. */ -#define WR_RLEAF(p, data, flags) { \ - *(size_t *)p = data->size; \ - p += sizeof(size_t); \ - *(u_char *)p = flags; \ - p += sizeof(u_char); \ - memmove(p, data->data, data->size); \ -} - -/* - * A record in the tree is either a pointer to a page and an index in the page - * or a page number and an index. These structures are used as a cursor, stack - * entry and search returns as well as to pass records to other routines. - * - * One comment about searches. Internal page searches must find the largest - * record less than key in the tree so that descents work. Leaf page searches - * must find the smallest record greater than key so that the returned index - * is the record's correct position for insertion. - * - * One comment about cursors. The cursor key is never removed from the tree, - * even if deleted. This is because it is quite difficult to decide where the - * cursor should be when other keys have been inserted/deleted in the tree; - * duplicate keys make it impossible. This scheme does require extra work - * though, to make sure that we don't perform an operation on a deleted key. - */ -typedef struct _epgno { - pgno_t pgno; /* the page number */ - indx_t index; /* the index on the page */ -} EPGNO; - -typedef struct _epg { - PAGE *page; /* the (pinned) page */ - indx_t index; /* the index on the page */ -} EPG; - -/* - * The metadata of the tree. The m_nrecs field is used only by the RECNO code. - * This is because the btree doesn't really need it and it requires that every - * put or delete call modify the metadata. - */ -typedef struct _btmeta { - u_int32_t m_magic; /* magic number */ - u_int32_t m_version; /* version */ - u_int32_t m_psize; /* page size */ - u_int32_t m_free; /* page number of first free page */ - u_int32_t m_nrecs; /* R: number of records */ -#define SAVEMETA (B_NODUPS | R_RECNO) - u_int32_t m_flags; /* bt_flags & SAVEMETA */ - u_int32_t m_unused; /* unused */ -} BTMETA; - -/* The in-memory btree/recno data structure. */ -typedef struct _btree { - MPOOL *bt_mp; /* memory pool cookie */ - - DB *bt_dbp; /* pointer to enclosing DB */ - - EPG bt_cur; /* current (pinned) page */ - PAGE *bt_pinned; /* page pinned across calls */ - - EPGNO bt_bcursor; /* B: btree cursor */ - recno_t bt_rcursor; /* R: recno cursor (1-based) */ - -#define BT_POP(t) (t->bt_sp ? t->bt_stack + --t->bt_sp : NULL) -#define BT_CLR(t) (t->bt_sp = 0) - EPGNO *bt_stack; /* stack of parent pages */ - u_int bt_sp; /* current stack pointer */ - u_int bt_maxstack; /* largest stack */ - - char *bt_kbuf; /* key buffer */ - size_t bt_kbufsz; /* key buffer size */ - char *bt_dbuf; /* data buffer */ - size_t bt_dbufsz; /* data buffer size */ - - int bt_fd; /* tree file descriptor */ - - pgno_t bt_free; /* next free page */ - u_int32_t bt_psize; /* page size */ - indx_t bt_ovflsize; /* cut-off for key/data overflow */ - int bt_lorder; /* byte order */ - /* sorted order */ - enum { NOT, BACK, FORWARD } bt_order; - EPGNO bt_last; /* last insert */ - - /* B: key comparison function */ - int (*bt_cmp) __P((const DBT *, const DBT *)); - /* B: prefix comparison function */ - size_t (*bt_pfx) __P((const DBT *, const DBT *)); - /* R: recno input function */ - int (*bt_irec) __P((struct _btree *, recno_t)); - - FILE *bt_rfp; /* R: record FILE pointer */ - int bt_rfd; /* R: record file descriptor */ - - caddr_t bt_cmap; /* R: current point in mapped space */ - caddr_t bt_smap; /* R: start of mapped space */ - caddr_t bt_emap; /* R: end of mapped space */ - size_t bt_msize; /* R: size of mapped region. */ - - recno_t bt_nrecs; /* R: number of records */ - size_t bt_reclen; /* R: fixed record length */ - u_char bt_bval; /* R: delimiting byte/pad character */ - -/* - * NB: - * B_NODUPS and R_RECNO are stored on disk, and may not be changed. - */ -#define B_DELCRSR 0x00001 /* cursor has been deleted */ -#define B_INMEM 0x00002 /* in-memory tree */ -#define B_METADIRTY 0x00004 /* need to write metadata */ -#define B_MODIFIED 0x00008 /* tree modified */ -#define B_NEEDSWAP 0x00010 /* if byte order requires swapping */ -#define B_NODUPS 0x00020 /* no duplicate keys permitted */ -#define B_RDONLY 0x00040 /* read-only tree */ -#define R_RECNO 0x00080 /* record oriented tree */ -#define B_SEQINIT 0x00100 /* sequential scan initialized */ - -#define R_CLOSEFP 0x00200 /* opened a file pointer */ -#define R_EOF 0x00400 /* end of input file reached. */ -#define R_FIXLEN 0x00800 /* fixed length records */ -#define R_MEMMAPPED 0x01000 /* memory mapped file. */ -#define R_INMEM 0x02000 /* in-memory file */ -#define R_MODIFIED 0x04000 /* modified file */ -#define R_RDONLY 0x08000 /* read-only file */ - -#define B_DB_LOCK 0x10000 /* DB_LOCK specified. */ -#define B_DB_SHMEM 0x20000 /* DB_SHMEM specified. */ -#define B_DB_TXN 0x40000 /* DB_TXN specified. */ - - u_int32_t bt_flags; /* btree state */ -} BTREE; - -#define SET(t, f) ((t)->bt_flags |= (f)) -#define CLR(t, f) ((t)->bt_flags &= ~(f)) -#define ISSET(t, f) ((t)->bt_flags & (f)) - -#include "bt_extern.h" diff --git a/db.subproj/db.subproj/Makefile b/db.subproj/db.subproj/Makefile deleted file mode 100644 index b3f08b6..0000000 --- a/db.subproj/db.subproj/Makefile +++ /dev/null @@ -1,45 +0,0 @@ -# -# Generated by the NeXT Project Builder. -# -# NOTE: Do NOT change this file -- Project Builder maintains it. -# -# Put all of your customizations in files called Makefile.preamble -# and Makefile.postamble (both optional), and Makefile will include them. -# - -NAME = db - -PROJECTVERSION = 2.8 -PROJECT_TYPE = Component - -CFILES = db.c - -OTHERSRCS = Makefile.preamble Makefile Makefile.postamble - - -MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles -CODE_GEN_STYLE = DYNAMIC -MAKEFILE = subproj.make -LIBS = -DEBUG_LIBS = $(LIBS) -PROF_LIBS = $(LIBS) - - - - -NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc -WINDOWS_OBJCPLUS_COMPILER = $(DEVDIR)/gcc -PDO_UNIX_OBJCPLUS_COMPILER = $(NEXTDEV_BIN)/gcc -NEXTSTEP_JAVA_COMPILER = /usr/bin/javac -WINDOWS_JAVA_COMPILER = $(JDKBINDIR)/javac.exe -PDO_UNIX_JAVA_COMPILER = $(JDKBINDIR)/javac - -include $(MAKEFILEDIR)/platform.make - --include Makefile.preamble - -include $(MAKEFILEDIR)/$(MAKEFILE) - --include Makefile.postamble - --include Makefile.dependencies diff --git a/db.subproj/db.subproj/Makefile.postamble b/db.subproj/db.subproj/Makefile.postamble deleted file mode 100644 index 411cde6..0000000 --- a/db.subproj/db.subproj/Makefile.postamble +++ /dev/null @@ -1,100 +0,0 @@ -############################################################################### -# Makefile.postamble -# Copyright 1997, Apple Computer, Inc. -# -# Use this makefile, which is imported after all other makefiles, to -# override attributes for a project's Makefile environment. This allows you -# to take advantage of the environment set up by the other Makefiles. -# You can also define custom rules at the end of this file. -# -############################################################################### -# -# These variables are exported by the standard makefiles and can be -# used in any customizations you make. They are *outputs* of -# the Makefiles and should be used, not set. -# -# PRODUCTS: products to install. All of these products will be placed in -# the directory $(DSTROOT)$(INSTALLDIR) -# GLOBAL_RESOURCE_DIR: The directory to which resources are copied. -# LOCAL_RESOURCE_DIR: The directory to which localized resources are copied. -# OFILE_DIR: Directory into which .o object files are generated. -# DERIVED_SRC_DIR: Directory used for all other derived files -# -# ALL_CFLAGS: flags to pass when compiling .c files -# ALL_MFLAGS: flags to pass when compiling .m files -# ALL_CCFLAGS: flags to pass when compiling .cc, .cxx, and .C files -# ALL_MMFLAGS: flags to pass when compiling .mm, .mxx, and .M files -# ALL_PRECOMPFLAGS: flags to pass when precompiling .h files -# ALL_LDFLAGS: flags to pass when linking object files -# ALL_LIBTOOL_FLAGS: flags to pass when libtooling object files -# ALL_PSWFLAGS: flags to pass when processing .psw and .pswm (pswrap) files -# ALL_RPCFLAGS: flags to pass when processing .rpc (rpcgen) files -# ALL_YFLAGS: flags to pass when processing .y (yacc) files -# ALL_LFLAGS: flags to pass when processing .l (lex) files -# -# NAME: name of application, bundle, subproject, palette, etc. -# LANGUAGES: langages in which the project is written (default "English") -# English_RESOURCES: localized resources (e.g. nib's, images) of project -# GLOBAL_RESOURCES: non-localized resources of project -# -# SRCROOT: base directory in which to place the new source files -# SRCPATH: relative path from SRCROOT to present subdirectory -# -# INSTALLDIR: Directory the product will be installed into by 'install' target -# PUBLIC_HDR_INSTALLDIR: where to install public headers. Don't forget -# to prefix this with DSTROOT when you use it. -# PRIVATE_HDR_INSTALLDIR: where to install private headers. Don't forget -# to prefix this with DSTROOT when you use it. -# -# EXECUTABLE_EXT: Executable extension for the platform (i.e. .exe on Windows) -# -############################################################################### - -# Some compiler flags can be overridden here for certain build situations. -# -# WARNING_CFLAGS: flag used to set warning level (defaults to -Wmost) -# DEBUG_SYMBOLS_CFLAGS: debug-symbol flag passed to all builds (defaults -# to -g) -# DEBUG_BUILD_CFLAGS: flags passed during debug builds (defaults to -DDEBUG) -# OPTIMIZE_BUILD_CFLAGS: flags passed during optimized builds (defaults -# to -O) -# PROFILE_BUILD_CFLAGS: flags passed during profile builds (defaults -# to -pg -DPROFILE) -# LOCAL_DIR_INCLUDE_DIRECTIVE: flag used to add current directory to -# the include path (defaults to -I.) -# DEBUG_BUILD_LDFLAGS, OPTIMIZE_BUILD_LDFLAGS, PROFILE_BUILD_LDFLAGS: flags -# passed to ld/libtool (defaults to nothing) - - -# Library and Framework projects only: -# INSTALL_NAME_DIRECTIVE: This directive ensures that executables linked -# against the framework will run against the correct version even if -# the current version of the framework changes. You may override this -# to "" as an alternative to using the DYLD_LIBRARY_PATH during your -# development cycle, but be sure to restore it before installing. - - -# Ownership and permissions of files installed by 'install' target - -#INSTALL_AS_USER = root - # User/group ownership -#INSTALL_AS_GROUP = wheel - # (probably want to set both of these) -#INSTALL_PERMISSIONS = - # If set, 'install' chmod's executable to this - - -# Options to strip. Note: -S strips debugging symbols (executables can be stripped -# down further with -x or, if they load no bundles, with no options at all). - -#STRIPFLAGS = -S - - -######################################################################### -# Put rules to extend the behavior of the standard Makefiles here. Include them in -# the dependency tree via cvariables like AFTER_INSTALL in the Makefile.preamble. -# -# You should avoid redefining things like "install" or "app", as they are -# owned by the top-level Makefile API and no context has been set up for where -# derived files should go. -# diff --git a/db.subproj/db.subproj/Makefile.preamble b/db.subproj/db.subproj/Makefile.preamble deleted file mode 100644 index c1624b4..0000000 --- a/db.subproj/db.subproj/Makefile.preamble +++ /dev/null @@ -1,137 +0,0 @@ -############################################################################### -# Makefile.preamble -# Copyright 1997, Apple Computer, Inc. -# -# Use this makefile for configuring the standard application makefiles -# associated with ProjectBuilder. It is included before the main makefile. -# In Makefile.preamble you set attributes for a project, so they are available -# to the project's makefiles. In contrast, you typically write additional rules or -# override built-in behavior in the Makefile.postamble. -# -# Each directory in a project tree (main project plus subprojects) should -# have its own Makefile.preamble and Makefile.postamble. -############################################################################### -# -# Before the main makefile is included for this project, you may set: -# -# MAKEFILEDIR: Directory in which to find $(MAKEFILE) -# MAKEFILE: Top level mechanism Makefile (e.g., app.make, bundle.make) - -# Compiler/linker flags added to the defaults: The OTHER_* variables will be -# inherited by all nested sub-projects, but the LOCAL_ versions of the same -# variables will not. Put your -I, -D, -U, and -L flags in ProjectBuilder's -# Build Attributes inspector if at all possible. To override the default flags -# that get passed to ${CC} (e.g. change -O to -O2), see Makefile.postamble. The -# variables below are *inputs* to the build process and distinct from the override -# settings done (less often) in the Makefile.postamble. -# -# OTHER_CFLAGS, LOCAL_CFLAGS: additional flags to pass to the compiler -# Note that $(OTHER_CFLAGS) and $(LOCAL_CFLAGS) are used for .h, ...c, .m, -# .cc, .cxx, .C, and .M files. There is no need to respecify the -# flags in OTHER_MFLAGS, etc. -# OTHER_MFLAGS, LOCAL_MFLAGS: additional flags for .m files -# OTHER_CCFLAGS, LOCAL_CCFLAGS: additional flags for .cc, .cxx, and ...C files -# OTHER_MMFLAGS, LOCAL_MMFLAGS: additional flags for .mm and .M files -# OTHER_PRECOMPFLAGS, LOCAL_PRECOMPFLAGS: additional flags used when -# precompiling header files -# OTHER_LDFLAGS, LOCAL_LDFLAGS: additional flags passed to ld and libtool -# OTHER_PSWFLAGS, LOCAL_PSWFLAGS: additional flags passed to pswrap -# OTHER_RPCFLAGS, LOCAL_RPCFLAGS: additional flags passed to rpcgen -# OTHER_YFLAGS, LOCAL_YFLAGS: additional flags passed to yacc -# OTHER_LFLAGS, LOCAL_LFLAGS: additional flags passed to lex - -# These variables provide hooks enabling you to add behavior at almost every -# stage of the make: -# -# BEFORE_PREBUILD: targets to build before installing headers for a subproject -# AFTER_PREBUILD: targets to build after installing headers for a subproject -# BEFORE_BUILD_RECURSION: targets to make before building subprojects -# BEFORE_BUILD: targets to make before a build, but after subprojects -# AFTER_BUILD: targets to make after a build -# -# BEFORE_INSTALL: targets to build before installing the product -# AFTER_INSTALL: targets to build after installing the product -# BEFORE_POSTINSTALL: targets to build before postinstalling every subproject -# AFTER_POSTINSTALL: targts to build after postinstalling every subproject -# -# BEFORE_INSTALLHDRS: targets to build before installing headers for a -# subproject -# AFTER_INSTALLHDRS: targets to build after installing headers for a subproject -# BEFORE_INSTALLSRC: targets to build before installing source for a subproject -# AFTER_INSTALLSRC: targets to build after installing source for a subproject -# -# BEFORE_DEPEND: targets to build before building dependencies for a -# subproject -# AFTER_DEPEND: targets to build after building dependencies for a -# subproject -# -# AUTOMATIC_DEPENDENCY_INFO: if YES, then the dependency file is -# updated every time the project is built. If NO, the dependency -# file is only built when the depend target is invoked. - -# Framework-related variables: -# FRAMEWORK_DLL_INSTALLDIR: On Windows platforms, this variable indicates -# where to put the framework's DLL. This variable defaults to -# $(INSTALLDIR)/../Executables - -# Library-related variables: -# PUBLIC_HEADER_DIR: Determines where public exported header files -# should be installed. Do not include $(DSTROOT) in this value -- -# it is prefixed automatically. For library projects you should -# set this to something like /Developer/Headers/$(NAME). Do not set -# this variable for framework projects unless you do not want the -# header files included in the framework. -# PRIVATE_HEADER_DIR: Determines where private exported header files -# should be installed. Do not include $(DSTROOT) in this value -- -# it is prefixed automatically. -# LIBRARY_STYLE: This may be either STATIC or DYNAMIC, and determines -# whether the libraries produced are statically linked when they -# are used or if they are dynamically loadable. This defaults to -# DYNAMIC. -# LIBRARY_DLL_INSTALLDIR: On Windows platforms, this variable indicates -# where to put the library's DLL. This variable defaults to -# $(INSTALLDIR)/../Executables -# -# INSTALL_AS_USER: owner of the intalled products (default root) -# INSTALL_AS_GROUP: group of the installed products (default wheel) -# INSTALL_PERMISSIONS: permissions of the installed product (default o+rX) -# -# OTHER_RECURSIVE_VARIABLES: The names of variables which you want to be -# passed on the command line to recursive invocations of make. Note that -# the values in OTHER_*FLAGS are inherited by subprojects automatically -- -# you do not have to (and shouldn't) add OTHER_*FLAGS to -# OTHER_RECURSIVE_VARIABLES. - -# Additional headers to export beyond those in the PB.project: -# OTHER_PUBLIC_HEADERS -# OTHER_PROJECT_HEADERS -# OTHER_PRIVATE_HEADERS - -# Additional files for the project's product: <> -# OTHER_RESOURCES: (non-localized) resources for this project -# OTHER_OFILES: relocatables to be linked into this project -# OTHER_LIBS: more libraries to link against -# OTHER_PRODUCT_DEPENDS: other dependencies of this project -# OTHER_SOURCEFILES: other source files maintained by .pre/postamble -# OTHER_GARBAGE: additional files to be removed by `make clean' - -# Set this to YES if you don't want a final libtool call for a library/framework. -# BUILD_OFILES_LIST_ONLY - -# To include a version string, project source must exist in a directory named -# $(NAME).%d[.%d][.%d] and the following line must be uncommented. -# OTHER_GENERATED_OFILES = $(VERS_OFILE) - -# This definition will suppress stripping of debug symbols when an executable -# is installed. By default it is YES. -# STRIP_ON_INSTALL = NO - -# Uncomment to suppress generation of a KeyValueCoding index when installing -# frameworks (This index is used by WOB and IB to determine keys available -# for an object). Set to YES by default. -# PREINDEX_FRAMEWORK = NO - -# Change this definition to install projects somewhere other than the -# standard locations. NEXT_ROOT defaults to "C:/Apple" on Windows systems -# and "" on other systems. -DSTROOT = $(HOME) diff --git a/db.subproj/db.subproj/PB.project b/db.subproj/db.subproj/PB.project deleted file mode 100644 index b93a5d0..0000000 --- a/db.subproj/db.subproj/PB.project +++ /dev/null @@ -1,23 +0,0 @@ -{ - DYNAMIC_CODE_GEN = YES; - FILESTABLE = { - H_FILES = (); - OTHER_LINKED = (db.c); - OTHER_SOURCES = (Makefile.preamble, Makefile, Makefile.postamble); - SUBPROJECTS = (); - }; - LANGUAGE = English; - MAKEFILEDIR = "$(MAKEFILEPATH)/pb_makefiles"; - NEXTSTEP_BUILDTOOL = /bin/gnumake; - NEXTSTEP_JAVA_COMPILER = /usr/bin/javac; - NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc; - PDO_UNIX_BUILDTOOL = $NEXT_ROOT/Developer/bin/make; - PDO_UNIX_JAVA_COMPILER = "$(JDKBINDIR)/javac"; - PDO_UNIX_OBJCPLUS_COMPILER = "$(NEXTDEV_BIN)/gcc"; - PROJECTNAME = db; - PROJECTTYPE = Component; - PROJECTVERSION = 2.8; - WINDOWS_BUILDTOOL = $NEXT_ROOT/Developer/Executables/make; - WINDOWS_JAVA_COMPILER = "$(JDKBINDIR)/javac.exe"; - WINDOWS_OBJCPLUS_COMPILER = "$(DEVDIR)/gcc"; -} diff --git a/db.subproj/db.subproj/db.c b/db.subproj/db.subproj/db.c deleted file mode 100644 index 086e14d..0000000 --- a/db.subproj/db.subproj/db.c +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * 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. - */ - - -#include - -#include -#include -#include -#include - -#include - -DB * -dbopen(fname, flags, mode, type, openinfo) - const char *fname; - int flags, mode; - DBTYPE type; - const void *openinfo; -{ - -#define DB_FLAGS (DB_LOCK | DB_SHMEM | DB_TXN) -#define USE_OPEN_FLAGS \ - (O_CREAT | O_EXCL | O_EXLOCK | O_NONBLOCK | O_RDONLY | \ - O_RDWR | O_SHLOCK | O_TRUNC) - - if ((flags & ~(USE_OPEN_FLAGS | DB_FLAGS)) == 0) - switch (type) { - case DB_BTREE: - return (__bt_open(fname, flags & USE_OPEN_FLAGS, - mode, openinfo, flags & DB_FLAGS)); - case DB_HASH: - return (__hash_open(fname, flags & USE_OPEN_FLAGS, - mode, openinfo, flags & DB_FLAGS)); - case DB_RECNO: - return (__rec_open(fname, flags & USE_OPEN_FLAGS, - mode, openinfo, flags & DB_FLAGS)); - } - errno = EINVAL; - return (NULL); -} - -static int -__dberr() -{ - return (RET_ERROR); -} - -/* - * __DBPANIC -- Stop. - * - * Parameters: - * dbp: pointer to the DB structure. - */ -void -__dbpanic(dbp) - DB *dbp; -{ - /* The only thing that can succeed is a close. */ - dbp->del = (int (*)())__dberr; - dbp->fd = (int (*)())__dberr; - dbp->get = (int (*)())__dberr; - dbp->put = (int (*)())__dberr; - dbp->seq = (int (*)())__dberr; - dbp->sync = (int (*)())__dberr; -} diff --git a/db.subproj/hash.subproj/Makefile b/db.subproj/hash.subproj/Makefile deleted file mode 100644 index f27af80..0000000 --- a/db.subproj/hash.subproj/Makefile +++ /dev/null @@ -1,48 +0,0 @@ -# -# Generated by the NeXT Project Builder. -# -# NOTE: Do NOT change this file -- Project Builder maintains it. -# -# Put all of your customizations in files called Makefile.preamble -# and Makefile.postamble (both optional), and Makefile will include them. -# - -NAME = hash - -PROJECTVERSION = 2.8 -PROJECT_TYPE = Component - -HFILES = extern.h hash.h page.h search.h - -CFILES = hash.c hash_bigkey.c hash_buf.c hash_func.c hash_log2.c\ - hash_page.c hsearch.c ndbm.c - -OTHERSRCS = Makefile.preamble Makefile Makefile.postamble - - -MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles -CODE_GEN_STYLE = DYNAMIC -MAKEFILE = subproj.make -LIBS = -DEBUG_LIBS = $(LIBS) -PROF_LIBS = $(LIBS) - - - - -NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc -WINDOWS_OBJCPLUS_COMPILER = $(DEVDIR)/gcc -PDO_UNIX_OBJCPLUS_COMPILER = $(NEXTDEV_BIN)/gcc -NEXTSTEP_JAVA_COMPILER = /usr/bin/javac -WINDOWS_JAVA_COMPILER = $(JDKBINDIR)/javac.exe -PDO_UNIX_JAVA_COMPILER = $(JDKBINDIR)/javac - -include $(MAKEFILEDIR)/platform.make - --include Makefile.preamble - -include $(MAKEFILEDIR)/$(MAKEFILE) - --include Makefile.postamble - --include Makefile.dependencies diff --git a/db.subproj/hash.subproj/Makefile.postamble b/db.subproj/hash.subproj/Makefile.postamble deleted file mode 100644 index 411cde6..0000000 --- a/db.subproj/hash.subproj/Makefile.postamble +++ /dev/null @@ -1,100 +0,0 @@ -############################################################################### -# Makefile.postamble -# Copyright 1997, Apple Computer, Inc. -# -# Use this makefile, which is imported after all other makefiles, to -# override attributes for a project's Makefile environment. This allows you -# to take advantage of the environment set up by the other Makefiles. -# You can also define custom rules at the end of this file. -# -############################################################################### -# -# These variables are exported by the standard makefiles and can be -# used in any customizations you make. They are *outputs* of -# the Makefiles and should be used, not set. -# -# PRODUCTS: products to install. All of these products will be placed in -# the directory $(DSTROOT)$(INSTALLDIR) -# GLOBAL_RESOURCE_DIR: The directory to which resources are copied. -# LOCAL_RESOURCE_DIR: The directory to which localized resources are copied. -# OFILE_DIR: Directory into which .o object files are generated. -# DERIVED_SRC_DIR: Directory used for all other derived files -# -# ALL_CFLAGS: flags to pass when compiling .c files -# ALL_MFLAGS: flags to pass when compiling .m files -# ALL_CCFLAGS: flags to pass when compiling .cc, .cxx, and .C files -# ALL_MMFLAGS: flags to pass when compiling .mm, .mxx, and .M files -# ALL_PRECOMPFLAGS: flags to pass when precompiling .h files -# ALL_LDFLAGS: flags to pass when linking object files -# ALL_LIBTOOL_FLAGS: flags to pass when libtooling object files -# ALL_PSWFLAGS: flags to pass when processing .psw and .pswm (pswrap) files -# ALL_RPCFLAGS: flags to pass when processing .rpc (rpcgen) files -# ALL_YFLAGS: flags to pass when processing .y (yacc) files -# ALL_LFLAGS: flags to pass when processing .l (lex) files -# -# NAME: name of application, bundle, subproject, palette, etc. -# LANGUAGES: langages in which the project is written (default "English") -# English_RESOURCES: localized resources (e.g. nib's, images) of project -# GLOBAL_RESOURCES: non-localized resources of project -# -# SRCROOT: base directory in which to place the new source files -# SRCPATH: relative path from SRCROOT to present subdirectory -# -# INSTALLDIR: Directory the product will be installed into by 'install' target -# PUBLIC_HDR_INSTALLDIR: where to install public headers. Don't forget -# to prefix this with DSTROOT when you use it. -# PRIVATE_HDR_INSTALLDIR: where to install private headers. Don't forget -# to prefix this with DSTROOT when you use it. -# -# EXECUTABLE_EXT: Executable extension for the platform (i.e. .exe on Windows) -# -############################################################################### - -# Some compiler flags can be overridden here for certain build situations. -# -# WARNING_CFLAGS: flag used to set warning level (defaults to -Wmost) -# DEBUG_SYMBOLS_CFLAGS: debug-symbol flag passed to all builds (defaults -# to -g) -# DEBUG_BUILD_CFLAGS: flags passed during debug builds (defaults to -DDEBUG) -# OPTIMIZE_BUILD_CFLAGS: flags passed during optimized builds (defaults -# to -O) -# PROFILE_BUILD_CFLAGS: flags passed during profile builds (defaults -# to -pg -DPROFILE) -# LOCAL_DIR_INCLUDE_DIRECTIVE: flag used to add current directory to -# the include path (defaults to -I.) -# DEBUG_BUILD_LDFLAGS, OPTIMIZE_BUILD_LDFLAGS, PROFILE_BUILD_LDFLAGS: flags -# passed to ld/libtool (defaults to nothing) - - -# Library and Framework projects only: -# INSTALL_NAME_DIRECTIVE: This directive ensures that executables linked -# against the framework will run against the correct version even if -# the current version of the framework changes. You may override this -# to "" as an alternative to using the DYLD_LIBRARY_PATH during your -# development cycle, but be sure to restore it before installing. - - -# Ownership and permissions of files installed by 'install' target - -#INSTALL_AS_USER = root - # User/group ownership -#INSTALL_AS_GROUP = wheel - # (probably want to set both of these) -#INSTALL_PERMISSIONS = - # If set, 'install' chmod's executable to this - - -# Options to strip. Note: -S strips debugging symbols (executables can be stripped -# down further with -x or, if they load no bundles, with no options at all). - -#STRIPFLAGS = -S - - -######################################################################### -# Put rules to extend the behavior of the standard Makefiles here. Include them in -# the dependency tree via cvariables like AFTER_INSTALL in the Makefile.preamble. -# -# You should avoid redefining things like "install" or "app", as they are -# owned by the top-level Makefile API and no context has been set up for where -# derived files should go. -# diff --git a/db.subproj/hash.subproj/Makefile.preamble b/db.subproj/hash.subproj/Makefile.preamble deleted file mode 100644 index c1624b4..0000000 --- a/db.subproj/hash.subproj/Makefile.preamble +++ /dev/null @@ -1,137 +0,0 @@ -############################################################################### -# Makefile.preamble -# Copyright 1997, Apple Computer, Inc. -# -# Use this makefile for configuring the standard application makefiles -# associated with ProjectBuilder. It is included before the main makefile. -# In Makefile.preamble you set attributes for a project, so they are available -# to the project's makefiles. In contrast, you typically write additional rules or -# override built-in behavior in the Makefile.postamble. -# -# Each directory in a project tree (main project plus subprojects) should -# have its own Makefile.preamble and Makefile.postamble. -############################################################################### -# -# Before the main makefile is included for this project, you may set: -# -# MAKEFILEDIR: Directory in which to find $(MAKEFILE) -# MAKEFILE: Top level mechanism Makefile (e.g., app.make, bundle.make) - -# Compiler/linker flags added to the defaults: The OTHER_* variables will be -# inherited by all nested sub-projects, but the LOCAL_ versions of the same -# variables will not. Put your -I, -D, -U, and -L flags in ProjectBuilder's -# Build Attributes inspector if at all possible. To override the default flags -# that get passed to ${CC} (e.g. change -O to -O2), see Makefile.postamble. The -# variables below are *inputs* to the build process and distinct from the override -# settings done (less often) in the Makefile.postamble. -# -# OTHER_CFLAGS, LOCAL_CFLAGS: additional flags to pass to the compiler -# Note that $(OTHER_CFLAGS) and $(LOCAL_CFLAGS) are used for .h, ...c, .m, -# .cc, .cxx, .C, and .M files. There is no need to respecify the -# flags in OTHER_MFLAGS, etc. -# OTHER_MFLAGS, LOCAL_MFLAGS: additional flags for .m files -# OTHER_CCFLAGS, LOCAL_CCFLAGS: additional flags for .cc, .cxx, and ...C files -# OTHER_MMFLAGS, LOCAL_MMFLAGS: additional flags for .mm and .M files -# OTHER_PRECOMPFLAGS, LOCAL_PRECOMPFLAGS: additional flags used when -# precompiling header files -# OTHER_LDFLAGS, LOCAL_LDFLAGS: additional flags passed to ld and libtool -# OTHER_PSWFLAGS, LOCAL_PSWFLAGS: additional flags passed to pswrap -# OTHER_RPCFLAGS, LOCAL_RPCFLAGS: additional flags passed to rpcgen -# OTHER_YFLAGS, LOCAL_YFLAGS: additional flags passed to yacc -# OTHER_LFLAGS, LOCAL_LFLAGS: additional flags passed to lex - -# These variables provide hooks enabling you to add behavior at almost every -# stage of the make: -# -# BEFORE_PREBUILD: targets to build before installing headers for a subproject -# AFTER_PREBUILD: targets to build after installing headers for a subproject -# BEFORE_BUILD_RECURSION: targets to make before building subprojects -# BEFORE_BUILD: targets to make before a build, but after subprojects -# AFTER_BUILD: targets to make after a build -# -# BEFORE_INSTALL: targets to build before installing the product -# AFTER_INSTALL: targets to build after installing the product -# BEFORE_POSTINSTALL: targets to build before postinstalling every subproject -# AFTER_POSTINSTALL: targts to build after postinstalling every subproject -# -# BEFORE_INSTALLHDRS: targets to build before installing headers for a -# subproject -# AFTER_INSTALLHDRS: targets to build after installing headers for a subproject -# BEFORE_INSTALLSRC: targets to build before installing source for a subproject -# AFTER_INSTALLSRC: targets to build after installing source for a subproject -# -# BEFORE_DEPEND: targets to build before building dependencies for a -# subproject -# AFTER_DEPEND: targets to build after building dependencies for a -# subproject -# -# AUTOMATIC_DEPENDENCY_INFO: if YES, then the dependency file is -# updated every time the project is built. If NO, the dependency -# file is only built when the depend target is invoked. - -# Framework-related variables: -# FRAMEWORK_DLL_INSTALLDIR: On Windows platforms, this variable indicates -# where to put the framework's DLL. This variable defaults to -# $(INSTALLDIR)/../Executables - -# Library-related variables: -# PUBLIC_HEADER_DIR: Determines where public exported header files -# should be installed. Do not include $(DSTROOT) in this value -- -# it is prefixed automatically. For library projects you should -# set this to something like /Developer/Headers/$(NAME). Do not set -# this variable for framework projects unless you do not want the -# header files included in the framework. -# PRIVATE_HEADER_DIR: Determines where private exported header files -# should be installed. Do not include $(DSTROOT) in this value -- -# it is prefixed automatically. -# LIBRARY_STYLE: This may be either STATIC or DYNAMIC, and determines -# whether the libraries produced are statically linked when they -# are used or if they are dynamically loadable. This defaults to -# DYNAMIC. -# LIBRARY_DLL_INSTALLDIR: On Windows platforms, this variable indicates -# where to put the library's DLL. This variable defaults to -# $(INSTALLDIR)/../Executables -# -# INSTALL_AS_USER: owner of the intalled products (default root) -# INSTALL_AS_GROUP: group of the installed products (default wheel) -# INSTALL_PERMISSIONS: permissions of the installed product (default o+rX) -# -# OTHER_RECURSIVE_VARIABLES: The names of variables which you want to be -# passed on the command line to recursive invocations of make. Note that -# the values in OTHER_*FLAGS are inherited by subprojects automatically -- -# you do not have to (and shouldn't) add OTHER_*FLAGS to -# OTHER_RECURSIVE_VARIABLES. - -# Additional headers to export beyond those in the PB.project: -# OTHER_PUBLIC_HEADERS -# OTHER_PROJECT_HEADERS -# OTHER_PRIVATE_HEADERS - -# Additional files for the project's product: <> -# OTHER_RESOURCES: (non-localized) resources for this project -# OTHER_OFILES: relocatables to be linked into this project -# OTHER_LIBS: more libraries to link against -# OTHER_PRODUCT_DEPENDS: other dependencies of this project -# OTHER_SOURCEFILES: other source files maintained by .pre/postamble -# OTHER_GARBAGE: additional files to be removed by `make clean' - -# Set this to YES if you don't want a final libtool call for a library/framework. -# BUILD_OFILES_LIST_ONLY - -# To include a version string, project source must exist in a directory named -# $(NAME).%d[.%d][.%d] and the following line must be uncommented. -# OTHER_GENERATED_OFILES = $(VERS_OFILE) - -# This definition will suppress stripping of debug symbols when an executable -# is installed. By default it is YES. -# STRIP_ON_INSTALL = NO - -# Uncomment to suppress generation of a KeyValueCoding index when installing -# frameworks (This index is used by WOB and IB to determine keys available -# for an object). Set to YES by default. -# PREINDEX_FRAMEWORK = NO - -# Change this definition to install projects somewhere other than the -# standard locations. NEXT_ROOT defaults to "C:/Apple" on Windows systems -# and "" on other systems. -DSTROOT = $(HOME) diff --git a/db.subproj/hash.subproj/PB.project b/db.subproj/hash.subproj/PB.project deleted file mode 100644 index 6cfb553..0000000 --- a/db.subproj/hash.subproj/PB.project +++ /dev/null @@ -1,32 +0,0 @@ -{ - DYNAMIC_CODE_GEN = YES; - FILESTABLE = { - H_FILES = (extern.h, hash.h, page.h, search.h); - OTHER_LINKED = ( - hash.c, - hash_bigkey.c, - hash_buf.c, - hash_func.c, - hash_log2.c, - hash_page.c, - hsearch.c, - ndbm.c - ); - OTHER_SOURCES = (Makefile.preamble, Makefile, Makefile.postamble); - SUBPROJECTS = (); - }; - LANGUAGE = English; - MAKEFILEDIR = "$(MAKEFILEPATH)/pb_makefiles"; - NEXTSTEP_BUILDTOOL = /bin/gnumake; - NEXTSTEP_JAVA_COMPILER = /usr/bin/javac; - NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc; - PDO_UNIX_BUILDTOOL = $NEXT_ROOT/Developer/bin/make; - PDO_UNIX_JAVA_COMPILER = "$(JDKBINDIR)/javac"; - PDO_UNIX_OBJCPLUS_COMPILER = "$(NEXTDEV_BIN)/gcc"; - PROJECTNAME = hash; - PROJECTTYPE = Component; - PROJECTVERSION = 2.8; - WINDOWS_BUILDTOOL = $NEXT_ROOT/Developer/Executables/make; - WINDOWS_JAVA_COMPILER = "$(JDKBINDIR)/javac.exe"; - WINDOWS_OBJCPLUS_COMPILER = "$(DEVDIR)/gcc"; -} diff --git a/db.subproj/hash.subproj/extern.h b/db.subproj/hash.subproj/extern.h deleted file mode 100644 index cf678d2..0000000 --- a/db.subproj/hash.subproj/extern.h +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * 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. - */ - -BUFHEAD *__add_ovflpage __P((HTAB *, BUFHEAD *)); -int __addel __P((HTAB *, BUFHEAD *, const DBT *, const DBT *)); -int __big_delete __P((HTAB *, BUFHEAD *)); -int __big_insert __P((HTAB *, BUFHEAD *, const DBT *, const DBT *)); -int __big_keydata __P((HTAB *, BUFHEAD *, DBT *, DBT *, int)); -int __big_return __P((HTAB *, BUFHEAD *, int, DBT *, int)); -int __big_split __P((HTAB *, BUFHEAD *, BUFHEAD *, BUFHEAD *, - int, u_int, SPLIT_RETURN *)); -int __buf_free __P((HTAB *, int, int)); -void __buf_init __P((HTAB *, int)); -u_int __call_hash __P((HTAB *, char *, int)); -int __delpair __P((HTAB *, BUFHEAD *, int)); -int __expand_table __P((HTAB *)); -int __find_bigpair __P((HTAB *, BUFHEAD *, int, char *, int)); -u_short __find_last_page __P((HTAB *, BUFHEAD **)); -void __free_ovflpage __P((HTAB *, BUFHEAD *)); -BUFHEAD *__get_buf __P((HTAB *, u_int, BUFHEAD *, int)); -int __get_page __P((HTAB *, char *, u_int, int, int, int)); -int __init_bitmap __P((HTAB *, int, int, int)); -u_int __log2 __P((u_int)); -int __put_page __P((HTAB *, char *, u_int, int, int)); -void __reclaim_buf __P((HTAB *, BUFHEAD *)); -int __split_page __P((HTAB *, u_int, u_int)); - -/* Default hash routine. */ -extern u_int32_t (*__default_hash) __P((const void *, size_t)); - -#ifdef HASH_STATISTICS -extern long hash_accesses, hash_collisions, hash_expansions, hash_overflows; -#endif diff --git a/db.subproj/hash.subproj/hash.c b/db.subproj/hash.subproj/hash.c deleted file mode 100644 index 40b4761..0000000 --- a/db.subproj/hash.subproj/hash.c +++ /dev/null @@ -1,1012 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Margo Seltzer. - * - * 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 -#include - -#include -#include -#include -#include -#include -#include -#ifdef DEBUG -#include -#endif - -#include -#include "hash.h" -#include "page.h" -#include "extern.h" - -static int alloc_segs __P((HTAB *, int)); -static int flush_meta __P((HTAB *)); -static int hash_access __P((HTAB *, ACTION, DBT *, DBT *)); -static int hash_close __P((DB *)); -static int hash_delete __P((const DB *, const DBT *, u_int)); -static int hash_fd __P((const DB *)); -static int hash_get __P((const DB *, const DBT *, DBT *, u_int)); -static int hash_put __P((const DB *, DBT *, const DBT *, u_int)); -static void *hash_realloc __P((SEGMENT **, int, int)); -static int hash_seq __P((const DB *, DBT *, DBT *, u_int)); -static int hash_sync __P((const DB *, u_int)); -static int hdestroy __P((HTAB *)); -static HTAB *init_hash __P((HTAB *, const char *, HASHINFO *)); -static int init_htab __P((HTAB *, int)); -#if BYTE_ORDER == LITTLE_ENDIAN -static void swap_header __P((HTAB *)); -static void swap_header_copy __P((HASHHDR *, HASHHDR *)); -#endif - -/* Fast arithmetic, relying on powers of 2, */ -#define MOD(x, y) ((x) & ((y) - 1)) - -#define RETURN_ERROR(ERR, LOC) { save_errno = ERR; goto LOC; } - -/* Return values */ -#define SUCCESS (0) -#define ERROR (-1) -#define ABNORMAL (1) - -#ifdef HASH_STATISTICS -long hash_accesses, hash_collisions, hash_expansions, hash_overflows; -#endif - -/************************** INTERFACE ROUTINES ***************************/ -/* OPEN/CLOSE */ - -extern DB * -__hash_open(file, flags, mode, info, dflags) - const char *file; - int flags, mode, dflags; - const HASHINFO *info; /* Special directives for create */ -{ - HTAB *hashp; - struct stat statbuf; - DB *dbp; - int bpages, hdrsize, new_table, nsegs, save_errno; - - if ((flags & O_ACCMODE) == O_WRONLY) { - errno = EINVAL; - return (NULL); - } - - if (!(hashp = (HTAB *)calloc(1, sizeof(HTAB)))) - return (NULL); - hashp->fp = -1; - - /* - * Even if user wants write only, we need to be able to read - * the actual file, so we need to open it read/write. But, the - * field in the hashp structure needs to be accurate so that - * we can check accesses. - */ - hashp->flags = flags; - - new_table = 0; - if (!file || (flags & O_TRUNC) || - (stat(file, &statbuf) && (errno == ENOENT))) { - if (errno == ENOENT) - errno = 0; /* Just in case someone looks at errno */ - new_table = 1; - } - if (file) { - if ((hashp->fp = open(file, flags, mode)) == -1) - RETURN_ERROR(errno, error0); - (void)fcntl(hashp->fp, F_SETFD, 1); - } - if (new_table) { - if (!(hashp = init_hash(hashp, file, (HASHINFO *)info))) - RETURN_ERROR(errno, error1); - } else { - /* Table already exists */ - if (info && info->hash) - hashp->hash = info->hash; - else - hashp->hash = __default_hash; - - hdrsize = read(hashp->fp, &hashp->hdr, sizeof(HASHHDR)); -#if BYTE_ORDER == LITTLE_ENDIAN - swap_header(hashp); -#endif - if (hdrsize == -1) - RETURN_ERROR(errno, error1); - if (hdrsize != sizeof(HASHHDR)) - RETURN_ERROR(EFTYPE, error1); - /* Verify file type, versions and hash function */ - if (hashp->MAGIC != HASHMAGIC) - RETURN_ERROR(EFTYPE, error1); -#define OLDHASHVERSION 1 - if (hashp->VERSION != HASHVERSION && - hashp->VERSION != OLDHASHVERSION) - RETURN_ERROR(EFTYPE, error1); - if (hashp->hash(CHARKEY, sizeof(CHARKEY)) != hashp->H_CHARKEY) - RETURN_ERROR(EFTYPE, error1); - /* - * Figure out how many segments we need. Max_Bucket is the - * maximum bucket number, so the number of buckets is - * max_bucket + 1. - */ - nsegs = (hashp->MAX_BUCKET + 1 + hashp->SGSIZE - 1) / - hashp->SGSIZE; - hashp->nsegs = 0; - if (alloc_segs(hashp, nsegs)) - /* - * If alloc_segs fails, table will have been destroyed - * and errno will have been set. - */ - return (NULL); - /* Read in bitmaps */ - bpages = (hashp->SPARES[hashp->OVFL_POINT] + - (hashp->BSIZE << BYTE_SHIFT) - 1) >> - (hashp->BSHIFT + BYTE_SHIFT); - - hashp->nmaps = bpages; - (void)memset(&hashp->mapp[0], 0, bpages * sizeof(u_long *)); - } - - /* Initialize Buffer Manager */ - if (info && info->cachesize) - __buf_init(hashp, info->cachesize); - else - __buf_init(hashp, DEF_BUFSIZE); - - hashp->new_file = new_table; - hashp->save_file = file && (hashp->flags & O_RDWR); - hashp->cbucket = -1; - if (!(dbp = (DB *)malloc(sizeof(DB)))) { - save_errno = errno; - hdestroy(hashp); - errno = save_errno; - return (NULL); - } - dbp->internal = hashp; - dbp->close = hash_close; - dbp->del = hash_delete; - dbp->fd = hash_fd; - dbp->get = hash_get; - dbp->put = hash_put; - dbp->seq = hash_seq; - dbp->sync = hash_sync; - dbp->type = DB_HASH; - -#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", - "init_htab:", - "TABLE POINTER ", hashp, - "BUCKET SIZE ", hashp->BSIZE, - "BUCKET SHIFT ", hashp->BSHIFT, - "DIRECTORY SIZE ", hashp->DSIZE, - "SEGMENT SIZE ", hashp->SGSIZE, - "SEGMENT SHIFT ", hashp->SSHIFT, - "FILL FACTOR ", hashp->FFACTOR, - "MAX BUCKET ", hashp->MAX_BUCKET, - "OVFL POINT ", hashp->OVFL_POINT, - "LAST FREED ", hashp->LAST_FREED, - "HIGH MASK ", hashp->HIGH_MASK, - "LOW MASK ", hashp->LOW_MASK, - "NSEGS ", hashp->nsegs, - "NKEYS ", hashp->NKEYS); -#endif -#ifdef HASH_STATISTICS - hash_overflows = hash_accesses = hash_collisions = hash_expansions = 0; -#endif - return (dbp); - -error1: - if (hashp != NULL) - (void)close(hashp->fp); - -error0: - free(hashp); - errno = save_errno; - return (NULL); -} - -static int -hash_close(dbp) - DB *dbp; -{ - HTAB *hashp; - int retval; - - if (!dbp) - return (ERROR); - - hashp = (HTAB *)dbp->internal; - retval = hdestroy(hashp); - free(dbp); - return (retval); -} - -static int -hash_fd(dbp) - const DB *dbp; -{ - HTAB *hashp; - - if (!dbp) - return (ERROR); - - hashp = (HTAB *)dbp->internal; - if (hashp->fp == -1) { - errno = ENOENT; - return (-1); - } - return (hashp->fp); -} - -/************************** LOCAL CREATION ROUTINES **********************/ -static HTAB * -init_hash(hashp, file, info) - HTAB *hashp; - const char *file; - HASHINFO *info; -{ - struct stat statbuf; - int nelem; - - nelem = 1; - hashp->NKEYS = 0; - hashp->LORDER = BYTE_ORDER; - hashp->BSIZE = DEF_BUCKET_SIZE; - hashp->BSHIFT = DEF_BUCKET_SHIFT; - hashp->SGSIZE = DEF_SEGSIZE; - hashp->SSHIFT = DEF_SEGSIZE_SHIFT; - hashp->DSIZE = DEF_DIRSIZE; - hashp->FFACTOR = DEF_FFACTOR; - hashp->hash = __default_hash; - memset(hashp->SPARES, 0, sizeof(hashp->SPARES)); - memset(hashp->BITMAPS, 0, sizeof (hashp->BITMAPS)); - - /* Fix bucket size to be optimal for file system */ - if (file != NULL) { - if (stat(file, &statbuf)) - return (NULL); - hashp->BSIZE = statbuf.st_blksize; - hashp->BSHIFT = __log2(hashp->BSIZE); - } - - if (info) { - if (info->bsize) { - /* Round pagesize up to power of 2 */ - hashp->BSHIFT = __log2(info->bsize); - hashp->BSIZE = 1 << hashp->BSHIFT; - if (hashp->BSIZE > MAX_BSIZE) { - errno = EINVAL; - return (NULL); - } - } - if (info->ffactor) - hashp->FFACTOR = info->ffactor; - if (info->hash) - hashp->hash = info->hash; - if (info->nelem) - nelem = info->nelem; - if (info->lorder) { - if (info->lorder != BIG_ENDIAN && - info->lorder != LITTLE_ENDIAN) { - errno = EINVAL; - return (NULL); - } - hashp->LORDER = info->lorder; - } - } - /* init_htab should destroy the table and set errno if it fails */ - if (init_htab(hashp, nelem)) - return (NULL); - else - return (hashp); -} -/* - * This calls alloc_segs which may run out of memory. Alloc_segs will destroy - * the table and set errno, so we just pass the error information along. - * - * Returns 0 on No Error - */ -static int -init_htab(hashp, nelem) - HTAB *hashp; - int nelem; -{ - register int nbuckets, nsegs; - int l2; - - /* - * Divide number of elements by the fill factor and determine a - * desired number of buckets. Allocate space for the next greater - * power of two number of buckets. - */ - nelem = (nelem - 1) / hashp->FFACTOR + 1; - - l2 = __log2(MAX(nelem, 2)); - nbuckets = 1 << l2; - - hashp->SPARES[l2] = l2 + 1; - hashp->SPARES[l2 + 1] = l2 + 1; - hashp->OVFL_POINT = l2; - hashp->LAST_FREED = 2; - - /* First bitmap page is at: splitpoint l2 page offset 1 */ - if (__init_bitmap(hashp, OADDR_OF(l2, 1), l2 + 1, 0)) - return (-1); - - hashp->MAX_BUCKET = hashp->LOW_MASK = nbuckets - 1; - hashp->HIGH_MASK = (nbuckets << 1) - 1; - hashp->HDRPAGES = ((MAX(sizeof(HASHHDR), MINHDRSIZE) - 1) >> - hashp->BSHIFT) + 1; - - nsegs = (nbuckets - 1) / hashp->SGSIZE + 1; - nsegs = 1 << __log2(nsegs); - - if (nsegs > hashp->DSIZE) - hashp->DSIZE = nsegs; - return (alloc_segs(hashp, nsegs)); -} - -/********************** DESTROY/CLOSE ROUTINES ************************/ - -/* - * Flushes any changes to the file if necessary and destroys the hashp - * structure, freeing all allocated space. - */ -static int -hdestroy(hashp) - HTAB *hashp; -{ - int i, save_errno; - - save_errno = 0; - -#ifdef HASH_STATISTICS - (void)fprintf(stderr, "hdestroy: accesses %ld collisions %ld\n", - hash_accesses, hash_collisions); - (void)fprintf(stderr, "hdestroy: expansions %ld\n", - hash_expansions); - (void)fprintf(stderr, "hdestroy: overflows %ld\n", - hash_overflows); - (void)fprintf(stderr, "keys %ld maxp %d segmentcount %d\n", - hashp->NKEYS, hashp->MAX_BUCKET, hashp->nsegs); - - for (i = 0; i < NCACHED; i++) - (void)fprintf(stderr, - "spares[%d] = %d\n", i, hashp->SPARES[i]); -#endif - /* - * Call on buffer manager to free buffers, and if required, - * write them to disk. - */ - if (__buf_free(hashp, 1, hashp->save_file)) - save_errno = errno; - if (hashp->dir) { - free(*hashp->dir); /* Free initial segments */ - /* Free extra segments */ - while (hashp->exsegs--) - free(hashp->dir[--hashp->nsegs]); - free(hashp->dir); - } - if (flush_meta(hashp) && !save_errno) - save_errno = errno; - /* Free Bigmaps */ - for (i = 0; i < hashp->nmaps; i++) - if (hashp->mapp[i]) - free(hashp->mapp[i]); - - if (hashp->fp != -1) - (void)close(hashp->fp); - - free(hashp); - - if (save_errno) { - errno = save_errno; - return (ERROR); - } - return (SUCCESS); -} -/* - * Write modified pages to disk - * - * Returns: - * 0 == OK - * -1 ERROR - */ -static int -hash_sync(dbp, flags) - const DB *dbp; - u_int flags; -{ - HTAB *hashp; - - if (flags != 0) { - errno = EINVAL; - return (ERROR); - } - - if (!dbp) - return (ERROR); - - hashp = (HTAB *)dbp->internal; - if (!hashp->save_file) - return (0); - if (__buf_free(hashp, 0, 1) || flush_meta(hashp)) - return (ERROR); - hashp->new_file = 0; - return (0); -} - -/* - * Returns: - * 0 == OK - * -1 indicates that errno should be set - */ -static int -flush_meta(hashp) - HTAB *hashp; -{ - HASHHDR *whdrp; -#if BYTE_ORDER == LITTLE_ENDIAN - HASHHDR whdr; -#endif - int fp, i, wsize; - - if (!hashp->save_file) - return (0); - hashp->MAGIC = HASHMAGIC; - hashp->VERSION = HASHVERSION; - hashp->H_CHARKEY = hashp->hash(CHARKEY, sizeof(CHARKEY)); - - fp = hashp->fp; - whdrp = &hashp->hdr; -#if BYTE_ORDER == LITTLE_ENDIAN - whdrp = &whdr; - swap_header_copy(&hashp->hdr, whdrp); -#endif - if ((lseek(fp, (off_t)0, SEEK_SET) == -1) || - ((wsize = write(fp, whdrp, sizeof(HASHHDR))) == -1)) - return (-1); - else - if (wsize != sizeof(HASHHDR)) { - errno = EFTYPE; - hashp->error = errno; - return (-1); - } - for (i = 0; i < NCACHED; i++) - if (hashp->mapp[i]) - if (__put_page(hashp, (char *)hashp->mapp[i], - hashp->BITMAPS[i], 0, 1)) - return (-1); - return (0); -} - -/*******************************SEARCH ROUTINES *****************************/ -/* - * All the access routines return - * - * Returns: - * 0 on SUCCESS - * 1 to indicate an external ERROR (i.e. key not found, etc) - * -1 to indicate an internal ERROR (i.e. out of memory, etc) - */ -static int -hash_get(dbp, key, data, flag) - const DB *dbp; - const DBT *key; - DBT *data; - u_int flag; -{ - HTAB *hashp; - - hashp = (HTAB *)dbp->internal; - if (flag) { - hashp->error = errno = EINVAL; - return (ERROR); - } - return (hash_access(hashp, HASH_GET, (DBT *)key, data)); -} - -static int -hash_put(dbp, key, data, flag) - const DB *dbp; - DBT *key; - const DBT *data; - u_int flag; -{ - HTAB *hashp; - - hashp = (HTAB *)dbp->internal; - if (flag && flag != R_NOOVERWRITE) { - hashp->error = errno = EINVAL; - return (ERROR); - } - if ((hashp->flags & O_ACCMODE) == O_RDONLY) { - hashp->error = errno = EPERM; - return (ERROR); - } - return (hash_access(hashp, flag == R_NOOVERWRITE ? - HASH_PUTNEW : HASH_PUT, (DBT *)key, (DBT *)data)); -} - -static int -hash_delete(dbp, key, flag) - const DB *dbp; - const DBT *key; - u_int flag; /* Ignored */ -{ - HTAB *hashp; - - hashp = (HTAB *)dbp->internal; - if (flag && flag != R_CURSOR) { - hashp->error = errno = EINVAL; - return (ERROR); - } - if ((hashp->flags & O_ACCMODE) == O_RDONLY) { - hashp->error = errno = EPERM; - return (ERROR); - } - return (hash_access(hashp, HASH_DELETE, (DBT *)key, NULL)); -} - -/* - * Assume that hashp has been set in wrapper routine. - */ -static int -hash_access(hashp, action, key, val) - HTAB *hashp; - ACTION action; - DBT *key, *val; -{ - register BUFHEAD *rbufp; - BUFHEAD *bufp, *save_bufp; - register u_short *bp; - register int n, ndx, off, size; - register char *kp; - u_short pageno; - -#ifdef HASH_STATISTICS - hash_accesses++; -#endif - - off = hashp->BSIZE; - size = key->size; - kp = (char *)key->data; - rbufp = __get_buf(hashp, __call_hash(hashp, kp, size), NULL, 0); - if (!rbufp) - return (ERROR); - save_bufp = rbufp; - - /* Pin the bucket chain */ - rbufp->flags |= BUF_PIN; - for (bp = (u_short *)rbufp->page, n = *bp++, ndx = 1; ndx < n;) - if (bp[1] >= REAL_KEY) { - /* Real key/data pair */ - if (size == off - *bp && - memcmp(kp, rbufp->page + *bp, size) == 0) - goto found; - off = bp[1]; -#ifdef HASH_STATISTICS - hash_collisions++; -#endif - bp += 2; - ndx += 2; - } else if (bp[1] == OVFLPAGE) { - rbufp = __get_buf(hashp, *bp, rbufp, 0); - if (!rbufp) { - save_bufp->flags &= ~BUF_PIN; - return (ERROR); - } - /* FOR LOOP INIT */ - bp = (u_short *)rbufp->page; - n = *bp++; - ndx = 1; - off = hashp->BSIZE; - } else if (bp[1] < REAL_KEY) { - if ((ndx = - __find_bigpair(hashp, rbufp, ndx, kp, size)) > 0) - goto found; - if (ndx == -2) { - bufp = rbufp; - if (!(pageno = - __find_last_page(hashp, &bufp))) { - ndx = 0; - rbufp = bufp; - break; /* FOR */ - } - rbufp = __get_buf(hashp, pageno, bufp, 0); - if (!rbufp) { - save_bufp->flags &= ~BUF_PIN; - return (ERROR); - } - /* FOR LOOP INIT */ - bp = (u_short *)rbufp->page; - n = *bp++; - ndx = 1; - off = hashp->BSIZE; - } else { - save_bufp->flags &= ~BUF_PIN; - return (ERROR); - } - } - - /* Not found */ - switch (action) { - case HASH_PUT: - case HASH_PUTNEW: - if (__addel(hashp, rbufp, key, val)) { - save_bufp->flags &= ~BUF_PIN; - return (ERROR); - } else { - save_bufp->flags &= ~BUF_PIN; - return (SUCCESS); - } - case HASH_GET: - case HASH_DELETE: - default: - save_bufp->flags &= ~BUF_PIN; - return (ABNORMAL); - } - -found: - switch (action) { - case HASH_PUTNEW: - save_bufp->flags &= ~BUF_PIN; - return (ABNORMAL); - case HASH_GET: - bp = (u_short *)rbufp->page; - if (bp[ndx + 1] < REAL_KEY) { - if (__big_return(hashp, rbufp, ndx, val, 0)) - return (ERROR); - } else { - val->data = (u_char *)rbufp->page + (int)bp[ndx + 1]; - val->size = bp[ndx] - bp[ndx + 1]; - } - break; - case HASH_PUT: - if ((__delpair(hashp, rbufp, ndx)) || - (__addel(hashp, rbufp, key, val))) { - save_bufp->flags &= ~BUF_PIN; - return (ERROR); - } - break; - case HASH_DELETE: - if (__delpair(hashp, rbufp, ndx)) - return (ERROR); - break; - default: - abort(); - } - save_bufp->flags &= ~BUF_PIN; - return (SUCCESS); -} - -static int -hash_seq(dbp, key, data, flag) - const DB *dbp; - DBT *key, *data; - u_int flag; -{ - register u_int bucket; - register BUFHEAD *bufp; - HTAB *hashp; - u_short *bp, ndx; - - hashp = (HTAB *)dbp->internal; - if (flag && flag != R_FIRST && flag != R_NEXT) { - hashp->error = errno = EINVAL; - return (ERROR); - } -#ifdef HASH_STATISTICS - hash_accesses++; -#endif - if ((hashp->cbucket < 0) || (flag == R_FIRST)) { - hashp->cbucket = 0; - hashp->cndx = 1; - hashp->cpage = NULL; - } - - for (bp = NULL; !bp || !bp[0]; ) { - if (!(bufp = hashp->cpage)) { - for (bucket = hashp->cbucket; - bucket <= hashp->MAX_BUCKET; - bucket++, hashp->cndx = 1) { - bufp = __get_buf(hashp, bucket, NULL, 0); - if (!bufp) - return (ERROR); - hashp->cpage = bufp; - bp = (u_short *)bufp->page; - if (bp[0]) - break; - } - hashp->cbucket = bucket; - if (hashp->cbucket > hashp->MAX_BUCKET) { - hashp->cbucket = -1; - return (ABNORMAL); - } - } else - bp = (u_short *)hashp->cpage->page; - -#ifdef DEBUG - assert(bp); - assert(bufp); -#endif - while (bp[hashp->cndx + 1] == OVFLPAGE) { - bufp = hashp->cpage = - __get_buf(hashp, bp[hashp->cndx], bufp, 0); - if (!bufp) - return (ERROR); - bp = (u_short *)(bufp->page); - hashp->cndx = 1; - } - if (!bp[0]) { - hashp->cpage = NULL; - ++hashp->cbucket; - } - } - ndx = hashp->cndx; - if (bp[ndx + 1] < REAL_KEY) { - if (__big_keydata(hashp, bufp, key, data, 1)) - return (ERROR); - } else { - key->data = (u_char *)hashp->cpage->page + bp[ndx]; - key->size = (ndx > 1 ? bp[ndx - 1] : hashp->BSIZE) - bp[ndx]; - data->data = (u_char *)hashp->cpage->page + bp[ndx + 1]; - data->size = bp[ndx] - bp[ndx + 1]; - ndx += 2; - if (ndx > bp[0]) { - hashp->cpage = NULL; - hashp->cbucket++; - hashp->cndx = 1; - } else - hashp->cndx = ndx; - } - return (SUCCESS); -} - -/********************************* UTILITIES ************************/ - -/* - * Returns: - * 0 ==> OK - * -1 ==> Error - */ -extern int -__expand_table(hashp) - HTAB *hashp; -{ - u_int old_bucket, new_bucket; - int dirsize, new_segnum, spare_ndx; - -#ifdef HASH_STATISTICS - hash_expansions++; -#endif - new_bucket = ++hashp->MAX_BUCKET; - old_bucket = (hashp->MAX_BUCKET & hashp->LOW_MASK); - - new_segnum = new_bucket >> hashp->SSHIFT; - - /* Check if we need a new segment */ - if (new_segnum >= hashp->nsegs) { - /* Check if we need to expand directory */ - if (new_segnum >= hashp->DSIZE) { - /* Reallocate directory */ - dirsize = hashp->DSIZE * sizeof(SEGMENT *); - if (!hash_realloc(&hashp->dir, dirsize, dirsize << 1)) - return (-1); - hashp->DSIZE = dirsize << 1; - } - if ((hashp->dir[new_segnum] = - (SEGMENT)calloc(hashp->SGSIZE, sizeof(SEGMENT))) == NULL) - return (-1); - hashp->exsegs++; - hashp->nsegs++; - } - /* - * If the split point is increasing (MAX_BUCKET's log base 2 - * * increases), we need to copy the current contents of the spare - * split bucket to the next bucket. - */ - spare_ndx = __log2(hashp->MAX_BUCKET + 1); - if (spare_ndx > hashp->OVFL_POINT) { - hashp->SPARES[spare_ndx] = hashp->SPARES[hashp->OVFL_POINT]; - hashp->OVFL_POINT = spare_ndx; - } - - if (new_bucket > hashp->HIGH_MASK) { - /* Starting a new doubling */ - hashp->LOW_MASK = hashp->HIGH_MASK; - hashp->HIGH_MASK = new_bucket | hashp->LOW_MASK; - } - /* Relocate records to the new bucket */ - return (__split_page(hashp, old_bucket, new_bucket)); -} - -/* - * If realloc guarantees that the pointer is not destroyed if the realloc - * fails, then this routine can go away. - */ -static void * -hash_realloc(p_ptr, oldsize, newsize) - SEGMENT **p_ptr; - int oldsize, newsize; -{ - register void *p; - - if (p = malloc(newsize)) { - memmove(p, *p_ptr, oldsize); - memset((char *)p + oldsize, 0, newsize - oldsize); - free(*p_ptr); - *p_ptr = p; - } - return (p); -} - -extern u_int -__call_hash(hashp, k, len) - HTAB *hashp; - char *k; - int len; -{ - int n, bucket; - - n = hashp->hash(k, len); - bucket = n & hashp->HIGH_MASK; - if (bucket > hashp->MAX_BUCKET) - bucket = bucket & hashp->LOW_MASK; - return (bucket); -} - -/* - * Allocate segment table. On error, destroy the table and set errno. - * - * Returns 0 on success - */ -static int -alloc_segs(hashp, nsegs) - HTAB *hashp; - int nsegs; -{ - register int i; - register SEGMENT store; - - int save_errno; - - if ((hashp->dir = - (SEGMENT *)calloc(hashp->DSIZE, sizeof(SEGMENT *))) == NULL) { - save_errno = errno; - (void)hdestroy(hashp); - errno = save_errno; - return (-1); - } - /* Allocate segments */ - if ((store = - (SEGMENT)calloc(nsegs << hashp->SSHIFT, sizeof(SEGMENT))) == NULL) { - save_errno = errno; - (void)hdestroy(hashp); - errno = save_errno; - return (-1); - } - for (i = 0; i < nsegs; i++, hashp->nsegs++) - hashp->dir[i] = &store[i << hashp->SSHIFT]; - return (0); -} - -#if BYTE_ORDER == LITTLE_ENDIAN -/* - * Hashp->hdr needs to be byteswapped. - */ -static void -swap_header_copy(srcp, destp) - HASHHDR *srcp, *destp; -{ - int i; - - P_32_COPY(srcp->magic, destp->magic); - P_32_COPY(srcp->version, destp->version); - P_32_COPY(srcp->lorder, destp->lorder); - P_32_COPY(srcp->bsize, destp->bsize); - P_32_COPY(srcp->bshift, destp->bshift); - P_32_COPY(srcp->dsize, destp->dsize); - P_32_COPY(srcp->ssize, destp->ssize); - P_32_COPY(srcp->sshift, destp->sshift); - P_32_COPY(srcp->ovfl_point, destp->ovfl_point); - P_32_COPY(srcp->last_freed, destp->last_freed); - P_32_COPY(srcp->max_bucket, destp->max_bucket); - P_32_COPY(srcp->high_mask, destp->high_mask); - P_32_COPY(srcp->low_mask, destp->low_mask); - P_32_COPY(srcp->ffactor, destp->ffactor); - P_32_COPY(srcp->nkeys, destp->nkeys); - P_32_COPY(srcp->hdrpages, destp->hdrpages); - P_32_COPY(srcp->h_charkey, destp->h_charkey); - for (i = 0; i < NCACHED; i++) { - P_32_COPY(srcp->spares[i], destp->spares[i]); - P_16_COPY(srcp->bitmaps[i], destp->bitmaps[i]); - } -} - -static void -swap_header(hashp) - HTAB *hashp; -{ - HASHHDR *hdrp; - int i; - - hdrp = &hashp->hdr; - - M_32_SWAP(hdrp->magic); - M_32_SWAP(hdrp->version); - M_32_SWAP(hdrp->lorder); - M_32_SWAP(hdrp->bsize); - M_32_SWAP(hdrp->bshift); - M_32_SWAP(hdrp->dsize); - M_32_SWAP(hdrp->ssize); - M_32_SWAP(hdrp->sshift); - M_32_SWAP(hdrp->ovfl_point); - M_32_SWAP(hdrp->last_freed); - M_32_SWAP(hdrp->max_bucket); - M_32_SWAP(hdrp->high_mask); - M_32_SWAP(hdrp->low_mask); - M_32_SWAP(hdrp->ffactor); - M_32_SWAP(hdrp->nkeys); - M_32_SWAP(hdrp->hdrpages); - M_32_SWAP(hdrp->h_charkey); - for (i = 0; i < NCACHED; i++) { - M_32_SWAP(hdrp->spares[i]); - M_16_SWAP(hdrp->bitmaps[i]); - } -} -#endif diff --git a/db.subproj/hash.subproj/hash.h b/db.subproj/hash.subproj/hash.h deleted file mode 100644 index 2140387..0000000 --- a/db.subproj/hash.subproj/hash.h +++ /dev/null @@ -1,303 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Margo Seltzer. - * - * 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. - */ - -/* Operations */ -typedef enum { - HASH_GET, HASH_PUT, HASH_PUTNEW, HASH_DELETE, HASH_FIRST, HASH_NEXT -} ACTION; - -/* Buffer Management structures */ -typedef struct _bufhead BUFHEAD; - -struct _bufhead { - BUFHEAD *prev; /* LRU links */ - BUFHEAD *next; /* LRU links */ - BUFHEAD *ovfl; /* Overflow page buffer header */ - u_int addr; /* Address of this page */ - char *page; /* Actual page data */ - char flags; -#define BUF_MOD 0x0001 -#define BUF_DISK 0x0002 -#define BUF_BUCKET 0x0004 -#define BUF_PIN 0x0008 -}; - -#define IS_BUCKET(X) ((X) & BUF_BUCKET) - -typedef BUFHEAD **SEGMENT; - -/* Hash Table Information */ -typedef struct hashhdr { /* Disk resident portion */ - int magic; /* Magic NO for hash tables */ - int version; /* Version ID */ - long lorder; /* Byte Order */ - int bsize; /* Bucket/Page Size */ - int bshift; /* Bucket shift */ - int dsize; /* Directory Size */ - int ssize; /* Segment Size */ - int sshift; /* Segment shift */ - int ovfl_point; /* Where overflow pages are being allocated */ - int last_freed; /* Last overflow page freed */ - int max_bucket; /* ID of Maximum bucket in use */ - int high_mask; /* Mask to modulo into entire table */ - int low_mask; /* Mask to modulo into lower half of table */ - int ffactor; /* Fill factor */ - int nkeys; /* Number of keys in hash table */ - int hdrpages; /* Size of table header */ - int h_charkey; /* value of hash(CHARKEY) */ -#define NCACHED 32 /* number of bit maps and spare points */ - int spares[NCACHED];/* spare pages for overflow */ - u_short bitmaps[NCACHED]; /* address of overflow page bitmaps */ -} HASHHDR; - -typedef struct htab { /* Memory resident data structure */ - HASHHDR hdr; /* Header */ - int nsegs; /* Number of allocated segments */ - int exsegs; /* Number of extra allocated segments */ - u_int32_t /* Hash function */ - (*hash)__P((const void *, size_t)); - int flags; /* Flag values */ - int fp; /* File pointer */ - char *tmp_buf; /* Temporary Buffer for BIG data */ - char *tmp_key; /* Temporary Buffer for BIG keys */ - BUFHEAD *cpage; /* Current page */ - int cbucket; /* Current bucket */ - int cndx; /* Index of next item on cpage */ - int error; /* Error Number -- for DBM compatability */ - int new_file; /* Indicates if fd is backing store or no */ - int save_file; /* Indicates whether we need to flush file at - * exit */ - u_long *mapp[NCACHED]; /* Pointers to page maps */ - int nmaps; /* Initial number of bitmaps */ - int nbufs; /* Number of buffers left to allocate */ - BUFHEAD bufhead; /* Header of buffer lru list */ - SEGMENT *dir; /* Hash Bucket directory */ -} HTAB; - -/* - * Constants - */ -#define MAX_BSIZE 65536 /* 2^16 */ -#define MIN_BUFFERS 6 -#define MINHDRSIZE 512 -#define DEF_BUFSIZE 65536 /* 64 K */ -#define DEF_BUCKET_SIZE 4096 -#define DEF_BUCKET_SHIFT 12 /* log2(BUCKET) */ -#define DEF_SEGSIZE 256 -#define DEF_SEGSIZE_SHIFT 8 /* log2(SEGSIZE) */ -#define DEF_DIRSIZE 256 -#define DEF_FFACTOR 65536 -#define MIN_FFACTOR 4 -#define SPLTMAX 8 -#define CHARKEY "%$sniglet^&" -#define NUMKEY 1038583 -#define BYTE_SHIFT 3 -#define INT_TO_BYTE 2 -#define INT_BYTE_SHIFT 5 -#define ALL_SET ((u_int)0xFFFFFFFF) -#define ALL_CLEAR 0 - -#define PTROF(X) ((BUFHEAD *)((u_int)(X)&~0x3)) -#define ISMOD(X) ((u_int)(X)&0x1) -#define DOMOD(X) ((X) = (char *)((u_int)(X)|0x1)) -#define ISDISK(X) ((u_int)(X)&0x2) -#define DODISK(X) ((X) = (char *)((u_int)(X)|0x2)) - -#define BITS_PER_MAP 32 - -/* Given the address of the beginning of a big map, clear/set the nth bit */ -#define CLRBIT(A, N) ((A)[(N)/BITS_PER_MAP] &= ~(1<<((N)%BITS_PER_MAP))) -#define SETBIT(A, N) ((A)[(N)/BITS_PER_MAP] |= (1<<((N)%BITS_PER_MAP))) -#define ISSET(A, N) ((A)[(N)/BITS_PER_MAP] & (1<<((N)%BITS_PER_MAP))) - -/* Overflow management */ -/* - * Overflow page numbers are allocated per split point. At each doubling of - * the table, we can allocate extra pages. So, an overflow page number has - * the top 5 bits indicate which split point and the lower 11 bits indicate - * which page at that split point is indicated (pages within split points are - * numberered starting with 1). - */ - -#define SPLITSHIFT 11 -#define SPLITMASK 0x7FF -#define SPLITNUM(N) (((u_int)(N)) >> SPLITSHIFT) -#define OPAGENUM(N) ((N) & SPLITMASK) -#define OADDR_OF(S,O) ((u_int)((u_int)(S) << SPLITSHIFT) + (O)) - -#define BUCKET_TO_PAGE(B) \ - (B) + hashp->HDRPAGES + ((B) ? hashp->SPARES[__log2((B)+1)-1] : 0) -#define OADDR_TO_PAGE(B) \ - BUCKET_TO_PAGE ( (1 << SPLITNUM((B))) -1 ) + OPAGENUM((B)); - -/* - * page.h contains a detailed description of the page format. - * - * Normally, keys and data are accessed from offset tables in the top of - * each page which point to the beginning of the key and data. There are - * four flag values which may be stored in these offset tables which indicate - * the following: - * - * - * OVFLPAGE Rather than a key data pair, this pair contains - * the address of an overflow page. The format of - * the pair is: - * OVERFLOW_PAGE_NUMBER OVFLPAGE - * - * PARTIAL_KEY This must be the first key/data pair on a page - * and implies that page contains only a partial key. - * That is, the key is too big to fit on a single page - * so it starts on this page and continues on the next. - * The format of the page is: - * KEY_OFF PARTIAL_KEY OVFL_PAGENO OVFLPAGE - * - * KEY_OFF -- offset of the beginning of the key - * PARTIAL_KEY -- 1 - * OVFL_PAGENO - page number of the next overflow page - * OVFLPAGE -- 0 - * - * FULL_KEY This must be the first key/data pair on the page. It - * is used in two cases. - * - * Case 1: - * There is a complete key on the page but no data - * (because it wouldn't fit). The next page contains - * the data. - * - * Page format it: - * KEY_OFF FULL_KEY OVFL_PAGENO OVFL_PAGE - * - * KEY_OFF -- offset of the beginning of the key - * FULL_KEY -- 2 - * OVFL_PAGENO - page number of the next overflow page - * OVFLPAGE -- 0 - * - * Case 2: - * This page contains no key, but part of a large - * data field, which is continued on the next page. - * - * Page format it: - * DATA_OFF FULL_KEY OVFL_PAGENO OVFL_PAGE - * - * KEY_OFF -- offset of the beginning of the data on - * this page - * FULL_KEY -- 2 - * OVFL_PAGENO - page number of the next overflow page - * OVFLPAGE -- 0 - * - * FULL_KEY_DATA - * This must be the first key/data pair on the page. - * There are two cases: - * - * Case 1: - * This page contains a key and the beginning of the - * data field, but the data field is continued on the - * next page. - * - * Page format is: - * KEY_OFF FULL_KEY_DATA OVFL_PAGENO DATA_OFF - * - * KEY_OFF -- offset of the beginning of the key - * FULL_KEY_DATA -- 3 - * OVFL_PAGENO - page number of the next overflow page - * DATA_OFF -- offset of the beginning of the data - * - * Case 2: - * This page contains the last page of a big data pair. - * There is no key, only the tail end of the data - * on this page. - * - * Page format is: - * DATA_OFF FULL_KEY_DATA - * - * DATA_OFF -- offset of the beginning of the data on - * this page - * FULL_KEY_DATA -- 3 - * OVFL_PAGENO - page number of the next overflow page - * OVFLPAGE -- 0 - * - * OVFL_PAGENO and OVFLPAGE are optional (they are - * not present if there is no next page). - */ - -#define OVFLPAGE 0 -#define PARTIAL_KEY 1 -#define FULL_KEY 2 -#define FULL_KEY_DATA 3 -#define REAL_KEY 4 - -/* Short hands for accessing structure */ -#define BSIZE hdr.bsize -#define BSHIFT hdr.bshift -#define DSIZE hdr.dsize -#define SGSIZE hdr.ssize -#define SSHIFT hdr.sshift -#define LORDER hdr.lorder -#define OVFL_POINT hdr.ovfl_point -#define LAST_FREED hdr.last_freed -#define MAX_BUCKET hdr.max_bucket -#define FFACTOR hdr.ffactor -#define HIGH_MASK hdr.high_mask -#define LOW_MASK hdr.low_mask -#define NKEYS hdr.nkeys -#define HDRPAGES hdr.hdrpages -#define SPARES hdr.spares -#define BITMAPS hdr.bitmaps -#define VERSION hdr.version -#define MAGIC hdr.magic -#define NEXT_FREE hdr.next_free -#define H_CHARKEY hdr.h_charkey diff --git a/db.subproj/hash.subproj/hash_bigkey.c b/db.subproj/hash.subproj/hash_bigkey.c deleted file mode 100644 index 8c8f467..0000000 --- a/db.subproj/hash.subproj/hash_bigkey.c +++ /dev/null @@ -1,685 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Margo Seltzer. - * - * 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. - */ - - -/* - * PACKAGE: hash - * DESCRIPTION: - * Big key/data handling for the hashing package. - * - * ROUTINES: - * External - * __big_keydata - * __big_split - * __big_insert - * __big_return - * __big_delete - * __find_last_page - * Internal - * collect_key - * collect_data - */ - -#include - -#include -#include -#include -#include - -#ifdef DEBUG -#include -#endif - -#include -#include "hash.h" -#include "page.h" -#include "extern.h" - -static int collect_key __P((HTAB *, BUFHEAD *, int, DBT *, int)); -static int collect_data __P((HTAB *, BUFHEAD *, int, int)); - -/* - * Big_insert - * - * You need to do an insert and the key/data pair is too big - * - * Returns: - * 0 ==> OK - *-1 ==> ERROR - */ -extern int -__big_insert(hashp, bufp, key, val) - HTAB *hashp; - BUFHEAD *bufp; - const DBT *key, *val; -{ - register u_short *p; - int key_size, n, val_size; - u_short space, move_bytes, off; - char *cp, *key_data, *val_data; - - cp = bufp->page; /* Character pointer of p. */ - p = (u_short *)cp; - - key_data = (char *)key->data; - key_size = key->size; - val_data = (char *)val->data; - val_size = val->size; - - /* First move the Key */ - for (space = FREESPACE(p) - BIGOVERHEAD; key_size; - space = FREESPACE(p) - BIGOVERHEAD) { - move_bytes = MIN(space, key_size); - off = OFFSET(p) - move_bytes; - memmove(cp + off, key_data, move_bytes); - key_size -= move_bytes; - key_data += move_bytes; - n = p[0]; - p[++n] = off; - p[0] = ++n; - FREESPACE(p) = off - PAGE_META(n); - OFFSET(p) = off; - p[n] = PARTIAL_KEY; - bufp = __add_ovflpage(hashp, bufp); - if (!bufp) - return (-1); - n = p[0]; - if (!key_size) - if (FREESPACE(p)) { - move_bytes = MIN(FREESPACE(p), val_size); - off = OFFSET(p) - move_bytes; - p[n] = off; - memmove(cp + off, val_data, move_bytes); - val_data += move_bytes; - val_size -= move_bytes; - p[n - 2] = FULL_KEY_DATA; - FREESPACE(p) = FREESPACE(p) - move_bytes; - OFFSET(p) = off; - } else - p[n - 2] = FULL_KEY; - p = (u_short *)bufp->page; - cp = bufp->page; - bufp->flags |= BUF_MOD; - } - - /* Now move the data */ - for (space = FREESPACE(p) - BIGOVERHEAD; val_size; - space = FREESPACE(p) - BIGOVERHEAD) { - move_bytes = MIN(space, val_size); - /* - * Here's the hack to make sure that if the data ends on the - * same page as the key ends, FREESPACE is at least one. - */ - if (space == val_size && val_size == val->size) - move_bytes--; - off = OFFSET(p) - move_bytes; - memmove(cp + off, val_data, move_bytes); - val_size -= move_bytes; - val_data += move_bytes; - n = p[0]; - p[++n] = off; - p[0] = ++n; - FREESPACE(p) = off - PAGE_META(n); - OFFSET(p) = off; - if (val_size) { - p[n] = FULL_KEY; - bufp = __add_ovflpage(hashp, bufp); - if (!bufp) - return (-1); - cp = bufp->page; - p = (u_short *)cp; - } else - p[n] = FULL_KEY_DATA; - bufp->flags |= BUF_MOD; - } - return (0); -} - -/* - * Called when bufp's page contains a partial key (index should be 1) - * - * All pages in the big key/data pair except bufp are freed. We cannot - * free bufp because the page pointing to it is lost and we can't get rid - * of its pointer. - * - * Returns: - * 0 => OK - *-1 => ERROR - */ -extern int -__big_delete(hashp, bufp) - HTAB *hashp; - BUFHEAD *bufp; -{ - register BUFHEAD *last_bfp, *rbufp; - u_short *bp, pageno; - int key_done, n; - - rbufp = bufp; - last_bfp = NULL; - bp = (u_short *)bufp->page; - pageno = 0; - key_done = 0; - - while (!key_done || (bp[2] != FULL_KEY_DATA)) { - if (bp[2] == FULL_KEY || bp[2] == FULL_KEY_DATA) - key_done = 1; - - /* - * If there is freespace left on a FULL_KEY_DATA page, then - * the data is short and fits entirely on this page, and this - * is the last page. - */ - if (bp[2] == FULL_KEY_DATA && FREESPACE(bp)) - break; - pageno = bp[bp[0] - 1]; - rbufp->flags |= BUF_MOD; - rbufp = __get_buf(hashp, pageno, rbufp, 0); - if (last_bfp) - __free_ovflpage(hashp, last_bfp); - last_bfp = rbufp; - if (!rbufp) - return (-1); /* Error. */ - bp = (u_short *)rbufp->page; - } - - /* - * If we get here then rbufp points to the last page of the big - * key/data pair. Bufp points to the first one -- it should now be - * empty pointing to the next page after this pair. Can't free it - * because we don't have the page pointing to it. - */ - - /* This is information from the last page of the pair. */ - n = bp[0]; - pageno = bp[n - 1]; - - /* Now, bp is the first page of the pair. */ - bp = (u_short *)bufp->page; - if (n > 2) { - /* There is an overflow page. */ - bp[1] = pageno; - bp[2] = OVFLPAGE; - bufp->ovfl = rbufp->ovfl; - } else - /* This is the last page. */ - bufp->ovfl = NULL; - n -= 2; - bp[0] = n; - FREESPACE(bp) = hashp->BSIZE - PAGE_META(n); - OFFSET(bp) = hashp->BSIZE - 1; - - bufp->flags |= BUF_MOD; - if (rbufp) - __free_ovflpage(hashp, rbufp); - if (last_bfp != rbufp) - __free_ovflpage(hashp, last_bfp); - - hashp->NKEYS--; - return (0); -} -/* - * Returns: - * 0 = key not found - * -1 = get next overflow page - * -2 means key not found and this is big key/data - * -3 error - */ -extern int -__find_bigpair(hashp, bufp, ndx, key, size) - HTAB *hashp; - BUFHEAD *bufp; - int ndx; - char *key; - int size; -{ - register u_short *bp; - register char *p; - int ksize; - u_short bytes; - char *kkey; - - bp = (u_short *)bufp->page; - p = bufp->page; - ksize = size; - kkey = key; - - for (bytes = hashp->BSIZE - bp[ndx]; - bytes <= size && bp[ndx + 1] == PARTIAL_KEY; - bytes = hashp->BSIZE - bp[ndx]) { - if (memcmp(p + bp[ndx], kkey, bytes)) - return (-2); - kkey += bytes; - ksize -= bytes; - bufp = __get_buf(hashp, bp[ndx + 2], bufp, 0); - if (!bufp) - return (-3); - p = bufp->page; - bp = (u_short *)p; - ndx = 1; - } - - if (bytes != ksize || memcmp(p + bp[ndx], kkey, bytes)) { -#ifdef HASH_STATISTICS - ++hash_collisions; -#endif - return (-2); - } else - return (ndx); -} - -/* - * Given the buffer pointer of the first overflow page of a big pair, - * find the end of the big pair - * - * This will set bpp to the buffer header of the last page of the big pair. - * It will return the pageno of the overflow page following the last page - * of the pair; 0 if there isn't any (i.e. big pair is the last key in the - * bucket) - */ -extern u_short -__find_last_page(hashp, bpp) - HTAB *hashp; - BUFHEAD **bpp; -{ - BUFHEAD *bufp; - u_short *bp, pageno; - int n; - - bufp = *bpp; - bp = (u_short *)bufp->page; - for (;;) { - n = bp[0]; - - /* - * This is the last page if: the tag is FULL_KEY_DATA and - * either only 2 entries OVFLPAGE marker is explicit there - * is freespace on the page. - */ - if (bp[2] == FULL_KEY_DATA && - ((n == 2) || (bp[n] == OVFLPAGE) || (FREESPACE(bp)))) - break; - - pageno = bp[n - 1]; - bufp = __get_buf(hashp, pageno, bufp, 0); - if (!bufp) - return (0); /* Need to indicate an error! */ - bp = (u_short *)bufp->page; - } - - *bpp = bufp; - if (bp[0] > 2) - return (bp[3]); - else - return (0); -} - -/* - * Return the data for the key/data pair that begins on this page at this - * index (index should always be 1). - */ -extern int -__big_return(hashp, bufp, ndx, val, set_current) - HTAB *hashp; - BUFHEAD *bufp; - int ndx; - DBT *val; - int set_current; -{ - BUFHEAD *save_p; - u_short *bp, len, off, save_addr; - char *tp; - - bp = (u_short *)bufp->page; - while (bp[ndx + 1] == PARTIAL_KEY) { - bufp = __get_buf(hashp, bp[bp[0] - 1], bufp, 0); - if (!bufp) - return (-1); - bp = (u_short *)bufp->page; - ndx = 1; - } - - if (bp[ndx + 1] == FULL_KEY) { - bufp = __get_buf(hashp, bp[bp[0] - 1], bufp, 0); - if (!bufp) - return (-1); - bp = (u_short *)bufp->page; - save_p = bufp; - save_addr = save_p->addr; - off = bp[1]; - len = 0; - } else - if (!FREESPACE(bp)) { - /* - * This is a hack. We can't distinguish between - * FULL_KEY_DATA that contains complete data or - * incomplete data, so we require that if the data - * is complete, there is at least 1 byte of free - * space left. - */ - off = bp[bp[0]]; - len = bp[1] - off; - save_p = bufp; - save_addr = bufp->addr; - bufp = __get_buf(hashp, bp[bp[0] - 1], bufp, 0); - if (!bufp) - return (-1); - bp = (u_short *)bufp->page; - } else { - /* The data is all on one page. */ - tp = (char *)bp; - off = bp[bp[0]]; - val->data = (u_char *)tp + off; - val->size = bp[1] - off; - if (set_current) { - if (bp[0] == 2) { /* No more buckets in - * chain */ - hashp->cpage = NULL; - hashp->cbucket++; - hashp->cndx = 1; - } else { - hashp->cpage = __get_buf(hashp, - bp[bp[0] - 1], bufp, 0); - if (!hashp->cpage) - return (-1); - hashp->cndx = 1; - if (!((u_short *) - hashp->cpage->page)[0]) { - hashp->cbucket++; - hashp->cpage = NULL; - } - } - } - return (0); - } - - val->size = collect_data(hashp, bufp, (int)len, set_current); - if (val->size == -1) - return (-1); - if (save_p->addr != save_addr) { - /* We are pretty short on buffers. */ - errno = EINVAL; /* OUT OF BUFFERS */ - return (-1); - } - memmove(hashp->tmp_buf, (save_p->page) + off, len); - val->data = (u_char *)hashp->tmp_buf; - return (0); -} -/* - * Count how big the total datasize is by recursing through the pages. Then - * allocate a buffer and copy the data as you recurse up. - */ -static int -collect_data(hashp, bufp, len, set) - HTAB *hashp; - BUFHEAD *bufp; - int len, set; -{ - register u_short *bp; - register char *p; - BUFHEAD *xbp; - u_short save_addr; - int mylen, totlen; - - p = bufp->page; - bp = (u_short *)p; - mylen = hashp->BSIZE - bp[1]; - save_addr = bufp->addr; - - if (bp[2] == FULL_KEY_DATA) { /* End of Data */ - totlen = len + mylen; - if (hashp->tmp_buf) - free(hashp->tmp_buf); - if ((hashp->tmp_buf = (char *)malloc(totlen)) == NULL) - return (-1); - if (set) { - hashp->cndx = 1; - if (bp[0] == 2) { /* No more buckets in chain */ - hashp->cpage = NULL; - hashp->cbucket++; - } else { - hashp->cpage = - __get_buf(hashp, bp[bp[0] - 1], bufp, 0); - if (!hashp->cpage) - return (-1); - else if (!((u_short *)hashp->cpage->page)[0]) { - hashp->cbucket++; - hashp->cpage = NULL; - } - } - } - } else { - xbp = __get_buf(hashp, bp[bp[0] - 1], bufp, 0); - if (!xbp || ((totlen = - collect_data(hashp, xbp, len + mylen, set)) < 1)) - return (-1); - } - if (bufp->addr != save_addr) { - errno = EINVAL; /* Out of buffers. */ - return (-1); - } - memmove(&hashp->tmp_buf[len], (bufp->page) + bp[1], mylen); - return (totlen); -} - -/* - * Fill in the key and data for this big pair. - */ -extern int -__big_keydata(hashp, bufp, key, val, set) - HTAB *hashp; - BUFHEAD *bufp; - DBT *key, *val; - int set; -{ - key->size = collect_key(hashp, bufp, 0, val, set); - if (key->size == -1) - return (-1); - key->data = (u_char *)hashp->tmp_key; - return (0); -} - -/* - * Count how big the total key size is by recursing through the pages. Then - * collect the data, allocate a buffer and copy the key as you recurse up. - */ -static int -collect_key(hashp, bufp, len, val, set) - HTAB *hashp; - BUFHEAD *bufp; - int len; - DBT *val; - int set; -{ - BUFHEAD *xbp; - char *p; - int mylen, totlen; - u_short *bp, save_addr; - - p = bufp->page; - bp = (u_short *)p; - mylen = hashp->BSIZE - bp[1]; - - save_addr = bufp->addr; - totlen = len + mylen; - if (bp[2] == FULL_KEY || bp[2] == FULL_KEY_DATA) { /* End of Key. */ - if (hashp->tmp_key != NULL) - free(hashp->tmp_key); - if ((hashp->tmp_key = (char *)malloc(totlen)) == NULL) - return (-1); - if (__big_return(hashp, bufp, 1, val, set)) - return (-1); - } else { - xbp = __get_buf(hashp, bp[bp[0] - 1], bufp, 0); - if (!xbp || ((totlen = - collect_key(hashp, xbp, totlen, val, set)) < 1)) - return (-1); - } - if (bufp->addr != save_addr) { - errno = EINVAL; /* MIS -- OUT OF BUFFERS */ - return (-1); - } - memmove(&hashp->tmp_key[len], (bufp->page) + bp[1], mylen); - return (totlen); -} - -/* - * Returns: - * 0 => OK - * -1 => error - */ -extern int -__big_split(hashp, op, np, big_keyp, addr, obucket, ret) - HTAB *hashp; - BUFHEAD *op; /* Pointer to where to put keys that go in old bucket */ - BUFHEAD *np; /* Pointer to new bucket page */ - /* Pointer to first page containing the big key/data */ - BUFHEAD *big_keyp; - int addr; /* Address of big_keyp */ - u_int obucket;/* Old Bucket */ - SPLIT_RETURN *ret; -{ - register BUFHEAD *tmpp; - register u_short *tp; - BUFHEAD *bp; - DBT key, val; - u_int change; - u_short free_space, n, off; - - bp = big_keyp; - - /* Now figure out where the big key/data goes */ - if (__big_keydata(hashp, big_keyp, &key, &val, 0)) - return (-1); - change = (__call_hash(hashp, key.data, key.size) != obucket); - - if (ret->next_addr = __find_last_page(hashp, &big_keyp)) { - if (!(ret->nextp = - __get_buf(hashp, ret->next_addr, big_keyp, 0))) - return (-1);; - } else - ret->nextp = NULL; - - /* Now make one of np/op point to the big key/data pair */ -#ifdef DEBUG - assert(np->ovfl == NULL); -#endif - if (change) - tmpp = np; - else - tmpp = op; - - tmpp->flags |= BUF_MOD; -#ifdef DEBUG1 - (void)fprintf(stderr, - "BIG_SPLIT: %d->ovfl was %d is now %d\n", tmpp->addr, - (tmpp->ovfl ? tmpp->ovfl->addr : 0), (bp ? bp->addr : 0)); -#endif - tmpp->ovfl = bp; /* one of op/np point to big_keyp */ - tp = (u_short *)tmpp->page; -#ifdef DEBUG - assert(FREESPACE(tp) >= OVFLSIZE); -#endif - n = tp[0]; - off = OFFSET(tp); - free_space = FREESPACE(tp); - tp[++n] = (u_short)addr; - tp[++n] = OVFLPAGE; - tp[0] = n; - OFFSET(tp) = off; - FREESPACE(tp) = free_space - OVFLSIZE; - - /* - * Finally, set the new and old return values. BIG_KEYP contains a - * pointer to the last page of the big key_data pair. Make sure that - * big_keyp has no following page (2 elements) or create an empty - * following page. - */ - - ret->newp = np; - ret->oldp = op; - - tp = (u_short *)big_keyp->page; - big_keyp->flags |= BUF_MOD; - if (tp[0] > 2) { - /* - * There may be either one or two offsets on this page. If - * there is one, then the overflow page is linked on normally - * and tp[4] is OVFLPAGE. If there are two, tp[4] contains - * the second offset and needs to get stuffed in after the - * next overflow page is added. - */ - n = tp[4]; - free_space = FREESPACE(tp); - off = OFFSET(tp); - tp[0] -= 2; - FREESPACE(tp) = free_space + OVFLSIZE; - OFFSET(tp) = off; - tmpp = __add_ovflpage(hashp, big_keyp); - if (!tmpp) - return (-1); - tp[4] = n; - } else - tmpp = big_keyp; - - if (change) - ret->newp = tmpp; - else - ret->oldp = tmpp; - return (0); -} diff --git a/db.subproj/hash.subproj/hash_buf.c b/db.subproj/hash.subproj/hash_buf.c deleted file mode 100644 index 9d89a8b..0000000 --- a/db.subproj/hash.subproj/hash_buf.c +++ /dev/null @@ -1,365 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Margo Seltzer. - * - * 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. - */ - - -/* - * PACKAGE: hash - * - * DESCRIPTION: - * Contains buffer management - * - * ROUTINES: - * External - * __buf_init - * __get_buf - * __buf_free - * __reclaim_buf - * Internal - * newbuf - */ - -#include - -#include -#include -#include -#ifdef DEBUG -#include -#endif - -#include -#include "hash.h" -#include "page.h" -#include "extern.h" - -static BUFHEAD *newbuf __P((HTAB *, u_int, BUFHEAD *)); - -/* Unlink B from its place in the lru */ -#define BUF_REMOVE(B) { \ - (B)->prev->next = (B)->next; \ - (B)->next->prev = (B)->prev; \ -} - -/* Insert B after P */ -#define BUF_INSERT(B, P) { \ - (B)->next = (P)->next; \ - (B)->prev = (P); \ - (P)->next = (B); \ - (B)->next->prev = (B); \ -} - -#define MRU hashp->bufhead.next -#define LRU hashp->bufhead.prev - -#define MRU_INSERT(B) BUF_INSERT((B), &hashp->bufhead) -#define LRU_INSERT(B) BUF_INSERT((B), LRU) - -/* - * We are looking for a buffer with address "addr". If prev_bp is NULL, then - * address is a bucket index. If prev_bp is not NULL, then it points to the - * page previous to an overflow page that we are trying to find. - * - * CAVEAT: The buffer header accessed via prev_bp's ovfl field may no longer - * be valid. Therefore, you must always verify that its address matches the - * address you are seeking. - */ -extern BUFHEAD * -__get_buf(hashp, addr, prev_bp, newpage) - HTAB *hashp; - u_int addr; - BUFHEAD *prev_bp; - int newpage; /* If prev_bp set, indicates a new overflow page. */ -{ - register BUFHEAD *bp; - register u_int is_disk_mask; - register int is_disk, segment_ndx; - SEGMENT segp; - - is_disk = 0; - is_disk_mask = 0; - if (prev_bp) { - bp = prev_bp->ovfl; - if (!bp || (bp->addr != addr)) - bp = NULL; - if (!newpage) - is_disk = BUF_DISK; - } else { - /* Grab buffer out of directory */ - segment_ndx = addr & (hashp->SGSIZE - 1); - - /* valid segment ensured by __call_hash() */ - segp = hashp->dir[addr >> hashp->SSHIFT]; -#ifdef DEBUG - assert(segp != NULL); -#endif - bp = PTROF(segp[segment_ndx]); - is_disk_mask = ISDISK(segp[segment_ndx]); - is_disk = is_disk_mask || !hashp->new_file; - } - - if (!bp) { - bp = newbuf(hashp, addr, prev_bp); - if (!bp || - __get_page(hashp, bp->page, addr, !prev_bp, is_disk, 0)) - return (NULL); - if (!prev_bp) - segp[segment_ndx] = - (BUFHEAD *)((u_int)bp | is_disk_mask); - } else { - BUF_REMOVE(bp); - MRU_INSERT(bp); - } - return (bp); -} - -/* - * We need a buffer for this page. Either allocate one, or evict a resident - * one (if we have as many buffers as we're allowed) and put this one in. - * - * If newbuf finds an error (returning NULL), it also sets errno. - */ -static BUFHEAD * -newbuf(hashp, addr, prev_bp) - HTAB *hashp; - u_int addr; - BUFHEAD *prev_bp; -{ - register BUFHEAD *bp; /* The buffer we're going to use */ - register BUFHEAD *xbp; /* Temp pointer */ - register BUFHEAD *next_xbp; - SEGMENT segp; - int segment_ndx; - u_short oaddr, *shortp; - - oaddr = 0; - bp = LRU; - /* - * If LRU buffer is pinned, the buffer pool is too small. We need to - * allocate more buffers. - */ - if (hashp->nbufs || (bp->flags & BUF_PIN)) { - /* Allocate a new one */ - if ((bp = (BUFHEAD *)malloc(sizeof(BUFHEAD))) == NULL) - return (NULL); - if ((bp->page = (char *)malloc(hashp->BSIZE)) == NULL) { - free(bp); - return (NULL); - } - if (hashp->nbufs) - hashp->nbufs--; - } else { - /* Kick someone out */ - BUF_REMOVE(bp); - /* - * If this is an overflow page with addr 0, it's already been - * flushed back in an overflow chain and initialized. - */ - if ((bp->addr != 0) || (bp->flags & BUF_BUCKET)) { - /* - * Set oaddr before __put_page so that you get it - * before bytes are swapped. - */ - shortp = (u_short *)bp->page; - if (shortp[0]) - oaddr = shortp[shortp[0] - 1]; - if ((bp->flags & BUF_MOD) && __put_page(hashp, bp->page, - bp->addr, (int)IS_BUCKET(bp->flags), 0)) - return (NULL); - /* - * Update the pointer to this page (i.e. invalidate it). - * - * If this is a new file (i.e. we created it at open - * time), make sure that we mark pages which have been - * written to disk so we retrieve them from disk later, - * rather than allocating new pages. - */ - if (IS_BUCKET(bp->flags)) { - segment_ndx = bp->addr & (hashp->SGSIZE - 1); - segp = hashp->dir[bp->addr >> hashp->SSHIFT]; -#ifdef DEBUG - assert(segp != NULL); -#endif - - if (hashp->new_file && - ((bp->flags & BUF_MOD) || - ISDISK(segp[segment_ndx]))) - segp[segment_ndx] = (BUFHEAD *)BUF_DISK; - else - segp[segment_ndx] = NULL; - } - /* - * Since overflow pages can only be access by means of - * their bucket, free overflow pages associated with - * this bucket. - */ - for (xbp = bp; xbp->ovfl;) { - next_xbp = xbp->ovfl; - xbp->ovfl = 0; - xbp = next_xbp; - - /* Check that ovfl pointer is up date. */ - if (IS_BUCKET(xbp->flags) || - (oaddr != xbp->addr)) - break; - - shortp = (u_short *)xbp->page; - if (shortp[0]) - /* set before __put_page */ - oaddr = shortp[shortp[0] - 1]; - if ((xbp->flags & BUF_MOD) && __put_page(hashp, - xbp->page, xbp->addr, 0, 0)) - return (NULL); - xbp->addr = 0; - xbp->flags = 0; - BUF_REMOVE(xbp); - LRU_INSERT(xbp); - } - } - } - - /* Now assign this buffer */ - bp->addr = addr; -#ifdef DEBUG1 - (void)fprintf(stderr, "NEWBUF1: %d->ovfl was %d is now %d\n", - bp->addr, (bp->ovfl ? bp->ovfl->addr : 0), 0); -#endif - bp->ovfl = NULL; - if (prev_bp) { - /* - * If prev_bp is set, this is an overflow page, hook it in to - * the buffer overflow links. - */ -#ifdef DEBUG1 - (void)fprintf(stderr, "NEWBUF2: %d->ovfl was %d is now %d\n", - prev_bp->addr, (prev_bp->ovfl ? bp->ovfl->addr : 0), - (bp ? bp->addr : 0)); -#endif - prev_bp->ovfl = bp; - bp->flags = 0; - } else - bp->flags = BUF_BUCKET; - MRU_INSERT(bp); - return (bp); -} - -extern void -__buf_init(hashp, nbytes) - HTAB *hashp; - int nbytes; -{ - BUFHEAD *bfp; - int npages; - - bfp = &(hashp->bufhead); - npages = (nbytes + hashp->BSIZE - 1) >> hashp->BSHIFT; - npages = MAX(npages, MIN_BUFFERS); - - hashp->nbufs = npages; - bfp->next = bfp; - bfp->prev = bfp; - /* - * This space is calloc'd so these are already null. - * - * bfp->ovfl = NULL; - * bfp->flags = 0; - * bfp->page = NULL; - * bfp->addr = 0; - */ -} - -extern int -__buf_free(hashp, do_free, to_disk) - HTAB *hashp; - int do_free, to_disk; -{ - BUFHEAD *bp; - - /* Need to make sure that buffer manager has been initialized */ - if (!LRU) - return (0); - for (bp = LRU; bp != &hashp->bufhead;) { - /* Check that the buffer is valid */ - if (bp->addr || IS_BUCKET(bp->flags)) { - if (to_disk && (bp->flags & BUF_MOD) && - __put_page(hashp, bp->page, - bp->addr, IS_BUCKET(bp->flags), 0)) - return (-1); - } - /* Check if we are freeing stuff */ - if (do_free) { - if (bp->page) - free(bp->page); - BUF_REMOVE(bp); - free(bp); - bp = LRU; - } else - bp = bp->prev; - } - return (0); -} - -extern void -__reclaim_buf(hashp, bp) - HTAB *hashp; - BUFHEAD *bp; -{ - bp->ovfl = 0; - bp->addr = 0; - bp->flags = 0; - BUF_REMOVE(bp); - LRU_INSERT(bp); -} diff --git a/db.subproj/hash.subproj/hash_func.c b/db.subproj/hash.subproj/hash_func.c deleted file mode 100644 index d33b481..0000000 --- a/db.subproj/hash.subproj/hash_func.c +++ /dev/null @@ -1,230 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Margo Seltzer. - * - * 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 - -#include -#include "hash.h" -#include "page.h" -#include "extern.h" - -static u_int32_t hash1 __P((const void *, size_t)); -static u_int32_t hash2 __P((const void *, size_t)); -static u_int32_t hash3 __P((const void *, size_t)); -static u_int32_t hash4 __P((const void *, size_t)); - -/* Global default hash function */ -u_int32_t (*__default_hash) __P((const void *, size_t)) = hash4; - -/* - * HASH FUNCTIONS - * - * Assume that we've already split the bucket to which this key hashes, - * calculate that bucket, and check that in fact we did already split it. - * - * This came from ejb's hsearch. - */ - -#define PRIME1 37 -#define PRIME2 1048583 - -static u_int32_t -hash1(keyarg, len) - const void *keyarg; - register size_t len; -{ - register const u_char *key; - register u_int32_t h; - - /* Convert string to integer */ - for (key = keyarg, h = 0; len--;) - h = h * PRIME1 ^ (*key++ - ' '); - h %= PRIME2; - return (h); -} - -/* - * Phong's linear congruential hash - */ -#define dcharhash(h, c) ((h) = 0x63c63cd9*(h) + 0x9c39c33d + (c)) - -static u_int32_t -hash2(keyarg, len) - const void *keyarg; - size_t len; -{ - register const u_char *e, *key; - register u_int32_t h; - register u_char c; - - key = keyarg; - e = key + len; - for (h = 0; key != e;) { - c = *key++; - if (!c && key > e) - break; - dcharhash(h, c); - } - return (h); -} - -/* - * This is INCREDIBLY ugly, but fast. We break the string up into 8 byte - * units. On the first time through the loop we get the "leftover bytes" - * (strlen % 8). On every other iteration, we perform 8 HASHC's so we handle - * all 8 bytes. Essentially, this saves us 7 cmp & branch instructions. If - * this routine is heavily used enough, it's worth the ugly coding. - * - * OZ's original sdbm hash - */ -static u_int32_t -hash3(keyarg, len) - const void *keyarg; - register size_t len; -{ - register const u_char *key; - register size_t loop; - register u_int32_t h; - -#define HASHC h = *key++ + 65599 * h - - h = 0; - key = keyarg; - if (len > 0) { - loop = (len + 8 - 1) >> 3; - - switch (len & (8 - 1)) { - case 0: - do { - HASHC; - /* FALLTHROUGH */ - case 7: - HASHC; - /* FALLTHROUGH */ - case 6: - HASHC; - /* FALLTHROUGH */ - case 5: - HASHC; - /* FALLTHROUGH */ - case 4: - HASHC; - /* FALLTHROUGH */ - case 3: - HASHC; - /* FALLTHROUGH */ - case 2: - HASHC; - /* FALLTHROUGH */ - case 1: - HASHC; - } while (--loop); - } - } - return (h); -} - -/* Hash function from Chris Torek. */ -static u_int32_t -hash4(keyarg, len) - const void *keyarg; - register size_t len; -{ - register const u_char *key; - register size_t loop; - register u_int32_t h; - -#define HASH4a h = (h << 5) - h + *key++; -#define HASH4b h = (h << 5) + h + *key++; -#define HASH4 HASH4b - - h = 0; - key = keyarg; - if (len > 0) { - loop = (len + 8 - 1) >> 3; - - switch (len & (8 - 1)) { - case 0: - do { - HASH4; - /* FALLTHROUGH */ - case 7: - HASH4; - /* FALLTHROUGH */ - case 6: - HASH4; - /* FALLTHROUGH */ - case 5: - HASH4; - /* FALLTHROUGH */ - case 4: - HASH4; - /* FALLTHROUGH */ - case 3: - HASH4; - /* FALLTHROUGH */ - case 2: - HASH4; - /* FALLTHROUGH */ - case 1: - HASH4; - } while (--loop); - } - } - return (h); -} diff --git a/db.subproj/hash.subproj/hash_log2.c b/db.subproj/hash.subproj/hash_log2.c deleted file mode 100644 index 0f7f002..0000000 --- a/db.subproj/hash.subproj/hash_log2.c +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Margo Seltzer. - * - * 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 - -u_int -__log2(num) - u_int num; -{ - register u_int i, limit; - - limit = 1; - for (i = 0; limit < num; limit = limit << 1, i++); - return (i); -} diff --git a/db.subproj/hash.subproj/hash_page.c b/db.subproj/hash.subproj/hash_page.c deleted file mode 100644 index aa7b36f..0000000 --- a/db.subproj/hash.subproj/hash_page.c +++ /dev/null @@ -1,962 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Margo Seltzer. - * - * 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. - */ - - -/* - * PACKAGE: hashing - * - * DESCRIPTION: - * Page manipulation for hashing package. - * - * ROUTINES: - * - * External - * __get_page - * __add_ovflpage - * Internal - * overflow_page - * open_temp - */ - -#include - -#include -#include -#include -#include -#include -#include -#include -#ifdef DEBUG -#include -#endif - -#include -#include "hash.h" -#include "page.h" -#include "extern.h" - -static u_long *fetch_bitmap __P((HTAB *, int)); -static u_long first_free __P((u_long)); -static int open_temp __P((HTAB *)); -static u_short overflow_page __P((HTAB *)); -static void putpair __P((char *, const DBT *, const DBT *)); -static void squeeze_key __P((u_short *, const DBT *, const DBT *)); -static int ugly_split - __P((HTAB *, u_int, BUFHEAD *, BUFHEAD *, int, int)); - -#define PAGE_INIT(P) { \ - ((u_short *)(P))[0] = 0; \ - ((u_short *)(P))[1] = hashp->BSIZE - 3 * sizeof(u_short); \ - ((u_short *)(P))[2] = hashp->BSIZE; \ -} - -/* - * This is called AFTER we have verified that there is room on the page for - * the pair (PAIRFITS has returned true) so we go right ahead and start moving - * stuff on. - */ -static void -putpair(p, key, val) - char *p; - const DBT *key, *val; -{ - register u_short *bp, n, off; - - bp = (u_short *)p; - - /* Enter the key first. */ - n = bp[0]; - - off = OFFSET(bp) - key->size; - memmove(p + off, key->data, key->size); - bp[++n] = off; - - /* Now the data. */ - off -= val->size; - memmove(p + off, val->data, val->size); - bp[++n] = off; - - /* Adjust page info. */ - bp[0] = n; - bp[n + 1] = off - ((n + 3) * sizeof(u_short)); - bp[n + 2] = off; -} - -/* - * Returns: - * 0 OK - * -1 error - */ -extern int -__delpair(hashp, bufp, ndx) - HTAB *hashp; - BUFHEAD *bufp; - register int ndx; -{ - register u_short *bp, newoff; - register int n; - u_short pairlen; - - bp = (u_short *)bufp->page; - n = bp[0]; - - if (bp[ndx + 1] < REAL_KEY) - return (__big_delete(hashp, bufp)); - if (ndx != 1) - newoff = bp[ndx - 1]; - else - newoff = hashp->BSIZE; - pairlen = newoff - bp[ndx + 1]; - - if (ndx != (n - 1)) { - /* Hard Case -- need to shuffle keys */ - register int i; - register char *src = bufp->page + (int)OFFSET(bp); - register char *dst = src + (int)pairlen; - memmove(dst, src, bp[ndx + 1] - OFFSET(bp)); - - /* Now adjust the pointers */ - for (i = ndx + 2; i <= n; i += 2) { - if (bp[i + 1] == OVFLPAGE) { - bp[i - 2] = bp[i]; - bp[i - 1] = bp[i + 1]; - } else { - bp[i - 2] = bp[i] + pairlen; - bp[i - 1] = bp[i + 1] + pairlen; - } - } - } - /* Finally adjust the page data */ - bp[n] = OFFSET(bp) + pairlen; - bp[n - 1] = bp[n + 1] + pairlen + 2 * sizeof(u_short); - bp[0] = n - 2; - hashp->NKEYS--; - - bufp->flags |= BUF_MOD; - return (0); -} -/* - * Returns: - * 0 ==> OK - * -1 ==> Error - */ -extern int -__split_page(hashp, obucket, nbucket) - HTAB *hashp; - u_int obucket, nbucket; -{ - register BUFHEAD *new_bufp, *old_bufp; - register u_short *ino; - register char *np; - DBT key, val; - int n, ndx, retval; - u_short copyto, diff, off, moved; - char *op; - - copyto = (u_short)hashp->BSIZE; - off = (u_short)hashp->BSIZE; - old_bufp = __get_buf(hashp, obucket, NULL, 0); - if (old_bufp == NULL) - return (-1); - new_bufp = __get_buf(hashp, nbucket, NULL, 0); - if (new_bufp == NULL) - return (-1); - - old_bufp->flags |= (BUF_MOD | BUF_PIN); - new_bufp->flags |= (BUF_MOD | BUF_PIN); - - ino = (u_short *)(op = old_bufp->page); - np = new_bufp->page; - - moved = 0; - - for (n = 1, ndx = 1; n < ino[0]; n += 2) { - if (ino[n + 1] < REAL_KEY) { - retval = ugly_split(hashp, obucket, old_bufp, new_bufp, - (int)copyto, (int)moved); - old_bufp->flags &= ~BUF_PIN; - new_bufp->flags &= ~BUF_PIN; - return (retval); - - } - key.data = (u_char *)op + ino[n]; - key.size = off - ino[n]; - - if (__call_hash(hashp, key.data, key.size) == obucket) { - /* Don't switch page */ - diff = copyto - off; - if (diff) { - copyto = ino[n + 1] + diff; - memmove(op + copyto, op + ino[n + 1], - off - ino[n + 1]); - ino[ndx] = copyto + ino[n] - ino[n + 1]; - ino[ndx + 1] = copyto; - } else - copyto = ino[n + 1]; - ndx += 2; - } else { - /* Switch page */ - val.data = (u_char *)op + ino[n + 1]; - val.size = ino[n] - ino[n + 1]; - putpair(np, &key, &val); - moved += 2; - } - - off = ino[n + 1]; - } - - /* Now clean up the page */ - ino[0] -= moved; - FREESPACE(ino) = copyto - sizeof(u_short) * (ino[0] + 3); - OFFSET(ino) = copyto; - -#ifdef DEBUG3 - (void)fprintf(stderr, "split %d/%d\n", - ((u_short *)np)[0] / 2, - ((u_short *)op)[0] / 2); -#endif - /* unpin both pages */ - old_bufp->flags &= ~BUF_PIN; - new_bufp->flags &= ~BUF_PIN; - return (0); -} - -/* - * Called when we encounter an overflow or big key/data page during split - * handling. This is special cased since we have to begin checking whether - * the key/data pairs fit on their respective pages and because we may need - * overflow pages for both the old and new pages. - * - * The first page might be a page with regular key/data pairs in which case - * we have a regular overflow condition and just need to go on to the next - * page or it might be a big key/data pair in which case we need to fix the - * big key/data pair. - * - * Returns: - * 0 ==> success - * -1 ==> failure - */ -static int -ugly_split(hashp, obucket, old_bufp, new_bufp, copyto, moved) - HTAB *hashp; - u_int obucket; /* Same as __split_page. */ - BUFHEAD *old_bufp, *new_bufp; - int copyto; /* First byte on page which contains key/data values. */ - int moved; /* Number of pairs moved to new page. */ -{ - register BUFHEAD *bufp; /* Buffer header for ino */ - register u_short *ino; /* Page keys come off of */ - register u_short *np; /* New page */ - register u_short *op; /* Page keys go on to if they aren't moving */ - - BUFHEAD *last_bfp; /* Last buf header OVFL needing to be freed */ - DBT key, val; - SPLIT_RETURN ret; - u_short n, off, ov_addr, scopyto; - char *cino; /* Character value of ino */ - - bufp = old_bufp; - ino = (u_short *)old_bufp->page; - np = (u_short *)new_bufp->page; - op = (u_short *)old_bufp->page; - last_bfp = NULL; - scopyto = (u_short)copyto; /* ANSI */ - - n = ino[0] - 1; - while (n < ino[0]) { - if (ino[2] < REAL_KEY && ino[2] != OVFLPAGE) { - if (__big_split(hashp, old_bufp, - new_bufp, bufp, bufp->addr, obucket, &ret)) - return (-1); - old_bufp = ret.oldp; - if (!old_bufp) - return (-1); - op = (u_short *)old_bufp->page; - new_bufp = ret.newp; - if (!new_bufp) - return (-1); - np = (u_short *)new_bufp->page; - bufp = ret.nextp; - if (!bufp) - return (0); - cino = (char *)bufp->page; - ino = (u_short *)cino; - last_bfp = ret.nextp; - } else if (ino[n + 1] == OVFLPAGE) { - ov_addr = ino[n]; - /* - * Fix up the old page -- the extra 2 are the fields - * which contained the overflow information. - */ - ino[0] -= (moved + 2); - FREESPACE(ino) = - scopyto - sizeof(u_short) * (ino[0] + 3); - OFFSET(ino) = scopyto; - - bufp = __get_buf(hashp, ov_addr, bufp, 0); - if (!bufp) - return (-1); - - ino = (u_short *)bufp->page; - n = 1; - scopyto = hashp->BSIZE; - moved = 0; - - if (last_bfp) - __free_ovflpage(hashp, last_bfp); - last_bfp = bufp; - } - /* Move regular sized pairs of there are any */ - off = hashp->BSIZE; - for (n = 1; (n < ino[0]) && (ino[n + 1] >= REAL_KEY); n += 2) { - cino = (char *)ino; - key.data = (u_char *)cino + ino[n]; - key.size = off - ino[n]; - val.data = (u_char *)cino + ino[n + 1]; - val.size = ino[n] - ino[n + 1]; - off = ino[n + 1]; - - if (__call_hash(hashp, key.data, key.size) == obucket) { - /* Keep on old page */ - if (PAIRFITS(op, (&key), (&val))) - putpair((char *)op, &key, &val); - else { - old_bufp = - __add_ovflpage(hashp, old_bufp); - if (!old_bufp) - return (-1); - op = (u_short *)old_bufp->page; - putpair((char *)op, &key, &val); - } - old_bufp->flags |= BUF_MOD; - } else { - /* Move to new page */ - if (PAIRFITS(np, (&key), (&val))) - putpair((char *)np, &key, &val); - else { - new_bufp = - __add_ovflpage(hashp, new_bufp); - if (!new_bufp) - return (-1); - np = (u_short *)new_bufp->page; - putpair((char *)np, &key, &val); - } - new_bufp->flags |= BUF_MOD; - } - } - } - if (last_bfp) - __free_ovflpage(hashp, last_bfp); - return (0); -} - -/* - * Add the given pair to the page - * - * Returns: - * 0 ==> OK - * 1 ==> failure - */ -extern int -__addel(hashp, bufp, key, val) - HTAB *hashp; - BUFHEAD *bufp; - const DBT *key, *val; -{ - register u_short *bp, *sop; - int do_expand; - - bp = (u_short *)bufp->page; - do_expand = 0; - while (bp[0] && (bp[2] < REAL_KEY || bp[bp[0]] < REAL_KEY)) - /* Exception case */ - if (bp[2] == FULL_KEY_DATA && bp[0] == 2) - /* This is the last page of a big key/data pair - and we need to add another page */ - break; - else if (bp[2] < REAL_KEY && bp[bp[0]] != OVFLPAGE) { - bufp = __get_buf(hashp, bp[bp[0] - 1], bufp, 0); - if (!bufp) - return (-1); - bp = (u_short *)bufp->page; - } else - /* Try to squeeze key on this page */ - if (FREESPACE(bp) > PAIRSIZE(key, val)) { - squeeze_key(bp, key, val); - return (0); - } else { - bufp = __get_buf(hashp, bp[bp[0] - 1], bufp, 0); - if (!bufp) - return (-1); - bp = (u_short *)bufp->page; - } - - if (PAIRFITS(bp, key, val)) - putpair(bufp->page, key, val); - else { - do_expand = 1; - bufp = __add_ovflpage(hashp, bufp); - if (!bufp) - return (-1); - sop = (u_short *)bufp->page; - - if (PAIRFITS(sop, key, val)) - putpair((char *)sop, key, val); - else - if (__big_insert(hashp, bufp, key, val)) - return (-1); - } - bufp->flags |= BUF_MOD; - /* - * If the average number of keys per bucket exceeds the fill factor, - * expand the table. - */ - hashp->NKEYS++; - if (do_expand || - (hashp->NKEYS / (hashp->MAX_BUCKET + 1) > hashp->FFACTOR)) - return (__expand_table(hashp)); - return (0); -} - -/* - * - * Returns: - * pointer on success - * NULL on error - */ -extern BUFHEAD * -__add_ovflpage(hashp, bufp) - HTAB *hashp; - BUFHEAD *bufp; -{ - register u_short *sp; - u_short ndx, ovfl_num; -#ifdef DEBUG1 - int tmp1, tmp2; -#endif - sp = (u_short *)bufp->page; - - /* Check if we are dynamically determining the fill factor */ - if (hashp->FFACTOR == DEF_FFACTOR) { - hashp->FFACTOR = sp[0] >> 1; - if (hashp->FFACTOR < MIN_FFACTOR) - hashp->FFACTOR = MIN_FFACTOR; - } - bufp->flags |= BUF_MOD; - ovfl_num = overflow_page(hashp); -#ifdef DEBUG1 - tmp1 = bufp->addr; - tmp2 = bufp->ovfl ? bufp->ovfl->addr : 0; -#endif - if (!ovfl_num || !(bufp->ovfl = __get_buf(hashp, ovfl_num, bufp, 1))) - return (NULL); - bufp->ovfl->flags |= BUF_MOD; -#ifdef DEBUG1 - (void)fprintf(stderr, "ADDOVFLPAGE: %d->ovfl was %d is now %d\n", - tmp1, tmp2, bufp->ovfl->addr); -#endif - ndx = sp[0]; - /* - * Since a pair is allocated on a page only if there's room to add - * an overflow page, we know that the OVFL information will fit on - * the page. - */ - sp[ndx + 4] = OFFSET(sp); - sp[ndx + 3] = FREESPACE(sp) - OVFLSIZE; - sp[ndx + 1] = ovfl_num; - sp[ndx + 2] = OVFLPAGE; - sp[0] = ndx + 2; -#ifdef HASH_STATISTICS - hash_overflows++; -#endif - return (bufp->ovfl); -} - -/* - * Returns: - * 0 indicates SUCCESS - * -1 indicates FAILURE - */ -extern int -__get_page(hashp, p, bucket, is_bucket, is_disk, is_bitmap) - HTAB *hashp; - char *p; - u_int bucket; - int is_bucket, is_disk, is_bitmap; -{ - register int fd, page, size; - int rsize; - u_short *bp; - - fd = hashp->fp; - size = hashp->BSIZE; - - if ((fd == -1) || !is_disk) { - PAGE_INIT(p); - return (0); - } - if (is_bucket) - page = BUCKET_TO_PAGE(bucket); - else - page = OADDR_TO_PAGE(bucket); - if ((lseek(fd, (off_t)page << hashp->BSHIFT, SEEK_SET) == -1) || - ((rsize = read(fd, p, size)) == -1)) - return (-1); - bp = (u_short *)p; - if (!rsize) - bp[0] = 0; /* We hit the EOF, so initialize a new page */ - else - if (rsize != size) { - errno = EFTYPE; - return (-1); - } - if (!is_bitmap && !bp[0]) { - PAGE_INIT(p); - } else - if (hashp->LORDER != BYTE_ORDER) { - register int i, max; - - if (is_bitmap) { - max = hashp->BSIZE >> 2; /* divide by 4 */ - for (i = 0; i < max; i++) - M_32_SWAP(((long *)p)[i]); - } else { - M_16_SWAP(bp[0]); - max = bp[0] + 2; - for (i = 1; i <= max; i++) - M_16_SWAP(bp[i]); - } - } - return (0); -} - -/* - * Write page p to disk - * - * Returns: - * 0 ==> OK - * -1 ==>failure - */ -extern int -__put_page(hashp, p, bucket, is_bucket, is_bitmap) - HTAB *hashp; - char *p; - u_int bucket; - int is_bucket, is_bitmap; -{ - register int fd, page, size; - int wsize; - - size = hashp->BSIZE; - if ((hashp->fp == -1) && open_temp(hashp)) - return (-1); - fd = hashp->fp; - - if (hashp->LORDER != BYTE_ORDER) { - register int i; - register int max; - - if (is_bitmap) { - max = hashp->BSIZE >> 2; /* divide by 4 */ - for (i = 0; i < max; i++) - M_32_SWAP(((long *)p)[i]); - } else { - max = ((u_short *)p)[0] + 2; - for (i = 0; i <= max; i++) - M_16_SWAP(((u_short *)p)[i]); - } - } - if (is_bucket) - page = BUCKET_TO_PAGE(bucket); - else - page = OADDR_TO_PAGE(bucket); - if ((lseek(fd, (off_t)page << hashp->BSHIFT, SEEK_SET) == -1) || - ((wsize = write(fd, p, size)) == -1)) - /* Errno is set */ - return (-1); - if (wsize != size) { - errno = EFTYPE; - return (-1); - } - return (0); -} - -#define BYTE_MASK ((1 << INT_BYTE_SHIFT) -1) -/* - * Initialize a new bitmap page. Bitmap pages are left in memory - * once they are read in. - */ -extern int -__init_bitmap(hashp, pnum, nbits, ndx) - HTAB *hashp; - int pnum, nbits, ndx; -{ - u_long *ip; - int clearbytes, clearints; - - if ((ip = (u_long *)malloc(hashp->BSIZE)) == NULL) - return (1); - hashp->nmaps++; - clearints = ((nbits - 1) >> INT_BYTE_SHIFT) + 1; - clearbytes = clearints << INT_TO_BYTE; - (void)memset((char *)ip, 0, clearbytes); - (void)memset(((char *)ip) + clearbytes, 0xFF, - hashp->BSIZE - clearbytes); - ip[clearints - 1] = ALL_SET << (nbits & BYTE_MASK); - SETBIT(ip, 0); - hashp->BITMAPS[ndx] = (u_short)pnum; - hashp->mapp[ndx] = ip; - return (0); -} - -static u_long -first_free(map) - u_long map; -{ - register u_long i, mask; - - mask = 0x1; - for (i = 0; i < BITS_PER_MAP; i++) { - if (!(mask & map)) - return (i); - mask = mask << 1; - } - return (i); -} - -static u_short -overflow_page(hashp) - HTAB *hashp; -{ - register u_long *freep; - register int max_free, offset, splitnum; - u_short addr; - int bit, first_page, free_bit, free_page, i, in_use_bits, j; -#ifdef DEBUG2 - int tmp1, tmp2; -#endif - splitnum = hashp->OVFL_POINT; - max_free = hashp->SPARES[splitnum]; - - free_page = (max_free - 1) >> (hashp->BSHIFT + BYTE_SHIFT); - free_bit = (max_free - 1) & ((hashp->BSIZE << BYTE_SHIFT) - 1); - - /* Look through all the free maps to find the first free block */ - first_page = hashp->LAST_FREED >>(hashp->BSHIFT + BYTE_SHIFT); - for ( i = first_page; i <= free_page; i++ ) { - if (!(freep = (u_long *)hashp->mapp[i]) && - !(freep = fetch_bitmap(hashp, i))) - return (NULL); - if (i == free_page) - in_use_bits = free_bit; - else - in_use_bits = (hashp->BSIZE << BYTE_SHIFT) - 1; - - if (i == first_page) { - bit = hashp->LAST_FREED & - ((hashp->BSIZE << BYTE_SHIFT) - 1); - j = bit / BITS_PER_MAP; - bit = bit & ~(BITS_PER_MAP - 1); - } else { - bit = 0; - j = 0; - } - for (; bit <= in_use_bits; j++, bit += BITS_PER_MAP) - if (freep[j] != ALL_SET) - goto found; - } - - /* No Free Page Found */ - hashp->LAST_FREED = hashp->SPARES[splitnum]; - hashp->SPARES[splitnum]++; - offset = hashp->SPARES[splitnum] - - (splitnum ? hashp->SPARES[splitnum - 1] : 0); - -#define OVMSG "HASH: Out of overflow pages. Increase page size\n" - if (offset > SPLITMASK) { - if (++splitnum >= NCACHED) { - (void)write(STDERR_FILENO, OVMSG, sizeof(OVMSG) - 1); - return (NULL); - } - hashp->OVFL_POINT = splitnum; - hashp->SPARES[splitnum] = hashp->SPARES[splitnum-1]; - hashp->SPARES[splitnum-1]--; - offset = 1; - } - - /* Check if we need to allocate a new bitmap page */ - if (free_bit == (hashp->BSIZE << BYTE_SHIFT) - 1) { - free_page++; - if (free_page >= NCACHED) { - (void)write(STDERR_FILENO, OVMSG, sizeof(OVMSG) - 1); - return (NULL); - } - /* - * This is tricky. The 1 indicates that you want the new page - * allocated with 1 clear bit. Actually, you are going to - * allocate 2 pages from this map. The first is going to be - * the map page, the second is the overflow page we were - * looking for. The init_bitmap routine automatically, sets - * the first bit of itself to indicate that the bitmap itself - * is in use. We would explicitly set the second bit, but - * don't have to if we tell init_bitmap not to leave it clear - * in the first place. - */ - if (__init_bitmap(hashp, (int)OADDR_OF(splitnum, offset), - 1, free_page)) - return (NULL); - hashp->SPARES[splitnum]++; -#ifdef DEBUG2 - free_bit = 2; -#endif - offset++; - if (offset > SPLITMASK) { - if (++splitnum >= NCACHED) { - (void)write(STDERR_FILENO, OVMSG, - sizeof(OVMSG) - 1); - return (NULL); - } - hashp->OVFL_POINT = splitnum; - hashp->SPARES[splitnum] = hashp->SPARES[splitnum-1]; - hashp->SPARES[splitnum-1]--; - offset = 0; - } - } else { - /* - * Free_bit addresses the last used bit. Bump it to address - * the first available bit. - */ - free_bit++; - SETBIT(freep, free_bit); - } - - /* Calculate address of the new overflow page */ - addr = OADDR_OF(splitnum, offset); -#ifdef DEBUG2 - (void)fprintf(stderr, "OVERFLOW_PAGE: ADDR: %d BIT: %d PAGE %d\n", - addr, free_bit, free_page); -#endif - return (addr); - -found: - bit = bit + first_free(freep[j]); - SETBIT(freep, bit); -#ifdef DEBUG2 - tmp1 = bit; - tmp2 = i; -#endif - /* - * Bits are addressed starting with 0, but overflow pages are addressed - * beginning at 1. Bit is a bit addressnumber, so we need to increment - * it to convert it to a page number. - */ - bit = 1 + bit + (i * (hashp->BSIZE << BYTE_SHIFT)); - if (bit >= hashp->LAST_FREED) - hashp->LAST_FREED = bit - 1; - - /* Calculate the split number for this page */ - for (i = 0; (i < splitnum) && (bit > hashp->SPARES[i]); i++); - offset = (i ? bit - hashp->SPARES[i - 1] : bit); - if (offset >= SPLITMASK) - return (NULL); /* Out of overflow pages */ - addr = OADDR_OF(i, offset); -#ifdef DEBUG2 - (void)fprintf(stderr, "OVERFLOW_PAGE: ADDR: %d BIT: %d PAGE %d\n", - addr, tmp1, tmp2); -#endif - - /* Allocate and return the overflow page */ - return (addr); -} - -/* - * Mark this overflow page as free. - */ -extern void -__free_ovflpage(hashp, obufp) - HTAB *hashp; - BUFHEAD *obufp; -{ - register u_short addr; - u_long *freep; - int bit_address, free_page, free_bit; - u_short ndx; - - addr = obufp->addr; -#ifdef DEBUG1 - (void)fprintf(stderr, "Freeing %d\n", addr); -#endif - ndx = (((u_short)addr) >> SPLITSHIFT); - bit_address = - (ndx ? hashp->SPARES[ndx - 1] : 0) + (addr & SPLITMASK) - 1; - if (bit_address < hashp->LAST_FREED) - hashp->LAST_FREED = bit_address; - free_page = (bit_address >> (hashp->BSHIFT + BYTE_SHIFT)); - free_bit = bit_address & ((hashp->BSIZE << BYTE_SHIFT) - 1); - - if (!(freep = hashp->mapp[free_page])) - freep = fetch_bitmap(hashp, free_page); -#ifdef DEBUG - /* - * This had better never happen. It means we tried to read a bitmap - * that has already had overflow pages allocated off it, and we - * failed to read it from the file. - */ - if (!freep) - assert(0); -#endif - CLRBIT(freep, free_bit); -#ifdef DEBUG2 - (void)fprintf(stderr, "FREE_OVFLPAGE: ADDR: %d BIT: %d PAGE %d\n", - obufp->addr, free_bit, free_page); -#endif - __reclaim_buf(hashp, obufp); -} - -/* - * Returns: - * 0 success - * -1 failure - */ -static int -open_temp(hashp) - HTAB *hashp; -{ - sigset_t set, oset; - static char namestr[] = "_hashXXXXXX"; - - /* Block signals; make sure file goes away at process exit. */ - (void)sigfillset(&set); - (void)sigprocmask(SIG_BLOCK, &set, &oset); - if ((hashp->fp = mkstemp(namestr)) != -1) { - (void)unlink(namestr); - (void)fcntl(hashp->fp, F_SETFD, 1); - } - (void)sigprocmask(SIG_SETMASK, &oset, (sigset_t *)NULL); - return (hashp->fp != -1 ? 0 : -1); -} - -/* - * We have to know that the key will fit, but the last entry on the page is - * an overflow pair, so we need to shift things. - */ -static void -squeeze_key(sp, key, val) - u_short *sp; - const DBT *key, *val; -{ - register char *p; - u_short free_space, n, off, pageno; - - p = (char *)sp; - n = sp[0]; - free_space = FREESPACE(sp); - off = OFFSET(sp); - - pageno = sp[n - 1]; - off -= key->size; - sp[n - 1] = off; - memmove(p + off, key->data, key->size); - off -= val->size; - sp[n] = off; - memmove(p + off, val->data, val->size); - sp[0] = n + 2; - sp[n + 1] = pageno; - sp[n + 2] = OVFLPAGE; - FREESPACE(sp) = free_space - PAIRSIZE(key, val); - OFFSET(sp) = off; -} - -static u_long * -fetch_bitmap(hashp, ndx) - HTAB *hashp; - int ndx; -{ - if (ndx >= hashp->nmaps) - return (NULL); - if ((hashp->mapp[ndx] = (u_long *)malloc(hashp->BSIZE)) == NULL) - return (NULL); - if (__get_page(hashp, - (char *)hashp->mapp[ndx], hashp->BITMAPS[ndx], 0, 1, 1)) { - free(hashp->mapp[ndx]); - return (NULL); - } - return (hashp->mapp[ndx]); -} - -#ifdef DEBUG4 -int -print_chain(addr) - int addr; -{ - BUFHEAD *bufp; - short *bp, oaddr; - - (void)fprintf(stderr, "%d ", addr); - bufp = __get_buf(hashp, addr, NULL, 0); - bp = (short *)bufp->page; - while (bp[0] && ((bp[bp[0]] == OVFLPAGE) || - ((bp[0] > 2) && bp[2] < REAL_KEY))) { - oaddr = bp[bp[0] - 1]; - (void)fprintf(stderr, "%d ", (int)oaddr); - bufp = __get_buf(hashp, (int)oaddr, bufp, 0); - bp = (short *)bufp->page; - } - (void)fprintf(stderr, "\n"); -} -#endif diff --git a/db.subproj/hash.subproj/hsearch.c b/db.subproj/hash.subproj/hsearch.c deleted file mode 100644 index 83ed150..0000000 --- a/db.subproj/hash.subproj/hsearch.c +++ /dev/null @@ -1,125 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Margo Seltzer. - * - * 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 - -#include -#include - -#include -#include "search.h" - -static DB *dbp = NULL; -static ENTRY retval; - -extern int -hcreate(nel) - u_int nel; -{ - HASHINFO info; - - info.nelem = nel; - info.bsize = 256; - info.ffactor = 8; - info.cachesize = NULL; - info.hash = NULL; - info.lorder = 0; - dbp = (DB *)__hash_open(NULL, O_CREAT | O_RDWR, 0600, &info, 0); - return ((int)dbp); -} - -extern ENTRY * -hsearch(item, action) - ENTRY item; - ACTION action; -{ - DBT key, val; - int status; - - if (!dbp) - return (NULL); - key.data = (u_char *)item.key; - key.size = strlen(item.key) + 1; - - if (action == ENTER) { - val.data = (u_char *)item.data; - val.size = strlen(item.data) + 1; - status = (dbp->put)(dbp, &key, &val, R_NOOVERWRITE); - if (status) - return (NULL); - } else { - /* FIND */ - status = (dbp->get)(dbp, &key, &val, 0); - if (status) - return (NULL); - else - item.data = (char *)val.data; - } - retval.key = item.key; - retval.data = item.data; - return (&retval); -} - -extern void -hdestroy() -{ - if (dbp) { - (void)(dbp->close)(dbp); - dbp = NULL; - } -} diff --git a/db.subproj/hash.subproj/ndbm.c b/db.subproj/hash.subproj/ndbm.c deleted file mode 100644 index ca7125b..0000000 --- a/db.subproj/hash.subproj/ndbm.c +++ /dev/null @@ -1,220 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Margo Seltzer. - * - * 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. - */ - - -/* - * This package provides a dbm compatible interface to the new hashing - * package described in db(3). - */ - -#include - -#include -#include -#include - -#include "hash.h" - -/* - * Returns: - * *DBM on success - * NULL on failure - */ -extern DBM * -dbm_open(file, flags, mode) - const char *file; - int flags, mode; -{ - HASHINFO info; - char path[MAXPATHLEN]; - - info.bsize = 4096; - info.ffactor = 40; - info.nelem = 1; - info.cachesize = NULL; - info.hash = NULL; - info.lorder = 0; - (void)strcpy(path, file); - (void)strcat(path, DBM_SUFFIX); - return ((DBM *)__hash_open(path, flags, mode, &info, 0)); -} - -extern void -dbm_close(db) - DBM *db; -{ - (void)(db->close)(db); -} - -/* - * Returns: - * DATUM on success - * NULL on failure - */ -extern datum -dbm_fetch(db, key) - DBM *db; - datum key; -{ - datum retval; - int status; - - status = (db->get)(db, (DBT *)&key, (DBT *)&retval, 0); - if (status) { - retval.dptr = NULL; - retval.dsize = 0; - } - return (retval); -} - -/* - * Returns: - * DATUM on success - * NULL on failure - */ -extern datum -dbm_firstkey(db) - DBM *db; -{ - int status; - datum retdata, retkey; - - status = (db->seq)(db, (DBT *)&retkey, (DBT *)&retdata, R_FIRST); - if (status) - retkey.dptr = NULL; - return (retkey); -} - -/* - * Returns: - * DATUM on success - * NULL on failure - */ -extern datum -dbm_nextkey(db) - DBM *db; -{ - int status; - datum retdata, retkey; - - status = (db->seq)(db, (DBT *)&retkey, (DBT *)&retdata, R_NEXT); - if (status) - retkey.dptr = NULL; - return (retkey); -} -/* - * Returns: - * 0 on success - * <0 failure - */ -extern int -dbm_delete(db, key) - DBM *db; - datum key; -{ - int status; - - status = (db->del)(db, (DBT *)&key, 0); - if (status) - return (-1); - else - return (0); -} - -/* - * Returns: - * 0 on success - * <0 failure - * 1 if DBM_INSERT and entry exists - */ -extern int -dbm_store(db, key, content, flags) - DBM *db; - datum key, content; - int flags; -{ - return ((db->put)(db, (DBT *)&key, (DBT *)&content, - (flags == DBM_INSERT) ? R_NOOVERWRITE : 0)); -} - -extern int -dbm_error(db) - DBM *db; -{ - HTAB *hp; - - hp = (HTAB *)db->internal; - return (hp->error); -} - -extern int -dbm_clearerr(db) - DBM *db; -{ - HTAB *hp; - - hp = (HTAB *)db->internal; - hp->error = 0; - return (0); -} - -extern int -dbm_dirfno(db) - DBM *db; -{ - return(((HTAB *)db->internal)->fp); -} diff --git a/db.subproj/hash.subproj/page.h b/db.subproj/hash.subproj/page.h deleted file mode 100644 index a74c50b..0000000 --- a/db.subproj/hash.subproj/page.h +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Margo Seltzer. - * - * 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. - */ - -/* - * Definitions for hashing page file format. - */ - -/* - * routines dealing with a data page - * - * page format: - * +------------------------------+ - * p | n | keyoff | datoff | keyoff | - * +------------+--------+--------+ - * | datoff | free | ptr | --> | - * +--------+---------------------+ - * | F R E E A R E A | - * +--------------+---------------+ - * | <---- - - - | data | - * +--------+-----+----+----------+ - * | key | data | key | - * +--------+----------+----------+ - * - * Pointer to the free space is always: p[p[0] + 2] - * Amount of free space on the page is: p[p[0] + 1] - */ - -/* - * How many bytes required for this pair? - * 2 shorts in the table at the top of the page + room for the - * key and room for the data - * - * We prohibit entering a pair on a page unless there is also room to append - * an overflow page. The reason for this it that you can get in a situation - * where a single key/data pair fits on a page, but you can't append an - * overflow page and later you'd have to split the key/data and handle like - * a big pair. - * You might as well do this up front. - */ - -#define PAIRSIZE(K,D) (2*sizeof(u_short) + (K)->size + (D)->size) -#define BIGOVERHEAD (4*sizeof(u_short)) -#define KEYSIZE(K) (4*sizeof(u_short) + (K)->size); -#define OVFLSIZE (2*sizeof(u_short)) -#define FREESPACE(P) ((P)[(P)[0]+1]) -#define OFFSET(P) ((P)[(P)[0]+2]) -#define PAIRFITS(P,K,D) \ - (((P)[2] >= REAL_KEY) && \ - (PAIRSIZE((K),(D)) + OVFLSIZE) <= FREESPACE((P))) -#define PAGE_META(N) (((N)+3) * sizeof(u_short)) - -typedef struct { - BUFHEAD *newp; - BUFHEAD *oldp; - BUFHEAD *nextp; - u_short next_addr; -} SPLIT_RETURN; diff --git a/db.subproj/hash.subproj/search.h b/db.subproj/hash.subproj/search.h deleted file mode 100644 index 3196b8f..0000000 --- a/db.subproj/hash.subproj/search.h +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Margo Seltzer. - * - * 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. - */ - -/* Backward compatibility to hsearch interface. */ -typedef struct entry { - char *key; - char *data; -} ENTRY; - -typedef enum { - FIND, ENTER -} ACTION; - -int hcreate __P((unsigned int)); -void hdestroy __P((void)); -ENTRY *hsearch __P((ENTRY, ACTION)); diff --git a/db.subproj/mpool.subproj/Makefile b/db.subproj/mpool.subproj/Makefile deleted file mode 100644 index a127134..0000000 --- a/db.subproj/mpool.subproj/Makefile +++ /dev/null @@ -1,45 +0,0 @@ -# -# Generated by the NeXT Project Builder. -# -# NOTE: Do NOT change this file -- Project Builder maintains it. -# -# Put all of your customizations in files called Makefile.preamble -# and Makefile.postamble (both optional), and Makefile will include them. -# - -NAME = mpool - -PROJECTVERSION = 2.8 -PROJECT_TYPE = Component - -CFILES = mpool.c - -OTHERSRCS = Makefile.preamble Makefile Makefile.postamble - - -MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles -CODE_GEN_STYLE = DYNAMIC -MAKEFILE = subproj.make -LIBS = -DEBUG_LIBS = $(LIBS) -PROF_LIBS = $(LIBS) - - - - -NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc -WINDOWS_OBJCPLUS_COMPILER = $(DEVDIR)/gcc -PDO_UNIX_OBJCPLUS_COMPILER = $(NEXTDEV_BIN)/gcc -NEXTSTEP_JAVA_COMPILER = /usr/bin/javac -WINDOWS_JAVA_COMPILER = $(JDKBINDIR)/javac.exe -PDO_UNIX_JAVA_COMPILER = $(JDKBINDIR)/javac - -include $(MAKEFILEDIR)/platform.make - --include Makefile.preamble - -include $(MAKEFILEDIR)/$(MAKEFILE) - --include Makefile.postamble - --include Makefile.dependencies diff --git a/db.subproj/mpool.subproj/Makefile.postamble b/db.subproj/mpool.subproj/Makefile.postamble deleted file mode 100644 index 411cde6..0000000 --- a/db.subproj/mpool.subproj/Makefile.postamble +++ /dev/null @@ -1,100 +0,0 @@ -############################################################################### -# Makefile.postamble -# Copyright 1997, Apple Computer, Inc. -# -# Use this makefile, which is imported after all other makefiles, to -# override attributes for a project's Makefile environment. This allows you -# to take advantage of the environment set up by the other Makefiles. -# You can also define custom rules at the end of this file. -# -############################################################################### -# -# These variables are exported by the standard makefiles and can be -# used in any customizations you make. They are *outputs* of -# the Makefiles and should be used, not set. -# -# PRODUCTS: products to install. All of these products will be placed in -# the directory $(DSTROOT)$(INSTALLDIR) -# GLOBAL_RESOURCE_DIR: The directory to which resources are copied. -# LOCAL_RESOURCE_DIR: The directory to which localized resources are copied. -# OFILE_DIR: Directory into which .o object files are generated. -# DERIVED_SRC_DIR: Directory used for all other derived files -# -# ALL_CFLAGS: flags to pass when compiling .c files -# ALL_MFLAGS: flags to pass when compiling .m files -# ALL_CCFLAGS: flags to pass when compiling .cc, .cxx, and .C files -# ALL_MMFLAGS: flags to pass when compiling .mm, .mxx, and .M files -# ALL_PRECOMPFLAGS: flags to pass when precompiling .h files -# ALL_LDFLAGS: flags to pass when linking object files -# ALL_LIBTOOL_FLAGS: flags to pass when libtooling object files -# ALL_PSWFLAGS: flags to pass when processing .psw and .pswm (pswrap) files -# ALL_RPCFLAGS: flags to pass when processing .rpc (rpcgen) files -# ALL_YFLAGS: flags to pass when processing .y (yacc) files -# ALL_LFLAGS: flags to pass when processing .l (lex) files -# -# NAME: name of application, bundle, subproject, palette, etc. -# LANGUAGES: langages in which the project is written (default "English") -# English_RESOURCES: localized resources (e.g. nib's, images) of project -# GLOBAL_RESOURCES: non-localized resources of project -# -# SRCROOT: base directory in which to place the new source files -# SRCPATH: relative path from SRCROOT to present subdirectory -# -# INSTALLDIR: Directory the product will be installed into by 'install' target -# PUBLIC_HDR_INSTALLDIR: where to install public headers. Don't forget -# to prefix this with DSTROOT when you use it. -# PRIVATE_HDR_INSTALLDIR: where to install private headers. Don't forget -# to prefix this with DSTROOT when you use it. -# -# EXECUTABLE_EXT: Executable extension for the platform (i.e. .exe on Windows) -# -############################################################################### - -# Some compiler flags can be overridden here for certain build situations. -# -# WARNING_CFLAGS: flag used to set warning level (defaults to -Wmost) -# DEBUG_SYMBOLS_CFLAGS: debug-symbol flag passed to all builds (defaults -# to -g) -# DEBUG_BUILD_CFLAGS: flags passed during debug builds (defaults to -DDEBUG) -# OPTIMIZE_BUILD_CFLAGS: flags passed during optimized builds (defaults -# to -O) -# PROFILE_BUILD_CFLAGS: flags passed during profile builds (defaults -# to -pg -DPROFILE) -# LOCAL_DIR_INCLUDE_DIRECTIVE: flag used to add current directory to -# the include path (defaults to -I.) -# DEBUG_BUILD_LDFLAGS, OPTIMIZE_BUILD_LDFLAGS, PROFILE_BUILD_LDFLAGS: flags -# passed to ld/libtool (defaults to nothing) - - -# Library and Framework projects only: -# INSTALL_NAME_DIRECTIVE: This directive ensures that executables linked -# against the framework will run against the correct version even if -# the current version of the framework changes. You may override this -# to "" as an alternative to using the DYLD_LIBRARY_PATH during your -# development cycle, but be sure to restore it before installing. - - -# Ownership and permissions of files installed by 'install' target - -#INSTALL_AS_USER = root - # User/group ownership -#INSTALL_AS_GROUP = wheel - # (probably want to set both of these) -#INSTALL_PERMISSIONS = - # If set, 'install' chmod's executable to this - - -# Options to strip. Note: -S strips debugging symbols (executables can be stripped -# down further with -x or, if they load no bundles, with no options at all). - -#STRIPFLAGS = -S - - -######################################################################### -# Put rules to extend the behavior of the standard Makefiles here. Include them in -# the dependency tree via cvariables like AFTER_INSTALL in the Makefile.preamble. -# -# You should avoid redefining things like "install" or "app", as they are -# owned by the top-level Makefile API and no context has been set up for where -# derived files should go. -# diff --git a/db.subproj/mpool.subproj/Makefile.preamble b/db.subproj/mpool.subproj/Makefile.preamble deleted file mode 100644 index c1624b4..0000000 --- a/db.subproj/mpool.subproj/Makefile.preamble +++ /dev/null @@ -1,137 +0,0 @@ -############################################################################### -# Makefile.preamble -# Copyright 1997, Apple Computer, Inc. -# -# Use this makefile for configuring the standard application makefiles -# associated with ProjectBuilder. It is included before the main makefile. -# In Makefile.preamble you set attributes for a project, so they are available -# to the project's makefiles. In contrast, you typically write additional rules or -# override built-in behavior in the Makefile.postamble. -# -# Each directory in a project tree (main project plus subprojects) should -# have its own Makefile.preamble and Makefile.postamble. -############################################################################### -# -# Before the main makefile is included for this project, you may set: -# -# MAKEFILEDIR: Directory in which to find $(MAKEFILE) -# MAKEFILE: Top level mechanism Makefile (e.g., app.make, bundle.make) - -# Compiler/linker flags added to the defaults: The OTHER_* variables will be -# inherited by all nested sub-projects, but the LOCAL_ versions of the same -# variables will not. Put your -I, -D, -U, and -L flags in ProjectBuilder's -# Build Attributes inspector if at all possible. To override the default flags -# that get passed to ${CC} (e.g. change -O to -O2), see Makefile.postamble. The -# variables below are *inputs* to the build process and distinct from the override -# settings done (less often) in the Makefile.postamble. -# -# OTHER_CFLAGS, LOCAL_CFLAGS: additional flags to pass to the compiler -# Note that $(OTHER_CFLAGS) and $(LOCAL_CFLAGS) are used for .h, ...c, .m, -# .cc, .cxx, .C, and .M files. There is no need to respecify the -# flags in OTHER_MFLAGS, etc. -# OTHER_MFLAGS, LOCAL_MFLAGS: additional flags for .m files -# OTHER_CCFLAGS, LOCAL_CCFLAGS: additional flags for .cc, .cxx, and ...C files -# OTHER_MMFLAGS, LOCAL_MMFLAGS: additional flags for .mm and .M files -# OTHER_PRECOMPFLAGS, LOCAL_PRECOMPFLAGS: additional flags used when -# precompiling header files -# OTHER_LDFLAGS, LOCAL_LDFLAGS: additional flags passed to ld and libtool -# OTHER_PSWFLAGS, LOCAL_PSWFLAGS: additional flags passed to pswrap -# OTHER_RPCFLAGS, LOCAL_RPCFLAGS: additional flags passed to rpcgen -# OTHER_YFLAGS, LOCAL_YFLAGS: additional flags passed to yacc -# OTHER_LFLAGS, LOCAL_LFLAGS: additional flags passed to lex - -# These variables provide hooks enabling you to add behavior at almost every -# stage of the make: -# -# BEFORE_PREBUILD: targets to build before installing headers for a subproject -# AFTER_PREBUILD: targets to build after installing headers for a subproject -# BEFORE_BUILD_RECURSION: targets to make before building subprojects -# BEFORE_BUILD: targets to make before a build, but after subprojects -# AFTER_BUILD: targets to make after a build -# -# BEFORE_INSTALL: targets to build before installing the product -# AFTER_INSTALL: targets to build after installing the product -# BEFORE_POSTINSTALL: targets to build before postinstalling every subproject -# AFTER_POSTINSTALL: targts to build after postinstalling every subproject -# -# BEFORE_INSTALLHDRS: targets to build before installing headers for a -# subproject -# AFTER_INSTALLHDRS: targets to build after installing headers for a subproject -# BEFORE_INSTALLSRC: targets to build before installing source for a subproject -# AFTER_INSTALLSRC: targets to build after installing source for a subproject -# -# BEFORE_DEPEND: targets to build before building dependencies for a -# subproject -# AFTER_DEPEND: targets to build after building dependencies for a -# subproject -# -# AUTOMATIC_DEPENDENCY_INFO: if YES, then the dependency file is -# updated every time the project is built. If NO, the dependency -# file is only built when the depend target is invoked. - -# Framework-related variables: -# FRAMEWORK_DLL_INSTALLDIR: On Windows platforms, this variable indicates -# where to put the framework's DLL. This variable defaults to -# $(INSTALLDIR)/../Executables - -# Library-related variables: -# PUBLIC_HEADER_DIR: Determines where public exported header files -# should be installed. Do not include $(DSTROOT) in this value -- -# it is prefixed automatically. For library projects you should -# set this to something like /Developer/Headers/$(NAME). Do not set -# this variable for framework projects unless you do not want the -# header files included in the framework. -# PRIVATE_HEADER_DIR: Determines where private exported header files -# should be installed. Do not include $(DSTROOT) in this value -- -# it is prefixed automatically. -# LIBRARY_STYLE: This may be either STATIC or DYNAMIC, and determines -# whether the libraries produced are statically linked when they -# are used or if they are dynamically loadable. This defaults to -# DYNAMIC. -# LIBRARY_DLL_INSTALLDIR: On Windows platforms, this variable indicates -# where to put the library's DLL. This variable defaults to -# $(INSTALLDIR)/../Executables -# -# INSTALL_AS_USER: owner of the intalled products (default root) -# INSTALL_AS_GROUP: group of the installed products (default wheel) -# INSTALL_PERMISSIONS: permissions of the installed product (default o+rX) -# -# OTHER_RECURSIVE_VARIABLES: The names of variables which you want to be -# passed on the command line to recursive invocations of make. Note that -# the values in OTHER_*FLAGS are inherited by subprojects automatically -- -# you do not have to (and shouldn't) add OTHER_*FLAGS to -# OTHER_RECURSIVE_VARIABLES. - -# Additional headers to export beyond those in the PB.project: -# OTHER_PUBLIC_HEADERS -# OTHER_PROJECT_HEADERS -# OTHER_PRIVATE_HEADERS - -# Additional files for the project's product: <> -# OTHER_RESOURCES: (non-localized) resources for this project -# OTHER_OFILES: relocatables to be linked into this project -# OTHER_LIBS: more libraries to link against -# OTHER_PRODUCT_DEPENDS: other dependencies of this project -# OTHER_SOURCEFILES: other source files maintained by .pre/postamble -# OTHER_GARBAGE: additional files to be removed by `make clean' - -# Set this to YES if you don't want a final libtool call for a library/framework. -# BUILD_OFILES_LIST_ONLY - -# To include a version string, project source must exist in a directory named -# $(NAME).%d[.%d][.%d] and the following line must be uncommented. -# OTHER_GENERATED_OFILES = $(VERS_OFILE) - -# This definition will suppress stripping of debug symbols when an executable -# is installed. By default it is YES. -# STRIP_ON_INSTALL = NO - -# Uncomment to suppress generation of a KeyValueCoding index when installing -# frameworks (This index is used by WOB and IB to determine keys available -# for an object). Set to YES by default. -# PREINDEX_FRAMEWORK = NO - -# Change this definition to install projects somewhere other than the -# standard locations. NEXT_ROOT defaults to "C:/Apple" on Windows systems -# and "" on other systems. -DSTROOT = $(HOME) diff --git a/db.subproj/mpool.subproj/PB.project b/db.subproj/mpool.subproj/PB.project deleted file mode 100644 index 06d52a0..0000000 --- a/db.subproj/mpool.subproj/PB.project +++ /dev/null @@ -1,23 +0,0 @@ -{ - DYNAMIC_CODE_GEN = YES; - FILESTABLE = { - H_FILES = (); - OTHER_LINKED = (mpool.c); - OTHER_SOURCES = (Makefile.preamble, Makefile, Makefile.postamble); - SUBPROJECTS = (); - }; - LANGUAGE = English; - MAKEFILEDIR = "$(MAKEFILEPATH)/pb_makefiles"; - NEXTSTEP_BUILDTOOL = /bin/gnumake; - NEXTSTEP_JAVA_COMPILER = /usr/bin/javac; - NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc; - PDO_UNIX_BUILDTOOL = $NEXT_ROOT/Developer/bin/make; - PDO_UNIX_JAVA_COMPILER = "$(JDKBINDIR)/javac"; - PDO_UNIX_OBJCPLUS_COMPILER = "$(NEXTDEV_BIN)/gcc"; - PROJECTNAME = mpool; - PROJECTTYPE = Component; - PROJECTVERSION = 2.8; - WINDOWS_BUILDTOOL = $NEXT_ROOT/Developer/Executables/make; - WINDOWS_JAVA_COMPILER = "$(JDKBINDIR)/javac.exe"; - WINDOWS_OBJCPLUS_COMPILER = "$(DEVDIR)/gcc"; -} diff --git a/db.subproj/mpool.subproj/mpool.c b/db.subproj/mpool.subproj/mpool.c deleted file mode 100644 index d3e9e2e..0000000 --- a/db.subproj/mpool.subproj/mpool.c +++ /dev/null @@ -1,552 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 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 -#include - -#include -#include -#include -#include -#include - -#include -#define __MPOOLINTERFACE_PRIVATE -#include "mpool.h" - -static BKT *mpool_bkt __P((MPOOL *)); -static BKT *mpool_look __P((MPOOL *, pgno_t)); -static int mpool_write __P((MPOOL *, BKT *)); -#ifdef DEBUG -static void __mpoolerr __P((const char *fmt, ...)); -#endif - -/* - * MPOOL_OPEN -- initialize a memory pool. - * - * Parameters: - * key: Shared buffer key. - * fd: File descriptor. - * pagesize: File page size. - * maxcache: Max number of cached pages. - * - * Returns: - * MPOOL pointer, NULL on error. - */ -MPOOL * -mpool_open(key, fd, pagesize, maxcache) - DBT *key; - int fd; - pgno_t pagesize, maxcache; -{ - struct stat sb; - MPOOL *mp; - int entry; - - if (fstat(fd, &sb)) - return (NULL); - /* XXX - * We should only set st_size to 0 for pipes -- 4.4BSD has the fix so - * that stat(2) returns true for ISSOCK on pipes. Until then, this is - * fairly close. - */ - if (!S_ISREG(sb.st_mode)) { - errno = ESPIPE; - return (NULL); - } - - if ((mp = (MPOOL *)malloc(sizeof(MPOOL))) == NULL) - return (NULL); - mp->free.cnext = mp->free.cprev = (BKT *)&mp->free; - mp->lru.cnext = mp->lru.cprev = (BKT *)&mp->lru; - for (entry = 0; entry < HASHSIZE; ++entry) - mp->hashtable[entry].hnext = mp->hashtable[entry].hprev = - mp->hashtable[entry].cnext = mp->hashtable[entry].cprev = - (BKT *)&mp->hashtable[entry]; - mp->curcache = 0; - mp->maxcache = maxcache; - mp->pagesize = pagesize; - mp->npages = sb.st_size / pagesize; - mp->fd = fd; - mp->pgcookie = NULL; - mp->pgin = mp->pgout = NULL; - -#ifdef STATISTICS - mp->cachehit = mp->cachemiss = mp->pagealloc = mp->pageflush = - mp->pageget = mp->pagenew = mp->pageput = mp->pageread = - mp->pagewrite = 0; -#endif - return (mp); -} - -/* - * MPOOL_FILTER -- initialize input/output filters. - * - * Parameters: - * pgin: Page in conversion routine. - * pgout: Page out conversion routine. - * pgcookie: Cookie for page in/out routines. - */ -void -mpool_filter(mp, pgin, pgout, pgcookie) - MPOOL *mp; - void (*pgin) __P((void *, pgno_t, void *)); - void (*pgout) __P((void *, pgno_t, void *)); - void *pgcookie; -{ - mp->pgin = pgin; - mp->pgout = pgout; - mp->pgcookie = pgcookie; -} - -/* - * MPOOL_NEW -- get a new page - * - * Parameters: - * mp: mpool cookie - * pgnoadddr: place to store new page number - * Returns: - * RET_ERROR, RET_SUCCESS - */ -void * -mpool_new(mp, pgnoaddr) - MPOOL *mp; - pgno_t *pgnoaddr; -{ - BKT *b; - BKTHDR *hp; - -#ifdef STATISTICS - ++mp->pagenew; -#endif - /* - * Get a BKT from the cache. Assign a new page number, attach it to - * the hash and lru chains and return. - */ - if ((b = mpool_bkt(mp)) == NULL) - return (NULL); - *pgnoaddr = b->pgno = mp->npages++; - b->flags = MPOOL_PINNED; - inshash(b, b->pgno); - inschain(b, &mp->lru); - return (b->page); -} - -/* - * MPOOL_GET -- get a page from the pool - * - * Parameters: - * mp: mpool cookie - * pgno: page number - * flags: not used - * - * Returns: - * RET_ERROR, RET_SUCCESS - */ -void * -mpool_get(mp, pgno, flags) - MPOOL *mp; - pgno_t pgno; - u_int flags; /* XXX not used? */ -{ - BKT *b; - BKTHDR *hp; - off_t off; - int nr; - - /* - * If asking for a specific page that is already in the cache, find - * it and return it. - */ - if (b = mpool_look(mp, pgno)) { -#ifdef STATISTICS - ++mp->pageget; -#endif -#ifdef DEBUG - if (b->flags & MPOOL_PINNED) - __mpoolerr("mpool_get: page %d already pinned", - b->pgno); -#endif - rmchain(b); - inschain(b, &mp->lru); - b->flags |= MPOOL_PINNED; - return (b->page); - } - - /* Not allowed to retrieve a non-existent page. */ - if (pgno >= mp->npages) { - errno = EINVAL; - return (NULL); - } - - /* Get a page from the cache. */ - if ((b = mpool_bkt(mp)) == NULL) - return (NULL); - b->pgno = pgno; - b->flags = MPOOL_PINNED; - -#ifdef STATISTICS - ++mp->pageread; -#endif - /* Read in the contents. */ - off = mp->pagesize * pgno; - if (lseek(mp->fd, off, SEEK_SET) != off) - return (NULL); - if ((nr = read(mp->fd, b->page, mp->pagesize)) != mp->pagesize) { - if (nr >= 0) - errno = EFTYPE; - return (NULL); - } - if (mp->pgin) - (mp->pgin)(mp->pgcookie, b->pgno, b->page); - - inshash(b, b->pgno); - inschain(b, &mp->lru); -#ifdef STATISTICS - ++mp->pageget; -#endif - return (b->page); -} - -/* - * MPOOL_PUT -- return a page to the pool - * - * Parameters: - * mp: mpool cookie - * page: page pointer - * pgno: page number - * - * Returns: - * RET_ERROR, RET_SUCCESS - */ -int -mpool_put(mp, page, flags) - MPOOL *mp; - void *page; - u_int flags; -{ - BKT *baddr; -#ifdef DEBUG - BKT *b; -#endif - -#ifdef STATISTICS - ++mp->pageput; -#endif - baddr = (BKT *)((char *)page - sizeof(BKT)); -#ifdef DEBUG - if (!(baddr->flags & MPOOL_PINNED)) - __mpoolerr("mpool_put: page %d not pinned", b->pgno); - for (b = mp->lru.cnext; b != (BKT *)&mp->lru; b = b->cnext) { - if (b == (BKT *)&mp->lru) - __mpoolerr("mpool_put: %0x: bad address", baddr); - if (b == baddr) - break; - } -#endif - baddr->flags &= ~MPOOL_PINNED; - baddr->flags |= flags & MPOOL_DIRTY; - return (RET_SUCCESS); -} - -/* - * MPOOL_CLOSE -- close the buffer pool - * - * Parameters: - * mp: mpool cookie - * - * Returns: - * RET_ERROR, RET_SUCCESS - */ -int -mpool_close(mp) - MPOOL *mp; -{ - BKT *b, *next; - - /* Free up any space allocated to the lru pages. */ - for (b = mp->lru.cprev; b != (BKT *)&mp->lru; b = next) { - next = b->cprev; - free(b); - } - free(mp); - return (RET_SUCCESS); -} - -/* - * MPOOL_SYNC -- sync the file to disk. - * - * Parameters: - * mp: mpool cookie - * - * Returns: - * RET_ERROR, RET_SUCCESS - */ -int -mpool_sync(mp) - MPOOL *mp; -{ - BKT *b; - - for (b = mp->lru.cprev; b != (BKT *)&mp->lru; b = b->cprev) - if (b->flags & MPOOL_DIRTY && mpool_write(mp, b) == RET_ERROR) - return (RET_ERROR); - return (fsync(mp->fd) ? RET_ERROR : RET_SUCCESS); -} - -/* - * MPOOL_BKT -- get/create a BKT from the cache - * - * Parameters: - * mp: mpool cookie - * - * Returns: - * NULL on failure and a pointer to the BKT on success - */ -static BKT * -mpool_bkt(mp) - MPOOL *mp; -{ - BKT *b; - - if (mp->curcache < mp->maxcache) - goto new; - - /* - * If the cache is maxxed out, search the lru list for a buffer we - * can flush. If we find one, write it if necessary and take it off - * any lists. If we don't find anything we grow the cache anyway. - * The cache never shrinks. - */ - for (b = mp->lru.cprev; b != (BKT *)&mp->lru; b = b->cprev) - if (!(b->flags & MPOOL_PINNED)) { - if (b->flags & MPOOL_DIRTY && - mpool_write(mp, b) == RET_ERROR) - return (NULL); - rmhash(b); - rmchain(b); -#ifdef STATISTICS - ++mp->pageflush; -#endif -#ifdef DEBUG - { - void *spage; - spage = b->page; - memset(b, 0xff, sizeof(BKT) + mp->pagesize); - b->page = spage; - } -#endif - return (b); - } - -new: if ((b = (BKT *)malloc(sizeof(BKT) + mp->pagesize)) == NULL) - return (NULL); -#ifdef STATISTICS - ++mp->pagealloc; -#endif -#ifdef DEBUG - memset(b, 0xff, sizeof(BKT) + mp->pagesize); -#endif - b->page = (char *)b + sizeof(BKT); - ++mp->curcache; - return (b); -} - -/* - * MPOOL_WRITE -- sync a page to disk - * - * Parameters: - * mp: mpool cookie - * - * Returns: - * RET_ERROR, RET_SUCCESS - */ -static int -mpool_write(mp, b) - MPOOL *mp; - BKT *b; -{ - off_t off; - - if (mp->pgout) - (mp->pgout)(mp->pgcookie, b->pgno, b->page); - -#ifdef STATISTICS - ++mp->pagewrite; -#endif - off = mp->pagesize * b->pgno; - if (lseek(mp->fd, off, SEEK_SET) != off) - return (RET_ERROR); - if (write(mp->fd, b->page, mp->pagesize) != mp->pagesize) - return (RET_ERROR); - b->flags &= ~MPOOL_DIRTY; - return (RET_SUCCESS); -} - -/* - * MPOOL_LOOK -- lookup a page - * - * Parameters: - * mp: mpool cookie - * pgno: page number - * - * Returns: - * NULL on failure and a pointer to the BKT on success - */ -static BKT * -mpool_look(mp, pgno) - MPOOL *mp; - pgno_t pgno; -{ - register BKT *b; - register BKTHDR *tb; - - /* XXX - * If find the buffer, put it first on the hash chain so can - * find it again quickly. - */ - tb = &mp->hashtable[HASHKEY(pgno)]; - for (b = tb->hnext; b != (BKT *)tb; b = b->hnext) - if (b->pgno == pgno) { -#ifdef STATISTICS - ++mp->cachehit; -#endif - return (b); - } -#ifdef STATISTICS - ++mp->cachemiss; -#endif - return (NULL); -} - -#ifdef STATISTICS -/* - * MPOOL_STAT -- cache statistics - * - * Parameters: - * mp: mpool cookie - */ -void -mpool_stat(mp) - MPOOL *mp; -{ - BKT *b; - int cnt; - char *sep; - - (void)fprintf(stderr, "%lu pages in the file\n", mp->npages); - (void)fprintf(stderr, - "page size %lu, cacheing %lu pages of %lu 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); - (void)fprintf(stderr, "%lu page allocs, %lu page flushes\n", - mp->pagealloc, mp->pageflush); - if (mp->cachehit + mp->cachemiss) - (void)fprintf(stderr, - "%.0f%% cache hit rate (%lu hits, %lu misses)\n", - ((double)mp->cachehit / (mp->cachehit + mp->cachemiss)) - * 100, mp->cachehit, mp->cachemiss); - (void)fprintf(stderr, "%lu page reads, %lu page writes\n", - mp->pageread, mp->pagewrite); - - sep = ""; - cnt = 0; - for (b = mp->lru.cnext; b != (BKT *)&mp->lru; b = b->cnext) { - (void)fprintf(stderr, "%s%d", sep, b->pgno); - if (b->flags & MPOOL_DIRTY) - (void)fprintf(stderr, "d"); - if (b->flags & MPOOL_PINNED) - (void)fprintf(stderr, "P"); - if (++cnt == 10) { - sep = "\n"; - cnt = 0; - } else - sep = ", "; - - } - (void)fprintf(stderr, "\n"); -} -#endif - -#ifdef DEBUG -#if __STDC__ -#include -#else -#include -#endif - -static void -#if __STDC__ -__mpoolerr(const char *fmt, ...) -#else -__mpoolerr(fmt, va_alist) - char *fmt; - va_dcl -#endif -{ - va_list ap; -#if __STDC__ - va_start(ap, fmt); -#else - va_start(ap); -#endif - (void)vfprintf(stderr, fmt, ap); - va_end(ap); - (void)fprintf(stderr, "\n"); - abort(); - /* NOTREACHED */ -} -#endif diff --git a/db.subproj/recno.subproj/Makefile b/db.subproj/recno.subproj/Makefile deleted file mode 100644 index 56520b7..0000000 --- a/db.subproj/recno.subproj/Makefile +++ /dev/null @@ -1,48 +0,0 @@ -# -# Generated by the NeXT Project Builder. -# -# NOTE: Do NOT change this file -- Project Builder maintains it. -# -# Put all of your customizations in files called Makefile.preamble -# and Makefile.postamble (both optional), and Makefile will include them. -# - -NAME = recno - -PROJECTVERSION = 2.8 -PROJECT_TYPE = Component - -HFILES = extern.h recno.h - -CFILES = rec_close.c rec_delete.c rec_get.c rec_open.c rec_put.c\ - rec_search.c rec_seq.c rec_utils.c - -OTHERSRCS = Makefile.preamble Makefile Makefile.postamble - - -MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles -CODE_GEN_STYLE = DYNAMIC -MAKEFILE = subproj.make -LIBS = -DEBUG_LIBS = $(LIBS) -PROF_LIBS = $(LIBS) - - - - -NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc -WINDOWS_OBJCPLUS_COMPILER = $(DEVDIR)/gcc -PDO_UNIX_OBJCPLUS_COMPILER = $(NEXTDEV_BIN)/gcc -NEXTSTEP_JAVA_COMPILER = /usr/bin/javac -WINDOWS_JAVA_COMPILER = $(JDKBINDIR)/javac.exe -PDO_UNIX_JAVA_COMPILER = $(JDKBINDIR)/javac - -include $(MAKEFILEDIR)/platform.make - --include Makefile.preamble - -include $(MAKEFILEDIR)/$(MAKEFILE) - --include Makefile.postamble - --include Makefile.dependencies diff --git a/db.subproj/recno.subproj/Makefile.postamble b/db.subproj/recno.subproj/Makefile.postamble deleted file mode 100644 index 411cde6..0000000 --- a/db.subproj/recno.subproj/Makefile.postamble +++ /dev/null @@ -1,100 +0,0 @@ -############################################################################### -# Makefile.postamble -# Copyright 1997, Apple Computer, Inc. -# -# Use this makefile, which is imported after all other makefiles, to -# override attributes for a project's Makefile environment. This allows you -# to take advantage of the environment set up by the other Makefiles. -# You can also define custom rules at the end of this file. -# -############################################################################### -# -# These variables are exported by the standard makefiles and can be -# used in any customizations you make. They are *outputs* of -# the Makefiles and should be used, not set. -# -# PRODUCTS: products to install. All of these products will be placed in -# the directory $(DSTROOT)$(INSTALLDIR) -# GLOBAL_RESOURCE_DIR: The directory to which resources are copied. -# LOCAL_RESOURCE_DIR: The directory to which localized resources are copied. -# OFILE_DIR: Directory into which .o object files are generated. -# DERIVED_SRC_DIR: Directory used for all other derived files -# -# ALL_CFLAGS: flags to pass when compiling .c files -# ALL_MFLAGS: flags to pass when compiling .m files -# ALL_CCFLAGS: flags to pass when compiling .cc, .cxx, and .C files -# ALL_MMFLAGS: flags to pass when compiling .mm, .mxx, and .M files -# ALL_PRECOMPFLAGS: flags to pass when precompiling .h files -# ALL_LDFLAGS: flags to pass when linking object files -# ALL_LIBTOOL_FLAGS: flags to pass when libtooling object files -# ALL_PSWFLAGS: flags to pass when processing .psw and .pswm (pswrap) files -# ALL_RPCFLAGS: flags to pass when processing .rpc (rpcgen) files -# ALL_YFLAGS: flags to pass when processing .y (yacc) files -# ALL_LFLAGS: flags to pass when processing .l (lex) files -# -# NAME: name of application, bundle, subproject, palette, etc. -# LANGUAGES: langages in which the project is written (default "English") -# English_RESOURCES: localized resources (e.g. nib's, images) of project -# GLOBAL_RESOURCES: non-localized resources of project -# -# SRCROOT: base directory in which to place the new source files -# SRCPATH: relative path from SRCROOT to present subdirectory -# -# INSTALLDIR: Directory the product will be installed into by 'install' target -# PUBLIC_HDR_INSTALLDIR: where to install public headers. Don't forget -# to prefix this with DSTROOT when you use it. -# PRIVATE_HDR_INSTALLDIR: where to install private headers. Don't forget -# to prefix this with DSTROOT when you use it. -# -# EXECUTABLE_EXT: Executable extension for the platform (i.e. .exe on Windows) -# -############################################################################### - -# Some compiler flags can be overridden here for certain build situations. -# -# WARNING_CFLAGS: flag used to set warning level (defaults to -Wmost) -# DEBUG_SYMBOLS_CFLAGS: debug-symbol flag passed to all builds (defaults -# to -g) -# DEBUG_BUILD_CFLAGS: flags passed during debug builds (defaults to -DDEBUG) -# OPTIMIZE_BUILD_CFLAGS: flags passed during optimized builds (defaults -# to -O) -# PROFILE_BUILD_CFLAGS: flags passed during profile builds (defaults -# to -pg -DPROFILE) -# LOCAL_DIR_INCLUDE_DIRECTIVE: flag used to add current directory to -# the include path (defaults to -I.) -# DEBUG_BUILD_LDFLAGS, OPTIMIZE_BUILD_LDFLAGS, PROFILE_BUILD_LDFLAGS: flags -# passed to ld/libtool (defaults to nothing) - - -# Library and Framework projects only: -# INSTALL_NAME_DIRECTIVE: This directive ensures that executables linked -# against the framework will run against the correct version even if -# the current version of the framework changes. You may override this -# to "" as an alternative to using the DYLD_LIBRARY_PATH during your -# development cycle, but be sure to restore it before installing. - - -# Ownership and permissions of files installed by 'install' target - -#INSTALL_AS_USER = root - # User/group ownership -#INSTALL_AS_GROUP = wheel - # (probably want to set both of these) -#INSTALL_PERMISSIONS = - # If set, 'install' chmod's executable to this - - -# Options to strip. Note: -S strips debugging symbols (executables can be stripped -# down further with -x or, if they load no bundles, with no options at all). - -#STRIPFLAGS = -S - - -######################################################################### -# Put rules to extend the behavior of the standard Makefiles here. Include them in -# the dependency tree via cvariables like AFTER_INSTALL in the Makefile.preamble. -# -# You should avoid redefining things like "install" or "app", as they are -# owned by the top-level Makefile API and no context has been set up for where -# derived files should go. -# diff --git a/db.subproj/recno.subproj/Makefile.preamble b/db.subproj/recno.subproj/Makefile.preamble deleted file mode 100644 index c1624b4..0000000 --- a/db.subproj/recno.subproj/Makefile.preamble +++ /dev/null @@ -1,137 +0,0 @@ -############################################################################### -# Makefile.preamble -# Copyright 1997, Apple Computer, Inc. -# -# Use this makefile for configuring the standard application makefiles -# associated with ProjectBuilder. It is included before the main makefile. -# In Makefile.preamble you set attributes for a project, so they are available -# to the project's makefiles. In contrast, you typically write additional rules or -# override built-in behavior in the Makefile.postamble. -# -# Each directory in a project tree (main project plus subprojects) should -# have its own Makefile.preamble and Makefile.postamble. -############################################################################### -# -# Before the main makefile is included for this project, you may set: -# -# MAKEFILEDIR: Directory in which to find $(MAKEFILE) -# MAKEFILE: Top level mechanism Makefile (e.g., app.make, bundle.make) - -# Compiler/linker flags added to the defaults: The OTHER_* variables will be -# inherited by all nested sub-projects, but the LOCAL_ versions of the same -# variables will not. Put your -I, -D, -U, and -L flags in ProjectBuilder's -# Build Attributes inspector if at all possible. To override the default flags -# that get passed to ${CC} (e.g. change -O to -O2), see Makefile.postamble. The -# variables below are *inputs* to the build process and distinct from the override -# settings done (less often) in the Makefile.postamble. -# -# OTHER_CFLAGS, LOCAL_CFLAGS: additional flags to pass to the compiler -# Note that $(OTHER_CFLAGS) and $(LOCAL_CFLAGS) are used for .h, ...c, .m, -# .cc, .cxx, .C, and .M files. There is no need to respecify the -# flags in OTHER_MFLAGS, etc. -# OTHER_MFLAGS, LOCAL_MFLAGS: additional flags for .m files -# OTHER_CCFLAGS, LOCAL_CCFLAGS: additional flags for .cc, .cxx, and ...C files -# OTHER_MMFLAGS, LOCAL_MMFLAGS: additional flags for .mm and .M files -# OTHER_PRECOMPFLAGS, LOCAL_PRECOMPFLAGS: additional flags used when -# precompiling header files -# OTHER_LDFLAGS, LOCAL_LDFLAGS: additional flags passed to ld and libtool -# OTHER_PSWFLAGS, LOCAL_PSWFLAGS: additional flags passed to pswrap -# OTHER_RPCFLAGS, LOCAL_RPCFLAGS: additional flags passed to rpcgen -# OTHER_YFLAGS, LOCAL_YFLAGS: additional flags passed to yacc -# OTHER_LFLAGS, LOCAL_LFLAGS: additional flags passed to lex - -# These variables provide hooks enabling you to add behavior at almost every -# stage of the make: -# -# BEFORE_PREBUILD: targets to build before installing headers for a subproject -# AFTER_PREBUILD: targets to build after installing headers for a subproject -# BEFORE_BUILD_RECURSION: targets to make before building subprojects -# BEFORE_BUILD: targets to make before a build, but after subprojects -# AFTER_BUILD: targets to make after a build -# -# BEFORE_INSTALL: targets to build before installing the product -# AFTER_INSTALL: targets to build after installing the product -# BEFORE_POSTINSTALL: targets to build before postinstalling every subproject -# AFTER_POSTINSTALL: targts to build after postinstalling every subproject -# -# BEFORE_INSTALLHDRS: targets to build before installing headers for a -# subproject -# AFTER_INSTALLHDRS: targets to build after installing headers for a subproject -# BEFORE_INSTALLSRC: targets to build before installing source for a subproject -# AFTER_INSTALLSRC: targets to build after installing source for a subproject -# -# BEFORE_DEPEND: targets to build before building dependencies for a -# subproject -# AFTER_DEPEND: targets to build after building dependencies for a -# subproject -# -# AUTOMATIC_DEPENDENCY_INFO: if YES, then the dependency file is -# updated every time the project is built. If NO, the dependency -# file is only built when the depend target is invoked. - -# Framework-related variables: -# FRAMEWORK_DLL_INSTALLDIR: On Windows platforms, this variable indicates -# where to put the framework's DLL. This variable defaults to -# $(INSTALLDIR)/../Executables - -# Library-related variables: -# PUBLIC_HEADER_DIR: Determines where public exported header files -# should be installed. Do not include $(DSTROOT) in this value -- -# it is prefixed automatically. For library projects you should -# set this to something like /Developer/Headers/$(NAME). Do not set -# this variable for framework projects unless you do not want the -# header files included in the framework. -# PRIVATE_HEADER_DIR: Determines where private exported header files -# should be installed. Do not include $(DSTROOT) in this value -- -# it is prefixed automatically. -# LIBRARY_STYLE: This may be either STATIC or DYNAMIC, and determines -# whether the libraries produced are statically linked when they -# are used or if they are dynamically loadable. This defaults to -# DYNAMIC. -# LIBRARY_DLL_INSTALLDIR: On Windows platforms, this variable indicates -# where to put the library's DLL. This variable defaults to -# $(INSTALLDIR)/../Executables -# -# INSTALL_AS_USER: owner of the intalled products (default root) -# INSTALL_AS_GROUP: group of the installed products (default wheel) -# INSTALL_PERMISSIONS: permissions of the installed product (default o+rX) -# -# OTHER_RECURSIVE_VARIABLES: The names of variables which you want to be -# passed on the command line to recursive invocations of make. Note that -# the values in OTHER_*FLAGS are inherited by subprojects automatically -- -# you do not have to (and shouldn't) add OTHER_*FLAGS to -# OTHER_RECURSIVE_VARIABLES. - -# Additional headers to export beyond those in the PB.project: -# OTHER_PUBLIC_HEADERS -# OTHER_PROJECT_HEADERS -# OTHER_PRIVATE_HEADERS - -# Additional files for the project's product: <> -# OTHER_RESOURCES: (non-localized) resources for this project -# OTHER_OFILES: relocatables to be linked into this project -# OTHER_LIBS: more libraries to link against -# OTHER_PRODUCT_DEPENDS: other dependencies of this project -# OTHER_SOURCEFILES: other source files maintained by .pre/postamble -# OTHER_GARBAGE: additional files to be removed by `make clean' - -# Set this to YES if you don't want a final libtool call for a library/framework. -# BUILD_OFILES_LIST_ONLY - -# To include a version string, project source must exist in a directory named -# $(NAME).%d[.%d][.%d] and the following line must be uncommented. -# OTHER_GENERATED_OFILES = $(VERS_OFILE) - -# This definition will suppress stripping of debug symbols when an executable -# is installed. By default it is YES. -# STRIP_ON_INSTALL = NO - -# Uncomment to suppress generation of a KeyValueCoding index when installing -# frameworks (This index is used by WOB and IB to determine keys available -# for an object). Set to YES by default. -# PREINDEX_FRAMEWORK = NO - -# Change this definition to install projects somewhere other than the -# standard locations. NEXT_ROOT defaults to "C:/Apple" on Windows systems -# and "" on other systems. -DSTROOT = $(HOME) diff --git a/db.subproj/recno.subproj/PB.project b/db.subproj/recno.subproj/PB.project deleted file mode 100644 index 3a7b202..0000000 --- a/db.subproj/recno.subproj/PB.project +++ /dev/null @@ -1,32 +0,0 @@ -{ - DYNAMIC_CODE_GEN = YES; - FILESTABLE = { - H_FILES = (extern.h, recno.h); - OTHER_LINKED = ( - rec_close.c, - rec_delete.c, - rec_get.c, - rec_open.c, - rec_put.c, - rec_search.c, - rec_seq.c, - rec_utils.c - ); - OTHER_SOURCES = (Makefile.preamble, Makefile, Makefile.postamble); - SUBPROJECTS = (); - }; - LANGUAGE = English; - MAKEFILEDIR = "$(MAKEFILEPATH)/pb_makefiles"; - NEXTSTEP_BUILDTOOL = /bin/gnumake; - NEXTSTEP_JAVA_COMPILER = /usr/bin/javac; - NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc; - PDO_UNIX_BUILDTOOL = $NEXT_ROOT/Developer/bin/make; - PDO_UNIX_JAVA_COMPILER = "$(JDKBINDIR)/javac"; - PDO_UNIX_OBJCPLUS_COMPILER = "$(NEXTDEV_BIN)/gcc"; - PROJECTNAME = recno; - PROJECTTYPE = Component; - PROJECTVERSION = 2.8; - WINDOWS_BUILDTOOL = $NEXT_ROOT/Developer/Executables/make; - WINDOWS_JAVA_COMPILER = "$(JDKBINDIR)/javac.exe"; - WINDOWS_OBJCPLUS_COMPILER = "$(DEVDIR)/gcc"; -} diff --git a/db.subproj/recno.subproj/extern.h b/db.subproj/recno.subproj/extern.h deleted file mode 100644 index d903770..0000000 --- a/db.subproj/recno.subproj/extern.h +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * 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. - */ - -#include "bt_extern.h" - -int __rec_close __P((DB *)); -int __rec_delete __P((const DB *, const DBT *, u_int)); -int __rec_dleaf __P((BTREE *, PAGE *, indx_t)); -int __rec_fd __P((const DB *)); -int __rec_fmap __P((BTREE *, recno_t)); -int __rec_fout __P((BTREE *)); -int __rec_fpipe __P((BTREE *, recno_t)); -int __rec_get __P((const DB *, const DBT *, DBT *, u_int)); -int __rec_iput __P((BTREE *, recno_t, const DBT *, u_int)); -int __rec_put __P((const DB *dbp, DBT *, const DBT *, u_int)); -int __rec_ret __P((BTREE *, EPG *, recno_t, DBT *, DBT *)); -EPG *__rec_search __P((BTREE *, recno_t, enum SRCHOP)); -int __rec_seq __P((const DB *, DBT *, DBT *, u_int)); -int __rec_sync __P((const DB *, u_int)); -int __rec_vmap __P((BTREE *, recno_t)); -int __rec_vout __P((BTREE *)); -int __rec_vpipe __P((BTREE *, recno_t)); diff --git a/db.subproj/recno.subproj/rec_close.c b/db.subproj/recno.subproj/rec_close.c deleted file mode 100644 index 7c57f5f..0000000 --- a/db.subproj/recno.subproj/rec_close.c +++ /dev/null @@ -1,183 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 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 -#include - -#include - -#include -#include -#include -#include - -#include -#include "recno.h" - -/* - * __REC_CLOSE -- Close a recno tree. - * - * Parameters: - * dbp: pointer to access method - * - * Returns: - * RET_ERROR, RET_SUCCESS - */ -int -__rec_close(dbp) - DB *dbp; -{ - BTREE *t; - int status; - - t = dbp->internal; - - /* Toss any page pinned across calls. */ - if (t->bt_pinned != NULL) { - mpool_put(t->bt_mp, t->bt_pinned, 0); - t->bt_pinned = NULL; - } - - if (__rec_sync(dbp, 0) == RET_ERROR) - return (RET_ERROR); - - /* Committed to closing. */ - status = RET_SUCCESS; - if (ISSET(t, R_MEMMAPPED) - && vm_deallocate(mach_task_self(), (vm_offset_t) t->bt_smap, t->bt_msize)) - status = RET_ERROR; - - if (!ISSET(t, R_INMEM)) - if (ISSET(t, R_CLOSEFP)) { - if (fclose(t->bt_rfp)) - status = RET_ERROR; - } else - if (close(t->bt_rfd)) - status = RET_ERROR; - - if (__bt_close(dbp) == RET_ERROR) - status = RET_ERROR; - - return (status); -} - -/* - * __REC_SYNC -- sync the recno tree to disk. - * - * Parameters: - * dbp: pointer to access method - * - * Returns: - * RET_SUCCESS, RET_ERROR. - */ -int -__rec_sync(dbp, flags) - const DB *dbp; - u_int flags; -{ - struct iovec iov[2]; - BTREE *t; - DBT data, key; - off_t off; - recno_t scursor, trec; - int status; - - t = dbp->internal; - - /* Toss any page pinned across calls. */ - if (t->bt_pinned != NULL) { - mpool_put(t->bt_mp, t->bt_pinned, 0); - t->bt_pinned = NULL; - } - - if (flags == R_RECNOSYNC) - return (__bt_sync(dbp, 0)); - - if (ISSET(t, R_RDONLY | R_INMEM) || !ISSET(t, R_MODIFIED)) - return (RET_SUCCESS); - - /* Read any remaining records into the tree. */ - if (!ISSET(t, R_EOF) && t->bt_irec(t, MAX_REC_NUMBER) == RET_ERROR) - return (RET_ERROR); - - /* Rewind the file descriptor. */ - if (lseek(t->bt_rfd, (off_t)0, SEEK_SET) != 0) - return (RET_ERROR); - - iov[1].iov_base = "\n"; - iov[1].iov_len = 1; - scursor = t->bt_rcursor; - - key.size = sizeof(recno_t); - key.data = &trec; - - status = (dbp->seq)(dbp, &key, &data, R_FIRST); - while (status == RET_SUCCESS) { - iov[0].iov_base = data.data; - iov[0].iov_len = data.size; - if (writev(t->bt_rfd, iov, 2) != data.size + 1) - return (RET_ERROR); - status = (dbp->seq)(dbp, &key, &data, R_NEXT); - } - t->bt_rcursor = scursor; - if (status == RET_ERROR) - return (RET_ERROR); - if ((off = lseek(t->bt_rfd, (off_t)0, SEEK_CUR)) == -1) - return (RET_ERROR); - if (ftruncate(t->bt_rfd, off)) - return (RET_ERROR); - CLR(t, R_MODIFIED); - return (RET_SUCCESS); -} diff --git a/db.subproj/recno.subproj/rec_delete.c b/db.subproj/recno.subproj/rec_delete.c deleted file mode 100644 index 126cd7f..0000000 --- a/db.subproj/recno.subproj/rec_delete.c +++ /dev/null @@ -1,215 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Mike Olson. - * - * 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 - -#include -#include -#include - -#include -#include "recno.h" - -static int rec_rdelete __P((BTREE *, recno_t)); - -/* - * __REC_DELETE -- Delete the item(s) referenced by a key. - * - * Parameters: - * dbp: pointer to access method - * key: key to delete - * flags: R_CURSOR if deleting what the cursor references - * - * Returns: - * RET_ERROR, RET_SUCCESS and RET_SPECIAL if the key not found. - */ -int -__rec_delete(dbp, key, flags) - const DB *dbp; - const DBT *key; - u_int flags; -{ - BTREE *t; - recno_t nrec; - int status; - - t = dbp->internal; - - /* Toss any page pinned across calls. */ - if (t->bt_pinned != NULL) { - mpool_put(t->bt_mp, t->bt_pinned, 0); - t->bt_pinned = NULL; - } - - switch(flags) { - case 0: - if ((nrec = *(recno_t *)key->data) == 0) - goto einval; - if (nrec > t->bt_nrecs) - return (RET_SPECIAL); - --nrec; - status = rec_rdelete(t, nrec); - break; - case R_CURSOR: - if (!ISSET(t, B_SEQINIT)) - goto einval; - if (t->bt_nrecs == 0) - return (RET_SPECIAL); - status = rec_rdelete(t, t->bt_rcursor - 1); - if (status == RET_SUCCESS) - --t->bt_rcursor; - break; - default: -einval: errno = EINVAL; - return (RET_ERROR); - } - - if (status == RET_SUCCESS) - SET(t, B_MODIFIED | R_MODIFIED); - return (status); -} - -/* - * REC_RDELETE -- Delete the data matching the specified key. - * - * Parameters: - * tree: tree - * nrec: record to delete - * - * Returns: - * RET_ERROR, RET_SUCCESS and RET_SPECIAL if the key not found. - */ -static int -rec_rdelete(t, nrec) - BTREE *t; - recno_t nrec; -{ - EPG *e; - PAGE *h; - int status; - - /* Find the record; __rec_search pins the page. */ - if ((e = __rec_search(t, nrec, SDELETE)) == NULL) - return (RET_ERROR); - - /* Delete the record. */ - h = e->page; - status = __rec_dleaf(t, h, e->index); - if (status != RET_SUCCESS) { - mpool_put(t->bt_mp, h, 0); - return (status); - } - mpool_put(t->bt_mp, h, MPOOL_DIRTY); - return (RET_SUCCESS); -} - -/* - * __REC_DLEAF -- Delete a single record from a recno leaf page. - * - * Parameters: - * t: tree - * index: index on current page to delete - * - * Returns: - * RET_SUCCESS, RET_ERROR. - */ -int -__rec_dleaf(t, h, index) - BTREE *t; - PAGE *h; - indx_t index; -{ - register RLEAF *rl; - register indx_t *ip, cnt, offset; - register size_t nbytes; - char *from; - void *to; - - /* - * Delete a record from a recno leaf page. Internal records are never - * deleted from internal pages, regardless of the records that caused - * them to be added being deleted. Pages made empty by deletion are - * not reclaimed. They are, however, made available for reuse. - * - * Pack the remaining entries at the end of the page, shift the indices - * down, overwriting the deleted record and its index. If the record - * uses overflow pages, make them available for reuse. - */ - to = rl = GETRLEAF(h, index); - if (rl->flags & P_BIGDATA && __ovfl_delete(t, rl->bytes) == RET_ERROR) - return (RET_ERROR); - nbytes = NRLEAF(rl); - - /* - * Compress the key/data pairs. Compress and adjust the [BR]LEAF - * offsets. Reset the headers. - */ - from = (char *)h + h->upper; - memmove(from + nbytes, from, (char *)to - from); - h->upper += nbytes; - - offset = h->linp[index]; - for (cnt = &h->linp[index] - (ip = &h->linp[0]); cnt--; ++ip) - if (ip[0] < offset) - ip[0] += nbytes; - for (cnt = &h->linp[NEXTINDEX(h)] - ip; --cnt; ++ip) - ip[0] = ip[1] < offset ? ip[1] + nbytes : ip[1]; - h->lower -= sizeof(indx_t); - --t->bt_nrecs; - return (RET_SUCCESS); -} diff --git a/db.subproj/recno.subproj/rec_get.c b/db.subproj/recno.subproj/rec_get.c deleted file mode 100644 index a14bfc2..0000000 --- a/db.subproj/recno.subproj/rec_get.c +++ /dev/null @@ -1,316 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 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 - -#include -#include -#include -#include -#include -#include - -#include -#include "recno.h" - -/* - * __REC_GET -- Get a record from the btree. - * - * Parameters: - * dbp: pointer to access method - * key: key to find - * data: data to return - * flag: currently unused - * - * Returns: - * RET_ERROR, RET_SUCCESS and RET_SPECIAL if the key not found. - */ -int -__rec_get(dbp, key, data, flags) - const DB *dbp; - const DBT *key; - DBT *data; - u_int flags; -{ - BTREE *t; - EPG *e; - recno_t nrec; - int status; - - t = dbp->internal; - - /* Toss any page pinned across calls. */ - if (t->bt_pinned != NULL) { - mpool_put(t->bt_mp, t->bt_pinned, 0); - t->bt_pinned = NULL; - } - - /* Get currently doesn't take any flags, and keys of 0 are illegal. */ - if (flags || (nrec = *(recno_t *)key->data) == 0) { - errno = EINVAL; - return (RET_ERROR); - } - - /* - * If we haven't seen this record yet, try to find it in the - * original file. - */ - if (nrec > t->bt_nrecs) { - if (ISSET(t, R_EOF | R_INMEM)) - return (RET_SPECIAL); - if ((status = t->bt_irec(t, nrec)) != RET_SUCCESS) - return (status); - } - - --nrec; - if ((e = __rec_search(t, nrec, SEARCH)) == NULL) - return (RET_ERROR); - - status = __rec_ret(t, e, 0, NULL, data); - if (ISSET(t, B_DB_LOCK)) - mpool_put(t->bt_mp, e->page, 0); - else - t->bt_pinned = e->page; - return (status); -} - -/* - * __REC_FPIPE -- Get fixed length records from a pipe. - * - * Parameters: - * t: tree - * cnt: records to read - * - * Returns: - * RET_ERROR, RET_SUCCESS - */ -int -__rec_fpipe(t, top) - BTREE *t; - recno_t top; -{ - DBT data; - recno_t nrec; - size_t len; - int ch; - char *p; - - if (t->bt_dbufsz < t->bt_reclen) { - if ((t->bt_dbuf = - (char *)realloc(t->bt_dbuf, t->bt_reclen)) == NULL) - return (RET_ERROR); - t->bt_dbufsz = t->bt_reclen; - } - data.data = t->bt_dbuf; - data.size = t->bt_reclen; - - for (nrec = t->bt_nrecs; nrec < top; ++nrec) { - len = t->bt_reclen; - for (p = t->bt_dbuf;; *p++ = ch) - if ((ch = getc(t->bt_rfp)) == EOF || !len--) { - if (__rec_iput(t, nrec, &data, 0) - != RET_SUCCESS) - return (RET_ERROR); - break; - } - if (ch == EOF) - break; - } - if (nrec < top) { - SET(t, R_EOF); - return (RET_SPECIAL); - } - return (RET_SUCCESS); -} - -/* - * __REC_VPIPE -- Get variable length records from a pipe. - * - * Parameters: - * t: tree - * cnt: records to read - * - * Returns: - * RET_ERROR, RET_SUCCESS - */ -int -__rec_vpipe(t, top) - BTREE *t; - recno_t top; -{ - DBT data; - recno_t nrec; - indx_t len; - size_t sz; - int bval, ch; - char *p; - - bval = t->bt_bval; - for (nrec = t->bt_nrecs; nrec < top; ++nrec) { - for (p = t->bt_dbuf, sz = t->bt_dbufsz;; *p++ = ch, --sz) { - if ((ch = getc(t->bt_rfp)) == EOF || ch == bval) { - data.data = t->bt_dbuf; - data.size = p - t->bt_dbuf; - if (ch == EOF && data.size == 0) - break; - if (__rec_iput(t, nrec, &data, 0) - != RET_SUCCESS) - return (RET_ERROR); - break; - } - if (sz == 0) { - len = p - t->bt_dbuf; - t->bt_dbufsz += (sz = 256); - if ((t->bt_dbuf = (char *)realloc(t->bt_dbuf, - t->bt_dbufsz)) == NULL) - return (RET_ERROR); - p = t->bt_dbuf + len; - } - } - if (ch == EOF) - break; - } - if (nrec < top) { - SET(t, R_EOF); - return (RET_SPECIAL); - } - return (RET_SUCCESS); -} - -/* - * __REC_FMAP -- Get fixed length records from a file. - * - * Parameters: - * t: tree - * cnt: records to read - * - * Returns: - * RET_ERROR, RET_SUCCESS - */ -int -__rec_fmap(t, top) - BTREE *t; - recno_t top; -{ - DBT data; - recno_t nrec; - caddr_t sp, ep; - size_t len; - char *p; - - if (t->bt_dbufsz < t->bt_reclen) { - if ((t->bt_dbuf = - (char *)realloc(t->bt_dbuf, t->bt_reclen)) == NULL) - return (RET_ERROR); - t->bt_dbufsz = t->bt_reclen; - } - data.data = t->bt_dbuf; - data.size = t->bt_reclen; - - sp = t->bt_cmap; - ep = t->bt_emap; - for (nrec = t->bt_nrecs; nrec < top; ++nrec) { - if (sp >= ep) { - SET(t, R_EOF); - return (RET_SPECIAL); - } - len = t->bt_reclen; - for (p = t->bt_dbuf; sp < ep && len--; *p++ = *sp++); - memset(p, t->bt_bval, len); - if (__rec_iput(t, nrec, &data, 0) != RET_SUCCESS) - return (RET_ERROR); - } - t->bt_cmap = sp; - return (RET_SUCCESS); -} - -/* - * __REC_VMAP -- Get variable length records from a file. - * - * Parameters: - * t: tree - * cnt: records to read - * - * Returns: - * RET_ERROR, RET_SUCCESS - */ -int -__rec_vmap(t, top) - BTREE *t; - recno_t top; -{ - DBT data; - caddr_t sp, ep; - recno_t nrec; - int bval; - - sp = t->bt_cmap; - ep = t->bt_emap; - bval = t->bt_bval; - - for (nrec = t->bt_nrecs; nrec < top; ++nrec) { - if (sp >= ep) { - SET(t, R_EOF); - return (RET_SPECIAL); - } - for (data.data = sp; sp < ep && *sp != bval; ++sp); - data.size = sp - (caddr_t)data.data; - if (__rec_iput(t, nrec, &data, 0) != RET_SUCCESS) - return (RET_ERROR); - ++sp; - } - t->bt_cmap = sp; - return (RET_SUCCESS); -} diff --git a/db.subproj/recno.subproj/rec_open.c b/db.subproj/recno.subproj/rec_open.c deleted file mode 100644 index 4f8743e..0000000 --- a/db.subproj/recno.subproj/rec_open.c +++ /dev/null @@ -1,253 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Mike Olson. - * - * 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 -#include - -#include -#include - -#include -#include -#include -#include -#include -#include - -#include -#include "recno.h" - -DB * -__rec_open(fname, flags, mode, openinfo, dflags) - const char *fname; - int flags, mode, dflags; - const RECNOINFO *openinfo; -{ - BTREE *t; - BTREEINFO btopeninfo; - DB *dbp; - PAGE *h; - struct stat sb; - int rfd, sverrno; - - /* Open the user's file -- if this fails, we're done. */ - if (fname != NULL && (rfd = open(fname, flags, mode)) < 0) - return (NULL); - - /* Create a btree in memory (backed by disk). */ - dbp = NULL; - if (openinfo) { - if (openinfo->flags & ~(R_FIXEDLEN | R_NOKEY | R_SNAPSHOT)) - goto einval; - btopeninfo.flags = 0; - btopeninfo.cachesize = openinfo->cachesize; - btopeninfo.maxkeypage = 0; - btopeninfo.minkeypage = 0; - btopeninfo.psize = openinfo->psize; - btopeninfo.compare = NULL; - btopeninfo.prefix = NULL; - btopeninfo.lorder = openinfo->lorder; - dbp = __bt_open(openinfo->bfname, - O_RDWR, S_IRUSR | S_IWUSR, &btopeninfo, dflags); - } else - dbp = __bt_open(NULL, O_RDWR, S_IRUSR | S_IWUSR, NULL, dflags); - if (dbp == NULL) - goto err; - - /* - * Some fields in the tree structure are recno specific. Fill them - * in and make the btree structure look like a recno structure. We - * don't change the bt_ovflsize value, it's close enough and slightly - * bigger. - */ - t = dbp->internal; - if (openinfo) { - if (openinfo->flags & R_FIXEDLEN) { - SET(t, R_FIXLEN); - t->bt_reclen = openinfo->reclen; - if (t->bt_reclen == 0) - goto einval; - } - t->bt_bval = openinfo->bval; - } else - t->bt_bval = '\n'; - - SET(t, R_RECNO); - if (fname == NULL) - SET(t, R_EOF | R_INMEM); - else - t->bt_rfd = rfd; - t->bt_rcursor = 0; - - if (fname != NULL) { - /* - * In 4.4BSD, stat(2) returns true for ISSOCK on pipes. - * Unfortunately, that's not portable, so we use lseek - * and check the errno values. - */ - errno = 0; - if (lseek(rfd, (off_t)0, SEEK_CUR) == -1 && errno == ESPIPE) { - switch (flags & O_ACCMODE) { - case O_RDONLY: - SET(t, R_RDONLY); - break; - default: - goto einval; - } -slow: if ((t->bt_rfp = fdopen(rfd, "r")) == NULL) - goto err; - SET(t, R_CLOSEFP); - t->bt_irec = - ISSET(t, R_FIXLEN) ? __rec_fpipe : __rec_vpipe; - } else { - switch (flags & O_ACCMODE) { - case O_RDONLY: - SET(t, R_RDONLY); - break; - case O_RDWR: - break; - default: - goto einval; - } - - if (fstat(rfd, &sb)) - goto err; - /* - * Kluge -- we'd like to test to see if the file is too - * big to mmap. Since, we don't know what size or type - * off_t's or size_t's are, what the largest unsigned - * integral type is, or what random insanity the local - * C compiler will perpetrate, doing the comparison in - * a portable way is flatly impossible. Hope that mmap - * fails if the file is too large. - */ - if (sb.st_size == 0) - SET(t, R_EOF); - else { - t->bt_msize = sb.st_size; - if ( (map_fd(rfd, 0, (vm_offset_t *) - &t->bt_smap, TRUE, t->bt_msize) - != KERN_SUCCESS) - || (vm_protect(mach_task_self(), (vm_offset_t) - t->bt_smap, t->bt_msize, TRUE, - VM_PROT_READ) != KERN_SUCCESS) ) - goto slow; - t->bt_cmap = t->bt_smap; - t->bt_emap = t->bt_smap + sb.st_size; - t->bt_irec = ISSET(t, R_FIXLEN) ? - __rec_fmap : __rec_vmap; - SET(t, R_MEMMAPPED); - } - } - } - - /* Use the recno routines. */ - dbp->close = __rec_close; - dbp->del = __rec_delete; - dbp->fd = __rec_fd; - dbp->get = __rec_get; - dbp->put = __rec_put; - dbp->seq = __rec_seq; - dbp->sync = __rec_sync; - - /* If the root page was created, reset the flags. */ - if ((h = mpool_get(t->bt_mp, P_ROOT, 0)) == NULL) - goto err; - if ((h->flags & P_TYPE) == P_BLEAF) { - h->flags = h->flags & ~P_TYPE | P_RLEAF; - mpool_put(t->bt_mp, h, MPOOL_DIRTY); - } else - mpool_put(t->bt_mp, h, 0); - - if (openinfo && openinfo->flags & R_SNAPSHOT && - !ISSET(t, R_EOF | R_INMEM) && - t->bt_irec(t, MAX_REC_NUMBER) == RET_ERROR) - goto err; - return (dbp); - -einval: errno = EINVAL; -err: sverrno = errno; - if (dbp != NULL) - (void)__bt_close(dbp); - if (fname != NULL) - (void)close(rfd); - errno = sverrno; - return (NULL); -} - -int -__rec_fd(dbp) - const DB *dbp; -{ - BTREE *t; - - t = dbp->internal; - - /* Toss any page pinned across calls. */ - if (t->bt_pinned != NULL) { - mpool_put(t->bt_mp, t->bt_pinned, 0); - t->bt_pinned = NULL; - } - - /* In-memory database can't have a file descriptor. */ - if (ISSET(t, R_INMEM)) { - errno = ENOENT; - return (-1); - } - return (t->bt_rfd); -} diff --git a/db.subproj/recno.subproj/rec_put.c b/db.subproj/recno.subproj/rec_put.c deleted file mode 100644 index 45029a6..0000000 --- a/db.subproj/recno.subproj/rec_put.c +++ /dev/null @@ -1,271 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 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 - -#include -#include -#include -#include - -#include -#include "recno.h" - -/* - * __REC_PUT -- Add a recno item to the tree. - * - * Parameters: - * dbp: pointer to access method - * key: key - * data: data - * flag: R_CURSOR, R_IAFTER, R_IBEFORE, R_NOOVERWRITE - * - * Returns: - * RET_ERROR, RET_SUCCESS and RET_SPECIAL if the key is - * already in the tree and R_NOOVERWRITE specified. - */ -int -__rec_put(dbp, key, data, flags) - const DB *dbp; - DBT *key; - const DBT *data; - u_int flags; -{ - BTREE *t; - DBT tdata; - recno_t nrec; - int status; - - t = dbp->internal; - - /* Toss any page pinned across calls. */ - if (t->bt_pinned != NULL) { - mpool_put(t->bt_mp, t->bt_pinned, 0); - t->bt_pinned = NULL; - } - - switch (flags) { - case R_CURSOR: - if (!ISSET(t, B_SEQINIT)) - goto einval; - nrec = t->bt_rcursor; - break; - case R_SETCURSOR: - if ((nrec = *(recno_t *)key->data) == 0) - goto einval; - break; - case R_IAFTER: - if ((nrec = *(recno_t *)key->data) == 0) { - nrec = 1; - flags = R_IBEFORE; - } - break; - case 0: - case R_IBEFORE: - if ((nrec = *(recno_t *)key->data) == 0) - goto einval; - break; - case R_NOOVERWRITE: - if ((nrec = *(recno_t *)key->data) == 0) - goto einval; - if (nrec <= t->bt_nrecs) - return (RET_SPECIAL); - break; - default: -einval: errno = EINVAL; - return (RET_ERROR); - } - - /* - * Make sure that records up to and including the put record are - * already in the database. If skipping records, create empty ones. - */ - if (nrec > t->bt_nrecs) { - if (!ISSET(t, R_EOF | R_INMEM) && - t->bt_irec(t, nrec) == RET_ERROR) - return (RET_ERROR); - if (nrec > t->bt_nrecs + 1) { - if (ISSET(t, R_FIXLEN)) { - if ((tdata.data = - (void *)malloc(t->bt_reclen)) == NULL) - return (RET_ERROR); - tdata.size = t->bt_reclen; - memset(tdata.data, t->bt_bval, tdata.size); - } else { - tdata.data = NULL; - tdata.size = 0; - } - while (nrec > t->bt_nrecs + 1) - if (__rec_iput(t, - t->bt_nrecs, &tdata, 0) != RET_SUCCESS) - return (RET_ERROR); - if (ISSET(t, R_FIXLEN)) - free(tdata.data); - } - } - - if ((status = __rec_iput(t, nrec - 1, data, flags)) != RET_SUCCESS) - return (status); - - if (flags == R_SETCURSOR) - t->bt_rcursor = nrec; - - SET(t, R_MODIFIED); - return (__rec_ret(t, NULL, nrec, key, NULL)); -} - -/* - * __REC_IPUT -- Add a recno item to the tree. - * - * Parameters: - * t: tree - * nrec: record number - * data: data - * - * Returns: - * RET_ERROR, RET_SUCCESS - */ -int -__rec_iput(t, nrec, data, flags) - BTREE *t; - recno_t nrec; - const DBT *data; - u_int flags; -{ - DBT tdata; - EPG *e; - PAGE *h; - indx_t index, nxtindex; - pgno_t pg; - size_t nbytes; - int dflags, status; - char *dest, db[NOVFLSIZE]; - - /* - * If the data won't fit on a page, store it on indirect pages. - * - * XXX - * If the insert fails later on, these pages aren't recovered. - */ - if (data->size > t->bt_ovflsize) { - if (__ovfl_put(t, data, &pg) == RET_ERROR) - return (RET_ERROR); - tdata.data = db; - tdata.size = NOVFLSIZE; - *(pgno_t *)db = pg; - *(size_t *)(db + sizeof(pgno_t)) = data->size; - dflags = P_BIGDATA; - data = &tdata; - } else - dflags = 0; - - /* __rec_search pins the returned page. */ - if ((e = __rec_search(t, nrec, - nrec > t->bt_nrecs || flags == R_IAFTER || flags == R_IBEFORE ? - SINSERT : SEARCH)) == NULL) - return (RET_ERROR); - - h = e->page; - index = e->index; - - /* - * Add the specified key/data pair to the tree. The R_IAFTER and - * R_IBEFORE flags insert the key after/before the specified key. - * - * Pages are split as required. - */ - switch (flags) { - case R_IAFTER: - ++index; - break; - case R_IBEFORE: - break; - default: - if (nrec < t->bt_nrecs && - __rec_dleaf(t, h, index) == RET_ERROR) { - mpool_put(t->bt_mp, h, 0); - return (RET_ERROR); - } - break; - } - - /* - * If not enough room, split the page. The split code will insert - * the key and data and unpin the current page. If inserting into - * the offset array, shift the pointers up. - */ - nbytes = NRLEAFDBT(data->size); - if (h->upper - h->lower < nbytes + sizeof(indx_t)) { - status = __bt_split(t, h, NULL, data, dflags, nbytes, index); - if (status == RET_SUCCESS) - ++t->bt_nrecs; - return (status); - } - - if (index < (nxtindex = NEXTINDEX(h))) - memmove(h->linp + index + 1, h->linp + index, - (nxtindex - index) * sizeof(indx_t)); - h->lower += sizeof(indx_t); - - h->linp[index] = h->upper -= nbytes; - dest = (char *)h + h->upper; - WR_RLEAF(dest, data, dflags); - - ++t->bt_nrecs; - SET(t, B_MODIFIED); - mpool_put(t->bt_mp, h, MPOOL_DIRTY); - - return (RET_SUCCESS); -} diff --git a/db.subproj/recno.subproj/rec_search.c b/db.subproj/recno.subproj/rec_search.c deleted file mode 100644 index 9cf4341..0000000 --- a/db.subproj/recno.subproj/rec_search.c +++ /dev/null @@ -1,145 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 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 - -#include -#include - -#include -#include "recno.h" - -/* - * __REC_SEARCH -- Search a btree for a key. - * - * Parameters: - * t: tree to search - * recno: key to find - * op: search operation - * - * Returns: - * EPG for matching record, if any, or the EPG for the location of the - * key, if it were inserted into the tree. - * - * Returns: - * The EPG for matching record, if any, or the EPG for the location - * of the key, if it were inserted into the tree, is entered into - * the bt_cur field of the tree. A pointer to the field is returned. - */ -EPG * -__rec_search(t, recno, op) - BTREE *t; - recno_t recno; - enum SRCHOP op; -{ - register indx_t index; - register PAGE *h; - EPGNO *parent; - RINTERNAL *r; - pgno_t pg; - indx_t top; - recno_t total; - int sverrno; - - BT_CLR(t); - for (pg = P_ROOT, total = 0;;) { - if ((h = mpool_get(t->bt_mp, pg, 0)) == NULL) - goto err; - if (h->flags & P_RLEAF) { - t->bt_cur.page = h; - t->bt_cur.index = recno - total; - return (&t->bt_cur); - } - for (index = 0, top = NEXTINDEX(h);;) { - r = GETRINTERNAL(h, index); - if (++index == top || total + r->nrecs > recno) - break; - total += r->nrecs; - } - - if (__bt_push(t, pg, index - 1) == RET_ERROR) - return (NULL); - - pg = r->pgno; - switch (op) { - case SDELETE: - --GETRINTERNAL(h, (index - 1))->nrecs; - mpool_put(t->bt_mp, h, MPOOL_DIRTY); - break; - case SINSERT: - ++GETRINTERNAL(h, (index - 1))->nrecs; - mpool_put(t->bt_mp, h, MPOOL_DIRTY); - break; - case SEARCH: - mpool_put(t->bt_mp, h, 0); - break; - } - - } - /* Try and recover the tree. */ -err: sverrno = errno; - if (op != SEARCH) - while ((parent = BT_POP(t)) != NULL) { - if ((h = mpool_get(t->bt_mp, parent->pgno, 0)) == NULL) - break; - if (op == SINSERT) - --GETRINTERNAL(h, parent->index)->nrecs; - else - ++GETRINTERNAL(h, parent->index)->nrecs; - mpool_put(t->bt_mp, h, MPOOL_DIRTY); - } - errno = sverrno; - return (NULL); -} diff --git a/db.subproj/recno.subproj/rec_seq.c b/db.subproj/recno.subproj/rec_seq.c deleted file mode 100644 index 693d447..0000000 --- a/db.subproj/recno.subproj/rec_seq.c +++ /dev/null @@ -1,149 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * 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. - */ - - -#include - -#include -#include -#include -#include - -#include -#include "recno.h" - -/* - * __REC_SEQ -- Recno sequential scan interface. - * - * Parameters: - * dbp: pointer to access method - * key: key for positioning and return value - * data: data return value - * flags: R_CURSOR, R_FIRST, R_LAST, R_NEXT, R_PREV. - * - * Returns: - * RET_ERROR, RET_SUCCESS or RET_SPECIAL if there's no next key. - */ -int -__rec_seq(dbp, key, data, flags) - const DB *dbp; - DBT *key, *data; - u_int flags; -{ - BTREE *t; - EPG *e; - recno_t nrec; - int status; - - t = dbp->internal; - - /* Toss any page pinned across calls. */ - if (t->bt_pinned != NULL) { - mpool_put(t->bt_mp, t->bt_pinned, 0); - t->bt_pinned = NULL; - } - - switch(flags) { - case R_CURSOR: - if ((nrec = *(recno_t *)key->data) == 0) - goto einval; - break; - case R_NEXT: - if (ISSET(t, B_SEQINIT)) { - nrec = t->bt_rcursor + 1; - break; - } - /* FALLTHROUGH */ - case R_FIRST: - nrec = 1; - break; - case R_PREV: - if (ISSET(t, B_SEQINIT)) { - if ((nrec = t->bt_rcursor - 1) == 0) - return (RET_SPECIAL); - break; - } - /* FALLTHROUGH */ - case R_LAST: - if (!ISSET(t, R_EOF | R_INMEM) && - t->bt_irec(t, MAX_REC_NUMBER) == RET_ERROR) - return (RET_ERROR); - nrec = t->bt_nrecs; - break; - default: -einval: errno = EINVAL; - return (RET_ERROR); - } - - if (t->bt_nrecs == 0 || nrec > t->bt_nrecs) { - if (!ISSET(t, R_EOF | R_INMEM) && - (status = t->bt_irec(t, nrec)) != RET_SUCCESS) - return (status); - if (t->bt_nrecs == 0 || nrec > t->bt_nrecs) - return (RET_SPECIAL); - } - - if ((e = __rec_search(t, nrec - 1, SEARCH)) == NULL) - return (RET_ERROR); - - SET(t, B_SEQINIT); - t->bt_rcursor = nrec; - - status = __rec_ret(t, e, nrec, key, data); - if (ISSET(t, B_DB_LOCK)) - mpool_put(t->bt_mp, e->page, 0); - else - t->bt_pinned = e->page; - return (status); -} diff --git a/db.subproj/recno.subproj/rec_utils.c b/db.subproj/recno.subproj/rec_utils.c deleted file mode 100644 index 8f7c475..0000000 --- a/db.subproj/recno.subproj/rec_utils.c +++ /dev/null @@ -1,132 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 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 - -#include -#include -#include - -#include -#include "recno.h" - -/* - * __REC_RET -- Build return data as a result of search or scan. - * - * Parameters: - * t: tree - * d: LEAF to be returned to the user. - * data: user's data structure - * - * Returns: - * RET_SUCCESS, RET_ERROR. - */ -int -__rec_ret(t, e, nrec, key, data) - BTREE *t; - EPG *e; - recno_t nrec; - DBT *key, *data; -{ - register RLEAF *rl; - register void *p; - - if (data == NULL) - goto retkey; - - rl = GETRLEAF(e->page, e->index); - - /* - * We always copy big data to make it contigous. Otherwise, we - * leave the page pinned and don't copy unless the user specified - * concurrent access. - */ - if (rl->flags & P_BIGDATA) { - if (__ovfl_get(t, rl->bytes, - &data->size, &t->bt_dbuf, &t->bt_dbufsz)) - return (RET_ERROR); - data->data = t->bt_dbuf; - } else if (ISSET(t, B_DB_LOCK)) { - /* Use +1 in case the first record retrieved is 0 length. */ - if (rl->dsize + 1 > t->bt_dbufsz) { - if ((p = - (void *)realloc(t->bt_dbuf, rl->dsize + 1)) == NULL) - return (RET_ERROR); - t->bt_dbuf = p; - t->bt_dbufsz = rl->dsize + 1; - } - memmove(t->bt_dbuf, rl->bytes, rl->dsize); - data->size = rl->dsize; - data->data = t->bt_dbuf; - } else { - data->size = rl->dsize; - data->data = rl->bytes; - } - -retkey: if (key == NULL) - return (RET_SUCCESS); - - /* We have to copy the key, it's not on the page. */ - if (sizeof(recno_t) > t->bt_kbufsz) { - if ((p = (void *)realloc(t->bt_kbuf, sizeof(recno_t))) == NULL) - return (RET_ERROR); - t->bt_kbuf = p; - t->bt_kbufsz = sizeof(recno_t); - } - memmove(t->bt_kbuf, &nrec, sizeof(recno_t)); - key->size = sizeof(recno_t); - key->data = t->bt_kbuf; - return (RET_SUCCESS); -} diff --git a/db.subproj/recno.subproj/recno.h b/db.subproj/recno.subproj/recno.h deleted file mode 100644 index 39b076d..0000000 --- a/db.subproj/recno.subproj/recno.h +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * 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. - */ - -enum SRCHOP { SDELETE, SINSERT, SEARCH}; /* Rec_search operation. */ - -#include -#include "extern.h" diff --git a/db/Makefile.inc b/db/Makefile.inc new file mode 100644 index 0000000..5806603 --- /dev/null +++ b/db/Makefile.inc @@ -0,0 +1,11 @@ +# from @(#)Makefile.inc 8.2 (Berkeley) 2/21/94 +# $FreeBSD: src/ldb/Makefile.inc,v 1.3 1999/08/27 23:58:15 peter Exp $ +# +CFLAGS+=-D__DBINTERFACE_PRIVATE + +.include "${.CURDIR}/db/btree/Makefile.inc" +.include "${.CURDIR}/db/db/Makefile.inc" +.include "${.CURDIR}/db/hash/Makefile.inc" +.include "${.CURDIR}/db/man/Makefile.inc" +.include "${.CURDIR}/db/mpool/Makefile.inc" +.include "${.CURDIR}/db/recno/Makefile.inc" diff --git a/db/btree/Makefile.inc b/db/btree/Makefile.inc new file mode 100644 index 0000000..9b80605 --- /dev/null +++ b/db/btree/Makefile.inc @@ -0,0 +1,8 @@ +# from @(#)Makefile.inc 8.2 (Berkeley) 7/14/94 +# $FreeBSD: src/lib/libc/db/btree/Makefile.inc,v 1.3 1999/08/27 23:58:16 peter Exp $ + +.PATH: ${.CURDIR}/db/btree + +SRCS+= bt_close.c bt_conv.c bt_debug.c bt_delete.c bt_get.c bt_open.c \ + bt_overflow.c bt_page.c bt_put.c bt_search.c bt_seq.c bt_split.c \ + bt_utils.c bt_stack.c diff --git a/db/btree/PB.project b/db/btree/PB.project new file mode 100644 index 0000000..8de9a71 --- /dev/null +++ b/db/btree/PB.project @@ -0,0 +1,42 @@ +{ + DYNAMIC_CODE_GEN = YES; + FILESTABLE = { + H_FILES = (bt_extern.h, btree.h); + OTHER_LINKED = ( + bt_close.c, + bt_conv.c, + bt_debug.c, + bt_delete.c, + bt_get.c, + bt_open.c, + bt_overflow.c, + bt_page.c, + bt_put.c, + bt_search.c, + bt_seq.c, + bt_split.c, + bt_stack.c, + bt_utils.c + ); + OTHER_SOURCES = (Makefile.preamble, Makefile, Makefile.postamble); + PROJECT_HEADERS = (btree.h, bt_extern.h); + SUBPROJECTS = (); + }; + LANGUAGE = English; + MAKEFILEDIR = "$(MAKEFILEPATH)/pb_makefiles"; + NEXTSTEP_BUILDDIR = "/Local/Public/Sandbox/$(USER)/BUILD/$(NAME)"; + NEXTSTEP_BUILDTOOL = /bin/gnumake; + NEXTSTEP_INSTALLDIR = /Local/Developer/System; + NEXTSTEP_JAVA_COMPILER = /usr/bin/javac; + NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc; + NEXTSTEP_PUBLICHEADERSDIR = /usr/include; + PDO_UNIX_BUILDTOOL = $NEXT_ROOT/Developer/bin/make; + PDO_UNIX_JAVA_COMPILER = "$(JDKBINDIR)/javac"; + PDO_UNIX_OBJCPLUS_COMPILER = "$(NEXTDEV_BIN)/gcc"; + PROJECTNAME = btree; + PROJECTTYPE = Component; + PROJECTVERSION = 2.8; + WINDOWS_BUILDTOOL = $NEXT_ROOT/Developer/Executables/make; + WINDOWS_JAVA_COMPILER = "$(JDKBINDIR)/javac.exe"; + WINDOWS_OBJCPLUS_COMPILER = "$(DEVDIR)/gcc"; +} diff --git a/db/btree/bt_close.c b/db/btree/bt_close.c new file mode 100644 index 0000000..9cbbf8a --- /dev/null +++ b/db/btree/bt_close.c @@ -0,0 +1,222 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Mike Olson. + * + * 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 + +#include +#include +#include +#include +#include + +#include +#include "btree.h" + +static int bt_meta __P((BTREE *)); + +/* + * BT_CLOSE -- Close a btree. + * + * Parameters: + * dbp: pointer to access method + * + * Returns: + * RET_ERROR, RET_SUCCESS + */ +int +__bt_close(dbp) + DB *dbp; +{ + BTREE *t; + int fd; + + t = dbp->internal; + + /* Toss any page pinned across calls. */ + if (t->bt_pinned != NULL) { + mpool_put(t->bt_mp, t->bt_pinned, 0); + t->bt_pinned = NULL; + } + + /* + * Delete any already deleted record that we've been saving + * because the cursor pointed to it. + */ + if (ISSET(t, B_DELCRSR) && __bt_crsrdel(t, &t->bt_bcursor)) + return (RET_ERROR); + + if (__bt_sync(dbp, 0) == RET_ERROR) + return (RET_ERROR); + + if (mpool_close(t->bt_mp) == RET_ERROR) + return (RET_ERROR); + + if (t->bt_stack) + free(t->bt_stack); + if (t->bt_kbuf) + free(t->bt_kbuf); + if (t->bt_dbuf) + free(t->bt_dbuf); + + fd = t->bt_fd; + free(t); + free(dbp); + return (close(fd) ? RET_ERROR : RET_SUCCESS); +} + +/* + * BT_SYNC -- sync the btree to disk. + * + * Parameters: + * dbp: pointer to access method + * + * Returns: + * RET_SUCCESS, RET_ERROR. + */ +int +__bt_sync(dbp, flags) + const DB *dbp; + u_int flags; +{ + BTREE *t; + int status; + PAGE *h; + void *p; + + t = dbp->internal; + + /* Toss any page pinned across calls. */ + if (t->bt_pinned != NULL) { + mpool_put(t->bt_mp, t->bt_pinned, 0); + t->bt_pinned = NULL; + } + + /* Sync doesn't currently take any flags. */ + if (flags != 0) { + errno = EINVAL; + return (RET_ERROR); + } + + if (ISSET(t, B_INMEM | B_RDONLY) || !ISSET(t, B_MODIFIED)) + return (RET_SUCCESS); + + if (ISSET(t, B_METADIRTY) && bt_meta(t) == RET_ERROR) + return (RET_ERROR); + + /* + * Nastiness. If the cursor has been marked for deletion, but not + * actually deleted, we have to make a copy of the page, delete the + * key/data item, sync the file, and then restore the original page + * contents. + */ + if (ISSET(t, B_DELCRSR)) { + if ((p = (void *)malloc(t->bt_psize)) == NULL) + return (RET_ERROR); + if ((h = mpool_get(t->bt_mp, t->bt_bcursor.pgno, 0)) == NULL) + return (RET_ERROR); + memmove(p, h, t->bt_psize); + if ((status = + __bt_dleaf(t, h, t->bt_bcursor.index)) == RET_ERROR) + goto ecrsr; + mpool_put(t->bt_mp, h, MPOOL_DIRTY); + } + + if ((status = mpool_sync(t->bt_mp)) == RET_SUCCESS) + CLR(t, B_MODIFIED); + +ecrsr: if (ISSET(t, B_DELCRSR)) { + if ((h = mpool_get(t->bt_mp, t->bt_bcursor.pgno, 0)) == NULL) + return (RET_ERROR); + memmove(h, p, t->bt_psize); + free(p); + mpool_put(t->bt_mp, h, MPOOL_DIRTY); + } + return (status); +} + +/* + * BT_META -- write the tree meta data to disk. + * + * Parameters: + * t: tree + * + * Returns: + * RET_ERROR, RET_SUCCESS + */ +static int +bt_meta(t) + BTREE *t; +{ + BTMETA m; + void *p; + + if ((p = mpool_get(t->bt_mp, P_META, 0)) == NULL) + return (RET_ERROR); + + /* Fill in metadata. */ + m.m_magic = BTREEMAGIC; + m.m_version = BTREEVERSION; + m.m_psize = t->bt_psize; + m.m_free = t->bt_free; + m.m_nrecs = t->bt_nrecs; + m.m_flags = t->bt_flags & SAVEMETA; + + memmove(p, &m, sizeof(BTMETA)); + mpool_put(t->bt_mp, p, MPOOL_DIRTY); + return (RET_SUCCESS); +} diff --git a/db/btree/bt_conv.c b/db/btree/bt_conv.c new file mode 100644 index 0000000..41d9530 --- /dev/null +++ b/db/btree/bt_conv.c @@ -0,0 +1,239 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Mike Olson. + * + * 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 + +#include + +#include +#include "btree.h" + +static void mswap __P((PAGE *)); + +/* + * __BT_BPGIN, __BT_BPGOUT -- + * Convert host-specific number layout to/from the host-independent + * format stored on disk. + * + * Parameters: + * t: tree + * pg: page number + * h: page to convert + */ +void +__bt_pgin(t, pg, pp) + void *t; + pgno_t pg; + void *pp; +{ + PAGE *h; + indx_t i, top; + u_char flags; + char *p; + + if (!ISSET(((BTREE *)t), B_NEEDSWAP)) + return; + if (pg == P_META) { + mswap(pp); + return; + } + + h = pp; + M_32_SWAP(h->pgno); + M_32_SWAP(h->prevpg); + M_32_SWAP(h->nextpg); + M_32_SWAP(h->flags); + M_16_SWAP(h->lower); + M_16_SWAP(h->upper); + + top = NEXTINDEX(h); + if ((h->flags & P_TYPE) == P_BINTERNAL) + for (i = 0; i < top; i++) { + M_16_SWAP(h->linp[i]); + p = (char *)GETBINTERNAL(h, i); + P_32_SWAP(p); + p += sizeof(size_t); + P_32_SWAP(p); + p += sizeof(pgno_t); + if (*(u_char *)p & P_BIGKEY) { + p += sizeof(u_char); + P_32_SWAP(p); + p += sizeof(pgno_t); + P_32_SWAP(p); + } + } + else if ((h->flags & P_TYPE) == P_BLEAF) + for (i = 0; i < top; i++) { + M_16_SWAP(h->linp[i]); + p = (char *)GETBLEAF(h, i); + P_32_SWAP(p); + p += sizeof(size_t); + P_32_SWAP(p); + p += sizeof(size_t); + flags = *(u_char *)p; + if (flags & (P_BIGKEY | P_BIGDATA)) { + p += sizeof(u_char); + if (flags & P_BIGKEY) { + P_32_SWAP(p); + p += sizeof(pgno_t); + P_32_SWAP(p); + } + if (flags & P_BIGDATA) { + p += sizeof(size_t); + P_32_SWAP(p); + p += sizeof(pgno_t); + P_32_SWAP(p); + } + } + } +} + +void +__bt_pgout(t, pg, pp) + void *t; + pgno_t pg; + void *pp; +{ + PAGE *h; + indx_t i, top; + u_char flags; + char *p; + + if (!ISSET(((BTREE *)t), B_NEEDSWAP)) + return; + if (pg == P_META) { + mswap(pp); + return; + } + + h = pp; + top = NEXTINDEX(h); + if ((h->flags & P_TYPE) == P_BINTERNAL) + for (i = 0; i < top; i++) { + p = (char *)GETBINTERNAL(h, i); + P_32_SWAP(p); + p += sizeof(size_t); + P_32_SWAP(p); + p += sizeof(pgno_t); + if (*(u_char *)p & P_BIGKEY) { + p += sizeof(u_char); + P_32_SWAP(p); + p += sizeof(pgno_t); + P_32_SWAP(p); + } + M_16_SWAP(h->linp[i]); + } + else if ((h->flags & P_TYPE) == P_BLEAF) + for (i = 0; i < top; i++) { + p = (char *)GETBLEAF(h, i); + P_32_SWAP(p); + p += sizeof(size_t); + P_32_SWAP(p); + p += sizeof(size_t); + flags = *(u_char *)p; + if (flags & (P_BIGKEY | P_BIGDATA)) { + p += sizeof(u_char); + if (flags & P_BIGKEY) { + P_32_SWAP(p); + p += sizeof(pgno_t); + P_32_SWAP(p); + } + if (flags & P_BIGDATA) { + p += sizeof(size_t); + P_32_SWAP(p); + p += sizeof(pgno_t); + P_32_SWAP(p); + } + } + M_16_SWAP(h->linp[i]); + } + + M_32_SWAP(h->pgno); + M_32_SWAP(h->prevpg); + M_32_SWAP(h->nextpg); + M_32_SWAP(h->flags); + M_16_SWAP(h->lower); + M_16_SWAP(h->upper); +} + +/* + * MSWAP -- Actually swap the bytes on the meta page. + * + * Parameters: + * p: page to convert + */ +static void +mswap(pg) + PAGE *pg; +{ + char *p; + + p = (char *)pg; + P_32_SWAP(p); /* m_magic */ + p += sizeof(u_int32_t); + P_32_SWAP(p); /* m_version */ + p += sizeof(u_int32_t); + P_32_SWAP(p); /* m_psize */ + p += sizeof(u_int32_t); + P_32_SWAP(p); /* m_free */ + p += sizeof(u_int32_t); + P_32_SWAP(p); /* m_nrecs */ + p += sizeof(u_int32_t); + P_32_SWAP(p); /* m_flags */ + p += sizeof(u_int32_t); +} diff --git a/db/btree/bt_debug.c b/db/btree/bt_debug.c new file mode 100644 index 0000000..e64187c --- /dev/null +++ b/db/btree/bt_debug.c @@ -0,0 +1,349 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Mike Olson. + * + * 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 + +#include +#include +#include + +#include +#include "btree.h" + +#ifdef DEBUG +/* + * BT_DUMP -- Dump the tree + * + * Parameters: + * dbp: pointer to the DB + */ +void +__bt_dump(dbp) + DB *dbp; +{ + BTREE *t; + PAGE *h; + pgno_t i; + char *sep; + + t = dbp->internal; + (void)fprintf(stderr, "%s: pgsz %d", + ISSET(t, B_INMEM) ? "memory" : "disk", t->bt_psize); + if (ISSET(t, R_RECNO)) + (void)fprintf(stderr, " keys %lu", t->bt_nrecs); +#undef X +#define X(flag, name) \ + if (ISSET(t, flag)) { \ + (void)fprintf(stderr, "%s%s", sep, name); \ + sep = ", "; \ + } + if (t->bt_flags) { + sep = " flags ("; + X(B_DELCRSR, "DELCRSR"); + X(R_FIXLEN, "FIXLEN"); + X(B_INMEM, "INMEM"); + X(B_NODUPS, "NODUPS"); + X(B_RDONLY, "RDONLY"); + X(R_RECNO, "RECNO"); + X(B_SEQINIT, "SEQINIT"); + X(B_METADIRTY,"METADIRTY"); + (void)fprintf(stderr, ")\n"); + } +#undef X + + for (i = P_ROOT; (h = mpool_get(t->bt_mp, i, 0)) != NULL; ++i) { + __bt_dpage(h); + (void)mpool_put(t->bt_mp, h, 0); + } +} + +/* + * BT_DMPAGE -- Dump the meta page + * + * Parameters: + * h: pointer to the PAGE + */ +void +__bt_dmpage(h) + PAGE *h; +{ + BTMETA *m; + char *sep; + + m = (BTMETA *)h; + (void)fprintf(stderr, "magic %lx\n", m->m_magic); + (void)fprintf(stderr, "version %lu\n", m->m_version); + (void)fprintf(stderr, "psize %lu\n", m->m_psize); + (void)fprintf(stderr, "free %lu\n", m->m_free); + (void)fprintf(stderr, "nrecs %lu\n", m->m_nrecs); + (void)fprintf(stderr, "flags %lu", m->m_flags); +#undef X +#define X(flag, name) \ + if (m->m_flags & flag) { \ + (void)fprintf(stderr, "%s%s", sep, name); \ + sep = ", "; \ + } + if (m->m_flags) { + sep = " ("; + X(B_NODUPS, "NODUPS"); + X(R_RECNO, "RECNO"); + (void)fprintf(stderr, ")"); + } +} + +/* + * BT_DNPAGE -- Dump the page + * + * Parameters: + * n: page number to dump. + */ +void +__bt_dnpage(dbp, pgno) + DB *dbp; + pgno_t pgno; +{ + BTREE *t; + PAGE *h; + + t = dbp->internal; + if ((h = mpool_get(t->bt_mp, pgno, 0)) != NULL) { + __bt_dpage(h); + (void)mpool_put(t->bt_mp, h, 0); + } +} + +/* + * BT_DPAGE -- Dump the page + * + * Parameters: + * h: pointer to the PAGE + */ +void +__bt_dpage(h) + PAGE *h; +{ + BINTERNAL *bi; + BLEAF *bl; + RINTERNAL *ri; + RLEAF *rl; + indx_t cur, top; + char *sep; + + (void)fprintf(stderr, " page %d: (", h->pgno); +#undef X +#define X(flag, name) \ + if (h->flags & flag) { \ + (void)fprintf(stderr, "%s%s", sep, name); \ + sep = ", "; \ + } + sep = ""; + X(P_BINTERNAL, "BINTERNAL") /* types */ + X(P_BLEAF, "BLEAF") + X(P_RINTERNAL, "RINTERNAL") /* types */ + X(P_RLEAF, "RLEAF") + X(P_OVERFLOW, "OVERFLOW") + X(P_PRESERVE, "PRESERVE"); + (void)fprintf(stderr, ")\n"); +#undef X + + (void)fprintf(stderr, "\tprev %2d next %2d", h->prevpg, h->nextpg); + if (h->flags & P_OVERFLOW) + return; + + top = NEXTINDEX(h); + (void)fprintf(stderr, " lower %3d upper %3d nextind %d\n", + h->lower, h->upper, top); + for (cur = 0; cur < top; cur++) { + (void)fprintf(stderr, "\t[%03d] %4d ", cur, h->linp[cur]); + switch(h->flags & P_TYPE) { + case P_BINTERNAL: + bi = GETBINTERNAL(h, cur); + (void)fprintf(stderr, + "size %03d pgno %03d", bi->ksize, bi->pgno); + if (bi->flags & P_BIGKEY) + (void)fprintf(stderr, " (indirect)"); + else if (bi->ksize) + (void)fprintf(stderr, + " {%.*s}", (int)bi->ksize, bi->bytes); + break; + case P_RINTERNAL: + ri = GETRINTERNAL(h, cur); + (void)fprintf(stderr, "entries %03d pgno %03d", + ri->nrecs, ri->pgno); + break; + case P_BLEAF: + bl = GETBLEAF(h, cur); + if (bl->flags & P_BIGKEY) + (void)fprintf(stderr, + "big key page %lu size %u/", + *(pgno_t *)bl->bytes, + *(size_t *)(bl->bytes + sizeof(pgno_t))); + else if (bl->ksize) + (void)fprintf(stderr, "%s/", bl->bytes); + if (bl->flags & P_BIGDATA) + (void)fprintf(stderr, + "big data page %lu size %u", + *(pgno_t *)(bl->bytes + bl->ksize), + *(size_t *)(bl->bytes + bl->ksize + + sizeof(pgno_t))); + else if (bl->dsize) + (void)fprintf(stderr, "%.*s", + (int)bl->dsize, bl->bytes + bl->ksize); + break; + case P_RLEAF: + rl = GETRLEAF(h, cur); + if (rl->flags & P_BIGDATA) + (void)fprintf(stderr, + "big data page %lu size %u", + *(pgno_t *)rl->bytes, + *(size_t *)(rl->bytes + sizeof(pgno_t))); + else if (rl->dsize) + (void)fprintf(stderr, + "%.*s", (int)rl->dsize, rl->bytes); + break; + } + (void)fprintf(stderr, "\n"); + } +} +#endif + +#ifdef STATISTICS +/* + * BT_STAT -- Gather/print the tree statistics + * + * Parameters: + * dbp: pointer to the DB + */ +void +__bt_stat(dbp) + DB *dbp; +{ + extern u_long bt_cache_hit, bt_cache_miss, bt_pfxsaved, bt_rootsplit; + extern u_long bt_sortsplit, bt_split; + BTREE *t; + PAGE *h; + pgno_t i, pcont, pinternal, pleaf; + u_long ifree, lfree, nkeys; + int levels; + + t = dbp->internal; + pcont = pinternal = pleaf = 0; + nkeys = ifree = lfree = 0; + for (i = P_ROOT; (h = mpool_get(t->bt_mp, i, 0)) != NULL; ++i) { + switch(h->flags & P_TYPE) { + case P_BINTERNAL: + case P_RINTERNAL: + ++pinternal; + ifree += h->upper - h->lower; + break; + case P_BLEAF: + case P_RLEAF: + ++pleaf; + lfree += h->upper - h->lower; + nkeys += NEXTINDEX(h); + break; + case P_OVERFLOW: + ++pcont; + break; + } + (void)mpool_put(t->bt_mp, h, 0); + } + + /* Count the levels of the tree. */ + for (i = P_ROOT, levels = 0 ;; ++levels) { + h = mpool_get(t->bt_mp, i, 0); + if (h->flags & (P_BLEAF|P_RLEAF)) { + if (levels == 0) + levels = 1; + (void)mpool_put(t->bt_mp, h, 0); + break; + } + i = ISSET(t, R_RECNO) ? + GETRINTERNAL(h, 0)->pgno : + GETBINTERNAL(h, 0)->pgno; + (void)mpool_put(t->bt_mp, h, 0); + } + + (void)fprintf(stderr, "%d level%s with %ld keys", + levels, levels == 1 ? "" : "s", nkeys); + if (ISSET(t, R_RECNO)) + (void)fprintf(stderr, " (%ld header count)", t->bt_nrecs); + (void)fprintf(stderr, + "\n%lu pages (leaf %ld, internal %ld, overflow %ld)\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", + bt_split, bt_rootsplit, bt_sortsplit); + pleaf *= t->bt_psize - BTDATAOFF; + if (pleaf) + (void)fprintf(stderr, + "%.0f%% leaf fill (%ld bytes used, %ld bytes free)\n", + ((double)(pleaf - lfree) / pleaf) * 100, + pleaf - lfree, lfree); + pinternal *= t->bt_psize - BTDATAOFF; + if (pinternal) + (void)fprintf(stderr, + "%.0f%% internal fill (%ld bytes used, %ld bytes free\n", + ((double)(pinternal - ifree) / pinternal) * 100, + pinternal - ifree, ifree); + if (bt_pfxsaved) + (void)fprintf(stderr, "prefix checking removed %lu bytes.\n", + bt_pfxsaved); +} +#endif diff --git a/db/btree/bt_delete.c b/db/btree/bt_delete.c new file mode 100644 index 0000000..90f049d --- /dev/null +++ b/db/btree/bt_delete.c @@ -0,0 +1,342 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Mike Olson. + * + * 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 + +#include +#include +#include + +#include +#include "btree.h" + +static int bt_bdelete __P((BTREE *, const DBT *)); + +/* + * __BT_DELETE -- Delete the item(s) referenced by a key. + * + * Parameters: + * dbp: pointer to access method + * key: key to delete + * flags: R_CURSOR if deleting what the cursor references + * + * Returns: + * RET_ERROR, RET_SUCCESS and RET_SPECIAL if the key not found. + */ +int +__bt_delete(dbp, key, flags) + const DB *dbp; + const DBT *key; + u_int flags; +{ + BTREE *t; + int status; + + t = dbp->internal; + + /* Toss any page pinned across calls. */ + if (t->bt_pinned != NULL) { + mpool_put(t->bt_mp, t->bt_pinned, 0); + t->bt_pinned = NULL; + } + + if (ISSET(t, B_RDONLY)) { + errno = EPERM; + return (RET_ERROR); + } + + switch(flags) { + case 0: + status = bt_bdelete(t, key); + break; + case R_CURSOR: + /* + * If flags is R_CURSOR, delete the cursor; must already have + * started a scan and not have already deleted the record. For + * the delete cursor bit to have been set requires that the + * scan be initialized, so no reason to check. + */ + if (!ISSET(t, B_SEQINIT)) + goto einval; + status = ISSET(t, B_DELCRSR) ? + RET_SPECIAL : __bt_crsrdel(t, &t->bt_bcursor); + break; + default: +einval: errno = EINVAL; + return (RET_ERROR); + } + if (status == RET_SUCCESS) + SET(t, B_MODIFIED); + return (status); +} + +/* + * BT_BDELETE -- Delete all key/data pairs matching the specified key. + * + * Parameters: + * tree: tree + * key: key to delete + * + * Returns: + * RET_ERROR, RET_SUCCESS and RET_SPECIAL if the key not found. + */ +static int +bt_bdelete(t, key) + BTREE *t; + const DBT *key; +{ + EPG *e, save; + PAGE *h; + pgno_t cpgno, pg; + indx_t cindex; + int deleted, dirty1, dirty2, exact; + + /* Find any matching record; __bt_search pins the page. */ + if ((e = __bt_search(t, key, &exact)) == NULL) + return (RET_ERROR); + if (!exact) { + mpool_put(t->bt_mp, e->page, 0); + return (RET_SPECIAL); + } + + /* + * Delete forward, then delete backward, from the found key. The + * ordering is so that the deletions don't mess up the page refs. + * The first loop deletes the key from the original page, the second + * unpins the original page. In the first loop, dirty1 is set if + * the original page is modified, and dirty2 is set if any subsequent + * pages are modified. In the second loop, dirty1 starts off set if + * the original page has been modified, and is set if any subsequent + * pages are modified. + * + * If find the key referenced by the cursor, don't delete it, just + * flag it for future deletion. The cursor page number is P_INVALID + * unless the sequential scan is initialized, so no reason to check. + * A special case is when the already deleted cursor record was the + * only record found. If so, then the delete opertion fails as no + * records were deleted. + * + * Cycle in place in the current page until the current record doesn't + * match the key or the page is empty. If the latter, walk forward, + * skipping empty pages and repeating until a record doesn't match + * the key or the end of the tree is reached. + */ + cpgno = t->bt_bcursor.pgno; + cindex = t->bt_bcursor.index; + save = *e; + dirty1 = 0; + for (h = e->page, deleted = 0;;) { + dirty2 = 0; + do { + if (h->pgno == cpgno && e->index == cindex) { + if (!ISSET(t, B_DELCRSR)) { + SET(t, B_DELCRSR); + deleted = 1; + } + ++e->index; + } else { + if (__bt_dleaf(t, h, e->index)) { + if (h->pgno != save.page->pgno) + mpool_put(t->bt_mp, h, dirty2); + mpool_put(t->bt_mp, save.page, dirty1); + return (RET_ERROR); + } + if (h->pgno == save.page->pgno) + dirty1 = MPOOL_DIRTY; + else + dirty2 = MPOOL_DIRTY; + deleted = 1; + } + } while (e->index < NEXTINDEX(h) && __bt_cmp(t, key, e) == 0); + + /* + * Quit if didn't find a match, no next page, or first key on + * the next page doesn't match. Don't unpin the original page + * unless an error occurs. + */ + if (e->index < NEXTINDEX(h)) + break; + for (;;) { + if ((pg = h->nextpg) == P_INVALID) + goto done1; + if (h->pgno != save.page->pgno) + mpool_put(t->bt_mp, h, dirty2); + if ((h = mpool_get(t->bt_mp, pg, 0)) == NULL) { + mpool_put(t->bt_mp, save.page, dirty1); + return (RET_ERROR); + } + if (NEXTINDEX(h) != 0) { + e->page = h; + e->index = 0; + break; + } + } + + if (__bt_cmp(t, key, e) != 0) + break; + } + + /* + * Reach here with the original page and the last page referenced + * pinned (they may be the same). Release it if not the original. + */ +done1: if (h->pgno != save.page->pgno) + mpool_put(t->bt_mp, h, dirty2); + + /* + * Walk backwards from the record previous to the record returned by + * __bt_search, skipping empty pages, until a record doesn't match + * the key or reach the beginning of the tree. + */ + *e = save; + for (;;) { + if (e->index) + --e->index; + for (h = e->page; e->index; --e->index) { + if (__bt_cmp(t, key, e) != 0) + goto done2; + if (h->pgno == cpgno && e->index == cindex) { + if (!ISSET(t, B_DELCRSR)) { + SET(t, B_DELCRSR); + deleted = 1; + } + } else { + if (__bt_dleaf(t, h, e->index) == RET_ERROR) { + mpool_put(t->bt_mp, h, dirty1); + return (RET_ERROR); + } + if (h->pgno == save.page->pgno) + dirty1 = MPOOL_DIRTY; + deleted = 1; + } + } + + if ((pg = h->prevpg) == P_INVALID) + goto done2; + mpool_put(t->bt_mp, h, dirty1); + dirty1 = 0; + if ((e->page = mpool_get(t->bt_mp, pg, 0)) == NULL) + return (RET_ERROR); + e->index = NEXTINDEX(e->page); + } + + /* + * Reach here with the last page that was looked at pinned. Release + * it. + */ +done2: mpool_put(t->bt_mp, h, dirty1); + return (deleted ? RET_SUCCESS : RET_SPECIAL); +} + +/* + * __BT_DLEAF -- Delete a single record from a leaf page. + * + * Parameters: + * t: tree + * index: index on current page to delete + * + * Returns: + * RET_SUCCESS, RET_ERROR. + */ +int +__bt_dleaf(t, h, index) + BTREE *t; + PAGE *h; + indx_t index; +{ + register BLEAF *bl; + register indx_t cnt, *ip, offset; + register size_t nbytes; + char *from; + void *to; + + /* + * Delete a record from a btree leaf page. Internal records are never + * deleted from internal pages, regardless of the records that caused + * them to be added being deleted. Pages made empty by deletion are + * not reclaimed. They are, however, made available for reuse. + * + * Pack the remaining entries at the end of the page, shift the indices + * down, overwriting the deleted record and its index. If the record + * uses overflow pages, make them available for reuse. + */ + to = bl = GETBLEAF(h, index); + if (bl->flags & P_BIGKEY && __ovfl_delete(t, bl->bytes) == RET_ERROR) + return (RET_ERROR); + if (bl->flags & P_BIGDATA && + __ovfl_delete(t, bl->bytes + bl->ksize) == RET_ERROR) + return (RET_ERROR); + nbytes = NBLEAF(bl); + + /* + * Compress the key/data pairs. Compress and adjust the [BR]LEAF + * offsets. Reset the headers. + */ + from = (char *)h + h->upper; + memmove(from + nbytes, from, (char *)to - from); + h->upper += nbytes; + + offset = h->linp[index]; + for (cnt = index, ip = &h->linp[0]; cnt--; ++ip) + if (ip[0] < offset) + ip[0] += nbytes; + for (cnt = NEXTINDEX(h) - index; --cnt; ++ip) + ip[0] = ip[1] < offset ? ip[1] + nbytes : ip[1]; + h->lower -= sizeof(indx_t); + return (RET_SUCCESS); +} diff --git a/db/btree/bt_extern.h b/db/btree/bt_extern.h new file mode 100644 index 0000000..9a3839b --- /dev/null +++ b/db/btree/bt_extern.h @@ -0,0 +1,89 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * 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. + */ + +int __bt_close __P((DB *)); +int __bt_cmp __P((BTREE *, const DBT *, EPG *)); +int __bt_crsrdel __P((BTREE *, EPGNO *)); +int __bt_defcmp __P((const DBT *, const DBT *)); +size_t __bt_defpfx __P((const DBT *, const DBT *)); +int __bt_delete __P((const DB *, const DBT *, u_int)); +int __bt_dleaf __P((BTREE *, PAGE *, int)); +int __bt_fd __P((const DB *)); +EPG *__bt_first __P((BTREE *, const DBT *, int *)); +int __bt_free __P((BTREE *, PAGE *)); +int __bt_get __P((const DB *, const DBT *, DBT *, u_int)); +PAGE *__bt_new __P((BTREE *, pgno_t *)); +void __bt_pgin __P((void *, pgno_t, void *)); +void __bt_pgout __P((void *, pgno_t, void *)); +int __bt_push __P((BTREE *, pgno_t, int)); +int __bt_put __P((const DB *dbp, DBT *, const DBT *, u_int)); +int __bt_ret __P((BTREE *, EPG *, DBT *, DBT *)); +EPG *__bt_search __P((BTREE *, const DBT *, int *)); +int __bt_seq __P((const DB *, DBT *, DBT *, u_int)); +int __bt_split __P((BTREE *, PAGE *, + const DBT *, const DBT *, int, size_t, indx_t)); +int __bt_sync __P((const DB *, u_int)); + +int __ovfl_delete __P((BTREE *, void *)); +int __ovfl_get __P((BTREE *, void *, size_t *, char **, size_t *)); +int __ovfl_put __P((BTREE *, const DBT *, pgno_t *)); + +#ifdef DEBUG +void __bt_dnpage __P((DB *, pgno_t)); +void __bt_dpage __P((PAGE *)); +void __bt_dump __P((DB *)); +#endif +#ifdef STATISTICS +void __bt_stat __P((DB *)); +#endif diff --git a/db/btree/bt_get.c b/db/btree/bt_get.c new file mode 100644 index 0000000..e62c7ac --- /dev/null +++ b/db/btree/bt_get.c @@ -0,0 +1,256 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Mike Olson. + * + * 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 + +#include +#include +#include + +#include +#include "btree.h" + +/* + * __BT_GET -- Get a record from the btree. + * + * Parameters: + * dbp: pointer to access method + * key: key to find + * data: data to return + * flag: currently unused + * + * Returns: + * RET_ERROR, RET_SUCCESS and RET_SPECIAL if the key not found. + */ +int +__bt_get(dbp, key, data, flags) + const DB *dbp; + const DBT *key; + DBT *data; + u_int flags; +{ + BTREE *t; + EPG *e; + int exact, status; + + t = dbp->internal; + + /* Toss any page pinned across calls. */ + if (t->bt_pinned != NULL) { + mpool_put(t->bt_mp, t->bt_pinned, 0); + t->bt_pinned = NULL; + } + + /* Get currently doesn't take any flags. */ + if (flags) { + errno = EINVAL; + return (RET_ERROR); + } + + if ((e = __bt_search(t, key, &exact)) == NULL) + return (RET_ERROR); + if (!exact) { + mpool_put(t->bt_mp, e->page, 0); + return (RET_SPECIAL); + } + + /* + * A special case is if we found the record but it's flagged for + * deletion. In this case, we want to find another record with the + * same key, if it exists. Rather than look around the tree we call + * __bt_first and have it redo the search, as __bt_first will not + * return keys marked for deletion. Slow, but should never happen. + */ + if (ISSET(t, B_DELCRSR) && e->page->pgno == t->bt_bcursor.pgno && + e->index == t->bt_bcursor.index) { + mpool_put(t->bt_mp, e->page, 0); + if ((e = __bt_first(t, key, &exact)) == NULL) + return (RET_ERROR); + if (!exact) + return (RET_SPECIAL); + } + + status = __bt_ret(t, e, NULL, data); + /* + * If the user is doing concurrent access, we copied the + * key/data, toss the page. + */ + if (ISSET(t, B_DB_LOCK)) + mpool_put(t->bt_mp, e->page, 0); + else + t->bt_pinned = e->page; + return (status); +} + +/* + * __BT_FIRST -- Find the first entry. + * + * Parameters: + * t: the tree + * key: the key + * + * Returns: + * The first entry in the tree greater than or equal to key. + */ +EPG * +__bt_first(t, key, exactp) + BTREE *t; + const DBT *key; + int *exactp; +{ + register PAGE *h; + register EPG *e; + EPG save; + pgno_t cpgno, pg; + indx_t cindex; + int found; + + /* + * Find any matching record; __bt_search pins the page. Only exact + * matches are tricky, otherwise just return the location of the key + * if it were to be inserted into the tree. + */ + if ((e = __bt_search(t, key, exactp)) == NULL) + return (NULL); + if (!*exactp) + return (e); + + if (ISSET(t, B_DELCRSR)) { + cpgno = t->bt_bcursor.pgno; + cindex = t->bt_bcursor.index; + } else { + cpgno = P_INVALID; + cindex = 0; /* GCC thinks it's uninitialized. */ + } + + /* + * Walk backwards, skipping empty pages, as long as the entry matches + * and there are keys left in the tree. Save a copy of each match in + * case we go too far. A special case is that we don't return a match + * on records that the cursor references that have already been flagged + * for deletion. + */ + save = *e; + h = e->page; + found = 0; + do { + if (cpgno != h->pgno || cindex != e->index) { + if (save.page->pgno != e->page->pgno) { + mpool_put(t->bt_mp, save.page, 0); + save = *e; + } else + save.index = e->index; + found = 1; + } + /* + * Make a special effort not to unpin the page the last (or + * original) match was on, but also make sure it's unpinned + * if an error occurs. + */ + while (e->index == 0) { + if (h->prevpg == P_INVALID) + goto done1; + if (h->pgno != save.page->pgno) + mpool_put(t->bt_mp, h, 0); + if ((h = mpool_get(t->bt_mp, h->prevpg, 0)) == NULL) { + if (h->pgno == save.page->pgno) + mpool_put(t->bt_mp, save.page, 0); + return (NULL); + } + e->page = h; + e->index = NEXTINDEX(h); + } + --e->index; + } while (__bt_cmp(t, key, e) == 0); + + /* + * Reach here with the last page that was looked at pinned, which may + * or may not be the same as the last (or original) match page. If + * it's not useful, release it. + */ +done1: if (h->pgno != save.page->pgno) + mpool_put(t->bt_mp, h, 0); + + /* + * If still haven't found a record, the only possibility left is the + * next one. Move forward one slot, skipping empty pages and check. + */ + if (!found) { + h = save.page; + if (++save.index == NEXTINDEX(h)) { + do { + pg = h->nextpg; + mpool_put(t->bt_mp, h, 0); + if (pg == P_INVALID) { + *exactp = 0; + return (e); + } + if ((h = mpool_get(t->bt_mp, pg, 0)) == NULL) + return (NULL); + } while ((save.index = NEXTINDEX(h)) == 0); + save.page = h; + } + if (__bt_cmp(t, key, &save) != 0) { + *exactp = 0; + return (e); + } + } + *e = save; + *exactp = 1; + return (e); +} diff --git a/db/btree/bt_open.c b/db/btree/bt_open.c new file mode 100644 index 0000000..0eb86d3 --- /dev/null +++ b/db/btree/bt_open.c @@ -0,0 +1,458 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Mike Olson. + * + * 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. + */ + + +/* + * Implementation of btree access method for 4.4BSD. + * + * The design here was originally based on that of the btree access method + * used in the Postgres database system at UC Berkeley. This implementation + * is wholly independent of the Postgres code. + */ + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include "btree.h" + +static int byteorder __P((void)); +static int nroot __P((BTREE *)); +static int tmp __P((void)); + +/* + * __BT_OPEN -- Open a btree. + * + * Creates and fills a DB struct, and calls the routine that actually + * opens the btree. + * + * Parameters: + * fname: filename (NULL for in-memory trees) + * flags: open flag bits + * mode: open permission bits + * b: BTREEINFO pointer + * + * Returns: + * NULL on failure, pointer to DB on success. + * + */ +DB * +__bt_open(fname, flags, mode, openinfo, dflags) + const char *fname; + int flags, mode, dflags; + const BTREEINFO *openinfo; +{ + struct stat sb; + BTMETA m; + BTREE *t; + BTREEINFO b; + DB *dbp; + pgno_t ncache; + ssize_t nr; + int machine_lorder; + + t = NULL; + + /* + * Intention is to make sure all of the user's selections are okay + * here and then use them without checking. Can't be complete, since + * we don't know the right page size, lorder or flags until the backing + * file is opened. Also, the file's page size can cause the cachesize + * to change. + */ + machine_lorder = byteorder(); + if (openinfo) { + b = *openinfo; + + /* Flags: R_DUP. */ + if (b.flags & ~(R_DUP)) + goto einval; + + /* + * Page size must be indx_t aligned and >= MINPSIZE. Default + * page size is set farther on, based on the underlying file + * transfer size. + */ + if (b.psize && + (b.psize < MINPSIZE || b.psize > MAX_PAGE_OFFSET + 1 || + b.psize & sizeof(indx_t) - 1)) + goto einval; + + /* Minimum number of keys per page; absolute minimum is 2. */ + if (b.minkeypage) { + if (b.minkeypage < 2) + goto einval; + } else + b.minkeypage = DEFMINKEYPAGE; + + /* If no comparison, use default comparison and prefix. */ + if (b.compare == NULL) { + b.compare = __bt_defcmp; + if (b.prefix == NULL) + b.prefix = __bt_defpfx; + } + + if (b.lorder == 0) + b.lorder = machine_lorder; + } else { + b.compare = __bt_defcmp; + b.cachesize = 0; + b.flags = 0; + b.lorder = machine_lorder; + b.minkeypage = DEFMINKEYPAGE; + b.prefix = __bt_defpfx; + b.psize = 0; + } + + /* Check for the ubiquitous PDP-11. */ + if (b.lorder != BIG_ENDIAN && b.lorder != LITTLE_ENDIAN) + goto einval; + + /* Allocate and initialize DB and BTREE structures. */ + if ((t = (BTREE *)malloc(sizeof(BTREE))) == NULL) + goto err; + memset(t, 0, sizeof(BTREE)); + t->bt_bcursor.pgno = P_INVALID; + t->bt_fd = -1; /* Don't close unopened fd on error. */ + t->bt_lorder = b.lorder; + t->bt_order = NOT; + t->bt_cmp = b.compare; + t->bt_pfx = b.prefix; + t->bt_rfd = -1; + + if ((t->bt_dbp = dbp = (DB *)malloc(sizeof(DB))) == NULL) + goto err; + t->bt_flags = 0; + if (t->bt_lorder != machine_lorder) + SET(t, B_NEEDSWAP); + + dbp->type = DB_BTREE; + dbp->internal = t; + dbp->close = __bt_close; + dbp->del = __bt_delete; + dbp->fd = __bt_fd; + dbp->get = __bt_get; + dbp->put = __bt_put; + dbp->seq = __bt_seq; + dbp->sync = __bt_sync; + + /* + * If no file name was supplied, this is an in-memory btree and we + * open a backing temporary file. Otherwise, it's a disk-based tree. + */ + if (fname) { + switch(flags & O_ACCMODE) { + case O_RDONLY: + SET(t, B_RDONLY); + break; + case O_RDWR: + break; + case O_WRONLY: + default: + goto einval; + } + + if ((t->bt_fd = open(fname, flags, mode)) < 0) + goto err; + + } else { + if ((flags & O_ACCMODE) != O_RDWR) + goto einval; + if ((t->bt_fd = tmp()) == -1) + goto err; + SET(t, B_INMEM); + } + + if (fcntl(t->bt_fd, F_SETFD, 1) == -1) + goto err; + + if (fstat(t->bt_fd, &sb)) + goto err; + if (sb.st_size) { + nr = read(t->bt_fd, &m, sizeof(BTMETA)); + if (nr < 0) + goto err; + if (nr != sizeof(BTMETA)) + goto eftype; + + /* + * Read in the meta-data. This can change the notion of what + * the lorder, page size and flags are, and, when the page size + * changes, the cachesize value can change too. If the user + * specified the wrong byte order for an existing database, we + * don't bother to return an error, we just clear the NEEDSWAP + * bit. + */ + if (m.m_magic == BTREEMAGIC) + CLR(t, B_NEEDSWAP); + else { + SET(t, B_NEEDSWAP); + M_32_SWAP(m.m_magic); + M_32_SWAP(m.m_version); + M_32_SWAP(m.m_psize); + M_32_SWAP(m.m_free); + M_32_SWAP(m.m_nrecs); + M_32_SWAP(m.m_flags); + } + if (m.m_magic != BTREEMAGIC || m.m_version != BTREEVERSION) + goto eftype; + if (m.m_psize < MINPSIZE || m.m_psize > MAX_PAGE_OFFSET + 1 || + m.m_psize & sizeof(indx_t) - 1) + goto eftype; + if (m.m_flags & ~SAVEMETA) + goto eftype; + b.psize = m.m_psize; + t->bt_flags |= m.m_flags; + t->bt_free = m.m_free; + t->bt_nrecs = m.m_nrecs; + } else { + /* + * Set the page size to the best value for I/O to this file. + * Don't overflow the page offset type. + */ + if (b.psize == 0) { + b.psize = sb.st_blksize; + if (b.psize < MINPSIZE) + b.psize = MINPSIZE; + if (b.psize > MAX_PAGE_OFFSET + 1) + b.psize = MAX_PAGE_OFFSET + 1; + } + + /* Set flag if duplicates permitted. */ + if (!(b.flags & R_DUP)) + SET(t, B_NODUPS); + + t->bt_free = P_INVALID; + t->bt_nrecs = 0; + SET(t, B_METADIRTY); + } + + t->bt_psize = b.psize; + + /* Set the cache size; must be a multiple of the page size. */ + if (b.cachesize && b.cachesize & b.psize - 1) + b.cachesize += (~b.cachesize & b.psize - 1) + 1; + if (b.cachesize < b.psize * MINCACHE) + b.cachesize = b.psize * MINCACHE; + + /* Calculate number of pages to cache. */ + ncache = (b.cachesize + t->bt_psize - 1) / t->bt_psize; + + /* + * The btree data structure requires that at least two keys can fit on + * a page, but other than that there's no fixed requirement. The user + * specified a minimum number per page, and we translated that into the + * number of bytes a key/data pair can use before being placed on an + * overflow page. This calculation includes the page header, the size + * of the index referencing the leaf item and the size of the leaf item + * structure. Also, don't let the user specify a minkeypage such that + * a key/data pair won't fit even if both key and data are on overflow + * pages. + */ + t->bt_ovflsize = (t->bt_psize - BTDATAOFF) / b.minkeypage - + (sizeof(indx_t) + NBLEAFDBT(0, 0)); + if (t->bt_ovflsize < NBLEAFDBT(NOVFLSIZE, NOVFLSIZE) + sizeof(indx_t)) + t->bt_ovflsize = + NBLEAFDBT(NOVFLSIZE, NOVFLSIZE) + sizeof(indx_t); + + /* Initialize the buffer pool. */ + if ((t->bt_mp = + mpool_open(NULL, t->bt_fd, t->bt_psize, ncache)) == NULL) + goto err; + if (!ISSET(t, B_INMEM)) + mpool_filter(t->bt_mp, __bt_pgin, __bt_pgout, t); + + /* Create a root page if new tree. */ + if (nroot(t) == RET_ERROR) + goto err; + + /* Global flags. */ + if (dflags & DB_LOCK) + SET(t, B_DB_LOCK); + if (dflags & DB_SHMEM) + SET(t, B_DB_SHMEM); + if (dflags & DB_TXN) + SET(t, B_DB_TXN); + + return (dbp); + +einval: errno = EINVAL; + goto err; + +eftype: errno = EFTYPE; + goto err; + +err: if (t) { + if (t->bt_dbp) + free(t->bt_dbp); + if (t->bt_fd != -1) + (void)close(t->bt_fd); + free(t); + } + return (NULL); +} + +/* + * NROOT -- Create the root of a new tree. + * + * Parameters: + * t: tree + * + * Returns: + * RET_ERROR, RET_SUCCESS + */ +static int +nroot(t) + BTREE *t; +{ + PAGE *meta, *root; + pgno_t npg; + + if ((meta = mpool_get(t->bt_mp, 0, 0)) != NULL) { + mpool_put(t->bt_mp, meta, 0); + return (RET_SUCCESS); + } + if (errno != EINVAL) + return (RET_ERROR); + + if ((meta = mpool_new(t->bt_mp, &npg)) == NULL) + return (RET_ERROR); + + if ((root = mpool_new(t->bt_mp, &npg)) == NULL) + return (RET_ERROR); + + if (npg != P_ROOT) + return (RET_ERROR); + root->pgno = npg; + root->prevpg = root->nextpg = P_INVALID; + root->lower = BTDATAOFF; + root->upper = t->bt_psize; + root->flags = P_BLEAF; + memset(meta, 0, t->bt_psize); + mpool_put(t->bt_mp, meta, MPOOL_DIRTY); + mpool_put(t->bt_mp, root, MPOOL_DIRTY); + return (RET_SUCCESS); +} + +static int +tmp() +{ + sigset_t set, oset; + int fd; + char *envtmp; + char path[MAXPATHLEN]; + + envtmp = getenv("TMPDIR"); + (void)snprintf(path, + sizeof(path), "%s/bt.XXXXXX", envtmp ? envtmp : "/tmp"); + + (void)sigfillset(&set); + (void)sigprocmask(SIG_BLOCK, &set, &oset); + if ((fd = mkstemp(path)) != -1) + (void)unlink(path); + (void)sigprocmask(SIG_SETMASK, &oset, NULL); + return(fd); +} + +static int +byteorder() +{ + u_int32_t x; + u_char *p; + + x = 0x01020304; + p = (u_char *)&x; + switch (*p) { + case 1: + return (BIG_ENDIAN); + case 4: + return (LITTLE_ENDIAN); + default: + return (0); + } +} + +int +__bt_fd(dbp) + const DB *dbp; +{ + BTREE *t; + + t = dbp->internal; + + /* Toss any page pinned across calls. */ + if (t->bt_pinned != NULL) { + mpool_put(t->bt_mp, t->bt_pinned, 0); + t->bt_pinned = NULL; + } + + /* In-memory database can't have a file descriptor. */ + if (ISSET(t, B_INMEM)) { + errno = ENOENT; + return (-1); + } + return (t->bt_fd); +} diff --git a/db/btree/bt_overflow.c b/db/btree/bt_overflow.c new file mode 100644 index 0000000..dc73942 --- /dev/null +++ b/db/btree/bt_overflow.c @@ -0,0 +1,242 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Mike Olson. + * + * 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 + +#include +#include +#include + +#include +#include "btree.h" + +/* + * Big key/data code. + * + * Big key and data entries are stored on linked lists of pages. The initial + * reference is byte string stored with the key or data and is the page number + * and size. The actual record is stored in a chain of pages linked by the + * nextpg field of the PAGE header. + * + * The first page of the chain has a special property. If the record is used + * by an internal page, it cannot be deleted and the P_PRESERVE bit will be set + * in the header. + * + * XXX + * A single DBT is written to each chain, so a lot of space on the last page + * is wasted. This is a fairly major bug for some data sets. + */ + +/* + * __OVFL_GET -- Get an overflow key/data item. + * + * Parameters: + * t: tree + * p: pointer to { pgno_t, size_t } + * buf: storage address + * bufsz: storage size + * + * Returns: + * RET_ERROR, RET_SUCCESS + */ +int +__ovfl_get(t, p, ssz, buf, bufsz) + BTREE *t; + void *p; + size_t *ssz; + char **buf; + size_t *bufsz; +{ + PAGE *h; + pgno_t pg; + size_t nb, plen, sz; + + memmove(&pg, p, sizeof(pgno_t)); + memmove(&sz, (char *)p + sizeof(pgno_t), sizeof(size_t)); + *ssz = sz; + +#ifdef DEBUG + if (pg == P_INVALID || sz == 0) + abort(); +#endif + /* Make the buffer bigger as necessary. */ + if (*bufsz < sz) { + if ((*buf = (char *)realloc(*buf, sz)) == NULL) + return (RET_ERROR); + *bufsz = sz; + } + + /* + * Step through the linked list of pages, copying the data on each one + * into the buffer. Never copy more than the data's length. + */ + plen = t->bt_psize - BTDATAOFF; + for (p = *buf;; p = (char *)p + nb, pg = h->nextpg) { + if ((h = mpool_get(t->bt_mp, pg, 0)) == NULL) + return (RET_ERROR); + + nb = MIN(sz, plen); + memmove(p, (char *)h + BTDATAOFF, nb); + mpool_put(t->bt_mp, h, 0); + + if ((sz -= nb) == 0) + break; + } + return (RET_SUCCESS); +} + +/* + * __OVFL_PUT -- Store an overflow key/data item. + * + * Parameters: + * t: tree + * data: DBT to store + * pgno: storage page number + * + * Returns: + * RET_ERROR, RET_SUCCESS + */ +int +__ovfl_put(t, dbt, pg) + BTREE *t; + const DBT *dbt; + pgno_t *pg; +{ + PAGE *h, *last; + void *p; + pgno_t npg; + size_t nb, plen, sz; + + /* + * Allocate pages and copy the key/data record into them. Store the + * number of the first page in the chain. + */ + plen = t->bt_psize - BTDATAOFF; + for (last = NULL, p = dbt->data, sz = dbt->size;; + p = (char *)p + plen, last = h) { + if ((h = __bt_new(t, &npg)) == NULL) + return (RET_ERROR); + + h->pgno = npg; + h->nextpg = h->prevpg = P_INVALID; + h->flags = P_OVERFLOW; + h->lower = h->upper = 0; + + nb = MIN(sz, plen); + memmove((char *)h + BTDATAOFF, p, nb); + + if (last) { + last->nextpg = h->pgno; + mpool_put(t->bt_mp, last, MPOOL_DIRTY); + } else + *pg = h->pgno; + + if ((sz -= nb) == 0) { + mpool_put(t->bt_mp, h, MPOOL_DIRTY); + break; + } + } + return (RET_SUCCESS); +} + +/* + * __OVFL_DELETE -- Delete an overflow chain. + * + * Parameters: + * t: tree + * p: pointer to { pgno_t, size_t } + * + * Returns: + * RET_ERROR, RET_SUCCESS + */ +int +__ovfl_delete(t, p) + BTREE *t; + void *p; +{ + PAGE *h; + pgno_t pg; + size_t plen, sz; + + memmove(&pg, p, sizeof(pgno_t)); + memmove(&sz, (char *)p + sizeof(pgno_t), sizeof(size_t)); + +#ifdef DEBUG + if (pg == P_INVALID || sz == 0) + abort(); +#endif + if ((h = mpool_get(t->bt_mp, pg, 0)) == NULL) + return (RET_ERROR); + + /* Don't delete chains used by internal pages. */ + if (h->flags & P_PRESERVE) { + mpool_put(t->bt_mp, h, 0); + return (RET_SUCCESS); + } + + /* Step through the chain, calling the free routine for each page. */ + for (plen = t->bt_psize - BTDATAOFF;; sz -= plen) { + pg = h->nextpg; + __bt_free(t, h); + if (sz <= plen) + break; + if ((h = mpool_get(t->bt_mp, pg, 0)) == NULL) + return (RET_ERROR); + } + return (RET_SUCCESS); +} diff --git a/db/btree/bt_page.c b/db/btree/bt_page.c new file mode 100644 index 0000000..c9c1b44 --- /dev/null +++ b/db/btree/bt_page.c @@ -0,0 +1,111 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 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 + +#include + +#include +#include "btree.h" + +/* + * __BT_FREE -- Put a page on the freelist. + * + * Parameters: + * t: tree + * h: page to free + * + * Returns: + * RET_ERROR, RET_SUCCESS + */ +int +__bt_free(t, h) + BTREE *t; + PAGE *h; +{ + /* Insert the page at the start of the free list. */ + h->prevpg = P_INVALID; + h->nextpg = t->bt_free; + t->bt_free = h->pgno; + + /* Make sure the page gets written back. */ + return (mpool_put(t->bt_mp, h, MPOOL_DIRTY)); +} + +/* + * __BT_NEW -- Get a new page, preferably from the freelist. + * + * Parameters: + * t: tree + * npg: storage for page number. + * + * Returns: + * Pointer to a page, NULL on error. + */ +PAGE * +__bt_new(t, npg) + BTREE *t; + pgno_t *npg; +{ + PAGE *h; + + if (t->bt_free != P_INVALID && + (h = mpool_get(t->bt_mp, t->bt_free, 0)) != NULL) { + *npg = t->bt_free; + t->bt_free = h->nextpg; + return (h); + } + return (mpool_new(t->bt_mp, npg)); +} diff --git a/db/btree/bt_put.c b/db/btree/bt_put.c new file mode 100644 index 0000000..403d16b --- /dev/null +++ b/db/btree/bt_put.c @@ -0,0 +1,336 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Mike Olson. + * + * 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 + +#include +#include +#include +#include + +#include +#include "btree.h" + +static EPG *bt_fast __P((BTREE *, const DBT *, const DBT *, int *)); + +/* + * __BT_PUT -- Add a btree item to the tree. + * + * Parameters: + * dbp: pointer to access method + * key: key + * data: data + * flag: R_NOOVERWRITE + * + * Returns: + * RET_ERROR, RET_SUCCESS and RET_SPECIAL if the key is already in the + * tree and R_NOOVERWRITE specified. + */ +int +__bt_put(dbp, key, data, flags) + const DB *dbp; + DBT *key; + const DBT *data; + u_int flags; +{ + BTREE *t; + DBT tkey, tdata; + EPG *e; + PAGE *h; + indx_t index, nxtindex; + pgno_t pg; + size_t nbytes; + int dflags, exact, status; + char *dest, db[NOVFLSIZE], kb[NOVFLSIZE]; + + t = dbp->internal; + + /* Toss any page pinned across calls. */ + if (t->bt_pinned != NULL) { + mpool_put(t->bt_mp, t->bt_pinned, 0); + t->bt_pinned = NULL; + } + + switch (flags) { + case R_CURSOR: + if (!ISSET(t, B_SEQINIT)) + goto einval; + if (ISSET(t, B_DELCRSR)) + goto einval; + break; + case 0: + case R_NOOVERWRITE: + break; + default: +einval: errno = EINVAL; + return (RET_ERROR); + } + + if (ISSET(t, B_RDONLY)) { + errno = EPERM; + return (RET_ERROR); + } + + /* + * If the key/data won't fit on a page, store it on indirect pages. + * Only store the key on the overflow page if it's too big after the + * data is on an overflow page. + * + * XXX + * If the insert fails later on, these pages aren't recovered. + */ + dflags = 0; + if (key->size + data->size > t->bt_ovflsize) { + if (key->size > t->bt_ovflsize) { +storekey: if (__ovfl_put(t, key, &pg) == RET_ERROR) + return (RET_ERROR); + tkey.data = kb; + tkey.size = NOVFLSIZE; + memmove(kb, &pg, sizeof(pgno_t)); + memmove(kb + sizeof(pgno_t), + &key->size, sizeof(size_t)); + dflags |= P_BIGKEY; + key = &tkey; + } + if (key->size + data->size > t->bt_ovflsize) { + if (__ovfl_put(t, data, &pg) == RET_ERROR) + return (RET_ERROR); + tdata.data = db; + tdata.size = NOVFLSIZE; + memmove(db, &pg, sizeof(pgno_t)); + memmove(db + sizeof(pgno_t), + &data->size, sizeof(size_t)); + dflags |= P_BIGDATA; + data = &tdata; + } + if (key->size + data->size > t->bt_ovflsize) + goto storekey; + } + + /* Replace the cursor. */ + if (flags == R_CURSOR) { + if ((h = mpool_get(t->bt_mp, t->bt_bcursor.pgno, 0)) == NULL) + return (RET_ERROR); + index = t->bt_bcursor.index; + goto delete; + } + + /* + * Find the key to delete, or, the location at which to insert. Bt_fast + * and __bt_search pin the returned page. + */ + if (t->bt_order == NOT || (e = bt_fast(t, key, data, &exact)) == NULL) + if ((e = __bt_search(t, key, &exact)) == NULL) + return (RET_ERROR); + h = e->page; + index = e->index; + + /* + * Add the specified key/data pair to the tree. If an identical key + * is already in the tree, and R_NOOVERWRITE is set, an error is + * returned. If R_NOOVERWRITE is not set, the key is either added (if + * duplicates are permitted) or an error is returned. + * + * Pages are split as required. + */ + switch (flags) { + case R_NOOVERWRITE: + if (!exact) + break; + /* + * One special case is if the cursor references the record and + * it's been flagged for deletion. Then, we delete the record, + * leaving the cursor there -- this means that the inserted + * record will not be seen in a cursor scan. + */ + if (ISSET(t, B_DELCRSR) && t->bt_bcursor.pgno == h->pgno && + t->bt_bcursor.index == index) { + CLR(t, B_DELCRSR); + goto delete; + } + mpool_put(t->bt_mp, h, 0); + return (RET_SPECIAL); + default: + if (!exact || !ISSET(t, B_NODUPS)) + break; +delete: if (__bt_dleaf(t, h, index) == RET_ERROR) { + mpool_put(t->bt_mp, h, 0); + return (RET_ERROR); + } + break; + } + + /* + * If not enough room, or the user has put a ceiling on the number of + * keys permitted in the page, split the page. The split code will + * insert the key and data and unpin the current page. If inserting + * into the offset array, shift the pointers up. + */ + nbytes = NBLEAFDBT(key->size, data->size); + if (h->upper - h->lower < nbytes + sizeof(indx_t)) { + if ((status = __bt_split(t, h, key, + data, dflags, nbytes, index)) != RET_SUCCESS) + return (status); + goto success; + } + + if (index < (nxtindex = NEXTINDEX(h))) + memmove(h->linp + index + 1, h->linp + index, + (nxtindex - index) * sizeof(indx_t)); + h->lower += sizeof(indx_t); + + h->linp[index] = h->upper -= nbytes; + dest = (char *)h + h->upper; + WR_BLEAF(dest, key, data, dflags); + + if (t->bt_order == NOT) + if (h->nextpg == P_INVALID) { + if (index == NEXTINDEX(h) - 1) { + t->bt_order = FORWARD; + t->bt_last.index = index; + t->bt_last.pgno = h->pgno; + } + } else if (h->prevpg == P_INVALID) { + if (index == 0) { + t->bt_order = BACK; + t->bt_last.index = 0; + t->bt_last.pgno = h->pgno; + } + } + + mpool_put(t->bt_mp, h, MPOOL_DIRTY); + +success: + if (flags == R_SETCURSOR) { + t->bt_bcursor.pgno = e->page->pgno; + t->bt_bcursor.index = e->index; + } + SET(t, B_MODIFIED); + return (RET_SUCCESS); +} + +#ifdef STATISTICS +u_long bt_cache_hit, bt_cache_miss; +#endif + +/* + * BT_FAST -- Do a quick check for sorted data. + * + * Parameters: + * t: tree + * key: key to insert + * + * Returns: + * EPG for new record or NULL if not found. + */ +static EPG * +bt_fast(t, key, data, exactp) + BTREE *t; + const DBT *key, *data; + int *exactp; +{ + PAGE *h; + size_t nbytes; + int cmp; + + if ((h = mpool_get(t->bt_mp, t->bt_last.pgno, 0)) == NULL) { + t->bt_order = NOT; + return (NULL); + } + t->bt_cur.page = h; + t->bt_cur.index = t->bt_last.index; + + /* + * If won't fit in this page or have too many keys in this page, have + * to search to get split stack. + */ + nbytes = NBLEAFDBT(key->size, data->size); + if (h->upper - h->lower < nbytes + sizeof(indx_t)) + goto miss; + + if (t->bt_order == FORWARD) { + if (t->bt_cur.page->nextpg != P_INVALID) + goto miss; + if (t->bt_cur.index != NEXTINDEX(h) - 1) + goto miss; + if ((cmp = __bt_cmp(t, key, &t->bt_cur)) < 0) + goto miss; + t->bt_last.index = cmp ? ++t->bt_cur.index : t->bt_cur.index; + } else { + if (t->bt_cur.page->prevpg != P_INVALID) + goto miss; + if (t->bt_cur.index != 0) + goto miss; + if ((cmp = __bt_cmp(t, key, &t->bt_cur)) > 0) + goto miss; + t->bt_last.index = 0; + } + *exactp = cmp == 0; +#ifdef STATISTICS + ++bt_cache_hit; +#endif + return (&t->bt_cur); + +miss: +#ifdef STATISTICS + ++bt_cache_miss; +#endif + t->bt_order = NOT; + mpool_put(t->bt_mp, h, 0); + return (NULL); +} diff --git a/db/btree/bt_search.c b/db/btree/bt_search.c new file mode 100644 index 0000000..aa1151a --- /dev/null +++ b/db/btree/bt_search.c @@ -0,0 +1,253 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Mike Olson. + * + * 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 + +#include + +#include +#include "btree.h" + +static int bt_snext __P((BTREE *, PAGE *, const DBT *, int *)); +static int bt_sprev __P((BTREE *, PAGE *, const DBT *, int *)); + +/* + * __BT_SEARCH -- Search a btree for a key. + * + * Parameters: + * t: tree to search + * key: key to find + * exactp: pointer to exact match flag + * + * Returns: + * The EPG for matching record, if any, or the EPG for the location + * of the key, if it were inserted into the tree, is entered into + * the bt_cur field of the tree. A pointer to the field is returned. + */ +EPG * +__bt_search(t, key, exactp) + BTREE *t; + const DBT *key; + int *exactp; +{ + PAGE *h; + indx_t base, index, lim; + pgno_t pg; + int cmp; + + BT_CLR(t); + for (pg = P_ROOT;;) { + if ((h = mpool_get(t->bt_mp, pg, 0)) == NULL) + return (NULL); + + /* Do a binary search on the current page. */ + t->bt_cur.page = h; + for (base = 0, lim = NEXTINDEX(h); lim; lim >>= 1) { + t->bt_cur.index = index = base + (lim >> 1); + if ((cmp = __bt_cmp(t, key, &t->bt_cur)) == 0) { + if (h->flags & P_BLEAF) { + *exactp = 1; + return (&t->bt_cur); + } + goto next; + } + if (cmp > 0) { + base = index + 1; + --lim; + } + } + + /* + * If it's a leaf page, and duplicates aren't allowed, we're + * done. If duplicates are allowed, it's possible that there + * were duplicate keys on duplicate pages, and they were later + * deleted, so we could be on a page with no matches while + * there are matches on other pages. If we're at the start or + * end of a page, check on both sides. + */ + if (h->flags & P_BLEAF) { + t->bt_cur.index = base; + *exactp = 0; + if (!ISSET(t, B_NODUPS)) { + if (base == 0 && + bt_sprev(t, h, key, exactp)) + return (&t->bt_cur); + if (base == NEXTINDEX(h) && + bt_snext(t, h, key, exactp)) + return (&t->bt_cur); + } + return (&t->bt_cur); + } + + /* + * No match found. Base is the smallest index greater than + * key and may be zero or a last + 1 index. If it's non-zero, + * decrement by one, and record the internal page which should + * be a parent page for the key. If a split later occurs, the + * inserted page will be to the right of the saved page. + */ + index = base ? base - 1 : base; + +next: if (__bt_push(t, h->pgno, index) == RET_ERROR) + return (NULL); + pg = GETBINTERNAL(h, index)->pgno; + mpool_put(t->bt_mp, h, 0); + } +} + +/* + * BT_SNEXT -- Check for an exact match after the key. + * + * Parameters: + * t: tree to search + * h: current page. + * key: key to find + * exactp: pointer to exact match flag + * + * Returns: + * If an exact match found. + */ +static int +bt_snext(t, h, key, exactp) + BTREE *t; + PAGE *h; + const DBT *key; + int *exactp; +{ + EPG e; + PAGE *tp; + pgno_t pg; + + /* Skip until reach the end of the tree or a key. */ + for (pg = h->nextpg; pg != P_INVALID;) { + if ((tp = mpool_get(t->bt_mp, pg, 0)) == NULL) { + mpool_put(t->bt_mp, h, 0); + return (NULL); + } + if (NEXTINDEX(tp) != 0) + break; + pg = tp->prevpg; + mpool_put(t->bt_mp, tp, 0); + } + /* + * The key is either an exact match, or not as good as + * the one we already have. + */ + if (pg != P_INVALID) { + e.page = tp; + e.index = NEXTINDEX(tp) - 1; + if (__bt_cmp(t, key, &e) == 0) { + mpool_put(t->bt_mp, h, 0); + t->bt_cur = e; + *exactp = 1; + return (1); + } + } + return (0); +} + +/* + * BT_SPREV -- Check for an exact match before the key. + * + * Parameters: + * t: tree to search + * h: current page. + * key: key to find + * exactp: pointer to exact match flag + * + * Returns: + * If an exact match found. + */ +static int +bt_sprev(t, h, key, exactp) + BTREE *t; + PAGE *h; + const DBT *key; + int *exactp; +{ + EPG e; + PAGE *tp; + pgno_t pg; + + /* Skip until reach the beginning of the tree or a key. */ + for (pg = h->prevpg; pg != P_INVALID;) { + if ((tp = mpool_get(t->bt_mp, pg, 0)) == NULL) { + mpool_put(t->bt_mp, h, 0); + return (NULL); + } + if (NEXTINDEX(tp) != 0) + break; + pg = tp->prevpg; + mpool_put(t->bt_mp, tp, 0); + } + /* + * The key is either an exact match, or not as good as + * the one we already have. + */ + if (pg != P_INVALID) { + e.page = tp; + e.index = NEXTINDEX(tp) - 1; + if (__bt_cmp(t, key, &e) == 0) { + mpool_put(t->bt_mp, h, 0); + t->bt_cur = e; + *exactp = 1; + return (1); + } + } + return (0); +} diff --git a/db/btree/bt_seq.c b/db/btree/bt_seq.c new file mode 100644 index 0000000..fcbfd2c --- /dev/null +++ b/db/btree/bt_seq.c @@ -0,0 +1,398 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Mike Olson. + * + * 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 + +#include +#include +#include +#include + +#include +#include "btree.h" + +static int bt_seqadv __P((BTREE *, EPG *, int)); +static int bt_seqset __P((BTREE *, EPG *, DBT *, int)); + +/* + * Sequential scan support. + * + * The tree can be scanned sequentially, starting from either end of the tree + * or from any specific key. A scan request before any scanning is done is + * initialized as starting from the least node. + * + * Each tree has an EPGNO which has the current position of the cursor. The + * cursor has to survive deletions/insertions in the tree without losing its + * position. This is done by noting deletions without doing them, and then + * doing them when the cursor moves (or the tree is closed). + */ + +/* + * __BT_SEQ -- Btree sequential scan interface. + * + * Parameters: + * dbp: pointer to access method + * key: key for positioning and return value + * data: data return value + * flags: R_CURSOR, R_FIRST, R_LAST, R_NEXT, R_PREV. + * + * Returns: + * RET_ERROR, RET_SUCCESS or RET_SPECIAL if there's no next key. + */ +int +__bt_seq(dbp, key, data, flags) + const DB *dbp; + DBT *key, *data; + u_int flags; +{ + BTREE *t; + EPG e; + int status; + + t = dbp->internal; + + /* Toss any page pinned across calls. */ + if (t->bt_pinned != NULL) { + mpool_put(t->bt_mp, t->bt_pinned, 0); + t->bt_pinned = NULL; + } + + /* + * If scan unitialized as yet, or starting at a specific record, set + * the scan to a specific key. Both bt_seqset and bt_seqadv pin the + * page the cursor references if they're successful. + */ + switch(flags) { + case R_NEXT: + case R_PREV: + if (ISSET(t, B_SEQINIT)) { + status = bt_seqadv(t, &e, flags); + break; + } + /* FALLTHROUGH */ + case R_CURSOR: + case R_FIRST: + case R_LAST: + status = bt_seqset(t, &e, key, flags); + break; + default: + errno = EINVAL; + return (RET_ERROR); + } + + if (status == RET_SUCCESS) { + status = __bt_ret(t, &e, key, data); + + /* Update the actual cursor. */ + t->bt_bcursor.pgno = e.page->pgno; + t->bt_bcursor.index = e.index; + + /* + * If the user is doing concurrent access, we copied the + * key/data, toss the page. + */ + if (ISSET(t, B_DB_LOCK)) + mpool_put(t->bt_mp, e.page, 0); + else + t->bt_pinned = e.page; + SET(t, B_SEQINIT); + } + return (status); +} + +/* + * BT_SEQSET -- Set the sequential scan to a specific key. + * + * Parameters: + * t: tree + * ep: storage for returned key + * key: key for initial scan position + * flags: R_CURSOR, R_FIRST, R_LAST, R_NEXT, R_PREV + * + * Side effects: + * Pins the page the cursor references. + * + * Returns: + * RET_ERROR, RET_SUCCESS or RET_SPECIAL if there's no next key. + */ +static int +bt_seqset(t, ep, key, flags) + BTREE *t; + EPG *ep; + DBT *key; + int flags; +{ + EPG *e; + PAGE *h; + pgno_t pg; + int exact; + + /* + * Delete any already deleted record that we've been saving because + * the cursor pointed to it. Since going to a specific key, should + * delete any logically deleted records so they aren't found. + */ + if (ISSET(t, B_DELCRSR) && __bt_crsrdel(t, &t->bt_bcursor)) + return (RET_ERROR); + + /* + * Find the first, last or specific key in the tree and point the cursor + * at it. The cursor may not be moved until a new key has been found. + */ + switch(flags) { + case R_CURSOR: /* Keyed scan. */ + /* + * Find the first instance of the key or the smallest key which + * is greater than or equal to the specified key. If run out + * of keys, return RET_SPECIAL. + */ + if (key->data == NULL || key->size == 0) { + errno = EINVAL; + return (RET_ERROR); + } + e = __bt_first(t, key, &exact); /* Returns pinned page. */ + if (e == NULL) + return (RET_ERROR); + /* + * If at the end of a page, skip any empty pages and find the + * next entry. + */ + if (e->index == NEXTINDEX(e->page)) { + h = e->page; + do { + pg = h->nextpg; + mpool_put(t->bt_mp, h, 0); + if (pg == P_INVALID) + return (RET_SPECIAL); + if ((h = mpool_get(t->bt_mp, pg, 0)) == NULL) + return (RET_ERROR); + } while (NEXTINDEX(h) == 0); + e->index = 0; + e->page = h; + } + *ep = *e; + break; + case R_FIRST: /* First record. */ + case R_NEXT: + /* Walk down the left-hand side of the tree. */ + for (pg = P_ROOT;;) { + if ((h = mpool_get(t->bt_mp, pg, 0)) == NULL) + return (RET_ERROR); + if (h->flags & (P_BLEAF | P_RLEAF)) + break; + pg = GETBINTERNAL(h, 0)->pgno; + mpool_put(t->bt_mp, h, 0); + } + + /* Skip any empty pages. */ + while (NEXTINDEX(h) == 0 && h->nextpg != P_INVALID) { + pg = h->nextpg; + mpool_put(t->bt_mp, h, 0); + if ((h = mpool_get(t->bt_mp, pg, 0)) == NULL) + return (RET_ERROR); + } + + if (NEXTINDEX(h) == 0) { + mpool_put(t->bt_mp, h, 0); + return (RET_SPECIAL); + } + + ep->page = h; + ep->index = 0; + break; + case R_LAST: /* Last record. */ + case R_PREV: + /* Walk down the right-hand side of the tree. */ + for (pg = P_ROOT;;) { + if ((h = mpool_get(t->bt_mp, pg, 0)) == NULL) + return (RET_ERROR); + if (h->flags & (P_BLEAF | P_RLEAF)) + break; + pg = GETBINTERNAL(h, NEXTINDEX(h) - 1)->pgno; + mpool_put(t->bt_mp, h, 0); + } + + /* Skip any empty pages. */ + while (NEXTINDEX(h) == 0 && h->prevpg != P_INVALID) { + pg = h->prevpg; + mpool_put(t->bt_mp, h, 0); + if ((h = mpool_get(t->bt_mp, pg, 0)) == NULL) + return (RET_ERROR); + } + + if (NEXTINDEX(h) == 0) { + mpool_put(t->bt_mp, h, 0); + return (RET_SPECIAL); + } + + ep->page = h; + ep->index = NEXTINDEX(h) - 1; + break; + } + return (RET_SUCCESS); +} + +/* + * BT_SEQADVANCE -- Advance the sequential scan. + * + * Parameters: + * t: tree + * flags: R_NEXT, R_PREV + * + * Side effects: + * Pins the page the new key/data record is on. + * + * Returns: + * RET_ERROR, RET_SUCCESS or RET_SPECIAL if there's no next key. + */ +static int +bt_seqadv(t, e, flags) + BTREE *t; + EPG *e; + int flags; +{ + EPGNO *c, delc; + PAGE *h; + indx_t index; + pgno_t pg; + + /* Save the current cursor if going to delete it. */ + c = &t->bt_bcursor; + if (ISSET(t, B_DELCRSR)) + delc = *c; + + if ((h = mpool_get(t->bt_mp, c->pgno, 0)) == NULL) + return (RET_ERROR); + + /* + * Find the next/previous record in the tree and point the cursor at it. + * The cursor may not be moved until a new key has been found. + */ + index = c->index; + switch(flags) { + case R_NEXT: /* Next record. */ + if (++index == NEXTINDEX(h)) { + do { + pg = h->nextpg; + mpool_put(t->bt_mp, h, 0); + if (pg == P_INVALID) + return (RET_SPECIAL); + if ((h = mpool_get(t->bt_mp, pg, 0)) == NULL) + return (RET_ERROR); + } while (NEXTINDEX(h) == 0); + index = 0; + } + break; + case R_PREV: /* Previous record. */ + if (index-- == 0) { + do { + pg = h->prevpg; + mpool_put(t->bt_mp, h, 0); + if (pg == P_INVALID) + return (RET_SPECIAL); + if ((h = mpool_get(t->bt_mp, pg, 0)) == NULL) + return (RET_ERROR); + } while (NEXTINDEX(h) == 0); + index = NEXTINDEX(h) - 1; + } + break; + } + + e->page = h; + e->index = index; + + /* + * Delete any already deleted record that we've been saving because the + * cursor pointed to it. This could cause the new index to be shifted + * down by one if the record we're deleting is on the same page and has + * a larger index. + */ + if (ISSET(t, B_DELCRSR)) { + CLR(t, B_DELCRSR); /* Don't try twice. */ + if (c->pgno == delc.pgno && c->index > delc.index) + --c->index; + if (__bt_crsrdel(t, &delc)) + return (RET_ERROR); + } + return (RET_SUCCESS); +} + +/* + * __BT_CRSRDEL -- Delete the record referenced by the cursor. + * + * Parameters: + * t: tree + * + * Returns: + * RET_ERROR, RET_SUCCESS + */ +int +__bt_crsrdel(t, c) + BTREE *t; + EPGNO *c; +{ + PAGE *h; + int status; + + CLR(t, B_DELCRSR); /* Don't try twice. */ + if ((h = mpool_get(t->bt_mp, c->pgno, 0)) == NULL) + return (RET_ERROR); + status = __bt_dleaf(t, h, c->index); + mpool_put(t->bt_mp, h, MPOOL_DIRTY); + return (status); +} diff --git a/db/btree/bt_split.c b/db/btree/bt_split.c new file mode 100644 index 0000000..d11c37f --- /dev/null +++ b/db/btree/bt_split.c @@ -0,0 +1,843 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Mike Olson. + * + * 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 + +#include +#include +#include +#include + +#include +#include "btree.h" + +static int bt_broot __P((BTREE *, PAGE *, PAGE *, PAGE *)); +static PAGE *bt_page + __P((BTREE *, PAGE *, PAGE **, PAGE **, indx_t *, size_t)); +static int bt_preserve __P((BTREE *, pgno_t)); +static PAGE *bt_psplit + __P((BTREE *, PAGE *, PAGE *, PAGE *, indx_t *, size_t)); +static PAGE *bt_root + __P((BTREE *, PAGE *, PAGE **, PAGE **, indx_t *, size_t)); +static int bt_rroot __P((BTREE *, PAGE *, PAGE *, PAGE *)); +static recno_t rec_total __P((PAGE *)); + +#ifdef STATISTICS +u_long bt_rootsplit, bt_split, bt_sortsplit, bt_pfxsaved; +#endif + +/* + * __BT_SPLIT -- Split the tree. + * + * Parameters: + * t: tree + * sp: page to split + * key: key to insert + * data: data to insert + * flags: BIGKEY/BIGDATA flags + * ilen: insert length + * skip: index to leave open + * + * Returns: + * RET_ERROR, RET_SUCCESS + */ +int +__bt_split(t, sp, key, data, flags, ilen, skip) + BTREE *t; + PAGE *sp; + const DBT *key, *data; + int flags; + size_t ilen; + indx_t skip; +{ + BINTERNAL *bi; + BLEAF *bl, *tbl; + DBT a, b; + EPGNO *parent; + PAGE *h, *l, *r, *lchild, *rchild; + indx_t nxtindex; + size_t n, nbytes, nksize; + int parentsplit; + char *dest; + + /* + * Split the page into two pages, l and r. The split routines return + * a pointer to the page into which the key should be inserted and with + * skip set to the offset which should be used. Additionally, l and r + * are pinned. + */ + h = sp->pgno == P_ROOT ? + bt_root(t, sp, &l, &r, &skip, ilen) : + bt_page(t, sp, &l, &r, &skip, ilen); + if (h == NULL) + return (RET_ERROR); + + /* + * Insert the new key/data pair into the leaf page. (Key inserts + * always cause a leaf page to split first.) + */ + h->linp[skip] = h->upper -= ilen; + dest = (char *)h + h->upper; + if (ISSET(t, R_RECNO)) + WR_RLEAF(dest, data, flags) + else + WR_BLEAF(dest, key, data, flags) + + /* If the root page was split, make it look right. */ + if (sp->pgno == P_ROOT && + (ISSET(t, R_RECNO) ? + bt_rroot(t, sp, l, r) : bt_broot(t, sp, l, r)) == RET_ERROR) + goto err2; + + /* + * Now we walk the parent page stack -- a LIFO stack of the pages that + * were traversed when we searched for the page that split. Each stack + * entry is a page number and a page index offset. The offset is for + * the page traversed on the search. We've just split a page, so we + * have to insert a new key into the parent page. + * + * If the insert into the parent page causes it to split, may have to + * continue splitting all the way up the tree. We stop if the root + * splits or the page inserted into didn't have to split to hold the + * new key. Some algorithms replace the key for the old page as well + * as the new page. We don't, as there's no reason to believe that the + * first key on the old page is any better than the key we have, and, + * in the case of a key being placed at index 0 causing the split, the + * key is unavailable. + * + * There are a maximum of 5 pages pinned at any time. We keep the left + * and right pages pinned while working on the parent. The 5 are the + * two children, left parent and right parent (when the parent splits) + * and the root page or the overflow key page when calling bt_preserve. + * This code must make sure that all pins are released other than the + * root page or overflow page which is unlocked elsewhere. + */ + while ((parent = BT_POP(t)) != NULL) { + lchild = l; + rchild = r; + + /* Get the parent page. */ + if ((h = mpool_get(t->bt_mp, parent->pgno, 0)) == NULL) + goto err2; + + /* + * The new key goes ONE AFTER the index, because the split + * was to the right. + */ + skip = parent->index + 1; + + /* + * Calculate the space needed on the parent page. + * + * Prefix trees: space hack when inserting into BINTERNAL + * pages. Retain only what's needed to distinguish between + * the new entry and the LAST entry on the page to its left. + * If the keys compare equal, retain the entire key. Note, + * we don't touch overflow keys, and the entire key must be + * retained for the next-to-left most key on the leftmost + * page of each level, or the search will fail. Applicable + * ONLY to internal pages that have leaf pages as children. + * Further reduction of the key between pairs of internal + * pages loses too much information. + */ + switch (rchild->flags & P_TYPE) { + case P_BINTERNAL: + bi = GETBINTERNAL(rchild, 0); + nbytes = NBINTERNAL(bi->ksize); + break; + case P_BLEAF: + bl = GETBLEAF(rchild, 0); + nbytes = NBINTERNAL(bl->ksize); + if (t->bt_pfx && !(bl->flags & P_BIGKEY) && + (h->prevpg != P_INVALID || skip > 1)) { + tbl = GETBLEAF(lchild, NEXTINDEX(lchild) - 1); + a.size = tbl->ksize; + a.data = tbl->bytes; + b.size = bl->ksize; + b.data = bl->bytes; + nksize = t->bt_pfx(&a, &b); + n = NBINTERNAL(nksize); + if (n < nbytes) { +#ifdef STATISTICS + bt_pfxsaved += nbytes - n; +#endif + nbytes = n; + } else + nksize = 0; + } else + nksize = 0; + break; + case P_RINTERNAL: + case P_RLEAF: + nbytes = NRINTERNAL; + break; + default: + abort(); + } + + /* Split the parent page if necessary or shift the indices. */ + if (h->upper - h->lower < nbytes + sizeof(indx_t)) { + sp = h; + h = h->pgno == P_ROOT ? + bt_root(t, h, &l, &r, &skip, nbytes) : + bt_page(t, h, &l, &r, &skip, nbytes); + if (h == NULL) + goto err1; + parentsplit = 1; + } else { + if (skip < (nxtindex = NEXTINDEX(h))) + memmove(h->linp + skip + 1, h->linp + skip, + (nxtindex - skip) * sizeof(indx_t)); + h->lower += sizeof(indx_t); + parentsplit = 0; + } + + /* Insert the key into the parent page. */ + switch(rchild->flags & P_TYPE) { + case P_BINTERNAL: + h->linp[skip] = h->upper -= nbytes; + dest = (char *)h + h->linp[skip]; + memmove(dest, bi, nbytes); + ((BINTERNAL *)dest)->pgno = rchild->pgno; + break; + case P_BLEAF: + h->linp[skip] = h->upper -= nbytes; + dest = (char *)h + h->linp[skip]; + WR_BINTERNAL(dest, nksize ? nksize : bl->ksize, + rchild->pgno, bl->flags & P_BIGKEY); + memmove(dest, bl->bytes, nksize ? nksize : bl->ksize); + if (bl->flags & P_BIGKEY && + bt_preserve(t, *(pgno_t *)bl->bytes) == RET_ERROR) + goto err1; + break; + case P_RINTERNAL: + /* + * Update the left page count. If split + * added at index 0, fix the correct page. + */ + if (skip > 0) + dest = (char *)h + h->linp[skip - 1]; + else + dest = (char *)l + l->linp[NEXTINDEX(l) - 1]; + ((RINTERNAL *)dest)->nrecs = rec_total(lchild); + ((RINTERNAL *)dest)->pgno = lchild->pgno; + + /* Update the right page count. */ + h->linp[skip] = h->upper -= nbytes; + dest = (char *)h + h->linp[skip]; + ((RINTERNAL *)dest)->nrecs = rec_total(rchild); + ((RINTERNAL *)dest)->pgno = rchild->pgno; + break; + case P_RLEAF: + /* + * Update the left page count. If split + * added at index 0, fix the correct page. + */ + if (skip > 0) + dest = (char *)h + h->linp[skip - 1]; + else + dest = (char *)l + l->linp[NEXTINDEX(l) - 1]; + ((RINTERNAL *)dest)->nrecs = NEXTINDEX(lchild); + ((RINTERNAL *)dest)->pgno = lchild->pgno; + + /* Update the right page count. */ + h->linp[skip] = h->upper -= nbytes; + dest = (char *)h + h->linp[skip]; + ((RINTERNAL *)dest)->nrecs = NEXTINDEX(rchild); + ((RINTERNAL *)dest)->pgno = rchild->pgno; + break; + default: + abort(); + } + + /* Unpin the held pages. */ + if (!parentsplit) { + mpool_put(t->bt_mp, h, MPOOL_DIRTY); + break; + } + + /* If the root page was split, make it look right. */ + if (sp->pgno == P_ROOT && + (ISSET(t, R_RECNO) ? + bt_rroot(t, sp, l, r) : bt_broot(t, sp, l, r)) == RET_ERROR) + goto err1; + + mpool_put(t->bt_mp, lchild, MPOOL_DIRTY); + mpool_put(t->bt_mp, rchild, MPOOL_DIRTY); + } + + /* Unpin the held pages. */ + mpool_put(t->bt_mp, l, MPOOL_DIRTY); + mpool_put(t->bt_mp, r, MPOOL_DIRTY); + + /* Clear any pages left on the stack. */ + return (RET_SUCCESS); + + /* + * If something fails in the above loop we were already walking back + * up the tree and the tree is now inconsistent. Nothing much we can + * do about it but release any memory we're holding. + */ +err1: mpool_put(t->bt_mp, lchild, MPOOL_DIRTY); + mpool_put(t->bt_mp, rchild, MPOOL_DIRTY); + +err2: mpool_put(t->bt_mp, l, 0); + mpool_put(t->bt_mp, r, 0); + __dbpanic(t->bt_dbp); + return (RET_ERROR); +} + +/* + * BT_PAGE -- Split a non-root page of a btree. + * + * Parameters: + * t: tree + * h: root page + * lp: pointer to left page pointer + * rp: pointer to right page pointer + * skip: pointer to index to leave open + * ilen: insert length + * + * Returns: + * Pointer to page in which to insert or NULL on error. + */ +static PAGE * +bt_page(t, h, lp, rp, skip, ilen) + BTREE *t; + PAGE *h, **lp, **rp; + indx_t *skip; + size_t ilen; +{ + PAGE *l, *r, *tp; + pgno_t npg; + +#ifdef STATISTICS + ++bt_split; +#endif + /* Put the new right page for the split into place. */ + if ((r = __bt_new(t, &npg)) == NULL) + return (NULL); + r->pgno = npg; + r->lower = BTDATAOFF; + r->upper = t->bt_psize; + r->nextpg = h->nextpg; + r->prevpg = h->pgno; + r->flags = h->flags & P_TYPE; + + /* + * If we're splitting the last page on a level because we're appending + * a key to it (skip is NEXTINDEX()), it's likely that the data is + * sorted. Adding an empty page on the side of the level is less work + * and can push the fill factor much higher than normal. If we're + * wrong it's no big deal, we'll just do the split the right way next + * time. It may look like it's equally easy to do a similar hack for + * reverse sorted data, that is, split the tree left, but it's not. + * Don't even try. + */ + if (h->nextpg == P_INVALID && *skip == NEXTINDEX(h)) { +#ifdef STATISTICS + ++bt_sortsplit; +#endif + h->nextpg = r->pgno; + r->lower = BTDATAOFF + sizeof(indx_t); + *skip = 0; + *lp = h; + *rp = r; + return (r); + } + + /* Put the new left page for the split into place. */ + if ((l = (PAGE *)malloc(t->bt_psize)) == NULL) { + mpool_put(t->bt_mp, r, 0); + return (NULL); + } + l->pgno = h->pgno; + l->nextpg = r->pgno; + l->prevpg = h->prevpg; + l->lower = BTDATAOFF; + l->upper = t->bt_psize; + l->flags = h->flags & P_TYPE; + + /* Fix up the previous pointer of the page after the split page. */ + if (h->nextpg != P_INVALID) { + if ((tp = mpool_get(t->bt_mp, h->nextpg, 0)) == NULL) { + free(l); + /* XXX mpool_free(t->bt_mp, r->pgno); */ + return (NULL); + } + tp->prevpg = r->pgno; + mpool_put(t->bt_mp, tp, 0); + } + + /* + * Split right. The key/data pairs aren't sorted in the btree page so + * it's simpler to copy the data from the split page onto two new pages + * instead of copying half the data to the right page and compacting + * the left page in place. Since the left page can't change, we have + * to swap the original and the allocated left page after the split. + */ + tp = bt_psplit(t, h, l, r, skip, ilen); + + /* Move the new left page onto the old left page. */ + memmove(h, l, t->bt_psize); + if (tp == l) + tp = h; + free(l); + + *lp = h; + *rp = r; + return (tp); +} + +/* + * BT_ROOT -- Split the root page of a btree. + * + * Parameters: + * t: tree + * h: root page + * lp: pointer to left page pointer + * rp: pointer to right page pointer + * skip: pointer to index to leave open + * ilen: insert length + * + * Returns: + * Pointer to page in which to insert or NULL on error. + */ +static PAGE * +bt_root(t, h, lp, rp, skip, ilen) + BTREE *t; + PAGE *h, **lp, **rp; + indx_t *skip; + size_t ilen; +{ + PAGE *l, *r, *tp; + pgno_t lnpg, rnpg; + +#ifdef STATISTICS + ++bt_split; + ++bt_rootsplit; +#endif + /* Put the new left and right pages for the split into place. */ + if ((l = __bt_new(t, &lnpg)) == NULL || + (r = __bt_new(t, &rnpg)) == NULL) + return (NULL); + l->pgno = lnpg; + r->pgno = rnpg; + l->nextpg = r->pgno; + r->prevpg = l->pgno; + l->prevpg = r->nextpg = P_INVALID; + l->lower = r->lower = BTDATAOFF; + l->upper = r->upper = t->bt_psize; + l->flags = r->flags = h->flags & P_TYPE; + + /* Split the root page. */ + tp = bt_psplit(t, h, l, r, skip, ilen); + + *lp = l; + *rp = r; + return (tp); +} + +/* + * BT_RROOT -- Fix up the recno root page after it has been split. + * + * Parameters: + * t: tree + * h: root page + * l: left page + * r: right page + * + * Returns: + * RET_ERROR, RET_SUCCESS + */ +static int +bt_rroot(t, h, l, r) + BTREE *t; + PAGE *h, *l, *r; +{ + char *dest; + + /* Insert the left and right keys, set the header information. */ + h->linp[0] = h->upper = t->bt_psize - NRINTERNAL; + dest = (char *)h + h->upper; + WR_RINTERNAL(dest, + l->flags & P_RLEAF ? NEXTINDEX(l) : rec_total(l), l->pgno); + + h->linp[1] = h->upper -= NRINTERNAL; + dest = (char *)h + h->upper; + WR_RINTERNAL(dest, + r->flags & P_RLEAF ? NEXTINDEX(r) : rec_total(r), r->pgno); + + h->lower = BTDATAOFF + 2 * sizeof(indx_t); + + /* Unpin the root page, set to recno internal page. */ + h->flags &= ~P_TYPE; + h->flags |= P_RINTERNAL; + mpool_put(t->bt_mp, h, MPOOL_DIRTY); + + return (RET_SUCCESS); +} + +/* + * BT_BROOT -- Fix up the btree root page after it has been split. + * + * Parameters: + * t: tree + * h: root page + * l: left page + * r: right page + * + * Returns: + * RET_ERROR, RET_SUCCESS + */ +static int +bt_broot(t, h, l, r) + BTREE *t; + PAGE *h, *l, *r; +{ + BINTERNAL *bi; + BLEAF *bl; + size_t nbytes; + char *dest; + + /* + * If the root page was a leaf page, change it into an internal page. + * We copy the key we split on (but not the key's data, in the case of + * a leaf page) to the new root page. + * + * The btree comparison code guarantees that the left-most key on any + * level of the tree is never used, so it doesn't need to be filled in. + */ + nbytes = NBINTERNAL(0); + h->linp[0] = h->upper = t->bt_psize - nbytes; + dest = (char *)h + h->upper; + WR_BINTERNAL(dest, 0, l->pgno, 0); + + switch(h->flags & P_TYPE) { + case P_BLEAF: + bl = GETBLEAF(r, 0); + nbytes = NBINTERNAL(bl->ksize); + h->linp[1] = h->upper -= nbytes; + dest = (char *)h + h->upper; + WR_BINTERNAL(dest, bl->ksize, r->pgno, 0); + memmove(dest, bl->bytes, bl->ksize); + + /* + * If the key is on an overflow page, mark the overflow chain + * so it isn't deleted when the leaf copy of the key is deleted. + */ + if (bl->flags & P_BIGKEY && + bt_preserve(t, *(pgno_t *)bl->bytes) == RET_ERROR) + return (RET_ERROR); + break; + case P_BINTERNAL: + bi = GETBINTERNAL(r, 0); + nbytes = NBINTERNAL(bi->ksize); + h->linp[1] = h->upper -= nbytes; + dest = (char *)h + h->upper; + memmove(dest, bi, nbytes); + ((BINTERNAL *)dest)->pgno = r->pgno; + break; + default: + abort(); + } + + /* There are two keys on the page. */ + h->lower = BTDATAOFF + 2 * sizeof(indx_t); + + /* Unpin the root page, set to btree internal page. */ + h->flags &= ~P_TYPE; + h->flags |= P_BINTERNAL; + mpool_put(t->bt_mp, h, MPOOL_DIRTY); + + return (RET_SUCCESS); +} + +/* + * BT_PSPLIT -- Do the real work of splitting the page. + * + * Parameters: + * t: tree + * h: page to be split + * l: page to put lower half of data + * r: page to put upper half of data + * pskip: pointer to index to leave open + * ilen: insert length + * + * Returns: + * Pointer to page in which to insert. + */ +static PAGE * +bt_psplit(t, h, l, r, pskip, ilen) + BTREE *t; + PAGE *h, *l, *r; + indx_t *pskip; + size_t ilen; +{ + BINTERNAL *bi; + BLEAF *bl; + RLEAF *rl; + EPGNO *c; + PAGE *rval; + void *src; + indx_t full, half, nxt, off, skip, top, used; + size_t nbytes; + int bigkeycnt, isbigkey; + + /* + * Split the data to the left and right pages. Leave the skip index + * open. Additionally, make some effort not to split on an overflow + * key. This makes internal page processing faster and can save + * space as overflow keys used by internal pages are never deleted. + */ + bigkeycnt = 0; + skip = *pskip; + full = t->bt_psize - BTDATAOFF; + half = full / 2; + used = 0; + for (nxt = off = 0, top = NEXTINDEX(h); nxt < top; ++off) { + if (skip == off) { + nbytes = ilen; + isbigkey = 0; /* XXX: not really known. */ + } else + switch (h->flags & P_TYPE) { + case P_BINTERNAL: + src = bi = GETBINTERNAL(h, nxt); + nbytes = NBINTERNAL(bi->ksize); + isbigkey = bi->flags & P_BIGKEY; + break; + case P_BLEAF: + src = bl = GETBLEAF(h, nxt); + nbytes = NBLEAF(bl); + isbigkey = bl->flags & P_BIGKEY; + break; + case P_RINTERNAL: + src = GETRINTERNAL(h, nxt); + nbytes = NRINTERNAL; + isbigkey = 0; + break; + case P_RLEAF: + src = rl = GETRLEAF(h, nxt); + nbytes = NRLEAF(rl); + isbigkey = 0; + break; + default: + abort(); + } + + /* + * If the key/data pairs are substantial fractions of the max + * possible size for the page, it's possible to get situations + * where we decide to try and copy too much onto the left page. + * Make sure that doesn't happen. + */ + if (skip <= off && used + nbytes >= full) { + --off; + break; + } + + /* Copy the key/data pair, if not the skipped index. */ + if (skip != off) { + ++nxt; + + l->linp[off] = l->upper -= nbytes; + memmove((char *)l + l->upper, src, nbytes); + } + + used += nbytes; + if (used >= half) { + if (!isbigkey || bigkeycnt == 3) + break; + else + ++bigkeycnt; + } + } + + /* + * Off is the last offset that's valid for the left page. + * Nxt is the first offset to be placed on the right page. + */ + l->lower += (off + 1) * sizeof(indx_t); + + /* + * If splitting the page that the cursor was on, the cursor has to be + * adjusted to point to the same record as before the split. If the + * cursor is at or past the skipped slot, the cursor is incremented by + * one. If the cursor is on the right page, it is decremented by the + * number of records split to the left page. + * + * Don't bother checking for the B_SEQINIT flag, the page number will + * be P_INVALID. + */ + c = &t->bt_bcursor; + if (c->pgno == h->pgno) { + if (c->index >= skip) + ++c->index; + if (c->index < nxt) /* Left page. */ + c->pgno = l->pgno; + else { /* Right page. */ + c->pgno = r->pgno; + c->index -= nxt; + } + } + + /* + * If the skipped index was on the left page, just return that page. + * Otherwise, adjust the skip index to reflect the new position on + * the right page. + */ + if (skip <= off) { + skip = 0; + rval = l; + } else { + rval = r; + *pskip -= nxt; + } + + for (off = 0; nxt < top; ++off) { + if (skip == nxt) { + ++off; + skip = 0; + } + switch (h->flags & P_TYPE) { + case P_BINTERNAL: + src = bi = GETBINTERNAL(h, nxt); + nbytes = NBINTERNAL(bi->ksize); + break; + case P_BLEAF: + src = bl = GETBLEAF(h, nxt); + nbytes = NBLEAF(bl); + break; + case P_RINTERNAL: + src = GETRINTERNAL(h, nxt); + nbytes = NRINTERNAL; + break; + case P_RLEAF: + src = rl = GETRLEAF(h, nxt); + nbytes = NRLEAF(rl); + break; + default: + abort(); + } + ++nxt; + r->linp[off] = r->upper -= nbytes; + memmove((char *)r + r->upper, src, nbytes); + } + r->lower += off * sizeof(indx_t); + + /* If the key is being appended to the page, adjust the index. */ + if (skip == top) + r->lower += sizeof(indx_t); + + return (rval); +} + +/* + * BT_PRESERVE -- Mark a chain of pages as used by an internal node. + * + * Chains of indirect blocks pointed to by leaf nodes get reclaimed when the + * record that references them gets deleted. Chains pointed to by internal + * pages never get deleted. This routine marks a chain as pointed to by an + * internal page. + * + * Parameters: + * t: tree + * pg: page number of first page in the chain. + * + * Returns: + * RET_SUCCESS, RET_ERROR. + */ +static int +bt_preserve(t, pg) + BTREE *t; + pgno_t pg; +{ + PAGE *h; + + if ((h = mpool_get(t->bt_mp, pg, 0)) == NULL) + return (RET_ERROR); + h->flags |= P_PRESERVE; + mpool_put(t->bt_mp, h, MPOOL_DIRTY); + return (RET_SUCCESS); +} + +/* + * REC_TOTAL -- Return the number of recno entries below a page. + * + * Parameters: + * h: page + * + * Returns: + * The number of recno entries below a page. + * + * XXX + * These values could be set by the bt_psplit routine. The problem is that the + * entry has to be popped off of the stack etc. or the values have to be passed + * all the way back to bt_split/bt_rroot and it's not very clean. + */ +static recno_t +rec_total(h) + PAGE *h; +{ + recno_t recs; + indx_t nxt, top; + + for (recs = 0, nxt = 0, top = NEXTINDEX(h); nxt < top; ++nxt) + recs += GETRINTERNAL(h, nxt)->nrecs; + return (recs); +} diff --git a/db/btree/bt_stack.c b/db/btree/bt_stack.c new file mode 100644 index 0000000..528299b --- /dev/null +++ b/db/btree/bt_stack.c @@ -0,0 +1,110 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Mike Olson. + * + * 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 + +#include +#include +#include + +#include +#include "btree.h" + +/* + * When a page splits, a new record has to be inserted into its parent page. + * This page may have to split as well, all the way up to the root. Since + * parent pointers in each page would be expensive, we maintain a stack of + * parent pages as we descend the tree. + * + * XXX + * This is a concurrency problem -- if user a builds a stack, then user b + * splits the tree, then user a tries to split the tree, there's a new level + * in the tree that user a doesn't know about. + */ + +/* + * __BT_PUSH -- Push parent page info onto the stack (LIFO). + * + * Parameters: + * t: tree + * pgno: page + * index: page index + * + * Returns: + * RET_ERROR, RET_SUCCESS + */ +int +__bt_push(t, pgno, index) + BTREE *t; + pgno_t pgno; + indx_t index; +{ + if (t->bt_sp == t->bt_maxstack) { + t->bt_maxstack += 50; + if ((t->bt_stack = (EPGNO *)realloc(t->bt_stack, + t->bt_maxstack * sizeof(EPGNO))) == NULL) { + t->bt_maxstack -= 50; + return (RET_ERROR); + } + } + + t->bt_stack[t->bt_sp].pgno = pgno; + t->bt_stack[t->bt_sp].index = index; + ++t->bt_sp; + return (RET_SUCCESS); +} diff --git a/db/btree/bt_utils.c b/db/btree/bt_utils.c new file mode 100644 index 0000000..17093b8 --- /dev/null +++ b/db/btree/bt_utils.c @@ -0,0 +1,265 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Mike Olson. + * + * 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 + +#include +#include +#include + +#include +#include "btree.h" + +/* + * __BT_RET -- Build return key/data pair as a result of search or scan. + * + * Parameters: + * t: tree + * d: LEAF to be returned to the user. + * key: user's key structure (NULL if not to be filled in) + * data: user's data structure + * + * Returns: + * RET_SUCCESS, RET_ERROR. + */ +int +__bt_ret(t, e, key, data) + BTREE *t; + EPG *e; + DBT *key, *data; +{ + register BLEAF *bl; + register void *p; + + bl = GETBLEAF(e->page, e->index); + + /* + * We always copy big keys/data to make them contigous. Otherwise, + * we leave the page pinned and don't copy unless the user specified + * concurrent access. + */ + if (bl->flags & P_BIGDATA) { + if (__ovfl_get(t, bl->bytes + bl->ksize, + &data->size, &t->bt_dbuf, &t->bt_dbufsz)) + return (RET_ERROR); + data->data = t->bt_dbuf; + } else if (ISSET(t, B_DB_LOCK)) { + /* Use +1 in case the first record retrieved is 0 length. */ + if (bl->dsize + 1 > t->bt_dbufsz) { + if ((p = + (void *)realloc(t->bt_dbuf, bl->dsize + 1)) == NULL) + return (RET_ERROR); + t->bt_dbuf = p; + t->bt_dbufsz = bl->dsize + 1; + } + memmove(t->bt_dbuf, bl->bytes + bl->ksize, bl->dsize); + data->size = bl->dsize; + data->data = t->bt_dbuf; + } else { + data->size = bl->dsize; + data->data = bl->bytes + bl->ksize; + } + + if (key == NULL) + return (RET_SUCCESS); + + if (bl->flags & P_BIGKEY) { + if (__ovfl_get(t, bl->bytes, + &key->size, &t->bt_kbuf, &t->bt_kbufsz)) + return (RET_ERROR); + key->data = t->bt_kbuf; + } else if (ISSET(t, B_DB_LOCK)) { + if (bl->ksize > t->bt_kbufsz) { + if ((p = + (void *)realloc(t->bt_kbuf, bl->ksize)) == NULL) + return (RET_ERROR); + t->bt_kbuf = p; + t->bt_kbufsz = bl->ksize; + } + memmove(t->bt_kbuf, bl->bytes, bl->ksize); + key->size = bl->ksize; + key->data = t->bt_kbuf; + } else { + key->size = bl->ksize; + key->data = bl->bytes; + } + return (RET_SUCCESS); +} + +/* + * __BT_CMP -- Compare a key to a given record. + * + * Parameters: + * t: tree + * k1: DBT pointer of first arg to comparison + * e: pointer to EPG for comparison + * + * Returns: + * < 0 if k1 is < record + * = 0 if k1 is = record + * > 0 if k1 is > record + */ +int +__bt_cmp(t, k1, e) + BTREE *t; + const DBT *k1; + EPG *e; +{ + BINTERNAL *bi; + BLEAF *bl; + DBT k2; + PAGE *h; + void *bigkey; + + /* + * The left-most key on internal pages, at any level of the tree, is + * guaranteed by the following code to be less than any user key. + * This saves us from having to update the leftmost key on an internal + * page when the user inserts a new key in the tree smaller than + * anything we've yet seen. + */ + h = e->page; + if (e->index == 0 && h->prevpg == P_INVALID && !(h->flags & P_BLEAF)) + return (1); + + bigkey = NULL; + if (h->flags & P_BLEAF) { + bl = GETBLEAF(h, e->index); + if (bl->flags & P_BIGKEY) + bigkey = bl->bytes; + else { + k2.data = bl->bytes; + k2.size = bl->ksize; + } + } else { + bi = GETBINTERNAL(h, e->index); + if (bi->flags & P_BIGKEY) + bigkey = bi->bytes; + else { + k2.data = bi->bytes; + k2.size = bi->ksize; + } + } + + if (bigkey) { + if (__ovfl_get(t, bigkey, + &k2.size, &t->bt_dbuf, &t->bt_dbufsz)) + return (RET_ERROR); + k2.data = t->bt_dbuf; + } + return ((*t->bt_cmp)(k1, &k2)); +} + +/* + * __BT_DEFCMP -- Default comparison routine. + * + * Parameters: + * a: DBT #1 + * b: DBT #2 + * + * Returns: + * < 0 if a is < b + * = 0 if a is = b + * > 0 if a is > b + */ +int +__bt_defcmp(a, b) + const DBT *a, *b; +{ + register size_t len; + register u_char *p1, *p2; + + /* + * XXX + * If a size_t doesn't fit in an int, this routine can lose. + * What we need is a integral type which is guaranteed to be + * larger than a size_t, and there is no such thing. + */ + len = MIN(a->size, b->size); + for (p1 = a->data, p2 = b->data; len--; ++p1, ++p2) + if (*p1 != *p2) + return ((int)*p1 - (int)*p2); + return ((int)a->size - (int)b->size); +} + +/* + * __BT_DEFPFX -- Default prefix routine. + * + * Parameters: + * a: DBT #1 + * b: DBT #2 + * + * Returns: + * Number of bytes needed to distinguish b from a. + */ +size_t +__bt_defpfx(a, b) + const DBT *a, *b; +{ + register u_char *p1, *p2; + register size_t cnt, len; + + cnt = 1; + len = MIN(a->size, b->size); + for (p1 = a->data, p2 = b->data; len--; ++p1, ++p2, ++cnt) + if (*p1 != *p2) + return (cnt); + + /* a->size must be <= b->size, or they wouldn't be in this order. */ + return (a->size < b->size ? a->size + 1 : a->size); +} diff --git a/db/btree/btree.h b/db/btree/btree.h new file mode 100644 index 0000000..aa62d01 --- /dev/null +++ b/db/btree/btree.h @@ -0,0 +1,372 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1991, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Mike Olson. + * + * 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 + +#define DEFMINKEYPAGE (2) /* Minimum keys per page */ +#define MINCACHE (5) /* Minimum cached pages */ +#define MINPSIZE (512) /* Minimum page size */ + +/* + * Page 0 of a btree file contains a copy of the meta-data. This page is also + * used as an out-of-band page, i.e. page pointers that point to nowhere point + * to page 0. Page 1 is the root of the btree. + */ +#define P_INVALID 0 /* Invalid tree page number. */ +#define P_META 0 /* Tree metadata page number. */ +#define P_ROOT 1 /* Tree root page number. */ + +/* + * There are five page layouts in the btree: btree internal pages (BINTERNAL), + * btree leaf pages (BLEAF), recno internal pages (RINTERNAL), recno leaf pages + * (RLEAF) and overflow pages. All five page types have a page header (PAGE). + * This implementation requires that values within structures NOT be padded. + * (ANSI C permits random padding.) If your compiler pads randomly you'll have + * to do some work to get this package to run. + */ +typedef struct _page { + pgno_t pgno; /* this page's page number */ + pgno_t prevpg; /* left sibling */ + pgno_t nextpg; /* right sibling */ + +#define P_BINTERNAL 0x01 /* btree internal page */ +#define P_BLEAF 0x02 /* leaf page */ +#define P_OVERFLOW 0x04 /* overflow page */ +#define P_RINTERNAL 0x08 /* recno internal page */ +#define P_RLEAF 0x10 /* leaf page */ +#define P_TYPE 0x1f /* type mask */ +#define P_PRESERVE 0x20 /* never delete this chain of pages */ + u_int32_t flags; + + indx_t lower; /* lower bound of free space on page */ + indx_t upper; /* upper bound of free space on page */ + indx_t linp[1]; /* indx_t-aligned VAR. LENGTH DATA */ +} PAGE; + +/* First and next index. */ +#define BTDATAOFF (sizeof(pgno_t) + sizeof(pgno_t) + sizeof(pgno_t) + \ + sizeof(u_int32_t) + sizeof(indx_t) + sizeof(indx_t)) +#define NEXTINDEX(p) (((p)->lower - BTDATAOFF) / sizeof(indx_t)) + +/* + * For pages other than overflow pages, there is an array of offsets into the + * rest of the page immediately following the page header. Each offset is to + * an item which is unique to the type of page. The h_lower offset is just + * past the last filled-in index. The h_upper offset is the first item on the + * page. Offsets are from the beginning of the page. + * + * If an item is too big to store on a single page, a flag is set and the item + * is a { page, size } pair such that the page is the first page of an overflow + * chain with size bytes of item. Overflow pages are simply bytes without any + * external structure. + * + * The page number and size fields in the items are pgno_t-aligned so they can + * be manipulated without copying. (This presumes that 32 bit items can be + * manipulated on this system.) + */ +#define LALIGN(n) \ + (((n) + sizeof(pgno_t) - 1) & ~(sizeof(pgno_t) - 1)) +#define NOVFLSIZE (sizeof(pgno_t) + sizeof(size_t)) + +/* + * For the btree internal pages, the item is a key. BINTERNALs are {key, pgno} + * pairs, such that the key compares less than or equal to all of the records + * on that page. For a tree without duplicate keys, an internal page with two + * consecutive keys, a and b, will have all records greater than or equal to a + * and less than b stored on the page associated with a. Duplicate keys are + * somewhat special and can cause duplicate internal and leaf page records and + * some minor modifications of the above rule. + */ +typedef struct _binternal { + size_t ksize; /* key size */ + pgno_t pgno; /* page number stored on */ +#define P_BIGDATA 0x01 /* overflow data */ +#define P_BIGKEY 0x02 /* overflow key */ + u_char flags; + char bytes[1]; /* data */ +} BINTERNAL; + +/* Get the page's BINTERNAL structure at index indx. */ +#define GETBINTERNAL(pg, indx) \ + ((BINTERNAL *)((char *)(pg) + (pg)->linp[indx])) + +/* Get the number of bytes in the entry. */ +#define NBINTERNAL(len) \ + LALIGN(sizeof(size_t) + sizeof(pgno_t) + sizeof(u_char) + (len)) + +/* Copy a BINTERNAL entry to the page. */ +#define WR_BINTERNAL(p, size, pgno, flags) { \ + *(size_t *)p = size; \ + p += sizeof(size_t); \ + *(pgno_t *)p = pgno; \ + p += sizeof(pgno_t); \ + *(u_char *)p = flags; \ + p += sizeof(u_char); \ +} + +/* + * For the recno internal pages, the item is a page number with the number of + * keys found on that page and below. + */ +typedef struct _rinternal { + recno_t nrecs; /* number of records */ + pgno_t pgno; /* page number stored below */ +} RINTERNAL; + +/* Get the page's RINTERNAL structure at index indx. */ +#define GETRINTERNAL(pg, indx) \ + ((RINTERNAL *)((char *)(pg) + (pg)->linp[indx])) + +/* Get the number of bytes in the entry. */ +#define NRINTERNAL \ + LALIGN(sizeof(recno_t) + sizeof(pgno_t)) + +/* Copy a RINTERAL entry to the page. */ +#define WR_RINTERNAL(p, nrecs, pgno) { \ + *(recno_t *)p = nrecs; \ + p += sizeof(recno_t); \ + *(pgno_t *)p = pgno; \ +} + +/* For the btree leaf pages, the item is a key and data pair. */ +typedef struct _bleaf { + size_t ksize; /* size of key */ + size_t dsize; /* size of data */ + u_char flags; /* P_BIGDATA, P_BIGKEY */ + char bytes[1]; /* data */ +} BLEAF; + +/* Get the page's BLEAF structure at index indx. */ +#define GETBLEAF(pg, indx) \ + ((BLEAF *)((char *)(pg) + (pg)->linp[indx])) + +/* Get the number of bytes in the entry. */ +#define NBLEAF(p) NBLEAFDBT((p)->ksize, (p)->dsize) + +/* Get the number of bytes in the user's key/data pair. */ +#define NBLEAFDBT(ksize, dsize) \ + LALIGN(sizeof(size_t) + sizeof(size_t) + sizeof(u_char) + \ + (ksize) + (dsize)) + +/* Copy a BLEAF entry to the page. */ +#define WR_BLEAF(p, key, data, flags) { \ + *(size_t *)p = key->size; \ + p += sizeof(size_t); \ + *(size_t *)p = data->size; \ + p += sizeof(size_t); \ + *(u_char *)p = flags; \ + p += sizeof(u_char); \ + memmove(p, key->data, key->size); \ + p += key->size; \ + memmove(p, data->data, data->size); \ +} + +/* For the recno leaf pages, the item is a data entry. */ +typedef struct _rleaf { + size_t dsize; /* size of data */ + u_char flags; /* P_BIGDATA */ + char bytes[1]; +} RLEAF; + +/* Get the page's RLEAF structure at index indx. */ +#define GETRLEAF(pg, indx) \ + ((RLEAF *)((char *)(pg) + (pg)->linp[indx])) + +/* Get the number of bytes in the entry. */ +#define NRLEAF(p) NRLEAFDBT((p)->dsize) + +/* Get the number of bytes from the user's data. */ +#define NRLEAFDBT(dsize) \ + LALIGN(sizeof(size_t) + sizeof(u_char) + (dsize)) + +/* Copy a RLEAF entry to the page. */ +#define WR_RLEAF(p, data, flags) { \ + *(size_t *)p = data->size; \ + p += sizeof(size_t); \ + *(u_char *)p = flags; \ + p += sizeof(u_char); \ + memmove(p, data->data, data->size); \ +} + +/* + * A record in the tree is either a pointer to a page and an index in the page + * or a page number and an index. These structures are used as a cursor, stack + * entry and search returns as well as to pass records to other routines. + * + * One comment about searches. Internal page searches must find the largest + * record less than key in the tree so that descents work. Leaf page searches + * must find the smallest record greater than key so that the returned index + * is the record's correct position for insertion. + * + * One comment about cursors. The cursor key is never removed from the tree, + * even if deleted. This is because it is quite difficult to decide where the + * cursor should be when other keys have been inserted/deleted in the tree; + * duplicate keys make it impossible. This scheme does require extra work + * though, to make sure that we don't perform an operation on a deleted key. + */ +typedef struct _epgno { + pgno_t pgno; /* the page number */ + indx_t index; /* the index on the page */ +} EPGNO; + +typedef struct _epg { + PAGE *page; /* the (pinned) page */ + indx_t index; /* the index on the page */ +} EPG; + +/* + * The metadata of the tree. The m_nrecs field is used only by the RECNO code. + * This is because the btree doesn't really need it and it requires that every + * put or delete call modify the metadata. + */ +typedef struct _btmeta { + u_int32_t m_magic; /* magic number */ + u_int32_t m_version; /* version */ + u_int32_t m_psize; /* page size */ + u_int32_t m_free; /* page number of first free page */ + u_int32_t m_nrecs; /* R: number of records */ +#define SAVEMETA (B_NODUPS | R_RECNO) + u_int32_t m_flags; /* bt_flags & SAVEMETA */ + u_int32_t m_unused; /* unused */ +} BTMETA; + +/* The in-memory btree/recno data structure. */ +typedef struct _btree { + MPOOL *bt_mp; /* memory pool cookie */ + + DB *bt_dbp; /* pointer to enclosing DB */ + + EPG bt_cur; /* current (pinned) page */ + PAGE *bt_pinned; /* page pinned across calls */ + + EPGNO bt_bcursor; /* B: btree cursor */ + recno_t bt_rcursor; /* R: recno cursor (1-based) */ + +#define BT_POP(t) (t->bt_sp ? t->bt_stack + --t->bt_sp : NULL) +#define BT_CLR(t) (t->bt_sp = 0) + EPGNO *bt_stack; /* stack of parent pages */ + u_int bt_sp; /* current stack pointer */ + u_int bt_maxstack; /* largest stack */ + + char *bt_kbuf; /* key buffer */ + size_t bt_kbufsz; /* key buffer size */ + char *bt_dbuf; /* data buffer */ + size_t bt_dbufsz; /* data buffer size */ + + int bt_fd; /* tree file descriptor */ + + pgno_t bt_free; /* next free page */ + u_int32_t bt_psize; /* page size */ + indx_t bt_ovflsize; /* cut-off for key/data overflow */ + int bt_lorder; /* byte order */ + /* sorted order */ + enum { NOT, BACK, FORWARD } bt_order; + EPGNO bt_last; /* last insert */ + + /* B: key comparison function */ + int (*bt_cmp) __P((const DBT *, const DBT *)); + /* B: prefix comparison function */ + size_t (*bt_pfx) __P((const DBT *, const DBT *)); + /* R: recno input function */ + int (*bt_irec) __P((struct _btree *, recno_t)); + + FILE *bt_rfp; /* R: record FILE pointer */ + int bt_rfd; /* R: record file descriptor */ + + caddr_t bt_cmap; /* R: current point in mapped space */ + caddr_t bt_smap; /* R: start of mapped space */ + caddr_t bt_emap; /* R: end of mapped space */ + size_t bt_msize; /* R: size of mapped region. */ + + recno_t bt_nrecs; /* R: number of records */ + size_t bt_reclen; /* R: fixed record length */ + u_char bt_bval; /* R: delimiting byte/pad character */ + +/* + * NB: + * B_NODUPS and R_RECNO are stored on disk, and may not be changed. + */ +#define B_DELCRSR 0x00001 /* cursor has been deleted */ +#define B_INMEM 0x00002 /* in-memory tree */ +#define B_METADIRTY 0x00004 /* need to write metadata */ +#define B_MODIFIED 0x00008 /* tree modified */ +#define B_NEEDSWAP 0x00010 /* if byte order requires swapping */ +#define B_NODUPS 0x00020 /* no duplicate keys permitted */ +#define B_RDONLY 0x00040 /* read-only tree */ +#define R_RECNO 0x00080 /* record oriented tree */ +#define B_SEQINIT 0x00100 /* sequential scan initialized */ + +#define R_CLOSEFP 0x00200 /* opened a file pointer */ +#define R_EOF 0x00400 /* end of input file reached. */ +#define R_FIXLEN 0x00800 /* fixed length records */ +#define R_MEMMAPPED 0x01000 /* memory mapped file. */ +#define R_INMEM 0x02000 /* in-memory file */ +#define R_MODIFIED 0x04000 /* modified file */ +#define R_RDONLY 0x08000 /* read-only file */ + +#define B_DB_LOCK 0x10000 /* DB_LOCK specified. */ +#define B_DB_SHMEM 0x20000 /* DB_SHMEM specified. */ +#define B_DB_TXN 0x40000 /* DB_TXN specified. */ + + u_int32_t bt_flags; /* btree state */ +} BTREE; + +#define SET(t, f) ((t)->bt_flags |= (f)) +#define CLR(t, f) ((t)->bt_flags &= ~(f)) +#define ISSET(t, f) ((t)->bt_flags & (f)) + +#include "bt_extern.h" diff --git a/db/db/Makefile.inc b/db/db/Makefile.inc new file mode 100644 index 0000000..67c4fef --- /dev/null +++ b/db/db/Makefile.inc @@ -0,0 +1,6 @@ +# from @(#)Makefile.inc 8.1 (Berkeley) 6/4/93 +# $FreeBSD: src/lib/libc/db/db/Makefile.inc,v 1.3 1999/08/27 23:58:17 peter Exp $ + +.PATH: ${.CURDIR}/db/db + +SRCS+= db.c diff --git a/db/db/db.c b/db/db/db.c new file mode 100644 index 0000000..086e14d --- /dev/null +++ b/db/db/db.c @@ -0,0 +1,117 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * 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. + */ + + +#include + +#include +#include +#include +#include + +#include + +DB * +dbopen(fname, flags, mode, type, openinfo) + const char *fname; + int flags, mode; + DBTYPE type; + const void *openinfo; +{ + +#define DB_FLAGS (DB_LOCK | DB_SHMEM | DB_TXN) +#define USE_OPEN_FLAGS \ + (O_CREAT | O_EXCL | O_EXLOCK | O_NONBLOCK | O_RDONLY | \ + O_RDWR | O_SHLOCK | O_TRUNC) + + if ((flags & ~(USE_OPEN_FLAGS | DB_FLAGS)) == 0) + switch (type) { + case DB_BTREE: + return (__bt_open(fname, flags & USE_OPEN_FLAGS, + mode, openinfo, flags & DB_FLAGS)); + case DB_HASH: + return (__hash_open(fname, flags & USE_OPEN_FLAGS, + mode, openinfo, flags & DB_FLAGS)); + case DB_RECNO: + return (__rec_open(fname, flags & USE_OPEN_FLAGS, + mode, openinfo, flags & DB_FLAGS)); + } + errno = EINVAL; + return (NULL); +} + +static int +__dberr() +{ + return (RET_ERROR); +} + +/* + * __DBPANIC -- Stop. + * + * Parameters: + * dbp: pointer to the DB structure. + */ +void +__dbpanic(dbp) + DB *dbp; +{ + /* The only thing that can succeed is a close. */ + dbp->del = (int (*)())__dberr; + dbp->fd = (int (*)())__dberr; + dbp->get = (int (*)())__dberr; + dbp->put = (int (*)())__dberr; + dbp->seq = (int (*)())__dberr; + dbp->sync = (int (*)())__dberr; +} diff --git a/db/hash/Makefile.inc b/db/hash/Makefile.inc new file mode 100644 index 0000000..b5874e8 --- /dev/null +++ b/db/hash/Makefile.inc @@ -0,0 +1,7 @@ +# from @(#)Makefile.inc 8.1 (Berkeley) 6/4/93 +# $FreeBSD: src/lib/libc/db/hash/Makefile.inc,v 1.4 2001/05/15 07:08:17 ru Exp $ + +.PATH: ${.CURDIR}/db/hash + +SRCS+= hash.c hash_bigkey.c hash_buf.c hash_func.c hash_log2.c \ + hash_page.c ndbm.c hsearch.c diff --git a/db/hash/extern.h b/db/hash/extern.h new file mode 100644 index 0000000..cf678d2 --- /dev/null +++ b/db/hash/extern.h @@ -0,0 +1,84 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * 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. + */ + +BUFHEAD *__add_ovflpage __P((HTAB *, BUFHEAD *)); +int __addel __P((HTAB *, BUFHEAD *, const DBT *, const DBT *)); +int __big_delete __P((HTAB *, BUFHEAD *)); +int __big_insert __P((HTAB *, BUFHEAD *, const DBT *, const DBT *)); +int __big_keydata __P((HTAB *, BUFHEAD *, DBT *, DBT *, int)); +int __big_return __P((HTAB *, BUFHEAD *, int, DBT *, int)); +int __big_split __P((HTAB *, BUFHEAD *, BUFHEAD *, BUFHEAD *, + int, u_int, SPLIT_RETURN *)); +int __buf_free __P((HTAB *, int, int)); +void __buf_init __P((HTAB *, int)); +u_int __call_hash __P((HTAB *, char *, int)); +int __delpair __P((HTAB *, BUFHEAD *, int)); +int __expand_table __P((HTAB *)); +int __find_bigpair __P((HTAB *, BUFHEAD *, int, char *, int)); +u_short __find_last_page __P((HTAB *, BUFHEAD **)); +void __free_ovflpage __P((HTAB *, BUFHEAD *)); +BUFHEAD *__get_buf __P((HTAB *, u_int, BUFHEAD *, int)); +int __get_page __P((HTAB *, char *, u_int, int, int, int)); +int __init_bitmap __P((HTAB *, int, int, int)); +u_int __log2 __P((u_int)); +int __put_page __P((HTAB *, char *, u_int, int, int)); +void __reclaim_buf __P((HTAB *, BUFHEAD *)); +int __split_page __P((HTAB *, u_int, u_int)); + +/* Default hash routine. */ +extern u_int32_t (*__default_hash) __P((const void *, size_t)); + +#ifdef HASH_STATISTICS +extern long hash_accesses, hash_collisions, hash_expansions, hash_overflows; +#endif diff --git a/db/hash/hash.c b/db/hash/hash.c new file mode 100644 index 0000000..40b4761 --- /dev/null +++ b/db/hash/hash.c @@ -0,0 +1,1012 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Margo Seltzer. + * + * 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 +#include + +#include +#include +#include +#include +#include +#include +#ifdef DEBUG +#include +#endif + +#include +#include "hash.h" +#include "page.h" +#include "extern.h" + +static int alloc_segs __P((HTAB *, int)); +static int flush_meta __P((HTAB *)); +static int hash_access __P((HTAB *, ACTION, DBT *, DBT *)); +static int hash_close __P((DB *)); +static int hash_delete __P((const DB *, const DBT *, u_int)); +static int hash_fd __P((const DB *)); +static int hash_get __P((const DB *, const DBT *, DBT *, u_int)); +static int hash_put __P((const DB *, DBT *, const DBT *, u_int)); +static void *hash_realloc __P((SEGMENT **, int, int)); +static int hash_seq __P((const DB *, DBT *, DBT *, u_int)); +static int hash_sync __P((const DB *, u_int)); +static int hdestroy __P((HTAB *)); +static HTAB *init_hash __P((HTAB *, const char *, HASHINFO *)); +static int init_htab __P((HTAB *, int)); +#if BYTE_ORDER == LITTLE_ENDIAN +static void swap_header __P((HTAB *)); +static void swap_header_copy __P((HASHHDR *, HASHHDR *)); +#endif + +/* Fast arithmetic, relying on powers of 2, */ +#define MOD(x, y) ((x) & ((y) - 1)) + +#define RETURN_ERROR(ERR, LOC) { save_errno = ERR; goto LOC; } + +/* Return values */ +#define SUCCESS (0) +#define ERROR (-1) +#define ABNORMAL (1) + +#ifdef HASH_STATISTICS +long hash_accesses, hash_collisions, hash_expansions, hash_overflows; +#endif + +/************************** INTERFACE ROUTINES ***************************/ +/* OPEN/CLOSE */ + +extern DB * +__hash_open(file, flags, mode, info, dflags) + const char *file; + int flags, mode, dflags; + const HASHINFO *info; /* Special directives for create */ +{ + HTAB *hashp; + struct stat statbuf; + DB *dbp; + int bpages, hdrsize, new_table, nsegs, save_errno; + + if ((flags & O_ACCMODE) == O_WRONLY) { + errno = EINVAL; + return (NULL); + } + + if (!(hashp = (HTAB *)calloc(1, sizeof(HTAB)))) + return (NULL); + hashp->fp = -1; + + /* + * Even if user wants write only, we need to be able to read + * the actual file, so we need to open it read/write. But, the + * field in the hashp structure needs to be accurate so that + * we can check accesses. + */ + hashp->flags = flags; + + new_table = 0; + if (!file || (flags & O_TRUNC) || + (stat(file, &statbuf) && (errno == ENOENT))) { + if (errno == ENOENT) + errno = 0; /* Just in case someone looks at errno */ + new_table = 1; + } + if (file) { + if ((hashp->fp = open(file, flags, mode)) == -1) + RETURN_ERROR(errno, error0); + (void)fcntl(hashp->fp, F_SETFD, 1); + } + if (new_table) { + if (!(hashp = init_hash(hashp, file, (HASHINFO *)info))) + RETURN_ERROR(errno, error1); + } else { + /* Table already exists */ + if (info && info->hash) + hashp->hash = info->hash; + else + hashp->hash = __default_hash; + + hdrsize = read(hashp->fp, &hashp->hdr, sizeof(HASHHDR)); +#if BYTE_ORDER == LITTLE_ENDIAN + swap_header(hashp); +#endif + if (hdrsize == -1) + RETURN_ERROR(errno, error1); + if (hdrsize != sizeof(HASHHDR)) + RETURN_ERROR(EFTYPE, error1); + /* Verify file type, versions and hash function */ + if (hashp->MAGIC != HASHMAGIC) + RETURN_ERROR(EFTYPE, error1); +#define OLDHASHVERSION 1 + if (hashp->VERSION != HASHVERSION && + hashp->VERSION != OLDHASHVERSION) + RETURN_ERROR(EFTYPE, error1); + if (hashp->hash(CHARKEY, sizeof(CHARKEY)) != hashp->H_CHARKEY) + RETURN_ERROR(EFTYPE, error1); + /* + * Figure out how many segments we need. Max_Bucket is the + * maximum bucket number, so the number of buckets is + * max_bucket + 1. + */ + nsegs = (hashp->MAX_BUCKET + 1 + hashp->SGSIZE - 1) / + hashp->SGSIZE; + hashp->nsegs = 0; + if (alloc_segs(hashp, nsegs)) + /* + * If alloc_segs fails, table will have been destroyed + * and errno will have been set. + */ + return (NULL); + /* Read in bitmaps */ + bpages = (hashp->SPARES[hashp->OVFL_POINT] + + (hashp->BSIZE << BYTE_SHIFT) - 1) >> + (hashp->BSHIFT + BYTE_SHIFT); + + hashp->nmaps = bpages; + (void)memset(&hashp->mapp[0], 0, bpages * sizeof(u_long *)); + } + + /* Initialize Buffer Manager */ + if (info && info->cachesize) + __buf_init(hashp, info->cachesize); + else + __buf_init(hashp, DEF_BUFSIZE); + + hashp->new_file = new_table; + hashp->save_file = file && (hashp->flags & O_RDWR); + hashp->cbucket = -1; + if (!(dbp = (DB *)malloc(sizeof(DB)))) { + save_errno = errno; + hdestroy(hashp); + errno = save_errno; + return (NULL); + } + dbp->internal = hashp; + dbp->close = hash_close; + dbp->del = hash_delete; + dbp->fd = hash_fd; + dbp->get = hash_get; + dbp->put = hash_put; + dbp->seq = hash_seq; + dbp->sync = hash_sync; + dbp->type = DB_HASH; + +#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", + "init_htab:", + "TABLE POINTER ", hashp, + "BUCKET SIZE ", hashp->BSIZE, + "BUCKET SHIFT ", hashp->BSHIFT, + "DIRECTORY SIZE ", hashp->DSIZE, + "SEGMENT SIZE ", hashp->SGSIZE, + "SEGMENT SHIFT ", hashp->SSHIFT, + "FILL FACTOR ", hashp->FFACTOR, + "MAX BUCKET ", hashp->MAX_BUCKET, + "OVFL POINT ", hashp->OVFL_POINT, + "LAST FREED ", hashp->LAST_FREED, + "HIGH MASK ", hashp->HIGH_MASK, + "LOW MASK ", hashp->LOW_MASK, + "NSEGS ", hashp->nsegs, + "NKEYS ", hashp->NKEYS); +#endif +#ifdef HASH_STATISTICS + hash_overflows = hash_accesses = hash_collisions = hash_expansions = 0; +#endif + return (dbp); + +error1: + if (hashp != NULL) + (void)close(hashp->fp); + +error0: + free(hashp); + errno = save_errno; + return (NULL); +} + +static int +hash_close(dbp) + DB *dbp; +{ + HTAB *hashp; + int retval; + + if (!dbp) + return (ERROR); + + hashp = (HTAB *)dbp->internal; + retval = hdestroy(hashp); + free(dbp); + return (retval); +} + +static int +hash_fd(dbp) + const DB *dbp; +{ + HTAB *hashp; + + if (!dbp) + return (ERROR); + + hashp = (HTAB *)dbp->internal; + if (hashp->fp == -1) { + errno = ENOENT; + return (-1); + } + return (hashp->fp); +} + +/************************** LOCAL CREATION ROUTINES **********************/ +static HTAB * +init_hash(hashp, file, info) + HTAB *hashp; + const char *file; + HASHINFO *info; +{ + struct stat statbuf; + int nelem; + + nelem = 1; + hashp->NKEYS = 0; + hashp->LORDER = BYTE_ORDER; + hashp->BSIZE = DEF_BUCKET_SIZE; + hashp->BSHIFT = DEF_BUCKET_SHIFT; + hashp->SGSIZE = DEF_SEGSIZE; + hashp->SSHIFT = DEF_SEGSIZE_SHIFT; + hashp->DSIZE = DEF_DIRSIZE; + hashp->FFACTOR = DEF_FFACTOR; + hashp->hash = __default_hash; + memset(hashp->SPARES, 0, sizeof(hashp->SPARES)); + memset(hashp->BITMAPS, 0, sizeof (hashp->BITMAPS)); + + /* Fix bucket size to be optimal for file system */ + if (file != NULL) { + if (stat(file, &statbuf)) + return (NULL); + hashp->BSIZE = statbuf.st_blksize; + hashp->BSHIFT = __log2(hashp->BSIZE); + } + + if (info) { + if (info->bsize) { + /* Round pagesize up to power of 2 */ + hashp->BSHIFT = __log2(info->bsize); + hashp->BSIZE = 1 << hashp->BSHIFT; + if (hashp->BSIZE > MAX_BSIZE) { + errno = EINVAL; + return (NULL); + } + } + if (info->ffactor) + hashp->FFACTOR = info->ffactor; + if (info->hash) + hashp->hash = info->hash; + if (info->nelem) + nelem = info->nelem; + if (info->lorder) { + if (info->lorder != BIG_ENDIAN && + info->lorder != LITTLE_ENDIAN) { + errno = EINVAL; + return (NULL); + } + hashp->LORDER = info->lorder; + } + } + /* init_htab should destroy the table and set errno if it fails */ + if (init_htab(hashp, nelem)) + return (NULL); + else + return (hashp); +} +/* + * This calls alloc_segs which may run out of memory. Alloc_segs will destroy + * the table and set errno, so we just pass the error information along. + * + * Returns 0 on No Error + */ +static int +init_htab(hashp, nelem) + HTAB *hashp; + int nelem; +{ + register int nbuckets, nsegs; + int l2; + + /* + * Divide number of elements by the fill factor and determine a + * desired number of buckets. Allocate space for the next greater + * power of two number of buckets. + */ + nelem = (nelem - 1) / hashp->FFACTOR + 1; + + l2 = __log2(MAX(nelem, 2)); + nbuckets = 1 << l2; + + hashp->SPARES[l2] = l2 + 1; + hashp->SPARES[l2 + 1] = l2 + 1; + hashp->OVFL_POINT = l2; + hashp->LAST_FREED = 2; + + /* First bitmap page is at: splitpoint l2 page offset 1 */ + if (__init_bitmap(hashp, OADDR_OF(l2, 1), l2 + 1, 0)) + return (-1); + + hashp->MAX_BUCKET = hashp->LOW_MASK = nbuckets - 1; + hashp->HIGH_MASK = (nbuckets << 1) - 1; + hashp->HDRPAGES = ((MAX(sizeof(HASHHDR), MINHDRSIZE) - 1) >> + hashp->BSHIFT) + 1; + + nsegs = (nbuckets - 1) / hashp->SGSIZE + 1; + nsegs = 1 << __log2(nsegs); + + if (nsegs > hashp->DSIZE) + hashp->DSIZE = nsegs; + return (alloc_segs(hashp, nsegs)); +} + +/********************** DESTROY/CLOSE ROUTINES ************************/ + +/* + * Flushes any changes to the file if necessary and destroys the hashp + * structure, freeing all allocated space. + */ +static int +hdestroy(hashp) + HTAB *hashp; +{ + int i, save_errno; + + save_errno = 0; + +#ifdef HASH_STATISTICS + (void)fprintf(stderr, "hdestroy: accesses %ld collisions %ld\n", + hash_accesses, hash_collisions); + (void)fprintf(stderr, "hdestroy: expansions %ld\n", + hash_expansions); + (void)fprintf(stderr, "hdestroy: overflows %ld\n", + hash_overflows); + (void)fprintf(stderr, "keys %ld maxp %d segmentcount %d\n", + hashp->NKEYS, hashp->MAX_BUCKET, hashp->nsegs); + + for (i = 0; i < NCACHED; i++) + (void)fprintf(stderr, + "spares[%d] = %d\n", i, hashp->SPARES[i]); +#endif + /* + * Call on buffer manager to free buffers, and if required, + * write them to disk. + */ + if (__buf_free(hashp, 1, hashp->save_file)) + save_errno = errno; + if (hashp->dir) { + free(*hashp->dir); /* Free initial segments */ + /* Free extra segments */ + while (hashp->exsegs--) + free(hashp->dir[--hashp->nsegs]); + free(hashp->dir); + } + if (flush_meta(hashp) && !save_errno) + save_errno = errno; + /* Free Bigmaps */ + for (i = 0; i < hashp->nmaps; i++) + if (hashp->mapp[i]) + free(hashp->mapp[i]); + + if (hashp->fp != -1) + (void)close(hashp->fp); + + free(hashp); + + if (save_errno) { + errno = save_errno; + return (ERROR); + } + return (SUCCESS); +} +/* + * Write modified pages to disk + * + * Returns: + * 0 == OK + * -1 ERROR + */ +static int +hash_sync(dbp, flags) + const DB *dbp; + u_int flags; +{ + HTAB *hashp; + + if (flags != 0) { + errno = EINVAL; + return (ERROR); + } + + if (!dbp) + return (ERROR); + + hashp = (HTAB *)dbp->internal; + if (!hashp->save_file) + return (0); + if (__buf_free(hashp, 0, 1) || flush_meta(hashp)) + return (ERROR); + hashp->new_file = 0; + return (0); +} + +/* + * Returns: + * 0 == OK + * -1 indicates that errno should be set + */ +static int +flush_meta(hashp) + HTAB *hashp; +{ + HASHHDR *whdrp; +#if BYTE_ORDER == LITTLE_ENDIAN + HASHHDR whdr; +#endif + int fp, i, wsize; + + if (!hashp->save_file) + return (0); + hashp->MAGIC = HASHMAGIC; + hashp->VERSION = HASHVERSION; + hashp->H_CHARKEY = hashp->hash(CHARKEY, sizeof(CHARKEY)); + + fp = hashp->fp; + whdrp = &hashp->hdr; +#if BYTE_ORDER == LITTLE_ENDIAN + whdrp = &whdr; + swap_header_copy(&hashp->hdr, whdrp); +#endif + if ((lseek(fp, (off_t)0, SEEK_SET) == -1) || + ((wsize = write(fp, whdrp, sizeof(HASHHDR))) == -1)) + return (-1); + else + if (wsize != sizeof(HASHHDR)) { + errno = EFTYPE; + hashp->error = errno; + return (-1); + } + for (i = 0; i < NCACHED; i++) + if (hashp->mapp[i]) + if (__put_page(hashp, (char *)hashp->mapp[i], + hashp->BITMAPS[i], 0, 1)) + return (-1); + return (0); +} + +/*******************************SEARCH ROUTINES *****************************/ +/* + * All the access routines return + * + * Returns: + * 0 on SUCCESS + * 1 to indicate an external ERROR (i.e. key not found, etc) + * -1 to indicate an internal ERROR (i.e. out of memory, etc) + */ +static int +hash_get(dbp, key, data, flag) + const DB *dbp; + const DBT *key; + DBT *data; + u_int flag; +{ + HTAB *hashp; + + hashp = (HTAB *)dbp->internal; + if (flag) { + hashp->error = errno = EINVAL; + return (ERROR); + } + return (hash_access(hashp, HASH_GET, (DBT *)key, data)); +} + +static int +hash_put(dbp, key, data, flag) + const DB *dbp; + DBT *key; + const DBT *data; + u_int flag; +{ + HTAB *hashp; + + hashp = (HTAB *)dbp->internal; + if (flag && flag != R_NOOVERWRITE) { + hashp->error = errno = EINVAL; + return (ERROR); + } + if ((hashp->flags & O_ACCMODE) == O_RDONLY) { + hashp->error = errno = EPERM; + return (ERROR); + } + return (hash_access(hashp, flag == R_NOOVERWRITE ? + HASH_PUTNEW : HASH_PUT, (DBT *)key, (DBT *)data)); +} + +static int +hash_delete(dbp, key, flag) + const DB *dbp; + const DBT *key; + u_int flag; /* Ignored */ +{ + HTAB *hashp; + + hashp = (HTAB *)dbp->internal; + if (flag && flag != R_CURSOR) { + hashp->error = errno = EINVAL; + return (ERROR); + } + if ((hashp->flags & O_ACCMODE) == O_RDONLY) { + hashp->error = errno = EPERM; + return (ERROR); + } + return (hash_access(hashp, HASH_DELETE, (DBT *)key, NULL)); +} + +/* + * Assume that hashp has been set in wrapper routine. + */ +static int +hash_access(hashp, action, key, val) + HTAB *hashp; + ACTION action; + DBT *key, *val; +{ + register BUFHEAD *rbufp; + BUFHEAD *bufp, *save_bufp; + register u_short *bp; + register int n, ndx, off, size; + register char *kp; + u_short pageno; + +#ifdef HASH_STATISTICS + hash_accesses++; +#endif + + off = hashp->BSIZE; + size = key->size; + kp = (char *)key->data; + rbufp = __get_buf(hashp, __call_hash(hashp, kp, size), NULL, 0); + if (!rbufp) + return (ERROR); + save_bufp = rbufp; + + /* Pin the bucket chain */ + rbufp->flags |= BUF_PIN; + for (bp = (u_short *)rbufp->page, n = *bp++, ndx = 1; ndx < n;) + if (bp[1] >= REAL_KEY) { + /* Real key/data pair */ + if (size == off - *bp && + memcmp(kp, rbufp->page + *bp, size) == 0) + goto found; + off = bp[1]; +#ifdef HASH_STATISTICS + hash_collisions++; +#endif + bp += 2; + ndx += 2; + } else if (bp[1] == OVFLPAGE) { + rbufp = __get_buf(hashp, *bp, rbufp, 0); + if (!rbufp) { + save_bufp->flags &= ~BUF_PIN; + return (ERROR); + } + /* FOR LOOP INIT */ + bp = (u_short *)rbufp->page; + n = *bp++; + ndx = 1; + off = hashp->BSIZE; + } else if (bp[1] < REAL_KEY) { + if ((ndx = + __find_bigpair(hashp, rbufp, ndx, kp, size)) > 0) + goto found; + if (ndx == -2) { + bufp = rbufp; + if (!(pageno = + __find_last_page(hashp, &bufp))) { + ndx = 0; + rbufp = bufp; + break; /* FOR */ + } + rbufp = __get_buf(hashp, pageno, bufp, 0); + if (!rbufp) { + save_bufp->flags &= ~BUF_PIN; + return (ERROR); + } + /* FOR LOOP INIT */ + bp = (u_short *)rbufp->page; + n = *bp++; + ndx = 1; + off = hashp->BSIZE; + } else { + save_bufp->flags &= ~BUF_PIN; + return (ERROR); + } + } + + /* Not found */ + switch (action) { + case HASH_PUT: + case HASH_PUTNEW: + if (__addel(hashp, rbufp, key, val)) { + save_bufp->flags &= ~BUF_PIN; + return (ERROR); + } else { + save_bufp->flags &= ~BUF_PIN; + return (SUCCESS); + } + case HASH_GET: + case HASH_DELETE: + default: + save_bufp->flags &= ~BUF_PIN; + return (ABNORMAL); + } + +found: + switch (action) { + case HASH_PUTNEW: + save_bufp->flags &= ~BUF_PIN; + return (ABNORMAL); + case HASH_GET: + bp = (u_short *)rbufp->page; + if (bp[ndx + 1] < REAL_KEY) { + if (__big_return(hashp, rbufp, ndx, val, 0)) + return (ERROR); + } else { + val->data = (u_char *)rbufp->page + (int)bp[ndx + 1]; + val->size = bp[ndx] - bp[ndx + 1]; + } + break; + case HASH_PUT: + if ((__delpair(hashp, rbufp, ndx)) || + (__addel(hashp, rbufp, key, val))) { + save_bufp->flags &= ~BUF_PIN; + return (ERROR); + } + break; + case HASH_DELETE: + if (__delpair(hashp, rbufp, ndx)) + return (ERROR); + break; + default: + abort(); + } + save_bufp->flags &= ~BUF_PIN; + return (SUCCESS); +} + +static int +hash_seq(dbp, key, data, flag) + const DB *dbp; + DBT *key, *data; + u_int flag; +{ + register u_int bucket; + register BUFHEAD *bufp; + HTAB *hashp; + u_short *bp, ndx; + + hashp = (HTAB *)dbp->internal; + if (flag && flag != R_FIRST && flag != R_NEXT) { + hashp->error = errno = EINVAL; + return (ERROR); + } +#ifdef HASH_STATISTICS + hash_accesses++; +#endif + if ((hashp->cbucket < 0) || (flag == R_FIRST)) { + hashp->cbucket = 0; + hashp->cndx = 1; + hashp->cpage = NULL; + } + + for (bp = NULL; !bp || !bp[0]; ) { + if (!(bufp = hashp->cpage)) { + for (bucket = hashp->cbucket; + bucket <= hashp->MAX_BUCKET; + bucket++, hashp->cndx = 1) { + bufp = __get_buf(hashp, bucket, NULL, 0); + if (!bufp) + return (ERROR); + hashp->cpage = bufp; + bp = (u_short *)bufp->page; + if (bp[0]) + break; + } + hashp->cbucket = bucket; + if (hashp->cbucket > hashp->MAX_BUCKET) { + hashp->cbucket = -1; + return (ABNORMAL); + } + } else + bp = (u_short *)hashp->cpage->page; + +#ifdef DEBUG + assert(bp); + assert(bufp); +#endif + while (bp[hashp->cndx + 1] == OVFLPAGE) { + bufp = hashp->cpage = + __get_buf(hashp, bp[hashp->cndx], bufp, 0); + if (!bufp) + return (ERROR); + bp = (u_short *)(bufp->page); + hashp->cndx = 1; + } + if (!bp[0]) { + hashp->cpage = NULL; + ++hashp->cbucket; + } + } + ndx = hashp->cndx; + if (bp[ndx + 1] < REAL_KEY) { + if (__big_keydata(hashp, bufp, key, data, 1)) + return (ERROR); + } else { + key->data = (u_char *)hashp->cpage->page + bp[ndx]; + key->size = (ndx > 1 ? bp[ndx - 1] : hashp->BSIZE) - bp[ndx]; + data->data = (u_char *)hashp->cpage->page + bp[ndx + 1]; + data->size = bp[ndx] - bp[ndx + 1]; + ndx += 2; + if (ndx > bp[0]) { + hashp->cpage = NULL; + hashp->cbucket++; + hashp->cndx = 1; + } else + hashp->cndx = ndx; + } + return (SUCCESS); +} + +/********************************* UTILITIES ************************/ + +/* + * Returns: + * 0 ==> OK + * -1 ==> Error + */ +extern int +__expand_table(hashp) + HTAB *hashp; +{ + u_int old_bucket, new_bucket; + int dirsize, new_segnum, spare_ndx; + +#ifdef HASH_STATISTICS + hash_expansions++; +#endif + new_bucket = ++hashp->MAX_BUCKET; + old_bucket = (hashp->MAX_BUCKET & hashp->LOW_MASK); + + new_segnum = new_bucket >> hashp->SSHIFT; + + /* Check if we need a new segment */ + if (new_segnum >= hashp->nsegs) { + /* Check if we need to expand directory */ + if (new_segnum >= hashp->DSIZE) { + /* Reallocate directory */ + dirsize = hashp->DSIZE * sizeof(SEGMENT *); + if (!hash_realloc(&hashp->dir, dirsize, dirsize << 1)) + return (-1); + hashp->DSIZE = dirsize << 1; + } + if ((hashp->dir[new_segnum] = + (SEGMENT)calloc(hashp->SGSIZE, sizeof(SEGMENT))) == NULL) + return (-1); + hashp->exsegs++; + hashp->nsegs++; + } + /* + * If the split point is increasing (MAX_BUCKET's log base 2 + * * increases), we need to copy the current contents of the spare + * split bucket to the next bucket. + */ + spare_ndx = __log2(hashp->MAX_BUCKET + 1); + if (spare_ndx > hashp->OVFL_POINT) { + hashp->SPARES[spare_ndx] = hashp->SPARES[hashp->OVFL_POINT]; + hashp->OVFL_POINT = spare_ndx; + } + + if (new_bucket > hashp->HIGH_MASK) { + /* Starting a new doubling */ + hashp->LOW_MASK = hashp->HIGH_MASK; + hashp->HIGH_MASK = new_bucket | hashp->LOW_MASK; + } + /* Relocate records to the new bucket */ + return (__split_page(hashp, old_bucket, new_bucket)); +} + +/* + * If realloc guarantees that the pointer is not destroyed if the realloc + * fails, then this routine can go away. + */ +static void * +hash_realloc(p_ptr, oldsize, newsize) + SEGMENT **p_ptr; + int oldsize, newsize; +{ + register void *p; + + if (p = malloc(newsize)) { + memmove(p, *p_ptr, oldsize); + memset((char *)p + oldsize, 0, newsize - oldsize); + free(*p_ptr); + *p_ptr = p; + } + return (p); +} + +extern u_int +__call_hash(hashp, k, len) + HTAB *hashp; + char *k; + int len; +{ + int n, bucket; + + n = hashp->hash(k, len); + bucket = n & hashp->HIGH_MASK; + if (bucket > hashp->MAX_BUCKET) + bucket = bucket & hashp->LOW_MASK; + return (bucket); +} + +/* + * Allocate segment table. On error, destroy the table and set errno. + * + * Returns 0 on success + */ +static int +alloc_segs(hashp, nsegs) + HTAB *hashp; + int nsegs; +{ + register int i; + register SEGMENT store; + + int save_errno; + + if ((hashp->dir = + (SEGMENT *)calloc(hashp->DSIZE, sizeof(SEGMENT *))) == NULL) { + save_errno = errno; + (void)hdestroy(hashp); + errno = save_errno; + return (-1); + } + /* Allocate segments */ + if ((store = + (SEGMENT)calloc(nsegs << hashp->SSHIFT, sizeof(SEGMENT))) == NULL) { + save_errno = errno; + (void)hdestroy(hashp); + errno = save_errno; + return (-1); + } + for (i = 0; i < nsegs; i++, hashp->nsegs++) + hashp->dir[i] = &store[i << hashp->SSHIFT]; + return (0); +} + +#if BYTE_ORDER == LITTLE_ENDIAN +/* + * Hashp->hdr needs to be byteswapped. + */ +static void +swap_header_copy(srcp, destp) + HASHHDR *srcp, *destp; +{ + int i; + + P_32_COPY(srcp->magic, destp->magic); + P_32_COPY(srcp->version, destp->version); + P_32_COPY(srcp->lorder, destp->lorder); + P_32_COPY(srcp->bsize, destp->bsize); + P_32_COPY(srcp->bshift, destp->bshift); + P_32_COPY(srcp->dsize, destp->dsize); + P_32_COPY(srcp->ssize, destp->ssize); + P_32_COPY(srcp->sshift, destp->sshift); + P_32_COPY(srcp->ovfl_point, destp->ovfl_point); + P_32_COPY(srcp->last_freed, destp->last_freed); + P_32_COPY(srcp->max_bucket, destp->max_bucket); + P_32_COPY(srcp->high_mask, destp->high_mask); + P_32_COPY(srcp->low_mask, destp->low_mask); + P_32_COPY(srcp->ffactor, destp->ffactor); + P_32_COPY(srcp->nkeys, destp->nkeys); + P_32_COPY(srcp->hdrpages, destp->hdrpages); + P_32_COPY(srcp->h_charkey, destp->h_charkey); + for (i = 0; i < NCACHED; i++) { + P_32_COPY(srcp->spares[i], destp->spares[i]); + P_16_COPY(srcp->bitmaps[i], destp->bitmaps[i]); + } +} + +static void +swap_header(hashp) + HTAB *hashp; +{ + HASHHDR *hdrp; + int i; + + hdrp = &hashp->hdr; + + M_32_SWAP(hdrp->magic); + M_32_SWAP(hdrp->version); + M_32_SWAP(hdrp->lorder); + M_32_SWAP(hdrp->bsize); + M_32_SWAP(hdrp->bshift); + M_32_SWAP(hdrp->dsize); + M_32_SWAP(hdrp->ssize); + M_32_SWAP(hdrp->sshift); + M_32_SWAP(hdrp->ovfl_point); + M_32_SWAP(hdrp->last_freed); + M_32_SWAP(hdrp->max_bucket); + M_32_SWAP(hdrp->high_mask); + M_32_SWAP(hdrp->low_mask); + M_32_SWAP(hdrp->ffactor); + M_32_SWAP(hdrp->nkeys); + M_32_SWAP(hdrp->hdrpages); + M_32_SWAP(hdrp->h_charkey); + for (i = 0; i < NCACHED; i++) { + M_32_SWAP(hdrp->spares[i]); + M_16_SWAP(hdrp->bitmaps[i]); + } +} +#endif diff --git a/db/hash/hash.h b/db/hash/hash.h new file mode 100644 index 0000000..2140387 --- /dev/null +++ b/db/hash/hash.h @@ -0,0 +1,303 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Margo Seltzer. + * + * 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. + */ + +/* Operations */ +typedef enum { + HASH_GET, HASH_PUT, HASH_PUTNEW, HASH_DELETE, HASH_FIRST, HASH_NEXT +} ACTION; + +/* Buffer Management structures */ +typedef struct _bufhead BUFHEAD; + +struct _bufhead { + BUFHEAD *prev; /* LRU links */ + BUFHEAD *next; /* LRU links */ + BUFHEAD *ovfl; /* Overflow page buffer header */ + u_int addr; /* Address of this page */ + char *page; /* Actual page data */ + char flags; +#define BUF_MOD 0x0001 +#define BUF_DISK 0x0002 +#define BUF_BUCKET 0x0004 +#define BUF_PIN 0x0008 +}; + +#define IS_BUCKET(X) ((X) & BUF_BUCKET) + +typedef BUFHEAD **SEGMENT; + +/* Hash Table Information */ +typedef struct hashhdr { /* Disk resident portion */ + int magic; /* Magic NO for hash tables */ + int version; /* Version ID */ + long lorder; /* Byte Order */ + int bsize; /* Bucket/Page Size */ + int bshift; /* Bucket shift */ + int dsize; /* Directory Size */ + int ssize; /* Segment Size */ + int sshift; /* Segment shift */ + int ovfl_point; /* Where overflow pages are being allocated */ + int last_freed; /* Last overflow page freed */ + int max_bucket; /* ID of Maximum bucket in use */ + int high_mask; /* Mask to modulo into entire table */ + int low_mask; /* Mask to modulo into lower half of table */ + int ffactor; /* Fill factor */ + int nkeys; /* Number of keys in hash table */ + int hdrpages; /* Size of table header */ + int h_charkey; /* value of hash(CHARKEY) */ +#define NCACHED 32 /* number of bit maps and spare points */ + int spares[NCACHED];/* spare pages for overflow */ + u_short bitmaps[NCACHED]; /* address of overflow page bitmaps */ +} HASHHDR; + +typedef struct htab { /* Memory resident data structure */ + HASHHDR hdr; /* Header */ + int nsegs; /* Number of allocated segments */ + int exsegs; /* Number of extra allocated segments */ + u_int32_t /* Hash function */ + (*hash)__P((const void *, size_t)); + int flags; /* Flag values */ + int fp; /* File pointer */ + char *tmp_buf; /* Temporary Buffer for BIG data */ + char *tmp_key; /* Temporary Buffer for BIG keys */ + BUFHEAD *cpage; /* Current page */ + int cbucket; /* Current bucket */ + int cndx; /* Index of next item on cpage */ + int error; /* Error Number -- for DBM compatability */ + int new_file; /* Indicates if fd is backing store or no */ + int save_file; /* Indicates whether we need to flush file at + * exit */ + u_long *mapp[NCACHED]; /* Pointers to page maps */ + int nmaps; /* Initial number of bitmaps */ + int nbufs; /* Number of buffers left to allocate */ + BUFHEAD bufhead; /* Header of buffer lru list */ + SEGMENT *dir; /* Hash Bucket directory */ +} HTAB; + +/* + * Constants + */ +#define MAX_BSIZE 65536 /* 2^16 */ +#define MIN_BUFFERS 6 +#define MINHDRSIZE 512 +#define DEF_BUFSIZE 65536 /* 64 K */ +#define DEF_BUCKET_SIZE 4096 +#define DEF_BUCKET_SHIFT 12 /* log2(BUCKET) */ +#define DEF_SEGSIZE 256 +#define DEF_SEGSIZE_SHIFT 8 /* log2(SEGSIZE) */ +#define DEF_DIRSIZE 256 +#define DEF_FFACTOR 65536 +#define MIN_FFACTOR 4 +#define SPLTMAX 8 +#define CHARKEY "%$sniglet^&" +#define NUMKEY 1038583 +#define BYTE_SHIFT 3 +#define INT_TO_BYTE 2 +#define INT_BYTE_SHIFT 5 +#define ALL_SET ((u_int)0xFFFFFFFF) +#define ALL_CLEAR 0 + +#define PTROF(X) ((BUFHEAD *)((u_int)(X)&~0x3)) +#define ISMOD(X) ((u_int)(X)&0x1) +#define DOMOD(X) ((X) = (char *)((u_int)(X)|0x1)) +#define ISDISK(X) ((u_int)(X)&0x2) +#define DODISK(X) ((X) = (char *)((u_int)(X)|0x2)) + +#define BITS_PER_MAP 32 + +/* Given the address of the beginning of a big map, clear/set the nth bit */ +#define CLRBIT(A, N) ((A)[(N)/BITS_PER_MAP] &= ~(1<<((N)%BITS_PER_MAP))) +#define SETBIT(A, N) ((A)[(N)/BITS_PER_MAP] |= (1<<((N)%BITS_PER_MAP))) +#define ISSET(A, N) ((A)[(N)/BITS_PER_MAP] & (1<<((N)%BITS_PER_MAP))) + +/* Overflow management */ +/* + * Overflow page numbers are allocated per split point. At each doubling of + * the table, we can allocate extra pages. So, an overflow page number has + * the top 5 bits indicate which split point and the lower 11 bits indicate + * which page at that split point is indicated (pages within split points are + * numberered starting with 1). + */ + +#define SPLITSHIFT 11 +#define SPLITMASK 0x7FF +#define SPLITNUM(N) (((u_int)(N)) >> SPLITSHIFT) +#define OPAGENUM(N) ((N) & SPLITMASK) +#define OADDR_OF(S,O) ((u_int)((u_int)(S) << SPLITSHIFT) + (O)) + +#define BUCKET_TO_PAGE(B) \ + (B) + hashp->HDRPAGES + ((B) ? hashp->SPARES[__log2((B)+1)-1] : 0) +#define OADDR_TO_PAGE(B) \ + BUCKET_TO_PAGE ( (1 << SPLITNUM((B))) -1 ) + OPAGENUM((B)); + +/* + * page.h contains a detailed description of the page format. + * + * Normally, keys and data are accessed from offset tables in the top of + * each page which point to the beginning of the key and data. There are + * four flag values which may be stored in these offset tables which indicate + * the following: + * + * + * OVFLPAGE Rather than a key data pair, this pair contains + * the address of an overflow page. The format of + * the pair is: + * OVERFLOW_PAGE_NUMBER OVFLPAGE + * + * PARTIAL_KEY This must be the first key/data pair on a page + * and implies that page contains only a partial key. + * That is, the key is too big to fit on a single page + * so it starts on this page and continues on the next. + * The format of the page is: + * KEY_OFF PARTIAL_KEY OVFL_PAGENO OVFLPAGE + * + * KEY_OFF -- offset of the beginning of the key + * PARTIAL_KEY -- 1 + * OVFL_PAGENO - page number of the next overflow page + * OVFLPAGE -- 0 + * + * FULL_KEY This must be the first key/data pair on the page. It + * is used in two cases. + * + * Case 1: + * There is a complete key on the page but no data + * (because it wouldn't fit). The next page contains + * the data. + * + * Page format it: + * KEY_OFF FULL_KEY OVFL_PAGENO OVFL_PAGE + * + * KEY_OFF -- offset of the beginning of the key + * FULL_KEY -- 2 + * OVFL_PAGENO - page number of the next overflow page + * OVFLPAGE -- 0 + * + * Case 2: + * This page contains no key, but part of a large + * data field, which is continued on the next page. + * + * Page format it: + * DATA_OFF FULL_KEY OVFL_PAGENO OVFL_PAGE + * + * KEY_OFF -- offset of the beginning of the data on + * this page + * FULL_KEY -- 2 + * OVFL_PAGENO - page number of the next overflow page + * OVFLPAGE -- 0 + * + * FULL_KEY_DATA + * This must be the first key/data pair on the page. + * There are two cases: + * + * Case 1: + * This page contains a key and the beginning of the + * data field, but the data field is continued on the + * next page. + * + * Page format is: + * KEY_OFF FULL_KEY_DATA OVFL_PAGENO DATA_OFF + * + * KEY_OFF -- offset of the beginning of the key + * FULL_KEY_DATA -- 3 + * OVFL_PAGENO - page number of the next overflow page + * DATA_OFF -- offset of the beginning of the data + * + * Case 2: + * This page contains the last page of a big data pair. + * There is no key, only the tail end of the data + * on this page. + * + * Page format is: + * DATA_OFF FULL_KEY_DATA + * + * DATA_OFF -- offset of the beginning of the data on + * this page + * FULL_KEY_DATA -- 3 + * OVFL_PAGENO - page number of the next overflow page + * OVFLPAGE -- 0 + * + * OVFL_PAGENO and OVFLPAGE are optional (they are + * not present if there is no next page). + */ + +#define OVFLPAGE 0 +#define PARTIAL_KEY 1 +#define FULL_KEY 2 +#define FULL_KEY_DATA 3 +#define REAL_KEY 4 + +/* Short hands for accessing structure */ +#define BSIZE hdr.bsize +#define BSHIFT hdr.bshift +#define DSIZE hdr.dsize +#define SGSIZE hdr.ssize +#define SSHIFT hdr.sshift +#define LORDER hdr.lorder +#define OVFL_POINT hdr.ovfl_point +#define LAST_FREED hdr.last_freed +#define MAX_BUCKET hdr.max_bucket +#define FFACTOR hdr.ffactor +#define HIGH_MASK hdr.high_mask +#define LOW_MASK hdr.low_mask +#define NKEYS hdr.nkeys +#define HDRPAGES hdr.hdrpages +#define SPARES hdr.spares +#define BITMAPS hdr.bitmaps +#define VERSION hdr.version +#define MAGIC hdr.magic +#define NEXT_FREE hdr.next_free +#define H_CHARKEY hdr.h_charkey diff --git a/db/hash/hash_bigkey.c b/db/hash/hash_bigkey.c new file mode 100644 index 0000000..8c8f467 --- /dev/null +++ b/db/hash/hash_bigkey.c @@ -0,0 +1,685 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Margo Seltzer. + * + * 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. + */ + + +/* + * PACKAGE: hash + * DESCRIPTION: + * Big key/data handling for the hashing package. + * + * ROUTINES: + * External + * __big_keydata + * __big_split + * __big_insert + * __big_return + * __big_delete + * __find_last_page + * Internal + * collect_key + * collect_data + */ + +#include + +#include +#include +#include +#include + +#ifdef DEBUG +#include +#endif + +#include +#include "hash.h" +#include "page.h" +#include "extern.h" + +static int collect_key __P((HTAB *, BUFHEAD *, int, DBT *, int)); +static int collect_data __P((HTAB *, BUFHEAD *, int, int)); + +/* + * Big_insert + * + * You need to do an insert and the key/data pair is too big + * + * Returns: + * 0 ==> OK + *-1 ==> ERROR + */ +extern int +__big_insert(hashp, bufp, key, val) + HTAB *hashp; + BUFHEAD *bufp; + const DBT *key, *val; +{ + register u_short *p; + int key_size, n, val_size; + u_short space, move_bytes, off; + char *cp, *key_data, *val_data; + + cp = bufp->page; /* Character pointer of p. */ + p = (u_short *)cp; + + key_data = (char *)key->data; + key_size = key->size; + val_data = (char *)val->data; + val_size = val->size; + + /* First move the Key */ + for (space = FREESPACE(p) - BIGOVERHEAD; key_size; + space = FREESPACE(p) - BIGOVERHEAD) { + move_bytes = MIN(space, key_size); + off = OFFSET(p) - move_bytes; + memmove(cp + off, key_data, move_bytes); + key_size -= move_bytes; + key_data += move_bytes; + n = p[0]; + p[++n] = off; + p[0] = ++n; + FREESPACE(p) = off - PAGE_META(n); + OFFSET(p) = off; + p[n] = PARTIAL_KEY; + bufp = __add_ovflpage(hashp, bufp); + if (!bufp) + return (-1); + n = p[0]; + if (!key_size) + if (FREESPACE(p)) { + move_bytes = MIN(FREESPACE(p), val_size); + off = OFFSET(p) - move_bytes; + p[n] = off; + memmove(cp + off, val_data, move_bytes); + val_data += move_bytes; + val_size -= move_bytes; + p[n - 2] = FULL_KEY_DATA; + FREESPACE(p) = FREESPACE(p) - move_bytes; + OFFSET(p) = off; + } else + p[n - 2] = FULL_KEY; + p = (u_short *)bufp->page; + cp = bufp->page; + bufp->flags |= BUF_MOD; + } + + /* Now move the data */ + for (space = FREESPACE(p) - BIGOVERHEAD; val_size; + space = FREESPACE(p) - BIGOVERHEAD) { + move_bytes = MIN(space, val_size); + /* + * Here's the hack to make sure that if the data ends on the + * same page as the key ends, FREESPACE is at least one. + */ + if (space == val_size && val_size == val->size) + move_bytes--; + off = OFFSET(p) - move_bytes; + memmove(cp + off, val_data, move_bytes); + val_size -= move_bytes; + val_data += move_bytes; + n = p[0]; + p[++n] = off; + p[0] = ++n; + FREESPACE(p) = off - PAGE_META(n); + OFFSET(p) = off; + if (val_size) { + p[n] = FULL_KEY; + bufp = __add_ovflpage(hashp, bufp); + if (!bufp) + return (-1); + cp = bufp->page; + p = (u_short *)cp; + } else + p[n] = FULL_KEY_DATA; + bufp->flags |= BUF_MOD; + } + return (0); +} + +/* + * Called when bufp's page contains a partial key (index should be 1) + * + * All pages in the big key/data pair except bufp are freed. We cannot + * free bufp because the page pointing to it is lost and we can't get rid + * of its pointer. + * + * Returns: + * 0 => OK + *-1 => ERROR + */ +extern int +__big_delete(hashp, bufp) + HTAB *hashp; + BUFHEAD *bufp; +{ + register BUFHEAD *last_bfp, *rbufp; + u_short *bp, pageno; + int key_done, n; + + rbufp = bufp; + last_bfp = NULL; + bp = (u_short *)bufp->page; + pageno = 0; + key_done = 0; + + while (!key_done || (bp[2] != FULL_KEY_DATA)) { + if (bp[2] == FULL_KEY || bp[2] == FULL_KEY_DATA) + key_done = 1; + + /* + * If there is freespace left on a FULL_KEY_DATA page, then + * the data is short and fits entirely on this page, and this + * is the last page. + */ + if (bp[2] == FULL_KEY_DATA && FREESPACE(bp)) + break; + pageno = bp[bp[0] - 1]; + rbufp->flags |= BUF_MOD; + rbufp = __get_buf(hashp, pageno, rbufp, 0); + if (last_bfp) + __free_ovflpage(hashp, last_bfp); + last_bfp = rbufp; + if (!rbufp) + return (-1); /* Error. */ + bp = (u_short *)rbufp->page; + } + + /* + * If we get here then rbufp points to the last page of the big + * key/data pair. Bufp points to the first one -- it should now be + * empty pointing to the next page after this pair. Can't free it + * because we don't have the page pointing to it. + */ + + /* This is information from the last page of the pair. */ + n = bp[0]; + pageno = bp[n - 1]; + + /* Now, bp is the first page of the pair. */ + bp = (u_short *)bufp->page; + if (n > 2) { + /* There is an overflow page. */ + bp[1] = pageno; + bp[2] = OVFLPAGE; + bufp->ovfl = rbufp->ovfl; + } else + /* This is the last page. */ + bufp->ovfl = NULL; + n -= 2; + bp[0] = n; + FREESPACE(bp) = hashp->BSIZE - PAGE_META(n); + OFFSET(bp) = hashp->BSIZE - 1; + + bufp->flags |= BUF_MOD; + if (rbufp) + __free_ovflpage(hashp, rbufp); + if (last_bfp != rbufp) + __free_ovflpage(hashp, last_bfp); + + hashp->NKEYS--; + return (0); +} +/* + * Returns: + * 0 = key not found + * -1 = get next overflow page + * -2 means key not found and this is big key/data + * -3 error + */ +extern int +__find_bigpair(hashp, bufp, ndx, key, size) + HTAB *hashp; + BUFHEAD *bufp; + int ndx; + char *key; + int size; +{ + register u_short *bp; + register char *p; + int ksize; + u_short bytes; + char *kkey; + + bp = (u_short *)bufp->page; + p = bufp->page; + ksize = size; + kkey = key; + + for (bytes = hashp->BSIZE - bp[ndx]; + bytes <= size && bp[ndx + 1] == PARTIAL_KEY; + bytes = hashp->BSIZE - bp[ndx]) { + if (memcmp(p + bp[ndx], kkey, bytes)) + return (-2); + kkey += bytes; + ksize -= bytes; + bufp = __get_buf(hashp, bp[ndx + 2], bufp, 0); + if (!bufp) + return (-3); + p = bufp->page; + bp = (u_short *)p; + ndx = 1; + } + + if (bytes != ksize || memcmp(p + bp[ndx], kkey, bytes)) { +#ifdef HASH_STATISTICS + ++hash_collisions; +#endif + return (-2); + } else + return (ndx); +} + +/* + * Given the buffer pointer of the first overflow page of a big pair, + * find the end of the big pair + * + * This will set bpp to the buffer header of the last page of the big pair. + * It will return the pageno of the overflow page following the last page + * of the pair; 0 if there isn't any (i.e. big pair is the last key in the + * bucket) + */ +extern u_short +__find_last_page(hashp, bpp) + HTAB *hashp; + BUFHEAD **bpp; +{ + BUFHEAD *bufp; + u_short *bp, pageno; + int n; + + bufp = *bpp; + bp = (u_short *)bufp->page; + for (;;) { + n = bp[0]; + + /* + * This is the last page if: the tag is FULL_KEY_DATA and + * either only 2 entries OVFLPAGE marker is explicit there + * is freespace on the page. + */ + if (bp[2] == FULL_KEY_DATA && + ((n == 2) || (bp[n] == OVFLPAGE) || (FREESPACE(bp)))) + break; + + pageno = bp[n - 1]; + bufp = __get_buf(hashp, pageno, bufp, 0); + if (!bufp) + return (0); /* Need to indicate an error! */ + bp = (u_short *)bufp->page; + } + + *bpp = bufp; + if (bp[0] > 2) + return (bp[3]); + else + return (0); +} + +/* + * Return the data for the key/data pair that begins on this page at this + * index (index should always be 1). + */ +extern int +__big_return(hashp, bufp, ndx, val, set_current) + HTAB *hashp; + BUFHEAD *bufp; + int ndx; + DBT *val; + int set_current; +{ + BUFHEAD *save_p; + u_short *bp, len, off, save_addr; + char *tp; + + bp = (u_short *)bufp->page; + while (bp[ndx + 1] == PARTIAL_KEY) { + bufp = __get_buf(hashp, bp[bp[0] - 1], bufp, 0); + if (!bufp) + return (-1); + bp = (u_short *)bufp->page; + ndx = 1; + } + + if (bp[ndx + 1] == FULL_KEY) { + bufp = __get_buf(hashp, bp[bp[0] - 1], bufp, 0); + if (!bufp) + return (-1); + bp = (u_short *)bufp->page; + save_p = bufp; + save_addr = save_p->addr; + off = bp[1]; + len = 0; + } else + if (!FREESPACE(bp)) { + /* + * This is a hack. We can't distinguish between + * FULL_KEY_DATA that contains complete data or + * incomplete data, so we require that if the data + * is complete, there is at least 1 byte of free + * space left. + */ + off = bp[bp[0]]; + len = bp[1] - off; + save_p = bufp; + save_addr = bufp->addr; + bufp = __get_buf(hashp, bp[bp[0] - 1], bufp, 0); + if (!bufp) + return (-1); + bp = (u_short *)bufp->page; + } else { + /* The data is all on one page. */ + tp = (char *)bp; + off = bp[bp[0]]; + val->data = (u_char *)tp + off; + val->size = bp[1] - off; + if (set_current) { + if (bp[0] == 2) { /* No more buckets in + * chain */ + hashp->cpage = NULL; + hashp->cbucket++; + hashp->cndx = 1; + } else { + hashp->cpage = __get_buf(hashp, + bp[bp[0] - 1], bufp, 0); + if (!hashp->cpage) + return (-1); + hashp->cndx = 1; + if (!((u_short *) + hashp->cpage->page)[0]) { + hashp->cbucket++; + hashp->cpage = NULL; + } + } + } + return (0); + } + + val->size = collect_data(hashp, bufp, (int)len, set_current); + if (val->size == -1) + return (-1); + if (save_p->addr != save_addr) { + /* We are pretty short on buffers. */ + errno = EINVAL; /* OUT OF BUFFERS */ + return (-1); + } + memmove(hashp->tmp_buf, (save_p->page) + off, len); + val->data = (u_char *)hashp->tmp_buf; + return (0); +} +/* + * Count how big the total datasize is by recursing through the pages. Then + * allocate a buffer and copy the data as you recurse up. + */ +static int +collect_data(hashp, bufp, len, set) + HTAB *hashp; + BUFHEAD *bufp; + int len, set; +{ + register u_short *bp; + register char *p; + BUFHEAD *xbp; + u_short save_addr; + int mylen, totlen; + + p = bufp->page; + bp = (u_short *)p; + mylen = hashp->BSIZE - bp[1]; + save_addr = bufp->addr; + + if (bp[2] == FULL_KEY_DATA) { /* End of Data */ + totlen = len + mylen; + if (hashp->tmp_buf) + free(hashp->tmp_buf); + if ((hashp->tmp_buf = (char *)malloc(totlen)) == NULL) + return (-1); + if (set) { + hashp->cndx = 1; + if (bp[0] == 2) { /* No more buckets in chain */ + hashp->cpage = NULL; + hashp->cbucket++; + } else { + hashp->cpage = + __get_buf(hashp, bp[bp[0] - 1], bufp, 0); + if (!hashp->cpage) + return (-1); + else if (!((u_short *)hashp->cpage->page)[0]) { + hashp->cbucket++; + hashp->cpage = NULL; + } + } + } + } else { + xbp = __get_buf(hashp, bp[bp[0] - 1], bufp, 0); + if (!xbp || ((totlen = + collect_data(hashp, xbp, len + mylen, set)) < 1)) + return (-1); + } + if (bufp->addr != save_addr) { + errno = EINVAL; /* Out of buffers. */ + return (-1); + } + memmove(&hashp->tmp_buf[len], (bufp->page) + bp[1], mylen); + return (totlen); +} + +/* + * Fill in the key and data for this big pair. + */ +extern int +__big_keydata(hashp, bufp, key, val, set) + HTAB *hashp; + BUFHEAD *bufp; + DBT *key, *val; + int set; +{ + key->size = collect_key(hashp, bufp, 0, val, set); + if (key->size == -1) + return (-1); + key->data = (u_char *)hashp->tmp_key; + return (0); +} + +/* + * Count how big the total key size is by recursing through the pages. Then + * collect the data, allocate a buffer and copy the key as you recurse up. + */ +static int +collect_key(hashp, bufp, len, val, set) + HTAB *hashp; + BUFHEAD *bufp; + int len; + DBT *val; + int set; +{ + BUFHEAD *xbp; + char *p; + int mylen, totlen; + u_short *bp, save_addr; + + p = bufp->page; + bp = (u_short *)p; + mylen = hashp->BSIZE - bp[1]; + + save_addr = bufp->addr; + totlen = len + mylen; + if (bp[2] == FULL_KEY || bp[2] == FULL_KEY_DATA) { /* End of Key. */ + if (hashp->tmp_key != NULL) + free(hashp->tmp_key); + if ((hashp->tmp_key = (char *)malloc(totlen)) == NULL) + return (-1); + if (__big_return(hashp, bufp, 1, val, set)) + return (-1); + } else { + xbp = __get_buf(hashp, bp[bp[0] - 1], bufp, 0); + if (!xbp || ((totlen = + collect_key(hashp, xbp, totlen, val, set)) < 1)) + return (-1); + } + if (bufp->addr != save_addr) { + errno = EINVAL; /* MIS -- OUT OF BUFFERS */ + return (-1); + } + memmove(&hashp->tmp_key[len], (bufp->page) + bp[1], mylen); + return (totlen); +} + +/* + * Returns: + * 0 => OK + * -1 => error + */ +extern int +__big_split(hashp, op, np, big_keyp, addr, obucket, ret) + HTAB *hashp; + BUFHEAD *op; /* Pointer to where to put keys that go in old bucket */ + BUFHEAD *np; /* Pointer to new bucket page */ + /* Pointer to first page containing the big key/data */ + BUFHEAD *big_keyp; + int addr; /* Address of big_keyp */ + u_int obucket;/* Old Bucket */ + SPLIT_RETURN *ret; +{ + register BUFHEAD *tmpp; + register u_short *tp; + BUFHEAD *bp; + DBT key, val; + u_int change; + u_short free_space, n, off; + + bp = big_keyp; + + /* Now figure out where the big key/data goes */ + if (__big_keydata(hashp, big_keyp, &key, &val, 0)) + return (-1); + change = (__call_hash(hashp, key.data, key.size) != obucket); + + if (ret->next_addr = __find_last_page(hashp, &big_keyp)) { + if (!(ret->nextp = + __get_buf(hashp, ret->next_addr, big_keyp, 0))) + return (-1);; + } else + ret->nextp = NULL; + + /* Now make one of np/op point to the big key/data pair */ +#ifdef DEBUG + assert(np->ovfl == NULL); +#endif + if (change) + tmpp = np; + else + tmpp = op; + + tmpp->flags |= BUF_MOD; +#ifdef DEBUG1 + (void)fprintf(stderr, + "BIG_SPLIT: %d->ovfl was %d is now %d\n", tmpp->addr, + (tmpp->ovfl ? tmpp->ovfl->addr : 0), (bp ? bp->addr : 0)); +#endif + tmpp->ovfl = bp; /* one of op/np point to big_keyp */ + tp = (u_short *)tmpp->page; +#ifdef DEBUG + assert(FREESPACE(tp) >= OVFLSIZE); +#endif + n = tp[0]; + off = OFFSET(tp); + free_space = FREESPACE(tp); + tp[++n] = (u_short)addr; + tp[++n] = OVFLPAGE; + tp[0] = n; + OFFSET(tp) = off; + FREESPACE(tp) = free_space - OVFLSIZE; + + /* + * Finally, set the new and old return values. BIG_KEYP contains a + * pointer to the last page of the big key_data pair. Make sure that + * big_keyp has no following page (2 elements) or create an empty + * following page. + */ + + ret->newp = np; + ret->oldp = op; + + tp = (u_short *)big_keyp->page; + big_keyp->flags |= BUF_MOD; + if (tp[0] > 2) { + /* + * There may be either one or two offsets on this page. If + * there is one, then the overflow page is linked on normally + * and tp[4] is OVFLPAGE. If there are two, tp[4] contains + * the second offset and needs to get stuffed in after the + * next overflow page is added. + */ + n = tp[4]; + free_space = FREESPACE(tp); + off = OFFSET(tp); + tp[0] -= 2; + FREESPACE(tp) = free_space + OVFLSIZE; + OFFSET(tp) = off; + tmpp = __add_ovflpage(hashp, big_keyp); + if (!tmpp) + return (-1); + tp[4] = n; + } else + tmpp = big_keyp; + + if (change) + ret->newp = tmpp; + else + ret->oldp = tmpp; + return (0); +} diff --git a/db/hash/hash_buf.c b/db/hash/hash_buf.c new file mode 100644 index 0000000..9d89a8b --- /dev/null +++ b/db/hash/hash_buf.c @@ -0,0 +1,365 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Margo Seltzer. + * + * 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. + */ + + +/* + * PACKAGE: hash + * + * DESCRIPTION: + * Contains buffer management + * + * ROUTINES: + * External + * __buf_init + * __get_buf + * __buf_free + * __reclaim_buf + * Internal + * newbuf + */ + +#include + +#include +#include +#include +#ifdef DEBUG +#include +#endif + +#include +#include "hash.h" +#include "page.h" +#include "extern.h" + +static BUFHEAD *newbuf __P((HTAB *, u_int, BUFHEAD *)); + +/* Unlink B from its place in the lru */ +#define BUF_REMOVE(B) { \ + (B)->prev->next = (B)->next; \ + (B)->next->prev = (B)->prev; \ +} + +/* Insert B after P */ +#define BUF_INSERT(B, P) { \ + (B)->next = (P)->next; \ + (B)->prev = (P); \ + (P)->next = (B); \ + (B)->next->prev = (B); \ +} + +#define MRU hashp->bufhead.next +#define LRU hashp->bufhead.prev + +#define MRU_INSERT(B) BUF_INSERT((B), &hashp->bufhead) +#define LRU_INSERT(B) BUF_INSERT((B), LRU) + +/* + * We are looking for a buffer with address "addr". If prev_bp is NULL, then + * address is a bucket index. If prev_bp is not NULL, then it points to the + * page previous to an overflow page that we are trying to find. + * + * CAVEAT: The buffer header accessed via prev_bp's ovfl field may no longer + * be valid. Therefore, you must always verify that its address matches the + * address you are seeking. + */ +extern BUFHEAD * +__get_buf(hashp, addr, prev_bp, newpage) + HTAB *hashp; + u_int addr; + BUFHEAD *prev_bp; + int newpage; /* If prev_bp set, indicates a new overflow page. */ +{ + register BUFHEAD *bp; + register u_int is_disk_mask; + register int is_disk, segment_ndx; + SEGMENT segp; + + is_disk = 0; + is_disk_mask = 0; + if (prev_bp) { + bp = prev_bp->ovfl; + if (!bp || (bp->addr != addr)) + bp = NULL; + if (!newpage) + is_disk = BUF_DISK; + } else { + /* Grab buffer out of directory */ + segment_ndx = addr & (hashp->SGSIZE - 1); + + /* valid segment ensured by __call_hash() */ + segp = hashp->dir[addr >> hashp->SSHIFT]; +#ifdef DEBUG + assert(segp != NULL); +#endif + bp = PTROF(segp[segment_ndx]); + is_disk_mask = ISDISK(segp[segment_ndx]); + is_disk = is_disk_mask || !hashp->new_file; + } + + if (!bp) { + bp = newbuf(hashp, addr, prev_bp); + if (!bp || + __get_page(hashp, bp->page, addr, !prev_bp, is_disk, 0)) + return (NULL); + if (!prev_bp) + segp[segment_ndx] = + (BUFHEAD *)((u_int)bp | is_disk_mask); + } else { + BUF_REMOVE(bp); + MRU_INSERT(bp); + } + return (bp); +} + +/* + * We need a buffer for this page. Either allocate one, or evict a resident + * one (if we have as many buffers as we're allowed) and put this one in. + * + * If newbuf finds an error (returning NULL), it also sets errno. + */ +static BUFHEAD * +newbuf(hashp, addr, prev_bp) + HTAB *hashp; + u_int addr; + BUFHEAD *prev_bp; +{ + register BUFHEAD *bp; /* The buffer we're going to use */ + register BUFHEAD *xbp; /* Temp pointer */ + register BUFHEAD *next_xbp; + SEGMENT segp; + int segment_ndx; + u_short oaddr, *shortp; + + oaddr = 0; + bp = LRU; + /* + * If LRU buffer is pinned, the buffer pool is too small. We need to + * allocate more buffers. + */ + if (hashp->nbufs || (bp->flags & BUF_PIN)) { + /* Allocate a new one */ + if ((bp = (BUFHEAD *)malloc(sizeof(BUFHEAD))) == NULL) + return (NULL); + if ((bp->page = (char *)malloc(hashp->BSIZE)) == NULL) { + free(bp); + return (NULL); + } + if (hashp->nbufs) + hashp->nbufs--; + } else { + /* Kick someone out */ + BUF_REMOVE(bp); + /* + * If this is an overflow page with addr 0, it's already been + * flushed back in an overflow chain and initialized. + */ + if ((bp->addr != 0) || (bp->flags & BUF_BUCKET)) { + /* + * Set oaddr before __put_page so that you get it + * before bytes are swapped. + */ + shortp = (u_short *)bp->page; + if (shortp[0]) + oaddr = shortp[shortp[0] - 1]; + if ((bp->flags & BUF_MOD) && __put_page(hashp, bp->page, + bp->addr, (int)IS_BUCKET(bp->flags), 0)) + return (NULL); + /* + * Update the pointer to this page (i.e. invalidate it). + * + * If this is a new file (i.e. we created it at open + * time), make sure that we mark pages which have been + * written to disk so we retrieve them from disk later, + * rather than allocating new pages. + */ + if (IS_BUCKET(bp->flags)) { + segment_ndx = bp->addr & (hashp->SGSIZE - 1); + segp = hashp->dir[bp->addr >> hashp->SSHIFT]; +#ifdef DEBUG + assert(segp != NULL); +#endif + + if (hashp->new_file && + ((bp->flags & BUF_MOD) || + ISDISK(segp[segment_ndx]))) + segp[segment_ndx] = (BUFHEAD *)BUF_DISK; + else + segp[segment_ndx] = NULL; + } + /* + * Since overflow pages can only be access by means of + * their bucket, free overflow pages associated with + * this bucket. + */ + for (xbp = bp; xbp->ovfl;) { + next_xbp = xbp->ovfl; + xbp->ovfl = 0; + xbp = next_xbp; + + /* Check that ovfl pointer is up date. */ + if (IS_BUCKET(xbp->flags) || + (oaddr != xbp->addr)) + break; + + shortp = (u_short *)xbp->page; + if (shortp[0]) + /* set before __put_page */ + oaddr = shortp[shortp[0] - 1]; + if ((xbp->flags & BUF_MOD) && __put_page(hashp, + xbp->page, xbp->addr, 0, 0)) + return (NULL); + xbp->addr = 0; + xbp->flags = 0; + BUF_REMOVE(xbp); + LRU_INSERT(xbp); + } + } + } + + /* Now assign this buffer */ + bp->addr = addr; +#ifdef DEBUG1 + (void)fprintf(stderr, "NEWBUF1: %d->ovfl was %d is now %d\n", + bp->addr, (bp->ovfl ? bp->ovfl->addr : 0), 0); +#endif + bp->ovfl = NULL; + if (prev_bp) { + /* + * If prev_bp is set, this is an overflow page, hook it in to + * the buffer overflow links. + */ +#ifdef DEBUG1 + (void)fprintf(stderr, "NEWBUF2: %d->ovfl was %d is now %d\n", + prev_bp->addr, (prev_bp->ovfl ? bp->ovfl->addr : 0), + (bp ? bp->addr : 0)); +#endif + prev_bp->ovfl = bp; + bp->flags = 0; + } else + bp->flags = BUF_BUCKET; + MRU_INSERT(bp); + return (bp); +} + +extern void +__buf_init(hashp, nbytes) + HTAB *hashp; + int nbytes; +{ + BUFHEAD *bfp; + int npages; + + bfp = &(hashp->bufhead); + npages = (nbytes + hashp->BSIZE - 1) >> hashp->BSHIFT; + npages = MAX(npages, MIN_BUFFERS); + + hashp->nbufs = npages; + bfp->next = bfp; + bfp->prev = bfp; + /* + * This space is calloc'd so these are already null. + * + * bfp->ovfl = NULL; + * bfp->flags = 0; + * bfp->page = NULL; + * bfp->addr = 0; + */ +} + +extern int +__buf_free(hashp, do_free, to_disk) + HTAB *hashp; + int do_free, to_disk; +{ + BUFHEAD *bp; + + /* Need to make sure that buffer manager has been initialized */ + if (!LRU) + return (0); + for (bp = LRU; bp != &hashp->bufhead;) { + /* Check that the buffer is valid */ + if (bp->addr || IS_BUCKET(bp->flags)) { + if (to_disk && (bp->flags & BUF_MOD) && + __put_page(hashp, bp->page, + bp->addr, IS_BUCKET(bp->flags), 0)) + return (-1); + } + /* Check if we are freeing stuff */ + if (do_free) { + if (bp->page) + free(bp->page); + BUF_REMOVE(bp); + free(bp); + bp = LRU; + } else + bp = bp->prev; + } + return (0); +} + +extern void +__reclaim_buf(hashp, bp) + HTAB *hashp; + BUFHEAD *bp; +{ + bp->ovfl = 0; + bp->addr = 0; + bp->flags = 0; + BUF_REMOVE(bp); + LRU_INSERT(bp); +} diff --git a/db/hash/hash_func.c b/db/hash/hash_func.c new file mode 100644 index 0000000..d33b481 --- /dev/null +++ b/db/hash/hash_func.c @@ -0,0 +1,230 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Margo Seltzer. + * + * 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 + +#include +#include "hash.h" +#include "page.h" +#include "extern.h" + +static u_int32_t hash1 __P((const void *, size_t)); +static u_int32_t hash2 __P((const void *, size_t)); +static u_int32_t hash3 __P((const void *, size_t)); +static u_int32_t hash4 __P((const void *, size_t)); + +/* Global default hash function */ +u_int32_t (*__default_hash) __P((const void *, size_t)) = hash4; + +/* + * HASH FUNCTIONS + * + * Assume that we've already split the bucket to which this key hashes, + * calculate that bucket, and check that in fact we did already split it. + * + * This came from ejb's hsearch. + */ + +#define PRIME1 37 +#define PRIME2 1048583 + +static u_int32_t +hash1(keyarg, len) + const void *keyarg; + register size_t len; +{ + register const u_char *key; + register u_int32_t h; + + /* Convert string to integer */ + for (key = keyarg, h = 0; len--;) + h = h * PRIME1 ^ (*key++ - ' '); + h %= PRIME2; + return (h); +} + +/* + * Phong's linear congruential hash + */ +#define dcharhash(h, c) ((h) = 0x63c63cd9*(h) + 0x9c39c33d + (c)) + +static u_int32_t +hash2(keyarg, len) + const void *keyarg; + size_t len; +{ + register const u_char *e, *key; + register u_int32_t h; + register u_char c; + + key = keyarg; + e = key + len; + for (h = 0; key != e;) { + c = *key++; + if (!c && key > e) + break; + dcharhash(h, c); + } + return (h); +} + +/* + * This is INCREDIBLY ugly, but fast. We break the string up into 8 byte + * units. On the first time through the loop we get the "leftover bytes" + * (strlen % 8). On every other iteration, we perform 8 HASHC's so we handle + * all 8 bytes. Essentially, this saves us 7 cmp & branch instructions. If + * this routine is heavily used enough, it's worth the ugly coding. + * + * OZ's original sdbm hash + */ +static u_int32_t +hash3(keyarg, len) + const void *keyarg; + register size_t len; +{ + register const u_char *key; + register size_t loop; + register u_int32_t h; + +#define HASHC h = *key++ + 65599 * h + + h = 0; + key = keyarg; + if (len > 0) { + loop = (len + 8 - 1) >> 3; + + switch (len & (8 - 1)) { + case 0: + do { + HASHC; + /* FALLTHROUGH */ + case 7: + HASHC; + /* FALLTHROUGH */ + case 6: + HASHC; + /* FALLTHROUGH */ + case 5: + HASHC; + /* FALLTHROUGH */ + case 4: + HASHC; + /* FALLTHROUGH */ + case 3: + HASHC; + /* FALLTHROUGH */ + case 2: + HASHC; + /* FALLTHROUGH */ + case 1: + HASHC; + } while (--loop); + } + } + return (h); +} + +/* Hash function from Chris Torek. */ +static u_int32_t +hash4(keyarg, len) + const void *keyarg; + register size_t len; +{ + register const u_char *key; + register size_t loop; + register u_int32_t h; + +#define HASH4a h = (h << 5) - h + *key++; +#define HASH4b h = (h << 5) + h + *key++; +#define HASH4 HASH4b + + h = 0; + key = keyarg; + if (len > 0) { + loop = (len + 8 - 1) >> 3; + + switch (len & (8 - 1)) { + case 0: + do { + HASH4; + /* FALLTHROUGH */ + case 7: + HASH4; + /* FALLTHROUGH */ + case 6: + HASH4; + /* FALLTHROUGH */ + case 5: + HASH4; + /* FALLTHROUGH */ + case 4: + HASH4; + /* FALLTHROUGH */ + case 3: + HASH4; + /* FALLTHROUGH */ + case 2: + HASH4; + /* FALLTHROUGH */ + case 1: + HASH4; + } while (--loop); + } + } + return (h); +} diff --git a/db/hash/hash_log2.c b/db/hash/hash_log2.c new file mode 100644 index 0000000..0f7f002 --- /dev/null +++ b/db/hash/hash_log2.c @@ -0,0 +1,70 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Margo Seltzer. + * + * 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 + +u_int +__log2(num) + u_int num; +{ + register u_int i, limit; + + limit = 1; + for (i = 0; limit < num; limit = limit << 1, i++); + return (i); +} diff --git a/db/hash/hash_page.c b/db/hash/hash_page.c new file mode 100644 index 0000000..aa7b36f --- /dev/null +++ b/db/hash/hash_page.c @@ -0,0 +1,962 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Margo Seltzer. + * + * 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. + */ + + +/* + * PACKAGE: hashing + * + * DESCRIPTION: + * Page manipulation for hashing package. + * + * ROUTINES: + * + * External + * __get_page + * __add_ovflpage + * Internal + * overflow_page + * open_temp + */ + +#include + +#include +#include +#include +#include +#include +#include +#include +#ifdef DEBUG +#include +#endif + +#include +#include "hash.h" +#include "page.h" +#include "extern.h" + +static u_long *fetch_bitmap __P((HTAB *, int)); +static u_long first_free __P((u_long)); +static int open_temp __P((HTAB *)); +static u_short overflow_page __P((HTAB *)); +static void putpair __P((char *, const DBT *, const DBT *)); +static void squeeze_key __P((u_short *, const DBT *, const DBT *)); +static int ugly_split + __P((HTAB *, u_int, BUFHEAD *, BUFHEAD *, int, int)); + +#define PAGE_INIT(P) { \ + ((u_short *)(P))[0] = 0; \ + ((u_short *)(P))[1] = hashp->BSIZE - 3 * sizeof(u_short); \ + ((u_short *)(P))[2] = hashp->BSIZE; \ +} + +/* + * This is called AFTER we have verified that there is room on the page for + * the pair (PAIRFITS has returned true) so we go right ahead and start moving + * stuff on. + */ +static void +putpair(p, key, val) + char *p; + const DBT *key, *val; +{ + register u_short *bp, n, off; + + bp = (u_short *)p; + + /* Enter the key first. */ + n = bp[0]; + + off = OFFSET(bp) - key->size; + memmove(p + off, key->data, key->size); + bp[++n] = off; + + /* Now the data. */ + off -= val->size; + memmove(p + off, val->data, val->size); + bp[++n] = off; + + /* Adjust page info. */ + bp[0] = n; + bp[n + 1] = off - ((n + 3) * sizeof(u_short)); + bp[n + 2] = off; +} + +/* + * Returns: + * 0 OK + * -1 error + */ +extern int +__delpair(hashp, bufp, ndx) + HTAB *hashp; + BUFHEAD *bufp; + register int ndx; +{ + register u_short *bp, newoff; + register int n; + u_short pairlen; + + bp = (u_short *)bufp->page; + n = bp[0]; + + if (bp[ndx + 1] < REAL_KEY) + return (__big_delete(hashp, bufp)); + if (ndx != 1) + newoff = bp[ndx - 1]; + else + newoff = hashp->BSIZE; + pairlen = newoff - bp[ndx + 1]; + + if (ndx != (n - 1)) { + /* Hard Case -- need to shuffle keys */ + register int i; + register char *src = bufp->page + (int)OFFSET(bp); + register char *dst = src + (int)pairlen; + memmove(dst, src, bp[ndx + 1] - OFFSET(bp)); + + /* Now adjust the pointers */ + for (i = ndx + 2; i <= n; i += 2) { + if (bp[i + 1] == OVFLPAGE) { + bp[i - 2] = bp[i]; + bp[i - 1] = bp[i + 1]; + } else { + bp[i - 2] = bp[i] + pairlen; + bp[i - 1] = bp[i + 1] + pairlen; + } + } + } + /* Finally adjust the page data */ + bp[n] = OFFSET(bp) + pairlen; + bp[n - 1] = bp[n + 1] + pairlen + 2 * sizeof(u_short); + bp[0] = n - 2; + hashp->NKEYS--; + + bufp->flags |= BUF_MOD; + return (0); +} +/* + * Returns: + * 0 ==> OK + * -1 ==> Error + */ +extern int +__split_page(hashp, obucket, nbucket) + HTAB *hashp; + u_int obucket, nbucket; +{ + register BUFHEAD *new_bufp, *old_bufp; + register u_short *ino; + register char *np; + DBT key, val; + int n, ndx, retval; + u_short copyto, diff, off, moved; + char *op; + + copyto = (u_short)hashp->BSIZE; + off = (u_short)hashp->BSIZE; + old_bufp = __get_buf(hashp, obucket, NULL, 0); + if (old_bufp == NULL) + return (-1); + new_bufp = __get_buf(hashp, nbucket, NULL, 0); + if (new_bufp == NULL) + return (-1); + + old_bufp->flags |= (BUF_MOD | BUF_PIN); + new_bufp->flags |= (BUF_MOD | BUF_PIN); + + ino = (u_short *)(op = old_bufp->page); + np = new_bufp->page; + + moved = 0; + + for (n = 1, ndx = 1; n < ino[0]; n += 2) { + if (ino[n + 1] < REAL_KEY) { + retval = ugly_split(hashp, obucket, old_bufp, new_bufp, + (int)copyto, (int)moved); + old_bufp->flags &= ~BUF_PIN; + new_bufp->flags &= ~BUF_PIN; + return (retval); + + } + key.data = (u_char *)op + ino[n]; + key.size = off - ino[n]; + + if (__call_hash(hashp, key.data, key.size) == obucket) { + /* Don't switch page */ + diff = copyto - off; + if (diff) { + copyto = ino[n + 1] + diff; + memmove(op + copyto, op + ino[n + 1], + off - ino[n + 1]); + ino[ndx] = copyto + ino[n] - ino[n + 1]; + ino[ndx + 1] = copyto; + } else + copyto = ino[n + 1]; + ndx += 2; + } else { + /* Switch page */ + val.data = (u_char *)op + ino[n + 1]; + val.size = ino[n] - ino[n + 1]; + putpair(np, &key, &val); + moved += 2; + } + + off = ino[n + 1]; + } + + /* Now clean up the page */ + ino[0] -= moved; + FREESPACE(ino) = copyto - sizeof(u_short) * (ino[0] + 3); + OFFSET(ino) = copyto; + +#ifdef DEBUG3 + (void)fprintf(stderr, "split %d/%d\n", + ((u_short *)np)[0] / 2, + ((u_short *)op)[0] / 2); +#endif + /* unpin both pages */ + old_bufp->flags &= ~BUF_PIN; + new_bufp->flags &= ~BUF_PIN; + return (0); +} + +/* + * Called when we encounter an overflow or big key/data page during split + * handling. This is special cased since we have to begin checking whether + * the key/data pairs fit on their respective pages and because we may need + * overflow pages for both the old and new pages. + * + * The first page might be a page with regular key/data pairs in which case + * we have a regular overflow condition and just need to go on to the next + * page or it might be a big key/data pair in which case we need to fix the + * big key/data pair. + * + * Returns: + * 0 ==> success + * -1 ==> failure + */ +static int +ugly_split(hashp, obucket, old_bufp, new_bufp, copyto, moved) + HTAB *hashp; + u_int obucket; /* Same as __split_page. */ + BUFHEAD *old_bufp, *new_bufp; + int copyto; /* First byte on page which contains key/data values. */ + int moved; /* Number of pairs moved to new page. */ +{ + register BUFHEAD *bufp; /* Buffer header for ino */ + register u_short *ino; /* Page keys come off of */ + register u_short *np; /* New page */ + register u_short *op; /* Page keys go on to if they aren't moving */ + + BUFHEAD *last_bfp; /* Last buf header OVFL needing to be freed */ + DBT key, val; + SPLIT_RETURN ret; + u_short n, off, ov_addr, scopyto; + char *cino; /* Character value of ino */ + + bufp = old_bufp; + ino = (u_short *)old_bufp->page; + np = (u_short *)new_bufp->page; + op = (u_short *)old_bufp->page; + last_bfp = NULL; + scopyto = (u_short)copyto; /* ANSI */ + + n = ino[0] - 1; + while (n < ino[0]) { + if (ino[2] < REAL_KEY && ino[2] != OVFLPAGE) { + if (__big_split(hashp, old_bufp, + new_bufp, bufp, bufp->addr, obucket, &ret)) + return (-1); + old_bufp = ret.oldp; + if (!old_bufp) + return (-1); + op = (u_short *)old_bufp->page; + new_bufp = ret.newp; + if (!new_bufp) + return (-1); + np = (u_short *)new_bufp->page; + bufp = ret.nextp; + if (!bufp) + return (0); + cino = (char *)bufp->page; + ino = (u_short *)cino; + last_bfp = ret.nextp; + } else if (ino[n + 1] == OVFLPAGE) { + ov_addr = ino[n]; + /* + * Fix up the old page -- the extra 2 are the fields + * which contained the overflow information. + */ + ino[0] -= (moved + 2); + FREESPACE(ino) = + scopyto - sizeof(u_short) * (ino[0] + 3); + OFFSET(ino) = scopyto; + + bufp = __get_buf(hashp, ov_addr, bufp, 0); + if (!bufp) + return (-1); + + ino = (u_short *)bufp->page; + n = 1; + scopyto = hashp->BSIZE; + moved = 0; + + if (last_bfp) + __free_ovflpage(hashp, last_bfp); + last_bfp = bufp; + } + /* Move regular sized pairs of there are any */ + off = hashp->BSIZE; + for (n = 1; (n < ino[0]) && (ino[n + 1] >= REAL_KEY); n += 2) { + cino = (char *)ino; + key.data = (u_char *)cino + ino[n]; + key.size = off - ino[n]; + val.data = (u_char *)cino + ino[n + 1]; + val.size = ino[n] - ino[n + 1]; + off = ino[n + 1]; + + if (__call_hash(hashp, key.data, key.size) == obucket) { + /* Keep on old page */ + if (PAIRFITS(op, (&key), (&val))) + putpair((char *)op, &key, &val); + else { + old_bufp = + __add_ovflpage(hashp, old_bufp); + if (!old_bufp) + return (-1); + op = (u_short *)old_bufp->page; + putpair((char *)op, &key, &val); + } + old_bufp->flags |= BUF_MOD; + } else { + /* Move to new page */ + if (PAIRFITS(np, (&key), (&val))) + putpair((char *)np, &key, &val); + else { + new_bufp = + __add_ovflpage(hashp, new_bufp); + if (!new_bufp) + return (-1); + np = (u_short *)new_bufp->page; + putpair((char *)np, &key, &val); + } + new_bufp->flags |= BUF_MOD; + } + } + } + if (last_bfp) + __free_ovflpage(hashp, last_bfp); + return (0); +} + +/* + * Add the given pair to the page + * + * Returns: + * 0 ==> OK + * 1 ==> failure + */ +extern int +__addel(hashp, bufp, key, val) + HTAB *hashp; + BUFHEAD *bufp; + const DBT *key, *val; +{ + register u_short *bp, *sop; + int do_expand; + + bp = (u_short *)bufp->page; + do_expand = 0; + while (bp[0] && (bp[2] < REAL_KEY || bp[bp[0]] < REAL_KEY)) + /* Exception case */ + if (bp[2] == FULL_KEY_DATA && bp[0] == 2) + /* This is the last page of a big key/data pair + and we need to add another page */ + break; + else if (bp[2] < REAL_KEY && bp[bp[0]] != OVFLPAGE) { + bufp = __get_buf(hashp, bp[bp[0] - 1], bufp, 0); + if (!bufp) + return (-1); + bp = (u_short *)bufp->page; + } else + /* Try to squeeze key on this page */ + if (FREESPACE(bp) > PAIRSIZE(key, val)) { + squeeze_key(bp, key, val); + return (0); + } else { + bufp = __get_buf(hashp, bp[bp[0] - 1], bufp, 0); + if (!bufp) + return (-1); + bp = (u_short *)bufp->page; + } + + if (PAIRFITS(bp, key, val)) + putpair(bufp->page, key, val); + else { + do_expand = 1; + bufp = __add_ovflpage(hashp, bufp); + if (!bufp) + return (-1); + sop = (u_short *)bufp->page; + + if (PAIRFITS(sop, key, val)) + putpair((char *)sop, key, val); + else + if (__big_insert(hashp, bufp, key, val)) + return (-1); + } + bufp->flags |= BUF_MOD; + /* + * If the average number of keys per bucket exceeds the fill factor, + * expand the table. + */ + hashp->NKEYS++; + if (do_expand || + (hashp->NKEYS / (hashp->MAX_BUCKET + 1) > hashp->FFACTOR)) + return (__expand_table(hashp)); + return (0); +} + +/* + * + * Returns: + * pointer on success + * NULL on error + */ +extern BUFHEAD * +__add_ovflpage(hashp, bufp) + HTAB *hashp; + BUFHEAD *bufp; +{ + register u_short *sp; + u_short ndx, ovfl_num; +#ifdef DEBUG1 + int tmp1, tmp2; +#endif + sp = (u_short *)bufp->page; + + /* Check if we are dynamically determining the fill factor */ + if (hashp->FFACTOR == DEF_FFACTOR) { + hashp->FFACTOR = sp[0] >> 1; + if (hashp->FFACTOR < MIN_FFACTOR) + hashp->FFACTOR = MIN_FFACTOR; + } + bufp->flags |= BUF_MOD; + ovfl_num = overflow_page(hashp); +#ifdef DEBUG1 + tmp1 = bufp->addr; + tmp2 = bufp->ovfl ? bufp->ovfl->addr : 0; +#endif + if (!ovfl_num || !(bufp->ovfl = __get_buf(hashp, ovfl_num, bufp, 1))) + return (NULL); + bufp->ovfl->flags |= BUF_MOD; +#ifdef DEBUG1 + (void)fprintf(stderr, "ADDOVFLPAGE: %d->ovfl was %d is now %d\n", + tmp1, tmp2, bufp->ovfl->addr); +#endif + ndx = sp[0]; + /* + * Since a pair is allocated on a page only if there's room to add + * an overflow page, we know that the OVFL information will fit on + * the page. + */ + sp[ndx + 4] = OFFSET(sp); + sp[ndx + 3] = FREESPACE(sp) - OVFLSIZE; + sp[ndx + 1] = ovfl_num; + sp[ndx + 2] = OVFLPAGE; + sp[0] = ndx + 2; +#ifdef HASH_STATISTICS + hash_overflows++; +#endif + return (bufp->ovfl); +} + +/* + * Returns: + * 0 indicates SUCCESS + * -1 indicates FAILURE + */ +extern int +__get_page(hashp, p, bucket, is_bucket, is_disk, is_bitmap) + HTAB *hashp; + char *p; + u_int bucket; + int is_bucket, is_disk, is_bitmap; +{ + register int fd, page, size; + int rsize; + u_short *bp; + + fd = hashp->fp; + size = hashp->BSIZE; + + if ((fd == -1) || !is_disk) { + PAGE_INIT(p); + return (0); + } + if (is_bucket) + page = BUCKET_TO_PAGE(bucket); + else + page = OADDR_TO_PAGE(bucket); + if ((lseek(fd, (off_t)page << hashp->BSHIFT, SEEK_SET) == -1) || + ((rsize = read(fd, p, size)) == -1)) + return (-1); + bp = (u_short *)p; + if (!rsize) + bp[0] = 0; /* We hit the EOF, so initialize a new page */ + else + if (rsize != size) { + errno = EFTYPE; + return (-1); + } + if (!is_bitmap && !bp[0]) { + PAGE_INIT(p); + } else + if (hashp->LORDER != BYTE_ORDER) { + register int i, max; + + if (is_bitmap) { + max = hashp->BSIZE >> 2; /* divide by 4 */ + for (i = 0; i < max; i++) + M_32_SWAP(((long *)p)[i]); + } else { + M_16_SWAP(bp[0]); + max = bp[0] + 2; + for (i = 1; i <= max; i++) + M_16_SWAP(bp[i]); + } + } + return (0); +} + +/* + * Write page p to disk + * + * Returns: + * 0 ==> OK + * -1 ==>failure + */ +extern int +__put_page(hashp, p, bucket, is_bucket, is_bitmap) + HTAB *hashp; + char *p; + u_int bucket; + int is_bucket, is_bitmap; +{ + register int fd, page, size; + int wsize; + + size = hashp->BSIZE; + if ((hashp->fp == -1) && open_temp(hashp)) + return (-1); + fd = hashp->fp; + + if (hashp->LORDER != BYTE_ORDER) { + register int i; + register int max; + + if (is_bitmap) { + max = hashp->BSIZE >> 2; /* divide by 4 */ + for (i = 0; i < max; i++) + M_32_SWAP(((long *)p)[i]); + } else { + max = ((u_short *)p)[0] + 2; + for (i = 0; i <= max; i++) + M_16_SWAP(((u_short *)p)[i]); + } + } + if (is_bucket) + page = BUCKET_TO_PAGE(bucket); + else + page = OADDR_TO_PAGE(bucket); + if ((lseek(fd, (off_t)page << hashp->BSHIFT, SEEK_SET) == -1) || + ((wsize = write(fd, p, size)) == -1)) + /* Errno is set */ + return (-1); + if (wsize != size) { + errno = EFTYPE; + return (-1); + } + return (0); +} + +#define BYTE_MASK ((1 << INT_BYTE_SHIFT) -1) +/* + * Initialize a new bitmap page. Bitmap pages are left in memory + * once they are read in. + */ +extern int +__init_bitmap(hashp, pnum, nbits, ndx) + HTAB *hashp; + int pnum, nbits, ndx; +{ + u_long *ip; + int clearbytes, clearints; + + if ((ip = (u_long *)malloc(hashp->BSIZE)) == NULL) + return (1); + hashp->nmaps++; + clearints = ((nbits - 1) >> INT_BYTE_SHIFT) + 1; + clearbytes = clearints << INT_TO_BYTE; + (void)memset((char *)ip, 0, clearbytes); + (void)memset(((char *)ip) + clearbytes, 0xFF, + hashp->BSIZE - clearbytes); + ip[clearints - 1] = ALL_SET << (nbits & BYTE_MASK); + SETBIT(ip, 0); + hashp->BITMAPS[ndx] = (u_short)pnum; + hashp->mapp[ndx] = ip; + return (0); +} + +static u_long +first_free(map) + u_long map; +{ + register u_long i, mask; + + mask = 0x1; + for (i = 0; i < BITS_PER_MAP; i++) { + if (!(mask & map)) + return (i); + mask = mask << 1; + } + return (i); +} + +static u_short +overflow_page(hashp) + HTAB *hashp; +{ + register u_long *freep; + register int max_free, offset, splitnum; + u_short addr; + int bit, first_page, free_bit, free_page, i, in_use_bits, j; +#ifdef DEBUG2 + int tmp1, tmp2; +#endif + splitnum = hashp->OVFL_POINT; + max_free = hashp->SPARES[splitnum]; + + free_page = (max_free - 1) >> (hashp->BSHIFT + BYTE_SHIFT); + free_bit = (max_free - 1) & ((hashp->BSIZE << BYTE_SHIFT) - 1); + + /* Look through all the free maps to find the first free block */ + first_page = hashp->LAST_FREED >>(hashp->BSHIFT + BYTE_SHIFT); + for ( i = first_page; i <= free_page; i++ ) { + if (!(freep = (u_long *)hashp->mapp[i]) && + !(freep = fetch_bitmap(hashp, i))) + return (NULL); + if (i == free_page) + in_use_bits = free_bit; + else + in_use_bits = (hashp->BSIZE << BYTE_SHIFT) - 1; + + if (i == first_page) { + bit = hashp->LAST_FREED & + ((hashp->BSIZE << BYTE_SHIFT) - 1); + j = bit / BITS_PER_MAP; + bit = bit & ~(BITS_PER_MAP - 1); + } else { + bit = 0; + j = 0; + } + for (; bit <= in_use_bits; j++, bit += BITS_PER_MAP) + if (freep[j] != ALL_SET) + goto found; + } + + /* No Free Page Found */ + hashp->LAST_FREED = hashp->SPARES[splitnum]; + hashp->SPARES[splitnum]++; + offset = hashp->SPARES[splitnum] - + (splitnum ? hashp->SPARES[splitnum - 1] : 0); + +#define OVMSG "HASH: Out of overflow pages. Increase page size\n" + if (offset > SPLITMASK) { + if (++splitnum >= NCACHED) { + (void)write(STDERR_FILENO, OVMSG, sizeof(OVMSG) - 1); + return (NULL); + } + hashp->OVFL_POINT = splitnum; + hashp->SPARES[splitnum] = hashp->SPARES[splitnum-1]; + hashp->SPARES[splitnum-1]--; + offset = 1; + } + + /* Check if we need to allocate a new bitmap page */ + if (free_bit == (hashp->BSIZE << BYTE_SHIFT) - 1) { + free_page++; + if (free_page >= NCACHED) { + (void)write(STDERR_FILENO, OVMSG, sizeof(OVMSG) - 1); + return (NULL); + } + /* + * This is tricky. The 1 indicates that you want the new page + * allocated with 1 clear bit. Actually, you are going to + * allocate 2 pages from this map. The first is going to be + * the map page, the second is the overflow page we were + * looking for. The init_bitmap routine automatically, sets + * the first bit of itself to indicate that the bitmap itself + * is in use. We would explicitly set the second bit, but + * don't have to if we tell init_bitmap not to leave it clear + * in the first place. + */ + if (__init_bitmap(hashp, (int)OADDR_OF(splitnum, offset), + 1, free_page)) + return (NULL); + hashp->SPARES[splitnum]++; +#ifdef DEBUG2 + free_bit = 2; +#endif + offset++; + if (offset > SPLITMASK) { + if (++splitnum >= NCACHED) { + (void)write(STDERR_FILENO, OVMSG, + sizeof(OVMSG) - 1); + return (NULL); + } + hashp->OVFL_POINT = splitnum; + hashp->SPARES[splitnum] = hashp->SPARES[splitnum-1]; + hashp->SPARES[splitnum-1]--; + offset = 0; + } + } else { + /* + * Free_bit addresses the last used bit. Bump it to address + * the first available bit. + */ + free_bit++; + SETBIT(freep, free_bit); + } + + /* Calculate address of the new overflow page */ + addr = OADDR_OF(splitnum, offset); +#ifdef DEBUG2 + (void)fprintf(stderr, "OVERFLOW_PAGE: ADDR: %d BIT: %d PAGE %d\n", + addr, free_bit, free_page); +#endif + return (addr); + +found: + bit = bit + first_free(freep[j]); + SETBIT(freep, bit); +#ifdef DEBUG2 + tmp1 = bit; + tmp2 = i; +#endif + /* + * Bits are addressed starting with 0, but overflow pages are addressed + * beginning at 1. Bit is a bit addressnumber, so we need to increment + * it to convert it to a page number. + */ + bit = 1 + bit + (i * (hashp->BSIZE << BYTE_SHIFT)); + if (bit >= hashp->LAST_FREED) + hashp->LAST_FREED = bit - 1; + + /* Calculate the split number for this page */ + for (i = 0; (i < splitnum) && (bit > hashp->SPARES[i]); i++); + offset = (i ? bit - hashp->SPARES[i - 1] : bit); + if (offset >= SPLITMASK) + return (NULL); /* Out of overflow pages */ + addr = OADDR_OF(i, offset); +#ifdef DEBUG2 + (void)fprintf(stderr, "OVERFLOW_PAGE: ADDR: %d BIT: %d PAGE %d\n", + addr, tmp1, tmp2); +#endif + + /* Allocate and return the overflow page */ + return (addr); +} + +/* + * Mark this overflow page as free. + */ +extern void +__free_ovflpage(hashp, obufp) + HTAB *hashp; + BUFHEAD *obufp; +{ + register u_short addr; + u_long *freep; + int bit_address, free_page, free_bit; + u_short ndx; + + addr = obufp->addr; +#ifdef DEBUG1 + (void)fprintf(stderr, "Freeing %d\n", addr); +#endif + ndx = (((u_short)addr) >> SPLITSHIFT); + bit_address = + (ndx ? hashp->SPARES[ndx - 1] : 0) + (addr & SPLITMASK) - 1; + if (bit_address < hashp->LAST_FREED) + hashp->LAST_FREED = bit_address; + free_page = (bit_address >> (hashp->BSHIFT + BYTE_SHIFT)); + free_bit = bit_address & ((hashp->BSIZE << BYTE_SHIFT) - 1); + + if (!(freep = hashp->mapp[free_page])) + freep = fetch_bitmap(hashp, free_page); +#ifdef DEBUG + /* + * This had better never happen. It means we tried to read a bitmap + * that has already had overflow pages allocated off it, and we + * failed to read it from the file. + */ + if (!freep) + assert(0); +#endif + CLRBIT(freep, free_bit); +#ifdef DEBUG2 + (void)fprintf(stderr, "FREE_OVFLPAGE: ADDR: %d BIT: %d PAGE %d\n", + obufp->addr, free_bit, free_page); +#endif + __reclaim_buf(hashp, obufp); +} + +/* + * Returns: + * 0 success + * -1 failure + */ +static int +open_temp(hashp) + HTAB *hashp; +{ + sigset_t set, oset; + static char namestr[] = "_hashXXXXXX"; + + /* Block signals; make sure file goes away at process exit. */ + (void)sigfillset(&set); + (void)sigprocmask(SIG_BLOCK, &set, &oset); + if ((hashp->fp = mkstemp(namestr)) != -1) { + (void)unlink(namestr); + (void)fcntl(hashp->fp, F_SETFD, 1); + } + (void)sigprocmask(SIG_SETMASK, &oset, (sigset_t *)NULL); + return (hashp->fp != -1 ? 0 : -1); +} + +/* + * We have to know that the key will fit, but the last entry on the page is + * an overflow pair, so we need to shift things. + */ +static void +squeeze_key(sp, key, val) + u_short *sp; + const DBT *key, *val; +{ + register char *p; + u_short free_space, n, off, pageno; + + p = (char *)sp; + n = sp[0]; + free_space = FREESPACE(sp); + off = OFFSET(sp); + + pageno = sp[n - 1]; + off -= key->size; + sp[n - 1] = off; + memmove(p + off, key->data, key->size); + off -= val->size; + sp[n] = off; + memmove(p + off, val->data, val->size); + sp[0] = n + 2; + sp[n + 1] = pageno; + sp[n + 2] = OVFLPAGE; + FREESPACE(sp) = free_space - PAIRSIZE(key, val); + OFFSET(sp) = off; +} + +static u_long * +fetch_bitmap(hashp, ndx) + HTAB *hashp; + int ndx; +{ + if (ndx >= hashp->nmaps) + return (NULL); + if ((hashp->mapp[ndx] = (u_long *)malloc(hashp->BSIZE)) == NULL) + return (NULL); + if (__get_page(hashp, + (char *)hashp->mapp[ndx], hashp->BITMAPS[ndx], 0, 1, 1)) { + free(hashp->mapp[ndx]); + return (NULL); + } + return (hashp->mapp[ndx]); +} + +#ifdef DEBUG4 +int +print_chain(addr) + int addr; +{ + BUFHEAD *bufp; + short *bp, oaddr; + + (void)fprintf(stderr, "%d ", addr); + bufp = __get_buf(hashp, addr, NULL, 0); + bp = (short *)bufp->page; + while (bp[0] && ((bp[bp[0]] == OVFLPAGE) || + ((bp[0] > 2) && bp[2] < REAL_KEY))) { + oaddr = bp[bp[0] - 1]; + (void)fprintf(stderr, "%d ", (int)oaddr); + bufp = __get_buf(hashp, (int)oaddr, bufp, 0); + bp = (short *)bufp->page; + } + (void)fprintf(stderr, "\n"); +} +#endif diff --git a/db/hash/hsearch.c b/db/hash/hsearch.c new file mode 100644 index 0000000..83ed150 --- /dev/null +++ b/db/hash/hsearch.c @@ -0,0 +1,125 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Margo Seltzer. + * + * 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 + +#include +#include + +#include +#include "search.h" + +static DB *dbp = NULL; +static ENTRY retval; + +extern int +hcreate(nel) + u_int nel; +{ + HASHINFO info; + + info.nelem = nel; + info.bsize = 256; + info.ffactor = 8; + info.cachesize = NULL; + info.hash = NULL; + info.lorder = 0; + dbp = (DB *)__hash_open(NULL, O_CREAT | O_RDWR, 0600, &info, 0); + return ((int)dbp); +} + +extern ENTRY * +hsearch(item, action) + ENTRY item; + ACTION action; +{ + DBT key, val; + int status; + + if (!dbp) + return (NULL); + key.data = (u_char *)item.key; + key.size = strlen(item.key) + 1; + + if (action == ENTER) { + val.data = (u_char *)item.data; + val.size = strlen(item.data) + 1; + status = (dbp->put)(dbp, &key, &val, R_NOOVERWRITE); + if (status) + return (NULL); + } else { + /* FIND */ + status = (dbp->get)(dbp, &key, &val, 0); + if (status) + return (NULL); + else + item.data = (char *)val.data; + } + retval.key = item.key; + retval.data = item.data; + return (&retval); +} + +extern void +hdestroy() +{ + if (dbp) { + (void)(dbp->close)(dbp); + dbp = NULL; + } +} diff --git a/db/hash/ndbm.c b/db/hash/ndbm.c new file mode 100644 index 0000000..ca7125b --- /dev/null +++ b/db/hash/ndbm.c @@ -0,0 +1,220 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Margo Seltzer. + * + * 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. + */ + + +/* + * This package provides a dbm compatible interface to the new hashing + * package described in db(3). + */ + +#include + +#include +#include +#include + +#include "hash.h" + +/* + * Returns: + * *DBM on success + * NULL on failure + */ +extern DBM * +dbm_open(file, flags, mode) + const char *file; + int flags, mode; +{ + HASHINFO info; + char path[MAXPATHLEN]; + + info.bsize = 4096; + info.ffactor = 40; + info.nelem = 1; + info.cachesize = NULL; + info.hash = NULL; + info.lorder = 0; + (void)strcpy(path, file); + (void)strcat(path, DBM_SUFFIX); + return ((DBM *)__hash_open(path, flags, mode, &info, 0)); +} + +extern void +dbm_close(db) + DBM *db; +{ + (void)(db->close)(db); +} + +/* + * Returns: + * DATUM on success + * NULL on failure + */ +extern datum +dbm_fetch(db, key) + DBM *db; + datum key; +{ + datum retval; + int status; + + status = (db->get)(db, (DBT *)&key, (DBT *)&retval, 0); + if (status) { + retval.dptr = NULL; + retval.dsize = 0; + } + return (retval); +} + +/* + * Returns: + * DATUM on success + * NULL on failure + */ +extern datum +dbm_firstkey(db) + DBM *db; +{ + int status; + datum retdata, retkey; + + status = (db->seq)(db, (DBT *)&retkey, (DBT *)&retdata, R_FIRST); + if (status) + retkey.dptr = NULL; + return (retkey); +} + +/* + * Returns: + * DATUM on success + * NULL on failure + */ +extern datum +dbm_nextkey(db) + DBM *db; +{ + int status; + datum retdata, retkey; + + status = (db->seq)(db, (DBT *)&retkey, (DBT *)&retdata, R_NEXT); + if (status) + retkey.dptr = NULL; + return (retkey); +} +/* + * Returns: + * 0 on success + * <0 failure + */ +extern int +dbm_delete(db, key) + DBM *db; + datum key; +{ + int status; + + status = (db->del)(db, (DBT *)&key, 0); + if (status) + return (-1); + else + return (0); +} + +/* + * Returns: + * 0 on success + * <0 failure + * 1 if DBM_INSERT and entry exists + */ +extern int +dbm_store(db, key, content, flags) + DBM *db; + datum key, content; + int flags; +{ + return ((db->put)(db, (DBT *)&key, (DBT *)&content, + (flags == DBM_INSERT) ? R_NOOVERWRITE : 0)); +} + +extern int +dbm_error(db) + DBM *db; +{ + HTAB *hp; + + hp = (HTAB *)db->internal; + return (hp->error); +} + +extern int +dbm_clearerr(db) + DBM *db; +{ + HTAB *hp; + + hp = (HTAB *)db->internal; + hp->error = 0; + return (0); +} + +extern int +dbm_dirfno(db) + DBM *db; +{ + return(((HTAB *)db->internal)->fp); +} diff --git a/db/hash/page.h b/db/hash/page.h new file mode 100644 index 0000000..a74c50b --- /dev/null +++ b/db/hash/page.h @@ -0,0 +1,111 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Margo Seltzer. + * + * 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. + */ + +/* + * Definitions for hashing page file format. + */ + +/* + * routines dealing with a data page + * + * page format: + * +------------------------------+ + * p | n | keyoff | datoff | keyoff | + * +------------+--------+--------+ + * | datoff | free | ptr | --> | + * +--------+---------------------+ + * | F R E E A R E A | + * +--------------+---------------+ + * | <---- - - - | data | + * +--------+-----+----+----------+ + * | key | data | key | + * +--------+----------+----------+ + * + * Pointer to the free space is always: p[p[0] + 2] + * Amount of free space on the page is: p[p[0] + 1] + */ + +/* + * How many bytes required for this pair? + * 2 shorts in the table at the top of the page + room for the + * key and room for the data + * + * We prohibit entering a pair on a page unless there is also room to append + * an overflow page. The reason for this it that you can get in a situation + * where a single key/data pair fits on a page, but you can't append an + * overflow page and later you'd have to split the key/data and handle like + * a big pair. + * You might as well do this up front. + */ + +#define PAIRSIZE(K,D) (2*sizeof(u_short) + (K)->size + (D)->size) +#define BIGOVERHEAD (4*sizeof(u_short)) +#define KEYSIZE(K) (4*sizeof(u_short) + (K)->size); +#define OVFLSIZE (2*sizeof(u_short)) +#define FREESPACE(P) ((P)[(P)[0]+1]) +#define OFFSET(P) ((P)[(P)[0]+2]) +#define PAIRFITS(P,K,D) \ + (((P)[2] >= REAL_KEY) && \ + (PAIRSIZE((K),(D)) + OVFLSIZE) <= FREESPACE((P))) +#define PAGE_META(N) (((N)+3) * sizeof(u_short)) + +typedef struct { + BUFHEAD *newp; + BUFHEAD *oldp; + BUFHEAD *nextp; + u_short next_addr; +} SPLIT_RETURN; diff --git a/db/hash/search.h b/db/hash/search.h new file mode 100644 index 0000000..3196b8f --- /dev/null +++ b/db/hash/search.h @@ -0,0 +1,70 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Margo Seltzer. + * + * 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. + */ + +/* Backward compatibility to hsearch interface. */ +typedef struct entry { + char *key; + char *data; +} ENTRY; + +typedef enum { + FIND, ENTER +} ACTION; + +int hcreate __P((unsigned int)); +void hdestroy __P((void)); +ENTRY *hsearch __P((ENTRY, ACTION)); diff --git a/db/man/Makefile.inc b/db/man/Makefile.inc new file mode 100644 index 0000000..3ee0369 --- /dev/null +++ b/db/man/Makefile.inc @@ -0,0 +1,20 @@ +# from @(#)Makefile.inc 8.1 (Berkeley) 6/4/93 +# $FreeBSD: src/lib/libc/db/man/Makefile.inc,v 1.10 2001/03/27 17:26:46 ru Exp $ + +.PATH: ${.CURDIR}/db/man + +.if ${LIB} == "c" +MAN3+= btree.3 dbm.3 dbopen.3 hash.3 mpool.3 recno.3 + +MLINKS+= dbm.3 dbm_clearerr.3 +MLINKS+= dbm.3 dbm_close.3 +MLINKS+= dbm.3 dbm_delete.3 +MLINKS+= dbm.3 dbm_dirnfo.3 +MLINKS+= dbm.3 dbm_error.3 +MLINKS+= dbm.3 dbm_fetch.3 +MLINKS+= dbm.3 dbm_firstkey.3 +MLINKS+= dbm.3 dbm_nextkey.3 +MLINKS+= dbm.3 dbm_open.3 +MLINKS+= dbm.3 dbm_store.3 +MLINKS+= dbopen.3 db.3 +.endif diff --git a/db/man/btree.3 b/db/man/btree.3 new file mode 100644 index 0000000..b8cee89 --- /dev/null +++ b/db/man/btree.3 @@ -0,0 +1,272 @@ +.\" Copyright (c) 1990, 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. +.\" +.\" @(#)btree.3 8.4 (Berkeley) 8/18/94 +.\" $FreeBSD: src/lib/libc/db/man/btree.3,v 1.5 2001/10/01 16:08:50 ru Exp $ +.\" +.Dd August 18, 1994 +.Dt BTREE 3 +.Os +.Sh NAME +.Nm btree +.Nd "btree database access method" +.Sh SYNOPSIS +.In sys/types.h +.In db.h +.Sh DESCRIPTION +The routine +.Fn dbopen +is the library interface to database files. +One of the supported file formats is +.Nm +files. +The general description of the database access methods is in +.Xr dbopen 3 , +this manual page describes only the +.Nm +specific information. +.Pp +The +.Nm +data structure is a sorted, balanced tree structure storing +associated key/data pairs. +.Pp +The +.Nm +access method specific data structure provided to +.Fn dbopen +is defined in the +.Aq Pa db.h +include file as follows: +.Bd -literal +typedef struct { + u_long flags; + u_int cachesize; + int maxkeypage; + int minkeypage; + u_int psize; + int (*compare)(const DBT *key1, const DBT *key2); + size_t (*prefix)(const DBT *key1, const DBT *key2); + int lorder; +} BTREEINFO; +.Ed +.Pp +The elements of this structure are as follows: +.Bl -tag -width indent +.It Va flags +The flag value is specified by +.Em or Ns 'ing +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 +inserted already exists in the tree. +The default behavior, as described in +.Xr dbopen 3 , +is to overwrite a matching key when inserting a new key or to fail if +the +.Dv R_NOOVERWRITE +flag is specified. +The +.Dv R_DUP +flag is overridden by the +.Dv R_NOOVERWRITE +flag, and if the +.Dv R_NOOVERWRITE +flag is specified, attempts to insert duplicate keys into +the tree will fail. +.Pp +If the database contains duplicate keys, the order of retrieval of +key/data pairs is undefined if the +.Va get +routine is used, however, +.Va seq +routine calls with the +.Dv R_CURSOR +flag set will always return the logical +.Dq first +of any group of duplicate keys. +.El +.It Va cachesize +A suggested maximum size (in bytes) of the memory cache. +This value is +.Em only +advisory, and the access method will allocate more memory rather than fail. +Since every search examines the root page of the tree, caching the most +recently used pages substantially improves access time. +In addition, physical writes are delayed as long as possible, so a moderate +cache can reduce the number of I/O operations significantly. +Obviously, using a cache increases (but only increases) the likelihood of +corruption or lost data if the system crashes while a tree is being modified. +If +.Va cachesize +is 0 (no size is specified) a default cache is used. +.It Va maxkeypage +The maximum number of keys which will be stored on any single page. +Not currently implemented. +.\" The maximum number of keys which will be stored on any single page. +.\" Because of the way the +.\" .Nm +.\" data structure works, +.\" .Va maxkeypage +.\" must always be greater than or equal to 2. +.\" If +.\" .Va maxkeypage +.\" is 0 (no maximum number of keys is specified) the page fill factor is +.\" made as large as possible (which is almost invariably what is wanted). +.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 +by the minkeypage value, it will be stored on overflow pages instead +of in the page itself. +If +.Va minkeypage +is 0 (no minimum number of keys is specified) a value of 2 is used. +.It Va psize +Page size is the size (in bytes) of the pages used for nodes in the tree. +The minimum page size is 512 bytes and the maximum page size is 64K. +If +.Va psize +is 0 (no page size is specified) a page size is chosen based on the +underlying file system I/O block size. +.It Va compare +Compare is the key comparison function. +It must return an integer less than, equal to, or greater than zero if the +first key argument is considered to be respectively less than, equal to, +or greater than the second key argument. +The same comparison function must be used on a given tree every time it +is opened. +If +.Va compare +is +.Dv NULL +(no comparison function is specified), the keys are compared +lexically, with shorter keys considered less than longer keys. +.It Va prefix +.Va Prefix +is the prefix comparison function. +If specified, this routine must return the number of bytes of the second key +argument which are necessary to determine that it is greater than the first +key argument. +If the keys are equal, the key length should be returned. +Note, the usefulness of this routine is very data dependent, but, in some +data sets can produce significantly reduced tree sizes and search times. +If +.Va prefix +is +.Dv NULL +(no prefix function is specified), +.Em and +no comparison function is specified, a default lexical comparison routine +is used. +If +.Va prefix +is +.Dv NULL +and a comparison routine is specified, no prefix comparison is +done. +.It Va lorder +The byte order for integers in the stored database metadata. +The number should represent the order as an integer; for example, +big endian order would be the number 4,321. +If +.Va lorder +is 0 (no order is specified) the current host order is used. +.El +.Pp +If the file already exists (and the +.Dv O_TRUNC +flag is not specified), the +values specified for the parameters +.Va flags , lorder +and +.Va psize +are ignored +in favor of the values used when the tree was created. +.Pp +Forward sequential scans of a tree are from the least key to the greatest. +.Pp +Space freed up by deleting key/data pairs from the tree is never reclaimed, +although it is normally made available for reuse. +This means that the +.Nm +storage structure is grow-only. +The only solutions are to avoid excessive deletions, or to create a fresh +tree periodically from a scan of an existing one. +.Pp +Searches, insertions, and deletions in a +.Nm +will all complete in +O lg base N where base is the average fill factor. +Often, inserting ordered data into +.Nm Ns s +results in a low fill factor. +This implementation has been modified to make ordered insertion the best +case, resulting in a much better than normal page fill factor. +.Sh ERRORS +The +.Nm +access method routines may fail and set +.Va errno +for any of the errors specified for the library routine +.Xr dbopen 3 . +.Sh SEE ALSO +.Xr dbopen 3 , +.Xr hash 3 , +.Xr mpool 3 , +.Xr recno 3 +.Rs +.%T "The Ubiquitous B-tree" +.%A Douglas Comer +.%J "ACM Comput. Surv. 11" +.%N 2 +.%D June 1979 +.%P 121-138 +.Re +.Rs +.%A Bayer +.%A Unterauer +.%T "Prefix B-trees" +.%J "ACM Transactions on Database Systems" +.%N 1 +.%V Vol. 2 +.%D March 1977 +.%P 11-26 +.Re +.Rs +.%B "The Art of Computer Programming Vol. 3: Sorting and Searching" +.%A D. E. Knuth +.%D 1968 +.%P 471-480 +.Re +.Sh BUGS +Only big and little endian byte order is supported. diff --git a/db/man/dbm.3 b/db/man/dbm.3 new file mode 100644 index 0000000..55b076b --- /dev/null +++ b/db/man/dbm.3 @@ -0,0 +1,196 @@ +.\" Copyright (c) 1999 Tim Singletary +.\" No copyright is claimed. +.\" +.\" 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/db/man/dbm.3,v 1.5 2001/10/01 16:08:50 ru Exp $ +.\" +.\" Note: The date here should be updated whenever a non-trivial +.\" change is made to the manual page. +.Dd July 7, 1999 +.Dt DBM 3 +.Os +.Sh NAME +.Nm dbm_clearerr , +.Nm dbm_close , +.Nm dbm_delete , +.Nm dbm_dirfno , +.Nm dbm_error , +.Nm dbm_fetch , +.Nm dbm_firstkey , +.Nm dbm_nextkey , +.Nm dbm_open , +.Nm dbm_store +.Nd database access functions +.Sh SYNOPSIS +.In fcntl.h +.In ndbm.h +.Ft DBM * +.Fn dbm_open "const char *base" "int flags" "int mode" +.Ft void +.Fn dbm_close "DBM *db" +.Ft int +.Fn dbm_store "DBM *db" "datum key" "datum data" "int flags" +.Ft datum +.Fn dbm_fetch "DBM *db" "datum key" +.Ft int +.Fn dbm_delete "DBM *db" "datum key" +.Ft datum +.Fn dbm_firstkey "DBM *db" +.Ft datum +.Fn dbm_nextkey "DBM *db" +.Ft int +.Fn dbm_error "DBM *db" +.Ft int +.Fn dbm_clearerr "DBM *db" +.Ft int +.Fn dbm_dirfno "DBM *db" +.Sh DESCRIPTION +Database access functions. +These functions are implemented using +.Xr dbopen 3 +with a +.Xr hash 3 +database. +.Pp +.Vt datum +is declared in +.Aq Pa ndbm.h : +.Bd -literal +typedef struct { + char *dptr; + int dsize; +} datum; +.Ed +.Pp +.Fn dbm_open base flags mode +opens or creates a database. +.Fa base +is the basename of the file containing +the database; the actual database has a +.Pa .db +suffix. +I.e., if +.Fa base +is +.Qq Li /home/me/mystuff +then the actual database is in the file +.Pa /home/me/mystuff.db . +.Fa flags +and +.Fa mode +are passed to +.Xr open 2 . +.Pq Dv O_RDWR | O_CREAT +is a typical value for +.Fa flags ; +.Li 0660 +is a typical value for +.Fa mode . +.Dv O_WRONLY +is not allowed in +.Fa flags . +The pointer returned by +.Fn dbm_open +identifies the database and is the +.Fa db +argument to the other functions. +.Fn dbm_open +returns +.Dv NULL +and sets +.Va errno +if there were any errors. +.Pp +.Fn dbm_close db +closes the database. +.Fn dbm_close +normally returns zero. +.Pp +.Fn dbm_store db key data flags +inserts or replaces an entry in the database. +.Fa flags +is either +.Dv DBM_INSERT +or +.Dv DBM_REPLACE . +If +.Fa flags +is +.Dv DBM_INSERT +and the database already contains an entry for +.Fa key , +that entry is not replaced. +Otherwise the entry is replaced or inserted. +.Fn dbm_store +normally returns zero but returns 1 if the entry could not be +inserted (because +.Fa flags +is +.Dv DBM_INSERT , +and an entry with +.Fa key +already exists) or returns -1 and sets +.Va errno +if there were any errors. +.Pp +.Fn dbm_fetch db key +returns +.Dv NULL +or the +.Fa data +corresponding to +.Fa key . +.Pp +.Fn dbm_delete db key +deletes the entry for +.Fa key . +.Fn dbm_delete +normally returns zero but returns 1 if there was no entry with +.Fa key +in the database or returns -1 and sets +.Va errno +if there were any errors. +.Pp +.Fn dbm_firstkey db +returns the first key in the database. +.Fn dbm_nextkey db +returns subsequent keys. +.Fn db_firstkey +must be called before +.Fn dbm_nextkey . +The order in which keys are returned is unspecified and may appear +random. +.Fn dbm_nextkey +returns +.Dv NULL +after all keys have been returned. +.Pp +.Fn dbm_error db +returns the +.Va errno +value of the most recent error. +.Fn dbm_clearerr db +resets this value to 0 and returns 0. +.Pp +.Fn dbm_dirfno db +returns the file descriptor to the database. +.Sh SEE ALSO +.Xr open 2 , +.Xr dbopen 3 , +.Xr hash 3 +.Sh STANDARDS +These functions (except +.Fn dbm_dirfno ) +are included in the +.St -susv2 . diff --git a/db/man/dbopen.3 b/db/man/dbopen.3 new file mode 100644 index 0000000..f04c771 --- /dev/null +++ b/db/man/dbopen.3 @@ -0,0 +1,539 @@ +.\" Copyright (c) 1990, 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. +.\" +.\" @(#)dbopen.3 8.5 (Berkeley) 1/2/94 +.\" $FreeBSD: src/lib/libc/db/man/dbopen.3,v 1.5 2001/10/01 16:08:50 ru Exp $ +.\" +.Dd January 2, 1994 +.Dt DBOPEN 3 +.Os +.Sh NAME +.Nm dbopen +.Nd "database access methods" +.Sh SYNOPSIS +.In sys/types.h +.In limits.h +.In db.h +.Ft DB * +.Fn dbopen "const char *file" "int flags" "int mode" "DBTYPE type" "const void *openinfo" +.Sh DESCRIPTION +.Fn Dbopen +is the library interface to database files. +The supported file formats are btree, hashed and UNIX file oriented. +The btree format is a representation of a sorted, balanced tree structure. +The hashed format is an extensible, dynamic hashing scheme. +The flat-file format is a byte stream file with fixed or variable length +records. +The formats and file format specific information are described in detail +in their respective manual pages +.Xr btree 3 , +.Xr hash 3 +and +.Xr recno 3 . +.Pp +.Fn Dbopen +opens +.Fa file +for reading and/or writing. +Files never intended to be preserved on disk may be created by setting +the file parameter to +.Dv NULL . +.Pp +The +.Fa flags +and +.Fa mode +arguments +are as specified to the +.Xr open 2 +routine, however, only the +.Dv O_CREAT , O_EXCL , O_EXLOCK , O_NONBLOCK , +.Dv O_RDONLY , O_RDWR , O_SHLOCK +and +.Dv O_TRUNC +flags are meaningful. +(Note, opening a database file +.Dv O_WRONLY +is not possible.) +.\"Three additional options may be specified by +.\".Em or Ns 'ing +.\"them into the +.\".Fa flags +.\"argument. +.\".Bl -tag -width indent +.\".It Dv DB_LOCK +.\"Do the necessary locking in the database to support concurrent access. +.\"If concurrent access isn't needed or the database is read-only this +.\"flag should not be set, as it tends to have an associated performance +.\"penalty. +.\".It Dv DB_SHMEM +.\"Place the underlying memory pool used by the database in shared +.\"memory. +.\"Necessary for concurrent access. +.\".It Dv DB_TXN +.\"Support transactions in the database. +.\"The +.\".Dv DB_LOCK +.\"and +.\".Dv DB_SHMEM +.\"flags must be set as well. +.\".El +.Pp +The +.Fa type +argument is of type +.Ft DBTYPE +(as defined in the +.Aq Pa db.h +include file) and +may be set to +.Dv DB_BTREE , DB_HASH +or +.Dv DB_RECNO . +.Pp +The +.Fa openinfo +argument is a pointer to an access method specific structure described +in the access method's manual page. +If +.Fa openinfo +is +.Dv NULL , +each access method will use defaults appropriate for the system +and the access method. +.Pp +.Fn Dbopen +returns a pointer to a +.Ft DB +structure on success and +.Dv NULL +on error. +The +.Ft DB +structure is defined in the +.Aq Pa db.h +include file, and contains at +least the following fields: +.Bd -literal +typedef struct { + DBTYPE type; + int (*close)(const DB *db); + int (*del)(const DB *db, const DBT *key, u_int flags); + int (*fd)(const DB *db); + int (*get)(const DB *db, DBT *key, DBT *data, u_int flags); + int (*put)(const DB *db, DBT *key, const DBT *data, + u_int flags); + int (*sync)(const DB *db, u_int flags); + int (*seq)(const DB *db, DBT *key, DBT *data, u_int flags); +} DB; +.Ed +.Pp +These elements describe a database type and a set of functions performing +various actions. +These functions take a pointer to a structure as returned by +.Fn dbopen , +and sometimes one or more pointers to key/data structures and a flag value. +.Bl -tag -width indent +.It Va type +The type of the underlying access method (and file format). +.It Va close +A pointer to a routine to flush any cached information to disk, free any +allocated resources, and close the underlying file(s). +Since key/data pairs may be cached in memory, failing to sync the file +with a +.Va close +or +.Va sync +function may result in inconsistent or lost information. +.Va Close +routines return -1 on error (setting +.Va errno ) +and 0 on success. +.It Va del +A pointer to a routine to remove key/data pairs from the database. +.Pp +The parameter +.Fa flags +may be set to the following value: +.Bl -tag -width indent +.It Dv R_CURSOR +Delete the record referenced by the cursor. +The cursor must have previously been initialized. +.El +.Pp +.Va Delete +routines return -1 on error (setting +.Va errno ) , +0 on success, and 1 if the specified +.Fa key +was not in the file. +.It Va fd +A pointer to a routine which returns a file descriptor representative +of the underlying database. +A file descriptor referencing the same file will be returned to all +processes which call +.Fn dbopen +with the same +.Fa file +name. +This file descriptor may be safely used as an argument to the +.Xr fcntl 2 +and +.Xr flock 2 +locking functions. +The file descriptor is not necessarily associated with any of the +underlying files used by the access method. +No file descriptor is available for in memory databases. +.Va \&Fd +routines return -1 on error (setting +.Va errno ) , +and the file descriptor on success. +.It Va get +A pointer to a routine which is the interface for keyed retrieval from +the database. +The address and length of the data associated with the specified +.Fa key +are returned in the structure referenced by +.Fa data . +.Va Get +routines return -1 on error (setting +.Va errno ) , +0 on success, and 1 if the +.Fa key +was not in the file. +.It Va put +A pointer to a routine to store key/data pairs in the database. +.Pp +The parameter +.Fa flags +may be set to one of the following values: +.Bl -tag -width indent +.It Dv R_CURSOR +Replace the key/data pair referenced by the cursor. +The cursor must have previously been initialized. +.It Dv R_IAFTER +Append the data immediately after the data referenced by +.Fa key , +creating a new key/data pair. +The record number of the appended key/data pair is returned in the +.Fa key +structure. +(Applicable only to the +.Dv DB_RECNO +access method.) +.It Dv R_IBEFORE +Insert the data immediately before the data referenced by +.Fa key , +creating a new key/data pair. +The record number of the inserted key/data pair is returned in the +.Fa key +structure. +(Applicable only to the +.Dv DB_RECNO +access method.) +.It Dv R_NOOVERWRITE +Enter the new key/data pair only if the key does not previously exist. +.It Dv R_SETCURSOR +Store the key/data pair, setting or initializing the position of the +cursor to reference it. +(Applicable only to the +.Dv DB_BTREE +and +.Dv DB_RECNO +access methods.) +.El +.Pp +.Dv R_SETCURSOR +is available only for the +.Dv DB_BTREE +and +.Dv DB_RECNO +access +methods because it implies that the keys have an inherent order +which does not change. +.Pp +.Dv R_IAFTER +and +.Dv R_IBEFORE +are available only for the +.Dv DB_RECNO +access method because they each imply that the access method is able to +create new keys. +This is only true if the keys are ordered and independent, record numbers +for example. +.Pp +The default behavior of the +.Va put +routines is to enter the new key/data pair, replacing any previously +existing key. +.Pp +.Va Put +routines return -1 on error (setting +.Va errno ) , +0 on success, and 1 if the +.Dv R_NOOVERWRITE +flag +was set and the key already exists in the file. +.It Va seq +A pointer to a routine which is the interface for sequential +retrieval from the database. +The address and length of the key are returned in the structure +referenced by +.Fa key , +and the address and length of the data are returned in the +structure referenced +by +.Fa data . +.Pp +Sequential key/data pair retrieval may begin at any time, and the +position of the +.Dq cursor +is not affected by calls to the +.Va del , +.Va get , +.Va put , +or +.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 +while records inserted in front of the cursor will be returned. +.Pp +The +.Fa flags +value +.Em must +be set to one of the following values: +.Bl -tag -width indent +.It Dv R_CURSOR +The data associated with the specified key is returned. +This differs from the +.Va get +routines in that it sets or initializes the cursor to the location of +the key as well. +(Note, for the +.Dv DB_BTREE +access method, the returned key is not necessarily an +exact match for the specified key. +The returned key is the smallest key greater than or equal to the specified +key, permitting partial key matches and range searches.) +.It Dv R_FIRST +The first key/data pair of the database is returned, and the cursor +is set or initialized to reference it. +.It Dv R_LAST +The last key/data pair of the database is returned, and the cursor +is set or initialized to reference it. +(Applicable only to the +.Dv DB_BTREE +and +.Dv DB_RECNO +access methods.) +.It Dv R_NEXT +Retrieve the key/data pair immediately after the cursor. +If the cursor is not yet set, this is the same as the +.Dv R_FIRST +flag. +.It Dv R_PREV +Retrieve the key/data pair immediately before the cursor. +If the cursor is not yet set, this is the same as the +.Dv R_LAST +flag. +(Applicable only to the +.Dv DB_BTREE +and +.Dv DB_RECNO +access methods.) +.El +.Pp +.Dv R_LAST +and +.Dv R_PREV +are available only for the +.Dv DB_BTREE +and +.Dv DB_RECNO +access methods because they each imply that the keys have an inherent +order which does not change. +.Pp +.Va Seq +routines return -1 on error (setting +.Va errno ) , +0 on success and 1 if there are no key/data pairs less than or greater +than the specified or current key. +If the +.Dv DB_RECNO +access method is being used, and if the database file +is a character special file and no complete key/data pairs are currently +available, the +.Va seq +routines return 2. +.It Va sync +A pointer to a routine to flush any cached information to disk. +If the database is in memory only, the +.Va sync +routine has no effect and will always succeed. +.Pp +The +.Fa flags +value may be set to the following value: +.Bl -tag -width indent +.It Dv R_RECNOSYNC +If the +.Dv DB_RECNO +access method is being used, this flag causes +the +.Va sync +routine to apply to the btree file which underlies the +recno file, not the recno file itself. +(See the +.Va bfname +field of the +.Xr recno 3 +manual page for more information.) +.El +.Pp +.Va Sync +routines return -1 on error (setting +.Va errno ) +and 0 on success. +.El +.Sh "KEY/DATA PAIRS" +Access to all file types is based on key/data pairs. +Both keys and data are represented by the following data structure: +.Bd -literal +typedef struct { + void *data; + size_t size; +} DBT; +.Ed +.Pp +The elements of the +.Ft DBT +structure are defined as follows: +.Bl -tag -width "data" +.It Va data +A pointer to a byte string. +.It Va size +The length of the byte string. +.El +.Pp +Key and data byte strings may reference strings of essentially unlimited +length although any two of them must fit into available memory at the same +time. +It should be noted that the access methods provide no guarantees about +byte string alignment. +.Sh ERRORS +The +.Fn dbopen +routine may fail and set +.Va errno +for any of the errors specified for the library routines +.Xr open 2 +and +.Xr malloc 3 +or the following: +.Bl -tag -width Er +.It Bq Er EFTYPE +A file is incorrectly formatted. +.It Bq Er EINVAL +A parameter has been specified (hash function, pad byte etc.) that is +incompatible with the current file specification or which is not +meaningful for the function (for example, use of the cursor without +prior initialization) or there is a mismatch between the version +number of file and the software. +.El +.Pp +The +.Va close +routines may fail and set +.Va errno +for any of the errors specified for the library routines +.Xr close 2 , +.Xr read 2 , +.Xr write 2 , +.Xr free 3 , +or +.Xr fsync 2 . +.Pp +The +.Va del , +.Va get , +.Va put +and +.Va seq +routines may fail and set +.Va errno +for any of the errors specified for the library routines +.Xr read 2 , +.Xr write 2 , +.Xr free 3 +or +.Xr malloc 3 . +.Pp +The +.Va fd +routines will fail and set +.Va errno +to +.Er ENOENT +for in memory databases. +.Pp +The +.Va sync +routines may fail and set +.Va errno +for any of the errors specified for the library routine +.Xr fsync 2 . +.Sh SEE ALSO +.Xr btree 3 , +.Xr hash 3 , +.Xr mpool 3 , +.Xr recno 3 +.Rs +.%T "LIBTP: Portable, Modular Transactions for UNIX" +.%A Margo Seltzer +.%A Michael Olson +.%R "USENIX proceedings" +.%D Winter 1992 +.Re +.Sh BUGS +The typedef +.Ft DBT +is a mnemonic for +.Dq "data base thang" , +and was used +because noone could think of a reasonable name that wasn't already used. +.Pp +The file descriptor interface is a kluge and will be deleted in a +future version of the interface. +.Pp +None of the access methods provide any form of concurrent access, +locking, or transactions. diff --git a/db/man/hash.3 b/db/man/hash.3 new file mode 100644 index 0000000..f51bb06 --- /dev/null +++ b/db/man/hash.3 @@ -0,0 +1,191 @@ +.\" Copyright (c) 1990, 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. +.\" +.\" @(#)hash.3 8.6 (Berkeley) 8/18/94 +.\" $FreeBSD: src/lib/libc/db/man/hash.3,v 1.6 2001/10/01 16:08:50 ru Exp $ +.\" +.Dd August 18, 1994 +.Dt HASH 3 +.Os +.Sh NAME +.Nm hash +.Nd "hash database access method" +.Sh SYNOPSIS +.In sys/types.h +.In db.h +.Sh DESCRIPTION +The routine +.Fn dbopen +is the library interface to database files. +One of the supported file formats is +.Nm +files. +The general description of the database access methods is in +.Xr dbopen 3 , +this manual page describes only the +.Nm +specific information. +.Pp +The +.Nm +data structure is an extensible, dynamic hashing scheme. +.Pp +The access method specific data structure provided to +.Fn dbopen +is defined in the +.Aq Pa db.h +include file as follows: +.Bd -literal +typedef struct { + u_int bsize; + u_int ffactor; + u_int nelem; + u_int cachesize; + u_int32_t (*hash)(const void *, size_t); + int lorder; +} HASHINFO; +.Ed +.Pp +The elements of this structure are as follows: +.Bl -tag -width indent +.It Va bsize +.Va Bsize +defines the +.Nm +table bucket size, and is, by default, 256 bytes. +It may be preferable to increase the page size for disk-resident tables +and tables with large data items. +.It Va ffactor +.Va Ffactor +indicates a desired density within the +.Nm +table. +It is an approximation of the number of keys allowed to accumulate in any +one bucket, determining when the +.Nm +table grows or shrinks. +The default value is 8. +.It Va nelem +.Va Nelem +is an estimate of the final size of the +.Nm +table. +If not set or set too low, +.Nm +tables will expand gracefully as keys +are entered, although a slight performance degradation may be noticed. +The default value is 1. +.It Va cachesize +A suggested maximum size, in bytes, of the memory cache. +This value is +.Em only +advisory, and the access method will allocate more memory rather +than fail. +.It Va hash +.Va Hash +is a user defined +.Nm +function. +Since no +.Nm +function performs equally well on all possible data, the +user may find that the built-in +.Nm +function does poorly on a particular +data set. +User specified +.Nm +functions must take two arguments (a pointer to a byte +string and a length) and return a 32-bit quantity to be used as the +.Nm +value. +.It Va lorder +The byte order for integers in the stored database metadata. +The number should represent the order as an integer; for example, +big endian order would be the number 4,321. +If +.Va lorder +is 0 (no order is specified) the current host order is used. +If the file already exists, the specified value is ignored and the +value specified when the tree was created is used. +.El +.Pp +If the file already exists (and the +.Dv O_TRUNC +flag is not specified), the +values specified for the parameters +.Va bsize , ffactor , lorder +and +.Va nelem +are +ignored and the values specified when the tree was created are used. +.Pp +If a +.Nm +function is specified, +.Fn hash_open +will attempt to determine if the +.Nm +function specified is the same as +the one with which the database was created, and will fail if it is not. +.Pp +Backward compatible interfaces to the older +.Em dbm +and +.Em ndbm +routines are provided, however these interfaces are not compatible with +previous file formats. +.Sh ERRORS +The +.Nm +access method routines may fail and set +.Va errno +for any of the errors specified for the library routine +.Xr dbopen 3 . +.Sh SEE ALSO +.Xr btree 3 , +.Xr dbopen 3 , +.Xr mpool 3 , +.Xr recno 3 +.Rs +.%T "Dynamic Hash Tables" +.%A Per-Ake Larson +.%R "Communications of the ACM" +.%D April 1988 +.Re +.Rs +.%T "A New Hash Package for UNIX" +.%A Margo Seltzer +.%R "USENIX Proceedings" +.%D Winter 1991 +.Re +.Sh BUGS +Only big and little endian byte order is supported. diff --git a/db/man/mpool.3 b/db/man/mpool.3 new file mode 100644 index 0000000..36c91e1 --- /dev/null +++ b/db/man/mpool.3 @@ -0,0 +1,238 @@ +.\" Copyright (c) 1990, 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. +.\" +.\" @(#)mpool.3 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD: src/lib/libc/db/man/mpool.3,v 1.9 2001/10/01 16:08:50 ru Exp $ +.\" +.Dd June 4, 1993 +.Dt MPOOL 3 +.Os +.Sh NAME +.Nm mpool +.Nd "shared memory buffer pool" +.Sh SYNOPSIS +.In db.h +.In mpool.h +.Ft MPOOL * +.Fn mpool_open "void *key" "int fd" "pgno_t pagesize" "pgno_t maxcache" +.Ft void +.Fo mpool_filter +.Fa "MPOOL *mp" +.Fa "void (*pgin)(void *, pgno_t, void *)" +.Fa "void (*pgout)(void *, pgno_t, void *)" +.Fa "void *pgcookie" +.Fc +.Ft void * +.Fn mpool_new "MPOOL *mp" "pgno_t *pgnoaddr" +.Ft void * +.Fn mpool_get "MPOOL *mp" "pgno_t pgno" "u_int flags" +.Ft int +.Fn mpool_put "MPOOL *mp" "void *pgaddr" "u_int flags" +.Ft int +.Fn mpool_sync "MPOOL *mp" +.Ft int +.Fn mpool_close "MPOOL *mp" +.Sh DESCRIPTION +.Nm Mpool +is the library interface intended to provide page oriented buffer management +of files. +The buffers may be shared between processes. +.Pp +The function +.Fn mpool_open +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. +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 +argument is the size, in bytes, of the pages into which the file is broken up. +The +.Fa maxcache +argument is the maximum number of pages from the underlying file to cache +at any one time. +This value is not relative to the number of processes which share a file's +buffers, but will be the largest value specified by any of the processes +sharing the file. +.Pp +The +.Fn mpool_filter +function is intended to make transparent input and output processing of the +pages possible. +If the +.Fa pgin +function is specified, it is called each time a buffer is read into the memory +pool from the backing file. +If the +.Fa pgout +function is specified, it is called each time a buffer is written into the +backing file. +Both functions are called with the +.Fa pgcookie +pointer, the page number and a pointer to the page to being read or written. +.Pp +The function +.Fn mpool_new +takes an +.Ft MPOOL +pointer and an address as arguments. +If a new page can be allocated, a pointer to the page is returned and +the page number is stored into the +.Fa pgnoaddr +address. +Otherwise, +.Dv NULL +is returned and +.Va errno +is set. +.Pp +The function +.Fn mpool_get +takes a +.Ft MPOOL +pointer and a page number as arguments. +If the page exists, a pointer to the page is returned. +Otherwise, +.Dv NULL +is returned and +.Va errno +is set. +The +.Fa flags +parameter is not currently used. +.Pp +The function +.Fn mpool_put +unpins the page referenced by +.Fa pgaddr . +.Fa Pgaddr +must be an address previously returned by +.Fn mpool_get +or +.Fn mpool_new . +The +.Fa flags +value is specified by +.Em or Ns 'ing +any of the following values: +.Bl -tag -width indent +.It Dv MPOOL_DIRTY +The page has been modified and needs to be written to the backing file. +.El +.Pp +.Fn Mpool_put +returns 0 on success and -1 if an error occurs. +.Pp +The function +.Fn mpool_sync +writes all modified pages associated with the +.Ft MPOOL +pointer to the +backing file. +.Fn Mpool_sync +returns 0 on success and -1 if an error occurs. +.Pp +The +.Fn mpool_close +function free's up any allocated memory associated with the memory pool +cookie. +Modified pages are +.Em not +written to the backing file. +.Fn Mpool_close +returns 0 on success and -1 if an error occurs. +.Sh ERRORS +The +.Fn mpool_open +function may fail and set +.Va errno +for any of the errors specified for the library routine +.Xr malloc 3 . +.Pp +The +.Fn mpool_get +function may fail and set +.Va errno +for the following: +.Bl -tag -width Er +.It Bq Er EINVAL +The requested record doesn't exist. +.El +.Pp +The +.Fn mpool_new +and +.Fn mpool_get +functions may fail and set +.Va errno +for any of the errors specified for the library routines +.Xr read 2 , +.Xr write 2 , +and +.Xr malloc 3 . +.Pp +The +.Fn mpool_sync +function may fail and set +.Va errno +for any of the errors specified for the library routine +.Xr write 2 . +.Pp +The +.Fn mpool_close +function may fail and set +.Va errno +for any of the errors specified for the library routine +.Xr free 3 . +.Sh SEE ALSO +.Xr btree 3 , +.Xr dbopen 3 , +.Xr hash 3 , +.Xr recno 3 diff --git a/db/man/recno.3 b/db/man/recno.3 new file mode 100644 index 0000000..7f069cf --- /dev/null +++ b/db/man/recno.3 @@ -0,0 +1,232 @@ +.\" Copyright (c) 1990, 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. +.\" +.\" @(#)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 $ +.\" +.Dd August 18, 1994 +.Dt RECNO 3 +.Os +.Sh NAME +.Nm recno +.Nd "record number database access method" +.Sh SYNOPSIS +.In sys/types.h +.In db.h +.Sh DESCRIPTION +The routine +.Fn dbopen +is the library interface to database files. +One of the supported file formats is record number files. +The general description of the database access methods is in +.Xr dbopen 3 , +this manual page describes only the +.Nm +specific information. +.Pp +The record number data structure is either variable or fixed-length +records stored in a flat-file format, accessed by the logical record +number. +The existence of record number five implies the existence of records +one through four, and the deletion of record number one causes +record number five to be renumbered to record number four, as well +as the cursor, if positioned after record number one, to shift down +one record. +.Pp +The +.Nm +access method specific data structure provided to +.Fn dbopen +is defined in the +.Aq Pa db.h +include file as follows: +.Bd -literal +typedef struct { + u_long flags; + u_int cachesize; + u_int psize; + int lorder; + size_t reclen; + u_char bval; + char *bfname; +} RECNOINFO; +.Ed +.Pp +The elements of this structure are defined as follows: +.Bl -tag -width indent +.It Va flags +The flag value is specified by +.Em or Ns 'ing +any of the following values: +.Bl -tag -width indent +.It Dv R_FIXEDLEN +The records are fixed-length, not byte delimited. +The structure element +.Va reclen +specifies the length of the record, and the structure element +.Va bval +is used as the pad character. +Any records, inserted into the database, that are less than +.Va reclen +bytes long are automatically padded. +.It Dv R_NOKEY +In the interface specified by +.Fn dbopen , +the sequential record retrieval fills in both the caller's key and +data structures. +If the +.Dv R_NOKEY +flag is specified, the +.Em cursor +routines are not required to fill in the key structure. +This permits applications to retrieve records at the end of files without +reading all of the intervening records. +.It Dv R_SNAPSHOT +This flag requires that a snapshot of the file be taken when +.Fn dbopen +is called, instead of permitting any unmodified records to be read from +the original file. +.El +.It Va cachesize +A suggested maximum size, in bytes, of the memory cache. +This value is +.Em only +advisory, and the access method will allocate more memory rather than fail. +If +.Va cachesize +is 0 (no size is specified) a default cache is used. +.It Va psize +The +.Nm +access method stores the in-memory copies of its records +in a btree. +This value is the size (in bytes) of the pages used for nodes in that tree. +If +.Va psize +is 0 (no page size is specified) a page size is chosen based on the +underlying file system I/O block size. +See +.Xr btree 3 +for more information. +.It Va lorder +The byte order for integers in the stored database metadata. +The number should represent the order as an integer; for example, +big endian order would be the number 4,321. +If +.Va lorder +is 0 (no order is specified) the current host order is used. +.It Va reclen +The length of a fixed-length record. +.It Va bval +The delimiting byte to be used to mark the end of a record for +variable-length records, and the pad character for fixed-length +records. +If no value is specified, newlines +.Pq Dq \en +are used to mark the end +of variable-length records and fixed-length records are padded with +spaces. +.It Va bfname +The +.Nm +access method stores the in-memory copies of its records +in a btree. +If +.Va bfname +is +.No non\- Ns Dv NULL , +it specifies the name of the btree file, +as if specified as the file name for a +.Fn dbopen +of a btree file. +.El +.Pp +The data part of the key/data pair used by the +.Nm +access method +is the same as other access methods. +The key is different. +The +.Va data +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 +include file. +This type is normally the largest unsigned integral type available to +the implementation. +The +.Va size +field of the key should be the size of that type. +.Pp +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 +specified each time the file is opened. +.Pp +In the interface specified by +.Fn dbopen , +using the +.Va put +interface to create a new record will cause the creation of multiple, +empty records if the record number is more than one greater than the +largest record currently in the database. +.Sh ERRORS +The +.Nm +access method routines may fail and set +.Va errno +for any of the errors specified for the library routine +.Xr dbopen 3 +or the following: +.Bl -tag -width Er +.It Bq Er EINVAL +An attempt was made to add a record to a fixed-length database that +was too large to fit. +.El +.Sh SEE ALSO +.Xr btree 3 , +.Xr dbopen 3 , +.Xr hash 3 , +.Xr mpool 3 +.Rs +.%T "Document Processing in a Relational Database System" +.%A Michael Stonebraker +.%A Heidi Stettner +.%A Joseph Kalash +.%A Antonin Guttman +.%A Nadene Lynn +.%R "Memorandum No. UCB/ERL M82/32" +.%D May 1982 +.Re +.Sh BUGS +Only big and little endian byte order is supported. diff --git a/db/mpool/Makefile.inc b/db/mpool/Makefile.inc new file mode 100644 index 0000000..4438d14 --- /dev/null +++ b/db/mpool/Makefile.inc @@ -0,0 +1,6 @@ +# from @(#)Makefile.inc 8.1 (Berkeley) 6/4/93 +# $FreeBSD: src/lib/libc/db/mpool/Makefile.inc,v 1.3 1999/08/27 23:58:23 peter Exp $ + +.PATH: ${.CURDIR}/db/mpool + +SRCS+= mpool.c diff --git a/db/mpool/mpool.c b/db/mpool/mpool.c new file mode 100644 index 0000000..d3e9e2e --- /dev/null +++ b/db/mpool/mpool.c @@ -0,0 +1,552 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 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 +#include + +#include +#include +#include +#include +#include + +#include +#define __MPOOLINTERFACE_PRIVATE +#include "mpool.h" + +static BKT *mpool_bkt __P((MPOOL *)); +static BKT *mpool_look __P((MPOOL *, pgno_t)); +static int mpool_write __P((MPOOL *, BKT *)); +#ifdef DEBUG +static void __mpoolerr __P((const char *fmt, ...)); +#endif + +/* + * MPOOL_OPEN -- initialize a memory pool. + * + * Parameters: + * key: Shared buffer key. + * fd: File descriptor. + * pagesize: File page size. + * maxcache: Max number of cached pages. + * + * Returns: + * MPOOL pointer, NULL on error. + */ +MPOOL * +mpool_open(key, fd, pagesize, maxcache) + DBT *key; + int fd; + pgno_t pagesize, maxcache; +{ + struct stat sb; + MPOOL *mp; + int entry; + + if (fstat(fd, &sb)) + return (NULL); + /* XXX + * We should only set st_size to 0 for pipes -- 4.4BSD has the fix so + * that stat(2) returns true for ISSOCK on pipes. Until then, this is + * fairly close. + */ + if (!S_ISREG(sb.st_mode)) { + errno = ESPIPE; + return (NULL); + } + + if ((mp = (MPOOL *)malloc(sizeof(MPOOL))) == NULL) + return (NULL); + mp->free.cnext = mp->free.cprev = (BKT *)&mp->free; + mp->lru.cnext = mp->lru.cprev = (BKT *)&mp->lru; + for (entry = 0; entry < HASHSIZE; ++entry) + mp->hashtable[entry].hnext = mp->hashtable[entry].hprev = + mp->hashtable[entry].cnext = mp->hashtable[entry].cprev = + (BKT *)&mp->hashtable[entry]; + mp->curcache = 0; + mp->maxcache = maxcache; + mp->pagesize = pagesize; + mp->npages = sb.st_size / pagesize; + mp->fd = fd; + mp->pgcookie = NULL; + mp->pgin = mp->pgout = NULL; + +#ifdef STATISTICS + mp->cachehit = mp->cachemiss = mp->pagealloc = mp->pageflush = + mp->pageget = mp->pagenew = mp->pageput = mp->pageread = + mp->pagewrite = 0; +#endif + return (mp); +} + +/* + * MPOOL_FILTER -- initialize input/output filters. + * + * Parameters: + * pgin: Page in conversion routine. + * pgout: Page out conversion routine. + * pgcookie: Cookie for page in/out routines. + */ +void +mpool_filter(mp, pgin, pgout, pgcookie) + MPOOL *mp; + void (*pgin) __P((void *, pgno_t, void *)); + void (*pgout) __P((void *, pgno_t, void *)); + void *pgcookie; +{ + mp->pgin = pgin; + mp->pgout = pgout; + mp->pgcookie = pgcookie; +} + +/* + * MPOOL_NEW -- get a new page + * + * Parameters: + * mp: mpool cookie + * pgnoadddr: place to store new page number + * Returns: + * RET_ERROR, RET_SUCCESS + */ +void * +mpool_new(mp, pgnoaddr) + MPOOL *mp; + pgno_t *pgnoaddr; +{ + BKT *b; + BKTHDR *hp; + +#ifdef STATISTICS + ++mp->pagenew; +#endif + /* + * Get a BKT from the cache. Assign a new page number, attach it to + * the hash and lru chains and return. + */ + if ((b = mpool_bkt(mp)) == NULL) + return (NULL); + *pgnoaddr = b->pgno = mp->npages++; + b->flags = MPOOL_PINNED; + inshash(b, b->pgno); + inschain(b, &mp->lru); + return (b->page); +} + +/* + * MPOOL_GET -- get a page from the pool + * + * Parameters: + * mp: mpool cookie + * pgno: page number + * flags: not used + * + * Returns: + * RET_ERROR, RET_SUCCESS + */ +void * +mpool_get(mp, pgno, flags) + MPOOL *mp; + pgno_t pgno; + u_int flags; /* XXX not used? */ +{ + BKT *b; + BKTHDR *hp; + off_t off; + int nr; + + /* + * If asking for a specific page that is already in the cache, find + * it and return it. + */ + if (b = mpool_look(mp, pgno)) { +#ifdef STATISTICS + ++mp->pageget; +#endif +#ifdef DEBUG + if (b->flags & MPOOL_PINNED) + __mpoolerr("mpool_get: page %d already pinned", + b->pgno); +#endif + rmchain(b); + inschain(b, &mp->lru); + b->flags |= MPOOL_PINNED; + return (b->page); + } + + /* Not allowed to retrieve a non-existent page. */ + if (pgno >= mp->npages) { + errno = EINVAL; + return (NULL); + } + + /* Get a page from the cache. */ + if ((b = mpool_bkt(mp)) == NULL) + return (NULL); + b->pgno = pgno; + b->flags = MPOOL_PINNED; + +#ifdef STATISTICS + ++mp->pageread; +#endif + /* Read in the contents. */ + off = mp->pagesize * pgno; + if (lseek(mp->fd, off, SEEK_SET) != off) + return (NULL); + if ((nr = read(mp->fd, b->page, mp->pagesize)) != mp->pagesize) { + if (nr >= 0) + errno = EFTYPE; + return (NULL); + } + if (mp->pgin) + (mp->pgin)(mp->pgcookie, b->pgno, b->page); + + inshash(b, b->pgno); + inschain(b, &mp->lru); +#ifdef STATISTICS + ++mp->pageget; +#endif + return (b->page); +} + +/* + * MPOOL_PUT -- return a page to the pool + * + * Parameters: + * mp: mpool cookie + * page: page pointer + * pgno: page number + * + * Returns: + * RET_ERROR, RET_SUCCESS + */ +int +mpool_put(mp, page, flags) + MPOOL *mp; + void *page; + u_int flags; +{ + BKT *baddr; +#ifdef DEBUG + BKT *b; +#endif + +#ifdef STATISTICS + ++mp->pageput; +#endif + baddr = (BKT *)((char *)page - sizeof(BKT)); +#ifdef DEBUG + if (!(baddr->flags & MPOOL_PINNED)) + __mpoolerr("mpool_put: page %d not pinned", b->pgno); + for (b = mp->lru.cnext; b != (BKT *)&mp->lru; b = b->cnext) { + if (b == (BKT *)&mp->lru) + __mpoolerr("mpool_put: %0x: bad address", baddr); + if (b == baddr) + break; + } +#endif + baddr->flags &= ~MPOOL_PINNED; + baddr->flags |= flags & MPOOL_DIRTY; + return (RET_SUCCESS); +} + +/* + * MPOOL_CLOSE -- close the buffer pool + * + * Parameters: + * mp: mpool cookie + * + * Returns: + * RET_ERROR, RET_SUCCESS + */ +int +mpool_close(mp) + MPOOL *mp; +{ + BKT *b, *next; + + /* Free up any space allocated to the lru pages. */ + for (b = mp->lru.cprev; b != (BKT *)&mp->lru; b = next) { + next = b->cprev; + free(b); + } + free(mp); + return (RET_SUCCESS); +} + +/* + * MPOOL_SYNC -- sync the file to disk. + * + * Parameters: + * mp: mpool cookie + * + * Returns: + * RET_ERROR, RET_SUCCESS + */ +int +mpool_sync(mp) + MPOOL *mp; +{ + BKT *b; + + for (b = mp->lru.cprev; b != (BKT *)&mp->lru; b = b->cprev) + if (b->flags & MPOOL_DIRTY && mpool_write(mp, b) == RET_ERROR) + return (RET_ERROR); + return (fsync(mp->fd) ? RET_ERROR : RET_SUCCESS); +} + +/* + * MPOOL_BKT -- get/create a BKT from the cache + * + * Parameters: + * mp: mpool cookie + * + * Returns: + * NULL on failure and a pointer to the BKT on success + */ +static BKT * +mpool_bkt(mp) + MPOOL *mp; +{ + BKT *b; + + if (mp->curcache < mp->maxcache) + goto new; + + /* + * If the cache is maxxed out, search the lru list for a buffer we + * can flush. If we find one, write it if necessary and take it off + * any lists. If we don't find anything we grow the cache anyway. + * The cache never shrinks. + */ + for (b = mp->lru.cprev; b != (BKT *)&mp->lru; b = b->cprev) + if (!(b->flags & MPOOL_PINNED)) { + if (b->flags & MPOOL_DIRTY && + mpool_write(mp, b) == RET_ERROR) + return (NULL); + rmhash(b); + rmchain(b); +#ifdef STATISTICS + ++mp->pageflush; +#endif +#ifdef DEBUG + { + void *spage; + spage = b->page; + memset(b, 0xff, sizeof(BKT) + mp->pagesize); + b->page = spage; + } +#endif + return (b); + } + +new: if ((b = (BKT *)malloc(sizeof(BKT) + mp->pagesize)) == NULL) + return (NULL); +#ifdef STATISTICS + ++mp->pagealloc; +#endif +#ifdef DEBUG + memset(b, 0xff, sizeof(BKT) + mp->pagesize); +#endif + b->page = (char *)b + sizeof(BKT); + ++mp->curcache; + return (b); +} + +/* + * MPOOL_WRITE -- sync a page to disk + * + * Parameters: + * mp: mpool cookie + * + * Returns: + * RET_ERROR, RET_SUCCESS + */ +static int +mpool_write(mp, b) + MPOOL *mp; + BKT *b; +{ + off_t off; + + if (mp->pgout) + (mp->pgout)(mp->pgcookie, b->pgno, b->page); + +#ifdef STATISTICS + ++mp->pagewrite; +#endif + off = mp->pagesize * b->pgno; + if (lseek(mp->fd, off, SEEK_SET) != off) + return (RET_ERROR); + if (write(mp->fd, b->page, mp->pagesize) != mp->pagesize) + return (RET_ERROR); + b->flags &= ~MPOOL_DIRTY; + return (RET_SUCCESS); +} + +/* + * MPOOL_LOOK -- lookup a page + * + * Parameters: + * mp: mpool cookie + * pgno: page number + * + * Returns: + * NULL on failure and a pointer to the BKT on success + */ +static BKT * +mpool_look(mp, pgno) + MPOOL *mp; + pgno_t pgno; +{ + register BKT *b; + register BKTHDR *tb; + + /* XXX + * If find the buffer, put it first on the hash chain so can + * find it again quickly. + */ + tb = &mp->hashtable[HASHKEY(pgno)]; + for (b = tb->hnext; b != (BKT *)tb; b = b->hnext) + if (b->pgno == pgno) { +#ifdef STATISTICS + ++mp->cachehit; +#endif + return (b); + } +#ifdef STATISTICS + ++mp->cachemiss; +#endif + return (NULL); +} + +#ifdef STATISTICS +/* + * MPOOL_STAT -- cache statistics + * + * Parameters: + * mp: mpool cookie + */ +void +mpool_stat(mp) + MPOOL *mp; +{ + BKT *b; + int cnt; + char *sep; + + (void)fprintf(stderr, "%lu pages in the file\n", mp->npages); + (void)fprintf(stderr, + "page size %lu, cacheing %lu pages of %lu 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); + (void)fprintf(stderr, "%lu page allocs, %lu page flushes\n", + mp->pagealloc, mp->pageflush); + if (mp->cachehit + mp->cachemiss) + (void)fprintf(stderr, + "%.0f%% cache hit rate (%lu hits, %lu misses)\n", + ((double)mp->cachehit / (mp->cachehit + mp->cachemiss)) + * 100, mp->cachehit, mp->cachemiss); + (void)fprintf(stderr, "%lu page reads, %lu page writes\n", + mp->pageread, mp->pagewrite); + + sep = ""; + cnt = 0; + for (b = mp->lru.cnext; b != (BKT *)&mp->lru; b = b->cnext) { + (void)fprintf(stderr, "%s%d", sep, b->pgno); + if (b->flags & MPOOL_DIRTY) + (void)fprintf(stderr, "d"); + if (b->flags & MPOOL_PINNED) + (void)fprintf(stderr, "P"); + if (++cnt == 10) { + sep = "\n"; + cnt = 0; + } else + sep = ", "; + + } + (void)fprintf(stderr, "\n"); +} +#endif + +#ifdef DEBUG +#if __STDC__ +#include +#else +#include +#endif + +static void +#if __STDC__ +__mpoolerr(const char *fmt, ...) +#else +__mpoolerr(fmt, va_alist) + char *fmt; + va_dcl +#endif +{ + va_list ap; +#if __STDC__ + va_start(ap, fmt); +#else + va_start(ap); +#endif + (void)vfprintf(stderr, fmt, ap); + va_end(ap); + (void)fprintf(stderr, "\n"); + abort(); + /* NOTREACHED */ +} +#endif diff --git a/db/recno/Makefile.inc b/db/recno/Makefile.inc new file mode 100644 index 0000000..63ff12a --- /dev/null +++ b/db/recno/Makefile.inc @@ -0,0 +1,9 @@ +# from @(#)Makefile.inc 8.1 (Berkeley) 6/4/93 +# $FreeBSD: src/lib/libc/db/recno/Makefile.inc,v 1.3 1999/08/27 23:58:25 peter Exp $ + +.PATH: ${.CURDIR}/db/recno + +CFLAGS+= -I${.CURDIR}/db/btree + +SRCS+= rec_close.c rec_delete.c rec_get.c rec_open.c rec_put.c rec_search.c \ + rec_seq.c rec_utils.c diff --git a/db/recno/extern.h b/db/recno/extern.h new file mode 100644 index 0000000..d903770 --- /dev/null +++ b/db/recno/extern.h @@ -0,0 +1,73 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * 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. + */ + +#include "bt_extern.h" + +int __rec_close __P((DB *)); +int __rec_delete __P((const DB *, const DBT *, u_int)); +int __rec_dleaf __P((BTREE *, PAGE *, indx_t)); +int __rec_fd __P((const DB *)); +int __rec_fmap __P((BTREE *, recno_t)); +int __rec_fout __P((BTREE *)); +int __rec_fpipe __P((BTREE *, recno_t)); +int __rec_get __P((const DB *, const DBT *, DBT *, u_int)); +int __rec_iput __P((BTREE *, recno_t, const DBT *, u_int)); +int __rec_put __P((const DB *dbp, DBT *, const DBT *, u_int)); +int __rec_ret __P((BTREE *, EPG *, recno_t, DBT *, DBT *)); +EPG *__rec_search __P((BTREE *, recno_t, enum SRCHOP)); +int __rec_seq __P((const DB *, DBT *, DBT *, u_int)); +int __rec_sync __P((const DB *, u_int)); +int __rec_vmap __P((BTREE *, recno_t)); +int __rec_vout __P((BTREE *)); +int __rec_vpipe __P((BTREE *, recno_t)); diff --git a/db/recno/rec_close.c b/db/recno/rec_close.c new file mode 100644 index 0000000..7c57f5f --- /dev/null +++ b/db/recno/rec_close.c @@ -0,0 +1,183 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 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 +#include + +#include + +#include +#include +#include +#include + +#include +#include "recno.h" + +/* + * __REC_CLOSE -- Close a recno tree. + * + * Parameters: + * dbp: pointer to access method + * + * Returns: + * RET_ERROR, RET_SUCCESS + */ +int +__rec_close(dbp) + DB *dbp; +{ + BTREE *t; + int status; + + t = dbp->internal; + + /* Toss any page pinned across calls. */ + if (t->bt_pinned != NULL) { + mpool_put(t->bt_mp, t->bt_pinned, 0); + t->bt_pinned = NULL; + } + + if (__rec_sync(dbp, 0) == RET_ERROR) + return (RET_ERROR); + + /* Committed to closing. */ + status = RET_SUCCESS; + if (ISSET(t, R_MEMMAPPED) + && vm_deallocate(mach_task_self(), (vm_offset_t) t->bt_smap, t->bt_msize)) + status = RET_ERROR; + + if (!ISSET(t, R_INMEM)) + if (ISSET(t, R_CLOSEFP)) { + if (fclose(t->bt_rfp)) + status = RET_ERROR; + } else + if (close(t->bt_rfd)) + status = RET_ERROR; + + if (__bt_close(dbp) == RET_ERROR) + status = RET_ERROR; + + return (status); +} + +/* + * __REC_SYNC -- sync the recno tree to disk. + * + * Parameters: + * dbp: pointer to access method + * + * Returns: + * RET_SUCCESS, RET_ERROR. + */ +int +__rec_sync(dbp, flags) + const DB *dbp; + u_int flags; +{ + struct iovec iov[2]; + BTREE *t; + DBT data, key; + off_t off; + recno_t scursor, trec; + int status; + + t = dbp->internal; + + /* Toss any page pinned across calls. */ + if (t->bt_pinned != NULL) { + mpool_put(t->bt_mp, t->bt_pinned, 0); + t->bt_pinned = NULL; + } + + if (flags == R_RECNOSYNC) + return (__bt_sync(dbp, 0)); + + if (ISSET(t, R_RDONLY | R_INMEM) || !ISSET(t, R_MODIFIED)) + return (RET_SUCCESS); + + /* Read any remaining records into the tree. */ + if (!ISSET(t, R_EOF) && t->bt_irec(t, MAX_REC_NUMBER) == RET_ERROR) + return (RET_ERROR); + + /* Rewind the file descriptor. */ + if (lseek(t->bt_rfd, (off_t)0, SEEK_SET) != 0) + return (RET_ERROR); + + iov[1].iov_base = "\n"; + iov[1].iov_len = 1; + scursor = t->bt_rcursor; + + key.size = sizeof(recno_t); + key.data = &trec; + + status = (dbp->seq)(dbp, &key, &data, R_FIRST); + while (status == RET_SUCCESS) { + iov[0].iov_base = data.data; + iov[0].iov_len = data.size; + if (writev(t->bt_rfd, iov, 2) != data.size + 1) + return (RET_ERROR); + status = (dbp->seq)(dbp, &key, &data, R_NEXT); + } + t->bt_rcursor = scursor; + if (status == RET_ERROR) + return (RET_ERROR); + if ((off = lseek(t->bt_rfd, (off_t)0, SEEK_CUR)) == -1) + return (RET_ERROR); + if (ftruncate(t->bt_rfd, off)) + return (RET_ERROR); + CLR(t, R_MODIFIED); + return (RET_SUCCESS); +} diff --git a/db/recno/rec_delete.c b/db/recno/rec_delete.c new file mode 100644 index 0000000..126cd7f --- /dev/null +++ b/db/recno/rec_delete.c @@ -0,0 +1,215 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Mike Olson. + * + * 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 + +#include +#include +#include + +#include +#include "recno.h" + +static int rec_rdelete __P((BTREE *, recno_t)); + +/* + * __REC_DELETE -- Delete the item(s) referenced by a key. + * + * Parameters: + * dbp: pointer to access method + * key: key to delete + * flags: R_CURSOR if deleting what the cursor references + * + * Returns: + * RET_ERROR, RET_SUCCESS and RET_SPECIAL if the key not found. + */ +int +__rec_delete(dbp, key, flags) + const DB *dbp; + const DBT *key; + u_int flags; +{ + BTREE *t; + recno_t nrec; + int status; + + t = dbp->internal; + + /* Toss any page pinned across calls. */ + if (t->bt_pinned != NULL) { + mpool_put(t->bt_mp, t->bt_pinned, 0); + t->bt_pinned = NULL; + } + + switch(flags) { + case 0: + if ((nrec = *(recno_t *)key->data) == 0) + goto einval; + if (nrec > t->bt_nrecs) + return (RET_SPECIAL); + --nrec; + status = rec_rdelete(t, nrec); + break; + case R_CURSOR: + if (!ISSET(t, B_SEQINIT)) + goto einval; + if (t->bt_nrecs == 0) + return (RET_SPECIAL); + status = rec_rdelete(t, t->bt_rcursor - 1); + if (status == RET_SUCCESS) + --t->bt_rcursor; + break; + default: +einval: errno = EINVAL; + return (RET_ERROR); + } + + if (status == RET_SUCCESS) + SET(t, B_MODIFIED | R_MODIFIED); + return (status); +} + +/* + * REC_RDELETE -- Delete the data matching the specified key. + * + * Parameters: + * tree: tree + * nrec: record to delete + * + * Returns: + * RET_ERROR, RET_SUCCESS and RET_SPECIAL if the key not found. + */ +static int +rec_rdelete(t, nrec) + BTREE *t; + recno_t nrec; +{ + EPG *e; + PAGE *h; + int status; + + /* Find the record; __rec_search pins the page. */ + if ((e = __rec_search(t, nrec, SDELETE)) == NULL) + return (RET_ERROR); + + /* Delete the record. */ + h = e->page; + status = __rec_dleaf(t, h, e->index); + if (status != RET_SUCCESS) { + mpool_put(t->bt_mp, h, 0); + return (status); + } + mpool_put(t->bt_mp, h, MPOOL_DIRTY); + return (RET_SUCCESS); +} + +/* + * __REC_DLEAF -- Delete a single record from a recno leaf page. + * + * Parameters: + * t: tree + * index: index on current page to delete + * + * Returns: + * RET_SUCCESS, RET_ERROR. + */ +int +__rec_dleaf(t, h, index) + BTREE *t; + PAGE *h; + indx_t index; +{ + register RLEAF *rl; + register indx_t *ip, cnt, offset; + register size_t nbytes; + char *from; + void *to; + + /* + * Delete a record from a recno leaf page. Internal records are never + * deleted from internal pages, regardless of the records that caused + * them to be added being deleted. Pages made empty by deletion are + * not reclaimed. They are, however, made available for reuse. + * + * Pack the remaining entries at the end of the page, shift the indices + * down, overwriting the deleted record and its index. If the record + * uses overflow pages, make them available for reuse. + */ + to = rl = GETRLEAF(h, index); + if (rl->flags & P_BIGDATA && __ovfl_delete(t, rl->bytes) == RET_ERROR) + return (RET_ERROR); + nbytes = NRLEAF(rl); + + /* + * Compress the key/data pairs. Compress and adjust the [BR]LEAF + * offsets. Reset the headers. + */ + from = (char *)h + h->upper; + memmove(from + nbytes, from, (char *)to - from); + h->upper += nbytes; + + offset = h->linp[index]; + for (cnt = &h->linp[index] - (ip = &h->linp[0]); cnt--; ++ip) + if (ip[0] < offset) + ip[0] += nbytes; + for (cnt = &h->linp[NEXTINDEX(h)] - ip; --cnt; ++ip) + ip[0] = ip[1] < offset ? ip[1] + nbytes : ip[1]; + h->lower -= sizeof(indx_t); + --t->bt_nrecs; + return (RET_SUCCESS); +} diff --git a/db/recno/rec_get.c b/db/recno/rec_get.c new file mode 100644 index 0000000..a14bfc2 --- /dev/null +++ b/db/recno/rec_get.c @@ -0,0 +1,316 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 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 + +#include +#include +#include +#include +#include +#include + +#include +#include "recno.h" + +/* + * __REC_GET -- Get a record from the btree. + * + * Parameters: + * dbp: pointer to access method + * key: key to find + * data: data to return + * flag: currently unused + * + * Returns: + * RET_ERROR, RET_SUCCESS and RET_SPECIAL if the key not found. + */ +int +__rec_get(dbp, key, data, flags) + const DB *dbp; + const DBT *key; + DBT *data; + u_int flags; +{ + BTREE *t; + EPG *e; + recno_t nrec; + int status; + + t = dbp->internal; + + /* Toss any page pinned across calls. */ + if (t->bt_pinned != NULL) { + mpool_put(t->bt_mp, t->bt_pinned, 0); + t->bt_pinned = NULL; + } + + /* Get currently doesn't take any flags, and keys of 0 are illegal. */ + if (flags || (nrec = *(recno_t *)key->data) == 0) { + errno = EINVAL; + return (RET_ERROR); + } + + /* + * If we haven't seen this record yet, try to find it in the + * original file. + */ + if (nrec > t->bt_nrecs) { + if (ISSET(t, R_EOF | R_INMEM)) + return (RET_SPECIAL); + if ((status = t->bt_irec(t, nrec)) != RET_SUCCESS) + return (status); + } + + --nrec; + if ((e = __rec_search(t, nrec, SEARCH)) == NULL) + return (RET_ERROR); + + status = __rec_ret(t, e, 0, NULL, data); + if (ISSET(t, B_DB_LOCK)) + mpool_put(t->bt_mp, e->page, 0); + else + t->bt_pinned = e->page; + return (status); +} + +/* + * __REC_FPIPE -- Get fixed length records from a pipe. + * + * Parameters: + * t: tree + * cnt: records to read + * + * Returns: + * RET_ERROR, RET_SUCCESS + */ +int +__rec_fpipe(t, top) + BTREE *t; + recno_t top; +{ + DBT data; + recno_t nrec; + size_t len; + int ch; + char *p; + + if (t->bt_dbufsz < t->bt_reclen) { + if ((t->bt_dbuf = + (char *)realloc(t->bt_dbuf, t->bt_reclen)) == NULL) + return (RET_ERROR); + t->bt_dbufsz = t->bt_reclen; + } + data.data = t->bt_dbuf; + data.size = t->bt_reclen; + + for (nrec = t->bt_nrecs; nrec < top; ++nrec) { + len = t->bt_reclen; + for (p = t->bt_dbuf;; *p++ = ch) + if ((ch = getc(t->bt_rfp)) == EOF || !len--) { + if (__rec_iput(t, nrec, &data, 0) + != RET_SUCCESS) + return (RET_ERROR); + break; + } + if (ch == EOF) + break; + } + if (nrec < top) { + SET(t, R_EOF); + return (RET_SPECIAL); + } + return (RET_SUCCESS); +} + +/* + * __REC_VPIPE -- Get variable length records from a pipe. + * + * Parameters: + * t: tree + * cnt: records to read + * + * Returns: + * RET_ERROR, RET_SUCCESS + */ +int +__rec_vpipe(t, top) + BTREE *t; + recno_t top; +{ + DBT data; + recno_t nrec; + indx_t len; + size_t sz; + int bval, ch; + char *p; + + bval = t->bt_bval; + for (nrec = t->bt_nrecs; nrec < top; ++nrec) { + for (p = t->bt_dbuf, sz = t->bt_dbufsz;; *p++ = ch, --sz) { + if ((ch = getc(t->bt_rfp)) == EOF || ch == bval) { + data.data = t->bt_dbuf; + data.size = p - t->bt_dbuf; + if (ch == EOF && data.size == 0) + break; + if (__rec_iput(t, nrec, &data, 0) + != RET_SUCCESS) + return (RET_ERROR); + break; + } + if (sz == 0) { + len = p - t->bt_dbuf; + t->bt_dbufsz += (sz = 256); + if ((t->bt_dbuf = (char *)realloc(t->bt_dbuf, + t->bt_dbufsz)) == NULL) + return (RET_ERROR); + p = t->bt_dbuf + len; + } + } + if (ch == EOF) + break; + } + if (nrec < top) { + SET(t, R_EOF); + return (RET_SPECIAL); + } + return (RET_SUCCESS); +} + +/* + * __REC_FMAP -- Get fixed length records from a file. + * + * Parameters: + * t: tree + * cnt: records to read + * + * Returns: + * RET_ERROR, RET_SUCCESS + */ +int +__rec_fmap(t, top) + BTREE *t; + recno_t top; +{ + DBT data; + recno_t nrec; + caddr_t sp, ep; + size_t len; + char *p; + + if (t->bt_dbufsz < t->bt_reclen) { + if ((t->bt_dbuf = + (char *)realloc(t->bt_dbuf, t->bt_reclen)) == NULL) + return (RET_ERROR); + t->bt_dbufsz = t->bt_reclen; + } + data.data = t->bt_dbuf; + data.size = t->bt_reclen; + + sp = t->bt_cmap; + ep = t->bt_emap; + for (nrec = t->bt_nrecs; nrec < top; ++nrec) { + if (sp >= ep) { + SET(t, R_EOF); + return (RET_SPECIAL); + } + len = t->bt_reclen; + for (p = t->bt_dbuf; sp < ep && len--; *p++ = *sp++); + memset(p, t->bt_bval, len); + if (__rec_iput(t, nrec, &data, 0) != RET_SUCCESS) + return (RET_ERROR); + } + t->bt_cmap = sp; + return (RET_SUCCESS); +} + +/* + * __REC_VMAP -- Get variable length records from a file. + * + * Parameters: + * t: tree + * cnt: records to read + * + * Returns: + * RET_ERROR, RET_SUCCESS + */ +int +__rec_vmap(t, top) + BTREE *t; + recno_t top; +{ + DBT data; + caddr_t sp, ep; + recno_t nrec; + int bval; + + sp = t->bt_cmap; + ep = t->bt_emap; + bval = t->bt_bval; + + for (nrec = t->bt_nrecs; nrec < top; ++nrec) { + if (sp >= ep) { + SET(t, R_EOF); + return (RET_SPECIAL); + } + for (data.data = sp; sp < ep && *sp != bval; ++sp); + data.size = sp - (caddr_t)data.data; + if (__rec_iput(t, nrec, &data, 0) != RET_SUCCESS) + return (RET_ERROR); + ++sp; + } + t->bt_cmap = sp; + return (RET_SUCCESS); +} diff --git a/db/recno/rec_open.c b/db/recno/rec_open.c new file mode 100644 index 0000000..4f8743e --- /dev/null +++ b/db/recno/rec_open.c @@ -0,0 +1,253 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Mike Olson. + * + * 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 +#include + +#include +#include + +#include +#include +#include +#include +#include +#include + +#include +#include "recno.h" + +DB * +__rec_open(fname, flags, mode, openinfo, dflags) + const char *fname; + int flags, mode, dflags; + const RECNOINFO *openinfo; +{ + BTREE *t; + BTREEINFO btopeninfo; + DB *dbp; + PAGE *h; + struct stat sb; + int rfd, sverrno; + + /* Open the user's file -- if this fails, we're done. */ + if (fname != NULL && (rfd = open(fname, flags, mode)) < 0) + return (NULL); + + /* Create a btree in memory (backed by disk). */ + dbp = NULL; + if (openinfo) { + if (openinfo->flags & ~(R_FIXEDLEN | R_NOKEY | R_SNAPSHOT)) + goto einval; + btopeninfo.flags = 0; + btopeninfo.cachesize = openinfo->cachesize; + btopeninfo.maxkeypage = 0; + btopeninfo.minkeypage = 0; + btopeninfo.psize = openinfo->psize; + btopeninfo.compare = NULL; + btopeninfo.prefix = NULL; + btopeninfo.lorder = openinfo->lorder; + dbp = __bt_open(openinfo->bfname, + O_RDWR, S_IRUSR | S_IWUSR, &btopeninfo, dflags); + } else + dbp = __bt_open(NULL, O_RDWR, S_IRUSR | S_IWUSR, NULL, dflags); + if (dbp == NULL) + goto err; + + /* + * Some fields in the tree structure are recno specific. Fill them + * in and make the btree structure look like a recno structure. We + * don't change the bt_ovflsize value, it's close enough and slightly + * bigger. + */ + t = dbp->internal; + if (openinfo) { + if (openinfo->flags & R_FIXEDLEN) { + SET(t, R_FIXLEN); + t->bt_reclen = openinfo->reclen; + if (t->bt_reclen == 0) + goto einval; + } + t->bt_bval = openinfo->bval; + } else + t->bt_bval = '\n'; + + SET(t, R_RECNO); + if (fname == NULL) + SET(t, R_EOF | R_INMEM); + else + t->bt_rfd = rfd; + t->bt_rcursor = 0; + + if (fname != NULL) { + /* + * In 4.4BSD, stat(2) returns true for ISSOCK on pipes. + * Unfortunately, that's not portable, so we use lseek + * and check the errno values. + */ + errno = 0; + if (lseek(rfd, (off_t)0, SEEK_CUR) == -1 && errno == ESPIPE) { + switch (flags & O_ACCMODE) { + case O_RDONLY: + SET(t, R_RDONLY); + break; + default: + goto einval; + } +slow: if ((t->bt_rfp = fdopen(rfd, "r")) == NULL) + goto err; + SET(t, R_CLOSEFP); + t->bt_irec = + ISSET(t, R_FIXLEN) ? __rec_fpipe : __rec_vpipe; + } else { + switch (flags & O_ACCMODE) { + case O_RDONLY: + SET(t, R_RDONLY); + break; + case O_RDWR: + break; + default: + goto einval; + } + + if (fstat(rfd, &sb)) + goto err; + /* + * Kluge -- we'd like to test to see if the file is too + * big to mmap. Since, we don't know what size or type + * off_t's or size_t's are, what the largest unsigned + * integral type is, or what random insanity the local + * C compiler will perpetrate, doing the comparison in + * a portable way is flatly impossible. Hope that mmap + * fails if the file is too large. + */ + if (sb.st_size == 0) + SET(t, R_EOF); + else { + t->bt_msize = sb.st_size; + if ( (map_fd(rfd, 0, (vm_offset_t *) + &t->bt_smap, TRUE, t->bt_msize) + != KERN_SUCCESS) + || (vm_protect(mach_task_self(), (vm_offset_t) + t->bt_smap, t->bt_msize, TRUE, + VM_PROT_READ) != KERN_SUCCESS) ) + goto slow; + t->bt_cmap = t->bt_smap; + t->bt_emap = t->bt_smap + sb.st_size; + t->bt_irec = ISSET(t, R_FIXLEN) ? + __rec_fmap : __rec_vmap; + SET(t, R_MEMMAPPED); + } + } + } + + /* Use the recno routines. */ + dbp->close = __rec_close; + dbp->del = __rec_delete; + dbp->fd = __rec_fd; + dbp->get = __rec_get; + dbp->put = __rec_put; + dbp->seq = __rec_seq; + dbp->sync = __rec_sync; + + /* If the root page was created, reset the flags. */ + if ((h = mpool_get(t->bt_mp, P_ROOT, 0)) == NULL) + goto err; + if ((h->flags & P_TYPE) == P_BLEAF) { + h->flags = h->flags & ~P_TYPE | P_RLEAF; + mpool_put(t->bt_mp, h, MPOOL_DIRTY); + } else + mpool_put(t->bt_mp, h, 0); + + if (openinfo && openinfo->flags & R_SNAPSHOT && + !ISSET(t, R_EOF | R_INMEM) && + t->bt_irec(t, MAX_REC_NUMBER) == RET_ERROR) + goto err; + return (dbp); + +einval: errno = EINVAL; +err: sverrno = errno; + if (dbp != NULL) + (void)__bt_close(dbp); + if (fname != NULL) + (void)close(rfd); + errno = sverrno; + return (NULL); +} + +int +__rec_fd(dbp) + const DB *dbp; +{ + BTREE *t; + + t = dbp->internal; + + /* Toss any page pinned across calls. */ + if (t->bt_pinned != NULL) { + mpool_put(t->bt_mp, t->bt_pinned, 0); + t->bt_pinned = NULL; + } + + /* In-memory database can't have a file descriptor. */ + if (ISSET(t, R_INMEM)) { + errno = ENOENT; + return (-1); + } + return (t->bt_rfd); +} diff --git a/db/recno/rec_put.c b/db/recno/rec_put.c new file mode 100644 index 0000000..45029a6 --- /dev/null +++ b/db/recno/rec_put.c @@ -0,0 +1,271 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 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 + +#include +#include +#include +#include + +#include +#include "recno.h" + +/* + * __REC_PUT -- Add a recno item to the tree. + * + * Parameters: + * dbp: pointer to access method + * key: key + * data: data + * flag: R_CURSOR, R_IAFTER, R_IBEFORE, R_NOOVERWRITE + * + * Returns: + * RET_ERROR, RET_SUCCESS and RET_SPECIAL if the key is + * already in the tree and R_NOOVERWRITE specified. + */ +int +__rec_put(dbp, key, data, flags) + const DB *dbp; + DBT *key; + const DBT *data; + u_int flags; +{ + BTREE *t; + DBT tdata; + recno_t nrec; + int status; + + t = dbp->internal; + + /* Toss any page pinned across calls. */ + if (t->bt_pinned != NULL) { + mpool_put(t->bt_mp, t->bt_pinned, 0); + t->bt_pinned = NULL; + } + + switch (flags) { + case R_CURSOR: + if (!ISSET(t, B_SEQINIT)) + goto einval; + nrec = t->bt_rcursor; + break; + case R_SETCURSOR: + if ((nrec = *(recno_t *)key->data) == 0) + goto einval; + break; + case R_IAFTER: + if ((nrec = *(recno_t *)key->data) == 0) { + nrec = 1; + flags = R_IBEFORE; + } + break; + case 0: + case R_IBEFORE: + if ((nrec = *(recno_t *)key->data) == 0) + goto einval; + break; + case R_NOOVERWRITE: + if ((nrec = *(recno_t *)key->data) == 0) + goto einval; + if (nrec <= t->bt_nrecs) + return (RET_SPECIAL); + break; + default: +einval: errno = EINVAL; + return (RET_ERROR); + } + + /* + * Make sure that records up to and including the put record are + * already in the database. If skipping records, create empty ones. + */ + if (nrec > t->bt_nrecs) { + if (!ISSET(t, R_EOF | R_INMEM) && + t->bt_irec(t, nrec) == RET_ERROR) + return (RET_ERROR); + if (nrec > t->bt_nrecs + 1) { + if (ISSET(t, R_FIXLEN)) { + if ((tdata.data = + (void *)malloc(t->bt_reclen)) == NULL) + return (RET_ERROR); + tdata.size = t->bt_reclen; + memset(tdata.data, t->bt_bval, tdata.size); + } else { + tdata.data = NULL; + tdata.size = 0; + } + while (nrec > t->bt_nrecs + 1) + if (__rec_iput(t, + t->bt_nrecs, &tdata, 0) != RET_SUCCESS) + return (RET_ERROR); + if (ISSET(t, R_FIXLEN)) + free(tdata.data); + } + } + + if ((status = __rec_iput(t, nrec - 1, data, flags)) != RET_SUCCESS) + return (status); + + if (flags == R_SETCURSOR) + t->bt_rcursor = nrec; + + SET(t, R_MODIFIED); + return (__rec_ret(t, NULL, nrec, key, NULL)); +} + +/* + * __REC_IPUT -- Add a recno item to the tree. + * + * Parameters: + * t: tree + * nrec: record number + * data: data + * + * Returns: + * RET_ERROR, RET_SUCCESS + */ +int +__rec_iput(t, nrec, data, flags) + BTREE *t; + recno_t nrec; + const DBT *data; + u_int flags; +{ + DBT tdata; + EPG *e; + PAGE *h; + indx_t index, nxtindex; + pgno_t pg; + size_t nbytes; + int dflags, status; + char *dest, db[NOVFLSIZE]; + + /* + * If the data won't fit on a page, store it on indirect pages. + * + * XXX + * If the insert fails later on, these pages aren't recovered. + */ + if (data->size > t->bt_ovflsize) { + if (__ovfl_put(t, data, &pg) == RET_ERROR) + return (RET_ERROR); + tdata.data = db; + tdata.size = NOVFLSIZE; + *(pgno_t *)db = pg; + *(size_t *)(db + sizeof(pgno_t)) = data->size; + dflags = P_BIGDATA; + data = &tdata; + } else + dflags = 0; + + /* __rec_search pins the returned page. */ + if ((e = __rec_search(t, nrec, + nrec > t->bt_nrecs || flags == R_IAFTER || flags == R_IBEFORE ? + SINSERT : SEARCH)) == NULL) + return (RET_ERROR); + + h = e->page; + index = e->index; + + /* + * Add the specified key/data pair to the tree. The R_IAFTER and + * R_IBEFORE flags insert the key after/before the specified key. + * + * Pages are split as required. + */ + switch (flags) { + case R_IAFTER: + ++index; + break; + case R_IBEFORE: + break; + default: + if (nrec < t->bt_nrecs && + __rec_dleaf(t, h, index) == RET_ERROR) { + mpool_put(t->bt_mp, h, 0); + return (RET_ERROR); + } + break; + } + + /* + * If not enough room, split the page. The split code will insert + * the key and data and unpin the current page. If inserting into + * the offset array, shift the pointers up. + */ + nbytes = NRLEAFDBT(data->size); + if (h->upper - h->lower < nbytes + sizeof(indx_t)) { + status = __bt_split(t, h, NULL, data, dflags, nbytes, index); + if (status == RET_SUCCESS) + ++t->bt_nrecs; + return (status); + } + + if (index < (nxtindex = NEXTINDEX(h))) + memmove(h->linp + index + 1, h->linp + index, + (nxtindex - index) * sizeof(indx_t)); + h->lower += sizeof(indx_t); + + h->linp[index] = h->upper -= nbytes; + dest = (char *)h + h->upper; + WR_RLEAF(dest, data, dflags); + + ++t->bt_nrecs; + SET(t, B_MODIFIED); + mpool_put(t->bt_mp, h, MPOOL_DIRTY); + + return (RET_SUCCESS); +} diff --git a/db/recno/rec_search.c b/db/recno/rec_search.c new file mode 100644 index 0000000..9cf4341 --- /dev/null +++ b/db/recno/rec_search.c @@ -0,0 +1,145 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 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 + +#include +#include + +#include +#include "recno.h" + +/* + * __REC_SEARCH -- Search a btree for a key. + * + * Parameters: + * t: tree to search + * recno: key to find + * op: search operation + * + * Returns: + * EPG for matching record, if any, or the EPG for the location of the + * key, if it were inserted into the tree. + * + * Returns: + * The EPG for matching record, if any, or the EPG for the location + * of the key, if it were inserted into the tree, is entered into + * the bt_cur field of the tree. A pointer to the field is returned. + */ +EPG * +__rec_search(t, recno, op) + BTREE *t; + recno_t recno; + enum SRCHOP op; +{ + register indx_t index; + register PAGE *h; + EPGNO *parent; + RINTERNAL *r; + pgno_t pg; + indx_t top; + recno_t total; + int sverrno; + + BT_CLR(t); + for (pg = P_ROOT, total = 0;;) { + if ((h = mpool_get(t->bt_mp, pg, 0)) == NULL) + goto err; + if (h->flags & P_RLEAF) { + t->bt_cur.page = h; + t->bt_cur.index = recno - total; + return (&t->bt_cur); + } + for (index = 0, top = NEXTINDEX(h);;) { + r = GETRINTERNAL(h, index); + if (++index == top || total + r->nrecs > recno) + break; + total += r->nrecs; + } + + if (__bt_push(t, pg, index - 1) == RET_ERROR) + return (NULL); + + pg = r->pgno; + switch (op) { + case SDELETE: + --GETRINTERNAL(h, (index - 1))->nrecs; + mpool_put(t->bt_mp, h, MPOOL_DIRTY); + break; + case SINSERT: + ++GETRINTERNAL(h, (index - 1))->nrecs; + mpool_put(t->bt_mp, h, MPOOL_DIRTY); + break; + case SEARCH: + mpool_put(t->bt_mp, h, 0); + break; + } + + } + /* Try and recover the tree. */ +err: sverrno = errno; + if (op != SEARCH) + while ((parent = BT_POP(t)) != NULL) { + if ((h = mpool_get(t->bt_mp, parent->pgno, 0)) == NULL) + break; + if (op == SINSERT) + --GETRINTERNAL(h, parent->index)->nrecs; + else + ++GETRINTERNAL(h, parent->index)->nrecs; + mpool_put(t->bt_mp, h, MPOOL_DIRTY); + } + errno = sverrno; + return (NULL); +} diff --git a/db/recno/rec_seq.c b/db/recno/rec_seq.c new file mode 100644 index 0000000..693d447 --- /dev/null +++ b/db/recno/rec_seq.c @@ -0,0 +1,149 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * 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. + */ + + +#include + +#include +#include +#include +#include + +#include +#include "recno.h" + +/* + * __REC_SEQ -- Recno sequential scan interface. + * + * Parameters: + * dbp: pointer to access method + * key: key for positioning and return value + * data: data return value + * flags: R_CURSOR, R_FIRST, R_LAST, R_NEXT, R_PREV. + * + * Returns: + * RET_ERROR, RET_SUCCESS or RET_SPECIAL if there's no next key. + */ +int +__rec_seq(dbp, key, data, flags) + const DB *dbp; + DBT *key, *data; + u_int flags; +{ + BTREE *t; + EPG *e; + recno_t nrec; + int status; + + t = dbp->internal; + + /* Toss any page pinned across calls. */ + if (t->bt_pinned != NULL) { + mpool_put(t->bt_mp, t->bt_pinned, 0); + t->bt_pinned = NULL; + } + + switch(flags) { + case R_CURSOR: + if ((nrec = *(recno_t *)key->data) == 0) + goto einval; + break; + case R_NEXT: + if (ISSET(t, B_SEQINIT)) { + nrec = t->bt_rcursor + 1; + break; + } + /* FALLTHROUGH */ + case R_FIRST: + nrec = 1; + break; + case R_PREV: + if (ISSET(t, B_SEQINIT)) { + if ((nrec = t->bt_rcursor - 1) == 0) + return (RET_SPECIAL); + break; + } + /* FALLTHROUGH */ + case R_LAST: + if (!ISSET(t, R_EOF | R_INMEM) && + t->bt_irec(t, MAX_REC_NUMBER) == RET_ERROR) + return (RET_ERROR); + nrec = t->bt_nrecs; + break; + default: +einval: errno = EINVAL; + return (RET_ERROR); + } + + if (t->bt_nrecs == 0 || nrec > t->bt_nrecs) { + if (!ISSET(t, R_EOF | R_INMEM) && + (status = t->bt_irec(t, nrec)) != RET_SUCCESS) + return (status); + if (t->bt_nrecs == 0 || nrec > t->bt_nrecs) + return (RET_SPECIAL); + } + + if ((e = __rec_search(t, nrec - 1, SEARCH)) == NULL) + return (RET_ERROR); + + SET(t, B_SEQINIT); + t->bt_rcursor = nrec; + + status = __rec_ret(t, e, nrec, key, data); + if (ISSET(t, B_DB_LOCK)) + mpool_put(t->bt_mp, e->page, 0); + else + t->bt_pinned = e->page; + return (status); +} diff --git a/db/recno/rec_utils.c b/db/recno/rec_utils.c new file mode 100644 index 0000000..8f7c475 --- /dev/null +++ b/db/recno/rec_utils.c @@ -0,0 +1,132 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 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 + +#include +#include +#include + +#include +#include "recno.h" + +/* + * __REC_RET -- Build return data as a result of search or scan. + * + * Parameters: + * t: tree + * d: LEAF to be returned to the user. + * data: user's data structure + * + * Returns: + * RET_SUCCESS, RET_ERROR. + */ +int +__rec_ret(t, e, nrec, key, data) + BTREE *t; + EPG *e; + recno_t nrec; + DBT *key, *data; +{ + register RLEAF *rl; + register void *p; + + if (data == NULL) + goto retkey; + + rl = GETRLEAF(e->page, e->index); + + /* + * We always copy big data to make it contigous. Otherwise, we + * leave the page pinned and don't copy unless the user specified + * concurrent access. + */ + if (rl->flags & P_BIGDATA) { + if (__ovfl_get(t, rl->bytes, + &data->size, &t->bt_dbuf, &t->bt_dbufsz)) + return (RET_ERROR); + data->data = t->bt_dbuf; + } else if (ISSET(t, B_DB_LOCK)) { + /* Use +1 in case the first record retrieved is 0 length. */ + if (rl->dsize + 1 > t->bt_dbufsz) { + if ((p = + (void *)realloc(t->bt_dbuf, rl->dsize + 1)) == NULL) + return (RET_ERROR); + t->bt_dbuf = p; + t->bt_dbufsz = rl->dsize + 1; + } + memmove(t->bt_dbuf, rl->bytes, rl->dsize); + data->size = rl->dsize; + data->data = t->bt_dbuf; + } else { + data->size = rl->dsize; + data->data = rl->bytes; + } + +retkey: if (key == NULL) + return (RET_SUCCESS); + + /* We have to copy the key, it's not on the page. */ + if (sizeof(recno_t) > t->bt_kbufsz) { + if ((p = (void *)realloc(t->bt_kbuf, sizeof(recno_t))) == NULL) + return (RET_ERROR); + t->bt_kbuf = p; + t->bt_kbufsz = sizeof(recno_t); + } + memmove(t->bt_kbuf, &nrec, sizeof(recno_t)); + key->size = sizeof(recno_t); + key->data = t->bt_kbuf; + return (RET_SUCCESS); +} diff --git a/db/recno/recno.h b/db/recno/recno.h new file mode 100644 index 0000000..39b076d --- /dev/null +++ b/db/recno/recno.h @@ -0,0 +1,58 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * 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. + */ + +enum SRCHOP { SDELETE, SINSERT, SEARCH}; /* Rec_search operation. */ + +#include +#include "extern.h" diff --git a/dpkg/control b/dpkg/control new file mode 100644 index 0000000..836adea --- /dev/null +++ b/dpkg/control @@ -0,0 +1,4 @@ +Package: libc +Maintainer: Darwin Developers +Description: C library +Build-Depends: cctools, libsystem, gnumake, libinfo-hdrs, project-makefiles, pb-makefiles, system-cmds, shell-cmds, zsh, file-cmds, bootstrap-cmds, text-cmds, gcc, xnu, architecture, gnutar diff --git a/gen.subproj/Makefile b/gen.subproj/Makefile deleted file mode 100644 index 0148fde..0000000 --- a/gen.subproj/Makefile +++ /dev/null @@ -1,72 +0,0 @@ -# -# Generated by the Apple Project Builder. -# -# NOTE: Do NOT change this file -- Project Builder maintains it. -# -# Put all of your customizations in files called Makefile.preamble -# and Makefile.postamble (both optional), and Makefile will include them. -# - -NAME = gen - -PROJECTVERSION = 2.8 -PROJECT_TYPE = Component - -HFILES = zone.h scalable_malloc.h malloc.h stack_logging.h - -CFILES = alarm.c assert.c clock.c closedir.c confstr.c crypt.c\ - ctermid.c ctime.c daemon.c devname.c difftime.c disklabel.c\ - err.c errlst.c exec.c fnmatch.c ftok.c fts.c getbsize.c\ - getcap.c getcwd.c gethostname.c getloadavg.c getlogin.c\ - getmntinfo.c getpagesize.c getpass.c getttyent.c\ - getusershell.c getvfsbyname.c gmon.c isatty.c isnan.c\ - malloc.c nanosleep.c nice.c nlist.c NSSystemDirectories.c\ - opendir.c pause.c popen.c psignal.c raise.c readdir.c\ - rewinddir.c scalable_malloc.c scandir.c seekdir.c\ - sethostname.c setlogin.c setmode.c siginterrupt.c siglist.c\ - signal.c sigsetops.c sleep.c stack_logging.c sysconf.c\ - sysctl.c syslog.c telldir.c termios.c time.c times.c\ - timezone.c ttyname.c ttyslot.c ualarm.c uname.c unvis.c\ - usleep.c utime.c vis.c wait.c wait3.c waitpid.c zone.c\ - sysctlbyname.c - -SUBPROJECTS = i386.subproj ppc.subproj - -OTHERSRCS = Makefile.preamble Makefile Makefile.postamble ftok.3 - - -MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles -CODE_GEN_STYLE = DYNAMIC -MAKEFILE = subproj.make -NEXTSTEP_INSTALLDIR = /Local/Developer/System -LIBS = -DEBUG_LIBS = $(LIBS) -PROF_LIBS = $(LIBS) - - -PUBLIC_HEADERS = zone.h malloc.h - -PROJECT_HEADERS = malloc.h zone.h stack_logging.h - - - -NEXTSTEP_BUILD_OUTPUT_DIR = /Local/Public/SandBox/$(USER)/BUILD/$(NAME) - -NEXTSTEP_PUBLIC_HEADERS_DIR = /usr/include - -NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc -WINDOWS_OBJCPLUS_COMPILER = $(DEVDIR)/gcc -PDO_UNIX_OBJCPLUS_COMPILER = $(NEXTDEV_BIN)/gcc -NEXTSTEP_JAVA_COMPILER = /usr/bin/javac -WINDOWS_JAVA_COMPILER = $(JDKBINDIR)/javac.exe -PDO_UNIX_JAVA_COMPILER = $(JDKBINDIR)/javac - -include $(MAKEFILEDIR)/platform.make - --include Makefile.preamble - -include $(MAKEFILEDIR)/$(MAKEFILE) - --include Makefile.postamble - --include Makefile.dependencies diff --git a/gen.subproj/Makefile.postamble b/gen.subproj/Makefile.postamble deleted file mode 100644 index b0473f2..0000000 --- a/gen.subproj/Makefile.postamble +++ /dev/null @@ -1,4 +0,0 @@ -PROFILE_CFLAGS = $(filter-out -DPROFILE, $(filter-out -pg, $(ALL_CFLAGS))) -$(OFILE_DIR)/gmon.i386.o $(OFILE_DIR)/gmon.ppc.o: gmon.c - $(CC) -arch $(CURRENT_ARCH) $(PROFILE_CFLAGS) $(LOCAL_DIR_INCLUDE_DIRECTIVE) -c gmon.c -o $@ - diff --git a/gen.subproj/Makefile.preamble b/gen.subproj/Makefile.preamble deleted file mode 100644 index 3be9dcf..0000000 --- a/gen.subproj/Makefile.preamble +++ /dev/null @@ -1,2 +0,0 @@ -PUBLIC_HEADER_DIR_SUFFIX = /objc -PROJECT_HEADER_DIR_SUFFIX = /objc diff --git a/gen.subproj/NSSystemDirectories.c b/gen.subproj/NSSystemDirectories.c deleted file mode 100644 index 1e37408..0000000 --- a/gen.subproj/NSSystemDirectories.c +++ /dev/null @@ -1,122 +0,0 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * Portions Copyright (c) 1999 Apple Computer, Inc. All Rights - * Reserved. This 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.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. - * - * 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@ - */ -#import -#import -#import -#import - -// Names of directories; index into this with NSSearchPathDirectory - 1 -#define numDirs 8 -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, "Developer/Applications"}, - {0, 0, "Applications/Utilities"}, - {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 -}; - -// Ordered list of where to find applications in each domain (the numbers are NSSearchPathDirectory) -#define numApplicationDirs 4 -static const char applicationDirs[numApplicationDirs] = {1, 4, 3, 2}; - -// Ordered list of where to find resources in each domain (the numbers are NSSearchPathDirectory) -#define numLibraryDirs 2 -static const char libraryDirs[numLibraryDirs] = {5, 6}; - -// Names of domains; index into this log2(domainMask). If the search path ordering is ever changed, then we need an indirection (as the domainMask values cannot be changed). -#define numDomains 4 -static const struct { - char needsRootPrepended; - const char *domainPath; - const char *alternateDomainPath; -} domainInfo[numDomains] = { - {0, "~", "~"}, - {1, "", ""}, - {1, "/Network", "/Network"}, - {1, "", "/System"} -}; - -#define invalidDomains 0x00 // some domains may be invalid on non-Mach systems - -NSSearchPathEnumerationState NSStartSearchPathEnumeration(NSSearchPathDirectory dir, NSSearchPathDomainMask domainMask) { - // The state is AABBCCCC, where - // AA is the dir(s) requested - // BB is the current state of dirs (if AA < 100, then this is always 0; otherwise it goes up to number of dirs) - // CCCC is the domains requested - // the state always contains the next item; if CCCC is 0, then we're done - domainMask = domainMask & ((1 << numDomains) - 1) & ~invalidDomains; // Just leave useful bits in there - if (dir != NSAllLibrariesDirectory && dir != NSLibraryDirectory && dir != NSUserDirectory && dir != NSDocumentationDirectory && (domainMask & NSLocalDomainMask) && (domainMask & NSSystemDomainMask)) domainMask = domainMask & ~NSSystemDomainMask; // Hack to avoid duplication - return (((unsigned int)dir) << 24) + ((unsigned int)domainMask); -} - -NSSearchPathEnumerationState NSGetNextSearchPathEnumeration(NSSearchPathEnumerationState state, char *path) { - static const char *nextRoot = NULL; - unsigned dir = (state >> 24) & 0xff; - unsigned dirState = (state >> 16) & 0xff; - unsigned domainMask = state & 0xffff; - unsigned int curDomain; // The current domain we're at... - unsigned int curDir = 0; // The current dir... - - do { - if (domainMask == 0) return 0; // Looks like we're done - for (curDomain = 0; curDomain < numDomains; curDomain++) if ((domainMask & (1 << curDomain))) break; - - // Determine directory - if (dir < NSAllApplicationsDirectory) { // One directory per domain, simple... - curDir = dir; - } else { // Can return multiple directories for each domain - if (dir == NSAllApplicationsDirectory) { - curDir = applicationDirs[dirState]; - if (++dirState == numApplicationDirs) dirState = 0; - } else if (dir == NSAllLibrariesDirectory) { - curDir = libraryDirs[dirState]; - if (++dirState == numLibraryDirs) dirState = 0; - } - } - if (dirState == 0) domainMask &= ~(1 << curDomain); // If necessary, jump to next domain - } while ((dirInfo[curDir - 1].invalidDomainMask & (1 << curDomain))); // If invalid, try again... - - // Get NEXT_ROOT, if necessary. - if (domainInfo[curDomain].needsRootPrepended && nextRoot == 0) { - nextRoot = getenv("NEXT_ROOT"); - if (nextRoot == NULL) { - nextRoot = ""; - } else { - strcpy(malloc(strlen(nextRoot) + 1), nextRoot); // Be safe... - } - } - - snprintf(path, PATH_MAX, "%s%s/%s", domainInfo[curDomain].needsRootPrepended ? nextRoot : "", (dirInfo[curDir - 1].alternateDomainMask & (1 << curDomain)) ? domainInfo[curDomain].alternateDomainPath : domainInfo[curDomain].domainPath, dirInfo[curDir - 1].dirPath); - - return (dir << 24) + (dirState << 16) + domainMask; -} - - diff --git a/gen.subproj/PB.project b/gen.subproj/PB.project deleted file mode 100644 index 5401699..0000000 --- a/gen.subproj/PB.project +++ /dev/null @@ -1,108 +0,0 @@ -{ - DYNAMIC_CODE_GEN = YES; - FILESTABLE = { - H_FILES = (zone.h, scalable_malloc.h, malloc.h, stack_logging.h); - OTHER_LINKED = ( - alarm.c, - assert.c, - clock.c, - closedir.c, - confstr.c, - crypt.c, - ctermid.c, - ctime.c, - daemon.c, - devname.c, - difftime.c, - disklabel.c, - err.c, - errlst.c, - exec.c, - fnmatch.c, - ftok.c, - fts.c, - getbsize.c, - getcap.c, - getcwd.c, - gethostname.c, - getloadavg.c, - getlogin.c, - getmntinfo.c, - getpagesize.c, - getpass.c, - getttyent.c, - getusershell.c, - getvfsbyname.c, - gmon.c, - isatty.c, - isnan.c, - malloc.c, - nanosleep.c, - nice.c, - nlist.c, - NSSystemDirectories.c, - opendir.c, - pause.c, - popen.c, - psignal.c, - raise.c, - readdir.c, - rewinddir.c, - scalable_malloc.c, - scandir.c, - seekdir.c, - sethostname.c, - setlogin.c, - setmode.c, - siginterrupt.c, - siglist.c, - signal.c, - sigsetops.c, - sleep.c, - stack_logging.c, - sysconf.c, - sysctl.c, - syslog.c, - telldir.c, - termios.c, - time.c, - times.c, - timezone.c, - ttyname.c, - ttyslot.c, - ualarm.c, - uname.c, - unvis.c, - usleep.c, - utime.c, - vis.c, - wait.c, - wait3.c, - waitpid.c, - zone.c, - sysctlbyname.c - ); - OTHER_SOURCES = (Makefile.preamble, Makefile, Makefile.postamble, ftok.3); - PRECOMPILED_HEADERS = (); - PROJECT_HEADERS = (malloc.h, zone.h, stack_logging.h); - PUBLIC_HEADERS = (zone.h, malloc.h); - SUBPROJECTS = (i386.subproj, ppc.subproj); - }; - LANGUAGE = English; - MAKEFILEDIR = "$(MAKEFILEPATH)/pb_makefiles"; - NEXTSTEP_BUILDDIR = "/Local/Public/SandBox/$(USER)/BUILD/$(NAME)"; - NEXTSTEP_BUILDTOOL = /bin/gnumake; - NEXTSTEP_INSTALLDIR = /Local/Developer/System; - NEXTSTEP_JAVA_COMPILER = /usr/bin/javac; - NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc; - NEXTSTEP_PUBLICHEADERSDIR = /usr/include; - PDO_UNIX_BUILDTOOL = $NEXT_ROOT/Developer/bin/make; - PDO_UNIX_JAVA_COMPILER = "$(JDKBINDIR)/javac"; - PDO_UNIX_OBJCPLUS_COMPILER = "$(NEXTDEV_BIN)/gcc"; - PROJECTNAME = gen; - PROJECTTYPE = Component; - PROJECTVERSION = 2.8; - WINDOWS_BUILDTOOL = $NEXT_ROOT/Developer/Executables/make; - WINDOWS_JAVA_COMPILER = "$(JDKBINDIR)/javac.exe"; - WINDOWS_OBJCPLUS_COMPILER = "$(DEVDIR)/gcc"; -} diff --git a/gen.subproj/alarm.c b/gen.subproj/alarm.c deleted file mode 100644 index 1b66b07..0000000 --- a/gen.subproj/alarm.c +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1983, 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. - */ - - -/* - * Backwards compatible alarm. - */ -#include -#include - -unsigned int -alarm(secs) - unsigned int secs; -{ - struct itimerval it, oitv; - register struct itimerval *itp = ⁢ - - timerclear(&itp->it_interval); - itp->it_value.tv_sec = secs; - itp->it_value.tv_usec = 0; - if (setitimer(ITIMER_REAL, itp, &oitv) < 0) - return (-1); - if (oitv.it_value.tv_usec) - oitv.it_value.tv_sec++; - return (oitv.it_value.tv_sec); -} diff --git a/gen.subproj/assert.c b/gen.subproj/assert.c deleted file mode 100644 index 2ce97a7..0000000 --- a/gen.subproj/assert.c +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * 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 -#include -#include -#include - -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 diff --git a/gen.subproj/clock.c b/gen.subproj/clock.c deleted file mode 100644 index 47367f3..0000000 --- a/gen.subproj/clock.c +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1989, 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 -#include -#include - -/* - * Convert usec to clock ticks; could do (usec * CLK_TCK) / 1000000, - * but this would overflow if we switch to nanosec. - */ -#define CONVTCK(r) (r.tv_sec * CLK_TCK + r.tv_usec / (1000000 / CLK_TCK)) - -clock_t -clock() -{ - struct rusage ru; - - if (getrusage(RUSAGE_SELF, &ru)) - return ((clock_t) -1); - return((clock_t)((CONVTCK(ru.ru_utime) + CONVTCK(ru.ru_stime)))); -} diff --git a/gen.subproj/closedir.c b/gen.subproj/closedir.c deleted file mode 100644 index 858f4fc..0000000 --- a/gen.subproj/closedir.c +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1983, 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 -#include -#include -#include - -/* - * close a directory. - */ -int -closedir(dirp) - register DIR *dirp; -{ - int fd; - - seekdir(dirp, dirp->dd_rewind); /* free seekdir storage */ - fd = dirp->dd_fd; - dirp->dd_fd = -1; - dirp->dd_loc = 0; - (void)free((void *)dirp->dd_buf); - (void)free((void *)dirp); - return(close(fd)); -} diff --git a/gen.subproj/confstr.c b/gen.subproj/confstr.c deleted file mode 100644 index 9c380aa..0000000 --- a/gen.subproj/confstr.c +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * 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 -#include - -#include -#include -#include -#include -#include - -size_t -confstr(name, buf, len) - int name; - char *buf; - size_t len; -{ - size_t tlen; - int mib[2], sverrno; - char *p; - - switch (name) { - case _CS_PATH: - mib[0] = CTL_USER; - mib[1] = USER_CS_PATH; - if (sysctl(mib, 2, NULL, &tlen, NULL, 0) == -1) - return (-1); - if (len != 0 && buf != NULL) { - if ((p = malloc(tlen)) == NULL) - return (-1); - if (sysctl(mib, 2, p, &tlen, NULL, 0) == -1) { - sverrno = errno; - free(p); - errno = sverrno; - return (-1); - } - /* - * POSIX 1003.2 requires partial return of - * the string -- that should be *real* useful. - */ - (void)strncpy(buf, p, len - 1); - buf[len - 1] = '\0'; - free(p); - } - return (tlen + 1); - default: - errno = EINVAL; - return (0); - } - /* NOTREACHED */ -} diff --git a/gen.subproj/crypt.c b/gen.subproj/crypt.c deleted file mode 100644 index 2f56953..0000000 --- a/gen.subproj/crypt.c +++ /dev/null @@ -1,993 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1989, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Tom Truscott. - * - * 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 -#include -#include -#include - -/* - * UNIX password, and DES, encryption. - * By Tom Truscott, trt@rti.rti.org, - * from algorithms by Robert W. Baldwin and James Gillogly. - * - * References: - * "Mathematical Cryptology for Computer Scientists and Mathematicians," - * by Wayne Patterson, 1987, ISBN 0-8476-7438-X. - * - * "Password Security: A Case History," R. Morris and Ken Thompson, - * Communications of the ACM, vol. 22, pp. 594-597, Nov. 1979. - * - * "DES will be Totally Insecure within Ten Years," M.E. Hellman, - * IEEE Spectrum, vol. 16, pp. 32-39, July 1979. - */ - -/* ===== Configuration ==================== */ - -/* - * 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!) - */ -#if !defined(vax) -#define MUST_ALIGN -#endif - -#ifdef CHAR_BITS -#if CHAR_BITS != 8 - #error C_block structure assumes 8 bit characters -#endif -#endif - -/* - * 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) -#define LONG_IS_32_BITS -#endif - -/* - * define "B64" to be the declaration for a 64 bit integer. - * XXX this feature is currently unused, see "endian" comment below. - */ -#if defined(cray) -#define B64 long -#endif -#if defined(convex) -#define B64 long long -#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 - * little effect on crypt(). - */ -#if defined(notdef) -#define LARGEDATA -#endif - -/* compile with "-DSTATIC=int" when profiling */ -#ifndef STATIC -#define STATIC static -#endif -STATIC void init_des(), init_perm(), permute(); -#ifdef DEBUG -STATIC prtab(); -#endif - -/* ==================================== */ - -/* - * Cipher-block representation (Bob Baldwin): - * - * DES operates on groups of 64 bits, numbered 1..64 (sigh). One - * representation is to store one bit per byte in an array of bytes. Bit N of - * the NBS spec is stored as the LSB of the Nth byte (index N-1) in the array. - * Another representation stores the 64 bits in 8 bytes, with bits 1..8 in the - * first byte, 9..16 in the second, and so on. The DES spec apparently has - * bit 1 in the MSB of the first byte, but that is particularly noxious so we - * bit-reverse each byte so that bit 1 is the LSB of the first byte, bit 8 is - * the MSB of the first byte. Specifically, the 64-bit input data and key are - * converted to LSB format, and the output 64-bit block is converted back into - * MSB format. - * - * DES operates internally on groups of 32 bits which are expanded to 48 bits - * by permutation E and shrunk back to 32 bits by the S boxes. To speed up - * the computation, the expansion is applied only once, the expanded - * representation is maintained during the encryption, and a compression - * permutation is applied only at the end. To speed up the S-box lookups, - * the 48 bits are maintained as eight 6 bit groups, one per byte, which - * directly feed the eight S-boxes. Within each byte, the 6 bits are the - * most significant ones. The low two bits of each byte are zero. (Thus, - * bit 1 of the 48 bit E expansion is stored as the "4"-valued bit of the - * first byte in the eight byte representation, bit 2 of the 48 bit value is - * the "8"-valued bit, and so on.) In fact, a combined "SPE"-box lookup is - * used, in which the output is the 64 bit result of an S-box lookup which - * has been permuted by P and expanded by E, and is ready for use in the next - * iteration. Two 32-bit wide tables, SPE[0] and SPE[1], are used for this - * lookup. Since each byte in the 48 bit path is a multiple of four, indexed - * lookup of SPE[0] and SPE[1] is simple and fast. The key schedule and - * "salt" are also converted to this 8*(6+2) format. The SPE table size is - * 8*64*8 = 4K bytes. - * - * To speed up bit-parallel operations (such as XOR), the 8 byte - * representation is "union"ed with 32 bit values "i0" and "i1", and, on - * machines which support it, a 64 bit value "b64". This data structure, - * "C_block", has two problems. First, alignment restrictions must be - * honored. Second, the byte-order (e.g. little-endian or big-endian) of - * the architecture becomes visible. - * - * The byte-order problem is unfortunate, since on the one hand it is good - * to have a machine-independent C_block representation (bits 1..8 in the - * first byte, etc.), and on the other hand it is good for the LSB of the - * first byte to be the LSB of i0. We cannot have both these things, so we - * currently use the "little-endian" representation and avoid any multi-byte - * operations that depend on byte order. This largely precludes use of the - * 64-bit datatype since the relative order of i0 and i1 are unknown. It - * also inhibits grouping the SPE table to look up 12 bits at a time. (The - * 12 bits can be stored in a 16-bit field with 3 low-order zeroes and 1 - * high-order zero, providing fast indexing into a 64-bit wide SPE.) On the - * other hand, 64-bit datatypes are currently rare, and a 12-bit SPE lookup - * requires a 128 kilobyte table, so perhaps this is not a big loss. - * - * Permutation representation (Jim Gillogly): - * - * A transformation is defined by its effect on each of the 8 bytes of the - * 64-bit input. For each byte we give a 64-bit output that has the bits in - * the input distributed appropriately. The transformation is then the OR - * of the 8 sets of 64-bits. This uses 8*256*8 = 16K bytes of storage for - * each transformation. Unless LARGEDATA is defined, however, a more compact - * table is used which looks up 16 4-bit "chunks" rather than 8 8-bit chunks. - * The smaller table uses 16*16*8 = 2K bytes for each transformation. This - * is slower but tolerable, particularly for password encryption in which - * the SPE transformation is iterated many times. The small tables total 9K - * bytes, the large tables total 72K bytes. - * - * The transformations used are: - * IE3264: MSB->LSB conversion, initial permutation, and expansion. - * This is done by collecting the 32 even-numbered bits and applying - * a 32->64 bit transformation, and then collecting the 32 odd-numbered - * bits and applying the same transformation. Since there are only - * 32 input bits, the IE3264 transformation table is half the size of - * the usual table. - * CF6464: Compression, final permutation, and LSB->MSB conversion. - * This is done by two trivial 48->32 bit compressions to obtain - * a 64-bit block (the bit numbering is given in the "CIFP" table) - * followed by a 64->64 bit "cleanup" transformation. (It would - * be possible to group the bits in the 64-bit block so that 2 - * identical 32->32 bit transformations could be used instead, - * saving a factor of 4 in space and possibly 2 in time, but - * byte-ordering and other complications rear their ugly head. - * Similar opportunities/problems arise in the key schedule - * transforms.) - * PC1ROT: MSB->LSB, PC1 permutation, rotate, and PC2 permutation. - * This admittedly baroque 64->64 bit transformation is used to - * produce the first code (in 8*(6+2) format) of the key schedule. - * PC2ROT[0]: Inverse PC2 permutation, rotate, and PC2 permutation. - * It would be possible to define 15 more transformations, each - * with a different rotation, to generate the entire key schedule. - * To save space, however, we instead permute each code into the - * next by using a transformation that "undoes" the PC2 permutation, - * rotates the code, and then applies PC2. Unfortunately, PC2 - * transforms 56 bits into 48 bits, dropping 8 bits, so PC2 is not - * invertible. We get around that problem by using a modified PC2 - * which retains the 8 otherwise-lost bits in the unused low-order - * bits of each byte. The low-order bits are cleared when the - * codes are stored into the key schedule. - * PC2ROT[1]: Same as PC2ROT[0], but with two rotations. - * This is faster than applying PC2ROT[0] twice, - * - * The Bell Labs "salt" (Bob Baldwin): - * - * The salting is a simple permutation applied to the 48-bit result of E. - * Specifically, if bit i (1 <= i <= 24) of the salt is set then bits i and - * i+24 of the result are swapped. The salt is thus a 24 bit number, with - * 16777216 possible values. (The original salt was 12 bits and could not - * swap bits 13..24 with 36..48.) - * - * It is possible, but ugly, to warp the SPE table to account for the salt - * permutation. Fortunately, the conditional bit swapping requires only - * about four machine instructions and can be done on-the-fly with about an - * 8% performance penalty. - */ - -typedef union { - unsigned char b[8]; - struct { -#if defined(LONG_IS_32_BITS) - /* long is often faster than a 32-bit bit field */ - long i0; - long i1; -#else - long i0: 32; - long i1: 32; -#endif - } b32; -#if defined(B64) - B64 b64; -#endif -} C_block; - -/* - * Convert twenty-four-bit long in host-order - * to six bits (and 2 low-order zeroes) per char little-endian format. - */ -#define TO_SIX_BIT(rslt, src) { \ - C_block cvt; \ - cvt.b[0] = src; src >>= 6; \ - cvt.b[1] = src; src >>= 6; \ - cvt.b[2] = src; src >>= 6; \ - cvt.b[3] = src; \ - rslt = (cvt.b32.i0 & 0x3f3f3f3fL) << 2; \ - } - -/* - * These macros may someday permit efficient use of 64-bit integers. - */ -#define ZERO(d,d0,d1) d0 = 0, d1 = 0 -#define LOAD(d,d0,d1,bl) d0 = (bl).b32.i0, d1 = (bl).b32.i1 -#define LOADREG(d,d0,d1,s,s0,s1) d0 = s0, d1 = s1 -#define OR(d,d0,d1,bl) d0 |= (bl).b32.i0, d1 |= (bl).b32.i1 -#define STORE(s,s0,s1,bl) (bl).b32.i0 = s0, (bl).b32.i1 = s1 -#define DCL_BLOCK(d,d0,d1) long d0, d1 - -#if defined(LARGEDATA) - /* Waste memory like crazy. Also, do permutations in line */ -#define LGCHUNKBITS 3 -#define CHUNKBITS (1<>4]; OR(D,D0,D1,*tp); p += (1< 0); - STORE(D,D0,D1,*out); -} -#endif /* LARGEDATA */ - - -/* ===== (mostly) Standard DES Tables ==================== */ - -static unsigned char IP[] = { /* initial permutation */ - 58, 50, 42, 34, 26, 18, 10, 2, - 60, 52, 44, 36, 28, 20, 12, 4, - 62, 54, 46, 38, 30, 22, 14, 6, - 64, 56, 48, 40, 32, 24, 16, 8, - 57, 49, 41, 33, 25, 17, 9, 1, - 59, 51, 43, 35, 27, 19, 11, 3, - 61, 53, 45, 37, 29, 21, 13, 5, - 63, 55, 47, 39, 31, 23, 15, 7, -}; - -/* The final permutation is the inverse of IP - no table is necessary */ - -static unsigned char ExpandTr[] = { /* expansion operation */ - 32, 1, 2, 3, 4, 5, - 4, 5, 6, 7, 8, 9, - 8, 9, 10, 11, 12, 13, - 12, 13, 14, 15, 16, 17, - 16, 17, 18, 19, 20, 21, - 20, 21, 22, 23, 24, 25, - 24, 25, 26, 27, 28, 29, - 28, 29, 30, 31, 32, 1, -}; - -static unsigned char PC1[] = { /* permuted choice table 1 */ - 57, 49, 41, 33, 25, 17, 9, - 1, 58, 50, 42, 34, 26, 18, - 10, 2, 59, 51, 43, 35, 27, - 19, 11, 3, 60, 52, 44, 36, - - 63, 55, 47, 39, 31, 23, 15, - 7, 62, 54, 46, 38, 30, 22, - 14, 6, 61, 53, 45, 37, 29, - 21, 13, 5, 28, 20, 12, 4, -}; - -static unsigned char Rotates[] = { /* PC1 rotation schedule */ - 1, 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1, -}; - -/* note: each "row" of PC2 is left-padded with bits that make it invertible */ -static unsigned char PC2[] = { /* permuted choice table 2 */ - 9, 18, 14, 17, 11, 24, 1, 5, - 22, 25, 3, 28, 15, 6, 21, 10, - 35, 38, 23, 19, 12, 4, 26, 8, - 43, 54, 16, 7, 27, 20, 13, 2, - - 0, 0, 41, 52, 31, 37, 47, 55, - 0, 0, 30, 40, 51, 45, 33, 48, - 0, 0, 44, 49, 39, 56, 34, 53, - 0, 0, 46, 42, 50, 36, 29, 32, -}; - -static const unsigned char S[8][64] = { /* 48->32 bit substitution tables */ - /* S[1] */ - 14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12, 5, 9, 0, 7, - 0, 15, 7, 4, 14, 2, 13, 1, 10, 6, 12, 11, 9, 5, 3, 8, - 4, 1, 14, 8, 13, 6, 2, 11, 15, 12, 9, 7, 3, 10, 5, 0, - 15, 12, 8, 2, 4, 9, 1, 7, 5, 11, 3, 14, 10, 0, 6, 13, - /* S[2] */ - 15, 1, 8, 14, 6, 11, 3, 4, 9, 7, 2, 13, 12, 0, 5, 10, - 3, 13, 4, 7, 15, 2, 8, 14, 12, 0, 1, 10, 6, 9, 11, 5, - 0, 14, 7, 11, 10, 4, 13, 1, 5, 8, 12, 6, 9, 3, 2, 15, - 13, 8, 10, 1, 3, 15, 4, 2, 11, 6, 7, 12, 0, 5, 14, 9, - /* S[3] */ - 10, 0, 9, 14, 6, 3, 15, 5, 1, 13, 12, 7, 11, 4, 2, 8, - 13, 7, 0, 9, 3, 4, 6, 10, 2, 8, 5, 14, 12, 11, 15, 1, - 13, 6, 4, 9, 8, 15, 3, 0, 11, 1, 2, 12, 5, 10, 14, 7, - 1, 10, 13, 0, 6, 9, 8, 7, 4, 15, 14, 3, 11, 5, 2, 12, - /* S[4] */ - 7, 13, 14, 3, 0, 6, 9, 10, 1, 2, 8, 5, 11, 12, 4, 15, - 13, 8, 11, 5, 6, 15, 0, 3, 4, 7, 2, 12, 1, 10, 14, 9, - 10, 6, 9, 0, 12, 11, 7, 13, 15, 1, 3, 14, 5, 2, 8, 4, - 3, 15, 0, 6, 10, 1, 13, 8, 9, 4, 5, 11, 12, 7, 2, 14, - /* S[5] */ - 2, 12, 4, 1, 7, 10, 11, 6, 8, 5, 3, 15, 13, 0, 14, 9, - 14, 11, 2, 12, 4, 7, 13, 1, 5, 0, 15, 10, 3, 9, 8, 6, - 4, 2, 1, 11, 10, 13, 7, 8, 15, 9, 12, 5, 6, 3, 0, 14, - 11, 8, 12, 7, 1, 14, 2, 13, 6, 15, 0, 9, 10, 4, 5, 3, - /* S[6] */ - 12, 1, 10, 15, 9, 2, 6, 8, 0, 13, 3, 4, 14, 7, 5, 11, - 10, 15, 4, 2, 7, 12, 9, 5, 6, 1, 13, 14, 0, 11, 3, 8, - 9, 14, 15, 5, 2, 8, 12, 3, 7, 0, 4, 10, 1, 13, 11, 6, - 4, 3, 2, 12, 9, 5, 15, 10, 11, 14, 1, 7, 6, 0, 8, 13, - /* S[7] */ - 4, 11, 2, 14, 15, 0, 8, 13, 3, 12, 9, 7, 5, 10, 6, 1, - 13, 0, 11, 7, 4, 9, 1, 10, 14, 3, 5, 12, 2, 15, 8, 6, - 1, 4, 11, 13, 12, 3, 7, 14, 10, 15, 6, 8, 0, 5, 9, 2, - 6, 11, 13, 8, 1, 4, 10, 7, 9, 5, 0, 15, 14, 2, 3, 12, - /* S[8] */ - 13, 2, 8, 4, 6, 15, 11, 1, 10, 9, 3, 14, 5, 0, 12, 7, - 1, 15, 13, 8, 10, 3, 7, 4, 12, 5, 6, 11, 0, 14, 9, 2, - 7, 11, 4, 1, 9, 12, 14, 2, 0, 6, 10, 13, 15, 3, 5, 8, - 2, 1, 14, 7, 4, 10, 8, 13, 15, 12, 9, 0, 3, 5, 6, 11, -}; - -static unsigned char P32Tr[] = { /* 32-bit permutation function */ - 16, 7, 20, 21, - 29, 12, 28, 17, - 1, 15, 23, 26, - 5, 18, 31, 10, - 2, 8, 24, 14, - 32, 27, 3, 9, - 19, 13, 30, 6, - 22, 11, 4, 25, -}; - -static unsigned char CIFP[] = { /* compressed/interleaved permutation */ - 1, 2, 3, 4, 17, 18, 19, 20, - 5, 6, 7, 8, 21, 22, 23, 24, - 9, 10, 11, 12, 25, 26, 27, 28, - 13, 14, 15, 16, 29, 30, 31, 32, - - 33, 34, 35, 36, 49, 50, 51, 52, - 37, 38, 39, 40, 53, 54, 55, 56, - 41, 42, 43, 44, 57, 58, 59, 60, - 45, 46, 47, 48, 61, 62, 63, 64, -}; - -static unsigned char itoa64[] = /* 0..63 => ascii-64 */ - "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; - - -/* ===== Tables that are initialized at run time ==================== */ - - -static unsigned char a64toi[128]; /* ascii-64 => 0..63 */ - -/* Initial key schedule permutation */ -// static C_block PC1ROT[64/CHUNKBITS][1< final permutation table */ -// static C_block CF6464[64/CHUNKBITS][1<= 0; ) { - if ((t = (unsigned char)setting[i]) == '\0') - t = '.'; - encp[i] = t; - num_iter = (num_iter<<6) | a64toi[t]; - } - setting += 4; - encp += 4; - salt_size = 4; - break; - default: - num_iter = 25; - salt_size = 2; - } - - salt = 0; - for (i = salt_size; --i >= 0; ) { - if ((t = (unsigned char)setting[i]) == '\0') - t = '.'; - encp[i] = t; - salt = (salt<<6) | a64toi[t]; - } - encp += salt_size; - if (des_cipher((char *)&constdatablock, (char *)&rsltblock, - salt, num_iter)) - return (NULL); - - /* - * Encode the 64 cipher bits as 11 ascii characters. - */ - i = ((long)((rsltblock.b[0]<<8) | rsltblock.b[1])<<8) | rsltblock.b[2]; - encp[3] = itoa64[i&0x3f]; i >>= 6; - encp[2] = itoa64[i&0x3f]; i >>= 6; - encp[1] = itoa64[i&0x3f]; i >>= 6; - encp[0] = itoa64[i]; encp += 4; - i = ((long)((rsltblock.b[3]<<8) | rsltblock.b[4])<<8) | rsltblock.b[5]; - encp[3] = itoa64[i&0x3f]; i >>= 6; - encp[2] = itoa64[i&0x3f]; i >>= 6; - encp[1] = itoa64[i&0x3f]; i >>= 6; - encp[0] = itoa64[i]; encp += 4; - i = ((long)((rsltblock.b[6])<<8) | rsltblock.b[7])<<2; - encp[2] = itoa64[i&0x3f]; i >>= 6; - encp[1] = itoa64[i&0x3f]; i >>= 6; - encp[0] = itoa64[i]; - - encp[3] = 0; - - return (cryptresult); -} - - -/* - * The Key Schedule, filled in by 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) - register const char *key; -{ - register DCL_BLOCK(K, K0, K1); - register C_block *ptabp; - register int i; - static int des_ready = 0; - - if (!des_ready) { - init_des(); - des_ready = 1; - } - - PERM6464(K,K0,K1,(unsigned char *)key,PC1ROT); - key = (char *)&KS[0]; - STORE(K&~0x03030303L, K0&~0x03030303L, K1, *(C_block *)key); - for (i = 1; i < 16; i++) { - key += sizeof(C_block); - STORE(K,K0,K1,*(C_block *)key); - ptabp = PC2ROT[Rotates[i]-1]; - PERM6464(K,K0,K1,(unsigned char *)key,ptabp); - STORE(K&~0x03030303L, K0&~0x03030303L, K1, *(C_block *)key); - } - return (0); -} - -/* - * Encrypt (or decrypt if num_iter < 0) the 8 chars at "in" with abs(num_iter) - * iterations of DES, using the the given 24-bit salt and the pre-computed key - * schedule, and store the resulting 8 chars at "out" (in == out is permitted). - * - * NOTE: the performance of this routine is critically dependent on your - * compiler and machine architecture. - */ -STATIC int des_cipher(in, out, salt, num_iter) - const char *in; - char *out; - long salt; - int num_iter; -{ - /* variables that we want in registers, most important first */ -#if defined(pdp11) - register int j; -#endif - register long L0, L1, R0, R1, k; - register C_block *kp; - register int ks_inc, loop_count; - C_block B; - - L0 = salt; - TO_SIX_BIT(salt, L0); /* convert to 4*(6+2) format */ - -#if defined(vax) || defined(pdp11) - salt = ~salt; /* "x &~ y" is faster than "x & y". */ -#define SALT (~salt) -#else -#define SALT salt -#endif - -#if defined(MUST_ALIGN) - B.b[0] = in[0]; B.b[1] = in[1]; B.b[2] = in[2]; B.b[3] = in[3]; - B.b[4] = in[4]; B.b[5] = in[5]; B.b[6] = in[6]; B.b[7] = in[7]; - LOAD(L,L0,L1,B); -#else - LOAD(L,L0,L1,*(C_block *)in); -#endif - LOADREG(R,R0,R1,L,L0,L1); - L0 &= 0x55555555L; - L1 &= 0x55555555L; - L0 = (L0 << 1) | L1; /* L0 is the even-numbered input bits */ - R0 &= 0xaaaaaaaaL; - R1 = (R1 >> 1) & 0x55555555L; - L1 = R0 | R1; /* L1 is the odd-numbered input bits */ - STORE(L,L0,L1,B); - PERM3264(L,L0,L1,B.b,IE3264); /* even bits */ - PERM3264(R,R0,R1,B.b+4,IE3264); /* odd bits */ - - if (num_iter >= 0) - { /* encryption */ - kp = &KS[0]; - ks_inc = sizeof(*kp); - } - else - { /* decryption */ - num_iter = -num_iter; - kp = &KS[KS_SIZE-1]; - ks_inc = -sizeof(*kp); - } - - while (--num_iter >= 0) { - loop_count = 8; - do { - -#define SPTAB(t, i) (*(long *)((unsigned char *)t + i*(sizeof(long)/4))) -#if defined(gould) - /* use this if B.b[i] is evaluated just once ... */ -#define DOXOR(x,y,i) x^=SPTAB(&SPE[i * 64],B.b[i]); y^=SPTAB(&SPE[(8 * 64) + (i * 64)],B.b[i]); -#else -#if defined(pdp11) - /* use this if your "long" int indexing is slow */ -#define DOXOR(x,y,i) j=B.b[i]; x^=SPTAB(&SPE[i * 64],j); y^=SPTAB(&SPE[(8 * 64) + (i * 64)],j); -#else - /* use this if "k" is allocated to a register ... */ -#define DOXOR(x,y,i) k=B.b[i]; x^=SPTAB(&SPE[i * 64],k); y^=SPTAB(&SPE[(8 * 64) + (i * 64)],k); -#endif -#endif - -#define CRUNCH(p0, p1, q0, q1) \ - k = (q0 ^ q1) & SALT; \ - B.b32.i0 = k ^ q0 ^ kp->b32.i0; \ - B.b32.i1 = k ^ q1 ^ kp->b32.i1; \ - kp = (C_block *)((char *)kp+ks_inc); \ - \ - DOXOR(p0, p1, 0); \ - DOXOR(p0, p1, 1); \ - DOXOR(p0, p1, 2); \ - DOXOR(p0, p1, 3); \ - DOXOR(p0, p1, 4); \ - DOXOR(p0, p1, 5); \ - DOXOR(p0, p1, 6); \ - DOXOR(p0, p1, 7); - - CRUNCH(L0, L1, R0, R1); - CRUNCH(R0, R1, L0, L1); - } while (--loop_count != 0); - kp = (C_block *)((char *)kp-(ks_inc*KS_SIZE)); - - - /* swap L and R */ - L0 ^= R0; L1 ^= R1; - R0 ^= L0; R1 ^= L1; - L0 ^= R0; L1 ^= R1; - } - - /* store the encrypted (or decrypted) result */ - L0 = ((L0 >> 3) & 0x0f0f0f0fL) | ((L1 << 1) & 0xf0f0f0f0L); - L1 = ((R0 >> 3) & 0x0f0f0f0fL) | ((R1 << 1) & 0xf0f0f0f0L); - STORE(L,L0,L1,B); - PERM6464(L,L0,L1,B.b,CF6464); -#if defined(MUST_ALIGN) - STORE(L,L0,L1,B); - out[0] = B.b[0]; out[1] = B.b[1]; out[2] = B.b[2]; out[3] = B.b[3]; - out[4] = B.b[4]; out[5] = B.b[5]; out[6] = B.b[6]; out[7] = B.b[7]; -#else - STORE(L,L0,L1,*(C_block *)out); -#endif - return (0); -} - - -/* - * Initialize various tables. This need only be done once. It could even be - * done at compile time, if the compiler were capable of that sort of thing. - */ -STATIC void init_des() -{ - register int i, j; - register long k; - register int tableno; - static unsigned char perm[64], tmp32[32]; /* "static" for speed */ - - /* - * table that converts chars "./0-9A-Za-z"to integers 0-63. - */ - for (i = 0; i < 64; i++) - a64toi[itoa64[i]] = i; - - /* - * PC1ROT - bit reverse, then PC1, then Rotate, then PC2. - */ - for (i = 0; i < 64; i++) - perm[i] = 0; - for (i = 0; i < 64; i++) { - if ((k = PC2[i]) == 0) - continue; - k += Rotates[0]-1; - if ((k%28) < Rotates[0]) k -= 28; - k = PC1[k]; - if (k > 0) { - k--; - k = (k|07) - (k&07); - k++; - } - perm[i] = k; - } -#ifdef DEBUG - prtab("pc1tab", perm, 8); -#endif - PC1ROT = (C_block *)calloc(sizeof(C_block), (64/CHUNKBITS) * (1< 32) - k -= 32; - else if (k > 0) - k--; - if (k > 0) { - k--; - k = (k|07) - (k&07); - k++; - } - perm[i*8+j] = k; - } - } -#ifdef DEBUG - prtab("ietab", perm, 8); -#endif - IE3264 = (C_block *)calloc(sizeof(C_block), (32/CHUNKBITS) * (1< 0) { - k--; - k = (k|07) - (k&07); - k++; - } - perm[k-1] = i+1; - } -#ifdef DEBUG - prtab("cftab", perm, 8); -#endif - CF6464 = (C_block *)calloc(sizeof(C_block), (64/CHUNKBITS) * (1<> 0) &01) << 5)| - (((j >> 1) &01) << 3)| - (((j >> 2) &01) << 2)| - (((j >> 3) &01) << 1)| - (((j >> 4) &01) << 0)| - (((j >> 5) &01) << 4); - k = S[tableno][k]; - k = (((k >> 3)&01) << 0)| - (((k >> 2)&01) << 1)| - (((k >> 1)&01) << 2)| - (((k >> 0)&01) << 3); - for (i = 0; i < 32; i++) - tmp32[i] = 0; - for (i = 0; i < 4; i++) - tmp32[4 * tableno + i] = (k >> i) & 01; - k = 0; - for (i = 24; --i >= 0; ) - k = (k<<1) | tmp32[perm[i]-1]; - TO_SIX_BIT(SPE[(tableno * 64) + j], k); - k = 0; - for (i = 24; --i >= 0; ) - k = (k<<1) | tmp32[perm[i+24]-1]; - TO_SIX_BIT(SPE[(8 * 64) + (tableno * 64) + j], k); - } - } -} - -/* - * Initialize "perm" to represent transformation "p", which rearranges - * (perhaps with expansion and/or contraction) one packed array of bits - * (of size "chars_in" characters) into another array (of size "chars_out" - * characters). - * - * "perm" must be all-zeroes on entry to this routine. - */ -STATIC void init_perm(perm, p, chars_in, chars_out) - C_block *perm; - unsigned char p[64]; - int chars_in, chars_out; -{ - register int i, j, k, l; - - for (k = 0; k < chars_out*8; k++) { /* each output bit position */ - l = p[k] - 1; /* where this bit comes from */ - if (l < 0) - continue; /* output bit is always 0 */ - i = l>>LGCHUNKBITS; /* which chunk this bit comes from */ - l = 1<<(l&(CHUNKBITS-1)); /* mask for this bit */ - for (j = 0; j < (1<>3] |= 1<<(k&07); - } - } -} - -/* - * "setkey" routine (for backwards compatibility) - */ -int setkey(key) - register const char *key; -{ - register int i, j, k; - C_block keyblock; - - for (i = 0; i < 8; i++) { - k = 0; - for (j = 0; j < 8; j++) { - k <<= 1; - k |= (unsigned char)*key++; - } - keyblock.b[i] = k; - } - return (des_setkey((char *)keyblock.b)); -} - -/* - * "encrypt" routine (for backwards compatibility) - */ -int encrypt(block, flag) - register char *block; - int flag; -{ - register int i, j, k; - C_block cblock; - - for (i = 0; i < 8; i++) { - k = 0; - for (j = 0; j < 8; j++) { - k <<= 1; - k |= (unsigned char)*block++; - } - cblock.b[i] = k; - } - if (des_cipher((char *)&cblock, (char *)&cblock, 0L, (flag ? -1: 1))) - return (1); - for (i = 7; i >= 0; i--) { - k = cblock.b[i]; - for (j = 7; j >= 0; j--) { - *--block = k&01; - k >>= 1; - } - } - return (0); -} - -#ifdef DEBUG -STATIC -prtab(s, t, num_rows) - char *s; - unsigned char *t; - int num_rows; -{ - register int i, j; - - (void)printf("%s:\n", s); - for (i = 0; i < num_rows; i++) { - for (j = 0; j < 8; j++) { - (void)printf("%3d", t[i*8+j]); - } - (void)printf("\n"); - } - (void)printf("\n"); -} -#endif diff --git a/gen.subproj/ctermid.c b/gen.subproj/ctermid.c deleted file mode 100644 index 507c9cf..0000000 --- a/gen.subproj/ctermid.c +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 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 -#include -#include - -char * -ctermid(s) - char *s; -{ - static char def[] = _PATH_TTY; - - if (s) { - bcopy(def, s, sizeof(_PATH_TTY)); - return(s); - } - return(def); -} diff --git a/gen.subproj/ctime.c b/gen.subproj/ctime.c deleted file mode 100644 index d8b0656..0000000 --- a/gen.subproj/ctime.c +++ /dev/null @@ -1,1399 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1987, 1989, 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. - */ - - -/* -** Leap second handling from Bradley White (bww@k.gp.cs.cmu.edu). -** POSIX-style TZ environment variable handling from Guy Harris -** (guy@auspex.com). -*/ - -/*LINTLIBRARY*/ - -#include -#include -#include -#include -#include -#include -#include -#include - -#ifdef __STDC__ -#include - -#define P(s) s -#define alloc_size_t size_t -#define qsort_size_t size_t -#define fread_size_t size_t -#define fwrite_size_t size_t - -#else /* !defined __STDC__ */ - -#define P(s) () - -typedef char * genericptr_t; -typedef unsigned alloc_size_t; -typedef int qsort_size_t; -typedef int fread_size_t; -typedef int fwrite_size_t; - -extern char * calloc(); -extern char * malloc(); -extern char * realloc(); -extern char * getenv(); - -#endif /* !defined __STDC__ */ - -extern time_t time(); - -#define ACCESS_MODE O_RDONLY -#define OPEN_MODE O_RDONLY - -#ifndef WILDABBR -/* -** Someone might make incorrect use of a time zone abbreviation: -** 1. They might reference tzname[0] before calling tzset (explicitly -** or implicitly). -** 2. They might reference tzname[1] before calling tzset (explicitly -** or implicitly). -** 3. They might reference tzname[1] after setting to a time zone -** in which Daylight Saving Time is never observed. -** 4. They might reference tzname[0] after setting to a time zone -** in which Standard Time is never observed. -** 5. They might reference tm.TM_ZONE after calling offtime. -** What's best to do in the above cases is open to debate; -** for now, we just set things up so that in any of the five cases -** WILDABBR is used. Another possibility: initialize tzname[0] to the -** string "tzname[0] used before set", and similarly for the other cases. -** And another: initialize tzname[0] to "ERA", with an explanation in the -** manual page of what this "time zone abbreviation" means (doing this so -** that tzname[0] has the "normal" length of three characters). -*/ -#define WILDABBR " " -#endif /* !defined WILDABBR */ - -#ifndef TRUE -#define TRUE 1 -#define FALSE 0 -#endif /* !defined TRUE */ - -static const char GMT[] = "GMT"; - -struct ttinfo { /* time type information */ - long tt_gmtoff; /* GMT 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 */ -}; - -struct lsinfo { /* leap second information */ - time_t ls_trans; /* transition time */ - long ls_corr; /* correction to apply */ -}; - -struct state { - int leapcnt; - int timecnt; - int typecnt; - int charcnt; - time_t ats[TZ_MAX_TIMES]; - unsigned char types[TZ_MAX_TIMES]; - struct ttinfo ttis[TZ_MAX_TYPES]; - char chars[(TZ_MAX_CHARS + 1 > sizeof GMT) ? - TZ_MAX_CHARS + 1 : sizeof GMT]; - struct lsinfo lsis[TZ_MAX_LEAPS]; -}; - -struct rule { - int r_type; /* type of rule--see below */ - int r_day; /* day number of rule */ - int r_week; /* week number of rule */ - int r_mon; /* month number of rule */ - long r_time; /* transition time of rule */ -}; - -#define JULIAN_DAY 0 /* Jn - Julian day */ -#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. -*/ - -static long detzcode P((const char * codep)); -static const char * getzname P((const char * strp)); -static const char * getnum P((const char * strp, int * nump, int min, - int max)); -static const char * getsecs P((const char * strp, long * secsp)); -static const char * getoffset P((const char * strp, long * offsetp)); -static const char * getrule P((const char * strp, struct rule * rulep)); -static void gmtload P((struct state * sp)); -static void gmtsub P((const time_t * timep, long offset, - struct tm * tmp)); -static void localsub P((const time_t * timep, long offset, - struct tm * tmp)); -static void normalize P((int * tensptr, int * unitsptr, int base)); -static void settzname P((void)); -static time_t time1 P((struct tm * tmp, void (* funcp)(), - long offset)); -static time_t time2 P((struct tm *tmp, void (* funcp)(), - long offset, int * okayp)); -static void timesub P((const time_t * timep, long offset, - const struct state * sp, struct tm * tmp)); -static int tmcomp P((const struct tm * atmp, - const struct tm * btmp)); -static time_t transtime P((time_t janfirst, int year, - const struct rule * rulep, long offset)); -static int tzload P((const char * name, struct state * sp)); -static int tzparse P((const char * name, struct state * sp, - int lastditch)); - -#ifdef ALL_STATE -static struct state * lclptr; -static struct state * gmtptr; -#endif /* defined ALL_STATE */ - -#ifndef ALL_STATE -static struct state lclmem; -static struct state gmtmem; -#define lclptr (&lclmem) -#define gmtptr (&gmtmem) -#endif /* State Farm */ - -static int lcl_is_set; -static int gmt_is_set; - -char * tzname[2] = { - WILDABBR, - WILDABBR -}; - -#ifdef USG_COMPAT -time_t timezone = 0; -int daylight = 0; -#endif /* defined USG_COMPAT */ - -#ifdef ALTZONE -time_t altzone = 0; -#endif /* defined ALTZONE */ - -static long -detzcode(codep) -const char * const codep; -{ - register long result; - register int i; - - result = 0; - for (i = 0; i < 4; ++i) - result = (result << 8) | (codep[i] & 0xff); - return result; -} - -static void -settzname() -{ - register const struct state * const sp = lclptr; - register int i; - - tzname[0] = WILDABBR; - tzname[1] = WILDABBR; -#ifdef USG_COMPAT - daylight = 0; - timezone = 0; -#endif /* defined USG_COMPAT */ -#ifdef ALTZONE - altzone = 0; -#endif /* defined ALTZONE */ -#ifdef ALL_STATE - if (sp == NULL) { - tzname[0] = tzname[1] = GMT; - return; - } -#endif /* defined ALL_STATE */ - for (i = 0; i < sp->typecnt; ++i) { - register const struct ttinfo * const ttisp = &sp->ttis[i]; - - tzname[ttisp->tt_isdst] = - (char *) &sp->chars[ttisp->tt_abbrind]; -#ifdef USG_COMPAT - if (ttisp->tt_isdst) - daylight = 1; - if (i == 0 || !ttisp->tt_isdst) - timezone = -(ttisp->tt_gmtoff); -#endif /* defined USG_COMPAT */ -#ifdef ALTZONE - if (i == 0 || ttisp->tt_isdst) - altzone = -(ttisp->tt_gmtoff); -#endif /* defined ALTZONE */ - } - /* - ** And to get the latest zone names into tzname. . . - */ - for (i = 0; i < sp->timecnt; ++i) { - register const struct ttinfo * const ttisp = - &sp->ttis[sp->types[i]]; - - tzname[ttisp->tt_isdst] = - (char *) &sp->chars[ttisp->tt_abbrind]; - } -} - -static int -tzload(name, sp) -register const char * name; -register struct state * const sp; -{ - register const char * p; - register int i; - register int fid; - - if (name == NULL && (name = TZDEFAULT) == NULL) - return -1; - { - char fullname[FILENAME_MAX + 1]; - - if (name[0] == ':') - ++name; - if (name[0] != '/') { - if ((p = TZDIR) == NULL) - return -1; - if ((strlen(p) + strlen(name) + 1) >= sizeof fullname) - return -1; - (void) strcpy(fullname, p); - (void) strcat(fullname, "/"); - (void) strcat(fullname, name); - name = fullname; - } - if ((fid = open(name, OPEN_MODE)) == -1) - return -1; - } - { - register const struct tzhead * tzhp; - char buf[sizeof *sp + sizeof *tzhp]; - int ttisstdcnt; - - i = read(fid, buf, sizeof buf); - if (close(fid) != 0 || i < sizeof *tzhp) - return -1; - tzhp = (struct tzhead *) buf; - ttisstdcnt = (int) detzcode(tzhp->tzh_ttisstdcnt); - sp->leapcnt = (int) detzcode(tzhp->tzh_leapcnt); - sp->timecnt = (int) detzcode(tzhp->tzh_timecnt); - sp->typecnt = (int) detzcode(tzhp->tzh_typecnt); - sp->charcnt = (int) detzcode(tzhp->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 || - sp->charcnt < 0 || sp->charcnt > TZ_MAX_CHARS || - (ttisstdcnt != sp->typecnt && ttisstdcnt != 0)) - return -1; - if (i < sizeof *tzhp + - sp->timecnt * (4 + sizeof (char)) + - sp->typecnt * (4 + 2 * sizeof (char)) + - sp->charcnt * sizeof (char) + - sp->leapcnt * 2 * 4 + - ttisstdcnt * sizeof (char)) - return -1; - p = buf + sizeof *tzhp; - for (i = 0; i < sp->timecnt; ++i) { - sp->ats[i] = detzcode(p); - p += 4; - } - for (i = 0; i < sp->timecnt; ++i) { - sp->types[i] = (unsigned char) *p++; - if (sp->types[i] >= sp->typecnt) - return -1; - } - for (i = 0; i < sp->typecnt; ++i) { - register struct ttinfo * ttisp; - - ttisp = &sp->ttis[i]; - ttisp->tt_gmtoff = detzcode(p); - p += 4; - ttisp->tt_isdst = (unsigned char) *p++; - if (ttisp->tt_isdst != 0 && ttisp->tt_isdst != 1) - return -1; - ttisp->tt_abbrind = (unsigned char) *p++; - if (ttisp->tt_abbrind < 0 || - ttisp->tt_abbrind > sp->charcnt) - return -1; - } - for (i = 0; i < sp->charcnt; ++i) - sp->chars[i] = *p++; - sp->chars[i] = '\0'; /* ensure '\0' at end */ - for (i = 0; i < sp->leapcnt; ++i) { - register struct lsinfo * lsisp; - - lsisp = &sp->lsis[i]; - lsisp->ls_trans = detzcode(p); - p += 4; - lsisp->ls_corr = detzcode(p); - p += 4; - } - for (i = 0; i < sp->typecnt; ++i) { - register struct ttinfo * ttisp; - - ttisp = &sp->ttis[i]; - if (ttisstdcnt == 0) - ttisp->tt_ttisstd = FALSE; - else { - ttisp->tt_ttisstd = *p++; - if (ttisp->tt_ttisstd != TRUE && - ttisp->tt_ttisstd != FALSE) - return -1; - } - } - } - return 0; -} - -static const int mon_lengths[2][MONSPERYEAR] = { - 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, - 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 -}; - -static const int year_lengths[2] = { - DAYSPERNYEAR, DAYSPERLYEAR -}; - -/* -** Given a pointer into a time zone string, scan until a character that is not -** a valid character in a zone name is found. Return a pointer to that -** character. -*/ - -static const char * -getzname(strp) -register const char * strp; -{ - register char c; - - while ((c = *strp) != '\0' && !isdigit(c) && c != ',' && c != '-' && - c != '+') - ++strp; - return strp; -} - -/* -** Given a pointer into a time zone string, extract a number from that string. -** Check that the number is within a specified range; if it is not, return -** NULL. -** Otherwise, return a pointer to the first character not part of the number. -*/ - -static const char * -getnum(strp, nump, min, max) -register const char * strp; -int * const nump; -const int min; -const int max; -{ - register char c; - register int num; - - if (strp == NULL || !isdigit(*strp)) - return NULL; - num = 0; - while ((c = *strp) != '\0' && isdigit(c)) { - num = num * 10 + (c - '0'); - if (num > max) - return NULL; /* illegal value */ - ++strp; - } - if (num < min) - return NULL; /* illegal value */ - *nump = num; - return strp; -} - -/* -** Given a pointer into a time zone string, extract a number of seconds, -** in hh[:mm[:ss]] form, from the string. -** If any error occurs, return NULL. -** Otherwise, return a pointer to the first character not part of the number -** of seconds. -*/ - -static const char * -getsecs(strp, secsp) -register const char * strp; -long * const secsp; -{ - int num; - - strp = getnum(strp, &num, 0, HOURSPERDAY); - if (strp == NULL) - return NULL; - *secsp = num * SECSPERHOUR; - if (*strp == ':') { - ++strp; - strp = getnum(strp, &num, 0, MINSPERHOUR - 1); - if (strp == NULL) - return NULL; - *secsp += num * SECSPERMIN; - if (*strp == ':') { - ++strp; - strp = getnum(strp, &num, 0, SECSPERMIN - 1); - if (strp == NULL) - return NULL; - *secsp += num; - } - } - return strp; -} - -/* -** Given a pointer into a time zone string, extract an offset, in -** [+-]hh[:mm[:ss]] form, from the string. -** If any error occurs, return NULL. -** Otherwise, return a pointer to the first character not part of the time. -*/ - -static const char * -getoffset(strp, offsetp) -register const char * strp; -long * const offsetp; -{ - register int neg; - - if (*strp == '-') { - neg = 1; - ++strp; - } else if (isdigit(*strp) || *strp++ == '+') - neg = 0; - else return NULL; /* illegal offset */ - strp = getsecs(strp, offsetp); - if (strp == NULL) - return NULL; /* illegal time */ - if (neg) - *offsetp = -*offsetp; - return strp; -} - -/* -** Given a pointer into a time zone string, extract a rule in the form -** date[/time]. See POSIX section 8 for the format of "date" and "time". -** If a valid rule is not found, return NULL. -** Otherwise, return a pointer to the first character not part of the rule. -*/ - -static const char * -getrule(strp, rulep) -const char * strp; -register struct rule * const rulep; -{ - if (*strp == 'J') { - /* - ** Julian day. - */ - rulep->r_type = JULIAN_DAY; - ++strp; - strp = getnum(strp, &rulep->r_day, 1, DAYSPERNYEAR); - } else if (*strp == 'M') { - /* - ** Month, week, day. - */ - rulep->r_type = MONTH_NTH_DAY_OF_WEEK; - ++strp; - strp = getnum(strp, &rulep->r_mon, 1, MONSPERYEAR); - if (strp == NULL) - return NULL; - if (*strp++ != '.') - return NULL; - strp = getnum(strp, &rulep->r_week, 1, 5); - if (strp == NULL) - return NULL; - if (*strp++ != '.') - return NULL; - strp = getnum(strp, &rulep->r_day, 0, DAYSPERWEEK - 1); - } else if (isdigit(*strp)) { - /* - ** Day of year. - */ - rulep->r_type = DAY_OF_YEAR; - strp = getnum(strp, &rulep->r_day, 0, DAYSPERLYEAR - 1); - } else return NULL; /* invalid format */ - if (strp == NULL) - return NULL; - if (*strp == '/') { - /* - ** Time specified. - */ - ++strp; - strp = getsecs(strp, &rulep->r_time); - } else rulep->r_time = 2 * SECSPERHOUR; /* default = 2:00:00 */ - return strp; -} - -/* -** 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, -** calculate the Epoch-relative time that rule takes effect. -*/ - -static time_t -transtime(janfirst, year, rulep, offset) -const time_t janfirst; -const int year; -register const struct rule * const rulep; -const long offset; -{ - register int leapyear; - register time_t value; - register int i; - int d, m1, yy0, yy1, yy2, dow; - - leapyear = isleap(year); - switch (rulep->r_type) { - - case JULIAN_DAY: - /* - ** Jn - Julian day, 1 == January 1, 60 == March 1 even in leap - ** years. - ** In non-leap years, or if the day number is 59 or less, just - ** add SECSPERDAY times the day number-1 to the time of - ** January 1, midnight, to get the day. - */ - value = janfirst + (rulep->r_day - 1) * SECSPERDAY; - if (leapyear && rulep->r_day >= 60) - value += SECSPERDAY; - break; - - case DAY_OF_YEAR: - /* - ** n - day of year. - ** Just add SECSPERDAY times the day number to the time of - ** January 1, midnight, to get the day. - */ - value = janfirst + rulep->r_day * SECSPERDAY; - break; - - case MONTH_NTH_DAY_OF_WEEK: - /* - ** Mm.n.d - nth "dth day" of month m. - */ - value = janfirst; - for (i = 0; i < rulep->r_mon - 1; ++i) - value += mon_lengths[leapyear][i] * SECSPERDAY; - - /* - ** Use Zeller's Congruence to get day-of-week of first day of - ** month. - */ - m1 = (rulep->r_mon + 9) % 12 + 1; - yy0 = (rulep->r_mon <= 2) ? (year - 1) : year; - yy1 = yy0 / 100; - yy2 = yy0 % 100; - dow = ((26 * m1 - 2) / 10 + - 1 + yy2 + yy2 / 4 + yy1 / 4 - 2 * yy1) % 7; - if (dow < 0) - dow += DAYSPERWEEK; - - /* - ** "dow" is the day-of-week of the first day of the month. Get - ** the day-of-month (zero-origin) of the first "dow" day of the - ** month. - */ - d = rulep->r_day - dow; - if (d < 0) - d += DAYSPERWEEK; - for (i = 1; i < rulep->r_week; ++i) { - if (d + DAYSPERWEEK >= - mon_lengths[leapyear][rulep->r_mon - 1]) - break; - d += DAYSPERWEEK; - } - - /* - ** "d" is the day-of-month (zero-origin) of the day we want. - */ - value += d * SECSPERDAY; - break; - } - - /* - ** "value" is the Epoch-relative time of 00:00:00 GMT 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. - */ - return value + rulep->r_time + offset; -} - -/* -** Given a POSIX section 8-style TZ string, fill in the rule tables as -** appropriate. -*/ - -static int -tzparse(name, sp, lastditch) -const char * name; -register struct state * const sp; -const int lastditch; -{ - const char * stdname; - const char * dstname; - int stdlen; - int dstlen; - long stdoffset; - long dstoffset; - register time_t * atp; - register unsigned char * typep; - register char * cp; - register int load_result; - - stdname = name; - if (lastditch) { - stdlen = strlen(name); /* length of standard zone name */ - name += stdlen; - if (stdlen >= sizeof sp->chars) - stdlen = (sizeof sp->chars) - 1; - } else { - name = getzname(name); - stdlen = name - stdname; - if (stdlen < 3) - return -1; - } - if (*name == '\0') - return -1; - else { - name = getoffset(name, &stdoffset); - if (name == NULL) - return -1; - } - load_result = tzload(TZDEFRULES, sp); - if (load_result != 0) - sp->leapcnt = 0; /* so, we're off a little */ - if (*name != '\0') { - dstname = name; - name = getzname(name); - dstlen = name - dstname; /* length of DST zone name */ - if (dstlen < 3) - return -1; - if (*name != '\0' && *name != ',' && *name != ';') { - name = getoffset(name, &dstoffset); - if (name == NULL) - return -1; - } else dstoffset = stdoffset - SECSPERHOUR; - if (*name == ',' || *name == ';') { - struct rule start; - struct rule end; - register int year; - register time_t janfirst; - time_t starttime; - time_t endtime; - - ++name; - if ((name = getrule(name, &start)) == NULL) - return -1; - if (*name++ != ',') - return -1; - if ((name = getrule(name, &end)) == NULL) - return -1; - if (*name != '\0') - return -1; - sp->typecnt = 2; /* standard time and DST */ - /* - ** Two transitions per year, from EPOCH_YEAR to 2037. - */ - sp->timecnt = 2 * (2037 - EPOCH_YEAR + 1); - if (sp->timecnt > TZ_MAX_TIMES) - return -1; - sp->ttis[0].tt_gmtoff = -dstoffset; - sp->ttis[0].tt_isdst = 1; - sp->ttis[0].tt_abbrind = stdlen + 1; - sp->ttis[1].tt_gmtoff = -stdoffset; - sp->ttis[1].tt_isdst = 0; - sp->ttis[1].tt_abbrind = 0; - atp = sp->ats; - typep = sp->types; - janfirst = 0; - for (year = EPOCH_YEAR; year <= 2037; ++year) { - starttime = transtime(janfirst, year, &start, - stdoffset); - endtime = transtime(janfirst, year, &end, - dstoffset); - if (starttime > endtime) { - *atp++ = endtime; - *typep++ = 1; /* DST ends */ - *atp++ = starttime; - *typep++ = 0; /* DST begins */ - } else { - *atp++ = starttime; - *typep++ = 0; /* DST begins */ - *atp++ = endtime; - *typep++ = 1; /* DST ends */ - } - janfirst += - year_lengths[isleap(year)] * SECSPERDAY; - } - } else { - int sawstd; - int sawdst; - long stdfix; - long dstfix; - long oldfix; - int isdst; - register int i; - - if (*name != '\0') - return -1; - if (load_result != 0) - return -1; - /* - ** Compute the difference between the real and - ** prototype standard and summer time offsets - ** from GMT, and put the real standard and summer - ** time offsets into the rules in place of the - ** prototype offsets. - */ - sawstd = FALSE; - sawdst = FALSE; - stdfix = 0; - dstfix = 0; - for (i = 0; i < sp->typecnt; ++i) { - if (sp->ttis[i].tt_isdst) { - oldfix = dstfix; - dstfix = - sp->ttis[i].tt_gmtoff + dstoffset; - if (sawdst && (oldfix != dstfix)) - return -1; - sp->ttis[i].tt_gmtoff = -dstoffset; - sp->ttis[i].tt_abbrind = stdlen + 1; - sawdst = TRUE; - } else { - oldfix = stdfix; - stdfix = - sp->ttis[i].tt_gmtoff + stdoffset; - if (sawstd && (oldfix != stdfix)) - return -1; - sp->ttis[i].tt_gmtoff = -stdoffset; - sp->ttis[i].tt_abbrind = 0; - sawstd = TRUE; - } - } - /* - ** Make sure we have both standard and summer time. - */ - if (!sawdst || !sawstd) - return -1; - /* - ** Now correct the transition times by shifting - ** them by the difference between the real and - ** prototype offsets. Note that this difference - ** can be different in standard and summer time; - ** the prototype probably has a 1-hour difference - ** between standard and summer time, but a different - ** difference can be specified in TZ. - */ - isdst = FALSE; /* we start in standard time */ - for (i = 0; i < sp->timecnt; ++i) { - register const struct ttinfo * ttisp; - - /* - ** If summer time is in effect, and the - ** transition time was not specified as - ** standard time, add the summer time - ** offset to the transition time; - ** otherwise, add the standard time offset - ** to the transition time. - */ - ttisp = &sp->ttis[sp->types[i]]; - sp->ats[i] += - (isdst && !ttisp->tt_ttisstd) ? - dstfix : stdfix; - isdst = ttisp->tt_isdst; - } - } - } else { - dstlen = 0; - sp->typecnt = 1; /* only standard time */ - sp->timecnt = 0; - sp->ttis[0].tt_gmtoff = -stdoffset; - sp->ttis[0].tt_isdst = 0; - sp->ttis[0].tt_abbrind = 0; - } - sp->charcnt = stdlen + 1; - if (dstlen != 0) - sp->charcnt += dstlen + 1; - if (sp->charcnt > sizeof sp->chars) - return -1; - cp = sp->chars; - (void) strncpy(cp, stdname, stdlen); - cp += stdlen; - *cp++ = '\0'; - if (dstlen != 0) { - (void) strncpy(cp, dstname, dstlen); - *(cp + dstlen) = '\0'; - } - return 0; -} - -static void -gmtload(sp) -struct state * const sp; -{ - if (tzload(GMT, sp) != 0) - (void) tzparse(GMT, sp, TRUE); -} - -void -tzset() -{ - register const char * name; - void tzsetwall(); - - name = getenv("TZ"); - if (name == NULL) { - tzsetwall(); - return; - } - lcl_is_set = TRUE; -#ifdef ALL_STATE - if (lclptr == NULL) { - lclptr = (struct state *) malloc(sizeof *lclptr); - if (lclptr == NULL) { - settzname(); /* all we can do */ - return; - } - } -#endif /* defined ALL_STATE */ - if (*name == '\0') { - /* - ** User wants it fast rather than right. - */ - lclptr->leapcnt = 0; /* so, we're off a little */ - lclptr->timecnt = 0; - lclptr->ttis[0].tt_gmtoff = 0; - lclptr->ttis[0].tt_abbrind = 0; - (void) strcpy(lclptr->chars, GMT); - } else if (tzload(name, lclptr) != 0) - if (name[0] == ':' || tzparse(name, lclptr, FALSE) != 0) - (void) gmtload(lclptr); - settzname(); -} - -void -tzsetwall() -{ - lcl_is_set = TRUE; -#ifdef ALL_STATE - if (lclptr == NULL) { - lclptr = (struct state *) malloc(sizeof *lclptr); - if (lclptr == NULL) { - settzname(); /* all we can do */ - return; - } - } -#endif /* defined ALL_STATE */ - if (tzload((char *) NULL, lclptr) != 0) - gmtload(lclptr); - settzname(); -} - -/* -** The easy way to behave "as if no library function calls" localtime -** is to not call it--so we drop its guts into "localsub", which can be -** freely called. (And no, the PANS doesn't require the above behavior-- -** but it *is* desirable.) -** -** The unused offset argument is for the benefit of mktime variants. -*/ - -/*ARGSUSED*/ -static void -localsub(timep, offset, tmp) -const time_t * const timep; -const long offset; -struct tm * const tmp; -{ - register struct state * sp; - register const struct ttinfo * ttisp; - register int i; - const time_t t = *timep; - - if (!lcl_is_set) - tzset(); - sp = lclptr; -#ifdef ALL_STATE - if (sp == NULL) { - gmtsub(timep, offset, tmp); - return; - } -#endif /* defined ALL_STATE */ - if (sp->timecnt == 0 || t < sp->ats[0]) { - i = 0; - while (sp->ttis[i].tt_isdst) - if (++i >= sp->typecnt) { - i = 0; - break; - } - } else { - for (i = 1; i < sp->timecnt; ++i) - if (t < sp->ats[i]) - break; - i = sp->types[i - 1]; - } - ttisp = &sp->ttis[i]; - /* - ** To get (wrong) behavior that's compatible with System V Release 2.0 - ** you'd replace the statement below with - ** t += ttisp->tt_gmtoff; - ** timesub(&t, 0L, sp, tmp); - */ - timesub(&t, ttisp->tt_gmtoff, sp, tmp); - tmp->tm_isdst = ttisp->tt_isdst; - tzname[tmp->tm_isdst] = (char *) &sp->chars[ttisp->tt_abbrind]; - tmp->tm_zone = &sp->chars[ttisp->tt_abbrind]; -} - -struct tm * -localtime(timep) -const time_t * const timep; -{ - static struct tm tm; - - localsub(timep, 0L, &tm); - return &tm; -} - -/* -** gmtsub is to gmtime as localsub is to localtime. -*/ - -static void -gmtsub(timep, offset, tmp) -const time_t * const timep; -const long offset; -struct tm * const tmp; -{ - if (!gmt_is_set) { - gmt_is_set = TRUE; -#ifdef ALL_STATE - gmtptr = (struct state *) malloc(sizeof *gmtptr); - if (gmtptr != NULL) -#endif /* defined ALL_STATE */ - gmtload(gmtptr); - } - timesub(timep, offset, gmtptr, tmp); - /* - ** Could get fancy here and deliver something such as - ** "GMT+xxxx" or "GMT-xxxx" if offset is non-zero, - ** but this is no time for a treasure hunt. - */ - if (offset != 0) - tmp->tm_zone = WILDABBR; - else { -#ifdef ALL_STATE - if (gmtptr == NULL) - tmp->TM_ZONE = GMT; - else tmp->TM_ZONE = gmtptr->chars; -#endif /* defined ALL_STATE */ -#ifndef ALL_STATE - tmp->tm_zone = gmtptr->chars; -#endif /* State Farm */ - } -} - -struct tm * -gmtime(timep) -const time_t * const timep; -{ - static struct tm tm; - - gmtsub(timep, 0L, &tm); - return &tm; -} - -static void -timesub(timep, offset, sp, tmp) -const time_t * const timep; -const long offset; -register const struct state * const sp; -register struct tm * const tmp; -{ - register const struct lsinfo * lp; - register long days; - register long rem; - register int y; - register int yleap; - register const int * ip; - register long corr; - register int hit; - register int i; - - corr = 0; - hit = FALSE; -#ifdef ALL_STATE - i = (sp == NULL) ? 0 : sp->leapcnt; -#endif /* defined ALL_STATE */ -#ifndef ALL_STATE - i = sp->leapcnt; -#endif /* State Farm */ - while (--i >= 0) { - lp = &sp->lsis[i]; - if (*timep >= lp->ls_trans) { - if (*timep == lp->ls_trans) - hit = ((i == 0 && lp->ls_corr > 0) || - lp->ls_corr > sp->lsis[i - 1].ls_corr); - corr = lp->ls_corr; - break; - } - } - days = *timep / SECSPERDAY; - rem = *timep % SECSPERDAY; -#ifdef mc68k - if (*timep == 0x80000000) { - /* - ** A 3B1 muffs the division on the most negative number. - */ - days = -24855; - rem = -11648; - } -#endif /* mc68k */ - rem += (offset - corr); - while (rem < 0) { - rem += SECSPERDAY; - --days; - } - while (rem >= SECSPERDAY) { - rem -= SECSPERDAY; - ++days; - } - tmp->tm_hour = (int) (rem / SECSPERHOUR); - rem = rem % SECSPERHOUR; - tmp->tm_min = (int) (rem / SECSPERMIN); - tmp->tm_sec = (int) (rem % SECSPERMIN); - if (hit) - /* - ** A positive leap second requires a special - ** representation. This uses "... ??:59:60". - */ - ++(tmp->tm_sec); - tmp->tm_wday = (int) ((EPOCH_WDAY + days) % DAYSPERWEEK); - if (tmp->tm_wday < 0) - tmp->tm_wday += DAYSPERWEEK; - y = EPOCH_YEAR; - if (days >= 0) - for ( ; ; ) { - yleap = isleap(y); - if (days < (long) year_lengths[yleap]) - break; - ++y; - days = days - (long) year_lengths[yleap]; - } - else do { - --y; - yleap = isleap(y); - days = days + (long) year_lengths[yleap]; - } while (days < 0); - tmp->tm_year = y - TM_YEAR_BASE; - tmp->tm_yday = (int) days; - ip = mon_lengths[yleap]; - for (tmp->tm_mon = 0; days >= (long) ip[tmp->tm_mon]; ++(tmp->tm_mon)) - days = days - (long) ip[tmp->tm_mon]; - tmp->tm_mday = (int) (days + 1); - tmp->tm_isdst = 0; - tmp->tm_gmtoff = offset; -} - -/* -** A la X3J11 -*/ - -char * -asctime(timeptr) -register const struct tm * timeptr; -{ - static const char wday_name[DAYSPERWEEK][3] = { - "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" - }; - static const char mon_name[MONSPERYEAR][3] = { - "Jan", "Feb", "Mar", "Apr", "May", "Jun", - "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" - }; - static char result[26]; - - (void) sprintf(result, "%.3s %.3s%3d %02.2d:%02.2d:%02.2d %d\n", - wday_name[timeptr->tm_wday], - mon_name[timeptr->tm_mon], - timeptr->tm_mday, timeptr->tm_hour, - timeptr->tm_min, timeptr->tm_sec, - TM_YEAR_BASE + timeptr->tm_year); - return result; -} - -char * -ctime(timep) -const time_t * const timep; -{ - return asctime(localtime(timep)); -} - -/* -** Adapted from code provided by Robert Elz, who writes: -** The "best" way to do mktime I think is based on an idea of Bob -** Kridle's (so its said...) from a long time ago. (mtxinu!kridle now). -** It does a binary search of the time_t space. Since time_t's are -** just 32 bits, its a max of 32 iterations (even at 64 bits it -** would still be very reasonable). -*/ - -#ifndef WRONG -#define WRONG (-1) -#endif /* !defined WRONG */ - -static void -normalize(tensptr, unitsptr, base) -int * const tensptr; -int * const unitsptr; -const int base; -{ - if (*unitsptr >= base) { - *tensptr += *unitsptr / base; - *unitsptr %= base; - } else if (*unitsptr < 0) { - *tensptr -= 1 + (-(*unitsptr + 1)) / base; - *unitsptr = base - 1 - (-(*unitsptr + 1)) % base; - } -} - -static int -tmcomp(atmp, btmp) -register const struct tm * const atmp; -register const struct tm * const btmp; -{ - register int result; - - if ((result = (atmp->tm_year - btmp->tm_year)) == 0 && - (result = (atmp->tm_mon - btmp->tm_mon)) == 0 && - (result = (atmp->tm_mday - btmp->tm_mday)) == 0 && - (result = (atmp->tm_hour - btmp->tm_hour)) == 0 && - (result = (atmp->tm_min - btmp->tm_min)) == 0) - result = atmp->tm_sec - btmp->tm_sec; - return result; -} - -static time_t -time2(tmp, funcp, offset, okayp) -struct tm * const tmp; -void (* const funcp)(); -const long offset; -int * const okayp; -{ - register const struct state * sp; - register int dir; - register int bits; - register int i, j ; - register int saved_seconds; - time_t newt; - time_t t; - struct tm yourtm, mytm; - - *okayp = FALSE; - yourtm = *tmp; - if (yourtm.tm_sec >= SECSPERMIN + 2 || yourtm.tm_sec < 0) - normalize(&yourtm.tm_min, &yourtm.tm_sec, SECSPERMIN); - normalize(&yourtm.tm_hour, &yourtm.tm_min, MINSPERHOUR); - normalize(&yourtm.tm_mday, &yourtm.tm_hour, HOURSPERDAY); - normalize(&yourtm.tm_year, &yourtm.tm_mon, MONSPERYEAR); - while (yourtm.tm_mday <= 0) { - --yourtm.tm_year; - yourtm.tm_mday += - year_lengths[isleap(yourtm.tm_year + TM_YEAR_BASE)]; - } - while (yourtm.tm_mday > DAYSPERLYEAR) { - yourtm.tm_mday -= - year_lengths[isleap(yourtm.tm_year + TM_YEAR_BASE)]; - ++yourtm.tm_year; - } - for ( ; ; ) { - i = mon_lengths[isleap(yourtm.tm_year + - TM_YEAR_BASE)][yourtm.tm_mon]; - if (yourtm.tm_mday <= i) - break; - yourtm.tm_mday -= i; - if (++yourtm.tm_mon >= MONSPERYEAR) { - yourtm.tm_mon = 0; - ++yourtm.tm_year; - } - } - saved_seconds = yourtm.tm_sec; - yourtm.tm_sec = 0; - /* - ** Calculate the number of magnitude bits in a time_t - ** (this works regardless of whether time_t is - ** signed or unsigned, though lint complains if unsigned). - */ - for (bits = 0, t = 1; t > 0; ++bits, t <<= 1) - ; - /* - ** If time_t is signed, then 0 is the median value, - ** if time_t is unsigned, then 1 << bits is median. - */ - t = (t < 0) ? 0 : ((time_t) 1 << bits); - for ( ; ; ) { - (*funcp)(&t, offset, &mytm); - dir = tmcomp(&mytm, &yourtm); - if (dir != 0) { - if (bits-- < 0) - return WRONG; - if (bits < 0) - --t; - else if (dir > 0) - t -= (time_t) 1 << bits; - else t += (time_t) 1 << bits; - continue; - } - if (yourtm.tm_isdst < 0 || mytm.tm_isdst == yourtm.tm_isdst) - break; - /* - ** Right time, wrong type. - ** Hunt for right time, right type. - ** It's okay to guess wrong since the guess - ** gets checked. - */ - sp = (const struct state *) - ((funcp == localsub) ? lclptr : gmtptr); -#ifdef ALL_STATE - if (sp == NULL) - return WRONG; -#endif /* defined ALL_STATE */ - for (i = 0; i < sp->typecnt; ++i) { - if (sp->ttis[i].tt_isdst != yourtm.tm_isdst) - continue; - for (j = 0; j < sp->typecnt; ++j) { - if (sp->ttis[j].tt_isdst == yourtm.tm_isdst) - continue; - newt = t + sp->ttis[j].tt_gmtoff - - sp->ttis[i].tt_gmtoff; - (*funcp)(&newt, offset, &mytm); - if (tmcomp(&mytm, &yourtm) != 0) - continue; - if (mytm.tm_isdst != yourtm.tm_isdst) - continue; - /* - ** We have a match. - */ - t = newt; - goto label; - } - } - return WRONG; - } -label: - t += saved_seconds; - (*funcp)(&t, offset, tmp); - *okayp = TRUE; - return t; -} - -static time_t -time1(tmp, funcp, offset) -struct tm * const tmp; -void (* const funcp)(); -const long offset; -{ - register time_t t; - register const struct state * sp; - register int samei, otheri; - int okay; - - if (tmp->tm_isdst > 1) - tmp->tm_isdst = 1; - t = time2(tmp, funcp, offset, &okay); - if (okay || tmp->tm_isdst < 0) - return t; - /* - ** We're supposed to assume that somebody took a time of one type - ** and did some math on it that yielded a "struct tm" that's bad. - ** We try to divine the type they started from and adjust to the - ** type they need. - */ - sp = (const struct state *) ((funcp == localsub) ? lclptr : gmtptr); -#ifdef ALL_STATE - if (sp == NULL) - return WRONG; -#endif /* defined ALL_STATE */ - for (samei = 0; samei < sp->typecnt; ++samei) { - if (sp->ttis[samei].tt_isdst != tmp->tm_isdst) - continue; - for (otheri = 0; otheri < sp->typecnt; ++otheri) { - if (sp->ttis[otheri].tt_isdst == tmp->tm_isdst) - continue; - tmp->tm_sec += sp->ttis[otheri].tt_gmtoff - - sp->ttis[samei].tt_gmtoff; - tmp->tm_isdst = !tmp->tm_isdst; - t = time2(tmp, funcp, offset, &okay); - if (okay) - return t; - tmp->tm_sec -= sp->ttis[otheri].tt_gmtoff - - sp->ttis[samei].tt_gmtoff; - tmp->tm_isdst = !tmp->tm_isdst; - } - } - return WRONG; -} - -time_t -mktime(tmp) -struct tm * const tmp; -{ - return time1(tmp, localsub, 0L); -} diff --git a/gen.subproj/daemon.c b/gen.subproj/daemon.c deleted file mode 100644 index 7c638ce..0000000 --- a/gen.subproj/daemon.c +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 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 -#include -#include - -int -daemon(nochdir, noclose) - int nochdir, noclose; -{ - int fd; - - switch (fork()) { - case -1: - return (-1); - case 0: - break; - default: - _exit(0); - } - - if (setsid() == -1) - return (-1); - - if (!nochdir) - (void)chdir("/"); - - if (!noclose && (fd = open(_PATH_DEVNULL, O_RDWR, 0)) != -1) { - (void)dup2(fd, STDIN_FILENO); - (void)dup2(fd, STDOUT_FILENO); - (void)dup2(fd, STDERR_FILENO); - if (fd > 2) - (void)close (fd); - } - return (0); -} diff --git a/gen.subproj/devname.c b/gen.subproj/devname.c deleted file mode 100644 index 3a03f5a..0000000 --- a/gen.subproj/devname.c +++ /dev/null @@ -1,130 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1989, 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 -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -static char buf[sizeof(_PATH_DEV) + MAXNAMLEN] = _PATH_DEV; -static char *olddevname __P((dev_t, mode_t)); - -char * -devname(dev, type) - dev_t dev; - mode_t type; -{ - struct { - mode_t type; - dev_t dev; - } bkey; - static DB *db; - static int failure; - DBT data, key; - - if (!db && !failure && - !(db = dbopen(_PATH_DEVDB, O_RDONLY, 0, DB_HASH, NULL))) { - failure = 1; - } - if (failure) - return (olddevname(dev, type)); - - /* - * Keys are a mode_t followed by a dev_t. The former is the type of - * the file (mode & S_IFMT), the latter is the st_rdev field. Be - * sure to clear any padding that may be found in bkey. - */ - memset(&bkey, 0, sizeof(bkey)); - bkey.dev = dev; - bkey.type = type; - key.data = &bkey; - key.size = sizeof(bkey); - return ((db->get)(db, &key, &data, 0) ? NULL : (char *)data.data); -} - -static char * -olddevname(dev, type) - dev_t dev; - mode_t type; -{ - register DIR *dp; - register struct dirent *dirp; - struct stat sb; - - if ((dp = opendir(_PATH_DEV)) == NULL) - return (NULL); - - while ( (dirp = readdir(dp)) ) { - bcopy(dirp->d_name, buf + sizeof(_PATH_DEV) - 1, - dirp->d_namlen + 1); - if (stat(buf, &sb)) - continue; - if (dev != sb.st_rdev) - continue; - if (type != (sb.st_mode & S_IFMT)) - continue; - (void)closedir(dp); - return (buf + sizeof(_PATH_DEV) - 1); - } - (void)closedir(dp); - return (NULL); -} diff --git a/gen.subproj/difftime.c b/gen.subproj/difftime.c deleted file mode 100644 index 015b223..0000000 --- a/gen.subproj/difftime.c +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1989, 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 - -double -difftime(time1, time0) - time_t time1, time0; -{ - return(time1 - time0); -} diff --git a/gen.subproj/disklabel.c b/gen.subproj/disklabel.c deleted file mode 100644 index e828970..0000000 --- a/gen.subproj/disklabel.c +++ /dev/null @@ -1,204 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1983, 1987, 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 -#include -#define DKTYPENAMES -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -static int error __P((int)); -static int gettype __P((char *, char **)); - -struct disklabel * -getdiskbyname(name) - const char *name; -{ - static struct disklabel disk; - register struct disklabel *dp = &disk; - register struct partition *pp; - char *buf; - char *db_array[2] = { _PATH_DISKTAB, 0 }; - char *cp, *cq; /* can't be register */ - char p, max, psize[3], pbsize[3], - pfsize[3], poffset[3], ptype[3]; - u_int32_t *dx; - - if (cgetent(&buf, db_array, (char *) name) < 0) - return NULL; - - bzero((char *)&disk, sizeof(disk)); - /* - * typename - */ - cq = dp->d_typename; - cp = buf; - while (cq < dp->d_typename + sizeof(dp->d_typename) - 1 && - (*cq = *cp) && *cq != '|' && *cq != ':') - cq++, cp++; - *cq = '\0'; - /* - * boot name (optional) xxboot, bootxx - */ - cgetstr(buf, "b0", &dp->d_boot0); - cgetstr(buf, "b1", &dp->d_boot1); - - if (cgetstr(buf, "ty", &cq) > 0 && strcmp(cq, "removable") == 0) - dp->d_flags |= D_REMOVABLE; - else if (cq && strcmp(cq, "simulated") == 0) - dp->d_flags |= D_RAMDISK; - if (cgetcap(buf, "sf", ':') != NULL) - dp->d_flags |= D_BADSECT; - -#define getnumdflt(field, dname, dflt) \ - { long f; (field) = (cgetnum(buf, dname, &f) == -1) ? (dflt) : f; } - - getnumdflt(dp->d_secsize, "se", DEV_BSIZE); - cgetnum(buf, "nt",(long *) &dp->d_ntracks); - cgetnum(buf, "ns",(long *) &dp->d_nsectors); - cgetnum(buf, "nc",(long *) &dp->d_ncylinders); - - if (cgetstr(buf, "dt", &cq) > 0) - dp->d_type = gettype(cq, dktypenames); - else - getnumdflt(dp->d_type, "dt", 0); - getnumdflt(dp->d_secpercyl, "sc", dp->d_nsectors * dp->d_ntracks); - getnumdflt(dp->d_secperunit, "su", dp->d_secpercyl * dp->d_ncylinders); - getnumdflt(dp->d_rpm, "rm", 3600); - getnumdflt(dp->d_interleave, "il", 1); - getnumdflt(dp->d_trackskew, "sk", 0); - getnumdflt(dp->d_cylskew, "cs", 0); - getnumdflt(dp->d_headswitch, "hs", 0); - getnumdflt(dp->d_trkseek, "ts", 0); - getnumdflt(dp->d_bbsize, "bs", BBSIZE); - getnumdflt(dp->d_sbsize, "sb", SBSIZE); - strcpy(psize, "px"); - strcpy(pbsize, "bx"); - strcpy(pfsize, "fx"); - strcpy(poffset, "ox"); - strcpy(ptype, "tx"); - max = 'a' - 1; - pp = &dp->d_partitions[0]; - for (p = 'a'; p < 'a' + MAXPARTITIONS; p++, pp++) { - psize[1] = pbsize[1] = pfsize[1] = poffset[1] = ptype[1] = p; - if (cgetnum(buf, psize,(long *) &pp->p_size) == -1) - pp->p_size = 0; - else { - cgetnum(buf, poffset, (long *) &pp->p_offset); - getnumdflt(pp->p_fsize, pfsize, 0); - if (pp->p_fsize) { - long bsize; - - if (cgetnum(buf, pbsize, &bsize) == 0) - pp->p_frag = bsize / pp->p_fsize; - else - pp->p_frag = 8; - } - getnumdflt(pp->p_fstype, ptype, 0); - if (pp->p_fstype == 0 && cgetstr(buf, ptype, &cq) > 0) - pp->p_fstype = gettype(cq, fstypenames); - max = p; - } - } - dp->d_npartitions = max + 1 - 'a'; - (void)strcpy(psize, "dx"); - dx = dp->d_drivedata; - for (p = '0'; p < '0' + NDDATA; p++, dx++) { - psize[1] = p; - getnumdflt(*dx, psize, 0); - } - dp->d_magic = DISKMAGIC; - dp->d_magic2 = DISKMAGIC; - free(buf); - return (dp); -} - -static int -gettype(t, names) - char *t; - char **names; -{ - register char **nm; - - for (nm = names; *nm; nm++) - if (strcasecmp(t, *nm) == 0) - return (nm - names); - if (isdigit(*t)) - return (atoi(t)); - return (0); -} - -static int -error(err) - int err; -{ - char *p; - - (void)write(STDERR_FILENO, "disktab: ", 9); - (void)write(STDERR_FILENO, _PATH_DISKTAB, sizeof(_PATH_DISKTAB) - 1); - (void)write(STDERR_FILENO, ": ", 2); - p = strerror(err); - (void)write(STDERR_FILENO, p, strlen(p)); - (void)write(STDERR_FILENO, "\n", 1); -} diff --git a/gen.subproj/err.c b/gen.subproj/err.c deleted file mode 100644 index a355d99..0000000 --- a/gen.subproj/err.c +++ /dev/null @@ -1,206 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * 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 -#include -#include -#include -#include - -#include - -#ifdef __STDC__ -#include -#else -#include -#endif - -__dead void -#ifdef __STDC__ -err(int eval, const char *fmt, ...) -#else -err(eval, fmt, va_alist) - int eval; - const char *fmt; - va_dcl -#endif -{ - va_list ap; -#if __STDC__ - va_start(ap, fmt); -#else - va_start(ap); -#endif - verr(eval, fmt, ap); - va_end(ap); -} - -__dead void -verr(eval, fmt, ap) - int eval; - const char *fmt; - va_list ap; -{ - char* __progname = *(*_NSGetArgv()); - int sverrno; - - sverrno = errno; - (void)fprintf(stderr, "%s: ", __progname); - if (fmt != NULL) { - (void)vfprintf(stderr, fmt, ap); - (void)fprintf(stderr, ": "); - } - (void)fprintf(stderr, "%s\n", strerror(sverrno)); - exit(eval); -} - -__dead void -#if __STDC__ -errx(int eval, const char *fmt, ...) -#else -errx(eval, fmt, va_alist) - int eval; - const char *fmt; - va_dcl -#endif -{ - va_list ap; -#if __STDC__ - va_start(ap, fmt); -#else - va_start(ap); -#endif - verrx(eval, fmt, ap); - va_end(ap); -} - -__dead void -verrx(eval, fmt, ap) - int eval; - const char *fmt; - va_list ap; -{ - char* __progname = *(*_NSGetArgv()); - (void)fprintf(stderr, "%s: ", __progname); - if (fmt != NULL) - (void)vfprintf(stderr, fmt, ap); - (void)fprintf(stderr, "\n"); - exit(eval); -} - -void -#if __STDC__ -warn(const char *fmt, ...) -#else -warn(fmt, va_alist) - const char *fmt; - va_dcl -#endif -{ - va_list ap; -#if __STDC__ - va_start(ap, fmt); -#else - va_start(ap); -#endif - vwarn(fmt, ap); - va_end(ap); -} - -void -vwarn(fmt, ap) - const char *fmt; - va_list ap; -{ - int sverrno = errno; - char* __progname = *(*_NSGetArgv()); - (void)fprintf(stderr, "%s: ", __progname); - if (fmt != NULL) { - (void)vfprintf(stderr, fmt, ap); - (void)fprintf(stderr, ": "); - } - (void)fprintf(stderr, "%s\n", strerror(sverrno)); -} - -void -#ifdef __STDC__ -warnx(const char *fmt, ...) -#else -warnx(fmt, va_alist) - const char *fmt; - va_dcl -#endif -{ - va_list ap; -#ifdef __STDC__ - va_start(ap, fmt); -#else - va_start(ap); -#endif - vwarnx(fmt, ap); - va_end(ap); -} - -void -vwarnx(fmt, ap) - const char *fmt; - va_list ap; -{ - char* __progname = *(*_NSGetArgv()); - (void)fprintf(stderr, "%s: ", __progname); - if (fmt != NULL) - (void)vfprintf(stderr, fmt, ap); - (void)fprintf(stderr, "\n"); -} diff --git a/gen.subproj/errlst.c b/gen.subproj/errlst.c deleted file mode 100644 index 1a022c9..0000000 --- a/gen.subproj/errlst.c +++ /dev/null @@ -1,173 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1982, 1985, 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 - -const char *const sys_errlist[] = { - "Undefined error: 0", /* 0 - ENOERROR */ - "Operation not permitted", /* 1 - EPERM */ - "No such file or directory", /* 2 - ENOENT */ - "No such process", /* 3 - ESRCH */ - "Interrupted system call", /* 4 - EINTR */ - "Input/output error", /* 5 - EIO */ - "Device not configured", /* 6 - ENXIO */ - "Argument list too long", /* 7 - E2BIG */ - "Exec format error", /* 8 - ENOEXEC */ - "Bad file descriptor", /* 9 - EBADF */ - "No child processes", /* 10 - ECHILD */ - "Resource deadlock avoided", /* 11 - EDEADLK */ - "Cannot allocate memory", /* 12 - ENOMEM */ - "Permission denied", /* 13 - EACCES */ - "Bad address", /* 14 - EFAULT */ - "Block device required", /* 15 - ENOTBLK */ - "Device busy", /* 16 - EBUSY */ - "File exists", /* 17 - EEXIST */ - "Cross-device link", /* 18 - EXDEV */ - "Operation not supported by device", /* 19 - ENODEV */ - "Not a directory", /* 20 - ENOTDIR */ - "Is a directory", /* 21 - EISDIR */ - "Invalid argument", /* 22 - EINVAL */ - "Too many open files in system", /* 23 - ENFILE */ - "Too many open files", /* 24 - EMFILE */ - "Inappropriate ioctl for device", /* 25 - ENOTTY */ - "Text file busy", /* 26 - ETXTBSY */ - "File too large", /* 27 - EFBIG */ - "No space left on device", /* 28 - ENOSPC */ - "Illegal seek", /* 29 - ESPIPE */ - "Read-only file system", /* 30 - EROFS */ - "Too many links", /* 31 - EMLINK */ - "Broken pipe", /* 32 - EPIPE */ - -/* math software */ - "Numerical argument out of domain", /* 33 - EDOM */ - "Result too large", /* 34 - ERANGE */ - -/* non-blocking and interrupt i/o */ - "Resource temporarily unavailable", /* 35 - EAGAIN */ - /* 35 - EWOULDBLOCK */ - "Operation now in progress", /* 36 - EINPROGRESS */ - "Operation already in progress", /* 37 - EALREADY */ - -/* ipc/network software -- argument errors */ - "Socket operation on non-socket", /* 38 - ENOTSOCK */ - "Destination address required", /* 39 - EDESTADDRREQ */ - "Message too long", /* 40 - EMSGSIZE */ - "Protocol wrong type for socket", /* 41 - EPROTOTYPE */ - "Protocol not available", /* 42 - ENOPROTOOPT */ - "Protocol not supported", /* 43 - EPROTONOSUPPORT */ - "Socket type not supported", /* 44 - ESOCKTNOSUPPORT */ - "Operation not supported", /* 45 - EOPNOTSUPP */ - "Protocol family not supported", /* 46 - EPFNOSUPPORT */ - /* 47 - EAFNOSUPPORT */ - "Address family not supported by protocol family", - "Address already in use", /* 48 - EADDRINUSE */ - "Can't assign requested address", /* 49 - EADDRNOTAVAIL */ - -/* ipc/network software -- operational errors */ - "Network is down", /* 50 - ENETDOWN */ - "Network is unreachable", /* 51 - ENETUNREACH */ - "Network dropped connection on reset", /* 52 - ENETRESET */ - "Software caused connection abort", /* 53 - ECONNABORTED */ - "Connection reset by peer", /* 54 - ECONNRESET */ - "No buffer space available", /* 55 - ENOBUFS */ - "Socket is already connected", /* 56 - EISCONN */ - "Socket is not connected", /* 57 - ENOTCONN */ - "Can't send after socket shutdown", /* 58 - ESHUTDOWN */ - "Too many references: can't splice", /* 59 - ETOOMANYREFS */ - "Operation timed out", /* 60 - ETIMEDOUT */ - "Connection refused", /* 61 - ECONNREFUSED */ - - "Too many levels of symbolic links", /* 62 - ELOOP */ - "File name too long", /* 63 - ENAMETOOLONG */ - -/* should be rearranged */ - "Host is down", /* 64 - EHOSTDOWN */ - "No route to host", /* 65 - EHOSTUNREACH */ - "Directory not empty", /* 66 - ENOTEMPTY */ - -/* quotas & mush */ - "Too many processes", /* 67 - EPROCLIM */ - "Too many users", /* 68 - EUSERS */ - "Disc quota exceeded", /* 69 - EDQUOT */ - -/* Network File System */ - "Stale NFS file handle", /* 70 - ESTALE */ - "Too many levels of remote in path", /* 71 - EREMOTE */ - "RPC struct is bad", /* 72 - EBADRPC */ - "RPC version wrong", /* 73 - ERPCMISMATCH */ - "RPC prog. not avail", /* 74 - EPROGUNAVAIL */ - "Program version wrong", /* 75 - EPROGMISMATCH */ - "Bad procedure for program", /* 76 - EPROCUNAVAIL */ - - "No locks available", /* 77 - ENOLCK */ - "Function not implemented", /* 78 - ENOSYS */ - "Inappropriate file type or format", /* 79 - EFTYPE */ - "Authentication error", /* 80 - EAUTH */ - "Need authenticator", /* 81 - ENEEDAUTH */ - - "Device power is off", /* 82 - EPWROFF */ - "Device error", /* 83 - EDEVERR */ - "Value too large to be stored in data type", /* 84 - EOVERFLOW */ - -/* program loading errors */ - "Bad executable (or shared library)", /* 85 - EBADEXEC */ - "Bad CPU type in executable", /* 86 - EBADARCH */ - "Shared library version mismatch", /* 87 - ESHLIBVERS */ - "Malformed Mach-o file" /* 88 - EBADMACHO */ -}; - -int errno; - -const int sys_nerr = sizeof(sys_errlist) / sizeof(sys_errlist[0]); diff --git a/gen.subproj/exec.c b/gen.subproj/exec.c deleted file mode 100644 index 1f6e2d7..0000000 --- a/gen.subproj/exec.c +++ /dev/null @@ -1,323 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * 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. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#ifdef __STDC__ -#include -#else -#include -#endif - -#if defined(__APPLE__) -#include -#define environ (*_NSGetEnviron()) -#else -extern char **environ; -#endif - -int -#ifdef __STDC__ -execl(const char *name, const char *arg, ...) -#else -execl(name, arg, va_alist) - const char *name; - const char *arg; - va_dcl -#endif -{ - va_list ap; - char **argv; - int n; - -#ifdef __STDC__ - va_start(ap, arg); -#else - va_start(ap); -#endif - n = 1; - while (va_arg(ap, char *) != NULL) - n++; - va_end(ap); - argv = alloca((n + 1) * sizeof(*argv)); - if (argv == NULL) { - errno = ENOMEM; - return (-1); - } -#ifdef __STDC__ - va_start(ap, arg); -#else - va_start(ap); -#endif - n = 1; - argv[0] = (char *)arg; - while ((argv[n] = va_arg(ap, char *)) != NULL) - n++; - va_end(ap); - return (execve(name, argv, environ)); -} - -int -#ifdef __STDC__ -execle(const char *name, const char *arg, ...) -#else -execle(name, arg, va_alist) - const char *name; - const char *arg; - va_dcl -#endif -{ - va_list ap; - char **argv, **envp; - int n; - -#ifdef __STDC__ - va_start(ap, arg); -#else - va_start(ap); -#endif - n = 1; - while (va_arg(ap, char *) != NULL) - n++; - va_end(ap); - argv = alloca((n + 1) * sizeof(*argv)); - if (argv == NULL) { - errno = ENOMEM; - return (-1); - } -#ifdef __STDC__ - va_start(ap, arg); -#else - va_start(ap); -#endif - n = 1; - argv[0] = (char *)arg; - while ((argv[n] = va_arg(ap, char *)) != NULL) - n++; - envp = va_arg(ap, char **); - va_end(ap); - return (execve(name, argv, envp)); -} - -int -#ifdef __STDC__ -execlp(const char *name, const char *arg, ...) -#else -execlp(name, arg, va_alist) - const char *name; - const char *arg; - va_dcl -#endif -{ - va_list ap; - char **argv; - int n; - -#ifdef __STDC__ - va_start(ap, arg); -#else - va_start(ap); -#endif - n = 1; - while (va_arg(ap, char *) != NULL) - n++; - va_end(ap); - argv = alloca((n + 1) * sizeof(*argv)); - if (argv == NULL) { - errno = ENOMEM; - return (-1); - } -#ifdef __STDC__ - va_start(ap, arg); -#else - va_start(ap); -#endif - n = 1; - argv[0] = (char *)arg; - while ((argv[n] = va_arg(ap, char *)) != NULL) - n++; - va_end(ap); - return (execvp(name, argv)); -} - -int -execv(name, argv) - const char *name; - char * const *argv; -{ - (void)execve(name, argv, environ); - return (-1); -} - -int -execvp(name, argv) - const char *name; - char * const *argv; -{ - char **memp; - register int cnt, lp, ln; - register char *p; - int eacces = 0, etxtbsy = 0; - char *bp, *cur, *path, buf[MAXPATHLEN]; - - /* - * Do not allow null name - */ - if (name == NULL || *name == '\0') { - errno = ENOENT; - return (-1); - } - - /* If it's an absolute or relative path name, it's easy. */ - if (strchr(name, '/')) { - bp = (char *)name; - cur = path = NULL; - goto retry; - } - bp = buf; - - /* 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, ":"))) { - /* - * It's a SHELL path -- double, leading and trailing colons - * mean the current directory. - */ - if (!*p) { - p = "."; - lp = 1; - } else - lp = strlen(p); - ln = strlen(name); - - /* - * If the path is too long complain. This is a possible - * security issue; given a way to make the path too long - * the user may execute the wrong program. - */ - if (lp + ln + 2 > sizeof(buf)) { - struct iovec iov[3]; - - iov[0].iov_base = "execvp: "; - iov[0].iov_len = 8; - iov[1].iov_base = p; - iov[1].iov_len = lp; - iov[2].iov_base = ": path too long\n"; - iov[2].iov_len = 16; - (void)writev(STDERR_FILENO, iov, 3); - continue; - } - bcopy(p, buf, lp); - buf[lp] = '/'; - bcopy(name, buf + lp + 1, ln); - buf[lp + ln + 1] = '\0'; - -retry: (void)execve(bp, argv, environ); - switch(errno) { - case E2BIG: - goto done; - case ELOOP: - case ENAMETOOLONG: - case ENOENT: - break; - case ENOEXEC: - for (cnt = 0; argv[cnt]; ++cnt) - ; - memp = alloca((cnt + 2) * sizeof(char *)); - if (memp == NULL) - goto done; - memp[0] = "sh"; - memp[1] = bp; - bcopy(argv + 1, memp + 2, cnt * sizeof(char *)); - (void)execve(_PATH_BSHELL, memp, environ); - goto done; - case ENOMEM: - goto done; - case ENOTDIR: - break; - case ETXTBSY: - /* - * We used to retry here, but sh(1) doesn't. - */ - goto done; - case EACCES: - eacces = 1; - break; - default: - goto done; - } - } - if (eacces) - errno = EACCES; - else if (!errno) - errno = ENOENT; -done: - return (-1); -} diff --git a/gen.subproj/fnmatch.c b/gen.subproj/fnmatch.c deleted file mode 100644 index 93bb361..0000000 --- a/gen.subproj/fnmatch.c +++ /dev/null @@ -1,189 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1989, 1993, 1994 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Guido van Rossum. - * - * 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. - */ - - -/* - * Function fnmatch() as specified in POSIX 1003.2-1992, section B.6. - * Compares a filename or pathname to a pattern. - */ - -#include -#include - -#define EOS '\0' - -static const char *rangematch __P((const char *, int, int)); - -int -fnmatch(pattern, string, flags) - const char *pattern, *string; - int flags; -{ - const char *stringstart; - char c, test; - - for (stringstart = string;;) - switch (c = *pattern++) { - case EOS: - return (*string == EOS ? 0 : FNM_NOMATCH); - case '?': - if (*string == EOS) - return (FNM_NOMATCH); - if (*string == '/' && (flags & FNM_PATHNAME)) - return (FNM_NOMATCH); - if (*string == '.' && (flags & FNM_PERIOD) && - (string == stringstart || - ((flags & FNM_PATHNAME) && *(string - 1) == '/'))) - return (FNM_NOMATCH); - ++string; - break; - case '*': - c = *pattern; - /* Collapse multiple stars. */ - while (c == '*') - c = *++pattern; - - if (*string == '.' && (flags & FNM_PERIOD) && - (string == stringstart || - ((flags & FNM_PATHNAME) && *(string - 1) == '/'))) - return (FNM_NOMATCH); - - /* Optimize for pattern with * at end or before /. */ - if (c == EOS) - if (flags & FNM_PATHNAME) - return (strchr(string, '/') == NULL ? - 0 : FNM_NOMATCH); - else - return (0); - else if (c == '/' && flags & FNM_PATHNAME) { - if ((string = strchr(string, '/')) == NULL) - return (FNM_NOMATCH); - break; - } - - /* General case, use recursion. */ - while ((test = *string) != EOS) { - if (!fnmatch(pattern, string, flags & ~FNM_PERIOD)) - return (0); - if (test == '/' && flags & FNM_PATHNAME) - break; - ++string; - } - return (FNM_NOMATCH); - case '[': - if (*string == EOS) - return (FNM_NOMATCH); - if (*string == '/' && flags & FNM_PATHNAME) - return (FNM_NOMATCH); - if ((pattern = - rangematch(pattern, *string, flags)) == NULL) - return (FNM_NOMATCH); - ++string; - break; - case '\\': - if (!(flags & FNM_NOESCAPE)) { - if ((c = *pattern++) == EOS) { - c = '\\'; - --pattern; - } - } - /* FALLTHROUGH */ - default: - if (c != *string++) - return (FNM_NOMATCH); - break; - } - /* NOTREACHED */ -} - -static const char * -rangematch(pattern, test, flags) - const char *pattern; - int test, flags; -{ - int negate, ok; - char c, c2; - - /* - * A bracket expression starting with an unquoted circumflex - * character produces unspecified results (IEEE 1003.2-1992, - * 3.13.2). This implementation treats it like '!', for - * consistency with the regular expression syntax. - * J.T. Conklin (conklin@ngai.kaleida.com) - */ - if (negate = (*pattern == '!' || *pattern == '^')) - ++pattern; - - for (ok = 0; (c = *pattern++) != ']';) { - if (c == '\\' && !(flags & FNM_NOESCAPE)) - c = *pattern++; - if (c == EOS) - return (NULL); - if (*pattern == '-' - && (c2 = *(pattern+1)) != EOS && c2 != ']') { - pattern += 2; - if (c2 == '\\' && !(flags & FNM_NOESCAPE)) - c2 = *pattern++; - if (c2 == EOS) - return (NULL); - if (c <= test && test <= c2) - ok = 1; - } else if (c == test) - ok = 1; - } - return (ok == negate ? NULL : pattern); -} diff --git a/gen.subproj/ftok.3 b/gen.subproj/ftok.3 deleted file mode 100644 index ceed639..0000000 --- a/gen.subproj/ftok.3 +++ /dev/null @@ -1,87 +0,0 @@ -.\" $OpenBSD: ftok.3,v 1.8 1999/07/07 10:55:36 aaron Exp $ -.\" -.\" Copyright (c) 1994 SigmaSoft, Th. Lockert -.\" 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. 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 BY THE AUTHOR ``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 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 June 24, 1994 -.Dt FTOK 3 -.Os -.Sh NAME -.Nm ftok -.Nd create IPC indentifier from a pathname -.Sh SYNOPSIS -.Fd #include -.Fd #include -.Ft key_t -.Fn ftok "const char *path" "int id" ; -.Sh DESCRIPTION -The -.Fn ftok -function attempts to create a unique key suitable for use with the -.Xr msgget 2 , -.Xr semget 2 -and -.Xr shmget 2 -functions given the -.Fa path -of an existing file and a user-selectable -.Fa id . -.Pp -The specified -.Fa path -must refer to an existing file that is accessible to the calling process -or the call will fail. Also, note that links to files will return the -same key, given the same -.Fa id . -Only the 8 least significant bits of -.Fa id -are used in the key generation; the rest of the bits are ignored. -.Sh RETURN VALUES -The -.Fn ftok -function will return (key_t)\-1 if -.Fa path -does not exist or if it cannot be accessed by the calling process. -.Sh SEE ALSO -.Xr msgget 2 , -.Xr semget 2 , -.Xr shmget 2 -.Sh HISTORY -The -.Fn ftok -function originated with System V and is typically used by programs -that use the System V IPC routines. -.Sh AUTHOR -Thorsten Lockert -.Sh BUGS -The returned key is computed based on the device and inode of the -specified -.Fa path -in combination with the given -.Fa id . -Thus it is quite possible for the routine to return duplicate keys -given that those fields are not 8- and 16-bit quantities like they -were on System V based systems where this library routine's ancestors -were originally created. diff --git a/gen.subproj/ftok.c b/gen.subproj/ftok.c deleted file mode 100644 index fc70f62..0000000 --- a/gen.subproj/ftok.c +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (c) 1994 SigmaSoft, Th. Lockert - * 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. 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 BY THE AUTHOR ``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 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 *rcsid = "$Id: ftok.c,v 1.1.1.1 1999/10/14 21:08:51 wsanchez Exp $"; -#endif /* LIBC_SCCS and not lint */ - -#include -#include -#include - -key_t -ftok(path, id) - const char *path; - int id; -{ - struct stat st; - - if (stat(path, &st) < 0) - return (key_t)-1; - - return (key_t) ((id & 0xff) << 24 | (st.st_dev & 0xff) << 16 | (st.st_ino & 0xffff)); -} diff --git a/gen.subproj/fts.c b/gen.subproj/fts.c deleted file mode 100644 index 75576d7..0000000 --- a/gen.subproj/fts.c +++ /dev/null @@ -1,1015 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 1993, 1994 - * 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 -#include - -#include -#include -#include -#include -#include -#include -#include - -static FTSENT *fts_alloc __P((FTS *, char *, int)); -static FTSENT *fts_build __P((FTS *, int)); -static void fts_lfree __P((FTSENT *)); -static void fts_load __P((FTS *, FTSENT *)); -static size_t fts_maxarglen __P((char * const *)); -static void fts_padjust __P((FTS *, void *)); -static int fts_palloc __P((FTS *, size_t)); -static FTSENT *fts_sort __P((FTS *, FTSENT *, int)); -static u_short fts_stat __P((FTS *, FTSENT *, int)); - -#define ISDOT(a) (a[0] == '.' && (!a[1] || a[1] == '.' && !a[2])) - -#define ISSET(opt) (sp->fts_options & opt) -#define SET(opt) (sp->fts_options |= opt) - -#define CHDIR(sp, path) (!ISSET(FTS_NOCHDIR) && chdir(path)) -#define FCHDIR(sp, fd) (!ISSET(FTS_NOCHDIR) && fchdir(fd)) - -/* fts_build flags */ -#define BCHILD 1 /* fts_children */ -#define BNAMES 2 /* fts_children, names only */ -#define BREAD 3 /* fts_read */ - -FTS * -fts_open(argv, options, compar) - char * const *argv; - register int options; - int (*compar)(); -{ - register FTS *sp; - register FTSENT *p, *root; - register int nitems; - FTSENT *parent, *tmp; - int len; - - /* Options check. */ - if (options & ~FTS_OPTIONMASK) { - errno = EINVAL; - return (NULL); - } - - /* Allocate/initialize the stream */ - if ((sp = malloc((u_int)sizeof(FTS))) == NULL) - return (NULL); - memset(sp, 0, sizeof(FTS)); - sp->fts_compar = compar; - sp->fts_options = options; - - /* Logical walks turn on NOCHDIR; symbolic links are too hard. */ - if (ISSET(FTS_LOGICAL)) - SET(FTS_NOCHDIR); - - /* - * Start out with 1K of path space, and enough, in any case, - * to hold the user's paths. - */ - if (fts_palloc(sp, MAX(fts_maxarglen(argv), MAXPATHLEN))) - goto mem1; - - /* Allocate/initialize root's parent. */ - if ((parent = fts_alloc(sp, "", 0)) == NULL) - goto mem2; - parent->fts_level = FTS_ROOTPARENTLEVEL; - - /* Allocate/initialize root(s). */ - for (root = NULL, nitems = 0; *argv; ++argv, ++nitems) { - /* Don't allow zero-length paths. */ - if ((len = strlen(*argv)) == 0) { - errno = ENOENT; - goto mem3; - } - - p = fts_alloc(sp, *argv, len); - p->fts_level = FTS_ROOTLEVEL; - p->fts_parent = parent; - p->fts_accpath = p->fts_name; - p->fts_info = fts_stat(sp, p, ISSET(FTS_COMFOLLOW)); - - /* Command-line "." and ".." are real directories. */ - if (p->fts_info == FTS_DOT) - p->fts_info = FTS_D; - - /* - * If comparison routine supplied, traverse in sorted - * order; otherwise traverse in the order specified. - */ - if (compar) { - p->fts_link = root; - root = p; - } else { - p->fts_link = NULL; - if (root == NULL) - tmp = root = p; - else { - tmp->fts_link = p; - tmp = p; - } - } - } - if (compar && nitems > 1) - root = fts_sort(sp, root, nitems); - - /* - * Allocate a dummy pointer and make fts_read think that we've just - * finished the node before the root(s); set p->fts_info to FTS_INIT - * so that everything about the "current" node is ignored. - */ - if ((sp->fts_cur = fts_alloc(sp, "", 0)) == NULL) - goto mem3; - sp->fts_cur->fts_link = root; - sp->fts_cur->fts_info = FTS_INIT; - - /* - * If using chdir(2), grab a file descriptor pointing to dot to insure - * that we can get back here; this could be avoided for some paths, - * but almost certainly not worth the effort. Slashes, symbolic links, - * and ".." are all fairly nasty problems. Note, if we can't get the - * descriptor we run anyway, just more slowly. - */ - if (!ISSET(FTS_NOCHDIR) && (sp->fts_rfd = open(".", O_RDONLY, 0)) < 0) - SET(FTS_NOCHDIR); - - return (sp); - -mem3: fts_lfree(root); - free(parent); -mem2: free(sp->fts_path); -mem1: free(sp); - return (NULL); -} - -static void -fts_load(sp, p) - FTS *sp; - register FTSENT *p; -{ - register int len; - register char *cp; - - /* - * Load the stream structure for the next traversal. Since we don't - * actually enter the directory until after the preorder visit, set - * the fts_accpath field specially so the chdir gets done to the right - * place and the user can access the first node. From fts_open it's - * known that the path will fit. - */ - len = p->fts_pathlen = p->fts_namelen; - memmove(sp->fts_path, p->fts_name, len + 1); - if ((cp = strrchr(p->fts_name, '/')) && (cp != p->fts_name || cp[1])) { - len = strlen(++cp); - memmove(p->fts_name, cp, len + 1); - p->fts_namelen = len; - } - p->fts_accpath = p->fts_path = sp->fts_path; - sp->fts_dev = p->fts_dev; -} - -int -fts_close(sp) - FTS *sp; -{ - register FTSENT *freep, *p; - int saved_errno = 0; - - /* - * This still works if we haven't read anything -- the dummy structure - * points to the root list, so we step through to the end of the root - * list which has a valid parent pointer. - */ - if (sp->fts_cur) { - for (p = sp->fts_cur; p->fts_level >= FTS_ROOTLEVEL;) { - freep = p; - p = p->fts_link ? p->fts_link : p->fts_parent; - free(freep); - } - free(p); - } - - /* Free up child linked list, sort array, path buffer. */ - if (sp->fts_child) - fts_lfree(sp->fts_child); - if (sp->fts_array) - free(sp->fts_array); - free(sp->fts_path); - - /* Return to original directory, save errno if necessary. */ - if (!ISSET(FTS_NOCHDIR)) { - if (fchdir(sp->fts_rfd)) { - saved_errno = errno; - } - (void)close(sp->fts_rfd); - } - - /* Free up the stream pointer. */ - free(sp); - - /* Set errno and return. */ - if (saved_errno) { - errno = saved_errno; - return (-1); - } - return (0); -} - -/* - * Special case a root of "/" so that slashes aren't appended which would - * cause paths to be written as "//foo". - */ -#define NAPPEND(p) \ - (p->fts_level == FTS_ROOTLEVEL && p->fts_pathlen == 1 && \ - p->fts_path[0] == '/' ? 0 : p->fts_pathlen) - -FTSENT * -fts_read(sp) - register FTS *sp; -{ - register FTSENT *p, *tmp; - register int instr; - register char *t; - int saved_errno; - - /* If finished or unrecoverable error, return NULL. */ - if (sp->fts_cur == NULL || ISSET(FTS_STOP)) - return (NULL); - - /* Set current node pointer. */ - p = sp->fts_cur; - - /* Save and zero out user instructions. */ - instr = p->fts_instr; - p->fts_instr = FTS_NOINSTR; - - /* Any type of file may be re-visited; re-stat and re-turn. */ - if (instr == FTS_AGAIN) { - p->fts_info = fts_stat(sp, p, 0); - return (p); - } - - /* - * Following a symlink -- SLNONE test allows application to see - * SLNONE and recover. If indirecting through a symlink, have - * keep a pointer to current location. If unable to get that - * pointer, follow fails. - */ - if (instr == FTS_FOLLOW && - (p->fts_info == FTS_SL || p->fts_info == FTS_SLNONE)) { - p->fts_info = fts_stat(sp, p, 1); - if (p->fts_info == FTS_D && !ISSET(FTS_NOCHDIR)) - if ((p->fts_symfd = open(".", O_RDONLY, 0)) < 0) { - p->fts_errno = errno; - p->fts_info = FTS_ERR; - } else - p->fts_flags |= FTS_SYMFOLLOW; - return (p); - } - - /* Directory in pre-order. */ - if (p->fts_info == FTS_D) { - /* If skipped or crossed mount point, do post-order visit. */ - if (instr == FTS_SKIP || - ISSET(FTS_XDEV) && p->fts_dev != sp->fts_dev) { - if (p->fts_flags & FTS_SYMFOLLOW) - (void)close(p->fts_symfd); - if (sp->fts_child) { - fts_lfree(sp->fts_child); - sp->fts_child = NULL; - } - p->fts_info = FTS_DP; - return (p); - } - - /* Rebuild if only read the names and now traversing. */ - if (sp->fts_child && sp->fts_options & FTS_NAMEONLY) { - sp->fts_options &= ~FTS_NAMEONLY; - fts_lfree(sp->fts_child); - sp->fts_child = NULL; - } - - /* - * Cd to the subdirectory. - * - * If have already read and now fail to chdir, whack the list - * to make the names come out right, and set the parent errno - * so the application will eventually get an error condition. - * Set the FTS_DONTCHDIR flag so that when we logically change - * directories back to the parent we don't do a chdir. - * - * If haven't read do so. If the read fails, fts_build sets - * FTS_STOP or the fts_info field of the node. - */ - if (sp->fts_child) { - if (CHDIR(sp, p->fts_accpath)) { - p->fts_errno = errno; - p->fts_flags |= FTS_DONTCHDIR; - for (p = sp->fts_child; p; p = p->fts_link) - p->fts_accpath = - p->fts_parent->fts_accpath; - } - } else if ((sp->fts_child = fts_build(sp, BREAD)) == NULL) { - if (ISSET(FTS_STOP)) - return (NULL); - return (p); - } - p = sp->fts_child; - sp->fts_child = NULL; - goto name; - } - - /* Move to the next node on this level. */ -next: tmp = p; - if (p = p->fts_link) { - free(tmp); - - /* - * If reached the top, return to the original directory, and - * load the paths for the next root. - */ - if (p->fts_level == FTS_ROOTLEVEL) { - if (!ISSET(FTS_NOCHDIR) && FCHDIR(sp, sp->fts_rfd)) { - SET(FTS_STOP); - return (NULL); - } - fts_load(sp, p); - return (sp->fts_cur = p); - } - - /* - * User may have called fts_set on the node. If skipped, - * ignore. If followed, get a file descriptor so we can - * get back if necessary. - */ - if (p->fts_instr == FTS_SKIP) - goto next; - if (p->fts_instr == FTS_FOLLOW) { - p->fts_info = fts_stat(sp, p, 1); - if (p->fts_info == FTS_D && !ISSET(FTS_NOCHDIR)) - if ((p->fts_symfd = - open(".", O_RDONLY, 0)) < 0) { - p->fts_errno = errno; - p->fts_info = FTS_ERR; - } else - p->fts_flags |= FTS_SYMFOLLOW; - p->fts_instr = FTS_NOINSTR; - } - -name: t = sp->fts_path + NAPPEND(p->fts_parent); - *t++ = '/'; - memmove(t, p->fts_name, p->fts_namelen + 1); - return (sp->fts_cur = p); - } - - /* Move up to the parent node. */ - p = tmp->fts_parent; - free(tmp); - - if (p->fts_level == FTS_ROOTPARENTLEVEL) { - /* - * Done; free everything up and set errno to 0 so the user - * can distinguish between error and EOF. - */ - free(p); - errno = 0; - return (sp->fts_cur = NULL); - } - - /* Nul terminate the pathname. */ - sp->fts_path[p->fts_pathlen] = '\0'; - - /* - * Return to the parent directory. If at a root node or came through - * a symlink, go back through the file descriptor. Otherwise, cd up - * one directory. - */ - if (p->fts_level == FTS_ROOTLEVEL) { - if (!ISSET(FTS_NOCHDIR) && FCHDIR(sp, sp->fts_rfd)) { - SET(FTS_STOP); - return (NULL); - } - } else if (p->fts_flags & FTS_SYMFOLLOW) { - if (FCHDIR(sp, p->fts_symfd)) { - saved_errno = errno; - (void)close(p->fts_symfd); - errno = saved_errno; - SET(FTS_STOP); - return (NULL); - } - (void)close(p->fts_symfd); - } else if (!(p->fts_flags & FTS_DONTCHDIR)) { - if (CHDIR(sp, "..")) { - SET(FTS_STOP); - return (NULL); - } - } - p->fts_info = p->fts_errno ? FTS_ERR : FTS_DP; - return (sp->fts_cur = p); -} - -/* - * Fts_set takes the stream as an argument although it's not used in this - * implementation; it would be necessary if anyone wanted to add global - * semantics to fts using fts_set. An error return is allowed for similar - * reasons. - */ -/* ARGSUSED */ -int -fts_set(sp, p, instr) - FTS *sp; - FTSENT *p; - int instr; -{ - if (instr && instr != FTS_AGAIN && instr != FTS_FOLLOW && - instr != FTS_NOINSTR && instr != FTS_SKIP) { - errno = EINVAL; - return (1); - } - p->fts_instr = instr; - return (0); -} - -FTSENT * -fts_children(sp, instr) - register FTS *sp; - int instr; -{ - register FTSENT *p; - int fd; - - if (instr && instr != FTS_NAMEONLY) { - errno = EINVAL; - return (NULL); - } - - /* Set current node pointer. */ - p = sp->fts_cur; - - /* - * Errno set to 0 so user can distinguish empty directory from - * an error. - */ - errno = 0; - - /* Fatal errors stop here. */ - if (ISSET(FTS_STOP)) - return (NULL); - - /* Return logical hierarchy of user's arguments. */ - if (p->fts_info == FTS_INIT) - return (p->fts_link); - - /* - * If not a directory being visited in pre-order, stop here. Could - * allow FTS_DNR, assuming the user has fixed the problem, but the - * same effect is available with FTS_AGAIN. - */ - if (p->fts_info != FTS_D /* && p->fts_info != FTS_DNR */) - return (NULL); - - /* Free up any previous child list. */ - if (sp->fts_child) - fts_lfree(sp->fts_child); - - if (instr == FTS_NAMEONLY) { - sp->fts_options |= FTS_NAMEONLY; - instr = BNAMES; - } else - instr = BCHILD; - - /* - * If using chdir on a relative path and called BEFORE fts_read does - * its chdir to the root of a traversal, we can lose -- we need to - * chdir into the subdirectory, and we don't know where the current - * directory is, so we can't get back so that the upcoming chdir by - * fts_read will work. - */ - if (p->fts_level != FTS_ROOTLEVEL || p->fts_accpath[0] == '/' || - ISSET(FTS_NOCHDIR)) - return (sp->fts_child = fts_build(sp, instr)); - - if ((fd = open(".", O_RDONLY, 0)) < 0) - return (NULL); - sp->fts_child = fts_build(sp, instr); - if (fchdir(fd)) - return (NULL); - (void)close(fd); - return (sp->fts_child); -} - -/* - * This is the tricky part -- do not casually change *anything* in here. The - * idea is to build the linked list of entries that are used by fts_children - * and fts_read. There are lots of special cases. - * - * The real slowdown in walking the tree is the stat calls. If FTS_NOSTAT is - * set and it's a physical walk (so that symbolic links can't be directories), - * we can do things quickly. First, if it's a 4.4BSD file system, the type - * of the file is in the directory entry. Otherwise, we assume that the number - * of subdirectories in a node is equal to the number of links to the parent. - * The former skips all stat calls. The latter skips stat calls in any leaf - * directories and for any files after the subdirectories in the directory have - * been found, cutting the stat calls by about 2/3. - */ -static FTSENT * -fts_build(sp, type) - register FTS *sp; - int type; -{ - register struct dirent *dp; - register FTSENT *p, *head; - register int nitems; - FTSENT *cur, *tail; - DIR *dirp; - void *adjaddr; - int cderrno, descend, len, level, maxlen, nlinks, oflag, saved_errno; - char *cp; - - /* Set current node pointer. */ - cur = sp->fts_cur; - - /* - * Open the directory for reading. If this fails, we're done. - * If being called from fts_read, set the fts_info field. - */ -#ifdef FTS_WHITEOUT - if (ISSET(FTS_WHITEOUT)) - oflag = DTF_NODUP|DTF_REWIND; - else - oflag = DTF_HIDEW|DTF_NODUP|DTF_REWIND; -#else -#define __opendir2(path, flag) opendir(path) -#endif - if ((dirp = __opendir2(cur->fts_accpath, oflag)) == NULL) { - if (type == BREAD) { - cur->fts_info = FTS_DNR; - cur->fts_errno = errno; - } - return (NULL); - } - - /* - * Nlinks is the number of possible entries of type directory in the - * directory if we're cheating on stat calls, 0 if we're not doing - * any stat calls at all, -1 if we're doing stats on everything. - */ - if (type == BNAMES) - nlinks = 0; - else if (ISSET(FTS_NOSTAT) && ISSET(FTS_PHYSICAL)) - nlinks = cur->fts_nlink - (ISSET(FTS_SEEDOT) ? 0 : 2); - else - nlinks = -1; - -#ifdef notdef - (void)printf("nlinks == %d (cur: %d)\n", nlinks, cur->fts_nlink); - (void)printf("NOSTAT %d PHYSICAL %d SEEDOT %d\n", - ISSET(FTS_NOSTAT), ISSET(FTS_PHYSICAL), ISSET(FTS_SEEDOT)); -#endif - /* - * If we're going to need to stat anything or we want to descend - * and stay in the directory, chdir. If this fails we keep going, - * but set a flag so we don't chdir after the post-order visit. - * We won't be able to stat anything, but we can still return the - * names themselves. Note, that since fts_read won't be able to - * chdir into the directory, it will have to return different path - * names than before, i.e. "a/b" instead of "b". Since the node - * has already been visited in pre-order, have to wait until the - * post-order visit to return the error. There is a special case - * here, if there was nothing to stat then it's not an error to - * not be able to stat. This is all fairly nasty. If a program - * needed sorted entries or stat information, they had better be - * checking FTS_NS on the returned nodes. - */ - cderrno = 0; - if (nlinks || type == BREAD) - if (FCHDIR(sp, dirfd(dirp))) { - if (nlinks && type == BREAD) - cur->fts_errno = errno; - cur->fts_flags |= FTS_DONTCHDIR; - descend = 0; - cderrno = errno; - } else - descend = 1; - else - descend = 0; - - /* - * Figure out the max file name length that can be stored in the - * current path -- the inner loop allocates more path as necessary. - * We really wouldn't have to do the maxlen calculations here, we - * could do them in fts_read before returning the path, but it's a - * lot easier here since the length is part of the dirent structure. - * - * If not changing directories set a pointer so that can just append - * each new name into the path. - */ - maxlen = sp->fts_pathlen - cur->fts_pathlen - 1; - len = NAPPEND(cur); - if (ISSET(FTS_NOCHDIR)) { - cp = sp->fts_path + len; - *cp++ = '/'; - } - - level = cur->fts_level + 1; - - /* Read the directory, attaching each entry to the `link' pointer. */ - adjaddr = NULL; - for (head = tail = NULL, nitems = 0; dp = readdir(dirp);) { - if (!ISSET(FTS_SEEDOT) && ISDOT(dp->d_name)) - continue; - - if ((p = fts_alloc(sp, dp->d_name, (int)dp->d_namlen)) == NULL) - goto mem1; - if (dp->d_namlen > maxlen) { - if (fts_palloc(sp, (size_t)dp->d_namlen)) { - /* - * No more memory for path or structures. Save - * errno, free up the current structure and the - * structures already allocated. - */ -mem1: saved_errno = errno; - if (p) - free(p); - fts_lfree(head); - (void)closedir(dirp); - errno = saved_errno; - cur->fts_info = FTS_ERR; - SET(FTS_STOP); - return (NULL); - } - adjaddr = sp->fts_path; - maxlen = sp->fts_pathlen - sp->fts_cur->fts_pathlen - 1; - } - - p->fts_pathlen = len + dp->d_namlen + 1; - p->fts_parent = sp->fts_cur; - p->fts_level = level; - -#ifdef FTS_WHITEOUT - if (dp->d_type == DT_WHT) - p->fts_flags |= FTS_ISW; -#endif - - if (cderrno) { - if (nlinks) { - p->fts_info = FTS_NS; - p->fts_errno = cderrno; - } else - p->fts_info = FTS_NSOK; - p->fts_accpath = cur->fts_accpath; - } else if (nlinks == 0 -#ifdef DT_DIR - || nlinks > 0 && - dp->d_type != DT_DIR && dp->d_type != DT_UNKNOWN -#endif - ) { - p->fts_accpath = - ISSET(FTS_NOCHDIR) ? p->fts_path : p->fts_name; - p->fts_info = FTS_NSOK; - } else { - /* Build a file name for fts_stat to stat. */ - if (ISSET(FTS_NOCHDIR)) { - p->fts_accpath = p->fts_path; - memmove(cp, p->fts_name, p->fts_namelen + 1); - } else - p->fts_accpath = p->fts_name; - /* Stat it. */ - p->fts_info = fts_stat(sp, p, 0); - - /* Decrement link count if applicable. */ - if (nlinks > 0 && (p->fts_info == FTS_D || - p->fts_info == FTS_DC || p->fts_info == FTS_DOT)) - --nlinks; - } - - /* We walk in directory order so "ls -f" doesn't get upset. */ - p->fts_link = NULL; - if (head == NULL) - head = tail = p; - else { - tail->fts_link = p; - tail = p; - } - ++nitems; - } - (void)closedir(dirp); - - /* - * If had to realloc the path, adjust the addresses for the rest - * of the tree. - */ - if (adjaddr) - fts_padjust(sp, adjaddr); - - /* - * If not changing directories, reset the path back to original - * state. - */ - if (ISSET(FTS_NOCHDIR)) { - if (cp - 1 > sp->fts_path) - --cp; - *cp = '\0'; - } - - /* - * If descended after called from fts_children or after called from - * fts_read and nothing found, get back. At the root level we use - * the saved fd; if one of fts_open()'s arguments is a relative path - * to an empty directory, we wind up here with no other way back. If - * can't get back, we're done. - */ - if (descend && (type == BCHILD || !nitems) && - (cur->fts_level == FTS_ROOTLEVEL ? - FCHDIR(sp, sp->fts_rfd) : CHDIR(sp, ".."))) { - cur->fts_info = FTS_ERR; - SET(FTS_STOP); - return (NULL); - } - - /* If didn't find anything, return NULL. */ - if (!nitems) { - if (type == BREAD) - cur->fts_info = FTS_DP; - return (NULL); - } - - /* Sort the entries. */ - if (sp->fts_compar && nitems > 1) - head = fts_sort(sp, head, nitems); - return (head); -} - -static u_short -fts_stat(sp, p, follow) - FTS *sp; - register FTSENT *p; - int follow; -{ - register FTSENT *t; - register dev_t dev; - register ino_t ino; - struct stat *sbp, sb; - int saved_errno; - - /* If user needs stat info, stat buffer already allocated. */ - sbp = ISSET(FTS_NOSTAT) ? &sb : p->fts_statp; - -#ifdef FTS_WHITEOUT - /* check for whiteout */ - if (p->fts_flags & FTS_ISW) { - if (sbp != &sb) { - memset(sbp, '\0', sizeof (*sbp)); - sbp->st_mode = S_IFWHT; - } - return (FTS_W); - } -#endif - - /* - * If doing a logical walk, or application requested FTS_FOLLOW, do - * a stat(2). If that fails, check for a non-existent symlink. If - * fail, set the errno from the stat call. - */ - if (ISSET(FTS_LOGICAL) || follow) { - if (stat(p->fts_accpath, sbp)) { - saved_errno = errno; - if (!lstat(p->fts_accpath, sbp)) { - errno = 0; - return (FTS_SLNONE); - } - p->fts_errno = saved_errno; - goto err; - } - } else if (lstat(p->fts_accpath, sbp)) { - p->fts_errno = errno; -err: memset(sbp, 0, sizeof(struct stat)); - return (FTS_NS); - } - - if (S_ISDIR(sbp->st_mode)) { - /* - * Set the device/inode. Used to find cycles and check for - * crossing mount points. Also remember the link count, used - * in fts_build to limit the number of stat calls. It is - * understood that these fields are only referenced if fts_info - * is set to FTS_D. - */ - dev = p->fts_dev = sbp->st_dev; - ino = p->fts_ino = sbp->st_ino; - p->fts_nlink = sbp->st_nlink; - - if (ISDOT(p->fts_name)) - return (FTS_DOT); - - /* - * Cycle detection is done by brute force when the directory - * is first encountered. If the tree gets deep enough or the - * number of symbolic links to directories is high enough, - * something faster might be worthwhile. - */ - for (t = p->fts_parent; - t->fts_level >= FTS_ROOTLEVEL; t = t->fts_parent) - if (ino == t->fts_ino && dev == t->fts_dev) { - p->fts_cycle = t; - return (FTS_DC); - } - return (FTS_D); - } - if (S_ISLNK(sbp->st_mode)) - return (FTS_SL); - if (S_ISREG(sbp->st_mode)) - return (FTS_F); - return (FTS_DEFAULT); -} - -static FTSENT * -fts_sort(sp, head, nitems) - FTS *sp; - FTSENT *head; - register int nitems; -{ - register FTSENT **ap, *p; - - /* - * Construct an array of pointers to the structures and call qsort(3). - * Reassemble the array in the order returned by qsort. If unable to - * sort for memory reasons, return the directory entries in their - * current order. Allocate enough space for the current needs plus - * 40 so don't realloc one entry at a time. - */ - if (nitems > sp->fts_nitems) { - sp->fts_nitems = nitems + 40; - if ((sp->fts_array = realloc(sp->fts_array, - (size_t)(sp->fts_nitems * sizeof(FTSENT *)))) == NULL) { - sp->fts_nitems = 0; - return (head); - } - } - for (ap = sp->fts_array, p = head; p; p = p->fts_link) - *ap++ = p; - qsort((void *)sp->fts_array, nitems, sizeof(FTSENT *), sp->fts_compar); - for (head = *(ap = sp->fts_array); --nitems; ++ap) - ap[0]->fts_link = ap[1]; - ap[0]->fts_link = NULL; - return (head); -} - -static FTSENT * -fts_alloc(sp, name, namelen) - FTS *sp; - char *name; - register int namelen; -{ - register FTSENT *p; - size_t len; - - /* - * The file name is a variable length array and no stat structure is - * necessary if the user has set the nostat bit. Allocate the FTSENT - * structure, the file name and the stat structure in one chunk, but - * be careful that the stat structure is reasonably aligned. Since the - * fts_name field is declared to be of size 1, the fts_name pointer is - * namelen + 2 before the first possible address of the stat structure. - */ - len = sizeof(FTSENT) + namelen; - if (!ISSET(FTS_NOSTAT)) - len += sizeof(struct stat) + ALIGNBYTES; - if ((p = malloc(len)) == NULL) - return (NULL); - - /* Copy the name plus the trailing NULL. */ - memmove(p->fts_name, name, namelen + 1); - - if (!ISSET(FTS_NOSTAT)) - p->fts_statp = (struct stat *)ALIGN(p->fts_name + namelen + 2); - p->fts_namelen = namelen; - p->fts_path = sp->fts_path; - p->fts_errno = 0; - p->fts_flags = 0; - p->fts_instr = FTS_NOINSTR; - p->fts_number = 0; - p->fts_pointer = NULL; - return (p); -} - -static void -fts_lfree(head) - register FTSENT *head; -{ - register FTSENT *p; - - /* Free a linked list of structures. */ - while (p = head) { - head = head->fts_link; - free(p); - } -} - -/* - * Allow essentially unlimited paths; find, rm, ls should all work on any tree. - * Most systems will allow creation of paths much longer than MAXPATHLEN, even - * though the kernel won't resolve them. Add the size (not just what's needed) - * plus 256 bytes so don't realloc the path 2 bytes at a time. - */ -static int -fts_palloc(sp, more) - FTS *sp; - size_t more; -{ - sp->fts_pathlen += more + 256; - sp->fts_path = realloc(sp->fts_path, (size_t)sp->fts_pathlen); - return (sp->fts_path == NULL); -} - -/* - * When the path is realloc'd, have to fix all of the pointers in structures - * already returned. - */ -static void -fts_padjust(sp, addr) - FTS *sp; - void *addr; -{ - FTSENT *p; - -#define ADJUST(p) { \ - (p)->fts_accpath = \ - (char *)addr + ((p)->fts_accpath - (p)->fts_path); \ - (p)->fts_path = addr; \ -} - /* Adjust the current set of children. */ - for (p = sp->fts_child; p; p = p->fts_link) - ADJUST(p); - - /* Adjust the rest of the tree. */ - for (p = sp->fts_cur; p->fts_level >= FTS_ROOTLEVEL;) { - ADJUST(p); - p = p->fts_link ? p->fts_link : p->fts_parent; - } -} - -static size_t -fts_maxarglen(argv) - char * const *argv; -{ - size_t len, max; - - for (max = 0; *argv; ++argv) - if ((len = strlen(*argv)) > max) - max = len; - return (max); -} diff --git a/gen.subproj/getbsize.c b/gen.subproj/getbsize.c deleted file mode 100644 index 8d64465..0000000 --- a/gen.subproj/getbsize.c +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * 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. - */ - - -#include -#include -#include -#include - -char * -getbsize(headerlenp, blocksizep) - int *headerlenp; - long *blocksizep; -{ - static char header[20]; - long n, max, mul, blocksize; - char *ep, *p, *form; - -#define KB (1024L) -#define MB (1024L * 1024L) -#define GB (1024L * 1024L * 1024L) -#define MAXB GB /* No tera, peta, nor exa. */ - form = ""; - if ((p = getenv("BLOCKSIZE")) != NULL && *p != '\0') { - if ((n = strtol(p, &ep, 10)) < 0) - goto underflow; - if (n == 0) - n = 1; - if (*ep && ep[1]) - goto fmterr; - switch (*ep) { - case 'G': case 'g': - form = "G"; - max = MAXB / GB; - mul = GB; - break; - case 'K': case 'k': - form = "K"; - max = MAXB / KB; - mul = KB; - break; - case 'M': case 'm': - form = "M"; - max = MAXB / MB; - mul = MB; - break; - case '\0': - max = MAXB; - mul = 1; - break; - default: -fmterr: warnx("%s: unknown blocksize", p); - n = 512; - mul = 1; - break; - } - if (n > max) { - warnx("maximum blocksize is %dG", MAXB / GB); - n = max; - } - if ((blocksize = n * mul) < 512) { -underflow: warnx("minimum blocksize is 512"); - form = ""; - blocksize = n = 512; - } - } else - blocksize = n = 512; - - (void)snprintf(header, sizeof(header), "%d%s-blocks", n, form); - *headerlenp = strlen(header); - *blocksizep = blocksize; - return (header); -} diff --git a/gen.subproj/getcap.c b/gen.subproj/getcap.c deleted file mode 100644 index 8ce326b..0000000 --- a/gen.subproj/getcap.c +++ /dev/null @@ -1,1064 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/*- - * Copyright (c) 1992, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Casey Leedom of Lawrence Livermore National Laboratory. - * - * 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 rcsid[] = "$OpenBSD: getcap.c,v 1.4 1997/02/01 04:35:33 deraadt Exp $"; -#endif /* LIBC_SCCS and not lint */ - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define BFRAG 1024 -#define BSIZE 1024 -#define ESC ('[' & 037) /* ASCII ESC */ -#define MAX_RECURSION 32 /* maximum getent recursion */ -#define SFRAG 100 /* cgetstr mallocs in SFRAG chunks */ - -#define RECOK (char)0 -#define TCERR (char)1 -#define SHADOW (char)2 - -static size_t topreclen; /* toprec length */ -static char *toprec; /* Additional record specified by cgetset() */ -static int gottoprec; /* Flag indicating retrieval of toprecord */ - -static int cdbget __P((DB *, char **, char *)); -static int getent __P((char **, u_int *, char **, int, char *, int, char *)); -static int nfcmp __P((char *, char *)); - -/* - * Cgetset() allows the addition of a user specified buffer to be added - * to the database array, in effect "pushing" the buffer on top of the - * virtual database. 0 is returned on success, -1 on failure. - */ -int -cgetset(ent) - char *ent; -{ - if (ent == NULL) { - if (toprec) - free(toprec); - toprec = NULL; - topreclen = 0; - return (0); - } - topreclen = strlen(ent); - if ((toprec = malloc (topreclen + 1)) == NULL) { - errno = ENOMEM; - return (-1); - } - gottoprec = 0; - (void)strcpy(toprec, ent); - return (0); -} - -/* - * Cgetcap searches the capability record buf for the capability cap with - * type `type'. A pointer to the value of cap is returned on success, NULL - * if the requested capability couldn't be found. - * - * Specifying a type of ':' means that nothing should follow cap (:cap:). - * In this case a pointer to the terminating ':' or NUL will be returned if - * cap is found. - * - * If (cap, '@') or (cap, terminator, '@') is found before (cap, terminator) - * return NULL. - */ -char * -cgetcap(buf, cap, type) - char *buf, *cap; - int type; -{ - register char *bp, *cp; - - bp = buf; - for (;;) { - /* - * Skip past the current capability field - it's either the - * name field if this is the first time through the loop, or - * the remainder of a field whose name failed to match cap. - */ - for (;;) - if (*bp == '\0') - return (NULL); - else - if (*bp++ == ':') - break; - - /* - * Try to match (cap, type) in buf. - */ - for (cp = cap; *cp == *bp && *bp != '\0'; cp++, bp++) - continue; - if (*cp != '\0') - continue; - if (*bp == '@') - return (NULL); - if (type == ':') { - if (*bp != '\0' && *bp != ':') - continue; - return(bp); - } - if (*bp != type) - continue; - bp++; - return (*bp == '@' ? NULL : bp); - } - /* NOTREACHED */ -} - -/* - * Cgetent extracts the capability record name from the NULL terminated file - * array db_array and returns a pointer to a malloc'd copy of it in buf. - * Buf must be retained through all subsequent calls to cgetcap, cgetnum, - * cgetflag, and cgetstr, but may then be free'd. 0 is returned on success, - * -1 if the requested record couldn't be found, -2 if a system error was - * encountered (couldn't open/read a file, etc.), and -3 if a potential - * reference loop is detected. - */ -int -cgetent(buf, db_array, name) - char **buf, **db_array, *name; -{ - u_int dummy; - - return (getent(buf, &dummy, db_array, -1, name, 0, NULL)); -} - -/* - * Getent implements the functions of cgetent. If fd is non-negative, - * *db_array has already been opened and fd is the open file descriptor. We - * do this to save time and avoid using up file descriptors for tc= - * recursions. - * - * Getent returns the same success/failure codes as cgetent. On success, a - * pointer to a malloc'ed capability record with all tc= capabilities fully - * expanded and its length (not including trailing ASCII NUL) are left in - * *cap and *len. - * - * Basic algorithm: - * + Allocate memory incrementally as needed in chunks of size BFRAG - * for capability buffer. - * + Recurse for each tc=name and interpolate result. Stop when all - * names interpolated, a name can't be found, or depth exceeds - * MAX_RECURSION. - */ -static int -getent(cap, len, db_array, fd, name, depth, nfield) - char **cap, **db_array, *name, *nfield; - u_int *len; - int fd, depth; -{ - DB *capdbp; - register char *r_end, *rp, **db_p; - int myfd, eof, foundit, retval, clen; - char *record, *cbuf; - int tc_not_resolved; - char pbuf[_POSIX_PATH_MAX]; - - /* - * Return with ``loop detected'' error if we've recursed more than - * MAX_RECURSION times. - */ - if (depth > MAX_RECURSION) - return (-3); - - /* - * Check if we have a top record from cgetset(). - */ - if (depth == 0 && toprec != NULL && cgetmatch(toprec, name) == 0) { - if ((record = malloc (topreclen + BFRAG)) == NULL) { - errno = ENOMEM; - return (-2); - } - (void)strcpy(record, toprec); - myfd = 0; - db_p = db_array; - rp = record + topreclen + 1; - r_end = rp + BFRAG; - goto tc_exp; - } - /* - * Allocate first chunk of memory. - */ - if ((record = malloc(BFRAG)) == NULL) { - errno = ENOMEM; - return (-2); - } - r_end = record + BFRAG; - foundit = 0; - /* - * Loop through database array until finding the record. - */ - - for (db_p = db_array; *db_p != NULL; db_p++) { - eof = 0; - - /* - * Open database if not already open. - */ - - if (fd >= 0) { - (void)lseek(fd, (off_t)0, SEEK_SET); - myfd = 0; - } else { - (void)snprintf(pbuf, sizeof(pbuf), "%s.db", *db_p); - if ((capdbp = dbopen(pbuf, O_RDONLY, 0, DB_HASH, 0)) - != NULL) { - free(record); - retval = cdbget(capdbp, &record, name); - if (retval < 0) { - /* no record available */ - (void)capdbp->close(capdbp); - return (retval); - } - /* save the data; close frees it */ - clen = strlen(record); - cbuf = malloc(clen + 1); - memcpy(cbuf, record, clen + 1); - if (capdbp->close(capdbp) < 0) { - free(cbuf); - return (-2); - } - *len = clen; - *cap = cbuf; - return (retval); - } else { - fd = open(*db_p, O_RDONLY, 0); - if (fd < 0) { - /* No error on unfound file. */ - continue; - } - myfd = 1; - } - } - /* - * Find the requested capability record ... - */ - { - char buf[BUFSIZ]; - register char *b_end, *bp; - register int c; - - /* - * Loop invariants: - * There is always room for one more character in record. - * R_end always points just past end of record. - * Rp always points just past last character in record. - * B_end always points just past last character in buf. - * Bp always points at next character in buf. - */ - b_end = buf; - bp = buf; - for (;;) { - - /* - * Read in a line implementing (\, newline) - * line continuation. - */ - rp = record; - for (;;) { - if (bp >= b_end) { - int n; - - n = read(fd, buf, sizeof(buf)); - if (n <= 0) { - if (myfd) - (void)close(fd); - if (n < 0) { - free(record); - return (-2); - } else { - fd = -1; - eof = 1; - break; - } - } - b_end = buf+n; - bp = buf; - } - - c = *bp++; - if (c == '\n') { - if (rp > record && *(rp-1) == '\\') { - rp--; - continue; - } else - break; - } - *rp++ = c; - - /* - * Enforce loop invariant: if no room - * left in record buffer, try to get - * some more. - */ - if (rp >= r_end) { - u_int pos; - size_t newsize; - - pos = rp - record; - newsize = r_end - record + BFRAG; - record = realloc(record, newsize); - if (record == NULL) { - errno = ENOMEM; - if (myfd) - (void)close(fd); - return (-2); - } - r_end = record + newsize; - rp = record + pos; - } - } - /* loop invariant let's us do this */ - *rp++ = '\0'; - - /* - * If encountered eof check next file. - */ - if (eof) - break; - - /* - * Toss blank lines and comments. - */ - if (*record == '\0' || *record == '#') - continue; - - /* - * See if this is the record we want ... - */ - if (cgetmatch(record, name) == 0) { - if (nfield == NULL || !nfcmp(nfield, record)) { - foundit = 1; - break; /* found it! */ - } - } - } - } - if (foundit) - break; - } - - if (!foundit) { - free(record); - return (-1); - } - - /* - * Got the capability record, but now we have to expand all tc=name - * references in it ... - */ -tc_exp: { - register char *newicap, *s; - register int newilen; - u_int ilen; - int diff, iret, tclen; - char *icap, *scan, *tc, *tcstart, *tcend; - - /* - * Loop invariants: - * There is room for one more character in record. - * R_end points just past end of record. - * Rp points just past last character in record. - * Scan points at remainder of record that needs to be - * scanned for tc=name constructs. - */ - scan = record; - tc_not_resolved = 0; - for (;;) { - if ((tc = cgetcap(scan, "tc", '=')) == NULL) - break; - - /* - * Find end of tc=name and stomp on the trailing `:' - * (if present) so we can use it to call ourselves. - */ - s = tc; - for (;;) - if (*s == '\0') - break; - else - if (*s++ == ':') { - *(s - 1) = '\0'; - break; - } - tcstart = tc - 3; - tclen = s - tcstart; - tcend = s; - - iret = getent(&icap, &ilen, db_p, fd, tc, depth+1, - NULL); - newicap = icap; /* Put into a register. */ - newilen = ilen; - if (iret != 0) { - /* an error */ - if (iret < -1) { - if (myfd) - (void)close(fd); - free(record); - return (iret); - } - if (iret == 1) - tc_not_resolved = 1; - /* couldn't resolve tc */ - if (iret == -1) { - *(s - 1) = ':'; - scan = s - 1; - tc_not_resolved = 1; - continue; - - } - } - /* not interested in name field of tc'ed record */ - s = newicap; - for (;;) - if (*s == '\0') - break; - else - if (*s++ == ':') - break; - newilen -= s - newicap; - newicap = s; - - /* make sure interpolated record is `:'-terminated */ - s += newilen; - if (*(s-1) != ':') { - *s = ':'; /* overwrite NUL with : */ - newilen++; - } - - /* - * Make sure there's enough room to insert the - * new record. - */ - diff = newilen - tclen; - if (diff >= r_end - rp) { - u_int pos, tcpos, tcposend; - size_t newsize; - - pos = rp - record; - newsize = r_end - record + diff + BFRAG; - tcpos = tcstart - record; - tcposend = tcend - record; - record = realloc(record, newsize); - if (record == NULL) { - errno = ENOMEM; - if (myfd) - (void)close(fd); - free(icap); - return (-2); - } - r_end = record + newsize; - rp = record + pos; - tcstart = record + tcpos; - tcend = record + tcposend; - } - - /* - * Insert tc'ed record into our record. - */ - s = tcstart + newilen; - bcopy(tcend, s, rp - tcend); - bcopy(newicap, tcstart, newilen); - rp += diff; - free(icap); - - /* - * Start scan on `:' so next cgetcap works properly - * (cgetcap always skips first field). - */ - scan = s-1; - } - - } - /* - * Close file (if we opened it), give back any extra memory, and - * return capability, length and success. - */ - if (myfd) - (void)close(fd); - *len = rp - record - 1; /* don't count NUL */ - if (r_end > rp) - if ((record = - realloc(record, (size_t)(rp - record))) == NULL) { - errno = ENOMEM; - return (-2); - } - - *cap = record; - if (tc_not_resolved) - return (1); - return (0); -} - -static int -cdbget(capdbp, bp, name) - DB *capdbp; - char **bp, *name; -{ - DBT key, data; - - key.data = name; - key.size = strlen(name); - - for (;;) { - /* Get the reference. */ - switch(capdbp->get(capdbp, &key, &data, 0)) { - case -1: - return (-2); - case 1: - return (-1); - } - - /* If not an index to another record, leave. */ - if (((char *)data.data)[0] != SHADOW) - break; - - key.data = (char *)data.data + 1; - key.size = data.size - 1; - } - - *bp = (char *)data.data + 1; - return (((char *)(data.data))[0] == TCERR ? 1 : 0); -} - -/* - * Cgetmatch will return 0 if name is one of the names of the capability - * record buf, -1 if not. - */ -int -cgetmatch(buf, name) - char *buf, *name; -{ - register char *np, *bp; - - /* - * Start search at beginning of record. - */ - bp = buf; - for (;;) { - /* - * Try to match a record name. - */ - np = name; - for (;;) - if (*np == '\0') - if (*bp == '|' || *bp == ':' || *bp == '\0') - return (0); - else - break; - else - if (*bp++ != *np++) - break; - - /* - * Match failed, skip to next name in record. - */ - bp--; /* a '|' or ':' may have stopped the match */ - for (;;) - if (*bp == '\0' || *bp == ':') - return (-1); /* match failed totally */ - else - if (*bp++ == '|') - break; /* found next name */ - } -} - - - - - -int -cgetfirst(buf, db_array) - char **buf, **db_array; -{ - (void)cgetclose(); - return (cgetnext(buf, db_array)); -} - -static FILE *pfp; -static int slash; -static char **dbp; - -int -cgetclose() -{ - if (pfp != NULL) { - (void)fclose(pfp); - pfp = NULL; - } - dbp = NULL; - gottoprec = 0; - slash = 0; - return(0); -} - -/* - * Cgetnext() gets either the first or next entry in the logical database - * specified by db_array. It returns 0 upon completion of the database, 1 - * upon returning an entry with more remaining, and -1 if an error occurs. - */ -int -cgetnext(bp, db_array) - register char **bp; - char **db_array; -{ - size_t len; - int status, done; - char *cp, *line, *rp, *np, buf[BSIZE], nbuf[BSIZE]; - u_int dummy; - - if (dbp == NULL) - dbp = db_array; - - if (pfp == NULL && (pfp = fopen(*dbp, "r")) == NULL) { - (void)cgetclose(); - return (-1); - } - for(;;) { - if (toprec && !gottoprec) { - gottoprec = 1; - line = toprec; - } else { - line = fgetln(pfp, &len); - if (line == NULL && pfp) { - (void)fclose(pfp); - if (ferror(pfp)) { - (void)cgetclose(); - return (-1); - } else { - if (*++dbp == NULL) { - (void)cgetclose(); - return (0); - } else if ((pfp = - fopen(*dbp, "r")) == NULL) { - (void)cgetclose(); - return (-1); - } else - continue; - } - } else - line[len - 1] = '\0'; - if (len == 1) { - slash = 0; - continue; - } - if (isspace(*line) || - *line == ':' || *line == '#' || slash) { - if (line[len - 2] == '\\') - slash = 1; - else - slash = 0; - continue; - } - if (line[len - 2] == '\\') - slash = 1; - else - slash = 0; - } - - - /* - * Line points to a name line. - */ - done = 0; - np = nbuf; - for (;;) { - for (cp = line; *cp != '\0'; cp++) { - if (*cp == ':') { - *np++ = ':'; - done = 1; - break; - } - if (*cp == '\\') - break; - *np++ = *cp; - } - if (done) { - *np = '\0'; - break; - } else { /* name field extends beyond the line */ - line = fgetln(pfp, &len); - if (line == NULL && pfp) { - (void)fclose(pfp); - if (ferror(pfp)) { - (void)cgetclose(); - return (-1); - } - } else - line[len - 1] = '\0'; - } - } - rp = buf; - for(cp = nbuf; *cp != NULL; cp++) - if (*cp == '|' || *cp == ':') - break; - else - *rp++ = *cp; - - *rp = '\0'; - /* - * XXX - * Last argument of getent here should be nbuf if we want true - * sequential access in the case of duplicates. - * With NULL, getent will return the first entry found - * 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); - if (status == -2 || status == -3) - (void)cgetclose(); - - return (status + 1); - } - /* NOTREACHED */ -} - -/* - * Cgetstr retrieves the value of the string capability cap from the - * capability record pointed to by buf. A pointer to a decoded, NUL - * terminated, malloc'd copy of the string is returned in the char * - * pointed to by str. The length of the string not including the trailing - * NUL is returned on success, -1 if the requested string capability - * couldn't be found, -2 if a system error was encountered (storage - * allocation failure). - */ -int -cgetstr(buf, cap, str) - char *buf, *cap; - char **str; -{ - register u_int m_room; - register char *bp, *mp; - int len; - char *mem; - - /* - * Find string capability cap - */ - bp = cgetcap(buf, cap, '='); - if (bp == NULL) - return (-1); - - /* - * Conversion / storage allocation loop ... Allocate memory in - * chunks SFRAG in size. - */ - if ((mem = malloc(SFRAG)) == NULL) { - errno = ENOMEM; - return (-2); /* couldn't even allocate the first fragment */ - } - m_room = SFRAG; - mp = mem; - - while (*bp != ':' && *bp != '\0') { - /* - * Loop invariants: - * There is always room for one more character in mem. - * Mp always points just past last character in mem. - * Bp always points at next character in buf. - */ - if (*bp == '^') { - bp++; - if (*bp == ':' || *bp == '\0') - break; /* drop unfinished escape */ - *mp++ = *bp++ & 037; - } else if (*bp == '\\') { - bp++; - if (*bp == ':' || *bp == '\0') - break; /* drop unfinished escape */ - if ('0' <= *bp && *bp <= '7') { - register int n, i; - - n = 0; - i = 3; /* maximum of three octal digits */ - do { - n = n * 8 + (*bp++ - '0'); - } while (--i && '0' <= *bp && *bp <= '7'); - *mp++ = n; - } - else switch (*bp++) { - case 'b': case 'B': - *mp++ = '\b'; - break; - case 't': case 'T': - *mp++ = '\t'; - break; - case 'n': case 'N': - *mp++ = '\n'; - break; - case 'f': case 'F': - *mp++ = '\f'; - break; - case 'r': case 'R': - *mp++ = '\r'; - break; - case 'e': case 'E': - *mp++ = ESC; - break; - case 'c': case 'C': - *mp++ = ':'; - break; - default: - /* - * Catches '\', '^', and - * everything else. - */ - *mp++ = *(bp-1); - break; - } - } else - *mp++ = *bp++; - m_room--; - - /* - * Enforce loop invariant: if no room left in current - * buffer, try to get some more. - */ - if (m_room == 0) { - size_t size = mp - mem; - - if ((mem = realloc(mem, size + SFRAG)) == NULL) - return (-2); - m_room = SFRAG; - mp = mem + size; - } - } - *mp++ = '\0'; /* loop invariant let's us do this */ - m_room--; - len = mp - mem - 1; - - /* - * Give back any extra memory and return value and success. - */ - if (m_room != 0) - if ((mem = realloc(mem, (size_t)(mp - mem))) == NULL) - return (-2); - *str = mem; - return (len); -} - -/* - * Cgetustr retrieves the value of the string capability cap from the - * capability record pointed to by buf. The difference between cgetustr() - * and cgetstr() is that cgetustr does not decode escapes but rather treats - * all characters literally. A pointer to a NUL terminated malloc'd - * copy of the string is returned in the char pointed to by str. The - * length of the string not including the trailing NUL is returned on success, - * -1 if the requested string capability couldn't be found, -2 if a system - * error was encountered (storage allocation failure). - */ -int -cgetustr(buf, cap, str) - char *buf, *cap, **str; -{ - register u_int m_room; - register char *bp, *mp; - int len; - char *mem; - - /* - * Find string capability cap - */ - if ((bp = cgetcap(buf, cap, '=')) == NULL) - return (-1); - - /* - * Conversion / storage allocation loop ... Allocate memory in - * chunks SFRAG in size. - */ - if ((mem = malloc(SFRAG)) == NULL) { - errno = ENOMEM; - return (-2); /* couldn't even allocate the first fragment */ - } - m_room = SFRAG; - mp = mem; - - while (*bp != ':' && *bp != '\0') { - /* - * Loop invariants: - * There is always room for one more character in mem. - * Mp always points just past last character in mem. - * Bp always points at next character in buf. - */ - *mp++ = *bp++; - m_room--; - - /* - * Enforce loop invariant: if no room left in current - * buffer, try to get some more. - */ - if (m_room == 0) { - size_t size = mp - mem; - - if ((mem = realloc(mem, size + SFRAG)) == NULL) - return (-2); - m_room = SFRAG; - mp = mem + size; - } - } - *mp++ = '\0'; /* loop invariant let's us do this */ - m_room--; - len = mp - mem - 1; - - /* - * Give back any extra memory and return value and success. - */ - if (m_room != 0) - if ((mem = realloc(mem, (size_t)(mp - mem))) == NULL) - return (-2); - *str = mem; - return (len); -} - -/* - * Cgetnum retrieves the value of the numeric capability cap from the - * capability record pointed to by buf. The numeric value is returned in - * the long pointed to by num. 0 is returned on success, -1 if the requested - * numeric capability couldn't be found. - */ -int -cgetnum(buf, cap, num) - char *buf, *cap; - long *num; -{ - register long n; - register int base, digit; - register char *bp; - - /* - * Find numeric capability cap - */ - bp = cgetcap(buf, cap, '#'); - if (bp == NULL) - return (-1); - - /* - * Look at value and determine numeric base: - * 0x... or 0X... hexadecimal, - * else 0... octal, - * else decimal. - */ - if (*bp == '0') { - bp++; - if (*bp == 'x' || *bp == 'X') { - bp++; - base = 16; - } else - base = 8; - } else - base = 10; - - /* - * Conversion loop ... - */ - n = 0; - for (;;) { - if ('0' <= *bp && *bp <= '9') - digit = *bp - '0'; - else if ('a' <= *bp && *bp <= 'f') - digit = 10 + *bp - 'a'; - else if ('A' <= *bp && *bp <= 'F') - digit = 10 + *bp - 'A'; - else - break; - - if (digit >= base) - break; - - n = n * base + digit; - bp++; - } - - /* - * Return value and success. - */ - *num = n; - return (0); -} - - -/* - * Compare name field of record. - */ -static int -nfcmp(nf, rec) - char *nf, *rec; -{ - char *cp, tmp; - int ret; - - for (cp = rec; *cp != ':'; cp++) - ; - - tmp = *(cp + 1); - *(cp + 1) = '\0'; - ret = strcmp(nf, rec); - *(cp + 1) = tmp; - - return (ret); -} diff --git a/gen.subproj/getcwd.c b/gen.subproj/getcwd.c deleted file mode 100644 index 0c71e79..0000000 --- a/gen.subproj/getcwd.c +++ /dev/null @@ -1,410 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1989, 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. - */ - - -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -static char *getcwd_physical __P((char *, size_t)); - -#define ISDOT(dp) \ - (dp->d_name[0] == '.' && (dp->d_name[1] == '\0' || \ - dp->d_name[1] == '.' && dp->d_name[2] == '\0')) - -char * -getcwd(pt, size) - char *pt; - size_t size; -{ - char *pwd; - size_t pwdlen; - dev_t dev; - ino_t ino; - struct stat s; - - /* Check $PWD -- if it's right, it's fast. */ - if ((pwd = getenv("PWD")) != NULL && pwd[0] == '/' && stat(pwd, &s) != -1) { - dev = s.st_dev; - ino = s.st_ino; - if (stat(".", &s) != -1 && dev == s.st_dev && ino == s.st_ino) { - pwdlen = strlen(pwd); - if (pt) { - if (!size) { - errno = EINVAL; - return (NULL); - } - if (pwdlen + 1 > size) { - errno = ERANGE; - return (NULL); - } - } else if ((pt = malloc(pwdlen + 1)) == NULL) { - errno = ENOMEM; - return (NULL); - } - memmove(pt, pwd, pwdlen); - pt[pwdlen] = '\0'; - return (pt); - } - } - - return (getcwd_physical(pt, size)); -} - -/* - * char *realpath(const char *path, char resolved_path[MAXPATHLEN]); - * - * Find the real name of path, by removing all ".", ".." and symlink - * components. Returns (resolved) on success, or (NULL) on failure, - * in which case the path which caused trouble is left in (resolved). - */ -char * -realpath(path, resolved) - const char *path; - char *resolved; -{ - struct stat sb; - int fd, n, rootd, serrno; - char *p, *q, wbuf[MAXPATHLEN]; - int symlinks = 0; - - /* Save the starting point. */ - if ((fd = open(".", O_RDONLY)) < 0) { - (void)strcpy(resolved, "."); - return (NULL); - } - - /* - * Find the dirname and basename from the path to be resolved. - * Change directory to the dirname component. - * lstat the basename part. - * if it is a symlink, read in the value and loop. - * if it is a directory, then change to that directory. - * get the current directory name and append the basename. - */ - (void)strncpy(resolved, path, MAXPATHLEN - 1); - resolved[MAXPATHLEN - 1] = '\0'; -loop: - q = strrchr(resolved, '/'); - if (q != NULL) { - p = q + 1; - if (q == resolved) - q = "/"; - else { - do { - --q; - } while (q > resolved && *q == '/'); - q[1] = '\0'; - q = resolved; - } - if (chdir(q) < 0) - goto err1; - } else - p = resolved; - - /* Deal with the last component. */ - if (lstat(p, &sb) == 0) { - if (S_ISLNK(sb.st_mode)) { - if (++symlinks > MAXSYMLINKS) { - errno = ELOOP; - goto err1; - } - n = readlink(p, resolved, MAXPATHLEN-1); - if (n < 0) - goto err1; - resolved[n] = '\0'; - goto loop; - } - if (S_ISDIR(sb.st_mode)) { - if (chdir(p) < 0) - goto err1; - p = ""; - } - } - - /* - * Save the last component name and get the full pathname of - * the current directory. - */ - (void)strcpy(wbuf, p); - - /* - * Call the inernal internal version of getcwd which - * does a physical search rather than using the $PWD short-cut - */ - if (getcwd_physical(resolved, MAXPATHLEN) == 0) - goto err1; - - /* - * Join the two strings together, ensuring that the right thing - * happens if the last component is empty, or the dirname is root. - */ - if (resolved[0] == '/' && resolved[1] == '\0') - rootd = 1; - else - rootd = 0; - - if (*wbuf) { - if (strlen(resolved) + strlen(wbuf) + rootd + 1 > MAXPATHLEN) { - errno = ENAMETOOLONG; - goto err1; - } - if (rootd == 0) - (void)strcat(resolved, "/"); - (void)strcat(resolved, wbuf); - } - - /* Go back to where we came from. */ - if (fchdir(fd) < 0) { - serrno = errno; - goto err2; - } - - /* It's okay if the close fails, what's an fd more or less? */ - (void)close(fd); - return (resolved); - -err1: serrno = errno; - (void)fchdir(fd); -err2: (void)close(fd); - errno = serrno; - return (NULL); -} - -static char * -getcwd_physical(pt, size) - char *pt; - size_t size; -{ - register struct dirent *dp; - register DIR *dir; - register dev_t dev; - register ino_t ino; - register int first; - register char *bpt, *bup; - struct stat s; - dev_t root_dev; - ino_t root_ino; - size_t ptsize, upsize; - int save_errno; - char *ept, *eup, *up; - - /* - * If no buffer specified by the user, allocate one as necessary. - * If a buffer is specified, the size has to be non-zero. The path - * is built from the end of the buffer backwards. - */ - if (pt) { - ptsize = 0; - if (!size) { - errno = EINVAL; - return (NULL); - } - ept = pt + size; - } else { - if ((pt = malloc(ptsize = 1024 - 4)) == NULL) - return (NULL); - ept = pt + ptsize; - } - bpt = ept - 1; - *bpt = '\0'; - - /* - * Allocate bytes (1024 - malloc space) for the string of "../"'s. - * Should always be enough (it's 340 levels). If it's not, allocate - * as necessary. Special case the first stat, it's ".", not "..". - */ - if ((up = malloc(upsize = 1024 - 4)) == NULL) - goto err; - eup = up + MAXPATHLEN; - bup = up; - up[0] = '.'; - up[1] = '\0'; - - /* Save root values, so know when to stop. */ - if (stat("/", &s)) - goto err; - root_dev = s.st_dev; - root_ino = s.st_ino; - - errno = 0; /* XXX readdir has no error return. */ - - for (first = 1;; first = 0) { - /* Stat the current level. */ - if (lstat(up, &s)) - goto err; - - /* Save current node values. */ - ino = s.st_ino; - dev = s.st_dev; - - /* Check for reaching root. */ - if (root_dev == dev && root_ino == ino) { - *--bpt = '/'; - /* - * It's unclear that it's a requirement to copy the - * path to the beginning of the buffer, but it's always - * been that way and stuff would probably break. - */ - (void)bcopy(bpt, pt, ept - bpt); - free(up); - return (pt); - } - - /* - * Build pointer to the parent directory, allocating memory - * as necessary. Max length is 3 for "../", the largest - * possible component name, plus a trailing NULL. - */ - if (bup + 3 + MAXNAMLEN + 1 >= eup) { - if ((up = realloc(up, upsize *= 2)) == NULL) - goto err; - bup = up; - eup = up + upsize; - } - *bup++ = '.'; - *bup++ = '.'; - *bup = '\0'; - - /* Open and stat parent directory. */ - if (!(dir = opendir(up)) || fstat(dirfd(dir), &s)) - goto err; - - /* Add trailing slash for next directory. */ - *bup++ = '/'; - - /* - * If it's a mount point, have to stat each element because - * the inode number in the directory is for the entry in the - * parent directory, not the inode number of the mounted file. - */ - save_errno = 0; - if (s.st_dev == dev) { - for (;;) { - if (!(dp = readdir(dir))) - goto notfound; - if (dp->d_fileno == ino) - break; - } - } else - for (;;) { - if (!(dp = readdir(dir))) - goto notfound; - if (ISDOT(dp)) - continue; - bcopy(dp->d_name, bup, dp->d_namlen + 1); - - /* Save the first error for later. */ - if (lstat(up, &s)) { - if (!save_errno) - save_errno = errno; - errno = 0; - continue; - } - if (s.st_dev == dev && s.st_ino == ino) - break; - } - - /* - * Check for length of the current name, preceding slash, - * leading slash. - */ - if (bpt - pt <= dp->d_namlen + (first ? 1 : 2)) { - size_t len, off; - - if (!ptsize) { - errno = ERANGE; - goto err; - } - off = bpt - pt; - len = ept - bpt; - if ((pt = realloc(pt, ptsize *= 2)) == NULL) - goto err; - bpt = pt + off; - ept = pt + ptsize; - (void)bcopy(bpt, ept - len, len); - bpt = ept - len; - } - if (!first) - *--bpt = '/'; - bpt -= dp->d_namlen; - bcopy(dp->d_name, bpt, dp->d_namlen); - (void)closedir(dir); - - /* Truncate any file name. */ - *bup = '\0'; - } - -notfound: - /* - * If readdir set errno, use it, not any saved error; otherwise, - * didn't find the current directory in its parent directory, set - * errno to ENOENT. - */ - if (!errno) - errno = save_errno ? save_errno : ENOENT; - /* FALLTHROUGH */ -err: - if (ptsize) - free(pt); - free(up); - return (NULL); -} diff --git a/gen.subproj/gethostname.c b/gen.subproj/gethostname.c deleted file mode 100644 index 50ce9b5..0000000 --- a/gen.subproj/gethostname.c +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1989, 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 -#include - - -long -gethostname(name, namelen) - char *name; - int namelen; -{ - int mib[2]; - size_t size; - - mib[0] = CTL_KERN; - mib[1] = KERN_HOSTNAME; - size = namelen; - if (sysctl(mib, 2, name, &size, NULL, 0) == -1) - return (-1); - return (0); -} diff --git a/gen.subproj/getloadavg.c b/gen.subproj/getloadavg.c deleted file mode 100644 index e65fdff..0000000 --- a/gen.subproj/getloadavg.c +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1989, 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 -#include -#include -#include - -#if 0 -#include -#endif /* 0 */ - -#include - -/* - * getloadavg() -- Get system load averages. - * - * Put `nelem' samples into `loadavg' array. - * Return number of samples retrieved, or -1 on error. - */ -int -getloadavg(loadavg, nelem) - double loadavg[]; - int nelem; -{ - struct loadavg loadinfo; - int i, mib[2]; - size_t size; - - mib[0] = CTL_VM; - mib[1] = VM_LOADAVG; - size = sizeof(loadinfo); - if (sysctl(mib, 2, &loadinfo, &size, NULL, 0) < 0) - return (-1); - - nelem = MIN(nelem, sizeof(loadinfo.ldavg) / sizeof(fixpt_t)); - for (i = 0; i < nelem; i++) - loadavg[i] = (double) loadinfo.ldavg[i] / loadinfo.fscale; - return (nelem); -} diff --git a/gen.subproj/getlogin.c b/gen.subproj/getlogin.c deleted file mode 100644 index 02563a6..0000000 --- a/gen.subproj/getlogin.c +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1988, 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 -#include -#include -#include -#include -#include - -int _logname_valid = 0; /* known to setlogin() */ - -char * -getlogin() -{ - static char logname[MAXLOGNAME + 1]; - - if (_logname_valid == 0) { - if (_getlogin(logname, sizeof(logname) - 1) < 0) - return ((char *)NULL); - _logname_valid = 1; - } - return (*logname ? logname : (char *)NULL); -} diff --git a/gen.subproj/getmntinfo.c b/gen.subproj/getmntinfo.c deleted file mode 100644 index 9284aa7..0000000 --- a/gen.subproj/getmntinfo.c +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1989, 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 -#include -#include -#include - -/* - * Return information about mounted filesystems. - */ -int -getmntinfo(mntbufp, flags) - struct statfs **mntbufp; - int flags; -{ - static struct statfs *mntbuf; - static int mntsize; - static long bufsize; - - if (mntsize <= 0 && (mntsize = getfsstat(0, 0, MNT_NOWAIT)) < 0) - return (0); - if (bufsize > 0 && (mntsize = getfsstat(mntbuf, bufsize, flags)) < 0) - return (0); - while (bufsize <= mntsize * sizeof(struct statfs)) { - if (mntbuf) - free(mntbuf); - bufsize = (mntsize + 1) * sizeof(struct statfs); - if ((mntbuf = (struct statfs *)malloc(bufsize)) == 0) - return (0); - if ((mntsize = getfsstat(mntbuf, bufsize, flags)) < 0) - return (0); - } - *mntbufp = mntbuf; - return (mntsize); -} diff --git a/gen.subproj/getpagesize.c b/gen.subproj/getpagesize.c deleted file mode 100644 index c10d072..0000000 --- a/gen.subproj/getpagesize.c +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1989, 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 -#include - -int -getpagesize() -{ - int mib[2], value; - size_t size; - - mib[0] = CTL_HW; - mib[1] = HW_PAGESIZE; - size = sizeof value; - if (sysctl(mib, 2, &value, &size, NULL, 0) == -1) - return (-1); - return (value); -} - diff --git a/gen.subproj/getpass.c b/gen.subproj/getpass.c deleted file mode 100644 index a09ca80..0000000 --- a/gen.subproj/getpass.c +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1988, 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 -#include - -#include -#include -#include -#include - -char * -getpass(prompt) - const char *prompt; -{ - struct termios term; - register int ch; - register char *p; - FILE *fp, *outfp; - long omask; - int echo; - static char buf[_PASSWORD_LEN + 1]; - - /* - * read and write to /dev/tty if possible; else read from - * stdin and write to stderr. - */ - if ((outfp = fp = fopen(_PATH_TTY, "w+")) == NULL) { - outfp = stderr; - fp = stdin; - } - /* - * note - blocking signals isn't necessarily the - * right thing, but we leave it for now. - */ - omask = sigblock(sigmask(SIGINT)|sigmask(SIGTSTP)); - (void)tcgetattr(fileno(fp), &term); - if (echo = (term.c_lflag & ECHO)) { - term.c_lflag &= ~ECHO; - (void)tcsetattr(fileno(fp), TCSAFLUSH|TCSASOFT, &term); - } - (void)fputs(prompt, outfp); - rewind(outfp); /* implied flush */ - for (p = buf; (ch = getc(fp)) != EOF && ch != '\n';) - if (p < buf + _PASSWORD_LEN) - *p++ = ch; - *p = '\0'; - (void)write(fileno(outfp), "\n", 1); - if (echo) { - term.c_lflag |= ECHO; - (void)tcsetattr(fileno(fp), TCSAFLUSH|TCSASOFT, &term); - } - (void)sigsetmask(omask); - if (fp != stdin) - (void)fclose(fp); - return(buf); -} diff --git a/gen.subproj/getttyent.c b/gen.subproj/getttyent.c deleted file mode 100644 index f033908..0000000 --- a/gen.subproj/getttyent.c +++ /dev/null @@ -1,223 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1989, 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 -#include -#include -#include - -static char zapchar; -static FILE *tf; - -struct ttyent * -getttynam(tty) - const char *tty; -{ - register struct ttyent *t; - - setttyent(); - while (t = getttyent()) - if (!strcmp(tty, t->ty_name)) - break; - endttyent(); - return (t); -} - -struct ttyent * -getttyent() -{ - static struct ttyent tty; - register int c; - register char *p; -#define MAXLINELENGTH 1024 - static char line[MAXLINELENGTH]; - static char *skip(), *value(); - - if (!tf && !setttyent()) - return (NULL); - for (;;) { - if (!fgets(p = line, sizeof(line), tf)) - return (NULL); - /* skip lines that are too big */ - if (!index(p, '\n')) { - while ((c = getc(tf)) != '\n' && c != EOF) - ; - continue; - } - while (isspace(*p)) - ++p; - if (*p && *p != '#') - break; - } - - zapchar = 0; - tty.ty_name = p; - p = skip(p); - if (!*(tty.ty_getty = p)) - tty.ty_getty = tty.ty_type = NULL; - else { - p = skip(p); - if (!*(tty.ty_type = p)) - tty.ty_type = NULL; - else - p = skip(p); - } - tty.ty_status = 0; - tty.ty_window = NULL; - tty.ty_onerror = NULL; - tty.ty_onoption = NULL; - -#define scmp(e) !strncmp(p, e, sizeof(e) - 1) && isspace(p[sizeof(e) - 1]) -#define vcmp(e) !strncmp(p, e, sizeof(e) - 1) && p[sizeof(e) - 1] == '=' - for (; *p; p = skip(p)) { - if (scmp(_TTYS_OFF)) - tty.ty_status &= ~TTY_ON; - else if (scmp(_TTYS_ON)) - tty.ty_status |= TTY_ON; - else if (scmp(_TTYS_SECURE)) - tty.ty_status |= TTY_SECURE; - else if (vcmp(_TTYS_WINDOW)) - tty.ty_window = value(p); - else if (vcmp(_TTYS_ONERROR)) - tty.ty_onerror = value(p); - else if (vcmp(_TTYS_ONOPTION)) - tty.ty_onoption = value(p); - else - break; - } - - if (zapchar == '#' || *p == '#') - while ((c = *++p) == ' ' || c == '\t') - ; - tty.ty_comment = p; - if (*p == 0) - tty.ty_comment = 0; - if (p = index(p, '\n')) - *p = '\0'; - return (&tty); -} - -#define QUOTED 1 - -/* - * Skip over the current field, removing quotes, and return a pointer to - * the next field. - */ -static char * -skip(p) - register char *p; -{ - register char *t; - register int c, q; - - for (q = 0, t = p; (c = *p) != '\0'; p++) { - if (c == '"') { - q ^= QUOTED; /* obscure, but nice */ - continue; - } - if (q == QUOTED && *p == '\\' && *(p+1) == '"') - p++; - *t++ = *p; - if (q == QUOTED) - continue; - if (c == '#') { - zapchar = c; - *p = 0; - break; - } - if (c == '\t' || c == ' ' || c == '\n') { - zapchar = c; - *p++ = 0; - while ((c = *p) == '\t' || c == ' ' || c == '\n') - p++; - break; - } - } - *--t = '\0'; - return (p); -} - -static char * -value(p) - register char *p; -{ - - return ((p = index(p, '=')) ? ++p : NULL); -} - -int -setttyent() -{ - - if (tf) { - (void)rewind(tf); - return (1); - } else if (tf = fopen(_PATH_TTYS, "r")) - return (1); - return (0); -} - -int -endttyent() -{ - int rval; - - if (tf) { - rval = !(fclose(tf) == EOF); - tf = NULL; - return (rval); - } - return (1); -} diff --git a/gen.subproj/getusershell.c b/gen.subproj/getusershell.c deleted file mode 100644 index 5a5f09a..0000000 --- a/gen.subproj/getusershell.c +++ /dev/null @@ -1,155 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1985, 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 -#include -#include -#include -#include -#include -#include -#include - -/* - * Local shells should NOT be added here. They should be added in - * /etc/shells. - */ - -static char *okshells[] = { _PATH_BSHELL, _PATH_CSHELL, NULL }; -static char **curshell, **shells, *strings; -static char **initshells __P((void)); - -/* - * Get a list of shells from _PATH_SHELLS, if it exists. - */ -char * -getusershell() -{ - char *ret; - - if (curshell == NULL) - curshell = initshells(); - ret = *curshell; - if (ret != NULL) - curshell++; - return (ret); -} - -void -endusershell() -{ - - if (shells != NULL) - free(shells); - shells = NULL; - if (strings != NULL) - free(strings); - strings = NULL; - curshell = NULL; -} - -void -setusershell() -{ - - curshell = initshells(); -} - -static char ** -initshells() -{ - register char **sp, *cp; - register FILE *fp; - struct stat statb; - - if (shells != NULL) - free(shells); - shells = NULL; - if (strings != NULL) - free(strings); - strings = NULL; - if ((fp = fopen(_PATH_SHELLS, "r")) == NULL) - return (okshells); - if (fstat(fileno(fp), &statb) == -1) { - (void)fclose(fp); - return (okshells); - } - if ((strings = malloc((u_int)statb.st_size)) == NULL) { - (void)fclose(fp); - return (okshells); - } - shells = calloc((unsigned)statb.st_size / 3, sizeof (char *)); - if (shells == NULL) { - (void)fclose(fp); - free(strings); - strings = NULL; - return (okshells); - } - sp = shells; - cp = strings; - while (fgets(cp, MAXPATHLEN + 1, fp) != NULL) { - while (*cp != '#' && *cp != '/' && *cp != '\0') - cp++; - if (*cp == '#' || *cp == '\0') - continue; - *sp++ = cp; - while (!isspace(*cp) && *cp != '#' && *cp != '\0') - cp++; - *cp++ = '\0'; - } - *sp = NULL; - (void)fclose(fp); - return (shells); -} diff --git a/gen.subproj/getvfsbyname.c b/gen.subproj/getvfsbyname.c deleted file mode 100644 index 2e1af68..0000000 --- a/gen.subproj/getvfsbyname.c +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 - * 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 -#include -#include -#include -#include - -int getvfsbyname __P((const char *, struct vfsconf *)); - -/* - * Given a filesystem name, determine if it is resident in the kernel, - * and if it is resident, return its vfsconf structure. - */ -getvfsbyname(fsname, vfcp) - const char *fsname; - struct vfsconf *vfcp; -{ - int name[4], maxtypenum, cnt; - size_t buflen; - - name[0] = CTL_VFS; - name[1] = VFS_GENERIC; - name[2] = VFS_MAXTYPENUM; - buflen = 4; - if (sysctl(name, 3, &maxtypenum, &buflen, (void *)0, (size_t)0) < 0) - return (-1); - name[2] = VFS_CONF; - buflen = sizeof *vfcp; - for (cnt = 0; cnt < maxtypenum; cnt++) { - name[3] = cnt; - if (sysctl(name, 4, vfcp, &buflen, (void *)0, (size_t)0) < 0) { - if (errno != EOPNOTSUPP) - return (-1); - continue; - } - if (!strcmp(fsname, vfcp->vfc_name)) - return (0); - } - errno = ENOENT; - return (-1); -} diff --git a/gen.subproj/gmon.c b/gen.subproj/gmon.c deleted file mode 100644 index 8872c02..0000000 --- a/gen.subproj/gmon.c +++ /dev/null @@ -1,758 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#if defined(PROFILE) -#error This module cannot be compiled with profiling -#endif - -/*- - * Copyright (c) 1983, 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. - */ -/* - * History - * 2-Mar-90 Gregg Kellogg (gk) at NeXT - * Changed include of kern/mach.h to kern/mach_interface.h - * - * 1-May-90 Matthew Self (mself) at NeXT - * Added prototypes, and added casts to remove all warnings. - * Made all private data static. - * vm_deallocate old data defore vm_allocate'ing new data. - * Added new functions monoutput and monreset. - * - * 18-Dec-92 Development Environment Group at NeXT - * Added multiple profile areas, the ability to profile shlibs and the - * ability to profile rld loaded code. Moved the machine dependent mcount - * routine out of this source file. - * - * 13-Dec-92 Development Environment Group at NeXT - * Added support for dynamic shared libraries. Also removed the code that - * had been ifdef'ed out for profiling fixed shared libraries and - * objective-C. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)gmon.c 5.2 (Berkeley) 6/21/85"; -#endif - -/* - * see profil(2) where this (SCALE_1_TO_1) is describe (incorrectly). - * - * The correct description: scale is a fixed point value with - * the binary point in the middle of the 32 bit value. (Bit 16 is - * 1, bit 15 is .5, etc.) - * - * Setting the scale to "1" (i.e. 0x10000), results in the kernel - * choosing the profile bucket address 1 to 1 with the pc sampled. - * Since buckets are shorts, if the profiling base were 0, then a pc - * of 0 increments bucket 0, a pc of 2 increments bucket 1, and a pc - * of 4 increments bucket 2.) (Actually, this seems a little bogus, - * 1 to 1 should map pc's to buckets -- that's probably what was - * intended from the man page, but historically.... - */ -#define SCALE_1_TO_1 0x10000L - -#define MSG "No space for monitor buffer(s)\n" - -#include -#include -extern const struct section *getsectbyname( - const char *segname, - const char *sectname); -#include -#include -#include -#include -#include -#include -#include -#include - -/* - * These are defined in here and these declarations need to be moved to libc.h - * where the other declarations for the monitor(3) routines are declared. - */ -extern void moninit( - void); -extern void monaddition( - char *lowpc, - char *highpc); -extern void moncount( - char *frompc, - char *selfpc); -extern void monreset( - 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 */ - -static unsigned long order = 0; /* call order */ - -struct mon_t { - /* the address range and size this mon struct refers to */ - char *lowpc; - char *highpc; - unsigned long textsize; - /* the data structures to support the arc's and their counts */ - unsigned short *froms; /* froms is unsigned shorts indexing into tos */ - struct tostruct *tos; - long tolimit; - /* the pc-sample buffer, it's size and scale */ - char *sbuf; - int ssiz; /* includes the gmonhdr struct */ - int scale; -}; -static struct mon_t *mon = NULL; -static unsigned long nmon = 0; - -static void monsetup( - struct mon_t *m, - char *lowpc, - char *highpc); -static int getprofhz( - void); - -void -moninit( -void) -{ - const struct section *section; - char *lowpc, *highpc; - unsigned long i; - - monreset(); - init = 1; - - section = getsectbyname ("__TEXT", "__text"); - lowpc = (char *)section->addr, - highpc = (char *)(section->addr + section->size); - - if(mon == NULL){ - if((mon = malloc(sizeof(struct mon_t))) == NULL){ - write(2, MSG, sizeof(MSG) - 1); - return; - } - nmon = 1; - memset(mon, '\0', sizeof(struct mon_t)); - } - /* - * To continue to make monstartup() and the functions that existed - * before adding multiple profiling areas working correctly the new - * calls to get the dyld loaded code profiled are made after - * the first mon_t struct is allocated so that they will not use the - * first mon_t and the old calls will always use the first mon_t struct - * in the list. - */ - monsetup(mon, lowpc, highpc); - - profil(mon->sbuf + sizeof(struct gmonhdr), - mon->ssiz - sizeof(struct gmonhdr), - (int)mon->lowpc, mon->scale); - for(i = 1; i < nmon; i++) - add_profil(mon[i].sbuf + sizeof(struct gmonhdr), - mon[i].ssiz - sizeof(struct gmonhdr), - (int)mon[i].lowpc, mon[i].scale); - init = 0; - profiling = 0; - -#if defined(__DYNAMIC__) - /* - * Call _dyld_moninit() if the dyld is present. This is done after the - * above calls so the dynamic libraries will be added after the - * executable. - */ - if(_dyld_present()) - _dyld_moninit(monaddition); -#endif -} - -void -monstartup( -char *lowpc, -char *highpc) -{ - monreset(); - if(mon == NULL){ - if((mon = malloc(sizeof(struct mon_t))) == NULL){ - write(2, MSG, sizeof(MSG) - 1); - return; - } - nmon = 1; - memset(mon, '\0', sizeof(struct mon_t)); - } - monsetup(mon, lowpc, highpc); -} - -/* - * monaddtion() is used for adding additional pc ranges to profile. This is - * used for profiling dyld loaded code. - */ -void -monaddition( -char *lowpc, -char *highpc) -{ - char save_profiling; - struct mon_t *m; - - if(mon == NULL){ - monstartup(lowpc, highpc); - return; - } - save_profiling = profiling; - profiling = -1; - if((mon = realloc(mon, (nmon + 1) * sizeof(struct mon_t))) == NULL){ - write(2, MSG, sizeof(MSG) - 1); - return; - } - m = mon + nmon; - memset(m, '\0', sizeof(struct mon_t)); - nmon++; - monsetup(m, lowpc, highpc); - profiling = save_profiling; -} - -static -void -monsetup( -struct mon_t *m, -char *lowpc, -char *highpc) -{ - int monsize; - char *buffer; - kern_return_t ret; - struct gmonhdr *p; - unsigned int o; - - /* - * round lowpc and highpc to multiples of the density we're using - * so the rest of the scaling (here and in gprof) stays in ints. - */ - lowpc = (char *)ROUNDDOWN((unsigned)lowpc, - HISTFRACTION * sizeof(HISTCOUNTER)); - m->lowpc = lowpc; - highpc = (char *)ROUNDUP((unsigned)highpc, - HISTFRACTION * sizeof(HISTCOUNTER)); - m->highpc = highpc; - - if(m->froms) - vm_deallocate(mach_task_self(), - (vm_address_t)m->froms, - (vm_size_t)(m->textsize / HASHFRACTION)); - m->textsize = highpc - lowpc; - ret = vm_allocate(mach_task_self(), - (vm_address_t *)&m->froms, - (vm_size_t)(m->textsize / HASHFRACTION), - TRUE); - if(ret != KERN_SUCCESS){ - write(2, MSG, sizeof(MSG) - 1); - m->froms = 0; - return; - } - - if(m->sbuf) - vm_deallocate(mach_task_self(), - (vm_address_t)m->sbuf, - (vm_size_t)m->ssiz); - monsize = (m->textsize / HISTFRACTION) + sizeof(struct gmonhdr); - ret = vm_allocate(mach_task_self(), - (vm_address_t *)&buffer, - (vm_size_t)monsize, - TRUE); - if(ret != KERN_SUCCESS){ - write(2, MSG, sizeof(MSG) - 1); - m->sbuf = 0; - return; - } - - if(m->tos) - vm_deallocate(mach_task_self(), - (vm_address_t)m->tos, - (vm_size_t)(m->tolimit * sizeof(struct tostruct))); - m->tolimit = m->textsize * ARCDENSITY / 100; - if(m->tolimit < MINARCS){ - m->tolimit = MINARCS; - } - else if(m->tolimit > 65534){ - m->tolimit = 65534; - } - ret = vm_allocate(mach_task_self(), - (vm_address_t *)&m->tos, - (vm_size_t)(m->tolimit * sizeof(struct tostruct)), - TRUE); - if(ret != KERN_SUCCESS){ - write(2, MSG, sizeof(MSG) - 1); - m->tos = 0; - return; - } - m->tos[0].link = 0; /* a nop since tos was vm_allocated and is zero */ - - /* - * If this is call to monsetup() was via monstartup() (m == mon) then - * it is using or reusing the first pc range and then the pc sample - * buffer can be setup by the system call profil() via monitor() via - * a moncontrol(1) call. - * - * Otherwise this is call to monsetup() was via monaddition() and a - * new system call is needed to add an additional pc sample buffer in - * the kernel. - */ - if(m == mon && !init){ - monitor(lowpc, highpc, buffer, monsize, m->tolimit); - } - else{ - /* monitor() functionality */ - m->sbuf = buffer; - m->ssiz = monsize; - p = (struct gmonhdr *)m->sbuf; - memset(p, '\0', sizeof(struct gmonhdr)); - p->lpc = (unsigned long)m->lowpc; - p->hpc = (unsigned long)m->highpc; - p->ncnt = m->ssiz; - p->version = GMONVERSION; - p->profrate = getprofhz(); - o = highpc - lowpc; - if((monsize - sizeof(struct gmonhdr)) < o) - m->scale = ((float) (monsize - sizeof(struct gmonhdr))/ o) * - SCALE_1_TO_1; - else - m->scale = SCALE_1_TO_1; - - /* moncontrol(mode == 1) functionality */ - if(!init) - add_profil(m->sbuf + sizeof(struct gmonhdr), - m->ssiz - sizeof(struct gmonhdr), - (int)m->lowpc, m->scale); - } -} - -void -monreset( -void) -{ - unsigned long i; - struct mon_t *m; - struct gmonhdr *p; - - moncontrol(0); - if(mon == NULL) - return; - for(i = 0; i < nmon; i++){ - m = mon + i; - if(m->sbuf != NULL){ - memset(m->sbuf, '\0', m->ssiz); - p = (struct gmonhdr *)m->sbuf; - p->lpc = (unsigned long)m->lowpc; - p->hpc = (unsigned long)m->highpc; - p->ncnt = m->ssiz; - } - if(m->froms != NULL) - memset(m->froms, '\0', m->textsize / HASHFRACTION); - if(m->tos != NULL) - memset(m->tos, '\0', m->tolimit * sizeof (struct tostruct)); - } - order = 0; - moncontrol(1); -} - -void -monoutput( -const char *filename) -{ - int fd; - unsigned long magic, i, fromindex, endfrom, toindex; - struct gmon_data sample_data, arc_data, dyld_data; - char *frompc; - struct rawarc_order rawarc_order; - struct mon_t *m; - unsigned long image_count, vmaddr_slide; - char *image_name; - - moncontrol(0); - m = mon; - if(m == NULL) - return; - fd = creat(filename, 0666); - if(fd < 0){ - perror("mcount: gmon.out"); - return; - } - - magic = GMON_MAGIC; - write(fd, &magic, sizeof(unsigned long)); - -#if defined(__DYNAMIC__) - if(_dyld_present()){ - image_count = _dyld_image_count(); - if(image_count > 1){ -#ifdef DYLD_DEBUG - printf("image_count = %lu\n", image_count - 1); - for(i = 1; i < image_count; i++){ - vmaddr_slide = _dyld_get_image_vmaddr_slide(i); - printf("\tvmaddr_slide 0x%x\n", (unsigned int)vmaddr_slide); - image_name = _dyld_get_image_name(i); - printf("\timage_name %s\n", image_name); - } -#endif - /* - * Calculate the dyld_data.size. - */ - dyld_data.type = GMONTYPE_DYLD_STATE; - dyld_data.size = sizeof(unsigned long) + - sizeof(unsigned long) * (image_count - 1); - for(i = 1; i < image_count; i++){ - image_name = _dyld_get_image_name(i); - dyld_data.size += strlen(image_name) + 1; - } - - /* - * Write the dyld_data. - */ - write(fd, &dyld_data, sizeof(struct gmon_data)); - image_count--; - write(fd, &image_count, sizeof(unsigned long)); - image_count++; - for(i = 1; i < image_count; i++){ - vmaddr_slide = _dyld_get_image_vmaddr_slide(i); - write(fd, &vmaddr_slide, sizeof(unsigned long)); - image_name = _dyld_get_image_name(i); - write(fd, image_name, strlen(image_name) + 1); - } - } - } -#endif - for(i = 0; i < nmon; i++){ - m = mon + i; -#ifdef DEBUG - fprintf(stderr, "[monoutput] sbuf 0x%x ssiz %d\n", - m->sbuf, m->ssiz); -#endif - sample_data.type = GMONTYPE_SAMPLES; - sample_data.size = m->ssiz; - write(fd, &sample_data, sizeof(struct gmon_data)); - /* - * Write the gmonhdr struct and the pc-sample buffer. Note the - * gmonhdr struct is in sbuf at the beginning of sbuf already - * filled in. - */ - write(fd, m->sbuf, m->ssiz); - - /* - * Now write out the raw arcs. - */ - endfrom = m->textsize / (HASHFRACTION * sizeof(*m->froms)); - arc_data.type = GMONTYPE_ARCS_ORDERS; - arc_data.size = 0; - for(fromindex = 0; fromindex < endfrom; fromindex++){ - if(m->froms[fromindex] == 0){ - continue; - } - frompc = m->lowpc + - (fromindex * HASHFRACTION * sizeof(*m->froms)); - for(toindex = m->froms[fromindex]; - toindex != 0; - toindex = m->tos[toindex].link){ - arc_data.size += sizeof(struct rawarc_order); - } - } - write(fd, &arc_data, sizeof(struct gmon_data)); - - for(fromindex = 0; fromindex < endfrom; fromindex++){ - if(m->froms[fromindex] == 0){ - continue; - } - frompc = m->lowpc + - (fromindex * HASHFRACTION * sizeof(*m->froms)); - for(toindex = m->froms[fromindex]; - toindex != 0; - toindex = m->tos[toindex].link){ -#ifdef DEBUG - fprintf(stderr, "[monoutput] frompc 0x%x selfpc 0x%x " - "count %ld order %lu\n", (unsigned int)frompc, - (unsigned int)m->tos[toindex].selfpc, - m->tos[toindex].count, m->tos[toindex].order); -#endif - rawarc_order.raw_frompc = (unsigned long)frompc; - rawarc_order.raw_selfpc = (unsigned long) - m->tos[toindex].selfpc; - rawarc_order.raw_count = m->tos[toindex].count; - rawarc_order.raw_order = m->tos[toindex].order; - write(fd, &rawarc_order, sizeof(struct rawarc_order)); - } - } - } - close(fd); -} - -void -monitor( -char *lowpc, -char *highpc, -char *buf, -int bufsiz, -int nfunc) /* nfunc is not used; available for compatability only. */ -{ - unsigned int o; - struct gmonhdr *p; - struct mon_t *m; - - moncontrol(0); - m = mon; - if(m == NULL) - return; - if(lowpc == 0){ - moncontrol(0); - monoutput("gmon.out"); - return; - } - m->sbuf = buf; - m->ssiz = bufsiz; - p = (struct gmonhdr *)buf; - memset(p, '\0', sizeof(struct gmonhdr)); - p->lpc = (unsigned long)lowpc; - p->hpc = (unsigned long)highpc; - p->ncnt = m->ssiz; - p->version = GMONVERSION; - p->profrate = getprofhz(); - bufsiz -= sizeof(struct gmonhdr); - if(bufsiz <= 0) - return; - o = highpc - lowpc; - if(bufsiz < o) - m->scale = ((float) bufsiz / o) * SCALE_1_TO_1; - else - m->scale = SCALE_1_TO_1; - moncontrol(1); -} - -/* - * Control profiling - * profiling is what mcount checks to see if - * all the data structures are ready. - */ -void -moncontrol( -int mode) -{ - struct mon_t *m; - unsigned long i; - - if(mode){ - /* start */ - m = mon; - if(m != NULL){ - profil(m->sbuf + sizeof(struct gmonhdr), - m->ssiz - sizeof(struct gmonhdr), - (int)m->lowpc, m->scale); - for(i = 1; i < nmon; i++) - add_profil(mon[i].sbuf + sizeof(struct gmonhdr), - mon[i].ssiz - sizeof(struct gmonhdr), - (int)mon[i].lowpc, mon[i].scale); - profiling = 0; - } - } - else{ - /* stop */ - profil((char *)0, 0, 0, 0); - profiling = -1; - } -} - -void -moncount( -char *frompc, -char *selfpc) -{ - unsigned short *frompcindex; - struct tostruct *top, *prevtop; - unsigned long i, toindex; - struct mon_t *m; - - m = mon; - if(m == NULL) - return; - /* - * Check that we are profiling and that we aren't recursively invoked. - * This should really be a test and set instruction in changing the - * value of profiling. - */ - if(profiling) - return; - profiling++; - - -#ifdef DEBUG - fprintf(stderr, "[moncount] frompc 0x%x selfpc 0x%x\n", - (unsigned int)frompc, (unsigned int)selfpc); -#endif - frompcindex = (unsigned short *)frompc; - - /* - * check that frompcindex is a reasonable pc value. - * for example: signal catchers get called from the stack, - * not from text space. too bad. - */ - for(i = 0; i < nmon; i++){ - m = mon + i; - if((unsigned long)frompcindex >= (unsigned long)m->lowpc && - (unsigned long)frompcindex < (unsigned long)m->highpc) - break; - } - if(i == nmon){ - goto done; - } - else{ - frompcindex = (unsigned short *) - ((unsigned long)frompcindex - (unsigned long)m->lowpc); - } - frompcindex = - &m->froms[((long)frompcindex) / (HASHFRACTION * sizeof(*m->froms))]; - toindex = *frompcindex; - if(toindex == 0){ - /* - * first time traversing this arc - */ - toindex = ++m->tos[0].link; - if(toindex >= m->tolimit){ - goto overflow; - } - *frompcindex = toindex; - top = &m->tos[toindex]; - top->selfpc = (unsigned long)selfpc; - top->count = 1; - top->link = 0; - top->order = ++order; - goto done; - } - top = &m->tos[toindex]; - if(top->selfpc == (unsigned long)selfpc){ - /* - * arc at front of chain; usual case. - */ - top->count++; - goto done; - } - /* - * have to go looking down chain for it. - * top points to what we are looking at, - * prevtop points to previous top. - * we know it is not at the head of the chain. - */ - for(; /* goto done */; ){ - if(top->link == 0){ - /* - * top is end of the chain and none of the chain - * had top->selfpc == selfpc. - * so we allocate a new tostruct - * and link it to the head of the chain. - */ - toindex = ++m->tos[0].link; - if(toindex >= m->tolimit){ - goto overflow; - } - top = &m->tos[toindex]; - top->selfpc = (unsigned long)selfpc; - top->count = 1; - top->link = *frompcindex; - top->order = ++order; - *frompcindex = toindex; - goto done; - } - /* - * otherwise, check the next arc on the chain. - */ - prevtop = top; - top = &m->tos[top->link]; - if(top->selfpc == (unsigned long)selfpc){ - /* - * there it is. - * increment its count - * move it to the head of the chain. - */ - top->count++; - toindex = prevtop->link; - prevtop->link = top->link; - top->link = *frompcindex; - *frompcindex = toindex; - goto done; - } - } -done: - profiling--; - return; - -overflow: - profiling++; /* halt further profiling */ -#define TOLIMIT "mcount: tos overflow\n" - write(2, TOLIMIT, sizeof(TOLIMIT) - 1); -} - -/* - * Get the profiling rate. - */ -static -int -getprofhz(void) -{ - int mib[2]; - size_t size; - struct clockinfo clockrate; - - mib[0] = CTL_KERN; - mib[1] = KERN_CLOCKRATE; - clockrate.profhz = 1; - size = sizeof(clockrate); - if(sysctl(mib, 2, &clockrate, &size, NULL, 0) < 0) - ; - return(clockrate.profhz); -} diff --git a/gen.subproj/i386.subproj/Makefile b/gen.subproj/i386.subproj/Makefile deleted file mode 100644 index 5aea859..0000000 --- a/gen.subproj/i386.subproj/Makefile +++ /dev/null @@ -1,50 +0,0 @@ -# -# Generated by the NeXT Project Builder. -# -# NOTE: Do NOT change this file -- Project Builder maintains it. -# -# Put all of your customizations in files called Makefile.preamble -# and Makefile.postamble (both optional), and Makefile will include them. -# - -NAME = i386 - -PROJECTVERSION = 2.8 -PROJECT_TYPE = Component - -OTHERLINKED = mcount.s - -CFILES = abs.c bcmp.c bcopy.c bzero.c ecvt.c ffs.c insque.c isinf.c\ - memcpy.c memmove.c remque.c setjmperr.c strcat.c strcpy.c\ - strlen.c strncat.c strncmp.c strncpy.c - -OTHERSRCS = Makefile.preamble Makefile Makefile.postamble - -OTHERLINKEDOFILES = mcount.o - -MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles -CODE_GEN_STYLE = DYNAMIC -MAKEFILE = subproj.make -LIBS = -DEBUG_LIBS = $(LIBS) -PROF_LIBS = $(LIBS) - - - - -NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc -WINDOWS_OBJCPLUS_COMPILER = $(DEVDIR)/gcc -PDO_UNIX_OBJCPLUS_COMPILER = $(NEXTDEV_BIN)/gcc -NEXTSTEP_JAVA_COMPILER = /usr/bin/javac -WINDOWS_JAVA_COMPILER = $(JDKBINDIR)/javac.exe -PDO_UNIX_JAVA_COMPILER = $(JDKBINDIR)/javac - -include $(MAKEFILEDIR)/platform.make - --include Makefile.preamble - -include $(MAKEFILEDIR)/$(MAKEFILE) - --include Makefile.postamble - --include Makefile.dependencies diff --git a/gen.subproj/i386.subproj/Makefile.postamble b/gen.subproj/i386.subproj/Makefile.postamble deleted file mode 100644 index 411cde6..0000000 --- a/gen.subproj/i386.subproj/Makefile.postamble +++ /dev/null @@ -1,100 +0,0 @@ -############################################################################### -# Makefile.postamble -# Copyright 1997, Apple Computer, Inc. -# -# Use this makefile, which is imported after all other makefiles, to -# override attributes for a project's Makefile environment. This allows you -# to take advantage of the environment set up by the other Makefiles. -# You can also define custom rules at the end of this file. -# -############################################################################### -# -# These variables are exported by the standard makefiles and can be -# used in any customizations you make. They are *outputs* of -# the Makefiles and should be used, not set. -# -# PRODUCTS: products to install. All of these products will be placed in -# the directory $(DSTROOT)$(INSTALLDIR) -# GLOBAL_RESOURCE_DIR: The directory to which resources are copied. -# LOCAL_RESOURCE_DIR: The directory to which localized resources are copied. -# OFILE_DIR: Directory into which .o object files are generated. -# DERIVED_SRC_DIR: Directory used for all other derived files -# -# ALL_CFLAGS: flags to pass when compiling .c files -# ALL_MFLAGS: flags to pass when compiling .m files -# ALL_CCFLAGS: flags to pass when compiling .cc, .cxx, and .C files -# ALL_MMFLAGS: flags to pass when compiling .mm, .mxx, and .M files -# ALL_PRECOMPFLAGS: flags to pass when precompiling .h files -# ALL_LDFLAGS: flags to pass when linking object files -# ALL_LIBTOOL_FLAGS: flags to pass when libtooling object files -# ALL_PSWFLAGS: flags to pass when processing .psw and .pswm (pswrap) files -# ALL_RPCFLAGS: flags to pass when processing .rpc (rpcgen) files -# ALL_YFLAGS: flags to pass when processing .y (yacc) files -# ALL_LFLAGS: flags to pass when processing .l (lex) files -# -# NAME: name of application, bundle, subproject, palette, etc. -# LANGUAGES: langages in which the project is written (default "English") -# English_RESOURCES: localized resources (e.g. nib's, images) of project -# GLOBAL_RESOURCES: non-localized resources of project -# -# SRCROOT: base directory in which to place the new source files -# SRCPATH: relative path from SRCROOT to present subdirectory -# -# INSTALLDIR: Directory the product will be installed into by 'install' target -# PUBLIC_HDR_INSTALLDIR: where to install public headers. Don't forget -# to prefix this with DSTROOT when you use it. -# PRIVATE_HDR_INSTALLDIR: where to install private headers. Don't forget -# to prefix this with DSTROOT when you use it. -# -# EXECUTABLE_EXT: Executable extension for the platform (i.e. .exe on Windows) -# -############################################################################### - -# Some compiler flags can be overridden here for certain build situations. -# -# WARNING_CFLAGS: flag used to set warning level (defaults to -Wmost) -# DEBUG_SYMBOLS_CFLAGS: debug-symbol flag passed to all builds (defaults -# to -g) -# DEBUG_BUILD_CFLAGS: flags passed during debug builds (defaults to -DDEBUG) -# OPTIMIZE_BUILD_CFLAGS: flags passed during optimized builds (defaults -# to -O) -# PROFILE_BUILD_CFLAGS: flags passed during profile builds (defaults -# to -pg -DPROFILE) -# LOCAL_DIR_INCLUDE_DIRECTIVE: flag used to add current directory to -# the include path (defaults to -I.) -# DEBUG_BUILD_LDFLAGS, OPTIMIZE_BUILD_LDFLAGS, PROFILE_BUILD_LDFLAGS: flags -# passed to ld/libtool (defaults to nothing) - - -# Library and Framework projects only: -# INSTALL_NAME_DIRECTIVE: This directive ensures that executables linked -# against the framework will run against the correct version even if -# the current version of the framework changes. You may override this -# to "" as an alternative to using the DYLD_LIBRARY_PATH during your -# development cycle, but be sure to restore it before installing. - - -# Ownership and permissions of files installed by 'install' target - -#INSTALL_AS_USER = root - # User/group ownership -#INSTALL_AS_GROUP = wheel - # (probably want to set both of these) -#INSTALL_PERMISSIONS = - # If set, 'install' chmod's executable to this - - -# Options to strip. Note: -S strips debugging symbols (executables can be stripped -# down further with -x or, if they load no bundles, with no options at all). - -#STRIPFLAGS = -S - - -######################################################################### -# Put rules to extend the behavior of the standard Makefiles here. Include them in -# the dependency tree via cvariables like AFTER_INSTALL in the Makefile.preamble. -# -# You should avoid redefining things like "install" or "app", as they are -# owned by the top-level Makefile API and no context has been set up for where -# derived files should go. -# diff --git a/gen.subproj/i386.subproj/Makefile.preamble b/gen.subproj/i386.subproj/Makefile.preamble deleted file mode 100644 index 6544e5f..0000000 --- a/gen.subproj/i386.subproj/Makefile.preamble +++ /dev/null @@ -1,137 +0,0 @@ -############################################################################### -# Makefile.preamble -# Copyright 1997, Apple Computer, Inc. -# -# Use this makefile for configuring the standard application makefiles -# associated with ProjectBuilder. It is included before the main makefile. -# In Makefile.preamble you set attributes for a project, so they are available -# to the project's makefiles. In contrast, you typically write additional rules or -# override built-in behavior in the Makefile.postamble. -# -# Each directory in a project tree (main project plus subprojects) should -# have its own Makefile.preamble and Makefile.postamble. -############################################################################### -# -# Before the main makefile is included for this project, you may set: -# -# MAKEFILEDIR: Directory in which to find $(MAKEFILE) -# MAKEFILE: Top level mechanism Makefile (e.g., app.make, bundle.make) - -# Compiler/linker flags added to the defaults: The OTHER_* variables will be -# inherited by all nested sub-projects, but the LOCAL_ versions of the same -# variables will not. Put your -I, -D, -U, and -L flags in ProjectBuilder's -# Build Attributes inspector if at all possible. To override the default flags -# that get passed to ${CC} (e.g. change -O to -O2), see Makefile.postamble. The -# variables below are *inputs* to the build process and distinct from the override -# settings done (less often) in the Makefile.postamble. -# -# OTHER_CFLAGS, LOCAL_CFLAGS: additional flags to pass to the compiler -# Note that $(OTHER_CFLAGS) and $(LOCAL_CFLAGS) are used for .h, ...c, .m, -# .cc, .cxx, .C, and .M files. There is no need to respecify the -# flags in OTHER_MFLAGS, etc. -# OTHER_MFLAGS, LOCAL_MFLAGS: additional flags for .m files -# OTHER_CCFLAGS, LOCAL_CCFLAGS: additional flags for .cc, .cxx, and ...C files -# OTHER_MMFLAGS, LOCAL_MMFLAGS: additional flags for .mm and .M files -# OTHER_PRECOMPFLAGS, LOCAL_PRECOMPFLAGS: additional flags used when -# precompiling header files -# OTHER_LDFLAGS, LOCAL_LDFLAGS: additional flags passed to ld and libtool -# OTHER_PSWFLAGS, LOCAL_PSWFLAGS: additional flags passed to pswrap -# OTHER_RPCFLAGS, LOCAL_RPCFLAGS: additional flags passed to rpcgen -# OTHER_YFLAGS, LOCAL_YFLAGS: additional flags passed to yacc -# OTHER_LFLAGS, LOCAL_LFLAGS: additional flags passed to lex - -# These variables provide hooks enabling you to add behavior at almost every -# stage of the make: -# -# BEFORE_PREBUILD: targets to build before installing headers for a subproject -# AFTER_PREBUILD: targets to build after installing headers for a subproject -# BEFORE_BUILD_RECURSION: targets to make before building subprojects -# BEFORE_BUILD: targets to make before a build, but after subprojects -# AFTER_BUILD: targets to make after a build -# -# BEFORE_INSTALL: targets to build before installing the product -# AFTER_INSTALL: targets to build after installing the product -# BEFORE_POSTINSTALL: targets to build before postinstalling every subproject -# AFTER_POSTINSTALL: targts to build after postinstalling every subproject -# -# BEFORE_INSTALLHDRS: targets to build before installing headers for a -# subproject -# AFTER_INSTALLHDRS: targets to build after installing headers for a subproject -# BEFORE_INSTALLSRC: targets to build before installing source for a subproject -# AFTER_INSTALLSRC: targets to build after installing source for a subproject -# -# BEFORE_DEPEND: targets to build before building dependencies for a -# subproject -# AFTER_DEPEND: targets to build after building dependencies for a -# subproject -# -# AUTOMATIC_DEPENDENCY_INFO: if YES, then the dependency file is -# updated every time the project is built. If NO, the dependency -# file is only built when the depend target is invoked. - -# Framework-related variables: -# FRAMEWORK_DLL_INSTALLDIR: On Windows platforms, this variable indicates -# where to put the framework's DLL. This variable defaults to -# $(INSTALLDIR)/../Executables - -# Library-related variables: -# PUBLIC_HEADER_DIR: Determines where public exported header files -# should be installed. Do not include $(DSTROOT) in this value -- -# it is prefixed automatically. For library projects you should -# set this to something like /Developer/Headers/$(NAME). Do not set -# this variable for framework projects unless you do not want the -# header files included in the framework. -# PRIVATE_HEADER_DIR: Determines where private exported header files -# should be installed. Do not include $(DSTROOT) in this value -- -# it is prefixed automatically. -# LIBRARY_STYLE: This may be either STATIC or DYNAMIC, and determines -# whether the libraries produced are statically linked when they -# are used or if they are dynamically loadable. This defaults to -# DYNAMIC. -# LIBRARY_DLL_INSTALLDIR: On Windows platforms, this variable indicates -# where to put the library's DLL. This variable defaults to -# $(INSTALLDIR)/../Executables -# -# INSTALL_AS_USER: owner of the intalled products (default root) -# INSTALL_AS_GROUP: group of the installed products (default wheel) -# INSTALL_PERMISSIONS: permissions of the installed product (default o+rX) -# -# OTHER_RECURSIVE_VARIABLES: The names of variables which you want to be -# passed on the command line to recursive invocations of make. Note that -# the values in OTHER_*FLAGS are inherited by subprojects automatically -- -# you do not have to (and shouldn't) add OTHER_*FLAGS to -# OTHER_RECURSIVE_VARIABLES. - -# Additional headers to export beyond those in the PB.project: -# OTHER_PUBLIC_HEADERS -# OTHER_PROJECT_HEADERS -# OTHER_PRIVATE_HEADERS - -# Additional files for the project's product: <> -# OTHER_RESOURCES: (non-localized) resources for this project -# OTHER_OFILES: relocatables to be linked into this project -# OTHER_LIBS: more libraries to link against -# OTHER_PRODUCT_DEPENDS: other dependencies of this project -# OTHER_SOURCEFILES: other source files maintained by .pre/postamble -# OTHER_GARBAGE: additional files to be removed by `make clean' - -# Set this to YES if you don't want a final libtool call for a library/framework. -# BUILD_OFILES_LIST_ONLY - -# To include a version string, project source must exist in a directory named -# $(NAME).%d[.%d][.%d] and the following line must be uncommented. -# OTHER_GENERATED_OFILES = $(VERS_OFILE) - -# This definition will suppress stripping of debug symbols when an executable -# is installed. By default it is YES. -# STRIP_ON_INSTALL = NO - -# Uncomment to suppress generation of a KeyValueCoding index when installing -# frameworks (This index is used by WOB and IB to determine keys available -# for an object). Set to YES by default. -# PREINDEX_FRAMEWORK = NO - -# Change this definition to install projects somewhere other than the -# standard locations. NEXT_ROOT defaults to "C:/Apple" on Windows systems -# and "" on other systems. -INCLUDED_ARCHS = i386 diff --git a/gen.subproj/i386.subproj/PB.project b/gen.subproj/i386.subproj/PB.project deleted file mode 100644 index 6bad7ee..0000000 --- a/gen.subproj/i386.subproj/PB.project +++ /dev/null @@ -1,43 +0,0 @@ -{ - DYNAMIC_CODE_GEN = YES; - FILESTABLE = { - H_FILES = (); - OTHER_LINKED = ( - abs.c, - bcmp.c, - bcopy.c, - bzero.c, - ecvt.c, - ffs.c, - insque.c, - isinf.c, - mcount.s, - memcpy.c, - memmove.c, - remque.c, - setjmperr.c, - strcat.c, - strcpy.c, - strlen.c, - strncat.c, - strncmp.c, - strncpy.c - ); - OTHER_SOURCES = (Makefile.preamble, Makefile, Makefile.postamble); - SUBPROJECTS = (); - }; - LANGUAGE = English; - MAKEFILEDIR = "$(MAKEFILEPATH)/pb_makefiles"; - NEXTSTEP_BUILDTOOL = /bin/gnumake; - NEXTSTEP_JAVA_COMPILER = /usr/bin/javac; - NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc; - PDO_UNIX_BUILDTOOL = $NEXT_ROOT/Developer/bin/make; - PDO_UNIX_JAVA_COMPILER = "$(JDKBINDIR)/javac"; - PDO_UNIX_OBJCPLUS_COMPILER = "$(NEXTDEV_BIN)/gcc"; - PROJECTNAME = i386; - PROJECTTYPE = Component; - PROJECTVERSION = 2.8; - WINDOWS_BUILDTOOL = $NEXT_ROOT/Developer/Executables/make; - WINDOWS_JAVA_COMPILER = "$(JDKBINDIR)/javac.exe"; - WINDOWS_OBJCPLUS_COMPILER = "$(DEVDIR)/gcc"; -} diff --git a/gen.subproj/i386.subproj/abs.c b/gen.subproj/i386.subproj/abs.c deleted file mode 100644 index 4d6c1bb..0000000 --- a/gen.subproj/i386.subproj/abs.c +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 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(__ppc__) - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)abs.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ - -#include - -int -abs(j) - int j; -{ - return(j < 0 ? -j : j); -} -#else -#warning ----------- Check for implementation of abs() ----------- ! -#endif /* !defined(__ppc__) */ diff --git a/gen.subproj/i386.subproj/bcmp.c b/gen.subproj/i386.subproj/bcmp.c deleted file mode 100644 index ae8f18f..0000000 --- a/gen.subproj/i386.subproj/bcmp.c +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1987, 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(__ppc__) - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)bcmp.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ - -#include - -/* - * bcmp -- vax cmpc3 instruction - */ -int -bcmp(b1, b2, length) - const void *b1, *b2; - register size_t length; -{ - register char *p1, *p2; - - if (length == 0) - return(0); - p1 = (char *)b1; - p2 = (char *)b2; - do - if (*p1++ != *p2++) - break; - while (--length); - return(length); -} - -#else -#warning ----------- Check for implementation of bcmp() ----------- ! -#endif /* !defined(__ppc__) */ diff --git a/gen.subproj/i386.subproj/bcopy.c b/gen.subproj/i386.subproj/bcopy.c deleted file mode 100644 index 6bfae93..0000000 --- a/gen.subproj/i386.subproj/bcopy.c +++ /dev/null @@ -1,161 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * 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[] = "@(#)bcopy.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ - -#include -#include - -/* - * sizeof(word) MUST BE A POWER OF TWO - * SO THAT wmask BELOW IS ALL ONES - */ -typedef int word; /* "word" used for optimal copy speed */ - -#define wsize sizeof(word) -#define wmask (wsize - 1) - -/* - * Copy a block of memory, handling overlap. - * This is the routine that actually implements - * (the portable versions of) bcopy, memcpy, and memmove. - */ -#ifdef MEMCOPY -void * -memcpy(dst0, src0, length) -#else -#ifdef MEMMOVE -void * -memmove(dst0, src0, length) -#else -void -bcopy(src0, dst0, length) -#endif -#endif - void *dst0; - const void *src0; - register size_t length; -{ - register char *dst = dst0; - register const char *src = src0; - register size_t t; - - if (length == 0 || dst == src) /* nothing to do */ - goto done; - - /* - * Macros: loop-t-times; and loop-t-times, t>0 - */ -#define TLOOP(s) if (t) TLOOP1(s) -#define TLOOP1(s) do { s; } while (--t) - - if (((unsigned long)dst < (unsigned long)src) || ((unsigned long)dst >= ((unsigned long)src + length))) { - /* - * Copy forward. - */ - t = (int)src; /* only need low bits */ - if ((t | (int)dst) & wmask) { - /* - * Try to align operands. This cannot be done - * unless the low bits match. - */ - if ((t ^ (int)dst) & wmask || length < wsize) - t = length; - else - t = wsize - (t & wmask); - length -= t; - TLOOP1(*dst++ = *src++); - } - /* - * Copy whole words, then mop up any trailing bytes. - */ - t = length / wsize; - TLOOP(*(word *)dst = *(word *)src; src += wsize; dst += wsize); - t = length & wmask; - TLOOP(*dst++ = *src++); - } else { - /* - * Copy backwards. Otherwise essentially the same. - * Alignment works as before, except that it takes - * (t&wmask) bytes to align, not wsize-(t&wmask). - */ - src += length; - dst += length; - t = (int)src; - if ((t | (int)dst) & wmask) { - if ((t ^ (int)dst) & wmask || length <= wsize) - t = length; - else - t &= wmask; - length -= t; - TLOOP1(*--dst = *--src); - } - t = length / wsize; - TLOOP(src -= wsize; dst -= wsize; *(word *)dst = *(word *)src); - t = length & wmask; - TLOOP(*--dst = *--src); - } -done: -#if defined(MEMCOPY) || defined(MEMMOVE) - return (dst0); -#else - return; -#endif -} - diff --git a/gen.subproj/i386.subproj/bzero.c b/gen.subproj/i386.subproj/bzero.c deleted file mode 100644 index b0c8884..0000000 --- a/gen.subproj/i386.subproj/bzero.c +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* Copyright (c) 1992 NeXT Computer, Inc. All rights reserved. - * - * File: libc/i386/gen/bzero.c - * Author: Bruce Martin, NeXT Computer, Inc. - * - * This file contains machine dependent code for the bzero function - * on NeXT i386-based products. Currently tuned for the i486. - * - * HISTORY - * 26-Aug-92 Bruce Martin (Bruce_Martin@NeXT.COM) - * Created. - */ - -#include - -#undef bzero - -void bzero (void *b, size_t length) -{ - memset((void *) b, 0, (size_t) length); -} diff --git a/gen.subproj/i386.subproj/ecvt.c b/gen.subproj/i386.subproj/ecvt.c deleted file mode 100644 index 70b7c25..0000000 --- a/gen.subproj/i386.subproj/ecvt.c +++ /dev/null @@ -1,166 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * 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); -} diff --git a/gen.subproj/i386.subproj/ffs.c b/gen.subproj/i386.subproj/ffs.c deleted file mode 100644 index 6205d2b..0000000 --- a/gen.subproj/i386.subproj/ffs.c +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 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(__ppc__) - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)ffs.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ - -#include - -/* - * ffs -- vax ffs instruction - */ -int -ffs(mask) - register int mask; -{ - register int bit; - - if (mask == 0) - return(0); - for (bit = 1; !(mask & 1); bit++) - mask >>= 1; - return(bit); -} - -#else -#warning ----------- Check for implementation of ffs() ----------- ! -#endif /* !defined(__ppc__) */ diff --git a/gen.subproj/i386.subproj/insque.c b/gen.subproj/i386.subproj/insque.c deleted file mode 100644 index 17f0b48..0000000 --- a/gen.subproj/i386.subproj/insque.c +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* Copyright (c) 1992, 1997 NeXT Software, Inc. All rights reserved. - * - * File: libc/gen/ppc/insque.c - * - * struct qelem { - * struct qelem *q_forw; - * struct qelem *q_back; - * char q_data[]; - * }; - * - * void insque(struct qelem *elem, struct qelem *prev); - * - * Inserts queue entry `elem' into a queue after element `prev'. - * - * HISTORY -* 24-Jan-1997 Umesh Vaishampayan (umeshv@NeXT.com) -* Ported to PPC. - * 10-Nov-92 Derek B Clegg (dclegg@next.com) - * Created. - */ -#include - -void -insque(struct qelem *elem, struct qelem *prev) -{ - struct qelem *next; - - next = prev->q_forw; - prev->q_forw = elem; - if (next != 0) - next->q_back = elem; - elem->q_forw = next; - elem->q_back = prev; -} diff --git a/gen.subproj/i386.subproj/isinf.c b/gen.subproj/i386.subproj/isinf.c deleted file mode 100644 index 838b17b..0000000 --- a/gen.subproj/i386.subproj/isinf.c +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1987 NeXT, INC. - */ - -/* - * isinf -- returns 1 if positive IEEE infinity, -1 if negative - * IEEE infinity, 0 otherwise. - */ -int -isinf(d) -double d; -{ - int i; - - i = *((int *)&d + 1); - if (i == 0x7ff00000) - return(1); - if (i == 0xfff00000) - return(-1); - return(0); -} diff --git a/gen.subproj/i386.subproj/mcount.s b/gen.subproj/i386.subproj/mcount.s deleted file mode 100644 index 82af032..0000000 --- a/gen.subproj/i386.subproj/mcount.s +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#import - -.text - .globl mcount -mcount: - pushl %ebp // setup mcount's frame - movl %esp,%ebp - - movl (%ebp),%eax // load the frame pointer of mcount's caller - movl 4(%eax),%eax // load mcount's caller's return address - pushl 4(%ebp) // push the selfpc parameter for moncount() - pushl %eax // push the frompc parameter for moncount() - CALL_EXTERN(_moncount) // call moncount() - - movl %ebp,%esp // tear down mcount's frame - popl %ebp - ret diff --git a/gen.subproj/i386.subproj/memcpy.c b/gen.subproj/i386.subproj/memcpy.c deleted file mode 100644 index 6b5774f..0000000 --- a/gen.subproj/i386.subproj/memcpy.c +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* Copyright (c) 1992 NeXT Computer, Inc. All rights reserved. - * - * File: libc/i386/ansi/memcpy.c - * Author: Bruce Martin, NeXT Computer, Inc. - * - * HISTORY - * 24-Nov-92 Derek B Clegg (dclegg@next.com) - * Created for m98k. - */ -#define MEMCOPY -#include "bcopy.c" diff --git a/gen.subproj/i386.subproj/memmove.c b/gen.subproj/i386.subproj/memmove.c deleted file mode 100644 index c907093..0000000 --- a/gen.subproj/i386.subproj/memmove.c +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* Copyright (c) 1992 NeXT Computer, Inc. All rights reserved. - * - * File: libc/i386/ansi/memmove.c - * Author: Bruce Martin, NeXT Computer, Inc. - * - * HISTORY - * 24-Nov-92 Derek B Clegg (dclegg@next.com) - * Created for m98k. - */ -#define MEMMOVE -#include "bcopy.c" diff --git a/gen.subproj/i386.subproj/remque.c b/gen.subproj/i386.subproj/remque.c deleted file mode 100644 index 9e032c5..0000000 --- a/gen.subproj/i386.subproj/remque.c +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* Copyright (c) 1992, 1997 NeXT Software, Inc. All rights reserved. - * - * File: libc/gen/ppc/remque.c - * - * struct qelem { - * struct qelem *q_forw; - * struct qelem *q_back; - * char q_data[]; - * }; - * - * void remque(struct qelem *entry); - * - * Removes `entry' from a queue. - * - * HISTORY - * 24-Jan-1997 Umesh Vaishampayan (umeshv@NeXT.com) - * Ported to PPC. - * 10-Nov-92 Derek B Clegg (dclegg@next.com) - * Created. - */ -#import - -void -remque(struct qelem *elem) -{ - struct qelem *next, *prev; - - next = elem->q_forw; - prev = elem->q_back; - if (next != 0) - next->q_back = prev; - if (prev != 0) - prev->q_forw = next; -} diff --git a/gen.subproj/i386.subproj/setjmperr.c b/gen.subproj/i386.subproj/setjmperr.c deleted file mode 100644 index ab963b5..0000000 --- a/gen.subproj/i386.subproj/setjmperr.c +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1980 Regents of the University of California. - * All rights reserved. - * - * Redistribution and use in source and binary forms are permitted - * provided that the above copyright notice and this paragraph are - * duplicated in all such forms and that any documentation, - * advertising materials, and other materials related to such - * distribution and use acknowledge that the software was developed - * by the University of California, Berkeley. The name of the - * University may not be used to endorse or promote products derived - * from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED - * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)setjmperr.c 5.4 (Berkeley) 6/27/88"; -#endif /* LIBC_SCCS and not lint */ - -/* - * This routine is called from longjmp() when an error occurs. - * Programs that wish to exit gracefully from this error may - * write their own versions. - * If this routine returns, the program is aborted. - */ - -void -longjmperror() -{ -#define ERRMSG "longjmp botch\n" - write(2, ERRMSG, sizeof(ERRMSG) - 1); -} diff --git a/gen.subproj/i386.subproj/strcat.c b/gen.subproj/i386.subproj/strcat.c deleted file mode 100644 index 32cefc0..0000000 --- a/gen.subproj/i386.subproj/strcat.c +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1988, 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(__ppc__) - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)strcat.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ - -#include - -char * -strcat(s, append) - register char *s; - register const char *append; -{ - char *save = s; - - for (; *s; ++s); - while (*s++ = *append++); - return(save); -} - -#else -#warning ----------- Check for implementation of strcat() ----------- ! -#endif /* !defined(__ppc__) */ diff --git a/gen.subproj/i386.subproj/strcpy.c b/gen.subproj/i386.subproj/strcpy.c deleted file mode 100644 index 77ecaf3..0000000 --- a/gen.subproj/i386.subproj/strcpy.c +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1988, 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(__ppc__) - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)strcpy.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ - -#include -#include - -char * -strcpy(to, from) - register char *to; - register const char *from; -{ - char *save = to; - - for (; *to = *from; ++from, ++to); - return(save); -} - -#else -#warning ----------- Check for implementation of strcpy() ----------- ! -#endif /* !defined(__ppc__) */ diff --git a/gen.subproj/i386.subproj/strlen.c b/gen.subproj/i386.subproj/strlen.c deleted file mode 100644 index b57e6e7..0000000 --- a/gen.subproj/i386.subproj/strlen.c +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 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(__ppc__) - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)strlen.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ - -#include -#include - -size_t -strlen(str) - const char *str; -{ - register const char *s; - - for (s = str; *s; ++s); - return(s - str); -} - -#else -#warning ----------- Check for implementation of strlen() ----------- ! -#endif /* !defined(__ppc__) */ - diff --git a/gen.subproj/i386.subproj/strncat.c b/gen.subproj/i386.subproj/strncat.c deleted file mode 100644 index a73aabe..0000000 --- a/gen.subproj/i386.subproj/strncat.c +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * 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(__ppc__) - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)strncat.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ - -#include -#include - -/* - * Concatenate src on the end of dst. At most strlen(dst)+n+1 bytes - * are written at dst (at most n+1 bytes being appended). Return dst. - */ -char * -strncat(dst, src, n) - char *dst; - const char *src; - register size_t n; -{ - if (n != 0) { - register char *d = dst; - register const char *s = src; - - while (*d != 0) - d++; - do { - if ((*d = *s++) == 0) - break; - d++; - } while (--n != 0); - *d = 0; - } - return (dst); -} - -#else -#warning ----------- Check for implementation of strncat() ----------- ! -#endif /* !defined(__ppc__) */ diff --git a/gen.subproj/i386.subproj/strncmp.c b/gen.subproj/i386.subproj/strncmp.c deleted file mode 100644 index 0dc3d06..0000000 --- a/gen.subproj/i386.subproj/strncmp.c +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1989, 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(__ppc__) - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)strncmp.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ - -#include -#include - -int -strncmp(s1, s2, n) - register const char *s1, *s2; - register size_t n; -{ - - if (n == 0) - return (0); - do { - if (*s1 != *s2++) - return (*(unsigned char *)s1 - *(unsigned char *)--s2); - if (*s1++ == 0) - break; - } while (--n != 0); - return (0); -} - -#else -#warning ----------- Check for implementation of strncmp() ----------- ! -#endif /* !defined(__ppc__) */ diff --git a/gen.subproj/i386.subproj/strncpy.c b/gen.subproj/i386.subproj/strncpy.c deleted file mode 100644 index c47add3..0000000 --- a/gen.subproj/i386.subproj/strncpy.c +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * 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(__ppc__) - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)strncpy.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ - -#include -#include - -/* - * Copy src to dst, truncating or null-padding to always copy n bytes. - * Return dst. - */ -char * -strncpy(dst, src, n) - char *dst; - const char *src; - register size_t n; -{ - if (n != 0) { - register char *d = dst; - register const char *s = src; - - do { - if ((*d++ = *s++) == 0) { - /* NUL pad the remaining n-1 bytes */ - while (--n != 0) - *d++ = 0; - break; - } - } while (--n != 0); - } - return (dst); -} - -#else -#warning ----------- Check for implementation of strncpy() ----------- ! -#endif /* !defined(__ppc__) */ diff --git a/gen.subproj/isatty.c b/gen.subproj/isatty.c deleted file mode 100644 index 5170369..0000000 --- a/gen.subproj/isatty.c +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1988, 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 -#include - -int -isatty(fd) - int fd; -{ - struct termios t; - - return(tcgetattr(fd, &t) != -1); -} diff --git a/gen.subproj/isnan.c b/gen.subproj/isnan.c deleted file mode 100644 index bce7a53..0000000 --- a/gen.subproj/isnan.c +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* @(#)s_isnan.c 5.1 93/09/24 */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -#if defined(LIBM_SCCS) && !defined(lint) -static char rcsid[] = "$NetBSD: s_isnan.c,v 1.8 1995/05/10 20:47:36 jtc Exp $"; -#endif - -/* - * isnan(x) returns 1 is x is nan, else 0; - * no branching! - */ - -#include - -typedef union -{ - double value; - struct - { -#if defined(__BIG_ENDIAN__) - u_int32_t msw; - u_int32_t lsw; -#else - u_int32_t lsw; - u_int32_t msw; -#endif - } parts; -} ieee_double_shape_type; -/* Get two 32 bit ints from a double. */ - -#define EXTRACT_WORDS(ix0,ix1,d) \ -do { \ - ieee_double_shape_type ew_u; \ - ew_u.value = (d); \ - (ix0) = ew_u.parts.msw; \ - (ix1) = ew_u.parts.lsw; \ -} while (0) - - -#ifdef __STDC__ - int isnan(double x) -#else - int isnan(x) - double x; -#endif -{ - int32_t hx,lx; - EXTRACT_WORDS(hx,lx,x); - hx &= 0x7fffffff; - hx |= (u_int32_t)(lx|(-lx))>>31; - hx = 0x7ff00000 - hx; - return (int)((u_int32_t)(hx))>>31; -} diff --git a/gen.subproj/malloc.c b/gen.subproj/malloc.c deleted file mode 100644 index 5393b99..0000000 --- a/gen.subproj/malloc.c +++ /dev/null @@ -1,774 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ - -#define __POSIX_LIB__ -#import -#import -#import -#import -#import -#import // for spin lock -#import -#include - -#import "scalable_malloc.h" -#import "stack_logging.h" - -#define USE_SLEEP_RATHER_THAN_ABORT 0 - -#define MAX_ALLOCATION 0xc0000000 // beyond this, assume a programming error -#define INITIAL_ZONES 8 // After this number, we reallocate for new zones - -typedef void (malloc_logger_t)(unsigned type, unsigned arg1, unsigned arg2, unsigned arg3, unsigned result, unsigned num_hot_frames_to_skip); - -static pthread_lock_t _malloc_lock; -static malloc_zone_t *initial_malloc_zones[INITIAL_ZONES] = {0}; - -/* The following variables are exported for the benefit of performance tools */ -unsigned malloc_num_zones = 0; -malloc_zone_t **malloc_zones = initial_malloc_zones; -malloc_logger_t *malloc_logger = NULL; - -unsigned malloc_debug_flags = 0; - -unsigned malloc_check_start = 0; // 0 means don't check -unsigned malloc_check_counter = 0; -unsigned malloc_check_each = 1000; - -#define MALLOC_LOCK() LOCK(_malloc_lock) -#define MALLOC_UNLOCK() UNLOCK(_malloc_lock) - -#define MALLOC_LOG_TYPE_ALLOCATE stack_logging_type_alloc -#define MALLOC_LOG_TYPE_DEALLOCATE stack_logging_type_dealloc -#define MALLOC_LOG_TYPE_HAS_ZONE stack_logging_flag_zone -#define MALLOC_LOG_TYPE_CLEARED stack_logging_flag_cleared - -/********* Utilities ************/ - -static inline malloc_zone_t *find_registered_zone(const void *ptr, size_t *returned_size) { - // locates the proper zone - // if zone found fills returnedSize; else returns NULL - // See comment in malloc_zone_register() about clients non locking to call this function - // Speed is critical for this function - unsigned index = malloc_num_zones; - malloc_zone_t **zones = malloc_zones; - while (index--) { - malloc_zone_t *zone = *zones++; - size_t size; - size = zone->size(zone, ptr); - if (size) { - if (returned_size) *returned_size = size; - return zone; - } - } - return NULL; -} - -/********* Creation and destruction ************/ - -static void _malloc_initialize(void) { - // guaranteed to be called only once - (void)malloc_create_zone(0, 0); - malloc_set_zone_name(malloc_zones[0], "DefaultMallocZone"); - LOCK_INIT(_malloc_lock); - // malloc_printf("Malloc: %d registered zones\n", malloc_num_zones); - // malloc_printf("malloc: malloc_zones is at 0x%x; malloc_num_zones is at 0x%x\n", (unsigned)&malloc_zones, (unsigned)&malloc_num_zones); -} - -static inline malloc_zone_t *inline_malloc_default_zone(void) { - if (!malloc_num_zones) _malloc_initialize(); - // malloc_printf("In inline_malloc_default_zone with %d %d\n", malloc_num_zones, malloc_has_debug_zone); - return malloc_zones[0]; -} - -malloc_zone_t *malloc_default_zone(void) { - return inline_malloc_default_zone(); -} - -static void set_flags_from_environment(void) { - const char *flag; - if (getenv("MallocGuardEdges")) { - malloc_debug_flags = SCALABLE_MALLOC_ADD_GUARD_PAGES; - malloc_printf("malloc[%d]: protecting edges\n", getpid()); - if (getenv("MallocDoNotProtectPrelude")) { - malloc_debug_flags |= SCALABLE_MALLOC_DONT_PROTECT_PRELUDE; - malloc_printf("malloc[%d]: ... but not protecting prelude guard page\n", getpid()); - } - if (getenv("MallocDoNotProtectPostlude")) { - malloc_debug_flags |= SCALABLE_MALLOC_DONT_PROTECT_POSTLUDE; - malloc_printf("malloc[%d]: ... but not protecting postlude guard page\n", getpid()); - } - } - flag = getenv("MallocStackLogging"); - if (!flag) { - flag = getenv("MallocStackLoggingNoCompact"); - stack_logging_dontcompact = 1; - } - if (flag) { - unsigned val = strtoul(flag, NULL, 0); - if (val == 1) val = 0; - if (val == -1) val = 0; - malloc_logger = (val) ? (void *)val : stack_logging_log_stack; - stack_logging_enable_logging = 1; - if (malloc_logger == stack_logging_log_stack) { - malloc_printf("malloc[%d]: recording stacks using standard recorder\n", getpid()); - } else { - malloc_printf("malloc[%d]: recording stacks using recorder %p\n", getpid(), malloc_logger); - } - if (stack_logging_dontcompact) malloc_printf("malloc[%d]: stack logging compaction turned off; VM can increase rapidly\n", getpid()); - } - if (getenv("MallocScribble")) { - malloc_debug_flags |= SCALABLE_MALLOC_DO_SCRIBBLE; - malloc_printf("malloc[%d]: enabling scribbling to detect mods to free blocks\n", getpid()); - } - flag = getenv("MallocCheckHeapStart"); - if (flag) { - malloc_check_start = strtoul(flag, NULL, 0); - if (malloc_check_start == 0) malloc_check_start = 1; - if (malloc_check_start == -1) malloc_check_start = 1; - flag = getenv("MallocCheckHeapEach"); - if (flag) { - malloc_check_each = strtoul(flag, NULL, 0); - if (malloc_check_each == 0) malloc_check_each = 1; - if (malloc_check_each == -1) malloc_check_each = 1; - } - malloc_printf("malloc[%d]: checks heap after %dth operation and each %d operations\n", getpid(), malloc_check_start, malloc_check_each); - } - if (getenv("MallocHelp")) { - malloc_printf( - "malloc[%d]: environment variables that can be set for debug:\n" - "- MallocGuardEdges to add 2 guard pages for each large block\n" - "- MallocDoNotProtectPrelude to disable protection (when previous flag set)\n" - "- MallocDoNotProtectPostlude to disable protection (when previous flag set)\n" - "- MallocStackLogging to record all stacks. Tools like leaks can then be applied\n" - "- MallocStackLoggingNoCompact to record all stacks. Needed for malloc_history\n" - "- MallocScribble to detect writing on free blocks: 0x55 is written upon free\n" - "- MallocCheckHeapStart to check the heap from time to time after operations \n" - "- MallocHelp - this help!\n", getpid()); - } -} - -malloc_zone_t *malloc_create_zone(vm_size_t start_size, unsigned flags) { - malloc_zone_t *zone; - if (!malloc_num_zones) { - char **env = * _NSGetEnviron(); - 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() */ - for (p = env; (c = *p) != NULL; ++p) { - if (!strncmp(c, "Malloc", 6)) { - set_flags_from_environment(); - break; - } - } - - } - zone = create_scalable_zone(start_size, malloc_debug_flags); - malloc_zone_register(zone); - return zone; -} - -void malloc_destroy_zone(malloc_zone_t *zone) { - malloc_zone_unregister(zone); - zone->destroy(zone); -} - -/********* Block creation and manipulation ************/ - -static void internal_check(void) { - static vm_address_t *frames = NULL; - static unsigned num_frames; - if (malloc_zone_check(NULL)) { - malloc_printf("MallocCheckHeap: PASSED check at %dth operation\n", malloc_check_counter-1); - if (!frames) vm_allocate(mach_task_self(), (void *)&frames, vm_page_size, 1); - thread_stack_pcs(frames, vm_page_size/sizeof(vm_address_t) - 1, &num_frames); - } else { - malloc_printf("*** MallocCheckHeap: FAILED check at %dth operation\n", malloc_check_counter-1); - if (frames) { - unsigned index = 1; - malloc_printf("Stack for last operation where the malloc check succeeded: "); - while (index < num_frames) malloc_printf("0x%x ", frames[index++]); - malloc_printf("\n(Use 'atos' for a symbolic stack)\n"); - } - if (malloc_check_each > 1) { - unsigned recomm_each = (malloc_check_each > 10) ? malloc_check_each/10 : 1; - unsigned recomm_start = (malloc_check_counter > malloc_check_each+1) ? malloc_check_counter-1-malloc_check_each : 1; - malloc_printf("*** Recommend using 'setenv MallocCheckHeapStart %d; setenv MallocCheckHeapEach %d' to narrow down failure\n", recomm_start, recomm_each); - } - malloc_printf("*** Sleeping for 100 seconds to leave time to attach\n"); - sleep(100); - } - malloc_check_start += malloc_check_each; -} - -void *malloc_zone_malloc(malloc_zone_t *zone, size_t size) { - void *ptr; - if ((unsigned)size >= MAX_ALLOCATION) { - /* Probably a programming error */ - fprintf(stderr, "*** malloc_zone_malloc[%d]: argument too large: %d\n", getpid(), (unsigned)size); - return NULL; - } - if (malloc_check_start && (malloc_check_counter++ >= malloc_check_start)) { - internal_check(); - } - ptr = zone->malloc(zone, size); - if (malloc_logger) malloc_logger(MALLOC_LOG_TYPE_ALLOCATE | MALLOC_LOG_TYPE_HAS_ZONE, (unsigned)zone, size, 0, (unsigned)ptr, 0); - return ptr; -} - -void *malloc_zone_calloc(malloc_zone_t *zone, size_t num_items, size_t size) { - void *ptr; - if (malloc_check_start && (malloc_check_counter++ >= malloc_check_start)) { - internal_check(); - } - if (((unsigned)num_items >= MAX_ALLOCATION) || ((unsigned)size >= MAX_ALLOCATION) || ((long long)size * num_items >= (long long) MAX_ALLOCATION)) { - /* Probably a programming error */ - fprintf(stderr, "*** malloc_zone_calloc[%d]: arguments too large: %d,%d\n", getpid(), (unsigned)num_items, (unsigned)size); - return NULL; - } - ptr = zone->calloc(zone, num_items, size); - if (malloc_logger) malloc_logger(MALLOC_LOG_TYPE_ALLOCATE | MALLOC_LOG_TYPE_HAS_ZONE | MALLOC_LOG_TYPE_CLEARED, (unsigned)zone, num_items * size, 0, (unsigned)ptr, 0); - return ptr; -} - -void *malloc_zone_valloc(malloc_zone_t *zone, size_t size) { - void *ptr; - if ((unsigned)size >= MAX_ALLOCATION) { - /* Probably a programming error */ - fprintf(stderr, "*** malloc_zone_valloc[%d]: argument too large: %d\n", getpid(), (unsigned)size); - return NULL; - } - if (malloc_check_start && (malloc_check_counter++ >= malloc_check_start)) { - internal_check(); - } - ptr = zone->valloc(zone, size); - if (malloc_logger) malloc_logger(MALLOC_LOG_TYPE_ALLOCATE | MALLOC_LOG_TYPE_HAS_ZONE, (unsigned)zone, size, 0, (unsigned)ptr, 0); - return ptr; -} - -void *malloc_zone_realloc(malloc_zone_t *zone, void *ptr, size_t size) { - void *new_ptr; - if (malloc_check_start && (malloc_check_counter++ >= malloc_check_start)) { - internal_check(); - } - new_ptr = zone->realloc(zone, ptr, size); - if (malloc_logger) malloc_logger(MALLOC_LOG_TYPE_ALLOCATE | MALLOC_LOG_TYPE_DEALLOCATE | MALLOC_LOG_TYPE_HAS_ZONE, (unsigned)zone, (unsigned)ptr, size, (unsigned)new_ptr, 0); - return new_ptr; -} - -void malloc_zone_free(malloc_zone_t *zone, void *ptr) { - if (malloc_logger) malloc_logger(MALLOC_LOG_TYPE_DEALLOCATE | MALLOC_LOG_TYPE_HAS_ZONE, (unsigned)zone, (unsigned)ptr, 0, 0, 0); - if (malloc_check_start && (malloc_check_counter++ >= malloc_check_start)) { - internal_check(); - } - zone->free(zone, ptr); -} - -malloc_zone_t *malloc_zone_from_ptr(const void *ptr) { - malloc_zone_t *zone; - if (!ptr) return NULL; - zone = find_registered_zone(ptr, NULL); - return zone; -} - -/********* Functions for zone implementors ************/ - -void malloc_zone_register(malloc_zone_t *zone) { - /* Note that given the sequencing it is always safe to first get the number of zones, then get malloc_zones without taking the lock, if all you need is to iterate through the list */ - MALLOC_LOCK(); - if (malloc_num_zones >= INITIAL_ZONES) { - malloc_zone_t **zones = malloc_zones; - malloc_zone_t *pzone = malloc_zones[0]; - boolean_t copy = malloc_num_zones == INITIAL_ZONES; - if (copy) zones = NULL; // to avoid realloc on something not allocated - MALLOC_UNLOCK(); - zones = pzone->realloc(pzone, zones, (malloc_num_zones + 1) * sizeof(malloc_zone_t *)); // we leak initial_malloc_zones, not worth tracking it - MALLOC_LOCK(); - if (copy) memcpy(zones, malloc_zones, malloc_num_zones * sizeof(malloc_zone_t *)); - malloc_zones = zones; - } - malloc_zones[malloc_num_zones] = zone; - malloc_num_zones++; // note that we do this after setting malloc_num_zones, so enumerations without taking the lock are safe - MALLOC_UNLOCK(); - // malloc_printf("Registered %p malloc_zones at address %p is %p [%d zones]\n", zone, &malloc_zones, malloc_zones, malloc_num_zones); -} - -void malloc_zone_unregister(malloc_zone_t *z) { - unsigned index; - MALLOC_LOCK(); - index = malloc_num_zones; - while (index--) { - malloc_zone_t *zone = malloc_zones[index]; - if (zone == z) { - malloc_zones[index] = malloc_zones[--malloc_num_zones]; - MALLOC_UNLOCK(); - return; - } - } - MALLOC_UNLOCK(); - fprintf(stderr, "*** malloc[%d]: malloc_zone_unregister() failed for %p\n", getpid(), z); -} - -void malloc_set_zone_name(malloc_zone_t *z, const char *name) { - char *newName; - if (z->zone_name) { - free((char *)z->zone_name); - z->zone_name = NULL; - } - newName = malloc_zone_malloc(z, strlen(name) + 1); - strcpy(newName, name); - z->zone_name = (const char *)newName; -} - -const char *malloc_get_zone_name(malloc_zone_t *zone) { - return zone->zone_name; -} - -static char *_malloc_append_unsigned(unsigned value, unsigned base, char *head) { - if (!value) { - head[0] = '0'; - } else { - if (value >= base) head = _malloc_append_unsigned(value / base, base, head); - value = value % base; - head[0] = (value < 10) ? '0' + value : 'a' + value - 10; - } - return head+1; -} - -void malloc_printf(const char *format, ...) { - va_list args; - char buf[1024]; - char *head = buf; - char ch; - unsigned *nums; - va_start(args, format); -#if LOG_THREAD - head = _malloc_append_unsigned(((unsigned)&args) >> 12, 16, head); - *head++ = ' '; -#endif - nums = args; - while (ch = *format++) { - if (ch == '%') { - ch = *format++; - if (ch == 's') { - char *str = (char *)(*nums++); - write(2, buf, head - buf); - head = buf; - write(2, str, strlen(str)); - } else { - if (ch == 'p') { - *head++ = '0'; *head++ = 'x'; - } - head = _malloc_append_unsigned(*nums++, (ch == 'd') ? 10 : 16, head); - } - } else { - *head++ = ch; - } - } - write(2, buf, head - buf); fflush(stderr); - va_end(args); -} - -/********* Generic ANSI callouts ************/ - -void *malloc(size_t size) { - return malloc_zone_malloc(inline_malloc_default_zone(), size); -} - -void *calloc(size_t num_items, size_t size) { - return malloc_zone_calloc(inline_malloc_default_zone(), num_items, size); -} - -void free(void *ptr) { - malloc_zone_t *zone; - if (!ptr) return; - zone = find_registered_zone(ptr, NULL); - if (zone) { - malloc_zone_free(zone, ptr); - } else { - fprintf(stderr, "*** malloc[%d]: Deallocation of a pointer not malloced: %p; This could be a double free(), or free() called with the middle of an allocated block; Try setting environment variable MallocHelp to see tools to help debug\n", getpid(), ptr); - } -} - -void *realloc(void *old_ptr, size_t new_size) { - malloc_zone_t *zone; - size_t old_size = 0; - if (!old_ptr) return malloc_zone_malloc(inline_malloc_default_zone(), new_size); - zone = find_registered_zone(old_ptr, &old_size); - if (zone && (old_size >= new_size)) return old_ptr; - if (!zone) zone = inline_malloc_default_zone(); - return malloc_zone_realloc(zone, old_ptr, new_size); -} - -void *valloc(size_t size) { - malloc_zone_t *zone = inline_malloc_default_zone(); - return malloc_zone_valloc(zone, size); -} - -extern void vfree(void *ptr) { - free(ptr); -} - -size_t malloc_size(const void *ptr) { - size_t size = 0; - if (!ptr) return size; - (void)find_registered_zone(ptr, &size); - return size; -} - -size_t malloc_good_size (size_t size) { - malloc_zone_t *zone = inline_malloc_default_zone(); - return zone->introspect->good_size(zone, size); -} - -/********* Functions for performance tools ************/ - -static kern_return_t _malloc_default_reader(task_t task, vm_address_t address, vm_size_t size, void **ptr) { - *ptr = (void *)address; - return 0; -} - -kern_return_t malloc_get_all_zones(task_t task, memory_reader_t reader, vm_address_t **addresses, unsigned *count) { - // Note that the 2 following addresses are not correct if the address of the target is different from your own. This notably occurs if the address of System.framework is slid (e.g. different than at B & I ) - vm_address_t remote_malloc_zones = (vm_address_t)&malloc_zones; - vm_address_t remote_malloc_num_zones = (vm_address_t)&malloc_num_zones; - kern_return_t err; - vm_address_t zones_address; - vm_address_t *zones_address_ref; - unsigned num_zones; - unsigned *num_zones_ref; - if (!reader) reader = _malloc_default_reader; - // printf("Read malloc_zones at address %p should be %p\n", &malloc_zones, malloc_zones); - err = reader(task, remote_malloc_zones, sizeof(void *), (void **)&zones_address_ref); - // printf("Read malloc_zones[0x%x]=%p\n", remote_malloc_zones, *zones_address_ref); - if (err) { - fprintf(stderr, "*** malloc[%d]: malloc_get_all_zones: error reading zones_address at 0x%x\n", getpid(), (unsigned)remote_malloc_zones); - return err; - } - zones_address = *zones_address_ref; - // printf("Reading num_zones at address %p\n", remote_malloc_num_zones); - err = reader(task, remote_malloc_num_zones, sizeof(unsigned), (void **)&num_zones_ref); - if (err) { - fprintf(stderr, "*** malloc[%d]: malloc_get_all_zones: error reading num_zones at 0x%x\n", getpid(), (unsigned)remote_malloc_num_zones); - return err; - } - num_zones = *num_zones_ref; - // printf("Read malloc_num_zones[0x%x]=%d\n", remote_malloc_num_zones, num_zones); - *count = num_zones; - // printf("malloc_get_all_zones succesfully found %d zones\n", num_zones); - err = reader(task, zones_address, sizeof(malloc_zone_t *) * num_zones, (void **)addresses); - if (err) { - fprintf(stderr, "*** malloc[%d]: malloc_get_all_zones: error reading zones at 0x%x\n", getpid(), (unsigned)&zones_address); - return err; - } - // printf("malloc_get_all_zones succesfully read %d zones\n", num_zones); - return err; -} - -/********* Debug helpers ************/ - -void malloc_zone_print_ptr_info(void *ptr) { - malloc_zone_t *zone; - if (!ptr) return; - zone = find_registered_zone(ptr, NULL); - if (zone) { - printf("ptr %p in registered zone %p\n", ptr, zone); - } else { - printf("ptr %p not in heap\n", ptr); - } -} - -boolean_t malloc_zone_check(malloc_zone_t *zone) { - boolean_t ok = 1; - if (!zone) { - unsigned index = 0; - while (index < malloc_num_zones) { - zone = malloc_zones[index++]; - if (!zone->introspect->check(zone)) ok = 0; - } - } else { - ok = zone->introspect->check(zone); - } - return ok; -} - -void malloc_zone_print(malloc_zone_t *zone, boolean_t verbose) { - if (!zone) { - unsigned index = 0; - while (index < malloc_num_zones) { - zone = malloc_zones[index++]; - zone->introspect->print(zone, verbose); - } - } else { - zone->introspect->print(zone, verbose); - } -} - -void malloc_zone_log(malloc_zone_t *zone, void *address) { - if (!zone) { - unsigned index = 0; - while (index < malloc_num_zones) { - zone = malloc_zones[index++]; - zone->introspect->log(zone, address); - } - } else { - zone->introspect->log(zone, address); - } -} - -/********* Misc other entry points ************/ - -static void DefaultMallocError(int x) { - fprintf(stderr, "*** malloc[%d]: error %d\n", getpid(), x); -#if USE_SLEEP_RATHER_THAN_ABORT - sleep(3600); -#else - abort(); -#endif -} - -void (*malloc_error(void (*func)(int)))(int) { - return DefaultMallocError; -} - -void _malloc_fork_prepare() { - /* Prepare the malloc module for a fork by insuring that no thread is in a malloc critical section */ - unsigned index = 0; - MALLOC_LOCK(); - while (index < malloc_num_zones) { - malloc_zone_t *zone = malloc_zones[index++]; - zone->introspect->force_lock(zone); - } -} - -void _malloc_fork_parent() { - /* Called in the parent process after a fork() to resume normal operation. */ - unsigned index = 0; - MALLOC_UNLOCK(); - while (index < malloc_num_zones) { - malloc_zone_t *zone = malloc_zones[index++]; - zone->introspect->force_unlock(zone); - } -} - -void _malloc_fork_child() { - /* Called in the child process after a fork() to resume normal operation. In the MTASK case we also have to change memory inheritance so that the child does not share memory with the parent. */ - unsigned index = 0; - MALLOC_UNLOCK(); - while (index < malloc_num_zones) { - malloc_zone_t *zone = malloc_zones[index++]; - zone->introspect->force_unlock(zone); - } -} - -size_t mstats(void) { - malloc_zone_print(NULL, 0); - return 1; -} - -/***************** OBSOLETE ENTRY POINTS ********************/ - -#if PHASE_OUT_OLD_MALLOC -#error PHASE OUT THE FOLLOWING FUNCTIONS -#else -#warning PHASE OUT THE FOLLOWING FUNCTIONS -#endif - -void set_malloc_singlethreaded(boolean_t single) { - static boolean_t warned = 0; - if (!warned) { -#if PHASE_OUT_OLD_MALLOC - fprintf(stderr, "*** malloc[%d]: OBSOLETE: set_malloc_singlethreaded(%d)\n", getpid(), single); -#endif - warned = 1; - } -} - -void malloc_singlethreaded() { - static boolean_t warned = 0; - if (!warned) { - fprintf(stderr, "*** malloc[%d]: OBSOLETE: malloc_singlethreaded()\n", getpid()); - warned = 1; - } -} - -int malloc_debug(int level) { - fprintf(stderr, "*** malloc[%d]: OBSOLETE: malloc_debug()\n", getpid()); - return 0; -} - -/********* exo_zone - FOR emacs freeze drying ************/ - -typedef struct { - malloc_zone_t basic_zone; - vm_range_t range; - unsigned flags; -} exo_zone_t; - -#define MALLOC_EXO_ZONE_SIZE_IS_OLD 1 -#define MALLOC_EXO_ZONE_SIZE_IS_SCALABLE 2 - -typedef struct { - unsigned int lastguyfree:1; - unsigned int free:1; - unsigned int size:30; -} old_header_t; - -#define THIS_FREE 0x8000 // indicates this block is free -#define PREV_FREE 0x4000 // indicates previous block is free -#define SHIFT_QUANTUM 4 - -static size_t exo_zone_size(exo_zone_t *zone, const void *ptr) { - if (zone->flags == MALLOC_EXO_ZONE_SIZE_IS_OLD) { - if (ptr == (void *)zone->range.address) return zone->range.size; - return ((old_header_t *)ptr)[-1].size - sizeof(old_header_t); - } - if (zone->flags == MALLOC_EXO_ZONE_SIZE_IS_SCALABLE) { - // this is indeed a valid pointer - unsigned short msize_and_free = ((unsigned short *)ptr)[-1]; - return (msize_and_free & THIS_FREE) ? 0 : ((msize_and_free & ~PREV_FREE) << SHIFT_QUANTUM) - sizeof(unsigned short); - } - fprintf(stderr, "*** malloc[%d]: exo_zone_size unknown flags()\n", getpid()); - return 0; -} - -static void *exo_zone_malloc(exo_zone_t *zone, size_t new_size) { - return malloc(new_size); -} - -static void *exo_zone_calloc(exo_zone_t *zone, size_t num_items, size_t size) { - return calloc(num_items, size); -} - -static void *exo_zone_valloc(exo_zone_t *zone, size_t new_size) { - return valloc(new_size); -} - -static void *exo_zone_realloc(exo_zone_t *zone, void *ptr, size_t new_size) { - size_t old_size = exo_zone_size(zone, ptr); - void *new_ptr; - if (new_size <= old_size) return ptr; - new_ptr = malloc(new_size); - if (old_size) memcpy(new_ptr, ptr, old_size); - return new_ptr; -} - -static void exo_zone_free(exo_zone_t *zone, void *ptr) { -} - -static void exo_zone_destroy(exo_zone_t *zone) { - free(zone); -} - -static kern_return_t exo_zone_noop(void) { - return 0; -} - -static size_t exo_zone_good_size(exo_zone_t *zone, size_t size) { - return size; -} - -static struct malloc_introspection_t exo_zone_introspect = {(void *)exo_zone_noop, (void *)exo_zone_good_size, (void *)exo_zone_noop, (void *)exo_zone_noop, (void *)exo_zone_noop, (void *)exo_zone_noop, (void *)exo_zone_noop}; - -static malloc_zone_t *create_exo_zone(vm_address_t start, vm_size_t size, unsigned flags) { - exo_zone_t *zone = calloc(sizeof(exo_zone_t), 1); - zone->basic_zone.size = (void *)exo_zone_size; - zone->basic_zone.malloc = (void *)exo_zone_malloc; - zone->basic_zone.calloc = (void *)exo_zone_calloc; - zone->basic_zone.valloc = (void *)exo_zone_valloc; - zone->basic_zone.free = (void *)exo_zone_free; - zone->basic_zone.realloc = (void *)exo_zone_realloc; - zone->basic_zone.destroy = (void *)exo_zone_destroy; - zone->basic_zone.introspect = &exo_zone_introspect; - zone->flags = flags; - return (malloc_zone_t *)zone; -} - -/********* Support for emacs FreezeDrying ************/ - -#define OLD_MALLOC_VERSION 1 -#define SCALABLE_MALLOC_VERSION 2 - -#define MAX_RANGES 1023 -typedef struct { - unsigned version; - unsigned num; - vm_range_t ranges[MAX_RANGES]; -} malloc_freezedry_ranges; - -static void malloc_freezedry_recorder(task_t task, void *rr, unsigned type, vm_range_t *ranges, unsigned num) { - malloc_freezedry_ranges *recorded = rr; - while (num && (recorded->num < MAX_RANGES)) { - recorded->ranges[recorded->num++] = *ranges; - ranges++; num--; - } - if (recorded->num == MAX_RANGES) fprintf(stderr, "*** malloc[%d]: malloc_freezedry_recorder: exceeding capacity\n", getpid()); -} - -#define ADDINT(cp,i) (*((int *)cp) = i, cp += sizeof(int)) -static kern_return_t default_reader(task_t task, vm_address_t address, vm_size_t size, void **ptr) { - *ptr = (void *)address; - return 0; -} - -int malloc_freezedry(void) { - malloc_freezedry_ranges rr; - unsigned index = 0; - char *cp; - size_t size; - rr.version = SCALABLE_MALLOC_VERSION; - rr.num = 0; - while (index < malloc_num_zones) { - malloc_zone_t *zone = malloc_zones[index++]; - zone->introspect->enumerator(mach_task_self(), &rr, MALLOC_PTR_REGION_RANGE_TYPE | MALLOC_ADMIN_REGION_RANGE_TYPE, (vm_address_t)zone, default_reader, malloc_freezedry_recorder); - } - size = sizeof(rr) - (MAX_RANGES - rr.num) * sizeof(vm_range_t); - cp = valloc(size); - memcpy(cp, (void *)&rr, size); - return (int)cp; -} - -#define FETCHINT(i) (i = *((int *)cp), cp += sizeof(int)) -int malloc_jumpstart(int cookie) { - char *cp = (char *)cookie; - int version, regions; - FETCHINT(version); - if ((version != OLD_MALLOC_VERSION) && (version != SCALABLE_MALLOC_VERSION)) return 1; - FETCHINT(regions); - // fprintf(stderr, "malloc_jumpstart got (version %d): %d regions\n", version, regions); - while (--regions >= 0) { - malloc_zone_t *zone; - void **region = (void **)cp; - if (version == OLD_MALLOC_VERSION) { - cp += 3 * sizeof(void *); - // printf("Should add region beginadd=%p endadd=%p zone=%p\n", region[0], region[1], region[2]); - zone = create_exo_zone((vm_address_t)(region[0]), (vm_size_t)(region[1] - region[0]), MALLOC_EXO_ZONE_SIZE_IS_OLD); - } else { - cp += 2 * sizeof(void *); - // printf("Should add region beginadd=%p endadd=%p zone=%p\n", region[0], region[1], region[2]); - zone = create_exo_zone((vm_address_t)(region[0]), (vm_size_t)region[1], MALLOC_EXO_ZONE_SIZE_IS_SCALABLE); - } - malloc_zone_register(zone); - } - return 0; -} - diff --git a/gen.subproj/malloc.h b/gen.subproj/malloc.h deleted file mode 100644 index 219f605..0000000 --- a/gen.subproj/malloc.h +++ /dev/null @@ -1,151 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ - -#import -#import - -/********* Type definitions ************/ - -typedef struct _malloc_zone_t { - /* Only zone implementors should depend on the layout of this structure; - Regular callers should use the access functions below */ - void *reserved1; - void *reserved2; - size_t (*size)(struct _malloc_zone_t *zone, const void *ptr); /* returns the size of a block or 0 if not in this zone; must be fast, especially for negative answers */ - void *(*malloc)(struct _malloc_zone_t *zone, size_t size); - void *(*calloc)(struct _malloc_zone_t *zone, size_t num_items, size_t size); /* same as malloc, but block returned is set to zero */ - void *(*valloc)(struct _malloc_zone_t *zone, size_t size); /* same as malloc, but block returned is set to zero and is guaranteed to be page aligned */ - void (*free)(struct _malloc_zone_t *zone, void *ptr); - void *(*realloc)(struct _malloc_zone_t *zone, void *ptr, size_t size); - void (*destroy)(struct _malloc_zone_t *zone); /* zone is destroyed and all memory reclaimed */ - const char *zone_name; - void *reserved3; - void *reserved4; - struct malloc_introspection_t *introspect; - void *reserved5; -} malloc_zone_t; - -/********* Creation and destruction ************/ - -extern malloc_zone_t *malloc_default_zone(void); - /* The initial zone */ - -extern malloc_zone_t *malloc_create_zone(vm_size_t start_size, unsigned flags); - /* Create a new zone */ - -extern void malloc_destroy_zone(malloc_zone_t *zone); - /* Destroys zone and everything it allocated */ - -/********* Block creation and manipulation ************/ - -extern void *malloc_zone_malloc(malloc_zone_t *zone, size_t size); - /* Allocates a new pointer of size size; zone must be non-NULL */ - -extern void *malloc_zone_calloc(malloc_zone_t *zone, size_t num_items, size_t size); - /* Allocates a new pointer of size num_items * size; block is cleared; zone must be non-NULL */ - -extern void *malloc_zone_valloc(malloc_zone_t *zone, size_t size); - /* Allocates a new pointer of size size; zone must be non-NULL; Pointer is guaranteed to be page-aligned and block is cleared */ - -extern void malloc_zone_free(malloc_zone_t *zone, void *ptr); - /* Frees pointer in zone; zone must be non-NULL */ - -extern void *malloc_zone_realloc(malloc_zone_t *zone, void *ptr, size_t size); - /* Enlarges block if necessary; zone must be non-NULL */ - -extern malloc_zone_t *malloc_zone_from_ptr(const void *ptr); - /* Returns the zone for a pointer, or NULL if not in any zone. - The ptr must have been returned from a malloc or realloc call. */ - -extern size_t malloc_size(const void *ptr); - /* Returns size of given ptr */ - -/********* Functions for zone implementors ************/ - -extern void malloc_zone_register(malloc_zone_t *zone); - /* Registers a freshly created zone; - Should typically be called after a zone has been created */ - -extern void malloc_zone_unregister(malloc_zone_t *zone); - /* De-registers a zone - Should typically be called before calling the zone destruction routine */ - -extern void malloc_set_zone_name(malloc_zone_t *zone, const char *name); - /* Sets the name of a zone */ - -extern const char *malloc_get_zone_name(malloc_zone_t *zone); - /* Returns the name of a zone */ - -typedef struct { - vm_address_t address; - vm_size_t size; -} vm_range_t; - -typedef kern_return_t memory_reader_t(task_t remote_task, vm_address_t remote_address, vm_size_t size, void **local_memory); - /* given a task, "reads" the memory at the given address and size -local_memory: set to a contiguous chunk of memory; validity of local_memory is assumed to be limited (until next call) */ - -#define MALLOC_PTR_IN_USE_RANGE_TYPE 1 /* for allocated pointers */ -#define MALLOC_PTR_REGION_RANGE_TYPE 2 /* for region containing pointers */ -#define MALLOC_ADMIN_REGION_RANGE_TYPE 4 /* for region used internally */ - -typedef void vm_range_recorder_t(task_t, void *, unsigned type, vm_range_t *, unsigned); - /* given a task and context, "records" the specified addresses */ - -typedef struct malloc_introspection_t { - kern_return_t (*enumerator)(task_t task, void *, unsigned type_mask, vm_address_t zone_address, memory_reader_t reader, vm_range_recorder_t recorder); /* enumerates all the malloc pointers in use */ - size_t (*good_size)(malloc_zone_t *zone, size_t size); - boolean_t (*check)(malloc_zone_t *zone); /* Consistency checker */ - void (*print)(malloc_zone_t *zone, boolean_t verbose); /* Prints zone */ - void (*log)(malloc_zone_t *zone, void *address); /* Enables logging of activity */ - void (*force_lock)(malloc_zone_t *zone); /* Forces locking zone */ - void (*force_unlock)(malloc_zone_t *zone); /* Forces unlocking zone */ -} malloc_introspection_t; - -extern void malloc_printf(const char *format, ...); - /* Convenience for logging errors and warnings; - No allocation is performed during execution of this function; - Only understand %p %d %x %s formats - */ - -/********* Functions for performance tools ************/ - -extern kern_return_t malloc_get_all_zones(task_t task, memory_reader_t reader, vm_address_t **addresses, unsigned *count); - /* Fills addresses and count with the addresses of the zones in task; - Note that the validity of the addresses returned correspond to the validity of the memory returned by reader */ - -/********* Debug helpers ************/ - -extern void malloc_zone_print_ptr_info(void *ptr); - /* print to stdout if this pointer is in the malloc heap, free status, and size */ - -extern boolean_t malloc_zone_check(malloc_zone_t *zone); - /* Checks zone is well formed; if !zone, checks all zones */ - -extern void malloc_zone_print(malloc_zone_t *zone, boolean_t verbose); - /* Prints summary on zone; if !zone, prints all zones */ - -extern void malloc_zone_log(malloc_zone_t *zone, void *address); - /* Controls logging of all activity; if !zone, for all zones; - If address==0 nothing is logged; - If address==-1 all activity is logged; - Else only the activity regarding address is logged */ diff --git a/gen.subproj/nanosleep.c b/gen.subproj/nanosleep.c deleted file mode 100644 index 84dec2f..0000000 --- a/gen.subproj/nanosleep.c +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ - -#include -#include -#include -#include -#include -#include -#include -#include - -extern mach_port_t clock_port; - -int -nanosleep(const struct timespec *requested_time, struct timespec *remaining_time) { - kern_return_t ret; - mach_timespec_t remain; - mach_timespec_t current; - - if ((requested_time == NULL) || (requested_time->tv_sec < 0) || (requested_time->tv_nsec > NSEC_PER_SEC)) { - errno = EINVAL; - return -1; - } - - ret = clock_get_time(clock_port, ¤t); - 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 */ - ret = clock_sleep_trap(clock_port, TIME_RELATIVE, requested_time->tv_sec, requested_time->tv_nsec, &remain); - if (ret != KERN_SUCCESS) { - if (ret == KERN_ABORTED) { - 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; - } - 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; - } - return 0; -} diff --git a/gen.subproj/nice.c b/gen.subproj/nice.c deleted file mode 100644 index 8b99cd2..0000000 --- a/gen.subproj/nice.c +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1983, 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 -#include -#include -#include -#include -/* - * Backwards compatible nice. - */ -int -nice(incr) - int incr; -{ - int prio; - - errno = 0; - prio = getpriority(PRIO_PROCESS, 0); - if (prio == -1 && errno) - return (-1); - return (setpriority(PRIO_PROCESS, 0, prio + incr)); -} diff --git a/gen.subproj/nlist.c b/gen.subproj/nlist.c deleted file mode 100644 index e6fca65..0000000 --- a/gen.subproj/nlist.c +++ /dev/null @@ -1,329 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * - * - * 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 -#include -#include -#include -#include -#include - -/* Stuff lifted from and since they are gone */ -/* - * Header prepended to each a.out file. - */ -struct exec { -unsigned short a_machtype; /* machine type */ -unsigned short a_magic; /* magic number */ -unsigned long a_text; /* size of text segment */ -unsigned long a_data; /* size of initialized data */ -unsigned long a_bss; /* size of uninitialized data */ -unsigned long a_syms; /* size of symbol table */ -unsigned long a_entry; /* entry point */ -unsigned long a_trsize; /* size of text relocation */ -unsigned long a_drsize; /* size of data relocation */ -}; - -#define OMAGIC 0407 /* old impure format */ -#define NMAGIC 0410 /* read-only text */ -#define ZMAGIC 0413 /* demand load format */ - -#define N_BADMAG(x) \ - (((x).a_magic)!=OMAGIC && ((x).a_magic)!=NMAGIC && ((x).a_magic)!=ZMAGIC) -#define N_TXTOFF(x) \ - ((x).a_magic==ZMAGIC ? 0 : sizeof (struct exec)) -#define N_SYMOFF(x) \ - (N_TXTOFF(x) + (x).a_text+(x).a_data + (x).a_trsize+(x).a_drsize) - -#include -#include -#include -#include -#include - -/* - * CPUSUBTYPE_SUPPORT should be changed to non-zero once the - * cpusubtype_* routines are available in libc. - */ -#define CPUSUBTYPE_SUPPORT 0 - -/* - * nlist - retreive attributes from name list (string table version) - */ - -int -nlist(name, list) - const char *name; - struct nlist *list; -{ - int fd, n; - - fd = open(name, O_RDONLY, 0); - if (fd < 0) - return (-1); - n = __fdnlist(fd, list); - (void)close(fd); - return (n); -} - -/* Note: __fdnlist() is called from kvm_nlist in libkvm's kvm.c */ - -int -__fdnlist(fd, list) - int fd; - struct nlist *list; -{ - register struct nlist *p, *q; - register char *s1, *s2; - register n, m; - int maxlen, nreq; - off_t sa; /* symbol address */ - off_t ss; /* start of strings */ - struct exec buf; - struct nlist space[BUFSIZ/sizeof (struct nlist)]; - unsigned arch_offset = 0; - - maxlen = 0; - for (q = list, nreq = 0; q->n_un.n_name && q->n_un.n_name[0]; q++, nreq++) { - q->n_type = 0; - q->n_value = 0; - q->n_desc = 0; - q->n_sect = 0; - n = strlen(q->n_un.n_name); - if (n > maxlen) - maxlen = n; - } - if (read(fd, (char *)&buf, sizeof(buf)) != sizeof(buf) || - (N_BADMAG(buf) && *((long *)&buf) != MH_MAGIC && - NXSwapBigLongToHost(*((long *)&buf)) != FAT_MAGIC)) { - return (-1); - } - - /* Deal with fat file if necessary */ - if (NXSwapBigLongToHost(*((long *)&buf)) == FAT_MAGIC) { - struct host_basic_info hbi; - struct fat_header fh; - struct fat_arch *fat_archs, *fap; - unsigned i; - - /* Get our host info */ - i = HOST_BASIC_INFO_COUNT; - if (host_info(mach_host_self(), HOST_BASIC_INFO, - (host_info_t)(&hbi), &i) != KERN_SUCCESS) { - return (-1); - } - - /* Read in the fat header */ - lseek(fd, 0, SEEK_SET); - if (read(fd, (char *)&fh, sizeof(fh)) != sizeof(fh)) { - return (-1); - } - - /* Convert fat_narchs to host byte order */ - fh.nfat_arch = NXSwapBigLongToHost(fh.nfat_arch); - - /* Read in the fat archs */ - fat_archs = (struct fat_arch *)malloc(fh.nfat_arch * - sizeof(struct fat_arch)); - if (fat_archs == NULL) { - return (-1); - } - if (read(fd, (char *)fat_archs, - sizeof(struct fat_arch) * fh.nfat_arch) != - sizeof(struct fat_arch) * fh.nfat_arch) { - free(fat_archs); - return (-1); - } - - /* - * Convert archs to host byte ordering (a constraint of - * cpusubtype_getbestarch() - */ - for (i = 0; i < fh.nfat_arch; i++) { - fat_archs[i].cputype = - NXSwapBigLongToHost(fat_archs[i].cputype); - fat_archs[i].cpusubtype = - NXSwapBigLongToHost(fat_archs[i].cpusubtype); - fat_archs[i].offset = - NXSwapBigLongToHost(fat_archs[i].offset); - fat_archs[i].size = - NXSwapBigLongToHost(fat_archs[i].size); - fat_archs[i].align = - NXSwapBigLongToHost(fat_archs[i].align); - } - -#if CPUSUBTYPE_SUPPORT - fap = cpusubtype_getbestarch(hbi.cpu_type, hbi.cpu_subtype, - fat_archs, fh.nfat_arch); -#else CPUSUBTYPE_SUPPORT -#warning Use the cpusubtype functions!!! - fap = NULL; - for (i = 0; i < fh.nfat_arch; i++) { - if (fat_archs[i].cputype == hbi.cpu_type) { - fap = &fat_archs[i]; - break; - } - } -#endif CPUSUBTYPE_SUPPORT - if (!fap) { - free(fat_archs); - return (-1); - } - arch_offset = fap->offset; - free(fat_archs); - - /* Read in the beginning of the architecture-specific file */ - lseek(fd, arch_offset, SEEK_SET); - if (read(fd, (char *)&buf, sizeof(buf)) != sizeof(buf)) { - return (-1); - } - } - - if (*((long *)&buf) == MH_MAGIC) { - struct mach_header mh; - struct load_command *load_commands, *lcp; - struct symtab_command *stp; - long i; - - lseek(fd, arch_offset, SEEK_SET); - if (read(fd, (char *)&mh, sizeof(mh)) != sizeof(mh)) { - return (-1); - } - load_commands = (struct load_command *)malloc(mh.sizeofcmds); - if (load_commands == NULL) { - return (-1); - } - if (read(fd, (char *)load_commands, mh.sizeofcmds) != - mh.sizeofcmds) { - free(load_commands); - return (-1); - } - stp = NULL; - lcp = load_commands; - for (i = 0; i < mh.ncmds; i++) { - if (lcp->cmdsize % sizeof(long) != 0 || - lcp->cmdsize <= 0 || - (char *)lcp + lcp->cmdsize > - (char *)load_commands + mh.sizeofcmds) { - free(load_commands); - return (-1); - } - if (lcp->cmd == LC_SYMTAB) { - if (lcp->cmdsize != - sizeof(struct symtab_command)) { - free(load_commands); - return (-1); - } - stp = (struct symtab_command *)lcp; - break; - } - lcp = (struct load_command *) - ((char *)lcp + lcp->cmdsize); - } - if (stp == NULL) { - free(load_commands); - return (-1); - } - sa = stp->symoff + arch_offset; - ss = stp->stroff + arch_offset; - n = stp->nsyms * sizeof(struct nlist); - free(load_commands); - } - else { - sa = N_SYMOFF(buf) + arch_offset; - ss = sa + buf.a_syms + arch_offset; - n = buf.a_syms; - } - - lseek(fd, sa, SEEK_SET); - while (n) { - long savpos; - - m = sizeof (space); - if (n < m) - m = n; - if (read(fd, (char *)space, m) != m) - break; - n -= m; - savpos = lseek(fd, 0, SEEK_CUR); - for (q = space; (m -= sizeof(struct nlist)) >= 0; q++) { - char nambuf[BUFSIZ]; - - if (q->n_un.n_strx == 0 || q->n_type & N_STAB) - continue; - lseek(fd, ss+q->n_un.n_strx, SEEK_SET); - read(fd, nambuf, maxlen+1); - for (p = list; p->n_un.n_name && p->n_un.n_name[0]; p++) { - s1 = p->n_un.n_name; - s2 = nambuf; - while (*s1) { - if (*s1++ != *s2++) - goto cont; - } - if (*s2) - goto cont; - p->n_value = q->n_value; - p->n_type = q->n_type; - p->n_desc = q->n_desc; - p->n_sect = q->n_sect; - if (--nreq == 0) - return (nreq); - break; - cont: ; - } - } - lseek(fd, savpos, SEEK_SET); - } - return (nreq); -} diff --git a/gen.subproj/opendir.c b/gen.subproj/opendir.c deleted file mode 100644 index 1426f1d..0000000 --- a/gen.subproj/opendir.c +++ /dev/null @@ -1,278 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1983, 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 -#include -#include - -#include -#include -#include -#include -#include -#include - -DIR *__opendir2(const char *name, int flags) -{ - DIR *dirp; - int fd; - int incr; - int unionstack; - struct stat statb; - - if ((fd = open(name, O_RDONLY)) == -1) - return (NULL); - if (fstat(fd, &statb) || !S_ISDIR(statb.st_mode)) { - errno = ENOTDIR; - close(fd); - return (NULL); - } - if (fcntl(fd, F_SETFD, FD_CLOEXEC) == -1 || - (dirp = (DIR *)malloc(sizeof(DIR))) == NULL) { - close(fd); - return (NULL); - } - - /* - * If CLBYTES is an exact multiple of DIRBLKSIZ, use a CLBYTES - * buffer that it cluster boundary aligned. - * Hopefully this can be a big win someday by allowing page - * trades to user space to be done by getdirentries() - */ - if ((CLBYTES % DIRBLKSIZ) == 0) - incr = CLBYTES; - else - incr = DIRBLKSIZ; - - /* - * Determine whether this directory is the top of a union stack. - */ - if (flags & DTF_NODUP) { - struct statfs sfb; - - if (fstatfs(fd, &sfb) < 0) { - free(dirp); - close(fd); - return (NULL); - } - unionstack = (!strcmp(sfb.f_fstypename, "union") || (sfb.f_flags & MNT_UNION)); - } else { - unionstack = 0; - } - - if (unionstack) { - int len = 0; - int space = 0; - char *buf = 0; - char *ddptr = 0; - char *ddeptr; - int n; - struct dirent **dpv; - - /* - * The strategy here is to read all the directory - * entries into a buffer, sort the buffer, and - * remove duplicate entries by setting the inode - * number to zero. - */ - - do { - /* - * Always make at least DIRBLKSIZ bytes - * available to getdirentries - */ - if (space < DIRBLKSIZ) { - space += incr; - len += incr; - buf = realloc(buf, len); - if (buf == NULL) { - free(dirp); - close(fd); - return (NULL); - } - ddptr = buf + (len - space); - } - - n = getdirentries(fd, ddptr, space, &dirp->dd_seek); - if (n > 0) { - ddptr += n; - space -= n; - } - } while (n > 0); - - ddeptr = ddptr; - flags |= __DTF_READALL; - - /* - * Re-open the directory. - * This has the effect of rewinding back to the - * top of the union stack and is needed by - * programs which plan to fchdir to a descriptor - * which has also been read -- see fts.c. - */ - if (flags & DTF_REWIND) { - (void) close(fd); - if ((fd = open(name, O_RDONLY)) == -1) { - free(buf); - free(dirp); - return (NULL); - } - } - - /* - * There is now a buffer full of (possibly) duplicate - * names. - */ - dirp->dd_buf = buf; - - /* - * Go round this loop twice... - * - * Scan through the buffer, counting entries. - * On the second pass, save pointers to each one. - * Then sort the pointers and remove duplicate names. - */ - for (dpv = 0;;) { - n = 0; - ddptr = buf; - while (ddptr < ddeptr) { - struct dirent *dp; - - dp = (struct dirent *) ddptr; - if ((int)dp & 03) - break; - if ((dp->d_reclen <= 0) || - (dp->d_reclen > (ddeptr + 1 - ddptr))) - break; - ddptr += dp->d_reclen; - if (dp->d_fileno) { - if (dpv) - dpv[n] = dp; - n++; - } - } - - if (dpv) { - struct dirent *xp; - - /* - * This sort must be stable. - */ - mergesort(dpv, n, sizeof(*dpv), alphasort); - - dpv[n] = NULL; - xp = NULL; - - /* - * Scan through the buffer in sort order, - * zapping the inode number of any - * duplicate names. - */ - for (n = 0; dpv[n]; n++) { - struct dirent *dp = dpv[n]; - - if ((xp == NULL) || - strcmp(dp->d_name, xp->d_name)) { - xp = dp; - } else { - dp->d_fileno = 0; - } - if (dp->d_type == DT_WHT && - (flags & DTF_HIDEW)) - dp->d_fileno = 0; - } - - free(dpv); - break; - } else { - dpv = malloc((n+1) * sizeof(struct dirent *)); - if (dpv == NULL) - break; - } - } - - dirp->dd_len = len; - dirp->dd_size = ddptr - dirp->dd_buf; - } else { - dirp->dd_len = incr; - dirp->dd_buf = malloc(dirp->dd_len); - if (dirp->dd_buf == NULL) { - free(dirp); - close (fd); - return (NULL); - } - dirp->dd_seek = 0; - flags &= ~DTF_REWIND; - } - - dirp->dd_loc = 0; - dirp->dd_fd = fd; - dirp->dd_flags = flags; - - /* - * Set up seek point for rewinddir. - */ - dirp->dd_rewind = telldir(dirp); - - return (dirp); -} - -/* - * Open a directory. - */ -DIR *opendir(const char *name) -{ - return (__opendir2(name, DTF_HIDEW|DTF_NODUP)); -} diff --git a/gen.subproj/pause.c b/gen.subproj/pause.c deleted file mode 100644 index fea8bc1..0000000 --- a/gen.subproj/pause.c +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1983, 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 -#include - -/* - * Backwards compatible pause. - */ -int -pause() -{ - - return sigpause(sigblock(0L)); -} diff --git a/gen.subproj/popen.c b/gen.subproj/popen.c deleted file mode 100644 index 885d6c6..0000000 --- a/gen.subproj/popen.c +++ /dev/null @@ -1,205 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1988, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software written by Ken Arnold and - * published in UNIX Review, Vol. 6, No. 8. - * - * 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 -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#define environ *(_NSGetEnviron()) - -static struct pid { - struct pid *next; - FILE *fp; - pid_t pid; -} *pidlist; - -FILE * -popen(command, type) - const char *command, *type; -{ - struct pid *cur; - FILE *iop; - int pdes[2], pid, twoway; - char *argv[4]; - struct pid *p; - - if (strchr(type, '+')) { - twoway = 1; - type = "r+"; - if (socketpair(AF_UNIX, SOCK_STREAM, 0, pdes) < 0) - return (NULL); - } else { - twoway = 0; - if ((*type != 'r' && *type != 'w') || type[1]) - return (NULL); - } - if (pipe(pdes) < 0) - return (NULL); - - if ((cur = malloc(sizeof(struct pid))) == NULL) { - (void)close(pdes[0]); - (void)close(pdes[1]); - return (NULL); - } - - argv[0] = "sh"; - argv[1] = "-c"; - argv[2] = (char *)command; - argv[3] = NULL; - - switch (pid = vfork()) { - case -1: /* Error. */ - (void)close(pdes[0]); - (void)close(pdes[1]); - free(cur); - return (NULL); - /* NOTREACHED */ - case 0: /* Child. */ - if (*type == 'r') { - /* - * The _dup2() to STDIN_FILENO is repeated to avoid - * writing to pdes[1], which might corrupt the - * parent's copy. This isn't good enough in - * general, since the _exit() is no return, so - * the compiler is free to corrupt all the local - * variables. - */ - (void)close(pdes[0]); - if (pdes[1] != STDOUT_FILENO) { - (void)dup2(pdes[1], STDOUT_FILENO); - (void)close(pdes[1]); - if (twoway) - (void)dup2(STDOUT_FILENO, STDIN_FILENO); - } else if (twoway && (pdes[1] != STDIN_FILENO)) - (void)dup2(pdes[1], STDIN_FILENO); - } else { - if (pdes[0] != STDIN_FILENO) { - (void)dup2(pdes[0], STDIN_FILENO); - (void)close(pdes[0]); - } - (void)close(pdes[1]); - } - for (p = pidlist; p; p = p->next) { - (void)close(fileno(p->fp)); - } - execve(_PATH_BSHELL, argv, environ); - _exit(127); - /* NOTREACHED */ - } - - /* Parent; assume fdopen can't fail. */ - if (*type == 'r') { - iop = fdopen(pdes[0], type); - (void)close(pdes[1]); - } else { - iop = fdopen(pdes[1], type); - (void)close(pdes[0]); - } - - /* Link into list of file descriptors. */ - cur->fp = iop; - cur->pid = pid; - cur->next = pidlist; - pidlist = cur; - - return (iop); -} - -/* - * pclose -- - * Pclose returns -1 if stream is not associated with a `popened' command, - * if already `pclosed', or waitpid returns an error. - */ -int -pclose(iop) - FILE *iop; -{ - register struct pid *cur, *last; - int pstat; - pid_t pid; - - /* Find the appropriate file pointer. */ - for (last = NULL, cur = pidlist; cur; last = cur, cur = cur->next) - if (cur->fp == iop) - break; - if (cur == NULL) - return (-1); - - (void)fclose(iop); - - do { - pid = wait4(cur->pid, &pstat, 0, (struct rusage *)0); - } while (pid == -1 && errno == EINTR); - - /* Remove the entry from the linked list. */ - if (last == NULL) - pidlist = cur->next; - else - last->next = cur->next; - free(cur); - - return (pid == -1 ? -1 : pstat); -} diff --git a/gen.subproj/ppc.subproj/Makefile b/gen.subproj/ppc.subproj/Makefile deleted file mode 100644 index 0c95a7b..0000000 --- a/gen.subproj/ppc.subproj/Makefile +++ /dev/null @@ -1,53 +0,0 @@ -# -# Generated by the NeXT Project Builder. -# -# NOTE: Do NOT change this file -- Project Builder maintains it. -# -# Put all of your customizations in files called Makefile.preamble -# and Makefile.postamble (both optional), and Makefile will include them. -# - -NAME = ppc - -PROJECTVERSION = 2.8 -PROJECT_TYPE = Component - -HFILES = fp.h genassym.h - -OTHERLINKED = abs.s blockmoof.s bzero.s ffs.s mcount.s \ - strlen.s - -CFILES = bcmp.c ecvt.c insque.c isinf.c remque.c setjmperr.c\ - strcat.c strcpy.c strncat.c strncmp.c strncpy.c - -OTHERSRCS = Makefile.preamble Makefile Makefile.postamble - -OTHERLINKEDOFILES = abs.o blockmoof.o bzero.o ffs.o mcount.o \ - strlen.o - -MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles -CODE_GEN_STYLE = DYNAMIC -MAKEFILE = subproj.make -LIBS = -DEBUG_LIBS = $(LIBS) -PROF_LIBS = $(LIBS) - - - - -NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc -WINDOWS_OBJCPLUS_COMPILER = $(DEVDIR)/gcc -PDO_UNIX_OBJCPLUS_COMPILER = $(NEXTDEV_BIN)/gcc -NEXTSTEP_JAVA_COMPILER = /usr/bin/javac -WINDOWS_JAVA_COMPILER = $(JDKBINDIR)/javac.exe -PDO_UNIX_JAVA_COMPILER = $(JDKBINDIR)/javac - -include $(MAKEFILEDIR)/platform.make - --include Makefile.preamble - -include $(MAKEFILEDIR)/$(MAKEFILE) - --include Makefile.postamble - --include Makefile.dependencies diff --git a/gen.subproj/ppc.subproj/Makefile.postamble b/gen.subproj/ppc.subproj/Makefile.postamble deleted file mode 100644 index 411cde6..0000000 --- a/gen.subproj/ppc.subproj/Makefile.postamble +++ /dev/null @@ -1,100 +0,0 @@ -############################################################################### -# Makefile.postamble -# Copyright 1997, Apple Computer, Inc. -# -# Use this makefile, which is imported after all other makefiles, to -# override attributes for a project's Makefile environment. This allows you -# to take advantage of the environment set up by the other Makefiles. -# You can also define custom rules at the end of this file. -# -############################################################################### -# -# These variables are exported by the standard makefiles and can be -# used in any customizations you make. They are *outputs* of -# the Makefiles and should be used, not set. -# -# PRODUCTS: products to install. All of these products will be placed in -# the directory $(DSTROOT)$(INSTALLDIR) -# GLOBAL_RESOURCE_DIR: The directory to which resources are copied. -# LOCAL_RESOURCE_DIR: The directory to which localized resources are copied. -# OFILE_DIR: Directory into which .o object files are generated. -# DERIVED_SRC_DIR: Directory used for all other derived files -# -# ALL_CFLAGS: flags to pass when compiling .c files -# ALL_MFLAGS: flags to pass when compiling .m files -# ALL_CCFLAGS: flags to pass when compiling .cc, .cxx, and .C files -# ALL_MMFLAGS: flags to pass when compiling .mm, .mxx, and .M files -# ALL_PRECOMPFLAGS: flags to pass when precompiling .h files -# ALL_LDFLAGS: flags to pass when linking object files -# ALL_LIBTOOL_FLAGS: flags to pass when libtooling object files -# ALL_PSWFLAGS: flags to pass when processing .psw and .pswm (pswrap) files -# ALL_RPCFLAGS: flags to pass when processing .rpc (rpcgen) files -# ALL_YFLAGS: flags to pass when processing .y (yacc) files -# ALL_LFLAGS: flags to pass when processing .l (lex) files -# -# NAME: name of application, bundle, subproject, palette, etc. -# LANGUAGES: langages in which the project is written (default "English") -# English_RESOURCES: localized resources (e.g. nib's, images) of project -# GLOBAL_RESOURCES: non-localized resources of project -# -# SRCROOT: base directory in which to place the new source files -# SRCPATH: relative path from SRCROOT to present subdirectory -# -# INSTALLDIR: Directory the product will be installed into by 'install' target -# PUBLIC_HDR_INSTALLDIR: where to install public headers. Don't forget -# to prefix this with DSTROOT when you use it. -# PRIVATE_HDR_INSTALLDIR: where to install private headers. Don't forget -# to prefix this with DSTROOT when you use it. -# -# EXECUTABLE_EXT: Executable extension for the platform (i.e. .exe on Windows) -# -############################################################################### - -# Some compiler flags can be overridden here for certain build situations. -# -# WARNING_CFLAGS: flag used to set warning level (defaults to -Wmost) -# DEBUG_SYMBOLS_CFLAGS: debug-symbol flag passed to all builds (defaults -# to -g) -# DEBUG_BUILD_CFLAGS: flags passed during debug builds (defaults to -DDEBUG) -# OPTIMIZE_BUILD_CFLAGS: flags passed during optimized builds (defaults -# to -O) -# PROFILE_BUILD_CFLAGS: flags passed during profile builds (defaults -# to -pg -DPROFILE) -# LOCAL_DIR_INCLUDE_DIRECTIVE: flag used to add current directory to -# the include path (defaults to -I.) -# DEBUG_BUILD_LDFLAGS, OPTIMIZE_BUILD_LDFLAGS, PROFILE_BUILD_LDFLAGS: flags -# passed to ld/libtool (defaults to nothing) - - -# Library and Framework projects only: -# INSTALL_NAME_DIRECTIVE: This directive ensures that executables linked -# against the framework will run against the correct version even if -# the current version of the framework changes. You may override this -# to "" as an alternative to using the DYLD_LIBRARY_PATH during your -# development cycle, but be sure to restore it before installing. - - -# Ownership and permissions of files installed by 'install' target - -#INSTALL_AS_USER = root - # User/group ownership -#INSTALL_AS_GROUP = wheel - # (probably want to set both of these) -#INSTALL_PERMISSIONS = - # If set, 'install' chmod's executable to this - - -# Options to strip. Note: -S strips debugging symbols (executables can be stripped -# down further with -x or, if they load no bundles, with no options at all). - -#STRIPFLAGS = -S - - -######################################################################### -# Put rules to extend the behavior of the standard Makefiles here. Include them in -# the dependency tree via cvariables like AFTER_INSTALL in the Makefile.preamble. -# -# You should avoid redefining things like "install" or "app", as they are -# owned by the top-level Makefile API and no context has been set up for where -# derived files should go. -# diff --git a/gen.subproj/ppc.subproj/Makefile.preamble b/gen.subproj/ppc.subproj/Makefile.preamble deleted file mode 100644 index 7211b2b..0000000 --- a/gen.subproj/ppc.subproj/Makefile.preamble +++ /dev/null @@ -1,137 +0,0 @@ -############################################################################### -# Makefile.preamble -# Copyright 1997, Apple Computer, Inc. -# -# Use this makefile for configuring the standard application makefiles -# associated with ProjectBuilder. It is included before the main makefile. -# In Makefile.preamble you set attributes for a project, so they are available -# to the project's makefiles. In contrast, you typically write additional rules or -# override built-in behavior in the Makefile.postamble. -# -# Each directory in a project tree (main project plus subprojects) should -# have its own Makefile.preamble and Makefile.postamble. -############################################################################### -# -# Before the main makefile is included for this project, you may set: -# -# MAKEFILEDIR: Directory in which to find $(MAKEFILE) -# MAKEFILE: Top level mechanism Makefile (e.g., app.make, bundle.make) - -# Compiler/linker flags added to the defaults: The OTHER_* variables will be -# inherited by all nested sub-projects, but the LOCAL_ versions of the same -# variables will not. Put your -I, -D, -U, and -L flags in ProjectBuilder's -# Build Attributes inspector if at all possible. To override the default flags -# that get passed to ${CC} (e.g. change -O to -O2), see Makefile.postamble. The -# variables below are *inputs* to the build process and distinct from the override -# settings done (less often) in the Makefile.postamble. -# -# OTHER_CFLAGS, LOCAL_CFLAGS: additional flags to pass to the compiler -# Note that $(OTHER_CFLAGS) and $(LOCAL_CFLAGS) are used for .h, ...c, .m, -# .cc, .cxx, .C, and .M files. There is no need to respecify the -# flags in OTHER_MFLAGS, etc. -# OTHER_MFLAGS, LOCAL_MFLAGS: additional flags for .m files -# OTHER_CCFLAGS, LOCAL_CCFLAGS: additional flags for .cc, .cxx, and ...C files -# OTHER_MMFLAGS, LOCAL_MMFLAGS: additional flags for .mm and .M files -# OTHER_PRECOMPFLAGS, LOCAL_PRECOMPFLAGS: additional flags used when -# precompiling header files -# OTHER_LDFLAGS, LOCAL_LDFLAGS: additional flags passed to ld and libtool -# OTHER_PSWFLAGS, LOCAL_PSWFLAGS: additional flags passed to pswrap -# OTHER_RPCFLAGS, LOCAL_RPCFLAGS: additional flags passed to rpcgen -# OTHER_YFLAGS, LOCAL_YFLAGS: additional flags passed to yacc -# OTHER_LFLAGS, LOCAL_LFLAGS: additional flags passed to lex - -# These variables provide hooks enabling you to add behavior at almost every -# stage of the make: -# -# BEFORE_PREBUILD: targets to build before installing headers for a subproject -# AFTER_PREBUILD: targets to build after installing headers for a subproject -# BEFORE_BUILD_RECURSION: targets to make before building subprojects -# BEFORE_BUILD: targets to make before a build, but after subprojects -# AFTER_BUILD: targets to make after a build -# -# BEFORE_INSTALL: targets to build before installing the product -# AFTER_INSTALL: targets to build after installing the product -# BEFORE_POSTINSTALL: targets to build before postinstalling every subproject -# AFTER_POSTINSTALL: targts to build after postinstalling every subproject -# -# BEFORE_INSTALLHDRS: targets to build before installing headers for a -# subproject -# AFTER_INSTALLHDRS: targets to build after installing headers for a subproject -# BEFORE_INSTALLSRC: targets to build before installing source for a subproject -# AFTER_INSTALLSRC: targets to build after installing source for a subproject -# -# BEFORE_DEPEND: targets to build before building dependencies for a -# subproject -# AFTER_DEPEND: targets to build after building dependencies for a -# subproject -# -# AUTOMATIC_DEPENDENCY_INFO: if YES, then the dependency file is -# updated every time the project is built. If NO, the dependency -# file is only built when the depend target is invoked. - -# Framework-related variables: -# FRAMEWORK_DLL_INSTALLDIR: On Windows platforms, this variable indicates -# where to put the framework's DLL. This variable defaults to -# $(INSTALLDIR)/../Executables - -# Library-related variables: -# PUBLIC_HEADER_DIR: Determines where public exported header files -# should be installed. Do not include $(DSTROOT) in this value -- -# it is prefixed automatically. For library projects you should -# set this to something like /Developer/Headers/$(NAME). Do not set -# this variable for framework projects unless you do not want the -# header files included in the framework. -# PRIVATE_HEADER_DIR: Determines where private exported header files -# should be installed. Do not include $(DSTROOT) in this value -- -# it is prefixed automatically. -# LIBRARY_STYLE: This may be either STATIC or DYNAMIC, and determines -# whether the libraries produced are statically linked when they -# are used or if they are dynamically loadable. This defaults to -# DYNAMIC. -# LIBRARY_DLL_INSTALLDIR: On Windows platforms, this variable indicates -# where to put the library's DLL. This variable defaults to -# $(INSTALLDIR)/../Executables -# -# INSTALL_AS_USER: owner of the intalled products (default root) -# INSTALL_AS_GROUP: group of the installed products (default wheel) -# INSTALL_PERMISSIONS: permissions of the installed product (default o+rX) -# -# OTHER_RECURSIVE_VARIABLES: The names of variables which you want to be -# passed on the command line to recursive invocations of make. Note that -# the values in OTHER_*FLAGS are inherited by subprojects automatically -- -# you do not have to (and shouldn't) add OTHER_*FLAGS to -# OTHER_RECURSIVE_VARIABLES. - -# Additional headers to export beyond those in the PB.project: -# OTHER_PUBLIC_HEADERS -# OTHER_PROJECT_HEADERS -# OTHER_PRIVATE_HEADERS - -# Additional files for the project's product: <> -# OTHER_RESOURCES: (non-localized) resources for this project -# OTHER_OFILES: relocatables to be linked into this project -# OTHER_LIBS: more libraries to link against -# OTHER_PRODUCT_DEPENDS: other dependencies of this project -# OTHER_SOURCEFILES: other source files maintained by .pre/postamble -# OTHER_GARBAGE: additional files to be removed by `make clean' - -# Set this to YES if you don't want a final libtool call for a library/framework. -# BUILD_OFILES_LIST_ONLY - -# To include a version string, project source must exist in a directory named -# $(NAME).%d[.%d][.%d] and the following line must be uncommented. -# OTHER_GENERATED_OFILES = $(VERS_OFILE) - -# This definition will suppress stripping of debug symbols when an executable -# is installed. By default it is YES. -# STRIP_ON_INSTALL = NO - -# Uncomment to suppress generation of a KeyValueCoding index when installing -# frameworks (This index is used by WOB and IB to determine keys available -# for an object). Set to YES by default. -# PREINDEX_FRAMEWORK = NO - -# Change this definition to install projects somewhere other than the -# standard locations. NEXT_ROOT defaults to "C:/Apple" on Windows systems -# and "" on other systems. -INCLUDED_ARCHS = ppc diff --git a/gen.subproj/ppc.subproj/PB.project b/gen.subproj/ppc.subproj/PB.project deleted file mode 100644 index 6fec101..0000000 --- a/gen.subproj/ppc.subproj/PB.project +++ /dev/null @@ -1,41 +0,0 @@ -{ - DYNAMIC_CODE_GEN = YES; - FILESTABLE = { - H_FILES = (fp.h, genassym.h); - OTHER_LINKED = ( - abs.s, - bcmp.c, - blockmoof.s, - bzero.s, - ecvt.c, - ffs.s, - insque.c, - isinf.c, - mcount.s, - remque.c, - setjmperr.c, - strcat.c, - strcpy.c, - strlen.s, - strncat.c, - strncmp.c, - strncpy.c - ); - OTHER_SOURCES = (Makefile.preamble, Makefile, Makefile.postamble); - SUBPROJECTS = (); - }; - LANGUAGE = English; - MAKEFILEDIR = "$(MAKEFILEPATH)/pb_makefiles"; - NEXTSTEP_BUILDTOOL = /bin/gnumake; - NEXTSTEP_JAVA_COMPILER = /usr/bin/javac; - NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc; - PDO_UNIX_BUILDTOOL = $NEXT_ROOT/Developer/bin/make; - PDO_UNIX_JAVA_COMPILER = "$(JDKBINDIR)/javac"; - PDO_UNIX_OBJCPLUS_COMPILER = "$(NEXTDEV_BIN)/gcc"; - PROJECTNAME = ppc; - PROJECTTYPE = Component; - PROJECTVERSION = 2.8; - WINDOWS_BUILDTOOL = $NEXT_ROOT/Developer/Executables/make; - WINDOWS_JAVA_COMPILER = "$(JDKBINDIR)/javac.exe"; - WINDOWS_OBJCPLUS_COMPILER = "$(DEVDIR)/gcc"; -} diff --git a/gen.subproj/ppc.subproj/abs.s b/gen.subproj/ppc.subproj/abs.s deleted file mode 100644 index 3d7ae3c..0000000 --- a/gen.subproj/ppc.subproj/abs.s +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* Copyright (c) 1992,1997 NeXT Software, Inc. All rights reserved. - * - * File: libc/gen/ppc/abs.s - * Author: Derek B Clegg, NeXT Software, Inc. - * - * HISTORY - * 24-Jan-1997 Umesh Vaishampayan (umeshv@NeXT.com) - * Ported to PPC. - * 10-Nov-92 Derek B Clegg (dclegg@next.com) - * Created. - * 13-Jan-93 Derek B Clegg (dclegg@next.com) - * Optimized. - * - * ANSI X3.159-1989: - * int abs(int j); - * - * Description: - * The `abs' function computes the absolute value of an integer `j'. - * If the result cannot be represented, the behavior is undefined. - * Returns: - * The `abs' function returns the absolute value. - */ -#include -#include - -/* We calculate abs(x) as - * s = x >> 31; - * y = x + s; - * return y ^ s; - * - * If x >= 0, then s = 0, so clearly we return x. On the other hand, if - * x < 0, then we may write x as ~z + 1, where z = -x. In this case, - * s = -1, so y = x - 1 = ~z, and hence we return -1 ^ (x - 1) = -1 ^ ~z - * = z = -x. - */ -LEAF(_abs) - srawi a1,a0,31 - add a2,a1,a0 - xor a0,a2,a1 - blr -END(_abs) diff --git a/gen.subproj/ppc.subproj/bcmp.c b/gen.subproj/ppc.subproj/bcmp.c deleted file mode 100644 index b9fdb04..0000000 --- a/gen.subproj/ppc.subproj/bcmp.c +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* Copyright (c) 1992, 1997 NeXT Software, Inc. All rights reserved. - * - * File: libc/gen/ppc/bcmp.c - * - * Byte-compare routine. - * - * HISTORY - * 24-Jan-1997 Umesh Vaishampayan (umeshv@NeXT.com) - * Ported to PPC. - */ - -#import - -#undef bcmp - -int -bcmp(const void *b1, const void *b2, size_t length) -{ - return memcmp(b1, b2, length); -} diff --git a/gen.subproj/ppc.subproj/blockmoof.s b/gen.subproj/ppc.subproj/blockmoof.s deleted file mode 100755 index 947e7f0..0000000 --- a/gen.subproj/ppc.subproj/blockmoof.s +++ /dev/null @@ -1,940 +0,0 @@ -/* - * Copyright (c) 1992-2001 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@ - */ -#include - -// ================================================================================================= -// *** The easiest way to assemble things on Mac OS X is via "cc", so this uses #defines and such. -// ================================================================================================= - -// Keep track of whether we have Altivec -// This gets set in pthread_init() - -.data -.align 2 -.globl __cpu_has_altivec -__cpu_has_altivec: -.long 0 - -.text -.align 2 -.globl _bcopy -.globl _memcpy -.globl _memmove - -_bcopy: - mr r2,r4 // Since bcopy uses (src,dest,count), swap r3,r4 - mr r4,r3 - mr r3,r2 -_memcpy: -_memmove: - mr r2,r3 // Store dest ptr in r2 to preserve r3 on return - -// ------------------ -// Standard registers - -#define rs r4 -#define rd r2 -#define rc r5 - -// Should we bother using Altivec? - - cmpwi r5, 128 - blt+ LScalar - -// Determine whether we have Altivec enabled - - mflr r0 - bcl 20,31,1f -1: - mflr r6 - mtlr r0 - addis r6, r6, ha16(__cpu_has_altivec - 1b) - lwz r6, lo16(__cpu_has_altivec - 1b)(r6) - cmpwi r6, 0 - bne+ LAltivec - -// ================================================================================================= - -// ***************************************** -// * S c a l a r B l o c k M o o f D a t a * -// ***************************************** -// -// This is the scalar (non-AltiVec) version of BlockMoofData. -// -// void ScalarBlockMoofData (ptr sou, ptr dest, long len) -// void ScalarBlockMoofDataUncached (ptr sou, ptr dest, long len) -// -// -// Calling Sequence: r3 = source pointer -// r4 = destination pointer -// r5 = length in bytes -// -// Uses: all volatile registers. - -LScalar: - cmplwi cr7,rc,32 // length <= 32 bytes? - cmplw cr6,rd,rs // up or down? - mr. r0,rc // copy to r0 for MoveShort, and test for negative - bgt cr7,Lbm1 // skip if count > 32 - -// Handle short moves (<=32 bytes.) - - beq cr7,LMove32 // special case 32-byte blocks - blt cr6,LMoveDownShort // move down in memory and return - add rs,rs,rc // moving up (right-to-left), so adjust pointers - add rd,rd,rc - b LMoveUpShort // move up in memory and return - -// Handle long moves (>32 bytes.) - -Lbm1: - beqlr cr6 // rs==rd, so nothing to move - bltlr cr0 // length<0, so ignore call and return - mflr r12 // save return address - bge cr6,Lbm2 // rd>=rs, so move up - -// Long moves down (left-to-right.) - - neg r6,rd // start to 32-byte-align destination - andi. r0,r6,0x1F // r0 <- bytes to move to align destination - bnel LMoveDownShort // align destination if necessary - bl LMoveDownLong // move 32-byte chunks down - andi. r0,rc,0x1F // done? - mtlr r12 // restore caller's return address - bne LMoveDownShort // move trailing leftover bytes and done - blr // no leftovers, so done - -// Long moves up (right-to-left.) - -Lbm2: - add rs,rs,rc // moving up (right-to-left), so adjust pointers - add rd,rd,rc - andi. r0,rd,0x1F // r0 <- bytes to move to align destination - bnel LMoveUpShort // align destination if necessary - bl LMoveUpLong // move 32-byte chunks up - andi. r0,rc,0x1F // done? - mtlr r12 // restore caller's return address - bne LMoveUpShort // move trailing leftover bytes and done - blr // no leftovers, so done - -// *************** -// * M O V E 3 2 * -// *************** -// -// Special case subroutine to move a 32-byte block. MoveDownShort and -// MoveUpShort only handle 0..31 bytes, and we believe 32 bytes is too -// common a case to send it through the general purpose long-block code. -// Since it moves both up and down, we must load all 32 bytes before -// storing any. -// -// Calling Sequence: rs = source ptr -// rd = destination ptr -// -// Uses: r0,r5-r11. -// - -LMove32: - lwz r0,0(rs) - lwz r5,4(rs) - lwz r6,8(rs) - lwz r7,12(rs) - lwz r8,16(rs) - lwz r9,20(rs) - lwz r10,24(rs) - lwz r11,28(rs) - stw r0,0(rd) - stw r5,4(rd) - stw r6,8(rd) - stw r7,12(rd) - stw r8,16(rd) - stw r9,20(rd) - stw r10,24(rd) - stw r11,28(rd) - blr - - -// ************************* -// * M o v e U p S h o r t * -// ************************* -// -// Subroutine called to move <32 bytes up in memory (ie, right-to-left). -// -// Entry conditions: rs = last byte moved from source (right-to-left) -// rd = last byte moved into destination -// r0 = #bytes to move (0..31) -// -// Exit conditions: rs = updated source ptr -// rd = updated destination ptr -// rc = decremented by #bytes moved -// -// Uses: r0,r6,r7,r8,cr7. -// - -LMoveUpShort: - andi. r6,r0,0x10 // test 0x10 bit in length - mtcrf 0x1,r0 // move count to cr7 so we can test bits - sub rc,rc,r0 // decrement count of bytes remaining to be moved - beq Lmus1 // skip if 0x10 bit in length is 0 - lwzu r0,-16(rs) // set, so copy up 16 bytes - lwz r6,4(rs) - lwz r7,8(rs) - lwz r8,12(rs) - stwu r0,-16(rd) - stw r6,4(rd) - stw r7,8(rd) - stw r8,12(rd) - -Lmus1: - bf 28,Lmus2 // test 0x08 bit - lwzu r0,-8(rs) - lwz r6,4(rs) - stwu r0,-8(rd) - stw r6,4(rd) - -Lmus2: - bf 29,Lmus3 // test 0x4 bit - lwzu r0,-4(rs) - stwu r0,-4(rd) - -Lmus3: - bf 30,Lmus4 // test 0x2 bit - lhzu r0,-2(rs) - sthu r0,-2(rd) - -Lmus4: - bflr 31 // test 0x1 bit, return if 0 - lbzu r0,-1(rs) - stbu r0,-1(rd) - blr - - -// ***************************** -// * M o v e D o w n S h o r t * -// ***************************** -// -// Subroutine called to move <32 bytes down in memory (ie, left-to-right). -// -// Entry conditions: rs = source pointer -// rd = destination pointer -// r0 = #bytes to move (0..31) -// -// Exit conditions: rs = ptr to 1st byte not moved -// rd = ptr to 1st byte not moved -// rc = decremented by #bytes moved -// -// Uses: r0,r6,r7,r8,cr7. -// - -LMoveDownShort: - andi. r6,r0,0x10 // test 0x10 bit in length - mtcrf 0x1,r0 // move count to cr7 so we can test bits - sub rc,rc,r0 // decrement count of bytes remaining to be moved - beq Lmds1 // skip if 0x10 bit in length is 0 - lwz r0,0(rs) // set, so copy up 16 bytes - lwz r6,4(rs) - lwz r7,8(rs) - lwz r8,12(rs) - addi rs,rs,16 - stw r0,0(rd) - stw r6,4(rd) - stw r7,8(rd) - stw r8,12(rd) - addi rd,rd,16 - -Lmds1: - bf 28,Lmds2 // test 0x08 bit - lwz r0,0(rs) - lwz r6,4(rs) - addi rs,rs,8 - stw r0,0(rd) - stw r6,4(rd) - addi rd,rd,8 - -Lmds2: - bf 29,Lmds3 // test 0x4 bit - lwz r0,0(rs) - addi rs,rs,4 - stw r0,0(rd) - addi rd,rd,4 - -Lmds3: - bf 30,Lmds4 // test 0x2 bit - lhz r0,0(rs) - addi rs,rs,2 - sth r0,0(rd) - addi rd,rd,2 - -Lmds4: - bflr 31 // test 0x1 bit, return if 0 - lbz r0,0(rs) - addi rs,rs,1 - stb r0,0(rd) - addi rd,rd,1 - blr - - -// *********************** -// * M o v e U p L o n g * -// *********************** -// -// Subroutine to move 32-byte chunks of memory up (ie, right-to-left.) -// The destination is known to be 32-byte aligned, but the source is -// *not* necessarily aligned. -// -// Entry conditions: rs = last byte moved from source (right-to-left) -// rd = last byte moved into destination -// rc = count of bytes to move -// cr = crCached set iff destination is cacheable -// -// Exit conditions: rs = updated source ptr -// rd = updated destination ptr -// rc = low order 8 bits of count of bytes to move -// -// Uses: r0,r5-r11,fr0-fr3,ctr,cr0,cr6,cr7. -// - -LMoveUpLong: - srwi. r11,rc,5 // r11 <- #32 byte chunks to move - mtctr r11 // prepare loop count - beqlr // return if no chunks to move - andi. r0,rs,7 // is source at least doubleword aligned? - beq Lmup3 // yes, can optimize this case - mtcrf 0x1,rc // save low bits of count - mtcrf 0x2,rc // (one cr at a time, as 604 prefers) - -Lmup1: // loop over each 32-byte-chunk - lwzu r0,-32(rs) - subi rd,rd,32 // prepare destination address for 'dcbz' - lwz r5,4(rs) - lwz r6,8(rs) - lwz r7,12(rs) - lwz r8,16(rs) - lwz r9,20(rs) - lwz r10,24(rs) - lwz r11,28(rs) - stw r0,0(rd) - stw r5,4(rd) - stw r6,8(rd) - stw r7,12(rd) - stw r8,16(rd) - stw r9,20(rd) - stw r10,24(rd) - stw r11,28(rd) - bdnz Lmup1 - mfcr rc // restore low bits of count - blr // return to caller - -// Aligned operands, so use d.p. floating point registers to move data. - -Lmup3: - lfdu f0,-32(rs) - subi rd,rd,32 // prepare destination address for 'dcbz' - lfd f1,8(rs) - lfd f2,16(rs) - lfd f3,24(rs) - stfd f0,0(rd) - stfd f1,8(rd) - stfd f2,16(rd) - stfd f3,24(rd) - bdnz Lmup3 - blr // return to caller - - -// *************************** -// * M o v e D o w n L o n g * -// *************************** -// -// Subroutine to move 32-byte chunks of memory down (ie, left-to-right.) -// The destination is known to be 32-byte aligned, but the source is -// *not* necessarily aligned. -// -// Entry conditions: rs = source ptr (next byte to move) -// rd = dest ptr (next byte to move into) -// rc = count of bytes to move -// cr = crCached set iff destination is cacheable -// -// Exit conditions: rs = updated source ptr -// rd = updated destination ptr -// rc = low order 8 bits of count of bytes to move -// -// Uses: r0,r5-r11,fr0-fr3,ctr,cr0,cr6,cr7. -// - -LMoveDownLong: - srwi. r11,rc,5 // r11 <- #32 byte chunks to move - mtctr r11 // prepare loop count - beqlr // return if no chunks to move - andi. r0,rs,7 // is source at least doubleword aligned? - beq Lmdown3 // yes, can optimize this case - mtcrf 0x1,rc // save low 8 bits of count - mtcrf 0x2,rc // (one cr at a time, as 604 prefers) - -Lmdown1: // loop over each 32-byte-chunk - lwz r0,0(rs) - lwz r5,4(rs) - lwz r6,8(rs) - lwz r7,12(rs) - lwz r8,16(rs) - lwz r9,20(rs) - lwz r10,24(rs) - lwz r11,28(rs) - stw r0,0(rd) - stw r5,4(rd) - stw r6,8(rd) - stw r7,12(rd) - stw r8,16(rd) - stw r9,20(rd) - addi rs,rs,32 - stw r10,24(rd) - stw r11,28(rd) - addi rd,rd,32 - bdnz Lmdown1 - mfcr rc // restore low bits of count - blr // return to caller - -// Aligned operands, so use d.p. floating point registers to move data. - -Lmdown3: - lfd f0,0(rs) - lfd f1,8(rs) - lfd f2,16(rs) - lfd f3,24(rs) - addi rs,rs,32 - stfd f0,0(rd) - stfd f1,8(rd) - stfd f2,16(rd) - stfd f3,24(rd) - addi rd,rd,32 - bdnz Lmdown3 - blr // return to caller - -// -// Register use conventions are as follows: -// -// r0 - temp -// r6 - copy of VMX SPR at entry -// r7 - temp -// r8 - constant -1 (also temp and a string op buffer) -// r9 - constant 16 or -17 (also temp and a string op buffer) -// r10- constant 32 or -33 (also temp and a string op buffer) -// r11- constant 48 or -49 (also temp and a string op buffer) -// r12- chunk count ("c") in long moves -// -// v0 - vp - permute vector -// v1 - va - 1st quadword of source -// v2 - vb - 2nd quadword of source -// v3 - vc - 3rd quadword of source -// v4 - vd - 4th quadword of source -// v5 - vx - temp -// v6 - vy - temp -// v7 - vz - temp - -#define vp v0 -#define va v1 -#define vb v2 -#define vc v3 -#define vd v4 -#define vx v5 -#define vy v6 -#define vz v7 - -#define VRSave 256 - -// kShort should be the crossover point where the long algorithm is faster than the short. -// WARNING: kShort must be >= 64 - -// Yes, I know, we just checked rc > 128 to get here... - -#define kShort 128 -LAltivec: - cmpwi cr1,rc,kShort //(1) too short to bother using vector regs? - sub. r0,rd,rs //(1) must move reverse if (rd-rs)<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><> -// <><> S H O R T O P E R A N D S <><> -// <><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><> - -LAlignedLoop: // word aligned operands (the common case) - lfd f0,0(rs) //(1) - lfd f1,8(rs) //(2) - addi rs,rs,16 //(2) - stfd f0,0(rd) //(3) - stfd f1,8(rd) //(4) - addi rd,rd,16 //(4) - bdnz LAlignedLoop //(4) - -Leftovers: - beqlr- cr7 //(8) done if r7==0, ie no leftover bytes - mtxer r7 //(9) count of bytes to move (1-15) - lswx r8,0,rs - stswx r8,0,rd - blr //(17) - -LUnalignedLoop: // not word aligned, cannot use lfd/stfd - lwz r8,0(rs) //(1) - lwz r9,4(rs) //(2) - lwz r10,8(rs) //(3) - lwz r11,12(rs) //(4) - addi rs,rs,16 //(4) - stw r8,0(rd) //(5) - stw r9,4(rd) //(6) - stw r10,8(rd) //(7) - stw r11,12(rd) //(8) - addi rd,rd,16 //(8) - bdnz LUnalignedLoop //(8) - - b Leftovers - - -// <><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><> -// <><> S H O R T R E V E R S E M O V E S <><> -// <><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><> - - // cr0 & r9 <- #doublewords to move (>=0) - // cr1 <- beq if word aligned - // r7 <- #leftover bytes to move (0-15) - -LShortReverse: - cmpwi cr7,r7,0 // leftover bytes? - add rs,rs,rc // point 1 past end of string for reverse moves - add rd,rd,rc - beq- LeftoversReverse // r9==0, ie no words to move - mtctr r9 // set up for quadword loop - bne- cr1,LUnalignedLoopReverse - -LAlignedLoopReverse: // word aligned, so use lfd/stfd - lfd f0,-8(rs) - lfdu f1,-16(rs) - stfd f0,-8(rd) - stfdu f1,-16(rd) - bdnz LAlignedLoopReverse - -LeftoversReverse: - beqlr- cr7 // done if r7==0, ie no leftover bytes - mtxer r7 // count of bytes to move (1-15) - neg r7,r7 // index back by #bytes - lswx r8,r7,rs - stswx r8,r7,rd - blr - -LUnalignedLoopReverse: // not word aligned, cannot use lfd/stfd - lwz r8,-4(rs) - lwz r9,-8(rs) - lwz r10,-12(rs) - lwzu r11,-16(rs) - stw r8,-4(rd) - stw r9,-8(rd) - stw r10,-12(rd) - stwu r11,-16(rd) - bdnz LUnalignedLoopReverse - - b LeftoversReverse - -// <><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><> -// <><> L O N G O P E R A N D S <><> -// <><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><> - - // cr6 set (blt) if must move reverse - // r0 <- (rd - rs) - -LMoveLong: - mfspr r6,VRSave //(5) save caller's VMX mask register - stw r6,-4(r1) // use CR save area so we can use r6 later - neg r8,rd //(5) start to compute #bytes to fill in 1st dest quadword - rlwinm r0,r0,0,28,31 //(6) start to determine relative alignment - andi. r7,r8,0xF //(6) r7 <- #bytes to fill in 1st dest quadword - cmpwi cr7,r0,0 //(7) relatively aligned? (ie, 16 bytes apart?) - oris r9,r6,0xFF00 //(7) light bits for regs we use (v0-v7) - mtspr VRSave,r9 //(8) update live register bitmask - blt- cr6,LongReverse //(8) must move reverse direction - sub rc,rc,r7 //(9) adjust length while we wait - beq- LDest16Aligned //(9) r7==0, ie destination already quadword aligned - - // Align destination on a quadword. - - mtxer r7 //(10) set up byte count (1-15) - lswx r8,0,rs // load into r8-r11 - stswx r8,0,rd // store r8-r11 (measured latency on arthur is 7.2 cycles) - add rd,rd,r7 //(18) adjust ptrs - add rs,rs,r7 //(18) - - // Begin preparation for inner loop and "dst" stream. - -LDest16Aligned: - andi. r0,rd,0x10 //(19) is destination cache-block aligned? - li r9,16 //(19) r9 <- constant used to access 2nd quadword - li r10,32 //(20) r10<- constant used to access 3rd quadword - beq- cr7,LAligned //(20) handle relatively aligned operands - lvx va,0,rs //(20) prefetch 1st source quadword - li r11,48 //(21) r11<- constant used to access 4th quadword - lvsl vp,0,rs //(21) get permute vector to left shift - beq LDest32Aligned //(22) destination already cache-block aligned - - // Copy 16 bytes to align destination on 32-byte (cache block) boundary - // to maximize store gathering. - - lvx vb,r9,rs //(23) get 2nd source qw - subi rc,rc,16 //(23) adjust count - addi rs,rs,16 //(24) adjust source ptr - vperm vx,va,vb,vp //(25) vx <- 1st destination qw - vor va,vb,vb //(25) va <- vb - stvx vx,0,rd //(26) assuming store Q deep enough to avoid latency - addi rd,rd,16 //(26) adjust dest ptr - - // Destination 32-byte aligned, source alignment unknown. - -LDest32Aligned: - srwi. r12,rc,6 //(27) r12<- count of 64-byte chunks to move - rlwinm r7,rc,28,30,31 //(27) r7 <- count of 16-byte chunks to move - cmpwi cr1,r7,0 //(28) remember if any 16-byte chunks - rlwinm r8,r12,0,26,31 //(29) mask chunk count down to 0-63 - subi r0,r8,1 //(30) r8==0? - beq- LNoChunks //(30) r12==0, ie no chunks to move - rlwimi r8,r0,0,25,25 //(31) if r8==0, then r8 <- 64 - li r0,64 //(31) r0 <- used to get 1st quadword of next chunk - sub. r12,r12,r8 //(32) adjust chunk count, set cr0 - mtctr r8 //(32) set up loop count - li r8,96 //SKP - li r6,128 //SKP - // Inner loop for unaligned sources. We copy 64 bytes per iteration. - // We loop at most 64 times, then reprime the "dst" and loop again for - // the next 4KB. This loop is tuned to keep the CPU flat out, which - // means we need to execute a lvx or stvx every cycle. - -LoopBy64: - dcbt rs,r8 //SKP - dcbt rs,r6 //SKP - lvx vb,r9,rs //(1) 2nd source quadword (1st already in va) - lvx vc,r10,rs //(2) 3rd - lvx vd,r11,rs //(3) 4th - vperm vx,va,vb,vp //(3) vx <- 1st destination quadword - lvx va,rs,r0 //(4) get 1st qw of next 64-byte chunk (r0 must be RB!) - vperm vy,vb,vc,vp //(4) vy <- 2nd dest qw - stvx vx,0,rd //(5) - vperm vz,vc,vd,vp //(5) vz <- 3rd dest qw - stvx vy,r9,rd //(6) - vperm vx,vd,va,vp //(6) vx <- 4th - stvx vz,r10,rd //(7) - addi rs,rs,64 //(7) - stvx vx,r11,rd //(8) - addi rd,rd,64 //(8) - bdnz LoopBy64 //(8) - - // End of inner loop. Should we reprime dst stream and restart loop? - // This block is only executed when we're moving more than 4KB. - // It is usually folded out because cr0 is set in the loop prologue. - - beq+ LNoChunks // r12==0, ie no more chunks to move - sub. r12,r12,r0 // set cr0 if more than 4KB remain to xfer - mtctr r0 // initialize loop count to 64 - b LoopBy64 // restart inner loop, xfer another 4KB - - // Fewer than 64 bytes remain to be moved. - -LNoChunks: // r7 and cr1 are set with the number of QWs - andi. rc,rc,0xF //(33) rc <- leftover bytes - beq- cr1,LCleanup //(33) r7==0, ie fewer than 16 bytes remaining - mtctr r7 //(34) we will loop over 1-3 QWs - -LoopBy16: - lvx vb,r9,rs //(1) vb <- 2nd source quadword - addi rs,rs,16 //(1) - vperm vx,va,vb,vp //(3) vx <- next destination quadword - vor va,vb,vb //(3) va <- vb - stvx vx,0,rd //(4) assuming store Q is deep enough to mask latency - addi rd,rd,16 //(4) - bdnz LoopBy16 //(4) - - // Move remaining bytes in last quadword. rc and cr0 have the count. - -LCleanup: - lwz r6,-4(r1) // load VRSave from CR save area - mtspr VRSave,r6 //(35) restore caller's live-register bitmask - beqlr //(36) rc==0, ie no leftovers, so done - mtxer rc //(37) load byte count (1-15) - lswx r8,0,rs - stswx r8,0,rd - blr //(45) - - -// <><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><> -// <><> L O N G A L I G N E D M O V E S <><> -// <><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><> - - // rs, rd <- both quadword aligned - // cr0 <- beq if dest is cache block (32-byte) aligned - // r9 <- 16 - // r10 <- 32 - -LAligned: - lvx va,0,rs // prefetch 1st source quadword - li r11,48 // r11<- constant used to access 4th quadword - beq LAligned32 // destination already cache-block aligned - - // Copy 16 bytes to align destination on 32-byte (cache block) boundary - // to maximize store gathering. - - subi rc,rc,16 // adjust count - addi rs,rs,16 // adjust source ptr - stvx va,0,rd // assuming store Q deep enough to avoid latency - addi rd,rd,16 // adjust dest ptr - - // Destination 32-byte aligned, source 16-byte aligned. Set up for inner loop. - -LAligned32: - srwi. r12,rc,6 // r12<- count of 64-byte chunks to move - rlwinm r7,rc,28,30,31 // r7 <- count of 16-byte chunks to move - cmpwi cr1,r7,0 // remember if any 16-byte chunks - rlwinm r8,r12,0,26,31 // mask chunk count down to 0-63 - subi r0,r8,1 // r8==0? - beq- LAlignedNoChunks // r12==0, ie no chunks to move - rlwimi r8,r0,0,25,25 // if r8==0, then r8 <- 64 - li r0,64 // r0 <- used at end of loop - sub. r12,r12,r8 // adjust chunk count, set cr0 - mtctr r8 // set up loop count - li r8,96 //SKP - li r6,128 //SKP - - // Inner loop for aligned sources. We copy 64 bytes per iteration. - -LAlignedLoopBy64: - dcbt rs,r8 //SKP - dcbt rs,r6 //SKP - lvx va,0,rs //(1) - lvx vb,r9,rs //(2) - lvx vc,r10,rs //(3) - lvx vd,r11,rs //(4) - addi rs,rs,64 //(4) - stvx va,0,rd //(5) - stvx vb,r9,rd //(6) - stvx vc,r10,rd //(7) - stvx vd,r11,rd //(8) - addi rd,rd,64 //(8) - bdnz LAlignedLoopBy64 //(8) - - // End of inner loop. Loop again for next 4KB iff any. - - beq+ LAlignedNoChunks // r12==0, ie no more chunks to move - sub. r12,r12,r0 // set cr0 if more than 4KB remain to xfer - mtctr r0 // reinitialize loop count to 64 - b LAlignedLoopBy64 // restart inner loop, xfer another 4KB - - // Fewer than 64 bytes remain to be moved. - -LAlignedNoChunks: // r7 and cr1 are set with the number of QWs - andi. rc,rc,0xF // rc <- leftover bytes - beq- cr1,LCleanup // r7==0, ie fewer than 16 bytes remaining - mtctr r7 // we will loop over 1-3 QWs - -LAlignedLoopBy16: - lvx va,0,rs // get next quadword - addi rs,rs,16 - stvx va,0,rd - addi rd,rd,16 - bdnz LAlignedLoopBy16 - - b LCleanup // handle last 0-15 bytes, if any - - -// <><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><> -// <><> L O N G R E V E R S E M O V E S <><> -// <><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><> - - // Reverse moves. These involve overlapping operands, with the source - // lower in memory (lower addresses) than the destination. They must be - // done right-to-left, ie from high addresses down to low addresses. - // Throughout this code, we maintain rs and rd as pointers one byte past - // the end of the untransferred operands. - // - // The byte count is >=kShort and the following registers are already loaded: - // - // r6 - VMX mask at entry - // cr7 - beq if relatively aligned - // - -LongReverse: - add rd,rd,rc // update source/dest ptrs to be 1 byte past end - add rs,rs,rc - andi. r7,rd,0xF // r7 <- #bytes needed to move to align destination - sub rc,rc,r7 // adjust length while we wait - sub rs,rs,r7 // adjust ptrs by #bytes to xfer, also while we wait - sub rd,rd,r7 - beq- LDest16AlignedReverse - - // Align destination on a quadword. Note that we do NOT align on a cache - // block boundary for store gathering etc// since all these operands overlap - // many dest cache blocks will already be in the L1, so its not clear that - // this would be a win. - - mtxer r7 // load byte count - lswx r8,0,rs - stswx r8,0,rd - - // Prepare for inner loop and start "dstst" stream. Frankly, its not - // clear whether "dst" or "dstst" would be better// somebody should - // measure. We use "dstst" because, being overlapped, at least some - // source cache blocks will also be stored into. - -LDest16AlignedReverse: - srwi. r12,rc,6 // r12 <- count of 64-byte chunks to move - rlwinm r0,rc,11,9,15 // position quadword count for dst - rlwinm r11,r12,0,26,31 // mask chunk count down to 0-63 - li r9,-17 // r9 <- constant used to access 2nd quadword - oris r0,r0,0x0100 // set dst block size to 1 qw - li r10,-33 // r10<- constant used to access 3rd quadword - ori r0,r0,0xFFE0 // set dst stride to -16 bytes - li r8,-1 // r8<- constant used to access 1st quadword - dstst rs,r0,3 // start stream 0 - subi r0,r11,1 // r11==0 ? - lvx va,r8,rs // prefetch 1st source quadword - rlwinm r7,rc,28,30,31 // r7 <- count of 16-byte chunks to move - lvsl vp,0,rs // get permute vector to right shift - cmpwi cr1,r7,0 // remember if any 16-byte chunks - beq- LNoChunksReverse // r12==0, so skip inner loop - rlwimi r11,r0,0,25,25 // if r11==0, then r11 <- 64 - sub. r12,r12,r11 // adjust chunk count, set cr0 - mtctr r11 // set up loop count - li r11,-49 // r11<- constant used to access 4th quadword - li r0,-64 // r0 <- used for several purposes - beq- cr7,LAlignedLoopBy64Reverse - - // Inner loop for unaligned sources. We copy 64 bytes per iteration. - -LoopBy64Reverse: - lvx vb,r9,rs //(1) 2nd source quadword (1st already in va) - lvx vc,r10,rs //(2) 3rd quadword - lvx vd,r11,rs //(3) 4th - vperm vx,vb,va,vp //(3) vx <- 1st destination quadword - lvx va,rs,r0 //(4) get 1st qw of next 64-byte chunk (note r0 must be RB) - vperm vy,vc,vb,vp //(4) vy <- 2nd dest qw - stvx vx,r8,rd //(5) - vperm vz,vd,vc,vp //(5) vz <- 3rd destination quadword - stvx vy,r9,rd //(6) - vperm vx,va,vd,vp //(6) vx <- 4th qw - stvx vz,r10,rd //(7) - subi rs,rs,64 //(7) - stvx vx,r11,rd //(8) - subi rd,rd,64 //(8) - bdnz LoopBy64Reverse //(8) - - // End of inner loop. Should we reprime dst stream and restart loop? - // This block is only executed when we're moving more than 4KB. - // It is usually folded out because cr0 is set in the loop prologue. - - beq+ LNoChunksReverse // r12==0, ie no more chunks to move - lis r8,0x0440 // dst control: 64 4-qw blocks - add. r12,r12,r0 // set cr0 if more than 4KB remain to xfer - ori r8,r8,0xFFC0 // stride is -64 bytes - dstst rs,r8,3 // restart the prefetch stream - li r8,64 // inner loop count - mtctr r8 // initialize loop count to 64 - li r8,-1 // restore qw1 offset for inner loop - b LoopBy64Reverse // restart inner loop, xfer another 4KB - - // Fewer than 64 bytes remain to be moved. - -LNoChunksReverse: // r7 and cr1 are set with the number of QWs - andi. rc,rc,0xF // rc <- leftover bytes - beq- cr1,LCleanupReverse // r7==0, ie fewer than 16 bytes left - mtctr r7 - beq- cr7,LAlignedLoopBy16Reverse - -LoopBy16Reverse: - lvx vb,r9,rs // vb <- 2nd source quadword - subi rs,rs,16 - vperm vx,vb,va,vp // vx <- next destination quadword - vor va,vb,vb // va <- vb - stvx vx,r8,rd - subi rd,rd,16 - bdnz LoopBy16Reverse - - // Fewer that 16 bytes remain to be moved. - -LCleanupReverse: // rc and cr0 set with remaining byte count - lwz r6,-4(r1) // load VRSave from CR save area - mtspr VRSave,r6 // restore caller's live-register bitmask - beqlr // rc==0, ie no leftovers so done - neg r7,rc // get -(#bytes) - mtxer rc // byte count - lswx r8,r7,rs - stswx r8,r7,rd - blr - - -// <><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><> -// <><> A L I G N E D L O N G R E V E R S E M O V E S <><> -// <><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><> - - // Inner loop. We copy 64 bytes per iteration. - -LAlignedLoopBy64Reverse: - lvx va,r8,rs //(1) - lvx vb,r9,rs //(2) - lvx vc,r10,rs //(3) - lvx vd,r11,rs //(4) - subi rs,rs,64 //(4) - stvx va,r8,rd //(5) - stvx vb,r9,rd //(6) - stvx vc,r10,rd //(7) - stvx vd,r11,rd //(8) - subi rd,rd,64 //(8) - bdnz LAlignedLoopBy64Reverse //(8) - - // End of inner loop. Loop for next 4KB iff any. - - beq+ LNoChunksReverse // r12==0, ie no more chunks to move - lis r8,0x0440 // dst control: 64 4-qw blocks - add. r12,r12,r0 // r12 <- r12 - 64, set cr0 - ori r8,r8,0xFFC0 // stride is -64 bytes - dstst rs,r8,3 // restart the prefetch stream - li r8,64 // inner loop count - mtctr r8 // initialize loop count to 64 - li r8,-1 // restore qw1 offset for inner loop - b LAlignedLoopBy64Reverse - - // Loop to copy leftover quadwords (1-3). - -LAlignedLoopBy16Reverse: - lvx va,r8,rs // get next qw - subi rs,rs,16 - stvx va,r8,rd - subi rd,rd,16 - bdnz LAlignedLoopBy16Reverse - - b LCleanupReverse // handle up to 15 bytes in last qw diff --git a/gen.subproj/ppc.subproj/bzero.s b/gen.subproj/ppc.subproj/bzero.s deleted file mode 100644 index f320437..0000000 --- a/gen.subproj/ppc.subproj/bzero.s +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* Copyright (c) 1992, 1997 NeXT Software, Inc. All rights reserved. - * - * File: libc/gen/ppc/bzero.s - * - * HISTORY - * 24-Jan-1997 Umesh Vaishampayan (umeshv@NeXT.com) - * Ported to PPC. - * 18-Jan-93 Derek B Clegg (dclegg@next.com) - * Created. - * - * void bzero(void *s, size_t n); - * - * Description: - * The `bzero' function copies a zero into the first `n' bytes of - * the object pointed to by `s'. - * Returns: - * The `bzero' function does not return a value. - */ -#import -#import - -#define a8 ep -#define a9 at - -.at_off - -LEAF(_bzero) - li32 a2,0 // Clear registers a2 - a9. - li32 a3,0 - li32 a4,0 - li32 a5,0 - li32 a6,0 - li32 a7,0 - li32 a8,0 - li32 a9,0 - andi. zt,a0,31 // We want `s' to be 32-byte aligned. - subfic zt,zt,32 // Get the number of bytes to start with. - cmplw a1,zt // Don't move more than we were asked to. - ble- L_finish - mtxer zt // Load xer with the number of bytes to move. - stswx a2,0,a0 // Store into `s'. - add a0,a0,zt // Advance the pointer; a0 is now aligned. - sub a1,a1,zt // Calculate the bytes remaining to move. - srwi. zt,a1,5 // Get the number of 32-byte blocks to move. - beq- L_finish // Branch if fewer than 32 bytes are left. - mtctr zt // Setup counter for loop. - andi. a1,a1,31 // Get the number of bytes left over. -L_loop: - dcbz 0,a0 // Clear 32 bytes. - addi a0,a0,32 // Advance the pointer. - bdnz+ L_loop // Continue if there are still blocks to move. - - /* At this point, `a1' contains the number of bytes left to move. */ -L_finish: - mtxer a1 // Setup xer with # of bytes left to move. - stswx a2,0,a0 // Store. - blr -END(_bzero) diff --git a/gen.subproj/ppc.subproj/ecvt.c b/gen.subproj/ppc.subproj/ecvt.c deleted file mode 100755 index 1146030..0000000 --- a/gen.subproj/ppc.subproj/ecvt.c +++ /dev/null @@ -1,237 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* 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 - -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 - */ - diff --git a/gen.subproj/ppc.subproj/ffs.s b/gen.subproj/ppc.subproj/ffs.s deleted file mode 100644 index bb4963a..0000000 --- a/gen.subproj/ppc.subproj/ffs.s +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* Copyright (c) 1992, 1997 NeXT Software, Inc. All rights reserved. - * - * File: libc/gen/ppc/ffs.s - * - * Find the first bit set (starting with the least significant bit). - * - * HISTORY - * - * 24-Jan-1997 Umesh Vaishampayan (umeshv@NeXT.com) - * Ported to PPC. - * - * 19-Jan-1998 Matt Watson (mwatson@apple.com) - * Simplified - * - * 10-Mar-1998 Matt Watson (mwatson@apple.com) - * Correctified - * - */ - -.text -.align 2 -.globl _ffs -_ffs: - neg r0,r3 - and r3,r0,r3 - cntlzw r3,r3 - subfic r3,r3,32 - blr diff --git a/gen.subproj/ppc.subproj/fp.h b/gen.subproj/ppc.subproj/fp.h deleted file mode 100755 index 0934658..0000000 --- a/gen.subproj/ppc.subproj/fp.h +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* Copyright (c) 1992, NeXT Computer, Inc. All rights reserved. - * - * File: libc/m98k/gen/fp.h - * Author: Derek B Clegg, NeXT Computer, Inc. - * - * HISTORY - * 11-Nov-92 Derek B Clegg (dclegg@next.com) - * Created. - * - * Common definitions for floating-point numbers. - */ - -/* The following definitions for for double precision IEEE format numbers. */ - -#define EXPONENT_BIAS 1023 - -#define SIGN_BITS 1 -#define EXPONENT_BITS 11 -#define FRACTION_BITS 52 -#define HI_FRACTION_BITS 20 -#define LO_FRACTION_BITS 32 - -struct double_format { - unsigned sign: SIGN_BITS; - unsigned exponent: EXPONENT_BITS; - unsigned hi_fraction: HI_FRACTION_BITS; - unsigned lo_fraction: LO_FRACTION_BITS; -}; - -union dbl { - struct double_format s; - unsigned int u[2]; - double value; -}; - -#define PlusInfinity (1.0/0.0) -#define MinusInfinity (-1.0/0.0) - -#define not_a_number(x) ((x) != (x)) -#define positive_infinity(x) ((x) == PlusInfinity) -#define negative_infinity(x) ((x) == MinusInfinity) diff --git a/gen.subproj/ppc.subproj/genassym.h b/gen.subproj/ppc.subproj/genassym.h deleted file mode 100644 index 729dfa9..0000000 --- a/gen.subproj/ppc.subproj/genassym.h +++ /dev/null @@ -1,126 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * genassym.h -- macros of use with genassym.c and assymdefs.c - */ - -#import -#import - -#define PRINT_OFFSET(ptr_type, field) \ -MACRO_BEGIN \ - print_define("", #ptr_type, #field); \ - print_hex((unsigned) &(((ptr_type)0)->field)); \ -MACRO_END - -#define PRINT_BIT_FIELD(reg_type, field) \ -MACRO_BEGIN \ - reg_type __reg; \ - CONTENTS(__reg) = 0; \ - __reg.field = (typeof (__reg.field)) -1; \ - print_define("", #reg_type, #field); \ - print_hex(CONTENTS(__reg)); \ -MACRO_END - -#define PRINT_ENUM(item) \ -MACRO_BEGIN \ - print_define("", "", #item); \ - print_hex((unsigned)item); \ -MACRO_END - -#define PRINT_DEFINE(macro) \ -MACRO_BEGIN \ - print_define("", "", #macro); \ - print_str(STRINGIFY(macro)); \ -MACRO_END - -#define PRINT_CONSTANT(macro) \ -MACRO_BEGIN \ - print_define("", "", #macro); \ - print_hex((unsigned)macro); \ -MACRO_END - -#define PRINT_REGADDR(macro) \ -MACRO_BEGIN \ - print_define("", "", #macro); \ - print_hex((unsigned) ¯o); \ -MACRO_END - -#define PRINT_REG_PAIR(struct_ptr, name0, name1) \ -MACRO_BEGIN \ - print_define("", #struct_ptr, #name0 "_" #name1); \ - print_hex((unsigned) &(((struct_ptr)0)->U_##name0##_##name1)); \ -MACRO_END - -#define PRINT_BIT_POS(reg_type, field) \ -MACRO_BEGIN \ - reg_type __reg; \ - CONTENTS(__reg) = 0; \ - __reg.field = 1; \ - print_define("", #reg_type, #field "_BIT"); \ - print_dec((int) bit_num(#reg_type, #field, CONTENTS(__reg))); \ -MACRO_END - -#define PRINT_FIELD_INFO(reg_type, field) \ -MACRO_BEGIN \ - reg_type __reg; \ - CONTENTS(__reg) = 0; \ - __reg.field = -1; \ - print_define("", #reg_type, #field "_OFF"); \ - print_dec((int) bit_num(#reg_type, #field, CONTENTS(__reg))); \ - print_define("", #reg_type, #field "_WIDTH"); \ - print_dec((int) field_width(#reg_type, #field, CONTENTS(__reg)));\ -MACRO_END - -#define PRINT_L2_SIZE(type) \ -MACRO_BEGIN \ - print_define("L2_SIZEOF", #type, ""); \ - print_dec((int) log2(sizeof(type), #type)); \ -MACRO_END - -#define PRINT_SIZEOF(type) \ -MACRO_BEGIN \ - print_define("SIZEOF", #type, ""); \ - print_dec((int) sizeof(type)); \ -MACRO_END - -#define PRINT_L2_CONSTANT(macro) \ -MACRO_BEGIN \ - print_define("L2", "", #macro); \ - print_dec((int) log2(macro, #macro)); \ -MACRO_END - -typedef enum { - MAJOR, MINOR -} cmt_level_t; - -extern void comment(cmt_level_t level, const char *cmt); -extern void print_define(const char *prefix, const char *type_name, - const char *field); -extern void print_dec(int val); -extern void print_hex(unsigned val); -extern void print_str(const char *str); -extern unsigned bit_num(char *reg_type, char *field, unsigned bits); -extern unsigned field_width(char *reg_type, char *field, unsigned bits); -extern unsigned log2(unsigned val, char *type); -extern void assymdefs(void); - diff --git a/gen.subproj/ppc.subproj/insque.c b/gen.subproj/ppc.subproj/insque.c deleted file mode 100644 index 17f0b48..0000000 --- a/gen.subproj/ppc.subproj/insque.c +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* Copyright (c) 1992, 1997 NeXT Software, Inc. All rights reserved. - * - * File: libc/gen/ppc/insque.c - * - * struct qelem { - * struct qelem *q_forw; - * struct qelem *q_back; - * char q_data[]; - * }; - * - * void insque(struct qelem *elem, struct qelem *prev); - * - * Inserts queue entry `elem' into a queue after element `prev'. - * - * HISTORY -* 24-Jan-1997 Umesh Vaishampayan (umeshv@NeXT.com) -* Ported to PPC. - * 10-Nov-92 Derek B Clegg (dclegg@next.com) - * Created. - */ -#include - -void -insque(struct qelem *elem, struct qelem *prev) -{ - struct qelem *next; - - next = prev->q_forw; - prev->q_forw = elem; - if (next != 0) - next->q_back = elem; - elem->q_forw = next; - elem->q_back = prev; -} diff --git a/gen.subproj/ppc.subproj/isinf.c b/gen.subproj/ppc.subproj/isinf.c deleted file mode 100644 index b98587d..0000000 --- a/gen.subproj/ppc.subproj/isinf.c +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* Copyright (c) 1992, 1997 NeXT Software, Inc. All rights reserved. - * - * File: libc/gen/ppc/isinf.c - * Author: Derek B Clegg, NeXT Software, Inc. - * - * HISTORY -* 24-Jan-1997 Umesh Vaishampayan (umeshv@NeXT.com) -* Ported to PPC. - * 11-Nov-92 Derek B Clegg (dclegg@next.com) - * Created. - * - * int isinf(double value); - * - * Returns 1 if `value' is equal to positive IEEE infinity, -1 if `value' - * is equal to negative IEEE infinity, 0 otherwise. - * - * An IEEE infinity is a double value with the maximum biased exponent value - * (2047) and a zero fraction value. - */ -#import "fp.h" - -int -isinf(double value) -{ - union dbl d; - - d.value = value; - if (d.u[0] == 0x7FF00000 && d.u[1] == 0) - return 1; - if (d.u[0] == 0xFFF00000 && d.u[1] == 0) - return -1; - return 0; -} diff --git a/gen.subproj/ppc.subproj/mcount.s b/gen.subproj/ppc.subproj/mcount.s deleted file mode 100644 index 2c73e3d..0000000 --- a/gen.subproj/ppc.subproj/mcount.s +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* Copyright 1997 Apple Computer, Inc. -** -** 10 June 1997 - Created by mwatson@apple.com -** -*/ - -#include - - .text - .align 2 - .globl mcount -mcount: - mflr r0 - stw r0,8(r1) - stwu r1,-64(r1) - mflr r4 - CALL_EXTERN(_moncount) - addi r1,r1,64 - lwz r0,8(r1) - mtlr r0 - blr - diff --git a/gen.subproj/ppc.subproj/remque.c b/gen.subproj/ppc.subproj/remque.c deleted file mode 100644 index 9e032c5..0000000 --- a/gen.subproj/ppc.subproj/remque.c +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* Copyright (c) 1992, 1997 NeXT Software, Inc. All rights reserved. - * - * File: libc/gen/ppc/remque.c - * - * struct qelem { - * struct qelem *q_forw; - * struct qelem *q_back; - * char q_data[]; - * }; - * - * void remque(struct qelem *entry); - * - * Removes `entry' from a queue. - * - * HISTORY - * 24-Jan-1997 Umesh Vaishampayan (umeshv@NeXT.com) - * Ported to PPC. - * 10-Nov-92 Derek B Clegg (dclegg@next.com) - * Created. - */ -#import - -void -remque(struct qelem *elem) -{ - struct qelem *next, *prev; - - next = elem->q_forw; - prev = elem->q_back; - if (next != 0) - next->q_back = prev; - if (prev != 0) - prev->q_forw = next; -} diff --git a/gen.subproj/ppc.subproj/setjmperr.c b/gen.subproj/ppc.subproj/setjmperr.c deleted file mode 100755 index 3df3b7d..0000000 --- a/gen.subproj/ppc.subproj/setjmperr.c +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1980 Regents of the University of California. - * All rights reserved. The Berkeley software License Agreement - * specifies the terms and conditions for redistribution. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)setjmperr.c 5.2 (Berkeley) 3/9/86"; -#endif LIBC_SCCS and not lint - -#define ERRMSG "longjmp botch\n" - -/* - * This routine is called from longjmp() when an error occurs. - * Programs that wish to exit gracefully from this error may - * write their own versions. - * If this routine returns, the program is aborted. - */ -void -longjmperror(void) -{ - write(2, ERRMSG, sizeof(ERRMSG)); -} diff --git a/gen.subproj/ppc.subproj/strcat.c b/gen.subproj/ppc.subproj/strcat.c deleted file mode 100644 index ef5c208..0000000 --- a/gen.subproj/ppc.subproj/strcat.c +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* Copyright (c) 1991, 1997 NeXT Software, Inc. All rights reserved. - * - * File: libc/gen/ppc/strcat.c - * Author: Mike DeMoney, NeXT Software, Inc. - * - * This file contains machine dependent code for string copy - * - * HISTORY - * 24-Jan-1997 Umesh Vaishampayan (umeshv@NeXT.com) - * Ported to PPC. - * 9-Nov-92 Derek B Clegg (dclegg@next.com) - * Ported to m98k. - * 4-Jun-91 Mike DeMoney (mike@next.com) - * Created. - */ -#import - -char * -strcat(char *s1, const char *s2) -{ - strcpy(&s1[strlen(s1)], s2); - return s1; -} diff --git a/gen.subproj/ppc.subproj/strcpy.c b/gen.subproj/ppc.subproj/strcpy.c deleted file mode 100644 index a4c78b4..0000000 --- a/gen.subproj/ppc.subproj/strcpy.c +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* Copyright (c) 1992, 1997 NeXT Software, Inc. All rights reserved. - * - * File: libc/gen/ppc/strcpy.c - * - * This file contains machine dependent code for string copy - * - * HISTORY - * 24-Jan-1997 Umesh Vaishampayan (umeshv@NeXT.com) - * Ported to PPC. - * 24-Nov-92 Derek B Clegg (dclegg@next.com) - * Created. - */ -#import - -/* XXX This routine should be optimized. */ - -/* ANSI sez: - * The `strcpy' function copies the string pointed to by `s2' (including - * the terminating null character) into the array pointed to by `s1'. - * If copying takes place between objects that overlap, the behavior - * is undefined. - * The `strcpy' function returns the value of `s1'. [4.11.2.3] - */ -char * -strcpy(char *s1, const char *s2) -{ - char *s = s1; - while ((*s++ = *s2++) != 0) - ; - return (s1); -} diff --git a/gen.subproj/ppc.subproj/strlen.s b/gen.subproj/ppc.subproj/strlen.s deleted file mode 100644 index baa1216..0000000 --- a/gen.subproj/ppc.subproj/strlen.s +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* Copyright (c) 1992, 1997 NeXT Software, Inc. All rights reserved. - * - * File: libc/gen/ppc/strlen.s - * - * HISTORY - * 24-Jan-1997 Umesh Vaishampayan (umeshv@NeXT.com) - * Ported to PPC. - * 12-Nov-92 Derek B Clegg (dclegg@next.com) - * Created. - * - * size_t strlen(const char *s); - * - * Description: - * - * Returns: - */ -#import -#import - -/* size_t strlen(const char *s); */ - -#define a8 ep -#define a9 at - -.at_off - -#define check_for_zero(reg, tmp, found_zero, checked_all) \ - extrwi. tmp,reg,8,0 @\ - beq- found_zero @\ - bdz- checked_all @\ - extrwi. tmp,reg,8,8 @\ - beq- found_zero @\ - bdz- checked_all @\ - extrwi. tmp,reg,8,16 @\ - beq- found_zero @\ - bdz- checked_all @\ - extrwi. tmp,reg,8,24 @\ - beq- found_zero @\ - bdz- checked_all - -#define check_32(tmp, found_zero) \ - check_for_zero(a2, tmp, found_zero, 1f) @\ - check_for_zero(a3, tmp, found_zero, 1f) @\ - check_for_zero(a4, tmp, found_zero, 1f) @\ - check_for_zero(a5, tmp, found_zero, 1f) @\ - check_for_zero(a6, tmp, found_zero, 1f) @\ - check_for_zero(a7, tmp, found_zero, 1f) @\ - check_for_zero(a8, tmp, found_zero, 1f) @\ - check_for_zero(a9, tmp, found_zero, 1f) @\ -1: - -LEAF(_strlen) - dcbt 0,a0 // Try to load the cache line. - andi. a1,a0,31 // We want to be 32-byte aligned. - subfic a1,a1,32 // Get the number of bytes to start with. - mtxer a1 // Setup xer for load. - lswx a2,0,a0 // Load the bytes. - mtctr a1 // Setup ctr for zero check. - check_32(zt, L_found_zero) - - /* Now check 32-byte blocks. At this point, ctr is zero, so we can - * use it as our running count. */ - dcbt a1,a0 // Try to load the cache line. - li32 a2,32 - mtxer a2 - li32 a2,0 - mtctr a2 - -2: lswx a2,a1,a0 // Load 32 bytes. - check_32(zt, L_found_zero) - addi a0,a0,32 // Increment the pointer. - dcbt a1,a0 // Try to load the cache. - b 2b // Loop - -L_found_zero: - mfctr a0 - sub a0,a1,a0 // Get the number of bytes before 0. - blr // Return. -END(_strlen) diff --git a/gen.subproj/ppc.subproj/strncat.c b/gen.subproj/ppc.subproj/strncat.c deleted file mode 100644 index 9f9ef54..0000000 --- a/gen.subproj/ppc.subproj/strncat.c +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* Copyright (c) 1991, 1997 NeXT Software, Inc. All rights reserved. - * - * File: libc/gen/ppc/strncat.c - * Author: Mike DeMoney, NeXT Software, Inc. - * - * This file contains machine dependent code for string copy - * - * HISTORY - * 24-Jan-1997 Umesh Vaishampayan (umeshv@NeXT.com) - * Ported to PPC. - * 23-Nov-92 Derek B Clegg (dclegg@next.com) - * Ported to m98k. - * 4-Jun-91 Mike DeMoney (mike@next.com) - * Created. - */ -#import - -char * -strncat(char *s1, const char *s2, size_t n) -{ - unsigned len1 = strlen(s1); - unsigned len2 = strlen(s2); - - if (len2 < n) { - strcpy(&s1[len1], s2); - } else { - strncpy(&s1[len1], s2, n); - s1[len1 + n] = '\0'; - } - return s1; -} diff --git a/gen.subproj/ppc.subproj/strncmp.c b/gen.subproj/ppc.subproj/strncmp.c deleted file mode 100644 index bd54d2d..0000000 --- a/gen.subproj/ppc.subproj/strncmp.c +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* Copyright (c) 1992, 1997 NeXT Software, Inc. All rights reserved. - * - * File: libc/gen/ppc/strncmp.c - * - * This file contains machine dependent code for string comparison - * - * HISTORY - * 24-Jan-1997 Umesh Vaishampayan (umeshv@NeXT.com) - * Ported to PPC. - * 24-Nov-92 Derek B Clegg (dclegg@next.com) - * Created. - */ -#import - -/* This routine should be optimized. */ - -/* ANSI sez: - * The `strncmp' function compares not more than `n' characters (characters - * that follow a null character are not compared) from the array pointed to - * by `s1' to the array pointed to by `s2'. - * The `strncmp' function returns an integer greater than, equal to, or less - * than zero, according as the possibly null-terminated array pointed to by - * `s1' is greater than, equal to, or less than the possibly null-terminated - * array pointed to by `s2'. [4.11.4.4] - */ -int -strncmp(const char *s1, const char *s2, size_t n) -{ - for ( ; n > 0; s1++, s2++, --n) - if (*s1 != *s2) - return ((*(unsigned char *)s1 < *(unsigned char *)s2) ? -1 : +1); - else if (*s1 == '\0') - return 0; - return 0; -} diff --git a/gen.subproj/ppc.subproj/strncpy.c b/gen.subproj/ppc.subproj/strncpy.c deleted file mode 100644 index 1fd6e26..0000000 --- a/gen.subproj/ppc.subproj/strncpy.c +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* Copyright (c) 1992, 1997 NeXT Software, Inc. All rights reserved. - * - * File: libc/gen/ppc/strncpy.c - * - * This file contains machine dependent code for string copy - * - * HISTORY - * 24-Jan-1997 Umesh Vaishampayan (umeshv@NeXT.com) - * Ported to PPC. - * 24-Nov-92 Derek B Clegg (dclegg@next.com) - * Created. - */ -#import - -/* This routine should be optimized. */ - -/* ANSI sez: - * The `strncpy' function copies not more than `n' characters (characters - * that follow a null character are not copied) from the array pointed to - * by `s2' to the array pointed to by `s1'. If copying takes place between - * objects that overlap, the behavior is undefined. - * If the array pointed to by `s2' is a string that is shorter than `n' - * characters, null characters are appended to the copy in the array - * pointed to by `s1', until `n' characters in all have been written. - * The `strncpy' function returns the value of `s1'. [4.11.2.4] - */ -char * -strncpy(char *s1, const char *s2, size_t n) -{ - char *s = s1; - while (n > 0 && *s2 != '\0') { - *s++ = *s2++; - --n; - } - while (n > 0) { - *s++ = '\0'; - --n; - } - return s1; -} diff --git a/gen.subproj/psignal.c b/gen.subproj/psignal.c deleted file mode 100644 index 3d8a0b8..0000000 --- a/gen.subproj/psignal.c +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1983, 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. - */ - - -/* - * Print the name of the signal indicated - * along with the supplied message. - */ -#include -#include -#include - -extern const char *const sys_siglist[]; - -void -psignal(sig, s) - unsigned int sig; - const char *s; -{ - register const char *c; - register int n; - - if (sig < NSIG) - c = (char *)sys_siglist[sig]; - else - c = "Unknown signal"; - n = strlen(s); - if (n) { - (void)write(STDERR_FILENO, s, n); - (void)write(STDERR_FILENO, ": ", 2); - } - (void)write(STDERR_FILENO, c, strlen(c)); - (void)write(STDERR_FILENO, "\n", 1); -} diff --git a/gen.subproj/raise.c b/gen.subproj/raise.c deleted file mode 100644 index 533615e..0000000 --- a/gen.subproj/raise.c +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 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 -#include - -raise(s) - int s; -{ - return(kill(getpid(), s)); -} diff --git a/gen.subproj/readdir.c b/gen.subproj/readdir.c deleted file mode 100644 index fd86c9e..0000000 --- a/gen.subproj/readdir.c +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1983, 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 -#include - -/* - * get next entry in a directory. - */ -struct dirent * -readdir(dirp) - register DIR *dirp; -{ - register struct dirent *dp; - - for (;;) { - if (dirp->dd_loc >= dirp->dd_size) { - if (dirp->dd_flags & __DTF_READALL) - return (NULL); - dirp->dd_loc = 0; - } - if (dirp->dd_loc == 0 && !(dirp->dd_flags & __DTF_READALL)) { - dirp->dd_size = getdirentries(dirp->dd_fd, - dirp->dd_buf, dirp->dd_len, &dirp->dd_seek); - if (dirp->dd_size <= 0) - return (NULL); - } - dp = (struct dirent *)(dirp->dd_buf + dirp->dd_loc); - if ((int)dp & 03) /* bogus pointer check */ - return (NULL); - if (dp->d_reclen <= 0 || - dp->d_reclen > dirp->dd_len + 1 - dirp->dd_loc) - return (NULL); - dirp->dd_loc += dp->d_reclen; - if (dp->d_ino == 0) - continue; - if (dp->d_type == DT_WHT && (dirp->dd_flags & DTF_HIDEW)) - continue; - return (dp); - } -} diff --git a/gen.subproj/rewinddir.c b/gen.subproj/rewinddir.c deleted file mode 100644 index 0829a23..0000000 --- a/gen.subproj/rewinddir.c +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 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 -#include - -void -rewinddir(dirp) - DIR *dirp; -{ - - _seekdir(dirp, dirp->dd_rewind); - dirp->dd_rewind = telldir(dirp); -} diff --git a/gen.subproj/scalable_malloc.c b/gen.subproj/scalable_malloc.c deleted file mode 100644 index a19c7a4..0000000 --- a/gen.subproj/scalable_malloc.c +++ /dev/null @@ -1,1677 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ - -/* Author: Bertrand Serlet, August 1999 */ - -#import "scalable_malloc.h" - -#define __POSIX_LIB__ -#import -#import // for spin lock -#import -#include - -/********************* DEFINITIONS ************************/ - -static unsigned vm_page_shift = 0; // guaranteed to be intialized by zone creation - -#define DEBUG_MALLOC 0 // set to one to debug malloc itself -#define DEBUG_CLIENT 0 // set to one to help debug a nasty memory smasher - -#if DEBUG_MALLOC -#warning DEBUG ENABLED -#define INLINE -#else -#define INLINE inline -#endif - -#define CHECK_REGIONS (1 << 31) - -#define VM_COPY_THRESHOLD (40 * 1024) - // When all memory is touched after a copy, vm_copy() is always a lose - // But if the memory is only read, vm_copy() wins over memmove() at 3 or 4 pages (on a G3/300MHz) -#define KILL_THRESHOLD (32 * 1024) - -#define LARGE_THRESHOLD (3 * vm_page_size) // at or above this use "large" - -#define SHIFT_QUANTUM 4 // Required for AltiVec -#define QUANTUM (1 << SHIFT_QUANTUM) // allocation quantum -#define MIN_BLOCK 1 // minimum size, in QUANTUM multiples - -/* The header of a small block in use contains its size (expressed as multiples of QUANTUM, and header included), or 0; -If 0 then the block is either free (in which case the size is directly at the block itself), or the last block (indicated by either being beyond range, or having 0 in the block itself) */ - -#define PTR_HEADER_SIZE (sizeof(msize_t)) -#define FOLLOWING_PTR(ptr,msize) (((char *)(ptr)) + ((msize) << SHIFT_QUANTUM)) -#define PREVIOUS_MSIZE(ptr) ((msize_t *)(ptr))[-2] - -#define THIS_FREE 0x8000 // indicates this block is free -#define PREV_FREE 0x4000 // indicates previous block is free -#define MSIZE_FLAGS_FOR_PTR(ptr) (((msize_t *)(ptr))[-1]) - -#define REGION_SIZE (1 << (16 - 2 + SHIFT_QUANTUM)) // since we only have 16 bits for msize_t, and 1 bit is taken by THIS_FREE, and 1 by PREV_FREE - -#define INITIAL_NUM_REGIONS 8 // must always be at least 2 to always have 1 slot empty - -#define CHECKSUM_MAGIC 0x357B - -#define PROTECT_SMALL 0 // Should be 0: 1 is too slow for normal use - -#define LARGE_CACHE_SIZE 1 // define hysterisis of large chunks -#define MAX_LARGE_SIZE_TO_CACHE (128*1024) /* blocks larger than this are not cached */ - -#define MAX_RECORDER_BUFFER 256 - -#define MAX_GRAIN 64 - -typedef unsigned short msize_t; // a size in multiples of SHIFT_QUANTUM - -typedef struct { - unsigned checksum; - void *previous; - void *next; -} free_list_t; - -typedef struct { - unsigned address_and_num_pages; - // this type represents both an address and a number of pages - // the low bits are the number of pages - // the high bits are the address - // note that the exact number of bits used for depends on the page size - // also, this cannot represent pointers larger than 1 << (vm_page_shift * 2) -} compact_range_t; - -typedef vm_address_t region_t; - -typedef compact_range_t large_entry_t; - -typedef vm_range_t huge_entry_t; - -typedef unsigned short grain_t; - -typedef struct { - malloc_zone_t basic_zone; - pthread_lock_t lock; - unsigned debug_flags; - void *log_address; - - /* Regions for small objects */ - unsigned num_regions; - region_t *regions; - // this array is always created with 1 extra slot to be able to add a region without taking memory right away - unsigned last_region_hit; - free_list_t *free_list[MAX_GRAIN]; - unsigned num_bytes_free_in_last_region; // these bytes are cleared - unsigned num_small_objects; - unsigned num_bytes_in_small_objects; - - /* Cache of recently freed large object */ - vm_range_t large_to_deallocate[LARGE_CACHE_SIZE]; - // Entries that are 0 should be discarded - - /* large objects: vm_page_shift <= log2(size) < 2 *vm_page_shift */ - unsigned num_large_objects_in_use; // does not count the large entries in large_to_deallocate - unsigned num_large_entries; - unsigned num_bytes_in_large_objects; - large_entry_t *large_entries; - // large_entries are hashed by location - // large_entries that are 0 should be discarded - - /* huge objects: log2(size) >= 2 *vm_page_shift */ - unsigned num_bytes_in_huge_objects; - unsigned num_huge_entries; - huge_entry_t *huge_entries; -} szone_t; - -static void *szone_malloc(szone_t *szone, size_t size); -static void *szone_valloc(szone_t *szone, size_t size); -static INLINE void *szone_malloc_should_clear(szone_t *szone, size_t size, boolean_t cleared_requested); -static void szone_free(szone_t *szone, void *ptr); -static size_t szone_good_size(szone_t *szone, size_t size); -static boolean_t szone_check_all(szone_t *szone, const char *function); -static void szone_print(szone_t *szone, boolean_t verbose); -static INLINE region_t *region_for_ptr_no_lock(szone_t *szone, const void *ptr); -static vm_range_t large_free_no_lock(szone_t *szone, large_entry_t *entry); - -#define LOG(szone,ptr) (szone->log_address && (szone->num_small_objects > 8) && (((unsigned)szone->log_address == -1) || (szone->log_address == (void *)(ptr)))) - -/********************* ACCESSOR MACROS ************************/ - -#define SZONE_LOCK(szone) LOCK(szone->lock) -#define SZONE_UNLOCK(szone) UNLOCK(szone->lock) - -#define CHECK(szone,fun) if ((szone)->debug_flags & CHECK_REGIONS) szone_check_all(szone, fun) - -#define REGION_ADDRESS(region) (region) -#define REGION_END(region) (region+REGION_SIZE) - -#define LARGE_ENTRY_ADDRESS(entry) (((entry).address_and_num_pages >> vm_page_shift) << vm_page_shift) -#define LARGE_ENTRY_NUM_PAGES(entry) ((entry).address_and_num_pages & ((1 << vm_page_shift) - 1)) -#define LARGE_ENTRY_SIZE(entry) (LARGE_ENTRY_NUM_PAGES(entry) << vm_page_shift) -#define LARGE_ENTRY_MATCHES(entry,ptr) (!(((entry).address_and_num_pages - (unsigned)(ptr)) >> vm_page_shift)) -#define LARGE_ENTRY_IS_EMPTY(entry) (!((entry).address_and_num_pages)) - -/********************* VERY LOW LEVEL UTILITIES ************************/ - -static void szone_error(szone_t *szone, const char *msg, const void *ptr) { - if (szone) SZONE_UNLOCK(szone); - if (ptr) { - malloc_printf("*** malloc[%d]: error for object %p: %s\n", getpid(), ptr, msg); -#if DEBUG_MALLOC - szone_print(szone, 1); -#endif - } else { - malloc_printf("*** malloc[%d]: error: %s\n", getpid(), msg); - } -#if DEBUG_CLIENT - malloc_printf("*** Sleeping to help debug\n"); - sleep(3600); // to help debug -#endif -} - -static void protect(szone_t *szone, vm_address_t address, vm_size_t size, unsigned protection, unsigned debug_flags) { - kern_return_t err; - if (!(debug_flags & SCALABLE_MALLOC_DONT_PROTECT_PRELUDE)) { - err = vm_protect(mach_task_self(), address - vm_page_size, vm_page_size, 0, protection); - if (err) malloc_printf("*** malloc[%d]: Can't protect(%x) region for prelude guard page at 0x%x\n", getpid(), protection, address - vm_page_size); - } - if (!(debug_flags & SCALABLE_MALLOC_DONT_PROTECT_POSTLUDE)) { - err = vm_protect(mach_task_self(), (vm_address_t)(address + size), vm_page_size, 0, protection); - if (err) malloc_printf("*** malloc[%d]: Can't protect(%x) region for postlude guard page at 0x%x\n", getpid(), protection, address + size); - } -} - -static vm_address_t allocate_pages(szone_t *szone, size_t size, unsigned debug_flags, int vm_page_label) { - kern_return_t err; - vm_address_t addr; - boolean_t add_guard_pages = debug_flags & SCALABLE_MALLOC_ADD_GUARD_PAGES; - size_t allocation_size = round_page(size); - if (!allocation_size) allocation_size = vm_page_size; - if (add_guard_pages) allocation_size += 2 * vm_page_size; - err = vm_allocate(mach_task_self(), &addr, allocation_size, vm_page_label | 1); - if (err) { - szone_error(szone, "Can't allocate region", NULL); - return NULL; - } - if (add_guard_pages) { - addr += vm_page_size; - protect(szone, addr, size, 0, debug_flags); - } - return addr; -} - -static void deallocate_pages(szone_t *szone, vm_address_t addr, size_t size, unsigned debug_flags) { - kern_return_t err; - boolean_t add_guard_pages = debug_flags & SCALABLE_MALLOC_ADD_GUARD_PAGES; - if (add_guard_pages) { - addr -= vm_page_size; - size += 2 * vm_page_size; - } - err = vm_deallocate(mach_task_self(), addr, size); - if (err) { - szone_error(szone, "Can't deallocate_pages region", (void *)addr); - } -} - -static kern_return_t _szone_default_reader(task_t task, vm_address_t address, vm_size_t size, void **ptr) { - *ptr = (void *)address; - return 0; -} - -/********************* RANGE UTILITIES ************************/ - -static const vm_range_t zero_range = {0, 0}; - -static vm_range_t coalesce_range(vm_range_t *ranges, unsigned count, vm_range_t range) { - // Given a sequence of ranges and a range, tries to find an abutting range - // If no, returns original range - // Else zeroes out coalesced range, and reapplies with coalesced range - unsigned index = count; - vm_range_t *current = ranges; - while (index--) { - vm_range_t this = *current++; - if (!this.size) continue; - if (this.address + this.size == range.address) { - range.address = this.address; - range.size += this.size; - current[-1] = zero_range; - return coalesce_range(ranges, count, range); - } - if (range.address + range.size == this.address) { - range.size += this.size; - current[-1] = zero_range; - return coalesce_range(ranges, count, range); - } - } - return range; -} - -static INLINE vm_range_t *first_zero_range(vm_range_t *ranges, unsigned count) { - // Given a sequence of ranges, find the first empty slot - // or returns NULL - while (count--) { - if (!ranges->size) return ranges; - ranges++; - } - return NULL; -} - -static vm_range_t *largest_range(vm_range_t *ranges, unsigned count) { - // Given a sequence of ranges, find the largest range - // Returns NULL on empty arrays - vm_range_t *largest_range; - if (!count) return NULL; - largest_range = ranges; - count--; ranges++; - while (count--) { - if (ranges->size > largest_range->size) largest_range = ranges; - ranges++; - } - return largest_range; -} - -static vm_range_t *first_range_greater_or_equal(vm_range_t *ranges, unsigned count, vm_size_t size) { - // Given a sequence of ranges, find the first range greater than range - // Returns NULL when none found - while (count--) { - if (ranges->size >= size) return ranges; - ranges++; - } - return NULL; -} - -/********************* FREE LIST UTILITIES ************************/ - -static INLINE grain_t grain_for_msize(szone_t *szone, msize_t msize) { - // assumes msize >= MIN_BLOCK -#if DEBUG_MALLOC - if (msize < MIN_BLOCK) { - szone_error(szone, "grain_for_msize: msize too small", NULL); - } -#endif - return (msize < MAX_GRAIN + MIN_BLOCK) ? msize - MIN_BLOCK : MAX_GRAIN - 1; -} - -static INLINE msize_t msize_for_grain(szone_t *szone, grain_t grain) { - // 0 if multiple sizes - return (grain < MAX_GRAIN - 1) ? grain + MIN_BLOCK : 0; -} - -static INLINE void free_list_checksum(szone_t *szone, free_list_t *ptr) { - // We always checksum, as testing whether to do it (based on szone->debug_flags) is as fast as doing it - if (ptr->checksum != (((unsigned)ptr->previous) ^ ((unsigned)ptr->next) ^ CHECKSUM_MAGIC)) { - szone_error(szone, "Incorrect check sum for freed object - object was probably modified after beeing freed; break at szone_error", ptr); - } -} - -static INLINE void free_list_set_checksum(szone_t *szone, free_list_t *ptr) { - // We always set checksum, as testing whether to do it (based on szone->debug_flags) is slower than just doing it - ptr->checksum = ((unsigned)ptr->previous) ^ ((unsigned)ptr->next) ^ CHECKSUM_MAGIC; -} - -static void free_list_add_ptr(szone_t *szone, void *ptr, msize_t msize) { - // Adds an item to the proper free list - // Also marks the header of the block properly - grain_t grain = grain_for_msize(szone, msize); - free_list_t *free_ptr = ptr; - free_list_t *free_head = szone->free_list[grain]; - msize_t *follower = (msize_t *)FOLLOWING_PTR(ptr, msize); -#if DEBUG_MALLOC - if (LOG(szone,ptr)) malloc_printf("In free_list_add_ptr(), ptr=%p, msize=%d\n", ptr, msize); - if (((unsigned)ptr) & (QUANTUM - 1)) { - szone_error(szone, "free_list_add_ptr: Unaligned ptr", ptr); - } -#endif - MSIZE_FLAGS_FOR_PTR(ptr) = msize | THIS_FREE; - if (free_head) { - free_list_checksum(szone, free_head); -#if DEBUG_MALLOC - if (free_head->previous) { - malloc_printf("ptr=%p grain=%d free_head=%p previous=%p\n", ptr, grain, free_head, free_head->previous); - szone_error(szone, "free_list_add_ptr: Internal invariant broken (free_head->previous)", ptr); - } - if (!(MSIZE_FLAGS_FOR_PTR(free_head) & THIS_FREE)) { - malloc_printf("ptr=%p grain=%d free_head=%p\n", ptr, grain, free_head); - szone_error(szone, "free_list_add_ptr: Internal invariant broken (free_head is not a free pointer)", ptr); - } - if ((grain != MAX_GRAIN-1) && (MSIZE_FLAGS_FOR_PTR(free_head) != (THIS_FREE | msize))) { - malloc_printf("ptr=%p grain=%d free_head=%p previous_msize=%d\n", ptr, grain, free_head, MSIZE_FLAGS_FOR_PTR(free_head)); - szone_error(szone, "free_list_add_ptr: Internal invariant broken (incorrect msize)", ptr); - } -#endif - free_head->previous = free_ptr; - free_list_set_checksum(szone, free_head); - } - free_ptr->previous = NULL; - free_ptr->next = free_head; - free_list_set_checksum(szone, free_ptr); - szone->free_list[grain] = free_ptr; - // mark the end of this block - PREVIOUS_MSIZE(follower) = msize; - MSIZE_FLAGS_FOR_PTR(follower) |= PREV_FREE; -} - -static void free_list_remove_ptr(szone_t *szone, void *ptr, msize_t msize) { - // Removes item in the proper free list - // msize could be read, but all callers have it so we pass it in - grain_t grain = grain_for_msize(szone, msize); - free_list_t *free_ptr = ptr; - free_list_t *next = free_ptr->next; - free_list_t *previous = free_ptr->previous; -#if DEBUG_MALLOC - if (LOG(szone,ptr)) malloc_printf("In free_list_remove_ptr(), ptr=%p, msize=%d\n", ptr, msize); -#endif - free_list_checksum(szone, free_ptr); - if (!previous) { -#if DEBUG_MALLOC - if (szone->free_list[grain] != ptr) { - malloc_printf("ptr=%p grain=%d msize=%d szone->free_list[grain]=%p\n", ptr, grain, msize, szone->free_list[grain]); - szone_error(szone, "free_list_remove_ptr: Internal invariant broken (szone->free_list[grain])", ptr); - return; - } -#endif - szone->free_list[grain] = next; - } else { - previous->next = next; - free_list_set_checksum(szone, previous); - } - if (next) { - next->previous = previous; - free_list_set_checksum(szone, next); - } - MSIZE_FLAGS_FOR_PTR(FOLLOWING_PTR(ptr, msize)) &= ~ PREV_FREE; -} - -static boolean_t free_list_check(szone_t *szone, grain_t grain) { - unsigned count = 0; - free_list_t *ptr = szone->free_list[grain]; - free_list_t *previous = NULL; - while (ptr) { - msize_t msize_and_free = MSIZE_FLAGS_FOR_PTR(ptr); - count++; - if (!(msize_and_free & THIS_FREE)) { - malloc_printf("*** malloc[%d]: In-use ptr in free list grain=%d count=%d ptr=%p\n", getpid(), grain, count, ptr); - return 0; - } - if (((unsigned)ptr) & (QUANTUM - 1)) { - malloc_printf("*** malloc[%d]: Unaligned ptr in free list grain=%d count=%d ptr=%p\n", getpid(), grain, count, ptr); - return 0; - } - if (!region_for_ptr_no_lock(szone, ptr)) { - malloc_printf("*** malloc[%d]: Ptr not in szone grain=%d count=%d ptr=%p\n", getpid(), grain, count, ptr); - return 0; - } - free_list_checksum(szone, ptr); - if (ptr->previous != previous) { - malloc_printf("*** malloc[%d]: Previous incorrectly set grain=%d count=%d ptr=%p\n", getpid(), grain, count, ptr); - return 0; - } - if ((grain != MAX_GRAIN-1) && (msize_and_free != (msize_for_grain(szone, grain) | THIS_FREE))) { - malloc_printf("*** malloc[%d]: Incorrect msize for grain=%d count=%d ptr=%p msize=%d\n", getpid(), grain, count, ptr, msize_and_free); - return 0; - } - previous = ptr; - ptr = ptr->next; - } - return 1; -} - -/********************* SMALL BLOCKS MANAGEMENT ************************/ - -static INLINE region_t *region_for_ptr_no_lock(szone_t *szone, const void *ptr) { - region_t *first_region = szone->regions; - region_t *region = first_region + szone->last_region_hit; - region_t this = *region; - if ((unsigned)ptr - (unsigned)REGION_ADDRESS(this) < (unsigned)REGION_SIZE) { - return region; - } else { - // We iterate in reverse order becase last regions are more likely - region = first_region + szone->num_regions; - while (region != first_region) { - this = *(--region); - if ((unsigned)ptr - (unsigned)REGION_ADDRESS(this) < (unsigned)REGION_SIZE) { - szone->last_region_hit = region - first_region; - return region; - } - } - return NULL; - } -} - -static INLINE void small_free_no_lock(szone_t *szone, region_t *region, void *ptr, msize_t msize_and_free) { - msize_t msize = msize_and_free & ~ PREV_FREE; - size_t original_size = msize << SHIFT_QUANTUM; - void *next_block = ((char *)ptr + original_size); - msize_t next_msize_and_free; -#if DEBUG_MALLOC - if (LOG(szone,ptr)) malloc_printf("In small_free_no_lock(), ptr=%p, msize=%d\n", ptr, msize); - if (msize < MIN_BLOCK) { - malloc_printf("In small_free_no_lock(), ptr=%p, msize=%d\n", ptr, msize); - szone_error(szone, "Trying to free small block that is too small", ptr); - } -#endif - if (((vm_address_t)next_block < REGION_END(*region)) && ((next_msize_and_free = MSIZE_FLAGS_FOR_PTR(next_block)) & THIS_FREE)) { - // If the next block is free, we coalesce - msize_t next_msize = next_msize_and_free & ~THIS_FREE; - if (LOG(szone,ptr)) malloc_printf("In small_free_no_lock(), for ptr=%p, msize=%d coalesced next block=%p next_msize=%d\n", ptr, msize, next_block, next_msize); - free_list_remove_ptr(szone, next_block, next_msize); - msize += next_msize; - } - // Let's try to coalesce backwards now - if (msize_and_free & PREV_FREE) { - msize_t previous_msize = PREVIOUS_MSIZE(ptr); - void *previous = ptr - (previous_msize << SHIFT_QUANTUM); -#if DEBUG_MALLOC - if (LOG(szone,previous)) malloc_printf("In small_free_no_lock(), coalesced backwards for %p previous=%p, msize=%d\n", ptr, previous, previous_msize); - if (!previous_msize || (previous_msize >= (((vm_address_t)ptr - REGION_ADDRESS(*region)) >> SHIFT_QUANTUM))) { - szone_error(szone, "Invariant 1 broken when coalescing backwards", ptr); - } - if (MSIZE_FLAGS_FOR_PTR(previous) != (previous_msize | THIS_FREE)) { - malloc_printf("previous=%p its_msize_and_free=0x%x previous_msize=%d\n", previous, MSIZE_FLAGS_FOR_PTR(previous), previous_msize); - szone_error(szone, "Invariant 3 broken when coalescing backwards", ptr); - } -#endif - free_list_remove_ptr(szone, previous, previous_msize); - ptr = previous; - msize += previous_msize; -#if DEBUG_MALLOC - if (msize & PREV_FREE) { - malloc_printf("In small_free_no_lock(), after coalescing with previous ptr=%p, msize=%d previous_msize=%d\n", ptr, msize, previous_msize); - szone_error(szone, "Incorrect coalescing", ptr); - } -#endif - } - if (szone->debug_flags & SCALABLE_MALLOC_DO_SCRIBBLE) { - if (!msize) { - szone_error(szone, "Incorrect size information - block header was damaged", ptr); - } else { - memset(ptr, 0x55, (msize << SHIFT_QUANTUM) - PTR_HEADER_SIZE); - } - } - free_list_add_ptr(szone, ptr, msize); - CHECK(szone, "small_free_no_lock: added to free list"); - szone->num_small_objects--; - szone->num_bytes_in_small_objects -= original_size; // we use original_size and not msize to avoid double counting the coalesced blocks -} - -static void *small_malloc_from_region_no_lock(szone_t *szone, msize_t msize) { - // Allocates from the last region or a freshly allocated region - region_t *last_region = szone->regions + szone->num_regions - 1; - vm_address_t new_address; - void *ptr; - msize_t msize_and_free; - unsigned region_capacity; - ptr = (void *)(REGION_END(*last_region) - szone->num_bytes_free_in_last_region + PTR_HEADER_SIZE); -#if DEBUG_MALLOC - if (((vm_address_t)ptr) & (QUANTUM - 1)) { - szone_error(szone, "Invariant broken while using end of region", ptr); - } -#endif - msize_and_free = MSIZE_FLAGS_FOR_PTR(ptr); -#if DEBUG_MALLOC - if (msize_and_free != PREV_FREE && msize_and_free != 0) { - malloc_printf("*** malloc[%d]: msize_and_free = %d\n", getpid(), msize_and_free); - szone_error(szone, "Invariant broken when allocating at end of zone", ptr); - } -#endif - // In order to make sure we don't have 2 free pointers following themselves, if the last item is a free item, we combine it and clear it - if (msize_and_free == PREV_FREE) { - msize_t previous_msize = PREVIOUS_MSIZE(ptr); - void *previous = ptr - (previous_msize << SHIFT_QUANTUM); -#if DEBUG_MALLOC - if (LOG(szone, ptr)) malloc_printf("Combining last with free space at %p\n", ptr); - if (!previous_msize || (previous_msize >= (((vm_address_t)ptr - REGION_ADDRESS(*last_region)) >> SHIFT_QUANTUM)) || (MSIZE_FLAGS_FOR_PTR(previous) != (previous_msize | THIS_FREE))) { - szone_error(szone, "Invariant broken when coalescing backwards at end of zone", ptr); - } -#endif - free_list_remove_ptr(szone, previous, previous_msize); - szone->num_bytes_free_in_last_region += previous_msize << SHIFT_QUANTUM; - memset(previous, 0, previous_msize << SHIFT_QUANTUM); - MSIZE_FLAGS_FOR_PTR(previous) = 0; - ptr = previous; - } - // first try at the end of the last region - CHECK(szone, __PRETTY_FUNCTION__); - if (szone->num_bytes_free_in_last_region >= (msize << SHIFT_QUANTUM)) { - szone->num_bytes_free_in_last_region -= (msize << SHIFT_QUANTUM); - szone->num_small_objects++; - szone->num_bytes_in_small_objects += msize << SHIFT_QUANTUM; - MSIZE_FLAGS_FOR_PTR(ptr) = msize; - return ptr; - } - // time to create a new region - new_address = allocate_pages(szone, REGION_SIZE, 0, VM_MAKE_TAG(VM_MEMORY_MALLOC_SMALL)); - if (!new_address) { - // out of memory! - return NULL; - } - // let's prepare to free the remnants of last_region - if (szone->num_bytes_free_in_last_region >= QUANTUM) { - msize_t this_msize = szone->num_bytes_free_in_last_region >> SHIFT_QUANTUM; - // malloc_printf("Entering last block %p size=%d\n", ptr, this_msize << SHIFT_QUANTUM); - if (this_msize >= MIN_BLOCK) { - free_list_add_ptr(szone, ptr, this_msize); - } else { - // malloc_printf("Leaking last block at %p\n", ptr); - } - szone->num_bytes_free_in_last_region -= this_msize << SHIFT_QUANTUM; // to avoid coming back here - } - last_region[1] = new_address; - szone->num_regions++; - szone->num_bytes_free_in_last_region = REGION_SIZE - QUANTUM + PTR_HEADER_SIZE - (msize << SHIFT_QUANTUM); - ptr = (void *)(new_address + QUANTUM); // waste the first bytes - region_capacity = (MSIZE_FLAGS_FOR_PTR(szone->regions) * QUANTUM - PTR_HEADER_SIZE) / sizeof(region_t); - if (szone->num_regions >= region_capacity) { - unsigned new_capacity = region_capacity * 2 + 1; - msize_t new_msize = (new_capacity * sizeof(region_t) + PTR_HEADER_SIZE + QUANTUM - 1) / QUANTUM; - region_t *new_regions = ptr; - // malloc_printf("Now %d regions growing regions %p to %d\n", szone->num_regions, szone->regions, new_capacity); - MSIZE_FLAGS_FOR_PTR(new_regions) = new_msize; - szone->num_small_objects++; - szone->num_bytes_in_small_objects += new_msize << SHIFT_QUANTUM; - memcpy(new_regions, szone->regions, szone->num_regions * sizeof(region_t)); - // We intentionally leak the previous regions pointer to avoid multi-threading crashes if another thread was reading it (unlocked) while we are changing it - // Given that in practise the number of regions is typically a handful, this should not be a big deal - szone->regions = new_regions; - ptr += (new_msize << SHIFT_QUANTUM); - szone->num_bytes_free_in_last_region -= (new_msize << SHIFT_QUANTUM); - // malloc_printf("Regions is now %p next ptr is %p\n", szone->regions, ptr); - } - szone->num_small_objects++; - szone->num_bytes_in_small_objects += msize << SHIFT_QUANTUM; - MSIZE_FLAGS_FOR_PTR(ptr) = msize; - return ptr; -} - -static boolean_t szone_check_region(szone_t *szone, region_t *region) { - void *ptr = (void *)REGION_ADDRESS(*region) + QUANTUM; - vm_address_t region_end = REGION_END(*region); - int is_last_region = region == szone->regions + szone->num_regions - 1; - msize_t prev_free = 0; - while ((vm_address_t)ptr < region_end) { - msize_t msize_and_free = MSIZE_FLAGS_FOR_PTR(ptr); - if (!(msize_and_free & THIS_FREE)) { - msize_t msize = msize_and_free & ~PREV_FREE; - if ((msize_and_free & PREV_FREE) != prev_free) { - malloc_printf("*** malloc[%d]: invariant broken for %p (prev_free=%d) this msize=%d\n", getpid(), ptr, prev_free, msize_and_free); - return 0; - } - if (!msize) { - int extra = (is_last_region) ? szone->num_bytes_free_in_last_region : QUANTUM; - if (((unsigned)(ptr + extra)) < region_end) { - malloc_printf("*** malloc[%d]: invariant broken at region end: ptr=%p extra=%d index=%d num_regions=%d end=%p\n", getpid(), ptr, extra, region - szone->regions, szone->num_regions, (void *)region_end); - return 0; - } - break; // last encountered - } - if (msize > (LARGE_THRESHOLD / QUANTUM)) { - malloc_printf("*** malloc[%d]: invariant broken for %p this msize=%d - size is too large\n", getpid(), ptr, msize_and_free); - return 0; - } - if ((msize < MIN_BLOCK) && ((unsigned)ptr != region_end - QUANTUM)) { - malloc_printf("*** malloc[%d]: invariant broken for %p this msize=%d - size is too small\n", getpid(), ptr, msize_and_free); - return 0; - } - ptr += msize << SHIFT_QUANTUM; - prev_free = 0; - if (is_last_region && ((vm_address_t)ptr - PTR_HEADER_SIZE > region_end - szone->num_bytes_free_in_last_region)) { - malloc_printf("*** malloc[%d]: invariant broken for %p this msize=%d - block extends beyond allocated region\n", getpid(), ptr, msize_and_free); - } - } else { - // free pointer - msize_t msize = msize_and_free & ~THIS_FREE; - free_list_t *free_head = ptr; - msize_t *follower = (void *)FOLLOWING_PTR(ptr, msize); - if ((msize_and_free & PREV_FREE) && !prev_free) { - malloc_printf("*** malloc[%d]: invariant broken for free block %p this msize=%d: PREV_FREE set while previous block is in use\n", getpid(), ptr, msize); - return 0; - } - if (msize < MIN_BLOCK) { - malloc_printf("*** malloc[%d]: invariant broken for free block %p this msize=%d\n", getpid(), ptr, msize); - return 0; - } - if (prev_free) { - malloc_printf("*** malloc[%d]: invariant broken for %p (2 free in a row)\n", getpid(), ptr); - return 0; - } - free_list_checksum(szone, free_head); - if (free_head->previous && !(MSIZE_FLAGS_FOR_PTR(free_head->previous) & THIS_FREE)) { - malloc_printf("*** malloc[%d]: invariant broken for %p (previous %p is not a free pointer)\n", getpid(), ptr, free_head->previous); - return 0; - } - if (free_head->next && !(MSIZE_FLAGS_FOR_PTR(free_head->next) & THIS_FREE)) { - malloc_printf("*** malloc[%d]: invariant broken for %p (next is not a free pointer)\n", getpid(), ptr); - return 0; - } - if (PREVIOUS_MSIZE(follower) != msize) { - malloc_printf("*** malloc[%d]: invariant broken for free %p followed by %p in region [%x-%x] (end marker incorrect) should be %d; in fact %d\n", getpid(), ptr, follower, REGION_ADDRESS(*region), region_end, msize, PREVIOUS_MSIZE(follower)); - return 0; - } - ptr = follower; - prev_free = PREV_FREE; - } - } - return 1; -} - -static kern_return_t small_in_use_enumerator(task_t task, void *context, unsigned type_mask, vm_address_t region_address, unsigned num_regions, memory_reader_t reader, vm_range_recorder_t recorder) { - region_t *regions; - unsigned index = 0; - vm_range_t buffer[MAX_RECORDER_BUFFER]; - unsigned count = 0; - kern_return_t err; - err = reader(task, region_address, sizeof(region_t) * num_regions, (void **)®ions); - if (err) return err; - while (index < num_regions) { - region_t region = regions[index++]; - vm_range_t range = {REGION_ADDRESS(region), REGION_SIZE}; - vm_address_t start = range.address + QUANTUM; - // malloc_printf("Enumerating small ptrs for Region starting at 0x%x\n", start); - if (type_mask & MALLOC_PTR_REGION_RANGE_TYPE) recorder(task, context, MALLOC_PTR_REGION_RANGE_TYPE, &range, 1); - if (type_mask & MALLOC_PTR_IN_USE_RANGE_TYPE) while (start < range.address + range.size) { - void *previous; - msize_t msize_and_free; - err = reader(task, start - PTR_HEADER_SIZE, QUANTUM, (void **)&previous); - if (err) return err; - previous += PTR_HEADER_SIZE; - msize_and_free = MSIZE_FLAGS_FOR_PTR(previous); - if (!(msize_and_free & THIS_FREE)) { - // Block in use - msize_t msize = msize_and_free & ~PREV_FREE; - if (!msize) break; // last encountered - buffer[count].address = start; - buffer[count].size = (msize << SHIFT_QUANTUM) - PTR_HEADER_SIZE; - count++; - if (count >= MAX_RECORDER_BUFFER) { - recorder(task, context, MALLOC_PTR_IN_USE_RANGE_TYPE, buffer, count); - count = 0; - } - start += msize << SHIFT_QUANTUM; - } else { - // free pointer - msize_t msize = msize_and_free & ~THIS_FREE; - start += msize << SHIFT_QUANTUM; - } - } - // malloc_printf("End region - count=%d\n", count); - } - if (count) recorder(task, context, MALLOC_PTR_IN_USE_RANGE_TYPE, buffer, count); - return 0; -} - -static INLINE void *small_malloc_from_free_list(szone_t *szone, msize_t msize, boolean_t *locked) { - void *ptr; - msize_t this_msize; - free_list_t **free_list; - free_list_t **limit = szone->free_list + MAX_GRAIN - 1; - // first try the small grains - free_list = szone->free_list + grain_for_msize(szone, msize); - while (free_list < limit) { - // try bigger grains - ptr = *free_list; - if (ptr) { - if (!*locked) { *locked = 1; SZONE_LOCK(szone); CHECK(szone, __PRETTY_FUNCTION__); } - ptr = *free_list; - if (ptr) { - // optimistic test worked - free_list_t *next; - next = ((free_list_t *)ptr)->next; - if (next) { - next->previous = NULL; - free_list_set_checksum(szone, next); - } - *free_list = next; - this_msize = MSIZE_FLAGS_FOR_PTR(ptr) & ~THIS_FREE; - MSIZE_FLAGS_FOR_PTR(FOLLOWING_PTR(ptr, this_msize)) &= ~ PREV_FREE; - goto add_leftover_and_proceed; - } - } - free_list++; - } - // We now check the large grains for one that is big enough - if (!*locked) { *locked = 1; SZONE_LOCK(szone); CHECK(szone, __PRETTY_FUNCTION__); } - ptr = *free_list; - while (ptr) { - this_msize = MSIZE_FLAGS_FOR_PTR(ptr) & ~THIS_FREE; - if (this_msize >= msize) { - free_list_remove_ptr(szone, ptr, this_msize); - goto add_leftover_and_proceed; - } - ptr = ((free_list_t *)ptr)->next; - } - return NULL; -add_leftover_and_proceed: - if (this_msize >= msize + MIN_BLOCK) { - if (LOG(szone,ptr)) malloc_printf("In small_malloc_should_clear(), adding leftover ptr=%p, this_msize=%d\n", ptr, this_msize); - free_list_add_ptr(szone, ptr + (msize << SHIFT_QUANTUM), this_msize - msize); - this_msize = msize; - } - szone->num_small_objects++; - szone->num_bytes_in_small_objects += this_msize << SHIFT_QUANTUM; -#if DEBUG_MALLOC - if (LOG(szone,ptr)) malloc_printf("In small_malloc_should_clear(), ptr=%p, this_msize=%d, msize=%d\n", ptr, this_msize, msize); -#endif - MSIZE_FLAGS_FOR_PTR(ptr) = this_msize; - return ptr; -} - -static INLINE void *small_malloc_should_clear(szone_t *szone, msize_t msize, boolean_t cleared_requested) { - boolean_t locked = 0; - void *ptr; -#if DEBUG_MALLOC - if (! (msize & 0xffff)) { - szone_error(szone, "Invariant broken (!msize) in allocation (region)", NULL); - } - if (msize < MIN_BLOCK) { - szone_error(szone, "Invariant broken (msize too small) in allocation (region)", NULL); - } -#endif - ptr = small_malloc_from_free_list(szone, msize, &locked); - if (ptr) { - CHECK(szone, __PRETTY_FUNCTION__); - SZONE_UNLOCK(szone); - if (cleared_requested) memset(ptr, 0, (msize << SHIFT_QUANTUM) - PTR_HEADER_SIZE); - return ptr; - } else { - if (!locked) SZONE_LOCK(szone); - CHECK(szone, __PRETTY_FUNCTION__); - ptr = small_malloc_from_region_no_lock(szone, msize); - // we don't clear because this freshly allocated space is pristine - CHECK(szone, __PRETTY_FUNCTION__); - SZONE_UNLOCK(szone); - } - return ptr; -} - -static INLINE void *small_malloc_cleared_no_lock(szone_t *szone, msize_t msize) { - // tries to allocate a small, cleared block - boolean_t locked = 1; - void *ptr; - ptr = small_malloc_from_free_list(szone, msize, &locked); - if (ptr) { - memset(ptr, 0, (msize << SHIFT_QUANTUM) - PTR_HEADER_SIZE); - return ptr; - } else { - ptr = small_malloc_from_region_no_lock(szone, msize); - // we don't clear because this freshly allocated space is pristine - } - return ptr; -} - -/********************* LARGE ENTRY UTILITIES ************************/ - -#if DEBUG_MALLOC - -static void large_cache_debug_print(szone_t *szone) { - unsigned index = LARGE_CACHE_SIZE; - malloc_printf("Cache to be dealloced: "); - while (index--) { - vm_range_t range = szone->large_to_deallocate[index]; - if (range.size) malloc_printf("0x%x(%dKB) ", range.address, range.size/1024); - } - malloc_printf("\n"); -} - -static void large_debug_print(szone_t *szone) { - unsigned num_large_entries = szone->num_large_entries; - unsigned index = num_large_entries; - while (index--) { - large_entry_t *range = szone->large_entries + index; - large_entry_t entry = *range; - if (!LARGE_ENTRY_IS_EMPTY(entry)) malloc_printf("%d: 0x%x(%dKB); ", index, LARGE_ENTRY_ADDRESS(entry), LARGE_ENTRY_SIZE(entry)/1024); - } - malloc_printf("\n"); -} -#endif - -static large_entry_t *large_entry_for_pointer_no_lock(szone_t *szone, const void *ptr) { - // result only valid during a lock - unsigned num_large_entries = szone->num_large_entries; - unsigned hash_index; - unsigned index; - if (!num_large_entries) return NULL; - hash_index = ((unsigned)ptr >> vm_page_shift) % num_large_entries; - index = hash_index; - do { - large_entry_t *range = szone->large_entries + index; - large_entry_t entry = *range; - if (LARGE_ENTRY_MATCHES(entry, ptr)) return range; - if (LARGE_ENTRY_IS_EMPTY(entry)) return NULL; // end of chain - index++; if (index == num_large_entries) index = 0; - } while (index != hash_index); - return NULL; -} - -static void large_entry_insert_no_lock(szone_t *szone, large_entry_t range) { - unsigned num_large_entries = szone->num_large_entries; - unsigned hash_index = (range.address_and_num_pages >> vm_page_shift) % num_large_entries; - unsigned index = hash_index; - // malloc_printf("Before insertion of 0x%x\n", LARGE_ENTRY_ADDRESS(range)); - do { - large_entry_t *entry = szone->large_entries + index; - if (LARGE_ENTRY_IS_EMPTY(*entry)) { - *entry = range; - return; // end of chain - } - index++; if (index == num_large_entries) index = 0; - } while (index != hash_index); -} - -static INLINE void large_entries_rehash_after_entry_no_lock(szone_t *szone, large_entry_t *entry) { - unsigned num_large_entries = szone->num_large_entries; - unsigned hash_index = entry - szone->large_entries; - unsigned index = hash_index; - do { - large_entry_t range; - index++; if (index == num_large_entries) index = 0; - range = szone->large_entries[index]; - if (LARGE_ENTRY_IS_EMPTY(range)) return; - szone->large_entries[index].address_and_num_pages = 0; - large_entry_insert_no_lock(szone, range); // this will reinsert in the proper place - } while (index != hash_index); -} - -static INLINE large_entry_t *large_entries_alloc_no_lock(szone_t *szone, unsigned num) { - size_t size = num * sizeof(large_entry_t); - boolean_t is_vm_allocation = size >= LARGE_THRESHOLD; - if (is_vm_allocation) { - return (void *)allocate_pages(szone, round_page(size), 0, VM_MAKE_TAG(VM_MEMORY_MALLOC_LARGE)); - } else { - return small_malloc_cleared_no_lock(szone, (size + PTR_HEADER_SIZE + QUANTUM - 1) >> SHIFT_QUANTUM); - } -} - -static void large_entries_free_no_lock(szone_t *szone, large_entry_t *entries, unsigned num) { - size_t size = num * sizeof(large_entry_t); - boolean_t is_vm_allocation = size >= LARGE_THRESHOLD; - if (is_vm_allocation) { - deallocate_pages(szone, (vm_address_t)entries, round_page(size), 0); - } else { - region_t *region = region_for_ptr_no_lock(szone, entries); - msize_t msize_and_free = MSIZE_FLAGS_FOR_PTR(entries); - if (msize_and_free & THIS_FREE) { - szone_error(szone, "Object already freed being freed", entries); - return; - } - small_free_no_lock(szone, region, entries, msize_and_free); - } -} - -static void large_entries_grow_no_lock(szone_t *szone) { - unsigned old_num_entries = szone->num_large_entries; - large_entry_t *old_entries = szone->large_entries; - unsigned new_num_entries = (old_num_entries) ? old_num_entries * 2 + 1 : 15; // always an odd number for good hashing - large_entry_t *new_entries = large_entries_alloc_no_lock(szone, new_num_entries); - unsigned index = old_num_entries; - szone->num_large_entries = new_num_entries; - szone->large_entries = new_entries; - // malloc_printf("_grow_large_entries old_num_entries=%d new_num_entries=%d\n", old_num_entries, new_num_entries); - while (index--) { - large_entry_t oldRange = old_entries[index]; - if (!LARGE_ENTRY_IS_EMPTY(oldRange)) large_entry_insert_no_lock(szone, oldRange); - } - if (old_entries) large_entries_free_no_lock(szone, old_entries, old_num_entries); -} - -static vm_range_t large_free_no_lock(szone_t *szone, large_entry_t *entry) { - // frees the specific entry in the size table - // returns a range to truly deallocate, taking into account - vm_range_t range; - range.address = LARGE_ENTRY_ADDRESS(*entry); - range.size = LARGE_ENTRY_SIZE(*entry); - szone->num_large_objects_in_use --; - szone->num_bytes_in_large_objects -= range.size; - if (szone->debug_flags & SCALABLE_MALLOC_ADD_GUARD_PAGES) { - protect(szone, range.address, range.size, VM_PROT_READ | VM_PROT_WRITE, szone->debug_flags); - range.address -= vm_page_size; - range.size += 2 * vm_page_size; - } - // printf("Entry is 0x%x=%d; cache is 0x%x ; found=0x%x\n", entry, entry-szone->large_entries, szone->large_entries, large_entry_for_pointer_no_lock(szone, (void *)range.address)); - entry->address_and_num_pages = 0; - large_entries_rehash_after_entry_no_lock(szone, entry); -#if DEBUG_MALLOC - if (large_entry_for_pointer_no_lock(szone, (void *)range.address)) { - malloc_printf("*** malloc[%d]: Freed entry 0x%x still in use; num_large_entries=%d\n", getpid(), range.address, szone->num_large_entries); - large_cache_debug_print(szone); - large_debug_print(szone); - sleep(3600); - } -#endif - return range; -} - -static vm_range_t large_find_better_range_to_deallocate(szone_t *szone, vm_range_t range) { - // enters the specified large entry into the cache of freed entries - // returns a range to truly deallocate - vm_range_t *range_to_use; - vm_range_t vm_range_to_deallocate; - - // if the specified range in larger than MAX_LARGE_SIZE_TO_CACHE the range is not cached - if (range.size > MAX_LARGE_SIZE_TO_CACHE) return range; - - range = coalesce_range(szone->large_to_deallocate, LARGE_CACHE_SIZE, range); - range_to_use = first_zero_range(szone->large_to_deallocate, LARGE_CACHE_SIZE); - if (range_to_use) { - // we fill an empty slot - *range_to_use = range; - return zero_range; - } - // we always try to deallocate the largest chunk - range_to_use = largest_range(szone->large_to_deallocate, LARGE_CACHE_SIZE); - if (!range_to_use) return range; - vm_range_to_deallocate = *range_to_use; - *range_to_use = range; - return vm_range_to_deallocate; -} - -static kern_return_t large_in_use_enumerator(task_t task, void *context, unsigned type_mask, vm_address_t large_entries_address, unsigned num_entries, memory_reader_t reader, vm_range_recorder_t recorder) { - unsigned index = 0; - vm_range_t buffer[MAX_RECORDER_BUFFER]; - unsigned count = 0; - large_entry_t *entries; - kern_return_t err; - err = reader(task, large_entries_address, sizeof(large_entry_t) * num_entries, (void **)&entries); - if (err) return err; - index = num_entries; - if ((type_mask & MALLOC_ADMIN_REGION_RANGE_TYPE) && (num_entries * sizeof(large_entry_t) >= LARGE_THRESHOLD)) { - vm_range_t range; - range.address = large_entries_address; - range.size = round_page(num_entries * sizeof(large_entry_t)); - recorder(task, context, MALLOC_ADMIN_REGION_RANGE_TYPE, &range, 1); - } - if (type_mask & (MALLOC_PTR_IN_USE_RANGE_TYPE | MALLOC_PTR_REGION_RANGE_TYPE)) while (index--) { - large_entry_t entry = entries[index]; - if (!LARGE_ENTRY_IS_EMPTY(entry)) { - vm_range_t range; - range.address = LARGE_ENTRY_ADDRESS(entry); - range.size = LARGE_ENTRY_SIZE(entry); - buffer[count++] = range; - if (count >= MAX_RECORDER_BUFFER) { - recorder(task, context, MALLOC_PTR_IN_USE_RANGE_TYPE | MALLOC_PTR_REGION_RANGE_TYPE, buffer, count); - count = 0; - } - } - } - if (count) recorder(task, context, MALLOC_PTR_IN_USE_RANGE_TYPE | MALLOC_PTR_REGION_RANGE_TYPE, buffer, count); - return 0; -} - -/********************* HUGE ENTRY UTILITIES ************************/ - -static huge_entry_t *huge_entry_for_pointer_no_lock(szone_t *szone, const void *ptr) { - unsigned index = szone->num_huge_entries; - while (index--) { - huge_entry_t *huge = szone->huge_entries + index; - if (huge->address == (vm_address_t)ptr) return huge; - } - return NULL; -} - -static void huge_entry_append(szone_t *szone, huge_entry_t huge) { - // We do a little dance with locking because doing allocation (even in the default szone) may cause something to get freed in this szone, with a deadlock - huge_entry_t *new_huge_entries = NULL; - SZONE_LOCK(szone); - while (1) { - unsigned num_huge_entries; - num_huge_entries = szone->num_huge_entries; - SZONE_UNLOCK(szone); - // malloc_printf("In huge_entry_append currentEntries=%d\n", num_huge_entries); - if (new_huge_entries) szone_free(szone, new_huge_entries); - new_huge_entries = szone_malloc(szone, (num_huge_entries + 1) * sizeof(huge_entry_t)); - SZONE_LOCK(szone); - if (num_huge_entries == szone->num_huge_entries) { - // No change - our malloc still applies - huge_entry_t *old_huge_entries = szone->huge_entries; - if (num_huge_entries) memcpy(new_huge_entries, old_huge_entries, num_huge_entries * sizeof(huge_entry_t)); - new_huge_entries[szone->num_huge_entries++] = huge; - szone->huge_entries = new_huge_entries; - SZONE_UNLOCK(szone); - szone_free(szone, old_huge_entries); - // malloc_printf("Done huge_entry_append now=%d\n", szone->num_huge_entries); - return; - } - // try again! - } -} - -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) { - huge_entry_t *entries; - kern_return_t err; - err = reader(task, huge_entries_address, sizeof(huge_entry_t) * num_entries, (void **)&entries); - if (err) return err; - if (num_entries) recorder(task, context, MALLOC_PTR_IN_USE_RANGE_TYPE | MALLOC_PTR_REGION_RANGE_TYPE, entries, num_entries); - return 0; -} - -static void *large_and_huge_malloc(szone_t *szone, unsigned num_pages, boolean_t cleared_requested) { - vm_address_t addr = 0; - boolean_t cleared_needed = 0; // by default blocks will be freshly allocated and therefore no need to clean them - if (!num_pages) num_pages = 1; // minimal allocation size for this szone - // malloc_printf("In large_and_huge_malloc for %dKB\n", num_pages * vm_page_size / 1024); - if (num_pages >= (1 << vm_page_shift)) { - huge_entry_t huge; - huge.size = num_pages << vm_page_shift; - addr = allocate_pages(szone, huge.size, szone->debug_flags, VM_MAKE_TAG(VM_MEMORY_MALLOC_HUGE)); - if (!addr) return NULL; - huge.address = addr; - huge_entry_append(szone, huge); - SZONE_LOCK(szone); - szone->num_bytes_in_huge_objects += huge.size; - } else { - vm_size_t size = num_pages << vm_page_shift; - large_entry_t entry; - boolean_t add_guard_pages = szone->debug_flags & SCALABLE_MALLOC_ADD_GUARD_PAGES; - vm_size_t guard_pages = (add_guard_pages) ? 2 * vm_page_size : 0; - vm_range_t *range_to_use; - cleared_needed = cleared_requested; // in the "large" case set by default - SZONE_LOCK(szone); - // First check in the list large_to_deallocate if we can reuse - // malloc_printf("In szone_malloc checking recently deallocated\n"); - range_to_use = first_range_greater_or_equal(szone->large_to_deallocate, LARGE_CACHE_SIZE, size + guard_pages); - if (range_to_use) { - // that one will do! - addr = range_to_use->address + ((add_guard_pages) ? vm_page_size : 0); - if (add_guard_pages) protect(szone, addr, size, 0, szone->debug_flags); - // malloc_printf("In szone_malloc found recently deallocated at 0x%x for %d pages\n", addr, num_pages); - if (range_to_use->size == size + guard_pages) { - *range_to_use = zero_range; - } else { - range_to_use->address += size + guard_pages; - range_to_use->size -= size + guard_pages; - } -#if DEBUG_MALLOC - if (large_entry_for_pointer_no_lock(szone, (void *)addr)) { - malloc_printf("Entry about to be reused already in use: 0x%x\n", addr); - large_debug_print(szone); - sleep(3600); - } -#endif - } - if (!addr) { - // we need to really allocate_pages a new region - SZONE_UNLOCK(szone); - addr = allocate_pages(szone, size, szone->debug_flags, VM_MAKE_TAG(VM_MEMORY_MALLOC_LARGE)); - cleared_needed = 0; // since we allocated the pages, no need to clean them - if (LOG(szone, addr)) malloc_printf("In szone_malloc true large allocation at %p for %dKB\n", (void *)addr, size / 1024); - SZONE_LOCK(szone); - if (!addr) return NULL; -#if DEBUG_MALLOC - if (large_entry_for_pointer_no_lock(szone, (void *)addr)) { - malloc_printf("Freshly allocated is already in use: 0x%x\n", addr); - large_debug_print(szone); - sleep(3600); - } -#endif - } - if ((szone->num_large_objects_in_use + 1) * 4 > szone->num_large_entries) { - // density of hash table too high; grow table - // we do that under lock to avoid a race - // malloc_printf("In szone_malloc growing hash table current=%d\n", szone->num_large_entries); - large_entries_grow_no_lock(szone); - } - // malloc_printf("Inserting large entry (0x%x, %dKB)\n", addr, num_pages * vm_page_size / 1024); - entry.address_and_num_pages = addr | num_pages; -#if DEBUG_MALLOC - if (large_entry_for_pointer_no_lock(szone, (void *)addr)) { - malloc_printf("Entry about to be added already in use: 0x%x\n", addr); - large_debug_print(szone); - sleep(3600); - } -#endif - large_entry_insert_no_lock(szone, entry); -#if DEBUG_MALLOC - if (!large_entry_for_pointer_no_lock(szone, (void *)addr)) { - malloc_printf("Can't find entry just added\n"); - large_debug_print(szone); - sleep(3600); - } -#endif - // malloc_printf("Inserted large entry (0x%x, %d pages)\n", addr, num_pages); - szone->num_large_objects_in_use ++; - szone->num_bytes_in_large_objects += size; - } - SZONE_UNLOCK(szone); - if (cleared_needed) memset((void *)addr, 0, num_pages << vm_page_shift); - return (void *)addr; -} - -/********************* Zone call backs ************************/ - -static void szone_free(szone_t *szone, void *ptr) { - region_t *region; - large_entry_t *entry; - vm_range_t vm_range_to_deallocate; - huge_entry_t *huge; - if (LOG(szone, ptr)) malloc_printf("In szone_free with %p\n", ptr); - if (!ptr) return; - if ((vm_address_t)ptr & (QUANTUM - 1)) { - szone_error(szone, "Non-aligned pointer being freed", ptr); - return; - } - // try a small pointer - region = region_for_ptr_no_lock(szone, ptr); - if (region) { - // this is indeed a valid pointer - msize_t msize_and_free; - SZONE_LOCK(szone); - msize_and_free = MSIZE_FLAGS_FOR_PTR(ptr); - if (msize_and_free & THIS_FREE) { - szone_error(szone, "Object already freed being freed", ptr); - return; - } - CHECK(szone, __PRETTY_FUNCTION__); - small_free_no_lock(szone, region, ptr, msize_and_free); - CHECK(szone, __PRETTY_FUNCTION__); - SZONE_UNLOCK(szone); - return; - } - if (((unsigned)ptr) & (vm_page_size - 1)) { - szone_error(szone, "Non-page-aligned, non-allocated pointer being freed", ptr); - return; - } - SZONE_LOCK(szone); - entry = large_entry_for_pointer_no_lock(szone, ptr); - if (entry) { - // malloc_printf("Ready for deallocation [0x%x-%dKB]\n", LARGE_ENTRY_ADDRESS(*entry), LARGE_ENTRY_SIZE(*entry)/1024); - if (KILL_THRESHOLD && (LARGE_ENTRY_SIZE(*entry) > KILL_THRESHOLD)) { - // We indicate to the VM system that these pages contain garbage and therefore don't need to be swapped out - vm_msync(mach_task_self(), LARGE_ENTRY_ADDRESS(*entry), LARGE_ENTRY_SIZE(*entry), VM_SYNC_KILLPAGES); - } - vm_range_to_deallocate = large_free_no_lock(szone, entry); - vm_range_to_deallocate = large_find_better_range_to_deallocate(szone, vm_range_to_deallocate); -#if DEBUG_MALLOC - if (large_entry_for_pointer_no_lock(szone, ptr)) { - malloc_printf("*** malloc[%d]: Just after freeing 0x%x still in use num_large_entries=%d\n", getpid(), ptr, szone->num_large_entries); - large_cache_debug_print(szone); - large_debug_print(szone); - sleep(3600); - } -#endif - } else if ((huge = huge_entry_for_pointer_no_lock(szone, ptr))) { - vm_range_to_deallocate = *huge; - *huge = szone->huge_entries[--szone->num_huge_entries]; // last entry fills that spot - szone->num_bytes_in_huge_objects -= vm_range_to_deallocate.size; - } else { -#if DEBUG_MALLOC - large_debug_print(szone); -#endif - szone_error(szone, "Pointer being freed was not allocated", ptr); - return; - } - CHECK(szone, __PRETTY_FUNCTION__); - SZONE_UNLOCK(szone); // we release the lock asap - // we deallocate_pages, including guard pages - if (vm_range_to_deallocate.address) { - // malloc_printf("About to deallocate 0x%x size %dKB\n", vm_range_to_deallocate.address, vm_range_to_deallocate.size / 1024); -#if DEBUG_MALLOC - if (large_entry_for_pointer_no_lock(szone, (void *)vm_range_to_deallocate.address)) { - malloc_printf("*** malloc[%d]: Invariant broken: 0x%x still in use num_large_entries=%d\n", getpid(), vm_range_to_deallocate.address, szone->num_large_entries); - large_cache_debug_print(szone); - large_debug_print(szone); - sleep(3600); - } -#endif - deallocate_pages(szone, vm_range_to_deallocate.address, vm_range_to_deallocate.size, 0); - } -} - -static INLINE void *szone_malloc_should_clear(szone_t *szone, size_t size, boolean_t cleared_requested) { - void *ptr; - if (!((szone->debug_flags & SCALABLE_MALLOC_ADD_GUARD_PAGES) && PROTECT_SMALL) && (size < LARGE_THRESHOLD)) { - // think small - size_t msize = (size + PTR_HEADER_SIZE + QUANTUM - 1) >> SHIFT_QUANTUM; - if (msize < MIN_BLOCK) msize = MIN_BLOCK; - ptr = small_malloc_should_clear(szone, msize, cleared_requested); -#if DEBUG_MALLOC - if ((MSIZE_FLAGS_FOR_PTR(ptr) & ~ PREV_FREE) < msize) { - malloc_printf("ptr=%p this=%d msize=%d\n", ptr, MSIZE_FLAGS_FOR_PTR(ptr), (int)msize); - szone_error(szone, "Pointer allocated has improper size (1)", ptr); - return NULL; - } - if ((MSIZE_FLAGS_FOR_PTR(ptr) & ~ PREV_FREE) < MIN_BLOCK) { - malloc_printf("ptr=%p this=%d msize=%d\n", ptr, MSIZE_FLAGS_FOR_PTR(ptr), (int)msize); - szone_error(szone, "Pointer allocated has improper size (2)", ptr); - return NULL; - } -#endif - } else { - unsigned num_pages; - num_pages = round_page(size) >> vm_page_shift; - ptr = large_and_huge_malloc(szone, num_pages, cleared_requested); - } - if (LOG(szone, ptr)) malloc_printf("szone_malloc returned %p\n", ptr); - return ptr; -} - -static void *szone_malloc(szone_t *szone, size_t size) { - return szone_malloc_should_clear(szone, size, 0); -} - -static void *szone_calloc(szone_t *szone, size_t num_items, size_t size) { - return szone_malloc_should_clear(szone, num_items * size, 1); -} - -static void *szone_valloc(szone_t *szone, size_t size) { - void *ptr; - unsigned num_pages; - num_pages = round_page(size) >> vm_page_shift; - ptr = large_and_huge_malloc(szone, num_pages, 1); - if (LOG(szone, ptr)) malloc_printf("szone_valloc returned %p\n", ptr); - return ptr; -} - -static size_t szone_size(szone_t *szone, const void *ptr) { - size_t size = 0; - region_t *region; - large_entry_t *entry; - huge_entry_t *huge; - if (!ptr) return 0; - if (LOG(szone, ptr)) malloc_printf("In szone_size for %p (szone=%p)\n", ptr, szone); - if ((vm_address_t)ptr & (QUANTUM - 1)) return 0; - if ((((unsigned)ptr) & (vm_page_size - 1)) && (MSIZE_FLAGS_FOR_PTR(ptr) & THIS_FREE)) { - // not page aligned, but definitely not in use - return 0; - } - // Try a small pointer - region = region_for_ptr_no_lock(szone, ptr); - // malloc_printf("FOUND REGION %p\n", region); - if (region) { - // this is indeed a valid pointer - msize_t msize_and_free = MSIZE_FLAGS_FOR_PTR(ptr); - return (msize_and_free & THIS_FREE) ? 0 : ((msize_and_free & ~PREV_FREE) << SHIFT_QUANTUM) - PTR_HEADER_SIZE; - } - if (((unsigned)ptr) & (vm_page_size - 1)) { - return 0; - } - SZONE_LOCK(szone); - entry = large_entry_for_pointer_no_lock(szone, ptr); - if (entry) { - size = LARGE_ENTRY_SIZE(*entry); - } else if ((huge = huge_entry_for_pointer_no_lock(szone, ptr))) { - size = huge->size; - } - SZONE_UNLOCK(szone); - // malloc_printf("szone_size for large/huge %p returned %d\n", ptr, (unsigned)size); - if (LOG(szone, ptr)) malloc_printf("szone_size for %p returned %d\n", ptr, (unsigned)size); - return size; -} - -static INLINE int szone_try_realloc_in_place(szone_t *szone, void *ptr, size_t old_size, size_t new_size) { - // returns 1 on success - void *next_block = (char *)ptr + old_size + PTR_HEADER_SIZE; - msize_t next_msize_and_free; - msize_t next_msize; - region_t region; - msize_t coalesced_msize; - msize_t leftover_msize; - msize_t new_msize_and_free; - void *following_ptr; - SZONE_LOCK(szone); - region = szone->regions[szone->num_regions - 1]; - if (((vm_address_t)ptr >= region) && ((vm_address_t)ptr < region + REGION_SIZE) && ((vm_address_t)next_block == REGION_END(region) - szone->num_bytes_free_in_last_region + PTR_HEADER_SIZE)) { - // This could be optimized but it is so rare it's not worth it - SZONE_UNLOCK(szone); - return 0; - } - // If the next block is free, we coalesce - next_msize_and_free = MSIZE_FLAGS_FOR_PTR(next_block); -#if DEBUG_MALLOC - if ((vm_address_t)next_block & (QUANTUM - 1)) { - szone_error(szone, "Internal invariant broken in realloc(next_block)", next_block); - } - if (next_msize_and_free & PREV_FREE) { - malloc_printf("szone_try_realloc_in_place: 0x%x=PREV_FREE|%d\n", next_msize_and_free, next_msize_and_free & ~PREV_FREE); - SZONE_UNLOCK(szone); - return 0; - } -#endif - next_msize = next_msize_and_free & ~THIS_FREE; - if (!(next_msize_and_free & THIS_FREE) || !next_msize || (old_size + (next_msize << SHIFT_QUANTUM) < new_size)) { - SZONE_UNLOCK(szone); - return 0; - } - coalesced_msize = (new_size - old_size + QUANTUM - 1) >> SHIFT_QUANTUM; - leftover_msize = next_msize - coalesced_msize; - new_msize_and_free = MSIZE_FLAGS_FOR_PTR(ptr); - // malloc_printf("Realloc in place for %p; current msize=%d next_msize=%d wanted=%d\n", ptr, MSIZE_FLAGS_FOR_PTR(ptr), next_msize, new_size); - free_list_remove_ptr(szone, next_block, next_msize); - if ((leftover_msize < MIN_BLOCK) || (leftover_msize < coalesced_msize / 4)) { - // don't bother splitting it off - // malloc_printf("No leftover "); - coalesced_msize = next_msize; - leftover_msize = 0; - } else { - void *leftover = next_block + (coalesced_msize << SHIFT_QUANTUM); - // malloc_printf("Leftover "); - free_list_add_ptr(szone, leftover, leftover_msize); - } - new_msize_and_free += coalesced_msize; - MSIZE_FLAGS_FOR_PTR(ptr) = new_msize_and_free; - following_ptr = FOLLOWING_PTR(ptr, new_msize_and_free & ~PREV_FREE); - MSIZE_FLAGS_FOR_PTR(following_ptr) &= ~ PREV_FREE; -#if DEBUG_MALLOC - { - msize_t ms = MSIZE_FLAGS_FOR_PTR(following_ptr); - msize_t pms = PREVIOUS_MSIZE(FOLLOWING_PTR(following_ptr, ms & ~THIS_FREE)); - malloc_printf("Following ptr of coalesced (%p) has msize_and_free=0x%x=%s%d end_of_block_marker=%d\n", following_ptr, ms, (ms & THIS_FREE) ? "THIS_FREE|" : "", ms & ~THIS_FREE, pms); - } - if (LOG(szone,ptr)) malloc_printf("In szone_realloc(), ptr=%p, msize=%d\n", ptr, MSIZE_FLAGS_FOR_PTR(ptr)); -#endif - CHECK(szone, __PRETTY_FUNCTION__); - szone->num_bytes_in_small_objects += coalesced_msize << SHIFT_QUANTUM; - SZONE_UNLOCK(szone); - // malloc_printf("Extended ptr %p for realloc old=%d desired=%d new=%d leftover=%d\n", ptr, (unsigned)old_size, (unsigned)new_size, (unsigned)szone_size(szone, ptr), leftover_msize << SHIFT_QUANTUM); - return 1; -} - -static void *szone_realloc(szone_t *szone, void *ptr, size_t new_size) { - size_t old_size = 0; - void *newPtr; - if (LOG(szone, ptr)) malloc_printf("In szone_realloc for %p, %d\n", ptr, (unsigned)new_size); - if (!ptr) return szone_malloc(szone, new_size); - old_size = szone_size(szone, ptr); - if (!old_size) { - szone_error(szone, "Pointer being reallocated was not allocated", ptr); - return NULL; - } - if (old_size >= new_size) return ptr; - if (!((szone->debug_flags & SCALABLE_MALLOC_ADD_GUARD_PAGES) && PROTECT_SMALL) && (new_size < LARGE_THRESHOLD)) { - // We now try to realloc in place - if (szone_try_realloc_in_place(szone, ptr, old_size, new_size)) return ptr; - } - newPtr = szone_malloc(szone, new_size); - if ((old_size > VM_COPY_THRESHOLD) && (old_size < (1 << (vm_page_shift + vm_page_shift)))) { - // we know it's a large block, and not a huge block - kern_return_t err = 0; - err = vm_copy(mach_task_self(), (vm_address_t)ptr, old_size, (vm_address_t)newPtr); - if (err) { - szone_error(szone, "Can't vm_copy region", ptr); - } else { - large_entry_t *entry; - vm_range_t range; - SZONE_LOCK(szone); - entry = large_entry_for_pointer_no_lock(szone, ptr); - if (!entry) { - szone_error(szone, "Can't find entry for large copied block", ptr); - } - range = large_free_no_lock(szone, entry); - SZONE_UNLOCK(szone); // we release the lock asap - // we truly deallocate_pages, including guard pages - deallocate_pages(szone, range.address, range.size, 0); - if (LOG(szone, ptr)) malloc_printf("szone_realloc returned %p for %d\n", newPtr, (unsigned)new_size); - return newPtr; - } - } else { - memcpy(newPtr, ptr, old_size); - } - szone_free(szone, ptr); - if (LOG(szone, ptr)) malloc_printf("szone_realloc returned %p for %d\n", newPtr, (unsigned)new_size); - return newPtr; -} - -static void szone_destroy(szone_t *szone) { - unsigned index; - index = szone->num_large_entries; - while (index--) { - large_entry_t *entry = szone->large_entries + index; - if (!LARGE_ENTRY_IS_EMPTY(*entry)) { - large_entry_t range; - range = *entry; - // we deallocate_pages, including guard pages - deallocate_pages(szone, LARGE_ENTRY_ADDRESS(range), LARGE_ENTRY_SIZE(range), szone->debug_flags); - } - } - if (szone->num_large_entries * sizeof(large_entry_t) >= LARGE_THRESHOLD) large_entries_free_no_lock(szone, szone->large_entries, szone->num_large_entries); // we do not free in the small chunk case - index = LARGE_CACHE_SIZE; - while (index--) { - vm_range_t range = szone->large_to_deallocate[index]; - if (range.size) deallocate_pages(szone, range.address, range.size, 0); - } - index = szone->num_huge_entries; - while (index--) { - huge_entry_t *huge = szone->huge_entries + index; - deallocate_pages(szone, huge->address, huge->size, szone->debug_flags); - } - // and now we free regions, with regions[0] as the last one (the final harakiri) - index = szone->num_regions; - while (index--) { // we skip the first region, that is the zone itself - region_t region = szone->regions[index]; - deallocate_pages(szone, REGION_ADDRESS(region), REGION_SIZE, 0); - } -} - -static size_t szone_good_size(szone_t *szone, size_t size) { - if (!((szone->debug_flags & SCALABLE_MALLOC_ADD_GUARD_PAGES) && PROTECT_SMALL) && (size < LARGE_THRESHOLD)) { - // think small - msize_t msize = (size + PTR_HEADER_SIZE + QUANTUM - 1) >> SHIFT_QUANTUM; - if (msize < MIN_BLOCK) msize = MIN_BLOCK; - return (msize << SHIFT_QUANTUM) - PTR_HEADER_SIZE; - } else { - unsigned num_pages; - num_pages = round_page(size) >> vm_page_shift; - if (!num_pages) num_pages = 1; // minimal allocation size for this - return num_pages << vm_page_shift; - } -} - -unsigned szone_check_counter = 0; -unsigned szone_check_start = 0; -unsigned szone_check_modulo = 1; - -static boolean_t szone_check_all(szone_t *szone, const char *function) { - unsigned index = 0; - SZONE_LOCK(szone); - while (index < szone->num_regions) { - region_t *region = szone->regions + index++; - if (!szone_check_region(szone, region)) { - SZONE_UNLOCK(szone); - szone->debug_flags &= ~ CHECK_REGIONS; - malloc_printf("*** malloc[%d]: Region %d incorrect szone_check_all(%s) counter=%d\n", getpid(), index-1, function, szone_check_counter); - szone_error(szone, "Check: region incorrect", NULL); - return 0; - } - } - index = 0; - while (index < MAX_GRAIN) { - if (! free_list_check(szone, index)) { - SZONE_UNLOCK(szone); - szone->debug_flags &= ~ CHECK_REGIONS; - malloc_printf("*** malloc[%d]: Free list incorrect (grain=%d) szone_check_all(%s) counter=%d\n", getpid(), index, function, szone_check_counter); - szone_error(szone, "Check: free list incorrect", NULL); - return 0; - } - index++; - } - SZONE_UNLOCK(szone); - return 1; -} - -static boolean_t szone_check(szone_t *szone) { - if (! (++szone_check_counter % 10000)) { - malloc_printf("At szone_check counter=%d\n", szone_check_counter); - } - if (szone_check_counter < szone_check_start) return 1; - if (szone_check_counter % szone_check_modulo) return 1; - return szone_check_all(szone, ""); -} - -static kern_return_t szone_ptr_in_use_enumerator(task_t task, void *context, unsigned type_mask, vm_address_t zone_address, memory_reader_t reader, vm_range_recorder_t recorder) { - szone_t *szone; - kern_return_t err; - if (!reader) reader = _szone_default_reader; - // malloc_printf("Enumerator for zone 0x%x\n", zone_address); - err = reader(task, zone_address, sizeof(szone_t), (void **)&szone); - if (err) return err; - // malloc_printf("Small ptrs enumeration for zone 0x%x\n", zone_address); - err = small_in_use_enumerator(task, context, type_mask, (vm_address_t)szone->regions, szone->num_regions, reader, recorder); - if (err) return err; - // malloc_printf("Large ptrs enumeration for zone 0x%x\n", zone_address); - err = large_in_use_enumerator(task, context, type_mask, (vm_address_t)szone->large_entries, szone->num_large_entries, reader, recorder); - if (err) return err; - // malloc_printf("Huge ptrs enumeration for zone 0x%x\n", zone_address); - err = huge_in_use_enumerator(task, context, type_mask, (vm_address_t)szone->huge_entries, szone->num_huge_entries, reader, recorder); - return err; -} - -static void szone_print_free_list(szone_t *szone) { - grain_t grain = MAX_GRAIN; - malloc_printf("Free Sizes: "); - while (grain--) { - free_list_t *ptr = szone->free_list[grain]; - if (ptr) { - unsigned count = 0; - while (ptr) { - count++; - // malloc_printf("%p ", ptr); - ptr = ptr->next; - } - malloc_printf("%s%d[%d] ", (grain == MAX_GRAIN-1) ? ">=" : "", (grain+1)*QUANTUM, count); - } - } - malloc_printf("\n"); -} - -static void szone_print(szone_t *szone, boolean_t verbose) { - unsigned info[scalable_zone_info_count]; - unsigned index; - unsigned num = 0; - index = LARGE_CACHE_SIZE; - while (index--) if (szone->large_to_deallocate[index].size) num++; - index = 0; - scalable_zone_info((void *)szone, info, scalable_zone_info_count); - malloc_printf("Scalable zone %p: inUse=%d(%dKB) small=%d(%dKB) large=%d(%dKB) to_be_deallocated=%d huge=%d(%dKB) guard_page=%d\n", szone, info[0], info[1] / 1024, info[2], info[3] / 1024, info[4], info[5] / 1024, num, info[6], info[7] / 1024, info[8]); - malloc_printf("%d regions: \n", szone->num_regions); - while (index < szone->num_regions) { - region_t *region = szone->regions + index; - unsigned counts[512]; - unsigned ci = 0; - unsigned in_use = 0; - vm_address_t start = REGION_ADDRESS(*region) + QUANTUM; - memset(counts, 0, 512 * sizeof(unsigned)); - while (start < REGION_END(*region)) { - msize_t msize_and_free = MSIZE_FLAGS_FOR_PTR(start); - if (!(msize_and_free & THIS_FREE)) { - msize_t msize = msize_and_free & ~PREV_FREE; - if (!msize) break; // last encountered - // block in use - if (msize < 512) counts[msize]++; - start += msize << SHIFT_QUANTUM; - in_use++; - } else { - msize_t msize = msize_and_free & ~THIS_FREE; - // free block - start += msize << SHIFT_QUANTUM; - } - } - malloc_printf("Region [0x%x-0x%x, %dKB] \tIn_use=%d ", REGION_ADDRESS(*region), REGION_END(*region), (int)REGION_SIZE / 1024, in_use); - if (verbose) { - malloc_printf("\n\tSizes in use: "); - while (ci < 512) { - if (counts[ci]) malloc_printf("%d[%d] ", ci << SHIFT_QUANTUM, counts[ci]); - ci++; - } - } - malloc_printf("\n"); - index++; - } - if (verbose) szone_print_free_list(szone); - malloc_printf("Free in last zone %d\n", szone->num_bytes_free_in_last_region); -} - -static void szone_log(malloc_zone_t *zone, void *log_address) { - szone_t *szone = (void *)zone; - szone->log_address = log_address; -} - -static void szone_force_lock(szone_t *szone) { - // malloc_printf("szone_force_lock\n"); - SZONE_LOCK(szone); -} - -static void szone_force_unlock(szone_t *szone) { - // malloc_printf("szone_force_unlock\n"); - SZONE_UNLOCK(szone); -} - -static struct malloc_introspection_t szone_introspect = {(void *)szone_ptr_in_use_enumerator, (void *)szone_good_size, (void *)szone_check, (void *)szone_print, szone_log, (void *)szone_force_lock, (void *)szone_force_unlock}; - -malloc_zone_t *create_scalable_zone(size_t initial_size, unsigned debug_flags) { - szone_t *szone; - vm_address_t addr; - size_t msize; - size_t msize_used = 0; - if (!vm_page_shift) { - unsigned page; - vm_page_shift = 12; // the minimal for page sizes - page = 1 << vm_page_shift; - while (page != vm_page_size) { page += page; vm_page_shift++;}; - if (MIN_BLOCK * QUANTUM < sizeof(free_list_t) + PTR_HEADER_SIZE) { - malloc_printf("*** malloc[%d]: inconsistant parameters\n", getpid()); - } - } - addr = allocate_pages(NULL, REGION_SIZE, 0, VM_MAKE_TAG(VM_MEMORY_MALLOC)); - if (!addr) return NULL; - szone = (void *)(addr + QUANTUM); - msize = (sizeof(szone_t) + PTR_HEADER_SIZE + QUANTUM-1) >> SHIFT_QUANTUM; - MSIZE_FLAGS_FOR_PTR(szone) = msize; - msize_used += msize; szone->num_small_objects++; - szone->basic_zone.size = (void *)szone_size; - szone->basic_zone.malloc = (void *)szone_malloc; - szone->basic_zone.calloc = (void *)szone_calloc; - szone->basic_zone.valloc = (void *)szone_valloc; - szone->basic_zone.free = (void *)szone_free; - szone->basic_zone.realloc = (void *)szone_realloc; - szone->basic_zone.destroy = (void *)szone_destroy; - szone->basic_zone.introspect = &szone_introspect; - LOCK_INIT(szone->lock); - szone->debug_flags = debug_flags; - szone->regions = (void *)((char *)szone + (msize << SHIFT_QUANTUM)); - // we always reserve room for a few regions - msize = (sizeof(region_t) * INITIAL_NUM_REGIONS + PTR_HEADER_SIZE + QUANTUM-1) >> SHIFT_QUANTUM; - if (msize < MIN_BLOCK) msize = MIN_BLOCK; - MSIZE_FLAGS_FOR_PTR(szone->regions) = msize; - msize_used += msize; szone->num_small_objects++; - szone->regions[0] = addr; - szone->num_regions = 1; - szone->num_bytes_free_in_last_region = REGION_SIZE - ((msize_used+1) << SHIFT_QUANTUM) + PTR_HEADER_SIZE; - CHECK(szone, __PRETTY_FUNCTION__); - return (malloc_zone_t *)szone; -} - -/********* The following is private API for debug and perf tools ************/ - -void scalable_zone_info(malloc_zone_t *zone, unsigned *info_to_fill, unsigned count) { - szone_t *szone = (void *)zone; - unsigned info[scalable_zone_info_count]; - // We do not lock to facilitate debug - info[2] = szone->num_small_objects; - info[3] = szone->num_bytes_in_small_objects; - info[4] = szone->num_large_objects_in_use; - info[5] = szone->num_bytes_in_large_objects; - info[6] = szone->num_huge_entries; - info[7] = szone->num_bytes_in_huge_objects; - info[8] = szone->debug_flags; - info[0] = info[2] + info[4] + info[6]; - info[1] = info[3] + info[5] + info[7]; - memcpy(info_to_fill, info, sizeof(unsigned)*count); -} - diff --git a/gen.subproj/scalable_malloc.h b/gen.subproj/scalable_malloc.h deleted file mode 100644 index 8891c3d..0000000 --- a/gen.subproj/scalable_malloc.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ - -#import - -#define SCALABLE_MALLOC_ADD_GUARD_PAGES (1 << 0) - // add a guard page before and after each VM region to help debug -#define SCALABLE_MALLOC_DONT_PROTECT_PRELUDE (1 << 1) - // do not protect prelude page -#define SCALABLE_MALLOC_DONT_PROTECT_POSTLUDE (1 << 2) - // do not protect postlude page -#define SCALABLE_MALLOC_DO_SCRIBBLE (1 << 3) - // write 0x55 onto free blocks - -extern malloc_zone_t *create_scalable_zone(size_t initial_size, unsigned debug_flags); - /* Create a new zone that scales for small objects or large objects */ - -/***** Private API for debug and performance tools ********/ - -#define scalable_zone_info_count 9 // maximum number of numbers - -extern void scalable_zone_info(malloc_zone_t *zone, unsigned *info, unsigned count); - /* Fills info[] with some statistical information: - info[0]: number of objects in use - info[1]: number of bytes in use - ... - */ - diff --git a/gen.subproj/scandir.c b/gen.subproj/scandir.c deleted file mode 100644 index d963bbd..0000000 --- a/gen.subproj/scandir.c +++ /dev/null @@ -1,153 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1983, 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. - */ - - -/* - * Scan the directory dirname calling select to make a list of selected - * directory entries then sort using qsort and compare routine dcomp. - * Returns the number of entries and a pointer to a list of pointers to - * struct dirent (through namelist). Returns -1 if there were any errors. - */ - -#include -#include -#include -#include -#include - -/* - * The DIRSIZ macro is the minimum record length which will hold the directory - * entry. This requires the amount of space in struct dirent without the - * d_name field, plus enough space for the name and a terminating nul byte - * (dp->d_namlen + 1), rounded up to a 4 byte boundary. - */ -#undef DIRSIZ -#define DIRSIZ(dp) \ - ((sizeof(struct dirent) - sizeof(dp)->d_name) + \ - (((dp)->d_namlen + 1 + 3) &~ 3)) - -int -scandir(dirname, namelist, select, dcomp) - const char *dirname; - struct dirent ***namelist; - int (*select) __P((struct dirent *)); - int (*dcomp) __P((const void *, const void *)); -{ - register struct dirent *d, *p, **names; - register size_t nitems; - struct stat stb; - long arraysz; - DIR *dirp; - - if ((dirp = opendir(dirname)) == NULL) - return(-1); - if (fstat(dirp->dd_fd, &stb) < 0) - return(-1); - - /* - * estimate the array size by taking the size of the directory file - * and dividing it by a multiple of the minimum size entry. - */ - arraysz = (stb.st_size / 24); - names = (struct dirent **)malloc(arraysz * sizeof(struct dirent *)); - if (names == NULL) - return(-1); - - nitems = 0; - while ((d = readdir(dirp)) != NULL) { - if (select != NULL && !(*select)(d)) - continue; /* just selected names */ - /* - * Make a minimum size copy of the data - */ - p = (struct dirent *)malloc(DIRSIZ(d)); - if (p == NULL) - return(-1); - p->d_ino = d->d_ino; - p->d_reclen = d->d_reclen; - p->d_namlen = d->d_namlen; - bcopy(d->d_name, p->d_name, p->d_namlen + 1); - /* - * Check to make sure the array has space left and - * realloc the maximum size. - */ - if (++nitems >= arraysz) { - if (fstat(dirp->dd_fd, &stb) < 0) - return(-1); /* just might have grown */ - arraysz = stb.st_size / 12; - names = (struct dirent **)realloc((char *)names, - arraysz * sizeof(struct dirent *)); - if (names == NULL) - return(-1); - } - names[nitems-1] = p; - } - closedir(dirp); - if (nitems && dcomp != NULL) - qsort(names, nitems, sizeof(struct dirent *), dcomp); - *namelist = names; - return(nitems); -} - -/* - * Alphabetic order comparison routine for those who want it. - */ -int -alphasort(d1, d2) - const void *d1; - const void *d2; -{ - return(strcmp((*(struct dirent **)d1)->d_name, - (*(struct dirent **)d2)->d_name)); -} diff --git a/gen.subproj/seekdir.c b/gen.subproj/seekdir.c deleted file mode 100644 index b005ed2..0000000 --- a/gen.subproj/seekdir.c +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1983, 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 -#include - -/* - * Seek to an entry in a directory. - * _seekdir is in telldir.c so that it can share opaque data structures. - */ -void -seekdir(dirp, loc) - DIR *dirp; - long loc; -{ - - _seekdir(dirp, loc); -} diff --git a/gen.subproj/sethostname.c b/gen.subproj/sethostname.c deleted file mode 100644 index 7947676..0000000 --- a/gen.subproj/sethostname.c +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1989, 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 -#include - -#if __STDC__ -long -sethostname(const char *name, int namelen) -#else -long -sethostname(name, namelen) - char *name; - int namelen; -#endif -{ - int mib[2]; - - mib[0] = CTL_KERN; - mib[1] = KERN_HOSTNAME; - if (sysctl(mib, 2, NULL, NULL, (void *)name, namelen) == -1) - return (-1); - return (0); -} - - diff --git a/gen.subproj/setlogin.c b/gen.subproj/setlogin.c deleted file mode 100644 index 5c6b5a3..0000000 --- a/gen.subproj/setlogin.c +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1988, 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 - -extern int _logname_valid; /* shared with getlogin() */ - -int setlogin(const char* name) -{ - return (_logname_valid = _setlogin(name)); -} diff --git a/gen.subproj/setmode.c b/gen.subproj/setmode.c deleted file mode 100644 index dc2cc3a..0000000 --- a/gen.subproj/setmode.c +++ /dev/null @@ -1,471 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1989, 1993, 1994 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Dave Borman at Cray Research, 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. - */ - - -#include -#include - -#include -#include -#include -#include -#include - -#ifdef SETMODE_DEBUG -#include -#endif - -#define SET_LEN 6 /* initial # of bitcmd struct to malloc */ -#define SET_LEN_INCR 4 /* # of bitcmd structs to add as needed */ - -typedef struct bitcmd { - char cmd; - char cmd2; - mode_t bits; -} BITCMD; - -#define CMD2_CLR 0x01 -#define CMD2_SET 0x02 -#define CMD2_GBITS 0x04 -#define CMD2_OBITS 0x08 -#define CMD2_UBITS 0x10 - -static BITCMD *addcmd __P((BITCMD *, int, int, int, u_int)); -static int compress_mode __P((BITCMD *)); -#ifdef SETMODE_DEBUG -static void dumpmode __P((BITCMD *)); -#endif - -/* - * Given the old mode and an array of bitcmd structures, apply the operations - * described in the bitcmd structures to the old mode, and return the new mode. - * Note that there is no '=' command; a strict assignment is just a '-' (clear - * bits) followed by a '+' (set bits). - */ -mode_t -getmode(bbox, omode) - void *bbox; - mode_t omode; -{ - register BITCMD *set; - register mode_t clrval, newmode, value; - - set = (BITCMD *)bbox; - newmode = omode; - for (value = 0;; set++) - switch(set->cmd) { - /* - * When copying the user, group or other bits around, we "know" - * where the bits are in the mode so that we can do shifts to - * copy them around. If we don't use shifts, it gets real - * grundgy with lots of single bit checks and bit sets. - */ - case 'u': - value = (newmode & S_IRWXU) >> 6; - goto common; - - case 'g': - value = (newmode & S_IRWXG) >> 3; - goto common; - - case 'o': - value = newmode & S_IRWXO; -common: if (set->cmd2 & CMD2_CLR) { - clrval = - (set->cmd2 & CMD2_SET) ? S_IRWXO : value; - if (set->cmd2 & CMD2_UBITS) - newmode &= ~((clrval<<6) & set->bits); - if (set->cmd2 & CMD2_GBITS) - newmode &= ~((clrval<<3) & set->bits); - if (set->cmd2 & CMD2_OBITS) - newmode &= ~(clrval & set->bits); - } - if (set->cmd2 & CMD2_SET) { - if (set->cmd2 & CMD2_UBITS) - newmode |= (value<<6) & set->bits; - if (set->cmd2 & CMD2_GBITS) - newmode |= (value<<3) & set->bits; - if (set->cmd2 & CMD2_OBITS) - newmode |= value & set->bits; - } - break; - - case '+': - newmode |= set->bits; - break; - - case '-': - newmode &= ~set->bits; - break; - - case 'X': - if (omode & (S_IFDIR|S_IXUSR|S_IXGRP|S_IXOTH)) - newmode |= set->bits; - break; - - case '\0': - default: -#ifdef SETMODE_DEBUG - (void)printf("getmode:%04o -> %04o\n", omode, newmode); -#endif - return (newmode); - } -} - -#define ADDCMD(a, b, c, d) \ - if (set >= endset) { \ - register BITCMD *newset; \ - setlen += SET_LEN_INCR; \ - newset = realloc(saveset, sizeof(BITCMD) * setlen); \ - if (!saveset) \ - return (NULL); \ - set = newset + (set - saveset); \ - saveset = newset; \ - endset = newset + (setlen - 2); \ - } \ - set = addcmd(set, (a), (b), (c), (d)) - -#define STANDARD_BITS (S_ISUID|S_ISGID|S_IRWXU|S_IRWXG|S_IRWXO) - -void * -setmode(p) - register char *p; -{ - register int perm, who; - register char op; - BITCMD *set, *saveset, *endset; - sigset_t sigset, sigoset; - mode_t mask; - int equalopdone, permXbits, setlen; - - if (!*p) - return (NULL); - - /* - * Get a copy of the mask for the permissions that are mask relative. - * Flip the bits, we want what's not set. Since it's possible that - * the caller is opening files inside a signal handler, protect them - * as best we can. - */ - sigfillset(&sigset); - (void)sigprocmask(SIG_BLOCK, &sigset, &sigoset); - (void)umask(mask = umask(0)); - mask = ~mask; - (void)sigprocmask(SIG_SETMASK, &sigoset, NULL); - - setlen = SET_LEN + 2; - - if ((set = malloc((u_int)(sizeof(BITCMD) * setlen))) == NULL) - return (NULL); - saveset = set; - endset = set + (setlen - 2); - - /* - * If an absolute number, get it and return; disallow non-octal digits - * or illegal bits. - */ - if (isdigit(*p)) { - perm = (mode_t)strtol(p, NULL, 8); - if (perm & ~(STANDARD_BITS|S_ISTXT)) { - free(saveset); - return (NULL); - } - while (*++p) - if (*p < '0' || *p > '7') { - free(saveset); - return (NULL); - } - ADDCMD('=', (STANDARD_BITS|S_ISTXT), perm, mask); - return (saveset); - } - - /* - * Build list of structures to set/clear/copy bits as described by - * each clause of the symbolic mode. - */ - for (;;) { - /* First, find out which bits might be modified. */ - for (who = 0;; ++p) { - switch (*p) { - case 'a': - who |= STANDARD_BITS; - break; - case 'u': - who |= S_ISUID|S_IRWXU; - break; - case 'g': - who |= S_ISGID|S_IRWXG; - break; - case 'o': - who |= S_IRWXO; - break; - default: - goto getop; - } - } - -getop: if ((op = *p++) != '+' && op != '-' && op != '=') { - free(saveset); - return (NULL); - } - if (op == '=') - equalopdone = 0; - - who &= ~S_ISTXT; - for (perm = 0, permXbits = 0;; ++p) { - switch (*p) { - case 'r': - perm |= S_IRUSR|S_IRGRP|S_IROTH; - break; - case 's': - /* If only "other" bits ignore set-id. */ - if (who & ~S_IRWXO) - perm |= S_ISUID|S_ISGID; - break; - case 't': - /* If only "other" bits ignore sticky. */ - if (who & ~S_IRWXO) { - who |= S_ISTXT; - perm |= S_ISTXT; - } - break; - case 'w': - perm |= S_IWUSR|S_IWGRP|S_IWOTH; - break; - case 'X': - permXbits = S_IXUSR|S_IXGRP|S_IXOTH; - break; - case 'x': - perm |= S_IXUSR|S_IXGRP|S_IXOTH; - break; - case 'u': - case 'g': - case 'o': - /* - * When ever we hit 'u', 'g', or 'o', we have - * to flush out any partial mode that we have, - * and then do the copying of the mode bits. - */ - if (perm) { - ADDCMD(op, who, perm, mask); - perm = 0; - } - if (op == '=') - equalopdone = 1; - if (op == '+' && permXbits) { - ADDCMD('X', who, permXbits, mask); - permXbits = 0; - } - ADDCMD(*p, who, op, mask); - break; - - default: - /* - * Add any permissions that we haven't already - * done. - */ - if (perm || (op == '=' && !equalopdone)) { - if (op == '=') - equalopdone = 1; - ADDCMD(op, who, perm, mask); - perm = 0; - } - if (permXbits) { - ADDCMD('X', who, permXbits, mask); - permXbits = 0; - } - goto apply; - } - } - -apply: if (!*p) - break; - if (*p != ',') - goto getop; - ++p; - } - set->cmd = 0; -#ifdef SETMODE_DEBUG - (void)printf("Before compress_mode()\n"); - dumpmode(saveset); -#endif - compress_mode(saveset); -#ifdef SETMODE_DEBUG - (void)printf("After compress_mode()\n"); - dumpmode(saveset); -#endif - return (saveset); -} - -static BITCMD * -addcmd(set, op, who, oparg, mask) - BITCMD *set; - register int oparg, who; - register int op; - u_int mask; -{ - switch (op) { - case '=': - set->cmd = '-'; - set->bits = who ? who : STANDARD_BITS; - set++; - - op = '+'; - /* FALLTHROUGH */ - case '+': - case '-': - case 'X': - set->cmd = op; - set->bits = (who ? who : mask) & oparg; - break; - - case 'u': - case 'g': - case 'o': - set->cmd = op; - if (who) { - set->cmd2 = ((who & S_IRUSR) ? CMD2_UBITS : 0) | - ((who & S_IRGRP) ? CMD2_GBITS : 0) | - ((who & S_IROTH) ? CMD2_OBITS : 0); - set->bits = ~0; - } else { - set->cmd2 = CMD2_UBITS | CMD2_GBITS | CMD2_OBITS; - set->bits = mask; - } - - if (oparg == '+') - set->cmd2 |= CMD2_SET; - else if (oparg == '-') - set->cmd2 |= CMD2_CLR; - else if (oparg == '=') - set->cmd2 |= CMD2_SET|CMD2_CLR; - break; - } - return (set + 1); -} - -#ifdef SETMODE_DEBUG -static void -dumpmode(set) - register BITCMD *set; -{ - for (; set->cmd; ++set) - (void)printf("cmd: '%c' bits %04o%s%s%s%s%s%s\n", - set->cmd, set->bits, set->cmd2 ? " cmd2:" : "", - set->cmd2 & CMD2_CLR ? " CLR" : "", - set->cmd2 & CMD2_SET ? " SET" : "", - set->cmd2 & CMD2_UBITS ? " UBITS" : "", - set->cmd2 & CMD2_GBITS ? " GBITS" : "", - set->cmd2 & CMD2_OBITS ? " OBITS" : ""); -} -#endif - -/* - * Given an array of bitcmd structures, compress by compacting consecutive - * '+', '-' and 'X' commands into at most 3 commands, one of each. The 'u', - * 'g' and 'o' commands continue to be separate. They could probably be - * compacted, but it's not worth the effort. - */ -static int -compress_mode(set) - register BITCMD *set; -{ - register BITCMD *nset; - register int setbits, clrbits, Xbits, op; - - for (nset = set;;) { - /* Copy over any 'u', 'g' and 'o' commands. */ - while ((op = nset->cmd) != '+' && op != '-' && op != 'X') { - *set++ = *nset++; - if (!op) - return; - } - - for (setbits = clrbits = Xbits = 0;; nset++) { - if ((op = nset->cmd) == '-') { - clrbits |= nset->bits; - setbits &= ~nset->bits; - Xbits &= ~nset->bits; - } else if (op == '+') { - setbits |= nset->bits; - clrbits &= ~nset->bits; - Xbits &= ~nset->bits; - } else if (op == 'X') - Xbits |= nset->bits & ~setbits; - else - break; - } - if (clrbits) { - set->cmd = '-'; - set->cmd2 = 0; - set->bits = clrbits; - set++; - } - if (setbits) { - set->cmd = '+'; - set->cmd2 = 0; - set->bits = setbits; - set++; - } - if (Xbits) { - set->cmd = 'X'; - set->cmd2 = 0; - set->bits = Xbits; - set++; - } - } -} diff --git a/gen.subproj/siginterrupt.c b/gen.subproj/siginterrupt.c deleted file mode 100644 index 591f73c..0000000 --- a/gen.subproj/siginterrupt.c +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1989, 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 - -/* - * Set signal state to prevent restart of system calls - * after an instance of the indicated signal. - */ -siginterrupt(sig, flag) - int sig, flag; -{ - extern sigset_t _sigintr; - struct sigaction sa; - int ret; - - if ((ret = sigaction(sig, (struct sigaction *)0, &sa)) < 0) - return (ret); - if (flag) { - sigaddset(&_sigintr, sig); - sa.sa_flags &= ~SA_RESTART; - } else { - sigdelset(&_sigintr, sig); - sa.sa_flags |= SA_RESTART; - } - return (sigaction(sig, &sa, (struct sigaction *)0)); -} diff --git a/gen.subproj/siglist.c b/gen.subproj/siglist.c deleted file mode 100644 index 5c700fe..0000000 --- a/gen.subproj/siglist.c +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1983, 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 -#include - -const char *const sys_signame[NSIG] = { - "Signal 0", - "hup", /* SIGHUP */ - "int", /* SIGINT */ - "quit", /* SIGQUIT */ - "ill", /* SIGILL */ - "trap", /* SIGTRAP */ - "abrt", /* SIGABRT */ - "emt", /* SIGEMT */ - "fpe", /* SIGFPE */ - "kill", /* SIGKILL */ - "bus", /* SIGBUS */ - "segv", /* SIGSEGV */ - "sys", /* SIGSYS */ - "pipe", /* SIGPIPE */ - "alrm", /* SIGALRM */ - "term", /* SIGTERM */ - "urg", /* SIGURG */ - "stop", /* SIGSTOP */ - "tstp", /* SIGTSTP */ - "cont", /* SIGCONT */ - "chld", /* SIGCHLD */ - "ttin", /* SIGTTIN */ - "ttou", /* SIGTTOU */ - "io", /* SIGIO */ - "xcpu", /* SIGXCPU */ - "xfsz", /* SIGXFSZ */ - "vtalrm", /* SIGVTALRM */ - "prof", /* SIGPROF */ - "winch", /* SIGWINCH */ - "info", /* SIGINFO */ - "usr1", /* SIGUSR1 */ - "usr2", /* SIGUSR2 */ -}; - -const char *const sys_siglist[NSIG] = { - "Signal 0", - "Hangup", /* SIGHUP */ - "Interrupt", /* SIGINT */ - "Quit", /* SIGQUIT */ - "Illegal instruction", /* SIGILL */ - "Trace/BPT trap", /* SIGTRAP */ - "Abort trap", /* SIGABRT */ - "EMT trap", /* SIGEMT */ - "Floating point exception", /* SIGFPE */ - "Killed", /* SIGKILL */ - "Bus error", /* SIGBUS */ - "Segmentation fault", /* SIGSEGV */ - "Bad system call", /* SIGSYS */ - "Broken pipe", /* SIGPIPE */ - "Alarm clock", /* SIGALRM */ - "Terminated", /* SIGTERM */ - "Urgent I/O condition", /* SIGURG */ - "Suspended (signal)", /* SIGSTOP */ - "Suspended", /* SIGTSTP */ - "Continued", /* SIGCONT */ - "Child exited", /* SIGCHLD */ - "Stopped (tty input)", /* SIGTTIN */ - "Stopped (tty output)", /* SIGTTOU */ - "I/O possible", /* SIGIO */ - "Cputime limit exceeded", /* SIGXCPU */ - "Filesize limit exceeded", /* SIGXFSZ */ - "Virtual timer expired", /* SIGVTALRM */ - "Profiling timer expired", /* SIGPROF */ - "Window size changes", /* SIGWINCH */ - "Information request", /* SIGINFO */ - "User defined signal 1", /* SIGUSR1 */ - "User defined signal 2" /* SIGUSR2 */ -}; diff --git a/gen.subproj/signal.c b/gen.subproj/signal.c deleted file mode 100644 index e936bd9..0000000 --- a/gen.subproj/signal.c +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1985, 1989, 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. - */ - - -/* - * Almost backwards compatible signal. - */ -#include - -sigset_t _sigintr = 0; /* shared with siginterrupt */ - -static sig_t -signal__(s, a, bind) - int s; - sig_t a; - int bind; -{ - struct sigaction sa, osa; - - sa.sa_handler = a; - sigemptyset(&sa.sa_mask); - sa.sa_flags = 0; - if (!sigismember(&_sigintr, s)) - sa.sa_flags |= SA_RESTART; -#if defined(__DYNAMIC__) - if (bind) { -#endif - if (sigaction(s, &sa, &osa) < 0) - return (SIG_ERR); -#if defined(__DYNAMIC__) - } else { - if (_sigaction_nobind(s, &sa, &osa) < 0) - return (SIG_ERR); - } -#endif - return (osa.sa_handler); -} - -sig_t -signal(s, a) - int s; - sig_t a; -{ - return signal__(s, a, 1); -} - -#if defined(__DYNAMIC__) -sig_t -_signal_nobind(s, a) - int s; - sig_t a; -{ - return signal__(s, a, 0); -} -#endif diff --git a/gen.subproj/sigsetops.c b/gen.subproj/sigsetops.c deleted file mode 100644 index 9588381..0000000 --- a/gen.subproj/sigsetops.c +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1989, 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 - -#undef sigemptyset -#undef sigfillset -#undef sigaddset -#undef sigdelset -#undef sigismember - -sigemptyset(set) - sigset_t *set; -{ - *set = 0; - return (0); -} - -sigfillset(set) - sigset_t *set; -{ - *set = ~(sigset_t)0; - return (0); -} - -sigaddset(set, signo) - sigset_t *set; - int signo; -{ - *set |= sigmask(signo); - return (0); -} - -sigdelset(set, signo) - sigset_t *set; - int signo; -{ - *set &= ~sigmask(signo); - return (0); -} - -sigismember(set, signo) - const sigset_t *set; - int signo; -{ - return ((*set & ~sigmask(signo)) != 0); -} diff --git a/gen.subproj/sleep.c b/gen.subproj/sleep.c deleted file mode 100644 index e47b89e..0000000 --- a/gen.subproj/sleep.c +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ - -#include - -extern int nanosleep(const struct timespec *, struct timespec *); - -/* We use nanosleep and let it set errno, and compute the residual for us. */ -unsigned int -sleep(unsigned int seconds) -{ - struct timespec req, rem; - - if (seconds == 0) { - return 0; - } - req.tv_sec = seconds; - req.tv_nsec = 0; - - /* It's not clear from the spec whether the remainder will be 0 - ** if we weren't interrupted - */ - if (nanosleep(&req, &rem) == -1) { - return (unsigned int)rem.tv_sec; - } - return 0; -} diff --git a/gen.subproj/stack_logging.c b/gen.subproj/stack_logging.c deleted file mode 100644 index a8e7a4d..0000000 --- a/gen.subproj/stack_logging.c +++ /dev/null @@ -1,384 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ - -/* Bertrand from vmutils -> CF -> System */ - -#import "stack_logging.h" - -#import -#import -#import -#include - -extern void spin_lock(int *); - -static inline void *allocate_pages(unsigned bytes) { - void *address; - if (vm_allocate(mach_task_self(), (vm_address_t *)&address, bytes, - VM_MAKE_TAG(VM_MEMORY_ANALYSIS_TOOL)| TRUE)) { - address = 0; - } - return (void *)address; -} - -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 *source, void *dest, unsigned bytes) { - if (vm_copy(mach_task_self(), (vm_address_t)source, bytes, (vm_address_t)dest)) memmove(dest, source, bytes); -} - -/*************** Recording stack ***********/ - -static void *first_frame_address(void) { -#if 0 - return __builtin_frame_address(1); -#elif defined(__ppc__) - void *addr; -#warning __builtin_frame_address IS BROKEN IN BEAKER: RADAR #2340421 - __asm__ volatile("mr %0, r1" : "=r" (addr)); - return addr; -#else -#warning first_frame_address WILL NOT BE FUNCTIONAL ON THIS ARCHITECTURE - return NULL; -#endif -} - -static void *next_frame_address(void *addr) { - void *ret; -#if defined(__MACH__) && defined(__i386__) - __asm__ volatile("movl (%1),%0" : "=r" (ret) : "r" (addr)); -#elif defined(__MACH__) && defined(__ppc__) - __asm__ volatile("lwz %0,0x0(%1)" : "=r" (ret) : "r" (addr)); -#elif defined(__hpux__) - __asm__ volatile("ldw 0x0(%1),%0" : "=r" (ret) : "r" (addr)); -#elif defined(__svr4__) - __asm__ volatile("ta 0x3"); - __asm__ volatile("ld [%1 + 56],%0" : "=r" (ret) : "r" (addr)); -#else -#error Unknown architecture -#endif - return ret; -} - -#if defined(__i386__) || defined (__m68k__) -#define FP_LINK_OFFSET 1 -#elif defined(__ppc__) -#define FP_LINK_OFFSET 2 -#elif defined(__hppa__) -#define FP_LINK_OFFSET -5 -#elif defined(__sparc__) -#define FP_LINK_OFFSET 14 -#else -#error ********** Unimplemented architecture -#endif - -void thread_stack_pcs(vm_address_t *buffer, unsigned max, unsigned *nb) { - void *addr; - addr = first_frame_address(); - *nb = 0; - while ((addr >= (void *)0x800) && (max--)) { - vm_address_t fp_link = (vm_address_t)(((unsigned *)addr)+FP_LINK_OFFSET); - void *addr2; - buffer[*nb] = *((vm_address_t *)fp_link); - (*nb)++; - addr2 = next_frame_address(addr); -#if defined(__ppc__) - if ((unsigned)addr2 <= (unsigned)addr) break; // catch bozo frames -#endif - addr = addr2; - } -} - -/*************** Uniquing stack ***********/ - -#define MAX_COLLIDE 8 - -#define MAX_NUM_PC 512 - -static int enter_pair_in_table(unsigned *table, unsigned numPages, unsigned *uniquedParent, unsigned thisPC) { - // uniquedParent is in-out; return 1 is collisions max not exceeded - unsigned base = numPages * vm_page_size / (sizeof(int)*2*2); - unsigned hash = base + (((*uniquedParent) << 4) ^ (thisPC >> 2)) % (base - 1); // modulo odd number for hashing - unsigned collisions = MAX_COLLIDE; - while (collisions--) { - unsigned *head = table + hash*2; - if (! head[0] && !head[1]) { - /* end of chain; store this entry! */ - /* Note that we need to test for both head[0] and head[1] as (0, -1) is a valid entry */ - head[0] = thisPC; - head[1] = *uniquedParent; - *uniquedParent = hash; - return 1; - } - if ((head[0] == thisPC) && (head[1] == *uniquedParent)) { - /* we found the proper entry, the value for the pair is the entry offset */ - *uniquedParent = hash; - return 1; - } - hash++; - if (hash == base*2) hash = base; - } - return 0; -} - -unsigned stack_logging_get_unique_stack(unsigned **table, unsigned *table_num_pages, unsigned *stack_entries, unsigned count, unsigned num_hot_to_skip) { - unsigned uniquedParent = (unsigned)-1; - // we skip the warmest entries that are an artefact of the code - while (num_hot_to_skip--) { - if (count > 0) { stack_entries++; count--; } - } - while (count--) { - unsigned thisPC = stack_entries[count]; - while (!enter_pair_in_table(*table, *table_num_pages, &uniquedParent, thisPC)) { - unsigned *newTable; - unsigned oldBytes = (*table_num_pages) * vm_page_size; - newTable = allocate_pages(oldBytes*2); - copy_pages(*table, newTable, oldBytes); - deallocate_pages(*table, oldBytes); - *table_num_pages *= 2; - *table = newTable; - } - } - return uniquedParent; -} - -/*************** Logging stack and arguments ***********/ - -stack_logging_record_list_t *stack_logging_the_record_list = NULL; - -int stack_logging_enable_logging = 0; - -int stack_logging_dontcompact = 0; - -static stack_logging_record_list_t *GrowLogRecords(stack_logging_record_list_t *records, unsigned desiredNumRecords) { - stack_logging_record_list_t *new_records; - unsigned old_size = records->overall_num_bytes; - if (desiredNumRecords*sizeof(stack_logging_record_t)+sizeof(stack_logging_record_list_t) < records->overall_num_bytes) return records; - records->overall_num_bytes += records->overall_num_bytes + vm_page_size; // in order to always get an even number of pages - new_records = allocate_pages(records->overall_num_bytes); - copy_pages(records, new_records, old_size); - deallocate_pages(records, old_size); - return new_records; -} - -static void prepare_to_log_stack(void) { - if (!stack_logging_the_record_list) { - unsigned totalSize = 4 * vm_page_size; - stack_logging_the_record_list = allocate_pages(totalSize); - memset(stack_logging_the_record_list, 0, sizeof(stack_logging_record_list_t)); - stack_logging_the_record_list->overall_num_bytes = totalSize; - stack_logging_the_record_list->uniquing_table_num_pages = 128; - stack_logging_the_record_list->uniquing_table = allocate_pages(stack_logging_the_record_list->uniquing_table_num_pages * vm_page_size); - } -} - -void stack_logging_log_stack(unsigned type, unsigned arg1, unsigned arg2, unsigned arg3, unsigned result, unsigned num_hot_to_skip) { - stack_logging_record_t *rec; - if (!stack_logging_enable_logging) return; - // printf("stack_logging_log_stack 0x%x 0x%x 0x%x 0x%x -> 0x%x\n", type, arg1, arg2, arg3, result); - if (type & stack_logging_flag_zone) { - // just process it now and be done with it! - arg1 = arg2; arg2 = arg3; arg3 = 0; type &= ~stack_logging_flag_zone; - } - if (type & stack_logging_flag_calloc) { - // just process it now and be done with it! - arg1 *= arg2; arg2 = arg3; arg3 = 0; type &= ~stack_logging_flag_calloc; - } - if (type & stack_logging_flag_object) { - unsigned *class = (unsigned *)arg1; - arg1 = arg2 + class[5]; // corresponds to the instance_size field - arg2 = 0; arg3 = 0; type = stack_logging_type_alloc; - } - if (type & stack_logging_flag_cleared) { - type &= ~stack_logging_flag_cleared; - } - if (type & stack_logging_flag_handle) { - if (stack_logging_type_alloc) { - if (!result) return; - stack_logging_log_stack(stack_logging_type_alloc, 0, 0, 0, result, num_hot_to_skip+1); - stack_logging_log_stack(stack_logging_type_alloc, arg1, 0, 0, *((int *)result), num_hot_to_skip+1); - return; - } - if (stack_logging_type_dealloc) { - if (!arg1) return; - stack_logging_log_stack(stack_logging_type_dealloc, *((int *)arg1), 0, 0, 0, num_hot_to_skip+1); - stack_logging_log_stack(stack_logging_type_dealloc, arg1, 0, 0, 0, num_hot_to_skip+1); - return; - } - printf("*** Unknown logging type: 0x%x\n", type); - } - if (type == stack_logging_flag_set_handle_size) { - if (!arg1) return; - // Thanks to a horrible hack, arg3 contains the prvious handle value - if (arg3 == *((int *)arg1)) return; - stack_logging_log_stack(stack_logging_type_dealloc, arg3, 0, 0, 0, num_hot_to_skip+1); - stack_logging_log_stack(stack_logging_type_alloc, arg2, 0, 0, *((int *)arg1), num_hot_to_skip+1); - return; - } - if (type == (stack_logging_type_dealloc|stack_logging_type_alloc)) { - if (arg1 == result) return; // realloc had no effect, skipping - if (!arg1) { - // realloc(NULL, size) same as malloc(size) - type = stack_logging_type_alloc; arg1 = arg2; arg2 = arg3; arg3 = 0; - } else { - // realloc(arg1, arg2) -> result is same as free(arg1); malloc(arg2) -> result - stack_logging_log_stack(stack_logging_type_dealloc, arg1, 0, 0, 0, num_hot_to_skip+1); - stack_logging_log_stack(stack_logging_type_alloc, arg2, 0, 0, result, num_hot_to_skip+1); - return; - } - } - if (type == stack_logging_type_dealloc) { - // simple free - if (!arg1) return; // free(nil) - } - prepare_to_log_stack(); - spin_lock(&stack_logging_the_record_list->lock); - stack_logging_enable_logging = 0; - stack_logging_the_record_list = GrowLogRecords(stack_logging_the_record_list, stack_logging_the_record_list->num_records + 1); - rec = stack_logging_the_record_list->records + stack_logging_the_record_list->num_records; - // We take care of the common case of alloc-dealloc - if (!stack_logging_dontcompact && stack_logging_the_record_list->num_records && (type == stack_logging_type_dealloc) && arg1 && ((rec-1)->type == stack_logging_type_alloc) && (arg1 == STACK_LOGGING_DISGUISE((rec-1)->address))) { - stack_logging_the_record_list->num_records--; - // printf("Erased previous record in alloc-dealloc sequence\n"); - } else { - unsigned stack_entries[MAX_NUM_PC]; - unsigned count = 0; - rec->type = type; - if (type == stack_logging_type_dealloc) { - rec->argument = 0; - rec->address = STACK_LOGGING_DISGUISE(arg1); // we disguise the address - } else if (type == stack_logging_type_alloc) { - rec->argument = arg1; - rec->address = STACK_LOGGING_DISGUISE(result); // we disguise the address - } else { - rec->argument = arg2; - rec->address = STACK_LOGGING_DISGUISE(arg1); // we disguise the address - } - // printf("Before getting samples 0x%x 0x%x 0x%x 0x%x -> 0x%x\n", type, arg1, arg2, arg3, result); - thread_stack_pcs(stack_entries, MAX_NUM_PC - 1, &count); - // We put at the bottom of the stack a marker that denotes the thread (+1 for good measure...) - stack_entries[count++] = (int)pthread_self() + 1; - /* now let's unique the sample */ - // printf("Uniquing 0x%x 0x%x 0x%x 0x%x -> 0x%x\n", type, arg1, arg2, arg3, result); - rec->uniqued_stack = stack_logging_get_unique_stack(&stack_logging_the_record_list->uniquing_table, &stack_logging_the_record_list->uniquing_table_num_pages, stack_entries, count, num_hot_to_skip+2); // we additionally skip the warmest 2 entries that are an artefact of the code - stack_logging_the_record_list->num_records++; - } - stack_logging_enable_logging = 1; - stack_logging_the_record_list->lock = 0; -} - -static kern_return_t default_reader(task_t task, vm_address_t address, vm_size_t size, void **ptr) { - *ptr = (void *)address; - return 0; -} - -static kern_return_t get_remote_records(task_t task, memory_reader_t reader, stack_logging_record_list_t **records) { - // sets records - vm_address_t *remote_records_address_ref; - kern_return_t err; - *records = NULL; - err = reader(task, (vm_address_t)&stack_logging_the_record_list, sizeof(vm_address_t), (void **)&remote_records_address_ref); - if (err) return err; - if (!*remote_records_address_ref) { - // printf("stack_logging: no stack record\n"); - return 0; - } - // printf("stack_logging: stack records at %p\n", (void *)(*remote_records_address_ref)); - // printf("stack_logging: reading %d bytes\n", sizeof(stack_logging_record_list_t)); - err = reader(task, *remote_records_address_ref, sizeof(stack_logging_record_list_t), (void **)records); // get the list head - if (err) return err; - // printf("stack_logging: overall num bytes = %d\n", records->overall_num_bytes); - return reader(task, *remote_records_address_ref, (*records)->overall_num_bytes, (void **)records); -} - -kern_return_t stack_logging_get_frames(task_t task, memory_reader_t reader, vm_address_t address, vm_address_t *stack_frames_buffer, unsigned max_stack_frames, unsigned *num_frames) { - stack_logging_record_list_t *records; - kern_return_t err; - unsigned index; - unsigned disguised = STACK_LOGGING_DISGUISE(address); - if (!reader) reader = default_reader; - *num_frames = 0; - err = get_remote_records(task, reader, &records); - if (err || !records) return err; - // printf("stack_logging: %d records\n", records->num_records); - index = 0; - while (index < records->num_records) { - stack_logging_record_t *record = records->records + index; - if (record->address == disguised) { - return stack_logging_frames_for_uniqued_stack(task, reader, record->uniqued_stack, stack_frames_buffer, max_stack_frames, num_frames); - } - index++; - } - fprintf(stderr, "*** stack_logging: no record found for 0x%x\n", address); - return 0; -} - -kern_return_t stack_logging_enumerate_records(task_t task, memory_reader_t reader, vm_address_t address, void enumerator(stack_logging_record_t, void *), void *context) { - stack_logging_record_list_t *records; - kern_return_t err; - unsigned index; - unsigned disguised = STACK_LOGGING_DISGUISE(address); - if (!reader) reader = default_reader; - err = get_remote_records(task, reader, &records); - if (err || !records) return err; - // printf("stack_logging: %d records\n", records->num_records); - index = 0; - while (index < records->num_records) { - stack_logging_record_t *record = records->records + index; - if (!address || (record->address == disguised)) enumerator(*record, context); - index++; - } - return 0; -} - -kern_return_t stack_logging_frames_for_uniqued_stack(task_t task, memory_reader_t reader, unsigned uniqued_stack, vm_address_t *stack_frames_buffer, unsigned max_stack_frames, unsigned *num_frames) { - stack_logging_record_list_t *records; - unsigned *uniquing_table; - kern_return_t err; - if (!reader) reader = default_reader; - *num_frames = 0; - err = get_remote_records(task, reader, &records); - if (err || !records) return err; - err = reader(task, (vm_address_t)records->uniquing_table, records->uniquing_table_num_pages * vm_page_size, (void **)&uniquing_table); - if (err) return err; - while (max_stack_frames && (uniqued_stack != -1)) { - unsigned thisPC; - if ((uniqued_stack * 2 + 1) * sizeof(unsigned) >= records->uniquing_table_num_pages * vm_page_size) { - fprintf(stderr, "*** stack_logging: Invalid uniqued stack 0x%x", uniqued_stack); - break; - } - thisPC = uniquing_table[uniqued_stack * 2]; - uniqued_stack = uniquing_table[uniqued_stack * 2 + 1]; - if (!thisPC && !uniqued_stack) { - // Invalid entry - fprintf(stderr, "*** stack_logging: Invalid entry 0x%x", thisPC); - break; - } - stack_frames_buffer[0] = thisPC; - stack_frames_buffer++; - (*num_frames)++; - max_stack_frames--; - } - return 0; -} diff --git a/gen.subproj/stack_logging.h b/gen.subproj/stack_logging.h deleted file mode 100644 index 32ede79..0000000 --- a/gen.subproj/stack_logging.h +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ - -#import - -#define stack_logging_type_free 0 -#define stack_logging_type_generic 1 /* anything that is not allocation/deallocation */ -#define stack_logging_type_alloc 2 /* malloc, realloc, etc... */ -#define stack_logging_type_dealloc 4 /* free, realloc, etc... */ - -// Following flags are absorbed by stack_logging_log_stack() -#define stack_logging_flag_zone 8 /* NSZoneMalloc, etc... */ -#define stack_logging_flag_calloc 16 /* multiply arguments to get the size */ -#define stack_logging_flag_object 32 /* NSAllocateObject(Class, extraBytes, zone) */ -#define stack_logging_flag_cleared 64 /* for NewEmptyHandle */ -#define stack_logging_flag_handle 128 /* for Handle (de-)allocation routines */ -#define stack_logging_flag_set_handle_size 256 /* (Handle, newSize) treated specially */ - -/* Macro used to disguise addresses so that leak finding can work */ -#define STACK_LOGGING_DISGUISE(address) (((unsigned)address) ^ 0x00005555) /* nicely idempotent */ - -typedef struct { - unsigned type; - unsigned uniqued_stack; - unsigned argument; - unsigned address; /* disguised, to avoid confusing leaks */ -} stack_logging_record_t; - -typedef struct { - unsigned overall_num_bytes; - unsigned num_records; - unsigned lock; /* 0 means OK to lock; used for inter-process locking */ - unsigned *uniquing_table; /* allocated using vm_allocate() */ - /* hashtable organized as (PC, uniqued parent) - Only the second half of the table is active - To enable us to grow dynamically */ - unsigned uniquing_table_num_pages; /* number of pages of the table */ - unsigned extra_retain_count; /* not used by stack_logging_log_stack */ - unsigned filler[2]; /* align to cache lines for better performance */ - stack_logging_record_t records[0]; /* records follow here */ -} stack_logging_record_list_t; - -extern unsigned stack_logging_get_unique_stack(unsigned **table, unsigned *table_num_pages, unsigned *stack_entries, unsigned count, unsigned num_hot_to_skip); - /* stack_entries are from hot to cold */ - -extern stack_logging_record_list_t *stack_logging_the_record_list; - /* This is the global variable containing all logs */ - -extern int stack_logging_enable_logging; - /* when clear, no logging takes place */ - -extern int stack_logging_dontcompact; - /* default is to compact; when set does not compact alloc/free logs; useful for tracing history */ - -extern void stack_logging_log_stack(unsigned type, unsigned arg1, unsigned arg2, unsigned arg3, unsigned result, unsigned num_hot_to_skip); - -extern kern_return_t stack_logging_get_frames(task_t task, memory_reader_t reader, vm_address_t address, vm_address_t *stack_frames_buffer, unsigned max_stack_frames, unsigned *num_frames); - /* Gets the last record in stack_logging_the_record_list about address */ - -#define STACK_LOGGING_ENUMERATION_PROVIDED 1 // temporary to avoid dependencies between projects - -extern kern_return_t stack_logging_enumerate_records(task_t task, memory_reader_t reader, vm_address_t address, void enumerator(stack_logging_record_t, void *), void *context); - /* Gets all the records about address; - If !address, gets all records */ - -extern kern_return_t stack_logging_frames_for_uniqued_stack(task_t task, memory_reader_t reader, unsigned uniqued_stack, vm_address_t *stack_frames_buffer, unsigned max_stack_frames, unsigned *num_frames); - /* Given a uniqued_stack fills stack_frames_buffer */ - -extern void thread_stack_pcs(vm_address_t *buffer, unsigned max, unsigned *num); - /* Convenience to fill buffer with the PCs of the frames, starting with the hot frames; - num: returned number of frames - */ - diff --git a/gen.subproj/sysconf.c b/gen.subproj/sysconf.c deleted file mode 100644 index 32cf64c..0000000 --- a/gen.subproj/sysconf.c +++ /dev/null @@ -1,206 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Sean Eric Fagan of Cygnus Support. - * - * 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 -#include -#include -#include - -#include -#include - -/* - * sysconf -- - * get configurable system variables. - * - * XXX - * POSIX 1003.1 (ISO/IEC 9945-1, 4.8.1.3) states that the variable values - * not change during the lifetime of the calling process. This would seem - * to require that any change to system limits kill all running processes. - * A workaround might be to cache the values when they are first retrieved - * and then simply return the cached value on subsequent calls. This is - * less useful than returning up-to-date values, however. - */ -long -sysconf(name) - int name; -{ - struct clockinfo clk; - struct rlimit rl; - size_t len; - int mib[2], value; - - len = sizeof(value); - - switch (name) { -/* 1003.1 */ - case _SC_ARG_MAX: - mib[0] = CTL_KERN; - mib[1] = KERN_ARGMAX; - break; - case _SC_CHILD_MAX: - return (getrlimit(RLIMIT_NPROC, &rl) ? -1 : rl.rlim_cur); - case _SC_CLK_TCK: - return (CLK_TCK); - case _SC_JOB_CONTROL: - mib[0] = CTL_KERN; - mib[1] = KERN_JOB_CONTROL; - goto yesno; - case _SC_NGROUPS_MAX: - mib[0] = CTL_KERN; - mib[1] = KERN_NGROUPS; - break; - case _SC_OPEN_MAX: - return (getrlimit(RLIMIT_NOFILE, &rl) ? -1 : rl.rlim_cur); - case _SC_STREAM_MAX: - mib[0] = CTL_USER; - mib[1] = USER_STREAM_MAX; - break; - case _SC_TZNAME_MAX: - mib[0] = CTL_USER; - mib[1] = USER_TZNAME_MAX; - break; - case _SC_SAVED_IDS: - mib[0] = CTL_KERN; - mib[1] = KERN_SAVED_IDS; - goto yesno; - case _SC_VERSION: - mib[0] = CTL_KERN; - mib[1] = KERN_POSIX1; - break; - -/* 1003.2 */ - case _SC_BC_BASE_MAX: - mib[0] = CTL_USER; - mib[1] = USER_BC_BASE_MAX; - break; - case _SC_BC_DIM_MAX: - mib[0] = CTL_USER; - mib[1] = USER_BC_DIM_MAX; - break; - case _SC_BC_SCALE_MAX: - mib[0] = CTL_USER; - mib[1] = USER_BC_SCALE_MAX; - break; - case _SC_BC_STRING_MAX: - mib[0] = CTL_USER; - mib[1] = USER_BC_STRING_MAX; - break; - case _SC_COLL_WEIGHTS_MAX: - mib[0] = CTL_USER; - mib[1] = USER_COLL_WEIGHTS_MAX; - break; - case _SC_EXPR_NEST_MAX: - mib[0] = CTL_USER; - mib[1] = USER_EXPR_NEST_MAX; - break; - case _SC_LINE_MAX: - mib[0] = CTL_USER; - mib[1] = USER_LINE_MAX; - break; - case _SC_RE_DUP_MAX: - mib[0] = CTL_USER; - mib[1] = USER_RE_DUP_MAX; - break; - case _SC_2_VERSION: - mib[0] = CTL_USER; - mib[1] = USER_POSIX2_VERSION; - break; - case _SC_2_C_BIND: - mib[0] = CTL_USER; - mib[1] = USER_POSIX2_C_BIND; - goto yesno; - case _SC_2_C_DEV: - mib[0] = CTL_USER; - mib[1] = USER_POSIX2_C_DEV; - goto yesno; - case _SC_2_CHAR_TERM: - mib[0] = CTL_USER; - mib[1] = USER_POSIX2_CHAR_TERM; - goto yesno; - case _SC_2_FORT_DEV: - mib[0] = CTL_USER; - mib[1] = USER_POSIX2_FORT_DEV; - goto yesno; - case _SC_2_FORT_RUN: - mib[0] = CTL_USER; - mib[1] = USER_POSIX2_FORT_RUN; - goto yesno; - case _SC_2_LOCALEDEF: - mib[0] = CTL_USER; - mib[1] = USER_POSIX2_LOCALEDEF; - goto yesno; - case _SC_2_SW_DEV: - mib[0] = CTL_USER; - mib[1] = USER_POSIX2_SW_DEV; - goto yesno; - case _SC_2_UPE: - mib[0] = CTL_USER; - mib[1] = USER_POSIX2_UPE; -yesno: if (sysctl(mib, 2, &value, &len, NULL, 0) == -1) - return (-1); - if (value == 0) - return (-1); - return (value); - break; - default: - errno = EINVAL; - return (-1); - } - return (sysctl(mib, 2, &value, &len, NULL, 0) == -1 ? -1 : value); -} diff --git a/gen.subproj/sysctl.c b/gen.subproj/sysctl.c deleted file mode 100644 index 0ba7784..0000000 --- a/gen.subproj/sysctl.c +++ /dev/null @@ -1,195 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * 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 -#include - -#include -#include -#include -#include -#include - -int -sysctl(name, namelen, oldp, oldlenp, newp, newlen) - int *name; - u_int namelen; - void *oldp, *newp; - size_t *oldlenp, newlen; -{ - if (name[0] != CTL_USER) - return (__sysctl(name, namelen, oldp, oldlenp, newp, newlen)); - - if (newp != NULL) { - errno = EPERM; - return (-1); - } - if (namelen != 2) { - errno = EINVAL; - return (-1); - } - - switch (name[1]) { - case USER_CS_PATH: - if (oldp && *oldlenp < sizeof(_PATH_STDPATH)) - return (ENOMEM); - *oldlenp = sizeof(_PATH_STDPATH); - if (oldp != NULL) - memmove(oldp, _PATH_STDPATH, sizeof(_PATH_STDPATH)); - return (0); - } - - if (oldp && *oldlenp < sizeof(int)) - return (ENOMEM); - *oldlenp = sizeof(int); - if (oldp == NULL) - return (0); - - switch (name[1]) { - case USER_BC_BASE_MAX: - *(int *)oldp = BC_BASE_MAX; - return (0); - case USER_BC_DIM_MAX: - *(int *)oldp = BC_DIM_MAX; - return (0); - case USER_BC_SCALE_MAX: - *(int *)oldp = BC_SCALE_MAX; - return (0); - case USER_BC_STRING_MAX: - *(int *)oldp = BC_STRING_MAX; - return (0); - case USER_COLL_WEIGHTS_MAX: - *(int *)oldp = COLL_WEIGHTS_MAX; - return (0); - case USER_EXPR_NEST_MAX: - *(int *)oldp = EXPR_NEST_MAX; - return (0); - case USER_LINE_MAX: - *(int *)oldp = LINE_MAX; - return (0); - case USER_RE_DUP_MAX: - *(int *)oldp = RE_DUP_MAX; - return (0); - case USER_POSIX2_VERSION: - *(int *)oldp = _POSIX2_VERSION; - return (0); - case USER_POSIX2_C_BIND: -#ifdef POSIX2_C_BIND - *(int *)oldp = 1; -#else - *(int *)oldp = 0; -#endif - return (0); - case USER_POSIX2_C_DEV: -#ifdef POSIX2_C_DEV - *(int *)oldp = 1; -#else - *(int *)oldp = 0; -#endif - return (0); - case USER_POSIX2_CHAR_TERM: -#ifdef POSIX2_CHAR_TERM - *(int *)oldp = 1; -#else - *(int *)oldp = 0; -#endif - return (0); - case USER_POSIX2_FORT_DEV: -#ifdef POSIX2_FORT_DEV - *(int *)oldp = 1; -#else - *(int *)oldp = 0; -#endif - return (0); - case USER_POSIX2_FORT_RUN: -#ifdef POSIX2_FORT_RUN - *(int *)oldp = 1; -#else - *(int *)oldp = 0; -#endif - return (0); - case USER_POSIX2_LOCALEDEF: -#ifdef POSIX2_LOCALEDEF - *(int *)oldp = 1; -#else - *(int *)oldp = 0; -#endif - return (0); - case USER_POSIX2_SW_DEV: -#ifdef POSIX2_SW_DEV - *(int *)oldp = 1; -#else - *(int *)oldp = 0; -#endif - return (0); - case USER_POSIX2_UPE: -#ifdef POSIX2_UPE - *(int *)oldp = 1; -#else - *(int *)oldp = 0; -#endif - return (0); - case USER_STREAM_MAX: - *(int *)oldp = FOPEN_MAX; - return (0); - case USER_TZNAME_MAX: - *(int *)oldp = NAME_MAX; - return (0); - default: - errno = EINVAL; - return (-1); - } - /* NOTREACHED */ -} diff --git a/gen.subproj/sysctlbyname.c b/gen.subproj/sysctlbyname.c deleted file mode 100644 index 27e3ca9..0000000 --- a/gen.subproj/sysctlbyname.c +++ /dev/null @@ -1,37 +0,0 @@ -/* - * ---------------------------------------------------------------------------- - * "THE BEER-WARE LICENSE" (Revision 42): - * wrote this file. As long as you retain this notice you - * can do whatever you want with this stuff. If we meet some day, and you think - * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp - * ---------------------------------------------------------------------------- - * - * $FreeBSD: src/lib/libc/gen/sysctlbyname.c,v 1.4 1999/08/27 23:59:01 peter Exp $ - * - */ -#include -#include -#include - -int -sysctlbyname(const char *name, void *oldp, size_t *oldlenp, void *newp, - size_t newlen) -{ - int name2oid_oid[2]; - int real_oid[CTL_MAXNAME+2]; - int error; - size_t oidlen; - - name2oid_oid[0] = 0; /* This is magic & undocumented! */ - name2oid_oid[1] = 3; - - oidlen = sizeof(real_oid); - error = sysctl(name2oid_oid, 2, real_oid, &oidlen, (void *)name, - strlen(name)); - if (error < 0) - return error; - oidlen /= sizeof (int); - error = sysctl(real_oid, oidlen, oldp, oldlenp, newp, newlen); - return (error); -} - diff --git a/gen.subproj/syslog.c b/gen.subproj/syslog.c deleted file mode 100644 index cd3985f..0000000 --- a/gen.subproj/syslog.c +++ /dev/null @@ -1,307 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * 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 -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -#ifdef __STDC__ -#include -#else -#include -#endif - -#include - -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 */ - -/* - * 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)) & LogMask)) - return; - - saved_errno = errno; - - /* Set default facility if none specified. */ - if ((pri & LOG_FACMASK) == 0) - pri |= 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 (LogStat & LOG_PERROR) - stdp = p; - if (LogTag == NULL) - LogTag = *(*_NSGetArgv()); - if (LogTag != NULL) { - prlen = snprintf(p, tbuf_left, "%s", LogTag); - DEC(); - } - if (LogStat & LOG_PID) { - prlen = snprintf(p, tbuf_left, "[%d]", getpid()); - DEC(); - } - if (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 (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 (!connected) - openlog(LogTag, LogStat | LOG_NDELAY, 0); - if (send(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) { - 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); - } -} - -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) - LogTag = ident; - LogStat = logstat; - if (logfac != 0 && (logfac &~ LOG_FACMASK) == 0) - LogFacility = logfac; - - if (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); - } - } - if (LogFile != -1 && !connected) - if (connect(LogFile, &SyslogAddr, sizeof(SyslogAddr)) == -1) { - (void)close(LogFile); - LogFile = -1; - } else - connected = 1; -} - -void -closelog() -{ - (void)close(LogFile); - LogFile = -1; - connected = 0; -} - -/* setlogmask -- set the log mask level */ -int -setlogmask(pmask) - int pmask; -{ - int omask; - - omask = LogMask; - if (pmask != 0) - LogMask = pmask; - return (omask); -} diff --git a/gen.subproj/telldir.c b/gen.subproj/telldir.c deleted file mode 100644 index 19d655e..0000000 --- a/gen.subproj/telldir.c +++ /dev/null @@ -1,146 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1983, 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 -#include -#include -#include - -/* - * The option SINGLEUSE may be defined to say that a telldir - * cookie may be used only once before it is freed. This option - * is used to avoid having memory usage grow without bound. - */ -#define SINGLEUSE - -/* - * One of these structures is malloced to describe the current directory - * position each time telldir is called. It records the current magic - * cookie returned by getdirentries and the offset within the buffer - * associated with that return value. - */ -struct ddloc { - struct ddloc *loc_next;/* next structure in list */ - long loc_index; /* key associated with structure */ - long loc_seek; /* magic cookie returned by getdirentries */ - long loc_loc; /* offset of entry in buffer */ -}; - -#define NDIRHASH 32 /* Num of hash lists, must be a power of 2 */ -#define LOCHASH(i) ((i)&(NDIRHASH-1)) - -static long dd_loccnt; /* Index of entry for sequential readdir's */ -static struct ddloc *dd_hash[NDIRHASH]; /* Hash list heads for ddlocs */ - -/* - * return a pointer into a directory - */ -long -telldir(dirp) - const DIR *dirp; -{ - register int index; - register struct ddloc *lp; - - if ((lp = (struct ddloc *)malloc(sizeof(struct ddloc))) == NULL) - return (-1); - index = dd_loccnt++; - lp->loc_index = index; - lp->loc_seek = dirp->dd_seek; - lp->loc_loc = dirp->dd_loc; - lp->loc_next = dd_hash[LOCHASH(index)]; - dd_hash[LOCHASH(index)] = lp; - return (index); -} - -/* - * seek to an entry in a directory. - * Only values returned by "telldir" should be passed to seekdir. - */ -void -_seekdir(dirp, loc) - register DIR *dirp; - long loc; -{ - register struct ddloc *lp; - register struct ddloc **prevlp; - struct dirent *dp; - - prevlp = &dd_hash[LOCHASH(loc)]; - lp = *prevlp; - while (lp != NULL) { - if (lp->loc_index == loc) - break; - prevlp = &lp->loc_next; - lp = lp->loc_next; - } - if (lp == NULL) - return; - if (lp->loc_loc == dirp->dd_loc && lp->loc_seek == dirp->dd_seek) - goto found; - (void) lseek(dirp->dd_fd, (off_t)lp->loc_seek, SEEK_SET); - dirp->dd_seek = lp->loc_seek; - dirp->dd_loc = 0; - while (dirp->dd_loc < lp->loc_loc) { - dp = readdir(dirp); - if (dp == NULL) - break; - } -found: -#ifdef SINGLEUSE - *prevlp = lp->loc_next; - free((caddr_t)lp); -#endif -} diff --git a/gen.subproj/termios.c b/gen.subproj/termios.c deleted file mode 100644 index d4af066..0000000 --- a/gen.subproj/termios.c +++ /dev/null @@ -1,260 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1989, 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 -#include -#include -#include -#define KERNEL /* XXX - FREAD and FWRITE ifdef'd KERNEL*/ -#include -#undef KERNEL - -#include -#include -#include -#include - -int -tcgetattr(fd, t) - int fd; - struct termios *t; -{ - - return (ioctl(fd, TIOCGETA, t)); -} - -int -tcsetattr(fd, opt, t) - int fd, opt; - const struct termios *t; -{ - struct termios localterm; - - if (opt & TCSASOFT) { - localterm = *t; - localterm.c_cflag |= CIGNORE; - t = &localterm; - } - switch (opt & ~TCSASOFT) { - case TCSANOW: - return (ioctl(fd, TIOCSETA, t)); - case TCSADRAIN: - return (ioctl(fd, TIOCSETAW, t)); - case TCSAFLUSH: - return (ioctl(fd, TIOCSETAF, t)); - default: - errno = EINVAL; - return (-1); - } -} - -int -#if __STDC__ -tcsetpgrp(int fd, pid_t pgrp) -#else -tcsetpgrp(fd, pgrp) - int fd; - pid_t pgrp; -#endif -{ - int s; - - s = pgrp; - return (ioctl(fd, TIOCSPGRP, &s)); -} - -pid_t -tcgetpgrp(fd) -{ - int s; - - if (ioctl(fd, TIOCGPGRP, &s) < 0) - return ((pid_t)-1); - - return ((pid_t)s); -} - -speed_t -cfgetospeed(t) - const struct termios *t; -{ - - return (t->c_ospeed); -} - -speed_t -cfgetispeed(t) - const struct termios *t; -{ - - return (t->c_ispeed); -} - -int -cfsetospeed(t, speed) - struct termios *t; - speed_t speed; -{ - - t->c_ospeed = speed; - return (0); -} - -int -cfsetispeed(t, speed) - struct termios *t; - speed_t speed; -{ - - t->c_ispeed = speed; - return (0); -} - -int -cfsetspeed(t, speed) - struct termios *t; - speed_t speed; -{ - - t->c_ispeed = t->c_ospeed = speed; - return (0); -} - -/* - * Make a pre-existing termios structure into "raw" mode: character-at-a-time - * mode with no characters interpreted, 8-bit data path. - */ -void -cfmakeraw(t) - struct termios *t; -{ - - t->c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP|INLCR|IGNCR|ICRNL|IXON); - t->c_oflag &= ~OPOST; - t->c_lflag &= ~(ECHO|ECHONL|ICANON|ISIG|IEXTEN); - t->c_cflag &= ~(CSIZE|PARENB); - t->c_cflag |= CS8; - /* XXX set MIN/TIME */ -} - -tcsendbreak(fd, len) - int fd, len; -{ - struct timeval sleepytime; - - sleepytime.tv_sec = 0; - sleepytime.tv_usec = 400000; - if (ioctl(fd, TIOCSBRK, 0) == -1) - return (-1); - (void)select(0, 0, 0, 0, &sleepytime); - if (ioctl(fd, TIOCCBRK, 0) == -1) - return (-1); - return (0); -} - -tcdrain(fd) - int fd; -{ - - return (ioctl(fd, TIOCDRAIN, 0)); -} - -tcflush(fd, which) - int fd, which; -{ - int com; - - switch (which) { - case TCIFLUSH: - com = FREAD; - break; - case TCOFLUSH: - com = FWRITE; - break; - case TCIOFLUSH: - com = FREAD | FWRITE; - break; - default: - errno = EINVAL; - return (-1); - } - return (ioctl(fd, TIOCFLUSH, &com)); -} - -tcflow(fd, action) - int fd, action; -{ - struct termios term; - u_char c; - - switch (action) { - case TCOOFF: - return (ioctl(fd, TIOCSTOP, 0)); - case TCOON: - return (ioctl(fd, TIOCSTART, 0)); - case TCION: - case TCIOFF: - if (tcgetattr(fd, &term) == -1) - return (-1); - c = term.c_cc[action == TCIOFF ? VSTOP : VSTART]; - if (c != _POSIX_VDISABLE && write(fd, &c, sizeof(c)) == -1) - return (-1); - return (0); - default: - errno = EINVAL; - return (-1); - } - /* NOTREACHED */ -} diff --git a/gen.subproj/time.c b/gen.subproj/time.c deleted file mode 100644 index dcfd0b2..0000000 --- a/gen.subproj/time.c +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1983, 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 -#include - -time_t -time(t) - time_t *t; -{ - struct timeval tt; - - if (gettimeofday(&tt, (struct timezone *)0) < 0) - return(-1); - if (t) - *t = tt.tv_sec; - return(tt.tv_sec); -} diff --git a/gen.subproj/times.c b/gen.subproj/times.c deleted file mode 100644 index 4b7c4e8..0000000 --- a/gen.subproj/times.c +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 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 -#include -#include -#include - -/* - * Convert usec to clock ticks; could do (usec * CLK_TCK) / 1000000, - * but this would overflow if we switch to nanosec. - */ -#define CONVTCK(r) (r.tv_sec * CLK_TCK + r.tv_usec / (1000000 / CLK_TCK)) - -clock_t -times(tp) - register struct tms *tp; -{ - struct rusage ru; - struct timeval t; - - if (getrusage(RUSAGE_SELF, &ru) < 0) - return ((clock_t)-1); - tp->tms_utime = CONVTCK(ru.ru_utime); - tp->tms_stime = CONVTCK(ru.ru_stime); - if (getrusage(RUSAGE_CHILDREN, &ru) < 0) - return ((clock_t)-1); - tp->tms_cutime = CONVTCK(ru.ru_utime); - tp->tms_cstime = CONVTCK(ru.ru_stime); - if (gettimeofday(&t, (struct timezone *)0)) - return ((clock_t)-1); - return ((clock_t)(CONVTCK(t))); -} diff --git a/gen.subproj/timezone.c b/gen.subproj/timezone.c deleted file mode 100644 index c175032..0000000 --- a/gen.subproj/timezone.c +++ /dev/null @@ -1,152 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1987, 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 -#include -#include -#include -#include -#include - -char *_tztab(); - -/* - * timezone -- - * The arguments are the number of minutes of time you are westward - * from Greenwich and whether DST is in effect. It returns a string - * giving the name of the local timezone. Should be replaced, in the - * application code, by a call to localtime. - */ - -static char czone[TZ_MAX_CHARS]; /* space for zone name */ - -char * -timezone(zone, dst) - int zone, - dst; -{ - register char *beg, - *end; - - if (beg = getenv("TZNAME")) { /* set in environment */ - if (end = index(beg, ',')) { /* "PST,PDT" */ - if (dst) - return(++end); - *end = '\0'; - (void)strncpy(czone,beg,sizeof(czone) - 1); - czone[sizeof(czone) - 1] = '\0'; - *end = ','; - return(czone); - } - return(beg); - } - return(_tztab(zone,dst)); /* default: table or created zone */ -} - -static struct zone { - int offset; - char *stdzone; - char *dlzone; -} zonetab[] = { - -1*60, "MET", "MET DST", /* Middle European */ - -2*60, "EET", "EET DST", /* Eastern European */ - 4*60, "AST", "ADT", /* Atlantic */ - 5*60, "EST", "EDT", /* Eastern */ - 6*60, "CST", "CDT", /* Central */ - 7*60, "MST", "MDT", /* Mountain */ - 8*60, "PST", "PDT", /* Pacific */ -#ifdef notdef - /* there's no way to distinguish this from WET */ - 0, "GMT", 0, /* Greenwich */ -#endif - 0*60, "WET", "WET DST", /* Western European */ - -10*60, "EST", "EST", /* Aust: Eastern */ - -10*60+30, "CST", "CST", /* Aust: Central */ - -8*60, "WST", 0, /* Aust: Western */ - -1 -}; - -/* - * _tztab -- - * check static tables or create a new zone name; broken out so that - * we can make a guess as to what the zone is if the standard tables - * aren't in place in /etc. DO NOT USE THIS ROUTINE OUTSIDE OF THE - * STANDARD LIBRARY. - */ -char * -_tztab(zone,dst) - register int zone; - int dst; -{ - register struct zone *zp; - register char sign; - - for (zp = zonetab; zp->offset != -1;++zp) /* static tables */ - if (zp->offset == zone) { - if (dst && zp->dlzone) - return(zp->dlzone); - if (!dst && zp->stdzone) - return(zp->stdzone); - } - - if (zone < 0) { /* create one */ - zone = -zone; - sign = '+'; - } - else - sign = '-'; - (void)sprintf(czone,"GMT%c%d:%02d",sign,zone / 60,zone % 60); - return(czone); -} diff --git a/gen.subproj/ttyname.c b/gen.subproj/ttyname.c deleted file mode 100644 index a07b134..0000000 --- a/gen.subproj/ttyname.c +++ /dev/null @@ -1,133 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1988, 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 -#include -#include -#include - -#include -#include -#include -#include -#include - -static char buf[sizeof(_PATH_DEV) + MAXNAMLEN] = _PATH_DEV; -static char *oldttyname __P((int, struct stat *)); - -char * -ttyname(fd) - int fd; -{ - struct stat sb; - struct termios term; - DB *db; - DBT data, key; - struct { - mode_t type; - dev_t dev; - } bkey; - - /* Must be a terminal. */ - if (ioctl(fd, TIOCGETA, &term) < 0) - return (NULL); - /* Must be a character device. */ - if (fstat(fd, &sb) || !S_ISCHR(sb.st_mode)) - return (NULL); - - db = dbopen(_PATH_DEVDB, O_RDONLY, 0, DB_HASH, NULL); - if (db) { - 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(fd, sb) - int fd; - struct stat *sb; -{ - register struct dirent *dirp; - register DIR *dp; - struct stat dsb; - - 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); -} diff --git a/gen.subproj/ttyslot.c b/gen.subproj/ttyslot.c deleted file mode 100644 index bb3cfb5..0000000 --- a/gen.subproj/ttyslot.c +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1988, 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 -#include -#include -#include - -int -ttyslot() -{ - register struct ttyent *ttyp; - register int slot; - register char *p; - int cnt; - char *name; - - setttyent(); - for (cnt = 0; cnt < 3; ++cnt) - if (name = ttyname(cnt)) { - if (p = rindex(name, '/')) - ++p; - else - p = name; - for (slot = 1; ttyp = getttyent(); ++slot) - if (!strcmp(ttyp->ty_name, p)) { - endttyent(); - return(slot); - } - break; - } - endttyent(); - return(0); -} diff --git a/gen.subproj/ualarm.c b/gen.subproj/ualarm.c deleted file mode 100644 index d057766..0000000 --- a/gen.subproj/ualarm.c +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1985, 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 -#include - -#define USPS 1000000 /* # of microseconds in a second */ - -/* - * Generate a SIGALRM signal in ``usecs'' microseconds. - * If ``reload'' is non-zero, keep generating SIGALRM - * every ``reload'' microseconds after the first signal. - */ -unsigned -ualarm(usecs, reload) - register unsigned usecs; - register unsigned reload; -{ - struct itimerval new, old; - - new.it_interval.tv_usec = reload % USPS; - new.it_interval.tv_sec = reload / USPS; - - new.it_value.tv_usec = usecs % USPS; - new.it_value.tv_sec = usecs / USPS; - - if (setitimer(ITIMER_REAL, &new, &old) == 0) - return (old.it_value.tv_sec * USPS + old.it_value.tv_usec); - /* else */ - return (-1); -} diff --git a/gen.subproj/uname.c b/gen.subproj/uname.c deleted file mode 100644 index f3d8ed7..0000000 --- a/gen.subproj/uname.c +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1994 - * 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 -#include -#include - -int -uname(name) - struct utsname *name; -{ - int mib[2], rval; - size_t len; - char *p; - - rval = 0; - - mib[0] = CTL_KERN; - mib[1] = KERN_OSTYPE; - len = sizeof(name->sysname); - if (sysctl(mib, 2, &name->sysname, &len, NULL, 0) == -1) - rval = -1; - - mib[0] = CTL_KERN; - mib[1] = KERN_HOSTNAME; - len = sizeof(name->nodename); - if (sysctl(mib, 2, &name->nodename, &len, NULL, 0) == -1) - rval = -1; - - mib[0] = CTL_KERN; - mib[1] = KERN_OSRELEASE; - len = sizeof(name->release); - if (sysctl(mib, 2, &name->release, &len, NULL, 0) == -1) - rval = -1; - - /* The version may have newlines in it, turn them into spaces. */ - mib[0] = CTL_KERN; - mib[1] = KERN_VERSION; - len = sizeof(name->version); - if (sysctl(mib, 2, &name->version, &len, NULL, 0) == -1) - rval = -1; - else - for (p = name->version; len--; ++p) - if (*p == '\n' || *p == '\t') - if (len > 1) - *p = ' '; - else - *p = '\0'; - - mib[0] = CTL_HW; - mib[1] = HW_MACHINE; - len = sizeof(name->machine); - if (sysctl(mib, 2, &name->machine, &len, NULL, 0) == -1) - rval = -1; - return (rval); -} diff --git a/gen.subproj/unvis.c b/gen.subproj/unvis.c deleted file mode 100644 index 0272875..0000000 --- a/gen.subproj/unvis.c +++ /dev/null @@ -1,266 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1989, 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 -#include -#include - -/* - * decode driven by state machine - */ -#define S_GROUND 0 /* haven't seen escape char */ -#define S_START 1 /* start decoding special sequence */ -#define S_META 2 /* metachar started (M) */ -#define S_META1 3 /* metachar more, regular char (-) */ -#define S_CTRL 4 /* control char started (^) */ -#define S_OCTAL2 5 /* octal digit 2 */ -#define S_OCTAL3 6 /* octal digit 3 */ - -#define isoctal(c) (((u_char)(c)) >= '0' && ((u_char)(c)) <= '7') - -/* - * unvis - decode characters previously encoded by vis - */ -int -unvis(cp, c, astate, flag) - char *cp; - int c, *astate, flag; -{ - - if (flag & UNVIS_END) { - if (*astate == S_OCTAL2 || *astate == S_OCTAL3) { - *astate = S_GROUND; - return (UNVIS_VALID); - } - return (*astate == S_GROUND ? UNVIS_NOCHAR : UNVIS_SYNBAD); - } - - switch (*astate) { - - case S_GROUND: - *cp = 0; - if (c == '\\') { - *astate = S_START; - return (0); - } - *cp = c; - return (UNVIS_VALID); - - case S_START: - switch(c) { - case '\\': - *cp = c; - *astate = S_GROUND; - return (UNVIS_VALID); - case '0': case '1': case '2': case '3': - case '4': case '5': case '6': case '7': - *cp = (c - '0'); - *astate = S_OCTAL2; - return (0); - case 'M': - *cp = 0200; - *astate = S_META; - return (0); - case '^': - *astate = S_CTRL; - return (0); - case 'n': - *cp = '\n'; - *astate = S_GROUND; - return (UNVIS_VALID); - case 'r': - *cp = '\r'; - *astate = S_GROUND; - return (UNVIS_VALID); - case 'b': - *cp = '\b'; - *astate = S_GROUND; - return (UNVIS_VALID); - case 'a': - *cp = '\007'; - *astate = S_GROUND; - return (UNVIS_VALID); - case 'v': - *cp = '\v'; - *astate = S_GROUND; - return (UNVIS_VALID); - case 't': - *cp = '\t'; - *astate = S_GROUND; - return (UNVIS_VALID); - case 'f': - *cp = '\f'; - *astate = S_GROUND; - return (UNVIS_VALID); - case 's': - *cp = ' '; - *astate = S_GROUND; - return (UNVIS_VALID); - case 'E': - *cp = '\033'; - *astate = S_GROUND; - return (UNVIS_VALID); - case '\n': - /* - * hidden newline - */ - *astate = S_GROUND; - return (UNVIS_NOCHAR); - case '$': - /* - * hidden marker - */ - *astate = S_GROUND; - return (UNVIS_NOCHAR); - } - *astate = S_GROUND; - return (UNVIS_SYNBAD); - - case S_META: - if (c == '-') - *astate = S_META1; - else if (c == '^') - *astate = S_CTRL; - else { - *astate = S_GROUND; - return (UNVIS_SYNBAD); - } - return (0); - - case S_META1: - *astate = S_GROUND; - *cp |= c; - return (UNVIS_VALID); - - case S_CTRL: - if (c == '?') - *cp |= 0177; - else - *cp |= c & 037; - *astate = S_GROUND; - return (UNVIS_VALID); - - case S_OCTAL2: /* second possible octal digit */ - if (isoctal(c)) { - /* - * yes - and maybe a third - */ - *cp = (*cp << 3) + (c - '0'); - *astate = S_OCTAL3; - return (0); - } - /* - * no - done with current sequence, push back passed char - */ - *astate = S_GROUND; - return (UNVIS_VALIDPUSH); - - case S_OCTAL3: /* third possible octal digit */ - *astate = S_GROUND; - if (isoctal(c)) { - *cp = (*cp << 3) + (c - '0'); - return (UNVIS_VALID); - } - /* - * we were done, push back passed char - */ - return (UNVIS_VALIDPUSH); - - default: - /* - * decoder in unknown state - (probably uninitialized) - */ - *astate = S_GROUND; - return (UNVIS_SYNBAD); - } -} - -/* - * strunvis - decode src into dst - * - * Number of chars decoded into dst is returned, -1 on error. - * Dst is null terminated. - */ - -int -strunvis(dst, src) - register char *dst; - register const char *src; -{ - register char c; - char *start = dst; - int state = 0; - - while (c = *src++) { - again: - switch (unvis(dst, c, &state, 0)) { - case UNVIS_VALID: - dst++; - break; - case UNVIS_VALIDPUSH: - dst++; - goto again; - case 0: - case UNVIS_NOCHAR: - break; - default: - return (-1); - } - } - if (unvis(dst, c, &state, UNVIS_END) == UNVIS_VALID) - dst++; - *dst = '\0'; - return (dst - start); -} diff --git a/gen.subproj/usleep.c b/gen.subproj/usleep.c deleted file mode 100644 index 96e7432..0000000 --- a/gen.subproj/usleep.c +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1989, 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 -#include -#include - -void -usleep(useconds) - unsigned int useconds; -{ - (void)syscall_thread_switch(THREAD_NULL, SWITCH_OPTION_WAIT, useconds / 1000); -} diff --git a/gen.subproj/utime.c b/gen.subproj/utime.c deleted file mode 100644 index cdddca7..0000000 --- a/gen.subproj/utime.c +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 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 - -#include - -int -utime(path, times) - const char *path; - const struct utimbuf *times; -{ - struct timeval tv[2], *tvp; - - if (times) { - tv[0].tv_sec = times->actime; - tv[1].tv_sec = times->modtime; - tv[0].tv_usec = tv[1].tv_usec = 0; - tvp = tv; - } else - tvp = NULL; - return (utimes(path, tvp)); -} diff --git a/gen.subproj/vis.c b/gen.subproj/vis.c deleted file mode 100644 index 4b6924e..0000000 --- a/gen.subproj/vis.c +++ /dev/null @@ -1,204 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1989, 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 -#include -#include -#include - -#define isoctal(c) (((u_char)(c)) >= '0' && ((u_char)(c)) <= '7') - -/* - * vis - visually encode characters - */ -char * -vis(dst, c, flag, nextc) - register char *dst; - int c, nextc; - register int flag; -{ - if ((u_int)c <= UCHAR_MAX && isgraph(c) || - ((flag & VIS_SP) == 0 && c == ' ') || - ((flag & VIS_TAB) == 0 && c == '\t') || - ((flag & VIS_NL) == 0 && c == '\n') || - ((flag & VIS_SAFE) && (c == '\b' || c == '\007' || c == '\r'))) { - *dst++ = c; - if (c == '\\' && (flag & VIS_NOSLASH) == 0) - *dst++ = '\\'; - *dst = '\0'; - return (dst); - } - - if (flag & VIS_CSTYLE) { - switch(c) { - case '\n': - *dst++ = '\\'; - *dst++ = 'n'; - goto done; - case '\r': - *dst++ = '\\'; - *dst++ = 'r'; - goto done; - case '\b': - *dst++ = '\\'; - *dst++ = 'b'; - goto done; -#if __STDC__ - case '\a': -#else - case '\007': -#endif - *dst++ = '\\'; - *dst++ = 'a'; - goto done; - case '\v': - *dst++ = '\\'; - *dst++ = 'v'; - goto done; - case '\t': - *dst++ = '\\'; - *dst++ = 't'; - goto done; - case '\f': - *dst++ = '\\'; - *dst++ = 'f'; - goto done; - case ' ': - *dst++ = '\\'; - *dst++ = 's'; - goto done; - case '\0': - *dst++ = '\\'; - *dst++ = '0'; - if (isoctal(nextc)) { - *dst++ = '0'; - *dst++ = '0'; - } - goto done; - } - } - if (((c & 0177) == ' ') || (flag & VIS_OCTAL)) { - *dst++ = '\\'; - *dst++ = ((u_char)c >> 6 & 07) + '0'; - *dst++ = ((u_char)c >> 3 & 07) + '0'; - *dst++ = ((u_char)c & 07) + '0'; - goto done; - } - if ((flag & VIS_NOSLASH) == 0) - *dst++ = '\\'; - if (c & 0200) { - c &= 0177; - *dst++ = 'M'; - } - if (iscntrl(c)) { - *dst++ = '^'; - if (c == 0177) - *dst++ = '?'; - else - *dst++ = c + '@'; - } else { - *dst++ = '-'; - *dst++ = c; - } -done: - *dst = '\0'; - return (dst); -} - -/* - * strvis, strvisx - visually encode characters from src into dst - * - * Dst must be 4 times the size of src to account for possible - * expansion. The length of dst, not including the trailing NULL, - * is returned. - * - * Strvisx encodes exactly len bytes from src into dst. - * This is useful for encoding a block of data. - */ -int -strvis(dst, src, flag) - register char *dst; - register const char *src; - int flag; -{ - register char c; - char *start; - - for (start = dst; c = *src;) - dst = vis(dst, c, flag, *++src); - *dst = '\0'; - return (dst - start); -} - -int -strvisx(dst, src, len, flag) - register char *dst; - register const char *src; - register size_t len; - int flag; -{ - int c; - char *start; - - for (start = dst; len > 1; len--) { - c = *src; - dst = vis(dst, c, flag, *++src); - } - if (len) - dst = vis(dst, *src, flag, '\0'); - *dst = '\0'; - - return (dst - start); -} diff --git a/gen.subproj/wait.c b/gen.subproj/wait.c deleted file mode 100644 index 216853a..0000000 --- a/gen.subproj/wait.c +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1988, 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 -#include -#include -#include - -pid_t wait(istat) - int *istat; -{ - return (wait4(WAIT_ANY, istat, 0, (struct rusage *)0)); -} - diff --git a/gen.subproj/wait3.c b/gen.subproj/wait3.c deleted file mode 100644 index e516385..0000000 --- a/gen.subproj/wait3.c +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1988, 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 -#include -#include -#include - -pid_t -wait3(istat, options, rup) - int *istat; - int options; - struct rusage *rup; -{ - return (wait4(WAIT_ANY, istat, options, rup)); -} diff --git a/gen.subproj/waitpid.c b/gen.subproj/waitpid.c deleted file mode 100644 index f60a2f1..0000000 --- a/gen.subproj/waitpid.c +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1988, 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 -#include -#include -#include - -pid_t -#if __STDC__ -waitpid(pid_t pid, int *istat, int options) -#else -waitpid(pid, istat, options) - pid_t pid; - int *istat; - int options; -#endif -{ - return (wait4(pid, istat, options, (struct rusage *)0)); -} diff --git a/gen.subproj/zone.c b/gen.subproj/zone.c deleted file mode 100644 index 0f4610f..0000000 --- a/gen.subproj/zone.c +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ - -#import -#import -#import - -/********* NX functions ************/ - -malloc_zone_t *NXDefaultMallocZone() { - return malloc_default_zone(); -} - -malloc_zone_t *NXCreateZone(size_t startsize, size_t granularity, int canfree) { - return malloc_create_zone(startsize, 0); -} - -void NXNameZone(malloc_zone_t *z, const char *name) { - malloc_set_zone_name(z, name); -} - -void *NXZoneMalloc(malloc_zone_t *zone, size_t size) { - return malloc_zone_malloc(zone, size); -} - -void *NXZoneRealloc(malloc_zone_t *zone, void *ptr, size_t size) { - return malloc_zone_realloc(zone, ptr, size); -} - -void *NXZoneCalloc(malloc_zone_t *zone, size_t num_items, size_t size) { - return malloc_zone_calloc(zone, num_items, size); -} - -void NXZoneFree(malloc_zone_t *zone, void *ptr) { - malloc_zone_free(zone, ptr); -} - -void NXDestroyZone(malloc_zone_t *zone) { - if (zone == malloc_default_zone()) return; // we avoid destroying child zones - malloc_destroy_zone(zone); -} - -NXZone *NXZoneFromPtr(void *ptr) { - NXZone *zone = malloc_zone_from_ptr(ptr); - if (!zone) { - fprintf(stderr, "*** malloc[%d]: NXZoneFromPtr() did not find any zone for %p; returning default\n", getpid(), ptr); - zone = NX_NOZONE; - } - return zone; -} - -void NXAddRegion(void *start, size_t size, malloc_zone_t *zone) { - fprintf(stderr, "*** malloc[%d]: OBSOLETE: NXAddRegion()\n", getpid()); -} - -void NXRemoveRegion(void *start) { - fprintf(stderr, "*** malloc[%d]: OBSOLETE: NXRemoveRegion()\n", getpid()); -} - -void NXZonePtrInfo(void *ptr) { - malloc_zone_print_ptr_info(ptr); -} - -int NXMallocCheck(void) { - malloc_zone_check(NULL); - return 1; -} - -void _NXMallocDumpZones(void) { - malloc_zone_print(NULL, 0); -} - -/***************** UNIMPLEMENTED ENTRY POINTS ********************/ - -void NXMergeZone(malloc_zone_t *z) { - static char warned = 0; - if (!warned) { - fprintf(stderr, "*** malloc[%d]: NXMergeZone() now obsolete, does nothing\n", getpid()); - warned = 1; - } -} - -boolean_t NXProtectZone(malloc_zone_t *zone, int protection) { - fprintf(stderr, "*** malloc[%d]: NXProtectZone() is obsolete\n", getpid()); - return 0; -} - -malloc_zone_t *NXCreateChildZone(malloc_zone_t *parentzone, size_t startsize, size_t granularity, int canfree) { - // We can not remove this one as it is still used by IndexingKit - static char warned = 0; - if (!warned) { - fprintf(stderr, "*** malloc[%d]: NXCreateChildZone() now obsolete, has been defined to create new zone\n", getpid()); - warned = 1; - } - return NXCreateZone(startsize, granularity, canfree); -} - -void _NXMallocDumpFrees(void) { - fprintf(stderr, "*** malloc[%d]: OBSOLETE: _NXMallocDumpFrees()\n", getpid()); -} - diff --git a/gen.subproj/zone.h b/gen.subproj/zone.h deleted file mode 100644 index 94dd796..0000000 --- a/gen.subproj/zone.h +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ - -#import - -typedef malloc_zone_t NXZone; - -#define NX_NOZONE ((NXZone *)0) - -/********* Interface to zone based malloc ************/ - -extern NXZone *NXDefaultMallocZone(void); - // Returns the default zone used by the malloc(3) calls - -extern NXZone *NXCreateZone(size_t startSize, size_t granularity, int canFree); - // Create a new zone with its own memory pool. - // canfree: if 0 the allocator will never free memory and mallocing will be fast - -extern void NXNameZone(NXZone *z, const char *name); - // name a zone; The string will be copied - -extern void *NXZoneMalloc(malloc_zone_t *zone, size_t size); - -extern void *NXZoneRealloc(malloc_zone_t *zone, void *ptr, size_t size); - -extern void *NXZoneCalloc(NXZone *zonep, size_t numElems, size_t byteSize); - // Allocates and then clears - -extern void NXZoneFree(malloc_zone_t *zone, void *ptr); - -extern void NXDestroyZone(malloc_zone_t *zone); - -extern NXZone *NXZoneFromPtr(void *ptr); - // Returns the zone for a pointer, or NX_NOZONE if not in any zone. - // The ptr must have been returned from a malloc or realloc call. - diff --git a/gen/Makefile.inc b/gen/Makefile.inc new file mode 100644 index 0000000..ed08ce0 --- /dev/null +++ b/gen/Makefile.inc @@ -0,0 +1,139 @@ +# @(#)Makefile.inc 8.6 (Berkeley) 5/4/95 +# $FreeBSD: src/lib/libc/gen/Makefile.inc,v 1.80 2001/08/17 22:09:15 dd Exp $ + +# machine-independent gen sources +.PATH: ${.CURDIR}/${MACHINE_ARCH}/gen ${.CURDIR}/gen + +CFLAGS+= -I${.CURDIR}/pthreads + +SRCS += NSSystemDirectories.c getpagesize.c siginterrupt.c \ + alarm.c getpass.c siglist.c \ + assert.c getttyent.c signal.c \ + getusershell.c sigsetops.c \ + clock.c getvfsbyname.c sleep.c \ + closedir.c stack_logging.c \ + confstr.c strchr.c \ + crypt.c sysconf.c \ + ctermid.c isatty.c sysctl.c \ + isnan.c sysctlbyname.c \ + daemon.c malloc.c syslog.c \ + devname.c nanosleep.c telldir.c \ + difftime.c nice.c termios.c \ + disklabel.c nlist.c time.c \ + err.c opendir.c times.c \ + errlst.c pause.c timezone.c \ + exec.c popen.c ttyname.c \ + fnmatch.c psignal.c ttyslot.c \ + ualarm.c \ + ftok.c raise.c uname.c \ + fts.c unvis.c \ + getbsize.c readdir.c usleep.c \ + getcap.c rewinddir.c utime.c \ + getcwd.c scalable_malloc.c vis.c \ + scandir.c wait.c \ + gethostname.c seekdir.c wait3.c \ + getloadavg.c sethostname.c waitpid.c \ + getlogin.c setlogin.c zone.c \ + getmntinfo.c setmode.c \ + _rand48.c erand48.c lcong48.c mrand48.c seed48.c drand48.c jrand48.c \ + nrand48.c srand48.c lrand48.c basename.c dirname.c arc4random.c \ + strtofflags.c lockf.c readdir_r.c ulimit.c + + +# machine-dependent gen sources +.if exists(${.CURDIR}/${MACHINE_ARCH}/gen/Makefile.inc) +.include "${.CURDIR}/${MACHINE_ARCH}/gen/Makefile.inc" +.endif + +.if ${LIB} == "c" +MAN3+= alarm.3 arc4random.3 clock.3 \ + basename.3 \ + confstr.3 ctermid.3 daemon.3 \ + devname.3 directory.3 dirname.3 \ + err.3 exec.3 fmtcheck.3 fnmatch.3 frexp.3 ftok.3 fts.3 \ + getbootfile.3 getbsize.3 getcap.3 getcwd.3 \ + getdomainname.3 getfsent.3 \ + getgrent.3 getgrouplist.3 gethostname.3 getloadavg.3 \ + getmntinfo.3 getnetgrent.3 getobjformat.3 \ + getpagesize.3 getpass.3 getpeereid.3 getpwent.3 \ + getttyent.3 getusershell.3 getvfsbyname.3 getvfsent.3 \ + glob.3 initgroups.3 isinf.3 \ + ldexp.3 lockf.3 modf.3 msgctl.3 msgget.3 msgrcv.3 msgsnd.3 \ + nice.3 nlist.3 pause.3 popen.3 psignal.3 pwcache.3 \ + raise.3 rand48.3 rfork_thread.3 \ + scandir.3 setjmp.3 setmode.3 \ + siginterrupt.3 signal.3 sigsetops.3 sleep.3 stringlist.3 \ + strtofflags.3 sysconf.3 sysctl.3 syslog.3 tcgetpgrp.3 \ + tcsendbreak.3 tcsetattr.3 tcsetpgrp.3 time.3 times.3 timezone.3 \ + ttyname.3 tzset.3 ualarm.3 uname.3 unvis.3 usleep.3 utime.3 \ + valloc.3 vis.3 + +MLINKS+=arc4random.3 arc4random_addrandom.3 arc4random.3 arc4random_stir.3 +MLINKS+=ctermid.3 ctermid_r.3 +MLINKS+=directory.3 closedir.3 directory.3 dirfd.3 directory.3 opendir.3 \ + directory.3 readdir.3 directory.3 rewinddir.3 directory.3 seekdir.3 \ + directory.3 telldir.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 +MLINKS+=exec.3 execl.3 exec.3 execle.3 exec.3 execlp.3 exec.3 exect.3 \ + exec.3 execv.3 exec.3 execvp.3 +MLINKS+=fts.3 fts_children.3 fts.3 fts_close.3 fts.3 fts_open.3 \ + fts.3 fts_read.3 fts.3 fts_set.3 +MLINKS+=getcap.3 cgetcap.3 getcap.3 cgetclose.3 getcap.3 cgetent.3 \ + getcap.3 cgetfirst.3 getcap.3 cgetmatch.3 getcap.3 cgetnext.3 \ + getcap.3 cgetnum.3 getcap.3 cgetset.3 getcap.3 cgetstr.3 \ + getcap.3 cgetustr.3 +MLINKS+=getcwd.3 getwd.3 +MLINKS+=getdomainname.3 setdomainname.3 +MLINKS+=getfsent.3 endfsent.3 getfsent.3 getfsfile.3 getfsent.3 getfsspec.3 \ + getfsent.3 getfstype.3 getfsent.3 setfsent.3 +MLINKS+=getgrent.3 endgrent.3 getgrent.3 getgrgid.3 getgrent.3 getgrnam.3 \ + getgrent.3 setgrent.3 getgrent.3 setgroupent.3 +MLINKS+=gethostname.3 sethostname.3 +MLINKS+=getnetgrent.3 endnetgrent.3 getnetgrent.3 innetgr.3 \ + getnetgrent.3 setnetgrent.3 +MLINKS+=getpwent.3 endpwent.3 getpwent.3 getpwnam.3 getpwent.3 getpwuid.3 \ + getpwent.3 setpassent.3 getpwent.3 setpwent.3 getpwent.3 setpwfile.3 +MLINKS+=getttyent.3 endttyent.3 getttyent.3 getttynam.3 \ + getttyent.3 isdialuptty.3 getttyent.3 isnettty.3 \ + getttyent.3 setttyent.3 +MLINKS+=getusershell.3 endusershell.3 getusershell.3 setusershell.3 +MLINKS+=getvfsent.3 endvfsent.3 getvfsent.3 getvfsbytype.3 \ + getvfsent.3 setvfsent.3 getvfsent.3 vfsisloadable.3 \ + getvfsent.3 vfsload.3 +MLINKS+=glob.3 globfree.3 +MLINKS+=isinf.3 isnan.3 isinf.3 isnanf.3 +MLINKS+=popen.3 pclose.3 +MLINKS+=psignal.3 sys_siglist.3 psignal.3 sys_signame.3 +MLINKS+=psignal.3 strsignal.3 psignal.3 sys_siglist.3 psignal.3 sys_signame.3 +MLINKS+=pwcache.3 group_from_gid.3 pwcache.3 user_from_uid.3 +MLINKS+=rand48.3 _rand48.3 rand48.3 drand48.3 rand48.3 erand48.3 \ + rand48.3 jrand48.3 rand48.3 lcong48.3 rand48.3 lrand48.3 \ + rand48.3 mrand48.3 rand48.3 nrand48.3 rand48.3 seed48.3 \ + rand48.3 srand48.3 +MLINKS+=scandir.3 alphasort.3 +MLINKS+=strtofflags.3 fflagstostr.3 +MLINKS+=setjmp.3 _longjmp.3 setjmp.3 _setjmp.3 setjmp.3 longjmp.3 \ + setjmp.3 longjmperr.3 setjmp.3 longjmperror.3 \ + setjmp.3 siglongjmp.3 setjmp.3 sigsetjmp.3 +MLINKS+=setmode.3 getmode.3 +MLINKS+=sigsetops.3 sigaddset.3 sigsetops.3 sigdelset.3 \ + sigsetops.3 sigemptyset.3 sigsetops.3 sigfillset.3 \ + sigsetops.3 sigismember.3 +MLINKS+=stringlist.3 sl_add.3 stringlist.3 sl_find.3 \ + stringlist.3 sl_free.3 stringlist.3 sl_init.3 +MLINKS+=sysctl.3 sysctlbyname.3 sysctl.3 sysctlnametomib.3 +MLINKS+=syslog.3 closelog.3 syslog.3 openlog.3 syslog.3 setlogmask.3 \ + syslog.3 vsyslog.3 +MLINKS+=tcsendbreak.3 tcdrain.3 tcsendbreak.3 tcflow.3 tcsendbreak.3 tcflush.3 +MLINKS+=tcsetattr.3 cfgetispeed.3 tcsetattr.3 cfgetospeed.3 \ + tcsetattr.3 cfmakeraw.3 tcsetattr.3 cfsetispeed.3 \ + tcsetattr.3 cfsetospeed.3 tcsetattr.3 cfsetspeed.3 \ + tcsetattr.3 tcgetattr.3 +MLINKS+=ttyname.3 isatty.3 ttyname.3 ttyslot.3 +MLINKS+=tzset.3 tzsetwall.3 +MLINKS+=unvis.3 strunvis.3 unvis.3 strunvisx.3 +MLINKS+=vis.3 strvis.3 vis.3 strvisx.3 +MLINKS+=readdir.3 readdir_r.3 +.endif diff --git a/gen/NSSystemDirectories.c b/gen/NSSystemDirectories.c new file mode 100644 index 0000000..fcbdb05 --- /dev/null +++ b/gen/NSSystemDirectories.c @@ -0,0 +1,124 @@ +/* + * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This 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.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. + * + * 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@ + */ +#import +#import +#import +#import + +// Names of directories; index into this with NSSearchPathDirectory - 1 +#define numDirs 10 +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, "Developer/Applications"}, + {0, 0, "Applications/Utilities"}, + {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 +}; + +// Ordered list of where to find applications in each domain (the numbers are NSSearchPathDirectory) +#define numApplicationDirs 4 +static const char applicationDirs[numApplicationDirs] = {1, 4, 3, 2}; + +// Ordered list of where to find resources in each domain (the numbers are NSSearchPathDirectory) +#define numLibraryDirs 2 +static const char libraryDirs[numLibraryDirs] = {5, 6}; + +// Names of domains; index into this log2(domainMask). If the search path ordering is ever changed, then we need an indirection (as the domainMask values cannot be changed). +#define numDomains 4 +static const struct { + char needsRootPrepended; + const char *domainPath; + const char *alternateDomainPath; +} domainInfo[numDomains] = { + {0, "~", "~"}, + {1, "", ""}, + {1, "/Network", "/Network"}, + {1, "", "/System"} +}; + +#define invalidDomains 0x00 // some domains may be invalid on non-Mach systems + +NSSearchPathEnumerationState NSStartSearchPathEnumeration(NSSearchPathDirectory dir, NSSearchPathDomainMask domainMask) { + // The state is AABBCCCC, where + // AA is the dir(s) requested + // BB is the current state of dirs (if AA < 100, then this is always 0; otherwise it goes up to number of dirs) + // CCCC is the domains requested + // the state always contains the next item; if CCCC is 0, then we're done + domainMask = domainMask & ((1 << numDomains) - 1) & ~invalidDomains; // Just leave useful bits in there + if (dir != NSAllLibrariesDirectory && dir != NSLibraryDirectory && dir != NSUserDirectory && dir != NSDocumentationDirectory && (domainMask & NSLocalDomainMask) && (domainMask & NSSystemDomainMask)) domainMask = domainMask & ~NSSystemDomainMask; // Hack to avoid duplication + return (((unsigned int)dir) << 24) + ((unsigned int)domainMask); +} + +NSSearchPathEnumerationState NSGetNextSearchPathEnumeration(NSSearchPathEnumerationState state, char *path) { + static const char *nextRoot = NULL; + unsigned dir = (state >> 24) & 0xff; + unsigned dirState = (state >> 16) & 0xff; + unsigned domainMask = state & 0xffff; + unsigned int curDomain; // The current domain we're at... + unsigned int curDir = 0; // The current dir... + + do { + if (domainMask == 0) return 0; // Looks like we're done + for (curDomain = 0; curDomain < numDomains; curDomain++) if ((domainMask & (1 << curDomain))) break; + + // Determine directory + if (dir < NSAllApplicationsDirectory) { // One directory per domain, simple... + curDir = dir; + } else { // Can return multiple directories for each domain + if (dir == NSAllApplicationsDirectory) { + curDir = applicationDirs[dirState]; + if (++dirState == numApplicationDirs) dirState = 0; + } else if (dir == NSAllLibrariesDirectory) { + curDir = libraryDirs[dirState]; + if (++dirState == numLibraryDirs) dirState = 0; + } + } + if (dirState == 0) domainMask &= ~(1 << curDomain); // If necessary, jump to next domain + } while ((dirInfo[curDir - 1].invalidDomainMask & (1 << curDomain))); // If invalid, try again... + + // Get NEXT_ROOT, if necessary. + if (domainInfo[curDomain].needsRootPrepended && nextRoot == 0) { + nextRoot = getenv("NEXT_ROOT"); + if (nextRoot == NULL) { + nextRoot = ""; + } else { + strcpy(malloc(strlen(nextRoot) + 1), nextRoot); // Be safe... + } + } + + snprintf(path, PATH_MAX, "%s%s/%s", domainInfo[curDomain].needsRootPrepended ? nextRoot : "", (dirInfo[curDir - 1].alternateDomainMask & (1 << curDomain)) ? domainInfo[curDomain].alternateDomainPath : domainInfo[curDomain].domainPath, dirInfo[curDir - 1].dirPath); + + return (dir << 24) + (dirState << 16) + domainMask; +} + + diff --git a/gen/_rand48.c b/gen/_rand48.c new file mode 100644 index 0000000..990e2c8 --- /dev/null +++ b/gen/_rand48.c @@ -0,0 +1,46 @@ +/* + * Copyright (c) 1993 Martin Birgmeier + * All rights reserved. + * + * You may redistribute unmodified or modified versions of this source + * code provided that the above copyright notice and this and the + * following conditions are retained. + * + * This software is provided ``as is'', and comes with no warranties + * of any kind. I shall in no event be liable for anything that happens + * to anyone/anything when using this software. + */ + +#include "rand48.h" + +unsigned short _rand48_seed[3] = { + RAND48_SEED_0, + RAND48_SEED_1, + RAND48_SEED_2 +}; +unsigned short _rand48_mult[3] = { + RAND48_MULT_0, + RAND48_MULT_1, + RAND48_MULT_2 +}; +unsigned short _rand48_add = RAND48_ADD; + +void +_dorand48(unsigned short xseed[3]) +{ + unsigned long accu; + unsigned short temp[2]; + + accu = (unsigned long) _rand48_mult[0] * (unsigned long) xseed[0] + + (unsigned long) _rand48_add; + temp[0] = (unsigned short) accu; /* lower 16 bits */ + accu >>= sizeof(unsigned short) * 8; + accu += (unsigned long) _rand48_mult[0] * (unsigned long) xseed[1] + + (unsigned long) _rand48_mult[1] * (unsigned long) xseed[0]; + temp[1] = (unsigned short) accu; /* middle 16 bits */ + accu >>= sizeof(unsigned short) * 8; + accu += _rand48_mult[0] * xseed[2] + _rand48_mult[1] * xseed[1] + _rand48_mult[2] * xseed[0]; + xseed[0] = temp[0]; + xseed[1] = temp[1]; + xseed[2] = (unsigned short) accu; +} diff --git a/gen/alarm.3 b/gen/alarm.3 new file mode 100644 index 0000000..d2725b1 --- /dev/null +++ b/gen/alarm.3 @@ -0,0 +1,98 @@ +.\" Copyright (c) 1980, 1991, 1993, 1994 +.\" 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. +.\" +.\" @(#)alarm.3 8.2 (Berkeley) 4/19/94 +.\" $FreeBSD: src/lib/libc/gen/alarm.3,v 1.15 2001/10/01 16:08:50 ru Exp $ +.\" +.Dd April 19, 1994 +.Dt ALARM 3 +.Os +.Sh NAME +.Nm alarm +.Nd set signal timer alarm +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In unistd.h +.Ft unsigned int +.Fn alarm "unsigned int seconds" +.Sh DESCRIPTION +.Bf -symbolic +This interface is made obsolete by +.Xr setitimer 2 . +.Ef +.Pp +The +.Fn alarm +function sets a timer to deliver the signal +.Dv SIGALRM +to the calling process after the specified number of +.Fa seconds . +If an alarm has already been set with +.Fn alarm +but has not been delivered, another call to +.Fn alarm +will supersede the prior call. +The request +.Fn alarm "0" +voids the current +alarm and the signal SIGALRM will not be delivered. +.Pp +Due to +.Xr setitimer 2 +restriction the maximum number of +.Ar seconds +allowed is 100000000. +.Sh RETURN VALUES +The return value of +.Fn alarm +is the amount of time left on the timer from a previous call to +.Fn alarm . +If no alarm is currently set, the return value is 0. +.Sh SEE ALSO +.Xr setitimer 2 , +.Xr sigaction 2 , +.Xr sigpause 2 , +.Xr sigvec 2 , +.Xr signal 3 , +.Xr sleep 3 , +.Xr ualarm 3 , +.Xr usleep 3 +.\" .Sh STANDARDS +.\" The +.\" .Fn alarm +.\" function conforms to +.\" .St -p1003.1-90 . +.Sh HISTORY +An +.Fn alarm +function appeared in +.At v7 . diff --git a/gen/alarm.c b/gen/alarm.c new file mode 100644 index 0000000..1b66b07 --- /dev/null +++ b/gen/alarm.c @@ -0,0 +1,77 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1983, 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. + */ + + +/* + * Backwards compatible alarm. + */ +#include +#include + +unsigned int +alarm(secs) + unsigned int secs; +{ + struct itimerval it, oitv; + register struct itimerval *itp = ⁢ + + timerclear(&itp->it_interval); + itp->it_value.tv_sec = secs; + itp->it_value.tv_usec = 0; + if (setitimer(ITIMER_REAL, itp, &oitv) < 0) + return (-1); + if (oitv.it_value.tv_usec) + oitv.it_value.tv_sec++; + return (oitv.it_value.tv_sec); +} diff --git a/gen/arc4random.3 b/gen/arc4random.3 new file mode 100644 index 0000000..85e6eb0 --- /dev/null +++ b/gen/arc4random.3 @@ -0,0 +1,89 @@ +.\" $OpenBSD: arc4random.3,v 1.2 1997/04/27 22:40:25 angelos Exp $ +.\" Copyright 1997 Niels Provos +.\" 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 Niels Provos. +.\" 4. 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 BY THE AUTHOR ``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 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. +.\" +.\" Manual page, using -mandoc macros +.\" $FreeBSD: src/lib/libc/gen/arc4random.3,v 1.12 2001/10/01 16:08:50 ru Exp $ +.\" +.Dd April 15, 1997 +.Dt ARC4RANDOM 3 +.Os +.Sh NAME +.Nm arc4random , +.Nm arc4random_stir , +.Nm arc4random_addrandom +.Nd arc4 random number generator +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In stdlib.h +.Ft u_int32_t +.Fn arc4random "void" +.Ft void +.Fn arc4random_stir "void" +.Ft void +.Fn arc4random_addrandom "unsigned char *dat" "int datlen" +.Sh DESCRIPTION +The +.Fn arc4random +function uses the key stream generator employed by the +arc4 cipher, which uses 8*8 8 bit S-Boxes. +The S-Boxes +can be in about +.if t 2\u\s71700\s10\d +.if n (2**1700) +states. +.Pp +The +.Fn arc4random_stir +function reads data from +.Pa /dev/urandom +and uses it to permute the S-Boxes via +.Fn arc4random_addrandom . +.Pp +There is no need to call +.Fn arc4random_stir +before using +.Fn arc4random , +since +.Fn arc4random +automatically initializes itself. +.Sh SEE ALSO +.Xr rand 3 , +.Xr random 3 , +.Xr srandomdev 3 +.Sh HISTORY +.Pa RC4 +has been designed by RSA Data Security, Inc. +It was posted anonymously +to the USENET and was confirmed to be equivalent by several sources who +had access to the original cipher. +Since +.Pa RC4 +used to be a trade secret, the cipher is now referred to as +.Pa ARC4 . diff --git a/gen/arc4random.c b/gen/arc4random.c new file mode 100644 index 0000000..0dce7ef --- /dev/null +++ b/gen/arc4random.c @@ -0,0 +1,177 @@ +/* $FreeBSD: src/lib/libc/gen/arc4random.c,v 1.4 2000/01/27 23:06:13 jasone Exp $ */ + +/* + * Arc4 random number generator for OpenBSD. + * Copyright 1996 David Mazieres . + * + * Modification and redistribution in source and binary forms is + * permitted provided that due credit is given to the author and the + * OpenBSD project (for instance by leaving this copyright notice + * intact). + */ + +/* + * This code is derived from section 17.1 of Applied Cryptography, + * second edition, which describes a stream cipher allegedly + * compatible with RSA Labs "RC4" cipher (the actual description of + * which is a trade secret). The same algorithm is used as a stream + * cipher called "arcfour" in Tatu Ylonen's ssh package. + * + * Here the stream cipher has been modified always to include the time + * when initializing the state. That makes it impossible to + * regenerate the same random sequence twice, so this can't be used + * for encryption, but will generate good random numbers. + * + * RC4 is a registered trademark of RSA Laboratories. + */ + +#include +#include +#include +#include +#include + +struct arc4_stream { + u_int8_t i; + u_int8_t j; + u_int8_t s[256]; +}; + +static int rs_initialized; +static struct arc4_stream *rs = NULL; + +static inline void +arc4_init(as) + struct arc4_stream *as; +{ + int n; + + for (n = 0; n < 256; n++) + as->s[n] = n; + as->i = 0; + as->j = 0; +} + +static inline void +arc4_addrandom(as, dat, datlen) + struct arc4_stream *as; + u_char *dat; + int datlen; +{ + int n; + u_int8_t si; + + as->i--; + for (n = 0; n < 256; n++) { + as->i = (as->i + 1); + si = as->s[as->i]; + as->j = (as->j + si + dat[n % datlen]); + as->s[as->i] = as->s[as->j]; + as->s[as->j] = si; + } +} + +static void +arc4_stir(as) + struct arc4_stream *as; +{ + int fd; + struct { + struct timeval tv; + pid_t pid; + u_int8_t rnd[128 - sizeof(struct timeval) - sizeof(pid_t)]; + } rdat; + + gettimeofday(&rdat.tv, NULL); + rdat.pid = getpid(); + fd = open("/dev/urandom", O_RDONLY, 0); + if (fd >= 0) { + (void) read(fd, rdat.rnd, sizeof(rdat.rnd)); + close(fd); + } + /* fd < 0? Ah, what the heck. We'll just take whatever was on the + * stack... */ + + arc4_addrandom(as, (void *) &rdat, sizeof(rdat)); +} + +static inline u_int8_t +arc4_getbyte(as) + struct arc4_stream *as; +{ + u_int8_t si, sj; + + as->i = (as->i + 1); + si = as->s[as->i]; + as->j = (as->j + si); + sj = as->s[as->j]; + as->s[as->i] = sj; + as->s[as->j] = si; + return (as->s[(si + sj) & 0xff]); +} + +static inline u_int32_t +arc4_getword(as) + struct arc4_stream *as; +{ + u_int32_t val; + val = arc4_getbyte(as) << 24; + val |= arc4_getbyte(as) << 16; + val |= arc4_getbyte(as) << 8; + val |= arc4_getbyte(as); + return val; +} + +void +arc4random_stir() +{ + if ( rs == NULL ) { + rs = malloc( sizeof(struct arc4_stream) ); + if( rs == NULL ) + return ; /* Hmmm. */ + } + if (!rs_initialized) { + arc4_init(rs); + rs_initialized = 1; + } + arc4_stir(rs); +} + +void +arc4random_addrandom(dat, datlen) + u_char *dat; + int datlen; +{ + if (!rs_initialized) + arc4random_stir(); + arc4_addrandom(rs, dat, datlen); +} + +u_int32_t +arc4random() +{ + if (!rs_initialized) + arc4random_stir(); + return arc4_getword(rs); +} + +#if 0 +/*-------- Test code for i386 --------*/ +#include +#include +int +main(int argc, char **argv) +{ + const int iter = 1000000; + int i; + pctrval v; + + v = rdtsc(); + for (i = 0; i < iter; i++) + arc4random(); + v = rdtsc() - v; + v /= iter; + + printf("%qd cycles\n", v); +} +#endif diff --git a/gen/assert.c b/gen/assert.c new file mode 100644 index 0000000..2ce97a7 --- /dev/null +++ b/gen/assert.c @@ -0,0 +1,75 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * 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 +#include +#include +#include + +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 diff --git a/gen/authentication.c b/gen/authentication.c new file mode 100644 index 0000000..54ac361 --- /dev/null +++ b/gen/authentication.c @@ -0,0 +1,101 @@ +/* + * Copyright (c) 2000 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@ + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "authentication.h" + +int isAuthenticatedAsAdministrator(void) +{ + if (isAuthenticatedAsRoot()) { + return 1; + } + // otherwise ... + return isAuthenticatedAsAdministratorForTask(0); +} + +int isAuthenticatedAsAdministratorForTask(int taskNum) +{ + int admin = 0; + uid_t ruid; + + if (isAuthenticatedAsRoot()) { + return 1; + } + + ruid = getuid(); + + if (ruid) { + gid_t groups[NGROUPS_MAX]; + int numgroups; + + /* + * Only allow those in group taskNum group (By default admin) to authenticate. + */ + if ((numgroups = getgroups(NGROUPS_MAX, groups)) > 0) { + int i; + gid_t admingid = 0; + struct group *admingroup; + + if ((admingroup = getgrnam(groupNameForTask(taskNum))) != NULL) { + admingid = admingroup->gr_gid; + + for (i = 0; i < numgroups; i++) { + if (groups[i] == admingid) { + admin = 1; + break; + } + } + } + + } + } + // otherwise + return admin; +} + +int isAuthenticatedAsRoot(void) +{ + if (getuid() == 0) { + return 1; + } + return 0; +} + +char *groupNameForTask(int taskNum) +{ + if (taskNum == 0) + return "admin"; + + return "admin"; +} + diff --git a/gen/basename.3 b/gen/basename.3 new file mode 100644 index 0000000..3385318 --- /dev/null +++ b/gen/basename.3 @@ -0,0 +1,101 @@ +.\" +.\" Copyright (c) 1997 Todd C. Miller +.\" 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. 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 ARE 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 +.\" 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.4 2001/10/01 16:08:50 ru Exp $ +.\" +.Dd August 17, 1997 +.Dt BASENAME 3 +.Os +.Sh NAME +.Nm basename +.Nd extract the base portion of a pathname +.Sh SYNOPSIS +.In libgen.h +.Ft char * +.Fn basename "const char *path" +.Sh DESCRIPTION +The +.Fn basename +function +returns the last component from the pathname pointed to by +.Ar path , +deleting any trailing +.Sq \&/ +characters. +If +.Ar path +consists entirely of +.Sq \&/ +characters, a pointer to the string +.Qq \&/ +is returned. +If +.Ar path +is a null pointer or the empty string, a pointer to the string +.Qq \&. +is returned. +.Sh RETURN VALUES +On successful completion, +.Fn basename +returns a pointer to the last component of +.Ar path . +.Pp +If +.Fn basename +fails, a null pointer is returned and the global variable +.Va errno +is set to indicate the error. +.Sh ERRORS +The following error codes may be set in +.Va errno : +.Bl -tag -width Er +.It Bq Er ENAMETOOLONG +The path component to be returned was larger than +.Dv MAXPATHLEN . +.El +.Sh WARNINGS +.Fn basename +returns a pointer to internal static storage space that will be overwritten +by subsequent calls. +.Sh SEE ALSO +.Xr basename 1 , +.Xr dirname 1 , +.Xr dirname 3 +.Sh STANDARDS +The +.Fn basename +function conforms to +.St -xpg4.2 . +.Sh HISTORY +The +.Fn basename +function first appeared in +.Ox 2.2 +and +.Fx 4.2 . +.Sh AUTHORS +Todd C. Miller diff --git a/gen/basename.c b/gen/basename.c new file mode 100644 index 0000000..a138177 --- /dev/null +++ b/gen/basename.c @@ -0,0 +1,83 @@ +/* $OpenBSD: basename.c,v 1.4 1999/05/30 17:10:30 espie Exp $ */ +/* $FreeBSD: src/lib/libc/gen/basename.c,v 1.1.2.2 2001/07/23 10:13:04 dd Exp $ */ + +/* + * Copyright (c) 1997 Todd C. Miller + * 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. 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 ARE 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 + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#if defined(LIBC_RCS) && !defined(lint) +static char rcsid[] = "$OpenBSD: basename.c,v 1.4 1999/05/30 17:10:30 espie Exp $"; +#endif /* not lint */ + +#include +#include +#include +#include +#include + +char * +basename(path) + const char *path; +{ + static char *bname = NULL; + register const char *endp, *startp; + + if( bname == NULL ) { + bname = malloc(MAXPATHLEN); + if( bname == NULL ) + return NULL; + } + + /* Empty or NULL string gets treated as "." */ + if (path == NULL || *path == '\0') { + (void)strcpy(bname, "."); + return(bname); + } + + /* Strip trailing slashes */ + endp = path + strlen(path) - 1; + while (endp > path && *endp == '/') + endp--; + + /* All slashes becomes "/" */ + if (endp == path && *endp == '/') { + (void)strcpy(bname, "/"); + return(bname); + } + + /* Find the start of the base */ + startp = endp; + while (startp > path && *(startp - 1) != '/') + startp--; + + if (endp - startp + 2 > MAXPATHLEN) { + errno = ENAMETOOLONG; + return(NULL); + } + (void)strncpy(bname, startp, endp - startp + 1); + bname[endp - startp + 1] = '\0'; + return(bname); +} diff --git a/gen/clock.3 b/gen/clock.3 new file mode 100644 index 0000000..2f053a6 --- /dev/null +++ b/gen/clock.3 @@ -0,0 +1,80 @@ +.\" 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. +.\" +.\" @(#)clock.3 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD: src/lib/libc/gen/clock.3,v 1.10 2001/11/05 21:30:43 dwmalone Exp $ +.\" +.Dd June 4, 1993 +.Dt CLOCK 3 +.Os +.Sh NAME +.Nm clock +.Nd determine processor time used +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In time.h +.Ft clock_t +.Fn clock void +.Sh DESCRIPTION +The +.Fn clock +function +determines the amount of processor time used since the invocation of the +calling process, measured in +.Dv CLOCKS_PER_SEC Ns s +of a second. +.Sh RETURN VALUES +The +.Fn clock +function returns the amount of time used unless an error occurs, in which +case the return value is \-1. +.Sh SEE ALSO +.Xr getrusage 2 , +.Xr clocks 7 +.Sh STANDARDS +The +.Fn clock +function conforms to +.St -isoC . +However, +.St -susv2 +requires +.Dv CLOCKS_PER_SEC +to be defined as one million. +.Fx +does not conform to this requirement; +changing the value would introduce binary incompatibility +and one million is still inadequate on modern processors. diff --git a/gen/clock.c b/gen/clock.c new file mode 100644 index 0000000..47367f3 --- /dev/null +++ b/gen/clock.c @@ -0,0 +1,74 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1989, 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 +#include +#include + +/* + * Convert usec to clock ticks; could do (usec * CLK_TCK) / 1000000, + * but this would overflow if we switch to nanosec. + */ +#define CONVTCK(r) (r.tv_sec * CLK_TCK + r.tv_usec / (1000000 / CLK_TCK)) + +clock_t +clock() +{ + struct rusage ru; + + if (getrusage(RUSAGE_SELF, &ru)) + return ((clock_t) -1); + return((clock_t)((CONVTCK(ru.ru_utime) + CONVTCK(ru.ru_stime)))); +} diff --git a/gen/closedir.c b/gen/closedir.c new file mode 100644 index 0000000..858f4fc --- /dev/null +++ b/gen/closedir.c @@ -0,0 +1,76 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1983, 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 +#include +#include +#include + +/* + * close a directory. + */ +int +closedir(dirp) + register DIR *dirp; +{ + int fd; + + seekdir(dirp, dirp->dd_rewind); /* free seekdir storage */ + fd = dirp->dd_fd; + dirp->dd_fd = -1; + dirp->dd_loc = 0; + (void)free((void *)dirp->dd_buf); + (void)free((void *)dirp); + return(close(fd)); +} diff --git a/gen/confstr.3 b/gen/confstr.3 new file mode 100644 index 0000000..ccecf7e --- /dev/null +++ b/gen/confstr.3 @@ -0,0 +1,136 @@ +.\" 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. +.\" +.\" @(#)confstr.3 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD: src/lib/libc/gen/confstr.3,v 1.11 2001/10/01 16:08:50 ru Exp $ +.\" +.Dd June 18, 2001 +.Dt CONFSTR 3 +.Os +.Sh NAME +.Nm confstr +.Nd get string-valued configurable variables +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In unistd.h +.Ft size_t +.Fn confstr "int name" "char *buf" "size_t len" +.Sh DESCRIPTION +This interface is specified by +.\" .St -p1003.1-200x . +.Tn POSIX . +A more flexible (but non-portable) interface is provided by +.Xr sysctl 3 . +.Pp +The +.Fn confstr +function provides a method for applications to get configuration +defined string values. +Shell programmers needing access to these parameters should use the +.Xr getconf 1 +utility. +.Pp +The +.Fa name +argument specifies the system variable to be queried. +Symbolic constants for each name value are found in the include file +.Aq Pa unistd.h . +The +.Fa len +argument specifies the size of the buffer referenced by the +argument +.Fa buf . +If +.Fa len +is non-zero, +.Fa buf +is a non-null pointer, and +.Fa name +has a value, up to +.Fa len +\- 1 bytes of the value are copied into the buffer +.Fa buf . +The copied value is always null terminated. +.Pp +The available values are as follows: +.Pp +.Bl -tag -width 6n +.Pp +.It Li _CS_PATH +Return a value for the +.Ev PATH +environment variable that finds all the standard utilities. +.El +.Sh RETURN VALUES +If the call to +.Fn confstr +is not successful, \-1 is returned and +.Va errno +is set appropriately. +Otherwise, if the variable does not have a configuration defined value, +0 is returned and +.Va errno +is not modified. +Otherwise, the buffer size needed to hold the entire configuration-defined +value is returned. +If this size is greater than the argument +.Fa len , +the string in +.Fa buf +was truncated. +.Sh ERRORS +The +.Fn confstr +function may fail and set +.Va errno +for any of the errors specified for the library functions +.Xr malloc 3 +and +.Xr sysctl 3 . +.Pp +In addition, the following errors may be reported: +.Bl -tag -width Er +.It Bq Er EINVAL +The value of the +.Fa name +argument is invalid. +.El +.Sh SEE ALSO +.Xr getconf 1 , +.Xr pathconf 2 , +.Xr sysconf 3 , +.Xr sysctl 3 +.Sh HISTORY +The +.Fn confstr +function first appeared in +.Bx 4.4 . diff --git a/gen/confstr.c b/gen/confstr.c new file mode 100644 index 0000000..9c380aa --- /dev/null +++ b/gen/confstr.c @@ -0,0 +1,104 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * 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 +#include + +#include +#include +#include +#include +#include + +size_t +confstr(name, buf, len) + int name; + char *buf; + size_t len; +{ + size_t tlen; + int mib[2], sverrno; + char *p; + + switch (name) { + case _CS_PATH: + mib[0] = CTL_USER; + mib[1] = USER_CS_PATH; + if (sysctl(mib, 2, NULL, &tlen, NULL, 0) == -1) + return (-1); + if (len != 0 && buf != NULL) { + if ((p = malloc(tlen)) == NULL) + return (-1); + if (sysctl(mib, 2, p, &tlen, NULL, 0) == -1) { + sverrno = errno; + free(p); + errno = sverrno; + return (-1); + } + /* + * POSIX 1003.2 requires partial return of + * the string -- that should be *real* useful. + */ + (void)strncpy(buf, p, len - 1); + buf[len - 1] = '\0'; + free(p); + } + return (tlen + 1); + default: + errno = EINVAL; + return (0); + } + /* NOTREACHED */ +} diff --git a/gen/crypt.c b/gen/crypt.c new file mode 100644 index 0000000..2f56953 --- /dev/null +++ b/gen/crypt.c @@ -0,0 +1,993 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1989, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Tom Truscott. + * + * 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 +#include +#include +#include + +/* + * UNIX password, and DES, encryption. + * By Tom Truscott, trt@rti.rti.org, + * from algorithms by Robert W. Baldwin and James Gillogly. + * + * References: + * "Mathematical Cryptology for Computer Scientists and Mathematicians," + * by Wayne Patterson, 1987, ISBN 0-8476-7438-X. + * + * "Password Security: A Case History," R. Morris and Ken Thompson, + * Communications of the ACM, vol. 22, pp. 594-597, Nov. 1979. + * + * "DES will be Totally Insecure within Ten Years," M.E. Hellman, + * IEEE Spectrum, vol. 16, pp. 32-39, July 1979. + */ + +/* ===== Configuration ==================== */ + +/* + * 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!) + */ +#if !defined(vax) +#define MUST_ALIGN +#endif + +#ifdef CHAR_BITS +#if CHAR_BITS != 8 + #error C_block structure assumes 8 bit characters +#endif +#endif + +/* + * 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) +#define LONG_IS_32_BITS +#endif + +/* + * define "B64" to be the declaration for a 64 bit integer. + * XXX this feature is currently unused, see "endian" comment below. + */ +#if defined(cray) +#define B64 long +#endif +#if defined(convex) +#define B64 long long +#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 + * little effect on crypt(). + */ +#if defined(notdef) +#define LARGEDATA +#endif + +/* compile with "-DSTATIC=int" when profiling */ +#ifndef STATIC +#define STATIC static +#endif +STATIC void init_des(), init_perm(), permute(); +#ifdef DEBUG +STATIC prtab(); +#endif + +/* ==================================== */ + +/* + * Cipher-block representation (Bob Baldwin): + * + * DES operates on groups of 64 bits, numbered 1..64 (sigh). One + * representation is to store one bit per byte in an array of bytes. Bit N of + * the NBS spec is stored as the LSB of the Nth byte (index N-1) in the array. + * Another representation stores the 64 bits in 8 bytes, with bits 1..8 in the + * first byte, 9..16 in the second, and so on. The DES spec apparently has + * bit 1 in the MSB of the first byte, but that is particularly noxious so we + * bit-reverse each byte so that bit 1 is the LSB of the first byte, bit 8 is + * the MSB of the first byte. Specifically, the 64-bit input data and key are + * converted to LSB format, and the output 64-bit block is converted back into + * MSB format. + * + * DES operates internally on groups of 32 bits which are expanded to 48 bits + * by permutation E and shrunk back to 32 bits by the S boxes. To speed up + * the computation, the expansion is applied only once, the expanded + * representation is maintained during the encryption, and a compression + * permutation is applied only at the end. To speed up the S-box lookups, + * the 48 bits are maintained as eight 6 bit groups, one per byte, which + * directly feed the eight S-boxes. Within each byte, the 6 bits are the + * most significant ones. The low two bits of each byte are zero. (Thus, + * bit 1 of the 48 bit E expansion is stored as the "4"-valued bit of the + * first byte in the eight byte representation, bit 2 of the 48 bit value is + * the "8"-valued bit, and so on.) In fact, a combined "SPE"-box lookup is + * used, in which the output is the 64 bit result of an S-box lookup which + * has been permuted by P and expanded by E, and is ready for use in the next + * iteration. Two 32-bit wide tables, SPE[0] and SPE[1], are used for this + * lookup. Since each byte in the 48 bit path is a multiple of four, indexed + * lookup of SPE[0] and SPE[1] is simple and fast. The key schedule and + * "salt" are also converted to this 8*(6+2) format. The SPE table size is + * 8*64*8 = 4K bytes. + * + * To speed up bit-parallel operations (such as XOR), the 8 byte + * representation is "union"ed with 32 bit values "i0" and "i1", and, on + * machines which support it, a 64 bit value "b64". This data structure, + * "C_block", has two problems. First, alignment restrictions must be + * honored. Second, the byte-order (e.g. little-endian or big-endian) of + * the architecture becomes visible. + * + * The byte-order problem is unfortunate, since on the one hand it is good + * to have a machine-independent C_block representation (bits 1..8 in the + * first byte, etc.), and on the other hand it is good for the LSB of the + * first byte to be the LSB of i0. We cannot have both these things, so we + * currently use the "little-endian" representation and avoid any multi-byte + * operations that depend on byte order. This largely precludes use of the + * 64-bit datatype since the relative order of i0 and i1 are unknown. It + * also inhibits grouping the SPE table to look up 12 bits at a time. (The + * 12 bits can be stored in a 16-bit field with 3 low-order zeroes and 1 + * high-order zero, providing fast indexing into a 64-bit wide SPE.) On the + * other hand, 64-bit datatypes are currently rare, and a 12-bit SPE lookup + * requires a 128 kilobyte table, so perhaps this is not a big loss. + * + * Permutation representation (Jim Gillogly): + * + * A transformation is defined by its effect on each of the 8 bytes of the + * 64-bit input. For each byte we give a 64-bit output that has the bits in + * the input distributed appropriately. The transformation is then the OR + * of the 8 sets of 64-bits. This uses 8*256*8 = 16K bytes of storage for + * each transformation. Unless LARGEDATA is defined, however, a more compact + * table is used which looks up 16 4-bit "chunks" rather than 8 8-bit chunks. + * The smaller table uses 16*16*8 = 2K bytes for each transformation. This + * is slower but tolerable, particularly for password encryption in which + * the SPE transformation is iterated many times. The small tables total 9K + * bytes, the large tables total 72K bytes. + * + * The transformations used are: + * IE3264: MSB->LSB conversion, initial permutation, and expansion. + * This is done by collecting the 32 even-numbered bits and applying + * a 32->64 bit transformation, and then collecting the 32 odd-numbered + * bits and applying the same transformation. Since there are only + * 32 input bits, the IE3264 transformation table is half the size of + * the usual table. + * CF6464: Compression, final permutation, and LSB->MSB conversion. + * This is done by two trivial 48->32 bit compressions to obtain + * a 64-bit block (the bit numbering is given in the "CIFP" table) + * followed by a 64->64 bit "cleanup" transformation. (It would + * be possible to group the bits in the 64-bit block so that 2 + * identical 32->32 bit transformations could be used instead, + * saving a factor of 4 in space and possibly 2 in time, but + * byte-ordering and other complications rear their ugly head. + * Similar opportunities/problems arise in the key schedule + * transforms.) + * PC1ROT: MSB->LSB, PC1 permutation, rotate, and PC2 permutation. + * This admittedly baroque 64->64 bit transformation is used to + * produce the first code (in 8*(6+2) format) of the key schedule. + * PC2ROT[0]: Inverse PC2 permutation, rotate, and PC2 permutation. + * It would be possible to define 15 more transformations, each + * with a different rotation, to generate the entire key schedule. + * To save space, however, we instead permute each code into the + * next by using a transformation that "undoes" the PC2 permutation, + * rotates the code, and then applies PC2. Unfortunately, PC2 + * transforms 56 bits into 48 bits, dropping 8 bits, so PC2 is not + * invertible. We get around that problem by using a modified PC2 + * which retains the 8 otherwise-lost bits in the unused low-order + * bits of each byte. The low-order bits are cleared when the + * codes are stored into the key schedule. + * PC2ROT[1]: Same as PC2ROT[0], but with two rotations. + * This is faster than applying PC2ROT[0] twice, + * + * The Bell Labs "salt" (Bob Baldwin): + * + * The salting is a simple permutation applied to the 48-bit result of E. + * Specifically, if bit i (1 <= i <= 24) of the salt is set then bits i and + * i+24 of the result are swapped. The salt is thus a 24 bit number, with + * 16777216 possible values. (The original salt was 12 bits and could not + * swap bits 13..24 with 36..48.) + * + * It is possible, but ugly, to warp the SPE table to account for the salt + * permutation. Fortunately, the conditional bit swapping requires only + * about four machine instructions and can be done on-the-fly with about an + * 8% performance penalty. + */ + +typedef union { + unsigned char b[8]; + struct { +#if defined(LONG_IS_32_BITS) + /* long is often faster than a 32-bit bit field */ + long i0; + long i1; +#else + long i0: 32; + long i1: 32; +#endif + } b32; +#if defined(B64) + B64 b64; +#endif +} C_block; + +/* + * Convert twenty-four-bit long in host-order + * to six bits (and 2 low-order zeroes) per char little-endian format. + */ +#define TO_SIX_BIT(rslt, src) { \ + C_block cvt; \ + cvt.b[0] = src; src >>= 6; \ + cvt.b[1] = src; src >>= 6; \ + cvt.b[2] = src; src >>= 6; \ + cvt.b[3] = src; \ + rslt = (cvt.b32.i0 & 0x3f3f3f3fL) << 2; \ + } + +/* + * These macros may someday permit efficient use of 64-bit integers. + */ +#define ZERO(d,d0,d1) d0 = 0, d1 = 0 +#define LOAD(d,d0,d1,bl) d0 = (bl).b32.i0, d1 = (bl).b32.i1 +#define LOADREG(d,d0,d1,s,s0,s1) d0 = s0, d1 = s1 +#define OR(d,d0,d1,bl) d0 |= (bl).b32.i0, d1 |= (bl).b32.i1 +#define STORE(s,s0,s1,bl) (bl).b32.i0 = s0, (bl).b32.i1 = s1 +#define DCL_BLOCK(d,d0,d1) long d0, d1 + +#if defined(LARGEDATA) + /* Waste memory like crazy. Also, do permutations in line */ +#define LGCHUNKBITS 3 +#define CHUNKBITS (1<>4]; OR(D,D0,D1,*tp); p += (1< 0); + STORE(D,D0,D1,*out); +} +#endif /* LARGEDATA */ + + +/* ===== (mostly) Standard DES Tables ==================== */ + +static unsigned char IP[] = { /* initial permutation */ + 58, 50, 42, 34, 26, 18, 10, 2, + 60, 52, 44, 36, 28, 20, 12, 4, + 62, 54, 46, 38, 30, 22, 14, 6, + 64, 56, 48, 40, 32, 24, 16, 8, + 57, 49, 41, 33, 25, 17, 9, 1, + 59, 51, 43, 35, 27, 19, 11, 3, + 61, 53, 45, 37, 29, 21, 13, 5, + 63, 55, 47, 39, 31, 23, 15, 7, +}; + +/* The final permutation is the inverse of IP - no table is necessary */ + +static unsigned char ExpandTr[] = { /* expansion operation */ + 32, 1, 2, 3, 4, 5, + 4, 5, 6, 7, 8, 9, + 8, 9, 10, 11, 12, 13, + 12, 13, 14, 15, 16, 17, + 16, 17, 18, 19, 20, 21, + 20, 21, 22, 23, 24, 25, + 24, 25, 26, 27, 28, 29, + 28, 29, 30, 31, 32, 1, +}; + +static unsigned char PC1[] = { /* permuted choice table 1 */ + 57, 49, 41, 33, 25, 17, 9, + 1, 58, 50, 42, 34, 26, 18, + 10, 2, 59, 51, 43, 35, 27, + 19, 11, 3, 60, 52, 44, 36, + + 63, 55, 47, 39, 31, 23, 15, + 7, 62, 54, 46, 38, 30, 22, + 14, 6, 61, 53, 45, 37, 29, + 21, 13, 5, 28, 20, 12, 4, +}; + +static unsigned char Rotates[] = { /* PC1 rotation schedule */ + 1, 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1, +}; + +/* note: each "row" of PC2 is left-padded with bits that make it invertible */ +static unsigned char PC2[] = { /* permuted choice table 2 */ + 9, 18, 14, 17, 11, 24, 1, 5, + 22, 25, 3, 28, 15, 6, 21, 10, + 35, 38, 23, 19, 12, 4, 26, 8, + 43, 54, 16, 7, 27, 20, 13, 2, + + 0, 0, 41, 52, 31, 37, 47, 55, + 0, 0, 30, 40, 51, 45, 33, 48, + 0, 0, 44, 49, 39, 56, 34, 53, + 0, 0, 46, 42, 50, 36, 29, 32, +}; + +static const unsigned char S[8][64] = { /* 48->32 bit substitution tables */ + /* S[1] */ + 14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12, 5, 9, 0, 7, + 0, 15, 7, 4, 14, 2, 13, 1, 10, 6, 12, 11, 9, 5, 3, 8, + 4, 1, 14, 8, 13, 6, 2, 11, 15, 12, 9, 7, 3, 10, 5, 0, + 15, 12, 8, 2, 4, 9, 1, 7, 5, 11, 3, 14, 10, 0, 6, 13, + /* S[2] */ + 15, 1, 8, 14, 6, 11, 3, 4, 9, 7, 2, 13, 12, 0, 5, 10, + 3, 13, 4, 7, 15, 2, 8, 14, 12, 0, 1, 10, 6, 9, 11, 5, + 0, 14, 7, 11, 10, 4, 13, 1, 5, 8, 12, 6, 9, 3, 2, 15, + 13, 8, 10, 1, 3, 15, 4, 2, 11, 6, 7, 12, 0, 5, 14, 9, + /* S[3] */ + 10, 0, 9, 14, 6, 3, 15, 5, 1, 13, 12, 7, 11, 4, 2, 8, + 13, 7, 0, 9, 3, 4, 6, 10, 2, 8, 5, 14, 12, 11, 15, 1, + 13, 6, 4, 9, 8, 15, 3, 0, 11, 1, 2, 12, 5, 10, 14, 7, + 1, 10, 13, 0, 6, 9, 8, 7, 4, 15, 14, 3, 11, 5, 2, 12, + /* S[4] */ + 7, 13, 14, 3, 0, 6, 9, 10, 1, 2, 8, 5, 11, 12, 4, 15, + 13, 8, 11, 5, 6, 15, 0, 3, 4, 7, 2, 12, 1, 10, 14, 9, + 10, 6, 9, 0, 12, 11, 7, 13, 15, 1, 3, 14, 5, 2, 8, 4, + 3, 15, 0, 6, 10, 1, 13, 8, 9, 4, 5, 11, 12, 7, 2, 14, + /* S[5] */ + 2, 12, 4, 1, 7, 10, 11, 6, 8, 5, 3, 15, 13, 0, 14, 9, + 14, 11, 2, 12, 4, 7, 13, 1, 5, 0, 15, 10, 3, 9, 8, 6, + 4, 2, 1, 11, 10, 13, 7, 8, 15, 9, 12, 5, 6, 3, 0, 14, + 11, 8, 12, 7, 1, 14, 2, 13, 6, 15, 0, 9, 10, 4, 5, 3, + /* S[6] */ + 12, 1, 10, 15, 9, 2, 6, 8, 0, 13, 3, 4, 14, 7, 5, 11, + 10, 15, 4, 2, 7, 12, 9, 5, 6, 1, 13, 14, 0, 11, 3, 8, + 9, 14, 15, 5, 2, 8, 12, 3, 7, 0, 4, 10, 1, 13, 11, 6, + 4, 3, 2, 12, 9, 5, 15, 10, 11, 14, 1, 7, 6, 0, 8, 13, + /* S[7] */ + 4, 11, 2, 14, 15, 0, 8, 13, 3, 12, 9, 7, 5, 10, 6, 1, + 13, 0, 11, 7, 4, 9, 1, 10, 14, 3, 5, 12, 2, 15, 8, 6, + 1, 4, 11, 13, 12, 3, 7, 14, 10, 15, 6, 8, 0, 5, 9, 2, + 6, 11, 13, 8, 1, 4, 10, 7, 9, 5, 0, 15, 14, 2, 3, 12, + /* S[8] */ + 13, 2, 8, 4, 6, 15, 11, 1, 10, 9, 3, 14, 5, 0, 12, 7, + 1, 15, 13, 8, 10, 3, 7, 4, 12, 5, 6, 11, 0, 14, 9, 2, + 7, 11, 4, 1, 9, 12, 14, 2, 0, 6, 10, 13, 15, 3, 5, 8, + 2, 1, 14, 7, 4, 10, 8, 13, 15, 12, 9, 0, 3, 5, 6, 11, +}; + +static unsigned char P32Tr[] = { /* 32-bit permutation function */ + 16, 7, 20, 21, + 29, 12, 28, 17, + 1, 15, 23, 26, + 5, 18, 31, 10, + 2, 8, 24, 14, + 32, 27, 3, 9, + 19, 13, 30, 6, + 22, 11, 4, 25, +}; + +static unsigned char CIFP[] = { /* compressed/interleaved permutation */ + 1, 2, 3, 4, 17, 18, 19, 20, + 5, 6, 7, 8, 21, 22, 23, 24, + 9, 10, 11, 12, 25, 26, 27, 28, + 13, 14, 15, 16, 29, 30, 31, 32, + + 33, 34, 35, 36, 49, 50, 51, 52, + 37, 38, 39, 40, 53, 54, 55, 56, + 41, 42, 43, 44, 57, 58, 59, 60, + 45, 46, 47, 48, 61, 62, 63, 64, +}; + +static unsigned char itoa64[] = /* 0..63 => ascii-64 */ + "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; + + +/* ===== Tables that are initialized at run time ==================== */ + + +static unsigned char a64toi[128]; /* ascii-64 => 0..63 */ + +/* Initial key schedule permutation */ +// static C_block PC1ROT[64/CHUNKBITS][1< final permutation table */ +// static C_block CF6464[64/CHUNKBITS][1<= 0; ) { + if ((t = (unsigned char)setting[i]) == '\0') + t = '.'; + encp[i] = t; + num_iter = (num_iter<<6) | a64toi[t]; + } + setting += 4; + encp += 4; + salt_size = 4; + break; + default: + num_iter = 25; + salt_size = 2; + } + + salt = 0; + for (i = salt_size; --i >= 0; ) { + if ((t = (unsigned char)setting[i]) == '\0') + t = '.'; + encp[i] = t; + salt = (salt<<6) | a64toi[t]; + } + encp += salt_size; + if (des_cipher((char *)&constdatablock, (char *)&rsltblock, + salt, num_iter)) + return (NULL); + + /* + * Encode the 64 cipher bits as 11 ascii characters. + */ + i = ((long)((rsltblock.b[0]<<8) | rsltblock.b[1])<<8) | rsltblock.b[2]; + encp[3] = itoa64[i&0x3f]; i >>= 6; + encp[2] = itoa64[i&0x3f]; i >>= 6; + encp[1] = itoa64[i&0x3f]; i >>= 6; + encp[0] = itoa64[i]; encp += 4; + i = ((long)((rsltblock.b[3]<<8) | rsltblock.b[4])<<8) | rsltblock.b[5]; + encp[3] = itoa64[i&0x3f]; i >>= 6; + encp[2] = itoa64[i&0x3f]; i >>= 6; + encp[1] = itoa64[i&0x3f]; i >>= 6; + encp[0] = itoa64[i]; encp += 4; + i = ((long)((rsltblock.b[6])<<8) | rsltblock.b[7])<<2; + encp[2] = itoa64[i&0x3f]; i >>= 6; + encp[1] = itoa64[i&0x3f]; i >>= 6; + encp[0] = itoa64[i]; + + encp[3] = 0; + + return (cryptresult); +} + + +/* + * The Key Schedule, filled in by 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) + register const char *key; +{ + register DCL_BLOCK(K, K0, K1); + register C_block *ptabp; + register int i; + static int des_ready = 0; + + if (!des_ready) { + init_des(); + des_ready = 1; + } + + PERM6464(K,K0,K1,(unsigned char *)key,PC1ROT); + key = (char *)&KS[0]; + STORE(K&~0x03030303L, K0&~0x03030303L, K1, *(C_block *)key); + for (i = 1; i < 16; i++) { + key += sizeof(C_block); + STORE(K,K0,K1,*(C_block *)key); + ptabp = PC2ROT[Rotates[i]-1]; + PERM6464(K,K0,K1,(unsigned char *)key,ptabp); + STORE(K&~0x03030303L, K0&~0x03030303L, K1, *(C_block *)key); + } + return (0); +} + +/* + * Encrypt (or decrypt if num_iter < 0) the 8 chars at "in" with abs(num_iter) + * iterations of DES, using the the given 24-bit salt and the pre-computed key + * schedule, and store the resulting 8 chars at "out" (in == out is permitted). + * + * NOTE: the performance of this routine is critically dependent on your + * compiler and machine architecture. + */ +STATIC int des_cipher(in, out, salt, num_iter) + const char *in; + char *out; + long salt; + int num_iter; +{ + /* variables that we want in registers, most important first */ +#if defined(pdp11) + register int j; +#endif + register long L0, L1, R0, R1, k; + register C_block *kp; + register int ks_inc, loop_count; + C_block B; + + L0 = salt; + TO_SIX_BIT(salt, L0); /* convert to 4*(6+2) format */ + +#if defined(vax) || defined(pdp11) + salt = ~salt; /* "x &~ y" is faster than "x & y". */ +#define SALT (~salt) +#else +#define SALT salt +#endif + +#if defined(MUST_ALIGN) + B.b[0] = in[0]; B.b[1] = in[1]; B.b[2] = in[2]; B.b[3] = in[3]; + B.b[4] = in[4]; B.b[5] = in[5]; B.b[6] = in[6]; B.b[7] = in[7]; + LOAD(L,L0,L1,B); +#else + LOAD(L,L0,L1,*(C_block *)in); +#endif + LOADREG(R,R0,R1,L,L0,L1); + L0 &= 0x55555555L; + L1 &= 0x55555555L; + L0 = (L0 << 1) | L1; /* L0 is the even-numbered input bits */ + R0 &= 0xaaaaaaaaL; + R1 = (R1 >> 1) & 0x55555555L; + L1 = R0 | R1; /* L1 is the odd-numbered input bits */ + STORE(L,L0,L1,B); + PERM3264(L,L0,L1,B.b,IE3264); /* even bits */ + PERM3264(R,R0,R1,B.b+4,IE3264); /* odd bits */ + + if (num_iter >= 0) + { /* encryption */ + kp = &KS[0]; + ks_inc = sizeof(*kp); + } + else + { /* decryption */ + num_iter = -num_iter; + kp = &KS[KS_SIZE-1]; + ks_inc = -sizeof(*kp); + } + + while (--num_iter >= 0) { + loop_count = 8; + do { + +#define SPTAB(t, i) (*(long *)((unsigned char *)t + i*(sizeof(long)/4))) +#if defined(gould) + /* use this if B.b[i] is evaluated just once ... */ +#define DOXOR(x,y,i) x^=SPTAB(&SPE[i * 64],B.b[i]); y^=SPTAB(&SPE[(8 * 64) + (i * 64)],B.b[i]); +#else +#if defined(pdp11) + /* use this if your "long" int indexing is slow */ +#define DOXOR(x,y,i) j=B.b[i]; x^=SPTAB(&SPE[i * 64],j); y^=SPTAB(&SPE[(8 * 64) + (i * 64)],j); +#else + /* use this if "k" is allocated to a register ... */ +#define DOXOR(x,y,i) k=B.b[i]; x^=SPTAB(&SPE[i * 64],k); y^=SPTAB(&SPE[(8 * 64) + (i * 64)],k); +#endif +#endif + +#define CRUNCH(p0, p1, q0, q1) \ + k = (q0 ^ q1) & SALT; \ + B.b32.i0 = k ^ q0 ^ kp->b32.i0; \ + B.b32.i1 = k ^ q1 ^ kp->b32.i1; \ + kp = (C_block *)((char *)kp+ks_inc); \ + \ + DOXOR(p0, p1, 0); \ + DOXOR(p0, p1, 1); \ + DOXOR(p0, p1, 2); \ + DOXOR(p0, p1, 3); \ + DOXOR(p0, p1, 4); \ + DOXOR(p0, p1, 5); \ + DOXOR(p0, p1, 6); \ + DOXOR(p0, p1, 7); + + CRUNCH(L0, L1, R0, R1); + CRUNCH(R0, R1, L0, L1); + } while (--loop_count != 0); + kp = (C_block *)((char *)kp-(ks_inc*KS_SIZE)); + + + /* swap L and R */ + L0 ^= R0; L1 ^= R1; + R0 ^= L0; R1 ^= L1; + L0 ^= R0; L1 ^= R1; + } + + /* store the encrypted (or decrypted) result */ + L0 = ((L0 >> 3) & 0x0f0f0f0fL) | ((L1 << 1) & 0xf0f0f0f0L); + L1 = ((R0 >> 3) & 0x0f0f0f0fL) | ((R1 << 1) & 0xf0f0f0f0L); + STORE(L,L0,L1,B); + PERM6464(L,L0,L1,B.b,CF6464); +#if defined(MUST_ALIGN) + STORE(L,L0,L1,B); + out[0] = B.b[0]; out[1] = B.b[1]; out[2] = B.b[2]; out[3] = B.b[3]; + out[4] = B.b[4]; out[5] = B.b[5]; out[6] = B.b[6]; out[7] = B.b[7]; +#else + STORE(L,L0,L1,*(C_block *)out); +#endif + return (0); +} + + +/* + * Initialize various tables. This need only be done once. It could even be + * done at compile time, if the compiler were capable of that sort of thing. + */ +STATIC void init_des() +{ + register int i, j; + register long k; + register int tableno; + static unsigned char perm[64], tmp32[32]; /* "static" for speed */ + + /* + * table that converts chars "./0-9A-Za-z"to integers 0-63. + */ + for (i = 0; i < 64; i++) + a64toi[itoa64[i]] = i; + + /* + * PC1ROT - bit reverse, then PC1, then Rotate, then PC2. + */ + for (i = 0; i < 64; i++) + perm[i] = 0; + for (i = 0; i < 64; i++) { + if ((k = PC2[i]) == 0) + continue; + k += Rotates[0]-1; + if ((k%28) < Rotates[0]) k -= 28; + k = PC1[k]; + if (k > 0) { + k--; + k = (k|07) - (k&07); + k++; + } + perm[i] = k; + } +#ifdef DEBUG + prtab("pc1tab", perm, 8); +#endif + PC1ROT = (C_block *)calloc(sizeof(C_block), (64/CHUNKBITS) * (1< 32) + k -= 32; + else if (k > 0) + k--; + if (k > 0) { + k--; + k = (k|07) - (k&07); + k++; + } + perm[i*8+j] = k; + } + } +#ifdef DEBUG + prtab("ietab", perm, 8); +#endif + IE3264 = (C_block *)calloc(sizeof(C_block), (32/CHUNKBITS) * (1< 0) { + k--; + k = (k|07) - (k&07); + k++; + } + perm[k-1] = i+1; + } +#ifdef DEBUG + prtab("cftab", perm, 8); +#endif + CF6464 = (C_block *)calloc(sizeof(C_block), (64/CHUNKBITS) * (1<> 0) &01) << 5)| + (((j >> 1) &01) << 3)| + (((j >> 2) &01) << 2)| + (((j >> 3) &01) << 1)| + (((j >> 4) &01) << 0)| + (((j >> 5) &01) << 4); + k = S[tableno][k]; + k = (((k >> 3)&01) << 0)| + (((k >> 2)&01) << 1)| + (((k >> 1)&01) << 2)| + (((k >> 0)&01) << 3); + for (i = 0; i < 32; i++) + tmp32[i] = 0; + for (i = 0; i < 4; i++) + tmp32[4 * tableno + i] = (k >> i) & 01; + k = 0; + for (i = 24; --i >= 0; ) + k = (k<<1) | tmp32[perm[i]-1]; + TO_SIX_BIT(SPE[(tableno * 64) + j], k); + k = 0; + for (i = 24; --i >= 0; ) + k = (k<<1) | tmp32[perm[i+24]-1]; + TO_SIX_BIT(SPE[(8 * 64) + (tableno * 64) + j], k); + } + } +} + +/* + * Initialize "perm" to represent transformation "p", which rearranges + * (perhaps with expansion and/or contraction) one packed array of bits + * (of size "chars_in" characters) into another array (of size "chars_out" + * characters). + * + * "perm" must be all-zeroes on entry to this routine. + */ +STATIC void init_perm(perm, p, chars_in, chars_out) + C_block *perm; + unsigned char p[64]; + int chars_in, chars_out; +{ + register int i, j, k, l; + + for (k = 0; k < chars_out*8; k++) { /* each output bit position */ + l = p[k] - 1; /* where this bit comes from */ + if (l < 0) + continue; /* output bit is always 0 */ + i = l>>LGCHUNKBITS; /* which chunk this bit comes from */ + l = 1<<(l&(CHUNKBITS-1)); /* mask for this bit */ + for (j = 0; j < (1<>3] |= 1<<(k&07); + } + } +} + +/* + * "setkey" routine (for backwards compatibility) + */ +int setkey(key) + register const char *key; +{ + register int i, j, k; + C_block keyblock; + + for (i = 0; i < 8; i++) { + k = 0; + for (j = 0; j < 8; j++) { + k <<= 1; + k |= (unsigned char)*key++; + } + keyblock.b[i] = k; + } + return (des_setkey((char *)keyblock.b)); +} + +/* + * "encrypt" routine (for backwards compatibility) + */ +int encrypt(block, flag) + register char *block; + int flag; +{ + register int i, j, k; + C_block cblock; + + for (i = 0; i < 8; i++) { + k = 0; + for (j = 0; j < 8; j++) { + k <<= 1; + k |= (unsigned char)*block++; + } + cblock.b[i] = k; + } + if (des_cipher((char *)&cblock, (char *)&cblock, 0L, (flag ? -1: 1))) + return (1); + for (i = 7; i >= 0; i--) { + k = cblock.b[i]; + for (j = 7; j >= 0; j--) { + *--block = k&01; + k >>= 1; + } + } + return (0); +} + +#ifdef DEBUG +STATIC +prtab(s, t, num_rows) + char *s; + unsigned char *t; + int num_rows; +{ + register int i, j; + + (void)printf("%s:\n", s); + for (i = 0; i < num_rows; i++) { + for (j = 0; j < 8; j++) { + (void)printf("%3d", t[i*8+j]); + } + (void)printf("\n"); + } + (void)printf("\n"); +} +#endif diff --git a/gen/ctermid.3 b/gen/ctermid.3 new file mode 100644 index 0000000..8206dcd --- /dev/null +++ b/gen/ctermid.3 @@ -0,0 +1,109 @@ +.\" Copyright (c) 1990, 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. +.\" +.\" @(#)ctermid.3 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD: src/lib/libc/gen/ctermid.3,v 1.8 2001/10/01 16:08:50 ru Exp $ +.\" +.Dd June 4, 1993 +.Dt CTERMID 3 +.Os +.Sh NAME +.Nm ctermid +.Nd generate terminal pathname +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In stdio.h +.Ft char * +.Fn ctermid "char *buf" +.Ft char * +.Fn ctermid_r "char *buf" +.Sh DESCRIPTION +The +.Fn ctermid +function generates a string, that, when used as a pathname, refers to +the current controlling terminal of the calling process. +.Pp +If +.Ar buf +is the +.Dv NULL +pointer, a pointer to a static area is returned. +Otherwise, the pathname is copied into the memory referenced by +.Ar buf . +The argument +.Ar buf +is assumed to be at least +.Dv L_ctermid +(as defined in the include +file +.Aq Pa stdio.h ) +bytes long. +.Pp +.Fn ctermid_r +provides the same functionality as +.Fn ctermid +except that if +.Ar buf +is a +.Dv NULL +pointer, +.Dv NULL +is returned. +.Pp +The current implementation simply returns +.Ql /dev/tty . +.Sh RETURN VALUES +Upon successful completion, a +.Pf non- Dv NULL +pointer is returned. +Otherwise, a +.Dv NULL +pointer is returned and the global variable +.Va errno +is set to indicate the error. +.Sh ERRORS +The current implementation detects no error conditions. +.Sh SEE ALSO +.Xr ttyname 3 +.Sh STANDARDS +The +.Fn ctermid +function conforms to +.St -p1003.1-88 . +.Sh BUGS +By default the +.Fn ctermid +function +writes all information to an internal static object. +Subsequent calls to +.Fn ctermid +will modify the same object. diff --git a/gen/ctermid.c b/gen/ctermid.c new file mode 100644 index 0000000..507c9cf --- /dev/null +++ b/gen/ctermid.c @@ -0,0 +1,71 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 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 +#include +#include + +char * +ctermid(s) + char *s; +{ + static char def[] = _PATH_TTY; + + if (s) { + bcopy(def, s, sizeof(_PATH_TTY)); + return(s); + } + return(def); +} diff --git a/gen/ctime.c b/gen/ctime.c new file mode 100644 index 0000000..d8b0656 --- /dev/null +++ b/gen/ctime.c @@ -0,0 +1,1399 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1987, 1989, 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. + */ + + +/* +** Leap second handling from Bradley White (bww@k.gp.cs.cmu.edu). +** POSIX-style TZ environment variable handling from Guy Harris +** (guy@auspex.com). +*/ + +/*LINTLIBRARY*/ + +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef __STDC__ +#include + +#define P(s) s +#define alloc_size_t size_t +#define qsort_size_t size_t +#define fread_size_t size_t +#define fwrite_size_t size_t + +#else /* !defined __STDC__ */ + +#define P(s) () + +typedef char * genericptr_t; +typedef unsigned alloc_size_t; +typedef int qsort_size_t; +typedef int fread_size_t; +typedef int fwrite_size_t; + +extern char * calloc(); +extern char * malloc(); +extern char * realloc(); +extern char * getenv(); + +#endif /* !defined __STDC__ */ + +extern time_t time(); + +#define ACCESS_MODE O_RDONLY +#define OPEN_MODE O_RDONLY + +#ifndef WILDABBR +/* +** Someone might make incorrect use of a time zone abbreviation: +** 1. They might reference tzname[0] before calling tzset (explicitly +** or implicitly). +** 2. They might reference tzname[1] before calling tzset (explicitly +** or implicitly). +** 3. They might reference tzname[1] after setting to a time zone +** in which Daylight Saving Time is never observed. +** 4. They might reference tzname[0] after setting to a time zone +** in which Standard Time is never observed. +** 5. They might reference tm.TM_ZONE after calling offtime. +** What's best to do in the above cases is open to debate; +** for now, we just set things up so that in any of the five cases +** WILDABBR is used. Another possibility: initialize tzname[0] to the +** string "tzname[0] used before set", and similarly for the other cases. +** And another: initialize tzname[0] to "ERA", with an explanation in the +** manual page of what this "time zone abbreviation" means (doing this so +** that tzname[0] has the "normal" length of three characters). +*/ +#define WILDABBR " " +#endif /* !defined WILDABBR */ + +#ifndef TRUE +#define TRUE 1 +#define FALSE 0 +#endif /* !defined TRUE */ + +static const char GMT[] = "GMT"; + +struct ttinfo { /* time type information */ + long tt_gmtoff; /* GMT 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 */ +}; + +struct lsinfo { /* leap second information */ + time_t ls_trans; /* transition time */ + long ls_corr; /* correction to apply */ +}; + +struct state { + int leapcnt; + int timecnt; + int typecnt; + int charcnt; + time_t ats[TZ_MAX_TIMES]; + unsigned char types[TZ_MAX_TIMES]; + struct ttinfo ttis[TZ_MAX_TYPES]; + char chars[(TZ_MAX_CHARS + 1 > sizeof GMT) ? + TZ_MAX_CHARS + 1 : sizeof GMT]; + struct lsinfo lsis[TZ_MAX_LEAPS]; +}; + +struct rule { + int r_type; /* type of rule--see below */ + int r_day; /* day number of rule */ + int r_week; /* week number of rule */ + int r_mon; /* month number of rule */ + long r_time; /* transition time of rule */ +}; + +#define JULIAN_DAY 0 /* Jn - Julian day */ +#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. +*/ + +static long detzcode P((const char * codep)); +static const char * getzname P((const char * strp)); +static const char * getnum P((const char * strp, int * nump, int min, + int max)); +static const char * getsecs P((const char * strp, long * secsp)); +static const char * getoffset P((const char * strp, long * offsetp)); +static const char * getrule P((const char * strp, struct rule * rulep)); +static void gmtload P((struct state * sp)); +static void gmtsub P((const time_t * timep, long offset, + struct tm * tmp)); +static void localsub P((const time_t * timep, long offset, + struct tm * tmp)); +static void normalize P((int * tensptr, int * unitsptr, int base)); +static void settzname P((void)); +static time_t time1 P((struct tm * tmp, void (* funcp)(), + long offset)); +static time_t time2 P((struct tm *tmp, void (* funcp)(), + long offset, int * okayp)); +static void timesub P((const time_t * timep, long offset, + const struct state * sp, struct tm * tmp)); +static int tmcomp P((const struct tm * atmp, + const struct tm * btmp)); +static time_t transtime P((time_t janfirst, int year, + const struct rule * rulep, long offset)); +static int tzload P((const char * name, struct state * sp)); +static int tzparse P((const char * name, struct state * sp, + int lastditch)); + +#ifdef ALL_STATE +static struct state * lclptr; +static struct state * gmtptr; +#endif /* defined ALL_STATE */ + +#ifndef ALL_STATE +static struct state lclmem; +static struct state gmtmem; +#define lclptr (&lclmem) +#define gmtptr (&gmtmem) +#endif /* State Farm */ + +static int lcl_is_set; +static int gmt_is_set; + +char * tzname[2] = { + WILDABBR, + WILDABBR +}; + +#ifdef USG_COMPAT +time_t timezone = 0; +int daylight = 0; +#endif /* defined USG_COMPAT */ + +#ifdef ALTZONE +time_t altzone = 0; +#endif /* defined ALTZONE */ + +static long +detzcode(codep) +const char * const codep; +{ + register long result; + register int i; + + result = 0; + for (i = 0; i < 4; ++i) + result = (result << 8) | (codep[i] & 0xff); + return result; +} + +static void +settzname() +{ + register const struct state * const sp = lclptr; + register int i; + + tzname[0] = WILDABBR; + tzname[1] = WILDABBR; +#ifdef USG_COMPAT + daylight = 0; + timezone = 0; +#endif /* defined USG_COMPAT */ +#ifdef ALTZONE + altzone = 0; +#endif /* defined ALTZONE */ +#ifdef ALL_STATE + if (sp == NULL) { + tzname[0] = tzname[1] = GMT; + return; + } +#endif /* defined ALL_STATE */ + for (i = 0; i < sp->typecnt; ++i) { + register const struct ttinfo * const ttisp = &sp->ttis[i]; + + tzname[ttisp->tt_isdst] = + (char *) &sp->chars[ttisp->tt_abbrind]; +#ifdef USG_COMPAT + if (ttisp->tt_isdst) + daylight = 1; + if (i == 0 || !ttisp->tt_isdst) + timezone = -(ttisp->tt_gmtoff); +#endif /* defined USG_COMPAT */ +#ifdef ALTZONE + if (i == 0 || ttisp->tt_isdst) + altzone = -(ttisp->tt_gmtoff); +#endif /* defined ALTZONE */ + } + /* + ** And to get the latest zone names into tzname. . . + */ + for (i = 0; i < sp->timecnt; ++i) { + register const struct ttinfo * const ttisp = + &sp->ttis[sp->types[i]]; + + tzname[ttisp->tt_isdst] = + (char *) &sp->chars[ttisp->tt_abbrind]; + } +} + +static int +tzload(name, sp) +register const char * name; +register struct state * const sp; +{ + register const char * p; + register int i; + register int fid; + + if (name == NULL && (name = TZDEFAULT) == NULL) + return -1; + { + char fullname[FILENAME_MAX + 1]; + + if (name[0] == ':') + ++name; + if (name[0] != '/') { + if ((p = TZDIR) == NULL) + return -1; + if ((strlen(p) + strlen(name) + 1) >= sizeof fullname) + return -1; + (void) strcpy(fullname, p); + (void) strcat(fullname, "/"); + (void) strcat(fullname, name); + name = fullname; + } + if ((fid = open(name, OPEN_MODE)) == -1) + return -1; + } + { + register const struct tzhead * tzhp; + char buf[sizeof *sp + sizeof *tzhp]; + int ttisstdcnt; + + i = read(fid, buf, sizeof buf); + if (close(fid) != 0 || i < sizeof *tzhp) + return -1; + tzhp = (struct tzhead *) buf; + ttisstdcnt = (int) detzcode(tzhp->tzh_ttisstdcnt); + sp->leapcnt = (int) detzcode(tzhp->tzh_leapcnt); + sp->timecnt = (int) detzcode(tzhp->tzh_timecnt); + sp->typecnt = (int) detzcode(tzhp->tzh_typecnt); + sp->charcnt = (int) detzcode(tzhp->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 || + sp->charcnt < 0 || sp->charcnt > TZ_MAX_CHARS || + (ttisstdcnt != sp->typecnt && ttisstdcnt != 0)) + return -1; + if (i < sizeof *tzhp + + sp->timecnt * (4 + sizeof (char)) + + sp->typecnt * (4 + 2 * sizeof (char)) + + sp->charcnt * sizeof (char) + + sp->leapcnt * 2 * 4 + + ttisstdcnt * sizeof (char)) + return -1; + p = buf + sizeof *tzhp; + for (i = 0; i < sp->timecnt; ++i) { + sp->ats[i] = detzcode(p); + p += 4; + } + for (i = 0; i < sp->timecnt; ++i) { + sp->types[i] = (unsigned char) *p++; + if (sp->types[i] >= sp->typecnt) + return -1; + } + for (i = 0; i < sp->typecnt; ++i) { + register struct ttinfo * ttisp; + + ttisp = &sp->ttis[i]; + ttisp->tt_gmtoff = detzcode(p); + p += 4; + ttisp->tt_isdst = (unsigned char) *p++; + if (ttisp->tt_isdst != 0 && ttisp->tt_isdst != 1) + return -1; + ttisp->tt_abbrind = (unsigned char) *p++; + if (ttisp->tt_abbrind < 0 || + ttisp->tt_abbrind > sp->charcnt) + return -1; + } + for (i = 0; i < sp->charcnt; ++i) + sp->chars[i] = *p++; + sp->chars[i] = '\0'; /* ensure '\0' at end */ + for (i = 0; i < sp->leapcnt; ++i) { + register struct lsinfo * lsisp; + + lsisp = &sp->lsis[i]; + lsisp->ls_trans = detzcode(p); + p += 4; + lsisp->ls_corr = detzcode(p); + p += 4; + } + for (i = 0; i < sp->typecnt; ++i) { + register struct ttinfo * ttisp; + + ttisp = &sp->ttis[i]; + if (ttisstdcnt == 0) + ttisp->tt_ttisstd = FALSE; + else { + ttisp->tt_ttisstd = *p++; + if (ttisp->tt_ttisstd != TRUE && + ttisp->tt_ttisstd != FALSE) + return -1; + } + } + } + return 0; +} + +static const int mon_lengths[2][MONSPERYEAR] = { + 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, + 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 +}; + +static const int year_lengths[2] = { + DAYSPERNYEAR, DAYSPERLYEAR +}; + +/* +** Given a pointer into a time zone string, scan until a character that is not +** a valid character in a zone name is found. Return a pointer to that +** character. +*/ + +static const char * +getzname(strp) +register const char * strp; +{ + register char c; + + while ((c = *strp) != '\0' && !isdigit(c) && c != ',' && c != '-' && + c != '+') + ++strp; + return strp; +} + +/* +** Given a pointer into a time zone string, extract a number from that string. +** Check that the number is within a specified range; if it is not, return +** NULL. +** Otherwise, return a pointer to the first character not part of the number. +*/ + +static const char * +getnum(strp, nump, min, max) +register const char * strp; +int * const nump; +const int min; +const int max; +{ + register char c; + register int num; + + if (strp == NULL || !isdigit(*strp)) + return NULL; + num = 0; + while ((c = *strp) != '\0' && isdigit(c)) { + num = num * 10 + (c - '0'); + if (num > max) + return NULL; /* illegal value */ + ++strp; + } + if (num < min) + return NULL; /* illegal value */ + *nump = num; + return strp; +} + +/* +** Given a pointer into a time zone string, extract a number of seconds, +** in hh[:mm[:ss]] form, from the string. +** If any error occurs, return NULL. +** Otherwise, return a pointer to the first character not part of the number +** of seconds. +*/ + +static const char * +getsecs(strp, secsp) +register const char * strp; +long * const secsp; +{ + int num; + + strp = getnum(strp, &num, 0, HOURSPERDAY); + if (strp == NULL) + return NULL; + *secsp = num * SECSPERHOUR; + if (*strp == ':') { + ++strp; + strp = getnum(strp, &num, 0, MINSPERHOUR - 1); + if (strp == NULL) + return NULL; + *secsp += num * SECSPERMIN; + if (*strp == ':') { + ++strp; + strp = getnum(strp, &num, 0, SECSPERMIN - 1); + if (strp == NULL) + return NULL; + *secsp += num; + } + } + return strp; +} + +/* +** Given a pointer into a time zone string, extract an offset, in +** [+-]hh[:mm[:ss]] form, from the string. +** If any error occurs, return NULL. +** Otherwise, return a pointer to the first character not part of the time. +*/ + +static const char * +getoffset(strp, offsetp) +register const char * strp; +long * const offsetp; +{ + register int neg; + + if (*strp == '-') { + neg = 1; + ++strp; + } else if (isdigit(*strp) || *strp++ == '+') + neg = 0; + else return NULL; /* illegal offset */ + strp = getsecs(strp, offsetp); + if (strp == NULL) + return NULL; /* illegal time */ + if (neg) + *offsetp = -*offsetp; + return strp; +} + +/* +** Given a pointer into a time zone string, extract a rule in the form +** date[/time]. See POSIX section 8 for the format of "date" and "time". +** If a valid rule is not found, return NULL. +** Otherwise, return a pointer to the first character not part of the rule. +*/ + +static const char * +getrule(strp, rulep) +const char * strp; +register struct rule * const rulep; +{ + if (*strp == 'J') { + /* + ** Julian day. + */ + rulep->r_type = JULIAN_DAY; + ++strp; + strp = getnum(strp, &rulep->r_day, 1, DAYSPERNYEAR); + } else if (*strp == 'M') { + /* + ** Month, week, day. + */ + rulep->r_type = MONTH_NTH_DAY_OF_WEEK; + ++strp; + strp = getnum(strp, &rulep->r_mon, 1, MONSPERYEAR); + if (strp == NULL) + return NULL; + if (*strp++ != '.') + return NULL; + strp = getnum(strp, &rulep->r_week, 1, 5); + if (strp == NULL) + return NULL; + if (*strp++ != '.') + return NULL; + strp = getnum(strp, &rulep->r_day, 0, DAYSPERWEEK - 1); + } else if (isdigit(*strp)) { + /* + ** Day of year. + */ + rulep->r_type = DAY_OF_YEAR; + strp = getnum(strp, &rulep->r_day, 0, DAYSPERLYEAR - 1); + } else return NULL; /* invalid format */ + if (strp == NULL) + return NULL; + if (*strp == '/') { + /* + ** Time specified. + */ + ++strp; + strp = getsecs(strp, &rulep->r_time); + } else rulep->r_time = 2 * SECSPERHOUR; /* default = 2:00:00 */ + return strp; +} + +/* +** 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, +** calculate the Epoch-relative time that rule takes effect. +*/ + +static time_t +transtime(janfirst, year, rulep, offset) +const time_t janfirst; +const int year; +register const struct rule * const rulep; +const long offset; +{ + register int leapyear; + register time_t value; + register int i; + int d, m1, yy0, yy1, yy2, dow; + + leapyear = isleap(year); + switch (rulep->r_type) { + + case JULIAN_DAY: + /* + ** Jn - Julian day, 1 == January 1, 60 == March 1 even in leap + ** years. + ** In non-leap years, or if the day number is 59 or less, just + ** add SECSPERDAY times the day number-1 to the time of + ** January 1, midnight, to get the day. + */ + value = janfirst + (rulep->r_day - 1) * SECSPERDAY; + if (leapyear && rulep->r_day >= 60) + value += SECSPERDAY; + break; + + case DAY_OF_YEAR: + /* + ** n - day of year. + ** Just add SECSPERDAY times the day number to the time of + ** January 1, midnight, to get the day. + */ + value = janfirst + rulep->r_day * SECSPERDAY; + break; + + case MONTH_NTH_DAY_OF_WEEK: + /* + ** Mm.n.d - nth "dth day" of month m. + */ + value = janfirst; + for (i = 0; i < rulep->r_mon - 1; ++i) + value += mon_lengths[leapyear][i] * SECSPERDAY; + + /* + ** Use Zeller's Congruence to get day-of-week of first day of + ** month. + */ + m1 = (rulep->r_mon + 9) % 12 + 1; + yy0 = (rulep->r_mon <= 2) ? (year - 1) : year; + yy1 = yy0 / 100; + yy2 = yy0 % 100; + dow = ((26 * m1 - 2) / 10 + + 1 + yy2 + yy2 / 4 + yy1 / 4 - 2 * yy1) % 7; + if (dow < 0) + dow += DAYSPERWEEK; + + /* + ** "dow" is the day-of-week of the first day of the month. Get + ** the day-of-month (zero-origin) of the first "dow" day of the + ** month. + */ + d = rulep->r_day - dow; + if (d < 0) + d += DAYSPERWEEK; + for (i = 1; i < rulep->r_week; ++i) { + if (d + DAYSPERWEEK >= + mon_lengths[leapyear][rulep->r_mon - 1]) + break; + d += DAYSPERWEEK; + } + + /* + ** "d" is the day-of-month (zero-origin) of the day we want. + */ + value += d * SECSPERDAY; + break; + } + + /* + ** "value" is the Epoch-relative time of 00:00:00 GMT 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. + */ + return value + rulep->r_time + offset; +} + +/* +** Given a POSIX section 8-style TZ string, fill in the rule tables as +** appropriate. +*/ + +static int +tzparse(name, sp, lastditch) +const char * name; +register struct state * const sp; +const int lastditch; +{ + const char * stdname; + const char * dstname; + int stdlen; + int dstlen; + long stdoffset; + long dstoffset; + register time_t * atp; + register unsigned char * typep; + register char * cp; + register int load_result; + + stdname = name; + if (lastditch) { + stdlen = strlen(name); /* length of standard zone name */ + name += stdlen; + if (stdlen >= sizeof sp->chars) + stdlen = (sizeof sp->chars) - 1; + } else { + name = getzname(name); + stdlen = name - stdname; + if (stdlen < 3) + return -1; + } + if (*name == '\0') + return -1; + else { + name = getoffset(name, &stdoffset); + if (name == NULL) + return -1; + } + load_result = tzload(TZDEFRULES, sp); + if (load_result != 0) + sp->leapcnt = 0; /* so, we're off a little */ + if (*name != '\0') { + dstname = name; + name = getzname(name); + dstlen = name - dstname; /* length of DST zone name */ + if (dstlen < 3) + return -1; + if (*name != '\0' && *name != ',' && *name != ';') { + name = getoffset(name, &dstoffset); + if (name == NULL) + return -1; + } else dstoffset = stdoffset - SECSPERHOUR; + if (*name == ',' || *name == ';') { + struct rule start; + struct rule end; + register int year; + register time_t janfirst; + time_t starttime; + time_t endtime; + + ++name; + if ((name = getrule(name, &start)) == NULL) + return -1; + if (*name++ != ',') + return -1; + if ((name = getrule(name, &end)) == NULL) + return -1; + if (*name != '\0') + return -1; + sp->typecnt = 2; /* standard time and DST */ + /* + ** Two transitions per year, from EPOCH_YEAR to 2037. + */ + sp->timecnt = 2 * (2037 - EPOCH_YEAR + 1); + if (sp->timecnt > TZ_MAX_TIMES) + return -1; + sp->ttis[0].tt_gmtoff = -dstoffset; + sp->ttis[0].tt_isdst = 1; + sp->ttis[0].tt_abbrind = stdlen + 1; + sp->ttis[1].tt_gmtoff = -stdoffset; + sp->ttis[1].tt_isdst = 0; + sp->ttis[1].tt_abbrind = 0; + atp = sp->ats; + typep = sp->types; + janfirst = 0; + for (year = EPOCH_YEAR; year <= 2037; ++year) { + starttime = transtime(janfirst, year, &start, + stdoffset); + endtime = transtime(janfirst, year, &end, + dstoffset); + if (starttime > endtime) { + *atp++ = endtime; + *typep++ = 1; /* DST ends */ + *atp++ = starttime; + *typep++ = 0; /* DST begins */ + } else { + *atp++ = starttime; + *typep++ = 0; /* DST begins */ + *atp++ = endtime; + *typep++ = 1; /* DST ends */ + } + janfirst += + year_lengths[isleap(year)] * SECSPERDAY; + } + } else { + int sawstd; + int sawdst; + long stdfix; + long dstfix; + long oldfix; + int isdst; + register int i; + + if (*name != '\0') + return -1; + if (load_result != 0) + return -1; + /* + ** Compute the difference between the real and + ** prototype standard and summer time offsets + ** from GMT, and put the real standard and summer + ** time offsets into the rules in place of the + ** prototype offsets. + */ + sawstd = FALSE; + sawdst = FALSE; + stdfix = 0; + dstfix = 0; + for (i = 0; i < sp->typecnt; ++i) { + if (sp->ttis[i].tt_isdst) { + oldfix = dstfix; + dstfix = + sp->ttis[i].tt_gmtoff + dstoffset; + if (sawdst && (oldfix != dstfix)) + return -1; + sp->ttis[i].tt_gmtoff = -dstoffset; + sp->ttis[i].tt_abbrind = stdlen + 1; + sawdst = TRUE; + } else { + oldfix = stdfix; + stdfix = + sp->ttis[i].tt_gmtoff + stdoffset; + if (sawstd && (oldfix != stdfix)) + return -1; + sp->ttis[i].tt_gmtoff = -stdoffset; + sp->ttis[i].tt_abbrind = 0; + sawstd = TRUE; + } + } + /* + ** Make sure we have both standard and summer time. + */ + if (!sawdst || !sawstd) + return -1; + /* + ** Now correct the transition times by shifting + ** them by the difference between the real and + ** prototype offsets. Note that this difference + ** can be different in standard and summer time; + ** the prototype probably has a 1-hour difference + ** between standard and summer time, but a different + ** difference can be specified in TZ. + */ + isdst = FALSE; /* we start in standard time */ + for (i = 0; i < sp->timecnt; ++i) { + register const struct ttinfo * ttisp; + + /* + ** If summer time is in effect, and the + ** transition time was not specified as + ** standard time, add the summer time + ** offset to the transition time; + ** otherwise, add the standard time offset + ** to the transition time. + */ + ttisp = &sp->ttis[sp->types[i]]; + sp->ats[i] += + (isdst && !ttisp->tt_ttisstd) ? + dstfix : stdfix; + isdst = ttisp->tt_isdst; + } + } + } else { + dstlen = 0; + sp->typecnt = 1; /* only standard time */ + sp->timecnt = 0; + sp->ttis[0].tt_gmtoff = -stdoffset; + sp->ttis[0].tt_isdst = 0; + sp->ttis[0].tt_abbrind = 0; + } + sp->charcnt = stdlen + 1; + if (dstlen != 0) + sp->charcnt += dstlen + 1; + if (sp->charcnt > sizeof sp->chars) + return -1; + cp = sp->chars; + (void) strncpy(cp, stdname, stdlen); + cp += stdlen; + *cp++ = '\0'; + if (dstlen != 0) { + (void) strncpy(cp, dstname, dstlen); + *(cp + dstlen) = '\0'; + } + return 0; +} + +static void +gmtload(sp) +struct state * const sp; +{ + if (tzload(GMT, sp) != 0) + (void) tzparse(GMT, sp, TRUE); +} + +void +tzset() +{ + register const char * name; + void tzsetwall(); + + name = getenv("TZ"); + if (name == NULL) { + tzsetwall(); + return; + } + lcl_is_set = TRUE; +#ifdef ALL_STATE + if (lclptr == NULL) { + lclptr = (struct state *) malloc(sizeof *lclptr); + if (lclptr == NULL) { + settzname(); /* all we can do */ + return; + } + } +#endif /* defined ALL_STATE */ + if (*name == '\0') { + /* + ** User wants it fast rather than right. + */ + lclptr->leapcnt = 0; /* so, we're off a little */ + lclptr->timecnt = 0; + lclptr->ttis[0].tt_gmtoff = 0; + lclptr->ttis[0].tt_abbrind = 0; + (void) strcpy(lclptr->chars, GMT); + } else if (tzload(name, lclptr) != 0) + if (name[0] == ':' || tzparse(name, lclptr, FALSE) != 0) + (void) gmtload(lclptr); + settzname(); +} + +void +tzsetwall() +{ + lcl_is_set = TRUE; +#ifdef ALL_STATE + if (lclptr == NULL) { + lclptr = (struct state *) malloc(sizeof *lclptr); + if (lclptr == NULL) { + settzname(); /* all we can do */ + return; + } + } +#endif /* defined ALL_STATE */ + if (tzload((char *) NULL, lclptr) != 0) + gmtload(lclptr); + settzname(); +} + +/* +** The easy way to behave "as if no library function calls" localtime +** is to not call it--so we drop its guts into "localsub", which can be +** freely called. (And no, the PANS doesn't require the above behavior-- +** but it *is* desirable.) +** +** The unused offset argument is for the benefit of mktime variants. +*/ + +/*ARGSUSED*/ +static void +localsub(timep, offset, tmp) +const time_t * const timep; +const long offset; +struct tm * const tmp; +{ + register struct state * sp; + register const struct ttinfo * ttisp; + register int i; + const time_t t = *timep; + + if (!lcl_is_set) + tzset(); + sp = lclptr; +#ifdef ALL_STATE + if (sp == NULL) { + gmtsub(timep, offset, tmp); + return; + } +#endif /* defined ALL_STATE */ + if (sp->timecnt == 0 || t < sp->ats[0]) { + i = 0; + while (sp->ttis[i].tt_isdst) + if (++i >= sp->typecnt) { + i = 0; + break; + } + } else { + for (i = 1; i < sp->timecnt; ++i) + if (t < sp->ats[i]) + break; + i = sp->types[i - 1]; + } + ttisp = &sp->ttis[i]; + /* + ** To get (wrong) behavior that's compatible with System V Release 2.0 + ** you'd replace the statement below with + ** t += ttisp->tt_gmtoff; + ** timesub(&t, 0L, sp, tmp); + */ + timesub(&t, ttisp->tt_gmtoff, sp, tmp); + tmp->tm_isdst = ttisp->tt_isdst; + tzname[tmp->tm_isdst] = (char *) &sp->chars[ttisp->tt_abbrind]; + tmp->tm_zone = &sp->chars[ttisp->tt_abbrind]; +} + +struct tm * +localtime(timep) +const time_t * const timep; +{ + static struct tm tm; + + localsub(timep, 0L, &tm); + return &tm; +} + +/* +** gmtsub is to gmtime as localsub is to localtime. +*/ + +static void +gmtsub(timep, offset, tmp) +const time_t * const timep; +const long offset; +struct tm * const tmp; +{ + if (!gmt_is_set) { + gmt_is_set = TRUE; +#ifdef ALL_STATE + gmtptr = (struct state *) malloc(sizeof *gmtptr); + if (gmtptr != NULL) +#endif /* defined ALL_STATE */ + gmtload(gmtptr); + } + timesub(timep, offset, gmtptr, tmp); + /* + ** Could get fancy here and deliver something such as + ** "GMT+xxxx" or "GMT-xxxx" if offset is non-zero, + ** but this is no time for a treasure hunt. + */ + if (offset != 0) + tmp->tm_zone = WILDABBR; + else { +#ifdef ALL_STATE + if (gmtptr == NULL) + tmp->TM_ZONE = GMT; + else tmp->TM_ZONE = gmtptr->chars; +#endif /* defined ALL_STATE */ +#ifndef ALL_STATE + tmp->tm_zone = gmtptr->chars; +#endif /* State Farm */ + } +} + +struct tm * +gmtime(timep) +const time_t * const timep; +{ + static struct tm tm; + + gmtsub(timep, 0L, &tm); + return &tm; +} + +static void +timesub(timep, offset, sp, tmp) +const time_t * const timep; +const long offset; +register const struct state * const sp; +register struct tm * const tmp; +{ + register const struct lsinfo * lp; + register long days; + register long rem; + register int y; + register int yleap; + register const int * ip; + register long corr; + register int hit; + register int i; + + corr = 0; + hit = FALSE; +#ifdef ALL_STATE + i = (sp == NULL) ? 0 : sp->leapcnt; +#endif /* defined ALL_STATE */ +#ifndef ALL_STATE + i = sp->leapcnt; +#endif /* State Farm */ + while (--i >= 0) { + lp = &sp->lsis[i]; + if (*timep >= lp->ls_trans) { + if (*timep == lp->ls_trans) + hit = ((i == 0 && lp->ls_corr > 0) || + lp->ls_corr > sp->lsis[i - 1].ls_corr); + corr = lp->ls_corr; + break; + } + } + days = *timep / SECSPERDAY; + rem = *timep % SECSPERDAY; +#ifdef mc68k + if (*timep == 0x80000000) { + /* + ** A 3B1 muffs the division on the most negative number. + */ + days = -24855; + rem = -11648; + } +#endif /* mc68k */ + rem += (offset - corr); + while (rem < 0) { + rem += SECSPERDAY; + --days; + } + while (rem >= SECSPERDAY) { + rem -= SECSPERDAY; + ++days; + } + tmp->tm_hour = (int) (rem / SECSPERHOUR); + rem = rem % SECSPERHOUR; + tmp->tm_min = (int) (rem / SECSPERMIN); + tmp->tm_sec = (int) (rem % SECSPERMIN); + if (hit) + /* + ** A positive leap second requires a special + ** representation. This uses "... ??:59:60". + */ + ++(tmp->tm_sec); + tmp->tm_wday = (int) ((EPOCH_WDAY + days) % DAYSPERWEEK); + if (tmp->tm_wday < 0) + tmp->tm_wday += DAYSPERWEEK; + y = EPOCH_YEAR; + if (days >= 0) + for ( ; ; ) { + yleap = isleap(y); + if (days < (long) year_lengths[yleap]) + break; + ++y; + days = days - (long) year_lengths[yleap]; + } + else do { + --y; + yleap = isleap(y); + days = days + (long) year_lengths[yleap]; + } while (days < 0); + tmp->tm_year = y - TM_YEAR_BASE; + tmp->tm_yday = (int) days; + ip = mon_lengths[yleap]; + for (tmp->tm_mon = 0; days >= (long) ip[tmp->tm_mon]; ++(tmp->tm_mon)) + days = days - (long) ip[tmp->tm_mon]; + tmp->tm_mday = (int) (days + 1); + tmp->tm_isdst = 0; + tmp->tm_gmtoff = offset; +} + +/* +** A la X3J11 +*/ + +char * +asctime(timeptr) +register const struct tm * timeptr; +{ + static const char wday_name[DAYSPERWEEK][3] = { + "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" + }; + static const char mon_name[MONSPERYEAR][3] = { + "Jan", "Feb", "Mar", "Apr", "May", "Jun", + "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" + }; + static char result[26]; + + (void) sprintf(result, "%.3s %.3s%3d %02.2d:%02.2d:%02.2d %d\n", + wday_name[timeptr->tm_wday], + mon_name[timeptr->tm_mon], + timeptr->tm_mday, timeptr->tm_hour, + timeptr->tm_min, timeptr->tm_sec, + TM_YEAR_BASE + timeptr->tm_year); + return result; +} + +char * +ctime(timep) +const time_t * const timep; +{ + return asctime(localtime(timep)); +} + +/* +** Adapted from code provided by Robert Elz, who writes: +** The "best" way to do mktime I think is based on an idea of Bob +** Kridle's (so its said...) from a long time ago. (mtxinu!kridle now). +** It does a binary search of the time_t space. Since time_t's are +** just 32 bits, its a max of 32 iterations (even at 64 bits it +** would still be very reasonable). +*/ + +#ifndef WRONG +#define WRONG (-1) +#endif /* !defined WRONG */ + +static void +normalize(tensptr, unitsptr, base) +int * const tensptr; +int * const unitsptr; +const int base; +{ + if (*unitsptr >= base) { + *tensptr += *unitsptr / base; + *unitsptr %= base; + } else if (*unitsptr < 0) { + *tensptr -= 1 + (-(*unitsptr + 1)) / base; + *unitsptr = base - 1 - (-(*unitsptr + 1)) % base; + } +} + +static int +tmcomp(atmp, btmp) +register const struct tm * const atmp; +register const struct tm * const btmp; +{ + register int result; + + if ((result = (atmp->tm_year - btmp->tm_year)) == 0 && + (result = (atmp->tm_mon - btmp->tm_mon)) == 0 && + (result = (atmp->tm_mday - btmp->tm_mday)) == 0 && + (result = (atmp->tm_hour - btmp->tm_hour)) == 0 && + (result = (atmp->tm_min - btmp->tm_min)) == 0) + result = atmp->tm_sec - btmp->tm_sec; + return result; +} + +static time_t +time2(tmp, funcp, offset, okayp) +struct tm * const tmp; +void (* const funcp)(); +const long offset; +int * const okayp; +{ + register const struct state * sp; + register int dir; + register int bits; + register int i, j ; + register int saved_seconds; + time_t newt; + time_t t; + struct tm yourtm, mytm; + + *okayp = FALSE; + yourtm = *tmp; + if (yourtm.tm_sec >= SECSPERMIN + 2 || yourtm.tm_sec < 0) + normalize(&yourtm.tm_min, &yourtm.tm_sec, SECSPERMIN); + normalize(&yourtm.tm_hour, &yourtm.tm_min, MINSPERHOUR); + normalize(&yourtm.tm_mday, &yourtm.tm_hour, HOURSPERDAY); + normalize(&yourtm.tm_year, &yourtm.tm_mon, MONSPERYEAR); + while (yourtm.tm_mday <= 0) { + --yourtm.tm_year; + yourtm.tm_mday += + year_lengths[isleap(yourtm.tm_year + TM_YEAR_BASE)]; + } + while (yourtm.tm_mday > DAYSPERLYEAR) { + yourtm.tm_mday -= + year_lengths[isleap(yourtm.tm_year + TM_YEAR_BASE)]; + ++yourtm.tm_year; + } + for ( ; ; ) { + i = mon_lengths[isleap(yourtm.tm_year + + TM_YEAR_BASE)][yourtm.tm_mon]; + if (yourtm.tm_mday <= i) + break; + yourtm.tm_mday -= i; + if (++yourtm.tm_mon >= MONSPERYEAR) { + yourtm.tm_mon = 0; + ++yourtm.tm_year; + } + } + saved_seconds = yourtm.tm_sec; + yourtm.tm_sec = 0; + /* + ** Calculate the number of magnitude bits in a time_t + ** (this works regardless of whether time_t is + ** signed or unsigned, though lint complains if unsigned). + */ + for (bits = 0, t = 1; t > 0; ++bits, t <<= 1) + ; + /* + ** If time_t is signed, then 0 is the median value, + ** if time_t is unsigned, then 1 << bits is median. + */ + t = (t < 0) ? 0 : ((time_t) 1 << bits); + for ( ; ; ) { + (*funcp)(&t, offset, &mytm); + dir = tmcomp(&mytm, &yourtm); + if (dir != 0) { + if (bits-- < 0) + return WRONG; + if (bits < 0) + --t; + else if (dir > 0) + t -= (time_t) 1 << bits; + else t += (time_t) 1 << bits; + continue; + } + if (yourtm.tm_isdst < 0 || mytm.tm_isdst == yourtm.tm_isdst) + break; + /* + ** Right time, wrong type. + ** Hunt for right time, right type. + ** It's okay to guess wrong since the guess + ** gets checked. + */ + sp = (const struct state *) + ((funcp == localsub) ? lclptr : gmtptr); +#ifdef ALL_STATE + if (sp == NULL) + return WRONG; +#endif /* defined ALL_STATE */ + for (i = 0; i < sp->typecnt; ++i) { + if (sp->ttis[i].tt_isdst != yourtm.tm_isdst) + continue; + for (j = 0; j < sp->typecnt; ++j) { + if (sp->ttis[j].tt_isdst == yourtm.tm_isdst) + continue; + newt = t + sp->ttis[j].tt_gmtoff - + sp->ttis[i].tt_gmtoff; + (*funcp)(&newt, offset, &mytm); + if (tmcomp(&mytm, &yourtm) != 0) + continue; + if (mytm.tm_isdst != yourtm.tm_isdst) + continue; + /* + ** We have a match. + */ + t = newt; + goto label; + } + } + return WRONG; + } +label: + t += saved_seconds; + (*funcp)(&t, offset, tmp); + *okayp = TRUE; + return t; +} + +static time_t +time1(tmp, funcp, offset) +struct tm * const tmp; +void (* const funcp)(); +const long offset; +{ + register time_t t; + register const struct state * sp; + register int samei, otheri; + int okay; + + if (tmp->tm_isdst > 1) + tmp->tm_isdst = 1; + t = time2(tmp, funcp, offset, &okay); + if (okay || tmp->tm_isdst < 0) + return t; + /* + ** We're supposed to assume that somebody took a time of one type + ** and did some math on it that yielded a "struct tm" that's bad. + ** We try to divine the type they started from and adjust to the + ** type they need. + */ + sp = (const struct state *) ((funcp == localsub) ? lclptr : gmtptr); +#ifdef ALL_STATE + if (sp == NULL) + return WRONG; +#endif /* defined ALL_STATE */ + for (samei = 0; samei < sp->typecnt; ++samei) { + if (sp->ttis[samei].tt_isdst != tmp->tm_isdst) + continue; + for (otheri = 0; otheri < sp->typecnt; ++otheri) { + if (sp->ttis[otheri].tt_isdst == tmp->tm_isdst) + continue; + tmp->tm_sec += sp->ttis[otheri].tt_gmtoff - + sp->ttis[samei].tt_gmtoff; + tmp->tm_isdst = !tmp->tm_isdst; + t = time2(tmp, funcp, offset, &okay); + if (okay) + return t; + tmp->tm_sec -= sp->ttis[otheri].tt_gmtoff - + sp->ttis[samei].tt_gmtoff; + tmp->tm_isdst = !tmp->tm_isdst; + } + } + return WRONG; +} + +time_t +mktime(tmp) +struct tm * const tmp; +{ + return time1(tmp, localsub, 0L); +} diff --git a/gen/daemon.3 b/gen/daemon.3 new file mode 100644 index 0000000..0a95ff8 --- /dev/null +++ b/gen/daemon.3 @@ -0,0 +1,81 @@ +.\" 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. +.\" +.\" @(#)daemon.3 8.1 (Berkeley) 6/9/93 +.\" $FreeBSD: src/lib/libc/gen/daemon.3,v 1.10 2001/10/01 16:08:50 ru Exp $ +.\" +.Dd June 9, 1993 +.Dt DAEMON 3 +.Os +.Sh NAME +.Nm daemon +.Nd run in the background +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In stdlib.h +.Ft int +.Fn daemon "int nochdir" "int noclose" +.Sh DESCRIPTION +The +.Fn daemon +function is for programs wishing to detach themselves from the +controlling terminal and run in the background as system daemons. +.Pp +Unless the argument +.Fa nochdir +is non-zero, +.Fn daemon +changes the current working directory to the root (``/''). +.Pp +Unless the argument +.Fa noclose +is non-zero, +.Fn daemon +will redirect standard input, standard output and standard error +to ``/dev/null''. +.Sh ERRORS +If an error occurs, +.Fn daemon +returns -1 and sets the global variable +.Va errno +to any of the errors specified for the library functions +.Xr fork 2 +and +.Xr setsid 2 . +.Sh SEE ALSO +.Xr fork 2 , +.Xr setsid 2 +.Sh HISTORY +The +.Fn daemon +function first appeared in +.Bx 4.4 . diff --git a/gen/daemon.c b/gen/daemon.c new file mode 100644 index 0000000..7c638ce --- /dev/null +++ b/gen/daemon.c @@ -0,0 +1,89 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 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 +#include +#include + +int +daemon(nochdir, noclose) + int nochdir, noclose; +{ + int fd; + + switch (fork()) { + case -1: + return (-1); + case 0: + break; + default: + _exit(0); + } + + if (setsid() == -1) + return (-1); + + if (!nochdir) + (void)chdir("/"); + + if (!noclose && (fd = open(_PATH_DEVNULL, O_RDWR, 0)) != -1) { + (void)dup2(fd, STDIN_FILENO); + (void)dup2(fd, STDOUT_FILENO); + (void)dup2(fd, STDERR_FILENO); + if (fd > 2) + (void)close (fd); + } + return (0); +} diff --git a/gen/devname.3 b/gen/devname.3 new file mode 100644 index 0000000..1a08e34 --- /dev/null +++ b/gen/devname.3 @@ -0,0 +1,72 @@ +.\" 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. +.\" +.\" @(#)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 +.Dt DEVNAME 3 +.Os +.Sh NAME +.Nm devname +.Nd get device name +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In sys/stat.h +.In stdlib.h +.Ft char * +.Fn devname "dev_t dev" "mode_t type" +.Sh DESCRIPTION +The +.Fn devname +function returns a pointer to the name of the block or character +device in +.Dq Pa /dev +with a device number of +.Fa dev , +and a file type matching the one encoded in +.Fa type +which must be one of S_IFBLK or S_IFCHR. +If no device matches the specified values, or no information is +available, NULL is returned. +.Pp +The traditional display for applications when no device is +found is the string +.Dq ?? . +.Sh SEE ALSO +.Xr stat 2 , +.Xr dev_mkdb 8 +.Sh HISTORY +The +.Fn devname +function call appeared in +.Bx 4.4 . diff --git a/gen/devname.c b/gen/devname.c new file mode 100644 index 0000000..451fb8f --- /dev/null +++ b/gen/devname.c @@ -0,0 +1,102 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1989, 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 +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +char * +devname(dev, type) + dev_t dev; + mode_t type; +{ + register DIR *dp; + register struct dirent *dirp; + struct stat sb; + static char *buf = NULL; + + if( buf == NULL ) { + buf = malloc(sizeof(_PATH_DEV) + MAXNAMLEN); + if( buf == NULL ) + return NULL; + 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, + dirp->d_namlen + 1); + if (stat(buf, &sb)) + continue; + if (dev != sb.st_rdev) + continue; + if (type != (sb.st_mode & S_IFMT)) + continue; + (void)closedir(dp); + return (buf + sizeof(_PATH_DEV) - 1); + } + (void)closedir(dp); + return (NULL); +} diff --git a/gen/difftime.c b/gen/difftime.c new file mode 100644 index 0000000..015b223 --- /dev/null +++ b/gen/difftime.c @@ -0,0 +1,63 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1989, 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 + +double +difftime(time1, time0) + time_t time1, time0; +{ + return(time1 - time0); +} diff --git a/gen/directory.3 b/gen/directory.3 new file mode 100644 index 0000000..347767e --- /dev/null +++ b/gen/directory.3 @@ -0,0 +1,200 @@ +.\" Copyright (c) 1983, 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. +.\" +.\" @(#)directory.3 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD: src/lib/libc/gen/directory.3,v 1.12 2001/10/01 16:08:50 ru Exp $ +.\" +.Dd June 4, 1993 +.Dt DIRECTORY 3 +.Os +.Sh NAME +.Nm opendir , +.Nm readdir , +.Nm readdir_r , +.Nm telldir , +.Nm seekdir , +.Nm rewinddir , +.Nm closedir , +.Nm dirfd +.Nd directory operations +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In sys/types.h +.In dirent.h +.Ft DIR * +.Fn opendir "const char *filename" +.Ft struct dirent * +.Fn readdir "DIR *dirp" +.Ft int +.Fn readdir_r "DIR *dirp" "struct dirent *entry" "struct dirent **result" +.Ft long +.Fn telldir "DIR *dirp" +.Ft void +.Fn seekdir "DIR *dirp" "long loc" +.Ft void +.Fn rewinddir "DIR *dirp" +.Ft int +.Fn closedir "DIR *dirp" +.Ft int +.Fn dirfd "DIR *dirp" +.Sh DESCRIPTION +The +.Fn opendir +function +opens the directory named by +.Fa filename , +associates a +.Em directory stream +with it +and +returns a pointer to be used to identify the +.Em directory stream +in subsequent operations. The pointer +.Dv NULL +is returned if +.Fa filename +cannot be accessed, or if it cannot +.Xr malloc 3 +enough memory to hold the whole thing. +.Pp +The +.Fn readdir +function +returns a pointer to the next directory entry. It returns +.Dv NULL +upon reaching the end of the directory or detecting an invalid +.Fn seekdir +operation. +.Pp +.Fn readdir_r +provides the same functionality as +.Fn readdir , +but the caller must provide a directory +.Fa entry +buffer to store the results in. If the read succeeds, +.Fa result +is pointed at the +.Fa entry ; +upon reaching the end of the directory +.Fa result +is set to +.Dv NULL . +.Fn readdir_r +returns 0 on success or an error number to indicate failure. +.Pp +The +.Fn telldir +function +returns the current location associated with the named +.Em directory stream . +Values returned by +.Fn telldir +are good only for the lifetime of the +.Dv DIR +pointer, +.Fa dirp , +from which they are derived. If the directory is closed and then +reopened, prior values returned by +.Fn telldir +will no longer be valid. +.Pp +The +.Fn seekdir +function +sets the position of the next +.Fn readdir +operation on the +.Em directory stream . +The new position reverts to the one associated with the +.Em directory stream +when the +.Fn telldir +operation was performed. +.Pp +The +.Fn rewinddir +function +resets the position of the named +.Em directory stream +to the beginning of the directory. +.Pp +The +.Fn closedir +function +closes the named +.Em directory stream +and frees the structure associated with the +.Fa dirp +pointer, +returning 0 on success. +On failure, \-1 is returned and the global variable +.Va errno +is set to indicate the error. +.Pp +The +.Fn dirfd +function +returns the integer file descriptor associated with the named +.Em directory stream , +see +.Xr open 2 . +.Pp +Sample code which searches a directory for entry ``name'' is: +.Bd -literal -offset indent +len = strlen(name); +dirp = opendir("."); +while ((dp = readdir(dirp)) != NULL) + if (dp->d_namlen == len && !strcmp(dp->d_name, name)) { + (void)closedir(dirp); + return FOUND; + } +(void)closedir(dirp); +return NOT_FOUND; +.Ed +.Sh SEE ALSO +.Xr close 2 , +.Xr lseek 2 , +.Xr open 2 , +.Xr read 2 , +.Xr dir 5 +.Sh HISTORY +The +.Fn opendir , +.Fn readdir , +.Fn telldir , +.Fn seekdir , +.Fn rewinddir , +.Fn closedir , +and +.Fn dirfd +functions appeared in +.Bx 4.2 . diff --git a/gen/dirname.3 b/gen/dirname.3 new file mode 100644 index 0000000..2b160a9 --- /dev/null +++ b/gen/dirname.3 @@ -0,0 +1,108 @@ +.\" +.\" Copyright (c) 1997 Todd C. Miller +.\" 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. 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 ARE 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 +.\" 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.4 2001/10/01 16:08:50 ru Exp $ +.\" +.Dd August 17, 1997 +.Dt DIRNAME 3 +.Os +.Sh NAME +.Nm dirname +.Nd extract the directory portition of a pathname +.Sh SYNOPSIS +.In libgen.h +.Ft char * +.Fn dirname "const char *path" +.Sh DESCRIPTION +The +.Fn dirname +function +is the converse of +.Xr basename 3 ; +it returns a pointer to the parent directory of the pathname pointed to by +.Ar path . +Any trailing +.Sq \&/ +characters are not counted as part of the directory +name. +If +.Ar path +is a null pointer, the empty string, or contains no +.Sq \&/ +characters, +.Fn dirname +returns a pointer to the string +.Qq \&. , +signifying the current directory. +.Sh RETURN VALUES +On successful completion, +.Fn dirname +returns a pointer to the parent directory of +.Ar path . +.Pp +If +.Fn dirname +fails, a null pointer is returned and the global variable +.Va errno +is set to indicate the error. +.Sh ERRORS +The following error codes may be set in +.Va errno : +.Bl -tag -width Er +.It Bq Er ENAMETOOLONG +The path component to be returned was larger than +.Dv MAXPATHLEN . +.El +.Sh WARNINGS +.Fn dirname +returns a pointer to internal static storage space that will be overwritten +by subsequent calls (each function has its own separate storage). +.Pp +Other vendor implementations of +.Fn dirname +may modify the contents of the string passed to +.Fn dirname ; +this should be taken into account when writing code which calls this function +if portability is desired. +.Sh SEE ALSO +.Xr basename 1 , +.Xr dirname 1 , +.Xr basename 3 +.Sh STANDARDS +The +.Fn dirname +function conforms to +.St -xpg4.2 . +.Sh HISTORY +The +.Fn dirname +function first appeared in +.Ox 2.2 +and +.Fx 4.2 . +.Sh AUTHORS +Todd C. Miller diff --git a/gen/dirname.c b/gen/dirname.c new file mode 100644 index 0000000..709c157 --- /dev/null +++ b/gen/dirname.c @@ -0,0 +1,86 @@ +/* $OpenBSD: dirname.c,v 1.4 1999/05/30 17:10:30 espie Exp $ */ +/* $FreeBSD: src/lib/libc/gen/dirname.c,v 1.1.2.2 2001/07/23 10:13:04 dd Exp $ */ + +/* + * Copyright (c) 1997 Todd C. Miller + * 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. 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 ARE 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 + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#if defined(LIBC_RCS) && !defined(lint) +static char rcsid[] = "$OpenBSD: dirname.c,v 1.4 1999/05/30 17:10:30 espie Exp $"; +#endif /* not lint */ + +#include +#include +#include +#include +#include + +char * +dirname(path) + const char *path; +{ + static char *bname = NULL; + register const char *endp; + + if ( bname == NULL ) { + bname = malloc(MAXPATHLEN); + if( bname == NULL ) + return NULL; + } + + /* Empty or NULL string gets treated as "." */ + if (path == NULL || *path == '\0') { + (void)strcpy(bname, "."); + return(bname); + } + + /* Strip trailing slashes */ + endp = path + strlen(path) - 1; + while (endp > path && *endp == '/') + endp--; + + /* Find the start of the dir */ + while (endp > path && *endp != '/') + endp--; + + /* Either the dir is "/" or there are no slashes */ + if (endp == path) { + (void)strcpy(bname, *endp == '/' ? "/" : "."); + return(bname); + } else { + do { + endp--; + } while (endp > path && *endp == '/'); + } + + if (endp - path + 2 > MAXPATHLEN) { + errno = ENAMETOOLONG; + return(NULL); + } + (void)strncpy(bname, path, endp - path + 1); + bname[endp - path + 1] = '\0'; + return(bname); +} diff --git a/gen/disklabel.c b/gen/disklabel.c new file mode 100644 index 0000000..e828970 --- /dev/null +++ b/gen/disklabel.c @@ -0,0 +1,204 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1983, 1987, 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 +#include +#define DKTYPENAMES +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +static int error __P((int)); +static int gettype __P((char *, char **)); + +struct disklabel * +getdiskbyname(name) + const char *name; +{ + static struct disklabel disk; + register struct disklabel *dp = &disk; + register struct partition *pp; + char *buf; + char *db_array[2] = { _PATH_DISKTAB, 0 }; + char *cp, *cq; /* can't be register */ + char p, max, psize[3], pbsize[3], + pfsize[3], poffset[3], ptype[3]; + u_int32_t *dx; + + if (cgetent(&buf, db_array, (char *) name) < 0) + return NULL; + + bzero((char *)&disk, sizeof(disk)); + /* + * typename + */ + cq = dp->d_typename; + cp = buf; + while (cq < dp->d_typename + sizeof(dp->d_typename) - 1 && + (*cq = *cp) && *cq != '|' && *cq != ':') + cq++, cp++; + *cq = '\0'; + /* + * boot name (optional) xxboot, bootxx + */ + cgetstr(buf, "b0", &dp->d_boot0); + cgetstr(buf, "b1", &dp->d_boot1); + + if (cgetstr(buf, "ty", &cq) > 0 && strcmp(cq, "removable") == 0) + dp->d_flags |= D_REMOVABLE; + else if (cq && strcmp(cq, "simulated") == 0) + dp->d_flags |= D_RAMDISK; + if (cgetcap(buf, "sf", ':') != NULL) + dp->d_flags |= D_BADSECT; + +#define getnumdflt(field, dname, dflt) \ + { long f; (field) = (cgetnum(buf, dname, &f) == -1) ? (dflt) : f; } + + getnumdflt(dp->d_secsize, "se", DEV_BSIZE); + cgetnum(buf, "nt",(long *) &dp->d_ntracks); + cgetnum(buf, "ns",(long *) &dp->d_nsectors); + cgetnum(buf, "nc",(long *) &dp->d_ncylinders); + + if (cgetstr(buf, "dt", &cq) > 0) + dp->d_type = gettype(cq, dktypenames); + else + getnumdflt(dp->d_type, "dt", 0); + getnumdflt(dp->d_secpercyl, "sc", dp->d_nsectors * dp->d_ntracks); + getnumdflt(dp->d_secperunit, "su", dp->d_secpercyl * dp->d_ncylinders); + getnumdflt(dp->d_rpm, "rm", 3600); + getnumdflt(dp->d_interleave, "il", 1); + getnumdflt(dp->d_trackskew, "sk", 0); + getnumdflt(dp->d_cylskew, "cs", 0); + getnumdflt(dp->d_headswitch, "hs", 0); + getnumdflt(dp->d_trkseek, "ts", 0); + getnumdflt(dp->d_bbsize, "bs", BBSIZE); + getnumdflt(dp->d_sbsize, "sb", SBSIZE); + strcpy(psize, "px"); + strcpy(pbsize, "bx"); + strcpy(pfsize, "fx"); + strcpy(poffset, "ox"); + strcpy(ptype, "tx"); + max = 'a' - 1; + pp = &dp->d_partitions[0]; + for (p = 'a'; p < 'a' + MAXPARTITIONS; p++, pp++) { + psize[1] = pbsize[1] = pfsize[1] = poffset[1] = ptype[1] = p; + if (cgetnum(buf, psize,(long *) &pp->p_size) == -1) + pp->p_size = 0; + else { + cgetnum(buf, poffset, (long *) &pp->p_offset); + getnumdflt(pp->p_fsize, pfsize, 0); + if (pp->p_fsize) { + long bsize; + + if (cgetnum(buf, pbsize, &bsize) == 0) + pp->p_frag = bsize / pp->p_fsize; + else + pp->p_frag = 8; + } + getnumdflt(pp->p_fstype, ptype, 0); + if (pp->p_fstype == 0 && cgetstr(buf, ptype, &cq) > 0) + pp->p_fstype = gettype(cq, fstypenames); + max = p; + } + } + dp->d_npartitions = max + 1 - 'a'; + (void)strcpy(psize, "dx"); + dx = dp->d_drivedata; + for (p = '0'; p < '0' + NDDATA; p++, dx++) { + psize[1] = p; + getnumdflt(*dx, psize, 0); + } + dp->d_magic = DISKMAGIC; + dp->d_magic2 = DISKMAGIC; + free(buf); + return (dp); +} + +static int +gettype(t, names) + char *t; + char **names; +{ + register char **nm; + + for (nm = names; *nm; nm++) + if (strcasecmp(t, *nm) == 0) + return (nm - names); + if (isdigit(*t)) + return (atoi(t)); + return (0); +} + +static int +error(err) + int err; +{ + char *p; + + (void)write(STDERR_FILENO, "disktab: ", 9); + (void)write(STDERR_FILENO, _PATH_DISKTAB, sizeof(_PATH_DISKTAB) - 1); + (void)write(STDERR_FILENO, ": ", 2); + p = strerror(err); + (void)write(STDERR_FILENO, p, strlen(p)); + (void)write(STDERR_FILENO, "\n", 1); +} diff --git a/gen/drand48.c b/gen/drand48.c new file mode 100644 index 0000000..cec04a6 --- /dev/null +++ b/gen/drand48.c @@ -0,0 +1,22 @@ +/* + * Copyright (c) 1993 Martin Birgmeier + * All rights reserved. + * + * You may redistribute unmodified or modified versions of this source + * code provided that the above copyright notice and this and the + * following conditions are retained. + * + * This software is provided ``as is'', and comes with no warranties + * of any kind. I shall in no event be liable for anything that happens + * to anyone/anything when using this software. + */ + +#include "rand48.h" + +extern unsigned short _rand48_seed[3]; + +double +drand48(void) +{ + return erand48(_rand48_seed); +} diff --git a/gen/erand48.c b/gen/erand48.c new file mode 100644 index 0000000..286904c --- /dev/null +++ b/gen/erand48.c @@ -0,0 +1,23 @@ +/* + * Copyright (c) 1993 Martin Birgmeier + * All rights reserved. + * + * You may redistribute unmodified or modified versions of this source + * code provided that the above copyright notice and this and the + * following conditions are retained. + * + * This software is provided ``as is'', and comes with no warranties + * of any kind. I shall in no event be liable for anything that happens + * to anyone/anything when using this software. + */ + +#include "rand48.h" + +double +erand48(unsigned short xseed[3]) +{ + _dorand48(xseed); + return ldexp((double) xseed[0], -48) + + ldexp((double) xseed[1], -32) + + ldexp((double) xseed[2], -16); +} diff --git a/gen/err.3 b/gen/err.3 new file mode 100644 index 0000000..08e6316 --- /dev/null +++ b/gen/err.3 @@ -0,0 +1,230 @@ +.\" 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. +.\" +.\" From: @(#)err.3 8.1 (Berkeley) 6/9/93 +.\" $FreeBSD: src/lib/libc/gen/err.3,v 1.18 2001/10/01 16:08:50 ru Exp $ +.\" +.Dd March 6, 1999 +.Dt ERR 3 +.Os +.Sh NAME +.Nm err , +.Nm verr , +.Nm errc , +.Nm verrc , +.Nm errx , +.Nm verrx , +.Nm warn , +.Nm vwarn , +.Nm warnc , +.Nm vwarnc , +.Nm warnx , +.Nm vwarnx , +.Nm err_set_exit , +.Nm err_set_file +.Nd formatted error messages +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In err.h +.Ft void +.Fn err "int eval" "const char *fmt" "..." +.Ft void +.Fn err_set_exit "void (*exitf)(int)" +.Ft void +.Fn err_set_file "void *vfp" +.Ft void +.Fn errc "int eval" "int code" "const char *fmt" "..." +.Ft void +.Fn errx "int eval" "const char *fmt" "..." +.Ft void +.Fn warn "const char *fmt" "..." +.Ft void +.Fn warnc "int code" "const char *fmt" "..." +.Ft void +.Fn warnx "const char *fmt" "..." +.In stdarg.h +.Ft void +.Fn verr "int eval" "const char *fmt" "va_list args" +.Ft void +.Fn verrc "int eval" "int code" "const char *fmt" "va_list args" +.Ft void +.Fn verrx "int eval" "const char *fmt" "va_list args" +.Ft void +.Fn vwarn "const char *fmt" "va_list args" +.Ft void +.Fn vwarnc "int code" "const char *fmt" "va_list args" +.Ft void +.Fn vwarnx "const char *fmt" "va_list args" +.Sh DESCRIPTION +The +.Fn err +and +.Fn warn +family of functions display a formatted error message on the standard +error output, or on another file specified using the +.Fn err_set_file +function. +In all cases, the last component of the program name, a colon character, +and a space are output. +If the +.Fa fmt +argument is not NULL, the +.Xr printf 3 +-like formatted error message is output. +The output is terminated by a newline character. +.Pp +The +.Fn err , +.Fn errc , +.Fn verr , +.Fn verrc , +.Fn warn , +.Fn warnc , +.Fn vwarn , +and +.Fn vwarnc +functions append an error message obtained from +.Xr strerror 3 +based on a code or the global variable +.Va errno , +preceded by another colon and space unless the +.Fa fmt +argument is +.Dv NULL . +.Pp +In the case of the +.Fn errc , +.Fn verrc , +.Fn warnc , +and +.Fn vwarnc +functions, +the +.Fa code +argument is used to look up the error message. +.Pp +The +.Fn err , +.Fn verr , +.Fn warn , +and +.Fn vwarn +functions use the global variable +.Va errno +to look up the error message. +.Pp +The +.Fn errx +and +.Fn warnx +functions do not append an error message. +.Pp +The +.Fn err , +.Fn verr , +.Fn errc , +.Fn verrc , +.Fn errx , +and +.Fn verrx +functions do not return, but exit with the value of the argument +.Fa eval . +The +.Fn err_set_exit +function can be used to specify a function which is called before +.Xr exit 3 +to perform any necessary cleanup; passing a null function pointer for +.Va exitf +resets the hook to do nothing. +The +.Fn err_set_file +function sets the output stream used by the other functions. +Its +.Fa vfp +argument must be either a pointer to an open stream +(possibly already converted to void *) +or a null pointer +(in which case the output stream is set to standard error). +.Sh EXAMPLES +Display the current errno information string and exit: +.Bd -literal -offset indent +if ((p = malloc(size)) == NULL) + err(1, NULL); +if ((fd = open(file_name, O_RDONLY, 0)) == -1) + err(1, "%s", file_name); +.Ed +.Pp +Display an error message and exit: +.Bd -literal -offset indent +if (tm.tm_hour < START_TIME) + errx(1, "too early, wait until %s", start_time_string); +.Ed +.Pp +Warn of an error: +.Bd -literal -offset indent +if ((fd = open(raw_device, O_RDONLY, 0)) == -1) + warnx("%s: %s: trying the block device", + raw_device, strerror(errno)); +if ((fd = open(block_device, O_RDONLY, 0)) == -1) + err(1, "%s", block_device); +.Ed +.Pp +Warn of an error without using the global variable +.Va errno : +.Bd -literal -offset indent +error = my_function(); /* returns a value from */ +if (error != 0) + warnc(error, "my_function"); +.Ed +.Sh SEE ALSO +.Xr exit 3 , +.Xr printf 3 , +.Xr strerror 3 +.Sh HISTORY +The +.Fn err +and +.Fn warn +functions first appeared in +.Bx 4.4 . +The +.Fn err_set_exit +and +.Fn err_set_file +functions first appeared in +.Fx 2.1 . +The +.Fn errc +and +.Fn warnc +functions first appeared in +.Fx 3.0 . diff --git a/gen/err.c b/gen/err.c new file mode 100644 index 0000000..a355d99 --- /dev/null +++ b/gen/err.c @@ -0,0 +1,206 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * 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 +#include +#include +#include +#include + +#include + +#ifdef __STDC__ +#include +#else +#include +#endif + +__dead void +#ifdef __STDC__ +err(int eval, const char *fmt, ...) +#else +err(eval, fmt, va_alist) + int eval; + const char *fmt; + va_dcl +#endif +{ + va_list ap; +#if __STDC__ + va_start(ap, fmt); +#else + va_start(ap); +#endif + verr(eval, fmt, ap); + va_end(ap); +} + +__dead void +verr(eval, fmt, ap) + int eval; + const char *fmt; + va_list ap; +{ + char* __progname = *(*_NSGetArgv()); + int sverrno; + + sverrno = errno; + (void)fprintf(stderr, "%s: ", __progname); + if (fmt != NULL) { + (void)vfprintf(stderr, fmt, ap); + (void)fprintf(stderr, ": "); + } + (void)fprintf(stderr, "%s\n", strerror(sverrno)); + exit(eval); +} + +__dead void +#if __STDC__ +errx(int eval, const char *fmt, ...) +#else +errx(eval, fmt, va_alist) + int eval; + const char *fmt; + va_dcl +#endif +{ + va_list ap; +#if __STDC__ + va_start(ap, fmt); +#else + va_start(ap); +#endif + verrx(eval, fmt, ap); + va_end(ap); +} + +__dead void +verrx(eval, fmt, ap) + int eval; + const char *fmt; + va_list ap; +{ + char* __progname = *(*_NSGetArgv()); + (void)fprintf(stderr, "%s: ", __progname); + if (fmt != NULL) + (void)vfprintf(stderr, fmt, ap); + (void)fprintf(stderr, "\n"); + exit(eval); +} + +void +#if __STDC__ +warn(const char *fmt, ...) +#else +warn(fmt, va_alist) + const char *fmt; + va_dcl +#endif +{ + va_list ap; +#if __STDC__ + va_start(ap, fmt); +#else + va_start(ap); +#endif + vwarn(fmt, ap); + va_end(ap); +} + +void +vwarn(fmt, ap) + const char *fmt; + va_list ap; +{ + int sverrno = errno; + char* __progname = *(*_NSGetArgv()); + (void)fprintf(stderr, "%s: ", __progname); + if (fmt != NULL) { + (void)vfprintf(stderr, fmt, ap); + (void)fprintf(stderr, ": "); + } + (void)fprintf(stderr, "%s\n", strerror(sverrno)); +} + +void +#ifdef __STDC__ +warnx(const char *fmt, ...) +#else +warnx(fmt, va_alist) + const char *fmt; + va_dcl +#endif +{ + va_list ap; +#ifdef __STDC__ + va_start(ap, fmt); +#else + va_start(ap); +#endif + vwarnx(fmt, ap); + va_end(ap); +} + +void +vwarnx(fmt, ap) + const char *fmt; + va_list ap; +{ + char* __progname = *(*_NSGetArgv()); + (void)fprintf(stderr, "%s: ", __progname); + if (fmt != NULL) + (void)vfprintf(stderr, fmt, ap); + (void)fprintf(stderr, "\n"); +} diff --git a/gen/errlst.c b/gen/errlst.c new file mode 100644 index 0000000..1a022c9 --- /dev/null +++ b/gen/errlst.c @@ -0,0 +1,173 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1982, 1985, 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 + +const char *const sys_errlist[] = { + "Undefined error: 0", /* 0 - ENOERROR */ + "Operation not permitted", /* 1 - EPERM */ + "No such file or directory", /* 2 - ENOENT */ + "No such process", /* 3 - ESRCH */ + "Interrupted system call", /* 4 - EINTR */ + "Input/output error", /* 5 - EIO */ + "Device not configured", /* 6 - ENXIO */ + "Argument list too long", /* 7 - E2BIG */ + "Exec format error", /* 8 - ENOEXEC */ + "Bad file descriptor", /* 9 - EBADF */ + "No child processes", /* 10 - ECHILD */ + "Resource deadlock avoided", /* 11 - EDEADLK */ + "Cannot allocate memory", /* 12 - ENOMEM */ + "Permission denied", /* 13 - EACCES */ + "Bad address", /* 14 - EFAULT */ + "Block device required", /* 15 - ENOTBLK */ + "Device busy", /* 16 - EBUSY */ + "File exists", /* 17 - EEXIST */ + "Cross-device link", /* 18 - EXDEV */ + "Operation not supported by device", /* 19 - ENODEV */ + "Not a directory", /* 20 - ENOTDIR */ + "Is a directory", /* 21 - EISDIR */ + "Invalid argument", /* 22 - EINVAL */ + "Too many open files in system", /* 23 - ENFILE */ + "Too many open files", /* 24 - EMFILE */ + "Inappropriate ioctl for device", /* 25 - ENOTTY */ + "Text file busy", /* 26 - ETXTBSY */ + "File too large", /* 27 - EFBIG */ + "No space left on device", /* 28 - ENOSPC */ + "Illegal seek", /* 29 - ESPIPE */ + "Read-only file system", /* 30 - EROFS */ + "Too many links", /* 31 - EMLINK */ + "Broken pipe", /* 32 - EPIPE */ + +/* math software */ + "Numerical argument out of domain", /* 33 - EDOM */ + "Result too large", /* 34 - ERANGE */ + +/* non-blocking and interrupt i/o */ + "Resource temporarily unavailable", /* 35 - EAGAIN */ + /* 35 - EWOULDBLOCK */ + "Operation now in progress", /* 36 - EINPROGRESS */ + "Operation already in progress", /* 37 - EALREADY */ + +/* ipc/network software -- argument errors */ + "Socket operation on non-socket", /* 38 - ENOTSOCK */ + "Destination address required", /* 39 - EDESTADDRREQ */ + "Message too long", /* 40 - EMSGSIZE */ + "Protocol wrong type for socket", /* 41 - EPROTOTYPE */ + "Protocol not available", /* 42 - ENOPROTOOPT */ + "Protocol not supported", /* 43 - EPROTONOSUPPORT */ + "Socket type not supported", /* 44 - ESOCKTNOSUPPORT */ + "Operation not supported", /* 45 - EOPNOTSUPP */ + "Protocol family not supported", /* 46 - EPFNOSUPPORT */ + /* 47 - EAFNOSUPPORT */ + "Address family not supported by protocol family", + "Address already in use", /* 48 - EADDRINUSE */ + "Can't assign requested address", /* 49 - EADDRNOTAVAIL */ + +/* ipc/network software -- operational errors */ + "Network is down", /* 50 - ENETDOWN */ + "Network is unreachable", /* 51 - ENETUNREACH */ + "Network dropped connection on reset", /* 52 - ENETRESET */ + "Software caused connection abort", /* 53 - ECONNABORTED */ + "Connection reset by peer", /* 54 - ECONNRESET */ + "No buffer space available", /* 55 - ENOBUFS */ + "Socket is already connected", /* 56 - EISCONN */ + "Socket is not connected", /* 57 - ENOTCONN */ + "Can't send after socket shutdown", /* 58 - ESHUTDOWN */ + "Too many references: can't splice", /* 59 - ETOOMANYREFS */ + "Operation timed out", /* 60 - ETIMEDOUT */ + "Connection refused", /* 61 - ECONNREFUSED */ + + "Too many levels of symbolic links", /* 62 - ELOOP */ + "File name too long", /* 63 - ENAMETOOLONG */ + +/* should be rearranged */ + "Host is down", /* 64 - EHOSTDOWN */ + "No route to host", /* 65 - EHOSTUNREACH */ + "Directory not empty", /* 66 - ENOTEMPTY */ + +/* quotas & mush */ + "Too many processes", /* 67 - EPROCLIM */ + "Too many users", /* 68 - EUSERS */ + "Disc quota exceeded", /* 69 - EDQUOT */ + +/* Network File System */ + "Stale NFS file handle", /* 70 - ESTALE */ + "Too many levels of remote in path", /* 71 - EREMOTE */ + "RPC struct is bad", /* 72 - EBADRPC */ + "RPC version wrong", /* 73 - ERPCMISMATCH */ + "RPC prog. not avail", /* 74 - EPROGUNAVAIL */ + "Program version wrong", /* 75 - EPROGMISMATCH */ + "Bad procedure for program", /* 76 - EPROCUNAVAIL */ + + "No locks available", /* 77 - ENOLCK */ + "Function not implemented", /* 78 - ENOSYS */ + "Inappropriate file type or format", /* 79 - EFTYPE */ + "Authentication error", /* 80 - EAUTH */ + "Need authenticator", /* 81 - ENEEDAUTH */ + + "Device power is off", /* 82 - EPWROFF */ + "Device error", /* 83 - EDEVERR */ + "Value too large to be stored in data type", /* 84 - EOVERFLOW */ + +/* program loading errors */ + "Bad executable (or shared library)", /* 85 - EBADEXEC */ + "Bad CPU type in executable", /* 86 - EBADARCH */ + "Shared library version mismatch", /* 87 - ESHLIBVERS */ + "Malformed Mach-o file" /* 88 - EBADMACHO */ +}; + +int errno; + +const int sys_nerr = sizeof(sys_errlist) / sizeof(sys_errlist[0]); diff --git a/gen/exec.3 b/gen/exec.3 new file mode 100644 index 0000000..69d4dfa --- /dev/null +++ b/gen/exec.3 @@ -0,0 +1,296 @@ +.\" 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. +.\" +.\" @(#)exec.3 8.3 (Berkeley) 1/24/94 +.\" $FreeBSD: src/lib/libc/gen/exec.3,v 1.16 2001/10/01 16:08:50 ru Exp $ +.\" +.Dd January 24, 1994 +.Dt EXEC 3 +.Os +.Sh NAME +.Nm execl , +.Nm execlp , +.Nm execle , +.Nm exect , +.Nm execv , +.Nm execvp +.Nd execute a file +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In unistd.h +.Vt extern char **environ ; +.Ft int +.Fn execl "const char *path" "const char *arg" ... +.Ft int +.Fn execlp "const char *file" "const char *arg" ... +.Ft int +.Fn execle "const char *path" "const char *arg" ... +.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[]" +.Sh DESCRIPTION +The +.Nm exec +family of functions replaces the current process image with a +new process image. +The functions described in this manual page are front-ends for the function +.Xr execve 2 . +(See the manual page for +.Xr execve 2 +for detailed information about the replacement of the current process.) +.Pp +The initial argument for these functions is the pathname of a file which +is to be executed. +.Pp +The +.Fa "const char *arg" +and subsequent ellipses in the +.Fn execl , +.Fn execlp , +and +.Fn execle +functions can be thought of as +.Em arg0 , +.Em arg1 , +\&..., +.Em argn . +Together they describe a list of one or more pointers to null-terminated +strings that represent the argument list available to the executed program. +The first argument, by convention, should point to the file name associated +with the file being executed. +The list of arguments +.Em must +be terminated by a +.Dv NULL +pointer. +.Pp +The +.Fn exect , +.Fn execv , +and +.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 +with the file being executed. +The array of pointers +.Sy must +be terminated by a +.Dv NULL +pointer. +.Pp +The +.Fn execle +and +.Fn exect +functions also specify the environment of the executed process by following +the +.Dv NULL +pointer that terminates the list of arguments in the parameter list +or the pointer to the argv array with an additional parameter. +This additional parameter is an array of pointers to null-terminated strings +and +.Em must +be terminated by a +.Dv NULL +pointer. +The other functions take the environment for the new process image from the +external variable +.Va environ +in the current process. +.Pp +Some of these functions have special semantics. +.Pp +The functions +.Fn execlp +and +.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 +.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 , +which is set to +.Dq Ev /usr/bin:/bin . +In addition, certain errors are treated specially. +.Pp +If an error is ambiguous (for simplicity, we shall consider all +errors except +.Er ENOEXEC +as being ambiguous here, although only the critical error +.Er EACCES +is really ambiguous), +then these functions will act as if they stat the file to determine +whether the file exists and has suitable execute permissions. +If it does, they will return immediately with the global variable +.Va errno +restored to the value set by +.Fn execve . +Otherwise, the search will be continued. +If the search completes without performing a successful +.Fn execve +or terminating due to an error, +these functions will return with the global variable +.Va errno +set to +.Er EACCES +or +.Er ENOENT +according to whether at least one file with suitable execute permissions +was found. +.Pp +If the header of a file isn't recognized (the attempted +.Fn execve +returned +.Er ENOEXEC ) , +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.) +.Pp +The function +.Fn exect +executes a file with the program tracing facilities enabled (see +.Xr ptrace 2 ) . +.Sh RETURN VALUES +If any of the +.Fn exec +functions returns, an error will have occurred. +The return value is \-1, and the global variable +.Va errno +will be set to indicate the error. +.Sh FILES +.Bl -tag -width /bin/sh -compact +.It Pa /bin/sh +The shell. +.El +.Sh ERRORS +.Fn Execl , +.Fn execle , +.Fn execlp +and +.Fn execvp +may fail and set +.Va errno +for any of the errors specified for the library functions +.Xr execve 2 +and +.Xr malloc 3 . +.Pp +.Fn Exect +and +.Fn execv +may fail and set +.Va errno +for any of the errors specified for the library function +.Xr execve 2 . +.Sh SEE ALSO +.Xr sh 1 , +.Xr execve 2 , +.Xr fork 2 , +.Xr ktrace 2 , +.Xr ptrace 2 , +.Xr environ 7 +.Sh COMPATIBILITY +Historically, the default path for the +.Fn execlp +and +.Fn execvp +functions was +.Dq Pa :/bin:/usr/bin . +This was changed to place the current directory last to enhance system +security. +.Pp +The behavior of +.Fn execlp +and +.Fn execvp +when errors occur while attempting to execute the file is not quite historic +practice, and has not traditionally been documented and is not specified +by the +.Tn POSIX +standard. +.Pp +Traditionally, the functions +.Fn execlp +and +.Fn execvp +ignored all errors except for the ones described above and +.Er ETXTBSY , +upon which they retried after sleeping for several seconds, and +.Er ENOMEM +and +.Er E2BIG , +upon which they returned. +They now return for +.Er ETXTBSY , +and determine existence and executability more carefully. +In particular, +.Er EACCES +for inaccessible directories in the path prefix is no longer +confused with +.Er EACCES +for files with unsuitable execute permissions. +In +.Bx 4.4 , +they returned upon all errors except +.Er EACCES , +.Er ENOENT , +.Er ENOEXEC +and +.Er ETXTBSY . +This was inferior to the traditional error handling, +since it breaks the ignoring of errors for path prefixes +and only improves the handling of the unusual ambiguous error +.Er EFAULT +and the unusual error +.Er EIO . +The behaviour was changed to match the behaviour of +.Xr sh 1 . +.Sh STANDARDS +.Fn Execl , +.Fn execv , +.Fn execle , +.Fn execlp +and +.Fn execvp +conform to +.St -p1003.1-88 . diff --git a/gen/exec.c b/gen/exec.c new file mode 100644 index 0000000..1f6e2d7 --- /dev/null +++ b/gen/exec.c @@ -0,0 +1,323 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * 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. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef __STDC__ +#include +#else +#include +#endif + +#if defined(__APPLE__) +#include +#define environ (*_NSGetEnviron()) +#else +extern char **environ; +#endif + +int +#ifdef __STDC__ +execl(const char *name, const char *arg, ...) +#else +execl(name, arg, va_alist) + const char *name; + const char *arg; + va_dcl +#endif +{ + va_list ap; + char **argv; + int n; + +#ifdef __STDC__ + va_start(ap, arg); +#else + va_start(ap); +#endif + n = 1; + while (va_arg(ap, char *) != NULL) + n++; + va_end(ap); + argv = alloca((n + 1) * sizeof(*argv)); + if (argv == NULL) { + errno = ENOMEM; + return (-1); + } +#ifdef __STDC__ + va_start(ap, arg); +#else + va_start(ap); +#endif + n = 1; + argv[0] = (char *)arg; + while ((argv[n] = va_arg(ap, char *)) != NULL) + n++; + va_end(ap); + return (execve(name, argv, environ)); +} + +int +#ifdef __STDC__ +execle(const char *name, const char *arg, ...) +#else +execle(name, arg, va_alist) + const char *name; + const char *arg; + va_dcl +#endif +{ + va_list ap; + char **argv, **envp; + int n; + +#ifdef __STDC__ + va_start(ap, arg); +#else + va_start(ap); +#endif + n = 1; + while (va_arg(ap, char *) != NULL) + n++; + va_end(ap); + argv = alloca((n + 1) * sizeof(*argv)); + if (argv == NULL) { + errno = ENOMEM; + return (-1); + } +#ifdef __STDC__ + va_start(ap, arg); +#else + va_start(ap); +#endif + n = 1; + argv[0] = (char *)arg; + while ((argv[n] = va_arg(ap, char *)) != NULL) + n++; + envp = va_arg(ap, char **); + va_end(ap); + return (execve(name, argv, envp)); +} + +int +#ifdef __STDC__ +execlp(const char *name, const char *arg, ...) +#else +execlp(name, arg, va_alist) + const char *name; + const char *arg; + va_dcl +#endif +{ + va_list ap; + char **argv; + int n; + +#ifdef __STDC__ + va_start(ap, arg); +#else + va_start(ap); +#endif + n = 1; + while (va_arg(ap, char *) != NULL) + n++; + va_end(ap); + argv = alloca((n + 1) * sizeof(*argv)); + if (argv == NULL) { + errno = ENOMEM; + return (-1); + } +#ifdef __STDC__ + va_start(ap, arg); +#else + va_start(ap); +#endif + n = 1; + argv[0] = (char *)arg; + while ((argv[n] = va_arg(ap, char *)) != NULL) + n++; + va_end(ap); + return (execvp(name, argv)); +} + +int +execv(name, argv) + const char *name; + char * const *argv; +{ + (void)execve(name, argv, environ); + return (-1); +} + +int +execvp(name, argv) + const char *name; + char * const *argv; +{ + char **memp; + register int cnt, lp, ln; + register char *p; + int eacces = 0, etxtbsy = 0; + char *bp, *cur, *path, buf[MAXPATHLEN]; + + /* + * Do not allow null name + */ + if (name == NULL || *name == '\0') { + errno = ENOENT; + return (-1); + } + + /* If it's an absolute or relative path name, it's easy. */ + if (strchr(name, '/')) { + bp = (char *)name; + cur = path = NULL; + goto retry; + } + bp = buf; + + /* 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, ":"))) { + /* + * It's a SHELL path -- double, leading and trailing colons + * mean the current directory. + */ + if (!*p) { + p = "."; + lp = 1; + } else + lp = strlen(p); + ln = strlen(name); + + /* + * If the path is too long complain. This is a possible + * security issue; given a way to make the path too long + * the user may execute the wrong program. + */ + if (lp + ln + 2 > sizeof(buf)) { + struct iovec iov[3]; + + iov[0].iov_base = "execvp: "; + iov[0].iov_len = 8; + iov[1].iov_base = p; + iov[1].iov_len = lp; + iov[2].iov_base = ": path too long\n"; + iov[2].iov_len = 16; + (void)writev(STDERR_FILENO, iov, 3); + continue; + } + bcopy(p, buf, lp); + buf[lp] = '/'; + bcopy(name, buf + lp + 1, ln); + buf[lp + ln + 1] = '\0'; + +retry: (void)execve(bp, argv, environ); + switch(errno) { + case E2BIG: + goto done; + case ELOOP: + case ENAMETOOLONG: + case ENOENT: + break; + case ENOEXEC: + for (cnt = 0; argv[cnt]; ++cnt) + ; + memp = alloca((cnt + 2) * sizeof(char *)); + if (memp == NULL) + goto done; + memp[0] = "sh"; + memp[1] = bp; + bcopy(argv + 1, memp + 2, cnt * sizeof(char *)); + (void)execve(_PATH_BSHELL, memp, environ); + goto done; + case ENOMEM: + goto done; + case ENOTDIR: + break; + case ETXTBSY: + /* + * We used to retry here, but sh(1) doesn't. + */ + goto done; + case EACCES: + eacces = 1; + break; + default: + goto done; + } + } + if (eacces) + errno = EACCES; + else if (!errno) + errno = ENOENT; +done: + return (-1); +} diff --git a/gen/fmtcheck.3 b/gen/fmtcheck.3 new file mode 100644 index 0000000..ec67305 --- /dev/null +++ b/gen/fmtcheck.3 @@ -0,0 +1,108 @@ +.\" Copyright (c) 2000 The NetBSD Foundation, Inc. +.\" All rights reserved. +.\" +.\" This file was contributed to The NetBSD Foundation by Allen Briggs. +.\" +.\" 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. +.\" +.\" $FreeBSD: src/lib/libc/gen/fmtcheck.3,v 1.4 2001/10/01 16:08:50 ru Exp $ +.Dd October 17, 2000 +.Os +.Dt FMTCHECK 3 +.Sh NAME +.Nm fmtcheck +.Nd sanitizes user-supplied +.Xr printf 3 Ns -style +format string +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In stdio.h +.Ft const char * +.Fn fmtcheck "const char *fmt_suspect" "const char *fmt_default" +.Sh DESCRIPTION +The +.Fn fmtcheck +scans +.Fa fmt_suspect +and +.Fa fmt_default +to determine if +.Fa fmt_suspect +will consume the same argument types as +.Fa fmt_default +and to ensure that +.Fa fmt_suspect +is a valid format string. +.Pp +The +.Xr printf 3 +family of functions can not verify the types of arguments that they are +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 parameters. +.Pp +The +.Fn fmtcheck +was designed to be used in these cases, as in: +.Bd -literal -offset indent +printf(fmtcheck(user_format, standard_format), arg1, arg2); +.Ed +.Pp +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 +is completely ignored. +.Pp +Note that the formats may be quite different as long as they accept the +same parameters. 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)" . +However, +.Qq Li %o +is not equivalent to +.Qq Li %lx +because +the first requires an integer and the second requires a long. +.Sh RETURN VALUES +If +.Fa fmt_suspect +is a valid format and consumes the same argument types as +.Fa fmt_default , +then the +.Fn fmtcheck +will return +.Fa fmt_suspect . +Otherwise, it will return +.Fa fmt_default . +.Sh SEE ALSO +.Xr printf 3 diff --git a/gen/fnmatch.3 b/gen/fnmatch.3 new file mode 100644 index 0000000..7442408 --- /dev/null +++ b/gen/fnmatch.3 @@ -0,0 +1,151 @@ +.\" Copyright (c) 1989, 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" This code is derived from software contributed to Berkeley by +.\" Guido van Rossum. +.\" 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. +.\" +.\" @(#)fnmatch.3 8.3 (Berkeley) 4/28/95 +.\" $FreeBSD: src/lib/libc/gen/fnmatch.3,v 1.9.2.3 2001/12/14 18:33:51 ru Exp $ +.\" +.Dd April 28, 1995 +.Dt FNMATCH 3 +.Os +.Sh NAME +.Nm fnmatch +.Nd match filename or pathname +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In fnmatch.h +.Ft int +.Fn fnmatch "const char *pattern" "const char *string" "int flags" +.Sh DESCRIPTION +The +.Fn fnmatch +function +matches patterns according to the rules used by the shell. +It checks the string specified by the +.Fa string +argument to see if it matches the pattern specified by the +.Fa pattern +argument. +.Pp +The +.Fa flags +argument modifies the interpretation of +.Fa pattern +and +.Fa string . +The value of +.Fa flags +is the bitwise inclusive +.Tn OR +of any of the following +constants, which are defined in the include file +.Pa fnmatch.h . +.Bl -tag -width FNM_PATHNAME +.It Dv FNM_NOESCAPE +Normally, every occurrence of a backslash +.Pq Ql \e +followed by a character in +.Fa pattern +is replaced by that character. +This is done to negate any special meaning for the character. +If the +.Dv FNM_NOESCAPE +flag is set, a backslash character is treated as an ordinary character. +.It Dv FNM_PATHNAME +Slash characters in +.Fa string +must be explicitly matched by slashes in +.Fa pattern . +If this flag is not set, then slashes are treated as regular characters. +.It Dv FNM_PERIOD +Leading periods in +.Fa string +must be explicitly matched by periods in +.Fa pattern . +If this flag is not set, then leading periods are treated as regular +characters. +The definition of +.Dq leading +is related to the specification of +.Dv FNM_PATHNAME . +A period is always +.Dq leading +if it is the first character in +.Ar string . +Additionally, if +.Dv FNM_PATHNAME +is set, +a period is +leading +if it immediately follows a slash. +.It Dv FNM_LEADING_DIR +Ignore +.Nm /* +rest after successful +.Fa pattern +matching. +.It Dv FNM_CASEFOLD +Ignore case distinctions in both the +.Fa pattern +and the +.Fa string . +.El +.Sh RETURN VALUES +The +.Fn fnmatch +function returns zero if +.Fa string +matches the pattern specified by +.Fa pattern , +otherwise, it returns the value +.Dv FNM_NOMATCH . +.Sh SEE ALSO +.Xr sh 1 , +.Xr glob 3 , +.Xr regex 3 +.Sh STANDARDS +The +.Fn fnmatch +function conforms to +.St -p1003.2 . +.Sh HISTORY +The +.Fn fnmatch +function first appeared in +.Bx 4.4 . +.Sh BUGS +The pattern +.Ql * +matches the empty string, even if +.Dv FNM_PATHNAME +is specified. diff --git a/gen/fnmatch.c b/gen/fnmatch.c new file mode 100644 index 0000000..c3312b4 --- /dev/null +++ b/gen/fnmatch.c @@ -0,0 +1,231 @@ +/* + * Copyright (c) 1989, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Guido van Rossum. + * + * 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[] = "@(#)fnmatch.c 8.2 (Berkeley) 4/16/94"; +#endif /* LIBC_SCCS and not lint */ + +/* + * Function fnmatch() as specified in POSIX 1003.2-1992, section B.6. + * Compares a filename or pathname to a pattern. + */ + +#include +#include +#include +#include + +#include "collate.h" + +#define EOS '\0' + +#define RANGE_MATCH 1 +#define RANGE_NOMATCH 0 +#define RANGE_ERROR (-1) + +static int rangematch __P((const char *, char, int, char **)); + +int +fnmatch(pattern, string, flags) + const char *pattern, *string; + int flags; +{ + const char *stringstart; + char *newp; + char c, test; + + for (stringstart = string;;) + switch (c = *pattern++) { + case EOS: + if ((flags & FNM_LEADING_DIR) && *string == '/') + return (0); + return (*string == EOS ? 0 : FNM_NOMATCH); + case '?': + if (*string == EOS) + return (FNM_NOMATCH); + if (*string == '/' && (flags & FNM_PATHNAME)) + return (FNM_NOMATCH); + if (*string == '.' && (flags & FNM_PERIOD) && + (string == stringstart || + ((flags & FNM_PATHNAME) && *(string - 1) == '/'))) + return (FNM_NOMATCH); + ++string; + break; + case '*': + c = *pattern; + /* Collapse multiple stars. */ + while (c == '*') + c = *++pattern; + + if (*string == '.' && (flags & FNM_PERIOD) && + (string == stringstart || + ((flags & FNM_PATHNAME) && *(string - 1) == '/'))) + return (FNM_NOMATCH); + + /* Optimize for pattern with * at end or before /. */ + if (c == EOS) + if (flags & FNM_PATHNAME) + return ((flags & FNM_LEADING_DIR) || + strchr(string, '/') == NULL ? + 0 : FNM_NOMATCH); + else + return (0); + else if (c == '/' && flags & FNM_PATHNAME) { + if ((string = strchr(string, '/')) == NULL) + return (FNM_NOMATCH); + break; + } + + /* General case, use recursion. */ + while ((test = *string) != EOS) { + if (!fnmatch(pattern, string, flags & ~FNM_PERIOD)) + return (0); + if (test == '/' && flags & FNM_PATHNAME) + break; + ++string; + } + return (FNM_NOMATCH); + case '[': + if (*string == EOS) + return (FNM_NOMATCH); + if (*string == '/' && (flags & FNM_PATHNAME)) + return (FNM_NOMATCH); + if (*string == '.' && (flags & FNM_PERIOD) && + (string == stringstart || + ((flags & FNM_PATHNAME) && *(string - 1) == '/'))) + return (FNM_NOMATCH); + + switch (rangematch(pattern, *string, flags, &newp)) { + case RANGE_ERROR: + goto norm; + case RANGE_MATCH: + pattern = newp; + break; + case RANGE_NOMATCH: + return (FNM_NOMATCH); + } + ++string; + break; + case '\\': + if (!(flags & FNM_NOESCAPE)) { + if ((c = *pattern++) == EOS) { + c = '\\'; + --pattern; + } + } + /* FALLTHROUGH */ + default: + norm: + if (c == *string) + ; + else if ((flags & FNM_CASEFOLD) && + (tolower((unsigned char)c) == + tolower((unsigned char)*string))) + ; + else + return (FNM_NOMATCH); + string++; + break; + } + /* NOTREACHED */ +} + +static int +rangematch(pattern, test, flags, newp) + const char *pattern; + char test; + int flags; + char **newp; +{ + int negate, ok; + char c, c2; + + /* + * A bracket expression starting with an unquoted circumflex + * character produces unspecified results (IEEE 1003.2-1992, + * 3.13.2). This implementation treats it like '!', for + * consistency with the regular expression syntax. + * J.T. Conklin (conklin@ngai.kaleida.com) + */ + if ( (negate = (*pattern == '!' || *pattern == '^')) ) + ++pattern; + + if (flags & FNM_CASEFOLD) + test = tolower((unsigned char)test); + + /* + * A right bracket shall lose its special meaning and represent + * itself in a bracket expression if it occurs first in the list. + * -- POSIX.2 2.8.3.2 + */ + ok = 0; + c = *pattern++; + do { + if (c == '\\' && !(flags & FNM_NOESCAPE)) + c = *pattern++; + if (c == EOS) + return (RANGE_ERROR); + + if (c == '/' && (flags & FNM_PATHNAME)) + return (RANGE_NOMATCH); + + if (flags & FNM_CASEFOLD) + c = tolower((unsigned char)c); + + if (*pattern == '-' + && (c2 = *(pattern+1)) != EOS && c2 != ']') { + pattern += 2; + if (c2 == '\\' && !(flags & FNM_NOESCAPE)) + c2 = *pattern++; + if (c2 == EOS) + return (RANGE_ERROR); + + if (flags & FNM_CASEFOLD) + c2 = tolower((unsigned char)c2); + + if (__collate_load_error ? + c <= test && test <= c2 : + __collate_range_cmp(c, test) <= 0 + && __collate_range_cmp(test, c2) <= 0 + ) + ok = 1; + } else if (c == test) + ok = 1; + } while ((c = *pattern++) != ']'); + + *newp = (char *)pattern; + return (ok == negate ? RANGE_NOMATCH : RANGE_MATCH); +} diff --git a/gen/frexp.3 b/gen/frexp.3 new file mode 100644 index 0000000..74836cc --- /dev/null +++ b/gen/frexp.3 @@ -0,0 +1,88 @@ +.\" Copyright (c) 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. +.\" +.\" @(#)frexp.3 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD: src/lib/libc/gen/frexp.3,v 1.9 2001/10/01 16:08:50 ru Exp $ +.\" +.Dd June 4, 1993 +.Dt FREXP 3 +.Os +.Sh NAME +.Nm frexp +.Nd convert floating-point number to fractional and integral components +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In math.h +.Ft double +.Fn frexp "double value" "int *exp" +.Sh DESCRIPTION +The +.Fn frexp +function breaks a floating-point number into a normalized +fraction and an integral power of 2. +It stores the integer in the +.Em int +object pointed to by +.Fa exp . +.Sh RETURN VALUES +The +.Fn frexp +function returns the value +.Em x , +such that +.Em x +is a +.Em double +with magnitude in the interval +.Bo 1/2 , 1 Pc +or zero, and +.Fa value +equals +.Em x +times 2 raised to the power +.Fa *exp . +If +.Fa value +is zero, both parts of the result are zero. +.Sh SEE ALSO +.Xr ldexp 3 , +.Xr math 3 , +.Xr modf 3 +.Sh STANDARDS +The +.Fn frexp +function conforms to +.St -isoC . diff --git a/gen/fstab.c b/gen/fstab.c new file mode 100644 index 0000000..ebdf2c9 --- /dev/null +++ b/gen/fstab.c @@ -0,0 +1,225 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1980, 1988, 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 +#include +#include +#include +#include +#include + +static FILE *_fs_fp; +static struct fstab _fs_fstab; + +static error __P((int)); +static fstabscan __P((void)); + +static +fstabscan() +{ + register char *cp; +#define MAXLINELENGTH 1024 + static char *line = NULL; + char subline[MAXLINELENGTH]; + int typexx; + + if( line == NULL ) { + line = malloc(MAXLINELENGTH); + if( line == NULL ) + return(1); + } + + for (;;) { + if (!(cp = fgets(line, sizeof(line), _fs_fp))) + return(0); +/* OLD_STYLE_FSTAB */ + if (!strpbrk(cp, " \t")) { + _fs_fstab.fs_spec = strtok(cp, ":\n"); + _fs_fstab.fs_file = strtok((char *)NULL, ":\n"); + _fs_fstab.fs_type = strtok((char *)NULL, ":\n"); + if (_fs_fstab.fs_type) { + if (!strcmp(_fs_fstab.fs_type, FSTAB_XX)) + continue; + _fs_fstab.fs_mntops = _fs_fstab.fs_type; + _fs_fstab.fs_vfstype = + strcmp(_fs_fstab.fs_type, FSTAB_SW) ? + "ufs" : "swap"; + if (cp = strtok((char *)NULL, ":\n")) { + _fs_fstab.fs_freq = atoi(cp); + if (cp = strtok((char *)NULL, ":\n")) { + _fs_fstab.fs_passno = atoi(cp); + return(1); + } + } + } + goto bad; + } +/* OLD_STYLE_FSTAB */ + _fs_fstab.fs_spec = strtok(cp, " \t\n"); + if (!_fs_fstab.fs_spec || *_fs_fstab.fs_spec == '#') + continue; + _fs_fstab.fs_file = strtok((char *)NULL, " \t\n"); + _fs_fstab.fs_vfstype = strtok((char *)NULL, " \t\n"); + _fs_fstab.fs_mntops = strtok((char *)NULL, " \t\n"); + if (_fs_fstab.fs_mntops == NULL) + goto bad; + _fs_fstab.fs_freq = 0; + _fs_fstab.fs_passno = 0; + if ((cp = strtok((char *)NULL, " \t\n")) != NULL) { + _fs_fstab.fs_freq = atoi(cp); + if ((cp = strtok((char *)NULL, " \t\n")) != NULL) + _fs_fstab.fs_passno = atoi(cp); + } + strcpy(subline, _fs_fstab.fs_mntops); + for (typexx = 0, cp = strtok(subline, ","); cp; + cp = strtok((char *)NULL, ",")) { + if (strlen(cp) != 2) + continue; + if (!strcmp(cp, FSTAB_RW)) { + _fs_fstab.fs_type = FSTAB_RW; + break; + } + if (!strcmp(cp, FSTAB_RQ)) { + _fs_fstab.fs_type = FSTAB_RQ; + break; + } + if (!strcmp(cp, FSTAB_RO)) { + _fs_fstab.fs_type = FSTAB_RO; + break; + } + if (!strcmp(cp, FSTAB_SW)) { + _fs_fstab.fs_type = FSTAB_SW; + break; + } + if (!strcmp(cp, FSTAB_XX)) { + _fs_fstab.fs_type = FSTAB_XX; + typexx++; + break; + } + } + if (typexx) + continue; + if (cp != NULL) + return(1); + +bad: /* no way to distinguish between EOF and syntax error */ + error(EFTYPE); + } + /* NOTREACHED */ +} + +struct fstab * +getfsent() +{ + if (!_fs_fp && !setfsent() || !fstabscan()) + return((struct fstab *)NULL); + return(&_fs_fstab); +} + +struct fstab * +getfsspec(name) + register const char *name; +{ + if (setfsent()) + while (fstabscan()) + if (!strcmp(_fs_fstab.fs_spec, name)) + return(&_fs_fstab); + return((struct fstab *)NULL); +} + +struct fstab * +getfsfile(name) + register const char *name; +{ + if (setfsent()) + while (fstabscan()) + if (!strcmp(_fs_fstab.fs_file, name)) + return(&_fs_fstab); + return((struct fstab *)NULL); +} + +setfsent() +{ + if (_fs_fp) { + rewind(_fs_fp); + return(1); + } + if (_fs_fp = fopen(_PATH_FSTAB, "r")) + return(1); + error(errno); + return(0); +} + +void +endfsent() +{ + if (_fs_fp) { + (void)fclose(_fs_fp); + _fs_fp = NULL; + } +} + +static +error(err) + int err; +{ + char *p; + + (void)write(STDERR_FILENO, "fstab: ", 7); + (void)write(STDERR_FILENO, _PATH_FSTAB, sizeof(_PATH_FSTAB) - 1); + (void)write(STDERR_FILENO, ": ", 1); + p = strerror(err); + (void)write(STDERR_FILENO, p, strlen(p)); + (void)write(STDERR_FILENO, "\n", 1); +} diff --git a/gen/ftok.3 b/gen/ftok.3 new file mode 100644 index 0000000..b706e88 --- /dev/null +++ b/gen/ftok.3 @@ -0,0 +1,85 @@ +.\" Copyright (c) 1994 SigmaSoft, Th. Lockert +.\" 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. 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 BY THE AUTHOR ``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 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/ftok.3,v 1.14 2001/10/01 16:08:50 ru Exp $ +.Dd June 24, 1994 +.Os +.Dt FTOK 3 +.Sh NAME +.Nm ftok +.Nd create IPC identifier from path name +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In sys/types.h +.In sys/ipc.h +.Ft key_t +.Fn ftok "const char *path" "int id" +.Sh DESCRIPTION +.Bf -symbolic +This function is available from the compatibility library, libcompat. +.Ef +The +.Fn ftok +function attempts to create a unique key suitable for use with the +.Xr msgget 3 , +.Xr semget 2 +and +.Xr shmget 2 +functions given the +.Fa path +of an existing file and a user-selectable +.Fa id . +.Pp +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 +same key, given the same +.Fa id . +.Sh RETURN VALUES +The +.Fn ftok +function will return -1 if +.Fa path +does not exist or if it cannot be accessed by the calling process. +.Sh SEE ALSO +.Xr semget 2 , +.Xr shmget 2 , +.Xr msgget 3 +.Sh HISTORY +The +.Fn ftok +function originates with System V and is typically used by programs +that use the System V IPC routines. +.Sh AUTHORS +.An Thorsten Lockert Aq tholo@sigmasoft.com +.Sh BUGS +The returned key is computed based on the device minor number and inode of the +specified +.Fa path +in combination with the lower 8 bits of the given +.Fa id . +Thus it is quite possible for the routine to return duplicate keys. diff --git a/gen/ftok.c b/gen/ftok.c new file mode 100644 index 0000000..fc70f62 --- /dev/null +++ b/gen/ftok.c @@ -0,0 +1,47 @@ +/* + * Copyright (c) 1994 SigmaSoft, Th. Lockert + * 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. 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 BY THE AUTHOR ``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 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 *rcsid = "$Id: ftok.c,v 1.1.1.1 1999/10/14 21:08:51 wsanchez Exp $"; +#endif /* LIBC_SCCS and not lint */ + +#include +#include +#include + +key_t +ftok(path, id) + const char *path; + int id; +{ + struct stat st; + + if (stat(path, &st) < 0) + return (key_t)-1; + + return (key_t) ((id & 0xff) << 24 | (st.st_dev & 0xff) << 16 | (st.st_ino & 0xffff)); +} diff --git a/gen/fts.3 b/gen/fts.3 new file mode 100644 index 0000000..9a02ab3 --- /dev/null +++ b/gen/fts.3 @@ -0,0 +1,761 @@ +.\" Copyright (c) 1989, 1991, 1993, 1994 +.\" 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. +.\" +.\" @(#)fts.3 8.5 (Berkeley) 4/16/94 +.\" $FreeBSD: src/lib/libc/gen/fts.3,v 1.13 2001/09/20 12:32:45 ru Exp $ +.\" +.Dd April 16, 1994 +.Dt FTS 3 +.Os +.Sh NAME +.Nm fts +.Nd traverse a file hierarchy +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In sys/types.h +.In sys/stat.h +.In fts.h +.Ft FTS * +.Fn fts_open "char * const *path_argv" "int options" "int (*compar)(const FTSENT **, const FTSENT **)" +.Ft FTSENT * +.Fn fts_read "FTS *ftsp" +.Ft FTSENT * +.Fn fts_children "FTS *ftsp" "int options" +.Ft int +.Fn fts_set "FTS *ftsp" "FTSENT *f" "int options" +.Ft int +.Fn fts_close "FTS *ftsp" +.Sh DESCRIPTION +The +.Nm +functions are provided for traversing +.Tn UNIX +file hierarchies. +A simple overview is that the +.Fn fts_open +function returns a +.Dq handle +on a file hierarchy, which is then supplied to +the other +.Nm +functions. +The function +.Fn fts_read +returns a pointer to a structure describing one of the files in the file +hierarchy. +The function +.Fn fts_children +returns a pointer to a linked list of structures, each of which describes +one of the files contained in a directory in the hierarchy. +In general, directories are visited two distinguishable times; in pre-order +(before any of their descendants are visited) and in post-order (after all +of their descendants have been visited). +Files are visited once. +It is possible to walk the hierarchy +.Dq logically +(ignoring symbolic links) +or physically (visiting symbolic links), order the walk of the hierarchy or +prune and/or re-visit portions of the hierarchy. +.Pp +Two structures are defined (and typedef'd) in the include file +.Aq Pa fts.h . +The first is +.Fa FTS , +the structure that represents the file hierarchy itself. +The second is +.Fa FTSENT , +the structure that represents a file in the file +hierarchy. +Normally, an +.Fa FTSENT +structure is returned for every file in the file +hierarchy. +In this manual page, +.Dq file +and +.Dq Fa FTSENT No structure +are generally +interchangeable. +The +.Fa FTSENT +structure contains at least the following fields, which are +described in greater detail below: +.Bd -literal +typedef struct _ftsent { + u_short fts_info; /* flags for FTSENT structure */ + char *fts_accpath; /* access path */ + char *fts_path; /* root path */ + u_short fts_pathlen; /* strlen(fts_path) */ + char *fts_name; /* file name */ + u_short fts_namelen; /* strlen(fts_name) */ + short fts_level; /* depth (\-1 to N) */ + int fts_errno; /* file errno */ + long fts_number; /* local numeric value */ + void *fts_pointer; /* local address value */ + struct ftsent *fts_parent; /* parent directory */ + struct ftsent *fts_link; /* next file structure */ + struct ftsent *fts_cycle; /* cycle structure */ + struct stat *fts_statp; /* stat(2) information */ +} FTSENT; +.Ed +.Pp +These fields are defined as follows: +.Bl -tag -width "fts_namelen" +.It Fa fts_info +One of the following values describing the returned +.Fa FTSENT +structure and +the file it represents. +With the exception of directories without errors +.Pq Dv FTS_D , +all of these +entries are terminal, that is, they will not be revisited, nor will any +of their descendants be visited. +.Bl -tag -width FTS_DEFAULT +.It Dv FTS_D +A directory being visited in pre-order. +.It Dv FTS_DC +A directory that causes a cycle in the tree. +(The +.Fa fts_cycle +field of the +.Fa FTSENT +structure will be filled in as well.) +.It Dv FTS_DEFAULT +Any +.Fa FTSENT +structure that represents a file type not explicitly described +by one of the other +.Fa fts_info +values. +.It Dv FTS_DNR +A directory which cannot be read. +This is an error return, and the +.Fa fts_errno +field will be set to indicate what caused the error. +.It Dv FTS_DOT +A file named +.Ql .\& +or +.Ql ..\& +which was not specified as a file name to +.Fn fts_open +(see +.Dv FTS_SEEDOT ) . +.It Dv FTS_DP +A directory being visited in post-order. +The contents of the +.Fa FTSENT +structure will be unchanged from when +it was returned in pre-order, i.e. with the +.Fa fts_info +field set to +.Dv FTS_D . +.It Dv FTS_ERR +This is an error return, and the +.Fa fts_errno +field will be set to indicate what caused the error. +.It Dv FTS_F +A regular file. +.It Dv FTS_NS +A file for which no +.Xr stat 2 +information was available. +The contents of the +.Fa fts_statp +field are undefined. +This is an error return, and the +.Fa fts_errno +field will be set to indicate what caused the error. +.It Dv FTS_NSOK +A file for which no +.Xr stat 2 +information was requested. +The contents of the +.Fa fts_statp +field are undefined. +.It Dv FTS_SL +A symbolic link. +.It Dv FTS_SLNONE +A symbolic link with a non-existent target. +The contents of the +.Fa fts_statp +field reference the file characteristic information for the symbolic link +itself. +.El +.It Fa fts_accpath +A path for accessing the file from the current directory. +.It Fa fts_path +The path for the file relative to the root of the traversal. +This path contains the path specified to +.Fn fts_open +as a prefix. +.It Fa fts_pathlen +The length of the string referenced by +.Fa fts_path . +.It Fa fts_name +The name of the file. +.It Fa fts_namelen +The length of the string referenced by +.Fa fts_name . +.It Fa fts_level +The depth of the traversal, numbered from \-1 to N, where this file +was found. +The +.Fa FTSENT +structure representing the parent of the starting point (or root) +of the traversal is numbered +.Dv FTS_ROOTPARENTLEVEL +(\-1), and the +.Fa FTSENT +structure for the root +itself is numbered +.Dv FTS_ROOTLEVEL +(0). +.It Fa fts_errno +Upon return of a +.Fa FTSENT +structure from the +.Fn fts_children +or +.Fn fts_read +functions, with its +.Fa fts_info +field set to +.Dv FTS_DNR , +.Dv FTS_ERR +or +.Dv FTS_NS , +the +.Fa fts_errno +field contains the value of the external variable +.Va errno +specifying the cause of the error. +Otherwise, the contents of the +.Fa fts_errno +field are undefined. +.It Fa fts_number +This field is provided for the use of the application program and is +not modified by the +.Nm +functions. +It is initialized to 0. +.It Fa fts_pointer +This field is provided for the use of the application program and is +not modified by the +.Nm +functions. +It is initialized to +.Dv NULL . +.It Fa fts_parent +A pointer to the +.Fa FTSENT +structure referencing the file in the hierarchy +immediately above the current file, i.e. the directory of which this +file is a member. +A parent structure for the initial entry point is provided as well, +however, only the +.Fa fts_level , +.Fa fts_number +and +.Fa fts_pointer +fields are guaranteed to be initialized. +.It Fa fts_link +Upon return from the +.Fn fts_children +function, the +.Fa fts_link +field points to the next structure in the NULL-terminated linked list of +directory members. +Otherwise, the contents of the +.Fa fts_link +field are undefined. +.It Fa fts_cycle +If a directory causes a cycle in the hierarchy (see +.Dv FTS_DC ) , +either because +of a hard link between two directories, or a symbolic link pointing to a +directory, the +.Fa fts_cycle +field of the structure will point to the +.Fa FTSENT +structure in the hierarchy that references the same file as the current +.Fa FTSENT +structure. +Otherwise, the contents of the +.Fa fts_cycle +field are undefined. +.It Fa fts_statp +A pointer to +.Xr stat 2 +information for the file. +.El +.Pp +A single buffer is used for all of the paths of all of the files in the +file hierarchy. +Therefore, the +.Fa fts_path +and +.Fa fts_accpath +fields are guaranteed to be +.Dv NUL Ns -terminated +.Em only +for the file most recently returned by +.Fn fts_read . +To use these fields to reference any files represented by other +.Fa FTSENT +structures will require that the path buffer be modified using the +information contained in that +.Fa FTSENT +structure's +.Fa fts_pathlen +field. +Any such modifications should be undone before further calls to +.Fn fts_read +are attempted. +The +.Fa fts_name +field is always +.Dv NUL Ns -terminated . +.Sh FTS_OPEN +The +.Fn fts_open +function takes a pointer to an array of character pointers naming one +or more paths which make up a logical file hierarchy to be traversed. +The array must be terminated by a +.Dv NULL +pointer. +.Pp +There are +a number of options, at least one of which (either +.Dv FTS_LOGICAL +or +.Dv FTS_PHYSICAL ) +must be specified. +The options are selected by +.Em or Ns 'ing +the following values: +.Bl -tag -width "FTS_PHYSICAL" +.It Dv FTS_COMFOLLOW +This option causes any symbolic link specified as a root path to be +followed immediately whether or not +.Dv FTS_LOGICAL +is also specified. +.It Dv FTS_LOGICAL +This option causes the +.Nm +routines to return +.Fa FTSENT +structures for the targets of symbolic links +instead of the symbolic links themselves. +If this option is set, the only symbolic links for which +.Fa FTSENT +structures +are returned to the application are those referencing non-existent files. +Either +.Dv FTS_LOGICAL +or +.Dv FTS_PHYSICAL +.Em must +be provided to the +.Fn fts_open +function. +.It Dv FTS_NOCHDIR +As a performance optimization, the +.Nm +functions change directories as they walk the file hierarchy. +This has the side-effect that an application cannot rely on being +in any particular directory during the traversal. +The +.Dv FTS_NOCHDIR +option turns off this optimization, and the +.Nm +functions will not change the current directory. +Note that applications should not themselves change their current directory +and try to access files unless +.Dv FTS_NOCHDIR +is specified and absolute +pathnames were provided as arguments to +.Fn fts_open . +.It Dv FTS_NOSTAT +By default, returned +.Fa FTSENT +structures reference file characteristic information (the +.Fa statp +field) for each file visited. +This option relaxes that requirement as a performance optimization, +allowing the +.Nm +functions to set the +.Fa fts_info +field to +.Dv FTS_NSOK +and leave the contents of the +.Fa statp +field undefined. +.It Dv FTS_PHYSICAL +This option causes the +.Nm +routines to return +.Fa FTSENT +structures for symbolic links themselves instead +of the target files they point to. +If this option is set, +.Fa FTSENT +structures for all symbolic links in the +hierarchy are returned to the application. +Either +.Dv FTS_LOGICAL +or +.Dv FTS_PHYSICAL +.Em must +be provided to the +.Fn fts_open +function. +.It Dv FTS_SEEDOT +By default, unless they are specified as path arguments to +.Fn fts_open , +any files named +.Ql .\& +or +.Ql ..\& +encountered in the file hierarchy are ignored. +This option causes the +.Nm +routines to return +.Fa FTSENT +structures for them. +.It Dv FTS_XDEV +This option prevents +.Nm +from descending into directories that have a different device number +than the file from which the descent began. +.El +.Pp +The argument +.Fn compar +specifies a user-defined function which may be used to order the traversal +of the hierarchy. +It +takes two pointers to pointers to +.Fa FTSENT +structures as arguments and +should return a negative value, zero, or a positive value to indicate +if the file referenced by its first argument comes before, in any order +with respect to, or after, the file referenced by its second argument. +The +.Fa fts_accpath , +.Fa fts_path +and +.Fa fts_pathlen +fields of the +.Fa FTSENT +structures may +.Em never +be used in this comparison. +If the +.Fa fts_info +field is set to +.Dv FTS_NS +or +.Dv FTS_NSOK , +the +.Fa fts_statp +field may not either. +If the +.Fn compar +argument is +.Dv NULL , +the directory traversal order is in the order listed in +.Fa path_argv +for the root paths, and in the order listed in the directory for +everything else. +.Sh FTS_READ +The +.Fn fts_read +function returns a pointer to an +.Fa FTSENT +structure describing a file in +the hierarchy. +Directories (that are readable and do not cause cycles) are visited at +least twice, once in pre-order and once in post-order. +All other files are visited at least once. +(Hard links between directories that do not cause cycles or symbolic +links to symbolic links may cause files to be visited more than once, +or directories more than twice.) +.Pp +If all the members of the hierarchy have been returned, +.Fn fts_read +returns +.Dv NULL +and sets the external variable +.Va errno +to 0. +If an error unrelated to a file in the hierarchy occurs, +.Fn fts_read +returns +.Dv NULL +and sets +.Va errno +appropriately. +If an error related to a returned file occurs, a pointer to an +.Fa FTSENT +structure is returned, and +.Va errno +may or may not have been set (see +.Fa fts_info ) . +.Pp +The +.Fa FTSENT +structures returned by +.Fn fts_read +may be overwritten after a call to +.Fn fts_close +on the same file hierarchy stream, or, after a call to +.Fn fts_read +on the same file hierarchy stream unless they represent a file of type +directory, in which case they will not be overwritten until after a call to +.Fn fts_read +after the +.Fa FTSENT +structure has been returned by the function +.Fn fts_read +in post-order. +.Sh FTS_CHILDREN +The +.Fn fts_children +function returns a pointer to an +.Fa FTSENT +structure describing the first entry in a NULL-terminated linked list of +the files in the directory represented by the +.Fa FTSENT +structure most recently returned by +.Fn fts_read . +The list is linked through the +.Fa fts_link +field of the +.Fa FTSENT +structure, and is ordered by the user-specified comparison function, if any. +Repeated calls to +.Fn fts_children +will recreate this linked list. +.Pp +As a special case, if +.Fn fts_read +has not yet been called for a hierarchy, +.Fn fts_children +will return a pointer to the files in the logical directory specified to +.Fn fts_open , +i.e. the arguments specified to +.Fn fts_open . +Otherwise, if the +.Fa FTSENT +structure most recently returned by +.Fn fts_read +is not a directory being visited in pre-order, +or the directory does not contain any files, +.Fn fts_children +returns +.Dv NULL +and sets +.Va errno +to zero. +If an error occurs, +.Fn fts_children +returns +.Dv NULL +and sets +.Va errno +appropriately. +.Pp +The +.Fa FTSENT +structures returned by +.Fn fts_children +may be overwritten after a call to +.Fn fts_children , +.Fn fts_close +or +.Fn fts_read +on the same file hierarchy stream. +.Pp +.Em Option +may be set to the following value: +.Bl -tag -width FTS_NAMEONLY +.It Dv FTS_NAMEONLY +Only the names of the files are needed. +The contents of all the fields in the returned linked list of structures +are undefined with the exception of the +.Fa fts_name +and +.Fa fts_namelen +fields. +.El +.Sh FTS_SET +The function +.Fn fts_set +allows the user application to determine further processing for the +file +.Fa f +of the stream +.Fa ftsp . +The +.Fn fts_set +function +returns 0 on success, and \-1 if an error occurs. +.Em Option +must be set to one of the following values: +.Bl -tag -width FTS_PHYSICAL +.It Dv FTS_AGAIN +Re-visit the file; any file type may be re-visited. +The next call to +.Fn fts_read +will return the referenced file. +The +.Fa fts_stat +and +.Fa fts_info +fields of the structure will be reinitialized at that time, +but no other fields will have been changed. +This option is meaningful only for the most recently returned +file from +.Fn fts_read . +Normal use is for post-order directory visits, where it causes the +directory to be re-visited (in both pre and post-order) as well as all +of its descendants. +.It Dv FTS_FOLLOW +The referenced file must be a symbolic link. +If the referenced file is the one most recently returned by +.Fn fts_read , +the next call to +.Fn fts_read +returns the file with the +.Fa fts_info +and +.Fa fts_statp +fields reinitialized to reflect the target of the symbolic link instead +of the symbolic link itself. +If the file is one of those most recently returned by +.Fn fts_children , +the +.Fa fts_info +and +.Fa fts_statp +fields of the structure, when returned by +.Fn fts_read , +will reflect the target of the symbolic link instead of the symbolic link +itself. +In either case, if the target of the symbolic link does not exist the +fields of the returned structure will be unchanged and the +.Fa fts_info +field will be set to +.Dv FTS_SLNONE . +.Pp +If the target of the link is a directory, the pre-order return, followed +by the return of all of its descendants, followed by a post-order return, +is done. +.It Dv FTS_SKIP +No descendants of this file are visited. +The file may be one of those most recently returned by either +.Fn fts_children +or +.Fn fts_read . +.El +.Sh FTS_CLOSE +The +.Fn fts_close +function closes a file hierarchy stream +.Fa ftsp +and restores the current directory to the directory from which +.Fn fts_open +was called to open +.Fa ftsp . +The +.Fn fts_close +function +returns 0 on success, and \-1 if an error occurs. +.Sh ERRORS +The function +.Fn fts_open +may fail and set +.Va errno +for any of the errors specified for the library functions +.Xr open 2 +and +.Xr malloc 3 . +.Pp +The function +.Fn fts_close +may fail and set +.Va errno +for any of the errors specified for the library functions +.Xr chdir 2 +and +.Xr close 2 . +.Pp +The functions +.Fn fts_read +and +.Fn fts_children +may fail and set +.Va errno +for any of the errors specified for the library functions +.Xr chdir 2 , +.Xr malloc 3 , +.Xr opendir 3 , +.Xr readdir 3 +and +.Xr stat 2 . +.Pp +In addition, +.Fn fts_children , +.Fn fts_open +and +.Fn fts_set +may fail and set +.Va errno +as follows: +.Bl -tag -width Er +.It Bq Er EINVAL +The options were invalid. +.El +.Sh SEE ALSO +.Xr find 1 , +.Xr chdir 2 , +.Xr stat 2 , +.Xr qsort 3 +.Sh STANDARDS +The +.Nm +utility is expected to be included in a future +.St -p1003.1-88 +revision. diff --git a/gen/fts.c b/gen/fts.c new file mode 100644 index 0000000..75576d7 --- /dev/null +++ b/gen/fts.c @@ -0,0 +1,1015 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 1993, 1994 + * 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 +#include + +#include +#include +#include +#include +#include +#include +#include + +static FTSENT *fts_alloc __P((FTS *, char *, int)); +static FTSENT *fts_build __P((FTS *, int)); +static void fts_lfree __P((FTSENT *)); +static void fts_load __P((FTS *, FTSENT *)); +static size_t fts_maxarglen __P((char * const *)); +static void fts_padjust __P((FTS *, void *)); +static int fts_palloc __P((FTS *, size_t)); +static FTSENT *fts_sort __P((FTS *, FTSENT *, int)); +static u_short fts_stat __P((FTS *, FTSENT *, int)); + +#define ISDOT(a) (a[0] == '.' && (!a[1] || a[1] == '.' && !a[2])) + +#define ISSET(opt) (sp->fts_options & opt) +#define SET(opt) (sp->fts_options |= opt) + +#define CHDIR(sp, path) (!ISSET(FTS_NOCHDIR) && chdir(path)) +#define FCHDIR(sp, fd) (!ISSET(FTS_NOCHDIR) && fchdir(fd)) + +/* fts_build flags */ +#define BCHILD 1 /* fts_children */ +#define BNAMES 2 /* fts_children, names only */ +#define BREAD 3 /* fts_read */ + +FTS * +fts_open(argv, options, compar) + char * const *argv; + register int options; + int (*compar)(); +{ + register FTS *sp; + register FTSENT *p, *root; + register int nitems; + FTSENT *parent, *tmp; + int len; + + /* Options check. */ + if (options & ~FTS_OPTIONMASK) { + errno = EINVAL; + return (NULL); + } + + /* Allocate/initialize the stream */ + if ((sp = malloc((u_int)sizeof(FTS))) == NULL) + return (NULL); + memset(sp, 0, sizeof(FTS)); + sp->fts_compar = compar; + sp->fts_options = options; + + /* Logical walks turn on NOCHDIR; symbolic links are too hard. */ + if (ISSET(FTS_LOGICAL)) + SET(FTS_NOCHDIR); + + /* + * Start out with 1K of path space, and enough, in any case, + * to hold the user's paths. + */ + if (fts_palloc(sp, MAX(fts_maxarglen(argv), MAXPATHLEN))) + goto mem1; + + /* Allocate/initialize root's parent. */ + if ((parent = fts_alloc(sp, "", 0)) == NULL) + goto mem2; + parent->fts_level = FTS_ROOTPARENTLEVEL; + + /* Allocate/initialize root(s). */ + for (root = NULL, nitems = 0; *argv; ++argv, ++nitems) { + /* Don't allow zero-length paths. */ + if ((len = strlen(*argv)) == 0) { + errno = ENOENT; + goto mem3; + } + + p = fts_alloc(sp, *argv, len); + p->fts_level = FTS_ROOTLEVEL; + p->fts_parent = parent; + p->fts_accpath = p->fts_name; + p->fts_info = fts_stat(sp, p, ISSET(FTS_COMFOLLOW)); + + /* Command-line "." and ".." are real directories. */ + if (p->fts_info == FTS_DOT) + p->fts_info = FTS_D; + + /* + * If comparison routine supplied, traverse in sorted + * order; otherwise traverse in the order specified. + */ + if (compar) { + p->fts_link = root; + root = p; + } else { + p->fts_link = NULL; + if (root == NULL) + tmp = root = p; + else { + tmp->fts_link = p; + tmp = p; + } + } + } + if (compar && nitems > 1) + root = fts_sort(sp, root, nitems); + + /* + * Allocate a dummy pointer and make fts_read think that we've just + * finished the node before the root(s); set p->fts_info to FTS_INIT + * so that everything about the "current" node is ignored. + */ + if ((sp->fts_cur = fts_alloc(sp, "", 0)) == NULL) + goto mem3; + sp->fts_cur->fts_link = root; + sp->fts_cur->fts_info = FTS_INIT; + + /* + * If using chdir(2), grab a file descriptor pointing to dot to insure + * that we can get back here; this could be avoided for some paths, + * but almost certainly not worth the effort. Slashes, symbolic links, + * and ".." are all fairly nasty problems. Note, if we can't get the + * descriptor we run anyway, just more slowly. + */ + if (!ISSET(FTS_NOCHDIR) && (sp->fts_rfd = open(".", O_RDONLY, 0)) < 0) + SET(FTS_NOCHDIR); + + return (sp); + +mem3: fts_lfree(root); + free(parent); +mem2: free(sp->fts_path); +mem1: free(sp); + return (NULL); +} + +static void +fts_load(sp, p) + FTS *sp; + register FTSENT *p; +{ + register int len; + register char *cp; + + /* + * Load the stream structure for the next traversal. Since we don't + * actually enter the directory until after the preorder visit, set + * the fts_accpath field specially so the chdir gets done to the right + * place and the user can access the first node. From fts_open it's + * known that the path will fit. + */ + len = p->fts_pathlen = p->fts_namelen; + memmove(sp->fts_path, p->fts_name, len + 1); + if ((cp = strrchr(p->fts_name, '/')) && (cp != p->fts_name || cp[1])) { + len = strlen(++cp); + memmove(p->fts_name, cp, len + 1); + p->fts_namelen = len; + } + p->fts_accpath = p->fts_path = sp->fts_path; + sp->fts_dev = p->fts_dev; +} + +int +fts_close(sp) + FTS *sp; +{ + register FTSENT *freep, *p; + int saved_errno = 0; + + /* + * This still works if we haven't read anything -- the dummy structure + * points to the root list, so we step through to the end of the root + * list which has a valid parent pointer. + */ + if (sp->fts_cur) { + for (p = sp->fts_cur; p->fts_level >= FTS_ROOTLEVEL;) { + freep = p; + p = p->fts_link ? p->fts_link : p->fts_parent; + free(freep); + } + free(p); + } + + /* Free up child linked list, sort array, path buffer. */ + if (sp->fts_child) + fts_lfree(sp->fts_child); + if (sp->fts_array) + free(sp->fts_array); + free(sp->fts_path); + + /* Return to original directory, save errno if necessary. */ + if (!ISSET(FTS_NOCHDIR)) { + if (fchdir(sp->fts_rfd)) { + saved_errno = errno; + } + (void)close(sp->fts_rfd); + } + + /* Free up the stream pointer. */ + free(sp); + + /* Set errno and return. */ + if (saved_errno) { + errno = saved_errno; + return (-1); + } + return (0); +} + +/* + * Special case a root of "/" so that slashes aren't appended which would + * cause paths to be written as "//foo". + */ +#define NAPPEND(p) \ + (p->fts_level == FTS_ROOTLEVEL && p->fts_pathlen == 1 && \ + p->fts_path[0] == '/' ? 0 : p->fts_pathlen) + +FTSENT * +fts_read(sp) + register FTS *sp; +{ + register FTSENT *p, *tmp; + register int instr; + register char *t; + int saved_errno; + + /* If finished or unrecoverable error, return NULL. */ + if (sp->fts_cur == NULL || ISSET(FTS_STOP)) + return (NULL); + + /* Set current node pointer. */ + p = sp->fts_cur; + + /* Save and zero out user instructions. */ + instr = p->fts_instr; + p->fts_instr = FTS_NOINSTR; + + /* Any type of file may be re-visited; re-stat and re-turn. */ + if (instr == FTS_AGAIN) { + p->fts_info = fts_stat(sp, p, 0); + return (p); + } + + /* + * Following a symlink -- SLNONE test allows application to see + * SLNONE and recover. If indirecting through a symlink, have + * keep a pointer to current location. If unable to get that + * pointer, follow fails. + */ + if (instr == FTS_FOLLOW && + (p->fts_info == FTS_SL || p->fts_info == FTS_SLNONE)) { + p->fts_info = fts_stat(sp, p, 1); + if (p->fts_info == FTS_D && !ISSET(FTS_NOCHDIR)) + if ((p->fts_symfd = open(".", O_RDONLY, 0)) < 0) { + p->fts_errno = errno; + p->fts_info = FTS_ERR; + } else + p->fts_flags |= FTS_SYMFOLLOW; + return (p); + } + + /* Directory in pre-order. */ + if (p->fts_info == FTS_D) { + /* If skipped or crossed mount point, do post-order visit. */ + if (instr == FTS_SKIP || + ISSET(FTS_XDEV) && p->fts_dev != sp->fts_dev) { + if (p->fts_flags & FTS_SYMFOLLOW) + (void)close(p->fts_symfd); + if (sp->fts_child) { + fts_lfree(sp->fts_child); + sp->fts_child = NULL; + } + p->fts_info = FTS_DP; + return (p); + } + + /* Rebuild if only read the names and now traversing. */ + if (sp->fts_child && sp->fts_options & FTS_NAMEONLY) { + sp->fts_options &= ~FTS_NAMEONLY; + fts_lfree(sp->fts_child); + sp->fts_child = NULL; + } + + /* + * Cd to the subdirectory. + * + * If have already read and now fail to chdir, whack the list + * to make the names come out right, and set the parent errno + * so the application will eventually get an error condition. + * Set the FTS_DONTCHDIR flag so that when we logically change + * directories back to the parent we don't do a chdir. + * + * If haven't read do so. If the read fails, fts_build sets + * FTS_STOP or the fts_info field of the node. + */ + if (sp->fts_child) { + if (CHDIR(sp, p->fts_accpath)) { + p->fts_errno = errno; + p->fts_flags |= FTS_DONTCHDIR; + for (p = sp->fts_child; p; p = p->fts_link) + p->fts_accpath = + p->fts_parent->fts_accpath; + } + } else if ((sp->fts_child = fts_build(sp, BREAD)) == NULL) { + if (ISSET(FTS_STOP)) + return (NULL); + return (p); + } + p = sp->fts_child; + sp->fts_child = NULL; + goto name; + } + + /* Move to the next node on this level. */ +next: tmp = p; + if (p = p->fts_link) { + free(tmp); + + /* + * If reached the top, return to the original directory, and + * load the paths for the next root. + */ + if (p->fts_level == FTS_ROOTLEVEL) { + if (!ISSET(FTS_NOCHDIR) && FCHDIR(sp, sp->fts_rfd)) { + SET(FTS_STOP); + return (NULL); + } + fts_load(sp, p); + return (sp->fts_cur = p); + } + + /* + * User may have called fts_set on the node. If skipped, + * ignore. If followed, get a file descriptor so we can + * get back if necessary. + */ + if (p->fts_instr == FTS_SKIP) + goto next; + if (p->fts_instr == FTS_FOLLOW) { + p->fts_info = fts_stat(sp, p, 1); + if (p->fts_info == FTS_D && !ISSET(FTS_NOCHDIR)) + if ((p->fts_symfd = + open(".", O_RDONLY, 0)) < 0) { + p->fts_errno = errno; + p->fts_info = FTS_ERR; + } else + p->fts_flags |= FTS_SYMFOLLOW; + p->fts_instr = FTS_NOINSTR; + } + +name: t = sp->fts_path + NAPPEND(p->fts_parent); + *t++ = '/'; + memmove(t, p->fts_name, p->fts_namelen + 1); + return (sp->fts_cur = p); + } + + /* Move up to the parent node. */ + p = tmp->fts_parent; + free(tmp); + + if (p->fts_level == FTS_ROOTPARENTLEVEL) { + /* + * Done; free everything up and set errno to 0 so the user + * can distinguish between error and EOF. + */ + free(p); + errno = 0; + return (sp->fts_cur = NULL); + } + + /* Nul terminate the pathname. */ + sp->fts_path[p->fts_pathlen] = '\0'; + + /* + * Return to the parent directory. If at a root node or came through + * a symlink, go back through the file descriptor. Otherwise, cd up + * one directory. + */ + if (p->fts_level == FTS_ROOTLEVEL) { + if (!ISSET(FTS_NOCHDIR) && FCHDIR(sp, sp->fts_rfd)) { + SET(FTS_STOP); + return (NULL); + } + } else if (p->fts_flags & FTS_SYMFOLLOW) { + if (FCHDIR(sp, p->fts_symfd)) { + saved_errno = errno; + (void)close(p->fts_symfd); + errno = saved_errno; + SET(FTS_STOP); + return (NULL); + } + (void)close(p->fts_symfd); + } else if (!(p->fts_flags & FTS_DONTCHDIR)) { + if (CHDIR(sp, "..")) { + SET(FTS_STOP); + return (NULL); + } + } + p->fts_info = p->fts_errno ? FTS_ERR : FTS_DP; + return (sp->fts_cur = p); +} + +/* + * Fts_set takes the stream as an argument although it's not used in this + * implementation; it would be necessary if anyone wanted to add global + * semantics to fts using fts_set. An error return is allowed for similar + * reasons. + */ +/* ARGSUSED */ +int +fts_set(sp, p, instr) + FTS *sp; + FTSENT *p; + int instr; +{ + if (instr && instr != FTS_AGAIN && instr != FTS_FOLLOW && + instr != FTS_NOINSTR && instr != FTS_SKIP) { + errno = EINVAL; + return (1); + } + p->fts_instr = instr; + return (0); +} + +FTSENT * +fts_children(sp, instr) + register FTS *sp; + int instr; +{ + register FTSENT *p; + int fd; + + if (instr && instr != FTS_NAMEONLY) { + errno = EINVAL; + return (NULL); + } + + /* Set current node pointer. */ + p = sp->fts_cur; + + /* + * Errno set to 0 so user can distinguish empty directory from + * an error. + */ + errno = 0; + + /* Fatal errors stop here. */ + if (ISSET(FTS_STOP)) + return (NULL); + + /* Return logical hierarchy of user's arguments. */ + if (p->fts_info == FTS_INIT) + return (p->fts_link); + + /* + * If not a directory being visited in pre-order, stop here. Could + * allow FTS_DNR, assuming the user has fixed the problem, but the + * same effect is available with FTS_AGAIN. + */ + if (p->fts_info != FTS_D /* && p->fts_info != FTS_DNR */) + return (NULL); + + /* Free up any previous child list. */ + if (sp->fts_child) + fts_lfree(sp->fts_child); + + if (instr == FTS_NAMEONLY) { + sp->fts_options |= FTS_NAMEONLY; + instr = BNAMES; + } else + instr = BCHILD; + + /* + * If using chdir on a relative path and called BEFORE fts_read does + * its chdir to the root of a traversal, we can lose -- we need to + * chdir into the subdirectory, and we don't know where the current + * directory is, so we can't get back so that the upcoming chdir by + * fts_read will work. + */ + if (p->fts_level != FTS_ROOTLEVEL || p->fts_accpath[0] == '/' || + ISSET(FTS_NOCHDIR)) + return (sp->fts_child = fts_build(sp, instr)); + + if ((fd = open(".", O_RDONLY, 0)) < 0) + return (NULL); + sp->fts_child = fts_build(sp, instr); + if (fchdir(fd)) + return (NULL); + (void)close(fd); + return (sp->fts_child); +} + +/* + * This is the tricky part -- do not casually change *anything* in here. The + * idea is to build the linked list of entries that are used by fts_children + * and fts_read. There are lots of special cases. + * + * The real slowdown in walking the tree is the stat calls. If FTS_NOSTAT is + * set and it's a physical walk (so that symbolic links can't be directories), + * we can do things quickly. First, if it's a 4.4BSD file system, the type + * of the file is in the directory entry. Otherwise, we assume that the number + * of subdirectories in a node is equal to the number of links to the parent. + * The former skips all stat calls. The latter skips stat calls in any leaf + * directories and for any files after the subdirectories in the directory have + * been found, cutting the stat calls by about 2/3. + */ +static FTSENT * +fts_build(sp, type) + register FTS *sp; + int type; +{ + register struct dirent *dp; + register FTSENT *p, *head; + register int nitems; + FTSENT *cur, *tail; + DIR *dirp; + void *adjaddr; + int cderrno, descend, len, level, maxlen, nlinks, oflag, saved_errno; + char *cp; + + /* Set current node pointer. */ + cur = sp->fts_cur; + + /* + * Open the directory for reading. If this fails, we're done. + * If being called from fts_read, set the fts_info field. + */ +#ifdef FTS_WHITEOUT + if (ISSET(FTS_WHITEOUT)) + oflag = DTF_NODUP|DTF_REWIND; + else + oflag = DTF_HIDEW|DTF_NODUP|DTF_REWIND; +#else +#define __opendir2(path, flag) opendir(path) +#endif + if ((dirp = __opendir2(cur->fts_accpath, oflag)) == NULL) { + if (type == BREAD) { + cur->fts_info = FTS_DNR; + cur->fts_errno = errno; + } + return (NULL); + } + + /* + * Nlinks is the number of possible entries of type directory in the + * directory if we're cheating on stat calls, 0 if we're not doing + * any stat calls at all, -1 if we're doing stats on everything. + */ + if (type == BNAMES) + nlinks = 0; + else if (ISSET(FTS_NOSTAT) && ISSET(FTS_PHYSICAL)) + nlinks = cur->fts_nlink - (ISSET(FTS_SEEDOT) ? 0 : 2); + else + nlinks = -1; + +#ifdef notdef + (void)printf("nlinks == %d (cur: %d)\n", nlinks, cur->fts_nlink); + (void)printf("NOSTAT %d PHYSICAL %d SEEDOT %d\n", + ISSET(FTS_NOSTAT), ISSET(FTS_PHYSICAL), ISSET(FTS_SEEDOT)); +#endif + /* + * If we're going to need to stat anything or we want to descend + * and stay in the directory, chdir. If this fails we keep going, + * but set a flag so we don't chdir after the post-order visit. + * We won't be able to stat anything, but we can still return the + * names themselves. Note, that since fts_read won't be able to + * chdir into the directory, it will have to return different path + * names than before, i.e. "a/b" instead of "b". Since the node + * has already been visited in pre-order, have to wait until the + * post-order visit to return the error. There is a special case + * here, if there was nothing to stat then it's not an error to + * not be able to stat. This is all fairly nasty. If a program + * needed sorted entries or stat information, they had better be + * checking FTS_NS on the returned nodes. + */ + cderrno = 0; + if (nlinks || type == BREAD) + if (FCHDIR(sp, dirfd(dirp))) { + if (nlinks && type == BREAD) + cur->fts_errno = errno; + cur->fts_flags |= FTS_DONTCHDIR; + descend = 0; + cderrno = errno; + } else + descend = 1; + else + descend = 0; + + /* + * Figure out the max file name length that can be stored in the + * current path -- the inner loop allocates more path as necessary. + * We really wouldn't have to do the maxlen calculations here, we + * could do them in fts_read before returning the path, but it's a + * lot easier here since the length is part of the dirent structure. + * + * If not changing directories set a pointer so that can just append + * each new name into the path. + */ + maxlen = sp->fts_pathlen - cur->fts_pathlen - 1; + len = NAPPEND(cur); + if (ISSET(FTS_NOCHDIR)) { + cp = sp->fts_path + len; + *cp++ = '/'; + } + + level = cur->fts_level + 1; + + /* Read the directory, attaching each entry to the `link' pointer. */ + adjaddr = NULL; + for (head = tail = NULL, nitems = 0; dp = readdir(dirp);) { + if (!ISSET(FTS_SEEDOT) && ISDOT(dp->d_name)) + continue; + + if ((p = fts_alloc(sp, dp->d_name, (int)dp->d_namlen)) == NULL) + goto mem1; + if (dp->d_namlen > maxlen) { + if (fts_palloc(sp, (size_t)dp->d_namlen)) { + /* + * No more memory for path or structures. Save + * errno, free up the current structure and the + * structures already allocated. + */ +mem1: saved_errno = errno; + if (p) + free(p); + fts_lfree(head); + (void)closedir(dirp); + errno = saved_errno; + cur->fts_info = FTS_ERR; + SET(FTS_STOP); + return (NULL); + } + adjaddr = sp->fts_path; + maxlen = sp->fts_pathlen - sp->fts_cur->fts_pathlen - 1; + } + + p->fts_pathlen = len + dp->d_namlen + 1; + p->fts_parent = sp->fts_cur; + p->fts_level = level; + +#ifdef FTS_WHITEOUT + if (dp->d_type == DT_WHT) + p->fts_flags |= FTS_ISW; +#endif + + if (cderrno) { + if (nlinks) { + p->fts_info = FTS_NS; + p->fts_errno = cderrno; + } else + p->fts_info = FTS_NSOK; + p->fts_accpath = cur->fts_accpath; + } else if (nlinks == 0 +#ifdef DT_DIR + || nlinks > 0 && + dp->d_type != DT_DIR && dp->d_type != DT_UNKNOWN +#endif + ) { + p->fts_accpath = + ISSET(FTS_NOCHDIR) ? p->fts_path : p->fts_name; + p->fts_info = FTS_NSOK; + } else { + /* Build a file name for fts_stat to stat. */ + if (ISSET(FTS_NOCHDIR)) { + p->fts_accpath = p->fts_path; + memmove(cp, p->fts_name, p->fts_namelen + 1); + } else + p->fts_accpath = p->fts_name; + /* Stat it. */ + p->fts_info = fts_stat(sp, p, 0); + + /* Decrement link count if applicable. */ + if (nlinks > 0 && (p->fts_info == FTS_D || + p->fts_info == FTS_DC || p->fts_info == FTS_DOT)) + --nlinks; + } + + /* We walk in directory order so "ls -f" doesn't get upset. */ + p->fts_link = NULL; + if (head == NULL) + head = tail = p; + else { + tail->fts_link = p; + tail = p; + } + ++nitems; + } + (void)closedir(dirp); + + /* + * If had to realloc the path, adjust the addresses for the rest + * of the tree. + */ + if (adjaddr) + fts_padjust(sp, adjaddr); + + /* + * If not changing directories, reset the path back to original + * state. + */ + if (ISSET(FTS_NOCHDIR)) { + if (cp - 1 > sp->fts_path) + --cp; + *cp = '\0'; + } + + /* + * If descended after called from fts_children or after called from + * fts_read and nothing found, get back. At the root level we use + * the saved fd; if one of fts_open()'s arguments is a relative path + * to an empty directory, we wind up here with no other way back. If + * can't get back, we're done. + */ + if (descend && (type == BCHILD || !nitems) && + (cur->fts_level == FTS_ROOTLEVEL ? + FCHDIR(sp, sp->fts_rfd) : CHDIR(sp, ".."))) { + cur->fts_info = FTS_ERR; + SET(FTS_STOP); + return (NULL); + } + + /* If didn't find anything, return NULL. */ + if (!nitems) { + if (type == BREAD) + cur->fts_info = FTS_DP; + return (NULL); + } + + /* Sort the entries. */ + if (sp->fts_compar && nitems > 1) + head = fts_sort(sp, head, nitems); + return (head); +} + +static u_short +fts_stat(sp, p, follow) + FTS *sp; + register FTSENT *p; + int follow; +{ + register FTSENT *t; + register dev_t dev; + register ino_t ino; + struct stat *sbp, sb; + int saved_errno; + + /* If user needs stat info, stat buffer already allocated. */ + sbp = ISSET(FTS_NOSTAT) ? &sb : p->fts_statp; + +#ifdef FTS_WHITEOUT + /* check for whiteout */ + if (p->fts_flags & FTS_ISW) { + if (sbp != &sb) { + memset(sbp, '\0', sizeof (*sbp)); + sbp->st_mode = S_IFWHT; + } + return (FTS_W); + } +#endif + + /* + * If doing a logical walk, or application requested FTS_FOLLOW, do + * a stat(2). If that fails, check for a non-existent symlink. If + * fail, set the errno from the stat call. + */ + if (ISSET(FTS_LOGICAL) || follow) { + if (stat(p->fts_accpath, sbp)) { + saved_errno = errno; + if (!lstat(p->fts_accpath, sbp)) { + errno = 0; + return (FTS_SLNONE); + } + p->fts_errno = saved_errno; + goto err; + } + } else if (lstat(p->fts_accpath, sbp)) { + p->fts_errno = errno; +err: memset(sbp, 0, sizeof(struct stat)); + return (FTS_NS); + } + + if (S_ISDIR(sbp->st_mode)) { + /* + * Set the device/inode. Used to find cycles and check for + * crossing mount points. Also remember the link count, used + * in fts_build to limit the number of stat calls. It is + * understood that these fields are only referenced if fts_info + * is set to FTS_D. + */ + dev = p->fts_dev = sbp->st_dev; + ino = p->fts_ino = sbp->st_ino; + p->fts_nlink = sbp->st_nlink; + + if (ISDOT(p->fts_name)) + return (FTS_DOT); + + /* + * Cycle detection is done by brute force when the directory + * is first encountered. If the tree gets deep enough or the + * number of symbolic links to directories is high enough, + * something faster might be worthwhile. + */ + for (t = p->fts_parent; + t->fts_level >= FTS_ROOTLEVEL; t = t->fts_parent) + if (ino == t->fts_ino && dev == t->fts_dev) { + p->fts_cycle = t; + return (FTS_DC); + } + return (FTS_D); + } + if (S_ISLNK(sbp->st_mode)) + return (FTS_SL); + if (S_ISREG(sbp->st_mode)) + return (FTS_F); + return (FTS_DEFAULT); +} + +static FTSENT * +fts_sort(sp, head, nitems) + FTS *sp; + FTSENT *head; + register int nitems; +{ + register FTSENT **ap, *p; + + /* + * Construct an array of pointers to the structures and call qsort(3). + * Reassemble the array in the order returned by qsort. If unable to + * sort for memory reasons, return the directory entries in their + * current order. Allocate enough space for the current needs plus + * 40 so don't realloc one entry at a time. + */ + if (nitems > sp->fts_nitems) { + sp->fts_nitems = nitems + 40; + if ((sp->fts_array = realloc(sp->fts_array, + (size_t)(sp->fts_nitems * sizeof(FTSENT *)))) == NULL) { + sp->fts_nitems = 0; + return (head); + } + } + for (ap = sp->fts_array, p = head; p; p = p->fts_link) + *ap++ = p; + qsort((void *)sp->fts_array, nitems, sizeof(FTSENT *), sp->fts_compar); + for (head = *(ap = sp->fts_array); --nitems; ++ap) + ap[0]->fts_link = ap[1]; + ap[0]->fts_link = NULL; + return (head); +} + +static FTSENT * +fts_alloc(sp, name, namelen) + FTS *sp; + char *name; + register int namelen; +{ + register FTSENT *p; + size_t len; + + /* + * The file name is a variable length array and no stat structure is + * necessary if the user has set the nostat bit. Allocate the FTSENT + * structure, the file name and the stat structure in one chunk, but + * be careful that the stat structure is reasonably aligned. Since the + * fts_name field is declared to be of size 1, the fts_name pointer is + * namelen + 2 before the first possible address of the stat structure. + */ + len = sizeof(FTSENT) + namelen; + if (!ISSET(FTS_NOSTAT)) + len += sizeof(struct stat) + ALIGNBYTES; + if ((p = malloc(len)) == NULL) + return (NULL); + + /* Copy the name plus the trailing NULL. */ + memmove(p->fts_name, name, namelen + 1); + + if (!ISSET(FTS_NOSTAT)) + p->fts_statp = (struct stat *)ALIGN(p->fts_name + namelen + 2); + p->fts_namelen = namelen; + p->fts_path = sp->fts_path; + p->fts_errno = 0; + p->fts_flags = 0; + p->fts_instr = FTS_NOINSTR; + p->fts_number = 0; + p->fts_pointer = NULL; + return (p); +} + +static void +fts_lfree(head) + register FTSENT *head; +{ + register FTSENT *p; + + /* Free a linked list of structures. */ + while (p = head) { + head = head->fts_link; + free(p); + } +} + +/* + * Allow essentially unlimited paths; find, rm, ls should all work on any tree. + * Most systems will allow creation of paths much longer than MAXPATHLEN, even + * though the kernel won't resolve them. Add the size (not just what's needed) + * plus 256 bytes so don't realloc the path 2 bytes at a time. + */ +static int +fts_palloc(sp, more) + FTS *sp; + size_t more; +{ + sp->fts_pathlen += more + 256; + sp->fts_path = realloc(sp->fts_path, (size_t)sp->fts_pathlen); + return (sp->fts_path == NULL); +} + +/* + * When the path is realloc'd, have to fix all of the pointers in structures + * already returned. + */ +static void +fts_padjust(sp, addr) + FTS *sp; + void *addr; +{ + FTSENT *p; + +#define ADJUST(p) { \ + (p)->fts_accpath = \ + (char *)addr + ((p)->fts_accpath - (p)->fts_path); \ + (p)->fts_path = addr; \ +} + /* Adjust the current set of children. */ + for (p = sp->fts_child; p; p = p->fts_link) + ADJUST(p); + + /* Adjust the rest of the tree. */ + for (p = sp->fts_cur; p->fts_level >= FTS_ROOTLEVEL;) { + ADJUST(p); + p = p->fts_link ? p->fts_link : p->fts_parent; + } +} + +static size_t +fts_maxarglen(argv) + char * const *argv; +{ + size_t len, max; + + for (max = 0; *argv; ++argv) + if ((len = strlen(*argv)) > max) + max = len; + return (max); +} diff --git a/gen/getbootfile.3 b/gen/getbootfile.3 new file mode 100644 index 0000000..55cb6fe --- /dev/null +++ b/gen/getbootfile.3 @@ -0,0 +1,72 @@ +.\" Copyright (c) 1983, 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. +.\" +.\" From: @(#)gethostname.3 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD: src/lib/libc/gen/getbootfile.3,v 1.9 2001/10/01 16:08:50 ru Exp $ +.\" +.Dd September 23, 1994 +.Dt GETBOOTFILE 3 +.Os +.Sh NAME +.Nm getbootfile +.Nd get kernel boot file name +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In paths.h +.Ft const char * +.Fn getbootfile void +.Sh DESCRIPTION +The +.Fn getbootfile +function retrieves the full pathname of the file from which the +current kernel was loaded, and returns a static pointer to the name. +A read/write interface to this information is available via the +.Xr sysctl 3 +MIB variable +.Dq Li kern.bootfile . +.Sh RETURN VALUES +If the call succeeds a string giving the pathname is returned. If it +fails, a null pointer is returned and an error code is +placed in the global location +.Va errno . +.Sh SEE ALSO +.Xr sysctl 3 +.Sh BUGS +If the boot blocks have not been modified to pass this information into +the kernel at boot time, the static string +.Dq Pa /kernel +is returned instead of the real boot file. +.Sh HISTORY +The +.Fn getbootfile +function call appeared in +.Fx 2.0 . diff --git a/gen/getbsize.3 b/gen/getbsize.3 new file mode 100644 index 0000000..8653389 --- /dev/null +++ b/gen/getbsize.3 @@ -0,0 +1,82 @@ +.\" 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. +.\" +.\" @(#)getbsize.3 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD: src/lib/libc/gen/getbsize.3,v 1.8 2001/10/01 16:08:50 ru Exp $ +.\" +.Dd June 4, 1993 +.Dt GETBSIZE 3 +.Os +.Sh NAME +.Nm getbsize +.Nd get user block size +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In stdlib.h +.Ft char * +.Fn getbsize "int *headerlenp" "long *blocksizep" +.Sh DESCRIPTION +The +.Fn getbsize +function determines the user's preferred block size based on the value of the +.Dq BLOCKSIZE +environment variable; see +.Xr environ 7 +for details on its use and format. +.Pp +The +.Fn getbsize +function returns a pointer to a null-terminated string describing +the block size, something like +.Dq 1K-blocks . +The memory referenced by +.Fa headerlenp +is filled in with the length of the string (not including the +terminating null). +The memory referenced by +.Fa blocksizep +is filled in with block size, in bytes. +.Pp +If the user's block size is unreasonable, a warning message is +written to standard error and the returned information reflects +a block size of 512 bytes. +.Sh SEE ALSO +.Xr df 1 , +.Xr du 1 , +.Xr ls 1 , +.Xr systat 1 , +.Xr environ 7 +.Sh HISTORY +The +.Fn getbsize +function first appeared in +.Bx 4.4 . diff --git a/gen/getbsize.c b/gen/getbsize.c new file mode 100644 index 0000000..8d64465 --- /dev/null +++ b/gen/getbsize.c @@ -0,0 +1,124 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * 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. + */ + + +#include +#include +#include +#include + +char * +getbsize(headerlenp, blocksizep) + int *headerlenp; + long *blocksizep; +{ + static char header[20]; + long n, max, mul, blocksize; + char *ep, *p, *form; + +#define KB (1024L) +#define MB (1024L * 1024L) +#define GB (1024L * 1024L * 1024L) +#define MAXB GB /* No tera, peta, nor exa. */ + form = ""; + if ((p = getenv("BLOCKSIZE")) != NULL && *p != '\0') { + if ((n = strtol(p, &ep, 10)) < 0) + goto underflow; + if (n == 0) + n = 1; + if (*ep && ep[1]) + goto fmterr; + switch (*ep) { + case 'G': case 'g': + form = "G"; + max = MAXB / GB; + mul = GB; + break; + case 'K': case 'k': + form = "K"; + max = MAXB / KB; + mul = KB; + break; + case 'M': case 'm': + form = "M"; + max = MAXB / MB; + mul = MB; + break; + case '\0': + max = MAXB; + mul = 1; + break; + default: +fmterr: warnx("%s: unknown blocksize", p); + n = 512; + mul = 1; + break; + } + if (n > max) { + warnx("maximum blocksize is %dG", MAXB / GB); + n = max; + } + if ((blocksize = n * mul) < 512) { +underflow: warnx("minimum blocksize is 512"); + form = ""; + blocksize = n = 512; + } + } else + blocksize = n = 512; + + (void)snprintf(header, sizeof(header), "%d%s-blocks", n, form); + *headerlenp = strlen(header); + *blocksizep = blocksize; + return (header); +} diff --git a/gen/getcap.3 b/gen/getcap.3 new file mode 100644 index 0000000..0af2a4f --- /dev/null +++ b/gen/getcap.3 @@ -0,0 +1,542 @@ +.\" Copyright (c) 1992, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" This code is derived from software contributed to Berkeley by +.\" Casey Leedom of Lawrence Livermore National Laboratory. +.\" +.\" 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. +.\" +.\" @(#)getcap.3 8.4 (Berkeley) 5/13/94 +.\" $FreeBSD: src/lib/libc/gen/getcap.3,v 1.20 2001/10/01 16:08:50 ru Exp $ +.\" +.Dd May 13, 1994 +.Dt GETCAP 3 +.Os +.Sh NAME +.Nm cgetent , +.Nm cgetset , +.Nm cgetmatch , +.Nm cgetcap , +.Nm cgetnum , +.Nm cgetstr , +.Nm cgetustr , +.Nm cgetfirst , +.Nm cgetnext , +.Nm cgetclose +.Nd capability database access routines +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In stdlib.h +.Ft int +.Fn cgetent "char **buf" "char **db_array" "char *name" +.Ft int +.Fn cgetset "char *ent" +.Ft int +.Fn cgetmatch "char *buf" "char *name" +.Ft char * +.Fn cgetcap "char *buf" "char *cap" "int type" +.Ft int +.Fn cgetnum "char *buf" "char *cap" "long *num" +.Ft int +.Fn cgetstr "char *buf" "char *cap" "char **str" +.Ft int +.Fn cgetustr "char *buf" "char *cap" "char **str" +.Ft int +.Fn cgetfirst "char **buf" "char **db_array" +.Ft int +.Fn cgetnext "char **buf" "char **db_array" +.Ft int +.Fn cgetclose "void" +.Sh DESCRIPTION +The +.Fn cgetent +function extracts the capability +.Fa name +from the database specified by the +.Dv NULL +terminated file array +.Fa db_array +and returns a pointer to a +.Xr malloc 3 Ns \&'d +copy of it in +.Fa buf . +The +.Fn cgetent +function will first look for files ending in +.Pa .db +(see +.Xr cap_mkdb 1 ) +before accessing the ASCII file. +.Fa Buf +must be retained through all subsequent calls to +.Fn cgetmatch , +.Fn cgetcap , +.Fn cgetnum , +.Fn cgetstr , +and +.Fn cgetustr , +but may then be +.Xr free 3 Ns \&'d . +On success 0 is returned, 1 if the returned +record contains an unresolved +.Nm tc +expansion, +\-1 if the requested record couldn't be found, +\-2 if a system error was encountered (couldn't open/read a file, etc.) also +setting +.Va errno , +and \-3 if a potential reference loop is detected (see +.Ic tc= +comments below). +.Pp +The +.Fn cgetset +function enables the addition of a character buffer containing a single capability +record entry +to the capability database. +Conceptually, the entry is added as the first ``file'' in the database, and +is therefore searched first on the call to +.Fn cgetent . +The entry is passed in +.Fa ent . +If +.Fa ent +is +.Dv NULL , +the current entry is removed from the database. +A call to +.Fn cgetset +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 +before the first sequential access call +.Fn ( cgetfirst +or +.Fn cgetnext ) , +or be directly preceded by a +.Fn cgetclose +call. +On success 0 is returned and \-1 on failure. +.Pp +The +.Fn cgetmatch +function will return 0 if +.Fa name +is one of the names of the capability record +.Fa buf , +\-1 if +not. +.Pp +The +.Fn cgetcap +function searches the capability record +.Fa buf +for the capability +.Fa cap +with type +.Fa type . +A +.Fa type +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 +.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 +.Tn ASCII +.Dv NUL +(see below for capability database syntax). +.Pp +The +.Fn cgetnum +function retrieves the value of the numeric capability +.Fa cap +from the capability record pointed to by +.Fa buf . +The numeric value is returned in the +.Ft long +pointed to by +.Fa num . +0 is returned on success, \-1 if the requested numeric capability couldn't +be found. +.Pp +The +.Fn cgetstr +function retrieves the value of the string capability +.Fa cap +from the capability record pointed to by +.Fa buf . +A pointer to a decoded, +.Dv NUL +terminated, +.Xr malloc 3 Ns \&'d +copy of the string is returned in the +.Ft char * +pointed to by +.Fa str . +The number of characters in the decoded string not including the trailing +.Dv NUL +is returned on success, \-1 if the requested string capability couldn't +be found, \-2 if a system error was encountered (storage allocation +failure). +.Pp +The +.Fn cgetustr +function is identical to +.Fn cgetstr +except that it does not expand special characters, but rather returns each +character of the capability string literally. +.Pp +The +.Fn cgetfirst +and +.Fn cgetnext +functions comprise a function group that provides for sequential +access of the +.Dv NULL +pointer terminated array of file names, +.Fa db_array . +The +.Fn cgetfirst +function returns the first record in the database and resets the access +to the first record. +The +.Fn cgetnext +function returns the next record in the database with respect to the +record returned by the previous +.Fn cgetfirst +or +.Fn cgetnext +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 +copy pointed to by +.Fa buf . +.Ic Tc +expansion is done (see +.Ic tc= +comments below). +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 +.Nm tc +expansion, \-1 is returned if an system error occurred, and \-2 +is returned if a potential reference loop is detected (see +.Ic tc= +comments below). +Upon completion of database (0 return) the database is closed. +.Pp +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 +.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 +is a continuation of the current line; the `\|\e' and following newline +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 +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. +By convention, the last name is usually a comment and is not intended as +a lookup tag. For example, the +.Em vt100 +record from the +.Nm termcap +database begins: +.Pp +.Dl "d0\||\|vt100\||\|vt100-am\||\|vt100am\||\|dec vt100:" +.Pp +giving four names that can be used to access the record. +.Pp +The remaining non-empty capabilities describe a set of (name, value) +bindings, consisting of a names optionally followed by a typed value: +.Bl -column "nameTvalue" +.It name Ta "typeless [boolean] capability" +.Em name No "is present [true]" +.It name Ns Em \&T Ns value Ta capability +.Pq Em name , \&T +has value +.Em value +.It name@ Ta "no capability" Em name No exists +.It name Ns Em T Ns \&@ Ta capability +.Pq Em name , T +does not exist +.El +.Pp +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 +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 +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 +distinguished by their +.Fa types . +The +.Fn cgetcap +function will return a pointer to a value of a name given the capability +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 +functions +.Fn cgetnum +and +.Fn cgetstr +can be used to implement the traditional syntax and semantics of `#' +and `='. +Typeless capabilities are typically used to denote boolean objects with +presence or absence indicating truth and false values respectively. +This interpretation is conveniently represented by: +.Pp +.Dl "(getcap(buf, name, ':') != NULL)" +.Pp +A special capability, +.Ic tc= name , +is used to indicate that the record specified by +.Fa name +should be substituted for the +.Ic tc +capability. +.Ic Tc +capabilities may interpolate records which also contain +.Ic tc +capabilities and more than one +.Ic tc +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 +.Ic tc +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 +capability, the first matching capability is returned; the capability +.Ic :nameT@: +will hide any following definition of a value of type +.Em T +for +.Fa name ; +and the capability +.Ic :name@: +will prevent any following values of +.Fa name +from being seen. +.Pp +These features combined with +.Ic tc +capabilities can be used to generate variations of other databases and +records by either adding new capabilities, overriding definitions with new +definitions, or hiding following definitions via `@' capabilities. +.Sh EXAMPLES +.Bd -unfilled -offset indent +example\||\|an example of binding multiple values to names:\e + :foo%bar:foo^blah:foo@:\e + :abc%xyz:abc^frap:abc$@:\e + :tc=more: +.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 +also has two values bound but only a value of type `$' is prevented from +being defined in the capability record more. +.Pp +.Bd -unfilled -offset indent +file1: + new\||\|new_record\||\|a modification of "old":\e + :fript=bar:who-cares@:tc=old:blah:tc=extensions: +file2: + old\||\|old_record\||\|an old database record:\e + :fript=foo:who-cares:glork#200: +.Ed +.Pp +The records are extracted by calling +.Fn cgetent +with file1 preceding file2. +In the capability record new in file1, fript=bar overrides the definition +of fript=foo interpolated from the capability record old in file2, +who-cares@ prevents the definition of any who-cares definitions in old +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 +would take precedence. +.Sh CGETNUM AND CGETSTR SYNTAX AND SEMANTICS +Two types are predefined by +.Fn cgetnum +and +.Fn cgetstr : +.Bl -column "nameXnumber" +.Sm off +.It Em name No \&# Em number Ta numeric +.Sm on +capability +.Em name +has value +.Em number +.Sm off +.It Em name No = Em string Ta "string capability" +.Sm on +.Em name +has value +.Em string +.Sm off +.It Em name No \&#@ Ta "the numeric capability" +.Sm on +.Em name +does not exist +.Sm off +.It Em name No \&=@ Ta "the string capability" +.Sm on +.Em name +does not exist +.El +.Pp +Numeric capability values may be given in one of three numeric bases. +If the number starts with either +.Ql 0x +or +.Ql 0X +it is interpreted as a hexadecimal number (both upper and lower case a-f +may be used to denote the extended hexadecimal digits). +Otherwise, if the number starts with a +.Ql 0 +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 +.Dv ASCII +codes, new lines, and colons may be conveniently represented by the use +of escape sequences: +.Bl -column "\e\|X,X\e\|X" "(ASCII octal nnn)" +^X ('X' & 037) control-X +\e\|b, \e\|B (ASCII 010) backspace +\e\|t, \e\|T (ASCII 011) tab +\e\|n, \e\|N (ASCII 012) line feed (newline) +\e\|f, \e\|F (ASCII 014) form feed +\e\|r, \e\|R (ASCII 015) carriage return +\e\|e, \e\|E (ASCII 027) escape +\e\|c, \e\|C (:) colon +\e\|\e (\e\|) back slash +\e\|^ (^) caret +\e\|nnn (ASCII octal nnn) +.El +.Pp +A `\|\e' may be followed by up to three octal digits directly specifies +the numeric code for a character. The use of +.Tn ASCII +.Dv NUL Ns s , +while easily +encoded, causes all sorts of problems and must be used with care since +.Dv NUL Ns s +are typically used to denote the end of strings; many applications +use `\e\|200' to represent a +.Dv NUL . +.Sh DIAGNOSTICS +The +.Fn cgetent , +.Fn cgetset , +.Fn cgetmatch , +.Fn cgetnum , +.Fn cgetstr , +.Fn cgetustr , +.Fn cgetfirst , +and +.Fn cgetnext +functions +return a value greater than or equal to 0 on success and a value less +than 0 on failure. +The +.Fn cgetcap +function returns a character pointer on success and a +.Dv NULL +on failure. +.Pp +The +.Fn cgetent , +and +.Fn cgetseq +functions may fail and set +.Va errno +for any of the errors specified for the library functions: +.Xr fopen 3 , +.Xr fclose 3 , +.Xr open 2 , +and +.Xr close 2 . +.Pp +The +.Fn cgetent , +.Fn cgetset , +.Fn cgetstr , +and +.Fn cgetustr +functions +may fail and set +.Va errno +as follows: +.Bl -tag -width Er +.It Bq Er ENOMEM +No memory to allocate. +.El +.Sh SEE ALSO +.Xr cap_mkdb 1 , +.Xr malloc 3 +.Sh BUGS +Colons (`:') can't be used in names, types, or values. +.Pp +There are no checks for +.Ic tc Ns = Ns Ic name +loops in +.Fn cgetent . +.Pp +The buffer added to the database by a call to +.Fn cgetset +is not unique to the database but is rather prepended to any database used. diff --git a/gen/getcap.c b/gen/getcap.c new file mode 100644 index 0000000..8ce326b --- /dev/null +++ b/gen/getcap.c @@ -0,0 +1,1064 @@ +/* + * Copyright (c) 1999 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@ + */ +/*- + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Casey Leedom of Lawrence Livermore National Laboratory. + * + * 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 rcsid[] = "$OpenBSD: getcap.c,v 1.4 1997/02/01 04:35:33 deraadt Exp $"; +#endif /* LIBC_SCCS and not lint */ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define BFRAG 1024 +#define BSIZE 1024 +#define ESC ('[' & 037) /* ASCII ESC */ +#define MAX_RECURSION 32 /* maximum getent recursion */ +#define SFRAG 100 /* cgetstr mallocs in SFRAG chunks */ + +#define RECOK (char)0 +#define TCERR (char)1 +#define SHADOW (char)2 + +static size_t topreclen; /* toprec length */ +static char *toprec; /* Additional record specified by cgetset() */ +static int gottoprec; /* Flag indicating retrieval of toprecord */ + +static int cdbget __P((DB *, char **, char *)); +static int getent __P((char **, u_int *, char **, int, char *, int, char *)); +static int nfcmp __P((char *, char *)); + +/* + * Cgetset() allows the addition of a user specified buffer to be added + * to the database array, in effect "pushing" the buffer on top of the + * virtual database. 0 is returned on success, -1 on failure. + */ +int +cgetset(ent) + char *ent; +{ + if (ent == NULL) { + if (toprec) + free(toprec); + toprec = NULL; + topreclen = 0; + return (0); + } + topreclen = strlen(ent); + if ((toprec = malloc (topreclen + 1)) == NULL) { + errno = ENOMEM; + return (-1); + } + gottoprec = 0; + (void)strcpy(toprec, ent); + return (0); +} + +/* + * Cgetcap searches the capability record buf for the capability cap with + * type `type'. A pointer to the value of cap is returned on success, NULL + * if the requested capability couldn't be found. + * + * Specifying a type of ':' means that nothing should follow cap (:cap:). + * In this case a pointer to the terminating ':' or NUL will be returned if + * cap is found. + * + * If (cap, '@') or (cap, terminator, '@') is found before (cap, terminator) + * return NULL. + */ +char * +cgetcap(buf, cap, type) + char *buf, *cap; + int type; +{ + register char *bp, *cp; + + bp = buf; + for (;;) { + /* + * Skip past the current capability field - it's either the + * name field if this is the first time through the loop, or + * the remainder of a field whose name failed to match cap. + */ + for (;;) + if (*bp == '\0') + return (NULL); + else + if (*bp++ == ':') + break; + + /* + * Try to match (cap, type) in buf. + */ + for (cp = cap; *cp == *bp && *bp != '\0'; cp++, bp++) + continue; + if (*cp != '\0') + continue; + if (*bp == '@') + return (NULL); + if (type == ':') { + if (*bp != '\0' && *bp != ':') + continue; + return(bp); + } + if (*bp != type) + continue; + bp++; + return (*bp == '@' ? NULL : bp); + } + /* NOTREACHED */ +} + +/* + * Cgetent extracts the capability record name from the NULL terminated file + * array db_array and returns a pointer to a malloc'd copy of it in buf. + * Buf must be retained through all subsequent calls to cgetcap, cgetnum, + * cgetflag, and cgetstr, but may then be free'd. 0 is returned on success, + * -1 if the requested record couldn't be found, -2 if a system error was + * encountered (couldn't open/read a file, etc.), and -3 if a potential + * reference loop is detected. + */ +int +cgetent(buf, db_array, name) + char **buf, **db_array, *name; +{ + u_int dummy; + + return (getent(buf, &dummy, db_array, -1, name, 0, NULL)); +} + +/* + * Getent implements the functions of cgetent. If fd is non-negative, + * *db_array has already been opened and fd is the open file descriptor. We + * do this to save time and avoid using up file descriptors for tc= + * recursions. + * + * Getent returns the same success/failure codes as cgetent. On success, a + * pointer to a malloc'ed capability record with all tc= capabilities fully + * expanded and its length (not including trailing ASCII NUL) are left in + * *cap and *len. + * + * Basic algorithm: + * + Allocate memory incrementally as needed in chunks of size BFRAG + * for capability buffer. + * + Recurse for each tc=name and interpolate result. Stop when all + * names interpolated, a name can't be found, or depth exceeds + * MAX_RECURSION. + */ +static int +getent(cap, len, db_array, fd, name, depth, nfield) + char **cap, **db_array, *name, *nfield; + u_int *len; + int fd, depth; +{ + DB *capdbp; + register char *r_end, *rp, **db_p; + int myfd, eof, foundit, retval, clen; + char *record, *cbuf; + int tc_not_resolved; + char pbuf[_POSIX_PATH_MAX]; + + /* + * Return with ``loop detected'' error if we've recursed more than + * MAX_RECURSION times. + */ + if (depth > MAX_RECURSION) + return (-3); + + /* + * Check if we have a top record from cgetset(). + */ + if (depth == 0 && toprec != NULL && cgetmatch(toprec, name) == 0) { + if ((record = malloc (topreclen + BFRAG)) == NULL) { + errno = ENOMEM; + return (-2); + } + (void)strcpy(record, toprec); + myfd = 0; + db_p = db_array; + rp = record + topreclen + 1; + r_end = rp + BFRAG; + goto tc_exp; + } + /* + * Allocate first chunk of memory. + */ + if ((record = malloc(BFRAG)) == NULL) { + errno = ENOMEM; + return (-2); + } + r_end = record + BFRAG; + foundit = 0; + /* + * Loop through database array until finding the record. + */ + + for (db_p = db_array; *db_p != NULL; db_p++) { + eof = 0; + + /* + * Open database if not already open. + */ + + if (fd >= 0) { + (void)lseek(fd, (off_t)0, SEEK_SET); + myfd = 0; + } else { + (void)snprintf(pbuf, sizeof(pbuf), "%s.db", *db_p); + if ((capdbp = dbopen(pbuf, O_RDONLY, 0, DB_HASH, 0)) + != NULL) { + free(record); + retval = cdbget(capdbp, &record, name); + if (retval < 0) { + /* no record available */ + (void)capdbp->close(capdbp); + return (retval); + } + /* save the data; close frees it */ + clen = strlen(record); + cbuf = malloc(clen + 1); + memcpy(cbuf, record, clen + 1); + if (capdbp->close(capdbp) < 0) { + free(cbuf); + return (-2); + } + *len = clen; + *cap = cbuf; + return (retval); + } else { + fd = open(*db_p, O_RDONLY, 0); + if (fd < 0) { + /* No error on unfound file. */ + continue; + } + myfd = 1; + } + } + /* + * Find the requested capability record ... + */ + { + char buf[BUFSIZ]; + register char *b_end, *bp; + register int c; + + /* + * Loop invariants: + * There is always room for one more character in record. + * R_end always points just past end of record. + * Rp always points just past last character in record. + * B_end always points just past last character in buf. + * Bp always points at next character in buf. + */ + b_end = buf; + bp = buf; + for (;;) { + + /* + * Read in a line implementing (\, newline) + * line continuation. + */ + rp = record; + for (;;) { + if (bp >= b_end) { + int n; + + n = read(fd, buf, sizeof(buf)); + if (n <= 0) { + if (myfd) + (void)close(fd); + if (n < 0) { + free(record); + return (-2); + } else { + fd = -1; + eof = 1; + break; + } + } + b_end = buf+n; + bp = buf; + } + + c = *bp++; + if (c == '\n') { + if (rp > record && *(rp-1) == '\\') { + rp--; + continue; + } else + break; + } + *rp++ = c; + + /* + * Enforce loop invariant: if no room + * left in record buffer, try to get + * some more. + */ + if (rp >= r_end) { + u_int pos; + size_t newsize; + + pos = rp - record; + newsize = r_end - record + BFRAG; + record = realloc(record, newsize); + if (record == NULL) { + errno = ENOMEM; + if (myfd) + (void)close(fd); + return (-2); + } + r_end = record + newsize; + rp = record + pos; + } + } + /* loop invariant let's us do this */ + *rp++ = '\0'; + + /* + * If encountered eof check next file. + */ + if (eof) + break; + + /* + * Toss blank lines and comments. + */ + if (*record == '\0' || *record == '#') + continue; + + /* + * See if this is the record we want ... + */ + if (cgetmatch(record, name) == 0) { + if (nfield == NULL || !nfcmp(nfield, record)) { + foundit = 1; + break; /* found it! */ + } + } + } + } + if (foundit) + break; + } + + if (!foundit) { + free(record); + return (-1); + } + + /* + * Got the capability record, but now we have to expand all tc=name + * references in it ... + */ +tc_exp: { + register char *newicap, *s; + register int newilen; + u_int ilen; + int diff, iret, tclen; + char *icap, *scan, *tc, *tcstart, *tcend; + + /* + * Loop invariants: + * There is room for one more character in record. + * R_end points just past end of record. + * Rp points just past last character in record. + * Scan points at remainder of record that needs to be + * scanned for tc=name constructs. + */ + scan = record; + tc_not_resolved = 0; + for (;;) { + if ((tc = cgetcap(scan, "tc", '=')) == NULL) + break; + + /* + * Find end of tc=name and stomp on the trailing `:' + * (if present) so we can use it to call ourselves. + */ + s = tc; + for (;;) + if (*s == '\0') + break; + else + if (*s++ == ':') { + *(s - 1) = '\0'; + break; + } + tcstart = tc - 3; + tclen = s - tcstart; + tcend = s; + + iret = getent(&icap, &ilen, db_p, fd, tc, depth+1, + NULL); + newicap = icap; /* Put into a register. */ + newilen = ilen; + if (iret != 0) { + /* an error */ + if (iret < -1) { + if (myfd) + (void)close(fd); + free(record); + return (iret); + } + if (iret == 1) + tc_not_resolved = 1; + /* couldn't resolve tc */ + if (iret == -1) { + *(s - 1) = ':'; + scan = s - 1; + tc_not_resolved = 1; + continue; + + } + } + /* not interested in name field of tc'ed record */ + s = newicap; + for (;;) + if (*s == '\0') + break; + else + if (*s++ == ':') + break; + newilen -= s - newicap; + newicap = s; + + /* make sure interpolated record is `:'-terminated */ + s += newilen; + if (*(s-1) != ':') { + *s = ':'; /* overwrite NUL with : */ + newilen++; + } + + /* + * Make sure there's enough room to insert the + * new record. + */ + diff = newilen - tclen; + if (diff >= r_end - rp) { + u_int pos, tcpos, tcposend; + size_t newsize; + + pos = rp - record; + newsize = r_end - record + diff + BFRAG; + tcpos = tcstart - record; + tcposend = tcend - record; + record = realloc(record, newsize); + if (record == NULL) { + errno = ENOMEM; + if (myfd) + (void)close(fd); + free(icap); + return (-2); + } + r_end = record + newsize; + rp = record + pos; + tcstart = record + tcpos; + tcend = record + tcposend; + } + + /* + * Insert tc'ed record into our record. + */ + s = tcstart + newilen; + bcopy(tcend, s, rp - tcend); + bcopy(newicap, tcstart, newilen); + rp += diff; + free(icap); + + /* + * Start scan on `:' so next cgetcap works properly + * (cgetcap always skips first field). + */ + scan = s-1; + } + + } + /* + * Close file (if we opened it), give back any extra memory, and + * return capability, length and success. + */ + if (myfd) + (void)close(fd); + *len = rp - record - 1; /* don't count NUL */ + if (r_end > rp) + if ((record = + realloc(record, (size_t)(rp - record))) == NULL) { + errno = ENOMEM; + return (-2); + } + + *cap = record; + if (tc_not_resolved) + return (1); + return (0); +} + +static int +cdbget(capdbp, bp, name) + DB *capdbp; + char **bp, *name; +{ + DBT key, data; + + key.data = name; + key.size = strlen(name); + + for (;;) { + /* Get the reference. */ + switch(capdbp->get(capdbp, &key, &data, 0)) { + case -1: + return (-2); + case 1: + return (-1); + } + + /* If not an index to another record, leave. */ + if (((char *)data.data)[0] != SHADOW) + break; + + key.data = (char *)data.data + 1; + key.size = data.size - 1; + } + + *bp = (char *)data.data + 1; + return (((char *)(data.data))[0] == TCERR ? 1 : 0); +} + +/* + * Cgetmatch will return 0 if name is one of the names of the capability + * record buf, -1 if not. + */ +int +cgetmatch(buf, name) + char *buf, *name; +{ + register char *np, *bp; + + /* + * Start search at beginning of record. + */ + bp = buf; + for (;;) { + /* + * Try to match a record name. + */ + np = name; + for (;;) + if (*np == '\0') + if (*bp == '|' || *bp == ':' || *bp == '\0') + return (0); + else + break; + else + if (*bp++ != *np++) + break; + + /* + * Match failed, skip to next name in record. + */ + bp--; /* a '|' or ':' may have stopped the match */ + for (;;) + if (*bp == '\0' || *bp == ':') + return (-1); /* match failed totally */ + else + if (*bp++ == '|') + break; /* found next name */ + } +} + + + + + +int +cgetfirst(buf, db_array) + char **buf, **db_array; +{ + (void)cgetclose(); + return (cgetnext(buf, db_array)); +} + +static FILE *pfp; +static int slash; +static char **dbp; + +int +cgetclose() +{ + if (pfp != NULL) { + (void)fclose(pfp); + pfp = NULL; + } + dbp = NULL; + gottoprec = 0; + slash = 0; + return(0); +} + +/* + * Cgetnext() gets either the first or next entry in the logical database + * specified by db_array. It returns 0 upon completion of the database, 1 + * upon returning an entry with more remaining, and -1 if an error occurs. + */ +int +cgetnext(bp, db_array) + register char **bp; + char **db_array; +{ + size_t len; + int status, done; + char *cp, *line, *rp, *np, buf[BSIZE], nbuf[BSIZE]; + u_int dummy; + + if (dbp == NULL) + dbp = db_array; + + if (pfp == NULL && (pfp = fopen(*dbp, "r")) == NULL) { + (void)cgetclose(); + return (-1); + } + for(;;) { + if (toprec && !gottoprec) { + gottoprec = 1; + line = toprec; + } else { + line = fgetln(pfp, &len); + if (line == NULL && pfp) { + (void)fclose(pfp); + if (ferror(pfp)) { + (void)cgetclose(); + return (-1); + } else { + if (*++dbp == NULL) { + (void)cgetclose(); + return (0); + } else if ((pfp = + fopen(*dbp, "r")) == NULL) { + (void)cgetclose(); + return (-1); + } else + continue; + } + } else + line[len - 1] = '\0'; + if (len == 1) { + slash = 0; + continue; + } + if (isspace(*line) || + *line == ':' || *line == '#' || slash) { + if (line[len - 2] == '\\') + slash = 1; + else + slash = 0; + continue; + } + if (line[len - 2] == '\\') + slash = 1; + else + slash = 0; + } + + + /* + * Line points to a name line. + */ + done = 0; + np = nbuf; + for (;;) { + for (cp = line; *cp != '\0'; cp++) { + if (*cp == ':') { + *np++ = ':'; + done = 1; + break; + } + if (*cp == '\\') + break; + *np++ = *cp; + } + if (done) { + *np = '\0'; + break; + } else { /* name field extends beyond the line */ + line = fgetln(pfp, &len); + if (line == NULL && pfp) { + (void)fclose(pfp); + if (ferror(pfp)) { + (void)cgetclose(); + return (-1); + } + } else + line[len - 1] = '\0'; + } + } + rp = buf; + for(cp = nbuf; *cp != NULL; cp++) + if (*cp == '|' || *cp == ':') + break; + else + *rp++ = *cp; + + *rp = '\0'; + /* + * XXX + * Last argument of getent here should be nbuf if we want true + * sequential access in the case of duplicates. + * With NULL, getent will return the first entry found + * 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); + if (status == -2 || status == -3) + (void)cgetclose(); + + return (status + 1); + } + /* NOTREACHED */ +} + +/* + * Cgetstr retrieves the value of the string capability cap from the + * capability record pointed to by buf. A pointer to a decoded, NUL + * terminated, malloc'd copy of the string is returned in the char * + * pointed to by str. The length of the string not including the trailing + * NUL is returned on success, -1 if the requested string capability + * couldn't be found, -2 if a system error was encountered (storage + * allocation failure). + */ +int +cgetstr(buf, cap, str) + char *buf, *cap; + char **str; +{ + register u_int m_room; + register char *bp, *mp; + int len; + char *mem; + + /* + * Find string capability cap + */ + bp = cgetcap(buf, cap, '='); + if (bp == NULL) + return (-1); + + /* + * Conversion / storage allocation loop ... Allocate memory in + * chunks SFRAG in size. + */ + if ((mem = malloc(SFRAG)) == NULL) { + errno = ENOMEM; + return (-2); /* couldn't even allocate the first fragment */ + } + m_room = SFRAG; + mp = mem; + + while (*bp != ':' && *bp != '\0') { + /* + * Loop invariants: + * There is always room for one more character in mem. + * Mp always points just past last character in mem. + * Bp always points at next character in buf. + */ + if (*bp == '^') { + bp++; + if (*bp == ':' || *bp == '\0') + break; /* drop unfinished escape */ + *mp++ = *bp++ & 037; + } else if (*bp == '\\') { + bp++; + if (*bp == ':' || *bp == '\0') + break; /* drop unfinished escape */ + if ('0' <= *bp && *bp <= '7') { + register int n, i; + + n = 0; + i = 3; /* maximum of three octal digits */ + do { + n = n * 8 + (*bp++ - '0'); + } while (--i && '0' <= *bp && *bp <= '7'); + *mp++ = n; + } + else switch (*bp++) { + case 'b': case 'B': + *mp++ = '\b'; + break; + case 't': case 'T': + *mp++ = '\t'; + break; + case 'n': case 'N': + *mp++ = '\n'; + break; + case 'f': case 'F': + *mp++ = '\f'; + break; + case 'r': case 'R': + *mp++ = '\r'; + break; + case 'e': case 'E': + *mp++ = ESC; + break; + case 'c': case 'C': + *mp++ = ':'; + break; + default: + /* + * Catches '\', '^', and + * everything else. + */ + *mp++ = *(bp-1); + break; + } + } else + *mp++ = *bp++; + m_room--; + + /* + * Enforce loop invariant: if no room left in current + * buffer, try to get some more. + */ + if (m_room == 0) { + size_t size = mp - mem; + + if ((mem = realloc(mem, size + SFRAG)) == NULL) + return (-2); + m_room = SFRAG; + mp = mem + size; + } + } + *mp++ = '\0'; /* loop invariant let's us do this */ + m_room--; + len = mp - mem - 1; + + /* + * Give back any extra memory and return value and success. + */ + if (m_room != 0) + if ((mem = realloc(mem, (size_t)(mp - mem))) == NULL) + return (-2); + *str = mem; + return (len); +} + +/* + * Cgetustr retrieves the value of the string capability cap from the + * capability record pointed to by buf. The difference between cgetustr() + * and cgetstr() is that cgetustr does not decode escapes but rather treats + * all characters literally. A pointer to a NUL terminated malloc'd + * copy of the string is returned in the char pointed to by str. The + * length of the string not including the trailing NUL is returned on success, + * -1 if the requested string capability couldn't be found, -2 if a system + * error was encountered (storage allocation failure). + */ +int +cgetustr(buf, cap, str) + char *buf, *cap, **str; +{ + register u_int m_room; + register char *bp, *mp; + int len; + char *mem; + + /* + * Find string capability cap + */ + if ((bp = cgetcap(buf, cap, '=')) == NULL) + return (-1); + + /* + * Conversion / storage allocation loop ... Allocate memory in + * chunks SFRAG in size. + */ + if ((mem = malloc(SFRAG)) == NULL) { + errno = ENOMEM; + return (-2); /* couldn't even allocate the first fragment */ + } + m_room = SFRAG; + mp = mem; + + while (*bp != ':' && *bp != '\0') { + /* + * Loop invariants: + * There is always room for one more character in mem. + * Mp always points just past last character in mem. + * Bp always points at next character in buf. + */ + *mp++ = *bp++; + m_room--; + + /* + * Enforce loop invariant: if no room left in current + * buffer, try to get some more. + */ + if (m_room == 0) { + size_t size = mp - mem; + + if ((mem = realloc(mem, size + SFRAG)) == NULL) + return (-2); + m_room = SFRAG; + mp = mem + size; + } + } + *mp++ = '\0'; /* loop invariant let's us do this */ + m_room--; + len = mp - mem - 1; + + /* + * Give back any extra memory and return value and success. + */ + if (m_room != 0) + if ((mem = realloc(mem, (size_t)(mp - mem))) == NULL) + return (-2); + *str = mem; + return (len); +} + +/* + * Cgetnum retrieves the value of the numeric capability cap from the + * capability record pointed to by buf. The numeric value is returned in + * the long pointed to by num. 0 is returned on success, -1 if the requested + * numeric capability couldn't be found. + */ +int +cgetnum(buf, cap, num) + char *buf, *cap; + long *num; +{ + register long n; + register int base, digit; + register char *bp; + + /* + * Find numeric capability cap + */ + bp = cgetcap(buf, cap, '#'); + if (bp == NULL) + return (-1); + + /* + * Look at value and determine numeric base: + * 0x... or 0X... hexadecimal, + * else 0... octal, + * else decimal. + */ + if (*bp == '0') { + bp++; + if (*bp == 'x' || *bp == 'X') { + bp++; + base = 16; + } else + base = 8; + } else + base = 10; + + /* + * Conversion loop ... + */ + n = 0; + for (;;) { + if ('0' <= *bp && *bp <= '9') + digit = *bp - '0'; + else if ('a' <= *bp && *bp <= 'f') + digit = 10 + *bp - 'a'; + else if ('A' <= *bp && *bp <= 'F') + digit = 10 + *bp - 'A'; + else + break; + + if (digit >= base) + break; + + n = n * base + digit; + bp++; + } + + /* + * Return value and success. + */ + *num = n; + return (0); +} + + +/* + * Compare name field of record. + */ +static int +nfcmp(nf, rec) + char *nf, *rec; +{ + char *cp, tmp; + int ret; + + for (cp = rec; *cp != ':'; cp++) + ; + + tmp = *(cp + 1); + *(cp + 1) = '\0'; + ret = strcmp(nf, rec); + *(cp + 1) = tmp; + + return (ret); +} diff --git a/gen/getcwd.3 b/gen/getcwd.3 new file mode 100644 index 0000000..b095a46 --- /dev/null +++ b/gen/getcwd.3 @@ -0,0 +1,158 @@ +.\" 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. +.\" +.\" @(#)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 $ +.\" +.Dd November 24, 1997 +.Dt GETCWD 3 +.Os +.Sh NAME +.Nm getcwd , +.Nm getwd +.Nd get working directory pathname +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In unistd.h +.Ft char * +.Fn getcwd "char *buf" "size_t size" +.Ft char * +.Fn getwd "char *buf" +.Sh DESCRIPTION +The +.Fn getcwd +function copies the absolute pathname of the current working directory +into the memory referenced by +.Fa buf +and returns a pointer to +.Fa buf . +The +.Fa size +argument is the size, in bytes, of the array referenced by +.Fa buf . +.Pp +If +.Fa buf +is +.Dv NULL , +space is allocated as necessary to store the pathname. +This space may later be +.Xr free 3 Ns 'd . +.Pp +The function +.Fn getwd +is a compatibility routine which calls +.Fn getcwd +with its +.Fa buf +argument and a size of +.Dv MAXPATHLEN +(as defined in the include +file +.Aq Pa sys/param.h ) . +Obviously, +.Fa buf +should be at least +.Dv MAXPATHLEN +bytes in length. +.Pp +These routines have traditionally been used by programs to save the +name of a working directory for the purpose of returning to it. +A much faster and less error-prone method of accomplishing this is to +open the current directory +.Pq Ql .\& +and use the +.Xr fchdir 2 +function to return. +.Sh RETURN VALUES +Upon successful completion, a pointer to the pathname is returned. +Otherwise a +.Dv NULL +pointer is returned and the global variable +.Va errno +is set to indicate the error. +In addition, +.Fn getwd +copies the error message associated with +.Va errno +into the memory referenced by +.Fa buf . +.Sh ERRORS +The +.Fn getcwd +function +will fail if: +.Bl -tag -width Er +.It Bq Er EACCES +Read or search permission was denied for a component of the pathname. +.It Bq Er EINVAL +The +.Fa size +argument is zero. +.It Bq Er ENOENT +A component of the pathname no longer exists. +.It Bq Er ENOMEM +Insufficient memory is available. +.It Bq Er ERANGE +The +.Fa size +argument is greater than zero but smaller than the length of the pathname +plus 1. +.El +.Sh SEE ALSO +.Xr chdir 2 , +.Xr fchdir 2 , +.Xr malloc 3 , +.Xr strerror 3 +.Sh STANDARDS +The +.Fn getcwd +function +conforms to +.St -p1003.1-90 . +The ability to specify a +.Dv NULL +pointer and have +.Fn getcwd +allocate memory as necessary is an extension. +.Sh HISTORY +The +.Fn getwd +function appeared in +.Bx 4.0 . +.Sh BUGS +The +.Fn getwd +function +does not do sufficient error checking and is not able to return very +long, but valid, paths. +It is provided for compatibility. diff --git a/gen/getcwd.c b/gen/getcwd.c new file mode 100644 index 0000000..0c71e79 --- /dev/null +++ b/gen/getcwd.c @@ -0,0 +1,410 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1989, 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. + */ + + +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +static char *getcwd_physical __P((char *, size_t)); + +#define ISDOT(dp) \ + (dp->d_name[0] == '.' && (dp->d_name[1] == '\0' || \ + dp->d_name[1] == '.' && dp->d_name[2] == '\0')) + +char * +getcwd(pt, size) + char *pt; + size_t size; +{ + char *pwd; + size_t pwdlen; + dev_t dev; + ino_t ino; + struct stat s; + + /* Check $PWD -- if it's right, it's fast. */ + if ((pwd = getenv("PWD")) != NULL && pwd[0] == '/' && stat(pwd, &s) != -1) { + dev = s.st_dev; + ino = s.st_ino; + if (stat(".", &s) != -1 && dev == s.st_dev && ino == s.st_ino) { + pwdlen = strlen(pwd); + if (pt) { + if (!size) { + errno = EINVAL; + return (NULL); + } + if (pwdlen + 1 > size) { + errno = ERANGE; + return (NULL); + } + } else if ((pt = malloc(pwdlen + 1)) == NULL) { + errno = ENOMEM; + return (NULL); + } + memmove(pt, pwd, pwdlen); + pt[pwdlen] = '\0'; + return (pt); + } + } + + return (getcwd_physical(pt, size)); +} + +/* + * char *realpath(const char *path, char resolved_path[MAXPATHLEN]); + * + * Find the real name of path, by removing all ".", ".." and symlink + * components. Returns (resolved) on success, or (NULL) on failure, + * in which case the path which caused trouble is left in (resolved). + */ +char * +realpath(path, resolved) + const char *path; + char *resolved; +{ + struct stat sb; + int fd, n, rootd, serrno; + char *p, *q, wbuf[MAXPATHLEN]; + int symlinks = 0; + + /* Save the starting point. */ + if ((fd = open(".", O_RDONLY)) < 0) { + (void)strcpy(resolved, "."); + return (NULL); + } + + /* + * Find the dirname and basename from the path to be resolved. + * Change directory to the dirname component. + * lstat the basename part. + * if it is a symlink, read in the value and loop. + * if it is a directory, then change to that directory. + * get the current directory name and append the basename. + */ + (void)strncpy(resolved, path, MAXPATHLEN - 1); + resolved[MAXPATHLEN - 1] = '\0'; +loop: + q = strrchr(resolved, '/'); + if (q != NULL) { + p = q + 1; + if (q == resolved) + q = "/"; + else { + do { + --q; + } while (q > resolved && *q == '/'); + q[1] = '\0'; + q = resolved; + } + if (chdir(q) < 0) + goto err1; + } else + p = resolved; + + /* Deal with the last component. */ + if (lstat(p, &sb) == 0) { + if (S_ISLNK(sb.st_mode)) { + if (++symlinks > MAXSYMLINKS) { + errno = ELOOP; + goto err1; + } + n = readlink(p, resolved, MAXPATHLEN-1); + if (n < 0) + goto err1; + resolved[n] = '\0'; + goto loop; + } + if (S_ISDIR(sb.st_mode)) { + if (chdir(p) < 0) + goto err1; + p = ""; + } + } + + /* + * Save the last component name and get the full pathname of + * the current directory. + */ + (void)strcpy(wbuf, p); + + /* + * Call the inernal internal version of getcwd which + * does a physical search rather than using the $PWD short-cut + */ + if (getcwd_physical(resolved, MAXPATHLEN) == 0) + goto err1; + + /* + * Join the two strings together, ensuring that the right thing + * happens if the last component is empty, or the dirname is root. + */ + if (resolved[0] == '/' && resolved[1] == '\0') + rootd = 1; + else + rootd = 0; + + if (*wbuf) { + if (strlen(resolved) + strlen(wbuf) + rootd + 1 > MAXPATHLEN) { + errno = ENAMETOOLONG; + goto err1; + } + if (rootd == 0) + (void)strcat(resolved, "/"); + (void)strcat(resolved, wbuf); + } + + /* Go back to where we came from. */ + if (fchdir(fd) < 0) { + serrno = errno; + goto err2; + } + + /* It's okay if the close fails, what's an fd more or less? */ + (void)close(fd); + return (resolved); + +err1: serrno = errno; + (void)fchdir(fd); +err2: (void)close(fd); + errno = serrno; + return (NULL); +} + +static char * +getcwd_physical(pt, size) + char *pt; + size_t size; +{ + register struct dirent *dp; + register DIR *dir; + register dev_t dev; + register ino_t ino; + register int first; + register char *bpt, *bup; + struct stat s; + dev_t root_dev; + ino_t root_ino; + size_t ptsize, upsize; + int save_errno; + char *ept, *eup, *up; + + /* + * If no buffer specified by the user, allocate one as necessary. + * If a buffer is specified, the size has to be non-zero. The path + * is built from the end of the buffer backwards. + */ + if (pt) { + ptsize = 0; + if (!size) { + errno = EINVAL; + return (NULL); + } + ept = pt + size; + } else { + if ((pt = malloc(ptsize = 1024 - 4)) == NULL) + return (NULL); + ept = pt + ptsize; + } + bpt = ept - 1; + *bpt = '\0'; + + /* + * Allocate bytes (1024 - malloc space) for the string of "../"'s. + * Should always be enough (it's 340 levels). If it's not, allocate + * as necessary. Special case the first stat, it's ".", not "..". + */ + if ((up = malloc(upsize = 1024 - 4)) == NULL) + goto err; + eup = up + MAXPATHLEN; + bup = up; + up[0] = '.'; + up[1] = '\0'; + + /* Save root values, so know when to stop. */ + if (stat("/", &s)) + goto err; + root_dev = s.st_dev; + root_ino = s.st_ino; + + errno = 0; /* XXX readdir has no error return. */ + + for (first = 1;; first = 0) { + /* Stat the current level. */ + if (lstat(up, &s)) + goto err; + + /* Save current node values. */ + ino = s.st_ino; + dev = s.st_dev; + + /* Check for reaching root. */ + if (root_dev == dev && root_ino == ino) { + *--bpt = '/'; + /* + * It's unclear that it's a requirement to copy the + * path to the beginning of the buffer, but it's always + * been that way and stuff would probably break. + */ + (void)bcopy(bpt, pt, ept - bpt); + free(up); + return (pt); + } + + /* + * Build pointer to the parent directory, allocating memory + * as necessary. Max length is 3 for "../", the largest + * possible component name, plus a trailing NULL. + */ + if (bup + 3 + MAXNAMLEN + 1 >= eup) { + if ((up = realloc(up, upsize *= 2)) == NULL) + goto err; + bup = up; + eup = up + upsize; + } + *bup++ = '.'; + *bup++ = '.'; + *bup = '\0'; + + /* Open and stat parent directory. */ + if (!(dir = opendir(up)) || fstat(dirfd(dir), &s)) + goto err; + + /* Add trailing slash for next directory. */ + *bup++ = '/'; + + /* + * If it's a mount point, have to stat each element because + * the inode number in the directory is for the entry in the + * parent directory, not the inode number of the mounted file. + */ + save_errno = 0; + if (s.st_dev == dev) { + for (;;) { + if (!(dp = readdir(dir))) + goto notfound; + if (dp->d_fileno == ino) + break; + } + } else + for (;;) { + if (!(dp = readdir(dir))) + goto notfound; + if (ISDOT(dp)) + continue; + bcopy(dp->d_name, bup, dp->d_namlen + 1); + + /* Save the first error for later. */ + if (lstat(up, &s)) { + if (!save_errno) + save_errno = errno; + errno = 0; + continue; + } + if (s.st_dev == dev && s.st_ino == ino) + break; + } + + /* + * Check for length of the current name, preceding slash, + * leading slash. + */ + if (bpt - pt <= dp->d_namlen + (first ? 1 : 2)) { + size_t len, off; + + if (!ptsize) { + errno = ERANGE; + goto err; + } + off = bpt - pt; + len = ept - bpt; + if ((pt = realloc(pt, ptsize *= 2)) == NULL) + goto err; + bpt = pt + off; + ept = pt + ptsize; + (void)bcopy(bpt, ept - len, len); + bpt = ept - len; + } + if (!first) + *--bpt = '/'; + bpt -= dp->d_namlen; + bcopy(dp->d_name, bpt, dp->d_namlen); + (void)closedir(dir); + + /* Truncate any file name. */ + *bup = '\0'; + } + +notfound: + /* + * If readdir set errno, use it, not any saved error; otherwise, + * didn't find the current directory in its parent directory, set + * errno to ENOENT. + */ + if (!errno) + errno = save_errno ? save_errno : ENOENT; + /* FALLTHROUGH */ +err: + if (ptsize) + free(pt); + free(up); + return (NULL); +} diff --git a/gen/getdomainname.3 b/gen/getdomainname.3 new file mode 100644 index 0000000..bb2b8a1 --- /dev/null +++ b/gen/getdomainname.3 @@ -0,0 +1,98 @@ +.\" Copyright (c) 1983, 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. +.\" +.\" @(#)gethostname.3 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD: src/lib/libc/gen/getdomainname.3,v 1.14 2001/10/01 16:08:51 ru Exp $ +.\" +.Dd May 6, 1994 +.Dt GETDOMAINNAME 3 +.Os +.Sh NAME +.Nm getdomainname , +.Nm setdomainname +.Nd get/set domain name of current host +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In unistd.h +.Ft int +.Fn getdomainname "char *name" "int namelen" +.Ft int +.Fn setdomainname "const char *name" "int namelen" +.Sh DESCRIPTION +.Fn Getdomainname +returns the standard domain name for the current processor, as +previously set by +.Fn setdomainname . +The parameter +.Fa namelen +specifies the size of the +.Fa name +array. The returned name is null-terminated unless insufficient +space is provided. +.Pp +.Fn Setdomainname +sets the domain name of the host machine to be +.Fa name , +which has length +.Fa namelen . +This call is restricted to the super-user and +is normally used only when the system is bootstrapped. +.Sh RETURN VALUES +.Rv -std +.Sh ERRORS +The following errors may be returned by these calls: +.Bl -tag -width Er +.It Bq Er EFAULT +The +.Fa name +or +.Fa namelen +parameter gave an +invalid address. +.It Bq Er EPERM +The caller tried to set the hostname and was not the super-user. +.El +.Sh SEE ALSO +.Xr gethostid 3 , +.Xr gethostname 3 , +.Xr sysctl 3 +.Sh BUGS +Domain names are limited to +.Dv MAXHOSTNAMELEN +(from +.Ao Pa sys/param.h Ac ) +characters, currently 256. +.Sh HISTORY +The +.Fn getdomainname +function call appeared in +.Bx 4.2 . diff --git a/gen/getfsent.3 b/gen/getfsent.3 new file mode 100644 index 0000000..a898b04 --- /dev/null +++ b/gen/getfsent.3 @@ -0,0 +1,153 @@ +.\" Copyright (c) 1983, 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. +.\" +.\" @(#)getfsent.3 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD: src/lib/libc/gen/getfsent.3,v 1.9 2001/10/01 16:08:51 ru Exp $ +.\" +.Dd June 4, 1993 +.Dt GETFSENT 3 +.Os +.Sh NAME +.Nm getfsent , +.Nm getfsspec , +.Nm getfsfile , +.Nm setfsent , +.Nm endfsent +.Nd get file system descriptor file entry +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In fstab.h +.Ft struct fstab * +.Fn getfsent void +.Ft struct fstab * +.Fn getfsspec "const char *spec" +.Ft struct fstab * +.Fn getfsfile "const char *file" +.Ft int +.Fn setfsent void +.Ft void +.Fn endfsent void +.Sh DESCRIPTION +The +.Fn getfsent , +.Fn getfsspec , +and +.Fn getfsfile +functions +each return a pointer to an object with the following structure +containing the broken-out fields of a line in the file system +description file, +.Aq Pa fstab.h . +.Bd -literal -offset indent +struct fstab { + char *fs_spec; /* block special device name */ + char *fs_file; /* file system path prefix */ + char *fs_vfstype; /* File system type, ufs, nfs */ + char *fs_mntops; /* Mount options ala -o */ + char *fs_type; /* FSTAB_* from fs_mntops */ + int fs_freq; /* dump frequency, in days */ + int fs_passno; /* pass number on parallel fsck */ +}; +.Ed +.Pp +The fields have meanings described in +.Xr fstab 5 . +.Pp +The +.Fn setfsent +function +opens the file (closing any previously opened file) or rewinds it +if it is already open. +.Pp +The +.Fn endfsent +function +closes the file. +.Pp +The +.Fn getfsspec +and +.Fn getfsfile +functions +search the entire file (opening it if necessary) for a matching special +file name or file system file name. +.Pp +For programs wishing to read the entire database, +.Fn getfsent +reads the next entry (opening the file if necessary). +.Pp +All entries in the file with a type field equivalent to +.Dv FSTAB_XX +are ignored. +.Sh RETURN VALUES +The +.Fn getfsent , +.Fn getfsspec , +and +.Fn getfsfile +functions +return a +.Dv NULL +pointer on +.Dv EOF +or error. +The +.Fn setfsent +function +returns 0 on failure, 1 on success. +The +.Fn endfsent +function +returns nothing. +.Sh FILES +.Bl -tag -width /etc/fstab -compact +.It Pa /etc/fstab +.El +.Sh SEE ALSO +.Xr fstab 5 +.Sh HISTORY +The +.Fn getfsent +function appeared in +.Bx 4.0 ; +the +.Fn endfsent , +.Fn getfsfile , +.Fn getfsspec , +and +.Fn setfsent +functions appeared in +.Bx 4.3 . +.Sh BUGS +These functions use static data storage; +if the data is needed for future use, it should be +copied before any subsequent calls overwrite it. diff --git a/gen/getgrent.3 b/gen/getgrent.3 new file mode 100644 index 0000000..6b12306 --- /dev/null +++ b/gen/getgrent.3 @@ -0,0 +1,203 @@ +.\" Copyright (c) 1989, 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. +.\" +.\" From: @(#)getgrent.3 8.2 (Berkeley) 4/19/94 +.\" $FreeBSD: src/lib/libc/gen/getgrent.3,v 1.16 2001/10/01 16:08:51 ru Exp $ +.\" +.Dd September 29, 1994 +.Dt GETGRENT 3 +.Os +.Sh NAME +.Nm getgrent , +.Nm getgrnam , +.Nm getgrgid , +.Nm setgroupent , +.\" .Nm setgrfile , +.Nm setgrent , +.Nm endgrent +.Nd group database operations +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In sys/types.h +.In grp.h +.Ft struct group * +.Fn getgrent void +.Ft struct group * +.Fn getgrnam "const char *name" +.Ft struct group * +.Fn getgrgid "gid_t gid" +.Ft int +.Fn setgroupent "int stayopen" +.\" .Ft void +.\" .Fn setgrfile "const char *name" +.Ft int +.Fn setgrent void +.Ft void +.Fn endgrent void +.Sh DESCRIPTION +These functions operate on the group database file +.Pa /etc/group +which is described +in +.Xr group 5 . +Each line of the database is defined by the structure +.Ar group +found in the include +file +.Aq Pa grp.h : +.Bd -literal -offset indent +struct group { + char *gr_name; /* group name */ + char *gr_passwd; /* group password */ + int gr_gid; /* group id */ + char **gr_mem; /* group members */ +}; +.Ed +.Pp +The functions +.Fn getgrnam +and +.Fn getgrgid +search the group database for the given group name pointed to by +.Ar name +or the group id pointed to by +.Ar gid , +respectively, returning the first one encountered. Identical group +names or group gids may result in undefined behavior. +.Pp +The +.Fn getgrent +function +sequentially reads the group database and is intended for programs +that wish to step through the complete list of groups. +.Pp +All three routines will open the group file for reading, if necessary. +.Pp +The +.Fn setgroupent +function +opens the file, or rewinds it if it is already open. If +.Fa stayopen +is non-zero, file descriptors are left open, significantly speeding +functions subsequent calls. This functionality is unnecessary for +.Fn getgrent +as it doesn't close its file descriptors by default. It should also +be noted that it is dangerous for long-running programs to use this +functionality as the group file may be updated. +.Pp +The +.Fn setgrent +function +is identical to +.Fn setgroupent +with an argument of zero. +.Pp +The +.Fn endgrent +function +closes any open files. +.Sh RETURN VALUES +The functions +.Fn getgrent , +.Fn getgrnam , +and +.Fn getgrgid , +return a pointer to the group entry if successful; if end-of-file +is reached or an error occurs a null pointer is returned. +The functions +.Fn setgroupent +and +.Fn setgrent +return the value 1 if successful, otherwise the value +0 is returned. +The functions +.Fn endgrent +and +.Fn setgrfile +have no return value. +.Sh FILES +.Bl -tag -width /etc/group -compact +.It Pa /etc/group +group database file +.El +.Sh SEE ALSO +.Xr getpwent 3 , +.Xr yp 4 , +.Xr group 5 , +.Xr nsswitch.conf 5 +.Sh HISTORY +The functions +.Fn endgrent , +.Fn getgrent , +.Fn getgrnam , +.Fn getgrgid , +and +.Fn setgrent +appeared in +.At v7 . +The functions +.Fn setgrfile +and +.Fn setgroupent +appeared in +.Bx 4.3 Reno . +.Sh COMPATIBILITY +The historic function +.Fn setgrfile , +which allowed the specification of alternate password databases, has +been deprecated and is no longer available. +.Sh BUGS +The functions +.Fn getgrent , +.Fn getgrnam , +.Fn getgrgid , +.Fn setgroupent +and +.Fn setgrent +leave their results in an internal static object and return +a pointer to that object. +Subsequent calls to +the same function +will modify the same object. +.Pp +The functions +.Fn getgrent , +.Fn endgrent , +.Fn setgroupent , +and +.Fn setgrent +are fairly useless in a networked environment and should be +avoided, if possible. +.Fn getgrent +makes no attempt to suppress duplicate information if multiple +sources are specified in +.Xr nsswitch.conf 5 . diff --git a/gen/getgrouplist.3 b/gen/getgrouplist.3 new file mode 100644 index 0000000..28364eb --- /dev/null +++ b/gen/getgrouplist.3 @@ -0,0 +1,96 @@ +.\" 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. +.\" +.\" @(#)getgrouplist.3 8.1 (Berkeley) 6/9/93 +.\" $FreeBSD: src/lib/libc/gen/getgrouplist.3,v 1.7 2001/10/01 16:08:51 ru Exp $ +.\" +.Dd June 9, 1993 +.Dt GETGROUPLIST 3 +.Os +.Sh NAME +.Nm getgrouplist +.Nd calculate group access list +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In unistd.h +.Ft int +.Fn getgrouplist "const char *name" "int basegid" "int *groups" "int *ngroups" +.Sh DESCRIPTION +The +.Fn getgrouplist +function reads through the group file and calculates +the group access list for the user specified in +.Fa name . +The +.Fa basegid +is automatically included in the groups list. +Typically this value is given as +the group number from the password file. +.Pp +The resulting group list is returned in the integer array pointed to by +.Fa groups . +The caller specifies the size of the +.Fa groups +array in the integer pointed to by +.Fa ngroups ; +the actual number of groups found is returned in +.Fa ngroups . +.Sh RETURN VALUES +The +.Fn getgrouplist +function +returns \-1 if the size of the group list is too small to +hold all the user's groups. +Here, the group array will be filled with as many groups as will fit. +.Sh FILES +.Bl -tag -width /etc/group -compact +.It Pa /etc/group +group membership list +.El +.Sh SEE ALSO +.Xr setgroups 2 , +.Xr initgroups 3 +.Sh HISTORY +The +.Fn getgrouplist +function first appeared in +.Bx 4.4 . +.Sh BUGS +The +.Fn getgrouplist +function +uses the routines based on +.Xr getgrent 3 . +If the invoking program uses any of these routines, +the group structure will +be overwritten in the call to +.Fn getgrouplist . diff --git a/gen/getgrouplist.c b/gen/getgrouplist.c new file mode 100644 index 0000000..ff9b54d --- /dev/null +++ b/gen/getgrouplist.c @@ -0,0 +1,110 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * 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. + */ + +#if defined(LIBC_SCCS) && !defined(lint) +static char sccsid[] = "@(#)getgrouplist.c 8.2 (Berkeley) 12/8/94"; +#endif /* LIBC_SCCS and not lint */ + +/* + * get credential + */ +#include +#include +#include + +int +getgrouplist(uname, agroup, groups, grpcnt) + const char *uname; + int agroup; + register int *groups; + int *grpcnt; +{ + register struct group *grp; + register struct passwd *pw; + register int i, ngroups; + int ret, maxgroups; + + ret = 0; + ngroups = 0; + maxgroups = *grpcnt; + /* + * When installing primary group, duplicate it; + * the first element of groups is the effective gid + * and will be overwritten when a setgid file is executed. + */ + groups[ngroups++] = agroup; + if (maxgroups > 1) + groups[ngroups++] = agroup; + /* + * Scan the group file to find additional groups. + */ + setgrent(); + while (grp = getgrent()) { + if (grp->gr_gid == agroup) + continue; + for (i = 0; grp->gr_mem[i]; i++) { + if (!strcmp(grp->gr_mem[i], uname)) { + if (ngroups >= maxgroups) { + ret = -1; + break; + } + groups[ngroups++] = grp->gr_gid; + break; + } + } + } + endgrent(); + *grpcnt = ngroups; + return (ret); +} diff --git a/gen/gethostname.3 b/gen/gethostname.3 new file mode 100644 index 0000000..9651d8d --- /dev/null +++ b/gen/gethostname.3 @@ -0,0 +1,99 @@ +.\" Copyright (c) 1983, 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. +.\" +.\" @(#)gethostname.3 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD: src/lib/libc/gen/gethostname.3,v 1.11 2001/10/01 16:08:51 ru Exp $ +.\" +.Dd June 4, 1993 +.Dt GETHOSTNAME 3 +.Os +.Sh NAME +.Nm gethostname , +.Nm sethostname +.Nd get/set name of current host +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In unistd.h +.Ft int +.Fn gethostname "char *name" "int namelen" +.Ft int +.Fn sethostname "const char *name" "int namelen" +.Sh DESCRIPTION +.Fn Gethostname +returns the standard host name for the current processor, as +previously set by +.Fn sethostname . +The parameter +.Fa namelen +specifies the size of the +.Fa name +array. The returned name is null-terminated unless insufficient +space is provided. +.Pp +.Fn Sethostname +sets the name of the host machine to be +.Fa name , +which has length +.Fa namelen . +This call is restricted to the super-user and +is normally used only when the system is bootstrapped. +.Sh RETURN VALUES +.Rv -std +.Sh ERRORS +The following errors may be returned by these calls: +.Bl -tag -width Er +.It Bq Er EFAULT +The +.Fa name +or +.Fa namelen +parameter gave an +invalid address. +.It Bq Er EPERM +The caller tried to set the hostname and was not the super-user. +.El +.Sh SEE ALSO +.Xr gethostid 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 HISTORY +The +.Fn gethostname +function call appeared in +.Bx 4.2 . diff --git a/gen/gethostname.c b/gen/gethostname.c new file mode 100644 index 0000000..50ce9b5 --- /dev/null +++ b/gen/gethostname.c @@ -0,0 +1,74 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1989, 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 +#include + + +long +gethostname(name, namelen) + char *name; + int namelen; +{ + int mib[2]; + size_t size; + + mib[0] = CTL_KERN; + mib[1] = KERN_HOSTNAME; + size = namelen; + if (sysctl(mib, 2, name, &size, NULL, 0) == -1) + return (-1); + return (0); +} diff --git a/gen/getloadavg.3 b/gen/getloadavg.3 new file mode 100644 index 0000000..24e7cdf --- /dev/null +++ b/gen/getloadavg.3 @@ -0,0 +1,69 @@ +.\" Copyright (c) 1989, 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. +.\" +.\" @(#)getloadavg.3 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD: src/lib/libc/gen/getloadavg.3,v 1.8 2001/10/01 16:08:51 ru Exp $ +.\" +.Dd June 4, 1993 +.Dt GETLOADAVG 3 +.Os +.Sh NAME +.Nm getloadavg +.Nd get system load averages +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In stdlib.h +.Ft int +.Fn getloadavg "double loadavg[]" "int nelem" +.Sh DESCRIPTION +The +.Fn getloadavg +function returns the number of processes in the system run queue +averaged over various periods of time. +Up to +.Fa nelem +samples are retrieved and assigned to successive elements of +.Fa loadavg Ns Bq . +The system imposes a maximum of 3 samples, representing averages +over the last 1, 5, and 15 minutes, respectively. +.Sh DIAGNOSTICS +If the load average was unobtainable, \-1 is returned; otherwise, +the number of samples actually retrieved is returned. +.Sh SEE ALSO +.Xr uptime 1 , +.Xr kvm_getloadavg 3 , +.Xr sysctl 3 +.Sh HISTORY +The +.Fn getloadavg +function appeared in +.Bx 4.3 Reno . diff --git a/gen/getloadavg.c b/gen/getloadavg.c new file mode 100644 index 0000000..e65fdff --- /dev/null +++ b/gen/getloadavg.c @@ -0,0 +1,92 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1989, 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 +#include +#include +#include + +#if 0 +#include +#endif /* 0 */ + +#include + +/* + * getloadavg() -- Get system load averages. + * + * Put `nelem' samples into `loadavg' array. + * Return number of samples retrieved, or -1 on error. + */ +int +getloadavg(loadavg, nelem) + double loadavg[]; + int nelem; +{ + struct loadavg loadinfo; + int i, mib[2]; + size_t size; + + mib[0] = CTL_VM; + mib[1] = VM_LOADAVG; + size = sizeof(loadinfo); + if (sysctl(mib, 2, &loadinfo, &size, NULL, 0) < 0) + return (-1); + + nelem = MIN(nelem, sizeof(loadinfo.ldavg) / sizeof(fixpt_t)); + for (i = 0; i < nelem; i++) + loadavg[i] = (double) loadinfo.ldavg[i] / loadinfo.fscale; + return (nelem); +} diff --git a/gen/getlogin.c b/gen/getlogin.c new file mode 100644 index 0000000..1d9b8f2 --- /dev/null +++ b/gen/getlogin.c @@ -0,0 +1,83 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1988, 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 +#include +#include +#include +#include +#include +#include + +int _logname_valid = 0; /* known to setlogin() */ + +char * +getlogin() +{ + static char *logname = NULL; + + if ( logname == NULL ) { + logname = malloc(MAXLOGNAME+1); + if ( logname == NULL ) + return NULL; + } + + if (_logname_valid == 0) { + if (_getlogin(logname, MAXLOGNAME) < 0) + return ((char *)NULL); + _logname_valid = 1; + } + return (*logname ? logname : (char *)NULL); +} diff --git a/gen/getmntinfo.3 b/gen/getmntinfo.3 new file mode 100644 index 0000000..58c08b8 --- /dev/null +++ b/gen/getmntinfo.3 @@ -0,0 +1,113 @@ +.\" Copyright (c) 1989, 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. +.\" +.\" @(#)getmntinfo.3 8.1 (Berkeley) 6/9/93 +.\" $FreeBSD: src/lib/libc/gen/getmntinfo.3,v 1.11 2001/10/01 16:08:51 ru Exp $ +.\" +.Dd June 9, 1993 +.Dt GETMNTINFO 3 +.Os +.Sh NAME +.Nm getmntinfo +.Nd get information about mounted file systems +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In sys/param.h +.In sys/ucred.h +.In sys/mount.h +.Ft int +.Fn getmntinfo "struct statfs **mntbufp" "int flags" +.Sh DESCRIPTION +The +.Fn getmntinfo +function +returns an array of +.Fn statfs +structures describing each currently mounted file system (see +.Xr statfs 2 ) . +.Pp +The +.Fn getmntinfo +function +passes its +.Fa flags +parameter transparently to +.Xr getfsstat 2 . +.Sh RETURN VALUES +On successful completion, +.Fn getmntinfo +returns a count of the number of elements in the array. +The pointer to the array is stored into +.Fa mntbufp . +.Pp +If an error occurs, zero is returned and the external variable +.Va errno +is set to indicate the error. +Although the pointer +.Fa mntbufp +will be unmodified, any information previously returned by +.Fn getmntinfo +will be lost. +.Sh ERRORS +The +.Fn getmntinfo +function +may fail and set errno for any of the errors specified for the library +routines +.Xr getfsstat 2 +or +.Xr malloc 3 . +.Sh SEE ALSO +.Xr getfsstat 2 , +.Xr mount 2 , +.Xr statfs 2 , +.Xr mount 8 +.Sh HISTORY +The +.Fn getmntinfo +function first appeared in +.Bx 4.4 . +.Sh BUGS +The +.Fn getmntinfo +function writes the array of structures to an internal static object +and returns +a pointer to that object. +Subsequent calls to +.Fn getmntinfo +will modify the same object. +.Pp +The memory allocated by +.Fn getmntinfo +cannot be +.Xr free 3 Ns 'd +by the application. diff --git a/gen/getmntinfo.c b/gen/getmntinfo.c new file mode 100644 index 0000000..9284aa7 --- /dev/null +++ b/gen/getmntinfo.c @@ -0,0 +1,88 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1989, 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 +#include +#include +#include + +/* + * Return information about mounted filesystems. + */ +int +getmntinfo(mntbufp, flags) + struct statfs **mntbufp; + int flags; +{ + static struct statfs *mntbuf; + static int mntsize; + static long bufsize; + + if (mntsize <= 0 && (mntsize = getfsstat(0, 0, MNT_NOWAIT)) < 0) + return (0); + if (bufsize > 0 && (mntsize = getfsstat(mntbuf, bufsize, flags)) < 0) + return (0); + while (bufsize <= mntsize * sizeof(struct statfs)) { + if (mntbuf) + free(mntbuf); + bufsize = (mntsize + 1) * sizeof(struct statfs); + if ((mntbuf = (struct statfs *)malloc(bufsize)) == 0) + return (0); + if ((mntsize = getfsstat(mntbuf, bufsize, flags)) < 0) + return (0); + } + *mntbufp = mntbuf; + return (mntsize); +} diff --git a/gen/getnetgrent.3 b/gen/getnetgrent.3 new file mode 100644 index 0000000..7124aef --- /dev/null +++ b/gen/getnetgrent.3 @@ -0,0 +1,133 @@ +.\" 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. +.\" +.\" @(#)getnetgrent.3 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD: src/lib/libc/gen/getnetgrent.3,v 1.10 2001/10/01 16:08:51 ru Exp $ +.\" +.Dd June 4, 1993 +.Dt GETNETGRENT 3 +.Os +.Sh NAME +.Nm getnetgrent , +.Nm innetgr , +.Nm setnetgrent , +.Nm endnetgrent +.Nd netgroup database operations +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In netdb.h +.Ft int +.Fn getnetgrent "char **host" "char **user" "char **domain" +.Ft int +.Fn innetgr "const char *netgroup" "const char *host" "const char *user" "const char *domain" +.Ft void +.Fn setnetgrent "const char *netgroup" +.Ft void +.Fn endnetgrent void +.Sh DESCRIPTION +These functions operate on the netgroup database file +.Pa /etc/netgroup +which is described +in +.Xr netgroup 5 . +The database defines a set of netgroups, each made up of one or more triples: +.Bd -literal -offset indent +(host, user, domain) +.Ed +that defines a combination of host, user and domain. +Any of the three fields may be specified as ``wildcards'' that match any +string. +.Pp +The function +.Fn getnetgrent +sets the three pointer arguments to the strings of the next member of the +current netgroup. +If any of the string pointers are +.Sy (char *)0 +that field is considered a wildcard. +.Pp +The functions +.Fn setnetgrent +and +.Fn endnetgrent +set the current netgroup and terminate the current netgroup respectively. +If +.Fn setnetgrent +is called with a different netgroup than the previous call, an implicit +.Fn endnetgrent +is implied. +.Fn Setnetgrent +also sets the offset to the first member of the netgroup. +.Pp +The function +.Fn innetgr +searches for a match of all fields within the specified group. +If any of the +.Sy host , +.Sy user , +or +.Sy domain +arguments are +.Sy (char *)0 +those fields will match any string value in the netgroup member. +.Sh RETURN VALUES +The function +.Fn getnetgrent +returns 0 for ``no more netgroup members'' and 1 otherwise. +The function +.Fn innetgr +returns 1 for a successful match and 0 otherwise. +The functions +.Fn setnetgrent +and +.Fn endnetgrent +have no return value. +.Sh FILES +.Bl -tag -width /etc/netgroup -compact +.It Pa /etc/netgroup +netgroup database file +.El +.Sh SEE ALSO +.Xr netgroup 5 +.Sh COMPATIBILITY +The netgroup members have three string fields to maintain compatibility +with other vendor implementations, however it is not obvious what use the +.Sy domain +string has within +.Bx . +.Sh BUGS +The function +.Fn getnetgrent +returns pointers to dynamically allocated data areas that are freed when +the function +.Fn endnetgrent +is called. diff --git a/gen/getobjformat.3 b/gen/getobjformat.3 new file mode 100644 index 0000000..ce1144c --- /dev/null +++ b/gen/getobjformat.3 @@ -0,0 +1,128 @@ +.\" Copyright (c) 1998 John D. Polstra +.\" 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/getobjformat.3,v 1.8 2001/10/01 16:08:51 ru Exp $ +.\" +.Dd September 7, 1998 +.Dt GETOBJFORMAT 3 +.Os +.Sh NAME +.Nm getobjformat +.Nd get preferred object file format +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In objformat.h +.Ft int +.Fn getobjformat "char *buf" "size_t bufsize" "int *argcp" "char **argv" +.Sh DESCRIPTION +.Fn getobjformat +queries several sources to determine the preferred object file +format, and copies its name into a buffer provided by the caller. +.Pp +The object file format is determined as follows. If +.Va argv +is +.No non- Ns Ev NULL +and an explicit command line argument such as +.Fl aout +or +.Fl elf +is present, then that determines the object file format. +.Pp +Otherwise, if the variable +.Ev OBJFORMAT +is set in the environment, the object file format is taken from its +value. +.Pp +Otherwise, if the file +.Pa /etc/objformat +is readable and contains a line of the form +.Ql OBJFORMAT=xxx , +the object file format is taken from there. +.Pp +Otherwise, a built-in system default object file format is returned. +.Pp +.Va buf +points to a user-supplied buffer into which the name of the object +file format is copied. +.Va bufsize +gives the size of the buffer in bytes. The string placed in +.Va buf +is always null-terminated. It is an error if the buffer is too +small to hold the null-terminated name. +.Pp +.Va argv +points to a +.Dv NULL Ns -terminated +argument vector to be scanned for object +format options. +.Va argv +may be +.Dv NULL , +in which case the argument vector is not scanned. +.Pp +If +.Va argcp +is non-NULL, any object format options are deleted from the +argument vector, and the updated argument count is stored into +the integer referenced by +.Va argcp . +If +.Va argcp +is +.Dv NULL , +the argument vector is left unchanged. +.Sh RETURN VALUES +On success, +.Fn getobjformat +returns the length of the object file format name, not counting the +null terminator. +If the supplied buffer is too small to hold the object file format +and its null terminator, +.Fn getobjformat +returns -1. In that case, the contents of the buffer and argument +vector supplied by the caller are indeterminate. +.Sh ENVIRONMENT +.Bl -tag -width OBJFORMAT +.It Ev OBJFORMAT +If the environment variable +.Ev OBJFORMAT +is set, it overrides the default object file format. +.Ev OBJFORMAT takes precedence over +.Pa /etc/objformat . +.El +.Sh FILES +.Bl -tag -width /etc/objformat -compact +.It Pa /etc/objformat +If present, specifies the object file format to use. Syntax is +.Ql OBJFORMAT=xxx . +.El +.Sh SEE ALSO +.Xr objformat 1 +.Sh HISTORY +The +.Fn getobjformat +function first appeared in +.Fx 3.0 . diff --git a/gen/getpagesize.3 b/gen/getpagesize.3 new file mode 100644 index 0000000..8f4cad3 --- /dev/null +++ b/gen/getpagesize.3 @@ -0,0 +1,63 @@ +.\" Copyright (c) 1983, 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. +.\" +.\" @(#)getpagesize.3 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD: src/lib/libc/gen/getpagesize.3,v 1.9 2001/10/01 16:08:51 ru Exp $ +.\" +.Dd June 4, 1993 +.Dt GETPAGESIZE 3 +.Os +.Sh NAME +.Nm getpagesize +.Nd get system page size +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In unistd.h +.Ft int +.Fn getpagesize void +.Sh DESCRIPTION +.Fn Getpagesize +returns the number of bytes in a page. +Page granularity is the granularity of many of the memory +management calls. +.Pp +The page size is a system +page size and may not be the same as the underlying +hardware page size. +.Sh SEE ALSO +.Xr pagesize 1 , +.Xr sbrk 2 +.Sh HISTORY +The +.Fn getpagesze +function call appeared in +.Bx 4.2 . diff --git a/gen/getpagesize.c b/gen/getpagesize.c new file mode 100644 index 0000000..c10d072 --- /dev/null +++ b/gen/getpagesize.c @@ -0,0 +1,72 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1989, 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 +#include + +int +getpagesize() +{ + int mib[2], value; + size_t size; + + mib[0] = CTL_HW; + mib[1] = HW_PAGESIZE; + size = sizeof value; + if (sysctl(mib, 2, &value, &size, NULL, 0) == -1) + return (-1); + return (value); +} + diff --git a/gen/getpass.3 b/gen/getpass.3 new file mode 100644 index 0000000..430a47e --- /dev/null +++ b/gen/getpass.3 @@ -0,0 +1,96 @@ +.\" Copyright (c) 1989, 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. +.\" +.\" @(#)getpass.3 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD: src/lib/libc/gen/getpass.3,v 1.9 2001/10/01 16:08:51 ru Exp $ +.\" +.Dd June 4, 1993 +.Dt GETPASS 3 +.Os +.Sh NAME +.Nm getpass +.Nd get a password +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In pwd.h +.In unistd.h +.Ft char * +.Fn getpass "const char *prompt" +.Sh DESCRIPTION +The +.Fn getpass +function displays a prompt to, and reads in a password from, +.Pa /dev/tty . +If this file is not accessible, +.Fn getpass +displays the prompt on the standard error output and reads from the standard +input. +.Pp +The password may be up to _PASSWORD_LEN (currently 128) +characters in length. +Any additional +characters and the terminating newline character are discarded. +.Pp +The +.Fn getpass +function turns off character echoing while reading the password. +.Sh RETURN VALUES +The +.Fn getpass +function returns a pointer to the null terminated password. +.Sh FILES +.Bl -tag -width /dev/tty -compact +.It Pa /dev/tty +.El +.Sh SEE ALSO +.Xr crypt 3 +.Sh HISTORY +A +.Fn getpass +function appeared in +.At v7 . +.Sh BUGS +The +.Fn getpass +function leaves its result in an internal static object and returns +a pointer to that object. +Subsequent calls to +.Fn getpass +will modify the same object. +.Pp +The calling process should zero the password as soon as possible to +avoid leaving the cleartext password visible in the process's address +space. +.Pp +Upon receipt of a SIGTSTP, the input buffer will be flushed, so any +partially typed password must be retyped when the process +continues. diff --git a/gen/getpass.c b/gen/getpass.c new file mode 100644 index 0000000..a09ca80 --- /dev/null +++ b/gen/getpass.c @@ -0,0 +1,109 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1988, 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 +#include + +#include +#include +#include +#include + +char * +getpass(prompt) + const char *prompt; +{ + struct termios term; + register int ch; + register char *p; + FILE *fp, *outfp; + long omask; + int echo; + static char buf[_PASSWORD_LEN + 1]; + + /* + * read and write to /dev/tty if possible; else read from + * stdin and write to stderr. + */ + if ((outfp = fp = fopen(_PATH_TTY, "w+")) == NULL) { + outfp = stderr; + fp = stdin; + } + /* + * note - blocking signals isn't necessarily the + * right thing, but we leave it for now. + */ + omask = sigblock(sigmask(SIGINT)|sigmask(SIGTSTP)); + (void)tcgetattr(fileno(fp), &term); + if (echo = (term.c_lflag & ECHO)) { + term.c_lflag &= ~ECHO; + (void)tcsetattr(fileno(fp), TCSAFLUSH|TCSASOFT, &term); + } + (void)fputs(prompt, outfp); + rewind(outfp); /* implied flush */ + for (p = buf; (ch = getc(fp)) != EOF && ch != '\n';) + if (p < buf + _PASSWORD_LEN) + *p++ = ch; + *p = '\0'; + (void)write(fileno(outfp), "\n", 1); + if (echo) { + term.c_lflag |= ECHO; + (void)tcsetattr(fileno(fp), TCSAFLUSH|TCSASOFT, &term); + } + (void)sigsetmask(omask); + if (fp != stdin) + (void)fclose(fp); + return(buf); +} diff --git a/gen/getpeereid.3 b/gen/getpeereid.3 new file mode 100644 index 0000000..ef07e29 --- /dev/null +++ b/gen/getpeereid.3 @@ -0,0 +1,134 @@ +.\" +.\" 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 getpeerid +.Sh ERRORS +.Fn getpeerid +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 . diff --git a/gen/getpwent.3 b/gen/getpwent.3 new file mode 100644 index 0000000..6ce2003 --- /dev/null +++ b/gen/getpwent.3 @@ -0,0 +1,218 @@ +.\" Copyright (c) 1988, 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. +.\" +.\" From: @(#)getpwent.3 8.2 (Berkeley) 12/11/93 +.\" $FreeBSD: src/lib/libc/gen/getpwent.3,v 1.18 2001/10/01 16:08:51 ru Exp $ +.\" +.Dd September 20, 1994 +.Dt GETPWENT 3 +.Os +.Sh NAME +.Nm getpwent , +.Nm getpwnam , +.Nm getpwuid , +.Nm setpassent , +.Nm setpwent , +.Nm endpwent +.Nd password database operations +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In sys/types.h +.In pwd.h +.Ft struct passwd * +.Fn getpwent void +.Ft struct passwd * +.Fn getpwnam "const char *login" +.Ft struct passwd * +.Fn getpwuid "uid_t uid" +.Ft int +.Fn setpassent "int stayopen" +.Ft void +.Fn setpwent void +.Ft void +.Fn endpwent void +.Sh DESCRIPTION +These functions +operate on the password database file +which is described +in +.Xr passwd 5 . +Each entry in the database is defined by the structure +.Ar passwd +found in the include +file +.Aq Pa pwd.h : +.Bd -literal -offset indent +struct passwd { + char *pw_name; /* user name */ + char *pw_passwd; /* encrypted password */ + uid_t pw_uid; /* user uid */ + gid_t pw_gid; /* user gid */ + 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 */ + int pw_fields; /* internal: fields filled in */ +}; +.Ed +.Pp +The functions +.Fn getpwnam +and +.Fn getpwuid +search the password database for the given login name or user uid, +respectively, always returning the first one encountered. +.Pp +The +.Fn getpwent +function +sequentially reads the password database and is intended for programs +that wish to process the complete list of users. +.Pp +The +.Fn setpassent +function +accomplishes two purposes. +First, it causes +.Fn getpwent +to ``rewind'' to the beginning of the database. +Additionally, if +.Fa stayopen +is non-zero, file descriptors are left open, significantly speeding +up subsequent accesses for all of the routines. +(This latter functionality is unnecessary for +.Fn getpwent +as it doesn't close its file descriptors by default.) +.Pp +It is dangerous for long-running programs to keep the file descriptors +open as the database will become out of date if it is updated while the +program is running. +.Pp +The +.Fn setpwent +function +is identical to +.Fn setpassent +with an argument of zero. +.Pp +The +.Fn endpwent +function +closes any open files. +.Pp +These routines have been written to ``shadow'' the password file, e.g.\& +allow only certain programs to have access to the encrypted password. +If the process which calls them has an effective uid of 0, the encrypted +password will be returned, otherwise, the password field of the returned +structure will point to the string +.Ql * . +.Sh RETURN VALUES +The functions +.Fn getpwent , +.Fn getpwnam , +and +.Fn getpwuid , +return a valid pointer to a passwd structure on success +and a null pointer if end-of-file is reached or an error occurs. +The +.Fn setpassent +function returns 0 on failure and 1 on success. +The +.Fn endpwent +and +.Fn setpwent +functions +have no return value. +.Sh FILES +.Bl -tag -width /etc/master.passwd -compact +.It Pa /etc/pwd.db +The insecure password database file +.It Pa /etc/spwd.db +The secure password database file +.It Pa /etc/master.passwd +The current password file +.It Pa /etc/passwd +A Version 7 format password file +.El +.Sh SEE ALSO +.Xr getlogin 2 , +.Xr getgrent 3 , +.Xr yp 4 , +.Xr nsswitch.conf 5 , +.Xr passwd 5 , +.Xr pwd_mkdb 8 , +.Xr vipw 8 +.Sh HISTORY +The +.Fn getpwent , +.Fn getpwnam , +.Fn getpwuid , +.Fn setpwent , +and +.Fn endpwent +functions appeared in +.At v7 . +The +.Fn setpassent +function appeared in +.Bx 4.3 Reno . +.Sh COMPATIBILITY +The historic function +.Xr setpwfile 3 , +which allowed the specification of alternate password databases, +has been deprecated and is no longer available. +.Sh BUGS +The functions +.Fn getpwent , +.Fn getpwnam , +and +.Fn getpwuid , +leave their results in an internal static object and return +a pointer to that object. +Subsequent calls to +the same function +will modify the same object. +.Pp +The functions +.Fn getpwent , +.Fn endpwent , +.Fn setpassent , +and +.Fn setpwent +are fairly useless in a networked environment and should be +avoided, if possible. +.Fn getpwent +makes no attempt to suppress duplicate information if multiple +sources are specified in +.Xr nsswitch.conf 5 . diff --git a/gen/getttyent.3 b/gen/getttyent.3 new file mode 100644 index 0000000..56d7a5d --- /dev/null +++ b/gen/getttyent.3 @@ -0,0 +1,212 @@ +.\" Copyright (c) 1989, 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. +.\" +.\" @(#)getttyent.3 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD: src/lib/libc/gen/getttyent.3,v 1.12 2001/10/01 16:08:51 ru Exp $ +.\" +.Dd November 17, 1996 +.Dt GETTTYENT 3 +.Os +.Sh NAME +.Nm getttyent , +.Nm getttynam , +.Nm setttyent , +.Nm endttyent +.Nd get ttys file entry +.Nm isdialuptty , +.Nm isnettty +.Nd determine tty type from ttys file entry +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In ttyent.h +.Ft struct ttyent * +.Fn getttyent void +.Ft struct ttyent * +.Fn getttynam "const char *name" +.Ft int +.Fn setttyent void +.Ft int +.Fn endttyent void +.Ft int +.Fn isdialuptty "const char *name" +.Ft int +.Fn isnettty "const char *name" +.Sh DESCRIPTION +The +.Fn getttyent , +and +.Fn getttynam +functions +each return a pointer to an object, with the following structure, +containing the broken-out fields of a line from the tty description +file. +.Bd -literal +struct ttyent { + char *ty_name; /* terminal device name */ + char *ty_getty; /* command to execute, usually getty */ + char *ty_type; /* terminal type for termcap */ +#define TTY_ON 0x01 /* enable logins (start ty_getty program) */ +#define TTY_SECURE 0x02 /* allow uid of 0 to login */ +#define TTY_DIALUP 0x04 /* is a dialup tty */ +#define TTY_NETWORK 0x08 /* is a network tty */ + int ty_status; /* status flags */ + char *ty_window; /* command to start up window manager */ + char *ty_comment; /* comment field */ + char *ty_group; /* tty group name */ +}; +.Ed +.Pp +The fields are as follows: +.Bl -tag -width ty_comment +.It Fa ty_name +The name of the character-special file. +.It Fa ty_getty +The name of the command invoked by +.Xr init 8 +to initialize tty line characteristics. +.It Fa ty_type +The name of the default terminal type connected to this tty line. +.It Fa ty_status +A mask of bit fields which indicate various actions allowed on this +tty line. +The possible flags are as follows: +.Bl -tag -width TTY_NETWORK +.It Dv TTY_ON +Enables logins (i.e., +.Xr init 8 +will start the command referenced by +.Fa ty_getty +on this entry). +.It Dv TTY_SECURE +Allow users with a uid of 0 to login on this terminal. +.It Dv TTY_DIALUP +Identifies a tty as a dialin line. +If this flag is set, then +.Fn isdialuptty +will return a non-zero value. +.It Dv TTY_NETWORK +Identifies a tty used for network connections. +If this flag is set, then +.Fn isnettty +will return a non-zero value. +.El +.It Fa ty_window +The command to execute for a window system associated with the line. +.It Fa ty_group +A group name to which the tty belongs. +If no group is specified in the ttys description file, +then the tty is placed in an anonymous group called "none". +.It Fa ty_comment +Any trailing comment field, with any leading hash marks (``#'') or +whitespace removed. +.El +.Pp +If any of the fields pointing to character strings are unspecified, +they are returned as null pointers. +The field +.Fa ty_status +will be zero if no flag values are specified. +.Pp +See +.Xr ttys 5 +for a more complete discussion of the meaning and usage of the +fields. +.Pp +The +.Fn getttyent +function +reads the next line from the ttys file, opening the file if necessary. +The +.Fn setttyent +function +rewinds the file if open, or opens the file if it is unopened. +The +.Fn endttyent +function +closes any open files. +.Pp +The +.Fn getttynam +function +searches from the beginning of the file until a matching +.Fa name +is found +(or until +.Dv EOF +is encountered). +.Sh RETURN VALUES +The routines +.Fn getttyent +and +.Fn getttynam +return a null pointer on +.Dv EOF +or error. +The +.Fn setttyent +function +and +.Fn endttyent +return 0 on failure and 1 on success. +.Pp +The routines +.Fn isdialuptty +and +.Fn isnettty +return non-zero if the dialup or network flag is set for the +tty entry relating to the tty named by the parameter, and +zero otherwise. +.Sh FILES +.Bl -tag -width /etc/ttys -compact +.It Pa /etc/ttys +.El +.Sh SEE ALSO +.Xr login 1 , +.Xr ttyslot 3 , +.Xr gettytab 5 , +.Xr termcap 5 , +.Xr ttys 5 , +.Xr getty 8 , +.Xr init 8 +.Sh HISTORY +The +.Fn getttyent , +.Fn getttynam , +.Fn setttyent , +and +.Fn endttyent +functions appeared in +.Bx 4.3 . +.Sh BUGS +These functions use static data storage; +if the data is needed for future use, it should be +copied before any subsequent calls overwrite it. diff --git a/gen/getttyent.c b/gen/getttyent.c new file mode 100644 index 0000000..89bf092 --- /dev/null +++ b/gen/getttyent.c @@ -0,0 +1,230 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1989, 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 +#include +#include +#include +#include + +static char zapchar; +static FILE *tf; + +struct ttyent * +getttynam(tty) + const char *tty; +{ + register struct ttyent *t; + + setttyent(); + while (t = getttyent()) + if (!strcmp(tty, t->ty_name)) + break; + endttyent(); + return (t); +} + +struct ttyent * +getttyent() +{ + static struct ttyent tty; + register int c; + register char *p; +#define MAXLINELENGTH 1024 + static char *line = NULL; + static char *skip(), *value(); + + if ( line == NULL ) { + line = malloc(MAXLINELENGTH); + if( line == NULL ) + return NULL; + } + + if (!tf && !setttyent()) + return (NULL); + for (;;) { + if (!fgets(p = line, MAXLINELENGTH, tf)) + return (NULL); + /* skip lines that are too big */ + if (!index(p, '\n')) { + while ((c = getc(tf)) != '\n' && c != EOF) + ; + continue; + } + while (isspace(*p)) + ++p; + if (*p && *p != '#') + break; + } + + zapchar = 0; + tty.ty_name = p; + p = skip(p); + if (!*(tty.ty_getty = p)) + tty.ty_getty = tty.ty_type = NULL; + else { + p = skip(p); + if (!*(tty.ty_type = p)) + tty.ty_type = NULL; + else + p = skip(p); + } + tty.ty_status = 0; + tty.ty_window = NULL; + tty.ty_onerror = NULL; + tty.ty_onoption = NULL; + +#define scmp(e) !strncmp(p, e, sizeof(e) - 1) && isspace(p[sizeof(e) - 1]) +#define vcmp(e) !strncmp(p, e, sizeof(e) - 1) && p[sizeof(e) - 1] == '=' + for (; *p; p = skip(p)) { + if (scmp(_TTYS_OFF)) + tty.ty_status &= ~TTY_ON; + else if (scmp(_TTYS_ON)) + tty.ty_status |= TTY_ON; + else if (scmp(_TTYS_SECURE)) + tty.ty_status |= TTY_SECURE; + else if (vcmp(_TTYS_WINDOW)) + tty.ty_window = value(p); + else if (vcmp(_TTYS_ONERROR)) + tty.ty_onerror = value(p); + else if (vcmp(_TTYS_ONOPTION)) + tty.ty_onoption = value(p); + else + break; + } + + if (zapchar == '#' || *p == '#') + while ((c = *++p) == ' ' || c == '\t') + ; + tty.ty_comment = p; + if (*p == 0) + tty.ty_comment = 0; + if (p = index(p, '\n')) + *p = '\0'; + return (&tty); +} + +#define QUOTED 1 + +/* + * Skip over the current field, removing quotes, and return a pointer to + * the next field. + */ +static char * +skip(p) + register char *p; +{ + register char *t; + register int c, q; + + for (q = 0, t = p; (c = *p) != '\0'; p++) { + if (c == '"') { + q ^= QUOTED; /* obscure, but nice */ + continue; + } + if (q == QUOTED && *p == '\\' && *(p+1) == '"') + p++; + *t++ = *p; + if (q == QUOTED) + continue; + if (c == '#') { + zapchar = c; + *p = 0; + break; + } + if (c == '\t' || c == ' ' || c == '\n') { + zapchar = c; + *p++ = 0; + while ((c = *p) == '\t' || c == ' ' || c == '\n') + p++; + break; + } + } + *--t = '\0'; + return (p); +} + +static char * +value(p) + register char *p; +{ + + return ((p = index(p, '=')) ? ++p : NULL); +} + +int +setttyent() +{ + + if (tf) { + (void)rewind(tf); + return (1); + } else if (tf = fopen(_PATH_TTYS, "r")) + return (1); + return (0); +} + +int +endttyent() +{ + int rval; + + if (tf) { + rval = !(fclose(tf) == EOF); + tf = NULL; + return (rval); + } + return (1); +} diff --git a/gen/getusershell.3 b/gen/getusershell.3 new file mode 100644 index 0000000..4d8805e --- /dev/null +++ b/gen/getusershell.3 @@ -0,0 +1,103 @@ +.\" $NetBSD: getusershell.3,v 1.6 1999/03/22 19:44:42 garbled Exp $ +.\" $FreeBSD: src/lib/libc/gen/getusershell.3,v 1.10 2001/10/01 16:08:51 ru Exp $ +.\" +.\" Copyright (c) 1985, 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. +.\" +.\" @(#)getusershell.3 8.1 (Berkeley) 6/4/93 +.\" +.Dd January 16, 1999 +.Dt GETUSERSHELL 3 +.Os +.Sh NAME +.Nm getusershell , +.Nm setusershell , +.Nm endusershell +.Nd get valid user shells +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In unistd.h +.Ft char * +.Fn getusershell void +.Ft void +.Fn setusershell void +.Ft void +.Fn endusershell void +.Sh DESCRIPTION +The +.Fn getusershell +function +returns a pointer to a valid user shell as defined by the +system manager in the shells database as described in +.Xr shells 5 . +If the shells database is not available, +.Fn getusershell +behaves as if +.Pa /bin/sh +and +.Pa /bin/csh +were listed. +.Pp +The +.Fn getusershell +function +reads the next +line (opening the file if necessary); +.Fn setusershell +rewinds the file; +.Fn endusershell +closes it. +.Sh FILES +.Bl -tag -width /etc/shells -compact +.It Pa /etc/shells +.El +.Sh DIAGNOSTICS +The routine +.Fn getusershell +returns a null pointer (0) on +.Dv EOF . +.Sh SEE ALSO +.Xr nsswitch.conf 5 , +.Xr shells 5 +.Sh HISTORY +The +.Fn getusershell +function appeared in +.Bx 4.3 . +.Sh BUGS +The +.Fn getusershell +function leaves its result in an internal static object and returns +a pointer to that object. +Subsequent calls to +.Fn getusershell +will modify the same object. diff --git a/gen/getusershell.c b/gen/getusershell.c new file mode 100644 index 0000000..5a5f09a --- /dev/null +++ b/gen/getusershell.c @@ -0,0 +1,155 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1985, 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 +#include +#include +#include +#include +#include +#include +#include + +/* + * Local shells should NOT be added here. They should be added in + * /etc/shells. + */ + +static char *okshells[] = { _PATH_BSHELL, _PATH_CSHELL, NULL }; +static char **curshell, **shells, *strings; +static char **initshells __P((void)); + +/* + * Get a list of shells from _PATH_SHELLS, if it exists. + */ +char * +getusershell() +{ + char *ret; + + if (curshell == NULL) + curshell = initshells(); + ret = *curshell; + if (ret != NULL) + curshell++; + return (ret); +} + +void +endusershell() +{ + + if (shells != NULL) + free(shells); + shells = NULL; + if (strings != NULL) + free(strings); + strings = NULL; + curshell = NULL; +} + +void +setusershell() +{ + + curshell = initshells(); +} + +static char ** +initshells() +{ + register char **sp, *cp; + register FILE *fp; + struct stat statb; + + if (shells != NULL) + free(shells); + shells = NULL; + if (strings != NULL) + free(strings); + strings = NULL; + if ((fp = fopen(_PATH_SHELLS, "r")) == NULL) + return (okshells); + if (fstat(fileno(fp), &statb) == -1) { + (void)fclose(fp); + return (okshells); + } + if ((strings = malloc((u_int)statb.st_size)) == NULL) { + (void)fclose(fp); + return (okshells); + } + shells = calloc((unsigned)statb.st_size / 3, sizeof (char *)); + if (shells == NULL) { + (void)fclose(fp); + free(strings); + strings = NULL; + return (okshells); + } + sp = shells; + cp = strings; + while (fgets(cp, MAXPATHLEN + 1, fp) != NULL) { + while (*cp != '#' && *cp != '/' && *cp != '\0') + cp++; + if (*cp == '#' || *cp == '\0') + continue; + *sp++ = cp; + while (!isspace(*cp) && *cp != '#' && *cp != '\0') + cp++; + *cp++ = '\0'; + } + *sp = NULL; + (void)fclose(fp); + return (shells); +} diff --git a/gen/getvfsbyname.3 b/gen/getvfsbyname.3 new file mode 100644 index 0000000..3b38bc1 --- /dev/null +++ b/gen/getvfsbyname.3 @@ -0,0 +1,97 @@ +.\" Copyright (c) 1995 +.\" 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. +.\" +.\" @(#)kvm_getvfsbyname.3 8.3 (Berkeley) 5/4/95 +.\" $FreeBSD: src/lib/libc/gen/getvfsbyname.3,v 1.12 2001/10/01 16:08:51 ru Exp $ +.\" +.Dd May 4, 1995 +.Dt GETVFSBYNAME 3 +.Os +.Sh NAME +.Nm getvfsbyname +.Nd get information about a filesystem +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In sys/param.h +.In sys/mount.h +.Ft int +.Fn getvfsbyname "const char *name" "struct vfsconf *vfc" +.Sh DESCRIPTION +The +.Fn getvfsbyname +function provides access to information about a +filesystem module that is configured in the kernel. +If successful, +the requested filesystem +.Fa vfsconf +is returned in the location pointed to by +.Fa vfc . +The fields in a +.Dq Li struct vfsconf +are defined as follows: +.Pp +.Bl -tag -compact -width vfc_refcount +.It vfc_name +the name of the filesystem +.It vfc_typenum +the filesystem type number assigned by the kernel +.It vfc_refcount +the number of active mount points using the filesystem +.It vfc_flags +flag bits as described in +.Xr getvfsent 3 +.El +.Sh RETURN VALUES +.Rv -std getvfsbyname +.Sh ERRORS +The following errors may be reported: +.Bl -tag -width Er +.It Bq Er EFAULT +The +.Fa vfc +pointer contains an invalid address. +.It Bq Er ENOENT +The +.Fa name +specifies a filesystem that is unknown or not configured in the kernel. +.El +.Sh SEE ALSO +.Xr mount 2 , +.Xr getvfsent 3 , +.Xr sysctl 3 , +.Xr mount 8 , +.Xr sysctl 8 +.Sh HISTORY +A variant of the +.Fn getvfsbyname +function first appeared in +.Fx 2.0 . diff --git a/gen/getvfsbyname.c b/gen/getvfsbyname.c new file mode 100644 index 0000000..2e1af68 --- /dev/null +++ b/gen/getvfsbyname.c @@ -0,0 +1,94 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 + * 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 +#include +#include +#include +#include + +int getvfsbyname __P((const char *, struct vfsconf *)); + +/* + * Given a filesystem name, determine if it is resident in the kernel, + * and if it is resident, return its vfsconf structure. + */ +getvfsbyname(fsname, vfcp) + const char *fsname; + struct vfsconf *vfcp; +{ + int name[4], maxtypenum, cnt; + size_t buflen; + + name[0] = CTL_VFS; + name[1] = VFS_GENERIC; + name[2] = VFS_MAXTYPENUM; + buflen = 4; + if (sysctl(name, 3, &maxtypenum, &buflen, (void *)0, (size_t)0) < 0) + return (-1); + name[2] = VFS_CONF; + buflen = sizeof *vfcp; + for (cnt = 0; cnt < maxtypenum; cnt++) { + name[3] = cnt; + if (sysctl(name, 4, vfcp, &buflen, (void *)0, (size_t)0) < 0) { + if (errno != EOPNOTSUPP) + return (-1); + continue; + } + if (!strcmp(fsname, vfcp->vfc_name)) + return (0); + } + errno = ENOENT; + return (-1); +} diff --git a/gen/getvfsent.3 b/gen/getvfsent.3 new file mode 100644 index 0000000..7795677 --- /dev/null +++ b/gen/getvfsent.3 @@ -0,0 +1,183 @@ +.\" $FreeBSD: src/lib/libc/gen/getvfsent.3,v 1.24 2001/10/01 16:08:51 ru Exp $ +.\" Written by Garrett A. Wollman, September 1994. +.\" This manual page is in the public domain. +.\" +.Dd September 24, 1994 +.Dt GETVFSENT 3 +.Os +.Sh NAME +.Nm getvfsent , +.Nm setvfsent , +.Nm endvfsent , +.Nm vfsisloadable , +.Nm vfsload +.Nd manage virtual filesystem modules +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In sys/param.h +.In sys/mount.h +.Ft struct ovfsconf * +.Fn getvfsent "void" +.Ft void +.Fn setvfsent "int cachelist" +.Ft void +.Fn endvfsent "void" +.Ft int +.Fn vfsisloadable "const char *name" +.Ft int +.Fn vfsload "const char *name" +.Sh DESCRIPTION +The +.Fn getvfsent +function provides convenient access to a list of installed virtual +filesystem modules managed by the kernel. It steps through the +list of filesystems one at a time. A null pointer is returned when +no more data is available. The fields in a +.Dq Li struct ovfsconf +are as follows: +.Pp +.Bl -tag -compact -width vfc_refcount +.It vfc_name +the name of the filesystem +.It vfc_index +the filesystem type number assigned by the kernel and used in calls to +.Xr mount 2 +.It vfc_refcount +the number of references to this filesystem +(usually the number of mounts, but one greater for filesystems which +cannot be unloaded or which are statically linked into the kernel) +.It vfc_flags +flag bits +.El +.Pp +The flags are defined as follows: +.Pp +.Bl -tag -width VFCF_SYNTHETIC -compact +.It Dv VFCF_STATIC +statically compiled into kernel +.It Dv VFCF_NETWORK +may get data over the network +.It Dv VFCF_READONLY +writes are not implemented +.It Dv VFCF_SYNTHETIC +data does not represent real files +.It Dv VFCF_LOOPBACK +aliases some other mounted FS +.It Dv VFCF_UNICODE +stores file names as Unicode +.El +.Pp +The +.Fn setvfsent +and +.Fn endvfsent +functions are used to control caching of the filesystem list, which is +obtained in toto from the kernel via +.Xr sysctl 3 . +If the +.Fa cachelist +parameter to +.Fn setvfsent +is non-zero, the list will be retrieved only once, upon the first call +to one of the retrieval functions, until +.Fn endvfsent +is called to clear the cache. In general, +.Fn setvfsent 1 +should be called by programs using the +.Fn getvfsent +function, and +.Fn setvfsent 0 +(which is also the default state) +should be called by programs using the +.Fn vfsload +function. +.Pp +The +.Fn vfsisloadable +function returns a non-zero value if a later call to +.Fn vfsload name +is likely to succeed. We say +.Dq likely +because +.Fn vfsisloadable +does not check any of the conditions necessary for +.Fn vfsload +to succeed. +.Pp +The +.Fn vfsload +function attempts to load a kernel module implementing filesystem +.Fa name . +It returns zero if the filesystem module was successfully located and +loaded, or non-zero otherwise. It should only be called in the +following circumstances: +.Bl -enum +.It +.Fn getvfsbyname +has been called and returned a non-zero value. +.It +.Fn vfsisloadable +has been called and returned a non-zero value. +.El +.Pp +Here is an example, taken from the source to +.Xr mount_cd9660 8 : +.Bd -literal -offset indent + +struct vfsconf *vfc; +int error; + +/* setup code here */ + +error = getvfsbyname("cd9660", &vfc); +if (error && vfsisloadable("cd9660")) { + if (vfsload("cd9660")) + err(EX_OSERR, "vfsload(cd9660)"); + endvfsent(); /* flush cache */ + error = getvfsbyname("cd9660", &vfc); +} +if (error) + errx(1, "cd9660 filesystem is not available"); + +if (mount(vfc.vfc_name, dir, mntflags, &args) < 0) + err(1, NULL); + +.Ed +.Sh RETURN VALUES +The +.Fn getvfsent +routine returns a pointer to a static data structure when +it succeeds, and returns a null pointer when it fails. On failure, +.Va errno +may be set to one of the values documented for +.Xr sysctl 3 +or +.Xr malloc 3 , +if a failure of that function was the cause; otherwise +.Va errno +will be unmodified. +.Pp +The +.Fn vfsload +function returns a non-zero value on failure, or zero on success. If +.Fn vfsload +fails, +.Va errno +may be set to one of the values documented for +.Xr kldload 2 . +.Sh SEE ALSO +.Xr kldload 2 , +.Xr mount 2 , +.Xr mount 8 +.Sh AUTHORS +.An -nosplit +The loadable filesystem support was written by +.An Garrett A. Wollman , +based on generic loadable kernel module support by +.An Terry Lambert . +.Sh HISTORY +The +.Fn getvfsent +family of functions first appeared in +.Fx 2.0 . diff --git a/gen/glob.3 b/gen/glob.3 new file mode 100644 index 0000000..aa509a3 --- /dev/null +++ b/gen/glob.3 @@ -0,0 +1,466 @@ +.\" Copyright (c) 1989, 1991, 1993, 1994 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" This code is derived from software contributed to Berkeley by +.\" Guido van Rossum. +.\" 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. +.\" +.\" @(#)glob.3 8.3 (Berkeley) 4/16/94 +.\" $FreeBSD: src/lib/libc/gen/glob.3,v 1.20 2001/10/01 16:08:51 ru Exp $ +.\" +.Dd April 16, 1994 +.Dt GLOB 3 +.Os +.Sh NAME +.Nm glob , +.Nm globfree +.Nd generate pathnames matching a pattern +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In glob.h +.Ft int +.Fn glob "const char *pattern" "int flags" "int (*errfunc)(const char *, int)" "glob_t *pglob" +.Ft void +.Fn globfree "glob_t *pglob" +.Sh DESCRIPTION +The +.Fn glob +function +is a pathname generator that implements the rules for file name pattern +matching used by the shell. +.Pp +The include file +.Pa glob.h +defines the structure type +.Fa glob_t , +which contains at least the following fields: +.Bd -literal +typedef struct { + int gl_pathc; /* count of total paths so far */ + int gl_matchc; /* count of paths matching pattern */ + int gl_offs; /* reserved at beginning of gl_pathv */ + int gl_flags; /* returned flags */ + char **gl_pathv; /* list of paths matching pattern */ +} glob_t; +.Ed +.Pp +The argument +.Fa pattern +is a pointer to a pathname pattern to be expanded. +The +.Fn glob +argument +matches all accessible pathnames against the pattern and creates +a list of the pathnames that match. +In order to have access to a pathname, +.Fn glob +requires search permission on every component of a path except the last +and read permission on each directory of any filename component of +.Fa pattern +that contains any of the special characters +.Ql * , +.Ql ?\& +or +.Ql \&[ . +.Pp +The +.Fn glob +argument +stores the number of matched pathnames into the +.Fa gl_pathc +field, and a pointer to a list of pointers to pathnames into the +.Fa gl_pathv +field. +The first pointer after the last pathname is +.Dv NULL . +If the pattern does not match any pathnames, the returned number of +matched paths is set to zero. +.Pp +It is the caller's responsibility to create the structure pointed to by +.Fa pglob . +The +.Fn glob +function allocates other space as needed, including the memory pointed +to by +.Fa gl_pathv . +.Pp +The argument +.Fa flags +is used to modify the behavior of +.Fn glob . +The value of +.Fa flags +is the bitwise inclusive +.Tn OR +of any of the following +values defined in +.Pa glob.h : +.Bl -tag -width GLOB_ALTDIRFUNC +.It Dv GLOB_APPEND +Append pathnames generated to the ones from a previous call (or calls) +to +.Fn glob . +The value of +.Fa gl_pathc +will be the total matches found by this call and the previous call(s). +The pathnames are appended to, not merged with the pathnames returned by +the previous call(s). +Between calls, the caller must not change the setting of the +.Dv GLOB_DOOFFS +flag, nor change the value of +.Fa gl_offs +when +.Dv GLOB_DOOFFS +is set, nor (obviously) call +.Fn globfree +for +.Fa pglob . +.It Dv GLOB_DOOFFS +Make use of the +.Fa gl_offs +field. +If this flag is set, +.Fa gl_offs +is used to specify how many +.Dv NULL +pointers to prepend to the beginning +of the +.Fa gl_pathv +field. +In other words, +.Fa gl_pathv +will point to +.Fa gl_offs +.Dv NULL +pointers, +followed by +.Fa gl_pathc +pathname pointers, followed by a +.Dv NULL +pointer. +.It Dv GLOB_ERR +Causes +.Fn glob +to return when it encounters a directory that it cannot open or read. +Ordinarily, +.Fn glob +continues to find matches. +.It Dv GLOB_MARK +Each pathname that is a directory that matches +.Fa pattern +has a slash +appended. +.It Dv GLOB_NOCHECK +If +.Fa pattern +does not match any pathname, then +.Fn glob +returns a list +consisting of only +.Fa pattern , +with the number of total pathnames is set to 1, and the number of matched +pathnames set to 0. +If +.Dv GLOB_QUOTE +is set, its effect is present in the pattern returned. +.It Dv GLOB_NOSORT +By default, the pathnames are sorted in ascending +.Tn ASCII +order; +this flag prevents that sorting (speeding up +.Fn glob ) . +.El +.Pp +The following values may also be included in +.Fa flags , +however, they are non-standard extensions to +.St -p1003.2 . +.Bl -tag -width GLOB_ALTDIRFUNC +.It Dv GLOB_ALTDIRFUNC +The following additional fields in the pglob structure have been +initialized with alternate functions for glob to use to open, read, +and close directories and to get stat information on names found +in those directories. +.Bd -literal +void *(*gl_opendir)(const char * name); +struct dirent *(*gl_readdir)(void *); +void (*gl_closedir)(void *); +int (*gl_lstat)(const char *name, struct stat *st); +int (*gl_stat)(const char *name, struct stat *st); +.Ed +.Pp +This extension is provided to allow programs such as +.Xr restore 8 +to provide globbing from directories stored on tape. +.It Dv GLOB_BRACE +Pre-process the pattern string to expand +.Ql {pat,pat,...} +strings like +.Xr csh 1 . +The pattern +.Ql {} +is left unexpanded for historical reasons (and +.Xr csh 1 +does the same thing to +ease typing +of +.Xr find 1 +patterns). +.It Dv GLOB_MAGCHAR +Set by the +.Fn glob +function if the pattern included globbing characters. +See the description of the usage of the +.Fa gl_matchc +structure member for more details. +.It Dv GLOB_NOMAGIC +Is the same as +.Dv GLOB_NOCHECK +but it only appends the +.Fa pattern +if it does not contain any of the special characters ``*'', ``?'' or ``[''. +.Dv GLOB_NOMAGIC +is provided to simplify implementing the historic +.Xr csh 1 +globbing behavior and should probably not be used anywhere else. +.It Dv GLOB_QUOTE +Use the backslash +.Pq Ql \e +character for quoting: every occurrence of +a backslash followed by a character in the pattern is replaced by that +character, avoiding any special interpretation of the character. +.It Dv GLOB_TILDE +Expand patterns that start with +.Ql ~ +to user name home directories. +.It Dv GLOB_LIMIT +Limit the total number of returned pathnames to the value provided in +.Fa gl_matchc +(default +.Dv ARG_MAX ) . +This option should be set for programs +that can be coerced into a denial of service attack +via patterns that expand to a very large number of matches, +such as a long string of +.Ql */../*/.. . +.El +.Pp +If, during the search, a directory is encountered that cannot be opened +or read and +.Fa errfunc +is +.Pf non- Dv NULL , +.Fn glob +calls +.Fa \*(lp*errfunc\*(rp Ns ( Fa path , errno ) . +This may be unintuitive: a pattern like +.Ql */Makefile +will try to +.Xr stat 2 +.Ql foo/Makefile +even if +.Ql foo +is not a directory, resulting in a +call to +.Fa errfunc . +The error routine can suppress this action by testing for +.Er ENOENT +and +.Er ENOTDIR ; +however, the +.Dv GLOB_ERR +flag will still cause an immediate +return when this happens. +.Pp +If +.Fa errfunc +returns non-zero, +.Fn glob +stops the scan and returns +.Dv GLOB_ABEND +after setting +.Fa gl_pathc +and +.Fa gl_pathv +to reflect any paths already matched. +This also happens if an error is encountered and +.Dv GLOB_ERR +is set in +.Fa flags , +regardless of the return value of +.Fa errfunc , +if called. +If +.Dv GLOB_ERR +is not set and either +.Fa errfunc +is +.Dv NULL +or +.Fa errfunc +returns zero, the error is ignored. +.Pp +The +.Fn globfree +function frees any space associated with +.Fa pglob +from a previous call(s) to +.Fn glob . +.Sh RETURN VALUES +On successful completion, +.Fn glob +returns zero. +In addition the fields of +.Fa pglob +contain the values described below: +.Bl -tag -width GLOB_NOCHECK +.It Fa gl_pathc +contains the total number of matched pathnames so far. +This includes other matches from previous invocations of +.Fn glob +if +.Dv GLOB_APPEND +was specified. +.It Fa gl_matchc +contains the number of matched pathnames in the current invocation of +.Fn glob . +.It Fa gl_flags +contains a copy of the +.Fa flags +parameter with the bit +.Dv GLOB_MAGCHAR +set if +.Fa pattern +contained any of the special characters ``*'', ``?'' or ``['', cleared +if not. +.It Fa gl_pathv +contains a pointer to a +.Dv NULL Ns -terminated +list of matched pathnames. +However, if +.Fa gl_pathc +is zero, the contents of +.Fa gl_pathv +are undefined. +.El +.Pp +If +.Fn glob +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 : +.Bl -tag -width GLOB_NOCHECK +.It Dv GLOB_NOSPACE +An attempt to allocate memory failed, or if +.Fa errno +was 0 +.Dv GLOB_LIMIT +was specified in the flags and +.Fa pglob\->gl_matchc +or more patterns were matched. +.It Dv GLOB_ABEND +The scan was stopped because an error was encountered and either +.Dv GLOB_ERR +was set or +.Fa \*(lp*errfunc\*(rp\*(lp\*(rp +returned non-zero. +.El +.Pp +The arguments +.Fa pglob\->gl_pathc +and +.Fa pglob\->gl_pathv +are still set as specified above. +.Sh EXAMPLES +A rough equivalent of +.Ql "ls -l *.c *.h" +can be obtained with the +following code: +.Bd -literal -offset indent +glob_t g; + +g.gl_offs = 2; +glob("*.c", GLOB_DOOFFS, NULL, &g); +glob("*.h", GLOB_DOOFFS | GLOB_APPEND, NULL, &g); +g.gl_pathv[0] = "ls"; +g.gl_pathv[1] = "-l"; +execvp("ls", g.gl_pathv); +.Ed +.Sh SEE ALSO +.Xr sh 1 , +.Xr fnmatch 3 , +.Xr regexp 3 +.Sh STANDARDS +The +.Fn glob +function is expected to be +.St -p1003.2 +compatible with the exception +that the flags +.Dv GLOB_ALTDIRFUNC , +.Dv GLOB_BRACE , +.Dv GLOB_LIMIT , +.Dv GLOB_MAGCHAR , +.Dv GLOB_NOMAGIC , +.Dv GLOB_QUOTE , +and +.Dv GLOB_TILDE , +and the fields +.Fa gl_matchc +and +.Fa gl_flags +should not be used by applications striving for strict +.Tn POSIX +conformance. +.Sh HISTORY +The +.Fn glob +and +.Fn globfree +functions first appeared in +.Bx 4.4 . +.Sh BUGS +Patterns longer than +.Dv MAXPATHLEN +may cause unchecked errors. +.Pp +The +.Fn glob +argument +may fail and set errno for any of the errors specified for the +library routines +.Xr stat 2 , +.Xr closedir 3 , +.Xr opendir 3 , +.Xr readdir 3 , +.Xr malloc 3 , +and +.Xr free 3 . diff --git a/gen/glob.c b/gen/glob.c new file mode 100644 index 0000000..273d6c9 --- /dev/null +++ b/gen/glob.c @@ -0,0 +1,864 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1989, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Guido van Rossum. + * + * 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. + */ + + +/* + * glob(3) -- a superset of the one defined in POSIX 1003.2. + * + * The [!...] convention to negate a range is supported (SysV, Posix, ksh). + * + * Optional extra services, controlled by flags not defined by POSIX: + * + * GLOB_QUOTE: + * Escaping convention: \ inhibits any special meaning the following + * character might have (except \ at end of string is retained). + * GLOB_MAGCHAR: + * Set in gl_flags if pattern contained a globbing character. + * GLOB_NOMAGIC: + * Same as GLOB_NOCHECK, but it will only append pattern if it did + * not contain any magic characters. [Used in csh style globbing] + * GLOB_ALTDIRFUNC: + * Use alternately specified directory access functions. + * GLOB_TILDE: + * expand ~user/foo to the /home/dir/of/user/foo + * GLOB_BRACE: + * expand {1,2}{a,b} to 1a 1b 2a 2b + * gl_matchc: + * Number of matches in the current invocation of glob. + */ + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define DOLLAR '$' +#define DOT '.' +#define EOS '\0' +#define LBRACKET '[' +#define NOT '!' +#define QUESTION '?' +#define QUOTE '\\' +#define RANGE '-' +#define RBRACKET ']' +#define SEP '/' +#define STAR '*' +#define TILDE '~' +#define UNDERSCORE '_' +#define LBRACE '{' +#define RBRACE '}' +#define SLASH '/' +#define COMMA ',' + +#ifndef DEBUG + +#define M_QUOTE 0x8000 +#define M_PROTECT 0x4000 +#define M_MASK 0xffff +#define M_ASCII 0x00ff + +typedef u_short Char; + +#else + +#define M_QUOTE 0x80 +#define M_PROTECT 0x40 +#define M_MASK 0xff +#define M_ASCII 0x7f + +typedef char Char; + +#endif + + +#define CHAR(c) ((Char)((c)&M_ASCII)) +#define META(c) ((Char)((c)|M_QUOTE)) +#define M_ALL META('*') +#define M_END META(']') +#define M_NOT META('!') +#define M_ONE META('?') +#define M_RNG META('-') +#define M_SET META('[') +#define ismeta(c) (((c)&M_QUOTE) != 0) + + +static int compare __P((const void *, const void *)); +static void g_Ctoc __P((const Char *, char *)); +static int g_lstat __P((Char *, struct stat *, glob_t *)); +static DIR *g_opendir __P((Char *, glob_t *)); +static Char *g_strchr __P((Char *, int)); +#ifdef notdef +static Char *g_strcat __P((Char *, const Char *)); +#endif +static int g_stat __P((Char *, struct stat *, glob_t *)); +static int glob0 __P((const Char *, glob_t *)); +static int glob1 __P((Char *, glob_t *)); +static int glob2 __P((Char *, Char *, Char *, glob_t *)); +static int glob3 __P((Char *, Char *, Char *, Char *, glob_t *)); +static int globextend __P((const Char *, glob_t *)); +static const Char * globtilde __P((const Char *, Char *, glob_t *)); +static int globexp1 __P((const Char *, glob_t *)); +static int globexp2 __P((const Char *, const Char *, glob_t *, int *)); +static int match __P((Char *, Char *, Char *)); +#ifdef DEBUG +static void qprintf __P((const char *, Char *)); +#endif + +int +glob(pattern, flags, errfunc, pglob) + const char *pattern; + int flags, (*errfunc) __P((const char *, int)); + glob_t *pglob; +{ + const u_char *patnext; + int c; + Char *bufnext, *bufend, patbuf[MAXPATHLEN+1]; + + patnext = (u_char *) pattern; + if (!(flags & GLOB_APPEND)) { + pglob->gl_pathc = 0; + pglob->gl_pathv = NULL; + if (!(flags & GLOB_DOOFFS)) + pglob->gl_offs = 0; + } + pglob->gl_flags = flags & ~GLOB_MAGCHAR; + pglob->gl_errfunc = errfunc; + pglob->gl_matchc = 0; + + bufnext = patbuf; + bufend = bufnext + MAXPATHLEN; + if (flags & GLOB_QUOTE) { + /* Protect the quoted characters. */ + while (bufnext < bufend && (c = *patnext++) != EOS) + if (c == QUOTE) { + if ((c = *patnext++) == EOS) { + c = QUOTE; + --patnext; + } + *bufnext++ = c | M_PROTECT; + } + else + *bufnext++ = c; + } + else + while (bufnext < bufend && (c = *patnext++) != EOS) + *bufnext++ = c; + *bufnext = EOS; + + if (flags & GLOB_BRACE) + return globexp1(patbuf, pglob); + else + return glob0(patbuf, pglob); +} + +/* + * Expand recursively a glob {} pattern. When there is no more expansion + * invoke the standard globbing routine to glob the rest of the magic + * characters + */ +static int globexp1(pattern, pglob) + const Char *pattern; + glob_t *pglob; +{ + 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); + + while ((ptr = (const Char *) g_strchr((Char *) ptr, LBRACE)) != NULL) + if (!globexp2(ptr, pattern, pglob, &rv)) + return rv; + + return glob0(pattern, pglob); +} + + +/* + * Recursive brace globbing helper. Tries to expand a single brace. + * If it succeeds then it invokes globexp1 with the new pattern. + * If it fails then it tries to glob the rest of the pattern and returns. + */ +static int globexp2(ptr, pattern, pglob, rv) + const Char *ptr, *pattern; + glob_t *pglob; + int *rv; +{ + int i; + Char *lm, *ls; + const Char *pe, *pm, *pl; + Char patbuf[MAXPATHLEN + 1]; + + /* copy part up to the brace */ + for (lm = patbuf, pm = pattern; pm != ptr; *lm++ = *pm++) + continue; + ls = lm; + + /* Find the balanced brace */ + for (i = 0, pe = ++ptr; *pe; pe++) + if (*pe == LBRACKET) { + /* Ignore everything between [] */ + for (pm = pe++; *pe != RBRACKET && *pe != EOS; pe++) + continue; + if (*pe == EOS) { + /* + * We could not find a matching RBRACKET. + * Ignore and just look for RBRACE + */ + pe = pm; + } + } + else if (*pe == LBRACE) + i++; + else if (*pe == RBRACE) { + if (i == 0) + break; + i--; + } + + /* Non matching braces; just glob the pattern */ + if (i != 0 || *pe == EOS) { + *rv = glob0(patbuf, pglob); + return 0; + } + + for (i = 0, pl = pm = ptr; pm <= pe; pm++) + switch (*pm) { + case LBRACKET: + /* Ignore everything between [] */ + for (pl = pm++; *pm != RBRACKET && *pm != EOS; pm++) + continue; + if (*pm == EOS) { + /* + * We could not find a matching RBRACKET. + * Ignore and just look for RBRACE + */ + pm = pl; + } + break; + + case LBRACE: + i++; + break; + + case RBRACE: + if (i) { + i--; + break; + } + /* FALLTHROUGH */ + case COMMA: + if (i && *pm == COMMA) + break; + else { + /* Append the current string */ + for (lm = ls; (pl < pm); *lm++ = *pl++) + continue; + /* + * Append the rest of the pattern after the + * closing brace + */ + for (pl = pe + 1; (*lm++ = *pl++) != EOS;) + continue; + + /* Expand the current pattern */ +#ifdef DEBUG + qprintf("globexp2:", patbuf); +#endif + *rv = globexp1(patbuf, pglob); + + /* move after the comma, to the next string */ + pl = pm + 1; + } + break; + + default: + break; + } + *rv = 0; + return 0; +} + + + +/* + * expand tilde from the passwd file. + */ +static const Char * +globtilde(pattern, patbuf, pglob) + const Char *pattern; + Char *patbuf; + glob_t *pglob; +{ + struct passwd *pwd; + char *h; + const Char *p; + Char *b; + + if (*pattern != TILDE || !(pglob->gl_flags & GLOB_TILDE)) + return pattern; + + /* Copy up to the end of the string or / */ + for (p = pattern + 1, h = (char *) patbuf; *p && *p != SLASH; + *h++ = *p++) + continue; + + *h = EOS; + + if (((char *) patbuf)[0] == EOS) { + /* + * handle a plain ~ or ~/ by expanding $HOME + * first and then trying the password file + */ + if ((h = getenv("HOME")) == NULL) { + if ((pwd = getpwuid(getuid())) == NULL) + return pattern; + else + h = pwd->pw_dir; + } + } + else { + /* + * Expand a ~user + */ + if ((pwd = getpwnam((char*) patbuf)) == NULL) + return pattern; + else + h = pwd->pw_dir; + } + + /* Copy the home directory */ + for (b = patbuf; *h; *b++ = *h++) + continue; + + /* Append the rest of the pattern */ + while ((*b++ = *p++) != EOS) + continue; + + return patbuf; +} + + +/* + * The main glob() routine: compiles the pattern (optionally processing + * quotes), calls glob1() to do the real pattern matching, and finally + * sorts the list (unless unsorted operation is requested). Returns 0 + * if things went well, nonzero if errors occurred. It is not an error + * to find no matches. + */ +static int +glob0(pattern, pglob) + const Char *pattern; + glob_t *pglob; +{ + const Char *qpatnext; + int c, err, oldpathc; + Char *bufnext, patbuf[MAXPATHLEN+1]; + + qpatnext = globtilde(pattern, patbuf, pglob); + oldpathc = pglob->gl_pathc; + bufnext = patbuf; + + /* We don't need to check for buffer overflow any more. */ + while ((c = *qpatnext++) != EOS) { + switch (c) { + case LBRACKET: + c = *qpatnext; + if (c == NOT) + ++qpatnext; + if (*qpatnext == EOS || + g_strchr((Char *) qpatnext+1, RBRACKET) == NULL) { + *bufnext++ = LBRACKET; + if (c == NOT) + --qpatnext; + break; + } + *bufnext++ = M_SET; + if (c == NOT) + *bufnext++ = M_NOT; + c = *qpatnext++; + do { + *bufnext++ = CHAR(c); + if (*qpatnext == RANGE && + (c = qpatnext[1]) != RBRACKET) { + *bufnext++ = M_RNG; + *bufnext++ = CHAR(c); + qpatnext += 2; + } + } while ((c = *qpatnext++) != RBRACKET); + pglob->gl_flags |= GLOB_MAGCHAR; + *bufnext++ = M_END; + break; + case QUESTION: + pglob->gl_flags |= GLOB_MAGCHAR; + *bufnext++ = M_ONE; + break; + case STAR: + pglob->gl_flags |= GLOB_MAGCHAR; + /* collapse adjacent stars to one, + * to avoid exponential behavior + */ + if (bufnext == patbuf || bufnext[-1] != M_ALL) + *bufnext++ = M_ALL; + break; + default: + *bufnext++ = CHAR(c); + break; + } + } + *bufnext = EOS; +#ifdef DEBUG + qprintf("glob0:", patbuf); +#endif + + if ((err = glob1(patbuf, pglob)) != 0) + return(err); + + /* + * If there was no match we are going to append the pattern + * if GLOB_NOCHECK was specified or if GLOB_NOMAGIC was specified + * and the pattern did not contain any magic characters + * GLOB_NOMAGIC is there just for compatibility with csh. + */ + if (pglob->gl_pathc == oldpathc && + ((pglob->gl_flags & GLOB_NOCHECK) || + ((pglob->gl_flags & GLOB_NOMAGIC) && + !(pglob->gl_flags & GLOB_MAGCHAR)))) + return(globextend(pattern, pglob)); + else if (!(pglob->gl_flags & GLOB_NOSORT)) + qsort(pglob->gl_pathv + pglob->gl_offs + oldpathc, + pglob->gl_pathc - oldpathc, sizeof(char *), compare); + return(0); +} + +static int +compare(p, q) + const void *p, *q; +{ + return(strcmp(*(char **)p, *(char **)q)); +} + +static int +glob1(pattern, pglob) + Char *pattern; + glob_t *pglob; +{ + Char pathbuf[MAXPATHLEN+1]; + + /* A null pathname is invalid -- POSIX 1003.1 sect. 2.4. */ + if (*pattern == EOS) + return(0); + return(glob2(pathbuf, pathbuf, pattern, pglob)); +} + +/* + * The functions glob2 and glob3 are mutually recursive; there is one level + * of recursion for each segment in the pattern that contains one or more + * meta characters. + */ +static int +glob2(pathbuf, pathend, pattern, pglob) + Char *pathbuf, *pathend, *pattern; + glob_t *pglob; +{ + struct stat sb; + Char *p, *q; + int anymeta; + + /* + * Loop over pattern segments until end of pattern or until + * segment with meta character found. + */ + for (anymeta = 0;;) { + if (*pattern == EOS) { /* End of pattern? */ + *pathend = EOS; + if (g_lstat(pathbuf, &sb, pglob)) + 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) && + S_ISDIR(sb.st_mode)))) { + *pathend++ = SEP; + *pathend = EOS; + } + ++pglob->gl_matchc; + return(globextend(pathbuf, pglob)); + } + + /* Find end of next segment, copy tentatively to pathend. */ + q = pathend; + p = pattern; + while (*p != EOS && *p != SEP) { + if (ismeta(*p)) + anymeta = 1; + *q++ = *p++; + } + + if (!anymeta) { /* No expansion, do next segment. */ + pathend = q; + pattern = p; + while (*pattern == SEP) + *pathend++ = *pattern++; + } else /* Need expansion, recurse. */ + return(glob3(pathbuf, pathend, pattern, p, pglob)); + } + /* NOTREACHED */ +} + +static int +glob3(pathbuf, pathend, pattern, restpattern, pglob) + Char *pathbuf, *pathend, *pattern, *restpattern; + glob_t *pglob; +{ + register struct dirent *dp; + DIR *dirp; + int err; + char buf[MAXPATHLEN]; + + /* + * The readdirfunc declaration can't be prototyped, because it is + * assigned, below, to two functions which are prototyped in glob.h + * and dirent.h as taking pointers to differently typed opaque + * structures. + */ + struct dirent *(*readdirfunc)(); + + *pathend = EOS; + errno = 0; + + if ((dirp = g_opendir(pathbuf, pglob)) == NULL) { + /* TODO: don't call for ENOENT or ENOTDIR? */ + if (pglob->gl_errfunc) { + g_Ctoc(pathbuf, buf); + if (pglob->gl_errfunc(buf, errno) || + pglob->gl_flags & GLOB_ERR) + return (GLOB_ABEND); + } + return(0); + } + + err = 0; + + /* Search directory for matching names. */ + if (pglob->gl_flags & GLOB_ALTDIRFUNC) + readdirfunc = pglob->gl_readdir; + else + readdirfunc = readdir; + while ((dp = (*readdirfunc)(dirp))) { + register u_char *sc; + register Char *dc; + + /* Initial DOT must be matched literally. */ + if (dp->d_name[0] == DOT && *pattern != DOT) + continue; + for (sc = (u_char *) dp->d_name, dc = pathend; + (*dc++ = *sc++) != EOS;) + continue; + if (!match(pathend, pattern, restpattern)) { + *pathend = EOS; + continue; + } + err = glob2(pathbuf, --dc, restpattern, pglob); + if (err) + break; + } + + if (pglob->gl_flags & GLOB_ALTDIRFUNC) + (*pglob->gl_closedir)(dirp); + else + closedir(dirp); + return(err); +} + + +/* + * Extend the gl_pathv member of a glob_t structure to accomodate a new item, + * add the new item, and update gl_pathc. + * + * This assumes the BSD realloc, which only copies the block when its size + * crosses a power-of-two boundary; for v7 realloc, this would cause quadratic + * behavior. + * + * Return 0 if new item added, error code if memory couldn't be allocated. + * + * Invariant of the glob_t structure: + * Either gl_pathc is zero and gl_pathv is NULL; or gl_pathc > 0 and + * gl_pathv points to (gl_offs + gl_pathc + 1) items. + */ +static int +globextend(path, pglob) + const Char *path; + glob_t *pglob; +{ + register char **pathv; + register int i; + u_int newsize; + char *copy; + const Char *p; + + newsize = sizeof(*pathv) * (2 + pglob->gl_pathc + pglob->gl_offs); + pathv = pglob->gl_pathv ? + realloc((char *)pglob->gl_pathv, newsize) : + malloc(newsize); + if (pathv == NULL) + return(GLOB_NOSPACE); + + if (pglob->gl_pathv == NULL && pglob->gl_offs > 0) { + /* first time around -- clear initial gl_offs items */ + pathv += pglob->gl_offs; + for (i = pglob->gl_offs; --i >= 0; ) + *--pathv = NULL; + } + pglob->gl_pathv = pathv; + + for (p = path; *p++;) + continue; + if ((copy = malloc(p - path)) != NULL) { + g_Ctoc(path, copy); + pathv[pglob->gl_offs + pglob->gl_pathc++] = copy; + } + pathv[pglob->gl_offs + pglob->gl_pathc] = NULL; + return(copy == NULL ? GLOB_NOSPACE : 0); +} + + +/* + * pattern matching function for filenames. Each occurrence of the * + * pattern causes a recursion level. + */ +static int +match(name, pat, patend) + register Char *name, *pat, *patend; +{ + int ok, negate_range; + Char c, k; + + while (pat < patend) { + c = *pat++; + switch (c & M_MASK) { + case M_ALL: + if (pat == patend) + return(1); + do + if (match(name, pat, patend)) + return(1); + while (*name++ != EOS); + return(0); + case M_ONE: + if (*name++ == EOS) + return(0); + break; + case M_SET: + ok = 0; + if ((k = *name++) == EOS) + return(0); + if ((negate_range = ((*pat & M_MASK) == M_NOT)) != EOS) + ++pat; + while (((c = *pat++) & M_MASK) != M_END) + if ((*pat & M_MASK) == M_RNG) { + if (c <= k && k <= pat[1]) + ok = 1; + pat += 2; + } else if (c == k) + ok = 1; + if (ok == negate_range) + return(0); + break; + default: + if (*name++ != c) + return(0); + break; + } + } + return(*name == EOS); +} + +/* Free allocated data belonging to a glob_t structure. */ +void +globfree(pglob) + glob_t *pglob; +{ + register int i; + register char **pp; + + if (pglob->gl_pathv != NULL) { + pp = pglob->gl_pathv + pglob->gl_offs; + for (i = pglob->gl_pathc; i--; ++pp) + if (*pp) + free(*pp); + free(pglob->gl_pathv); + } +} + +static DIR * +g_opendir(str, pglob) + register Char *str; + glob_t *pglob; +{ + char buf[MAXPATHLEN]; + + if (!*str) + strcpy(buf, "."); + else + g_Ctoc(str, buf); + + if (pglob->gl_flags & GLOB_ALTDIRFUNC) + return((*pglob->gl_opendir)(buf)); + + return(opendir(buf)); +} + +static int +g_lstat(fn, sb, pglob) + register Char *fn; + struct stat *sb; + glob_t *pglob; +{ + char buf[MAXPATHLEN]; + + g_Ctoc(fn, buf); + if (pglob->gl_flags & GLOB_ALTDIRFUNC) + return((*pglob->gl_lstat)(buf, sb)); + return(lstat(buf, sb)); +} + +static int +g_stat(fn, sb, pglob) + register Char *fn; + struct stat *sb; + glob_t *pglob; +{ + char buf[MAXPATHLEN]; + + g_Ctoc(fn, buf); + if (pglob->gl_flags & GLOB_ALTDIRFUNC) + return((*pglob->gl_stat)(buf, sb)); + return(stat(buf, sb)); +} + +static Char * +g_strchr(str, ch) + Char *str; + int ch; +{ + do { + if (*str == ch) + return (str); + } while (*str++); + return (NULL); +} + +#ifdef notdef +static Char * +g_strcat(dst, src) + Char *dst; + const Char* src; +{ + Char *sdst = dst; + + while (*dst++) + continue; + --dst; + while((*dst++ = *src++) != EOS) + continue; + + return (sdst); +} +#endif + +static void +g_Ctoc(str, buf) + register const Char *str; + char *buf; +{ + register char *dc; + + for (dc = buf; (*dc++ = *str++) != EOS;) + continue; +} + +#ifdef DEBUG +static void +qprintf(str, s) + const char *str; + register Char *s; +{ + register Char *p; + + (void)printf("%s:\n", str); + for (p = s; *p; p++) + (void)printf("%c", CHAR(*p)); + (void)printf("\n"); + for (p = s; *p; p++) + (void)printf("%c", *p & M_PROTECT ? '"' : ' '); + (void)printf("\n"); + for (p = s; *p; p++) + (void)printf("%c", ismeta(*p) ? '_' : ' '); + (void)printf("\n"); +} +#endif diff --git a/gen/hton.c b/gen/hton.c new file mode 100644 index 0000000..734e5dc --- /dev/null +++ b/gen/hton.c @@ -0,0 +1,50 @@ +/* + * Copyright (c) 1999 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@ + */ +/* Copyright (c) 1994 NeXT Computer, Inc. All rights reserved. + * + * File: hton.c + * Author: Matt Watson, NeXT Computer, Inc. + * + * Use the machine independent byte-swapping code for htonl-type functions. + * + * HISTORY + * 15-Dec-94 Matt Watson (Matt_Watson@NeXT.COM) + * Created. + */ + +#import + +long ntohl(long x) { + return NXSwapBigLongToHost(x); +} + +short ntohs(short x) { + return NXSwapBigShortToHost(x); +} + +long htonl(long x) { + return NXSwapHostLongToBig(x); +} + +short htons(short x) { + return NXSwapHostShortToBig(x); +} diff --git a/gen/initgroups.3 b/gen/initgroups.3 new file mode 100644 index 0000000..039b87f --- /dev/null +++ b/gen/initgroups.3 @@ -0,0 +1,86 @@ +.\" Copyright (c) 1983, 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. +.\" +.\" @(#)initgroups.3 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD: src/lib/libc/gen/initgroups.3,v 1.10 2001/10/01 16:08:51 ru Exp $ +.\" +.Dd June 4, 1993 +.Dt INITGROUPS 3 +.Os +.Sh NAME +.Nm initgroups +.Nd initialize group access list +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In unistd.h +.Ft int +.Fn initgroups "const char *name" "int basegid" +.Sh DESCRIPTION +The +.Fn initgroups +function +uses the +.Xr getgrouplist 3 +function to calculate the group access list for the user +specified in +.Fa name . +This group list is then setup for the current process using +.Xr setgroups 2 . +The +.Fa basegid +is automatically included in the groups list. +Typically this value is given as +the group number from the password file. +.Sh RETURN VALUES +The +.Fn initgroups +function +returns \-1 if it was not invoked by the super-user. +.Sh SEE ALSO +.Xr setgroups 2 , +.Xr getgrouplist 3 +.Sh HISTORY +The +.Fn initgroups +function appeared in +.Bx 4.2 . +.Sh BUGS +The +.Fn getgrouplist +function called by +.Fn initgroups +uses the routines based on +.Xr getgrent 3 . +If the invoking program uses any of these routines, +the group structure will +be overwritten in the call to +.Fn initgroups . diff --git a/gen/isatty.c b/gen/isatty.c new file mode 100644 index 0000000..5170369 --- /dev/null +++ b/gen/isatty.c @@ -0,0 +1,66 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1988, 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 +#include + +int +isatty(fd) + int fd; +{ + struct termios t; + + return(tcgetattr(fd, &t) != -1); +} diff --git a/gen/isinf.3 b/gen/isinf.3 new file mode 100644 index 0000000..dfc7efc --- /dev/null +++ b/gen/isinf.3 @@ -0,0 +1,80 @@ +.\" 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. +.\" +.\" @(#)isinf.3 8.2 (Berkeley) 1/29/94 +.\" $FreeBSD: src/lib/libc/gen/isinf.3,v 1.7 2000/10/30 13:23:18 asmodai Exp $ +.\" +.Dd January 29, 1994 +.Dt ISINF 3 +.Os +.Sh NAME +.Nm isinf , +.Nm isnan , +.Nm isnanf +.Nd test for infinity or not-a-number +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.Ft int +.Fn isinf double +.Ft int +.Fn isnan double +.Ft int +.Fn isnanf float +.Sh DESCRIPTION +The +.Fn isinf +function +returns 1 if the number is +.Dq \\*(If , +otherwise 0. +.Pp +The +.Fn isnan +and +.Fn isnanf +functions +return 1 if the double or float (respectively) is +.Dq not-a-number , +otherwise 0. +.Sh SEE ALSO +.Xr math 3 +.Rs +.%T "IEEE Standard for Binary Floating-Point Arithmetic" +.%Q ANSI +.%R Std 754-1985 +.Re +.Sh BUGS +Neither the +.Tn VAX +nor the Tahoe floating point have distinguished values +for either infinity or not-a-number. +These routines always return 0 on those architectures. diff --git a/gen/isnan.c b/gen/isnan.c new file mode 100644 index 0000000..bce7a53 --- /dev/null +++ b/gen/isnan.c @@ -0,0 +1,83 @@ +/* + * Copyright (c) 1999 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@ + */ +/* @(#)s_isnan.c 5.1 93/09/24 */ +/* + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunPro, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + */ + +#if defined(LIBM_SCCS) && !defined(lint) +static char rcsid[] = "$NetBSD: s_isnan.c,v 1.8 1995/05/10 20:47:36 jtc Exp $"; +#endif + +/* + * isnan(x) returns 1 is x is nan, else 0; + * no branching! + */ + +#include + +typedef union +{ + double value; + struct + { +#if defined(__BIG_ENDIAN__) + u_int32_t msw; + u_int32_t lsw; +#else + u_int32_t lsw; + u_int32_t msw; +#endif + } parts; +} ieee_double_shape_type; +/* Get two 32 bit ints from a double. */ + +#define EXTRACT_WORDS(ix0,ix1,d) \ +do { \ + ieee_double_shape_type ew_u; \ + ew_u.value = (d); \ + (ix0) = ew_u.parts.msw; \ + (ix1) = ew_u.parts.lsw; \ +} while (0) + + +#ifdef __STDC__ + int isnan(double x) +#else + int isnan(x) + double x; +#endif +{ + int32_t hx,lx; + EXTRACT_WORDS(hx,lx,x); + hx &= 0x7fffffff; + hx |= (u_int32_t)(lx|(-lx))>>31; + hx = 0x7ff00000 - hx; + return (int)((u_int32_t)(hx))>>31; +} diff --git a/gen/jrand48.c b/gen/jrand48.c new file mode 100644 index 0000000..051d5a6 --- /dev/null +++ b/gen/jrand48.c @@ -0,0 +1,21 @@ +/* + * Copyright (c) 1993 Martin Birgmeier + * All rights reserved. + * + * You may redistribute unmodified or modified versions of this source + * code provided that the above copyright notice and this and the + * following conditions are retained. + * + * This software is provided ``as is'', and comes with no warranties + * of any kind. I shall in no event be liable for anything that happens + * to anyone/anything when using this software. + */ + +#include "rand48.h" + +long +jrand48(unsigned short xseed[3]) +{ + _dorand48(xseed); + return ((long) xseed[2] << 16) + (long) xseed[1]; +} diff --git a/gen/lcong48.c b/gen/lcong48.c new file mode 100644 index 0000000..f13826b --- /dev/null +++ b/gen/lcong48.c @@ -0,0 +1,30 @@ +/* + * Copyright (c) 1993 Martin Birgmeier + * All rights reserved. + * + * You may redistribute unmodified or modified versions of this source + * code provided that the above copyright notice and this and the + * following conditions are retained. + * + * This software is provided ``as is'', and comes with no warranties + * of any kind. I shall in no event be liable for anything that happens + * to anyone/anything when using this software. + */ + +#include "rand48.h" + +extern unsigned short _rand48_seed[3]; +extern unsigned short _rand48_mult[3]; +extern unsigned short _rand48_add; + +void +lcong48(unsigned short p[7]) +{ + _rand48_seed[0] = p[0]; + _rand48_seed[1] = p[1]; + _rand48_seed[2] = p[2]; + _rand48_mult[0] = p[3]; + _rand48_mult[1] = p[4]; + _rand48_mult[2] = p[5]; + _rand48_add = p[6]; +} diff --git a/gen/ldexp.3 b/gen/ldexp.3 new file mode 100644 index 0000000..88c0d2f --- /dev/null +++ b/gen/ldexp.3 @@ -0,0 +1,80 @@ +.\" Copyright (c) 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. +.\" +.\" @(#)ldexp.3 8.2 (Berkeley) 4/19/94 +.\" $FreeBSD: src/lib/libc/gen/ldexp.3,v 1.8 2001/10/01 16:08:51 ru Exp $ +.\" +.Dd April 19, 1994 +.Dt LDEXP 3 +.Os +.Sh NAME +.Nm ldexp +.Nd multiply floating-point number by integral power of 2 +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In math.h +.Ft double +.Fn ldexp "double x" "int exp" +.Sh DESCRIPTION +The +.Fn ldexp +function multiplies a floating-point number by an integral +power of 2. +.Sh RETURN VALUES +The +.Fn ldexp +function returns the value of +.Fa x +times 2 raised to the power +.Fa exp . +.Pp +If the resultant value would cause an overflow, +the global variable +.Va errno +is set to +.Er ERANGE +and the value +.Dv HUGE +is returned. +.Sh SEE ALSO +.Xr frexp 3 , +.Xr math 3 , +.Xr modf 3 +.Sh STANDARDS +The +.Fn ldexp +function conforms to +.St -isoC . diff --git a/gen/lockf.3 b/gen/lockf.3 new file mode 100644 index 0000000..83f7818 --- /dev/null +++ b/gen/lockf.3 @@ -0,0 +1,254 @@ +.\" $NetBSD: lockf.3,v 1.2 1998/02/05 18:47:28 perry Exp $ +.\" +.\" Copyright (c) 1997 The NetBSD Foundation, Inc. +.\" All rights reserved. +.\" +.\" This code is derived from software contributed to The NetBSD Foundation +.\" by Klaus Klein and S.P. Zeidler. +.\" +.\" 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. +.\" +.\" $FreeBSD: src/lib/libc/gen/lockf.3,v 1.10 2001/10/01 16:08:51 ru Exp $ +.\" +.Dd December 19, 1997 +.Dt LOCKF 3 +.Os +.Sh NAME +.Nm lockf +.Nd record locking on files +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In unistd.h +.Ft int +.Fn lockf "int filedes" "int function" "off_t size" +.Sh DESCRIPTION +The +.Fn lockf +function allows sections of a file to be locked with advisory-mode locks. +Calls to +.Fn lockf +from other processes which attempt to lock the locked file section will +either return an error value or block until the section becomes unlocked. +All the locks for a process are removed when the process terminates. +.Pp +The argument +.Fa filedes +is an open file descriptor. +The file descriptor must have been opened either for write-only +.Dv ( O_WRONLY ) +or read/write +.Dv ( O_RDWR ) +operation. +.Pp +The +.Fa function +argument is a control value which specifies the action to be taken. +The permissible values for +.Fa function +are as follows: +.Bl -tag -width F_ULOCKXX -compact -offset indent +.It Sy Function +.Sy Description +.It Dv F_ULOCK +unlock locked sections +.It Dv F_LOCK +lock a section for exclusive use +.It Dv F_TLOCK +test and lock a section for exclusive use +.It Dv F_TEST +test a section for locks by other processes +.El +.Pp +.Dv F_ULOCK +removes locks from a section of the file; +.Dv F_LOCK +and +.Dv F_TLOCK +both lock a section of a file if the section is available; +.Dv F_TEST +detects if a lock by another process is present on the specified section. +.Pp +The +.Fa size +argument is the number of contiguous bytes to be locked or +unlocked. +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 +starts or extends before the beginning of the file. +If +.Fa size +is 0, the section from the current offset through the largest possible +file offset is locked (that is, from the current offset through the +present or any future end-of-file). +.Pp +The sections locked with +.Dv F_LOCK +or +.Dv F_TLOCK +may, in whole or in part, contain or be contained by a previously +locked section for the same process. +When this occurs, or if adjacent +locked sections would occur, the sections are combined into a single +locked section. +If the request would cause the number of locks to +exceed a system-imposed limit, the request will fail. +.Pp +.Dv F_LOCK +and +.Dv F_TLOCK +requests differ only by the action taken if the section is not +available. +.Dv F_LOCK +blocks the calling process until the section is available. +.Dv F_TLOCK +makes the function fail if the section is already locked by another +process. +.Pp +File locks are released on first close by the locking process of any +file descriptor for the file. +.Pp +.Dv F_ULOCK +requests release (wholly or in part) one or more locked sections +controlled by the process. +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 +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. +Releasing the center +portion of a locked section will cause the remaining locked beginning +and end portions to become two separate locked sections. +If the +request would cause the number of locks in the system to exceed a +system-imposed limit, the request will fail. +.Pp +An +.Dv F_ULOCK +request in which size is non-zero and the offset of the last byte of +the requested section is the maximum value for an object of type +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 +.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 +locked region is unlocked would cause a deadlock and fails with an +.Er EDEADLK +error. +.Pp +.Fn lockf , +.Xr fcntl 2 +and +.Xr flock 2 +locks may be safely used concurrently. +.Pp +Blocking on a section is interrupted by any signal. +.Sh RETURN VALUES +.Rv -std lockf +In the case of a failure, existing locks are not changed. +.Sh ERRORS +.Fn lockf +will fail if: +.Bl -tag -width Er +.It Bq Er EAGAIN +The argument +.Fa function +is +.Dv F_TLOCK +or +.Dv F_TEST +and the section is already locked by another process. +.It Bq Er EBADF +The argument +.Fa filedes +is not a valid open file descriptor. +.Pp +The argument +.Fa function +is +.Dv F_LOCK +or +.Dv F_TLOCK , +and +.Fa filedes +is not a valid file descriptor open for writing. +.It Bq Er EDEADLK +The argument +.Fa function +is +.Dv F_LOCK +and a deadlock is detected. +.It Bq Er EINTR +The argument +.Fa function +is F_LOCK +and +.Fn lockf +was interrupted by the delivery of a signal. +.It Bq Er EINVAL +The argument +.Fa function +is not one of +.Dv F_ULOCK , +.Dv F_LOCK , +.Dv F_TLOCK +or +.Dv F_TEST . +.Pp +The argument +.Fa filedes +refers to a file that does not support locking. +.It Bq Er ENOLCK +The argument +.Fa function +is +.Dv F_ULOCK , +.Dv F_LOCK +or +.Dv F_TLOCK , +and satisfying the lock or unlock request would result in the number +of locked regions in the system exceeding a system-imposed limit. +.El +.Sh SEE ALSO +.Xr fcntl 2 , +.Xr flock 2 +.Sh STANDARDS +The +.Fn lockf +function conforms to +.St -xpg4.2 . diff --git a/gen/lockf.c b/gen/lockf.c new file mode 100644 index 0000000..da94a3f --- /dev/null +++ b/gen/lockf.c @@ -0,0 +1,92 @@ +/* $NetBSD: lockf.c,v 1.1 1997/12/20 20:23:18 kleink Exp $ */ + +/*- + * Copyright (c) 1997 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Klaus Klein. + * + * 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. + * + * $FreeBSD: src/lib/libc/gen/lockf.c,v 1.5 2000/01/27 23:06:17 jasone Exp $ + */ + +#if defined(LIBC_SCCS) && !defined(lint) +static const char rcsid[]= + "$FreeBSD: src/lib/libc/gen/lockf.c,v 1.5 2000/01/27 23:06:17 jasone Exp $"; +#endif + +#include +#include +#include + +int +lockf(filedes, function, size) + int filedes; + int function; + off_t size; +{ + struct flock fl; + int cmd; + + fl.l_start = 0; + fl.l_len = size; + fl.l_whence = SEEK_CUR; + + switch (function) { + case F_ULOCK: + cmd = F_SETLK; + fl.l_type = F_UNLCK; + break; + case F_LOCK: + cmd = F_SETLKW; + fl.l_type = F_WRLCK; + break; + case F_TLOCK: + cmd = F_SETLK; + fl.l_type = F_WRLCK; + break; + case F_TEST: + fl.l_type = F_WRLCK; + if (fcntl(filedes, F_GETLK, &fl) == -1) + return (-1); + if (fl.l_type == F_UNLCK || fl.l_pid == getpid()) + return (0); + errno = EAGAIN; + return (-1); + /* NOTREACHED */ + default: + errno = EINVAL; + return (-1); + /* NOTREACHED */ + } + + return (fcntl(filedes, cmd, &fl)); +} diff --git a/gen/lrand48.c b/gen/lrand48.c new file mode 100644 index 0000000..a3d0111 --- /dev/null +++ b/gen/lrand48.c @@ -0,0 +1,23 @@ +/* + * Copyright (c) 1993 Martin Birgmeier + * All rights reserved. + * + * You may redistribute unmodified or modified versions of this source + * code provided that the above copyright notice and this and the + * following conditions are retained. + * + * This software is provided ``as is'', and comes with no warranties + * of any kind. I shall in no event be liable for anything that happens + * to anyone/anything when using this software. + */ + +#include "rand48.h" + +extern unsigned short _rand48_seed[3]; + +long +lrand48(void) +{ + _dorand48(_rand48_seed); + return ((long) _rand48_seed[2] << 15) + ((long) _rand48_seed[1] >> 1); +} diff --git a/gen/malloc.c b/gen/malloc.c new file mode 100644 index 0000000..1261d58 --- /dev/null +++ b/gen/malloc.c @@ -0,0 +1,617 @@ +/* + * Copyright (c) 1999 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@ + */ + +#define __POSIX_LIB__ +#import +#import +#import +#import +#import +#import // for spin lock +#import +#include + +#import "scalable_malloc.h" +#import "stack_logging.h" + +#define USE_SLEEP_RATHER_THAN_ABORT 0 + +#define MAX_ALLOCATION 0xc0000000 // beyond this, assume a programming error +#define INITIAL_ZONES 8 // After this number, we reallocate for new zones + +typedef void (malloc_logger_t)(unsigned type, unsigned arg1, unsigned arg2, unsigned arg3, unsigned result, unsigned num_hot_frames_to_skip); + +static pthread_lock_t _malloc_lock; +static malloc_zone_t *initial_malloc_zones[INITIAL_ZONES] = {0}; + +/* The following variables are exported for the benefit of performance tools */ +unsigned malloc_num_zones = 0; +malloc_zone_t **malloc_zones = initial_malloc_zones; +malloc_logger_t *malloc_logger = NULL; + +unsigned malloc_debug_flags = 0; + +unsigned malloc_check_start = 0; // 0 means don't check +unsigned malloc_check_counter = 0; +unsigned malloc_check_each = 1000; + +#define MALLOC_LOCK() LOCK(_malloc_lock) +#define MALLOC_UNLOCK() UNLOCK(_malloc_lock) + +#define MALLOC_LOG_TYPE_ALLOCATE stack_logging_type_alloc +#define MALLOC_LOG_TYPE_DEALLOCATE stack_logging_type_dealloc +#define MALLOC_LOG_TYPE_HAS_ZONE stack_logging_flag_zone +#define MALLOC_LOG_TYPE_CLEARED stack_logging_flag_cleared + +/********* Utilities ************/ + +static inline malloc_zone_t *find_registered_zone(const void *ptr, size_t *returned_size) { + // locates the proper zone + // if zone found fills returnedSize; else returns NULL + // See comment in malloc_zone_register() about clients non locking to call this function + // Speed is critical for this function + unsigned index = malloc_num_zones; + malloc_zone_t **zones = malloc_zones; + while (index--) { + malloc_zone_t *zone = *zones++; + size_t size; + size = zone->size(zone, ptr); + if (size) { + if (returned_size) *returned_size = size; + return zone; + } + } + return NULL; +} + +/********* Creation and destruction ************/ + +static void _malloc_initialize(void) { + // guaranteed to be called only once + (void)malloc_create_zone(0, 0); + malloc_set_zone_name(malloc_zones[0], "DefaultMallocZone"); + LOCK_INIT(_malloc_lock); + // malloc_printf("Malloc: %d registered zones\n", malloc_num_zones); + // malloc_printf("malloc: malloc_zones is at 0x%x; malloc_num_zones is at 0x%x\n", (unsigned)&malloc_zones, (unsigned)&malloc_num_zones); +} + +static inline malloc_zone_t *inline_malloc_default_zone(void) { + if (!malloc_num_zones) _malloc_initialize(); + // malloc_printf("In inline_malloc_default_zone with %d %d\n", malloc_num_zones, malloc_has_debug_zone); + return malloc_zones[0]; +} + +malloc_zone_t *malloc_default_zone(void) { + return inline_malloc_default_zone(); +} + +static void set_flags_from_environment(void) { + const char *flag; + if (getenv("MallocGuardEdges")) { + malloc_debug_flags = SCALABLE_MALLOC_ADD_GUARD_PAGES; + malloc_printf("malloc[%d]: protecting edges\n", getpid()); + if (getenv("MallocDoNotProtectPrelude")) { + malloc_debug_flags |= SCALABLE_MALLOC_DONT_PROTECT_PRELUDE; + malloc_printf("malloc[%d]: ... but not protecting prelude guard page\n", getpid()); + } + if (getenv("MallocDoNotProtectPostlude")) { + malloc_debug_flags |= SCALABLE_MALLOC_DONT_PROTECT_POSTLUDE; + malloc_printf("malloc[%d]: ... but not protecting postlude guard page\n", getpid()); + } + } + flag = getenv("MallocStackLogging"); + if (!flag) { + flag = getenv("MallocStackLoggingNoCompact"); + stack_logging_dontcompact = 1; + } + if (flag) { + unsigned val = strtoul(flag, NULL, 0); + if (val == 1) val = 0; + if (val == -1) val = 0; + malloc_logger = (val) ? (void *)val : stack_logging_log_stack; + stack_logging_enable_logging = 1; + if (malloc_logger == stack_logging_log_stack) { + malloc_printf("malloc[%d]: recording stacks using standard recorder\n", getpid()); + } else { + malloc_printf("malloc[%d]: recording stacks using recorder %p\n", getpid(), malloc_logger); + } + if (stack_logging_dontcompact) malloc_printf("malloc[%d]: stack logging compaction turned off; VM can increase rapidly\n", getpid()); + } + if (getenv("MallocScribble")) { + malloc_debug_flags |= SCALABLE_MALLOC_DO_SCRIBBLE; + malloc_printf("malloc[%d]: enabling scribbling to detect mods to free blocks\n", getpid()); + } + flag = getenv("MallocCheckHeapStart"); + if (flag) { + malloc_check_start = strtoul(flag, NULL, 0); + if (malloc_check_start == 0) malloc_check_start = 1; + if (malloc_check_start == -1) malloc_check_start = 1; + flag = getenv("MallocCheckHeapEach"); + if (flag) { + malloc_check_each = strtoul(flag, NULL, 0); + if (malloc_check_each == 0) malloc_check_each = 1; + if (malloc_check_each == -1) malloc_check_each = 1; + } + malloc_printf("malloc[%d]: checks heap after %dth operation and each %d operations\n", getpid(), malloc_check_start, malloc_check_each); + } + if (getenv("MallocHelp")) { + malloc_printf( + "malloc[%d]: environment variables that can be set for debug:\n" + "- MallocGuardEdges to add 2 guard pages for each large block\n" + "- MallocDoNotProtectPrelude to disable protection (when previous flag set)\n" + "- MallocDoNotProtectPostlude to disable protection (when previous flag set)\n" + "- MallocStackLogging to record all stacks. Tools like leaks can then be applied\n" + "- MallocStackLoggingNoCompact to record all stacks. Needed for malloc_history\n" + "- MallocScribble to detect writing on free blocks: 0x55 is written upon free\n" + "- MallocCheckHeapStart to check the heap from time to time after operations \n" + "- MallocHelp - this help!\n", getpid()); + } +} + +malloc_zone_t *malloc_create_zone(vm_size_t start_size, unsigned flags) { + malloc_zone_t *zone; + if (!malloc_num_zones) { + char **env = * _NSGetEnviron(); + 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() */ + for (p = env; (c = *p) != NULL; ++p) { + if (!strncmp(c, "Malloc", 6)) { + set_flags_from_environment(); + break; + } + } + + } + zone = create_scalable_zone(start_size, malloc_debug_flags); + malloc_zone_register(zone); + return zone; +} + +void malloc_destroy_zone(malloc_zone_t *zone) { + malloc_zone_unregister(zone); + zone->destroy(zone); +} + +/********* Block creation and manipulation ************/ + +static void internal_check(void) { + static vm_address_t *frames = NULL; + static unsigned num_frames; + if (malloc_zone_check(NULL)) { + malloc_printf("MallocCheckHeap: PASSED check at %dth operation\n", malloc_check_counter-1); + if (!frames) vm_allocate(mach_task_self(), (void *)&frames, vm_page_size, 1); + thread_stack_pcs(frames, vm_page_size/sizeof(vm_address_t) - 1, &num_frames); + } else { + malloc_printf("*** MallocCheckHeap: FAILED check at %dth operation\n", malloc_check_counter-1); + if (frames) { + unsigned index = 1; + malloc_printf("Stack for last operation where the malloc check succeeded: "); + while (index < num_frames) malloc_printf("0x%x ", frames[index++]); + malloc_printf("\n(Use 'atos' for a symbolic stack)\n"); + } + if (malloc_check_each > 1) { + unsigned recomm_each = (malloc_check_each > 10) ? malloc_check_each/10 : 1; + unsigned recomm_start = (malloc_check_counter > malloc_check_each+1) ? malloc_check_counter-1-malloc_check_each : 1; + malloc_printf("*** Recommend using 'setenv MallocCheckHeapStart %d; setenv MallocCheckHeapEach %d' to narrow down failure\n", recomm_start, recomm_each); + } + malloc_printf("*** Sleeping for 100 seconds to leave time to attach\n"); + sleep(100); + } + malloc_check_start += malloc_check_each; +} + +void *malloc_zone_malloc(malloc_zone_t *zone, size_t size) { + void *ptr; + if ((unsigned)size >= MAX_ALLOCATION) { + /* Probably a programming error */ + fprintf(stderr, "*** malloc_zone_malloc[%d]: argument too large: %d\n", getpid(), (unsigned)size); + return NULL; + } + if (malloc_check_start && (malloc_check_counter++ >= malloc_check_start)) { + internal_check(); + } + ptr = zone->malloc(zone, size); + if (malloc_logger) malloc_logger(MALLOC_LOG_TYPE_ALLOCATE | MALLOC_LOG_TYPE_HAS_ZONE, (unsigned)zone, size, 0, (unsigned)ptr, 0); + return ptr; +} + +void *malloc_zone_calloc(malloc_zone_t *zone, size_t num_items, size_t size) { + void *ptr; + if (malloc_check_start && (malloc_check_counter++ >= malloc_check_start)) { + internal_check(); + } + if (((unsigned)num_items >= MAX_ALLOCATION) || ((unsigned)size >= MAX_ALLOCATION) || ((long long)size * num_items >= (long long) MAX_ALLOCATION)) { + /* Probably a programming error */ + fprintf(stderr, "*** malloc_zone_calloc[%d]: arguments too large: %d,%d\n", getpid(), (unsigned)num_items, (unsigned)size); + return NULL; + } + ptr = zone->calloc(zone, num_items, size); + if (malloc_logger) malloc_logger(MALLOC_LOG_TYPE_ALLOCATE | MALLOC_LOG_TYPE_HAS_ZONE | MALLOC_LOG_TYPE_CLEARED, (unsigned)zone, num_items * size, 0, (unsigned)ptr, 0); + return ptr; +} + +void *malloc_zone_valloc(malloc_zone_t *zone, size_t size) { + void *ptr; + if ((unsigned)size >= MAX_ALLOCATION) { + /* Probably a programming error */ + fprintf(stderr, "*** malloc_zone_valloc[%d]: argument too large: %d\n", getpid(), (unsigned)size); + return NULL; + } + if (malloc_check_start && (malloc_check_counter++ >= malloc_check_start)) { + internal_check(); + } + ptr = zone->valloc(zone, size); + if (malloc_logger) malloc_logger(MALLOC_LOG_TYPE_ALLOCATE | MALLOC_LOG_TYPE_HAS_ZONE, (unsigned)zone, size, 0, (unsigned)ptr, 0); + return ptr; +} + +void *malloc_zone_realloc(malloc_zone_t *zone, void *ptr, size_t size) { + void *new_ptr; + if (malloc_check_start && (malloc_check_counter++ >= malloc_check_start)) { + internal_check(); + } + new_ptr = zone->realloc(zone, ptr, size); + if (malloc_logger) malloc_logger(MALLOC_LOG_TYPE_ALLOCATE | MALLOC_LOG_TYPE_DEALLOCATE | MALLOC_LOG_TYPE_HAS_ZONE, (unsigned)zone, (unsigned)ptr, size, (unsigned)new_ptr, 0); + return new_ptr; +} + +void malloc_zone_free(malloc_zone_t *zone, void *ptr) { + if (malloc_logger) malloc_logger(MALLOC_LOG_TYPE_DEALLOCATE | MALLOC_LOG_TYPE_HAS_ZONE, (unsigned)zone, (unsigned)ptr, 0, 0, 0); + if (malloc_check_start && (malloc_check_counter++ >= malloc_check_start)) { + internal_check(); + } + zone->free(zone, ptr); +} + +malloc_zone_t *malloc_zone_from_ptr(const void *ptr) { + malloc_zone_t *zone; + if (!ptr) return NULL; + zone = find_registered_zone(ptr, NULL); + return zone; +} + +/********* Functions for zone implementors ************/ + +void malloc_zone_register(malloc_zone_t *zone) { + /* Note that given the sequencing it is always safe to first get the number of zones, then get malloc_zones without taking the lock, if all you need is to iterate through the list */ + MALLOC_LOCK(); + if (malloc_num_zones >= INITIAL_ZONES) { + malloc_zone_t **zones = malloc_zones; + malloc_zone_t *pzone = malloc_zones[0]; + boolean_t copy = malloc_num_zones == INITIAL_ZONES; + if (copy) zones = NULL; // to avoid realloc on something not allocated + MALLOC_UNLOCK(); + zones = pzone->realloc(pzone, zones, (malloc_num_zones + 1) * sizeof(malloc_zone_t *)); // we leak initial_malloc_zones, not worth tracking it + MALLOC_LOCK(); + if (copy) memcpy(zones, malloc_zones, malloc_num_zones * sizeof(malloc_zone_t *)); + malloc_zones = zones; + } + malloc_zones[malloc_num_zones] = zone; + malloc_num_zones++; // note that we do this after setting malloc_num_zones, so enumerations without taking the lock are safe + MALLOC_UNLOCK(); + // malloc_printf("Registered %p malloc_zones at address %p is %p [%d zones]\n", zone, &malloc_zones, malloc_zones, malloc_num_zones); +} + +void malloc_zone_unregister(malloc_zone_t *z) { + unsigned index; + MALLOC_LOCK(); + index = malloc_num_zones; + while (index--) { + malloc_zone_t *zone = malloc_zones[index]; + if (zone == z) { + malloc_zones[index] = malloc_zones[--malloc_num_zones]; + MALLOC_UNLOCK(); + return; + } + } + MALLOC_UNLOCK(); + fprintf(stderr, "*** malloc[%d]: malloc_zone_unregister() failed for %p\n", getpid(), z); +} + +void malloc_set_zone_name(malloc_zone_t *z, const char *name) { + char *newName; + if (z->zone_name) { + free((char *)z->zone_name); + z->zone_name = NULL; + } + newName = malloc_zone_malloc(z, strlen(name) + 1); + strcpy(newName, name); + z->zone_name = (const char *)newName; +} + +const char *malloc_get_zone_name(malloc_zone_t *zone) { + return zone->zone_name; +} + +static char *_malloc_append_unsigned(unsigned value, unsigned base, char *head) { + if (!value) { + head[0] = '0'; + } else { + if (value >= base) head = _malloc_append_unsigned(value / base, base, head); + value = value % base; + head[0] = (value < 10) ? '0' + value : 'a' + value - 10; + } + return head+1; +} + +void malloc_printf(const char *format, ...) { + va_list args; + char buf[1024]; + char *head = buf; + char ch; + unsigned *nums; + va_start(args, format); +#if LOG_THREAD + head = _malloc_append_unsigned(((unsigned)&args) >> 12, 16, head); + *head++ = ' '; +#endif + nums = args; + while (ch = *format++) { + if (ch == '%') { + ch = *format++; + if (ch == 's') { + char *str = (char *)(*nums++); + write(2, buf, head - buf); + head = buf; + write(2, str, strlen(str)); + } else { + if (ch == 'p') { + *head++ = '0'; *head++ = 'x'; + } + head = _malloc_append_unsigned(*nums++, (ch == 'd') ? 10 : 16, head); + } + } else { + *head++ = ch; + } + } + write(2, buf, head - buf); fflush(stderr); + va_end(args); +} + +/********* Generic ANSI callouts ************/ + +void *malloc(size_t size) { + return malloc_zone_malloc(inline_malloc_default_zone(), size); +} + +void *calloc(size_t num_items, size_t size) { + return malloc_zone_calloc(inline_malloc_default_zone(), num_items, size); +} + +void free(void *ptr) { + malloc_zone_t *zone; + if (!ptr) return; + zone = find_registered_zone(ptr, NULL); + if (zone) { + malloc_zone_free(zone, ptr); + } else { + fprintf(stderr, "*** malloc[%d]: Deallocation of a pointer not malloced: %p; This could be a double free(), or free() called with the middle of an allocated block; Try setting environment variable MallocHelp to see tools to help debug\n", getpid(), ptr); + } +} + +void *realloc(void *old_ptr, size_t new_size) { + malloc_zone_t *zone; + size_t old_size = 0; + if (!old_ptr) return malloc_zone_malloc(inline_malloc_default_zone(), new_size); + zone = find_registered_zone(old_ptr, &old_size); + if (zone && (old_size >= new_size)) return old_ptr; + if (!zone) zone = inline_malloc_default_zone(); + return malloc_zone_realloc(zone, old_ptr, new_size); +} + +void *valloc(size_t size) { + malloc_zone_t *zone = inline_malloc_default_zone(); + return malloc_zone_valloc(zone, size); +} + +extern void vfree(void *ptr) { + free(ptr); +} + +size_t malloc_size(const void *ptr) { + size_t size = 0; + if (!ptr) return size; + (void)find_registered_zone(ptr, &size); + return size; +} + +size_t malloc_good_size (size_t size) { + malloc_zone_t *zone = inline_malloc_default_zone(); + return zone->introspect->good_size(zone, size); +} + +/********* Functions for performance tools ************/ + +static kern_return_t _malloc_default_reader(task_t task, vm_address_t address, vm_size_t size, void **ptr) { + *ptr = (void *)address; + return 0; +} + +kern_return_t malloc_get_all_zones(task_t task, memory_reader_t reader, vm_address_t **addresses, unsigned *count) { + // Note that the 2 following addresses are not correct if the address of the target is different from your own. This notably occurs if the address of System.framework is slid (e.g. different than at B & I ) + vm_address_t remote_malloc_zones = (vm_address_t)&malloc_zones; + vm_address_t remote_malloc_num_zones = (vm_address_t)&malloc_num_zones; + kern_return_t err; + vm_address_t zones_address; + vm_address_t *zones_address_ref; + unsigned num_zones; + unsigned *num_zones_ref; + if (!reader) reader = _malloc_default_reader; + // printf("Read malloc_zones at address %p should be %p\n", &malloc_zones, malloc_zones); + err = reader(task, remote_malloc_zones, sizeof(void *), (void **)&zones_address_ref); + // printf("Read malloc_zones[0x%x]=%p\n", remote_malloc_zones, *zones_address_ref); + if (err) { + fprintf(stderr, "*** malloc[%d]: malloc_get_all_zones: error reading zones_address at 0x%x\n", getpid(), (unsigned)remote_malloc_zones); + return err; + } + zones_address = *zones_address_ref; + // printf("Reading num_zones at address %p\n", remote_malloc_num_zones); + err = reader(task, remote_malloc_num_zones, sizeof(unsigned), (void **)&num_zones_ref); + if (err) { + fprintf(stderr, "*** malloc[%d]: malloc_get_all_zones: error reading num_zones at 0x%x\n", getpid(), (unsigned)remote_malloc_num_zones); + return err; + } + num_zones = *num_zones_ref; + // printf("Read malloc_num_zones[0x%x]=%d\n", remote_malloc_num_zones, num_zones); + *count = num_zones; + // printf("malloc_get_all_zones succesfully found %d zones\n", num_zones); + err = reader(task, zones_address, sizeof(malloc_zone_t *) * num_zones, (void **)addresses); + if (err) { + fprintf(stderr, "*** malloc[%d]: malloc_get_all_zones: error reading zones at 0x%x\n", getpid(), (unsigned)&zones_address); + return err; + } + // printf("malloc_get_all_zones succesfully read %d zones\n", num_zones); + return err; +} + +/********* Debug helpers ************/ + +void malloc_zone_print_ptr_info(void *ptr) { + malloc_zone_t *zone; + if (!ptr) return; + zone = find_registered_zone(ptr, NULL); + if (zone) { + printf("ptr %p in registered zone %p\n", ptr, zone); + } else { + printf("ptr %p not in heap\n", ptr); + } +} + +boolean_t malloc_zone_check(malloc_zone_t *zone) { + boolean_t ok = 1; + if (!zone) { + unsigned index = 0; + while (index < malloc_num_zones) { + zone = malloc_zones[index++]; + if (!zone->introspect->check(zone)) ok = 0; + } + } else { + ok = zone->introspect->check(zone); + } + return ok; +} + +void malloc_zone_print(malloc_zone_t *zone, boolean_t verbose) { + if (!zone) { + unsigned index = 0; + while (index < malloc_num_zones) { + zone = malloc_zones[index++]; + zone->introspect->print(zone, verbose); + } + } else { + zone->introspect->print(zone, verbose); + } +} + +void malloc_zone_log(malloc_zone_t *zone, void *address) { + if (!zone) { + unsigned index = 0; + while (index < malloc_num_zones) { + zone = malloc_zones[index++]; + zone->introspect->log(zone, address); + } + } else { + zone->introspect->log(zone, address); + } +} + +/********* Misc other entry points ************/ + +static void DefaultMallocError(int x) { + fprintf(stderr, "*** malloc[%d]: error %d\n", getpid(), x); +#if USE_SLEEP_RATHER_THAN_ABORT + sleep(3600); +#else + abort(); +#endif +} + +void (*malloc_error(void (*func)(int)))(int) { + return DefaultMallocError; +} + +void _malloc_fork_prepare() { + /* Prepare the malloc module for a fork by insuring that no thread is in a malloc critical section */ + unsigned index = 0; + MALLOC_LOCK(); + while (index < malloc_num_zones) { + malloc_zone_t *zone = malloc_zones[index++]; + zone->introspect->force_lock(zone); + } +} + +void _malloc_fork_parent() { + /* Called in the parent process after a fork() to resume normal operation. */ + unsigned index = 0; + MALLOC_UNLOCK(); + while (index < malloc_num_zones) { + malloc_zone_t *zone = malloc_zones[index++]; + zone->introspect->force_unlock(zone); + } +} + +void _malloc_fork_child() { + /* Called in the child process after a fork() to resume normal operation. In the MTASK case we also have to change memory inheritance so that the child does not share memory with the parent. */ + unsigned index = 0; + MALLOC_UNLOCK(); + while (index < malloc_num_zones) { + malloc_zone_t *zone = malloc_zones[index++]; + zone->introspect->force_unlock(zone); + } +} + +size_t mstats(void) { + malloc_zone_print(NULL, 0); + return 1; +} + +/***************** OBSOLETE ENTRY POINTS ********************/ + +#if PHASE_OUT_OLD_MALLOC +#error PHASE OUT THE FOLLOWING FUNCTIONS +#else +#warning PHASE OUT THE FOLLOWING FUNCTIONS +#endif + +void set_malloc_singlethreaded(boolean_t single) { + static boolean_t warned = 0; + if (!warned) { +#if PHASE_OUT_OLD_MALLOC + fprintf(stderr, "*** malloc[%d]: OBSOLETE: set_malloc_singlethreaded(%d)\n", getpid(), single); +#endif + warned = 1; + } +} + +void malloc_singlethreaded() { + static boolean_t warned = 0; + if (!warned) { + fprintf(stderr, "*** malloc[%d]: OBSOLETE: malloc_singlethreaded()\n", getpid()); + warned = 1; + } +} + +int malloc_debug(int level) { + fprintf(stderr, "*** malloc[%d]: OBSOLETE: malloc_debug()\n", getpid()); + return 0; +} diff --git a/gen/modf.3 b/gen/modf.3 new file mode 100644 index 0000000..3971000 --- /dev/null +++ b/gen/modf.3 @@ -0,0 +1,75 @@ +.\" Copyright (c) 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. +.\" +.\" @(#)modf.3 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD: src/lib/libc/gen/modf.3,v 1.7 2001/10/01 16:08:51 ru Exp $ +.\" +.Dd June 4, 1993 +.Dt MODF 3 +.Os +.Sh NAME +.Nm modf +.Nd extract signed integral and fractional values from floating-point number +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In math.h +.Ft double +.Fn modf "double value" "double *iptr" +.Sh DESCRIPTION +The +.Fn modf +function breaks the argument +.Fa value +into integral and fractional parts, each of which has the +same sign as the argument. +It stores the integral part as a +.Em double +in the object pointed to by +.Fa iptr . +.Sh RETURN VALUES +The +.Fn modf +function returns the signed fractional part of +.Fa value . +.Sh SEE ALSO +.Xr frexp 3 , +.Xr ldexp 3 , +.Xr math 3 +.Sh STANDARDS +The +.Fn modf +function conforms to +.St -isoC . diff --git a/gen/mrand48.c b/gen/mrand48.c new file mode 100644 index 0000000..b23db51 --- /dev/null +++ b/gen/mrand48.c @@ -0,0 +1,23 @@ +/* + * Copyright (c) 1993 Martin Birgmeier + * All rights reserved. + * + * You may redistribute unmodified or modified versions of this source + * code provided that the above copyright notice and this and the + * following conditions are retained. + * + * This software is provided ``as is'', and comes with no warranties + * of any kind. I shall in no event be liable for anything that happens + * to anyone/anything when using this software. + */ + +#include "rand48.h" + +extern unsigned short _rand48_seed[3]; + +long +mrand48(void) +{ + _dorand48(_rand48_seed); + return ((long) _rand48_seed[2] << 16) + (long) _rand48_seed[1]; +} diff --git a/gen/msgctl.3 b/gen/msgctl.3 new file mode 100644 index 0000000..83af0c3 --- /dev/null +++ b/gen/msgctl.3 @@ -0,0 +1,206 @@ +.\" $NetBSD: msgctl.2,v 1.1 1995/10/16 23:49:15 jtc Exp $ +.\" +.\" Copyright (c) 1995 Frank van der Linden +.\" 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 for the NetBSD Project +.\" by Frank van der Linden +.\" 4. 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 BY THE AUTHOR ``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 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/msgctl.3,v 1.16 2001/10/01 16:08:51 ru Exp $ +.\"/ +.Dd November 24, 1997 +.Dt MSGCTL 3 +.Os +.Sh NAME +.Nm msgctl +.Nd message control operations +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In sys/types.h +.In sys/ipc.h +.In sys/msg.h +.Ft int +.Fn msgctl "int msqid" "int cmd" "struct msqid_ds *buf" +.Sh DESCRIPTION +The +.Fn msgctl +system call performs some control operations on the message queue specified +by +.Fa msqid . +.Pp +Each message queue has a data structure associated with it, parts of which +may be altered by +.Fn msgctl +and parts of which determine the actions of +.Fn msgctl . +The data structure is defined in +.Aq Pa sys/msg.h +and contains (amongst others) the following members: +.Bd -literal +struct msqid_ds { + struct ipc_perm msg_perm; /* msg queue permission bits */ + struct msg *msg_first; /* first message in the queue */ + struct msg *msg_last; /* last message in the queue */ + u_long msg_cbytes; /* number of bytes in use on the queue */ + u_long msg_qnum; /* number of msgs in the queue */ + u_long msg_qbytes; /* max # of bytes on the queue */ + pid_t msg_lspid; /* pid of last msgsnd() */ + pid_t msg_lrpid; /* pid of last msgrcv() */ + time_t msg_stime; /* time of last msgsnd() */ + long msg_pad1; + time_t msg_rtime; /* time of last msgrcv() */ + long msg_pad2; + time_t msg_ctime; /* time of last msgctl() */ + long msg_pad3; + long msg_pad4[4]; +}; +.Ed +.Pp +The +.Vt ipc_perm +structure used inside the +.Vt shmid_ds +structure is defined in +.Aq Pa sys/ipc.h +and looks like this: +.Bd -literal +struct ipc_perm { + ushort cuid; /* creator user id */ + ushort cgid; /* creator group id */ + ushort uid; /* user id */ + ushort gid; /* group id */ + ushort mode; /* r/w permission */ + ushort seq; /* sequence # (to generate unique msg/sem/shm id) */ + key_t key; /* user specified msg/sem/shm key */ +}; +.Ed +.Pp +The operation to be performed by +.Fn msgctl +is specified in +.Fa cmd +and is one of: +.Bl -tag -width IPC_RMIDX +.It Dv IPC_STAT +Gather information about the message queue and place it in the +structure pointed to by +.Fa buf . +.It Dv IPC_SET +Set the value of the +.Va msg_perm.uid , +.Va msg_perm.gid , +.Va msg_perm.mode +and +.Va msg_qbytes +fields in the structure associated with +.Fa msqid . +The values are taken from the corresponding fields in the structure +pointed to by +.Fa buf . +This operation can only be executed by the super-user, or a process that +has an effective user id equal to either +.Va msg_perm.cuid +or +.Va msg_perm.uid +in the data structure associated with the message queue. +The value of +.Va msg_qbytes +can only be increased by the super-user. +Values for +.Va msg_qbytes +that exceed the system limit (MSGMNB from +.Aq Pa sys/msg.h ) +are silently truncated to that limit. +.It Dv IPC_RMID +Remove the message queue specified by +.Fa msqid +and destroy the data associated with it. +Only the super-user or a process +with an effective uid equal to the +.Va msg_perm.cuid +or +.Va msg_perm.uid +values in the data structure associated with the queue can do this. +.El +.Pp +The permission to read from or write to a message queue (see +.Xr msgsnd 3 +and +.Xr msgrcv 3 ) +is determined by the +.Va msg_perm.mode +field in the same way as is +done with files (see +.Xr chmod 2 ) , +but the effective uid can match either the +.Va msg_perm.cuid +field or the +.Va msg_perm.uid +field, and the +effective gid can match either +.Va msg_perm.cgid +or +.Va msg_perm.gid . +.Sh RETURN VALUES +.Rv -std msgctl +.Sh ERRORS +.Fn msgctl +will fail if: +.Bl -tag -width Er +.It Bq Er EPERM +.Fa cmd +is equal to IPC_SET or IPC_RMID and the caller is not the super-user, nor does +the effective uid match either the +.Va msg_perm.uid +or +.Va msg_perm.cuid +fields of the data structure associated with the message queue. +.Pp +An attempt is made to increase the value of +.Va msg_qbytes +through IPC_SET +but the caller is not the super-user. +.It Bq Er EACCES +The command is IPC_STAT +and the caller has no read permission for this message queue. +.It Bq Er EINVAL +.Fa msqid +is not a valid message queue identifier. +.Pp +.Va cmd +is not a valid command. +.It Bq Er EFAULT +.Fa buf +specifies an invalid address. +.El +.Sh SEE ALSO +.Xr msgget 3 , +.Xr msgrcv 3 , +.Xr msgsnd 3 +.Sh HISTORY +Message queues appeared in the first release of +.At V . diff --git a/gen/msgget.3 b/gen/msgget.3 new file mode 100644 index 0000000..6a7ee9e --- /dev/null +++ b/gen/msgget.3 @@ -0,0 +1,139 @@ +.\" $NetBSD: msgget.2,v 1.1 1995/10/16 23:49:19 jtc Exp $ +.\" +.\" Copyright (c) 1995 Frank van der Linden +.\" 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 for the NetBSD Project +.\" by Frank van der Linden +.\" 4. 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 BY THE AUTHOR ``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 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/msgget.3,v 1.12 2001/10/01 16:08:51 ru Exp $ +.\" +.\"/ +.Dd August 17, 1995 +.Dt MSGGET 3 +.Os +.Sh NAME +.Nm msgget +.Nd get message queue +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In sys/types.h +.In sys/ipc.h +.In sys/msg.h +.Ft int +.Fn msgget "key_t key" "int msgflg" +.Sh DESCRIPTION +.Fn msgget +returns the message queue identifier associated with +.Fa key . +A message queue identifier is a unique integer greater than zero. +.Pp +A message queue is created if either +.Fa key +is equal to +.Dv IPC_PRIVATE , +or +.Fa key +does not have a message queue identifier associated with it, and the +.Dv IPC_CREAT +bit is set in +.Fa msgflg . +.Pp +If a new message queue is created, the data structure associated with it (the +.Va msqid_ds +structure, see +.Xr msgctl 3 ) +is initialized as follows: +.Bl -bullet +.It +.Va msg_perm.cuid +and +.Va msg_perm.uid +are set to the effective uid of the calling process. +.It +.Va msg_perm.gid +and +.Va msg_perm.cgid +are set to the effective gid of the calling process. +.It +.Va msg_perm.mode +is set to the lower 9 bits of +.Fa msgflg . +.It +.Va msg_cbytes , +.Va msg_qnum , +.Va msg_lspid , +.Va msg_lrpid , +.Va msg_rtime , +and +.Va msg_stime +are set to 0. +.It +.Va msg_qbytes +is set to the system wide maximum value for the number of bytes in a queue +.Pf ( Dv MSGMNB ) . +.It +.Va msg_ctime +is set to the current time. +.El +.Sh RETURN VALUES +Upon successful completion a positive message queue identifier is returned. +Otherwise, -1 is returned and the global variable +.Va errno +is set to indicate the error. +.Sh ERRORS +.Bl -tag -width Er +.It Bq Er EACCES +A message queue is already associated with +.Fa key +and the caller has no permission to access it. +.It Bq Er EEXIST +Both +.Dv IPC_CREAT +and +.Dv IPC_EXCL +are set in +.Fa msgflg , +and a message queue is already associated with +.Fa key . +.It Bq Er ENOSPC +A new message queue could not be created because the system limit for +the number of message queues has been reached. +.It Bq Er ENOENT +.Dv IPC_CREAT +was not set in +.Fa msgflg +and no message queue associated with +.Fa key +was found. +.El +.Sh SEE ALSO +.Xr msgctl 3 , +.Xr msgrcv 3 , +.Xr msgsnd 3 +.Sh HISTORY +Message queues appeared in the first release of +.At V . diff --git a/gen/msgrcv.3 b/gen/msgrcv.3 new file mode 100644 index 0000000..b80f987 --- /dev/null +++ b/gen/msgrcv.3 @@ -0,0 +1,202 @@ +.\" $NetBSD: msgrcv.2,v 1.1 1995/10/16 23:49:20 jtc Exp $ +.\" +.\" Copyright (c) 1995 Frank van der Linden +.\" 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 for the NetBSD Project +.\" by Frank van der Linden +.\" 4. 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 BY THE AUTHOR ``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 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/msgrcv.3,v 1.16 2001/10/01 16:08:51 ru Exp $ +.\" +.\"/ +.Dd November 24, 1997 +.Dt MSGRCV 3 +.Os +.Sh NAME +.Nm msgrcv +.Nd receive a message from a message queue +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In sys/types.h +.In sys/ipc.h +.In sys/msg.h +.Ft int +.Fn msgrcv "int msqid" "void *msgp" "size_t msgsz" "long msgtyp" "int msgflg" +.Sh DESCRIPTION +The +.Fn msgrcv +function receives a message from the message queue specified in +.Fa msqid , +and places it into the structure pointed to by +.Fa msgp . +This structure should consist of the following members: +.Bd -literal + long mtype; /* message type */ + char mtext[1]; /* body of message */ +.Ed +.Pp +.Va mtype +is an integer greater than 0 that can be used for selecting messages, +.Va mtext +is an array of bytes, with a size up to that of the system limit +.Pf ( Dv MSGMAX ) . +.Pp +The value of +.Fa msgtyp +has one of the following meanings: +.Bl -bullet +.It +.Fa msgtyp +is greater than 0. The first message of type +.Fa msgtyp +will be received. +.It +.Fa msgtyp +is equal to 0. The first message on the queue will be received. +.It +.Fa msgtyp +is less than 0. The first message of the lowest message type that is +less than or equal to the absolute value of +.Fa msgtyp +will be received. +.El +.Pp +.Fa msgsz +specifies the maximum length of the requested message. +If the received +message has a length greater than +.Fa msgsz +it will be silently truncated if the +.Dv MSG_NOERROR +flag is set in +.Fa msgflg , +otherwise an error will be returned. +.Pp +If no matching message is present on the message queue specified by +.Fa msqid , +the behavior of +.Fn msgrcv +depends on whether the +.Dv IPC_NOWAIT +flag is set in +.Fa msgflg +or not. +If +.Dv IPC_NOWAIT +is set, +.Fn msgrcv +will immediately return a value of -1, and set +.Va errno +to +.Er EAGAIN . +If +.Dv IPC_NOWAIT +is not set, the calling process will be blocked +until: +.Bl -bullet +.It +A message of the requested type becomes available on the message queue. +.It +The message queue is removed, in which case -1 will be returned, and +.Va errno +set to +.Er EINVAL . +.It +A signal is received and caught. -1 is returned, and +.Va errno +set to +.Er EINTR . +.El +.Pp +If a message is successfully received, the data structure associated with +.Fa msqid +is updated as follows: +.Bl -bullet +.It +.Va msg_cbytes +is decremented by the size of the message. +.It +.Va msg_lrpid +is set to the pid of the caller. +.It +.Va msg_lrtime +is set to the current time. +.It +.Va msg_qnum +is decremented by 1. +.El +.Sh RETURN VALUES +Upon successful completion, +.Fn msgrcv +returns the number of bytes received into the +.Va mtext +field of the structure pointed to by +.Fa msgp . +Otherwise, -1 is returned, and +.Va errno +set to indicate the error. +.Sh ERRORS +.Fn msgrcv +will fail if: +.Bl -tag -width Er +.It Bq Er EINVAL +.Fa msqid +is not a valid message queue identifier. +.Pp +The message queue was removed while +.Fn msgrcv +was waiting for a message of the requested type to become available on it. +.Pp +.Fa msgsz +is less than 0. +.It Bq Er E2BIG +A matching message was received, but its size was greater than +.Fa msgsz +and the +.Dv MSG_NOERROR +flag was not set in +.Fa msgflg . +.It Bq Er EACCES +The calling process does not have read access to the message queue. +.It Bq Er EFAULT +.Fa msgp +points to an invalid address. +.It Bq Er EINTR +The system call was interrupted by the delivery of a signal. +.It Bq Er EAGAIN +There is no message of the requested type available on the message queue, +and +.Dv IPC_NOWAIT +is set in +.Fa msgflg . +.El +.Sh SEE ALSO +.Xr msgctl 3 , +.Xr msgget 3 , +.Xr msgsnd 3 +.Sh HISTORY +Message queues appeared in the first release of +.At V . diff --git a/gen/msgsnd.3 b/gen/msgsnd.3 new file mode 100644 index 0000000..ee70922 --- /dev/null +++ b/gen/msgsnd.3 @@ -0,0 +1,167 @@ +.\" $NetBSD: msgsnd.2,v 1.1 1995/10/16 23:49:24 jtc Exp $ +.\" +.\" Copyright (c) 1995 Frank van der Linden +.\" 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 for the NetBSD Project +.\" by Frank van der Linden +.\" 4. 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 BY THE AUTHOR ``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 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/msgsnd.3,v 1.16 2001/10/01 16:08:51 ru Exp $ +.\" +.Dd November 24, 1997 +.Dt MSGSND 3 +.Os +.Sh NAME +.Nm msgsnd +.Nd send a message to a message queue +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In sys/types.h +.In sys/ipc.h +.In sys/msg.h +.Ft int +.Fn msgsnd "int msqid" "void *msgp" "size_t msgsz" "int msgflg" +.Sh DESCRIPTION +The +.Fn msgsnd +function sends a message to the message queue specified in +.Fa msqid . +.Fa msgp +points to a structure containing the message. +This structure should +consist of the following members: +.Bd -literal + long mtype; /* message type */ + char mtext[1]; /* body of message */ +.Ed +.Pp +.Va mtype +is an integer greater than 0 that can be used for selecting messages (see +.Xr msgrcv 3 ) , +.Va mtext +is an array of bytes, with a size up to that of the system limit +.Pf ( Dv MSGMAX ) . +.Pp +If the number of bytes already on the message queue plus +.Fa msgsz +is bigger than the maximum number of bytes on the message queue +.Pf ( Va msg_qbytes , +see +.Xr msgctl 3 ) , +or the number of messages on all queues system-wide is already equal to +the system limit, +.Fa msgflg +determines the action of +.Fn msgsnd . +If +.Fa msgflg +has +.Dv IPC_NOWAIT +mask set in it, the call will return immediately. +If +.Fa msgflg +does not have +.Dv IPC_NOWAIT +set in it, the call will block until: +.Bl -bullet +.It +The condition which caused the call to block does no longer exist. +The message will be sent. +.It +The message queue is removed, in which case -1 will be returned, and +.Va errno +is set to +.Er EINVAL . +.It +The caller catches a signal. +The call returns with +.Va errno +set to +.Er EINTR . +.El +.Pp +After a successful call, the data structure associated with the message +queue is updated in the following way: +.Bl -bullet +.It +.Va msg_cbytes +is incremented by the size of the message. +.It +.Va msg_qnum +is incremented by 1. +.It +.Va msg_lspid +is set to the pid of the calling process. +.It +.Va msg_stime +is set to the current time. +.El +.Sh RETURN VALUES +.Rv -std msgsnd +.Sh ERRORS +.Fn msgsnd +will fail if: +.Bl -tag -width Er +.It Bq Er EINVAL +.Fa msqid +is not a valid message queue identifier +.Pp +The message queue was removed while +.Fn msgsnd +was waiting for a resource to become available in order to deliver the +message. +.Pp +.Fa msgsz +is less than 0, or greater than +.Va msg_qbytes . +.Pp +.Fa mtype +is not greater than 0. +.It Bq Er EACCES +The calling process does not have write access to the message queue. +.It Bq Er EAGAIN +There was no space for this message either on the queue, or in the whole +system, and +.Dv IPC_NOWAIT +was set in +.Fa msgflg . +.It Bq Er EFAULT +.Fa msgp +points to an invalid address. +.It Bq Er EINTR +The system call was interrupted by the delivery of a signal. +.El +.Sh BUGS +.Nx +and +.Fx +do not define the +.Er EIDRM +error value, which should be used +in the case of a removed message queue. +.Sh HISTORY +Message queues appeared in the first release of AT&T Unix System V. diff --git a/gen/nanosleep.c b/gen/nanosleep.c new file mode 100644 index 0000000..84dec2f --- /dev/null +++ b/gen/nanosleep.c @@ -0,0 +1,72 @@ +/* + * Copyright (c) 1999 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@ + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +extern mach_port_t clock_port; + +int +nanosleep(const struct timespec *requested_time, struct timespec *remaining_time) { + kern_return_t ret; + mach_timespec_t remain; + mach_timespec_t current; + + if ((requested_time == NULL) || (requested_time->tv_sec < 0) || (requested_time->tv_nsec > NSEC_PER_SEC)) { + errno = EINVAL; + return -1; + } + + ret = clock_get_time(clock_port, ¤t); + 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 */ + ret = clock_sleep_trap(clock_port, TIME_RELATIVE, requested_time->tv_sec, requested_time->tv_nsec, &remain); + if (ret != KERN_SUCCESS) { + if (ret == KERN_ABORTED) { + 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; + } + 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; + } + return 0; +} diff --git a/gen/nice.3 b/gen/nice.3 new file mode 100644 index 0000000..6a98d9e --- /dev/null +++ b/gen/nice.3 @@ -0,0 +1,73 @@ +.\" 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. +.\" +.\" @(#)nice.3 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD: src/lib/libc/gen/nice.3,v 1.11 2001/10/01 16:08:51 ru Exp $ +.\" +.Dd June 4, 1993 +.Dt NICE 3 +.Os +.Sh NAME +.Nm nice +.Nd set program scheduling priority +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In unistd.h +.Ft int +.Fn nice "int incr" +.Sh DESCRIPTION +.Bf -symbolic +This interface is obsoleted by +.Xr setpriority 2 . +.Ef +.Pp +The +.Fn nice +function obtains the scheduling priority of the process +from the system and sets it to the priority value specified in +.Fa incr . +The priority is a value in the range -20 to 20. +The default priority is 0; lower priorities cause more favorable scheduling. +Only the super-user may lower priorities. +.Pp +Children inherit the priority of their parent processes via +.Xr fork 2 . +.Sh SEE ALSO +.Xr nice 1 , +.Xr fork 2 , +.Xr setpriority 2 , +.Xr renice 8 +.Sh HISTORY +A +.Fn nice +syscall appeared in +.At v6 . diff --git a/gen/nice.c b/gen/nice.c new file mode 100644 index 0000000..8b99cd2 --- /dev/null +++ b/gen/nice.c @@ -0,0 +1,75 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1983, 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 +#include +#include +#include +#include +/* + * Backwards compatible nice. + */ +int +nice(incr) + int incr; +{ + int prio; + + errno = 0; + prio = getpriority(PRIO_PROCESS, 0); + if (prio == -1 && errno) + return (-1); + return (setpriority(PRIO_PROCESS, 0, prio + incr)); +} diff --git a/gen/nlist.3 b/gen/nlist.3 new file mode 100644 index 0000000..09df218 --- /dev/null +++ b/gen/nlist.3 @@ -0,0 +1,77 @@ +.\" $OpenBSD: nlist.3,v 1.2 1996/08/19 08:25:07 tholo 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. +.\" +.Dd April 19, 1994 +.Dt NLIST 3 +.Os Darwin +.Sh NAME +.Nm nlist +.Nd retrieve symbol table name list from an executable file +.Sh SYNOPSIS +.Fd #include +.Ft int +.Fn nlist "const char *filename" "struct nlist *nl" +.Sh DESCRIPTION +The +.Fn nlist +function +retrieves name list entries from the symbol table of an +executable file. (See ) +The argument +.Fa \&nl +is set to reference the +beginning of the list. +The list is preened of binary and invalid data; +if an entry in the +name list is valid, the +.Fa n_type +and +.Fa n_value +for the entry are copied into the list +referenced by +.Fa \&nl . +No other data is copied. +The last entry in the list is always +.Dv NULL . +.Sh RETURN VALUES +The number of invalid entries is returned if successful; otherwise, +if the file +.Fa filename +does not exist or is not executable, the returned value is \-1. +.Sh SEE ALSO +.Xr Mach-O 5 +.Sh HISTORY +A +.Fn nlist +function appeared in +.At v6 . diff --git a/gen/nlist.c b/gen/nlist.c new file mode 100644 index 0000000..ab17ad2 --- /dev/null +++ b/gen/nlist.c @@ -0,0 +1,332 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * + * + * 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 +#include +#include +#include +#include +#include + +/* Stuff lifted from and since they are gone */ +/* + * Header prepended to each a.out file. + */ +struct exec { +unsigned short a_machtype; /* machine type */ +unsigned short a_magic; /* magic number */ +unsigned long a_text; /* size of text segment */ +unsigned long a_data; /* size of initialized data */ +unsigned long a_bss; /* size of uninitialized data */ +unsigned long a_syms; /* size of symbol table */ +unsigned long a_entry; /* entry point */ +unsigned long a_trsize; /* size of text relocation */ +unsigned long a_drsize; /* size of data relocation */ +}; + +#define OMAGIC 0407 /* old impure format */ +#define NMAGIC 0410 /* read-only text */ +#define ZMAGIC 0413 /* demand load format */ + +#define N_BADMAG(x) \ + (((x).a_magic)!=OMAGIC && ((x).a_magic)!=NMAGIC && ((x).a_magic)!=ZMAGIC) +#define N_TXTOFF(x) \ + ((x).a_magic==ZMAGIC ? 0 : sizeof (struct exec)) +#define N_SYMOFF(x) \ + (N_TXTOFF(x) + (x).a_text+(x).a_data + (x).a_trsize+(x).a_drsize) + +#include +#include +#include +#include +#include + +/* + * CPUSUBTYPE_SUPPORT should be changed to non-zero once the + * cpusubtype_* routines are available in libc. + */ +#define CPUSUBTYPE_SUPPORT 0 + +/* + * nlist - retreive attributes from name list (string table version) + */ + +int +nlist(name, list) + const char *name; + struct nlist *list; +{ + int fd, n; + + fd = open(name, O_RDONLY, 0); + if (fd < 0) + return (-1); + n = __fdnlist(fd, list); + (void)close(fd); + return (n); +} + +/* Note: __fdnlist() is called from kvm_nlist in libkvm's kvm.c */ + +int +__fdnlist(fd, list) + int fd; + struct nlist *list; +{ + register struct nlist *p, *q; + register char *s1, *s2; + register n, m; + int maxlen, nreq; + off_t sa; /* symbol address */ + off_t ss; /* start of strings */ + struct exec buf; + struct nlist space[BUFSIZ/sizeof (struct nlist)]; + unsigned arch_offset = 0; + + maxlen = 0; + for (q = list, nreq = 0; q->n_un.n_name && q->n_un.n_name[0]; q++, nreq++) { + q->n_type = 0; + q->n_value = 0; + q->n_desc = 0; + q->n_sect = 0; + n = strlen(q->n_un.n_name); + if (n > maxlen) + maxlen = n; + } + if (read(fd, (char *)&buf, sizeof(buf)) != sizeof(buf) || + (N_BADMAG(buf) && *((long *)&buf) != MH_MAGIC && + NXSwapBigLongToHost(*((long *)&buf)) != FAT_MAGIC)) { + return (-1); + } + + /* Deal with fat file if necessary */ + if (NXSwapBigLongToHost(*((long *)&buf)) == FAT_MAGIC) { + struct host_basic_info hbi; + struct fat_header fh; + struct fat_arch *fat_archs, *fap; + unsigned i; + host_t host; + + /* Get our host info */ + host = mach_host_self(); + i = HOST_BASIC_INFO_COUNT; + if (host_info(host, HOST_BASIC_INFO, + (host_info_t)(&hbi), &i) != KERN_SUCCESS) { + return (-1); + } + mach_port_deallocate(mach_task_self(), host); + + /* Read in the fat header */ + lseek(fd, 0, SEEK_SET); + if (read(fd, (char *)&fh, sizeof(fh)) != sizeof(fh)) { + return (-1); + } + + /* Convert fat_narchs to host byte order */ + fh.nfat_arch = NXSwapBigLongToHost(fh.nfat_arch); + + /* Read in the fat archs */ + fat_archs = (struct fat_arch *)malloc(fh.nfat_arch * + sizeof(struct fat_arch)); + if (fat_archs == NULL) { + return (-1); + } + if (read(fd, (char *)fat_archs, + sizeof(struct fat_arch) * fh.nfat_arch) != + sizeof(struct fat_arch) * fh.nfat_arch) { + free(fat_archs); + return (-1); + } + + /* + * Convert archs to host byte ordering (a constraint of + * cpusubtype_getbestarch() + */ + for (i = 0; i < fh.nfat_arch; i++) { + fat_archs[i].cputype = + NXSwapBigLongToHost(fat_archs[i].cputype); + fat_archs[i].cpusubtype = + NXSwapBigLongToHost(fat_archs[i].cpusubtype); + fat_archs[i].offset = + NXSwapBigLongToHost(fat_archs[i].offset); + fat_archs[i].size = + NXSwapBigLongToHost(fat_archs[i].size); + fat_archs[i].align = + NXSwapBigLongToHost(fat_archs[i].align); + } + +#if CPUSUBTYPE_SUPPORT + fap = cpusubtype_getbestarch(hbi.cpu_type, hbi.cpu_subtype, + fat_archs, fh.nfat_arch); +#else CPUSUBTYPE_SUPPORT +#warning Use the cpusubtype functions!!! + fap = NULL; + for (i = 0; i < fh.nfat_arch; i++) { + if (fat_archs[i].cputype == hbi.cpu_type) { + fap = &fat_archs[i]; + break; + } + } +#endif CPUSUBTYPE_SUPPORT + if (!fap) { + free(fat_archs); + return (-1); + } + arch_offset = fap->offset; + free(fat_archs); + + /* Read in the beginning of the architecture-specific file */ + lseek(fd, arch_offset, SEEK_SET); + if (read(fd, (char *)&buf, sizeof(buf)) != sizeof(buf)) { + return (-1); + } + } + + if (*((long *)&buf) == MH_MAGIC) { + struct mach_header mh; + struct load_command *load_commands, *lcp; + struct symtab_command *stp; + long i; + + lseek(fd, arch_offset, SEEK_SET); + if (read(fd, (char *)&mh, sizeof(mh)) != sizeof(mh)) { + return (-1); + } + load_commands = (struct load_command *)malloc(mh.sizeofcmds); + if (load_commands == NULL) { + return (-1); + } + if (read(fd, (char *)load_commands, mh.sizeofcmds) != + mh.sizeofcmds) { + free(load_commands); + return (-1); + } + stp = NULL; + lcp = load_commands; + for (i = 0; i < mh.ncmds; i++) { + if (lcp->cmdsize % sizeof(long) != 0 || + lcp->cmdsize <= 0 || + (char *)lcp + lcp->cmdsize > + (char *)load_commands + mh.sizeofcmds) { + free(load_commands); + return (-1); + } + if (lcp->cmd == LC_SYMTAB) { + if (lcp->cmdsize != + sizeof(struct symtab_command)) { + free(load_commands); + return (-1); + } + stp = (struct symtab_command *)lcp; + break; + } + lcp = (struct load_command *) + ((char *)lcp + lcp->cmdsize); + } + if (stp == NULL) { + free(load_commands); + return (-1); + } + sa = stp->symoff + arch_offset; + ss = stp->stroff + arch_offset; + n = stp->nsyms * sizeof(struct nlist); + free(load_commands); + } + else { + sa = N_SYMOFF(buf) + arch_offset; + ss = sa + buf.a_syms + arch_offset; + n = buf.a_syms; + } + + lseek(fd, sa, SEEK_SET); + while (n) { + long savpos; + + m = sizeof (space); + if (n < m) + m = n; + if (read(fd, (char *)space, m) != m) + break; + n -= m; + savpos = lseek(fd, 0, SEEK_CUR); + for (q = space; (m -= sizeof(struct nlist)) >= 0; q++) { + char nambuf[BUFSIZ]; + + if (q->n_un.n_strx == 0 || q->n_type & N_STAB) + continue; + lseek(fd, ss+q->n_un.n_strx, SEEK_SET); + read(fd, nambuf, maxlen+1); + for (p = list; p->n_un.n_name && p->n_un.n_name[0]; p++) { + s1 = p->n_un.n_name; + s2 = nambuf; + while (*s1) { + if (*s1++ != *s2++) + goto cont; + } + if (*s2) + goto cont; + p->n_value = q->n_value; + p->n_type = q->n_type; + p->n_desc = q->n_desc; + p->n_sect = q->n_sect; + if (--nreq == 0) + return (nreq); + break; + cont: ; + } + } + lseek(fd, savpos, SEEK_SET); + } + return (nreq); +} diff --git a/gen/nrand48.c b/gen/nrand48.c new file mode 100644 index 0000000..6c54065 --- /dev/null +++ b/gen/nrand48.c @@ -0,0 +1,21 @@ +/* + * Copyright (c) 1993 Martin Birgmeier + * All rights reserved. + * + * You may redistribute unmodified or modified versions of this source + * code provided that the above copyright notice and this and the + * following conditions are retained. + * + * This software is provided ``as is'', and comes with no warranties + * of any kind. I shall in no event be liable for anything that happens + * to anyone/anything when using this software. + */ + +#include "rand48.h" + +long +nrand48(unsigned short xseed[3]) +{ + _dorand48(xseed); + return ((long) xseed[2] << 15) + ((long) xseed[1] >> 1); +} diff --git a/gen/opendir.c b/gen/opendir.c new file mode 100644 index 0000000..1426f1d --- /dev/null +++ b/gen/opendir.c @@ -0,0 +1,278 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1983, 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 +#include +#include + +#include +#include +#include +#include +#include +#include + +DIR *__opendir2(const char *name, int flags) +{ + DIR *dirp; + int fd; + int incr; + int unionstack; + struct stat statb; + + if ((fd = open(name, O_RDONLY)) == -1) + return (NULL); + if (fstat(fd, &statb) || !S_ISDIR(statb.st_mode)) { + errno = ENOTDIR; + close(fd); + return (NULL); + } + if (fcntl(fd, F_SETFD, FD_CLOEXEC) == -1 || + (dirp = (DIR *)malloc(sizeof(DIR))) == NULL) { + close(fd); + return (NULL); + } + + /* + * If CLBYTES is an exact multiple of DIRBLKSIZ, use a CLBYTES + * buffer that it cluster boundary aligned. + * Hopefully this can be a big win someday by allowing page + * trades to user space to be done by getdirentries() + */ + if ((CLBYTES % DIRBLKSIZ) == 0) + incr = CLBYTES; + else + incr = DIRBLKSIZ; + + /* + * Determine whether this directory is the top of a union stack. + */ + if (flags & DTF_NODUP) { + struct statfs sfb; + + if (fstatfs(fd, &sfb) < 0) { + free(dirp); + close(fd); + return (NULL); + } + unionstack = (!strcmp(sfb.f_fstypename, "union") || (sfb.f_flags & MNT_UNION)); + } else { + unionstack = 0; + } + + if (unionstack) { + int len = 0; + int space = 0; + char *buf = 0; + char *ddptr = 0; + char *ddeptr; + int n; + struct dirent **dpv; + + /* + * The strategy here is to read all the directory + * entries into a buffer, sort the buffer, and + * remove duplicate entries by setting the inode + * number to zero. + */ + + do { + /* + * Always make at least DIRBLKSIZ bytes + * available to getdirentries + */ + if (space < DIRBLKSIZ) { + space += incr; + len += incr; + buf = realloc(buf, len); + if (buf == NULL) { + free(dirp); + close(fd); + return (NULL); + } + ddptr = buf + (len - space); + } + + n = getdirentries(fd, ddptr, space, &dirp->dd_seek); + if (n > 0) { + ddptr += n; + space -= n; + } + } while (n > 0); + + ddeptr = ddptr; + flags |= __DTF_READALL; + + /* + * Re-open the directory. + * This has the effect of rewinding back to the + * top of the union stack and is needed by + * programs which plan to fchdir to a descriptor + * which has also been read -- see fts.c. + */ + if (flags & DTF_REWIND) { + (void) close(fd); + if ((fd = open(name, O_RDONLY)) == -1) { + free(buf); + free(dirp); + return (NULL); + } + } + + /* + * There is now a buffer full of (possibly) duplicate + * names. + */ + dirp->dd_buf = buf; + + /* + * Go round this loop twice... + * + * Scan through the buffer, counting entries. + * On the second pass, save pointers to each one. + * Then sort the pointers and remove duplicate names. + */ + for (dpv = 0;;) { + n = 0; + ddptr = buf; + while (ddptr < ddeptr) { + struct dirent *dp; + + dp = (struct dirent *) ddptr; + if ((int)dp & 03) + break; + if ((dp->d_reclen <= 0) || + (dp->d_reclen > (ddeptr + 1 - ddptr))) + break; + ddptr += dp->d_reclen; + if (dp->d_fileno) { + if (dpv) + dpv[n] = dp; + n++; + } + } + + if (dpv) { + struct dirent *xp; + + /* + * This sort must be stable. + */ + mergesort(dpv, n, sizeof(*dpv), alphasort); + + dpv[n] = NULL; + xp = NULL; + + /* + * Scan through the buffer in sort order, + * zapping the inode number of any + * duplicate names. + */ + for (n = 0; dpv[n]; n++) { + struct dirent *dp = dpv[n]; + + if ((xp == NULL) || + strcmp(dp->d_name, xp->d_name)) { + xp = dp; + } else { + dp->d_fileno = 0; + } + if (dp->d_type == DT_WHT && + (flags & DTF_HIDEW)) + dp->d_fileno = 0; + } + + free(dpv); + break; + } else { + dpv = malloc((n+1) * sizeof(struct dirent *)); + if (dpv == NULL) + break; + } + } + + dirp->dd_len = len; + dirp->dd_size = ddptr - dirp->dd_buf; + } else { + dirp->dd_len = incr; + dirp->dd_buf = malloc(dirp->dd_len); + if (dirp->dd_buf == NULL) { + free(dirp); + close (fd); + return (NULL); + } + dirp->dd_seek = 0; + flags &= ~DTF_REWIND; + } + + dirp->dd_loc = 0; + dirp->dd_fd = fd; + dirp->dd_flags = flags; + + /* + * Set up seek point for rewinddir. + */ + dirp->dd_rewind = telldir(dirp); + + return (dirp); +} + +/* + * Open a directory. + */ +DIR *opendir(const char *name) +{ + return (__opendir2(name, DTF_HIDEW|DTF_NODUP)); +} diff --git a/gen/pause.3 b/gen/pause.3 new file mode 100644 index 0000000..b8c257e --- /dev/null +++ b/gen/pause.3 @@ -0,0 +1,86 @@ +.\" 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. +.\" +.\" @(#)pause.3 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD: src/lib/libc/gen/pause.3,v 1.8 2001/10/01 16:08:51 ru Exp $ +.\" +.Dd June 4, 1993 +.Dt PAUSE 3 +.Os +.Sh NAME +.Nm pause +.Nd stop until signal +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In unistd.h +.Ft int +.Fn pause void +.Sh DESCRIPTION +.Sy Pause is made obsolete by +.Xr sigsuspend 2 . +.Pp +The +.Fn pause +function +forces a process to pause until +a signal is received from either the +.Xr kill 2 +function +or an interval timer. +(See +.Xr setitimer 2 . ) +Upon termination of a signal handler started during a +.Fn pause , +the +.Fn pause +call will return. +.Sh RETURN VALUES +Always returns \-1. +.Sh ERRORS +The +.Fn pause +function +always returns: +.Bl -tag -width Er +.It Bq Er EINTR +The call was interrupted. +.El +.Sh SEE ALSO +.Xr kill 2 , +.Xr select 2 , +.Xr sigsuspend 2 +.Sh HISTORY +A +.Fn pause +syscall +appeared in +.At v6 . diff --git a/gen/pause.c b/gen/pause.c new file mode 100644 index 0000000..fea8bc1 --- /dev/null +++ b/gen/pause.c @@ -0,0 +1,67 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1983, 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 +#include + +/* + * Backwards compatible pause. + */ +int +pause() +{ + + return sigpause(sigblock(0L)); +} diff --git a/gen/popen.3 b/gen/popen.3 new file mode 100644 index 0000000..757531b --- /dev/null +++ b/gen/popen.3 @@ -0,0 +1,201 @@ +.\" 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. +.\" +.\" @(#)popen.3 8.2 (Berkeley) 5/3/95 +.\" $FreeBSD: src/lib/libc/gen/popen.3,v 1.14 2001/10/01 16:08:51 ru Exp $ +.\" +.Dd May 3, 1995 +.Dt POPEN 3 +.Os +.Sh NAME +.Nm popen , +.Nm pclose +.Nd process +.Tn I/O +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In stdio.h +.Ft FILE * +.Fn popen "const char *command" "const char *type" +.Ft int +.Fn pclose "FILE *stream" +.Sh DESCRIPTION +The +.Fn popen +function +.Dq opens +a process by creating a bidirectional pipe +forking, +and invoking the shell. +Any streams opened by previous +.Fn popen +calls in the parent process are closed in the new child process. +Historically, +.Fn popen +was implemented with a unidirectional pipe; +hence many implementations of +.Fn popen +only allow the +.Fa type +argument to specify reading or writing, not both. +Since +.Fn popen +is now implemented using a bidirectional pipe, the +.Fa type +argument may request a bidirectional data flow. +The +.Fa type +argument is a pointer to a null-terminated string +which must be +.Ql r +for reading, +.Ql w +for writing, or +.Ql r+ +for reading and writing. +.Pp +The +.Fa command +argument is a pointer to a null-terminated string +containing a shell command line. +This command is passed to +.Pa /bin/sh +using the +.Fl c +flag; interpretation, if any, is performed by the shell. +.Pp +The return value from +.Fn popen +is a normal standard +.Tn I/O +stream in all respects +save that it must be closed with +.Fn pclose +rather than +.Fn fclose . +Writing to such a stream +writes to the standard input of the command; +the command's standard output is the same as that of the process that called +.Fn popen , +unless this is altered by the command itself. +Conversely, reading from a +.Dq popened +stream reads the command's standard output, and +the command's standard input is the same as that of the process that called +.Fn popen . +.Pp +Note that output +.Fn popen +streams are fully buffered by default. +.Pp +The +.Fn pclose +function waits for the associated process to terminate +and returns the exit status of the command +as returned by +.Fn wait4 . +.Sh RETURN VALUES +The +.Fn popen +function returns +.Dv NULL +if the +.Xr fork 2 +or +.Xr pipe 2 +calls fail, +or if it cannot allocate memory. +.Pp +The +.Fn pclose +function +returns \-1 if +.Fa stream +is not associated with a +.Dq popened +command, if +.Fa stream +already +.Dq pclosed , +or if +.Xr wait4 +returns an error. +.Sh ERRORS +The +.Fn popen +function does not reliably set +.Va errno . +.Sh SEE ALSO +.Xr sh 1 , +.Xr fork 2 , +.Xr pipe 2 , +.Xr wait4 2 , +.Xr fclose 3 , +.Xr fflush 3 , +.Xr fopen 3 , +.Xr stdio 3 , +.Xr system 3 +.Sh BUGS +Since the standard input of a command opened for reading +shares its seek offset with the process that called +.Fn popen , +if the original process has done a buffered read, +the command's input position may not be as expected. +Similarly, the output from a command opened for writing +may become intermingled with that of the original process. +The latter can be avoided by calling +.Xr fflush 3 +before +.Fn popen . +.Pp +Failure to execute the shell +is indistinguishable from the shell's failure to execute command, +or an immediate exit of the command. +The only hint is an exit status of 127. +.Pp +The +.Fn popen +argument +always calls +.Xr sh 1 , +never calls +.Xr csh 1 . +.Sh HISTORY +A +.Fn popen +and a +.Fn pclose +function appeared in +.At v7 . +.Pp +Bidirectional functionality was added in +.Fx 2.2.6 . diff --git a/gen/popen.c b/gen/popen.c new file mode 100644 index 0000000..885d6c6 --- /dev/null +++ b/gen/popen.c @@ -0,0 +1,205 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1988, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software written by Ken Arnold and + * published in UNIX Review, Vol. 6, No. 8. + * + * 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 +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#define environ *(_NSGetEnviron()) + +static struct pid { + struct pid *next; + FILE *fp; + pid_t pid; +} *pidlist; + +FILE * +popen(command, type) + const char *command, *type; +{ + struct pid *cur; + FILE *iop; + int pdes[2], pid, twoway; + char *argv[4]; + struct pid *p; + + if (strchr(type, '+')) { + twoway = 1; + type = "r+"; + if (socketpair(AF_UNIX, SOCK_STREAM, 0, pdes) < 0) + return (NULL); + } else { + twoway = 0; + if ((*type != 'r' && *type != 'w') || type[1]) + return (NULL); + } + if (pipe(pdes) < 0) + return (NULL); + + if ((cur = malloc(sizeof(struct pid))) == NULL) { + (void)close(pdes[0]); + (void)close(pdes[1]); + return (NULL); + } + + argv[0] = "sh"; + argv[1] = "-c"; + argv[2] = (char *)command; + argv[3] = NULL; + + switch (pid = vfork()) { + case -1: /* Error. */ + (void)close(pdes[0]); + (void)close(pdes[1]); + free(cur); + return (NULL); + /* NOTREACHED */ + case 0: /* Child. */ + if (*type == 'r') { + /* + * The _dup2() to STDIN_FILENO is repeated to avoid + * writing to pdes[1], which might corrupt the + * parent's copy. This isn't good enough in + * general, since the _exit() is no return, so + * the compiler is free to corrupt all the local + * variables. + */ + (void)close(pdes[0]); + if (pdes[1] != STDOUT_FILENO) { + (void)dup2(pdes[1], STDOUT_FILENO); + (void)close(pdes[1]); + if (twoway) + (void)dup2(STDOUT_FILENO, STDIN_FILENO); + } else if (twoway && (pdes[1] != STDIN_FILENO)) + (void)dup2(pdes[1], STDIN_FILENO); + } else { + if (pdes[0] != STDIN_FILENO) { + (void)dup2(pdes[0], STDIN_FILENO); + (void)close(pdes[0]); + } + (void)close(pdes[1]); + } + for (p = pidlist; p; p = p->next) { + (void)close(fileno(p->fp)); + } + execve(_PATH_BSHELL, argv, environ); + _exit(127); + /* NOTREACHED */ + } + + /* Parent; assume fdopen can't fail. */ + if (*type == 'r') { + iop = fdopen(pdes[0], type); + (void)close(pdes[1]); + } else { + iop = fdopen(pdes[1], type); + (void)close(pdes[0]); + } + + /* Link into list of file descriptors. */ + cur->fp = iop; + cur->pid = pid; + cur->next = pidlist; + pidlist = cur; + + return (iop); +} + +/* + * pclose -- + * Pclose returns -1 if stream is not associated with a `popened' command, + * if already `pclosed', or waitpid returns an error. + */ +int +pclose(iop) + FILE *iop; +{ + register struct pid *cur, *last; + int pstat; + pid_t pid; + + /* Find the appropriate file pointer. */ + for (last = NULL, cur = pidlist; cur; last = cur, cur = cur->next) + if (cur->fp == iop) + break; + if (cur == NULL) + return (-1); + + (void)fclose(iop); + + do { + pid = wait4(cur->pid, &pstat, 0, (struct rusage *)0); + } while (pid == -1 && errno == EINTR); + + /* Remove the entry from the linked list. */ + if (last == NULL) + pidlist = cur->next; + else + last->next = cur->next; + free(cur); + + return (pid == -1 ? -1 : pstat); +} diff --git a/gen/psignal.3 b/gen/psignal.3 new file mode 100644 index 0000000..67bed20 --- /dev/null +++ b/gen/psignal.3 @@ -0,0 +1,113 @@ +.\" Copyright (c) 1983, 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. +.\" +.\" @(#)psignal.3 8.2 (Berkeley) 2/27/95 +.\" $FreeBSD: src/lib/libc/gen/psignal.3,v 1.15 2001/10/01 16:08:51 ru Exp $ +.\" +.Dd February 27, 1995 +.Dt PSIGNAL 3 +.Os +.Sh NAME +.Nm psignal , +.Nm strsignal , +.Nm sys_siglist , +.Nm sys_signame +.Nd system signal messages +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In signal.h +.Ft void +.Fn psignal "unsigned sig" "const char *s" +.Vt extern const char * const sys_siglist[] ; +.Vt extern const char * const sys_signame[] ; +.In string.h +.Ft "char *" +.Fn strsignal "int sig" +.Sh DESCRIPTION +The +.Fn psignal +and +.Fn strsignal +functions locate the descriptive message +string for a signal number. +.Pp +The +.Fn strsignal +function accepts a signal number argument +.Fa sig +and returns a pointer to the corresponding message string. +.Pp +The +.Fn psignal +function accepts an signal number argument +.Fa sig +and writes it to the standard error. +If the argument +.Fa s +is +.Pf non- Dv NULL +and does not point to the null character, +.Fa s +is written to the standard error file descriptor +prior to the message string, +immediately followed by a colon and a space. +If the signal number is not recognized +.Pq Xr sigaction 2 , +the string +.Dq "Unknown signal +is produced. +.Pp +The message strings can be accessed directly +through the external array +.Va sys_siglist , +indexed by recognized signal numbers. +The external array +.Va sys_signame +is used similarly and +contains short, lower-case abbreviations for signals +which are useful for recognizing signal names +in user input. +The defined variable +.Dv NSIG +contains a count of the strings in +.Va sys_siglist +and +.Va sys_signame . +.Sh SEE ALSO +.Xr sigaction 2 , +.Xr perror 3 , +.Xr strerror 3 +.Sh HISTORY +The +.Fn psignal +function appeared in +.Bx 4.2 . diff --git a/gen/psignal.c b/gen/psignal.c new file mode 100644 index 0000000..3d8a0b8 --- /dev/null +++ b/gen/psignal.c @@ -0,0 +1,85 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1983, 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. + */ + + +/* + * Print the name of the signal indicated + * along with the supplied message. + */ +#include +#include +#include + +extern const char *const sys_siglist[]; + +void +psignal(sig, s) + unsigned int sig; + const char *s; +{ + register const char *c; + register int n; + + if (sig < NSIG) + c = (char *)sys_siglist[sig]; + else + c = "Unknown signal"; + n = strlen(s); + if (n) { + (void)write(STDERR_FILENO, s, n); + (void)write(STDERR_FILENO, ": ", 2); + } + (void)write(STDERR_FILENO, c, strlen(c)); + (void)write(STDERR_FILENO, "\n", 1); +} diff --git a/gen/pwcache.3 b/gen/pwcache.3 new file mode 100644 index 0000000..42f2592 --- /dev/null +++ b/gen/pwcache.3 @@ -0,0 +1,96 @@ +.\" Copyright (c) 1989, 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. +.\" +.\" @(#)pwcache.3 8.1 (Berkeley) 6/9/93 +.\" $FreeBSD: src/lib/libc/gen/pwcache.3,v 1.10 2001/10/01 16:08:51 ru Exp $ +.\" +.Dd June 9, 1993 +.Dt PWCACHE 3 +.Os +.Sh NAME +.Nm pwcache +.Nd cache password and group entries +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In stdlib.h +.Ft char * +.Fn user_from_uid "unsigned long uid" "int nouser" +.Ft char * +.Fn group_from_gid "unsigned long gid" "int nogroup" +.Sh DESCRIPTION +The +.Fn user_from_uid +function returns the user name associated with the argument +.Fa uid . +The user name is cached so that multiple calls with the same +.Fa uid +do not require additional calls to +.Xr getpwuid 3 . +If there is no user associated with the +.Fa uid , +a pointer is returned +to a string representation of the +.Fa uid , +unless the argument +.Fa nouser +is non-zero, in which case a +.Dv NULL +pointer is returned. +.Pp +The +.Fn group_from_gid +function returns the group name associated with the argument +.Fa gid . +The group name is cached so that multiple calls with the same +.Fa gid +do not require additional calls to +.Xr getgrgid 3 . +If there is no group associated with the +.Fa gid , +a pointer is returned +to a string representation of the +.Fa gid , +unless the argument +.Fa nogroup +is non-zero, in which case a +.Dv NULL +pointer is returned. +.Sh SEE ALSO +.Xr getgrgid 3 , +.Xr getpwuid 3 +.Sh HISTORY +The +.Fn user_from_uid +and +.Fn group_from_gid +functions first appeared in +.Bx 4.4 . diff --git a/gen/pwcache.c b/gen/pwcache.c new file mode 100644 index 0000000..9a5f33c --- /dev/null +++ b/gen/pwcache.c @@ -0,0 +1,158 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1989, 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 + +#include +#include +#include +#include + +#define NCACHE 64 /* power of 2 */ +#define MASK NCACHE - 1 /* bits to store with */ + +#ifdef NeXT +/* lookupd caches users, so there's no point in another cache here */ +char * +user_from_uid(uid, nouser) + uid_t uid; + int nouser; +{ + static struct passwd *pw; + + if ((pw = getpwuid(uid)) == NULL) return (NULL); + return pw->pw_name; +} +#else +char * +user_from_uid(uid, nouser) + uid_t uid; + int nouser; +{ + static struct ncache { + uid_t uid; + char name[UT_NAMESIZE + 1]; + } c_uid[NCACHE]; + static int pwopen; + static char nbuf[15]; /* 32 bits == 10 digits */ + register struct passwd *pw; + register struct ncache *cp; + + cp = c_uid + (uid & MASK); + if (cp->uid != uid || !*cp->name) { + if (pwopen == 0) { + setpassent(1); + pwopen = 1; + } + if ((pw = getpwuid(uid)) == NULL) { + if (nouser) + return (NULL); + (void)snprintf(nbuf, sizeof(nbuf), "%u", uid); + return (nbuf); + } + cp->uid = uid; + (void)strncpy(cp->name, pw->pw_name, UT_NAMESIZE); + cp->name[UT_NAMESIZE] = '\0'; + } + return (cp->name); +} +#endif + +#ifdef NeXT +/* lookupd caches groups, so there's no point in another cache here */ +char * +group_from_gid(gid, nogroup) + gid_t gid; + int nogroup; +{ + static struct group *gr; + + if ((gr = getgrgid(gid)) == NULL) return (NULL); + return gr->gr_name; +} +#else +char * +group_from_gid(gid, nogroup) + gid_t gid; + int nogroup; +{ + static struct ncache { + gid_t gid; + char name[UT_NAMESIZE + 1]; + } c_gid[NCACHE]; + static int gropen; + static char nbuf[15]; /* 32 bits == 10 digits */ + struct group *gr; + struct ncache *cp; + + cp = c_gid + (gid & MASK); + if (cp->gid != gid || !*cp->name) { + if (gropen == 0) { + setgroupent(1); + gropen = 1; + } + if ((gr = getgrgid(gid)) == NULL) { + if (nogroup) + return (NULL); + (void)snprintf(nbuf, sizeof(nbuf), "%u", gid); + return (nbuf); + } + cp->gid = gid; + (void)strncpy(cp->name, gr->gr_name, UT_NAMESIZE); + cp->name[UT_NAMESIZE] = '\0'; + } + return (cp->name); +} +#endif NeXT diff --git a/gen/raise.3 b/gen/raise.3 new file mode 100644 index 0000000..1a8fcd7 --- /dev/null +++ b/gen/raise.3 @@ -0,0 +1,77 @@ +.\" 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. +.\" +.\" @(#)raise.3 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD: src/lib/libc/gen/raise.3,v 1.7 2001/10/01 16:08:51 ru Exp $ +.\" +.Dd June 4, 1993 +.Dt RAISE 3 +.Os +.Sh NAME +.Nm raise +.Nd send a signal to the current process +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In signal.h +.Ft int +.Fn raise "int sig" +.Sh DESCRIPTION +The +.Fn raise +function sends the signal +.Fa sig +to the current process. +.Sh RETURN VALUES +.Rv -std raise +.Sh ERRORS +The +.Fn raise +function +may fail and set +.Va errno +for any of the errors specified for the +library functions +.Xr getpid 2 +and +.Xr kill 2 . +.Sh SEE ALSO +.Xr kill 2 +.Sh STANDARDS +The +.Fn raise +function +conforms to +.St -isoC . diff --git a/gen/raise.c b/gen/raise.c new file mode 100644 index 0000000..533615e --- /dev/null +++ b/gen/raise.c @@ -0,0 +1,63 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 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 +#include + +raise(s) + int s; +{ + return(kill(getpid(), s)); +} diff --git a/gen/rand48.3 b/gen/rand48.3 new file mode 100644 index 0000000..08aafec --- /dev/null +++ b/gen/rand48.3 @@ -0,0 +1,167 @@ +.\" Copyright (c) 1993 Martin Birgmeier +.\" All rights reserved. +.\" +.\" You may redistribute unmodified or modified versions of this source +.\" code provided that the above copyright notice and this and the +.\" following conditions are retained. +.\" +.\" This software is provided ``as is'', and comes with no warranties +.\" of any kind. I shall in no event be liable for anything that happens +.\" to anyone/anything when using this software. +.\" +.\" @(#)rand48.3 V1.0 MB 8 Oct 1993 +.\" $FreeBSD: src/lib/libc/gen/rand48.3,v 1.13 2001/10/01 16:08:51 ru Exp $ +.\" +.Dd October 8, 1993 +.Dt RAND48 3 +.Os +.Sh NAME +.Nm drand48 , +.Nm erand48 , +.Nm lrand48 , +.Nm nrand48 , +.Nm mrand48 , +.Nm jrand48 , +.Nm srand48 , +.Nm seed48 , +.Nm lcong48 +.Nd pseudo random number generators and initialization routines +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In stdlib.h +.Ft double +.Fn drand48 void +.Ft double +.Fn erand48 "unsigned short xseed[3]" +.Ft long +.Fn lrand48 void +.Ft long +.Fn nrand48 "unsigned short xseed[3]" +.Ft long +.Fn mrand48 void +.Ft long +.Fn jrand48 "unsigned short xseed[3]" +.Ft void +.Fn srand48 "long seed" +.Ft "unsigned short *" +.Fn seed48 "unsigned short xseed[3]" +.Ft void +.Fn lcong48 "unsigned short p[7]" +.Sh DESCRIPTION +The +.Fn rand48 +family of functions generates pseudo-random numbers using a linear +congruential algorithm working on integers 48 bits in size. +The +particular formula employed is +r(n+1) = (a * r(n) + c) mod m +where the default values are +for the multiplicand a = 0xfdeece66d = 25214903917 and +the addend c = 0xb = 11. +The modulo is always fixed at m = 2 ** 48. +r(n) is called the seed of the random number generator. +.Pp +For all the six generator routines described next, the first +computational step is to perform a single iteration of the algorithm. +.Pp +.Fn drand48 +and +.Fn erand48 +return values of type double. +The full 48 bits of r(n+1) are +loaded into the mantissa of the returned value, with the exponent set +such that the values produced lie in the interval [0.0, 1.0). +.Pp +.Fn lrand48 +and +.Fn nrand48 +return values of type long in the range +[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 mrand48 +and +.Fn jrand48 +return values of type long in the range +[-2**31, 2**31-1]. The high-order (32) bits of +r(n+1) are loaded into the returned value. +.Pp +.Fn drand48 , +.Fn lrand48 , +and +.Fn mrand48 +use an internal buffer to store r(n). For these functions +the initial value of r(0) = 0x1234abcd330e = 20017429951246. +.Pp +On the other hand, +.Fn erand48 , +.Fn nrand48 , +and +.Fn jrand48 +use a user-supplied buffer to store the seed r(n), +which consists of an array of 3 shorts, where the zeroth member +holds the least significant bits. +.Pp +All functions share the same multiplicand and addend. +.Pp +.Fn srand48 +is used to initialize the internal buffer r(n) of +.Fn drand48 , +.Fn lrand48 , +and +.Fn mrand48 +such that the 32 bits of the seed value are copied into the upper 32 bits +of r(n), with the lower 16 bits of r(n) arbitrarily being set to 0x330e. +Additionally, the constant multiplicand and addend of the algorithm are +reset to the default values given above. +.Pp +.Fn seed48 +also initializes the internal buffer r(n) of +.Fn drand48 , +.Fn lrand48 , +and +.Fn mrand48 , +but here all 48 bits of the seed can be specified in an array of 3 shorts, +where the zeroth member specifies the lowest bits. +Again, +the constant multiplicand and addend of the algorithm are +reset to the default values given above. +.Fn seed48 +returns a pointer to an array of 3 shorts which contains the old seed. +This array is statically allocated, thus its contents are lost after +each new call to +.Fn seed48 . +.Pp +Finally, +.Fn lcong48 +allows full control over the multiplicand and addend used in +.Fn drand48 , +.Fn erand48 , +.Fn lrand48 , +.Fn nrand48 , +.Fn mrand48 , +and +.Fn jrand48 , +and the seed used in +.Fn drand48 , +.Fn lrand48 , +and +.Fn mrand48 . +An array of 7 shorts is passed as parameter; the first three shorts are +used to initialize the seed; the second three are used to initialize the +multiplicand; and the last short is used to initialize the addend. +It is thus not possible to use values greater than 0xffff as the addend. +.Pp +Note that all three methods of seeding the random number generator +always also set the multiplicand and addend for any of the six +generator calls. +.Pp +For a more powerful random number generator, see +.Xr random 3 . +.Sh AUTHORS +.An Martin Birgmeier +.Sh SEE ALSO +.Xr rand 3 , +.Xr random 3 diff --git a/gen/rand48.h b/gen/rand48.h new file mode 100644 index 0000000..5b9f87d --- /dev/null +++ b/gen/rand48.h @@ -0,0 +1,30 @@ +/* + * Copyright (c) 1993 Martin Birgmeier + * All rights reserved. + * + * You may redistribute unmodified or modified versions of this source + * code provided that the above copyright notice and this and the + * following conditions are retained. + * + * This software is provided ``as is'', and comes with no warranties + * of any kind. I shall in no event be liable for anything that happens + * to anyone/anything when using this software. + */ + +#ifndef _RAND48_H_ +#define _RAND48_H_ + +#include +#include + +void _dorand48 __P((unsigned short[3])); + +#define RAND48_SEED_0 (0x330e) +#define RAND48_SEED_1 (0xabcd) +#define RAND48_SEED_2 (0x1234) +#define RAND48_MULT_0 (0xe66d) +#define RAND48_MULT_1 (0xdeec) +#define RAND48_MULT_2 (0x0005) +#define RAND48_ADD (0x000b) + +#endif /* _RAND48_H_ */ diff --git a/gen/rcmd.c b/gen/rcmd.c new file mode 100644 index 0000000..b884c9e --- /dev/null +++ b/gen/rcmd.c @@ -0,0 +1,429 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1983, 1993, 1994 + * 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[] = "@(#)rcmd.c 8.3 (Berkeley) 3/26/94"; +#endif /* LIBC_SCCS and not lint */ + +#include +#include +#include + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +int __ivaliduser __P((FILE *, u_long, const char *, const char *)); +static int __icheckhost __P((u_long, char *)); + +int +rcmd(ahost, rport, locuser, remuser, cmd, fd2p) + char **ahost; + u_short rport; + const char *locuser, *remuser, *cmd; + int *fd2p; +{ + struct hostent *hp; + struct sockaddr_in sin, from; + fd_set reads; + long oldmask; + pid_t pid; + int s, lport, timo; + char c; + + pid = getpid(); + hp = gethostbyname(*ahost); + if (hp == NULL) { + herror(*ahost); + return (-1); + } + *ahost = hp->h_name; + oldmask = sigblock(sigmask(SIGURG)); + for (timo = 1, lport = IPPORT_RESERVED - 1;;) { + s = rresvport(&lport); + if (s < 0) { + if (errno == EAGAIN) + (void)fprintf(stderr, + "rcmd: socket: All ports in use\n"); + else + (void)fprintf(stderr, "rcmd: socket: %s\n", + strerror(errno)); + sigsetmask(oldmask); + return (-1); + } + fcntl(s, F_SETOWN, pid); + sin.sin_family = hp->h_addrtype; + bcopy(hp->h_addr_list[0], &sin.sin_addr, hp->h_length); + sin.sin_port = rport; + if (connect(s, (struct sockaddr *)&sin, sizeof(sin)) >= 0) + break; + (void)close(s); + if (errno == EADDRINUSE) { + lport--; + continue; + } + if (errno == ECONNREFUSED && timo <= 16) { + (void)sleep(timo); + timo *= 2; + continue; + } + if (hp->h_addr_list[1] != NULL) { + int oerrno = errno; + + (void)fprintf(stderr, "connect to address %s: ", + inet_ntoa(sin.sin_addr)); + errno = oerrno; + perror(0); + hp->h_addr_list++; + bcopy(hp->h_addr_list[0], &sin.sin_addr, hp->h_length); + (void)fprintf(stderr, "Trying %s...\n", + inet_ntoa(sin.sin_addr)); + continue; + } + (void)fprintf(stderr, "%s: %s\n", hp->h_name, strerror(errno)); + sigsetmask(oldmask); + return (-1); + } + lport--; + if (fd2p == 0) { + write(s, "", 1); + lport = 0; + } else { + char num[8]; + int s2 = rresvport(&lport), s3; + int len = sizeof(from); + + if (s2 < 0) + goto bad; + listen(s2, 1); + (void)snprintf(num, sizeof(num), "%d", lport); + if (write(s, num, strlen(num)+1) != strlen(num)+1) { + (void)fprintf(stderr, + "rcmd: write (setting up stderr): %s\n", + strerror(errno)); + (void)close(s2); + goto bad; + } + FD_ZERO(&reads); + FD_SET(s, &reads); + FD_SET(s2, &reads); + errno = 0; + if (select(32, &reads, 0, 0, 0) < 1 || !FD_ISSET(s2, &reads)) { + if (errno != 0) + (void)fprintf(stderr, + "rcmd: select (setting up stderr): %s\n", + strerror(errno)); + else + (void)fprintf(stderr, + "select: protocol failure in circuit setup\n"); + (void)close(s2); + goto bad; + } + s3 = accept(s2, (struct sockaddr *)&from, &len); + (void)close(s2); + if (s3 < 0) { + (void)fprintf(stderr, + "rcmd: accept: %s\n", strerror(errno)); + lport = 0; + goto bad; + } + *fd2p = s3; + from.sin_port = ntohs((u_short)from.sin_port); + if (from.sin_family != AF_INET || + from.sin_port >= IPPORT_RESERVED || + from.sin_port < IPPORT_RESERVED / 2) { + (void)fprintf(stderr, + "socket: protocol failure in circuit setup.\n"); + goto bad2; + } + } + (void)write(s, locuser, strlen(locuser)+1); + (void)write(s, remuser, strlen(remuser)+1); + (void)write(s, cmd, strlen(cmd)+1); + if (read(s, &c, 1) != 1) { + (void)fprintf(stderr, + "rcmd: %s: %s\n", *ahost, strerror(errno)); + goto bad2; + } + if (c != 0) { + while (read(s, &c, 1) == 1) { + (void)write(STDERR_FILENO, &c, 1); + if (c == '\n') + break; + } + goto bad2; + } + sigsetmask(oldmask); + return (s); +bad2: + if (lport) + (void)close(*fd2p); +bad: + (void)close(s); + sigsetmask(oldmask); + return (-1); +} + +int +rresvport(alport) + int *alport; +{ + struct sockaddr_in sin; + int s; + + sin.sin_family = AF_INET; + sin.sin_addr.s_addr = INADDR_ANY; + s = socket(AF_INET, SOCK_STREAM, 0); + if (s < 0) + return (-1); + for (;;) { + sin.sin_port = htons((u_short)*alport); + if (bind(s, (struct sockaddr *)&sin, sizeof(sin)) >= 0) + return (s); + if (errno != EADDRINUSE) { + (void)close(s); + return (-1); + } + (*alport)--; + if (*alport == IPPORT_RESERVED/2) { + (void)close(s); + errno = EAGAIN; /* close */ + return (-1); + } + } +} + +int __check_rhosts_file = 1; +char *__rcmd_errstr; + +int +ruserok(rhost, superuser, ruser, luser) + const char *rhost, *ruser, *luser; + int superuser; +{ + struct hostent *hp; + u_long addr; + char **ap; + + if ((hp = gethostbyname(rhost)) == NULL) + return (-1); + for (ap = hp->h_addr_list; *ap; ++ap) { + bcopy(*ap, &addr, sizeof(addr)); + if (iruserok(addr, superuser, ruser, luser) == 0) + return (0); + } + return (-1); +} + +/* + * New .rhosts strategy: We are passed an ip address. We spin through + * hosts.equiv and .rhosts looking for a match. When the .rhosts only + * has ip addresses, we don't have to trust a nameserver. When it + * contains hostnames, we spin through the list of addresses the nameserver + * gives us and look for a match. + * + * Returns 0 if ok, -1 if not ok. + */ +int +iruserok(raddr, superuser, ruser, luser) + u_long raddr; + int superuser; + const char *ruser, *luser; +{ + register char *cp; + struct stat sbuf; + struct passwd *pwd; + FILE *hostf; + uid_t uid; + int first; + char pbuf[MAXPATHLEN]; + + first = 1; + hostf = superuser ? NULL : fopen(_PATH_HEQUIV, "r"); +again: + if (hostf) { + if (__ivaliduser(hostf, raddr, luser, ruser) == 0) { + (void)fclose(hostf); + return (0); + } + (void)fclose(hostf); + } + if (first == 1 && (__check_rhosts_file || superuser)) { + first = 0; + if ((pwd = getpwnam(luser)) == NULL) + return (-1); + (void)strcpy(pbuf, pwd->pw_dir); + (void)strcat(pbuf, "/.rhosts"); + + /* + * Change effective uid while opening .rhosts. If root and + * reading an NFS mounted file system, can't read files that + * are protected read/write owner only. + */ + uid = geteuid(); + (void)seteuid(pwd->pw_uid); + hostf = fopen(pbuf, "r"); + (void)seteuid(uid); + + if (hostf == NULL) + return (-1); + /* + * If not a regular file, or is owned by someone other than + * user or root or if writeable by anyone but the owner, quit. + */ + cp = NULL; + if (lstat(pbuf, &sbuf) < 0) + cp = ".rhosts lstat failed"; + else if (!S_ISREG(sbuf.st_mode)) + cp = ".rhosts not regular file"; + else if (fstat(fileno(hostf), &sbuf) < 0) + cp = ".rhosts fstat failed"; + else if (sbuf.st_uid && sbuf.st_uid != pwd->pw_uid) + cp = "bad .rhosts owner"; + else if (sbuf.st_mode & (S_IWGRP|S_IWOTH)) + cp = ".rhosts writeable by other than owner"; + /* If there were any problems, quit. */ + if (cp) { + __rcmd_errstr = cp; + (void)fclose(hostf); + return (-1); + } + goto again; + } + return (-1); +} + +/* + * XXX + * Don't make static, used by lpd(8). + * + * Returns 0 if ok, -1 if not ok. + */ +int +__ivaliduser(hostf, raddr, luser, ruser) + FILE *hostf; + u_long raddr; + const char *luser, *ruser; +{ + register char *user, *p; + int ch; + char buf[MAXHOSTNAMELEN + 128]; /* host + login */ + + while (fgets(buf, sizeof(buf), hostf)) { + p = buf; + /* Skip lines that are too long. */ + if (strchr(p, '\n') == NULL) { + while ((ch = getc(hostf)) != '\n' && ch != EOF); + continue; + } + while (*p != '\n' && *p != ' ' && *p != '\t' && *p != '\0') { + *p = isupper(*p) ? tolower(*p) : *p; + p++; + } + if (*p == ' ' || *p == '\t') { + *p++ = '\0'; + while (*p == ' ' || *p == '\t') + p++; + user = p; + while (*p != '\n' && *p != ' ' && + *p != '\t' && *p != '\0') + p++; + } else + user = p; + *p = '\0'; + if (__icheckhost(raddr, buf) && + strcmp(ruser, *user ? user : luser) == 0) { + return (0); + } + } + return (-1); +} + +/* + * Returns "true" if match, 0 if no match. + */ +static int +__icheckhost(raddr, lhost) + u_long raddr; + register char *lhost; +{ + register struct hostent *hp; + register u_long laddr; + register char **pp; + + /* Try for raw ip address first. */ + if (isdigit(*lhost) && (long)(laddr = inet_addr(lhost)) != -1) + return (raddr == laddr); + + /* Better be a hostname. */ + if ((hp = gethostbyname(lhost)) == NULL) + return (0); + + /* Spin through ip addresses. */ + for (pp = hp->h_addr_list; *pp; ++pp) + if (!bcmp(&raddr, *pp, sizeof(u_long))) + return (1); + + /* No match. */ + return (0); +} diff --git a/gen/readdir.c b/gen/readdir.c new file mode 100644 index 0000000..fd86c9e --- /dev/null +++ b/gen/readdir.c @@ -0,0 +1,93 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1983, 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 +#include + +/* + * get next entry in a directory. + */ +struct dirent * +readdir(dirp) + register DIR *dirp; +{ + register struct dirent *dp; + + for (;;) { + if (dirp->dd_loc >= dirp->dd_size) { + if (dirp->dd_flags & __DTF_READALL) + return (NULL); + dirp->dd_loc = 0; + } + if (dirp->dd_loc == 0 && !(dirp->dd_flags & __DTF_READALL)) { + dirp->dd_size = getdirentries(dirp->dd_fd, + dirp->dd_buf, dirp->dd_len, &dirp->dd_seek); + if (dirp->dd_size <= 0) + return (NULL); + } + dp = (struct dirent *)(dirp->dd_buf + dirp->dd_loc); + if ((int)dp & 03) /* bogus pointer check */ + return (NULL); + if (dp->d_reclen <= 0 || + dp->d_reclen > dirp->dd_len + 1 - dirp->dd_loc) + return (NULL); + dirp->dd_loc += dp->d_reclen; + if (dp->d_ino == 0) + continue; + if (dp->d_type == DT_WHT && (dirp->dd_flags & DTF_HIDEW)) + continue; + return (dp); + } +} diff --git a/gen/readdir_r.c b/gen/readdir_r.c new file mode 100644 index 0000000..8e19ccc --- /dev/null +++ b/gen/readdir_r.c @@ -0,0 +1,51 @@ +#include +#include +#include + +/* + * Synopsis: + * dir_table is a global static array of pthread mutexes. The array is NMUTEXES + * in length (NMUTEXES * sizeof(pthread_mutex_t)). + * + * Whenever a call to readdir_r is made, the element in the array indexed by the + * modulus of the file descriptor associated with dirp is locked, and readdir is + * called on dirp. The result is returned in readdir_r semantics and the + * element in dir_table is unlocked. + */ + +static pthread_mutex_t dir_table[] = { + PTHREAD_MUTEX_INITIALIZER, + PTHREAD_MUTEX_INITIALIZER, + PTHREAD_MUTEX_INITIALIZER, + PTHREAD_MUTEX_INITIALIZER, + PTHREAD_MUTEX_INITIALIZER, + PTHREAD_MUTEX_INITIALIZER, + PTHREAD_MUTEX_INITIALIZER, + PTHREAD_MUTEX_INITIALIZER +#define NMUTEXES 8 +}; + +int readdir_r(DIR *dirp, struct dirent *entry, struct dirent **result) +{ + int ret; + int mindex = dirp->dd_fd % NMUTEXES; + struct dirent *tmpdp; + + pthread_mutex_lock(&dir_table[mindex]); + + tmpdp = readdir(dirp); + if( tmpdp == NULL ) { + *result = NULL; + ret = errno; + pthread_mutex_unlock(&dir_table[mindex]); + return ret; + } + + memcpy(entry, tmpdp, sizeof(struct dirent)); + *result = entry; + + pthread_mutex_unlock(&dir_table[mindex]); + return 0; +} + + diff --git a/gen/rewinddir.c b/gen/rewinddir.c new file mode 100644 index 0000000..0829a23 --- /dev/null +++ b/gen/rewinddir.c @@ -0,0 +1,66 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 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 +#include + +void +rewinddir(dirp) + DIR *dirp; +{ + + _seekdir(dirp, dirp->dd_rewind); + dirp->dd_rewind = telldir(dirp); +} diff --git a/gen/rfork_thread.3 b/gen/rfork_thread.3 new file mode 100644 index 0000000..3d78998 --- /dev/null +++ b/gen/rfork_thread.3 @@ -0,0 +1,77 @@ +.\" +.\" Copyright (c) 2000 Peter Wemm +.\" 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/rfork_thread.3,v 1.5 2001/10/01 16:08:51 ru Exp $ +.\" +.Dd July 29, 2000 +.Dt RFORK_THREAD 3 +.Os +.Sh NAME +.Nm rfork_thread +.Nd create a rfork-based process thread +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In unistd.h +.Ft int +.Fn rfork_thread "int flags" "void *stack" "int (*func)(void *arg)" "void *arg" +.Sh DESCRIPTION +.Fn rfork_thread +is a helper function for +.Xr rfork 2 . +It arranges for a new process to be created and the child process will +call the specified function with the specified argument, while running on +the supplied stack. +.Pp +Using this function should avoid the need to implement complex stack +swap code. +.Sh RETURN VALUES +Upon successful completion, +.Fn rfork_thread +returns the process ID of the child process to the parent process. +Otherwise, a value of -1 is returned +to the parent process, no child process is created, and the global +variable +.Va errno +is set to indicate the error. +.Pp +The child process context is not aware of a return from the +.Fn rfork_thread +function as it begins executing directly with the supplied function. +.Sh ERRORS +See +.Xr rfork 2 +for error return codes. +.Sh SEE ALSO +.Xr fork 2 , +.Xr intro 2 , +.Xr minherit 2 , +.Xr rfork 2 , +.Xr vfork 2 +.Sh HISTORY +The +.Fn rfork_thread +function call first appeared in +.Fx 4.3 . diff --git a/gen/scalable_malloc.c b/gen/scalable_malloc.c new file mode 100644 index 0000000..2bd6bcf --- /dev/null +++ b/gen/scalable_malloc.c @@ -0,0 +1,1707 @@ +/* + * Copyright (c) 1999 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@ + */ + +/* Author: Bertrand Serlet, August 1999 */ + +#import "scalable_malloc.h" + +#define __POSIX_LIB__ +#import +#import // for spin lock +#import +#include + +/********************* DEFINITIONS ************************/ + +static unsigned vm_page_shift = 0; // guaranteed to be intialized by zone creation + +#define DEBUG_MALLOC 0 // set to one to debug malloc itself +#define DEBUG_CLIENT 0 // set to one to help debug a nasty memory smasher + +#if DEBUG_MALLOC +#warning DEBUG ENABLED +#define INLINE +#else +#define INLINE inline +#endif + +#define CHECK_REGIONS (1 << 31) + +#define VM_COPY_THRESHOLD (40 * 1024) + // When all memory is touched after a copy, vm_copy() is always a lose + // But if the memory is only read, vm_copy() wins over memmove() at 3 or 4 pages (on a G3/300MHz) + // This must be larger than LARGE_THRESHOLD + +#define KILL_THRESHOLD (32 * 1024) + +#define LARGE_THRESHOLD (3 * vm_page_size) // at or above this use "large" + +#define SHIFT_QUANTUM 4 // Required for AltiVec +#define QUANTUM (1 << SHIFT_QUANTUM) // allocation quantum +#define MIN_BLOCK 1 // minimum size, in QUANTUM multiples + +/* The header of a small block in use contains its size (expressed as multiples of QUANTUM, and header included), or 0; +If 0 then the block is either free (in which case the size is directly at the block itself), or the last block (indicated by either being beyond range, or having 0 in the block itself) */ + +#define PTR_HEADER_SIZE (sizeof(msize_t)) +#define FOLLOWING_PTR(ptr,msize) (((char *)(ptr)) + ((msize) << SHIFT_QUANTUM)) +#define PREVIOUS_MSIZE(ptr) ((msize_t *)(ptr))[-2] + +#define THIS_FREE 0x8000 // indicates this block is free +#define PREV_FREE 0x4000 // indicates previous block is free +#define MSIZE_FLAGS_FOR_PTR(ptr) (((msize_t *)(ptr))[-1]) + +#define REGION_SIZE (1 << (16 - 2 + SHIFT_QUANTUM)) // since we only have 16 bits for msize_t, and 1 bit is taken by THIS_FREE, and 1 by PREV_FREE + +#define INITIAL_NUM_REGIONS 8 // must always be at least 2 to always have 1 slot empty + +#define CHECKSUM_MAGIC 0x357B + +#define PROTECT_SMALL 0 // Should be 0: 1 is too slow for normal use + +#define MAX_RECORDER_BUFFER 256 + +#define MAX_GRAIN 128 + +typedef unsigned short msize_t; // a size in multiples of SHIFT_QUANTUM + +typedef struct { + unsigned checksum; + void *previous; + void *next; +} free_list_t; + +typedef struct { + unsigned address_and_num_pages; + // this type represents both an address and a number of pages + // the low bits are the number of pages + // the high bits are the address + // note that the exact number of bits used for depends on the page size + // also, this cannot represent pointers larger than 1 << (vm_page_shift * 2) +} compact_range_t; + +typedef vm_address_t region_t; + +typedef compact_range_t large_entry_t; + +typedef vm_range_t huge_entry_t; + +typedef unsigned short grain_t; + +typedef struct { + malloc_zone_t basic_zone; + pthread_lock_t lock; + unsigned debug_flags; + void *log_address; + + /* Regions for small objects */ + unsigned num_regions; + region_t *regions; + // this array is always created with 1 extra slot to be able to add a region without taking memory right away + unsigned last_region_hit; + free_list_t *free_list[MAX_GRAIN]; + unsigned num_bytes_free_in_last_region; // these bytes are cleared + unsigned num_small_objects; + unsigned num_bytes_in_small_objects; + + /* large objects: vm_page_shift <= log2(size) < 2 *vm_page_shift */ + unsigned num_large_objects_in_use; + unsigned num_large_entries; + unsigned num_bytes_in_large_objects; + large_entry_t *large_entries; + // large_entries are hashed by location + // large_entries that are 0 should be discarded + + /* huge objects: log2(size) >= 2 *vm_page_shift */ + unsigned num_bytes_in_huge_objects; + unsigned num_huge_entries; + huge_entry_t *huge_entries; +} szone_t; + +static void *szone_malloc(szone_t *szone, size_t size); +static void *szone_valloc(szone_t *szone, size_t size); +static INLINE void *szone_malloc_should_clear(szone_t *szone, size_t size, boolean_t cleared_requested); +static void szone_free(szone_t *szone, void *ptr); +static size_t szone_good_size(szone_t *szone, size_t size); +static boolean_t szone_check_all(szone_t *szone, const char *function); +static void szone_print(szone_t *szone, boolean_t verbose); +static INLINE region_t *region_for_ptr_no_lock(szone_t *szone, const void *ptr); +static vm_range_t large_free_no_lock(szone_t *szone, large_entry_t *entry); + +#define LOG(szone,ptr) (szone->log_address && (szone->num_small_objects > 8) && (((unsigned)szone->log_address == -1) || (szone->log_address == (void *)(ptr)))) + +/********************* ACCESSOR MACROS ************************/ + +#define SZONE_LOCK(szone) LOCK(szone->lock) +#define SZONE_UNLOCK(szone) UNLOCK(szone->lock) + +#define CHECK(szone,fun) if ((szone)->debug_flags & CHECK_REGIONS) szone_check_all(szone, fun) + +#define REGION_ADDRESS(region) (region) +#define REGION_END(region) (region+REGION_SIZE) + +#define LARGE_ENTRY_ADDRESS(entry) (((entry).address_and_num_pages >> vm_page_shift) << vm_page_shift) +#define LARGE_ENTRY_NUM_PAGES(entry) ((entry).address_and_num_pages & ((1 << vm_page_shift) - 1)) +#define LARGE_ENTRY_SIZE(entry) (LARGE_ENTRY_NUM_PAGES(entry) << vm_page_shift) +#define LARGE_ENTRY_MATCHES(entry,ptr) (!(((entry).address_and_num_pages - (unsigned)(ptr)) >> vm_page_shift)) +#define LARGE_ENTRY_IS_EMPTY(entry) (!((entry).address_and_num_pages)) + +/********************* VERY LOW LEVEL UTILITIES ************************/ + +static void szone_error(szone_t *szone, const char *msg, const void *ptr) { + if (szone) SZONE_UNLOCK(szone); + if (ptr) { + malloc_printf("*** malloc[%d]: error for object %p: %s\n", getpid(), ptr, msg); +#if DEBUG_MALLOC + szone_print(szone, 1); +#endif + } else { + malloc_printf("*** malloc[%d]: error: %s\n", getpid(), msg); + } +#if DEBUG_CLIENT + malloc_printf("*** Sleeping to help debug\n"); + sleep(3600); // to help debug +#endif +} + +static void protect(szone_t *szone, vm_address_t address, vm_size_t size, unsigned protection, unsigned debug_flags) { + kern_return_t err; + if (!(debug_flags & SCALABLE_MALLOC_DONT_PROTECT_PRELUDE)) { + err = vm_protect(mach_task_self(), address - vm_page_size, vm_page_size, 0, protection); + if (err) malloc_printf("*** malloc[%d]: Can't protect(%x) region for prelude guard page at 0x%x\n", getpid(), protection, address - vm_page_size); + } + if (!(debug_flags & SCALABLE_MALLOC_DONT_PROTECT_POSTLUDE)) { + err = vm_protect(mach_task_self(), (vm_address_t)(address + size), vm_page_size, 0, protection); + if (err) malloc_printf("*** malloc[%d]: Can't protect(%x) region for postlude guard page at 0x%x\n", getpid(), protection, address + size); + } +} + +static vm_address_t allocate_pages(szone_t *szone, size_t size, unsigned debug_flags, int vm_page_label) { + kern_return_t err; + vm_address_t addr; + boolean_t add_guard_pages = debug_flags & SCALABLE_MALLOC_ADD_GUARD_PAGES; + size_t allocation_size = round_page(size); + if (!allocation_size) allocation_size = vm_page_size; + if (add_guard_pages) allocation_size += 2 * vm_page_size; + err = vm_allocate(mach_task_self(), &addr, allocation_size, vm_page_label | 1); + if (err) { + malloc_printf("*** malloc: vm_allocate(size=%d) failed with %d\n", size, err); + szone_error(szone, "Can't allocate region", NULL); + return NULL; + } + if (add_guard_pages) { + addr += vm_page_size; + protect(szone, addr, size, 0, debug_flags); + } + return addr; +} + +static void deallocate_pages(szone_t *szone, vm_address_t addr, size_t size, unsigned debug_flags) { + kern_return_t err; + boolean_t add_guard_pages = debug_flags & SCALABLE_MALLOC_ADD_GUARD_PAGES; + if (add_guard_pages) { + addr -= vm_page_size; + size += 2 * vm_page_size; + } + err = vm_deallocate(mach_task_self(), addr, size); + if (err) { + szone_error(szone, "Can't deallocate_pages region", (void *)addr); + } +} + +static kern_return_t _szone_default_reader(task_t task, vm_address_t address, vm_size_t size, void **ptr) { + *ptr = (void *)address; + return 0; +} + +/********************* FREE LIST UTILITIES ************************/ + +static INLINE grain_t grain_for_msize(szone_t *szone, msize_t msize) { + // assumes msize >= MIN_BLOCK +#if DEBUG_MALLOC + if (msize < MIN_BLOCK) { + szone_error(szone, "grain_for_msize: msize too small", NULL); + } +#endif + return (msize < MAX_GRAIN + MIN_BLOCK) ? msize - MIN_BLOCK : MAX_GRAIN - 1; +} + +static INLINE msize_t msize_for_grain(szone_t *szone, grain_t grain) { + // 0 if multiple sizes + return (grain < MAX_GRAIN - 1) ? grain + MIN_BLOCK : 0; +} + +static INLINE void free_list_checksum(szone_t *szone, free_list_t *ptr) { + // We always checksum, as testing whether to do it (based on szone->debug_flags) is as fast as doing it + if (ptr->checksum != (((unsigned)ptr->previous) ^ ((unsigned)ptr->next) ^ CHECKSUM_MAGIC)) { + szone_error(szone, "Incorrect checksum for freed object - object was probably modified after being freed; break at szone_error", ptr); + } +} + +static INLINE void free_list_set_checksum(szone_t *szone, free_list_t *ptr) { + // We always set checksum, as testing whether to do it (based on szone->debug_flags) is slower than just doing it + ptr->checksum = ((unsigned)ptr->previous) ^ ((unsigned)ptr->next) ^ CHECKSUM_MAGIC; +} + +static void free_list_add_ptr(szone_t *szone, void *ptr, msize_t msize) { + // Adds an item to the proper free list + // Also marks the header of the block properly + grain_t grain = grain_for_msize(szone, msize); + free_list_t *free_ptr = ptr; + free_list_t *free_head = szone->free_list[grain]; + msize_t *follower = (msize_t *)FOLLOWING_PTR(ptr, msize); +#if DEBUG_MALLOC + if (LOG(szone,ptr)) malloc_printf("In free_list_add_ptr(), ptr=%p, msize=%d\n", ptr, msize); + if (((unsigned)ptr) & (QUANTUM - 1)) { + szone_error(szone, "free_list_add_ptr: Unaligned ptr", ptr); + } +#endif + MSIZE_FLAGS_FOR_PTR(ptr) = msize | THIS_FREE; + if (free_head) { + free_list_checksum(szone, free_head); +#if DEBUG_MALLOC + if (free_head->previous) { + malloc_printf("ptr=%p grain=%d free_head=%p previous=%p\n", ptr, grain, free_head, free_head->previous); + szone_error(szone, "free_list_add_ptr: Internal invariant broken (free_head->previous)", ptr); + } + if (!(MSIZE_FLAGS_FOR_PTR(free_head) & THIS_FREE)) { + malloc_printf("ptr=%p grain=%d free_head=%p\n", ptr, grain, free_head); + szone_error(szone, "free_list_add_ptr: Internal invariant broken (free_head is not a free pointer)", ptr); + } + if ((grain != MAX_GRAIN-1) && (MSIZE_FLAGS_FOR_PTR(free_head) != (THIS_FREE | msize))) { + malloc_printf("ptr=%p grain=%d free_head=%p previous_msize=%d\n", ptr, grain, free_head, MSIZE_FLAGS_FOR_PTR(free_head)); + szone_error(szone, "free_list_add_ptr: Internal invariant broken (incorrect msize)", ptr); + } +#endif + free_head->previous = free_ptr; + free_list_set_checksum(szone, free_head); + } + free_ptr->previous = NULL; + free_ptr->next = free_head; + free_list_set_checksum(szone, free_ptr); + szone->free_list[grain] = free_ptr; + // mark the end of this block + PREVIOUS_MSIZE(follower) = msize; + MSIZE_FLAGS_FOR_PTR(follower) |= PREV_FREE; +} + +static void free_list_remove_ptr(szone_t *szone, void *ptr, msize_t msize) { + // Removes item in the proper free list + // msize could be read, but all callers have it so we pass it in + grain_t grain = grain_for_msize(szone, msize); + free_list_t *free_ptr = ptr; + free_list_t *next = free_ptr->next; + free_list_t *previous = free_ptr->previous; +#if DEBUG_MALLOC + if (LOG(szone,ptr)) malloc_printf("In free_list_remove_ptr(), ptr=%p, msize=%d\n", ptr, msize); +#endif + free_list_checksum(szone, free_ptr); + if (!previous) { +#if DEBUG_MALLOC + if (szone->free_list[grain] != ptr) { + malloc_printf("ptr=%p grain=%d msize=%d szone->free_list[grain]=%p\n", ptr, grain, msize, szone->free_list[grain]); + szone_error(szone, "free_list_remove_ptr: Internal invariant broken (szone->free_list[grain])", ptr); + return; + } +#endif + szone->free_list[grain] = next; + } else { + previous->next = next; + free_list_set_checksum(szone, previous); + } + if (next) { + next->previous = previous; + free_list_set_checksum(szone, next); + } + MSIZE_FLAGS_FOR_PTR(FOLLOWING_PTR(ptr, msize)) &= ~ PREV_FREE; +} + +static boolean_t free_list_check(szone_t *szone, grain_t grain) { + unsigned count = 0; + free_list_t *ptr = szone->free_list[grain]; + free_list_t *previous = NULL; + while (ptr) { + msize_t msize_and_free = MSIZE_FLAGS_FOR_PTR(ptr); + count++; + if (!(msize_and_free & THIS_FREE)) { + malloc_printf("*** malloc[%d]: In-use ptr in free list grain=%d count=%d ptr=%p\n", getpid(), grain, count, ptr); + return 0; + } + if (((unsigned)ptr) & (QUANTUM - 1)) { + malloc_printf("*** malloc[%d]: Unaligned ptr in free list grain=%d count=%d ptr=%p\n", getpid(), grain, count, ptr); + return 0; + } + if (!region_for_ptr_no_lock(szone, ptr)) { + malloc_printf("*** malloc[%d]: Ptr not in szone grain=%d count=%d ptr=%p\n", getpid(), grain, count, ptr); + return 0; + } + free_list_checksum(szone, ptr); + if (ptr->previous != previous) { + malloc_printf("*** malloc[%d]: Previous incorrectly set grain=%d count=%d ptr=%p\n", getpid(), grain, count, ptr); + return 0; + } + if ((grain != MAX_GRAIN-1) && (msize_and_free != (msize_for_grain(szone, grain) | THIS_FREE))) { + malloc_printf("*** malloc[%d]: Incorrect msize for grain=%d count=%d ptr=%p msize=%d\n", getpid(), grain, count, ptr, msize_and_free); + return 0; + } + previous = ptr; + ptr = ptr->next; + } + return 1; +} + +/********************* SMALL BLOCKS MANAGEMENT ************************/ + +static INLINE region_t *region_for_ptr_no_lock(szone_t *szone, const void *ptr) { + region_t *first_region = szone->regions; + region_t *region = first_region + szone->last_region_hit; + region_t this = *region; + if ((unsigned)ptr - (unsigned)REGION_ADDRESS(this) < (unsigned)REGION_SIZE) { + return region; + } else { + // We iterate in reverse order becase last regions are more likely + region = first_region + szone->num_regions; + while (region != first_region) { + this = *(--region); + if ((unsigned)ptr - (unsigned)REGION_ADDRESS(this) < (unsigned)REGION_SIZE) { + szone->last_region_hit = region - first_region; + return region; + } + } + return NULL; + } +} + +static INLINE void small_free_no_lock(szone_t *szone, region_t *region, void *ptr, msize_t msize_and_free) { + msize_t msize = msize_and_free & ~ PREV_FREE; + size_t original_size = msize << SHIFT_QUANTUM; + void *next_block = ((char *)ptr + original_size); + msize_t next_msize_and_free; +#if DEBUG_MALLOC + if (LOG(szone,ptr)) malloc_printf("In small_free_no_lock(), ptr=%p, msize=%d\n", ptr, msize); + if (msize < MIN_BLOCK) { + malloc_printf("In small_free_no_lock(), ptr=%p, msize=%d\n", ptr, msize); + szone_error(szone, "Trying to free small block that is too small", ptr); + } +#endif + if (((vm_address_t)next_block < REGION_END(*region)) && ((next_msize_and_free = MSIZE_FLAGS_FOR_PTR(next_block)) & THIS_FREE)) { + // If the next block is free, we coalesce + msize_t next_msize = next_msize_and_free & ~THIS_FREE; + if (LOG(szone,ptr)) malloc_printf("In small_free_no_lock(), for ptr=%p, msize=%d coalesced next block=%p next_msize=%d\n", ptr, msize, next_block, next_msize); + free_list_remove_ptr(szone, next_block, next_msize); + msize += next_msize; + } + // Let's try to coalesce backwards now + if (msize_and_free & PREV_FREE) { + msize_t previous_msize = PREVIOUS_MSIZE(ptr); + void *previous = ptr - (previous_msize << SHIFT_QUANTUM); +#if DEBUG_MALLOC + if (LOG(szone,previous)) malloc_printf("In small_free_no_lock(), coalesced backwards for %p previous=%p, msize=%d\n", ptr, previous, previous_msize); + if (!previous_msize || (previous_msize >= (((vm_address_t)ptr - REGION_ADDRESS(*region)) >> SHIFT_QUANTUM))) { + szone_error(szone, "Invariant 1 broken when coalescing backwards", ptr); + } + if (MSIZE_FLAGS_FOR_PTR(previous) != (previous_msize | THIS_FREE)) { + malloc_printf("previous=%p its_msize_and_free=0x%x previous_msize=%d\n", previous, MSIZE_FLAGS_FOR_PTR(previous), previous_msize); + szone_error(szone, "Invariant 3 broken when coalescing backwards", ptr); + } +#endif + free_list_remove_ptr(szone, previous, previous_msize); + ptr = previous; + msize += previous_msize; +#if DEBUG_MALLOC + if (msize & PREV_FREE) { + malloc_printf("In small_free_no_lock(), after coalescing with previous ptr=%p, msize=%d previous_msize=%d\n", ptr, msize, previous_msize); + szone_error(szone, "Incorrect coalescing", ptr); + } +#endif + } + if (szone->debug_flags & SCALABLE_MALLOC_DO_SCRIBBLE) { + if (!msize) { + szone_error(szone, "Incorrect size information - block header was damaged", ptr); + } else { + memset(ptr, 0x55, (msize << SHIFT_QUANTUM) - PTR_HEADER_SIZE); + } + } + free_list_add_ptr(szone, ptr, msize); + CHECK(szone, "small_free_no_lock: added to free list"); + szone->num_small_objects--; + szone->num_bytes_in_small_objects -= original_size; // we use original_size and not msize to avoid double counting the coalesced blocks +} + +static void *small_malloc_from_region_no_lock(szone_t *szone, msize_t msize) { + // Allocates from the last region or a freshly allocated region + region_t *last_region = szone->regions + szone->num_regions - 1; + vm_address_t new_address; + void *ptr; + msize_t msize_and_free; + unsigned region_capacity; + ptr = (void *)(REGION_END(*last_region) - szone->num_bytes_free_in_last_region + PTR_HEADER_SIZE); +#if DEBUG_MALLOC + if (((vm_address_t)ptr) & (QUANTUM - 1)) { + szone_error(szone, "Invariant broken while using end of region", ptr); + } +#endif + msize_and_free = MSIZE_FLAGS_FOR_PTR(ptr); +#if DEBUG_MALLOC + if (msize_and_free != PREV_FREE && msize_and_free != 0) { + malloc_printf("*** malloc[%d]: msize_and_free = %d\n", getpid(), msize_and_free); + szone_error(szone, "Invariant broken when allocating at end of zone", ptr); + } +#endif + // In order to make sure we don't have 2 free pointers following themselves, if the last item is a free item, we combine it and clear it + if (msize_and_free == PREV_FREE) { + msize_t previous_msize = PREVIOUS_MSIZE(ptr); + void *previous = ptr - (previous_msize << SHIFT_QUANTUM); +#if DEBUG_MALLOC + if (LOG(szone, ptr)) malloc_printf("Combining last with free space at %p\n", ptr); + if (!previous_msize || (previous_msize >= (((vm_address_t)ptr - REGION_ADDRESS(*last_region)) >> SHIFT_QUANTUM)) || (MSIZE_FLAGS_FOR_PTR(previous) != (previous_msize | THIS_FREE))) { + szone_error(szone, "Invariant broken when coalescing backwards at end of zone", ptr); + } +#endif + free_list_remove_ptr(szone, previous, previous_msize); + szone->num_bytes_free_in_last_region += previous_msize << SHIFT_QUANTUM; + memset(previous, 0, previous_msize << SHIFT_QUANTUM); + MSIZE_FLAGS_FOR_PTR(previous) = 0; + ptr = previous; + } + // first try at the end of the last region + CHECK(szone, __PRETTY_FUNCTION__); + if (szone->num_bytes_free_in_last_region >= (msize << SHIFT_QUANTUM)) { + szone->num_bytes_free_in_last_region -= (msize << SHIFT_QUANTUM); + szone->num_small_objects++; + szone->num_bytes_in_small_objects += msize << SHIFT_QUANTUM; + MSIZE_FLAGS_FOR_PTR(ptr) = msize; + return ptr; + } + // time to create a new region + new_address = allocate_pages(szone, REGION_SIZE, 0, VM_MAKE_TAG(VM_MEMORY_MALLOC_SMALL)); + if (!new_address) { + // out of memory! + return NULL; + } + // let's prepare to free the remnants of last_region + if (szone->num_bytes_free_in_last_region >= QUANTUM) { + msize_t this_msize = szone->num_bytes_free_in_last_region >> SHIFT_QUANTUM; + // malloc_printf("Entering last block %p size=%d\n", ptr, this_msize << SHIFT_QUANTUM); + if (this_msize >= MIN_BLOCK) { + free_list_add_ptr(szone, ptr, this_msize); + } else { + // malloc_printf("Leaking last block at %p\n", ptr); + } + szone->num_bytes_free_in_last_region -= this_msize << SHIFT_QUANTUM; // to avoid coming back here + } + last_region[1] = new_address; + szone->num_regions++; + szone->num_bytes_free_in_last_region = REGION_SIZE - QUANTUM + PTR_HEADER_SIZE - (msize << SHIFT_QUANTUM); + ptr = (void *)(new_address + QUANTUM); // waste the first bytes + region_capacity = (MSIZE_FLAGS_FOR_PTR(szone->regions) * QUANTUM - PTR_HEADER_SIZE) / sizeof(region_t); + if (szone->num_regions >= region_capacity) { + unsigned new_capacity = region_capacity * 2 + 1; + msize_t new_msize = (new_capacity * sizeof(region_t) + PTR_HEADER_SIZE + QUANTUM - 1) / QUANTUM; + region_t *new_regions = ptr; + // malloc_printf("Now %d regions growing regions %p to %d\n", szone->num_regions, szone->regions, new_capacity); + MSIZE_FLAGS_FOR_PTR(new_regions) = new_msize; + szone->num_small_objects++; + szone->num_bytes_in_small_objects += new_msize << SHIFT_QUANTUM; + memcpy(new_regions, szone->regions, szone->num_regions * sizeof(region_t)); + // We intentionally leak the previous regions pointer to avoid multi-threading crashes if another thread was reading it (unlocked) while we are changing it + // Given that in practise the number of regions is typically a handful, this should not be a big deal + szone->regions = new_regions; + ptr += (new_msize << SHIFT_QUANTUM); + szone->num_bytes_free_in_last_region -= (new_msize << SHIFT_QUANTUM); + // malloc_printf("Regions is now %p next ptr is %p\n", szone->regions, ptr); + } + szone->num_small_objects++; + szone->num_bytes_in_small_objects += msize << SHIFT_QUANTUM; + MSIZE_FLAGS_FOR_PTR(ptr) = msize; + return ptr; +} + +static boolean_t szone_check_region(szone_t *szone, region_t *region) { + void *ptr = (void *)REGION_ADDRESS(*region) + QUANTUM; + vm_address_t region_end = REGION_END(*region); + int is_last_region = region == szone->regions + szone->num_regions - 1; + msize_t prev_free = 0; + while ((vm_address_t)ptr < region_end) { + msize_t msize_and_free = MSIZE_FLAGS_FOR_PTR(ptr); + if (!(msize_and_free & THIS_FREE)) { + msize_t msize = msize_and_free & ~PREV_FREE; + if ((msize_and_free & PREV_FREE) != prev_free) { + malloc_printf("*** malloc[%d]: invariant broken for %p (prev_free=%d) this msize=%d\n", getpid(), ptr, prev_free, msize_and_free); + return 0; + } + if (!msize) { + int extra = (is_last_region) ? szone->num_bytes_free_in_last_region : QUANTUM; + if (((unsigned)(ptr + extra)) < region_end) { + malloc_printf("*** malloc[%d]: invariant broken at region end: ptr=%p extra=%d index=%d num_regions=%d end=%p\n", getpid(), ptr, extra, region - szone->regions, szone->num_regions, (void *)region_end); + return 0; + } + break; // last encountered + } + if (msize > (LARGE_THRESHOLD / QUANTUM)) { + malloc_printf("*** malloc[%d]: invariant broken for %p this msize=%d - size is too large\n", getpid(), ptr, msize_and_free); + return 0; + } + if ((msize < MIN_BLOCK) && ((unsigned)ptr != region_end - QUANTUM)) { + malloc_printf("*** malloc[%d]: invariant broken for %p this msize=%d - size is too small\n", getpid(), ptr, msize_and_free); + return 0; + } + ptr += msize << SHIFT_QUANTUM; + prev_free = 0; + if (is_last_region && ((vm_address_t)ptr - PTR_HEADER_SIZE > region_end - szone->num_bytes_free_in_last_region)) { + malloc_printf("*** malloc[%d]: invariant broken for %p this msize=%d - block extends beyond allocated region\n", getpid(), ptr, msize_and_free); + } + } else { + // free pointer + msize_t msize = msize_and_free & ~THIS_FREE; + free_list_t *free_head = ptr; + msize_t *follower = (void *)FOLLOWING_PTR(ptr, msize); + if ((msize_and_free & PREV_FREE) && !prev_free) { + malloc_printf("*** malloc[%d]: invariant broken for free block %p this msize=%d: PREV_FREE set while previous block is in use\n", getpid(), ptr, msize); + return 0; + } + if (msize < MIN_BLOCK) { + malloc_printf("*** malloc[%d]: invariant broken for free block %p this msize=%d\n", getpid(), ptr, msize); + return 0; + } + if (prev_free) { + malloc_printf("*** malloc[%d]: invariant broken for %p (2 free in a row)\n", getpid(), ptr); + return 0; + } + free_list_checksum(szone, free_head); + if (free_head->previous && !(MSIZE_FLAGS_FOR_PTR(free_head->previous) & THIS_FREE)) { + malloc_printf("*** malloc[%d]: invariant broken for %p (previous %p is not a free pointer)\n", getpid(), ptr, free_head->previous); + return 0; + } + if (free_head->next && !(MSIZE_FLAGS_FOR_PTR(free_head->next) & THIS_FREE)) { + malloc_printf("*** malloc[%d]: invariant broken for %p (next is not a free pointer)\n", getpid(), ptr); + return 0; + } + if (PREVIOUS_MSIZE(follower) != msize) { + malloc_printf("*** malloc[%d]: invariant broken for free %p followed by %p in region [%x-%x] (end marker incorrect) should be %d; in fact %d\n", getpid(), ptr, follower, REGION_ADDRESS(*region), region_end, msize, PREVIOUS_MSIZE(follower)); + return 0; + } + ptr = follower; + prev_free = PREV_FREE; + } + } + return 1; +} + +static kern_return_t small_in_use_enumerator(task_t task, void *context, unsigned type_mask, vm_address_t region_address, unsigned num_regions, memory_reader_t reader, vm_range_recorder_t recorder) { + region_t *regions; + unsigned index = 0; + vm_range_t buffer[MAX_RECORDER_BUFFER]; + unsigned count = 0; + kern_return_t err; + err = reader(task, region_address, sizeof(region_t) * num_regions, (void **)®ions); + if (err) return err; + while (index < num_regions) { + region_t region = regions[index++]; + vm_range_t range = {REGION_ADDRESS(region), REGION_SIZE}; + vm_address_t start = range.address + QUANTUM; + // malloc_printf("Enumerating small ptrs for Region starting at 0x%x\n", start); + if (type_mask & MALLOC_PTR_REGION_RANGE_TYPE) recorder(task, context, MALLOC_PTR_REGION_RANGE_TYPE, &range, 1); + if (type_mask & MALLOC_PTR_IN_USE_RANGE_TYPE) while (start < range.address + range.size) { + void *previous; + msize_t msize_and_free; + err = reader(task, start - PTR_HEADER_SIZE, QUANTUM, (void **)&previous); + if (err) return err; + previous += PTR_HEADER_SIZE; + msize_and_free = MSIZE_FLAGS_FOR_PTR(previous); + if (!(msize_and_free & THIS_FREE)) { + // Block in use + msize_t msize = msize_and_free & ~PREV_FREE; + if (!msize) break; // last encountered + buffer[count].address = start; + buffer[count].size = (msize << SHIFT_QUANTUM) - PTR_HEADER_SIZE; + count++; + if (count >= MAX_RECORDER_BUFFER) { + recorder(task, context, MALLOC_PTR_IN_USE_RANGE_TYPE, buffer, count); + count = 0; + } + start += msize << SHIFT_QUANTUM; + } else { + // free pointer + msize_t msize = msize_and_free & ~THIS_FREE; + start += msize << SHIFT_QUANTUM; + } + } + // malloc_printf("End region - count=%d\n", count); + } + if (count) recorder(task, context, MALLOC_PTR_IN_USE_RANGE_TYPE, buffer, count); + return 0; +} + +static INLINE void *small_malloc_from_free_list(szone_t *szone, msize_t msize, boolean_t *locked) { + void *ptr; + msize_t this_msize; + free_list_t **free_list; + free_list_t **limit = szone->free_list + MAX_GRAIN - 1; + // first try the small grains + free_list = szone->free_list + grain_for_msize(szone, msize); + while (free_list < limit) { + // try bigger grains + ptr = *free_list; + if (ptr) { + if (!*locked) { *locked = 1; SZONE_LOCK(szone); CHECK(szone, __PRETTY_FUNCTION__); } + ptr = *free_list; + if (ptr) { + // optimistic test worked + free_list_t *next; + next = ((free_list_t *)ptr)->next; + if (next) { + next->previous = NULL; + free_list_set_checksum(szone, next); + } + *free_list = next; + this_msize = MSIZE_FLAGS_FOR_PTR(ptr) & ~THIS_FREE; + MSIZE_FLAGS_FOR_PTR(FOLLOWING_PTR(ptr, this_msize)) &= ~ PREV_FREE; + goto add_leftover_and_proceed; + } + } + free_list++; + } + // We now check the large grains for one that is big enough + if (!*locked) { *locked = 1; SZONE_LOCK(szone); CHECK(szone, __PRETTY_FUNCTION__); } + ptr = *free_list; + while (ptr) { + this_msize = MSIZE_FLAGS_FOR_PTR(ptr) & ~THIS_FREE; + if (this_msize >= msize) { + free_list_remove_ptr(szone, ptr, this_msize); + goto add_leftover_and_proceed; + } + ptr = ((free_list_t *)ptr)->next; + } + return NULL; +add_leftover_and_proceed: + if (this_msize >= msize + MIN_BLOCK) { + if (LOG(szone,ptr)) malloc_printf("In small_malloc_should_clear(), adding leftover ptr=%p, this_msize=%d\n", ptr, this_msize); + free_list_add_ptr(szone, ptr + (msize << SHIFT_QUANTUM), this_msize - msize); + this_msize = msize; + } + szone->num_small_objects++; + szone->num_bytes_in_small_objects += this_msize << SHIFT_QUANTUM; +#if DEBUG_MALLOC + if (LOG(szone,ptr)) malloc_printf("In small_malloc_should_clear(), ptr=%p, this_msize=%d, msize=%d\n", ptr, this_msize, msize); +#endif + MSIZE_FLAGS_FOR_PTR(ptr) = this_msize; + return ptr; +} + +static INLINE void *small_malloc_should_clear(szone_t *szone, msize_t msize, boolean_t cleared_requested) { + boolean_t locked = 0; + void *ptr; +#if DEBUG_MALLOC + if (! (msize & 0xffff)) { + szone_error(szone, "Invariant broken (!msize) in allocation (region)", NULL); + } + if (msize < MIN_BLOCK) { + szone_error(szone, "Invariant broken (msize too small) in allocation (region)", NULL); + } +#endif + ptr = small_malloc_from_free_list(szone, msize, &locked); + if (ptr) { + CHECK(szone, __PRETTY_FUNCTION__); + SZONE_UNLOCK(szone); + if (cleared_requested) memset(ptr, 0, (msize << SHIFT_QUANTUM) - PTR_HEADER_SIZE); + return ptr; + } else { + if (!locked) SZONE_LOCK(szone); + CHECK(szone, __PRETTY_FUNCTION__); + ptr = small_malloc_from_region_no_lock(szone, msize); + // we don't clear because this freshly allocated space is pristine + CHECK(szone, __PRETTY_FUNCTION__); + SZONE_UNLOCK(szone); + } + return ptr; +} + +static INLINE void *small_malloc_cleared_no_lock(szone_t *szone, msize_t msize) { + // tries to allocate a small, cleared block + boolean_t locked = 1; + void *ptr; + ptr = small_malloc_from_free_list(szone, msize, &locked); + if (ptr) { + memset(ptr, 0, (msize << SHIFT_QUANTUM) - PTR_HEADER_SIZE); + return ptr; + } else { + ptr = small_malloc_from_region_no_lock(szone, msize); + // we don't clear because this freshly allocated space is pristine + } + return ptr; +} + +/********************* LARGE ENTRY UTILITIES ************************/ + +#if DEBUG_MALLOC + +static void large_debug_print(szone_t *szone) { + unsigned num_large_entries = szone->num_large_entries; + unsigned index = num_large_entries; + while (index--) { + large_entry_t *range = szone->large_entries + index; + large_entry_t entry = *range; + if (!LARGE_ENTRY_IS_EMPTY(entry)) malloc_printf("%d: 0x%x(%dKB); ", index, LARGE_ENTRY_ADDRESS(entry), LARGE_ENTRY_SIZE(entry)/1024); + } + malloc_printf("\n"); +} +#endif + +static large_entry_t *large_entry_for_pointer_no_lock(szone_t *szone, const void *ptr) { + // result only valid during a lock + unsigned num_large_entries = szone->num_large_entries; + unsigned hash_index; + unsigned index; + if (!num_large_entries) return NULL; + hash_index = ((unsigned)ptr >> vm_page_shift) % num_large_entries; + index = hash_index; + do { + large_entry_t *range = szone->large_entries + index; + large_entry_t entry = *range; + if (LARGE_ENTRY_MATCHES(entry, ptr)) return range; + if (LARGE_ENTRY_IS_EMPTY(entry)) return NULL; // end of chain + index++; if (index == num_large_entries) index = 0; + } while (index != hash_index); + return NULL; +} + +static void large_entry_insert_no_lock(szone_t *szone, large_entry_t range) { + unsigned num_large_entries = szone->num_large_entries; + unsigned hash_index = (range.address_and_num_pages >> vm_page_shift) % num_large_entries; + unsigned index = hash_index; + // malloc_printf("Before insertion of 0x%x\n", LARGE_ENTRY_ADDRESS(range)); + do { + large_entry_t *entry = szone->large_entries + index; + if (LARGE_ENTRY_IS_EMPTY(*entry)) { + *entry = range; + return; // end of chain + } + index++; if (index == num_large_entries) index = 0; + } while (index != hash_index); +} + +static INLINE void large_entries_rehash_after_entry_no_lock(szone_t *szone, large_entry_t *entry) { + unsigned num_large_entries = szone->num_large_entries; + unsigned hash_index = entry - szone->large_entries; + unsigned index = hash_index; + do { + large_entry_t range; + index++; if (index == num_large_entries) index = 0; + range = szone->large_entries[index]; + if (LARGE_ENTRY_IS_EMPTY(range)) return; + szone->large_entries[index].address_and_num_pages = 0; + large_entry_insert_no_lock(szone, range); // this will reinsert in the proper place + } while (index != hash_index); +} + +static INLINE large_entry_t *large_entries_alloc_no_lock(szone_t *szone, unsigned num) { + size_t size = num * sizeof(large_entry_t); + boolean_t is_vm_allocation = size >= LARGE_THRESHOLD; + if (is_vm_allocation) { + return (void *)allocate_pages(szone, round_page(size), 0, VM_MAKE_TAG(VM_MEMORY_MALLOC_LARGE)); + } else { + return small_malloc_cleared_no_lock(szone, (size + PTR_HEADER_SIZE + QUANTUM - 1) >> SHIFT_QUANTUM); + } +} + +static void large_entries_free_no_lock(szone_t *szone, large_entry_t *entries, unsigned num) { + size_t size = num * sizeof(large_entry_t); + boolean_t is_vm_allocation = size >= LARGE_THRESHOLD; + if (is_vm_allocation) { + deallocate_pages(szone, (vm_address_t)entries, round_page(size), 0); + } else { + region_t *region = region_for_ptr_no_lock(szone, entries); + msize_t msize_and_free = MSIZE_FLAGS_FOR_PTR(entries); + if (msize_and_free & THIS_FREE) { + szone_error(szone, "Object already freed being freed", entries); + return; + } + small_free_no_lock(szone, region, entries, msize_and_free); + } +} + +static void large_entries_grow_no_lock(szone_t *szone) { + unsigned old_num_entries = szone->num_large_entries; + large_entry_t *old_entries = szone->large_entries; + unsigned new_num_entries = (old_num_entries) ? old_num_entries * 2 + 1 : 15; // always an odd number for good hashing + large_entry_t *new_entries = large_entries_alloc_no_lock(szone, new_num_entries); + unsigned index = old_num_entries; + szone->num_large_entries = new_num_entries; + szone->large_entries = new_entries; + // malloc_printf("_grow_large_entries old_num_entries=%d new_num_entries=%d\n", old_num_entries, new_num_entries); + while (index--) { + large_entry_t oldRange = old_entries[index]; + if (!LARGE_ENTRY_IS_EMPTY(oldRange)) large_entry_insert_no_lock(szone, oldRange); + } + if (old_entries) large_entries_free_no_lock(szone, old_entries, old_num_entries); +} + +static vm_range_t large_free_no_lock(szone_t *szone, large_entry_t *entry) { + // frees the specific entry in the size table + // returns a range to truly deallocate + vm_range_t range; + range.address = LARGE_ENTRY_ADDRESS(*entry); + range.size = LARGE_ENTRY_SIZE(*entry); + szone->num_large_objects_in_use --; + szone->num_bytes_in_large_objects -= range.size; + if (szone->debug_flags & SCALABLE_MALLOC_ADD_GUARD_PAGES) { + protect(szone, range.address, range.size, VM_PROT_READ | VM_PROT_WRITE, szone->debug_flags); + range.address -= vm_page_size; + range.size += 2 * vm_page_size; + } + // printf("Entry is 0x%x=%d; cache is 0x%x ; found=0x%x\n", entry, entry-szone->large_entries, szone->large_entries, large_entry_for_pointer_no_lock(szone, (void *)range.address)); + entry->address_and_num_pages = 0; + large_entries_rehash_after_entry_no_lock(szone, entry); +#if DEBUG_MALLOC + if (large_entry_for_pointer_no_lock(szone, (void *)range.address)) { + malloc_printf("*** malloc[%d]: Freed entry 0x%x still in use; num_large_entries=%d\n", getpid(), range.address, szone->num_large_entries); + large_debug_print(szone); + sleep(3600); + } +#endif + return range; +} + +static kern_return_t large_in_use_enumerator(task_t task, void *context, unsigned type_mask, vm_address_t large_entries_address, unsigned num_entries, memory_reader_t reader, vm_range_recorder_t recorder) { + unsigned index = 0; + vm_range_t buffer[MAX_RECORDER_BUFFER]; + unsigned count = 0; + large_entry_t *entries; + kern_return_t err; + err = reader(task, large_entries_address, sizeof(large_entry_t) * num_entries, (void **)&entries); + if (err) return err; + index = num_entries; + if ((type_mask & MALLOC_ADMIN_REGION_RANGE_TYPE) && (num_entries * sizeof(large_entry_t) >= LARGE_THRESHOLD)) { + vm_range_t range; + range.address = large_entries_address; + range.size = round_page(num_entries * sizeof(large_entry_t)); + recorder(task, context, MALLOC_ADMIN_REGION_RANGE_TYPE, &range, 1); + } + if (type_mask & (MALLOC_PTR_IN_USE_RANGE_TYPE | MALLOC_PTR_REGION_RANGE_TYPE)) while (index--) { + large_entry_t entry = entries[index]; + if (!LARGE_ENTRY_IS_EMPTY(entry)) { + vm_range_t range; + range.address = LARGE_ENTRY_ADDRESS(entry); + range.size = LARGE_ENTRY_SIZE(entry); + buffer[count++] = range; + if (count >= MAX_RECORDER_BUFFER) { + recorder(task, context, MALLOC_PTR_IN_USE_RANGE_TYPE | MALLOC_PTR_REGION_RANGE_TYPE, buffer, count); + count = 0; + } + } + } + if (count) recorder(task, context, MALLOC_PTR_IN_USE_RANGE_TYPE | MALLOC_PTR_REGION_RANGE_TYPE, buffer, count); + return 0; +} + +/********************* HUGE ENTRY UTILITIES ************************/ + +static huge_entry_t *huge_entry_for_pointer_no_lock(szone_t *szone, const void *ptr) { + unsigned index = szone->num_huge_entries; + while (index--) { + huge_entry_t *huge = szone->huge_entries + index; + if (huge->address == (vm_address_t)ptr) return huge; + } + return NULL; +} + +static boolean_t huge_entry_append(szone_t *szone, huge_entry_t huge) { + // We do a little dance with locking because doing allocation (even in the default szone) may cause something to get freed in this szone, with a deadlock + huge_entry_t *new_huge_entries = NULL; + SZONE_LOCK(szone); + while (1) { + unsigned num_huge_entries; + num_huge_entries = szone->num_huge_entries; + SZONE_UNLOCK(szone); + // malloc_printf("In huge_entry_append currentEntries=%d\n", num_huge_entries); + if (new_huge_entries) szone_free(szone, new_huge_entries); + new_huge_entries = szone_malloc(szone, (num_huge_entries + 1) * sizeof(huge_entry_t)); + if (new_huge_entries == NULL) + return 1; + SZONE_LOCK(szone); + if (num_huge_entries == szone->num_huge_entries) { + // No change - our malloc still applies + huge_entry_t *old_huge_entries = szone->huge_entries; + if (num_huge_entries) memcpy(new_huge_entries, old_huge_entries, num_huge_entries * sizeof(huge_entry_t)); + new_huge_entries[szone->num_huge_entries++] = huge; + szone->huge_entries = new_huge_entries; + SZONE_UNLOCK(szone); + szone_free(szone, old_huge_entries); + // malloc_printf("Done huge_entry_append now=%d\n", szone->num_huge_entries); + return 0; + } + // try again! + } +} + +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) { + huge_entry_t *entries; + kern_return_t err; + err = reader(task, huge_entries_address, sizeof(huge_entry_t) * num_entries, (void **)&entries); + if (err) return err; + if (num_entries) recorder(task, context, MALLOC_PTR_IN_USE_RANGE_TYPE | MALLOC_PTR_REGION_RANGE_TYPE, entries, num_entries); + return 0; +} + +static void *large_and_huge_malloc(szone_t *szone, unsigned num_pages) { + vm_address_t addr = 0; + if (!num_pages) num_pages = 1; // minimal allocation size for this szone + // malloc_printf("In large_and_huge_malloc for %dKB\n", num_pages * vm_page_size / 1024); + if (num_pages >= (1 << vm_page_shift)) { + huge_entry_t huge; + huge.size = num_pages << vm_page_shift; + addr = allocate_pages(szone, huge.size, szone->debug_flags, VM_MAKE_TAG(VM_MEMORY_MALLOC_HUGE)); + if (!addr) return NULL; + huge.address = addr; + if (huge_entry_append(szone, huge)) + return NULL; + SZONE_LOCK(szone); + szone->num_bytes_in_huge_objects += huge.size; + } else { + vm_size_t size = num_pages << vm_page_shift; + large_entry_t entry; + addr = allocate_pages(szone, size, szone->debug_flags, VM_MAKE_TAG(VM_MEMORY_MALLOC_LARGE)); + if (LOG(szone, addr)) malloc_printf("In szone_malloc true large allocation at %p for %dKB\n", (void *)addr, size / 1024); + SZONE_LOCK(szone); + if (!addr) { + SZONE_UNLOCK(szone); + return NULL; + } +#if DEBUG_MALLOC + if (large_entry_for_pointer_no_lock(szone, (void *)addr)) { + malloc_printf("Freshly allocated is already in use: 0x%x\n", addr); + large_debug_print(szone); + sleep(3600); + } +#endif + if ((szone->num_large_objects_in_use + 1) * 4 > szone->num_large_entries) { + // density of hash table too high; grow table + // we do that under lock to avoid a race + // malloc_printf("In szone_malloc growing hash table current=%d\n", szone->num_large_entries); + large_entries_grow_no_lock(szone); + } + // malloc_printf("Inserting large entry (0x%x, %dKB)\n", addr, num_pages * vm_page_size / 1024); + entry.address_and_num_pages = addr | num_pages; +#if DEBUG_MALLOC + if (large_entry_for_pointer_no_lock(szone, (void *)addr)) { + malloc_printf("Entry about to be added already in use: 0x%x\n", addr); + large_debug_print(szone); + sleep(3600); + } +#endif + large_entry_insert_no_lock(szone, entry); +#if DEBUG_MALLOC + if (!large_entry_for_pointer_no_lock(szone, (void *)addr)) { + malloc_printf("Can't find entry just added\n"); + large_debug_print(szone); + sleep(3600); + } +#endif + // malloc_printf("Inserted large entry (0x%x, %d pages)\n", addr, num_pages); + szone->num_large_objects_in_use ++; + szone->num_bytes_in_large_objects += size; + } + SZONE_UNLOCK(szone); + return (void *)addr; +} + +/********************* Zone call backs ************************/ + +static void szone_free(szone_t *szone, void *ptr) { + region_t *region; + large_entry_t *entry; + vm_range_t vm_range_to_deallocate; + huge_entry_t *huge; + if (LOG(szone, ptr)) malloc_printf("In szone_free with %p\n", ptr); + if (!ptr) return; + if ((vm_address_t)ptr & (QUANTUM - 1)) { + szone_error(szone, "Non-aligned pointer being freed", ptr); + return; + } + // try a small pointer + region = region_for_ptr_no_lock(szone, ptr); + if (region) { + // this is indeed a valid pointer + msize_t msize_and_free; + SZONE_LOCK(szone); + msize_and_free = MSIZE_FLAGS_FOR_PTR(ptr); + if (msize_and_free & THIS_FREE) { + szone_error(szone, "Object already freed being freed", ptr); + return; + } + CHECK(szone, __PRETTY_FUNCTION__); + small_free_no_lock(szone, region, ptr, msize_and_free); + CHECK(szone, __PRETTY_FUNCTION__); + SZONE_UNLOCK(szone); + return; + } + if (((unsigned)ptr) & (vm_page_size - 1)) { + szone_error(szone, "Non-page-aligned, non-allocated pointer being freed", ptr); + return; + } + SZONE_LOCK(szone); + entry = large_entry_for_pointer_no_lock(szone, ptr); + if (entry) { + // malloc_printf("Ready for deallocation [0x%x-%dKB]\n", LARGE_ENTRY_ADDRESS(*entry), LARGE_ENTRY_SIZE(*entry)/1024); + if (KILL_THRESHOLD && (LARGE_ENTRY_SIZE(*entry) > KILL_THRESHOLD)) { + // We indicate to the VM system that these pages contain garbage and therefore don't need to be swapped out + vm_msync(mach_task_self(), LARGE_ENTRY_ADDRESS(*entry), LARGE_ENTRY_SIZE(*entry), VM_SYNC_KILLPAGES); + } + vm_range_to_deallocate = large_free_no_lock(szone, entry); +#if DEBUG_MALLOC + if (large_entry_for_pointer_no_lock(szone, ptr)) { + malloc_printf("*** malloc[%d]: Just after freeing 0x%x still in use num_large_entries=%d\n", getpid(), ptr, szone->num_large_entries); + large_debug_print(szone); + sleep(3600); + } +#endif + } else if ((huge = huge_entry_for_pointer_no_lock(szone, ptr))) { + vm_range_to_deallocate = *huge; + *huge = szone->huge_entries[--szone->num_huge_entries]; // last entry fills that spot + szone->num_bytes_in_huge_objects -= vm_range_to_deallocate.size; + } else { +#if DEBUG_MALLOC + large_debug_print(szone); +#endif + szone_error(szone, "Pointer being freed was not allocated", ptr); + return; + } + CHECK(szone, __PRETTY_FUNCTION__); + SZONE_UNLOCK(szone); // we release the lock asap + // we deallocate_pages, including guard pages + if (vm_range_to_deallocate.address) { + // malloc_printf("About to deallocate 0x%x size %dKB\n", vm_range_to_deallocate.address, vm_range_to_deallocate.size / 1024); +#if DEBUG_MALLOC + if (large_entry_for_pointer_no_lock(szone, (void *)vm_range_to_deallocate.address)) { + malloc_printf("*** malloc[%d]: Invariant broken: 0x%x still in use num_large_entries=%d\n", getpid(), vm_range_to_deallocate.address, szone->num_large_entries); + large_debug_print(szone); + sleep(3600); + } +#endif + deallocate_pages(szone, vm_range_to_deallocate.address, vm_range_to_deallocate.size, 0); + } +} + +static INLINE void *szone_malloc_should_clear(szone_t *szone, size_t size, boolean_t cleared_requested) { + void *ptr; + if (!((szone->debug_flags & SCALABLE_MALLOC_ADD_GUARD_PAGES) && PROTECT_SMALL) && (size < LARGE_THRESHOLD)) { + // think small + size_t msize = (size + PTR_HEADER_SIZE + QUANTUM - 1) >> SHIFT_QUANTUM; + if (msize < MIN_BLOCK) msize = MIN_BLOCK; + ptr = small_malloc_should_clear(szone, msize, cleared_requested); +#if DEBUG_MALLOC + if ((MSIZE_FLAGS_FOR_PTR(ptr) & ~ PREV_FREE) < msize) { + malloc_printf("ptr=%p this=%d msize=%d\n", ptr, MSIZE_FLAGS_FOR_PTR(ptr), (int)msize); + szone_error(szone, "Pointer allocated has improper size (1)", ptr); + return NULL; + } + if ((MSIZE_FLAGS_FOR_PTR(ptr) & ~ PREV_FREE) < MIN_BLOCK) { + malloc_printf("ptr=%p this=%d msize=%d\n", ptr, MSIZE_FLAGS_FOR_PTR(ptr), (int)msize); + szone_error(szone, "Pointer allocated has improper size (2)", ptr); + return NULL; + } +#endif + } else { + unsigned num_pages; + num_pages = round_page(size) >> vm_page_shift; + ptr = large_and_huge_malloc(szone, num_pages); + } + if (LOG(szone, ptr)) malloc_printf("szone_malloc returned %p\n", ptr); + return ptr; +} + +static void *szone_malloc(szone_t *szone, size_t size) { + return szone_malloc_should_clear(szone, size, 0); +} + +static void *szone_calloc(szone_t *szone, size_t num_items, size_t size) { + return szone_malloc_should_clear(szone, num_items * size, 1); +} + +static void *szone_valloc(szone_t *szone, size_t size) { + void *ptr; + unsigned num_pages; + num_pages = round_page(size) >> vm_page_shift; + ptr = large_and_huge_malloc(szone, num_pages); + if (LOG(szone, ptr)) malloc_printf("szone_valloc returned %p\n", ptr); + return ptr; +} + +static size_t szone_size(szone_t *szone, const void *ptr) { + size_t size = 0; + region_t *region; + large_entry_t *entry; + huge_entry_t *huge; + if (!ptr) return 0; + if (LOG(szone, ptr)) malloc_printf("In szone_size for %p (szone=%p)\n", ptr, szone); + if ((vm_address_t)ptr & (QUANTUM - 1)) return 0; + if ((((unsigned)ptr) & (vm_page_size - 1)) && (MSIZE_FLAGS_FOR_PTR(ptr) & THIS_FREE)) { + // not page aligned, but definitely not in use + return 0; + } + // Try a small pointer + region = region_for_ptr_no_lock(szone, ptr); + // malloc_printf("FOUND REGION %p\n", region); + if (region) { + // this is indeed a valid pointer + msize_t msize_and_free = MSIZE_FLAGS_FOR_PTR(ptr); + return (msize_and_free & THIS_FREE) ? 0 : ((msize_and_free & ~PREV_FREE) << SHIFT_QUANTUM) - PTR_HEADER_SIZE; + } + if (((unsigned)ptr) & (vm_page_size - 1)) { + return 0; + } + SZONE_LOCK(szone); + entry = large_entry_for_pointer_no_lock(szone, ptr); + if (entry) { + size = LARGE_ENTRY_SIZE(*entry); + } else if ((huge = huge_entry_for_pointer_no_lock(szone, ptr))) { + size = huge->size; + } + SZONE_UNLOCK(szone); + // malloc_printf("szone_size for large/huge %p returned %d\n", ptr, (unsigned)size); + if (LOG(szone, ptr)) malloc_printf("szone_size for %p returned %d\n", ptr, (unsigned)size); + return size; +} + +static INLINE int try_realloc_small_in_place(szone_t *szone, void *ptr, size_t old_size, size_t new_size) { + // returns 1 on success + void *next_block = (char *)ptr + old_size + PTR_HEADER_SIZE; + msize_t next_msize_and_free; + msize_t next_msize; + region_t region; + msize_t coalesced_msize; + msize_t leftover_msize; + msize_t new_msize_and_free; + void *following_ptr; + SZONE_LOCK(szone); + region = szone->regions[szone->num_regions - 1]; + if (((vm_address_t)ptr >= region) && ((vm_address_t)ptr < region + REGION_SIZE) && ((vm_address_t)next_block == REGION_END(region) - szone->num_bytes_free_in_last_region + PTR_HEADER_SIZE)) { + // This could be optimized but it is so rare it's not worth it + SZONE_UNLOCK(szone); + return 0; + } + // If the next block is free, we coalesce + next_msize_and_free = MSIZE_FLAGS_FOR_PTR(next_block); +#if DEBUG_MALLOC + if ((vm_address_t)next_block & (QUANTUM - 1)) { + szone_error(szone, "Internal invariant broken in realloc(next_block)", next_block); + } + if (next_msize_and_free & PREV_FREE) { + malloc_printf("try_realloc_small_in_place: 0x%x=PREV_FREE|%d\n", next_msize_and_free, next_msize_and_free & ~PREV_FREE); + SZONE_UNLOCK(szone); + return 0; + } +#endif + next_msize = next_msize_and_free & ~THIS_FREE; + if (!(next_msize_and_free & THIS_FREE) || !next_msize || (old_size + (next_msize << SHIFT_QUANTUM) < new_size)) { + SZONE_UNLOCK(szone); + return 0; + } + coalesced_msize = (new_size - old_size + QUANTUM - 1) >> SHIFT_QUANTUM; + leftover_msize = next_msize - coalesced_msize; + new_msize_and_free = MSIZE_FLAGS_FOR_PTR(ptr); + // malloc_printf("Realloc in place for %p; current msize=%d next_msize=%d wanted=%d\n", ptr, MSIZE_FLAGS_FOR_PTR(ptr), next_msize, new_size); + free_list_remove_ptr(szone, next_block, next_msize); + if ((leftover_msize < MIN_BLOCK) || (leftover_msize < coalesced_msize / 4)) { + // don't bother splitting it off + // malloc_printf("No leftover "); + coalesced_msize = next_msize; + leftover_msize = 0; + } else { + void *leftover = next_block + (coalesced_msize << SHIFT_QUANTUM); + // malloc_printf("Leftover "); + free_list_add_ptr(szone, leftover, leftover_msize); + } + new_msize_and_free += coalesced_msize; + MSIZE_FLAGS_FOR_PTR(ptr) = new_msize_and_free; + following_ptr = FOLLOWING_PTR(ptr, new_msize_and_free & ~PREV_FREE); + MSIZE_FLAGS_FOR_PTR(following_ptr) &= ~ PREV_FREE; +#if DEBUG_MALLOC + { + msize_t ms = MSIZE_FLAGS_FOR_PTR(following_ptr); + msize_t pms = PREVIOUS_MSIZE(FOLLOWING_PTR(following_ptr, ms & ~THIS_FREE)); + malloc_printf("Following ptr of coalesced (%p) has msize_and_free=0x%x=%s%d end_of_block_marker=%d\n", following_ptr, ms, (ms & THIS_FREE) ? "THIS_FREE|" : "", ms & ~THIS_FREE, pms); + } + if (LOG(szone,ptr)) malloc_printf("In szone_realloc(), ptr=%p, msize=%d\n", ptr, MSIZE_FLAGS_FOR_PTR(ptr)); +#endif + CHECK(szone, __PRETTY_FUNCTION__); + szone->num_bytes_in_small_objects += coalesced_msize << SHIFT_QUANTUM; + SZONE_UNLOCK(szone); + // malloc_printf("Extended ptr %p for realloc old=%d desired=%d new=%d leftover=%d\n", ptr, (unsigned)old_size, (unsigned)new_size, (unsigned)szone_size(szone, ptr), leftover_msize << SHIFT_QUANTUM); + return 1; +} + +static INLINE int try_realloc_large_in_place(szone_t *szone, void *ptr, size_t old_size, size_t new_size) { + vm_address_t addr = (vm_address_t)ptr + old_size; + large_entry_t *entry; + kern_return_t err; + if (((szone->debug_flags & SCALABLE_MALLOC_ADD_GUARD_PAGES) && PROTECT_SMALL)) return 0; // don't want to bother with the protected case +#if DEBUG_MALLOC + if (old_size != ((old_size >> vm_page_shift) << vm_page_shift)) malloc_printf("*** old_size is %d\n", old_size); +#endif + // malloc_printf("=== Trying (1) to extend %p from %d to %d\n", ptr, old_size, new_size); + SZONE_LOCK(szone); + entry = large_entry_for_pointer_no_lock(szone, (void *)addr); + SZONE_UNLOCK(szone); + if (entry) return 0; // large pointer already exist in table - extension is not going to work + new_size = round_page(new_size); + // malloc_printf("=== Trying (2) to extend %p from %d to %d\n", ptr, old_size, new_size); + err = vm_allocate(mach_task_self(), &addr, new_size - old_size, VM_MAKE_TAG(VM_MEMORY_MALLOC_LARGE)); // we ask for allocation specifically at addr + if (err) return 0; + // we can just extend the block + SZONE_LOCK(szone); + entry = large_entry_for_pointer_no_lock(szone, ptr); + if (!entry) szone_error(szone, "large entry reallocated is not properly in table", ptr); + // malloc_printf("=== Successfully reallocated at end of %p from %d to %d\n", ptr, old_size, new_size); + entry->address_and_num_pages = (vm_address_t)ptr | (new_size >> vm_page_shift); + szone->num_bytes_in_large_objects += new_size - old_size; + SZONE_UNLOCK(szone); // we release the lock asap + return 1; +} + +static void *szone_realloc(szone_t *szone, void *ptr, size_t new_size) { + size_t old_size = 0; + void *new_ptr; + if (LOG(szone, ptr)) malloc_printf("In szone_realloc for %p, %d\n", ptr, (unsigned)new_size); + if (!ptr) return szone_malloc(szone, new_size); + old_size = szone_size(szone, ptr); + if (!old_size) { + szone_error(szone, "Pointer being reallocated was not allocated", ptr); + return NULL; + } + if (old_size >= new_size) return ptr; + if (!((szone->debug_flags & SCALABLE_MALLOC_ADD_GUARD_PAGES) && PROTECT_SMALL) && ((new_size + PTR_HEADER_SIZE + QUANTUM - 1) < LARGE_THRESHOLD)) { + // We now try to realloc in place + if (try_realloc_small_in_place(szone, ptr, old_size, new_size)) return ptr; + } + if ((old_size > VM_COPY_THRESHOLD) && ((new_size + vm_page_size - 1) < (1 << (vm_page_shift + vm_page_shift)))) { + // we know it's a large block, and not a huge block (both for old and new) + kern_return_t err = 0; + unsigned num_pages; + large_entry_t *entry; + vm_range_t range; + num_pages = round_page(new_size) >> vm_page_shift; + if (try_realloc_large_in_place(szone, ptr, old_size, new_size)) return ptr; + new_ptr = large_and_huge_malloc(szone, num_pages); + err = vm_copy(mach_task_self(), (vm_address_t)ptr, old_size, (vm_address_t)new_ptr); + if (err) { + szone_error(szone, "Can't vm_copy region", ptr); + } + // We do not want the kernel to alias the old and the new, so we deallocate the old pointer right away and tear down the ptr-to-size data structure + SZONE_LOCK(szone); + entry = large_entry_for_pointer_no_lock(szone, ptr); + if (!entry) { + szone_error(szone, "Can't find entry for large copied block", ptr); + } + range = large_free_no_lock(szone, entry); + SZONE_UNLOCK(szone); // we release the lock asap + // we truly deallocate_pages, including guard pages + deallocate_pages(szone, range.address, range.size, 0); + if (LOG(szone, ptr)) malloc_printf("szone_realloc returned %p for %d\n", new_ptr, (unsigned)new_size); + return new_ptr; + } else { + new_ptr = szone_malloc(szone, new_size); + if (new_ptr == NULL) + return NULL; + memcpy(new_ptr, ptr, old_size); + } + szone_free(szone, ptr); + if (LOG(szone, ptr)) malloc_printf("szone_realloc returned %p for %d\n", new_ptr, (unsigned)new_size); + return new_ptr; +} + +static void szone_destroy(szone_t *szone) { + unsigned index; + index = szone->num_large_entries; + while (index--) { + large_entry_t *entry = szone->large_entries + index; + if (!LARGE_ENTRY_IS_EMPTY(*entry)) { + large_entry_t range; + range = *entry; + // we deallocate_pages, including guard pages + deallocate_pages(szone, LARGE_ENTRY_ADDRESS(range), LARGE_ENTRY_SIZE(range), szone->debug_flags); + } + } + if (szone->num_large_entries * sizeof(large_entry_t) >= LARGE_THRESHOLD) large_entries_free_no_lock(szone, szone->large_entries, szone->num_large_entries); // we do not free in the small chunk case + index = szone->num_huge_entries; + while (index--) { + huge_entry_t *huge = szone->huge_entries + index; + deallocate_pages(szone, huge->address, huge->size, szone->debug_flags); + } + // and now we free regions, with regions[0] as the last one (the final harakiri) + index = szone->num_regions; + while (index--) { // we skip the first region, that is the zone itself + region_t region = szone->regions[index]; + deallocate_pages(szone, REGION_ADDRESS(region), REGION_SIZE, 0); + } +} + +static size_t szone_good_size(szone_t *szone, size_t size) { + if (!((szone->debug_flags & SCALABLE_MALLOC_ADD_GUARD_PAGES) && PROTECT_SMALL) && (size < LARGE_THRESHOLD)) { + // think small + msize_t msize = (size + PTR_HEADER_SIZE + QUANTUM - 1) >> SHIFT_QUANTUM; + if (msize < MIN_BLOCK) msize = MIN_BLOCK; + return (msize << SHIFT_QUANTUM) - PTR_HEADER_SIZE; + } else { + unsigned num_pages; + num_pages = round_page(size) >> vm_page_shift; + if (!num_pages) num_pages = 1; // minimal allocation size for this + return num_pages << vm_page_shift; + } +} + +unsigned szone_check_counter = 0; +unsigned szone_check_start = 0; +unsigned szone_check_modulo = 1; + +static boolean_t szone_check_all(szone_t *szone, const char *function) { + unsigned index = 0; + SZONE_LOCK(szone); + while (index < szone->num_regions) { + region_t *region = szone->regions + index++; + if (!szone_check_region(szone, region)) { + SZONE_UNLOCK(szone); + szone->debug_flags &= ~ CHECK_REGIONS; + malloc_printf("*** malloc[%d]: Region %d incorrect szone_check_all(%s) counter=%d\n", getpid(), index-1, function, szone_check_counter); + szone_error(szone, "Check: region incorrect", NULL); + return 0; + } + } + index = 0; + while (index < MAX_GRAIN) { + if (! free_list_check(szone, index)) { + SZONE_UNLOCK(szone); + szone->debug_flags &= ~ CHECK_REGIONS; + malloc_printf("*** malloc[%d]: Free list incorrect (grain=%d) szone_check_all(%s) counter=%d\n", getpid(), index, function, szone_check_counter); + szone_error(szone, "Check: free list incorrect", NULL); + return 0; + } + index++; + } + SZONE_UNLOCK(szone); + return 1; +} + +static boolean_t szone_check(szone_t *szone) { + if (! (++szone_check_counter % 10000)) { + malloc_printf("At szone_check counter=%d\n", szone_check_counter); + } + if (szone_check_counter < szone_check_start) return 1; + if (szone_check_counter % szone_check_modulo) return 1; + return szone_check_all(szone, ""); +} + +static kern_return_t szone_ptr_in_use_enumerator(task_t task, void *context, unsigned type_mask, vm_address_t zone_address, memory_reader_t reader, vm_range_recorder_t recorder) { + szone_t *szone; + kern_return_t err; + if (!reader) reader = _szone_default_reader; + // malloc_printf("Enumerator for zone 0x%x\n", zone_address); + err = reader(task, zone_address, sizeof(szone_t), (void **)&szone); + if (err) return err; + // malloc_printf("Small ptrs enumeration for zone 0x%x\n", zone_address); + err = small_in_use_enumerator(task, context, type_mask, (vm_address_t)szone->regions, szone->num_regions, reader, recorder); + if (err) return err; + // malloc_printf("Large ptrs enumeration for zone 0x%x\n", zone_address); + err = large_in_use_enumerator(task, context, type_mask, (vm_address_t)szone->large_entries, szone->num_large_entries, reader, recorder); + if (err) return err; + // malloc_printf("Huge ptrs enumeration for zone 0x%x\n", zone_address); + err = huge_in_use_enumerator(task, context, type_mask, (vm_address_t)szone->huge_entries, szone->num_huge_entries, reader, recorder); + return err; +} + +static void szone_print_free_list(szone_t *szone) { + grain_t grain = MAX_GRAIN; + malloc_printf("Free Sizes: "); + while (grain--) { + free_list_t *ptr = szone->free_list[grain]; + if (ptr) { + unsigned count = 0; + while (ptr) { + count++; + // malloc_printf("%p ", ptr); + ptr = ptr->next; + } + malloc_printf("%s%d[%d] ", (grain == MAX_GRAIN-1) ? ">=" : "", (grain+1)*QUANTUM, count); + } + } + malloc_printf("\n"); +} + +static void szone_print(szone_t *szone, boolean_t verbose) { + unsigned info[scalable_zone_info_count]; + unsigned index = 0; + scalable_zone_info((void *)szone, info, scalable_zone_info_count); + malloc_printf("Scalable zone %p: inUse=%d(%dKB) small=%d(%dKB) large=%d(%dKB) huge=%d(%dKB) guard_page=%d\n", szone, info[0], info[1] / 1024, info[2], info[3] / 1024, info[4], info[5] / 1024, info[6], info[7] / 1024, info[8]); + malloc_printf("%d regions: \n", szone->num_regions); + while (index < szone->num_regions) { + region_t *region = szone->regions + index; + unsigned counts[512]; + unsigned ci = 0; + unsigned in_use = 0; + vm_address_t start = REGION_ADDRESS(*region) + QUANTUM; + memset(counts, 0, 512 * sizeof(unsigned)); + while (start < REGION_END(*region)) { + msize_t msize_and_free = MSIZE_FLAGS_FOR_PTR(start); + if (!(msize_and_free & THIS_FREE)) { + msize_t msize = msize_and_free & ~PREV_FREE; + if (!msize) break; // last encountered + // block in use + if (msize < 512) counts[msize]++; + start += msize << SHIFT_QUANTUM; + in_use++; + } else { + msize_t msize = msize_and_free & ~THIS_FREE; + // free block + start += msize << SHIFT_QUANTUM; + } + } + malloc_printf("Region [0x%x-0x%x, %dKB] \tIn_use=%d ", REGION_ADDRESS(*region), REGION_END(*region), (int)REGION_SIZE / 1024, in_use); + if (verbose) { + malloc_printf("\n\tSizes in use: "); + while (ci < 512) { + if (counts[ci]) malloc_printf("%d[%d] ", ci << SHIFT_QUANTUM, counts[ci]); + ci++; + } + } + malloc_printf("\n"); + index++; + } + if (verbose) szone_print_free_list(szone); + malloc_printf("Free in last zone %d\n", szone->num_bytes_free_in_last_region); +} + +static void szone_log(malloc_zone_t *zone, void *log_address) { + szone_t *szone = (void *)zone; + szone->log_address = log_address; +} + +static void szone_force_lock(szone_t *szone) { + // malloc_printf("szone_force_lock\n"); + SZONE_LOCK(szone); +} + +static void szone_force_unlock(szone_t *szone) { + // malloc_printf("szone_force_unlock\n"); + SZONE_UNLOCK(szone); +} + +static struct malloc_introspection_t szone_introspect = {(void *)szone_ptr_in_use_enumerator, (void *)szone_good_size, (void *)szone_check, (void *)szone_print, szone_log, (void *)szone_force_lock, (void *)szone_force_unlock}; + +malloc_zone_t *create_scalable_zone(size_t initial_size, unsigned debug_flags) { + szone_t *szone; + vm_address_t addr; + size_t msize; + size_t msize_used = 0; + // malloc_printf("=== create_scalable_zone(%d,%d);\n", initial_size, debug_flags); + if (!vm_page_shift) { + unsigned page; + vm_page_shift = 12; // the minimal for page sizes + page = 1 << vm_page_shift; + while (page != vm_page_size) { page += page; vm_page_shift++;}; + if (MIN_BLOCK * QUANTUM < sizeof(free_list_t) + PTR_HEADER_SIZE) { + malloc_printf("*** malloc[%d]: inconsistant parameters\n", getpid()); + } + } + addr = allocate_pages(NULL, REGION_SIZE, 0, VM_MAKE_TAG(VM_MEMORY_MALLOC)); + if (!addr) return NULL; + szone = (void *)(addr + QUANTUM); + msize = (sizeof(szone_t) + PTR_HEADER_SIZE + QUANTUM-1) >> SHIFT_QUANTUM; + MSIZE_FLAGS_FOR_PTR(szone) = msize; + msize_used += msize; szone->num_small_objects++; + szone->basic_zone.size = (void *)szone_size; + szone->basic_zone.malloc = (void *)szone_malloc; + szone->basic_zone.calloc = (void *)szone_calloc; + szone->basic_zone.valloc = (void *)szone_valloc; + szone->basic_zone.free = (void *)szone_free; + szone->basic_zone.realloc = (void *)szone_realloc; + szone->basic_zone.destroy = (void *)szone_destroy; + szone->basic_zone.introspect = &szone_introspect; + LOCK_INIT(szone->lock); + szone->debug_flags = debug_flags; + szone->regions = (void *)((char *)szone + (msize << SHIFT_QUANTUM)); + // we always reserve room for a few regions + msize = (sizeof(region_t) * INITIAL_NUM_REGIONS + PTR_HEADER_SIZE + QUANTUM-1) >> SHIFT_QUANTUM; + if (msize < MIN_BLOCK) msize = MIN_BLOCK; + MSIZE_FLAGS_FOR_PTR(szone->regions) = msize; + msize_used += msize; szone->num_small_objects++; + szone->regions[0] = addr; + szone->num_regions = 1; + szone->num_bytes_free_in_last_region = REGION_SIZE - ((msize_used+1) << SHIFT_QUANTUM) + PTR_HEADER_SIZE; + CHECK(szone, __PRETTY_FUNCTION__); + return (malloc_zone_t *)szone; +} + +/********* The following is private API for debug and perf tools ************/ + +void scalable_zone_info(malloc_zone_t *zone, unsigned *info_to_fill, unsigned count) { + szone_t *szone = (void *)zone; + unsigned info[scalable_zone_info_count]; + // We do not lock to facilitate debug + info[2] = szone->num_small_objects; + info[3] = szone->num_bytes_in_small_objects; + info[4] = szone->num_large_objects_in_use; + info[5] = szone->num_bytes_in_large_objects; + info[6] = szone->num_huge_entries; + info[7] = szone->num_bytes_in_huge_objects; + info[8] = szone->debug_flags; + info[0] = info[2] + info[4] + info[6]; + info[1] = info[3] + info[5] + info[7]; + memcpy(info_to_fill, info, sizeof(unsigned)*count); +} + +/********* Support code for emacs unexec ************/ + +/* History of freezedry version numbers: + * + * 1) Old malloc (before the scalable malloc implementation in this file + * existed). + * 2) Original freezedrying code for scalable malloc. This code was apparently + * based on the old freezedrying code and was fundamentally flawed in its + * assumption that tracking allocated memory regions was adequate to fake + * operations on freezedried memory. This doesn't work, since scalable + * malloc does not store flags in front of large page-aligned allocations. + * 3) Original szone-based freezedrying code. + * + * No version backward compatibility is provided, but the version number does + * make it possible for malloc_jumpstart() to return an error if the application + * was freezedried with an older version of malloc. + */ +#define MALLOC_FREEZEDRY_VERSION 3 + +typedef struct { + unsigned version; + unsigned nszones; + szone_t *szones; +} malloc_frozen; + +static void *frozen_malloc(szone_t *zone, size_t new_size) { + return malloc(new_size); +} + +static void *frozen_calloc(szone_t *zone, size_t num_items, size_t size) { + return calloc(num_items, size); +} + +static void *frozen_valloc(szone_t *zone, size_t new_size) { + return valloc(new_size); +} + +static void *frozen_realloc(szone_t *zone, void *ptr, size_t new_size) { + size_t old_size = szone_size(zone, ptr); + void *new_ptr; + + if (new_size <= old_size) { + return ptr; + } + + new_ptr = malloc(new_size); + + if (old_size > 0) { + memcpy(new_ptr, ptr, old_size); + } + + return new_ptr; +} + +static void frozen_free(szone_t *zone, void *ptr) { +} + +static void frozen_destroy(szone_t *zone) { +} + +/********* Pseudo-private API for emacs unexec ************/ + +/* + * malloc_freezedry() records all of the szones in use, so that they can be + * partially reconstituted by malloc_jumpstart(). Due to the differences + * between reconstituted memory regions and those created by the szone code, + * care is taken not to reallocate from the freezedried memory, except in the + * case of a non-growing realloc(). + * + * Due to the flexibility provided by the zone registration mechanism, it is + * impossible to implement generic freezedrying for any zone type. This code + * only handles applications that use the szone allocator, so malloc_freezedry() + * returns 0 (error) if any non-szone zones are encountered. + */ + +int malloc_freezedry(void) { + extern unsigned malloc_num_zones; + extern malloc_zone_t **malloc_zones; + malloc_frozen *data; + unsigned i; + + /* Allocate space in which to store the freezedry state. */ + data = (malloc_frozen *) malloc(sizeof(malloc_frozen)); + + /* Set freezedry version number so that malloc_jumpstart() can check for + * compatibility. */ + data->version = MALLOC_FREEZEDRY_VERSION; + + /* Allocate the array of szone pointers. */ + data->nszones = malloc_num_zones; + data->szones = (szone_t *) calloc(malloc_num_zones, sizeof(szone_t)); + + /* Fill in the array of szone structures. They are copied rather than + * referenced, since the originals are likely to be clobbered during malloc + * initialization. */ + for (i = 0; i < malloc_num_zones; i++) { + if (strcmp(malloc_zones[i]->zone_name, "DefaultMallocZone")) { + /* Unknown zone type. */ + free(data->szones); + free(data); + return 0; + } + memcpy(&data->szones[i], malloc_zones[i], sizeof(szone_t)); + } + + return (int) data; +} + +int malloc_jumpstart(int cookie) { + malloc_frozen *data = (malloc_frozen *) cookie; + unsigned i; + + if (data->version != MALLOC_FREEZEDRY_VERSION) { + /* Unsupported freezedry version. */ + return 1; + } + + for (i = 0; i < data->nszones; i++) { + /* Set function pointers. Even the functions that stay the same must be + * set, since there are no guarantees that they will be mapped to the + * same addresses. */ + data->szones[i].basic_zone.size = (void *) szone_size; + data->szones[i].basic_zone.malloc = (void *) frozen_malloc; + data->szones[i].basic_zone.calloc = (void *) frozen_calloc; + data->szones[i].basic_zone.valloc = (void *) frozen_valloc; + data->szones[i].basic_zone.free = (void *) frozen_free; + data->szones[i].basic_zone.realloc = (void *) frozen_realloc; + data->szones[i].basic_zone.destroy = (void *) frozen_destroy; + data->szones[i].basic_zone.introspect = &szone_introspect; + + /* Register the freezedried zone. */ + malloc_zone_register(&data->szones[i].basic_zone); + } + + return 0; +} diff --git a/gen/scalable_malloc.h b/gen/scalable_malloc.h new file mode 100644 index 0000000..8891c3d --- /dev/null +++ b/gen/scalable_malloc.h @@ -0,0 +1,47 @@ +/* + * Copyright (c) 1999 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@ + */ + +#import + +#define SCALABLE_MALLOC_ADD_GUARD_PAGES (1 << 0) + // add a guard page before and after each VM region to help debug +#define SCALABLE_MALLOC_DONT_PROTECT_PRELUDE (1 << 1) + // do not protect prelude page +#define SCALABLE_MALLOC_DONT_PROTECT_POSTLUDE (1 << 2) + // do not protect postlude page +#define SCALABLE_MALLOC_DO_SCRIBBLE (1 << 3) + // write 0x55 onto free blocks + +extern malloc_zone_t *create_scalable_zone(size_t initial_size, unsigned debug_flags); + /* Create a new zone that scales for small objects or large objects */ + +/***** Private API for debug and performance tools ********/ + +#define scalable_zone_info_count 9 // maximum number of numbers + +extern void scalable_zone_info(malloc_zone_t *zone, unsigned *info, unsigned count); + /* Fills info[] with some statistical information: + info[0]: number of objects in use + info[1]: number of bytes in use + ... + */ + diff --git a/gen/scandir.3 b/gen/scandir.3 new file mode 100644 index 0000000..f2a24e6 --- /dev/null +++ b/gen/scandir.3 @@ -0,0 +1,109 @@ +.\" Copyright (c) 1983, 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. +.\" +.\" @(#)scandir.3 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD: src/lib/libc/gen/scandir.3,v 1.7 2001/10/01 16:08:51 ru Exp $ +.\" +.Dd June 4, 1993 +.Dt SCANDIR 3 +.Os +.Sh NAME +.Nm scandir , +.Nm alphasort +.Nd scan a directory +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In sys/types.h +.In dirent.h +.Ft int +.Fn scandir "const char *dirname" "struct dirent ***namelist" "int \\*(lp*select\\*(rp\\*(lpstruct dirent *\\*(rp" "int \\*(lp*compar\\*(rp\\*(lpconst void *, const void *\\*(rp" +.Ft int +.Fn alphasort "const void *d1" "const void *d2" +.Sh DESCRIPTION +The +.Fn scandir +function +reads the directory +.Fa dirname +and builds an array of pointers to directory +entries using +.Xr malloc 3 . +It returns the number of entries in the array. +A pointer to the array of directory entries is stored in the location +referenced by +.Fa namelist . +.Pp +The +.Fa select +parameter is a pointer to a user supplied subroutine which is called by +.Fn scandir +to select which entries are to be included in the array. +The select routine is passed a +pointer to a directory entry and should return a non-zero +value if the directory entry is to be included in the array. +If +.Fa select +is null, then all the directory entries will be included. +.Pp +The +.Fa compar +parameter is a pointer to a user supplied subroutine which is passed to +.Xr qsort 3 +to sort the completed array. +If this pointer is null, the array is not sorted. +.Pp +The +.Fn alphasort +function +is a routine which can be used for the +.Fa compar +parameter to sort the array alphabetically. +.Pp +The memory allocated for the array can be deallocated with +.Xr free 3 , +by freeing each pointer in the array and then the array itself. +.Sh DIAGNOSTICS +Returns \-1 if the directory cannot be opened for reading or if +.Xr malloc 3 +cannot allocate enough memory to hold all the data structures. +.Sh SEE ALSO +.Xr directory 3 , +.Xr malloc 3 , +.Xr qsort 3 , +.Xr dir 5 +.Sh HISTORY +The +.Fn scandir +and +.Fn alphasort +functions appeared in +.Bx 4.2 . diff --git a/gen/scandir.c b/gen/scandir.c new file mode 100644 index 0000000..d963bbd --- /dev/null +++ b/gen/scandir.c @@ -0,0 +1,153 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1983, 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. + */ + + +/* + * Scan the directory dirname calling select to make a list of selected + * directory entries then sort using qsort and compare routine dcomp. + * Returns the number of entries and a pointer to a list of pointers to + * struct dirent (through namelist). Returns -1 if there were any errors. + */ + +#include +#include +#include +#include +#include + +/* + * The DIRSIZ macro is the minimum record length which will hold the directory + * entry. This requires the amount of space in struct dirent without the + * d_name field, plus enough space for the name and a terminating nul byte + * (dp->d_namlen + 1), rounded up to a 4 byte boundary. + */ +#undef DIRSIZ +#define DIRSIZ(dp) \ + ((sizeof(struct dirent) - sizeof(dp)->d_name) + \ + (((dp)->d_namlen + 1 + 3) &~ 3)) + +int +scandir(dirname, namelist, select, dcomp) + const char *dirname; + struct dirent ***namelist; + int (*select) __P((struct dirent *)); + int (*dcomp) __P((const void *, const void *)); +{ + register struct dirent *d, *p, **names; + register size_t nitems; + struct stat stb; + long arraysz; + DIR *dirp; + + if ((dirp = opendir(dirname)) == NULL) + return(-1); + if (fstat(dirp->dd_fd, &stb) < 0) + return(-1); + + /* + * estimate the array size by taking the size of the directory file + * and dividing it by a multiple of the minimum size entry. + */ + arraysz = (stb.st_size / 24); + names = (struct dirent **)malloc(arraysz * sizeof(struct dirent *)); + if (names == NULL) + return(-1); + + nitems = 0; + while ((d = readdir(dirp)) != NULL) { + if (select != NULL && !(*select)(d)) + continue; /* just selected names */ + /* + * Make a minimum size copy of the data + */ + p = (struct dirent *)malloc(DIRSIZ(d)); + if (p == NULL) + return(-1); + p->d_ino = d->d_ino; + p->d_reclen = d->d_reclen; + p->d_namlen = d->d_namlen; + bcopy(d->d_name, p->d_name, p->d_namlen + 1); + /* + * Check to make sure the array has space left and + * realloc the maximum size. + */ + if (++nitems >= arraysz) { + if (fstat(dirp->dd_fd, &stb) < 0) + return(-1); /* just might have grown */ + arraysz = stb.st_size / 12; + names = (struct dirent **)realloc((char *)names, + arraysz * sizeof(struct dirent *)); + if (names == NULL) + return(-1); + } + names[nitems-1] = p; + } + closedir(dirp); + if (nitems && dcomp != NULL) + qsort(names, nitems, sizeof(struct dirent *), dcomp); + *namelist = names; + return(nitems); +} + +/* + * Alphabetic order comparison routine for those who want it. + */ +int +alphasort(d1, d2) + const void *d1; + const void *d2; +{ + return(strcmp((*(struct dirent **)d1)->d_name, + (*(struct dirent **)d2)->d_name)); +} diff --git a/gen/seed48.c b/gen/seed48.c new file mode 100644 index 0000000..258c4ba --- /dev/null +++ b/gen/seed48.c @@ -0,0 +1,36 @@ +/* + * Copyright (c) 1993 Martin Birgmeier + * All rights reserved. + * + * You may redistribute unmodified or modified versions of this source + * code provided that the above copyright notice and this and the + * following conditions are retained. + * + * This software is provided ``as is'', and comes with no warranties + * of any kind. I shall in no event be liable for anything that happens + * to anyone/anything when using this software. + */ + +#include "rand48.h" + +extern unsigned short _rand48_seed[3]; +extern unsigned short _rand48_mult[3]; +extern unsigned short _rand48_add; + +unsigned short * +seed48(unsigned short xseed[3]) +{ + static unsigned short sseed[3]; + + sseed[0] = _rand48_seed[0]; + sseed[1] = _rand48_seed[1]; + sseed[2] = _rand48_seed[2]; + _rand48_seed[0] = xseed[0]; + _rand48_seed[1] = xseed[1]; + _rand48_seed[2] = xseed[2]; + _rand48_mult[0] = RAND48_MULT_0; + _rand48_mult[1] = RAND48_MULT_1; + _rand48_mult[2] = RAND48_MULT_2; + _rand48_add = RAND48_ADD; + return sseed; +} diff --git a/gen/seekdir.c b/gen/seekdir.c new file mode 100644 index 0000000..b005ed2 --- /dev/null +++ b/gen/seekdir.c @@ -0,0 +1,70 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1983, 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 +#include + +/* + * Seek to an entry in a directory. + * _seekdir is in telldir.c so that it can share opaque data structures. + */ +void +seekdir(dirp, loc) + DIR *dirp; + long loc; +{ + + _seekdir(dirp, loc); +} diff --git a/gen/sethostname.c b/gen/sethostname.c new file mode 100644 index 0000000..7947676 --- /dev/null +++ b/gen/sethostname.c @@ -0,0 +1,77 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1989, 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 +#include + +#if __STDC__ +long +sethostname(const char *name, int namelen) +#else +long +sethostname(name, namelen) + char *name; + int namelen; +#endif +{ + int mib[2]; + + mib[0] = CTL_KERN; + mib[1] = KERN_HOSTNAME; + if (sysctl(mib, 2, NULL, NULL, (void *)name, namelen) == -1) + return (-1); + return (0); +} + + diff --git a/gen/setjmp.3 b/gen/setjmp.3 new file mode 100644 index 0000000..7707734 --- /dev/null +++ b/gen/setjmp.3 @@ -0,0 +1,176 @@ +.\" 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. +.\" +.\" @(#)setjmp.3 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD: src/lib/libc/gen/setjmp.3,v 1.9 2001/10/01 16:08:51 ru Exp $ +.\" +.Dd June 4, 1993 +.Dt SETJMP 3 +.Os +.Sh NAME +.Nm sigsetjmp , +.Nm siglongjmp , +.Nm setjmp , +.Nm longjmp , +.Nm _setjmp , +.Nm _longjmp , +.Nm longjmperror +.Nd non-local jumps +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In setjmp.h +.Ft int +.Fn sigsetjmp "sigjmp_buf env" "int savemask" +.Ft void +.Fn siglongjmp "sigjmp_buf env" "int val" +.Ft int +.Fn setjmp "jmp_buf env" +.Ft void +.Fn longjmp "jmp_buf env" "int val" +.Ft int +.Fn _setjmp "jmp_buf env" +.Ft void +.Fn _longjmp "jmp_buf env" "int val" +.Ft void +.Fn longjmperror void +.Sh DESCRIPTION +The +.Fn sigsetjmp , +.Fn setjmp , +and +.Fn _setjmp +functions save their calling environment in +.Fa env . +Each of these functions returns 0. +.Pp +The corresponding +.Fn longjmp +functions restore the environment saved by their most recent respective +invocations +of the +.Fn setjmp +function. +They then return so that program execution continues as if the corresponding +invocation of the +.Fn setjmp +call had just returned the value specified by +.Fa val , +instead of 0. +.Pp +Pairs of calls may be intermixed, i.e. both +.Fn sigsetjmp +and +.Fn siglongjmp +and +.Fn setjmp +and +.Fn longjmp +combinations may be used in the same program, however, individual +calls may not, e.g. the +.Fa env +argument to +.Fn setjmp +may not be passed to +.Fn siglongjmp . +.Pp +The +.Fn longjmp +routines may not be called after the routine which called the +.Fn setjmp +routines returns. +.Pp +All accessible objects have values as of the time +.Fn longjmp +routine was called, except that the values of objects of automatic storage +invocation duration that do not have the +.Em volatile +type and have been changed between the +.Fn setjmp +invocation and +.Fn longjmp +call are indeterminate. +.Pp +The +.Fn setjmp Ns / Ns Fn longjmp +pairs save and restore the signal mask while +.Fn _setjmp Ns / Ns Fn _longjmp +pairs save and restore only the register set and the stack. +(See +.Fn sigprocmask 2 . ) +.Pp +The +.Fn sigsetjmp Ns / Ns Fn siglongjmp +function +pairs save and restore the signal mask if the argument +.Fa savemask +is non-zero, otherwise only the register set and the stack are saved. +.Sh ERRORS +If the contents of the +.Fa env +are corrupted, or correspond to an environment that has already returned, +the +.Fn longjmp +routine calls the routine +.Fn longjmperror 3 . +If +.Fn longjmperror +returns the program is aborted (see +.Xr abort 3 ) . +The default version of +.Fn longjmperror +prints the message +.Dq Li longjmp botch +to standard error and returns. +User programs wishing to exit more gracefully should write their own +versions of +.Fn longjmperror . +.Sh SEE ALSO +.Xr sigaction 2 , +.Xr sigaltstack 2 , +.Xr signal 3 +.Sh STANDARDS +The +.Fn setjmp +and +.Fn longjmp +functions conform to +.St -isoC . +The +.Fn sigsetjmp +and +.Fn siglongjmp +functions conform to +.St -p1003.1-88 . diff --git a/gen/setlogin.c b/gen/setlogin.c new file mode 100644 index 0000000..5c6b5a3 --- /dev/null +++ b/gen/setlogin.c @@ -0,0 +1,63 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1988, 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 + +extern int _logname_valid; /* shared with getlogin() */ + +int setlogin(const char* name) +{ + return (_logname_valid = _setlogin(name)); +} diff --git a/gen/setmode.3 b/gen/setmode.3 new file mode 100644 index 0000000..07909bd --- /dev/null +++ b/gen/setmode.3 @@ -0,0 +1,118 @@ +.\" Copyright (c) 1989, 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. +.\" +.\" @(#)setmode.3 8.2 (Berkeley) 4/28/95 +.\" $FreeBSD: src/lib/libc/gen/setmode.3,v 1.8.2.3 2001/12/14 18:33:51 ru Exp $ +.\" +.Dd April 28, 1995 +.Dt SETMODE 3 +.Os +.Sh NAME +.Nm getmode , +.Nm setmode +.Nd modify mode bits +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In unistd.h +.Ft mode_t +.Fn getmode "const void *set" "mode_t mode" +.Ft void * +.Fn setmode "const char *mode_str" +.Sh DESCRIPTION +The +.Fn getmode +function +returns a copy of the file permission bits +.Fa mode +as altered by the values pointed to by +.Fa set . +While only the mode bits are altered, other parts of the file mode +may be examined. +.Pp +The +.Fn setmode +function +takes an absolute (octal) or symbolic value, as described in +.Xr chmod 1 , +as an argument +and returns a pointer to mode values to be supplied to +.Fn getmode . +Because some of the symbolic values are relative to the file +creation mask, +.Fn setmode +may call +.Xr umask 2 . +If this occurs, the file creation mask will be restored before +.Fn setmode +returns. +If the calling program changes the value of its file creation mask +after calling +.Fn setmode , +.Fn setmode +must be called again if +.Fn getmode +is to modify future file modes correctly. +.Pp +If the mode passed to +.Fn setmode +is invalid or if memory cannot be allocated for the return value, +.Fn setmode +returns +.Dv NULL . +.Pp +The value returned from +.Fn setmode +is obtained from +.Fn malloc +and should be returned to the system with +.Fn free +when the program is done with it, generally after a call to +.Fn getmode . +.Sh ERRORS +The +.Fn setmode +function +may fail and set errno for any of the errors specified for the library +routine +.Xr malloc 3 . +.Sh SEE ALSO +.Xr chmod 1 , +.Xr stat 2 , +.Xr umask 2 , +.Xr malloc 3 +.Sh HISTORY +The +.Fn getmode +and +.Fn setmode +functions first appeared in +.Bx 4.4 . diff --git a/gen/setmode.c b/gen/setmode.c new file mode 100644 index 0000000..181af06 --- /dev/null +++ b/gen/setmode.c @@ -0,0 +1,456 @@ +/* + * Copyright (c) 1989, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Dave Borman at Cray Research, 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. + */ + +#if defined(LIBC_SCCS) && !defined(lint) +#if 0 +static char sccsid[] = "@(#)setmode.c 8.2 (Berkeley) 3/25/94"; +#endif +static const char rcsid[] = + "$FreeBSD: src/lib/libc/gen/setmode.c,v 1.5.2.1 2001/03/05 09:34:10 obrien Exp $"; +#endif /* LIBC_SCCS and not lint */ + +#include +#include + +#include +#include +#include +#include + +#ifdef SETMODE_DEBUG +#include +#endif + +#define SET_LEN 6 /* initial # of bitcmd struct to malloc */ +#define SET_LEN_INCR 4 /* # of bitcmd structs to add as needed */ + +typedef struct bitcmd { + char cmd; + char cmd2; + mode_t bits; +} BITCMD; + +#define CMD2_CLR 0x01 +#define CMD2_SET 0x02 +#define CMD2_GBITS 0x04 +#define CMD2_OBITS 0x08 +#define CMD2_UBITS 0x10 + +static BITCMD *addcmd __P((BITCMD *, int, int, int, u_int)); +static void compress_mode __P((BITCMD *)); +#ifdef SETMODE_DEBUG +static void dumpmode __P((BITCMD *)); +#endif + +/* + * Given the old mode and an array of bitcmd structures, apply the operations + * described in the bitcmd structures to the old mode, and return the new mode. + * Note that there is no '=' command; a strict assignment is just a '-' (clear + * bits) followed by a '+' (set bits). + */ +mode_t +getmode(bbox, omode) + void *bbox; + mode_t omode; +{ + register BITCMD *set; + register mode_t clrval, newmode, value; + + set = (BITCMD *)bbox; + newmode = omode; + for (value = 0;; set++) + switch(set->cmd) { + /* + * When copying the user, group or other bits around, we "know" + * where the bits are in the mode so that we can do shifts to + * copy them around. If we don't use shifts, it gets real + * grundgy with lots of single bit checks and bit sets. + */ + case 'u': + value = (newmode & S_IRWXU) >> 6; + goto common; + + case 'g': + value = (newmode & S_IRWXG) >> 3; + goto common; + + case 'o': + value = newmode & S_IRWXO; +common: if (set->cmd2 & CMD2_CLR) { + clrval = + (set->cmd2 & CMD2_SET) ? S_IRWXO : value; + if (set->cmd2 & CMD2_UBITS) + newmode &= ~((clrval<<6) & set->bits); + if (set->cmd2 & CMD2_GBITS) + newmode &= ~((clrval<<3) & set->bits); + if (set->cmd2 & CMD2_OBITS) + newmode &= ~(clrval & set->bits); + } + if (set->cmd2 & CMD2_SET) { + if (set->cmd2 & CMD2_UBITS) + newmode |= (value<<6) & set->bits; + if (set->cmd2 & CMD2_GBITS) + newmode |= (value<<3) & set->bits; + if (set->cmd2 & CMD2_OBITS) + newmode |= value & set->bits; + } + break; + + case '+': + newmode |= set->bits; + break; + + case '-': + newmode &= ~set->bits; + break; + + case 'X': + if (omode & (S_IFDIR|S_IXUSR|S_IXGRP|S_IXOTH)) + newmode |= set->bits; + break; + + case '\0': + default: +#ifdef SETMODE_DEBUG + (void)printf("getmode:%04o -> %04o\n", omode, newmode); +#endif + return (newmode); + } +} + +#define ADDCMD(a, b, c, d) \ + if (set >= endset) { \ + register BITCMD *newset; \ + setlen += SET_LEN_INCR; \ + newset = realloc(saveset, sizeof(BITCMD) * setlen); \ + if (!saveset) \ + return (NULL); \ + set = newset + (set - saveset); \ + saveset = newset; \ + endset = newset + (setlen - 2); \ + } \ + set = addcmd(set, (a), (b), (c), (d)) + +#define STANDARD_BITS (S_ISUID|S_ISGID|S_IRWXU|S_IRWXG|S_IRWXO) + +void * +setmode(p) + register char *p; +{ + register int perm, who; + register char op; + BITCMD *set, *saveset, *endset; + sigset_t sigset, sigoset; + mode_t mask; + int equalopdone=0, permXbits, setlen; + + if (!*p) + return (NULL); + + /* + * Get a copy of the mask for the permissions that are mask relative. + * Flip the bits, we want what's not set. Since it's possible that + * the caller is opening files inside a signal handler, protect them + * as best we can. + */ + sigfillset(&sigset); + (void)sigprocmask(SIG_BLOCK, &sigset, &sigoset); + (void)umask(mask = umask(0)); + mask = ~mask; + (void)sigprocmask(SIG_SETMASK, &sigoset, NULL); + + setlen = SET_LEN + 2; + + if ((set = malloc((u_int)(sizeof(BITCMD) * setlen))) == NULL) + return (NULL); + saveset = set; + endset = set + (setlen - 2); + + /* + * If an absolute number, get it and return; disallow non-octal digits + * or illegal bits. + */ + if (isdigit((unsigned char)*p)) { + perm = (mode_t)strtol(p, NULL, 8); + if (perm & ~(STANDARD_BITS|S_ISTXT)) { + free(saveset); + return (NULL); + } + while (*++p) + if (*p < '0' || *p > '7') { + free(saveset); + return (NULL); + } + ADDCMD('=', (STANDARD_BITS|S_ISTXT), perm, mask); + return (saveset); + } + + /* + * Build list of structures to set/clear/copy bits as described by + * each clause of the symbolic mode. + */ + for (;;) { + /* First, find out which bits might be modified. */ + for (who = 0;; ++p) { + switch (*p) { + case 'a': + who |= STANDARD_BITS; + break; + case 'u': + who |= S_ISUID|S_IRWXU; + break; + case 'g': + who |= S_ISGID|S_IRWXG; + break; + case 'o': + who |= S_IRWXO; + break; + default: + goto getop; + } + } + +getop: if ((op = *p++) != '+' && op != '-' && op != '=') { + free(saveset); + return (NULL); + } + if (op == '=') + equalopdone = 0; + + who &= ~S_ISTXT; + for (perm = 0, permXbits = 0;; ++p) { + switch (*p) { + case 'r': + perm |= S_IRUSR|S_IRGRP|S_IROTH; + break; + case 's': + /* If only "other" bits ignore set-id. */ + if (!who || who & ~S_IRWXO) + perm |= S_ISUID|S_ISGID; + break; + case 't': + /* If only "other" bits ignore sticky. */ + if (!who || who & ~S_IRWXO) { + who |= S_ISTXT; + perm |= S_ISTXT; + } + break; + case 'w': + perm |= S_IWUSR|S_IWGRP|S_IWOTH; + break; + case 'X': + permXbits = S_IXUSR|S_IXGRP|S_IXOTH; + break; + case 'x': + perm |= S_IXUSR|S_IXGRP|S_IXOTH; + break; + case 'u': + case 'g': + case 'o': + /* + * When ever we hit 'u', 'g', or 'o', we have + * to flush out any partial mode that we have, + * and then do the copying of the mode bits. + */ + if (perm) { + ADDCMD(op, who, perm, mask); + perm = 0; + } + if (op == '=') + equalopdone = 1; + if (op == '+' && permXbits) { + ADDCMD('X', who, permXbits, mask); + permXbits = 0; + } + ADDCMD(*p, who, op, mask); + break; + + default: + /* + * Add any permissions that we haven't already + * done. + */ + if (perm || (op == '=' && !equalopdone)) { + if (op == '=') + equalopdone = 1; + ADDCMD(op, who, perm, mask); + perm = 0; + } + if (permXbits) { + ADDCMD('X', who, permXbits, mask); + permXbits = 0; + } + goto apply; + } + } + +apply: if (!*p) + break; + if (*p != ',') + goto getop; + ++p; + } + set->cmd = 0; +#ifdef SETMODE_DEBUG + (void)printf("Before compress_mode()\n"); + dumpmode(saveset); +#endif + compress_mode(saveset); +#ifdef SETMODE_DEBUG + (void)printf("After compress_mode()\n"); + dumpmode(saveset); +#endif + return (saveset); +} + +static BITCMD * +addcmd(set, op, who, oparg, mask) + BITCMD *set; + register int oparg, who; + register int op; + u_int mask; +{ + switch (op) { + case '=': + set->cmd = '-'; + set->bits = who ? who : STANDARD_BITS; + set++; + + op = '+'; + /* FALLTHROUGH */ + case '+': + case '-': + case 'X': + set->cmd = op; + set->bits = (who ? who : mask) & oparg; + break; + + case 'u': + case 'g': + case 'o': + set->cmd = op; + if (who) { + set->cmd2 = ((who & S_IRUSR) ? CMD2_UBITS : 0) | + ((who & S_IRGRP) ? CMD2_GBITS : 0) | + ((who & S_IROTH) ? CMD2_OBITS : 0); + set->bits = ~0; + } else { + set->cmd2 = CMD2_UBITS | CMD2_GBITS | CMD2_OBITS; + set->bits = mask; + } + + if (oparg == '+') + set->cmd2 |= CMD2_SET; + else if (oparg == '-') + set->cmd2 |= CMD2_CLR; + else if (oparg == '=') + set->cmd2 |= CMD2_SET|CMD2_CLR; + break; + } + return (set + 1); +} + +#ifdef SETMODE_DEBUG +static void +dumpmode(set) + register BITCMD *set; +{ + for (; set->cmd; ++set) + (void)printf("cmd: '%c' bits %04o%s%s%s%s%s%s\n", + set->cmd, set->bits, set->cmd2 ? " cmd2:" : "", + set->cmd2 & CMD2_CLR ? " CLR" : "", + set->cmd2 & CMD2_SET ? " SET" : "", + set->cmd2 & CMD2_UBITS ? " UBITS" : "", + set->cmd2 & CMD2_GBITS ? " GBITS" : "", + set->cmd2 & CMD2_OBITS ? " OBITS" : ""); +} +#endif + +/* + * Given an array of bitcmd structures, compress by compacting consecutive + * '+', '-' and 'X' commands into at most 3 commands, one of each. The 'u', + * 'g' and 'o' commands continue to be separate. They could probably be + * compacted, but it's not worth the effort. + */ +static void +compress_mode(set) + register BITCMD *set; +{ + register BITCMD *nset; + register int setbits, clrbits, Xbits, op; + + for (nset = set;;) { + /* Copy over any 'u', 'g' and 'o' commands. */ + while ((op = nset->cmd) != '+' && op != '-' && op != 'X') { + *set++ = *nset++; + if (!op) + return; + } + + for (setbits = clrbits = Xbits = 0;; nset++) { + if ((op = nset->cmd) == '-') { + clrbits |= nset->bits; + setbits &= ~nset->bits; + Xbits &= ~nset->bits; + } else if (op == '+') { + setbits |= nset->bits; + clrbits &= ~nset->bits; + Xbits &= ~nset->bits; + } else if (op == 'X') + Xbits |= nset->bits & ~setbits; + else + break; + } + if (clrbits) { + set->cmd = '-'; + set->cmd2 = 0; + set->bits = clrbits; + set++; + } + if (setbits) { + set->cmd = '+'; + set->cmd2 = 0; + set->bits = setbits; + set++; + } + if (Xbits) { + set->cmd = 'X'; + set->cmd2 = 0; + set->bits = Xbits; + set++; + } + } +} diff --git a/gen/siginterrupt.3 b/gen/siginterrupt.3 new file mode 100644 index 0000000..d587425 --- /dev/null +++ b/gen/siginterrupt.3 @@ -0,0 +1,122 @@ +.\" Copyright (c) 1985, 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. +.\" +.\" @(#)siginterrupt.3 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD: src/lib/libc/gen/siginterrupt.3,v 1.13 2001/10/01 16:08:51 ru Exp $ +.\" +.Dd June 4, 1993 +.Dt SIGINTERRUPT 3 +.Os +.Sh NAME +.Nm siginterrupt +.Nd allow signals to interrupt system calls +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In signal.h +.Ft int +.Fn siginterrupt "int sig" "int flag" +.Sh DESCRIPTION +The +.Fn siginterrupt +function +is used to change the system call restart +behavior when a system call is interrupted by the specified signal. +If the flag is false (0), then system calls will be restarted if +they are interrupted by the specified signal +and no data has been transferred yet. +System call restart has been the default behavior since +.Bx 4.2 , +and is the default behaviour for +.Xr signal 3 +on +.Fx . +.Pp +If the flag is true (1), +then restarting of system calls is disabled. +If a system call is interrupted by the specified signal +and no data has been transferred, +the system call will return \-1 with the global variable +.Va errno +set to +.Er EINTR . +Interrupted system calls that have started transferring +data will return the amount of data actually transferred. +System call interrupt is the signal behavior found on +.Bx 4.1 +and +.At V +systems. +.Pp +Note that the new +.Bx 4.2 +signal handling semantics are not +altered in any other way. +Most notably, signal handlers always remain installed until +explicitly changed by a subsequent +.Xr sigaction 2 +call, and the signal mask operates as documented in +.Xr sigaction 2 . +Programs may switch between restartable and interruptible +system call operation as often as desired in the execution of a program. +.Pp +Issuing a +.Fn siginterrupt 3 +call during the execution of a signal handler will cause +the new action to take place on the next signal to be caught. +.Sh NOTES +This library routine uses an extension of the +.Xr sigaction 2 +system call that is not available in +.Bx 4.2 , +hence it should not be used if backward compatibility is needed. +.Sh RETURN VALUES +.Rv -std siginterrupt +.Sh ERRORS +The +.Fn siginterrupt +call fails if: +.Bl -tag -width Er +.It Bq Er EINVAL +.Fa sig +is not a valid signal number. +.El +.Sh SEE ALSO +.Xr sigaction 2 , +.Xr sigblock 2 , +.Xr sigpause 2 , +.Xr sigsetmask 2 , +.Xr signal 3 +.Sh HISTORY +The +.Fn siginterrupt +function appeared in +.Bx 4.3 . diff --git a/gen/siginterrupt.c b/gen/siginterrupt.c new file mode 100644 index 0000000..591f73c --- /dev/null +++ b/gen/siginterrupt.c @@ -0,0 +1,79 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1989, 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 + +/* + * Set signal state to prevent restart of system calls + * after an instance of the indicated signal. + */ +siginterrupt(sig, flag) + int sig, flag; +{ + extern sigset_t _sigintr; + struct sigaction sa; + int ret; + + if ((ret = sigaction(sig, (struct sigaction *)0, &sa)) < 0) + return (ret); + if (flag) { + sigaddset(&_sigintr, sig); + sa.sa_flags &= ~SA_RESTART; + } else { + sigdelset(&_sigintr, sig); + sa.sa_flags |= SA_RESTART; + } + return (sigaction(sig, &sa, (struct sigaction *)0)); +} diff --git a/gen/siglist.c b/gen/siglist.c new file mode 100644 index 0000000..5c700fe --- /dev/null +++ b/gen/siglist.c @@ -0,0 +1,127 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1983, 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 +#include + +const char *const sys_signame[NSIG] = { + "Signal 0", + "hup", /* SIGHUP */ + "int", /* SIGINT */ + "quit", /* SIGQUIT */ + "ill", /* SIGILL */ + "trap", /* SIGTRAP */ + "abrt", /* SIGABRT */ + "emt", /* SIGEMT */ + "fpe", /* SIGFPE */ + "kill", /* SIGKILL */ + "bus", /* SIGBUS */ + "segv", /* SIGSEGV */ + "sys", /* SIGSYS */ + "pipe", /* SIGPIPE */ + "alrm", /* SIGALRM */ + "term", /* SIGTERM */ + "urg", /* SIGURG */ + "stop", /* SIGSTOP */ + "tstp", /* SIGTSTP */ + "cont", /* SIGCONT */ + "chld", /* SIGCHLD */ + "ttin", /* SIGTTIN */ + "ttou", /* SIGTTOU */ + "io", /* SIGIO */ + "xcpu", /* SIGXCPU */ + "xfsz", /* SIGXFSZ */ + "vtalrm", /* SIGVTALRM */ + "prof", /* SIGPROF */ + "winch", /* SIGWINCH */ + "info", /* SIGINFO */ + "usr1", /* SIGUSR1 */ + "usr2", /* SIGUSR2 */ +}; + +const char *const sys_siglist[NSIG] = { + "Signal 0", + "Hangup", /* SIGHUP */ + "Interrupt", /* SIGINT */ + "Quit", /* SIGQUIT */ + "Illegal instruction", /* SIGILL */ + "Trace/BPT trap", /* SIGTRAP */ + "Abort trap", /* SIGABRT */ + "EMT trap", /* SIGEMT */ + "Floating point exception", /* SIGFPE */ + "Killed", /* SIGKILL */ + "Bus error", /* SIGBUS */ + "Segmentation fault", /* SIGSEGV */ + "Bad system call", /* SIGSYS */ + "Broken pipe", /* SIGPIPE */ + "Alarm clock", /* SIGALRM */ + "Terminated", /* SIGTERM */ + "Urgent I/O condition", /* SIGURG */ + "Suspended (signal)", /* SIGSTOP */ + "Suspended", /* SIGTSTP */ + "Continued", /* SIGCONT */ + "Child exited", /* SIGCHLD */ + "Stopped (tty input)", /* SIGTTIN */ + "Stopped (tty output)", /* SIGTTOU */ + "I/O possible", /* SIGIO */ + "Cputime limit exceeded", /* SIGXCPU */ + "Filesize limit exceeded", /* SIGXFSZ */ + "Virtual timer expired", /* SIGVTALRM */ + "Profiling timer expired", /* SIGPROF */ + "Window size changes", /* SIGWINCH */ + "Information request", /* SIGINFO */ + "User defined signal 1", /* SIGUSR1 */ + "User defined signal 2" /* SIGUSR2 */ +}; diff --git a/gen/signal.3 b/gen/signal.3 new file mode 100644 index 0000000..6073b7b --- /dev/null +++ b/gen/signal.3 @@ -0,0 +1,243 @@ +.\" 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. +.\" +.\" @(#)signal.3 8.3 (Berkeley) 4/19/94 +.\" $FreeBSD: src/lib/libc/gen/signal.3,v 1.28 2001/10/01 16:08:51 ru Exp $ +.\" +.Dd April 19, 1994 +.Dt SIGNAL 3 +.Os +.Sh NAME +.Nm signal +.Nd simplified software signal facilities +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In signal.h +.\" 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 +or in +.Fx Ns 's +equivalent but easier to read typedef'd version: +.Ft typedef "void \*(lp*sig_t\*(rp \*(lpint\*(rp" +.Ft sig_t +.Fn signal "int sig" "sig_t func" +.Sh DESCRIPTION +This +.Fn signal +facility +is a simplified interface to the more general +.Xr sigaction 2 +facility. +.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: +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 +typing the `interrupt' character. +Signals are used when a process is stopped because it wishes to access +its control terminal while in the background (see +.Xr tty 4 ) . +Signals are optionally generated +when a process resumes after being stopped, +when the status of child processes changes, +or when input is ready at the control terminal. +Most signals result in the termination of the process receiving them +if no action +is taken; some signals instead cause the process receiving them +to be stopped, or are simply discarded if the process has not +requested otherwise. +Except for the +.Dv SIGKILL +and +.Dv SIGSTOP +signals, the +.Fn signal +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" +(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" +is possible on a descriptor (see +.Xr fcntl 2 ) +.It 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" +.Xr setrlimit 2 ) +.It Dv SIGVTALRM Ta "terminate process" Ta "virtual time alarm (see" +.Xr setitimer 2 ) +.It 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" +.El +.Pp +The +.Fa sig +parameter specifies which signal was received. +The +.Fa func +procedure allows a user to choose the action upon receipt of a signal. +To set the default action of the signal to occur as listed above, +.Fa func +should be +.Dv SIG_DFL . +A +.Dv SIG_DFL +resets the default action. +To ignore the signal +.Fa func +should be +.Dv SIG_IGN . +This will cause subsequent instances of the signal to be ignored +and pending instances to be discarded. +If +.Dv SIG_IGN +is not used, +further occurrences of the signal are +automatically blocked and +.Fa func +is called. +.Pp +The handled signal is unblocked when the +function returns and +the process continues from where it left off when the signal occurred. +.Bf -symbolic +Unlike previous signal facilities, the handler +func() remains installed after a signal has been delivered. +.Ef +.Pp +For some system calls, if a signal is caught while the call is +executing and the call is prematurely terminated, +the call is automatically restarted. +(The handler is installed using the +.Dv SA_RESTART +flag with +.Xr sigaction 2 . ) +The affected system calls include +.Xr read 2 , +.Xr write 2 , +.Xr sendto 2 , +.Xr recvfrom 2 , +.Xr sendmsg 2 +and +.Xr recvmsg 2 +on a communications channel or a low speed device +and during a +.Xr ioctl 2 +or +.Xr wait 2 . +However, calls that have already committed are not restarted, +but instead return a partial success (for example, a short read count). +This semantics could be changed with +.Xr siginterrupt 3 . +.Pp +When a process which has installed signal handlers forks, +the child process inherits the signals. +All caught signals may be reset to their default action by a call +to the +.Xr execve 2 +function; +ignored signals remain ignored. +.Pp +See +.Xr sigaction 2 +for a list of functions +that are considered safe for use in signal handler. +.Sh RETURN VALUES +The previous action is returned on a successful call. +Otherwise, SIG_ERR is returned and the global variable +.Va errno +is set to indicate the error. +.Sh ERRORS +.Fn Signal +will fail and no action will take place if one of the +following occur: +.Bl -tag -width Er +.It Bq Er EINVAL +.Em Sig +is not a valid signal number. +.It Bq Er EINVAL +An attempt is made to ignore or supply a handler for +.Dv SIGKILL +or +.Ev SIGSTOP . +.El +.Sh SEE ALSO +.Xr kill 1 , +.Xr kill 2 , +.Xr ptrace 2 , +.Xr sigaction 2 , +.Xr sigaltstack 2 , +.Xr sigprocmask 2 , +.Xr sigsuspend 2 , +.Xr fpsetmask 3 , +.Xr setjmp 3 , +.Xr siginterrupt 3 , +.Xr tty 4 +.Sh HISTORY +This +.Fn signal +facility appeared in +.Bx 4.0 . diff --git a/gen/signal.c b/gen/signal.c new file mode 100644 index 0000000..e936bd9 --- /dev/null +++ b/gen/signal.c @@ -0,0 +1,106 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1985, 1989, 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. + */ + + +/* + * Almost backwards compatible signal. + */ +#include + +sigset_t _sigintr = 0; /* shared with siginterrupt */ + +static sig_t +signal__(s, a, bind) + int s; + sig_t a; + int bind; +{ + struct sigaction sa, osa; + + sa.sa_handler = a; + sigemptyset(&sa.sa_mask); + sa.sa_flags = 0; + if (!sigismember(&_sigintr, s)) + sa.sa_flags |= SA_RESTART; +#if defined(__DYNAMIC__) + if (bind) { +#endif + if (sigaction(s, &sa, &osa) < 0) + return (SIG_ERR); +#if defined(__DYNAMIC__) + } else { + if (_sigaction_nobind(s, &sa, &osa) < 0) + return (SIG_ERR); + } +#endif + return (osa.sa_handler); +} + +sig_t +signal(s, a) + int s; + sig_t a; +{ + return signal__(s, a, 1); +} + +#if defined(__DYNAMIC__) +sig_t +_signal_nobind(s, a) + int s; + sig_t a; +{ + return signal__(s, a, 0); +} +#endif diff --git a/gen/sigsetops.3 b/gen/sigsetops.3 new file mode 100644 index 0000000..5c8f0dd --- /dev/null +++ b/gen/sigsetops.3 @@ -0,0 +1,116 @@ +.\" Copyright (c) 1983, 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. +.\" +.\" @(#)sigsetops.3 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD: src/lib/libc/gen/sigsetops.3,v 1.6 2001/10/01 16:08:51 ru Exp $ +.\" +.Dd June 4, 1993 +.Dt SIGSETOPS 3 +.Os +.Sh NAME +.Nm sigemptyset , +.Nm sigfillset , +.Nm sigaddset , +.Nm sigdelset , +.Nm sigismember +.Nd manipulate signal sets +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In signal.h +.Ft int +.Fn sigemptyset "sigset_t *set" +.Ft int +.Fn sigfillset "sigset_t *set" +.Ft int +.Fn sigaddset "sigset_t *set" "int signo" +.Ft int +.Fn sigdelset "sigset_t *set" "int signo" +.Ft int +.Fn sigismember "const sigset_t *set" "int signo" +.Sh DESCRIPTION +These functions manipulate signal sets stored in a +.Fa sigset_t . +Either +.Fn sigemptyset +or +.Fn sigfillset +must be called for every object of type +.Fa sigset_t +before any other use of the object. +.Pp +The +.Fn sigemptyset +function initializes a signal set to be empty. +.Pp +The +.Fn sigfillset +function initializes a signal set to contain all signals. +.Pp +The +.Fn sigaddset +function adds the specified signal +.Fa signo +to the signal set. +.Pp +The +.Fn sigdelset +function deletes the specified signal +.Fa signo +from the signal set. +.Pp +The +.Fn sigismember +function returns whether a specified signal +.Fa signo +is contained in the signal set. +.Pp +These functions +are provided as macros in the include file . +Actual functions are available +if their names are undefined (with #undef +.Em name ) . +.Sh RETURN VALUES +The +.Fn sigismember +function returns 1 +if the signal is a member of the set, +0 otherwise. +The other functions return 0. +.Sh ERRORS +Currently no errors are detected. +.Sh SEE ALSO +.Xr kill 2 , +.Xr sigaction 2 , +.Xr sigsuspend 2 +.Sh STANDARDS +These functions are defined by +.St -p1003.1-88 . diff --git a/gen/sigsetops.c b/gen/sigsetops.c new file mode 100644 index 0000000..eeca678 --- /dev/null +++ b/gen/sigsetops.c @@ -0,0 +1,112 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1989, 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 +#include + +#undef sigemptyset +#undef sigfillset +#undef sigaddset +#undef sigdelset +#undef sigismember + +sigemptyset(set) + sigset_t *set; +{ + *set = 0; + return (0); +} + +sigfillset(set) + sigset_t *set; +{ + *set = ~(sigset_t)0; + return (0); +} + +sigaddset(set, signo) + sigset_t *set; + int signo; +{ + if ((signo < 0 ) || (signo > NSIG)) { + errno = EINVAL; + return(-1); + } + *set |= sigmask(signo); + return (0); +} + +sigdelset(set, signo) + sigset_t *set; + int signo; +{ + if ((signo < 0 ) || (signo > NSIG)) { + errno = EINVAL; + return(-1); + } + *set &= ~sigmask(signo); + return (0); +} + +sigismember(set, signo) + const sigset_t *set; + int signo; +{ + if ((signo < 0 ) || (signo > NSIG)) { + errno = EINVAL; + return(-1); + } + return ((*set & ~sigmask(signo)) != 0); +} diff --git a/gen/sleep.3 b/gen/sleep.3 new file mode 100644 index 0000000..ba5985f --- /dev/null +++ b/gen/sleep.3 @@ -0,0 +1,86 @@ +.\" Copyright (c) 1986, 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. +.\" +.\" @(#)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 $ +.\" +.Dd February 13, 1998 +.Dt SLEEP 3 +.Os +.Sh NAME +.Nm sleep +.Nd suspend process execution for an interval measured in seconds +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In unistd.h +.Ft unsigned int +.Fn sleep "unsigned int seconds" +.Sh DESCRIPTION +The +.Fn sleep +function suspends execution of the calling process until either +.Fa seconds +seconds have elapsed or a signal is delivered to the process and its +action is to invoke a signal-catching function or to terminate the +process. +System activity may lengthen the sleep by an indeterminate amount. +.Pp +This function is implemented using +.Xr nanosleep 2 +by pausing for +.Fa seconds +seconds or until a signal occurs. +Consequently, in this implementation, +sleeping has no effect on the state of process timers, +and there is no special handling for SIGALRM. +.Sh RETURN VALUES +If the +.Fn sleep +function returns because the requested time has elapsed, the value +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 +slept) in seconds. +.Sh SEE ALSO +.Xr nanosleep 2 , +.Xr usleep 3 +.Sh STANDARDS +The +.Fn sleep +function conforms to +.St -p1003.1-90 . +.Sh HISTORY +A +.Fn sleep +function appeared in +.At v7 . diff --git a/gen/sleep.c b/gen/sleep.c new file mode 100644 index 0000000..e47b89e --- /dev/null +++ b/gen/sleep.c @@ -0,0 +1,46 @@ +/* + * Copyright (c) 1999 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@ + */ + +#include + +extern int nanosleep(const struct timespec *, struct timespec *); + +/* We use nanosleep and let it set errno, and compute the residual for us. */ +unsigned int +sleep(unsigned int seconds) +{ + struct timespec req, rem; + + if (seconds == 0) { + return 0; + } + req.tv_sec = seconds; + req.tv_nsec = 0; + + /* It's not clear from the spec whether the remainder will be 0 + ** if we weren't interrupted + */ + if (nanosleep(&req, &rem) == -1) { + return (unsigned int)rem.tv_sec; + } + return 0; +} diff --git a/gen/srand48.c b/gen/srand48.c new file mode 100644 index 0000000..fd369a0 --- /dev/null +++ b/gen/srand48.c @@ -0,0 +1,30 @@ +/* + * Copyright (c) 1993 Martin Birgmeier + * All rights reserved. + * + * You may redistribute unmodified or modified versions of this source + * code provided that the above copyright notice and this and the + * following conditions are retained. + * + * This software is provided ``as is'', and comes with no warranties + * of any kind. I shall in no event be liable for anything that happens + * to anyone/anything when using this software. + */ + +#include "rand48.h" + +extern unsigned short _rand48_seed[3]; +extern unsigned short _rand48_mult[3]; +extern unsigned short _rand48_add; + +void +srand48(long seed) +{ + _rand48_seed[0] = RAND48_SEED_0; + _rand48_seed[1] = (unsigned short) seed; + _rand48_seed[2] = (unsigned short) (seed >> 16); + _rand48_mult[0] = RAND48_MULT_0; + _rand48_mult[1] = RAND48_MULT_1; + _rand48_mult[2] = RAND48_MULT_2; + _rand48_add = RAND48_ADD; +} diff --git a/gen/stack_logging.c b/gen/stack_logging.c new file mode 100644 index 0000000..8389420 --- /dev/null +++ b/gen/stack_logging.c @@ -0,0 +1,384 @@ +/* + * Copyright (c) 1999 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@ + */ + +/* Bertrand from vmutils -> CF -> System */ + +#import "stack_logging.h" + +#import +#import +#import +#include + +extern void spin_lock(int *); + +static inline void *allocate_pages(unsigned bytes) { + void *address; + if (vm_allocate(mach_task_self(), (vm_address_t *)&address, bytes, + VM_MAKE_TAG(VM_MEMORY_ANALYSIS_TOOL)| TRUE)) { + address = 0; + } + return (void *)address; +} + +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 *source, void *dest, unsigned bytes) { + if (vm_copy(mach_task_self(), (vm_address_t)source, bytes, (vm_address_t)dest)) memmove(dest, source, bytes); +} + +/*************** Recording stack ***********/ + +static void *first_frame_address(void) { +#if 0 + return __builtin_frame_address(1); +#elif defined(__ppc__) + void *addr; +#warning __builtin_frame_address IS BROKEN IN BEAKER: RADAR #2340421 + __asm__ volatile("mr %0, r1" : "=r" (addr)); + return addr; +#else +#warning first_frame_address WILL NOT BE FUNCTIONAL ON THIS ARCHITECTURE + return NULL; +#endif +} + +static void *next_frame_address(void *addr) { + void *ret; +#if defined(__MACH__) && defined(__i386__) + __asm__ volatile("movl (%1),%0" : "=r" (ret) : "r" (addr)); +#elif defined(__MACH__) && defined(__ppc__) + __asm__ volatile("lwz %0,0x0(%1)" : "=r" (ret) : "b" (addr)); +#elif defined(__hpux__) + __asm__ volatile("ldw 0x0(%1),%0" : "=r" (ret) : "r" (addr)); +#elif defined(__svr4__) + __asm__ volatile("ta 0x3"); + __asm__ volatile("ld [%1 + 56],%0" : "=r" (ret) : "r" (addr)); +#else +#error Unknown architecture +#endif + return ret; +} + +#if defined(__i386__) || defined (__m68k__) +#define FP_LINK_OFFSET 1 +#elif defined(__ppc__) +#define FP_LINK_OFFSET 2 +#elif defined(__hppa__) +#define FP_LINK_OFFSET -5 +#elif defined(__sparc__) +#define FP_LINK_OFFSET 14 +#else +#error ********** Unimplemented architecture +#endif + +void thread_stack_pcs(vm_address_t *buffer, unsigned max, unsigned *nb) { + void *addr; + addr = first_frame_address(); + *nb = 0; + while ((addr >= (void *)0x800) && (max--)) { + vm_address_t fp_link = (vm_address_t)(((unsigned *)addr)+FP_LINK_OFFSET); + void *addr2; + buffer[*nb] = *((vm_address_t *)fp_link); + (*nb)++; + addr2 = next_frame_address(addr); +#if defined(__ppc__) + if ((unsigned)addr2 <= (unsigned)addr) break; // catch bozo frames +#endif + addr = addr2; + } +} + +/*************** Uniquing stack ***********/ + +#define MAX_COLLIDE 8 + +#define MAX_NUM_PC 512 + +static int enter_pair_in_table(unsigned *table, unsigned numPages, unsigned *uniquedParent, unsigned thisPC) { + // uniquedParent is in-out; return 1 is collisions max not exceeded + unsigned base = numPages * vm_page_size / (sizeof(int)*2*2); + unsigned hash = base + (((*uniquedParent) << 4) ^ (thisPC >> 2)) % (base - 1); // modulo odd number for hashing + unsigned collisions = MAX_COLLIDE; + while (collisions--) { + unsigned *head = table + hash*2; + if (! head[0] && !head[1]) { + /* end of chain; store this entry! */ + /* Note that we need to test for both head[0] and head[1] as (0, -1) is a valid entry */ + head[0] = thisPC; + head[1] = *uniquedParent; + *uniquedParent = hash; + return 1; + } + if ((head[0] == thisPC) && (head[1] == *uniquedParent)) { + /* we found the proper entry, the value for the pair is the entry offset */ + *uniquedParent = hash; + return 1; + } + hash++; + if (hash == base*2) hash = base; + } + return 0; +} + +unsigned stack_logging_get_unique_stack(unsigned **table, unsigned *table_num_pages, unsigned *stack_entries, unsigned count, unsigned num_hot_to_skip) { + unsigned uniquedParent = (unsigned)-1; + // we skip the warmest entries that are an artefact of the code + while (num_hot_to_skip--) { + if (count > 0) { stack_entries++; count--; } + } + while (count--) { + unsigned thisPC = stack_entries[count]; + while (!enter_pair_in_table(*table, *table_num_pages, &uniquedParent, thisPC)) { + unsigned *newTable; + unsigned oldBytes = (*table_num_pages) * vm_page_size; + newTable = allocate_pages(oldBytes*2); + copy_pages(*table, newTable, oldBytes); + deallocate_pages(*table, oldBytes); + *table_num_pages *= 2; + *table = newTable; + } + } + return uniquedParent; +} + +/*************** Logging stack and arguments ***********/ + +stack_logging_record_list_t *stack_logging_the_record_list = NULL; + +int stack_logging_enable_logging = 0; + +int stack_logging_dontcompact = 0; + +static stack_logging_record_list_t *GrowLogRecords(stack_logging_record_list_t *records, unsigned desiredNumRecords) { + stack_logging_record_list_t *new_records; + unsigned old_size = records->overall_num_bytes; + if (desiredNumRecords*sizeof(stack_logging_record_t)+sizeof(stack_logging_record_list_t) < records->overall_num_bytes) return records; + records->overall_num_bytes += records->overall_num_bytes + vm_page_size; // in order to always get an even number of pages + new_records = allocate_pages(records->overall_num_bytes); + copy_pages(records, new_records, old_size); + deallocate_pages(records, old_size); + return new_records; +} + +static void prepare_to_log_stack(void) { + if (!stack_logging_the_record_list) { + unsigned totalSize = 4 * vm_page_size; + stack_logging_the_record_list = allocate_pages(totalSize); + memset(stack_logging_the_record_list, 0, sizeof(stack_logging_record_list_t)); + stack_logging_the_record_list->overall_num_bytes = totalSize; + stack_logging_the_record_list->uniquing_table_num_pages = 128; + stack_logging_the_record_list->uniquing_table = allocate_pages(stack_logging_the_record_list->uniquing_table_num_pages * vm_page_size); + } +} + +void stack_logging_log_stack(unsigned type, unsigned arg1, unsigned arg2, unsigned arg3, unsigned result, unsigned num_hot_to_skip) { + stack_logging_record_t *rec; + if (!stack_logging_enable_logging) return; + // printf("stack_logging_log_stack 0x%x 0x%x 0x%x 0x%x -> 0x%x\n", type, arg1, arg2, arg3, result); + if (type & stack_logging_flag_zone) { + // just process it now and be done with it! + arg1 = arg2; arg2 = arg3; arg3 = 0; type &= ~stack_logging_flag_zone; + } + if (type & stack_logging_flag_calloc) { + // just process it now and be done with it! + arg1 *= arg2; arg2 = arg3; arg3 = 0; type &= ~stack_logging_flag_calloc; + } + if (type & stack_logging_flag_object) { + unsigned *class = (unsigned *)arg1; + arg1 = arg2 + class[5]; // corresponds to the instance_size field + arg2 = 0; arg3 = 0; type = stack_logging_type_alloc; + } + if (type & stack_logging_flag_cleared) { + type &= ~stack_logging_flag_cleared; + } + if (type & stack_logging_flag_handle) { + if (stack_logging_type_alloc) { + if (!result) return; + stack_logging_log_stack(stack_logging_type_alloc, 0, 0, 0, result, num_hot_to_skip+1); + stack_logging_log_stack(stack_logging_type_alloc, arg1, 0, 0, *((int *)result), num_hot_to_skip+1); + return; + } + if (stack_logging_type_dealloc) { + if (!arg1) return; + stack_logging_log_stack(stack_logging_type_dealloc, *((int *)arg1), 0, 0, 0, num_hot_to_skip+1); + stack_logging_log_stack(stack_logging_type_dealloc, arg1, 0, 0, 0, num_hot_to_skip+1); + return; + } + printf("*** Unknown logging type: 0x%x\n", type); + } + if (type == stack_logging_flag_set_handle_size) { + if (!arg1) return; + // Thanks to a horrible hack, arg3 contains the prvious handle value + if (arg3 == *((int *)arg1)) return; + stack_logging_log_stack(stack_logging_type_dealloc, arg3, 0, 0, 0, num_hot_to_skip+1); + stack_logging_log_stack(stack_logging_type_alloc, arg2, 0, 0, *((int *)arg1), num_hot_to_skip+1); + return; + } + if (type == (stack_logging_type_dealloc|stack_logging_type_alloc)) { + if (arg1 == result) return; // realloc had no effect, skipping + if (!arg1) { + // realloc(NULL, size) same as malloc(size) + type = stack_logging_type_alloc; arg1 = arg2; arg2 = arg3; arg3 = 0; + } else { + // realloc(arg1, arg2) -> result is same as free(arg1); malloc(arg2) -> result + stack_logging_log_stack(stack_logging_type_dealloc, arg1, 0, 0, 0, num_hot_to_skip+1); + stack_logging_log_stack(stack_logging_type_alloc, arg2, 0, 0, result, num_hot_to_skip+1); + return; + } + } + if (type == stack_logging_type_dealloc) { + // simple free + if (!arg1) return; // free(nil) + } + prepare_to_log_stack(); + spin_lock(&stack_logging_the_record_list->lock); + stack_logging_enable_logging = 0; + stack_logging_the_record_list = GrowLogRecords(stack_logging_the_record_list, stack_logging_the_record_list->num_records + 1); + rec = stack_logging_the_record_list->records + stack_logging_the_record_list->num_records; + // We take care of the common case of alloc-dealloc + if (!stack_logging_dontcompact && stack_logging_the_record_list->num_records && (type == stack_logging_type_dealloc) && arg1 && ((rec-1)->type == stack_logging_type_alloc) && (arg1 == STACK_LOGGING_DISGUISE((rec-1)->address))) { + stack_logging_the_record_list->num_records--; + // printf("Erased previous record in alloc-dealloc sequence\n"); + } else { + unsigned stack_entries[MAX_NUM_PC]; + unsigned count = 0; + rec->type = type; + if (type == stack_logging_type_dealloc) { + rec->argument = 0; + rec->address = STACK_LOGGING_DISGUISE(arg1); // we disguise the address + } else if (type == stack_logging_type_alloc) { + rec->argument = arg1; + rec->address = STACK_LOGGING_DISGUISE(result); // we disguise the address + } else { + rec->argument = arg2; + rec->address = STACK_LOGGING_DISGUISE(arg1); // we disguise the address + } + // printf("Before getting samples 0x%x 0x%x 0x%x 0x%x -> 0x%x\n", type, arg1, arg2, arg3, result); + thread_stack_pcs(stack_entries, MAX_NUM_PC - 1, &count); + // We put at the bottom of the stack a marker that denotes the thread (+1 for good measure...) + stack_entries[count++] = (int)pthread_self() + 1; + /* now let's unique the sample */ + // printf("Uniquing 0x%x 0x%x 0x%x 0x%x -> 0x%x\n", type, arg1, arg2, arg3, result); + rec->uniqued_stack = stack_logging_get_unique_stack(&stack_logging_the_record_list->uniquing_table, &stack_logging_the_record_list->uniquing_table_num_pages, stack_entries, count, num_hot_to_skip+2); // we additionally skip the warmest 2 entries that are an artefact of the code + stack_logging_the_record_list->num_records++; + } + stack_logging_enable_logging = 1; + stack_logging_the_record_list->lock = 0; +} + +static kern_return_t default_reader(task_t task, vm_address_t address, vm_size_t size, void **ptr) { + *ptr = (void *)address; + return 0; +} + +static kern_return_t get_remote_records(task_t task, memory_reader_t reader, stack_logging_record_list_t **records) { + // sets records + vm_address_t *remote_records_address_ref; + kern_return_t err; + *records = NULL; + err = reader(task, (vm_address_t)&stack_logging_the_record_list, sizeof(vm_address_t), (void **)&remote_records_address_ref); + if (err) return err; + if (!*remote_records_address_ref) { + // printf("stack_logging: no stack record\n"); + return 0; + } + // printf("stack_logging: stack records at %p\n", (void *)(*remote_records_address_ref)); + // printf("stack_logging: reading %d bytes\n", sizeof(stack_logging_record_list_t)); + err = reader(task, *remote_records_address_ref, sizeof(stack_logging_record_list_t), (void **)records); // get the list head + if (err) return err; + // printf("stack_logging: overall num bytes = %d\n", records->overall_num_bytes); + return reader(task, *remote_records_address_ref, (*records)->overall_num_bytes, (void **)records); +} + +kern_return_t stack_logging_get_frames(task_t task, memory_reader_t reader, vm_address_t address, vm_address_t *stack_frames_buffer, unsigned max_stack_frames, unsigned *num_frames) { + stack_logging_record_list_t *records; + kern_return_t err; + unsigned index; + unsigned disguised = STACK_LOGGING_DISGUISE(address); + if (!reader) reader = default_reader; + *num_frames = 0; + err = get_remote_records(task, reader, &records); + if (err || !records) return err; + // printf("stack_logging: %d records\n", records->num_records); + index = 0; + while (index < records->num_records) { + stack_logging_record_t *record = records->records + index; + if (record->address == disguised) { + return stack_logging_frames_for_uniqued_stack(task, reader, record->uniqued_stack, stack_frames_buffer, max_stack_frames, num_frames); + } + index++; + } + fprintf(stderr, "*** stack_logging: no record found for 0x%x\n", address); + return 0; +} + +kern_return_t stack_logging_enumerate_records(task_t task, memory_reader_t reader, vm_address_t address, void enumerator(stack_logging_record_t, void *), void *context) { + stack_logging_record_list_t *records; + kern_return_t err; + unsigned index; + unsigned disguised = STACK_LOGGING_DISGUISE(address); + if (!reader) reader = default_reader; + err = get_remote_records(task, reader, &records); + if (err || !records) return err; + // printf("stack_logging: %d records\n", records->num_records); + index = 0; + while (index < records->num_records) { + stack_logging_record_t *record = records->records + index; + if (!address || (record->address == disguised)) enumerator(*record, context); + index++; + } + return 0; +} + +kern_return_t stack_logging_frames_for_uniqued_stack(task_t task, memory_reader_t reader, unsigned uniqued_stack, vm_address_t *stack_frames_buffer, unsigned max_stack_frames, unsigned *num_frames) { + stack_logging_record_list_t *records; + unsigned *uniquing_table; + kern_return_t err; + if (!reader) reader = default_reader; + *num_frames = 0; + err = get_remote_records(task, reader, &records); + if (err || !records) return err; + err = reader(task, (vm_address_t)records->uniquing_table, records->uniquing_table_num_pages * vm_page_size, (void **)&uniquing_table); + if (err) return err; + while (max_stack_frames && (uniqued_stack != -1)) { + unsigned thisPC; + if ((uniqued_stack * 2 + 1) * sizeof(unsigned) >= records->uniquing_table_num_pages * vm_page_size) { + fprintf(stderr, "*** stack_logging: Invalid uniqued stack 0x%x", uniqued_stack); + break; + } + thisPC = uniquing_table[uniqued_stack * 2]; + uniqued_stack = uniquing_table[uniqued_stack * 2 + 1]; + if (!thisPC && !uniqued_stack) { + // Invalid entry + fprintf(stderr, "*** stack_logging: Invalid entry 0x%x", thisPC); + break; + } + stack_frames_buffer[0] = thisPC; + stack_frames_buffer++; + (*num_frames)++; + max_stack_frames--; + } + return 0; +} diff --git a/gen/stack_logging.h b/gen/stack_logging.h new file mode 100644 index 0000000..32ede79 --- /dev/null +++ b/gen/stack_logging.h @@ -0,0 +1,92 @@ +/* + * Copyright (c) 1999 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@ + */ + +#import + +#define stack_logging_type_free 0 +#define stack_logging_type_generic 1 /* anything that is not allocation/deallocation */ +#define stack_logging_type_alloc 2 /* malloc, realloc, etc... */ +#define stack_logging_type_dealloc 4 /* free, realloc, etc... */ + +// Following flags are absorbed by stack_logging_log_stack() +#define stack_logging_flag_zone 8 /* NSZoneMalloc, etc... */ +#define stack_logging_flag_calloc 16 /* multiply arguments to get the size */ +#define stack_logging_flag_object 32 /* NSAllocateObject(Class, extraBytes, zone) */ +#define stack_logging_flag_cleared 64 /* for NewEmptyHandle */ +#define stack_logging_flag_handle 128 /* for Handle (de-)allocation routines */ +#define stack_logging_flag_set_handle_size 256 /* (Handle, newSize) treated specially */ + +/* Macro used to disguise addresses so that leak finding can work */ +#define STACK_LOGGING_DISGUISE(address) (((unsigned)address) ^ 0x00005555) /* nicely idempotent */ + +typedef struct { + unsigned type; + unsigned uniqued_stack; + unsigned argument; + unsigned address; /* disguised, to avoid confusing leaks */ +} stack_logging_record_t; + +typedef struct { + unsigned overall_num_bytes; + unsigned num_records; + unsigned lock; /* 0 means OK to lock; used for inter-process locking */ + unsigned *uniquing_table; /* allocated using vm_allocate() */ + /* hashtable organized as (PC, uniqued parent) + Only the second half of the table is active + To enable us to grow dynamically */ + unsigned uniquing_table_num_pages; /* number of pages of the table */ + unsigned extra_retain_count; /* not used by stack_logging_log_stack */ + unsigned filler[2]; /* align to cache lines for better performance */ + stack_logging_record_t records[0]; /* records follow here */ +} stack_logging_record_list_t; + +extern unsigned stack_logging_get_unique_stack(unsigned **table, unsigned *table_num_pages, unsigned *stack_entries, unsigned count, unsigned num_hot_to_skip); + /* stack_entries are from hot to cold */ + +extern stack_logging_record_list_t *stack_logging_the_record_list; + /* This is the global variable containing all logs */ + +extern int stack_logging_enable_logging; + /* when clear, no logging takes place */ + +extern int stack_logging_dontcompact; + /* default is to compact; when set does not compact alloc/free logs; useful for tracing history */ + +extern void stack_logging_log_stack(unsigned type, unsigned arg1, unsigned arg2, unsigned arg3, unsigned result, unsigned num_hot_to_skip); + +extern kern_return_t stack_logging_get_frames(task_t task, memory_reader_t reader, vm_address_t address, vm_address_t *stack_frames_buffer, unsigned max_stack_frames, unsigned *num_frames); + /* Gets the last record in stack_logging_the_record_list about address */ + +#define STACK_LOGGING_ENUMERATION_PROVIDED 1 // temporary to avoid dependencies between projects + +extern kern_return_t stack_logging_enumerate_records(task_t task, memory_reader_t reader, vm_address_t address, void enumerator(stack_logging_record_t, void *), void *context); + /* Gets all the records about address; + If !address, gets all records */ + +extern kern_return_t stack_logging_frames_for_uniqued_stack(task_t task, memory_reader_t reader, unsigned uniqued_stack, vm_address_t *stack_frames_buffer, unsigned max_stack_frames, unsigned *num_frames); + /* Given a uniqued_stack fills stack_frames_buffer */ + +extern void thread_stack_pcs(vm_address_t *buffer, unsigned max, unsigned *num); + /* Convenience to fill buffer with the PCs of the frames, starting with the hot frames; + num: returned number of frames + */ + diff --git a/gen/strchr.c b/gen/strchr.c new file mode 100644 index 0000000..c1469d1 --- /dev/null +++ b/gen/strchr.c @@ -0,0 +1,41 @@ +/* + * Copyright (c) 1999 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@ + */ +/* Copyright (c) 1992, 1995 NeXT Computer, Inc. All rights reserved. + * + * File: libc/gen/strchr.c + * + * This file contains machine independent code for string index + * + */ +#import + +/* This routine needs to be optimized. */ + +char *strchr(const char *s, int c) +{ + const char ch = c; + + for ( ; *s != ch; s++) + if (*s == '\0') + return 0; + return (char *)s; +} diff --git a/gen/stringlist.3 b/gen/stringlist.3 new file mode 100644 index 0000000..559d5da --- /dev/null +++ b/gen/stringlist.3 @@ -0,0 +1,124 @@ +.\" $NetBSD: stringlist.3,v 1.2 1997/04/09 08:59:25 kleink Exp $ +.\" +.\" Copyright (c) 1997 The NetBSD Foundation, Inc. +.\" All rights reserved. +.\" +.\" This file was contributed to The NetBSD Foundation by Luke Mewburn. +.\" +.\" 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 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. +.\" +.\" $FreeBSD: src/lib/libc/gen/stringlist.3,v 1.7 2001/10/01 16:08:51 ru Exp $ +.\" +.Dd February 24, 1997 +.Os +.Dt STRINGLIST 3 +.Sh NAME +.Nm stringlist , +.Nm sl_init , +.Nm sl_add , +.Nm sl_free , +.Nm sl_find +.Nd stringlist manipulation functions +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In stringlist.h +.Ft StringList * +.Fn sl_init +.Ft void +.Fn sl_add "StringList *sl" "char *item" +.Ft void +.Fn sl_free "StringList *sl" "int freeall" +.Ft char * +.Fn sl_find "StringList *sl" "char *item" +.Sh DESCRIPTION +The +.Nm +functions manipulate stringlists, which are lists of +strings that extend automatically if necessary. +.Pp +The +.Ar StringList +structure has the following definition: +.Bd -literal -offset indent +typedef struct _stringlist { + char **sl_str; + size_t sl_max; + size_t sl_cur; +} StringList; +.Ed +.Pp +.Bl -tag -width "sl_str" -offset indent +.It Ar sl_str +a pointer to the base of the array containing the list. +.It Ar sl_max +the size of +.Ar sl_str . +.It Ar sl_cur +the offset in +.Ar sl_str +of the current element. +.El +.Pp +The following stringlist manipulation functions are available: +.Bl -tag -width "sl_init()" +.It Fn sl_init +Create a stringlist. +Returns a pointer to a +.Ar StringList . +.It Fn sl_free +Releases memory occupied by +.Ar sl +and the +.Ar sl->sl_str +array. +If +.Ar freeall +is non-zero, then each of the items within +.Ar sl->sl_str +is released as well. +.It Fn sl_add +Add +.Ar item +to +.Ar sl->sl_str +at +.Ar sl->sl_cur , +extending the size of +.Ar sl->sl_str +.It Fn sl_find +Find +.Ar item +in +.Ar sl , +returning NULL if it's not found. +.El +.Sh SEE ALSO +.Xr free 3 , +.Xr malloc 3 diff --git a/gen/strtofflags.3 b/gen/strtofflags.3 new file mode 100644 index 0000000..355e81a --- /dev/null +++ b/gen/strtofflags.3 @@ -0,0 +1,99 @@ +.\" Copyright (c) 1989, 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. +.\" +.\" @(#)setmode.3 8.2 (Berkeley) 4/28/95 +.\" $FreeBSD: src/lib/libc/gen/strtofflags.3,v 1.7 2001/10/01 16:08:51 ru Exp $ +.\" +.Dd January 1, 2000 +.Dt STRTOFFLAGS 3 +.Os +.Sh NAME +.Nm fflagstostr , +.Nm strtofflags +.Nd convert between file flag bits and their string names +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In unistd.h +.Ft char * +.Fn fflagstostr "u_long flags" +.Ft int +.Fn strtofflags "char **stringp" "u_long *setp" "u_long *clrp" +.Sh DESCRIPTION +The +.Fn fflagstostr +function returns a comma separated string of the file flags represented by +.Fa flags . +If no flags are set a zero length string is returned. +.Pp +If memory cannot be allocated for the return value, +.Fn fflagstostr +returns +.Dv NULL . +.Pp +The value returned from +.Fn fflagstostr +is obtained from +.Fn malloc +and should be returned to the system with +.Fn free +when the program is done with it. +.Pp +The +.Fn strtofflags +function takes a string of file flags, as described in +.Xr chflags 1 , +parses it, and returns the 'set' flags and 'clear' flags +such as would be given as arguments to +.Xr chflags 2 . +On success +.Fn strtofflags +returns 0, otherwise it returns non-zero and +.Fa stringp +is left pointing to the offending token. +.Sh ERRORS +The +.Fn fflagstostr +function +may fail and set errno for any of the errors specified for the library +routine +.Xr malloc 3 . +.Sh SEE ALSO +.Xr chflags 1 , +.Xr chflags 2 , +.Xr malloc 3 +.Sh HISTORY +The +.Fn fflagstostr +and +.Fn strtofflags +functions first appeared in +.Fx 4.0 . diff --git a/gen/strtofflags.c b/gen/strtofflags.c new file mode 100644 index 0000000..ba27a29 --- /dev/null +++ b/gen/strtofflags.c @@ -0,0 +1,154 @@ +/*- + * 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. + */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)stat_flags.c 8.1 (Berkeley) 5/31/93"; +#else +static const char rcsid[] = + "$FreeBSD: src/lib/libc/gen/strtofflags.c,v 1.18.2.1 2000/06/28 01:52:24 joe Exp $"; +#endif +#endif /* not lint */ + +#include +#include + +#include +#include +#include + +static struct { + char *name; + u_long flag; + int invert; +} mapping[] = { + /* shorter names per flag first, all prefixed by "no" */ + { "nosappnd", SF_APPEND, 0 }, + { "nosappend", SF_APPEND, 0 }, + { "noarch", SF_ARCHIVED, 0 }, + { "noarchived", SF_ARCHIVED, 0 }, + { "noschg", SF_IMMUTABLE, 0 }, + { "noschange", SF_IMMUTABLE, 0 }, + { "nosimmutable", SF_IMMUTABLE, 0 }, + { "nouappnd", UF_APPEND, 0 }, + { "nouappend", UF_APPEND, 0 }, + { "nouchg", UF_IMMUTABLE, 0 }, + { "nouchange", UF_IMMUTABLE, 0 }, + { "nouimmutable", UF_IMMUTABLE, 0 }, + { "nodump", UF_NODUMP, 1 }, + { "noopaque", UF_OPAQUE, 0 }, +}; +#define longestflaglen 12 +#define nmappings (sizeof(mapping) / sizeof(mapping[0])) + +/* + * fflagstostr -- + * Convert file flags to a comma-separated string. If no flags + * are set, return the empty string. + */ +char * +fflagstostr(flags) + u_long flags; +{ + char *string; + char *sp, *dp; + u_long setflags; + int i; + + if ((string = (char *)malloc(nmappings * (longestflaglen + 1))) == NULL) + return (NULL); + + setflags = flags; + dp = string; + for (i = 0; i < nmappings; i++) { + if (setflags & mapping[i].flag) { + if (dp > string) + *dp++ = ','; + for (sp = mapping[i].invert ? mapping[i].name : + mapping[i].name + 2; *sp; *dp++ = *sp++) ; + setflags &= ~mapping[i].flag; + } + } + *dp = '\0'; + return (string); +} + +/* + * strtofflags -- + * Take string of arguments and return file flags. Return 0 on + * success, 1 on failure. On failure, stringp is set to point + * to the offending token. + */ +int +strtofflags(stringp, setp, clrp) + char **stringp; + u_long *setp, *clrp; +{ + char *string, *p; + int i; + + if (setp) + *setp = 0; + if (clrp) + *clrp = 0; + string = *stringp; + while ((p = strsep(&string, "\t ,")) != NULL) { + *stringp = p; + if (*p == '\0') + continue; + for (i = 0; i < nmappings; i++) { + if (strcmp(p, mapping[i].name + 2) == 0) { + if (mapping[i].invert) { + if (clrp) + *clrp |= mapping[i].flag; + } else { + if (setp) + *setp |= mapping[i].flag; + } + break; + } else if (strcmp(p, mapping[i].name) == 0) { + if (mapping[i].invert) { + if (setp) + *setp |= mapping[i].flag; + } else { + if (clrp) + *clrp |= mapping[i].flag; + } + break; + } + } + if (i == nmappings) + return 1; + } + return 0; +} diff --git a/gen/sysconf.3 b/gen/sysconf.3 new file mode 100644 index 0000000..e3a47f1 --- /dev/null +++ b/gen/sysconf.3 @@ -0,0 +1,208 @@ +.\" 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. +.\" +.\" @(#)sysconf.3 8.3 (Berkeley) 4/19/94 +.\" $FreeBSD: src/lib/libc/gen/sysconf.3,v 1.16 2001/10/01 16:08:51 ru Exp $ +.\" +.Dd June 18, 2001 +.Dt SYSCONF 3 +.Os +.Sh NAME +.Nm sysconf +.Nd get configurable system variables +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In unistd.h +.Ft long +.Fn sysconf "int name" +.Sh DESCRIPTION +This interface is defined by +.St -p1003.1-88 . +A far more complete interface is available using +.Xr sysctl 3 . +.Pp +The +.Fn sysconf +function provides a method for applications to determine the current +value of a configurable system limit or option variable. +The +.Fa name +argument specifies the system variable to be queried. +Symbolic constants for each name value are found in the include file +.Aq Pa unistd.h . +Shell programmers who need access to these parameters should use the +.Xr getconf 1 +utility. +.Pp +The available values are as follows: +.Pp +.Bl -tag -width 6n +.Pp +.It Li _SC_ARG_MAX +The maximum bytes of argument to +.Xr execve 2 . +.It Li _SC_CHILD_MAX +The maximum number of simultaneous processes per user id. +.It Li _SC_CLK_TCK +The frequency of the statistics clock in ticks per second. +.It Li _SC_IOV_MAX +The maximum number of elements in the I/O vector used by +.Xr readv 2 , +.Xr writev 2 , +.Xr recvmsg 2 , +and +.Xr sendmsg 2 . +.It Li _SC_NGROUPS_MAX +The maximum number of supplemental groups. +.It Li _SC_OPEN_MAX +The maximum number of open files per user id. +.It Li _SC_STREAM_MAX +The minimum maximum number of streams that a process may have open +at any one time. +.It Li _SC_TZNAME_MAX +The minimum maximum number of types supported for the name of a +timezone. +.It Li _SC_JOB_CONTROL +Return 1 if job control is available on this system, otherwise \-1. +.It Li _SC_SAVED_IDS +Returns 1 if saved set-group and saved set-user ID is available, +otherwise \-1. +.It Li _SC_VERSION +The version of +.St -p1003.1 +with which the system +attempts to comply. +.It Li _SC_BC_BASE_MAX +The maximum ibase/obase values in the +.Xr bc 1 +utility. +.It Li _SC_BC_DIM_MAX +The maximum array size in the +.Xr bc 1 +utility. +.It Li _SC_BC_SCALE_MAX +The maximum scale value in the +.Xr bc 1 +utility. +.It Li _SC_BC_STRING_MAX +The maximum string length in the +.Xr bc 1 +utility. +.It Li _SC_COLL_WEIGHTS_MAX +The maximum number of weights that can be assigned to any entry of +the LC_COLLATE order keyword in the locale definition file. +.It Li _SC_EXPR_NEST_MAX +The maximum number of expressions that can be nested within +parenthesis by the +.Xr expr 1 +utility. +.It Li _SC_LINE_MAX +The maximum length in bytes of a text-processing utility's input +line. +.It Li _SC_RE_DUP_MAX +The maximum number of repeated occurrences of a regular expression +permitted when using interval notation. +.It Li _SC_2_VERSION +The version of +.St -p1003.2 +with which the system attempts to comply. +.It Li _SC_2_C_BIND +Return 1 if the system's C-language development facilities support the +C-Language Bindings Option, otherwise \-1. +.It Li _SC_2_C_DEV +Return 1 if the system supports the C-Language Development Utilities Option, +otherwise \-1. +.It Li _SC_2_CHAR_TERM +Return 1 if the system supports at least one terminal type capable of +all operations described in +.St -p1003.2 , +otherwise \-1. +.It Li _SC_2_FORT_DEV +Return 1 if the system supports the FORTRAN Development Utilities Option, +otherwise \-1. +.It Li _SC_2_FORT_RUN +Return 1 if the system supports the FORTRAN Runtime Utilities Option, +otherwise \-1. +.It Li _SC_2_LOCALEDEF +Return 1 if the system supports the creation of locales, otherwise \-1. +.It Li _SC_2_SW_DEV +Return 1 if the system supports the Software Development Utilities Option, +otherwise \-1. +.It Li _SC_2_UPE +Return 1 if the system supports the User Portability Utilities Option, +otherwise \-1. +.El +.Sh RETURN VALUES +If the call to +.Fn sysconf +is not successful, \-1 is returned and +.Va errno +is set appropriately. +Otherwise, if the variable is associated with functionality that is not +supported, \-1 is returned and +.Va errno +is not modified. +Otherwise, the current variable value is returned. +.Sh ERRORS +The +.Fn sysconf +function may fail and set +.Va errno +for any of the errors specified for the library function +.Xr sysctl 3 . +In addition, the following error may be reported: +.Bl -tag -width Er +.It Bq Er EINVAL +The value of the +.Fa name +argument is invalid. +.El +.Sh SEE ALSO +.Xr getconf 1 , +.Xr pathconf 2 , +.Xr confstr 3 , +.Xr sysctl 3 +.Sh BUGS +The value for _SC_STREAM_MAX is a minimum maximum, and required to be +the same as ANSI C's FOPEN_MAX, so the returned value is a ridiculously +small and misleading number. +.Sh STANDARDS +Except for the fact that values returned by +.Fn sysconf +may change over the lifetime of the calling process, +this function conforms to +.St -p1003.1-88 . +.Sh HISTORY +The +.Fn sysconf +function first appeared in +.Bx 4.4 . diff --git a/gen/sysconf.c b/gen/sysconf.c new file mode 100644 index 0000000..32cf64c --- /dev/null +++ b/gen/sysconf.c @@ -0,0 +1,206 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Sean Eric Fagan of Cygnus Support. + * + * 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 +#include +#include +#include + +#include +#include + +/* + * sysconf -- + * get configurable system variables. + * + * XXX + * POSIX 1003.1 (ISO/IEC 9945-1, 4.8.1.3) states that the variable values + * not change during the lifetime of the calling process. This would seem + * to require that any change to system limits kill all running processes. + * A workaround might be to cache the values when they are first retrieved + * and then simply return the cached value on subsequent calls. This is + * less useful than returning up-to-date values, however. + */ +long +sysconf(name) + int name; +{ + struct clockinfo clk; + struct rlimit rl; + size_t len; + int mib[2], value; + + len = sizeof(value); + + switch (name) { +/* 1003.1 */ + case _SC_ARG_MAX: + mib[0] = CTL_KERN; + mib[1] = KERN_ARGMAX; + break; + case _SC_CHILD_MAX: + return (getrlimit(RLIMIT_NPROC, &rl) ? -1 : rl.rlim_cur); + case _SC_CLK_TCK: + return (CLK_TCK); + case _SC_JOB_CONTROL: + mib[0] = CTL_KERN; + mib[1] = KERN_JOB_CONTROL; + goto yesno; + case _SC_NGROUPS_MAX: + mib[0] = CTL_KERN; + mib[1] = KERN_NGROUPS; + break; + case _SC_OPEN_MAX: + return (getrlimit(RLIMIT_NOFILE, &rl) ? -1 : rl.rlim_cur); + case _SC_STREAM_MAX: + mib[0] = CTL_USER; + mib[1] = USER_STREAM_MAX; + break; + case _SC_TZNAME_MAX: + mib[0] = CTL_USER; + mib[1] = USER_TZNAME_MAX; + break; + case _SC_SAVED_IDS: + mib[0] = CTL_KERN; + mib[1] = KERN_SAVED_IDS; + goto yesno; + case _SC_VERSION: + mib[0] = CTL_KERN; + mib[1] = KERN_POSIX1; + break; + +/* 1003.2 */ + case _SC_BC_BASE_MAX: + mib[0] = CTL_USER; + mib[1] = USER_BC_BASE_MAX; + break; + case _SC_BC_DIM_MAX: + mib[0] = CTL_USER; + mib[1] = USER_BC_DIM_MAX; + break; + case _SC_BC_SCALE_MAX: + mib[0] = CTL_USER; + mib[1] = USER_BC_SCALE_MAX; + break; + case _SC_BC_STRING_MAX: + mib[0] = CTL_USER; + mib[1] = USER_BC_STRING_MAX; + break; + case _SC_COLL_WEIGHTS_MAX: + mib[0] = CTL_USER; + mib[1] = USER_COLL_WEIGHTS_MAX; + break; + case _SC_EXPR_NEST_MAX: + mib[0] = CTL_USER; + mib[1] = USER_EXPR_NEST_MAX; + break; + case _SC_LINE_MAX: + mib[0] = CTL_USER; + mib[1] = USER_LINE_MAX; + break; + case _SC_RE_DUP_MAX: + mib[0] = CTL_USER; + mib[1] = USER_RE_DUP_MAX; + break; + case _SC_2_VERSION: + mib[0] = CTL_USER; + mib[1] = USER_POSIX2_VERSION; + break; + case _SC_2_C_BIND: + mib[0] = CTL_USER; + mib[1] = USER_POSIX2_C_BIND; + goto yesno; + case _SC_2_C_DEV: + mib[0] = CTL_USER; + mib[1] = USER_POSIX2_C_DEV; + goto yesno; + case _SC_2_CHAR_TERM: + mib[0] = CTL_USER; + mib[1] = USER_POSIX2_CHAR_TERM; + goto yesno; + case _SC_2_FORT_DEV: + mib[0] = CTL_USER; + mib[1] = USER_POSIX2_FORT_DEV; + goto yesno; + case _SC_2_FORT_RUN: + mib[0] = CTL_USER; + mib[1] = USER_POSIX2_FORT_RUN; + goto yesno; + case _SC_2_LOCALEDEF: + mib[0] = CTL_USER; + mib[1] = USER_POSIX2_LOCALEDEF; + goto yesno; + case _SC_2_SW_DEV: + mib[0] = CTL_USER; + mib[1] = USER_POSIX2_SW_DEV; + goto yesno; + case _SC_2_UPE: + mib[0] = CTL_USER; + mib[1] = USER_POSIX2_UPE; +yesno: if (sysctl(mib, 2, &value, &len, NULL, 0) == -1) + return (-1); + if (value == 0) + return (-1); + return (value); + break; + default: + errno = EINVAL; + return (-1); + } + return (sysctl(mib, 2, &value, &len, NULL, 0) == -1 ? -1 : value); +} diff --git a/gen/sysctl.3 b/gen/sysctl.3 new file mode 100644 index 0000000..9fa2a4a --- /dev/null +++ b/gen/sysctl.3 @@ -0,0 +1,827 @@ +.\" 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. +.\" +.\" @(#)sysctl.3 8.4 (Berkeley) 5/9/95 +.\" $FreeBSD: src/lib/libc/gen/sysctl.3,v 1.51 2001/10/01 16:08:51 ru Exp $ +.\" +.Dd January 23, 2001 +.Dt SYSCTL 3 +.Os +.Sh NAME +.Nm sysctl , +.Nm sysctlbyname , +.Nm sysctlnametomib +.Nd get or set system information +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In sys/types.h +.In sys/sysctl.h +.Ft int +.Fn sysctl "int *name" "u_int namelen" "void *oldp" "size_t *oldlenp" "void *newp" "size_t newlen" +.Ft int +.Fn sysctlbyname "const char *name" "void *oldp" "size_t *oldlenp" "void *newp" "size_t newlen" +.Ft int +.Fn sysctlnametomib "const char *name" "int *mibp" "size_t *sizep" +.Sh DESCRIPTION +The +.Fn sysctl +function retrieves system information and allows processes with +appropriate privileges to set system information. +The information available from +.Fn sysctl +consists of integers, strings, and tables. +Information may be retrieved and set from the command interface +using the +.Xr sysctl 8 +utility. +.Pp +Unless explicitly noted below, +.Fn sysctl +returns a consistent snapshot of the data requested. +Consistency is obtained by locking the destination +buffer into memory so that the data may be copied out without blocking. +Calls to +.Fn sysctl +are serialized to avoid deadlock. +.Pp +The state is described using a ``Management Information Base'' (MIB) +style name, listed in +.Fa name , +which is a +.Fa namelen +length array of integers. +.Pp +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 +as the standard +.Fn sysctl +function. +.Pp +The information is copied into the buffer specified by +.Fa oldp . +The size of the buffer is given by the location specified by +.Fa oldlenp +before the call, +and that location gives the amount of data copied after a successful call +and after a call that returns with the error code +.Er ENOMEM . +If the amount of data available is greater +than the size of the buffer supplied, +the call supplies as much data as fits in the buffer provided +and returns with the error code +.Er ENOMEM . +If the old value is not desired, +.Fa oldp +and +.Fa oldlenp +should be set to NULL. +.Pp +The size of the available data can be determined by calling +.Fn sysctl +with a NULL parameter for +.Fa oldp . +The size of the available data will be returned in the location pointed to by +.Fa oldlenp . +For some operations, the amount of space may change often. +For these operations, +the system attempts to round up so that the returned size is +large enough for a call to return the data shortly thereafter. +.Pp +To set a new value, +.Fa newp +is set to point to a buffer of length +.Fa newlen +from which the requested value is to be taken. +If a new value is not to be set, +.Fa newp +should be set to NULL and +.Fa newlen +set to 0. +.Pp +The +.Fn sysctlnametomib +function accepts an ASCII representation of the name, +looks up the integer name vector, +and returns the numeric representation in the mib array pointed to by +.Fa mibp . +The number of elements in the mib array is given by the location specified by +.Fa sizep +before the call, +and that location gives the number of entries copied after a successful call. +The resulting +.Fa mib +and +.Fa size +may be used in subsequent +.Fn sysctl +calls to get the data associated with the requested ASCII name. +This interface is intended for use by applications that want to +repeatedly request the same variable (the +.Fn sysctl +function runs in about a third the time as the same request made via the +.Fn sysctlbyname +function). +The +.Fn sysctlbyname +function is also useful for fetching mib prefixes and then adding +a final component. +For example, to fetch process information +for processes with pid's less than 100: +.Pp +.Bd -literal -offset indent -compact +int i, mib[4]; +size_t len; +struct kinfo_proc kp; + +/* Fill out the first three components of the mib */ +len = 4; +sysctlnametomib("kern.proc.pid", mib, &len); + +/* Fetch and print entries for pid's < 100 */ +for (i = 0; i < 100; i++) { + mib[3] = i; + len = sizeof(kp); + if (sysctl(mib, 4, &kp, &len, NULL, 0) == -1) + perror("sysctl"); + else if (len > 0) + printkproc(&kp); +} +.Ed +.Pp +The top level names are defined with a CTL_ prefix in +.Aq Pa 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 Filesystem" +.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 +in the system: +.Pp +.Bd -literal -offset indent -compact +int mib[2], maxproc; +size_t len; + +mib[0] = CTL_KERN; +mib[1] = KERN_MAXPROC; +len = sizeof(maxproc); +sysctl(mib, 2, &maxproc, &len, NULL, 0); +.Ed +.Pp +To retrieve the standard search path for the system utilities: +.Pp +.Bd -literal -offset indent -compact +int mib[2]; +size_t len; +char *p; + +mib[0] = CTL_USER; +mib[1] = USER_CS_PATH; +sysctl(mib, 2, NULL, &len, NULL, 0); +p = malloc(len); +sysctl(mib, 2, p, &len, NULL, 0); +.Ed +.Ss CTL_DEBUG +The debugging variables vary from system to system. +A debugging variable may be added or deleted without need to recompile +.Fn sysctl +to know about it. +Each time it runs, +.Fn sysctl +gets the list of debugging variables from the kernel and +displays their current values. +The system defines twenty +.Ns ( Va struct ctldebug ) +variables named +.Nm debug0 +through +.Nm debug19 . +They are declared as separate variables so that they can be +individually initialized at the location of their associated variable. +The loader prevents multiple use of the same variable by issuing errors +if a variable is initialized in more than one place. +For example, to export the variable +.Nm dospecialcheck +as a debugging variable, the following declaration would be used: +.Bd -literal -offset indent -compact +int dospecialcheck = 1; +struct ctldebug debug5 = { "dospecialcheck", &dospecialcheck }; +.Ed +.Ss CTL_VFS +A distinguished second level name, VFS_GENERIC, +is used to get general information about all filesystems. +One of its third level identifiers is VFS_MAXTYPENUM +that gives the highest valid filesystem type number. +Its other third level identifier is VFS_CONF that +returns configuration information about the filesystem +type given as a fourth level identifier (see +.Xr getvfsbyname 3 +as an example of its use). +The remaining second level identifiers are the +filesystem type number returned by a +.Xr statfs 2 +call or from VFS_CONF. +The third level identifiers available for each filesystem +are given in the header file that defines the mount +argument structure for that filesystem. +.Ss CTL_HW +The string and integer information available for the CTL_HW level +is detailed below. +The changeable column shows whether a process with appropriate +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" +.El +.Pp +.Bl -tag -width 6n +.It Li HW_MACHINE +The machine class. +.It Li HW_MODEL +The machine model +.It Li HW_NCPU +The number of cpus. +.It Li HW_BYTEORDER +The byteorder (4,321, or 1,234). +.It Li HW_PHYSMEM +The bytes of physical memory. +.It Li HW_USERMEM +The bytes of non-kernel memory. +.It Li HW_PAGESIZE +The software page size. +.It Li HW_FLOATINGPOINT +Nonzero if the floating point support is in hardware. +.It Li HW_MACHINE_ARCH +The machine dependent architecture type. +.\".It Fa HW_DISKNAMES +.\".It Fa HW_DISKSTATS +.El +.Ss CTL_KERN +The string and integer information available for the CTL_KERN level +is detailed below. +The changeable column shows whether a process with appropriate +privilege may change the value. +The types of data currently available are process information, +system vnodes, the open file entries, routing table entries, +virtual memory statistics, load average history, and clock rate +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" +.El +.Pp +.Bl -tag -width 6n +.It Li KERN_ARGMAX +The maximum bytes of argument to +.Xr execve 2 . +.It Li KERN_BOOTFILE +The full pathname of the file from which the kernel was loaded. +.It Li KERN_BOOTTIME +A +.Va struct timeval +structure is returned. +This structure contains the time that the system was booted. +.It Li KERN_CLOCKRATE +A +.Va struct clockinfo +structure is returned. +This structure contains the clock, statistics clock and profiling clock +frequencies, the number of micro-seconds per hz tick and the skew rate. +.It Li KERN_FILE +Return the entire file table. +The returned data consists of a single +.Va struct filehead +followed by an array of +.Va struct file , +whose size depends on the current number of such objects in the system. +.It Li KERN_HOSTID +Get or set the host id. +.It Li KERN_HOSTNAME +Get or set the hostname. +.It Li KERN_JOB_CONTROL +Return 1 if job control is available on this system, otherwise 0. +.It Li KERN_MAXFILES +The maximum number of files that may be open in the system. +.It Li KERN_MAXFILESPERPROC +The maximum number of files that may be open for a single process. +This limit only applies to processes with an effective uid of nonzero +at the time of the open request. +Files that have already been opened are not affected if the limit +or the effective uid is changed. +.It Li KERN_MAXPROC +The maximum number of concurrent processes the system will allow. +.It Li KERN_MAXPROCPERUID +The maximum number of concurrent processes the system will allow +for a single effective uid. +This limit only applies to processes with an effective uid of nonzero +at the time of a fork request. +Processes that have already been started are not affected if the limit +is changed. +.It Li KERN_MAXVNODES +The maximum number of vnodes available on the system. +.It Li KERN_NGROUPS +The maximum number of supplemental groups. +.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). +.It Li KERN_OSRELEASE +The system release string. +.It Li KERN_OSREV +The system revision string. +.It Li KERN_OSTYPE +The system type string. +.It Li KERN_POSIX1 +The version of +.St -p1003.1 +with which the system +attempts to comply. +.It Li KERN_PROC +Return the entire process table, or a subset of it. +An array of pairs of +.Va struct proc +followed by corresponding +.Va struct eproc +structures is returned, +whose size depends on the current number of such objects in the system. +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" +.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 +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" +.El +.It Li KERN_PROF +Return profiling information about the kernel. +If the kernel is not compiled for profiling, +attempts to retrieve any of the KERN_PROF values will +fail with +.Er EOPNOTSUPP . +The third level names for the string and integer profiling information +is detailed below. +The changeable column shows whether a process with appropriate +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" +.El +.Pp +The variables are as follows: +.Bl -tag -width 6n +.It Li GPROF_STATE +Returns GMON_PROF_ON or GMON_PROF_OFF to show that profiling +is running or stopped. +.It Li GPROF_COUNT +Array of statistical program counter counts. +.It Li GPROF_FROMS +Array indexed by program counter of call-from points. +.It Li GPROF_TOS +Array of +.Va struct tostruct +describing destination of calls and their counts. +.It Li GPROF_GMONPARAM +Structure giving the sizes of the above arrays. +.El +.It Li KERN_QUANTUM +The maximum period of time, in microseconds, for which a process is allowed +to run without being preempted if other processes are in the run queue. +.It Li KERN_SAVED_IDS +Returns 1 if saved set-group and saved set-user ID is available. +.It Li KERN_SECURELVL +The system security level. +This level may be raised by processes with appropriate privilege. +It may not be lowered. +.It Li KERN_VERSION +The system version string. +.It Li KERN_VNODE +Return the entire vnode table. +Note, the vnode table is not necessarily a consistent snapshot of +the system. +The returned data consists of an array whose size depends on the +current number of such objects in the system. +Each element of the array contains the kernel address of a vnode +.Va struct vnode * +followed by the vnode itself +.Va struct vnode . +.El +.Ss CTL_MACHDEP +The set of variables defined is architecture dependent. +The following variables are defined for the i386 architecture. +.Bl -column "CONSOLE_DEVICEXXX" "struct bootinfoXXX" -offset indent +.It Sy "Second level name Type Changeable" +.It Li "CPU_CONSDEV dev_t no" +.It Li "CPU_ADJKERNTZ int yes" +.It Li "CPU_DISRTCSET int yes" +.It Li "CPU_BOOTINFO struct bootinfo no" +.It Li "CPU_WALLCLOCK int yes" +.El +.Ss CTL_NET +The string and integer information available for the CTL_NET level +is detailed below. +The changeable column shows whether a process with appropriate +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" +.El +.Pp +.Bl -tag -width 6n +.It Li PF_ROUTE +Return the entire routing table or a subset of it. +The data is returned as a sequence of routing messages (see +.Xr route 4 +for the header file, format and meaning). +The length of each message is contained in the message header. +.Pp +The third level name is a protocol number, which is currently always 0. +The fourth level name is an address family, which may be set to 0 to +select all address families. +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 None" +.El +.It Li PF_INET +Get or set various global information about the IPv4 +(Internet Protocol version 4). +The third level name is the protocol. +The fourth level name is the variable name. +The currently defined protocols and names are: +.Bl -column ProtocolXX VariableXX TypeXX ChangeableXX +.It Sy "Protocol Variable Type Changeable" +.It "icmp bmcastecho integer yes" +.It "icmp maskrepl integer yes" +.It "ip forwarding integer yes" +.It "ip redirect integer yes" +.It "ip ttl integer yes" +.It "udp checksum integer yes" +.El +.Pp +The variables are as follows: +.Bl -tag -width 6n +.It Li icmp.bmcastecho +Returns 1 if an ICMP echo request to a broadcast or multicast address is +to be answered. +.It Li icmp.maskrepl +Returns 1 if ICMP network mask requests are to be answered. +.It Li ip.forwarding +Returns 1 when IP forwarding is enabled for the host, +meaning that the host is acting as a router. +.It Li ip.redirect +Returns 1 when ICMP redirects may be sent by the host. +This option is ignored unless the host is routing IP packets, +and should normally be enabled on all systems. +.It Li ip.ttl +The maximum time-to-live (hop count) value for an IP packet sourced by +the system. +This value applies to normal transport protocols, not to ICMP. +.It Li udp.checksum +Returns 1 when UDP checksums are being computed and checked. +Disabling UDP checksums is strongly discouraged. +.Pp +For variables net.inet.*.ipsec, please refer to +.Xr ipsec 4 . +.El +.It Li PF_INET6 +Get or set various global information about the IPv6 +(Internet Protocol version 6). +The third level name is the protocol. +The fourth level name is the variable name. +.Pp +For variables net.inet6.* please refer to +.Xr inet6 4 . +For variables net.inet6.*.ipsec6, please refer to +.Xr ipsec 4 . +.El +.Ss CTL_USER +The string and integer information available for the CTL_USER level +is detailed below. +The changeable column shows whether a process with appropriate +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" +.El +.Bl -tag -width 6n +.Pp +.It Li USER_BC_BASE_MAX +The maximum ibase/obase values in the +.Xr bc 1 +utility. +.It Li USER_BC_DIM_MAX +The maximum array size in the +.Xr bc 1 +utility. +.It Li USER_BC_SCALE_MAX +The maximum scale value in the +.Xr bc 1 +utility. +.It Li USER_BC_STRING_MAX +The maximum string length in the +.Xr bc 1 +utility. +.It Li USER_COLL_WEIGHTS_MAX +The maximum number of weights that can be assigned to any entry of +the LC_COLLATE order keyword in the locale definition file. +.It Li USER_CS_PATH +Return a value for the +.Ev PATH +environment variable that finds all the standard utilities. +.It Li USER_EXPR_NEST_MAX +The maximum number of expressions that can be nested within +parenthesis by the +.Xr expr 1 +utility. +.It Li USER_LINE_MAX +The maximum length in bytes of a text-processing utility's input +line. +.It Li USER_POSIX2_CHAR_TERM +Return 1 if the system supports at least one terminal type capable of +all operations described in +.St -p1003.2 , +otherwise 0. +.It Li USER_POSIX2_C_BIND +Return 1 if the system's C-language development facilities support the +C-Language Bindings Option, otherwise 0. +.It Li USER_POSIX2_C_DEV +Return 1 if the system supports the C-Language Development Utilities Option, +otherwise 0. +.It Li USER_POSIX2_FORT_DEV +Return 1 if the system supports the FORTRAN Development Utilities Option, +otherwise 0. +.It Li USER_POSIX2_FORT_RUN +Return 1 if the system supports the FORTRAN Runtime Utilities Option, +otherwise 0. +.It Li USER_POSIX2_LOCALEDEF +Return 1 if the system supports the creation of locales, otherwise 0. +.It Li USER_POSIX2_SW_DEV +Return 1 if the system supports the Software Development Utilities Option, +otherwise 0. +.It Li USER_POSIX2_UPE +Return 1 if the system supports the User Portability Utilities Option, +otherwise 0. +.It Li USER_POSIX2_VERSION +The version of +.St -p1003.2 +with which the system attempts to comply. +.It Li USER_RE_DUP_MAX +The maximum number of repeated occurrences of a regular expression +permitted when using interval notation. +.It Li USER_STREAM_MAX +The minimum maximum number of streams that a process may have open +at any one time. +.It Li USER_TZNAME_MAX +The minimum maximum number of types supported for the name of a +timezone. +.El +.Ss CTL_VM +The string and integer information available for the CTL_VM level +is detailed below. +The changeable column shows whether a process with appropriate +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" +.El +.Pp +.Bl -tag -width 6n +.It Li VM_LOADAVG +Return the load average history. +The returned data consists of a +.Va struct loadavg . +.It Li VM_METER +Return the system wide virtual memory statistics. +The returned data consists of a +.Va struct vmtotal . +.It Li VM_PAGEOUT_ALGORITHM +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 +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 +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) +required to be available before a process waiting on memory will be +awakened. +.It Li VM_V_FREE_RESERVED +Processes will awaken the pageout daemon and wait for memory if the +number of free and cached pages drops below this value. +.It Li VM_V_FREE_TARGET +The total amount of free memory (including cache memory) that the +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 +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 +pageout daemon will enter "memory conserving mode" to avoid deadlock. +.El +.Sh RETURN VALUES +.Rv -std +.Sh ERRORS +The following errors may be reported: +.Bl -tag -width Er +.It Bq Er EFAULT +The buffer +.Fa name , +.Fa oldp , +.Fa newp , +or length pointer +.Fa oldlenp +contains an invalid address. +.It Bq Er EINVAL +The +.Fa name +array is less than two or greater than CTL_MAXNAME. +.It Bq Er EINVAL +A non-null +.Fa newp +is given and its specified length in +.Fa newlen +is too large or too small. +.It Bq Er ENOMEM +The length pointed to by +.Fa oldlenp +is too short to hold the requested value. +.It Bq Er ENOTDIR +The +.Fa name +array specifies an intermediate rather than terminal name. +.It Bq Er EISDIR +The +.Fa name +array specifies a terminal name, but the actual name is not terminal. +.It Bq Er EOPNOTSUPP +The +.Fa name +array specifies a value that is unknown. +.It Bq Er EPERM +An attempt is made to set a read-only value. +.It Bq Er EPERM +A process without appropriate privilege attempts to set a value. +.El +.Sh FILES +.Bl -tag -width -compact +.It Aq Pa sys/sysctl.h +definitions for top level identifiers, second level kernel and hardware +identifiers, and user level identifiers +.It Aq Pa sys/socket.h +definitions for second level network identifiers +.It Aq Pa sys/gmon.h +definitions for third level profiling identifiers +.It Aq Pa vm/vm_param.h +definitions for second level virtual memory identifiers +.It Aq Pa netinet/in.h +definitions for third level IPv4/IPv6 identifiers and +fourth level IPv4/v6 identifiers +.It Aq Pa netinet/icmp_var.h +definitions for fourth level ICMP identifiers +.It Aq Pa netinet/icmp6.h +definitions for fourth level ICMPv6 identifiers +.It Aq Pa netinet/udp_var.h +definitions for fourth level UDP identifiers +.El +.Sh SEE ALSO +.Xr sysconf 3 , +.Xr sysctl 8 +.Sh HISTORY +The +.Fn sysctl +function first appeared in +.Bx 4.4 . diff --git a/gen/sysctl.c b/gen/sysctl.c new file mode 100644 index 0000000..0ba7784 --- /dev/null +++ b/gen/sysctl.c @@ -0,0 +1,195 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * 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 +#include + +#include +#include +#include +#include +#include + +int +sysctl(name, namelen, oldp, oldlenp, newp, newlen) + int *name; + u_int namelen; + void *oldp, *newp; + size_t *oldlenp, newlen; +{ + if (name[0] != CTL_USER) + return (__sysctl(name, namelen, oldp, oldlenp, newp, newlen)); + + if (newp != NULL) { + errno = EPERM; + return (-1); + } + if (namelen != 2) { + errno = EINVAL; + return (-1); + } + + switch (name[1]) { + case USER_CS_PATH: + if (oldp && *oldlenp < sizeof(_PATH_STDPATH)) + return (ENOMEM); + *oldlenp = sizeof(_PATH_STDPATH); + if (oldp != NULL) + memmove(oldp, _PATH_STDPATH, sizeof(_PATH_STDPATH)); + return (0); + } + + if (oldp && *oldlenp < sizeof(int)) + return (ENOMEM); + *oldlenp = sizeof(int); + if (oldp == NULL) + return (0); + + switch (name[1]) { + case USER_BC_BASE_MAX: + *(int *)oldp = BC_BASE_MAX; + return (0); + case USER_BC_DIM_MAX: + *(int *)oldp = BC_DIM_MAX; + return (0); + case USER_BC_SCALE_MAX: + *(int *)oldp = BC_SCALE_MAX; + return (0); + case USER_BC_STRING_MAX: + *(int *)oldp = BC_STRING_MAX; + return (0); + case USER_COLL_WEIGHTS_MAX: + *(int *)oldp = COLL_WEIGHTS_MAX; + return (0); + case USER_EXPR_NEST_MAX: + *(int *)oldp = EXPR_NEST_MAX; + return (0); + case USER_LINE_MAX: + *(int *)oldp = LINE_MAX; + return (0); + case USER_RE_DUP_MAX: + *(int *)oldp = RE_DUP_MAX; + return (0); + case USER_POSIX2_VERSION: + *(int *)oldp = _POSIX2_VERSION; + return (0); + case USER_POSIX2_C_BIND: +#ifdef POSIX2_C_BIND + *(int *)oldp = 1; +#else + *(int *)oldp = 0; +#endif + return (0); + case USER_POSIX2_C_DEV: +#ifdef POSIX2_C_DEV + *(int *)oldp = 1; +#else + *(int *)oldp = 0; +#endif + return (0); + case USER_POSIX2_CHAR_TERM: +#ifdef POSIX2_CHAR_TERM + *(int *)oldp = 1; +#else + *(int *)oldp = 0; +#endif + return (0); + case USER_POSIX2_FORT_DEV: +#ifdef POSIX2_FORT_DEV + *(int *)oldp = 1; +#else + *(int *)oldp = 0; +#endif + return (0); + case USER_POSIX2_FORT_RUN: +#ifdef POSIX2_FORT_RUN + *(int *)oldp = 1; +#else + *(int *)oldp = 0; +#endif + return (0); + case USER_POSIX2_LOCALEDEF: +#ifdef POSIX2_LOCALEDEF + *(int *)oldp = 1; +#else + *(int *)oldp = 0; +#endif + return (0); + case USER_POSIX2_SW_DEV: +#ifdef POSIX2_SW_DEV + *(int *)oldp = 1; +#else + *(int *)oldp = 0; +#endif + return (0); + case USER_POSIX2_UPE: +#ifdef POSIX2_UPE + *(int *)oldp = 1; +#else + *(int *)oldp = 0; +#endif + return (0); + case USER_STREAM_MAX: + *(int *)oldp = FOPEN_MAX; + return (0); + case USER_TZNAME_MAX: + *(int *)oldp = NAME_MAX; + return (0); + default: + errno = EINVAL; + return (-1); + } + /* NOTREACHED */ +} diff --git a/gen/sysctlbyname.c b/gen/sysctlbyname.c new file mode 100644 index 0000000..27e3ca9 --- /dev/null +++ b/gen/sysctlbyname.c @@ -0,0 +1,37 @@ +/* + * ---------------------------------------------------------------------------- + * "THE BEER-WARE LICENSE" (Revision 42): + * wrote this file. As long as you retain this notice you + * can do whatever you want with this stuff. If we meet some day, and you think + * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp + * ---------------------------------------------------------------------------- + * + * $FreeBSD: src/lib/libc/gen/sysctlbyname.c,v 1.4 1999/08/27 23:59:01 peter Exp $ + * + */ +#include +#include +#include + +int +sysctlbyname(const char *name, void *oldp, size_t *oldlenp, void *newp, + size_t newlen) +{ + int name2oid_oid[2]; + int real_oid[CTL_MAXNAME+2]; + int error; + size_t oidlen; + + name2oid_oid[0] = 0; /* This is magic & undocumented! */ + name2oid_oid[1] = 3; + + oidlen = sizeof(real_oid); + error = sysctl(name2oid_oid, 2, real_oid, &oidlen, (void *)name, + strlen(name)); + if (error < 0) + return error; + oidlen /= sizeof (int); + error = sysctl(real_oid, oidlen, oldp, oldlenp, newp, newlen); + return (error); +} + diff --git a/gen/syslog.3 b/gen/syslog.3 new file mode 100644 index 0000000..663c6d8 --- /dev/null +++ b/gen/syslog.3 @@ -0,0 +1,296 @@ +.\" Copyright (c) 1985, 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. +.\" +.\" @(#)syslog.3 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD: src/lib/libc/gen/syslog.3,v 1.22 2001/10/01 16:08:51 ru Exp $ +.\" +.Dd June 4, 1993 +.Dt SYSLOG 3 +.Os +.Sh NAME +.Nm syslog , +.Nm vsyslog , +.Nm openlog , +.Nm closelog , +.Nm setlogmask +.Nd control system log +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In syslog.h +.In stdarg.h +.Ft void +.Fn syslog "int priority" "const char *message" "..." +.Ft void +.Fn vsyslog "int priority" "const char *message" "va_list args" +.Ft void +.Fn openlog "const char *ident" "int logopt" "int facility" +.Ft void +.Fn closelog void +.Ft int +.Fn setlogmask "int maskpri" +.Sh DESCRIPTION +The +.Fn syslog +function +writes +.Fa message +to the system message logger. +The message is then written to the system console, log files, +logged-in users, or forwarded to other machines as appropriate. +(See +.Xr syslogd 8 . ) +.Pp +The message is identical to a +.Xr printf 3 +format string, except that +.Ql %m +is replaced by the current error +message. +(As denoted by the global variable +.Va errno ; +see +.Xr strerror 3 . ) +A trailing newline is added if none is present. +.Pp +The +.Fn vsyslog +function +is an alternate form in which the arguments have already been captured +using the variable-length argument facilities of +.Xr stdarg 3 . +.Pp +The message is tagged with +.Fa priority . +Priorities are encoded as a +.Fa facility +and a +.Em level . +The facility describes the part of the system +generating the message. +The level is selected from the following +.Em ordered +(high to low) list: +.Bl -tag -width LOG_AUTHPRIV +.It Dv LOG_EMERG +A panic condition. +This is normally broadcast to all users. +.It Dv LOG_ALERT +A condition that should be corrected immediately, such as a corrupted +system database. +.It Dv LOG_CRIT +Critical conditions, e.g., hard device errors. +.It Dv LOG_ERR +Errors. +.It Dv LOG_WARNING +Warning messages. +.It Dv LOG_NOTICE +Conditions that are not error conditions, +but should possibly be handled specially. +.It Dv LOG_INFO +Informational messages. +.It Dv LOG_DEBUG +Messages that contain information +normally of use only when debugging a program. +.El +.Pp +The +.Fn openlog +function +provides for more specialized processing of the messages sent +by +.Fn syslog +and +.Fn vsyslog . +The parameter +.Fa ident +is a string that will be prepended to every message. +The +.Fa logopt +argument +is a bit field specifying logging options, which is formed by +.Tn OR Ns 'ing +one or more of the following values: +.Bl -tag -width LOG_AUTHPRIV +.It Dv LOG_CONS +If +.Fn syslog +cannot pass the message to +.Xr syslogd 8 +it will attempt to write the message to the console +.Pq Dq Pa /dev/console . +.It Dv LOG_NDELAY +Open the connection to +.Xr syslogd 8 +immediately. +Normally the open is delayed until the first message is logged. +Useful for programs that need to manage the order in which file +descriptors are allocated. +.It Dv LOG_PERROR +Write the message to standard error output as well to the system log. +.It Dv LOG_PID +Log the process id with each message: useful for identifying +instantiations of daemons. +.El +.Pp +The +.Fa facility +parameter encodes a default facility to be assigned to all messages +that do not have an explicit facility encoded: +.Bl -tag -width LOG_AUTHPRIV +.It Dv LOG_AUTH +The authorization system: +.Xr login 1 , +.Xr su 1 , +.Xr getty 8 , +etc. +.It Dv LOG_AUTHPRIV +The same as +.Dv LOG_AUTH , +but logged to a file readable only by +selected individuals. +.It Dv LOG_CONSOLE +Messages written to +.Pa /dev/console +by the kernel console output driver. +.It Dv LOG_CRON +The cron daemon: +.Xr cron 8 . +.It Dv LOG_DAEMON +System daemons, such as +.Xr routed 8 , +that are not provided for explicitly by other facilities. +.It Dv LOG_FTP +The file transfer protocol daemons: +.Xr ftpd 8 , +.Xr tftpd 8 . +.It Dv LOG_KERN +Messages generated by the kernel. +These cannot be generated by any user processes. +.It Dv LOG_LPR +The line printer spooling system: +.Xr lpr 1 , +.Xr lpc 8 , +.Xr lpd 8 , +etc. +.It Dv LOG_MAIL +The mail system. +.It Dv LOG_NEWS +The network news system. +.It Dv LOG_SECURITY +Security subsystems, such as +.Xr ipfw 4 . +.It Dv LOG_SYSLOG +Messages generated internally by +.Xr syslogd 8 . +.It Dv LOG_USER +Messages generated by random user processes. +This is the default facility identifier if none is specified. +.It Dv LOG_UUCP +The uucp system. +.It Dv LOG_LOCAL0 +Reserved for local use. +Similarly for +.Dv LOG_LOCAL1 +through +.Dv LOG_LOCAL7 . +.El +.Pp +The +.Fn closelog +function +can be used to close the log file. +.Pp +The +.Fn setlogmask +function +sets the log priority mask to +.Fa maskpri +and returns the previous mask. +Calls to +.Fn syslog +with a priority not set in +.Fa maskpri +are rejected. +The mask for an individual priority +.Fa pri +is calculated by the macro +.Fn LOG_MASK pri ; +the mask for all priorities up to and including +.Fa toppri +is given by the macro +.Fn LOG_UPTO toppri ; . +The default allows all priorities to be logged. +.Sh RETURN VALUES +The routines +.Fn closelog , +.Fn openlog , +.Fn syslog +and +.Fn vsyslog +return no value. +.Pp +The routine +.Fn setlogmask +always returns the previous log mask level. +.Sh EXAMPLES +.Bd -literal -offset indent -compact +syslog(LOG_ALERT, "who: internal error 23"); + +openlog("ftpd", LOG_PID | LOG_NDELAY, LOG_FTP); + +setlogmask(LOG_UPTO(LOG_ERR)); + +syslog(LOG_INFO, "Connection from host %d", CallingHost); + +syslog(LOG_INFO|LOG_LOCAL2, "foobar error: %m"); +.Ed +.Sh SEE ALSO +.Xr logger 1 , +.Xr syslogd 8 +.Sh HISTORY +These +functions appeared in +.Bx 4.2 . +.Sh BUGS +Never pass a string with user-supplied data as a format without using +.Ql %s . +An attacker can put format specifiers in the string to mangle your stack, +leading to a possible security hole. +This holds true even if the string was built using a function like +.Fn snprintf , +as the resulting string may still contain user-supplied conversion specifiers +for later interpolation by +.Fn syslog . +.Pp +Always use the proper secure idiom: +.Pp +.Dl syslog("%s", string); diff --git a/gen/syslog.c b/gen/syslog.c new file mode 100644 index 0000000..cd3985f --- /dev/null +++ b/gen/syslog.c @@ -0,0 +1,307 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * 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 +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#ifdef __STDC__ +#include +#else +#include +#endif + +#include + +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 */ + +/* + * 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)) & LogMask)) + return; + + saved_errno = errno; + + /* Set default facility if none specified. */ + if ((pri & LOG_FACMASK) == 0) + pri |= 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 (LogStat & LOG_PERROR) + stdp = p; + if (LogTag == NULL) + LogTag = *(*_NSGetArgv()); + if (LogTag != NULL) { + prlen = snprintf(p, tbuf_left, "%s", LogTag); + DEC(); + } + if (LogStat & LOG_PID) { + prlen = snprintf(p, tbuf_left, "[%d]", getpid()); + DEC(); + } + if (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 (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 (!connected) + openlog(LogTag, LogStat | LOG_NDELAY, 0); + if (send(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) { + 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); + } +} + +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) + LogTag = ident; + LogStat = logstat; + if (logfac != 0 && (logfac &~ LOG_FACMASK) == 0) + LogFacility = logfac; + + if (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); + } + } + if (LogFile != -1 && !connected) + if (connect(LogFile, &SyslogAddr, sizeof(SyslogAddr)) == -1) { + (void)close(LogFile); + LogFile = -1; + } else + connected = 1; +} + +void +closelog() +{ + (void)close(LogFile); + LogFile = -1; + connected = 0; +} + +/* setlogmask -- set the log mask level */ +int +setlogmask(pmask) + int pmask; +{ + int omask; + + omask = LogMask; + if (pmask != 0) + LogMask = pmask; + return (omask); +} diff --git a/gen/tcgetpgrp.3 b/gen/tcgetpgrp.3 new file mode 100644 index 0000000..b155763 --- /dev/null +++ b/gen/tcgetpgrp.3 @@ -0,0 +1,82 @@ +.\" 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. +.\" +.\" @(#)tcgetpgrp.3 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD: src/lib/libc/gen/tcgetpgrp.3,v 1.8 2001/10/01 16:08:51 ru Exp $ +.\" +.Dd June 4, 1993 +.Dt TCGETPGRP 3 +.Os +.Sh NAME +.Nm tcgetpgrp +.Nd get foreground process group ID +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In sys/types.h +.In unistd.h +.Ft pid_t +.Fn tcgetpgrp "int fd" +.Sh DESCRIPTION +The +.Fn tcgetpgrp +function returns the value of the process group ID of the foreground +process group associated with the terminal device. +If there is no foreground process group, +.Fn tcgetpgrp +returns an invalid process ID. +.Sh ERRORS +If an error occurs, +.Fn tcgetpgrp +returns -1 and the global variable +.Va errno +is set to indicate the error, as follows: +.Bl -tag -width Er +.It Bq Er EBADF +The +.Fa fd +argument is not a valid file descriptor. +.It Bq Er ENOTTY +The calling process does not have a controlling terminal or the +underlying terminal device represented by +.Fa fd +is not the controlling terminal. +.El +.Sh SEE ALSO +.Xr setpgid 2 , +.Xr setsid 2 , +.Xr tcsetpgrp 3 +.Sh STANDARDS +The +.Fn tcgetpgrp +function is expected to be compliant with the +.St -p1003.1-88 +specification. diff --git a/gen/tcsendbreak.3 b/gen/tcsendbreak.3 new file mode 100644 index 0000000..e47779a --- /dev/null +++ b/gen/tcsendbreak.3 @@ -0,0 +1,157 @@ +.\" 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. +.\" +.\" @(#)tcsendbreak.3 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD: src/lib/libc/gen/tcsendbreak.3,v 1.8 2001/10/01 16:08:51 ru Exp $ +.\" +.Dd June 4, 1993 +.Dt TCSENDBREAK 3 +.Os +.Sh NAME +.Nm tcsendbreak , +.Nm tcdrain , +.Nm tcflush , +.Nm tcflow +.Nd line control functions +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In termios.h +.Ft int +.Fn tcdrain "int fd" +.Ft int +.Fn tcflow "int fd" "int action" +.Ft int +.Fn tcflush "int fd" "int action" +.Ft int +.Fn tcsendbreak "int fd" "int len" +.Sh DESCRIPTION +The +.Fn tcdrain +function waits until all output written to the terminal referenced by +.Fa fd +has been transmitted to the terminal. +.Pp +The +.Fn tcflow +function suspends transmission of data to or the reception of data from +the terminal referenced by +.Fa fd +depending on the value of +.Fa action . +The value of +.Fa action +must be one of the following: +.Bl -tag -width "TCIOFF" +.It Fa TCOOFF +Suspend output. +.It Fa TCOON +Restart suspended output. +.It Fa TCIOFF +Transmit a STOP character, which is intended to cause the terminal to stop +transmitting data to the system. +(See the description of IXOFF in the +.Ql Input Modes +section of +.Xr termios 4 ) . +.It Fa TCION +Transmit a START character, which is intended to cause the terminal to start +transmitting data to the system. +(See the description of IXOFF in the +.Ql Input Modes +section of +.Xr termios 4 ) . +.El +.Pp +The +.Fn tcflush +function discards any data written to the terminal referenced by +.Fa fd +which has not been transmitted to the terminal, or any data received +from the terminal but not yet read, depending on the value of +.Fa action . +The value of +.Fa action +must be one of the following: +.Bl -tag -width "TCIOFLUSH" +.It Fa TCIFLUSH +Flush data received but not read. +.It Fa TCOFLUSH +Flush data written but not transmitted. +.It Fa TCIOFLUSH +Flush both data received but not read and data written but not transmitted. +.El +.Pp +The +.Fn tcsendbreak +function transmits a continuous stream of zero-valued bits for four-tenths +of a second to the terminal referenced by +.Fa fd . +The +.Fa len +parameter is ignored in this implementation. +.Sh RETURN VALUES +Upon successful completion, all of these functions return a value of zero. +.Sh ERRORS +If any error occurs, a value of -1 is returned and the global variable +.Va errno +is set to indicate the error, as follows: +.Bl -tag -width Er +.It Bq Er EBADF +The +.Fa fd +argument is not a valid file descriptor. +.It Bq Er EINVAL +The +.Fa action +argument is not a proper value. +.It Bq Er ENOTTY +The file associated with +.Fa fd +is not a terminal. +.It Bq Er EINTR +A signal interrupted the +.Fn tcdrain +function. +.El +.Sh SEE ALSO +.Xr tcsetattr 3 , +.Xr termios 4 +.Sh STANDARDS +The +.Fn tcsendbreak , +.Fn tcdrain , +.Fn tcflush +and +.Fn tcflow +functions are expected to be compliant with the +.St -p1003.1-88 +specification. diff --git a/gen/tcsetattr.3 b/gen/tcsetattr.3 new file mode 100644 index 0000000..a4a3182 --- /dev/null +++ b/gen/tcsetattr.3 @@ -0,0 +1,333 @@ +.\" 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. +.\" +.\" @(#)tcsetattr.3 8.3 (Berkeley) 1/2/94 +.\" $FreeBSD: src/lib/libc/gen/tcsetattr.3,v 1.9 2001/10/01 16:08:51 ru Exp $ +.\" +.Dd January 2, 1994 +.Dt TCSETATTR 3 +.Os +.Sh NAME +.Nm cfgetispeed , +.Nm cfsetispeed , +.Nm cfgetospeed , +.Nm cfsetospeed , +.Nm cfsetspeed , +.Nm cfmakeraw , +.Nm tcgetattr , +.Nm tcsetattr +.Nd manipulating the termios structure +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In termios.h +.Ft speed_t +.Fn cfgetispeed "const struct termios *t" +.Ft int +.Fn cfsetispeed "struct termios *t" "speed_t speed" +.Ft speed_t +.Fn cfgetospeed "const struct termios *t" +.Ft int +.Fn cfsetospeed "struct termios *t" "speed_t speed" +.Ft int +.Fn cfsetspeed "struct termios *t" "speed_t speed" +.Ft void +.Fn cfmakeraw "struct termios *t" +.Ft int +.Fn tcgetattr "int fd" "struct termios *t" +.Ft int +.Fn tcsetattr "int fd" "int action" "const struct termios *t" +.Sh DESCRIPTION +The +.Fn cfmakeraw , +.Fn tcgetattr +and +.Fn tcsetattr +functions are provided for getting and setting the termios structure. +.Pp +The +.Fn cfgetispeed , +.Fn cfsetispeed , +.Fn cfgetospeed , +.Fn cfsetospeed +and +.Fn cfsetspeed +functions are provided for getting and setting the baud rate values in +the termios structure. +The effects of the functions on the terminal as described below +do not become effective, nor are all errors detected, until the +.Fn tcsetattr +function is called. +Certain values for baud rates set in the termios structure and passed to +.Fn tcsetattr +have special meanings. +These are discussed in the portion of the manual page that describes the +.Fn tcsetattr +function. +.Sh GETTING AND SETTING THE BAUD RATE +The input and output baud rates are found in the termios structure. +The unsigned integer +.Li speed_t +is typdef'd in the include file +.Aq Pa termios.h . +The value of the integer corresponds directly to the baud rate being +represented, however, the following symbolic values are defined. +.Bd -literal +#define B0 0 +#define B50 50 +#define B75 75 +#define B110 110 +#define B134 134 +#define B150 150 +#define B200 200 +#define B300 300 +#define B600 600 +#define B1200 1200 +#define B1800 1800 +#define B2400 2400 +#define B4800 4800 +#define B9600 9600 +#define B19200 19200 +#define B38400 38400 +#ifndef _POSIX_SOURCE +#define EXTA 19200 +#define EXTB 38400 +#endif /*_POSIX_SOURCE */ +.Ed +.Pp +The +.Fn cfgetispeed +function returns the input baud rate in the termios structure referenced by +.Fa tp . +.Pp +The +.Fn cfsetispeed +function sets the input baud rate in the termios structure referenced by +.Fa tp +to +.Fa speed . +.Pp +The +.Fn cfgetospeed +function returns the output baud rate in the termios structure referenced by +.Fa tp . +.Pp +The +.Fn cfsetospeed +function sets the output baud rate in the termios structure referenced by +.Fa tp +to +.Fa speed . +.Pp +The +.Fn cfsetspeed +function sets both the input and output baud rate in the termios structure +referenced by +.Fa tp +to +.Fa speed . +.Pp +Upon successful completion, the functions +.Fn cfsetispeed , +.Fn cfsetospeed , +and +.Fn cfsetspeed +return a value of 0. +Otherwise, a value of -1 is returned and the global variable +.Va errno +is set to indicate the error. +.Sh GETTING AND SETTING THE TERMIOS STATE +This section describes the functions that are used to control the general +terminal interface. +Unless otherwise noted for a specific command, these functions are restricted +from use by background processes. +Attempts to perform these operations shall cause the process group to be sent +a SIGTTOU signal. +If the calling process is blocking or ignoring SIGTTOU signals, the process +is allowed to perform the operation and the SIGTTOU signal is not sent. +.Pp +In all the functions, although +.Fa fd +is an open file descriptor, the functions affect the underlying terminal +file, not just the open file description associated with the particular +file descriptor. +.Pp +The +.Fn cfmakeraw +function sets the flags stored in the termios structure to a state disabling +all input and output processing, giving a +.Dq raw I/O path . +It should be noted that there is no function to reverse this effect. +This is because there are a variety of processing options that could be +re-enabled and the correct method is for an application to snapshot the +current terminal state using the function +.Fn tcgetattr , +setting raw mode with +.Fn cfmakeraw +and the subsequent +.Fn tcsetattr , +and then using another +.Fn tcsetattr +with the saved state to revert to the previous terminal state. +.Pp +The +.Fn tcgetattr +function copies the parameters associated with the terminal referenced +by +.Fa fd +in the termios structure referenced by +.Fa tp . +This function is allowed from a background process, however, the terminal +attributes may be subsequently changed by a foreground process. +.Pp +The +.Fn tcsetattr +function sets the parameters associated with the terminal from the +termios structure referenced by +.Fa tp . +The +.Fa action +field is created by +.Em or Ns 'ing +the following values, as specified in the include file +.Aq Pa termios.h . +.Bl -tag -width "TCSADRAIN" +.It Fa TCSANOW +The change occurs immediately. +.It Fa TCSADRAIN +The change occurs after all output written to +.Fa fd +has been transmitted to the terminal. +This value of +.Fa action +should be used when changing parameters that affect output. +.It Fa TCSAFLUSH +The change occurs after all output written to +.Fa fd +has been transmitted to the terminal. +Additionally, any input that has been received but not read is discarded. +.It Fa TCSASOFT +If this value is +.Em or Ns 'ed +into the +.Fa action +value, the values of the +.Em c_cflag , +.Em c_ispeed , +and +.Em c_ospeed +fields are ignored. +.El +.Pp +The 0 baud rate is used to terminate the connection. +If 0 is specified as the output speed to the function +.Fn tcsetattr , +modem control will no longer be asserted on the terminal, disconnecting +the terminal. +.Pp +If zero is specified as the input speed to the function +.Fn tcsetattr , +the input baud rate will be set to the same value as that specified by +the output baud rate. +.Pp +If +.Fn tcsetattr +is unable to make any of the requested changes, it returns -1 and +sets errno. +Otherwise, it makes all of the requested changes it can. +If the specified input and output baud rates differ and are a combination +that is not supported, neither baud rate is changed. +.Pp +Upon successful completion, the functions +.Fn tcgetattr +and +.Fn tcsetattr +return a value of 0. +Otherwise, they +return -1 and the global variable +.Va errno +is set to indicate the error, as follows: +.Bl -tag -width Er +.It Bq Er EBADF +The +.Fa fd +argument to +.Fn tcgetattr +or +.Fn tcsetattr +was not a valid file descriptor. +.It Bq Er EINTR +The +.Fn tcsetattr +function was interrupted by a signal. +.It Bq Er EINVAL +The +.Fa action +argument to the +.Fn tcsetattr +function was not valid, or an attempt was made to change an attribute +represented in the termios structure to an unsupported value. +.It Bq Er ENOTTY +The file associated with the +.Fa fd +argument to +.Fn tcgetattr +or +.Fn tcsetattr +is not a terminal. +.El +.Sh SEE ALSO +.Xr tcsendbreak 3 , +.Xr termios 4 +.Sh STANDARDS +The +.Fn cfgetispeed , +.Fn cfsetispeed , +.Fn cfgetospeed , +.Fn cfsetospeed , +.Fn tcgetattr +and +.Fn tcsetattr +functions are expected to be compliant with the +.St -p1003.1-88 +specification. +The +.Fn cfmakeraw +and +.Fn cfsetspeed +functions, +as well as the +.Li TCSASOFT +option to the +.Fn tcsetattr +function are extensions to the +.St -p1003.1-88 +specification. diff --git a/gen/tcsetpgrp.3 b/gen/tcsetpgrp.3 new file mode 100644 index 0000000..b50e6a8 --- /dev/null +++ b/gen/tcsetpgrp.3 @@ -0,0 +1,99 @@ +.\" 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. +.\" +.\" @(#)tcsetpgrp.3 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD: src/lib/libc/gen/tcsetpgrp.3,v 1.9 2001/10/01 16:08:51 ru Exp $ +.\" +.Dd June 4, 1993 +.Dt TCSETPGRP 3 +.Os +.Sh NAME +.Nm tcsetpgrp +.Nd set foreground process group ID +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In sys/types.h +.In unistd.h +.Ft int +.Fn tcsetpgrp "int fd" "pid_t pgrp_id" +.Sh DESCRIPTION +If the process has a controlling terminal, the +.Fn tcsetpgrp +function sets the foreground process group ID associated with the +terminal device to +.Fa pgrp_id . +The terminal device associated with +.Fa fd +must be the controlling terminal of the calling process and the +controlling terminal must be currently associated with the session +of the calling process. +The value of +.Fa pgrp_id +must be the same as the process group ID of a process in the same +session as the calling process. +.Sh RETURN VALUES +.Rv -std tcsetpgrp +.Sh ERRORS +The +.Fn tcsetpgrp +function will fail if: +.Bl -tag -width Er +.It Bq Er EBADF +The +.Fa fd +argument is not a valid file descriptor. +.It Bq Er EINVAL +An invalid value of +.Fa pgrp_id +was specified. +.It Bq Er ENOTTY +The calling process does not have a controlling terminal, or the file +represented by +.Fa fd +is not the controlling terminal, or the controlling terminal is no +longer associated with the session of the calling process. +.It Bq Er EPERM +The +.Fa pgrp_id +argument does not match the process group ID of a process in the same +session as the calling process. +.El +.Sh SEE ALSO +.Xr setpgid 2 , +.Xr setsid 2 , +.Xr tcgetpgrp 3 +.Sh STANDARDS +The +.Fn tcsetpgrp +function is expected to be compliant with the +.St -p1003.1-88 +specification. diff --git a/gen/telldir.c b/gen/telldir.c new file mode 100644 index 0000000..19d655e --- /dev/null +++ b/gen/telldir.c @@ -0,0 +1,146 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1983, 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 +#include +#include +#include + +/* + * The option SINGLEUSE may be defined to say that a telldir + * cookie may be used only once before it is freed. This option + * is used to avoid having memory usage grow without bound. + */ +#define SINGLEUSE + +/* + * One of these structures is malloced to describe the current directory + * position each time telldir is called. It records the current magic + * cookie returned by getdirentries and the offset within the buffer + * associated with that return value. + */ +struct ddloc { + struct ddloc *loc_next;/* next structure in list */ + long loc_index; /* key associated with structure */ + long loc_seek; /* magic cookie returned by getdirentries */ + long loc_loc; /* offset of entry in buffer */ +}; + +#define NDIRHASH 32 /* Num of hash lists, must be a power of 2 */ +#define LOCHASH(i) ((i)&(NDIRHASH-1)) + +static long dd_loccnt; /* Index of entry for sequential readdir's */ +static struct ddloc *dd_hash[NDIRHASH]; /* Hash list heads for ddlocs */ + +/* + * return a pointer into a directory + */ +long +telldir(dirp) + const DIR *dirp; +{ + register int index; + register struct ddloc *lp; + + if ((lp = (struct ddloc *)malloc(sizeof(struct ddloc))) == NULL) + return (-1); + index = dd_loccnt++; + lp->loc_index = index; + lp->loc_seek = dirp->dd_seek; + lp->loc_loc = dirp->dd_loc; + lp->loc_next = dd_hash[LOCHASH(index)]; + dd_hash[LOCHASH(index)] = lp; + return (index); +} + +/* + * seek to an entry in a directory. + * Only values returned by "telldir" should be passed to seekdir. + */ +void +_seekdir(dirp, loc) + register DIR *dirp; + long loc; +{ + register struct ddloc *lp; + register struct ddloc **prevlp; + struct dirent *dp; + + prevlp = &dd_hash[LOCHASH(loc)]; + lp = *prevlp; + while (lp != NULL) { + if (lp->loc_index == loc) + break; + prevlp = &lp->loc_next; + lp = lp->loc_next; + } + if (lp == NULL) + return; + if (lp->loc_loc == dirp->dd_loc && lp->loc_seek == dirp->dd_seek) + goto found; + (void) lseek(dirp->dd_fd, (off_t)lp->loc_seek, SEEK_SET); + dirp->dd_seek = lp->loc_seek; + dirp->dd_loc = 0; + while (dirp->dd_loc < lp->loc_loc) { + dp = readdir(dirp); + if (dp == NULL) + break; + } +found: +#ifdef SINGLEUSE + *prevlp = lp->loc_next; + free((caddr_t)lp); +#endif +} diff --git a/gen/termios.c b/gen/termios.c new file mode 100644 index 0000000..d4af066 --- /dev/null +++ b/gen/termios.c @@ -0,0 +1,260 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1989, 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 +#include +#include +#include +#define KERNEL /* XXX - FREAD and FWRITE ifdef'd KERNEL*/ +#include +#undef KERNEL + +#include +#include +#include +#include + +int +tcgetattr(fd, t) + int fd; + struct termios *t; +{ + + return (ioctl(fd, TIOCGETA, t)); +} + +int +tcsetattr(fd, opt, t) + int fd, opt; + const struct termios *t; +{ + struct termios localterm; + + if (opt & TCSASOFT) { + localterm = *t; + localterm.c_cflag |= CIGNORE; + t = &localterm; + } + switch (opt & ~TCSASOFT) { + case TCSANOW: + return (ioctl(fd, TIOCSETA, t)); + case TCSADRAIN: + return (ioctl(fd, TIOCSETAW, t)); + case TCSAFLUSH: + return (ioctl(fd, TIOCSETAF, t)); + default: + errno = EINVAL; + return (-1); + } +} + +int +#if __STDC__ +tcsetpgrp(int fd, pid_t pgrp) +#else +tcsetpgrp(fd, pgrp) + int fd; + pid_t pgrp; +#endif +{ + int s; + + s = pgrp; + return (ioctl(fd, TIOCSPGRP, &s)); +} + +pid_t +tcgetpgrp(fd) +{ + int s; + + if (ioctl(fd, TIOCGPGRP, &s) < 0) + return ((pid_t)-1); + + return ((pid_t)s); +} + +speed_t +cfgetospeed(t) + const struct termios *t; +{ + + return (t->c_ospeed); +} + +speed_t +cfgetispeed(t) + const struct termios *t; +{ + + return (t->c_ispeed); +} + +int +cfsetospeed(t, speed) + struct termios *t; + speed_t speed; +{ + + t->c_ospeed = speed; + return (0); +} + +int +cfsetispeed(t, speed) + struct termios *t; + speed_t speed; +{ + + t->c_ispeed = speed; + return (0); +} + +int +cfsetspeed(t, speed) + struct termios *t; + speed_t speed; +{ + + t->c_ispeed = t->c_ospeed = speed; + return (0); +} + +/* + * Make a pre-existing termios structure into "raw" mode: character-at-a-time + * mode with no characters interpreted, 8-bit data path. + */ +void +cfmakeraw(t) + struct termios *t; +{ + + t->c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP|INLCR|IGNCR|ICRNL|IXON); + t->c_oflag &= ~OPOST; + t->c_lflag &= ~(ECHO|ECHONL|ICANON|ISIG|IEXTEN); + t->c_cflag &= ~(CSIZE|PARENB); + t->c_cflag |= CS8; + /* XXX set MIN/TIME */ +} + +tcsendbreak(fd, len) + int fd, len; +{ + struct timeval sleepytime; + + sleepytime.tv_sec = 0; + sleepytime.tv_usec = 400000; + if (ioctl(fd, TIOCSBRK, 0) == -1) + return (-1); + (void)select(0, 0, 0, 0, &sleepytime); + if (ioctl(fd, TIOCCBRK, 0) == -1) + return (-1); + return (0); +} + +tcdrain(fd) + int fd; +{ + + return (ioctl(fd, TIOCDRAIN, 0)); +} + +tcflush(fd, which) + int fd, which; +{ + int com; + + switch (which) { + case TCIFLUSH: + com = FREAD; + break; + case TCOFLUSH: + com = FWRITE; + break; + case TCIOFLUSH: + com = FREAD | FWRITE; + break; + default: + errno = EINVAL; + return (-1); + } + return (ioctl(fd, TIOCFLUSH, &com)); +} + +tcflow(fd, action) + int fd, action; +{ + struct termios term; + u_char c; + + switch (action) { + case TCOOFF: + return (ioctl(fd, TIOCSTOP, 0)); + case TCOON: + return (ioctl(fd, TIOCSTART, 0)); + case TCION: + case TCIOFF: + if (tcgetattr(fd, &term) == -1) + return (-1); + c = term.c_cc[action == TCIOFF ? VSTOP : VSTART]; + if (c != _POSIX_VDISABLE && write(fd, &c, sizeof(c)) == -1) + return (-1); + return (0); + default: + errno = EINVAL; + return (-1); + } + /* NOTREACHED */ +} diff --git a/gen/time.3 b/gen/time.3 new file mode 100644 index 0000000..949c85a --- /dev/null +++ b/gen/time.3 @@ -0,0 +1,87 @@ +.\" Copyright (c) 1989, 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. +.\" +.\" @(#)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 $ +.\" +.Dd June 4, 1993 +.Dt TIME 3 +.Os +.Sh NAME +.Nm time +.Nd get time of day +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In time.h +.Ft time_t +.Fn time "time_t *tloc" +.Sh DESCRIPTION +The +.Fn time +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, +.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. +.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 +.Sh SEE ALSO +.Xr gettimeofday 2 , +.Xr ctime 3 +.Sh HISTORY +A +.Fn time +function appeared in +.At v6 . diff --git a/gen/time.c b/gen/time.c new file mode 100644 index 0000000..dcfd0b2 --- /dev/null +++ b/gen/time.c @@ -0,0 +1,70 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1983, 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 +#include + +time_t +time(t) + time_t *t; +{ + struct timeval tt; + + if (gettimeofday(&tt, (struct timezone *)0) < 0) + return(-1); + if (t) + *t = tt.tv_sec; + return(tt.tv_sec); +} diff --git a/gen/times.3 b/gen/times.3 new file mode 100644 index 0000000..6aa58c3 --- /dev/null +++ b/gen/times.3 @@ -0,0 +1,144 @@ +.\" Copyright (c) 1990, 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. +.\" +.\" @(#)times.3 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD: src/lib/libc/gen/times.3,v 1.10 2001/10/01 16:08:51 ru Exp $ +.\" +.Dd June 4, 1993 +.Dt TIMES 3 +.Os +.Sh NAME +.Nm times +.Nd process times +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In sys/times.h +.Ft clock_t +.Fn times "struct tms *tp" +.Sh DESCRIPTION +.Bf -symbolic +This interface is obsoleted by +.Xr getrusage 2 +and +.Xr gettimeofday 2 . +.Ef +.Pp +The +.Fn times +function returns the value of time in +.Dv CLK_TCK Ns 's +of a second since +0 hours, 0 minutes, 0 seconds, January 1, 1970, Coordinated Universal +Time. +.Pp +It also fills in the structure pointed to by +.Fa tp +with time-accounting information. +.Pp +The +.Vt tms +structure is defined as follows: +.Bd -literal -offset indent +struct tms { + clock_t tms_utime; + clock_t tms_stime; + clock_t tms_cutime; + clock_t tms_cstime; +}; +.Ed +.Pp +The elements of this structure are defined as follows: +.Bl -tag -width ".Va tms_cutime" +.It Va tms_utime +The +.Tn CPU +time charged for the execution of user instructions. +.It Va tms_stime +The +.Tn CPU +time charged for execution by the system on behalf of +the process. +.It Va tms_cutime +The sum of the +.Va tms_utime Ns s +and +.Va tms_cutime Ns s +of the child processes. +.It Va tms_cstime +The sum of the +.Fa tms_stime Ns s +and +.Fa tms_cstime Ns s +of the child processes. +.El +.Pp +All times are in +.Dv CLK_TCK Ns 's +of a second. +.Pp +The times of a terminated child process are included in the +.Va tms_cutime +and +.Va tms_cstime +elements of the parent when one of the +.Xr wait 2 +functions returns the process ID of the terminated child to the parent. +If an error occurs, +.Fn times +returns the value +.Pq Po Vt clock_t Pc Ns \-1 , +and sets +.Va errno +to indicate the error. +.Sh ERRORS +The +.Fn times +function +may fail and set the global variable +.Va errno +for any of the errors specified for the library +routines +.Xr getrusage 2 +and +.Xr gettimeofday 2 . +.Sh SEE ALSO +.Xr time 1 , +.Xr getrusage 2 , +.Xr gettimeofday 2 , +.Xr wait 2 , +.Xr clocks 7 +.Sh STANDARDS +The +.Fn times +function +conforms to +.St -p1003.1-88 . diff --git a/gen/times.c b/gen/times.c new file mode 100644 index 0000000..4b7c4e8 --- /dev/null +++ b/gen/times.c @@ -0,0 +1,85 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 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 +#include +#include +#include + +/* + * Convert usec to clock ticks; could do (usec * CLK_TCK) / 1000000, + * but this would overflow if we switch to nanosec. + */ +#define CONVTCK(r) (r.tv_sec * CLK_TCK + r.tv_usec / (1000000 / CLK_TCK)) + +clock_t +times(tp) + register struct tms *tp; +{ + struct rusage ru; + struct timeval t; + + if (getrusage(RUSAGE_SELF, &ru) < 0) + return ((clock_t)-1); + tp->tms_utime = CONVTCK(ru.ru_utime); + tp->tms_stime = CONVTCK(ru.ru_stime); + if (getrusage(RUSAGE_CHILDREN, &ru) < 0) + return ((clock_t)-1); + tp->tms_cutime = CONVTCK(ru.ru_utime); + tp->tms_cstime = CONVTCK(ru.ru_stime); + if (gettimeofday(&t, (struct timezone *)0)) + return ((clock_t)-1); + return ((clock_t)(CONVTCK(t))); +} diff --git a/gen/timezone.3 b/gen/timezone.3 new file mode 100644 index 0000000..bf1637f --- /dev/null +++ b/gen/timezone.3 @@ -0,0 +1,71 @@ +.\" 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. +.\" +.\" @(#)timezone.3 8.2 (Berkeley) 4/19/94 +.\" $FreeBSD: src/lib/libc/gen/timezone.3,v 1.7 2000/11/10 17:44:58 ru Exp $ +.\" +.Dd April 19, 1994 +.Dt TIMEZONE 3 +.Os +.Sh NAME +.Nm timezone +.Nd return the timezone abbreviation +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.Ft char * +.Fn timezone "int zone" "int dst" +.Sh DESCRIPTION +.Bf Sy +This interface is for compatibility only; it is impossible to reliably +map timezone's arguments to a time zone abbreviation. +See +.Xr ctime 3 . +.Ef +.Pp +The +.Fn timezone +function returns a pointer to a time zone abbreviation for the specified +.Ar zone +and +.Ar dst +values. +.Ar Zone +is the number of minutes west of GMT and +.Ar dst +is non-zero if daylight savings time is in effect. +.Sh SEE ALSO +.Xr ctime 3 +.Sh HISTORY +A +.Fn timezone +function appeared in +.At v7 . diff --git a/gen/timezone.c b/gen/timezone.c new file mode 100644 index 0000000..c175032 --- /dev/null +++ b/gen/timezone.c @@ -0,0 +1,152 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1987, 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 +#include +#include +#include +#include +#include + +char *_tztab(); + +/* + * timezone -- + * The arguments are the number of minutes of time you are westward + * from Greenwich and whether DST is in effect. It returns a string + * giving the name of the local timezone. Should be replaced, in the + * application code, by a call to localtime. + */ + +static char czone[TZ_MAX_CHARS]; /* space for zone name */ + +char * +timezone(zone, dst) + int zone, + dst; +{ + register char *beg, + *end; + + if (beg = getenv("TZNAME")) { /* set in environment */ + if (end = index(beg, ',')) { /* "PST,PDT" */ + if (dst) + return(++end); + *end = '\0'; + (void)strncpy(czone,beg,sizeof(czone) - 1); + czone[sizeof(czone) - 1] = '\0'; + *end = ','; + return(czone); + } + return(beg); + } + return(_tztab(zone,dst)); /* default: table or created zone */ +} + +static struct zone { + int offset; + char *stdzone; + char *dlzone; +} zonetab[] = { + -1*60, "MET", "MET DST", /* Middle European */ + -2*60, "EET", "EET DST", /* Eastern European */ + 4*60, "AST", "ADT", /* Atlantic */ + 5*60, "EST", "EDT", /* Eastern */ + 6*60, "CST", "CDT", /* Central */ + 7*60, "MST", "MDT", /* Mountain */ + 8*60, "PST", "PDT", /* Pacific */ +#ifdef notdef + /* there's no way to distinguish this from WET */ + 0, "GMT", 0, /* Greenwich */ +#endif + 0*60, "WET", "WET DST", /* Western European */ + -10*60, "EST", "EST", /* Aust: Eastern */ + -10*60+30, "CST", "CST", /* Aust: Central */ + -8*60, "WST", 0, /* Aust: Western */ + -1 +}; + +/* + * _tztab -- + * check static tables or create a new zone name; broken out so that + * we can make a guess as to what the zone is if the standard tables + * aren't in place in /etc. DO NOT USE THIS ROUTINE OUTSIDE OF THE + * STANDARD LIBRARY. + */ +char * +_tztab(zone,dst) + register int zone; + int dst; +{ + register struct zone *zp; + register char sign; + + for (zp = zonetab; zp->offset != -1;++zp) /* static tables */ + if (zp->offset == zone) { + if (dst && zp->dlzone) + return(zp->dlzone); + if (!dst && zp->stdzone) + return(zp->stdzone); + } + + if (zone < 0) { /* create one */ + zone = -zone; + sign = '+'; + } + else + sign = '-'; + (void)sprintf(czone,"GMT%c%d:%02d",sign,zone / 60,zone % 60); + return(czone); +} diff --git a/gen/ttyname.3 b/gen/ttyname.3 new file mode 100644 index 0000000..8a4b649 --- /dev/null +++ b/gen/ttyname.3 @@ -0,0 +1,131 @@ +.\" 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. +.\" +.\" @(#)ttyname.3 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD: src/lib/libc/gen/ttyname.3,v 1.9 2001/10/01 16:08:51 ru Exp $ +.\" +.Dd June 4, 1993 +.Dt TTYNAME 3 +.Os +.Sh NAME +.Nm ttyname , +.Nm isatty , +.Nm ttyslot +.Nd get name of associated terminal (tty) from file descriptor +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In unistd.h +.Ft char * +.Fn ttyname "int fd" +.Ft int +.Fn isatty "int fd" +.Ft int +.Fn ttyslot void +.Sh DESCRIPTION +These functions operate on the system file descriptors for terminal +type devices. +These descriptors are not related to the standard +.Tn I/O +.Dv FILE +typedef, but refer to the special device files found in +.Pa /dev +and named +.Pa /dev/tty Ns Em xx +and for which an entry exists +in the initialization file +.Pa /etc/ttys . +(See +.Xr ttys 5 . ) +.Pp +The +.Fn isatty +function +determines if the file descriptor +.Fa fd +refers to a valid +terminal type device. +.Pp +The +.Fn ttyname +function +gets the related device name of +a file descriptor for which +.Fn isatty +is true +.Pp +The +.Fn ttyslot +function +fetches the current process' control terminal number from the +.Xr ttys 5 +file entry. +.Sh RETURN VALUES +The +.Fn ttyname +function +returns the null terminated name if the device is found and +.Fn isatty +is true; otherwise +a +.Dv NULL +pointer is returned. +.Pp +The +.Fn ttyslot +function +returns the unit number of the device file if found; otherwise +the value zero is returned. +.Sh FILES +.Bl -tag -width /etc/ttys -compact +.It Pa /dev/\(** +.It Pa /etc/ttys +.El +.Sh SEE ALSO +.Xr ioctl 2 , +.Xr ttys 5 +.Sh HISTORY +A +.Fn isatty , +.Fn ttyname , +and +.Fn ttyslot +function +appeared in +.At v7 . +.Sh BUGS +The +.Fn ttyname +function leaves its result in an internal static object and returns +a pointer to that object. +Subsequent calls to +.Fn ttyname +will modify the same object. diff --git a/gen/ttyname.c b/gen/ttyname.c new file mode 100644 index 0000000..db31a9a --- /dev/null +++ b/gen/ttyname.c @@ -0,0 +1,147 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1988, 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 +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +static char *buf = NULL; +static char *oldttyname __P((int, struct stat *)); + +char * +ttyname(fd) + int fd; +{ + struct stat sb; + struct termios term; + DB *db; + DBT data, key; + struct { + mode_t type; + dev_t dev; + } bkey; + + if( buf == NULL ) { + buf = malloc(sizeof(_PATH_DEV) + MAXNAMLEN); + if( buf == NULL ) + return NULL; + strcpy(buf, _PATH_DEV); + } + + /* Must be a terminal. */ + if (ioctl(fd, TIOCGETA, &term) < 0) + return (NULL); + /* Must be a character device. */ + if (fstat(fd, &sb) || !S_ISCHR(sb.st_mode)) + return (NULL); + + db = dbopen(_PATH_DEVDB, O_RDONLY, 0, DB_HASH, NULL); + if (db) { + 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(fd, sb) + int fd; + struct stat *sb; +{ + register struct dirent *dirp; + register DIR *dp; + struct stat dsb; + + if( buf == NULL ) { + buf = malloc(sizeof(_PATH_DEV) + MAXNAMLEN); + if( buf == NULL ) + return NULL; + strcpy(buf, _PATH_DEV); + } + 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); +} diff --git a/gen/ttyslot.c b/gen/ttyslot.c new file mode 100644 index 0000000..bb3cfb5 --- /dev/null +++ b/gen/ttyslot.c @@ -0,0 +1,86 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1988, 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 +#include +#include +#include + +int +ttyslot() +{ + register struct ttyent *ttyp; + register int slot; + register char *p; + int cnt; + char *name; + + setttyent(); + for (cnt = 0; cnt < 3; ++cnt) + if (name = ttyname(cnt)) { + if (p = rindex(name, '/')) + ++p; + else + p = name; + for (slot = 1; ttyp = getttyent(); ++slot) + if (!strcmp(ttyp->ty_name, p)) { + endttyent(); + return(slot); + } + break; + } + endttyent(); + return(0); +} diff --git a/gen/tzset.3 b/gen/tzset.3 new file mode 100644 index 0000000..0d718f0 --- /dev/null +++ b/gen/tzset.3 @@ -0,0 +1,327 @@ +.\" Copyright (c) 1989, 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" This code is derived from software contributed to Berkeley by +.\" Arthur Olson. +.\" +.\" 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. +.\" +.\" @(#)tzset.3 8.2 (Berkeley) 11/17/93 +.\" $FreeBSD: src/lib/libc/gen/tzset.3,v 1.12 2001/10/01 16:08:51 ru Exp $ +.\" +.Dd November 17, 1993 +.Dt TZSET 3 +.Os +.Sh NAME +.Nm tzset , +.Nm tzsetwall +.Nd initialize time conversion information +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In time.h +.Ft void +.Fn tzset void +.Ft void +.Fn tzsetwall void +.Sh DESCRIPTION +The +.Fn tzset +function +initializes time conversion information used by the library routine +.Xr localtime 3 . +The environment variable +.Ev TZ +specifies how this is done. +.Pp +If +.Ev TZ +does not appear in the environment, the best available approximation to +local wall clock time, as specified by the +.Xr tzfile 5 Ns -format +file +.Pa /etc/localtime +is used. +.Pp +If +.Ev TZ +appears in the environment but its value is a null string, Coordinated +Universal Time +.Pq Tn UTC +is used (without leap second correction). +.Pp +If +.Ev TZ +appears in the environment and its value begins with a colon +.Pq Ql \&: , +the rest of its value is used as a pathname of a +.Xr tzfile 5 Ns -format +file from which to read the time conversion information. +If the first character of the pathname is a slash +.Pq Ql / +it is used as +an absolute pathname; otherwise, it is used as a pathname relative to +the system time conversion information directory. +.Pp +If its value does not begin with a colon, it is first used as the pathname +of a file (as described above) from which to read the time conversion +information. +If that file cannot be read, the value is then interpreted as a direct +specification (the format is described below) of the time conversion +information. +.Pp +If the +.Ev TZ +environment variable does not specify a +.Xr tzfile 5 Ns -format +file and cannot be interpreted as a direct specification, +.Tn UTC +is used. +.Pp +The +.Fn tzsetwall +function +sets things up so that +.Xr localtime +returns the best available approximation of local wall clock time. +.Sh SPECIFICATION FORMAT +When +.Ev TZ +is used directly as a specification of the time conversion information, +it must have the following syntax (spaces inserted for clarity): +.Bd -ragged -offset indent +.Em std offset +.Bo +.Em dst +.Bq Em offset +.Bq , Em rule +.Bc +.Ed +.Pp +Where: +.Bl -tag -width std_and_dst -offset indent +.It Em std No and Em dst +Three or more bytes that are the designation for the standard +.Pq Em std +or summer +.Pq Em dst +time zone. Only +.Em std +is required; if +.Em dst +is missing, then summer time does not apply in this locale. +Upper and lowercase letters are explicitly allowed. Any characters +except a leading colon +.Pq Ql \&: , +digits, comma +.Pq Ql \&, , +minus +.Pq Ql \- , +plus +.Pq Ql + , +and +.Tn ASCII +.Dv NUL +are allowed. +.It Em offset +Indicates the value one must add to the local time to arrive at +Coordinated Universal Time. The +.Em offset +has the form: +.Bd -ragged -offset indent +.Sm off +.Em hh Bo +.Em : mm +.Bq Em : ss +.Bc +.Sm on +.Ed +.Pp +The minutes +.Pq Em mm +and seconds +.Pq Em ss +are optional. The hour +.Pq Em hh +is required and may be a single digit. The +.Em offset +following +.Em std +is required. If no +.Em offset +follows +.Em dst , +summer time is assumed to be one hour ahead of standard time. One or +more digits may be used; the value is always interpreted as a decimal +number. The hour must be between zero and 24, and the minutes (and +seconds) \(em if present \(em between zero and 59. If preceded by a +.Pq Ql \- +the time zone shall be east of the Prime Meridian; otherwise it shall be +west (which may be indicated by an optional preceding +.Pq Ql + ) . +.It Em rule +Indicates when to change to and back from summer time. The +.Em rule +has the form: +.Bd -ragged -offset indent +.Em date/time,date/time +.Ed +.Pp +where the first +.Em date +describes when the change from standard to summer time occurs and the +second +.Em date +describes when the change back happens. Each +.Em time +field describes when, in current local time, the change to the other +time is made. +.Pp +The format of +.Em date +is one of the following: +.Bl -tag -width "M.m.n.d" +.It Sy J Em n +The Julian day +.Em n +(1 \*(Le +.Em n +\*(Le 365). +Leap days are not counted; that is, in all years \(em including leap +years \(em February 28 is day 59 and March 1 is day 60. It is +impossible to explicitly refer to the occasional February 29. +.It Em n +The zero-based Julian day +(0 \*(Le +.Em n +\*(Le 365 ) . +Leap days are counted, and it is possible to refer to February 29. +.It Sy M Em m.n.d +The +.Em d Ns 'th +day (0 \*(Le +.Em d +\*(Le 6) +of week +.Em n +of month +.Em m +of the year +(1 \*(Le +.Em n +\*(Le 5), +(1 \*(Le +.Em m +\*(Le 12), +where week 5 means +.Do +the last +.Em d +day in month +.Em m +.Dc +which may occur in either the fourth or the fifth week). Week 1 is the +first week in which the +.Em d Ns 'th +day occurs. Day zero is Sunday. +.Pp +The +.Em time +has the same format as +.Em offset +except that no leading sign +.Pq Ql \- +or +.Pq Ql + +is allowed. The default, if +.Em time +is not given, is +.Sy 02:00:00 . +.El +.Pp +If no +.Em rule +is present in the +.Ev TZ +specification, the rules specified +by the +.Xr tzfile 5 Ns -format +file +.Em posixrules +in the system time conversion information directory are used, with the +standard and summer time offsets from +.Tn UTC +replaced by those specified by +the +.Em offset +values in +.Ev TZ . +.El +.Pp +For compatibility with System V Release 3.1, a semicolon +.Pq Ql \&; +may be used to separate the +.Em rule +from the rest of the specification. +.Sh FILES +.Bl -tag -width /usr/share/zoneinfo/posixrules -compact +.It Pa /etc/localtime +local time zone file +.It Pa /usr/share/zoneinfo +time zone directory +.It Pa /usr/share/zoneinfo/posixrules +rules for +.Tn POSIX Ns -style +.Tn TZ Ns 's +.It Pa /usr/share/zoneinfo/GMT +for +.Tn UTC +leap seconds +.El +.Pp +If the file +.Pa /usr/share/zoneinfo/GMT +does not exist, +.Tn UTC +leap seconds are loaded from +.Pa /usr/share/zoneinfo/posixrules . +.Sh SEE ALSO +.Xr date 1 , +.Xr gettimeofday 2 , +.Xr ctime 3 , +.Xr getenv 3 , +.Xr time 3 , +.Xr tzfile 5 +.Sh HISTORY +The +.Fn tzset +and +.Fn tzsetwall +functions first appeared in +.Bx 4.4 . diff --git a/gen/ualarm.3 b/gen/ualarm.3 new file mode 100644 index 0000000..0f4774f --- /dev/null +++ b/gen/ualarm.3 @@ -0,0 +1,101 @@ +.\" Copyright (c) 1986, 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. +.\" +.\" 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 $ +.\" +.Dd April 19, 1994 +.Dt UALARM 3 +.Os +.Sh NAME +.Nm ualarm +.Nd schedule signal after specified time +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In unistd.h +.Ft u_int +.Fn ualarm "u_int microseconds" "u_int interval" +.Sh DESCRIPTION +.Bf -symbolic +This is a simplified interface to +.Xr setitimer 2 . +.Ef +.Pp +The +.Fn ualarm +function +waits a count of +.Ar microseconds +before asserting the terminating signal +.Dv SIGALRM . +System activity or time used in processing the call may cause a slight +delay. +.Pp +If the +.Fa interval +argument is non-zero, the +.Dv SIGALRM +signal will be sent +to the process every +.Fa interval +microseconds after the timer expires (e.g. after +.Fa value +microseconds have passed). +.Pp +Due to +.Xr setitimer 2 +restriction the maximum number of +.Ar microseconds +and +.Ar interval +is limited to 100000000000000 +(in case this value fit in the unsigned integer). +.Sh RETURN VALUES +When the signal has successfully been caught, +.Fn ualarm +returns the amount of time left on the clock. +.Sh NOTES +A microsecond is 0.000001 seconds. +.Sh SEE ALSO +.Xr getitimer 2 , +.Xr setitimer 2 , +.Xr sigpause 2 , +.Xr sigvec 2 , +.Xr alarm 3 , +.Xr signal 3 , +.Xr sleep 3 , +.Xr usleep 3 +.Sh HISTORY +The +.Fn ualarm +function appeared in +.Bx 4.3 . diff --git a/gen/ualarm.c b/gen/ualarm.c new file mode 100644 index 0000000..d057766 --- /dev/null +++ b/gen/ualarm.c @@ -0,0 +1,83 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1985, 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 +#include + +#define USPS 1000000 /* # of microseconds in a second */ + +/* + * Generate a SIGALRM signal in ``usecs'' microseconds. + * If ``reload'' is non-zero, keep generating SIGALRM + * every ``reload'' microseconds after the first signal. + */ +unsigned +ualarm(usecs, reload) + register unsigned usecs; + register unsigned reload; +{ + struct itimerval new, old; + + new.it_interval.tv_usec = reload % USPS; + new.it_interval.tv_sec = reload / USPS; + + new.it_value.tv_usec = usecs % USPS; + new.it_value.tv_sec = usecs / USPS; + + if (setitimer(ITIMER_REAL, &new, &old) == 0) + return (old.it_value.tv_sec * USPS + old.it_value.tv_usec); + /* else */ + return (-1); +} diff --git a/gen/ulimit.c b/gen/ulimit.c new file mode 100644 index 0000000..af68b84 --- /dev/null +++ b/gen/ulimit.c @@ -0,0 +1,32 @@ +#include +#include +#include +#include +#include +#include +#include + +long int ulimit( int cmd, ... ) +{ + va_list ap; + struct rlimit rlim; + + switch (cmd ) { + case UL_GETFSIZE: + if( getrlimit( RLIMIT_FSIZE, &rlim ) < 0 ) + return -1; + return rlim.rlim_cur/512; + case UL_SETFSIZE: + va_start(ap, cmd); + rlim.rlim_cur = 512 * va_arg(ap, long int); + rlim.rlim_max = rlim.rlim_cur; + va_end(ap); + return setrlimit( RLIMIT_FSIZE, &rlim ); + default: + errno = EINVAL; + return -1; + } + /* NOT REACHED */ + errno = EINVAL; + return -1; +} diff --git a/gen/uname.3 b/gen/uname.3 new file mode 100644 index 0000000..85b417d --- /dev/null +++ b/gen/uname.3 @@ -0,0 +1,92 @@ +.\" Copyright (c) 1994 +.\" 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. +.\" +.\" @(#)uname.3 8.1 (Berkeley) 1/4/94 +.\" $FreeBSD: src/lib/libc/gen/uname.3,v 1.10 2001/10/01 16:08:51 ru Exp $ +.\" +.Dd January 4, 1994 +.Dt UNAME 3 +.Os +.Sh NAME +.Nm uname +.Nd get system identification +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In sys/utsname.h +.Ft int +.Fn uname "struct utsname *name" +.Sh DESCRIPTION +The +.Fn uname +function stores nul-terminated strings of information identifying +the current system into the structure referenced by +.Fa name . +.Pp +The +.Vt utsname +structure is defined in the +.Aq Pa sys/utsname.h +header file, and contains the following members: +.Bl -tag -width nodenameXXXX -offset indent +.It sysname +Name of the operating system implementation. +.It nodename +Network name of this machine. +.It release +Release level of the operating system. +.It version +Version level of the operating system. +.It machine +Machine hardware platform. +.El +.Sh RETURN VALUES +.Rv -std uname +.Sh ERRORS +The +.Fn uname +function may fail and set +.Va errno +for any of the errors specified for the library functions +.Xr sysctl 3 . +.Sh SEE ALSO +.Xr uname 1 , +.Xr sysctl 3 +.Sh STANDARDS +The +.Fn uname +function conforms to +.St -p1003.1-88 . +.Sh HISTORY +The +.Fn uname +function first appeared in +.Bx 4.4 . diff --git a/gen/uname.c b/gen/uname.c new file mode 100644 index 0000000..f3d8ed7 --- /dev/null +++ b/gen/uname.c @@ -0,0 +1,108 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1994 + * 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 +#include +#include + +int +uname(name) + struct utsname *name; +{ + int mib[2], rval; + size_t len; + char *p; + + rval = 0; + + mib[0] = CTL_KERN; + mib[1] = KERN_OSTYPE; + len = sizeof(name->sysname); + if (sysctl(mib, 2, &name->sysname, &len, NULL, 0) == -1) + rval = -1; + + mib[0] = CTL_KERN; + mib[1] = KERN_HOSTNAME; + len = sizeof(name->nodename); + if (sysctl(mib, 2, &name->nodename, &len, NULL, 0) == -1) + rval = -1; + + mib[0] = CTL_KERN; + mib[1] = KERN_OSRELEASE; + len = sizeof(name->release); + if (sysctl(mib, 2, &name->release, &len, NULL, 0) == -1) + rval = -1; + + /* The version may have newlines in it, turn them into spaces. */ + mib[0] = CTL_KERN; + mib[1] = KERN_VERSION; + len = sizeof(name->version); + if (sysctl(mib, 2, &name->version, &len, NULL, 0) == -1) + rval = -1; + else + for (p = name->version; len--; ++p) + if (*p == '\n' || *p == '\t') + if (len > 1) + *p = ' '; + else + *p = '\0'; + + mib[0] = CTL_HW; + mib[1] = HW_MACHINE; + len = sizeof(name->machine); + if (sysctl(mib, 2, &name->machine, &len, NULL, 0) == -1) + rval = -1; + return (rval); +} diff --git a/gen/unvis.3 b/gen/unvis.3 new file mode 100644 index 0000000..35e36b6 --- /dev/null +++ b/gen/unvis.3 @@ -0,0 +1,196 @@ +.\" Copyright (c) 1989, 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. +.\" +.\" @(#)unvis.3 8.2 (Berkeley) 12/11/93 +.\" $FreeBSD: src/lib/libc/gen/unvis.3,v 1.14 2001/10/01 16:08:51 ru Exp $ +.\" +.Dd December 11, 1993 +.Dt UNVIS 3 +.Os +.Sh NAME +.Nm unvis , +.Nm strunvis +.Nd decode a visual representation of characters +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In vis.h +.Ft int +.Fn unvis "char *cp" "int c" "int *astate" "int flag" +.Ft int +.Fn strunvis "char *dst" "const char *src" +.Ft int +.Fn strunvisx "char *dst" "const char *src" "int flag" +.Sh DESCRIPTION +The +.Fn unvis , +.Fn strunvis +and +.Fn strunvisx +functions +are used to decode a visual representation of characters, as produced +by the +.Xr vis 3 +function, back into +the original form. Unvis is called with successive characters in +.Ar c +until a valid +sequence is recognized, at which time the decoded character is +available at the character pointed to by +.Ar cp . +Strunvis decodes the +characters pointed to by +.Ar src +into the buffer pointed to by +.Ar dst . +.Pp +The +.Fn strunvis +function +simply copies +.Ar src +to +.Ar dst , +decoding any escape sequences along the way, +and returns the number of characters placed into +.Ar dst , +or \-1 if an +invalid escape sequence was detected. The size of +.Ar dst +should be +equal to the size of +.Ar src +(that is, no expansion takes place during +decoding). +.Pp +The +.Fn strunvisx +function does the same as the +.Fn strunvis +function, +but it allows you to add a flag that specifies the style the string +.Ar src +is encoded with. +Currently, the only supported flag is +.Dv VIS_HTTPSTYLE . +.Pp +The +.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 +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 +start decoding a stream of bytes, first initialize an integer +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: +.Bl -tag -width UNVIS_VALIDPUSH +.It Li \&0 (zero) +Another character is necessary; nothing has been recognized yet. +.It Dv UNVIS_VALID +A valid character has been recognized and is available at the location +pointed to by cp. +.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 +return code is necessary to indicate a logical break between characters. +.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. +.El +.Pp +When all bytes in the stream have been processed, call +.Fn unvis +one more time with +.Ar flag +set to +.Dv UNVIS_END +to extract any remaining character (the character passed in is ignored). +.Pp +The +.Ar flag +argument is also used to specify the encoding style of the source. +If set to +.Dv VIS_HTTPSTYLE , +.Fn unvis +will decode URI strings as specified in RFC 1808. +.Pp +The following code fragment illustrates a proper use of +.Fn unvis . +.Bd -literal -offset indent +int state = 0; +char out; + +while ((ch = getchar()) != EOF) { +again: + switch(unvis(&out, ch, &state, 0)) { + case 0: + case UNVIS_NOCHAR: + break; + case UNVIS_VALID: + (void) putchar(out); + break; + case UNVIS_VALIDPUSH: + (void) putchar(out); + goto again; + case UNVIS_SYNBAD: + (void)fprintf(stderr, "bad sequence!\en"); + exit(1); + } +} +if (unvis(&out, (char)0, &state, UNVIS_END) == UNVIS_VALID) + (void) putchar(out); +.Ed +.Sh SEE ALSO +.Xr vis 1 , +.Xr vis 3 +.Rs +.%A R. Fielding +.%T Relative Uniform Resource Locators +.%O RFC1808 +.Re +.Sh HISTORY +The +.Fn unvis +function +first appeared in +.Bx 4.4 . diff --git a/gen/unvis.c b/gen/unvis.c new file mode 100644 index 0000000..0272875 --- /dev/null +++ b/gen/unvis.c @@ -0,0 +1,266 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1989, 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 +#include +#include + +/* + * decode driven by state machine + */ +#define S_GROUND 0 /* haven't seen escape char */ +#define S_START 1 /* start decoding special sequence */ +#define S_META 2 /* metachar started (M) */ +#define S_META1 3 /* metachar more, regular char (-) */ +#define S_CTRL 4 /* control char started (^) */ +#define S_OCTAL2 5 /* octal digit 2 */ +#define S_OCTAL3 6 /* octal digit 3 */ + +#define isoctal(c) (((u_char)(c)) >= '0' && ((u_char)(c)) <= '7') + +/* + * unvis - decode characters previously encoded by vis + */ +int +unvis(cp, c, astate, flag) + char *cp; + int c, *astate, flag; +{ + + if (flag & UNVIS_END) { + if (*astate == S_OCTAL2 || *astate == S_OCTAL3) { + *astate = S_GROUND; + return (UNVIS_VALID); + } + return (*astate == S_GROUND ? UNVIS_NOCHAR : UNVIS_SYNBAD); + } + + switch (*astate) { + + case S_GROUND: + *cp = 0; + if (c == '\\') { + *astate = S_START; + return (0); + } + *cp = c; + return (UNVIS_VALID); + + case S_START: + switch(c) { + case '\\': + *cp = c; + *astate = S_GROUND; + return (UNVIS_VALID); + case '0': case '1': case '2': case '3': + case '4': case '5': case '6': case '7': + *cp = (c - '0'); + *astate = S_OCTAL2; + return (0); + case 'M': + *cp = 0200; + *astate = S_META; + return (0); + case '^': + *astate = S_CTRL; + return (0); + case 'n': + *cp = '\n'; + *astate = S_GROUND; + return (UNVIS_VALID); + case 'r': + *cp = '\r'; + *astate = S_GROUND; + return (UNVIS_VALID); + case 'b': + *cp = '\b'; + *astate = S_GROUND; + return (UNVIS_VALID); + case 'a': + *cp = '\007'; + *astate = S_GROUND; + return (UNVIS_VALID); + case 'v': + *cp = '\v'; + *astate = S_GROUND; + return (UNVIS_VALID); + case 't': + *cp = '\t'; + *astate = S_GROUND; + return (UNVIS_VALID); + case 'f': + *cp = '\f'; + *astate = S_GROUND; + return (UNVIS_VALID); + case 's': + *cp = ' '; + *astate = S_GROUND; + return (UNVIS_VALID); + case 'E': + *cp = '\033'; + *astate = S_GROUND; + return (UNVIS_VALID); + case '\n': + /* + * hidden newline + */ + *astate = S_GROUND; + return (UNVIS_NOCHAR); + case '$': + /* + * hidden marker + */ + *astate = S_GROUND; + return (UNVIS_NOCHAR); + } + *astate = S_GROUND; + return (UNVIS_SYNBAD); + + case S_META: + if (c == '-') + *astate = S_META1; + else if (c == '^') + *astate = S_CTRL; + else { + *astate = S_GROUND; + return (UNVIS_SYNBAD); + } + return (0); + + case S_META1: + *astate = S_GROUND; + *cp |= c; + return (UNVIS_VALID); + + case S_CTRL: + if (c == '?') + *cp |= 0177; + else + *cp |= c & 037; + *astate = S_GROUND; + return (UNVIS_VALID); + + case S_OCTAL2: /* second possible octal digit */ + if (isoctal(c)) { + /* + * yes - and maybe a third + */ + *cp = (*cp << 3) + (c - '0'); + *astate = S_OCTAL3; + return (0); + } + /* + * no - done with current sequence, push back passed char + */ + *astate = S_GROUND; + return (UNVIS_VALIDPUSH); + + case S_OCTAL3: /* third possible octal digit */ + *astate = S_GROUND; + if (isoctal(c)) { + *cp = (*cp << 3) + (c - '0'); + return (UNVIS_VALID); + } + /* + * we were done, push back passed char + */ + return (UNVIS_VALIDPUSH); + + default: + /* + * decoder in unknown state - (probably uninitialized) + */ + *astate = S_GROUND; + return (UNVIS_SYNBAD); + } +} + +/* + * strunvis - decode src into dst + * + * Number of chars decoded into dst is returned, -1 on error. + * Dst is null terminated. + */ + +int +strunvis(dst, src) + register char *dst; + register const char *src; +{ + register char c; + char *start = dst; + int state = 0; + + while (c = *src++) { + again: + switch (unvis(dst, c, &state, 0)) { + case UNVIS_VALID: + dst++; + break; + case UNVIS_VALIDPUSH: + dst++; + goto again; + case 0: + case UNVIS_NOCHAR: + break; + default: + return (-1); + } + } + if (unvis(dst, c, &state, UNVIS_END) == UNVIS_VALID) + dst++; + *dst = '\0'; + return (dst - start); +} diff --git a/gen/usleep.3 b/gen/usleep.3 new file mode 100644 index 0000000..058c7d5 --- /dev/null +++ b/gen/usleep.3 @@ -0,0 +1,84 @@ +.\" Copyright (c) 1986, 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. +.\" +.\" @(#)usleep.3 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD: src/lib/libc/gen/usleep.3,v 1.10.2.7 2001/12/14 18:33:51 ru Exp $ +.\" +.Dd February 13, 1998 +.Dt USLEEP 3 +.Os +.Sh NAME +.Nm usleep +.Nd suspend process execution for an interval measured in microseconds +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In unistd.h +.Ft int +.Fn usleep "unsigned int microseconds" +.Sh DESCRIPTION +The +.Fn usleep +function suspends execution of the calling process until either +.Fa microseconds +microseconds have elapsed or a signal is delivered to the process and its +action is to invoke a signal-catching function or to terminate the +process. +System activity may lengthen the sleep by an indeterminate amount. +.Pp +This function is implemented using +.Xr nanosleep 2 +by pausing for +.Fa microseconds +microseconds or until a signal occurs. +Consequently, in this implementation, +sleeping has no effect on the state of process timers, +and there is no special handling for SIGALRM. +.Sh RETURN VALUES +.Rv -std usleep +.Sh ERRORS +The +.Fn usleep +function +will fail if: +.Bl -tag -width Er +.It Bq Er EINTR +A signal was delivered to the process and its +action was to invoke a signal-catching function. +.El +.Sh SEE ALSO +.Xr nanosleep 2 , +.Xr sleep 3 +.Sh HISTORY +The +.Fn usleep +function appeared in +.Bx 4.3 . diff --git a/gen/usleep.c b/gen/usleep.c new file mode 100644 index 0000000..15004e1 --- /dev/null +++ b/gen/usleep.c @@ -0,0 +1,54 @@ +/* + * Copyright (c) 1989, 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) +#if 0 +static char sccsid[] = "@(#)usleep.c 8.1 (Berkeley) 6/4/93"; +#endif +static char rcsid[] = + "$FreeBSD: src/lib/libc/gen/usleep.c,v 1.25 2000/01/27 23:06:22 jasone Exp $"; +#endif /* LIBC_SCCS and not lint */ + +#include +#include + +int +usleep(useconds) + unsigned int useconds; +{ + struct timespec time_to_sleep; + + time_to_sleep.tv_nsec = (useconds % 1000000) * 1000; + time_to_sleep.tv_sec = useconds / 1000000; + return (nanosleep(&time_to_sleep, NULL)); +} diff --git a/gen/utime.3 b/gen/utime.3 new file mode 100644 index 0000000..deb5336 --- /dev/null +++ b/gen/utime.3 @@ -0,0 +1,91 @@ +.\" 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. +.\" +.\" @(#)utime.3 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD: src/lib/libc/gen/utime.3,v 1.10 2001/10/01 16:08:51 ru Exp $ +.\" +.Dd June 4, 1993 +.Dt UTIME 3 +.Os +.Sh NAME +.Nm utime +.Nd set file times +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In sys/types.h +.In utime.h +.Ft int +.Fn utime "const char *file" "const struct utimbuf *timep" +.Sh DESCRIPTION +.Bf -symbolic +This interface is obsoleted by +.Xr utimes 2 . +.Ef +.Pp +The +.Fn utime +function sets the access and modification times of the named file from +the structures in the argument array +.Fa timep . +.Pp +If the times are specified (the +.Fa timep +argument is +.Pf non- Dv NULL ) +the caller must be the owner of the file or be the super-user. +.Pp +If the times are not specified (the +.Fa timep +argument is +.Dv NULL ) +the caller must be the owner of the file, have permission to write +the file, or be the super-user. +.Sh ERRORS +The +.Fn utime +function may fail and set +.Va errno +for any of the errors specified for the library function +.Xr utimes 2 . +.Sh SEE ALSO +.Xr stat 2 , +.Xr utimes 2 +.Sh HISTORY +A +.Fn utime +function appeared in +.At v7 . +.Sh STANDARDS +The +.Fn utime +function conforms to +.St -p1003.1-88 . diff --git a/gen/utime.c b/gen/utime.c new file mode 100644 index 0000000..cdddca7 --- /dev/null +++ b/gen/utime.c @@ -0,0 +1,75 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 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 + +#include + +int +utime(path, times) + const char *path; + const struct utimbuf *times; +{ + struct timeval tv[2], *tvp; + + if (times) { + tv[0].tv_sec = times->actime; + tv[1].tv_sec = times->modtime; + tv[0].tv_usec = tv[1].tv_usec = 0; + tvp = tv; + } else + tvp = NULL; + return (utimes(path, tvp)); +} diff --git a/gen/valloc.3 b/gen/valloc.3 new file mode 100644 index 0000000..051922b --- /dev/null +++ b/gen/valloc.3 @@ -0,0 +1,74 @@ +.\" 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. +.\" +.\" @(#)valloc.3 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD: src/lib/libc/gen/valloc.3,v 1.9 2001/10/01 16:08:51 ru Exp $ +.\" +.Dd June 4, 1993 +.Dt VALLOC 3 +.Os +.Sh NAME +.Nm valloc +.Nd aligned memory allocation function +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In unistd.h +.Ft void * +.Fn valloc "size_t size" +.Sh DESCRIPTION +.Bf -symbolic +The +.Fn valloc +function +allocates +.Fa size +bytes aligned on a page boundary. +It is implemented by calling +.Xr malloc 3 +with a slightly larger request, saving the true beginning of the block +allocated, and returning a properly aligned pointer. +.Sh RETURN VALUES +The +.Fn valloc +function returns +a pointer to the allocated space if successful; otherwise +a null pointer is returned +.Sh HISTORY +The +.Fn valloc +function appeared in +.Bx 3.0 . +.Sh BUGS +A +.Em vfree +function +has not been implemented. diff --git a/gen/vis.3 b/gen/vis.3 new file mode 100644 index 0000000..cd5f307 --- /dev/null +++ b/gen/vis.3 @@ -0,0 +1,277 @@ +.\" Copyright (c) 1989, 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. +.\" +.\" From: @(#)vis.3 8.1 (Berkeley) 6/9/93 +.\" $FreeBSD: src/lib/libc/gen/vis.3,v 1.18 2001/10/01 16:08:51 ru Exp $ +.\" +.Dd July 25, 1996 +.Dt VIS 3 +.Os +.Sh NAME +.Nm vis +.Nd visually encode characters +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In vis.h +.Ft char * +.Fn vis "char *dst" "int c" "int flag" "int nextc" +.Ft int +.Fn strvis "char *dst" "const char *src" "int flag" +.Ft int +.Fn strvisx "char *dst" "const char *src" "size_t len" "int flag" +.Sh DESCRIPTION +The +.Fn vis +function +copies into +.Fa dst +a string which represents the character +.Fa c . +If +.Fa c +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 +characters (not including the trailing +.Dv NUL ) ; +thus, when +encoding a set of characters into a buffer, the size of the buffer should +be four times the number of characters encoded, plus one for the trailing +.Dv NUL . +The flag parameter is used for altering the default range of +characters considered for encoding and for altering the visual +representation. +The additional character, +.Fa nextc , +is only used when selecting the +.Dv VIS_CSTYLE +encoding format (explained below). +.Pp +The +.Fn strvis +and +.Fn strvisx +functions copy into +.Fa dst +a visual representation of +the string +.Fa src . +The +.Fn strvis +function encodes characters from +.Fa src +up to the +first +.Dv NUL . +The +.Fn strvisx +function encodes exactly +.Fa len +characters from +.Fa src +(this +is useful for encoding a block of data that may contain +.Dv NUL Ns 's ) . +Both forms +.Dv NUL +terminate +.Fa dst . +The size of +.Fa dst +must be four times the number +of characters encoded from +.Fa src +(plus one for the +.Dv NUL ) . +Both +forms return the number of characters in dst (not including +the trailing +.Dv NUL ) . +.Pp +The encoding is a unique, invertible representation composed entirely of +graphic characters; it can be decoded back into the original form using +the +.Xr unvis 3 +or +.Xr strunvis 3 +functions. +.Pp +There are two parameters that can be controlled: the range of +characters that are encoded, and the type +of representation used. +By default, all non-graphic characters +except space, tab, and newline are encoded. +(See +.Xr isgraph 3 . ) +The following flags +alter this: +.Bl -tag -width VIS_WHITEX +.It Dv VIS_SP +Also encode space. +.It Dv VIS_TAB +Also encode tab. +.It Dv VIS_NL +Also encode newline. +.It Dv VIS_WHITE +Synonym for +.Dv VIS_SP +\&| +.Dv VIS_TAB +\&| +.Dv VIS_NL . +.It Dv VIS_SAFE +Only encode "unsafe" characters. Unsafe means control +characters which may cause common terminals to perform +unexpected functions. Currently this form allows space, +tab, newline, backspace, bell, and return - in addition +to all graphic characters - unencoded. +.El +.Pp +There are four forms of encoding. +Most forms use the backslash character +.Ql \e +to introduce a special +sequence; two backslashes are used to represent a real backslash. +These are the visual formats: +.Bl -tag -width VIS_HTTPSTYLE +.It (default) +Use an +.Ql M +to represent meta characters (characters with the 8th +bit set), and use carat +.Ql ^ +to represent control characters see +.Pf ( Xr iscntrl 3 ) . +The following formats are used: +.Bl -tag -width xxxxx +.It Dv \e^C +Represents the control character +.Ql C . +Spans characters +.Ql \e000 +through +.Ql \e037 , +and +.Ql \e177 +(as +.Ql \e^? ) . +.It Dv \eM-C +Represents character +.Ql C +with the 8th bit set. +Spans characters +.Ql \e241 +through +.Ql \e376 . +.It Dv \eM^C +Represents control character +.Ql C +with the 8th bit set. +Spans characters +.Ql \e200 +through +.Ql \e237 , +and +.Ql \e377 +(as +.Ql \eM^? ) . +.It Dv \e040 +Represents +.Tn ASCII +space. +.It Dv \e240 +Represents Meta-space. +.El +.Pp +.It Dv VIS_CSTYLE +Use C-style backslash sequences to represent standard non-printable +characters. +The following sequences are used to represent the indicated characters: +.Bd -unfilled -offset indent +.Li \ea Tn - BEL No (007) +.Li \eb Tn - BS No (010) +.Li \ef Tn - NP No (014) +.Li \en Tn - NL No (012) +.Li \er Tn - CR No (015) +.Li \et Tn - HT No (011) +.Li \ev Tn - VT No (013) +.Li \e0 Tn - NUL No (000) +.Ed +.Pp +When using this format, the nextc parameter is looked at to determine +if a +.Dv NUL +character can be encoded as +.Ql \e0 +instead of +.Ql \e000 . +If +.Fa nextc +is an octal digit, the latter representation is used to +avoid ambiguity. +.It Dv VIS_HTTPSTYLE +Use URI encoding as described in RFC 1808. +The form is +.Ql %dd +where +.Em d +represents a hexadecimal digit. +.It Dv VIS_OCTAL +Use a three digit octal sequence. The form is +.Ql \eddd +where +.Em d +represents an octal digit. +.El +.Pp +There is one additional flag, +.Dv VIS_NOSLASH , +which inhibits the +doubling of backslashes and the backslash before the default +format (that is, control characters are represented by +.Ql ^C +and +meta characters as +.Ql M-C ) . +With this flag set, the encoding is +ambiguous and non-invertible. +.Sh SEE ALSO +.Xr unvis 1 , +.Xr unvis 3 +.Rs +.%A R. Fielding +.%T Relative Uniform Resource Locators +.%O RFC1808 +.Re +.Sh HISTORY +These functions first appeared in +.Bx 4.4 . diff --git a/gen/vis.c b/gen/vis.c new file mode 100644 index 0000000..4b6924e --- /dev/null +++ b/gen/vis.c @@ -0,0 +1,204 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1989, 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 +#include +#include +#include + +#define isoctal(c) (((u_char)(c)) >= '0' && ((u_char)(c)) <= '7') + +/* + * vis - visually encode characters + */ +char * +vis(dst, c, flag, nextc) + register char *dst; + int c, nextc; + register int flag; +{ + if ((u_int)c <= UCHAR_MAX && isgraph(c) || + ((flag & VIS_SP) == 0 && c == ' ') || + ((flag & VIS_TAB) == 0 && c == '\t') || + ((flag & VIS_NL) == 0 && c == '\n') || + ((flag & VIS_SAFE) && (c == '\b' || c == '\007' || c == '\r'))) { + *dst++ = c; + if (c == '\\' && (flag & VIS_NOSLASH) == 0) + *dst++ = '\\'; + *dst = '\0'; + return (dst); + } + + if (flag & VIS_CSTYLE) { + switch(c) { + case '\n': + *dst++ = '\\'; + *dst++ = 'n'; + goto done; + case '\r': + *dst++ = '\\'; + *dst++ = 'r'; + goto done; + case '\b': + *dst++ = '\\'; + *dst++ = 'b'; + goto done; +#if __STDC__ + case '\a': +#else + case '\007': +#endif + *dst++ = '\\'; + *dst++ = 'a'; + goto done; + case '\v': + *dst++ = '\\'; + *dst++ = 'v'; + goto done; + case '\t': + *dst++ = '\\'; + *dst++ = 't'; + goto done; + case '\f': + *dst++ = '\\'; + *dst++ = 'f'; + goto done; + case ' ': + *dst++ = '\\'; + *dst++ = 's'; + goto done; + case '\0': + *dst++ = '\\'; + *dst++ = '0'; + if (isoctal(nextc)) { + *dst++ = '0'; + *dst++ = '0'; + } + goto done; + } + } + if (((c & 0177) == ' ') || (flag & VIS_OCTAL)) { + *dst++ = '\\'; + *dst++ = ((u_char)c >> 6 & 07) + '0'; + *dst++ = ((u_char)c >> 3 & 07) + '0'; + *dst++ = ((u_char)c & 07) + '0'; + goto done; + } + if ((flag & VIS_NOSLASH) == 0) + *dst++ = '\\'; + if (c & 0200) { + c &= 0177; + *dst++ = 'M'; + } + if (iscntrl(c)) { + *dst++ = '^'; + if (c == 0177) + *dst++ = '?'; + else + *dst++ = c + '@'; + } else { + *dst++ = '-'; + *dst++ = c; + } +done: + *dst = '\0'; + return (dst); +} + +/* + * strvis, strvisx - visually encode characters from src into dst + * + * Dst must be 4 times the size of src to account for possible + * expansion. The length of dst, not including the trailing NULL, + * is returned. + * + * Strvisx encodes exactly len bytes from src into dst. + * This is useful for encoding a block of data. + */ +int +strvis(dst, src, flag) + register char *dst; + register const char *src; + int flag; +{ + register char c; + char *start; + + for (start = dst; c = *src;) + dst = vis(dst, c, flag, *++src); + *dst = '\0'; + return (dst - start); +} + +int +strvisx(dst, src, len, flag) + register char *dst; + register const char *src; + register size_t len; + int flag; +{ + int c; + char *start; + + for (start = dst; len > 1; len--) { + c = *src; + dst = vis(dst, c, flag, *++src); + } + if (len) + dst = vis(dst, *src, flag, '\0'); + *dst = '\0'; + + return (dst - start); +} diff --git a/gen/wait.c b/gen/wait.c new file mode 100644 index 0000000..216853a --- /dev/null +++ b/gen/wait.c @@ -0,0 +1,65 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1988, 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 +#include +#include +#include + +pid_t wait(istat) + int *istat; +{ + return (wait4(WAIT_ANY, istat, 0, (struct rusage *)0)); +} + diff --git a/gen/wait3.c b/gen/wait3.c new file mode 100644 index 0000000..e516385 --- /dev/null +++ b/gen/wait3.c @@ -0,0 +1,67 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1988, 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 +#include +#include +#include + +pid_t +wait3(istat, options, rup) + int *istat; + int options; + struct rusage *rup; +{ + return (wait4(WAIT_ANY, istat, options, rup)); +} diff --git a/gen/waitpid.c b/gen/waitpid.c new file mode 100644 index 0000000..f60a2f1 --- /dev/null +++ b/gen/waitpid.c @@ -0,0 +1,72 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1988, 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 +#include +#include +#include + +pid_t +#if __STDC__ +waitpid(pid_t pid, int *istat, int options) +#else +waitpid(pid, istat, options) + pid_t pid; + int *istat; + int options; +#endif +{ + return (wait4(pid, istat, options, (struct rusage *)0)); +} diff --git a/gen/zone.c b/gen/zone.c new file mode 100644 index 0000000..0f4610f --- /dev/null +++ b/gen/zone.c @@ -0,0 +1,120 @@ +/* + * Copyright (c) 1999 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@ + */ + +#import +#import +#import + +/********* NX functions ************/ + +malloc_zone_t *NXDefaultMallocZone() { + return malloc_default_zone(); +} + +malloc_zone_t *NXCreateZone(size_t startsize, size_t granularity, int canfree) { + return malloc_create_zone(startsize, 0); +} + +void NXNameZone(malloc_zone_t *z, const char *name) { + malloc_set_zone_name(z, name); +} + +void *NXZoneMalloc(malloc_zone_t *zone, size_t size) { + return malloc_zone_malloc(zone, size); +} + +void *NXZoneRealloc(malloc_zone_t *zone, void *ptr, size_t size) { + return malloc_zone_realloc(zone, ptr, size); +} + +void *NXZoneCalloc(malloc_zone_t *zone, size_t num_items, size_t size) { + return malloc_zone_calloc(zone, num_items, size); +} + +void NXZoneFree(malloc_zone_t *zone, void *ptr) { + malloc_zone_free(zone, ptr); +} + +void NXDestroyZone(malloc_zone_t *zone) { + if (zone == malloc_default_zone()) return; // we avoid destroying child zones + malloc_destroy_zone(zone); +} + +NXZone *NXZoneFromPtr(void *ptr) { + NXZone *zone = malloc_zone_from_ptr(ptr); + if (!zone) { + fprintf(stderr, "*** malloc[%d]: NXZoneFromPtr() did not find any zone for %p; returning default\n", getpid(), ptr); + zone = NX_NOZONE; + } + return zone; +} + +void NXAddRegion(void *start, size_t size, malloc_zone_t *zone) { + fprintf(stderr, "*** malloc[%d]: OBSOLETE: NXAddRegion()\n", getpid()); +} + +void NXRemoveRegion(void *start) { + fprintf(stderr, "*** malloc[%d]: OBSOLETE: NXRemoveRegion()\n", getpid()); +} + +void NXZonePtrInfo(void *ptr) { + malloc_zone_print_ptr_info(ptr); +} + +int NXMallocCheck(void) { + malloc_zone_check(NULL); + return 1; +} + +void _NXMallocDumpZones(void) { + malloc_zone_print(NULL, 0); +} + +/***************** UNIMPLEMENTED ENTRY POINTS ********************/ + +void NXMergeZone(malloc_zone_t *z) { + static char warned = 0; + if (!warned) { + fprintf(stderr, "*** malloc[%d]: NXMergeZone() now obsolete, does nothing\n", getpid()); + warned = 1; + } +} + +boolean_t NXProtectZone(malloc_zone_t *zone, int protection) { + fprintf(stderr, "*** malloc[%d]: NXProtectZone() is obsolete\n", getpid()); + return 0; +} + +malloc_zone_t *NXCreateChildZone(malloc_zone_t *parentzone, size_t startsize, size_t granularity, int canfree) { + // We can not remove this one as it is still used by IndexingKit + static char warned = 0; + if (!warned) { + fprintf(stderr, "*** malloc[%d]: NXCreateChildZone() now obsolete, has been defined to create new zone\n", getpid()); + warned = 1; + } + return NXCreateZone(startsize, granularity, canfree); +} + +void _NXMallocDumpFrees(void) { + fprintf(stderr, "*** malloc[%d]: OBSOLETE: _NXMallocDumpFrees()\n", getpid()); +} + diff --git a/gmon/Makefile.inc b/gmon/Makefile.inc new file mode 100644 index 0000000..1e69c1d --- /dev/null +++ b/gmon/Makefile.inc @@ -0,0 +1,22 @@ +# from @(#)Makefile.inc 8.1 (Berkeley) 6/4/93 +# $FreeBSD: src/lib/libc/gmon/Makefile.inc,v 1.8 2001/03/27 17:26:47 ru Exp $ + +# gmon sources +.PATH: ${.CURDIR}/gmon + +SRCS+= gmon.c + +#.if ${LIB} == "c" +#MAN+= moncontrol.3 +# +#MLINKS+=moncontrol.3 monstartup.3 +#.endif + +# 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 -c ${.CURDIR}/gmon/gmon.c -o gmon.po + +#gmon.po: gmon.o +# cp gmon.o gmon.po diff --git a/gmon/gmon.c b/gmon/gmon.c new file mode 100644 index 0000000..8872c02 --- /dev/null +++ b/gmon/gmon.c @@ -0,0 +1,758 @@ +/* + * Copyright (c) 1999 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@ + */ +#if defined(PROFILE) +#error This module cannot be compiled with profiling +#endif + +/*- + * Copyright (c) 1983, 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. + */ +/* + * History + * 2-Mar-90 Gregg Kellogg (gk) at NeXT + * Changed include of kern/mach.h to kern/mach_interface.h + * + * 1-May-90 Matthew Self (mself) at NeXT + * Added prototypes, and added casts to remove all warnings. + * Made all private data static. + * vm_deallocate old data defore vm_allocate'ing new data. + * Added new functions monoutput and monreset. + * + * 18-Dec-92 Development Environment Group at NeXT + * Added multiple profile areas, the ability to profile shlibs and the + * ability to profile rld loaded code. Moved the machine dependent mcount + * routine out of this source file. + * + * 13-Dec-92 Development Environment Group at NeXT + * Added support for dynamic shared libraries. Also removed the code that + * had been ifdef'ed out for profiling fixed shared libraries and + * objective-C. + */ + +#if defined(LIBC_SCCS) && !defined(lint) +static char sccsid[] = "@(#)gmon.c 5.2 (Berkeley) 6/21/85"; +#endif + +/* + * see profil(2) where this (SCALE_1_TO_1) is describe (incorrectly). + * + * The correct description: scale is a fixed point value with + * the binary point in the middle of the 32 bit value. (Bit 16 is + * 1, bit 15 is .5, etc.) + * + * Setting the scale to "1" (i.e. 0x10000), results in the kernel + * choosing the profile bucket address 1 to 1 with the pc sampled. + * Since buckets are shorts, if the profiling base were 0, then a pc + * of 0 increments bucket 0, a pc of 2 increments bucket 1, and a pc + * of 4 increments bucket 2.) (Actually, this seems a little bogus, + * 1 to 1 should map pc's to buckets -- that's probably what was + * intended from the man page, but historically.... + */ +#define SCALE_1_TO_1 0x10000L + +#define MSG "No space for monitor buffer(s)\n" + +#include +#include +extern const struct section *getsectbyname( + const char *segname, + const char *sectname); +#include +#include +#include +#include +#include +#include +#include +#include + +/* + * These are defined in here and these declarations need to be moved to libc.h + * where the other declarations for the monitor(3) routines are declared. + */ +extern void moninit( + void); +extern void monaddition( + char *lowpc, + char *highpc); +extern void moncount( + char *frompc, + char *selfpc); +extern void monreset( + 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 */ + +static unsigned long order = 0; /* call order */ + +struct mon_t { + /* the address range and size this mon struct refers to */ + char *lowpc; + char *highpc; + unsigned long textsize; + /* the data structures to support the arc's and their counts */ + unsigned short *froms; /* froms is unsigned shorts indexing into tos */ + struct tostruct *tos; + long tolimit; + /* the pc-sample buffer, it's size and scale */ + char *sbuf; + int ssiz; /* includes the gmonhdr struct */ + int scale; +}; +static struct mon_t *mon = NULL; +static unsigned long nmon = 0; + +static void monsetup( + struct mon_t *m, + char *lowpc, + char *highpc); +static int getprofhz( + void); + +void +moninit( +void) +{ + const struct section *section; + char *lowpc, *highpc; + unsigned long i; + + monreset(); + init = 1; + + section = getsectbyname ("__TEXT", "__text"); + lowpc = (char *)section->addr, + highpc = (char *)(section->addr + section->size); + + if(mon == NULL){ + if((mon = malloc(sizeof(struct mon_t))) == NULL){ + write(2, MSG, sizeof(MSG) - 1); + return; + } + nmon = 1; + memset(mon, '\0', sizeof(struct mon_t)); + } + /* + * To continue to make monstartup() and the functions that existed + * before adding multiple profiling areas working correctly the new + * calls to get the dyld loaded code profiled are made after + * the first mon_t struct is allocated so that they will not use the + * first mon_t and the old calls will always use the first mon_t struct + * in the list. + */ + monsetup(mon, lowpc, highpc); + + profil(mon->sbuf + sizeof(struct gmonhdr), + mon->ssiz - sizeof(struct gmonhdr), + (int)mon->lowpc, mon->scale); + for(i = 1; i < nmon; i++) + add_profil(mon[i].sbuf + sizeof(struct gmonhdr), + mon[i].ssiz - sizeof(struct gmonhdr), + (int)mon[i].lowpc, mon[i].scale); + init = 0; + profiling = 0; + +#if defined(__DYNAMIC__) + /* + * Call _dyld_moninit() if the dyld is present. This is done after the + * above calls so the dynamic libraries will be added after the + * executable. + */ + if(_dyld_present()) + _dyld_moninit(monaddition); +#endif +} + +void +monstartup( +char *lowpc, +char *highpc) +{ + monreset(); + if(mon == NULL){ + if((mon = malloc(sizeof(struct mon_t))) == NULL){ + write(2, MSG, sizeof(MSG) - 1); + return; + } + nmon = 1; + memset(mon, '\0', sizeof(struct mon_t)); + } + monsetup(mon, lowpc, highpc); +} + +/* + * monaddtion() is used for adding additional pc ranges to profile. This is + * used for profiling dyld loaded code. + */ +void +monaddition( +char *lowpc, +char *highpc) +{ + char save_profiling; + struct mon_t *m; + + if(mon == NULL){ + monstartup(lowpc, highpc); + return; + } + save_profiling = profiling; + profiling = -1; + if((mon = realloc(mon, (nmon + 1) * sizeof(struct mon_t))) == NULL){ + write(2, MSG, sizeof(MSG) - 1); + return; + } + m = mon + nmon; + memset(m, '\0', sizeof(struct mon_t)); + nmon++; + monsetup(m, lowpc, highpc); + profiling = save_profiling; +} + +static +void +monsetup( +struct mon_t *m, +char *lowpc, +char *highpc) +{ + int monsize; + char *buffer; + kern_return_t ret; + struct gmonhdr *p; + unsigned int o; + + /* + * round lowpc and highpc to multiples of the density we're using + * so the rest of the scaling (here and in gprof) stays in ints. + */ + lowpc = (char *)ROUNDDOWN((unsigned)lowpc, + HISTFRACTION * sizeof(HISTCOUNTER)); + m->lowpc = lowpc; + highpc = (char *)ROUNDUP((unsigned)highpc, + HISTFRACTION * sizeof(HISTCOUNTER)); + m->highpc = highpc; + + if(m->froms) + vm_deallocate(mach_task_self(), + (vm_address_t)m->froms, + (vm_size_t)(m->textsize / HASHFRACTION)); + m->textsize = highpc - lowpc; + ret = vm_allocate(mach_task_self(), + (vm_address_t *)&m->froms, + (vm_size_t)(m->textsize / HASHFRACTION), + TRUE); + if(ret != KERN_SUCCESS){ + write(2, MSG, sizeof(MSG) - 1); + m->froms = 0; + return; + } + + if(m->sbuf) + vm_deallocate(mach_task_self(), + (vm_address_t)m->sbuf, + (vm_size_t)m->ssiz); + monsize = (m->textsize / HISTFRACTION) + sizeof(struct gmonhdr); + ret = vm_allocate(mach_task_self(), + (vm_address_t *)&buffer, + (vm_size_t)monsize, + TRUE); + if(ret != KERN_SUCCESS){ + write(2, MSG, sizeof(MSG) - 1); + m->sbuf = 0; + return; + } + + if(m->tos) + vm_deallocate(mach_task_self(), + (vm_address_t)m->tos, + (vm_size_t)(m->tolimit * sizeof(struct tostruct))); + m->tolimit = m->textsize * ARCDENSITY / 100; + if(m->tolimit < MINARCS){ + m->tolimit = MINARCS; + } + else if(m->tolimit > 65534){ + m->tolimit = 65534; + } + ret = vm_allocate(mach_task_self(), + (vm_address_t *)&m->tos, + (vm_size_t)(m->tolimit * sizeof(struct tostruct)), + TRUE); + if(ret != KERN_SUCCESS){ + write(2, MSG, sizeof(MSG) - 1); + m->tos = 0; + return; + } + m->tos[0].link = 0; /* a nop since tos was vm_allocated and is zero */ + + /* + * If this is call to monsetup() was via monstartup() (m == mon) then + * it is using or reusing the first pc range and then the pc sample + * buffer can be setup by the system call profil() via monitor() via + * a moncontrol(1) call. + * + * Otherwise this is call to monsetup() was via monaddition() and a + * new system call is needed to add an additional pc sample buffer in + * the kernel. + */ + if(m == mon && !init){ + monitor(lowpc, highpc, buffer, monsize, m->tolimit); + } + else{ + /* monitor() functionality */ + m->sbuf = buffer; + m->ssiz = monsize; + p = (struct gmonhdr *)m->sbuf; + memset(p, '\0', sizeof(struct gmonhdr)); + p->lpc = (unsigned long)m->lowpc; + p->hpc = (unsigned long)m->highpc; + p->ncnt = m->ssiz; + p->version = GMONVERSION; + p->profrate = getprofhz(); + o = highpc - lowpc; + if((monsize - sizeof(struct gmonhdr)) < o) + m->scale = ((float) (monsize - sizeof(struct gmonhdr))/ o) * + SCALE_1_TO_1; + else + m->scale = SCALE_1_TO_1; + + /* moncontrol(mode == 1) functionality */ + if(!init) + add_profil(m->sbuf + sizeof(struct gmonhdr), + m->ssiz - sizeof(struct gmonhdr), + (int)m->lowpc, m->scale); + } +} + +void +monreset( +void) +{ + unsigned long i; + struct mon_t *m; + struct gmonhdr *p; + + moncontrol(0); + if(mon == NULL) + return; + for(i = 0; i < nmon; i++){ + m = mon + i; + if(m->sbuf != NULL){ + memset(m->sbuf, '\0', m->ssiz); + p = (struct gmonhdr *)m->sbuf; + p->lpc = (unsigned long)m->lowpc; + p->hpc = (unsigned long)m->highpc; + p->ncnt = m->ssiz; + } + if(m->froms != NULL) + memset(m->froms, '\0', m->textsize / HASHFRACTION); + if(m->tos != NULL) + memset(m->tos, '\0', m->tolimit * sizeof (struct tostruct)); + } + order = 0; + moncontrol(1); +} + +void +monoutput( +const char *filename) +{ + int fd; + unsigned long magic, i, fromindex, endfrom, toindex; + struct gmon_data sample_data, arc_data, dyld_data; + char *frompc; + struct rawarc_order rawarc_order; + struct mon_t *m; + unsigned long image_count, vmaddr_slide; + char *image_name; + + moncontrol(0); + m = mon; + if(m == NULL) + return; + fd = creat(filename, 0666); + if(fd < 0){ + perror("mcount: gmon.out"); + return; + } + + magic = GMON_MAGIC; + write(fd, &magic, sizeof(unsigned long)); + +#if defined(__DYNAMIC__) + if(_dyld_present()){ + image_count = _dyld_image_count(); + if(image_count > 1){ +#ifdef DYLD_DEBUG + printf("image_count = %lu\n", image_count - 1); + for(i = 1; i < image_count; i++){ + vmaddr_slide = _dyld_get_image_vmaddr_slide(i); + printf("\tvmaddr_slide 0x%x\n", (unsigned int)vmaddr_slide); + image_name = _dyld_get_image_name(i); + printf("\timage_name %s\n", image_name); + } +#endif + /* + * Calculate the dyld_data.size. + */ + dyld_data.type = GMONTYPE_DYLD_STATE; + dyld_data.size = sizeof(unsigned long) + + sizeof(unsigned long) * (image_count - 1); + for(i = 1; i < image_count; i++){ + image_name = _dyld_get_image_name(i); + dyld_data.size += strlen(image_name) + 1; + } + + /* + * Write the dyld_data. + */ + write(fd, &dyld_data, sizeof(struct gmon_data)); + image_count--; + write(fd, &image_count, sizeof(unsigned long)); + image_count++; + for(i = 1; i < image_count; i++){ + vmaddr_slide = _dyld_get_image_vmaddr_slide(i); + write(fd, &vmaddr_slide, sizeof(unsigned long)); + image_name = _dyld_get_image_name(i); + write(fd, image_name, strlen(image_name) + 1); + } + } + } +#endif + for(i = 0; i < nmon; i++){ + m = mon + i; +#ifdef DEBUG + fprintf(stderr, "[monoutput] sbuf 0x%x ssiz %d\n", + m->sbuf, m->ssiz); +#endif + sample_data.type = GMONTYPE_SAMPLES; + sample_data.size = m->ssiz; + write(fd, &sample_data, sizeof(struct gmon_data)); + /* + * Write the gmonhdr struct and the pc-sample buffer. Note the + * gmonhdr struct is in sbuf at the beginning of sbuf already + * filled in. + */ + write(fd, m->sbuf, m->ssiz); + + /* + * Now write out the raw arcs. + */ + endfrom = m->textsize / (HASHFRACTION * sizeof(*m->froms)); + arc_data.type = GMONTYPE_ARCS_ORDERS; + arc_data.size = 0; + for(fromindex = 0; fromindex < endfrom; fromindex++){ + if(m->froms[fromindex] == 0){ + continue; + } + frompc = m->lowpc + + (fromindex * HASHFRACTION * sizeof(*m->froms)); + for(toindex = m->froms[fromindex]; + toindex != 0; + toindex = m->tos[toindex].link){ + arc_data.size += sizeof(struct rawarc_order); + } + } + write(fd, &arc_data, sizeof(struct gmon_data)); + + for(fromindex = 0; fromindex < endfrom; fromindex++){ + if(m->froms[fromindex] == 0){ + continue; + } + frompc = m->lowpc + + (fromindex * HASHFRACTION * sizeof(*m->froms)); + for(toindex = m->froms[fromindex]; + toindex != 0; + toindex = m->tos[toindex].link){ +#ifdef DEBUG + fprintf(stderr, "[monoutput] frompc 0x%x selfpc 0x%x " + "count %ld order %lu\n", (unsigned int)frompc, + (unsigned int)m->tos[toindex].selfpc, + m->tos[toindex].count, m->tos[toindex].order); +#endif + rawarc_order.raw_frompc = (unsigned long)frompc; + rawarc_order.raw_selfpc = (unsigned long) + m->tos[toindex].selfpc; + rawarc_order.raw_count = m->tos[toindex].count; + rawarc_order.raw_order = m->tos[toindex].order; + write(fd, &rawarc_order, sizeof(struct rawarc_order)); + } + } + } + close(fd); +} + +void +monitor( +char *lowpc, +char *highpc, +char *buf, +int bufsiz, +int nfunc) /* nfunc is not used; available for compatability only. */ +{ + unsigned int o; + struct gmonhdr *p; + struct mon_t *m; + + moncontrol(0); + m = mon; + if(m == NULL) + return; + if(lowpc == 0){ + moncontrol(0); + monoutput("gmon.out"); + return; + } + m->sbuf = buf; + m->ssiz = bufsiz; + p = (struct gmonhdr *)buf; + memset(p, '\0', sizeof(struct gmonhdr)); + p->lpc = (unsigned long)lowpc; + p->hpc = (unsigned long)highpc; + p->ncnt = m->ssiz; + p->version = GMONVERSION; + p->profrate = getprofhz(); + bufsiz -= sizeof(struct gmonhdr); + if(bufsiz <= 0) + return; + o = highpc - lowpc; + if(bufsiz < o) + m->scale = ((float) bufsiz / o) * SCALE_1_TO_1; + else + m->scale = SCALE_1_TO_1; + moncontrol(1); +} + +/* + * Control profiling + * profiling is what mcount checks to see if + * all the data structures are ready. + */ +void +moncontrol( +int mode) +{ + struct mon_t *m; + unsigned long i; + + if(mode){ + /* start */ + m = mon; + if(m != NULL){ + profil(m->sbuf + sizeof(struct gmonhdr), + m->ssiz - sizeof(struct gmonhdr), + (int)m->lowpc, m->scale); + for(i = 1; i < nmon; i++) + add_profil(mon[i].sbuf + sizeof(struct gmonhdr), + mon[i].ssiz - sizeof(struct gmonhdr), + (int)mon[i].lowpc, mon[i].scale); + profiling = 0; + } + } + else{ + /* stop */ + profil((char *)0, 0, 0, 0); + profiling = -1; + } +} + +void +moncount( +char *frompc, +char *selfpc) +{ + unsigned short *frompcindex; + struct tostruct *top, *prevtop; + unsigned long i, toindex; + struct mon_t *m; + + m = mon; + if(m == NULL) + return; + /* + * Check that we are profiling and that we aren't recursively invoked. + * This should really be a test and set instruction in changing the + * value of profiling. + */ + if(profiling) + return; + profiling++; + + +#ifdef DEBUG + fprintf(stderr, "[moncount] frompc 0x%x selfpc 0x%x\n", + (unsigned int)frompc, (unsigned int)selfpc); +#endif + frompcindex = (unsigned short *)frompc; + + /* + * check that frompcindex is a reasonable pc value. + * for example: signal catchers get called from the stack, + * not from text space. too bad. + */ + for(i = 0; i < nmon; i++){ + m = mon + i; + if((unsigned long)frompcindex >= (unsigned long)m->lowpc && + (unsigned long)frompcindex < (unsigned long)m->highpc) + break; + } + if(i == nmon){ + goto done; + } + else{ + frompcindex = (unsigned short *) + ((unsigned long)frompcindex - (unsigned long)m->lowpc); + } + frompcindex = + &m->froms[((long)frompcindex) / (HASHFRACTION * sizeof(*m->froms))]; + toindex = *frompcindex; + if(toindex == 0){ + /* + * first time traversing this arc + */ + toindex = ++m->tos[0].link; + if(toindex >= m->tolimit){ + goto overflow; + } + *frompcindex = toindex; + top = &m->tos[toindex]; + top->selfpc = (unsigned long)selfpc; + top->count = 1; + top->link = 0; + top->order = ++order; + goto done; + } + top = &m->tos[toindex]; + if(top->selfpc == (unsigned long)selfpc){ + /* + * arc at front of chain; usual case. + */ + top->count++; + goto done; + } + /* + * have to go looking down chain for it. + * top points to what we are looking at, + * prevtop points to previous top. + * we know it is not at the head of the chain. + */ + for(; /* goto done */; ){ + if(top->link == 0){ + /* + * top is end of the chain and none of the chain + * had top->selfpc == selfpc. + * so we allocate a new tostruct + * and link it to the head of the chain. + */ + toindex = ++m->tos[0].link; + if(toindex >= m->tolimit){ + goto overflow; + } + top = &m->tos[toindex]; + top->selfpc = (unsigned long)selfpc; + top->count = 1; + top->link = *frompcindex; + top->order = ++order; + *frompcindex = toindex; + goto done; + } + /* + * otherwise, check the next arc on the chain. + */ + prevtop = top; + top = &m->tos[top->link]; + if(top->selfpc == (unsigned long)selfpc){ + /* + * there it is. + * increment its count + * move it to the head of the chain. + */ + top->count++; + toindex = prevtop->link; + prevtop->link = top->link; + top->link = *frompcindex; + *frompcindex = toindex; + goto done; + } + } +done: + profiling--; + return; + +overflow: + profiling++; /* halt further profiling */ +#define TOLIMIT "mcount: tos overflow\n" + write(2, TOLIMIT, sizeof(TOLIMIT) - 1); +} + +/* + * Get the profiling rate. + */ +static +int +getprofhz(void) +{ + int mib[2]; + size_t size; + struct clockinfo clockrate; + + mib[0] = CTL_KERN; + mib[1] = KERN_CLOCKRATE; + clockrate.profhz = 1; + size = sizeof(clockrate); + if(sysctl(mib, 2, &clockrate, &size, NULL, 0) < 0) + ; + return(clockrate.profhz); +} diff --git a/headers.subproj/Makefile b/headers.subproj/Makefile deleted file mode 100644 index 4c2346e..0000000 --- a/headers.subproj/Makefile +++ /dev/null @@ -1,53 +0,0 @@ -# -# Generated by the Apple Project Builder. -# -# NOTE: Do NOT change this file -- Project Builder maintains it. -# -# Put all of your customizations in files called Makefile.preamble -# and Makefile.postamble (both optional), and Makefile will include them. -# - -NAME = headers - -PROJECTVERSION = 2.8 -PROJECT_TYPE = Component - -HFILES = asm.h crt_externs.h libc.h monitor.h NSSystemDirectories.h\ - standards.h - -OTHERSRCS = Makefile.preamble Makefile Makefile.postamble - -MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles -CODE_GEN_STYLE = DYNAMIC -MAKEFILE = subproj.make -NEXTSTEP_INSTALLDIR = /Local/Developer/System -LIBS = -DEBUG_LIBS = $(LIBS) -PROF_LIBS = $(LIBS) - - -PUBLIC_HEADERS = crt_externs.h libc.h monitor.h NSSystemDirectories.h\ - standards.h - - - -NEXTSTEP_BUILD_OUTPUT_DIR = /Local/Public/SandBox/$(USER)/BUILD/$(NAME) - -NEXTSTEP_PUBLIC_HEADERS_DIR = /usr/include - -NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc -WINDOWS_OBJCPLUS_COMPILER = $(DEVDIR)/gcc -PDO_UNIX_OBJCPLUS_COMPILER = $(NEXTDEV_BIN)/gcc -NEXTSTEP_JAVA_COMPILER = /usr/bin/javac -WINDOWS_JAVA_COMPILER = $(JDKBINDIR)/javac.exe -PDO_UNIX_JAVA_COMPILER = $(JDKBINDIR)/javac - -include $(MAKEFILEDIR)/platform.make - --include Makefile.preamble - -include $(MAKEFILEDIR)/$(MAKEFILE) - --include Makefile.postamble - --include Makefile.dependencies diff --git a/headers.subproj/Makefile.postamble b/headers.subproj/Makefile.postamble deleted file mode 100644 index df76c31..0000000 --- a/headers.subproj/Makefile.postamble +++ /dev/null @@ -1,5 +0,0 @@ -$(DSTROOT)$(PRIVATE_HDR_INSTALLDIR)$(MY_PRIVATE_HEADER_DIR_SUFFIX): - $(MKDIRS) $@ - -my_installhdrs: $(DSTROOT)$(PRIVATE_HDR_INSTALLDIR)$(MY_PRIVATE_HEADER_DIR_SUFFIX) - $(SILENT) $(FASTCP) $(MY_PRIVATE_HEADERS) $(DSTROOT)$(PRIVATE_HDR_INSTALLDIR)$(MY_PRIVATE_HEADER_DIR_SUFFIX) diff --git a/headers.subproj/Makefile.preamble b/headers.subproj/Makefile.preamble deleted file mode 100644 index 1a55329..0000000 --- a/headers.subproj/Makefile.preamble +++ /dev/null @@ -1,4 +0,0 @@ -MY_PRIVATE_HEADERS = asm.h -PUBLIC_HEADER_DIR_SUFFIX = -MY_PRIVATE_HEADER_DIR_SUFFIX = /machine -AFTER_INSTALLHDRS += my_installhdrs diff --git a/headers.subproj/NSSystemDirectories.h b/headers.subproj/NSSystemDirectories.h deleted file mode 100644 index 75782d6..0000000 --- a/headers.subproj/NSSystemDirectories.h +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright (c) 1999-2000 Apple Computer, Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * Portions Copyright (c) 1999-2000 Apple Computer, Inc. All Rights - * Reserved. This 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.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. - * - * 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@ - */ - -/* - This API returns the various standard system directories where apps, resources, etc get installed. - Because queries can return multiple directories, the API is in the form of an enumeration. - The directories are returned in search path order; that is, the first place to look is returned first. - This API may return directories that do not exist yet. - If NSUserDomain is included in a query, then the results will contain "~" to refer to the user's directory. - NEXT_ROOT is prepended as necessary to the returned values. - Some calls might return no directories! - The buffer that is passed in will be filled with a null-terminated string, possibly containing as many as PATH_MAX-1 characters. - - Typical usage: - - #include - #include - - char path[PATH_MAX]; - NSSearchPathEnumerationState state = NSStartSearchPathEnumeration(dir, domainMask); - while (state = NSGetNextSearchPathEnumeration(state, path)) { - // Handle path - } - - -*/ - -#ifndef __NS_SYSTEM_DIRECTORIES_H__ -#define __NS_SYSTEM_DIRECTORIES_H__ - -// 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) - 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) -} NSSearchPathDirectory; - -// Domains - -typedef enum { - NSUserDomainMask = 1, // user's home directory --- place to install user's personal items (~) - NSLocalDomainMask = 2, // local to the current machine --- place to install items available to everyone on this machine - NSNetworkDomainMask = 4, // publically available location in the local area network --- place to install items available on the network (/Network) - NSSystemDomainMask = 8, // provided by Apple - NSAllDomainsMask = 0x0ffff // all domains: all of the above and more, future items -} NSSearchPathDomainMask; - -typedef unsigned int NSSearchPathEnumerationState; - -/* Enumeration - Call NSStartSearchPathEnumeration() once, then call NSGetNextSearchPathEnumeration() one or more times with the returned state. - The return value of NSGetNextSearchPathEnumeration() should be used as the state next time around. - When NSGetNextSearchPathEnumeration() returns 0, you're done. -*/ -extern NSSearchPathEnumerationState NSStartSearchPathEnumeration(NSSearchPathDirectory dir, NSSearchPathDomainMask domainMask); - -extern NSSearchPathEnumerationState NSGetNextSearchPathEnumeration(NSSearchPathEnumerationState state, char *path); - -#endif /* __NS_SYSTEM_DIRECTORIES_H__ */ diff --git a/headers.subproj/PB.project b/headers.subproj/PB.project deleted file mode 100644 index c329ba0..0000000 --- a/headers.subproj/PB.project +++ /dev/null @@ -1,41 +0,0 @@ -{ - DYNAMIC_CODE_GEN = YES; - FILESTABLE = { - H_FILES = ( - asm.h, - crt_externs.h, - libc.h, - monitor.h, - NSSystemDirectories.h, - standards.h - ); - OTHER_SOURCES = (Makefile.preamble, Makefile, Makefile.postamble); - PRECOMPILED_HEADERS = (); - PROJECT_HEADERS = (); - PUBLIC_HEADERS = ( - crt_externs.h, - libc.h, - monitor.h, - NSSystemDirectories.h, - standards.h - ); - SUBPROJECTS = (); - }; - LANGUAGE = English; - MAKEFILEDIR = "$(MAKEFILEPATH)/pb_makefiles"; - NEXTSTEP_BUILDDIR = "/Local/Public/SandBox/$(USER)/BUILD/$(NAME)"; - NEXTSTEP_BUILDTOOL = /bin/gnumake; - NEXTSTEP_INSTALLDIR = /Local/Developer/System; - NEXTSTEP_JAVA_COMPILER = /usr/bin/javac; - NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc; - NEXTSTEP_PUBLICHEADERSDIR = /usr/include; - PDO_UNIX_BUILDTOOL = $NEXT_ROOT/Developer/bin/make; - PDO_UNIX_JAVA_COMPILER = "$(JDKBINDIR)/javac"; - PDO_UNIX_OBJCPLUS_COMPILER = "$(NEXTDEV_BIN)/gcc"; - PROJECTNAME = headers; - PROJECTTYPE = Component; - PROJECTVERSION = 2.8; - WINDOWS_BUILDTOOL = $NEXT_ROOT/Developer/Executables/make; - WINDOWS_JAVA_COMPILER = "$(JDKBINDIR)/javac.exe"; - WINDOWS_OBJCPLUS_COMPILER = "$(DEVDIR)/gcc"; -} diff --git a/headers.subproj/asm.h b/headers.subproj/asm.h deleted file mode 100644 index d21a6b5..0000000 --- a/headers.subproj/asm.h +++ /dev/null @@ -1,415 +0,0 @@ -/* - * @OSF_COPYRIGHT@ - */ - -#ifndef _PPC_ASM_H_ -#define _PPC_ASM_H_ - -#ifdef __ELF__ -#define __NO_UNDERSCORES__ 1 -#define __ASMNL__ ; -#else -#define __ASMNL__ @ -#endif - -#ifdef ASSEMBLER - -#ifdef __ELF__ -#define r0 0 -#define r1 1 -#define r2 2 -#define r3 3 -#define r4 4 -#define r5 5 -#define r6 6 -#define r7 7 -#define r8 8 -#define r9 9 -#define r10 10 -#define r11 11 -#define r12 12 -#define r13 13 -#define r14 14 -#define r15 15 -#define r16 16 -#define r17 17 -#define r18 18 -#define r19 19 -#define r20 20 -#define r21 21 -#define r22 22 -#define r23 23 -#define r24 24 -#define r25 25 -#define r26 26 -#define r27 27 -#define r28 28 -#define r29 29 -#define r30 30 -#define r31 31 - -#define f0 0 -#define f1 1 -#define f2 2 -#define f3 3 -#define f4 4 -#define f5 5 -#define f6 6 -#define f7 7 -#define f8 8 -#define f9 9 -#define f10 10 -#define f11 11 -#define f12 12 -#define f13 13 -#define f14 14 -#define f15 15 -#define f16 16 -#define f17 17 -#define f18 18 -#define f19 19 -#define f20 20 -#define f21 21 -#define f22 22 -#define f23 23 -#define f24 24 -#define f25 25 -#define f26 26 -#define f27 27 -#define f28 28 -#define f29 29 -#define f30 30 -#define f31 31 - -#define sr0 0 -#define sr1 1 -#define sr2 2 -#define sr3 3 -#define sr4 4 -#define sr5 5 -#define sr6 6 -#define sr7 7 -#define sr8 8 -#define sr9 9 -#define sr10 10 -#define sr11 11 -#define sr12 12 -#define sr13 13 -#define sr14 14 -#define sr15 15 -#define sr16 16 -#define sr17 17 -#define sr18 18 -#define sr19 19 -#define sr20 20 -#define sr21 21 -#define sr22 22 -#define sr23 23 -#define sr24 24 -#define sr25 25 -#define sr26 26 -#define sr27 27 -#define sr28 28 -#define sr29 29 -#define sr30 30 -#define sr31 31 -#endif - -#define ARG0 r3 -#define ARG1 r4 -#define ARG2 r5 -#define ARG3 r6 -#define ARG4 r7 -#define ARG5 r8 -#define ARG6 r9 -#define ARG7 r10 - -#define tmp0 r0 /* Temporary GPR remapping (603e specific) */ -#define tmp1 r1 -#define tmp2 r2 -#define tmp3 r3 - -/* SPR registers */ - -#define dmiss 976 /* ea that missed */ -#define dcmp 977 /* compare value for the va that missed */ -#define hash1 978 /* pointer to first hash pteg */ -#define hash2 979 /* pointer to second hash pteg */ -#define imiss 980 /* ea that missed */ -#define icmp 981 /* compare value for the va that missed */ -#define rpa 982 /* required physical address register */ - -#define iabr 1010 /* instruction address breakpoint register */ -#define pir 1023 /* Processor ID Register */ - -/* MQ register on the 601 */ -#define mq 0 /* spr number for mq register on 601 */ - -#define IBAT0U 528 -#define IBAT0L 529 -#define IBAT1U 530 -#define IBAT1L 531 -#define IBAT2U 532 -#define IBAT2L 533 -#define IBAT3U 534 -#define IBAT3L 535 -#define ibat0u 528 -#define ibat0l 529 -#define ibat1u 530 -#define ibat1l 531 -#define ibat2u 532 -#define ibat2l 533 -#define ibat3u 534 -#define ibat3l 535 - -#define DBAT0U 536 -#define DBAT0L 537 -#define DBAT1U 538 -#define DBAT1L 539 -#define DBAT2U 540 -#define DBAT2L 541 -#define DBAT3U 542 -#define DBAT3L 543 -#define dbat0u 536 -#define dbat0l 537 -#define dbat1u 538 -#define dbat1l 539 -#define dbat2u 540 -#define dbat2l 541 -#define dbat3u 542 -#define dbat3l 543 - -#define HID0 1008 -#define hid0 1008 -#define HID1 1009 -#define hid1 1009 -#define SDR1 25 -#define sprg0 272 -#define sprg1 273 -#define sprg2 274 -#define sprg3 275 -#define ppcDAR 19 -#define ppcdar 19 -#define srr0 26 -#define srr1 27 - -#define CR0 0 -#define CR1 1 -#define CR2 2 -#define CR3 3 -#define CR4 4 -#define CR5 5 -#define CR6 6 -#define CR7 7 - -#ifdef __ELF__ -#define cr0 0 -#define cr1 1 -#define cr2 2 -#define cr3 3 -#define cr4 4 -#define cr5 5 -#define cr6 6 -#define cr7 7 -#endif - -#define cr0_lt 0 -#define cr0_gt 1 -#define cr0_eq 2 -#define cr0_so 3 -#define cr0_un 3 - -/* - * Macros to access high and low word values of an address - */ - -#ifndef __ELF__ -#define HIGH_CADDR(x) ha16(x) -#define HIGH_ADDR(x) hi16(x) -#define LOW_ADDR(x) lo16(x) -#else -#define HIGH_CADDR(x) x@ha -#define HIGH_ADDR(x) x@h -#define LOW_ADDR(x) x@l -#endif /* __ELF__ */ - -#endif /* ASSEMBLER */ - -/* Tags are placed before Immediately Following Code (IFC) for the debugger - * to be able to deduce where to find various registers when backtracing - * - * We only define the values as we use them, see SVR4 ABI PowerPc Supplement - * for more details (defined in ELF spec). - */ - -#define TAG_NO_FRAME_USED 0x00000000 - -/* (should use genassym to get these offsets) */ - -#define FM_BACKPTR 0 -/* TODO NMGS FM_SIZE 8 is ok according to EABI specs, but gcc uses 16 */ -#ifdef __ELF__ -#define FM_LR_SAVE 4 /* gcc 2.7.1 is now following eabi spec correctly */ -#define FM_SIZE 16 /* minimum frame contents, backptr and LR save */ -#define FM_ARG0 8 -#else -#define FM_CR_SAVE 4 -#define FM_LR_SAVE 8 /* Rhapsody iS NOT following the ABI at the moment.. */ -#define FM_SIZE 72 /* minimum frame contents, backptr and LR save */ -#define FM_ARG0 56 -#endif - -#define FM_ELF_ARG0 8 -#define FM_MACHO_ARG0 56 -#define MACHO_SYSCALL_BEGIN 0x2000 -#define PK_SYSCALL_BEGIN 0x7000 - - -/* redzone is the area under the stack pointer which must be preserved - * when taking a trap, interrupt etc. This is no longer needed as gcc - * (2.7.2 and above) now follows ELF spec correctly and never loads/stores - * below the frame pointer - */ -#ifdef __ELF__ -#define FM_REDZONE 0 /* was ((32-14+1)*4) */ -#else -#define FM_REDZONE 224 /* is ((32-14+1)*4) */ -#endif - -#define COPYIN_ARG0_OFFSET FM_ARG0 - -#ifdef MACH_KERNEL_BUILD -#include -#else /* MACH_KERNEL */ -#define MACH_KDB 0 -#endif /* MACH_KERNEL */ - -#define BREAKPOINT_TRAP twge r2,r2 - -/* There is another definition of ALIGN for .c sources */ -#ifndef __LANGUAGE_ASSEMBLY -#define ALIGN 2 -#endif /* __LANGUAGE_ASSEMBLY */ - -#ifndef FALIGN -#define FALIGN 2 /* Align functions on words for now. Cachelines is better */ -#endif - -#define LB(x,n) n -#if __STDC__ -#ifndef __NO_UNDERSCORES__ -#define LCL(x) L ## x -#define EXT(x) _ ## x -#define LEXT(x) _ ## x ## : -#else -#define LCL(x) .L ## x -#define EXT(x) x -#define LEXT(x) x ## : -#endif -#define LBc(x,n) n ## : -#define LBb(x,n) n ## b -#define LBf(x,n) n ## f -#else /* __STDC__ */ -#ifndef __NO_UNDERSCORES__ -#define LCL(x) L/**/x -#define EXT(x) _/**/x -#define LEXT(x) _/**/x/**/: -#else /* __NO_UNDERSCORES__ */ -#define LCL(x) .L/**/x -#define EXT(x) x -#define LEXT(x) x/**/: -#endif /* __NO_UNDERSCORES__ */ -#define LBc(x,n) n/**/: -#define LBb(x,n) n/**/b -#define LBf(x,n) n/**/f -#endif /* __STDC__ */ - -#define String .asciz -#define Value .word -#define Times(a,b) (a*b) -#define Divide(a,b) (a/b) - -#define data16 .byte 0x66 -#define addr16 .byte 0x67 - -#if !GPROF -#define MCOUNT - -#elif defined(__SHARED__) -#define MCOUNT ; .data;\ - .align ALIGN;\ - LBc(x, 8) .long 0;\ - .text;\ - Gpush;\ - Gload;\ - leal Gotoff(LBb(x,8)),%edx;\ - Egaddr(%eax,_mcount_ptr);\ - Gpop;\ - call *(%eax); - -#else /* !GPROF, !__SHARED__ */ -#define MCOUNT ; .data;\ - .align ALIGN;\ - LBc(x, 8) .long 0;\ - .text;\ - movl $LBb(x,8),%edx;\ - call *EXT(_mcount_ptr); - -#endif /* GPROF */ - -#ifdef __ELF__ -#define ELF_FUNC(x) .type x,@function -#define ELF_DATA(x) .type x,@object -#define ELF_SIZE(x,s) .size x,s -#else -#define ELF_FUNC(x) -#define ELF_DATA(x) -#define ELF_SIZE(x,s) -#endif - -#ifdef __ELF__ -#define Entry(x,tag) .globl EXT(x); ELF_FUNC(EXT(x)); .long tag;.align FALIGN; LEXT(x) -#define ENTRY(x,tag) Entry(x,tag) MCOUNT -#define ENTRY2(x,y,tag) .globl EXT(x); .globl EXT(y); \ - ELF_FUNC(EXT(x)); ELF_FUNC(EXT(y)); \ - .align FALIGN; LEXT(x); LEXT(y) \ - MCOUNT -#if __STDC__ -#define ASENTRY(x) .globl x; .align FALIGN; x ## : ELF_FUNC(x) MCOUNT -#else -#define ASENTRY(x) .globl x; .align FALIGN; x: ELF_FUNC(x) MCOUNT -#endif /* __STDC__ */ -#define DATA(x) .globl EXT(x); ELF_DATA(EXT(x)); .align ALIGN; LEXT(x) - -#else /* __ELF__ */ - -#define Entry(x,tag) .text@.align FALIGN@ .globl EXT(x)@ LEXT(x) -#define ENTRY(x,tag) Entry(x,tag)@MCOUNT -#define ENTRY2(x,y,tag) .text@ .align FALIGN@ .globl EXT(x)@ .globl EXT(y)@ \ - LEXT(x)@ LEXT(y) @\ - MCOUNT -#if __STDC__ -#define ASENTRY(x) .globl x @ .align FALIGN; x ## @ MCOUNT -#else -#define ASENTRY(x) .globl x @ .align FALIGN; x @ MCOUNT -#endif /* __STDC__ */ -#define DATA(x) .globl EXT(x) @ .align ALIGN @ LEXT(x) -#endif - - - -#define End(x) ELF_SIZE(x,.-x) -#define END(x) End(EXT(x)) -#define ENDDATA(x) END(x) -#define Enddata(x) End(x) - -/* These defines are here for .c files that wish to reference global symbols - * within __asm__ statements. - */ -#ifndef __NO_UNDERSCORES__ -#define CC_SYM_PREFIX "_" -#else -#define CC_SYM_PREFIX "" -#endif /* __NO_UNDERSCORES__ */ - -#endif /* _PPC_ASM_H_ */ diff --git a/headers.subproj/crt_externs.h b/headers.subproj/crt_externs.h deleted file mode 100644 index 9434878..0000000 --- a/headers.subproj/crt_externs.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ - -/* -** Prototypes for the functions to get environment information in -** the world of dynamic libraries. Lifted from .c file of same name. -** Fri Jun 23 12:56:47 PDT 1995 -** AOF (afreier@next.com) -*/ - -extern char ***_NSGetArgv(void); -extern int *_NSGetArgc(void); -extern char ***_NSGetEnviron(void); -extern struct mach_header *_NSGetMachExecuteHeader(void); diff --git a/headers.subproj/libc.h b/headers.subproj/libc.h deleted file mode 100644 index 9125b3c..0000000 --- a/headers.subproj/libc.h +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ - -#ifndef LIBC_H -#define LIBC_H - -#include -#include -#include - -#ifdef __STRICT_BSD__ -#include -#include -#else -#include -#include -#include -#include -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -struct qelem { - struct qelem *q_forw; - struct qelem *q_back; - char *q_data; -}; - -extern kern_return_t map_fd(int fd, vm_offset_t offset, - vm_offset_t *addr, boolean_t find_space, vm_size_t numbytes); - - -#endif /* _LIBC_H */ diff --git a/headers.subproj/monitor.h b/headers.subproj/monitor.h deleted file mode 100644 index d9c14f3..0000000 --- a/headers.subproj/monitor.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1988 NeXT, Inc. - * - * HISTORY - * 04-May-90 Created - */ - -#ifndef __MONITOR_HEADER__ -#define __MONITOR_HEADER__ - -extern void monstartup (char *lowpc, char *highpc); - -extern void monitor (char *lowpc, char *highpc, char *buf, int bufsiz, int cntsiz); - -extern void moncontrol (int mode); - -extern void monoutput (const char *filename); - -extern void moninit (void); - -extern void monreset (void); - -#endif /* __MONITOR_HEADER__ */ diff --git a/headers.subproj/standards.h b/headers.subproj/standards.h deleted file mode 100644 index 934b381..0000000 --- a/headers.subproj/standards.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ - -#ifndef _STANDARDS_H -#define _STANDARDS_H - -#ifdef _POSIX_SOURCE - #ifndef __STRICT_ANSI__ - #define __STRICT_ANSI__ - #endif - #undef __STRICT_BSD__ -#endif /* _POSIX_SOURCE */ - -#endif /* _STANDARDS_H */ diff --git a/i386/gen/Makefile.inc b/i386/gen/Makefile.inc new file mode 100644 index 0000000..ed150c0 --- /dev/null +++ b/i386/gen/Makefile.inc @@ -0,0 +1,5 @@ +SRCS+= abs.c ecvt.c memcpy.s strcat.c strncat.c \ + bcmp.c ffs.c memmove.s strcmp.c strncmp.c \ + bcopy.s insque.c remque.c strcpy.c strncpy.c \ + bzero.s isinf.c setjmperr.c strlen.c mcount.s \ + bcopy_init.c diff --git a/i386/gen/abs.c b/i386/gen/abs.c new file mode 100644 index 0000000..4d6c1bb --- /dev/null +++ b/i386/gen/abs.c @@ -0,0 +1,71 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 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(__ppc__) + +#if defined(LIBC_SCCS) && !defined(lint) +static char sccsid[] = "@(#)abs.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ + +#include + +int +abs(j) + int j; +{ + return(j < 0 ? -j : j); +} +#else +#warning ----------- Check for implementation of abs() ----------- ! +#endif /* !defined(__ppc__) */ diff --git a/i386/gen/bcmp.c b/i386/gen/bcmp.c new file mode 100644 index 0000000..ae8f18f --- /dev/null +++ b/i386/gen/bcmp.c @@ -0,0 +1,86 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1987, 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(__ppc__) + +#if defined(LIBC_SCCS) && !defined(lint) +static char sccsid[] = "@(#)bcmp.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ + +#include + +/* + * bcmp -- vax cmpc3 instruction + */ +int +bcmp(b1, b2, length) + const void *b1, *b2; + register size_t length; +{ + register char *p1, *p2; + + if (length == 0) + return(0); + p1 = (char *)b1; + p2 = (char *)b2; + do + if (*p1++ != *p2++) + break; + while (--length); + return(length); +} + +#else +#warning ----------- Check for implementation of bcmp() ----------- ! +#endif /* !defined(__ppc__) */ diff --git a/i386/gen/bcopy.s b/i386/gen/bcopy.s new file mode 100644 index 0000000..bcf63b2 --- /dev/null +++ b/i386/gen/bcopy.s @@ -0,0 +1,123 @@ +/* + * Copyright (c) 1999 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@ + */ +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from locore.s. + * + * 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 + + /* + * (ov)bcopy (src,dst,cnt) + * ws@tools.de (Wolfgang Solfrank, TooLs GmbH) +49-228-985800 + */ + +TEXT +#ifdef MEMCOPY +LEAF(_memcpy,0) +#else +#ifdef MEMMOVE +LEAF(_memmove,0) +#else +LEAF(_bcopy,0) +#endif +#endif + pushl %esi + pushl %edi +#if defined(MEMCOPY) || defined(MEMMOVE) + movl 12(%esp),%edi + movl 16(%esp),%esi +#else + movl 12(%esp),%esi + movl 16(%esp),%edi +#endif + movl 20(%esp),%ecx + movl %edi,%eax + subl %esi,%eax + cmpl %ecx,%eax /* overlapping? */ + jb 1f + cld /* nope, copy forwards. */ + shrl $2,%ecx /* copy by words */ + rep + movsl + movl 20(%esp),%ecx + andl $3,%ecx /* any bytes left? */ + rep + movsb +#if defined(MEMCOPY) || defined(MEMMOVE) + movl 12(%esp),%eax +#endif + popl %edi + popl %esi + ret +1: + addl %ecx,%edi /* copy backwards. */ + addl %ecx,%esi + std + andl $3,%ecx /* any fractional bytes? */ + decl %edi + decl %esi + rep + movsb + movl 20(%esp),%ecx /* copy remainder by words */ + shrl $2,%ecx + subl $3,%esi + subl $3,%edi + rep + movsl +#if defined(MEMCOPY) || defined(MEMMOVE) + movl 12(%esp),%eax +#endif + popl %edi + popl %esi + cld +END(bcopy) diff --git a/i386/gen/bcopy_init.c b/i386/gen/bcopy_init.c new file mode 100644 index 0000000..d10eadc --- /dev/null +++ b/i386/gen/bcopy_init.c @@ -0,0 +1,9 @@ +/* Null function. This actually does something on ppc, and this is needed + * for the i386 version to link. + */ +int _cpu_capabilities; + +void _bcopy_initialize() +{ + return; +} diff --git a/i386/gen/bzero.s b/i386/gen/bzero.s new file mode 100644 index 0000000..473e991 --- /dev/null +++ b/i386/gen/bzero.s @@ -0,0 +1,103 @@ +/* + * Copyright (c) 2002 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@ + */ +/* + * Copyright (c) 1993 Winning Strategies, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Winning Strategies, Inc. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software withough specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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 + +/* + * bzero (void *b, size_t len) + * write len zero bytes to the string b. + * + * Written by: + * J.T. Conklin (jtc@wimsey.com), Winning Strategies, Inc. + */ + +TEXT +LEAF(_bzero,0) + pushl %edi + pushl %ebx + movl 12(%esp),%edi + movl 16(%esp),%ecx + + cld /* set fill direction forward */ + xorl %eax,%eax /* set fill data to 0 */ + + /* + * if the string is too short, it's really not worth the overhead + * of aligning to word boundries, etc. So we jump to a plain + * unaligned set. + */ + cmpl $0x0f,%ecx + jle L1 + + movl %edi,%edx /* compute misalignment */ + negl %edx + andl $3,%edx + movl %ecx,%ebx + subl %edx,%ebx + + movl %edx,%ecx /* zero until word aligned */ + rep + stosb + + movl %ebx,%ecx /* zero by words */ + shrl $2,%ecx + rep + stosl + + movl %ebx,%ecx + andl $3,%ecx /* zero remainder by bytes */ +L1: rep + stosb + + popl %ebx + popl %edi +END(_bzero) diff --git a/i386/gen/ecvt.c b/i386/gen/ecvt.c new file mode 100644 index 0000000..70b7c25 --- /dev/null +++ b/i386/gen/ecvt.c @@ -0,0 +1,166 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * 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); +} diff --git a/i386/gen/ffs.c b/i386/gen/ffs.c new file mode 100644 index 0000000..6205d2b --- /dev/null +++ b/i386/gen/ffs.c @@ -0,0 +1,81 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 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(__ppc__) + +#if defined(LIBC_SCCS) && !defined(lint) +static char sccsid[] = "@(#)ffs.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ + +#include + +/* + * ffs -- vax ffs instruction + */ +int +ffs(mask) + register int mask; +{ + register int bit; + + if (mask == 0) + return(0); + for (bit = 1; !(mask & 1); bit++) + mask >>= 1; + return(bit); +} + +#else +#warning ----------- Check for implementation of ffs() ----------- ! +#endif /* !defined(__ppc__) */ diff --git a/i386/gen/insque.c b/i386/gen/insque.c new file mode 100644 index 0000000..17f0b48 --- /dev/null +++ b/i386/gen/insque.c @@ -0,0 +1,55 @@ +/* + * Copyright (c) 1999 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@ + */ +/* Copyright (c) 1992, 1997 NeXT Software, Inc. All rights reserved. + * + * File: libc/gen/ppc/insque.c + * + * struct qelem { + * struct qelem *q_forw; + * struct qelem *q_back; + * char q_data[]; + * }; + * + * void insque(struct qelem *elem, struct qelem *prev); + * + * Inserts queue entry `elem' into a queue after element `prev'. + * + * HISTORY +* 24-Jan-1997 Umesh Vaishampayan (umeshv@NeXT.com) +* Ported to PPC. + * 10-Nov-92 Derek B Clegg (dclegg@next.com) + * Created. + */ +#include + +void +insque(struct qelem *elem, struct qelem *prev) +{ + struct qelem *next; + + next = prev->q_forw; + prev->q_forw = elem; + if (next != 0) + next->q_back = elem; + elem->q_forw = next; + elem->q_back = prev; +} diff --git a/i386/gen/isinf.c b/i386/gen/isinf.c new file mode 100644 index 0000000..cbc81ee --- /dev/null +++ b/i386/gen/isinf.c @@ -0,0 +1,56 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1987 NeXT, INC. + */ + +struct words { +#if defined(__BIG_ENDIAN__) + unsigned int hi; + unsigned int lo; +#else + unsigned int lo; + unsigned int hi; +#endif +}; + +union double_words { + double d; + struct words w; +}; + +/* + * isinf -- returns 1 if positive IEEE infinity, -1 if negative + * IEEE infinity, 0 otherwise. + */ +int +isinf(d) +double d; +{ + union double_words dw; + dw.d = d; + if (dw.w.hi == 0x7ff00000) + return(1); + if (dw.w.hi == 0xfff00000) + return(-1); + return(0); +} diff --git a/i386/gen/mcount.s b/i386/gen/mcount.s new file mode 100644 index 0000000..82af032 --- /dev/null +++ b/i386/gen/mcount.s @@ -0,0 +1,38 @@ +/* + * Copyright (c) 1999 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@ + */ +#import + +.text + .globl mcount +mcount: + pushl %ebp // setup mcount's frame + movl %esp,%ebp + + movl (%ebp),%eax // load the frame pointer of mcount's caller + movl 4(%eax),%eax // load mcount's caller's return address + pushl 4(%ebp) // push the selfpc parameter for moncount() + pushl %eax // push the frompc parameter for moncount() + CALL_EXTERN(_moncount) // call moncount() + + movl %ebp,%esp // tear down mcount's frame + popl %ebp + ret diff --git a/i386/gen/memcpy.s b/i386/gen/memcpy.s new file mode 100644 index 0000000..b6c5f3e --- /dev/null +++ b/i386/gen/memcpy.s @@ -0,0 +1,32 @@ +/* + * Copyright (c) 1999 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@ + */ +/* Copyright (c) 1992 NeXT Computer, Inc. All rights reserved. + * + * File: libc/i386/ansi/memcpy.c + * Author: Bruce Martin, NeXT Computer, Inc. + * + * HISTORY + * 24-Nov-92 Derek B Clegg (dclegg@next.com) + * Created for m98k. + */ +#define MEMCOPY +#include "bcopy.s" diff --git a/i386/gen/memmove.s b/i386/gen/memmove.s new file mode 100644 index 0000000..277f6e7 --- /dev/null +++ b/i386/gen/memmove.s @@ -0,0 +1,32 @@ +/* + * Copyright (c) 1999 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@ + */ +/* Copyright (c) 1992 NeXT Computer, Inc. All rights reserved. + * + * File: libc/i386/ansi/memmove.c + * Author: Bruce Martin, NeXT Computer, Inc. + * + * HISTORY + * 24-Nov-92 Derek B Clegg (dclegg@next.com) + * Created for m98k. + */ +#define MEMMOVE +#include "bcopy.s" diff --git a/i386/gen/remque.c b/i386/gen/remque.c new file mode 100644 index 0000000..9e032c5 --- /dev/null +++ b/i386/gen/remque.c @@ -0,0 +1,55 @@ +/* + * Copyright (c) 1999 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@ + */ +/* Copyright (c) 1992, 1997 NeXT Software, Inc. All rights reserved. + * + * File: libc/gen/ppc/remque.c + * + * struct qelem { + * struct qelem *q_forw; + * struct qelem *q_back; + * char q_data[]; + * }; + * + * void remque(struct qelem *entry); + * + * Removes `entry' from a queue. + * + * HISTORY + * 24-Jan-1997 Umesh Vaishampayan (umeshv@NeXT.com) + * Ported to PPC. + * 10-Nov-92 Derek B Clegg (dclegg@next.com) + * Created. + */ +#import + +void +remque(struct qelem *elem) +{ + struct qelem *next, *prev; + + next = elem->q_forw; + prev = elem->q_back; + if (next != 0) + next->q_back = prev; + if (prev != 0) + prev->q_forw = next; +} diff --git a/i386/gen/setjmperr.c b/i386/gen/setjmperr.c new file mode 100644 index 0000000..ab963b5 --- /dev/null +++ b/i386/gen/setjmperr.c @@ -0,0 +1,55 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1980 Regents of the University of California. + * All rights reserved. + * + * Redistribution and use in source and binary forms are permitted + * provided that the above copyright notice and this paragraph are + * duplicated in all such forms and that any documentation, + * advertising materials, and other materials related to such + * distribution and use acknowledge that the software was developed + * by the University of California, Berkeley. The name of the + * University may not be used to endorse or promote products derived + * from this software without specific prior written permission. + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. + */ + +#if defined(LIBC_SCCS) && !defined(lint) +static char sccsid[] = "@(#)setjmperr.c 5.4 (Berkeley) 6/27/88"; +#endif /* LIBC_SCCS and not lint */ + +/* + * This routine is called from longjmp() when an error occurs. + * Programs that wish to exit gracefully from this error may + * write their own versions. + * If this routine returns, the program is aborted. + */ + +void +longjmperror() +{ +#define ERRMSG "longjmp botch\n" + write(2, ERRMSG, sizeof(ERRMSG) - 1); +} diff --git a/i386/gen/strcat.c b/i386/gen/strcat.c new file mode 100644 index 0000000..32cefc0 --- /dev/null +++ b/i386/gen/strcat.c @@ -0,0 +1,77 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1988, 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(__ppc__) + +#if defined(LIBC_SCCS) && !defined(lint) +static char sccsid[] = "@(#)strcat.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ + +#include + +char * +strcat(s, append) + register char *s; + register const char *append; +{ + char *save = s; + + for (; *s; ++s); + while (*s++ = *append++); + return(save); +} + +#else +#warning ----------- Check for implementation of strcat() ----------- ! +#endif /* !defined(__ppc__) */ diff --git a/i386/gen/strcmp.c b/i386/gen/strcmp.c new file mode 100644 index 0000000..edb6235 --- /dev/null +++ b/i386/gen/strcmp.c @@ -0,0 +1,82 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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(hppa) && !defined(ppc) + +#if defined(LIBC_SCCS) && !defined(lint) +static char sccsid[] = "@(#)strcmp.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ + +#include +#include + +/* + * Compare strings. + */ +int +strcmp(s1, s2) + register const char *s1, *s2; +{ + while (*s1 == *s2++) + if (*s1++ == 0) + return (0); + return (*(unsigned char *)s1 - *(unsigned char *)--s2); +} + +#else +#warning ----------- Check for implementation of strcmp() ----------- ! +#endif /* !defined(hppa) */ diff --git a/i386/gen/strcpy.c b/i386/gen/strcpy.c new file mode 100644 index 0000000..77ecaf3 --- /dev/null +++ b/i386/gen/strcpy.c @@ -0,0 +1,77 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1988, 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(__ppc__) + +#if defined(LIBC_SCCS) && !defined(lint) +static char sccsid[] = "@(#)strcpy.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ + +#include +#include + +char * +strcpy(to, from) + register char *to; + register const char *from; +{ + char *save = to; + + for (; *to = *from; ++from, ++to); + return(save); +} + +#else +#warning ----------- Check for implementation of strcpy() ----------- ! +#endif /* !defined(__ppc__) */ diff --git a/i386/gen/strlen.c b/i386/gen/strlen.c new file mode 100644 index 0000000..b57e6e7 --- /dev/null +++ b/i386/gen/strlen.c @@ -0,0 +1,77 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 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(__ppc__) + +#if defined(LIBC_SCCS) && !defined(lint) +static char sccsid[] = "@(#)strlen.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ + +#include +#include + +size_t +strlen(str) + const char *str; +{ + register const char *s; + + for (s = str; *s; ++s); + return(s - str); +} + +#else +#warning ----------- Check for implementation of strlen() ----------- ! +#endif /* !defined(__ppc__) */ + diff --git a/i386/gen/strncat.c b/i386/gen/strncat.c new file mode 100644 index 0000000..a73aabe --- /dev/null +++ b/i386/gen/strncat.c @@ -0,0 +1,95 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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(__ppc__) + +#if defined(LIBC_SCCS) && !defined(lint) +static char sccsid[] = "@(#)strncat.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ + +#include +#include + +/* + * Concatenate src on the end of dst. At most strlen(dst)+n+1 bytes + * are written at dst (at most n+1 bytes being appended). Return dst. + */ +char * +strncat(dst, src, n) + char *dst; + const char *src; + register size_t n; +{ + if (n != 0) { + register char *d = dst; + register const char *s = src; + + while (*d != 0) + d++; + do { + if ((*d = *s++) == 0) + break; + d++; + } while (--n != 0); + *d = 0; + } + return (dst); +} + +#else +#warning ----------- Check for implementation of strncat() ----------- ! +#endif /* !defined(__ppc__) */ diff --git a/i386/gen/strncmp.c b/i386/gen/strncmp.c new file mode 100644 index 0000000..0dc3d06 --- /dev/null +++ b/i386/gen/strncmp.c @@ -0,0 +1,83 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1989, 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(__ppc__) + +#if defined(LIBC_SCCS) && !defined(lint) +static char sccsid[] = "@(#)strncmp.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ + +#include +#include + +int +strncmp(s1, s2, n) + register const char *s1, *s2; + register size_t n; +{ + + if (n == 0) + return (0); + do { + if (*s1 != *s2++) + return (*(unsigned char *)s1 - *(unsigned char *)--s2); + if (*s1++ == 0) + break; + } while (--n != 0); + return (0); +} + +#else +#warning ----------- Check for implementation of strncmp() ----------- ! +#endif /* !defined(__ppc__) */ diff --git a/i386/gen/strncpy.c b/i386/gen/strncpy.c new file mode 100644 index 0000000..c47add3 --- /dev/null +++ b/i386/gen/strncpy.c @@ -0,0 +1,95 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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(__ppc__) + +#if defined(LIBC_SCCS) && !defined(lint) +static char sccsid[] = "@(#)strncpy.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ + +#include +#include + +/* + * Copy src to dst, truncating or null-padding to always copy n bytes. + * Return dst. + */ +char * +strncpy(dst, src, n) + char *dst; + const char *src; + register size_t n; +{ + if (n != 0) { + register char *d = dst; + register const char *s = src; + + do { + if ((*d++ = *s++) == 0) { + /* NUL pad the remaining n-1 bytes */ + while (--n != 0) + *d++ = 0; + break; + } + } while (--n != 0); + } + return (dst); +} + +#else +#warning ----------- Check for implementation of strncpy() ----------- ! +#endif /* !defined(__ppc__) */ diff --git a/i386/mach/Makefile.inc b/i386/mach/Makefile.inc new file mode 100644 index 0000000..bf4f67b --- /dev/null +++ b/i386/mach/Makefile.inc @@ -0,0 +1 @@ +SRCS += mach_absolute_time.c diff --git a/i386/mach/mach_absolute_time.c b/i386/mach/mach_absolute_time.c new file mode 100644 index 0000000..86257b0 --- /dev/null +++ b/i386/mach/mach_absolute_time.c @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2000-2002 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@ + */ +#if !defined(__ppc__) +#include +#include + +extern mach_port_t clock_port; + +uint64_t mach_absolute_time(void) { + mach_timespec_t now; + (void)clock_get_time(clock_port, &now); + return (uint64_t)now.tv_sec * NSEC_PER_SEC + now.tv_nsec; +} +#endif diff --git a/i386/sys/ATPgetreq.s b/i386/sys/ATPgetreq.s new file mode 100644 index 0000000..3e47b64 --- /dev/null +++ b/i386/sys/ATPgetreq.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(ATPgetreq, 3) + ret diff --git a/i386/sys/ATPgetrsp.s b/i386/sys/ATPgetrsp.s new file mode 100644 index 0000000..4f995b5 --- /dev/null +++ b/i386/sys/ATPgetrsp.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(ATPgetrsp, 3) + ret diff --git a/i386/sys/ATPsndreq.s b/i386/sys/ATPsndreq.s new file mode 100644 index 0000000..7f35022 --- /dev/null +++ b/i386/sys/ATPsndreq.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(ATPsndreq, 3) + ret diff --git a/i386/sys/ATPsndrsp.s b/i386/sys/ATPsndrsp.s new file mode 100644 index 0000000..1207b67 --- /dev/null +++ b/i386/sys/ATPsndrsp.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(ATPsndrsp, 3) + ret diff --git a/i386/sys/ATgetmsg.s b/i386/sys/ATgetmsg.s new file mode 100644 index 0000000..9bc673a --- /dev/null +++ b/i386/sys/ATgetmsg.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(ATgetmsg, 3) + ret diff --git a/i386/sys/ATputmsg.s b/i386/sys/ATputmsg.s new file mode 100644 index 0000000..648d0a7 --- /dev/null +++ b/i386/sys/ATputmsg.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(ATputmsg, 3) + ret diff --git a/i386/sys/ATsocket.s b/i386/sys/ATsocket.s new file mode 100644 index 0000000..682c64c --- /dev/null +++ b/i386/sys/ATsocket.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(ATsocket, 3) + ret diff --git a/i386/sys/Makefile.inc b/i386/sys/Makefile.inc new file mode 100644 index 0000000..1d046d1 --- /dev/null +++ b/i386/sys/Makefile.inc @@ -0,0 +1,189 @@ +SRCS+= ATPgetreq.s \ + ATPgetrsp.s \ + ATPsndreq.s \ + ATPsndrsp.s \ + ATgetmsg.s \ + ATputmsg.s \ + ATsocket.s \ + _exit.s \ + _getlogin.s \ + _pthread_kill.s \ + _setjmp.s \ + _setlogin.s \ + _sysctl.s \ + accept.s \ + access.s \ + acct.s \ + add_profil.s \ + adjtime.s \ + bind.s \ + cerror.s \ + chdir.s \ + checkuseraccess.s \ + chflags.s \ + chmod.s \ + chown.s \ + chroot.s \ + close.s \ + connect.s \ + dup.s \ + dup2.s \ + exchangedata.s \ + execve.s \ + fchdir.s \ + fchflags.s \ + fchmod.s \ + fchown.s \ + fcntl.s \ + flock.s \ + fork.s \ + fpathconf.s \ + fstat.s \ + fstatfs.s \ + fstatv.s \ + fsync.s \ + ftruncate.s \ + futimes.s \ + getattrlist.s \ + getdirentries.s \ + getdirentriesattr.s \ + getegid.s \ + geteuid.s \ + getfh.s \ + getfsstat.s \ + getgid.s \ + getgroups.s \ + getitimer.s \ + getpeername.s \ + getpgrp.s \ + getpid.s \ + getppid.s \ + getpriority.s \ + getrlimit.s \ + getrusage.s \ + getpgid.s \ + getsid.s \ + getsockname.s \ + getsockopt.s \ + getuid.s \ + ioctl.s \ + issetugid.s \ + kill.s \ + ktrace.s \ + link.s \ + listen.s \ + load_shared_file.s \ + lseek.s \ + lstat.s \ + lstatv.s \ + madvise.s \ + mincore.s \ + minherit.s \ + mkcomplex.s \ + mkdir.s \ + mkfifo.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 \ + nfssvc.s \ + open.s \ + pathconf.s \ + pipe.s \ + pread.s \ + posix_madvise.s \ + profil.s \ + pwrite.s \ + ptrace.s \ + pthread_sigmask.s \ + quota.s \ + quotactl.s \ + read.s \ + readlink.s \ + readv.s \ + reboot.s \ + recvfrom.s \ + recvmsg.s \ + rename.s \ + reset_shared_file.s \ + revoke.s \ + rmdir.s \ + searchfs.s \ + select.s \ + sem_close.s \ + sem_destroy.s \ + sem_getvalue.s \ + sem_init.s \ + sem_open.s \ + sem_post.s \ + sem_trywait.s \ + sem_unlink.s \ + sem_wait.s \ + semconfig.s \ + semctl.s \ + semget.s \ + semop.s \ + semsys.s \ + sendmsg.s \ + sendto.s \ + setattrlist.s \ + setegid.s \ + seteuid.s \ + setgid.s \ + setgroups.s \ + setitimer.s \ + setjmp.s \ + setpgid.s \ + setpriority.s \ + setprivexec.s \ + setquota.s \ + setrlimit.s \ + setsid.s \ + setsockopt.s \ + settimeofday.s \ + setuid.s \ + shm_open.s \ + shm_unlink.s \ + shmat.s \ + shmctl.s \ + shmdt.s \ + shmget.s \ + shmsys.s \ + shutdown.s \ + sigaltstack.s \ + sigpending.s \ + sigprocmask.s \ + sigreturn.s \ + sigwait.s \ + socket.s \ + socketpair.s \ + stat.s \ + statfs.s \ + statv.s \ + swapon.s \ + symlink.s \ + sync.s \ + syscall.s \ + systable.s \ + truncate.s \ + umask.s \ + undelete.s \ + unlink.s \ + unmount.s \ + utimes.s \ + vfork.s \ + wait4.s \ + write.s \ + writev.s diff --git a/i386/sys/SYS.h b/i386/sys/SYS.h new file mode 100644 index 0000000..7da1969 --- /dev/null +++ b/i386/sys/SYS.h @@ -0,0 +1,90 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + * + * File: SYS.h + * + * Definition of the user side of the UNIX system call interface + * for i386. + * + * HISTORY + * 12-3-92 Bruce Martin (Bruce_Martin@next.com) + * Created. + */ + +#define KERNEL_PRIVATE 1 +/* + * Headers + */ +#include +#include +#include + + +#define UNIX_SYSCALL_TRAP lcall $0x2b, $0 +#define MACHDEP_SYSCALL_TRAP lcall $0x7, $0 + + +#define UNIX_SYSCALL(name, nargs) \ + .globl cerror ;\ +LEAF(_##name, 0) ;\ + movl $ SYS_##name, %eax ;\ + UNIX_SYSCALL_TRAP ;\ + jnb 2f ;\ + BRANCH_EXTERN(cerror) ;\ +2: + +#define UNIX_SYSCALL_NONAME(name, nargs) \ + .globl cerror ;\ + movl $ SYS_##name, %eax ;\ + UNIX_SYSCALL_TRAP ;\ + jnb 2f ;\ + BRANCH_EXTERN(cerror) ;\ +2: + +#define PSEUDO(pseudo, name, nargs) \ +LEAF(_##pseudo, 0) ;\ + UNIX_SYSCALL_NONAME(name, nargs) + +#if !defined(SYS_getdirentriesattr) +#define SYS_getdirentriesattr 222 +#endif + +#if !defined(SYS_semsys) +#define SYS_semsys 251 +#define SYS_msgsys 252 +#define SYS_shmsys 253 +#define SYS_semctl 254 +#define SYS_semget 255 +#define SYS_semop 256 +#define SYS_semconfig 257 +#define SYS_msgctl 258 +#define SYS_msgget 259 +#define SYS_msgsnd 260 +#define SYS_msgrcv 261 +#define SYS_shmat 262 +#define SYS_shmctl 263 +#define SYS_shmdt 264 +#define SYS_shmget 265 +#endif + diff --git a/i386/sys/_exit.s b/i386/sys/_exit.s new file mode 100644 index 0000000..f8c2d1e --- /dev/null +++ b/i386/sys/_exit.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +PSEUDO(_exit, exit, 1) + ret diff --git a/i386/sys/_getlogin.s b/i386/sys/_getlogin.s new file mode 100644 index 0000000..1d2a47a --- /dev/null +++ b/i386/sys/_getlogin.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +PSEUDO(_getlogin, getlogin, 0) + ret diff --git a/i386/sys/_pthread_kill.s b/i386/sys/_pthread_kill.s new file mode 100644 index 0000000..c45b088 --- /dev/null +++ b/i386/sys/_pthread_kill.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(__pthread_kill, 2) + ret diff --git a/i386/sys/_setjmp.s b/i386/sys/_setjmp.s new file mode 100644 index 0000000..bbec3f8 --- /dev/null +++ b/i386/sys/_setjmp.s @@ -0,0 +1,135 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + * + * HISTORY + * 20-Apr-92 Bruce Martin (bmartin@next.com) + * Created from M68K sources. + */ + +/* + * C library -- _setjmp, _longjmp + * + * _longjmp(a,v) + * will generate a "return(v)" from + * the last call to + * _setjmp(a) + * by restoring registers from the stack, + * The previous signal state is NOT restored. + * + */ + +#include + +#define JB_ONSTACK 0 +#define JB_MASK 4 +#define JB_EAX 8 +#define JB_EBX 12 +#define JB_ECX 16 +#define JB_EDX 20 +#define JB_EDI 24 +#define JB_ESI 28 +#define JB_EBP 32 +#define JB_ESP 36 +#define JB_SS 40 +#define JB_EFLAGS 44 +#define JB_EIP 48 +#define JB_CS 52 +#define JB_DS 56 +#define JB_ES 60 +#define JB_FS 64 +#define JB_GS 68 + + +LEAF(__setjmp, 0) + movl 4(%esp), %ecx // jmp_buf (struct sigcontext *) + + // now build sigcontext + movl %ebx, JB_EBX(%ecx) + movl %edi, JB_EDI(%ecx) + movl %esi, JB_ESI(%ecx) + movl %ebp, JB_EBP(%ecx) + + // EIP is set to the frame return address value + movl (%esp), %eax + movl %eax, JB_EIP(%ecx) + // ESP is set to the frame return address plus 4 + movl %esp, %eax + addl $4, %eax + movl %eax, JB_ESP(%ecx) + +#if SAVE_SEG_REGS + // segment registers + mov %ss, JB_SS(%ecx) + mov %cs, JB_CS(%ecx) + mov %ds, JB_DS(%ecx) + mov %es, JB_ES(%ecx) + mov %fs, JB_FS(%ecx) + mov %gs, JB_GS(%ecx) +#endif + + // save eflags - you can't use movl + pushf + popl %eax + movl %eax, JB_EFLAGS(%ecx) + + // return 0 + xorl %eax, %eax + ret + + +LEAF(__longjmp, 0) + subl $2,%esp + fnstcw (%esp) // save FP control word + fninit // reset FP coprocessor + fldcw (%esp) // restore FP control word + addl $2,%esp + + movl 4(%esp), %ecx // jmp_buf (struct sigcontext *) + movl 8(%esp), %eax // return value + testl %eax, %eax + jnz 1f + incl %eax + + // general registers +1: movl JB_EBX(%ecx), %ebx + movl JB_ESI(%ecx), %esi + movl JB_EDI(%ecx), %edi + movl JB_EBP(%ecx), %ebp + movl JB_ESP(%ecx), %esp + +#if SAVE_SEG_REGS + // segment registers + mov JB_SS(%ecx), %ss + mov JB_CS(%ecx), %cs + mov JB_DS(%ecx), %ds + mov JB_ES(%ecx), %es + mov JB_FS(%ecx), %fs + mov JB_GS(%ecx), %gs +#endif + + // eflags + pushl JB_EFLAGS(%ecx) + popf + + jmp *JB_EIP(%ecx) diff --git a/i386/sys/_setlogin.s b/i386/sys/_setlogin.s new file mode 100644 index 0000000..d8d2359 --- /dev/null +++ b/i386/sys/_setlogin.s @@ -0,0 +1,29 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +PSEUDO(_setlogin, setlogin, 0) + ret + diff --git a/i386/sys/_sysctl.s b/i386/sys/_sysctl.s new file mode 100644 index 0000000..1d174f8 --- /dev/null +++ b/i386/sys/_sysctl.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(__sysctl, 6) + ret diff --git a/i386/sys/accept.s b/i386/sys/accept.s new file mode 100644 index 0000000..6e0dc76 --- /dev/null +++ b/i386/sys/accept.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(accept, 3) + ret diff --git a/i386/sys/access.s b/i386/sys/access.s new file mode 100644 index 0000000..4d031b1 --- /dev/null +++ b/i386/sys/access.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(access, 2) + ret diff --git a/i386/sys/acct.s b/i386/sys/acct.s new file mode 100644 index 0000000..83074c5 --- /dev/null +++ b/i386/sys/acct.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(acct, 1) + ret diff --git a/i386/sys/add_profil.s b/i386/sys/add_profil.s new file mode 100644 index 0000000..02e610f --- /dev/null +++ b/i386/sys/add_profil.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(add_profil, 4) + ret diff --git a/i386/sys/adjtime.s b/i386/sys/adjtime.s new file mode 100644 index 0000000..4496a62 --- /dev/null +++ b/i386/sys/adjtime.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(adjtime, 2) + ret diff --git a/i386/sys/bind.s b/i386/sys/bind.s new file mode 100644 index 0000000..cbe58e1 --- /dev/null +++ b/i386/sys/bind.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(bind, 3) + ret diff --git a/i386/sys/cerror.s b/i386/sys/cerror.s new file mode 100644 index 0000000..e1ab9cc --- /dev/null +++ b/i386/sys/cerror.s @@ -0,0 +1,36 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + + .globl _errno + +LABEL(cerror) + REG_TO_EXTERN(%eax, _errno) + pushl %eax + CALL_EXTERN(_cthread_set_errno_self) + addl $4,%esp + movl $-1,%eax + movl $-1,%edx /* in case a 64-bit value is returned */ + ret diff --git a/i386/sys/chdir.s b/i386/sys/chdir.s new file mode 100644 index 0000000..b862cb4 --- /dev/null +++ b/i386/sys/chdir.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(chdir, 1) + ret diff --git a/i386/sys/checkuseraccess.s b/i386/sys/checkuseraccess.s new file mode 100644 index 0000000..a49371b --- /dev/null +++ b/i386/sys/checkuseraccess.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1998 Apple Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(checkuseraccess, 0) + ret diff --git a/i386/sys/chflags.s b/i386/sys/chflags.s new file mode 100644 index 0000000..2436f67 --- /dev/null +++ b/i386/sys/chflags.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(chflags, 2) + ret diff --git a/i386/sys/chmod.s b/i386/sys/chmod.s new file mode 100644 index 0000000..6bc417a --- /dev/null +++ b/i386/sys/chmod.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(chmod, 2) + ret diff --git a/i386/sys/chown.s b/i386/sys/chown.s new file mode 100644 index 0000000..05686ec --- /dev/null +++ b/i386/sys/chown.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(chown, 3) + ret diff --git a/i386/sys/chroot.s b/i386/sys/chroot.s new file mode 100644 index 0000000..79c27c7 --- /dev/null +++ b/i386/sys/chroot.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(chroot, 1) + ret diff --git a/i386/sys/close.s b/i386/sys/close.s new file mode 100644 index 0000000..33d4a42 --- /dev/null +++ b/i386/sys/close.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(close, 1) + ret diff --git a/i386/sys/connect.s b/i386/sys/connect.s new file mode 100644 index 0000000..96719ab --- /dev/null +++ b/i386/sys/connect.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(connect, 3) + ret diff --git a/i386/sys/dup.s b/i386/sys/dup.s new file mode 100644 index 0000000..9116c62 --- /dev/null +++ b/i386/sys/dup.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(dup, 2) + ret diff --git a/i386/sys/dup2.s b/i386/sys/dup2.s new file mode 100644 index 0000000..6f0fb01 --- /dev/null +++ b/i386/sys/dup2.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(dup2, 2) + ret diff --git a/i386/sys/exchangedata.s b/i386/sys/exchangedata.s new file mode 100644 index 0000000..dcd757f --- /dev/null +++ b/i386/sys/exchangedata.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1998 Apple Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(exchangedata, 0) + ret diff --git a/i386/sys/execve.s b/i386/sys/execve.s new file mode 100644 index 0000000..44e4ecb --- /dev/null +++ b/i386/sys/execve.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(execve, 3) + ret // execve(file, argv, arge) diff --git a/i386/sys/fchdir.s b/i386/sys/fchdir.s new file mode 100644 index 0000000..8040919 --- /dev/null +++ b/i386/sys/fchdir.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(fchdir, 1) + ret diff --git a/i386/sys/fchflags.s b/i386/sys/fchflags.s new file mode 100644 index 0000000..7189e7e --- /dev/null +++ b/i386/sys/fchflags.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(fchflags, 2) + ret diff --git a/i386/sys/fchmod.s b/i386/sys/fchmod.s new file mode 100644 index 0000000..a48a89a --- /dev/null +++ b/i386/sys/fchmod.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(fchmod, 2) + ret diff --git a/i386/sys/fchown.s b/i386/sys/fchown.s new file mode 100644 index 0000000..d410dca --- /dev/null +++ b/i386/sys/fchown.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(fchown, 3) + ret diff --git a/i386/sys/fcntl.s b/i386/sys/fcntl.s new file mode 100644 index 0000000..f788e03 --- /dev/null +++ b/i386/sys/fcntl.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(fcntl, 3) + ret diff --git a/i386/sys/flock.s b/i386/sys/flock.s new file mode 100644 index 0000000..f490a4a --- /dev/null +++ b/i386/sys/flock.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(flock, 2) + ret diff --git a/i386/sys/fork.s b/i386/sys/fork.s new file mode 100644 index 0000000..88dbda1 --- /dev/null +++ b/i386/sys/fork.s @@ -0,0 +1,164 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +LEAF(_fork, 0) + CALL_EXTERN(__cthread_fork_prepare) +#if defined(__DYNAMIC__) +// Just like __cthread_fork_prepare we need to prevent threads on the child's +// side from doing a mach call in the dynamic linker until __dyld_fork_child +// is run (see below). So we call __dyld_fork_prepare which takes out the dyld +// lock to prevent all other threads but this one from entering dyld. +.cstring +LC1: + .ascii "__dyld_fork_prepare\0" +.text + subl $4,%esp // allocate space for the address parameter + leal 0(%esp),%eax // get the address of the allocated space + pushl %eax // push the address of the allocated space + call 1f +1: popl %eax + leal LC1-1b(%eax),%eax + pushl %eax // push the name of the function to look up + call __dyld_func_lookup + addl $8,%esp // remove parameters to __dyld_func_lookup + movl 0(%esp),%eax // move the value returned in address parameter + addl $4,%esp // deallocate the space for the address param + call *%eax // call __dyld_fork_prepare indirectly +#endif + + movl $ SYS_fork,%eax; // code for fork -> eax + UNIX_SYSCALL_TRAP; // do the system call + jnc L1 // jump if CF==0 + +#if defined(__DYNAMIC__) +// __dyld_fork_parent() is called by the parent process after a fork syscall. +// This releases the dyld lock acquired by __dyld_fork_prepare(). In this case +// we just use it to clean up after a fork error so the parent process can +// dyld after fork() errors without deadlocking. +.cstring +LC2: + .ascii "__dyld_fork_parent\0" +.text + pushl %eax // save the return value (errno) + subl $4,%esp // allocate space for the address parameter + leal 0(%esp),%eax // get the address of the allocated space + pushl %eax // push the address of the allocated space + call 1f +1: popl %eax + leal LC2-1b(%eax),%eax + pushl %eax // push the name of the function to look up + call __dyld_func_lookup + addl $8,%esp // remove parameters to __dyld_func_lookup + movl 0(%esp),%eax // move the value returned in address parameter + addl $4,%esp // deallocate the space for the address param + call *%eax // call __dyld_fork_parent indirectly + popl %eax // restore the return value (errno) +#endif + CALL_EXTERN(cerror) + CALL_EXTERN(__cthread_fork_parent) + movl $-1,%eax + ret + +L1: + orl %edx,%edx // CF=OF=0, ZF set if zero result + jz L2 // parent, since r1 == 0 in parent, 1 in child + + //child here... +#if defined(__DYNAMIC__) +// Here on the child side of the fork we need to tell the dynamic linker that +// we have forked. To do this we call __dyld_fork_child in the dyanmic +// linker. But since we can't dynamicly bind anything until this is done we +// do this by using the private extern __dyld_func_lookup() function to get the +// address of __dyld_fork_child (the 'C' code equivlent): +// +// _dyld_func_lookup("__dyld_fork_child", &address); +// address(); +// +.cstring +LC0: + .ascii "__dyld_fork_child\0" + +.text + subl $4,%esp // allocate space for the address parameter + leal 0(%esp),%eax // get the address of the allocated space + pushl %eax // push the address of the allocated space + call 1f +1: popl %eax + leal LC0-1b(%eax),%eax + pushl %eax // push the name of the function to look up + call __dyld_func_lookup + addl $8,%esp // remove parameters to __dyld_func_lookup + movl 0(%esp),%eax // move the value returned in address parameter + addl $4,%esp // deallocate the space for the address param + call *%eax // call __dyld_fork_child indirectly +#endif + CALL_EXTERN(_fork_mach_init) + CALL_EXTERN(__cthread_fork_child) +#if defined(__DYNAMIC__) +.cstring +LC10: + .ascii "__dyld_fork_child_final\0" + +.text + subl $4,%esp // allocate space for the address parameter + leal 0(%esp),%eax // get the address of the allocated space + pushl %eax // push the address of the allocated space + call 1f +1: popl %eax + leal LC10-1b(%eax),%eax + pushl %eax // push the name of the function to look up + call __dyld_func_lookup + addl $8,%esp // remove parameters to __dyld_func_lookup + movl 0(%esp),%eax // move the value returned in address parameter + addl $4,%esp // deallocate the space for the address param + call *%eax // call __dyld_fork_child_final indirectly +#endif + xorl %eax,%eax // zero eax + ret + + //parent here... +L2: + push %eax // save pid +#if defined(__DYNAMIC__) +// __dyld_fork_parent() is called by the parent process after a fork syscall. +// This releases the dyld lock acquired by __dyld_fork_prepare(). + subl $4,%esp // allocate space for the address parameter + leal 0(%esp),%eax // get the address of the allocated space + pushl %eax // push the address of the allocated space + call 1f +1: popl %eax + leal LC2-1b(%eax),%eax + pushl %eax // push the name of the function to look up + call __dyld_func_lookup + addl $8,%esp // remove parameters to __dyld_func_lookup + movl 0(%esp),%eax // move the value returned in address parameter + addl $4,%esp // deallocate the space for the address param + call *%eax // call __dyld_fork_parent indirectly +#endif + CALL_EXTERN_AGAIN(__cthread_fork_parent) + pop %eax + ret + diff --git a/i386/sys/fpathconf.s b/i386/sys/fpathconf.s new file mode 100644 index 0000000..12f71ee --- /dev/null +++ b/i386/sys/fpathconf.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(fpathconf, 2) + ret diff --git a/i386/sys/fstat.s b/i386/sys/fstat.s new file mode 100644 index 0000000..1a72abb --- /dev/null +++ b/i386/sys/fstat.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(fstat, 2) + ret diff --git a/i386/sys/fstatfs.s b/i386/sys/fstatfs.s new file mode 100644 index 0000000..b9a8cdf --- /dev/null +++ b/i386/sys/fstatfs.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(fstatfs, 2) + ret diff --git a/i386/sys/fstatv.s b/i386/sys/fstatv.s new file mode 100644 index 0000000..69ee4c9 --- /dev/null +++ b/i386/sys/fstatv.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1998 Apple Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(fstatv, 0) + ret diff --git a/i386/sys/fsync.s b/i386/sys/fsync.s new file mode 100644 index 0000000..38d8f62 --- /dev/null +++ b/i386/sys/fsync.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(fsync, 1) + ret diff --git a/i386/sys/ftruncate.s b/i386/sys/ftruncate.s new file mode 100644 index 0000000..1522750 --- /dev/null +++ b/i386/sys/ftruncate.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(ftruncate, 2) + ret diff --git a/i386/sys/futimes.s b/i386/sys/futimes.s new file mode 100644 index 0000000..fc90f1d --- /dev/null +++ b/i386/sys/futimes.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(futimes, 2) + ret diff --git a/i386/sys/getattrlist.s b/i386/sys/getattrlist.s new file mode 100644 index 0000000..4e051b4 --- /dev/null +++ b/i386/sys/getattrlist.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1998 Apple Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(getattrlist, 0) + ret diff --git a/i386/sys/getdirentries.s b/i386/sys/getdirentries.s new file mode 100644 index 0000000..3592e4a --- /dev/null +++ b/i386/sys/getdirentries.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(getdirentries, 4) + ret diff --git a/i386/sys/getdirentriesattr.s b/i386/sys/getdirentriesattr.s new file mode 100644 index 0000000..4840434 --- /dev/null +++ b/i386/sys/getdirentriesattr.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1998 Apple Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(getdirentriesattr, 0) + ret diff --git a/i386/sys/getegid.s b/i386/sys/getegid.s new file mode 100644 index 0000000..5be6771 --- /dev/null +++ b/i386/sys/getegid.s @@ -0,0 +1,29 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +PSEUDO(getegid, getgid, 0) + movl %edx, %eax + ret // egid = getegid(); diff --git a/i386/sys/geteuid.s b/i386/sys/geteuid.s new file mode 100644 index 0000000..132c7a2 --- /dev/null +++ b/i386/sys/geteuid.s @@ -0,0 +1,29 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +PSEUDO(geteuid, getuid, 0) + movl %edx, %eax + ret // euid = geteuid(); diff --git a/i386/sys/getfh.s b/i386/sys/getfh.s new file mode 100644 index 0000000..a81c0e3 --- /dev/null +++ b/i386/sys/getfh.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(getfh, 2) + ret diff --git a/i386/sys/getfsstat.s b/i386/sys/getfsstat.s new file mode 100644 index 0000000..665b3a3 --- /dev/null +++ b/i386/sys/getfsstat.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(getfsstat, 3) + ret diff --git a/i386/sys/getgid.s b/i386/sys/getgid.s new file mode 100644 index 0000000..ba2aac4 --- /dev/null +++ b/i386/sys/getgid.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(getgid, 0) + ret // gid = getgid(); diff --git a/i386/sys/getgroups.s b/i386/sys/getgroups.s new file mode 100644 index 0000000..8d255a5 --- /dev/null +++ b/i386/sys/getgroups.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(getgroups, 2) + ret // ngroups = getgroups(gidsetsize, gidset) diff --git a/i386/sys/getitimer.s b/i386/sys/getitimer.s new file mode 100644 index 0000000..3e24bbf --- /dev/null +++ b/i386/sys/getitimer.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(getitimer, 2) + ret diff --git a/i386/sys/getpeername.s b/i386/sys/getpeername.s new file mode 100644 index 0000000..8a30166 --- /dev/null +++ b/i386/sys/getpeername.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(getpeername, 3) + ret diff --git a/i386/sys/getpgid.s b/i386/sys/getpgid.s new file mode 100644 index 0000000..f2dbba9 --- /dev/null +++ b/i386/sys/getpgid.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(getpgid, 1) + ret diff --git a/i386/sys/getpgrp.s b/i386/sys/getpgrp.s new file mode 100644 index 0000000..e1c3858 --- /dev/null +++ b/i386/sys/getpgrp.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(getpgrp, 1) + ret // pgrp = getpgrp(pid); diff --git a/i386/sys/getpid.s b/i386/sys/getpid.s new file mode 100644 index 0000000..beab7f7 --- /dev/null +++ b/i386/sys/getpid.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(getpid, 0) + ret // pid = getpid(); diff --git a/i386/sys/getppid.s b/i386/sys/getppid.s new file mode 100644 index 0000000..87cc8b7 --- /dev/null +++ b/i386/sys/getppid.s @@ -0,0 +1,29 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +PSEUDO(getppid, getpid, 0) + movl %edx, %eax + ret // ppid = getppid(); diff --git a/i386/sys/getpriority.s b/i386/sys/getpriority.s new file mode 100644 index 0000000..ca03e09 --- /dev/null +++ b/i386/sys/getpriority.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(getpriority, 2) + ret diff --git a/i386/sys/getrlimit.s b/i386/sys/getrlimit.s new file mode 100644 index 0000000..e8c7669 --- /dev/null +++ b/i386/sys/getrlimit.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(getrlimit, 2) + ret diff --git a/i386/sys/getrusage.s b/i386/sys/getrusage.s new file mode 100644 index 0000000..b3835d1 --- /dev/null +++ b/i386/sys/getrusage.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(getrusage, 2) + ret diff --git a/i386/sys/getsid.s b/i386/sys/getsid.s new file mode 100644 index 0000000..9af639f --- /dev/null +++ b/i386/sys/getsid.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(getsid, 1) + ret diff --git a/i386/sys/getsockname.s b/i386/sys/getsockname.s new file mode 100644 index 0000000..cdddd3f --- /dev/null +++ b/i386/sys/getsockname.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(getsockname, 3) + ret diff --git a/i386/sys/getsockopt.s b/i386/sys/getsockopt.s new file mode 100644 index 0000000..11fbb2c --- /dev/null +++ b/i386/sys/getsockopt.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(getsockopt, 5) + ret diff --git a/i386/sys/getuid.s b/i386/sys/getuid.s new file mode 100644 index 0000000..534a7ed --- /dev/null +++ b/i386/sys/getuid.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(getuid, 0) + ret // uid = getuid(); diff --git a/i386/sys/ioctl.s b/i386/sys/ioctl.s new file mode 100644 index 0000000..87d2668 --- /dev/null +++ b/i386/sys/ioctl.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(ioctl, 3) + ret diff --git a/i386/sys/issetugid.s b/i386/sys/issetugid.s new file mode 100644 index 0000000..054d7ad --- /dev/null +++ b/i386/sys/issetugid.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(issetugid, 0) + ret diff --git a/i386/sys/kill.s b/i386/sys/kill.s new file mode 100644 index 0000000..fbcde10 --- /dev/null +++ b/i386/sys/kill.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(kill, 2) + ret diff --git a/i386/sys/ktrace.s b/i386/sys/ktrace.s new file mode 100644 index 0000000..2cedba9 --- /dev/null +++ b/i386/sys/ktrace.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(ktrace, 4) + ret diff --git a/i386/sys/link.s b/i386/sys/link.s new file mode 100644 index 0000000..aaf945a --- /dev/null +++ b/i386/sys/link.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(link, 2) + ret diff --git a/i386/sys/listen.s b/i386/sys/listen.s new file mode 100644 index 0000000..ff4e5ee --- /dev/null +++ b/i386/sys/listen.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(listen, 2) + ret diff --git a/i386/sys/load_shared_file.s b/i386/sys/load_shared_file.s new file mode 100644 index 0000000..bdfebfd --- /dev/null +++ b/i386/sys/load_shared_file.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(load_shared_file, 7) + ret diff --git a/i386/sys/lseek.s b/i386/sys/lseek.s new file mode 100644 index 0000000..1d7ce24 --- /dev/null +++ b/i386/sys/lseek.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(lseek, 3) + ret diff --git a/i386/sys/lstat.s b/i386/sys/lstat.s new file mode 100644 index 0000000..fbf7e02 --- /dev/null +++ b/i386/sys/lstat.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(lstat, 2) + ret diff --git a/i386/sys/lstatv.s b/i386/sys/lstatv.s new file mode 100644 index 0000000..40d7f4f --- /dev/null +++ b/i386/sys/lstatv.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1998 Apple Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(lstatv, 0) + ret diff --git a/i386/sys/madvise.s b/i386/sys/madvise.s new file mode 100644 index 0000000..96a5603 --- /dev/null +++ b/i386/sys/madvise.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(madvise, 3) + ret diff --git a/i386/sys/mincore.s b/i386/sys/mincore.s new file mode 100644 index 0000000..1002afd --- /dev/null +++ b/i386/sys/mincore.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(mincore, 3) + ret diff --git a/i386/sys/minherit.s b/i386/sys/minherit.s new file mode 100644 index 0000000..3901af9 --- /dev/null +++ b/i386/sys/minherit.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(minherit, 3) + ret diff --git a/i386/sys/mkcomplex.s b/i386/sys/mkcomplex.s new file mode 100644 index 0000000..0b54a3b --- /dev/null +++ b/i386/sys/mkcomplex.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1998 Apple Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(mkcomplex, 0) + ret diff --git a/i386/sys/mkdir.s b/i386/sys/mkdir.s new file mode 100644 index 0000000..fd001b9 --- /dev/null +++ b/i386/sys/mkdir.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(mkdir, 2) + ret diff --git a/i386/sys/mkfifo.s b/i386/sys/mkfifo.s new file mode 100644 index 0000000..1469906 --- /dev/null +++ b/i386/sys/mkfifo.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(mkfifo, 2) + ret diff --git a/i386/sys/mknod.s b/i386/sys/mknod.s new file mode 100644 index 0000000..ab8c6fb --- /dev/null +++ b/i386/sys/mknod.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(mknod, 3) + ret diff --git a/i386/sys/mlock.s b/i386/sys/mlock.s new file mode 100644 index 0000000..0051c53 --- /dev/null +++ b/i386/sys/mlock.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(mlock, 3) + ret diff --git a/i386/sys/mlockall.s b/i386/sys/mlockall.s new file mode 100644 index 0000000..0a0dad4 --- /dev/null +++ b/i386/sys/mlockall.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(mlockall, 3) + ret diff --git a/i386/sys/mmap.s b/i386/sys/mmap.s new file mode 100644 index 0000000..57fa9a1 --- /dev/null +++ b/i386/sys/mmap.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(mmap, 6) + ret diff --git a/i386/sys/mount.s b/i386/sys/mount.s new file mode 100644 index 0000000..df208d0 --- /dev/null +++ b/i386/sys/mount.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(mount, 4) + ret diff --git a/i386/sys/mprotect.s b/i386/sys/mprotect.s new file mode 100644 index 0000000..368c648 --- /dev/null +++ b/i386/sys/mprotect.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(mprotect, 3) + ret diff --git a/i386/sys/msgctl.s b/i386/sys/msgctl.s new file mode 100644 index 0000000..9028ca2 --- /dev/null +++ b/i386/sys/msgctl.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(msgctl, 3) + ret diff --git a/i386/sys/msgget.s b/i386/sys/msgget.s new file mode 100644 index 0000000..9a9c46c --- /dev/null +++ b/i386/sys/msgget.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(msgget, 3) + ret diff --git a/i386/sys/msgrcv.s b/i386/sys/msgrcv.s new file mode 100644 index 0000000..627c8c5 --- /dev/null +++ b/i386/sys/msgrcv.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(msgrcv, 3) + ret diff --git a/i386/sys/msgsnd.s b/i386/sys/msgsnd.s new file mode 100644 index 0000000..0cf6dc2 --- /dev/null +++ b/i386/sys/msgsnd.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(msgsnd, 3) + ret diff --git a/i386/sys/msgsys.s b/i386/sys/msgsys.s new file mode 100644 index 0000000..bad4612 --- /dev/null +++ b/i386/sys/msgsys.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(msgsys, 3) + ret diff --git a/i386/sys/msync.s b/i386/sys/msync.s new file mode 100644 index 0000000..26924bc --- /dev/null +++ b/i386/sys/msync.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(msync, 2) + ret diff --git a/i386/sys/munlock.s b/i386/sys/munlock.s new file mode 100644 index 0000000..b7341af --- /dev/null +++ b/i386/sys/munlock.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(munlock, 3) + ret diff --git a/i386/sys/munlockall.s b/i386/sys/munlockall.s new file mode 100644 index 0000000..098b0b4 --- /dev/null +++ b/i386/sys/munlockall.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(munlockall, 3) + ret diff --git a/i386/sys/munmap.s b/i386/sys/munmap.s new file mode 100644 index 0000000..7e2e28c --- /dev/null +++ b/i386/sys/munmap.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(munmap, 2) + ret diff --git a/i386/sys/new_system_shared_regions.s b/i386/sys/new_system_shared_regions.s new file mode 100644 index 0000000..1a9b1bf --- /dev/null +++ b/i386/sys/new_system_shared_regions.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(new_system_shared_regions, 0) + ret diff --git a/i386/sys/nfssvc.s b/i386/sys/nfssvc.s new file mode 100644 index 0000000..70a8e2d --- /dev/null +++ b/i386/sys/nfssvc.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(nfssvc, 1) + ret diff --git a/i386/sys/open.s b/i386/sys/open.s new file mode 100644 index 0000000..c505660 --- /dev/null +++ b/i386/sys/open.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(open, 3) + ret diff --git a/i386/sys/pathconf.s b/i386/sys/pathconf.s new file mode 100644 index 0000000..ae6eab4 --- /dev/null +++ b/i386/sys/pathconf.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(pathconf, 2) + ret diff --git a/i386/sys/pipe.s b/i386/sys/pipe.s new file mode 100644 index 0000000..8fefcdd --- /dev/null +++ b/i386/sys/pipe.s @@ -0,0 +1,32 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(pipe, 0) + movl 4(%esp),%ecx + movl %eax,(%ecx) + movl %edx,4(%ecx) + xorl %eax,%eax + ret diff --git a/i386/sys/posix_madvise.s b/i386/sys/posix_madvise.s new file mode 100644 index 0000000..bfa2567 --- /dev/null +++ b/i386/sys/posix_madvise.s @@ -0,0 +1,27 @@ +/* + * Copyright (c) 1999 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@ + */ +/* Copyright 1998 Apple Computer, Inc. */ + +#include "SYS.h" + +PSEUDO(posix_madvise, madvise, 3) + ret diff --git a/i386/sys/pread.s b/i386/sys/pread.s new file mode 100644 index 0000000..3fb9c27 --- /dev/null +++ b/i386/sys/pread.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(pread, 4) + ret diff --git a/i386/sys/profil.s b/i386/sys/profil.s new file mode 100644 index 0000000..e9af89f --- /dev/null +++ b/i386/sys/profil.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(profil, 4) + ret diff --git a/i386/sys/pthread_sigmask.s b/i386/sys/pthread_sigmask.s new file mode 100644 index 0000000..629a6c2 --- /dev/null +++ b/i386/sys/pthread_sigmask.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(pthread_sigmask, 3) + ret diff --git a/i386/sys/ptrace.s b/i386/sys/ptrace.s new file mode 100644 index 0000000..28ab2ad --- /dev/null +++ b/i386/sys/ptrace.s @@ -0,0 +1,33 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + + .globl _errno + +LEAF(_ptrace, 0) + xorl %eax,%eax + REG_TO_EXTERN(%eax,_errno) +UNIX_SYSCALL_NONAME(ptrace, 4) + ret diff --git a/i386/sys/pwrite.s b/i386/sys/pwrite.s new file mode 100644 index 0000000..165c202 --- /dev/null +++ b/i386/sys/pwrite.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(pwrite, 4) + ret diff --git a/i386/sys/quota.s b/i386/sys/quota.s new file mode 100644 index 0000000..f3788d7 --- /dev/null +++ b/i386/sys/quota.s @@ -0,0 +1,30 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +#define SYS_quota 149 + +UNIX_SYSCALL(quota, 4) + ret diff --git a/i386/sys/quotactl.s b/i386/sys/quotactl.s new file mode 100644 index 0000000..cc89a5a --- /dev/null +++ b/i386/sys/quotactl.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(quotactl, 3) + ret diff --git a/i386/sys/read.s b/i386/sys/read.s new file mode 100644 index 0000000..1429fa2 --- /dev/null +++ b/i386/sys/read.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(read, 3) + ret diff --git a/i386/sys/readlink.s b/i386/sys/readlink.s new file mode 100644 index 0000000..958d7b7 --- /dev/null +++ b/i386/sys/readlink.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(readlink, 3) + ret diff --git a/i386/sys/readv.s b/i386/sys/readv.s new file mode 100644 index 0000000..fe11a86 --- /dev/null +++ b/i386/sys/readv.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(readv, 3) + ret diff --git a/i386/sys/reboot.s b/i386/sys/reboot.s new file mode 100644 index 0000000..b6841b4 --- /dev/null +++ b/i386/sys/reboot.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(reboot, 2) + hlt diff --git a/i386/sys/recvfrom.s b/i386/sys/recvfrom.s new file mode 100644 index 0000000..a9ab56e --- /dev/null +++ b/i386/sys/recvfrom.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(recvfrom, 6) + ret diff --git a/i386/sys/recvmsg.s b/i386/sys/recvmsg.s new file mode 100644 index 0000000..d61786f --- /dev/null +++ b/i386/sys/recvmsg.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(recvmsg, 3) + ret diff --git a/i386/sys/rename.s b/i386/sys/rename.s new file mode 100644 index 0000000..a3efcfb --- /dev/null +++ b/i386/sys/rename.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(rename, 2) + ret diff --git a/i386/sys/reset_shared_file.s b/i386/sys/reset_shared_file.s new file mode 100644 index 0000000..49e7424 --- /dev/null +++ b/i386/sys/reset_shared_file.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(reset_shared_file, 3) + ret diff --git a/i386/sys/revoke.s b/i386/sys/revoke.s new file mode 100644 index 0000000..438ad16 --- /dev/null +++ b/i386/sys/revoke.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(revoke, 1) + ret diff --git a/i386/sys/rmdir.s b/i386/sys/rmdir.s new file mode 100644 index 0000000..d5c2e6b --- /dev/null +++ b/i386/sys/rmdir.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(rmdir, 1) + ret diff --git a/i386/sys/s.template b/i386/sys/s.template new file mode 100644 index 0000000..d42f280 --- /dev/null +++ b/i386/sys/s.template @@ -0,0 +1,7 @@ +/* + * Copyright (c) 1998 Apple Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL($FILENAMESANSEXTENSION$, 0) + ret diff --git a/i386/sys/searchfs.s b/i386/sys/searchfs.s new file mode 100644 index 0000000..4ee3b8b --- /dev/null +++ b/i386/sys/searchfs.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1998 Apple Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(searchfs, 0) + ret diff --git a/i386/sys/select.s b/i386/sys/select.s new file mode 100644 index 0000000..2aa2880 --- /dev/null +++ b/i386/sys/select.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(select, 5) + ret diff --git a/i386/sys/sem_close.s b/i386/sys/sem_close.s new file mode 100644 index 0000000..c3ed857 --- /dev/null +++ b/i386/sys/sem_close.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +UNIX_SYSCALL(sem_close, 1) + ret + diff --git a/i386/sys/sem_destroy.s b/i386/sys/sem_destroy.s new file mode 100644 index 0000000..2b7fdc5 --- /dev/null +++ b/i386/sys/sem_destroy.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +UNIX_SYSCALL(sem_destroy, 1) + ret + diff --git a/i386/sys/sem_getvalue.s b/i386/sys/sem_getvalue.s new file mode 100644 index 0000000..d169e21 --- /dev/null +++ b/i386/sys/sem_getvalue.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +UNIX_SYSCALL(sem_getvalue, 2) + ret + diff --git a/i386/sys/sem_init.s b/i386/sys/sem_init.s new file mode 100644 index 0000000..daf0ba9 --- /dev/null +++ b/i386/sys/sem_init.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +UNIX_SYSCALL(sem_init, 3) + ret + diff --git a/i386/sys/sem_open.s b/i386/sys/sem_open.s new file mode 100644 index 0000000..2c68a7c --- /dev/null +++ b/i386/sys/sem_open.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +UNIX_SYSCALL(sem_open, 4) + ret + diff --git a/i386/sys/sem_post.s b/i386/sys/sem_post.s new file mode 100644 index 0000000..f6b24af --- /dev/null +++ b/i386/sys/sem_post.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +UNIX_SYSCALL(sem_post, 1) + ret + diff --git a/i386/sys/sem_trywait.s b/i386/sys/sem_trywait.s new file mode 100644 index 0000000..9c0f725 --- /dev/null +++ b/i386/sys/sem_trywait.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +UNIX_SYSCALL(sem_trywait, 1) + ret + diff --git a/i386/sys/sem_unlink.s b/i386/sys/sem_unlink.s new file mode 100644 index 0000000..0449cbf --- /dev/null +++ b/i386/sys/sem_unlink.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +UNIX_SYSCALL(sem_unlink, 1) + ret + diff --git a/i386/sys/sem_wait.s b/i386/sys/sem_wait.s new file mode 100644 index 0000000..405b047 --- /dev/null +++ b/i386/sys/sem_wait.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +UNIX_SYSCALL(sem_wait, 1) + ret + diff --git a/i386/sys/semconfig.s b/i386/sys/semconfig.s new file mode 100644 index 0000000..5c07385 --- /dev/null +++ b/i386/sys/semconfig.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(semconfig, 3) + ret diff --git a/i386/sys/semctl.s b/i386/sys/semctl.s new file mode 100644 index 0000000..b53bebe --- /dev/null +++ b/i386/sys/semctl.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(semctl, 3) + ret diff --git a/i386/sys/semget.s b/i386/sys/semget.s new file mode 100644 index 0000000..1889c4d --- /dev/null +++ b/i386/sys/semget.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(semget, 3) + ret diff --git a/i386/sys/semop.s b/i386/sys/semop.s new file mode 100644 index 0000000..7c0c902 --- /dev/null +++ b/i386/sys/semop.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(semop, 3) + ret diff --git a/i386/sys/semsys.s b/i386/sys/semsys.s new file mode 100644 index 0000000..e775bf6 --- /dev/null +++ b/i386/sys/semsys.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(semsys, 3) + ret diff --git a/i386/sys/sendmsg.s b/i386/sys/sendmsg.s new file mode 100644 index 0000000..c6acb08 --- /dev/null +++ b/i386/sys/sendmsg.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(sendmsg, 3) + ret diff --git a/i386/sys/sendto.s b/i386/sys/sendto.s new file mode 100644 index 0000000..990f1f1 --- /dev/null +++ b/i386/sys/sendto.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(sendto, 6) + ret diff --git a/i386/sys/setattrlist.s b/i386/sys/setattrlist.s new file mode 100644 index 0000000..907e057 --- /dev/null +++ b/i386/sys/setattrlist.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1998 Apple Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(setattrlist, 0) + ret diff --git a/i386/sys/setegid.s b/i386/sys/setegid.s new file mode 100644 index 0000000..a4db7f8 --- /dev/null +++ b/i386/sys/setegid.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(setegid, 1) + ret diff --git a/i386/sys/seteuid.s b/i386/sys/seteuid.s new file mode 100644 index 0000000..497ea22 --- /dev/null +++ b/i386/sys/seteuid.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(seteuid, 1) + ret diff --git a/i386/sys/setgid.s b/i386/sys/setgid.s new file mode 100644 index 0000000..4767c4c --- /dev/null +++ b/i386/sys/setgid.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(setgid, 1) + ret diff --git a/i386/sys/setgroups.s b/i386/sys/setgroups.s new file mode 100644 index 0000000..66add53 --- /dev/null +++ b/i386/sys/setgroups.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(setgroups, 2) + ret // setgroups(gidsetsize, gidset) diff --git a/i386/sys/setitimer.s b/i386/sys/setitimer.s new file mode 100644 index 0000000..8806cd9 --- /dev/null +++ b/i386/sys/setitimer.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(setitimer, 3) + ret diff --git a/i386/sys/setjmp.s b/i386/sys/setjmp.s new file mode 100644 index 0000000..3461c66 --- /dev/null +++ b/i386/sys/setjmp.s @@ -0,0 +1,154 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +/* + * NeXT 386 setjmp/longjmp + * + * Written by Bruce Martin, NeXT Inc. 4/9/92 + */ + +/* + * C library -- setjmp, longjmp + * + * longjmp(a,v) + * will generate a "return(v)" from + * the last call to + * setjmp(a) + * by restoring registers from the stack, + * The previous value of the signal mask is + * restored. + * + */ + +#include +#include "SYS.h" + +#define JB_ONSTACK 0 +#define JB_MASK 4 +#define JB_EAX 8 +#define JB_EBX 12 +#define JB_ECX 16 +#define JB_EDX 20 +#define JB_EDI 24 +#define JB_ESI 28 +#define JB_EBP 32 +#define JB_ESP 36 +#define JB_SS 40 +#define JB_EFLAGS 44 +#define JB_EIP 48 +#define JB_CS 52 +#define JB_DS 56 +#define JB_ES 60 +#define JB_FS 64 +#define JB_GS 68 +#define JB_SAVEMASK 72 // sigsetjmp/siglongjmp only + +LEAF(_sigsetjmp, 0) + movl 4(%esp), %eax // sigjmp_buf * jmpbuf; + movl 8(%esp), %ecx // int savemask; + movl %ecx, JB_SAVEMASK(%eax) // jmpbuf[_JBLEN] = savemask; + cmpl $0, %ecx // if savemask != 0 + jne _setjmp // setjmp(jmpbuf); + BRANCH_EXTERN(__setjmp) // else + // _setjmp(jmpbuf); + +LEAF(_setjmp, 0) + movl 4(%esp), %ecx // jmp_buf (struct sigcontext *) + pushl %ecx // save ecx + + // call sigstack to get the current signal stack + subl $12, %esp // space for return structure + pushl %esp + pushl $0 + CALL_EXTERN(_sigaltstack) + movl 12(%esp), %eax // save stack pointer + movl %eax, JB_ONSTACK(%ecx) + addl $20, %esp + + // call sigblock to get signal mask + pushl $0 + CALL_EXTERN(_sigblock) + addl $4, %esp + popl %ecx // restore ecx + movl %eax, JB_MASK(%ecx) + + // now build sigcontext + movl %ebx, JB_EBX(%ecx) + movl %edi, JB_EDI(%ecx) + movl %esi, JB_ESI(%ecx) + movl %ebp, JB_EBP(%ecx) + + // EIP is set to the frame return address value + movl (%esp), %eax + movl %eax, JB_EIP(%ecx) + // ESP is set to the frame return address plus 4 + movl %esp, %eax + addl $4, %eax + movl %eax, JB_ESP(%ecx) + + // segment registers + movl $0, JB_SS(%ecx) + mov %ss, JB_SS(%ecx) + movl $0, JB_CS(%ecx) + mov %cs, JB_CS(%ecx) + movl $0, JB_DS(%ecx) + mov %ds, JB_DS(%ecx) + movl $0, JB_ES(%ecx) + mov %es, JB_ES(%ecx) + movl $0, JB_FS(%ecx) + mov %fs, JB_FS(%ecx) + movl $0, JB_GS(%ecx) + mov %gs, JB_GS(%ecx) + + // save eflags - you can't use movl + pushf + popl %eax + movl %eax, JB_EFLAGS(%ecx) + + // return 0 + xorl %eax, %eax + ret + +LEAF(_siglongjmp, 0) + movl 4(%esp), %eax // sigjmp_buf * jmpbuf; + cmpl $0, JB_SAVEMASK(%eax) // if jmpbuf[_JBLEN] != 0 + jne _longjmp // longjmp(jmpbuf, var); + BRANCH_EXTERN(__longjmp) // else + // _longjmp(jmpbuf, var); + +LEAF(_longjmp, 0) + subl $2,%esp + fnstcw (%esp) // save FP control word + fninit // reset FP coprocessor + fldcw (%esp) // restore FP control word + addl $2,%esp + movl 4(%esp), %eax // address of jmp_buf (saved context) + movl 8(%esp), %edx // return value + movl %edx, JB_EAX(%eax) // return value into saved context + movl $ SYS_sigreturn, %eax // sigreturn system call + UNIX_SYSCALL_TRAP + addl $8, %esp + CALL_EXTERN(_longjmperror) + CALL_EXTERN(_abort) +END(_longjmp) diff --git a/i386/sys/setpgid.s b/i386/sys/setpgid.s new file mode 100644 index 0000000..d0627ef --- /dev/null +++ b/i386/sys/setpgid.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(setpgid, 2) + ret diff --git a/i386/sys/setpriority.s b/i386/sys/setpriority.s new file mode 100644 index 0000000..315ec64 --- /dev/null +++ b/i386/sys/setpriority.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(setpriority, 3) + ret diff --git a/i386/sys/setprivexec.s b/i386/sys/setprivexec.s new file mode 100644 index 0000000..9569b59 --- /dev/null +++ b/i386/sys/setprivexec.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(setprivexec, 3) + ret diff --git a/i386/sys/setquota.s b/i386/sys/setquota.s new file mode 100644 index 0000000..0919c02 --- /dev/null +++ b/i386/sys/setquota.s @@ -0,0 +1,30 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +#define SYS_setquota 148 + +UNIX_SYSCALL(setquota, 2) + ret diff --git a/i386/sys/setrlimit.s b/i386/sys/setrlimit.s new file mode 100644 index 0000000..06ffe21 --- /dev/null +++ b/i386/sys/setrlimit.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(setrlimit, 2) + ret diff --git a/i386/sys/setsid.s b/i386/sys/setsid.s new file mode 100644 index 0000000..5f6905e --- /dev/null +++ b/i386/sys/setsid.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(setsid, 0) + ret diff --git a/i386/sys/setsockopt.s b/i386/sys/setsockopt.s new file mode 100644 index 0000000..48d60af --- /dev/null +++ b/i386/sys/setsockopt.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(setsockopt, 5) + ret diff --git a/i386/sys/settimeofday.s b/i386/sys/settimeofday.s new file mode 100644 index 0000000..529c5f9 --- /dev/null +++ b/i386/sys/settimeofday.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(settimeofday, 2) + ret diff --git a/i386/sys/setuid.s b/i386/sys/setuid.s new file mode 100644 index 0000000..dbebb62 --- /dev/null +++ b/i386/sys/setuid.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(setuid, 1) + ret diff --git a/i386/sys/shm_open.s b/i386/sys/shm_open.s new file mode 100644 index 0000000..3629959 --- /dev/null +++ b/i386/sys/shm_open.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(shm_open, 3) + ret diff --git a/i386/sys/shm_unlink.s b/i386/sys/shm_unlink.s new file mode 100644 index 0000000..cbbc420 --- /dev/null +++ b/i386/sys/shm_unlink.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(shm_unlink, 3) + ret diff --git a/i386/sys/shmat.s b/i386/sys/shmat.s new file mode 100644 index 0000000..c8fdc2c --- /dev/null +++ b/i386/sys/shmat.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(shmat, 3) + ret diff --git a/i386/sys/shmctl.s b/i386/sys/shmctl.s new file mode 100644 index 0000000..4ae81b7 --- /dev/null +++ b/i386/sys/shmctl.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(shmctl, 3) + ret diff --git a/i386/sys/shmdt.s b/i386/sys/shmdt.s new file mode 100644 index 0000000..bfc59ab --- /dev/null +++ b/i386/sys/shmdt.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(shmdt, 3) + ret diff --git a/i386/sys/shmget.s b/i386/sys/shmget.s new file mode 100644 index 0000000..592ff0e --- /dev/null +++ b/i386/sys/shmget.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(shmget, 3) + ret diff --git a/i386/sys/shmsys.s b/i386/sys/shmsys.s new file mode 100644 index 0000000..48f49c6 --- /dev/null +++ b/i386/sys/shmsys.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(shmsys, 3) + ret diff --git a/i386/sys/shutdown.s b/i386/sys/shutdown.s new file mode 100644 index 0000000..8e201ac --- /dev/null +++ b/i386/sys/shutdown.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(shutdown, 2) + ret diff --git a/i386/sys/sigaltstack.s b/i386/sys/sigaltstack.s new file mode 100644 index 0000000..b4ca3e5 --- /dev/null +++ b/i386/sys/sigaltstack.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(sigaltstack, 3) + ret diff --git a/i386/sys/sigpending.s b/i386/sys/sigpending.s new file mode 100644 index 0000000..6e99e21 --- /dev/null +++ b/i386/sys/sigpending.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(sigpending, 1) + ret diff --git a/i386/sys/sigprocmask.s b/i386/sys/sigprocmask.s new file mode 100644 index 0000000..92b0432 --- /dev/null +++ b/i386/sys/sigprocmask.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(sigprocmask, 3) + ret diff --git a/i386/sys/sigreturn.s b/i386/sys/sigreturn.s new file mode 100644 index 0000000..b048bb4 --- /dev/null +++ b/i386/sys/sigreturn.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(sigreturn, 1) + ret diff --git a/i386/sys/sigwait.s b/i386/sys/sigwait.s new file mode 100644 index 0000000..0674fb8 --- /dev/null +++ b/i386/sys/sigwait.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(sigwait, 2) + ret diff --git a/i386/sys/socket.s b/i386/sys/socket.s new file mode 100644 index 0000000..905c645 --- /dev/null +++ b/i386/sys/socket.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(socket, 3) + ret diff --git a/i386/sys/socketpair.s b/i386/sys/socketpair.s new file mode 100644 index 0000000..2e7c00a --- /dev/null +++ b/i386/sys/socketpair.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(socketpair, 5) + ret diff --git a/i386/sys/stat.s b/i386/sys/stat.s new file mode 100644 index 0000000..cb041e5 --- /dev/null +++ b/i386/sys/stat.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(stat, 2) + ret diff --git a/i386/sys/statfs.s b/i386/sys/statfs.s new file mode 100644 index 0000000..386a41b --- /dev/null +++ b/i386/sys/statfs.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(statfs, 2); + ret diff --git a/i386/sys/statv.s b/i386/sys/statv.s new file mode 100644 index 0000000..db5ce1c --- /dev/null +++ b/i386/sys/statv.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1998 Apple Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(statv, 0) + ret diff --git a/i386/sys/swapon.s b/i386/sys/swapon.s new file mode 100644 index 0000000..fe34af2 --- /dev/null +++ b/i386/sys/swapon.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(swapon, 1) + ret diff --git a/i386/sys/symlink.s b/i386/sys/symlink.s new file mode 100644 index 0000000..44edc06 --- /dev/null +++ b/i386/sys/symlink.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(symlink, 2) + ret diff --git a/i386/sys/sync.s b/i386/sys/sync.s new file mode 100644 index 0000000..03f711f --- /dev/null +++ b/i386/sys/sync.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(sync, 0) + ret diff --git a/i386/sys/syscall.s b/i386/sys/syscall.s new file mode 100644 index 0000000..2e21b2d --- /dev/null +++ b/i386/sys/syscall.s @@ -0,0 +1,37 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +LEAF(_syscall, 0) + popl %ecx // ret addr + popl %eax // syscall number + pushl %ecx + UNIX_SYSCALL_TRAP + movl (%esp),%edx // add one element to stack so + pushl %ecx // caller "pop" will work + jnb 2f + BRANCH_EXTERN(cerror) +2: +END(_syscall) diff --git a/i386/sys/systable.s b/i386/sys/systable.s new file mode 100644 index 0000000..4dec901 --- /dev/null +++ b/i386/sys/systable.s @@ -0,0 +1,25 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +UNIX_SYSCALL(table, 5) + ret diff --git a/i386/sys/truncate.s b/i386/sys/truncate.s new file mode 100644 index 0000000..a29542d --- /dev/null +++ b/i386/sys/truncate.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(truncate, 2) + ret diff --git a/i386/sys/umask.s b/i386/sys/umask.s new file mode 100644 index 0000000..82d5619 --- /dev/null +++ b/i386/sys/umask.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(umask, 1) + ret diff --git a/i386/sys/undelete.s b/i386/sys/undelete.s new file mode 100644 index 0000000..1e1c804 --- /dev/null +++ b/i386/sys/undelete.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(undelete, 1) + ret diff --git a/i386/sys/unlink.s b/i386/sys/unlink.s new file mode 100644 index 0000000..d3b7191 --- /dev/null +++ b/i386/sys/unlink.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(unlink, 1) + ret diff --git a/i386/sys/unmount.s b/i386/sys/unmount.s new file mode 100644 index 0000000..283b03c --- /dev/null +++ b/i386/sys/unmount.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(unmount, 1) + ret diff --git a/i386/sys/utimes.s b/i386/sys/utimes.s new file mode 100644 index 0000000..d9d7b8b --- /dev/null +++ b/i386/sys/utimes.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(utimes, 1) + ret diff --git a/i386/sys/vfork.s b/i386/sys/vfork.s new file mode 100644 index 0000000..7bf2402 --- /dev/null +++ b/i386/sys/vfork.s @@ -0,0 +1,185 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +#if 0 +LEAF(_vfork, 0) + CALL_EXTERN(__cthread_fork_prepare) +#if defined(__DYNAMIC__) +// Just like __cthread_fork_prepare we need to prevent threads on the child's +// side from doing a mach call in the dynamic linker until __dyld_fork_child +// is run (see below). So we call __dyld_fork_prepare which takes out the dyld +// lock to prevent all other threads but this one from entering dyld. +.cstring +LC1: + .ascii "__dyld_fork_prepare\0" +.text + subl $4,%esp // allocate space for the address parameter + leal 0(%esp),%eax // get the address of the allocated space + pushl %eax // push the address of the allocated space + call 1f +1: popl %eax + leal LC1-1b(%eax),%eax + pushl %eax // push the name of the function to look up + call __dyld_func_lookup + addl $8,%esp // remove parameters to __dyld_func_lookup + movl 0(%esp),%eax // move the value returned in address parameter + addl $4,%esp // deallocate the space for the address param + call *%eax // call __dyld_fork_prepare indirectly +#endif + + movl $ SYS_vfork,%eax; // code for vfork -> eax + UNIX_SYSCALL_TRAP; // do the system call + jnc L1 // jump if CF==0 + +#if defined(__DYNAMIC__) +// __dyld_fork_parent() is called by the parent process after a vfork syscall. +// This releases the dyld lock acquired by __dyld_fork_prepare(). In this case +// we just use it to clean up after a vfork error so the parent process can +// dyld after vfork() errors without deadlocking. +.cstring +LC2: + .ascii "__dyld_fork_parent\0" +.text + pushl %eax // save the return value (errno) + subl $4,%esp // allocate space for the address parameter + leal 0(%esp),%eax // get the address of the allocated space + pushl %eax // push the address of the allocated space + call 1f +1: popl %eax + leal LC2-1b(%eax),%eax + pushl %eax // push the name of the function to look up + call __dyld_func_lookup + addl $8,%esp // remove parameters to __dyld_func_lookup + movl 0(%esp),%eax // move the value returned in address parameter + addl $4,%esp // deallocate the space for the address param + call *%eax // call __dyld_fork_parent indirectly + popl %eax // restore the return value (errno) +#endif + CALL_EXTERN(cerror) + CALL_EXTERN(__cthread_fork_parent) + movl $-1,%eax + ret + +L1: + orl %edx,%edx // CF=OF=0, ZF set if zero result + jz L2 // parent, since r1 == 0 in parent, 1 in child + + //child here... +#if defined(__DYNAMIC__) +// Here on the child side of the vfork we need to tell the dynamic linker that +// we have vforked. To do this we call __dyld_fork_child in the dyanmic +// linker. But since we can't dynamicly bind anything until this is done we +// do this by using the private extern __dyld_func_lookup() function to get the +// address of __dyld_fork_child (the 'C' code equivlent): +// +// _dyld_func_lookup("__dyld_fork_child", &address); +// address(); +// +.cstring +LC0: + .ascii "__dyld_fork_child\0" + +.text + subl $4,%esp // allocate space for the address parameter + leal 0(%esp),%eax // get the address of the allocated space + pushl %eax // push the address of the allocated space + call 1f +1: popl %eax + leal LC0-1b(%eax),%eax + pushl %eax // push the name of the function to look up + call __dyld_func_lookup + addl $8,%esp // remove parameters to __dyld_func_lookup + movl 0(%esp),%eax // move the value returned in address parameter + addl $4,%esp // deallocate the space for the address param + call *%eax // call __dyld_fork_child indirectly +#endif + CALL_EXTERN(_fork_mach_init) + CALL_EXTERN(__cthread_fork_child) +#if defined(__DYNAMIC__) +.cstring +LC10: + .ascii "__dyld_fork_child_final\0" + +.text + subl $4,%esp // allocate space for the address parameter + leal 0(%esp),%eax // get the address of the allocated space + pushl %eax // push the address of the allocated space + call 1f +1: popl %eax + leal LC10-1b(%eax),%eax + pushl %eax // push the name of the function to look up + call __dyld_func_lookup + addl $8,%esp // remove parameters to __dyld_func_lookup + movl 0(%esp),%eax // move the value returned in address parameter + addl $4,%esp // deallocate the space for the address param + call *%eax // call __dyld_fork_child_final indirectly +#endif + xorl %eax,%eax // zero eax + ret + + //parent here... +L2: + push %eax // save pid +#if defined(__DYNAMIC__) +// __dyld_fork_parent() is called by the parent process after a vfork syscall. +// This releases the dyld lock acquired by __dyld_fork_prepare(). + subl $4,%esp // allocate space for the address parameter + leal 0(%esp),%eax // get the address of the allocated space + pushl %eax // push the address of the allocated space + call 1f +1: popl %eax + leal LC2-1b(%eax),%eax + pushl %eax // push the name of the function to look up + call __dyld_func_lookup + addl $8,%esp // remove parameters to __dyld_func_lookup + movl 0(%esp),%eax // move the value returned in address parameter + addl $4,%esp // deallocate the space for the address param + call *%eax // call __dyld_fork_parent indirectly +#endif + CALL_EXTERN_AGAIN(__cthread_fork_parent) + pop %eax + ret +#else + +LEAF(_vfork, 0) + popl %ecx + movl $ SYS_vfork,%eax; // code for vfork -> eax + UNIX_SYSCALL_TRAP; // do the system call + jnb L1 // jump if CF==0 + pushl %ecx + BRANCH_EXTERN(cerror) + +L1: + orl %edx,%edx // CF=OF=0, ZF set if zero result + jz L2 // parent, since r1 == 0 in parent, 1 in child + xorl %eax,%eax // zero eax + jmp *%ecx + +L2: + jmp *%ecx + +#endif + diff --git a/i386/sys/wait4.s b/i386/sys/wait4.s new file mode 100644 index 0000000..889c6c0 --- /dev/null +++ b/i386/sys/wait4.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(wait4, 4) + ret diff --git a/i386/sys/write.s b/i386/sys/write.s new file mode 100644 index 0000000..e8e98f9 --- /dev/null +++ b/i386/sys/write.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(write, 3) + ret diff --git a/i386/sys/writev.s b/i386/sys/writev.s new file mode 100644 index 0000000..10fc07d --- /dev/null +++ b/i386/sys/writev.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include "SYS.h" + +UNIX_SYSCALL(writev, 3) + ret diff --git a/i386/threads/Makefile.inc b/i386/threads/Makefile.inc new file mode 100644 index 0000000..b0e854d --- /dev/null +++ b/i386/threads/Makefile.inc @@ -0,0 +1,2 @@ +CFLAGS+= -I${.CURDIR}/threads +SRCS+= thread.c diff --git a/i386/threads/thread.c b/i386/threads/thread.c new file mode 100644 index 0000000..a79fb2f --- /dev/null +++ b/i386/threads/thread.c @@ -0,0 +1,56 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Mach Operating System + * Copyright (c) 1989 Carnegie-Mellon University + * All rights reserved. The CMU software License Agreement specifies + * the terms and conditions for use and redistribution. + */ + +/* + * 386/thread.c + * + * Cproc startup for 386 MTHREAD implementation. + */ + +#include +#include +#include +#include "cthread_internals.h" + +void +_pthread_set_self(p) + cproc_t p; +{ + asm("pushl %0" : : "m" (p)); + asm("pushl $0"); // fake the kernel out + asm("movl $1, %%eax" : : : "ax"); + asm("lcall $0x3b, $0"); + asm("addl $0x8, %%esp" ::); +} + +void * +pthread_self() +{ + asm("movl $0, %eax"); + asm("lcall $0x3b, $0"); +} diff --git a/include/Makefile.inc b/include/Makefile.inc new file mode 100644 index 0000000..f6eb88b --- /dev/null +++ b/include/Makefile.inc @@ -0,0 +1,70 @@ +.include "${.CURDIR}/include/arpa/Makefile.inc" +.include "${.CURDIR}/include/protocols/Makefile.inc" +.include "${.CURDIR}/include/objc/Makefile.inc" + +INC_INSTHDRS += NSSystemDirectories.h \ + ar.h \ + asm.h \ + bitstring.h \ + c.h \ + crt_externs.h \ + ctype.h \ + db.h \ + dirent.h \ + disktab.h \ + err.h \ + errno.h \ + fcntl.h \ + fnmatch.h \ + fsproperties.h \ + fstab.h \ + fts.h \ + glob.h \ + grp.h \ + kvm.h \ + libc.h \ + libgen.h \ + limits.h \ + locale.h \ + memory.h \ + monitor.h \ + mpool.h \ + ndbm.h \ + netdb.h \ + nlist.h \ + paths.h \ + pwd.h \ + ranlib.h \ + regex.h \ + regexp.h \ + rune.h \ + runetype.h \ + semaphore.h \ + setjmp.h \ + sgtty.h \ + signal.h \ + stab.h \ + standards.h \ + stddef.h \ + stdio.h \ + stdlib.h \ + string.h \ + strings.h \ + struct.h \ + sysexits.h \ + syslog.h \ + tar.h \ + termios.h \ + time.h \ + ttyent.h \ + tzfile.h \ + ucontext.h \ + ulimit.h \ + unistd.h \ + util.h \ + utime.h \ + utmp.h \ + vis.h \ + +INC_INSTHDRS := ${INC_INSTHDRS:S/^/${.CURDIR}\/include\//} +INSTHDRS += ${INC_INSTHDRS} diff --git a/include/NSSystemDirectories.h b/include/NSSystemDirectories.h new file mode 100644 index 0000000..5dfd37a --- /dev/null +++ b/include/NSSystemDirectories.h @@ -0,0 +1,90 @@ +/* + * Copyright (c) 1999-2000 Apple Computer, Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * Portions Copyright (c) 1999-2000 Apple Computer, Inc. All Rights + * Reserved. This 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.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. + * + * 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@ + */ + +/* + This API returns the various standard system directories where apps, resources, etc get installed. + Because queries can return multiple directories, the API is in the form of an enumeration. + The directories are returned in search path order; that is, the first place to look is returned first. + This API may return directories that do not exist yet. + If NSUserDomain is included in a query, then the results will contain "~" to refer to the user's directory. + NEXT_ROOT is prepended as necessary to the returned values. + Some calls might return no directories! + The buffer that is passed in will be filled with a null-terminated string, possibly containing as many as PATH_MAX-1 characters. + + Typical usage: + + #include + #include + + char path[PATH_MAX]; + NSSearchPathEnumerationState state = NSStartSearchPathEnumeration(dir, domainMask); + while (state = NSGetNextSearchPathEnumeration(state, path)) { + // Handle path + } + + +*/ + +#ifndef __NS_SYSTEM_DIRECTORIES_H__ +#define __NS_SYSTEM_DIRECTORIES_H__ + +// 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) +} NSSearchPathDirectory; + +// Domains + +typedef enum { + NSUserDomainMask = 1, // user's home directory --- place to install user's personal items (~) + NSLocalDomainMask = 2, // local to the current machine --- place to install items available to everyone on this machine + NSNetworkDomainMask = 4, // publically available location in the local area network --- place to install items available on the network (/Network) + NSSystemDomainMask = 8, // provided by Apple + NSAllDomainsMask = 0x0ffff // all domains: all of the above and more, future items +} NSSearchPathDomainMask; + +typedef unsigned int NSSearchPathEnumerationState; + +/* Enumeration + Call NSStartSearchPathEnumeration() once, then call NSGetNextSearchPathEnumeration() one or more times with the returned state. + The return value of NSGetNextSearchPathEnumeration() should be used as the state next time around. + When NSGetNextSearchPathEnumeration() returns 0, you're done. +*/ +extern NSSearchPathEnumerationState NSStartSearchPathEnumeration(NSSearchPathDirectory dir, NSSearchPathDomainMask domainMask); + +extern NSSearchPathEnumerationState NSGetNextSearchPathEnumeration(NSSearchPathEnumerationState state, char *path); + +#endif /* __NS_SYSTEM_DIRECTORIES_H__ */ diff --git a/include/ar.h b/include/ar.h new file mode 100644 index 0000000..def1c43 --- /dev/null +++ b/include/ar.h @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2000 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@ + */ +/*- + * Copyright (c) 1991, 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 + * Hugh Smith at The University of Guelph. + * + * 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. + * + * @(#)ar.h 8.2 (Berkeley) 1/21/94 + */ + +#ifndef _AR_H_ +#define _AR_H_ + +/* Pre-4BSD archives had these magic numbers in them. */ +#define OARMAG1 0177555 +#define OARMAG2 0177545 + +#define ARMAG "!\n" /* ar "magic number" */ +#define SARMAG 8 /* strlen(ARMAG); */ + +#define AR_EFMT1 "#1/" /* extended format #1 */ + +struct ar_hdr { + char ar_name[16]; /* name */ + char ar_date[12]; /* modification time */ + char ar_uid[6]; /* user id */ + char ar_gid[6]; /* group id */ + char ar_mode[8]; /* octal file permissions */ + char ar_size[10]; /* size in bytes */ +#define ARFMAG "`\n" + char ar_fmag[2]; /* consistency check */ +}; + +#endif /* !_AR_H_ */ diff --git a/include/arpa/Makefile.inc b/include/arpa/Makefile.inc new file mode 100644 index 0000000..a4fb7b4 --- /dev/null +++ b/include/arpa/Makefile.inc @@ -0,0 +1,5 @@ +ARPA_INSTHDRS += ftp.h \ + nameser_compat.h \ + telnet.h \ + tftp.h +ARPA_INSTHDRS := ${ARPA_INSTHDRS:S/^/${.CURDIR}\/include\/arpa\//} diff --git a/include/arpa/ftp.h b/include/arpa/ftp.h new file mode 100644 index 0000000..90b425b --- /dev/null +++ b/include/arpa/ftp.h @@ -0,0 +1,130 @@ +/* + * Copyright (c) 2000 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@ + */ +/* + * Copyright (c) 1983, 1989, 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. + * + * @(#)ftp.h 8.1 (Berkeley) 6/2/93 + */ + +#ifndef _FTP_H_ +#define _FTP_H_ + +/* Definitions for FTP; see RFC-765. */ + +/* + * Reply codes. + */ +#define PRELIM 1 /* positive preliminary */ +#define COMPLETE 2 /* positive completion */ +#define CONTINUE 3 /* positive intermediate */ +#define TRANSIENT 4 /* transient negative completion */ +#define ERROR 5 /* permanent negative completion */ + +/* + * Type codes + */ +#define TYPE_A 1 /* ASCII */ +#define TYPE_E 2 /* EBCDIC */ +#define TYPE_I 3 /* image */ +#define TYPE_L 4 /* local byte size */ + +#ifdef FTP_NAMES +char *typenames[] = {"0", "ASCII", "EBCDIC", "Image", "Local" }; +#endif + +/* + * Form codes + */ +#define FORM_N 1 /* non-print */ +#define FORM_T 2 /* telnet format effectors */ +#define FORM_C 3 /* carriage control (ASA) */ +#ifdef FTP_NAMES +char *formnames[] = {"0", "Nonprint", "Telnet", "Carriage-control" }; +#endif + +/* + * Structure codes + */ +#define STRU_F 1 /* file (no record structure) */ +#define STRU_R 2 /* record structure */ +#define STRU_P 3 /* page structure */ +#ifdef FTP_NAMES +char *strunames[] = {"0", "File", "Record", "Page" }; +#endif + +/* + * Mode types + */ +#define MODE_S 1 /* stream */ +#define MODE_B 2 /* block */ +#define MODE_C 3 /* compressed */ +#ifdef FTP_NAMES +char *modenames[] = {"0", "Stream", "Block", "Compressed" }; +#endif + +/* + * Record Tokens + */ +#define REC_ESC '\377' /* Record-mode Escape */ +#define REC_EOR '\001' /* Record-mode End-of-Record */ +#define REC_EOF '\002' /* Record-mode End-of-File */ + +/* + * Block Header + */ +#define BLK_EOR 0x80 /* Block is End-of-Record */ +#define BLK_EOF 0x40 /* Block is End-of-File */ +#define BLK_ERRORS 0x20 /* Block is suspected of containing errors */ +#define BLK_RESTART 0x10 /* Block is Restart Marker */ + +#define BLK_BYTECOUNT 2 /* Bytes in this block */ + +#endif /* !_FTP_H_ */ diff --git a/include/arpa/nameser_compat.h b/include/arpa/nameser_compat.h new file mode 100644 index 0000000..33c96ac --- /dev/null +++ b/include/arpa/nameser_compat.h @@ -0,0 +1,194 @@ +/* Copyright (c) 1983, 1989 + * 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. + */ + +/* + * from nameser.h 8.1 (Berkeley) 6/2/93 + * From: Id: nameser_compat.h,v 8.9 1998/03/20 23:25:10 halley Exp + * $FreeBSD: src/include/arpa/nameser_compat.h,v 1.1.2.1 1999/08/29 14:39:01 peter Exp $ + */ + +#ifndef _ARPA_NAMESER_COMPAT_ +#define _ARPA_NAMESER_COMPAT_ + +#define __BIND 19950621 /* (DEAD) interface version stamp. */ + +#include + +#if !defined(BYTE_ORDER) || \ + (BYTE_ORDER != BIG_ENDIAN && BYTE_ORDER != LITTLE_ENDIAN && \ + BYTE_ORDER != PDP_ENDIAN) + /* you must determine what the correct bit order is for + * your compiler - the next line is an intentional error + * which will force your compiles to bomb until you fix + * the above macros. + */ + error "Undefined or invalid BYTE_ORDER"; +#endif + +/* + * Structure for query header. The order of the fields is machine- and + * compiler-dependent, depending on the byte/bit order and the layout + * of bit fields. We use bit fields only in int variables, as this + * is all ANSI requires. This requires a somewhat confusing rearrangement. + */ + +typedef struct { + unsigned id :16; /* query identification number */ +#if BYTE_ORDER == BIG_ENDIAN + /* fields in third byte */ + unsigned qr: 1; /* response flag */ + unsigned opcode: 4; /* purpose of message */ + unsigned aa: 1; /* authoritive answer */ + unsigned tc: 1; /* truncated message */ + unsigned rd: 1; /* recursion desired */ + /* fields in fourth byte */ + unsigned ra: 1; /* recursion available */ + unsigned unused :1; /* unused bits (MBZ as of 4.9.3a3) */ + unsigned ad: 1; /* authentic data from named */ + unsigned cd: 1; /* checking disabled by resolver */ + unsigned rcode :4; /* response code */ +#endif +#if BYTE_ORDER == LITTLE_ENDIAN || BYTE_ORDER == PDP_ENDIAN + /* fields in third byte */ + unsigned rd :1; /* recursion desired */ + unsigned tc :1; /* truncated message */ + unsigned aa :1; /* authoritive answer */ + unsigned opcode :4; /* purpose of message */ + unsigned qr :1; /* response flag */ + /* fields in fourth byte */ + unsigned rcode :4; /* response code */ + unsigned cd: 1; /* checking disabled by resolver */ + unsigned ad: 1; /* authentic data from named */ + unsigned unused :1; /* unused bits (MBZ as of 4.9.3a3) */ + unsigned ra :1; /* recursion available */ +#endif + /* remaining bytes */ + unsigned qdcount :16; /* number of question entries */ + unsigned ancount :16; /* number of answer entries */ + unsigned nscount :16; /* number of authority entries */ + unsigned arcount :16; /* number of resource entries */ +} HEADER; + +#define PACKETSZ NS_PACKETSZ +#define MAXDNAME NS_MAXDNAME +#define MAXCDNAME NS_MAXCDNAME +#define MAXLABEL NS_MAXLABEL +#define HFIXEDSZ NS_HFIXEDSZ +#define QFIXEDSZ NS_QFIXEDSZ +#define RRFIXEDSZ NS_RRFIXEDSZ +#define INT32SZ NS_INT32SZ +#define INT16SZ NS_INT16SZ +#define INADDRSZ NS_INADDRSZ +#define IN6ADDRSZ NS_IN6ADDRSZ +#define INDIR_MASK NS_CMPRSFLGS +#define NAMESERVER_PORT NS_DEFAULTPORT + +#define S_ZONE ns_s_zn +#define S_PREREQ ns_s_pr +#define S_UPDATE ns_s_ud +#define S_ADDT ns_s_ar + +#define QUERY ns_o_query +#define IQUERY ns_o_iquery +#define STATUS ns_o_status +#define NS_NOTIFY_OP ns_o_notify +#define NS_UPDATE_OP ns_o_update + +#define NOERROR ns_r_noerror +#define FORMERR ns_r_formerr +#define SERVFAIL ns_r_servfail +#define NXDOMAIN ns_r_nxdomain +#define NOTIMP ns_r_notimpl +#define REFUSED ns_r_refused +#define YXDOMAIN ns_r_yxdomain +#define YXRRSET ns_r_yxrrset +#define NXRRSET ns_r_nxrrset +#define NOTAUTH ns_r_notauth +#define NOTZONE ns_r_notzone + +#define DELETE ns_uop_delete +#define ADD ns_uop_add + +#define T_A ns_t_a +#define T_NS ns_t_ns +#define T_MD ns_t_md +#define T_MF ns_t_mf +#define T_CNAME ns_t_cname +#define T_SOA ns_t_soa +#define T_MB ns_t_mb +#define T_MG ns_t_mg +#define T_MR ns_t_mr +#define T_NULL ns_t_null +#define T_WKS ns_t_wks +#define T_PTR ns_t_ptr +#define T_HINFO ns_t_hinfo +#define T_MINFO ns_t_minfo +#define T_MX ns_t_mx +#define T_TXT ns_t_txt +#define T_RP ns_t_rp +#define T_AFSDB ns_t_afsdb +#define T_X25 ns_t_x25 +#define T_ISDN ns_t_isdn +#define T_RT ns_t_rt +#define T_NSAP ns_t_nsap +#define T_NSAP_PTR ns_t_nsap_ptr +#define T_SIG ns_t_sig +#define T_KEY ns_t_key +#define T_PX ns_t_px +#define T_GPOS ns_t_gpos +#define T_AAAA ns_t_aaaa +#define T_LOC ns_t_loc +#define T_NXT ns_t_nxt +#define T_EID ns_t_eid +#define T_NIMLOC ns_t_nimloc +#define T_SRV ns_t_srv +#define T_ATMA ns_t_atma +#define T_NAPTR ns_t_naptr +#define T_IXFR ns_t_ixfr +#define T_AXFR ns_t_axfr +#define T_MAILB ns_t_mailb +#define T_MAILA ns_t_maila +#define T_ANY ns_t_any + +#define C_IN ns_c_in +#define C_CHAOS ns_c_chaos +#define C_HS ns_c_hs +/* BIND_UPDATE */ +#define C_NONE ns_c_none +#define C_ANY ns_c_any + +#define GETSHORT NS_GET16 +#define GETLONG NS_GET32 +#define PUTSHORT NS_PUT16 +#define PUTLONG NS_PUT32 + +#endif /* _ARPA_NAMESER_COMPAT_ */ diff --git a/include/arpa/telnet.h b/include/arpa/telnet.h new file mode 100644 index 0000000..8126ce9 --- /dev/null +++ b/include/arpa/telnet.h @@ -0,0 +1,341 @@ +/* + * Copyright (c) 2000 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@ + */ +/* + * Copyright (c) 1983, 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. + * + * @(#)telnet.h 8.2 (Berkeley) 12/15/93 + */ + +#ifndef _TELNET_H_ +#define _TELNET_H_ + +/* + * Definitions for the TELNET protocol. + */ +#define IAC 255 /* interpret as command: */ +#define DONT 254 /* you are not to use option */ +#define DO 253 /* please, you use option */ +#define WONT 252 /* I won't use option */ +#define WILL 251 /* I will use option */ +#define SB 250 /* interpret as subnegotiation */ +#define GA 249 /* you may reverse the line */ +#define EL 248 /* erase the current line */ +#define EC 247 /* erase the current character */ +#define AYT 246 /* are you there */ +#define AO 245 /* abort output--but let prog finish */ +#define IP 244 /* interrupt process--permanently */ +#define BREAK 243 /* break */ +#define DM 242 /* data mark--for connect. cleaning */ +#define NOP 241 /* nop */ +#define SE 240 /* end sub negotiation */ +#define EOR 239 /* end of record (transparent mode) */ +#define ABORT 238 /* Abort process */ +#define SUSP 237 /* Suspend process */ +#define xEOF 236 /* End of file: EOF is already used... */ + +#define SYNCH 242 /* for telfunc calls */ + +#ifdef TELCMDS +char *telcmds[] = { + "EOF", "SUSP", "ABORT", "EOR", + "SE", "NOP", "DMARK", "BRK", "IP", "AO", "AYT", "EC", + "EL", "GA", "SB", "WILL", "WONT", "DO", "DONT", "IAC", 0, +}; +#else +extern char *telcmds[]; +#endif + +#define TELCMD_FIRST xEOF +#define TELCMD_LAST IAC +#define TELCMD_OK(x) ((unsigned int)(x) <= TELCMD_LAST && \ + (unsigned int)(x) >= TELCMD_FIRST) +#define TELCMD(x) telcmds[(x)-TELCMD_FIRST] + +/* telnet options */ +#define TELOPT_BINARY 0 /* 8-bit data path */ +#define TELOPT_ECHO 1 /* echo */ +#define TELOPT_RCP 2 /* prepare to reconnect */ +#define TELOPT_SGA 3 /* suppress go ahead */ +#define TELOPT_NAMS 4 /* approximate message size */ +#define TELOPT_STATUS 5 /* give status */ +#define TELOPT_TM 6 /* timing mark */ +#define TELOPT_RCTE 7 /* remote controlled transmission and echo */ +#define TELOPT_NAOL 8 /* negotiate about output line width */ +#define TELOPT_NAOP 9 /* negotiate about output page size */ +#define TELOPT_NAOCRD 10 /* negotiate about CR disposition */ +#define TELOPT_NAOHTS 11 /* negotiate about horizontal tabstops */ +#define TELOPT_NAOHTD 12 /* negotiate about horizontal tab disposition */ +#define TELOPT_NAOFFD 13 /* negotiate about formfeed disposition */ +#define TELOPT_NAOVTS 14 /* negotiate about vertical tab stops */ +#define TELOPT_NAOVTD 15 /* negotiate about vertical tab disposition */ +#define TELOPT_NAOLFD 16 /* negotiate about output LF disposition */ +#define TELOPT_XASCII 17 /* extended ascic character set */ +#define TELOPT_LOGOUT 18 /* force logout */ +#define TELOPT_BM 19 /* byte macro */ +#define TELOPT_DET 20 /* data entry terminal */ +#define TELOPT_SUPDUP 21 /* supdup protocol */ +#define TELOPT_SUPDUPOUTPUT 22 /* supdup output */ +#define TELOPT_SNDLOC 23 /* send location */ +#define TELOPT_TTYPE 24 /* terminal type */ +#define TELOPT_EOR 25 /* end or record */ +#define TELOPT_TUID 26 /* TACACS user identification */ +#define TELOPT_OUTMRK 27 /* output marking */ +#define TELOPT_TTYLOC 28 /* terminal location number */ +#define TELOPT_3270REGIME 29 /* 3270 regime */ +#define TELOPT_X3PAD 30 /* X.3 PAD */ +#define TELOPT_NAWS 31 /* window size */ +#define TELOPT_TSPEED 32 /* terminal speed */ +#define TELOPT_LFLOW 33 /* remote flow control */ +#define TELOPT_LINEMODE 34 /* Linemode option */ +#define TELOPT_XDISPLOC 35 /* X Display Location */ +#define TELOPT_OLD_ENVIRON 36 /* Old - Environment variables */ +#define TELOPT_AUTHENTICATION 37/* Authenticate */ +#define TELOPT_ENCRYPT 38 /* Encryption option */ +#define TELOPT_NEW_ENVIRON 39 /* New - Environment variables */ +#define TELOPT_EXOPL 255 /* extended-options-list */ + + +#define NTELOPTS (1+TELOPT_NEW_ENVIRON) +#ifdef TELOPTS +char *telopts[NTELOPTS+1] = { + "BINARY", "ECHO", "RCP", "SUPPRESS GO AHEAD", "NAME", + "STATUS", "TIMING MARK", "RCTE", "NAOL", "NAOP", + "NAOCRD", "NAOHTS", "NAOHTD", "NAOFFD", "NAOVTS", + "NAOVTD", "NAOLFD", "EXTEND ASCII", "LOGOUT", "BYTE MACRO", + "DATA ENTRY TERMINAL", "SUPDUP", "SUPDUP OUTPUT", + "SEND LOCATION", "TERMINAL TYPE", "END OF RECORD", + "TACACS UID", "OUTPUT MARKING", "TTYLOC", + "3270 REGIME", "X.3 PAD", "NAWS", "TSPEED", "LFLOW", + "LINEMODE", "XDISPLOC", "OLD-ENVIRON", "AUTHENTICATION", + "ENCRYPT", "NEW-ENVIRON", + 0, +}; +#define TELOPT_FIRST TELOPT_BINARY +#define TELOPT_LAST TELOPT_NEW_ENVIRON +#define TELOPT_OK(x) ((unsigned int)(x) <= TELOPT_LAST) +#define TELOPT(x) telopts[(x)-TELOPT_FIRST] +#endif + +/* sub-option qualifiers */ +#define TELQUAL_IS 0 /* option is... */ +#define TELQUAL_SEND 1 /* send option */ +#define TELQUAL_INFO 2 /* ENVIRON: informational version of IS */ +#define TELQUAL_REPLY 2 /* AUTHENTICATION: client version of IS */ +#define TELQUAL_NAME 3 /* AUTHENTICATION: client version of IS */ + +#define LFLOW_OFF 0 /* Disable remote flow control */ +#define LFLOW_ON 1 /* Enable remote flow control */ +#define LFLOW_RESTART_ANY 2 /* Restart output on any char */ +#define LFLOW_RESTART_XON 3 /* Restart output only on XON */ + +/* + * LINEMODE suboptions + */ + +#define LM_MODE 1 +#define LM_FORWARDMASK 2 +#define LM_SLC 3 + +#define MODE_EDIT 0x01 +#define MODE_TRAPSIG 0x02 +#define MODE_ACK 0x04 +#define MODE_SOFT_TAB 0x08 +#define MODE_LIT_ECHO 0x10 + +#define MODE_MASK 0x1f + +/* Not part of protocol, but needed to simplify things... */ +#define MODE_FLOW 0x0100 +#define MODE_ECHO 0x0200 +#define MODE_INBIN 0x0400 +#define MODE_OUTBIN 0x0800 +#define MODE_FORCE 0x1000 + +#define SLC_SYNCH 1 +#define SLC_BRK 2 +#define SLC_IP 3 +#define SLC_AO 4 +#define SLC_AYT 5 +#define SLC_EOR 6 +#define SLC_ABORT 7 +#define SLC_EOF 8 +#define SLC_SUSP 9 +#define SLC_EC 10 +#define SLC_EL 11 +#define SLC_EW 12 +#define SLC_RP 13 +#define SLC_LNEXT 14 +#define SLC_XON 15 +#define SLC_XOFF 16 +#define SLC_FORW1 17 +#define SLC_FORW2 18 + +#define NSLC 18 + +/* + * For backwards compatability, we define SLC_NAMES to be the + * list of names if SLC_NAMES is not defined. + */ +#define SLC_NAMELIST "0", "SYNCH", "BRK", "IP", "AO", "AYT", "EOR", \ + "ABORT", "EOF", "SUSP", "EC", "EL", "EW", "RP", \ + "LNEXT", "XON", "XOFF", "FORW1", "FORW2", 0, +#ifdef SLC_NAMES +char *slc_names[] = { + SLC_NAMELIST +}; +#else +extern char *slc_names[]; +#define SLC_NAMES SLC_NAMELIST +#endif + +#define SLC_NAME_OK(x) ((unsigned int)(x) <= NSLC) +#define SLC_NAME(x) slc_names[x] + +#define SLC_NOSUPPORT 0 +#define SLC_CANTCHANGE 1 +#define SLC_VARIABLE 2 +#define SLC_DEFAULT 3 +#define SLC_LEVELBITS 0x03 + +#define SLC_FUNC 0 +#define SLC_FLAGS 1 +#define SLC_VALUE 2 + +#define SLC_ACK 0x80 +#define SLC_FLUSHIN 0x40 +#define SLC_FLUSHOUT 0x20 + +#define OLD_ENV_VAR 1 +#define OLD_ENV_VALUE 0 +#define NEW_ENV_VAR 0 +#define NEW_ENV_VALUE 1 +#define ENV_ESC 2 +#define ENV_USERVAR 3 + +/* + * AUTHENTICATION suboptions + */ + +/* + * Who is authenticating who ... + */ +#define AUTH_WHO_CLIENT 0 /* Client authenticating server */ +#define AUTH_WHO_SERVER 1 /* Server authenticating client */ +#define AUTH_WHO_MASK 1 + +/* + * amount of authentication done + */ +#define AUTH_HOW_ONE_WAY 0 +#define AUTH_HOW_MUTUAL 2 +#define AUTH_HOW_MASK 2 + +#define AUTHTYPE_NULL 0 +#define AUTHTYPE_KERBEROS_V4 1 +#define AUTHTYPE_KERBEROS_V5 2 +#define AUTHTYPE_SPX 3 +#define AUTHTYPE_MINK 4 +#define AUTHTYPE_CNT 5 + +#define AUTHTYPE_TEST 99 + +#ifdef AUTH_NAMES +char *authtype_names[] = { + "NULL", "KERBEROS_V4", "KERBEROS_V5", "SPX", "MINK", 0, +}; +#else +extern char *authtype_names[]; +#endif + +#define AUTHTYPE_NAME_OK(x) ((unsigned int)(x) < AUTHTYPE_CNT) +#define AUTHTYPE_NAME(x) authtype_names[x] + +/* + * ENCRYPTion suboptions + */ +#define ENCRYPT_IS 0 /* I pick encryption type ... */ +#define ENCRYPT_SUPPORT 1 /* I support encryption types ... */ +#define ENCRYPT_REPLY 2 /* Initial setup response */ +#define ENCRYPT_START 3 /* Am starting to send encrypted */ +#define ENCRYPT_END 4 /* Am ending encrypted */ +#define ENCRYPT_REQSTART 5 /* Request you start encrypting */ +#define ENCRYPT_REQEND 6 /* Request you send encrypting */ +#define ENCRYPT_ENC_KEYID 7 +#define ENCRYPT_DEC_KEYID 8 +#define ENCRYPT_CNT 9 + +#define ENCTYPE_ANY 0 +#define ENCTYPE_DES_CFB64 1 +#define ENCTYPE_DES_OFB64 2 +#define ENCTYPE_CNT 3 + +#ifdef ENCRYPT_NAMES +char *encrypt_names[] = { + "IS", "SUPPORT", "REPLY", "START", "END", + "REQUEST-START", "REQUEST-END", "ENC-KEYID", "DEC-KEYID", + 0, +}; +char *enctype_names[] = { + "ANY", "DES_CFB64", "DES_OFB64", 0, +}; +#else +extern char *encrypt_names[]; +extern char *enctype_names[]; +#endif + + +#define ENCRYPT_NAME_OK(x) ((unsigned int)(x) < ENCRYPT_CNT) +#define ENCRYPT_NAME(x) encrypt_names[x] + +#define ENCTYPE_NAME_OK(x) ((unsigned int)(x) < ENCTYPE_CNT) +#define ENCTYPE_NAME(x) enctype_names[x] + +#endif /* !_TELNET_H_ */ diff --git a/include/arpa/tftp.h b/include/arpa/tftp.h new file mode 100644 index 0000000..1e7324f --- /dev/null +++ b/include/arpa/tftp.h @@ -0,0 +1,101 @@ +/* + * Copyright (c) 2000 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@ + */ +/* + * Copyright (c) 1983, 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. + * + * @(#)tftp.h 8.1 (Berkeley) 6/2/93 + */ + +#ifndef _TFTP_H_ +#define _TFTP_H_ + +/* + * Trivial File Transfer Protocol (IEN-133) + */ +#define SEGSIZE 512 /* data segment size */ + +/* + * Packet types. + */ +#define RRQ 01 /* read request */ +#define WRQ 02 /* write request */ +#define DATA 03 /* data packet */ +#define ACK 04 /* acknowledgement */ +#define ERROR 05 /* error code */ + +struct tftphdr { + short th_opcode; /* packet type */ + union { + short tu_block; /* block # */ + short tu_code; /* error code */ + char tu_stuff[1]; /* request packet stuff */ + } th_u; + char th_data[1]; /* data or error string */ +}; + +#define th_block th_u.tu_block +#define th_code th_u.tu_code +#define th_stuff th_u.tu_stuff +#define th_msg th_data + +/* + * Error codes. + */ +#define EUNDEF 0 /* not defined */ +#define ENOTFOUND 1 /* file not found */ +#define EACCESS 2 /* access violation */ +#define ENOSPACE 3 /* disk full or allocation exceeded */ +#define EBADOP 4 /* illegal TFTP operation */ +#define EBADID 5 /* unknown transfer ID */ +#define EEXISTS 6 /* file already exists */ +#define ENOUSER 7 /* no such user */ + +#endif /* !_TFTP_H_ */ diff --git a/include/asm.h b/include/asm.h new file mode 100644 index 0000000..d21a6b5 --- /dev/null +++ b/include/asm.h @@ -0,0 +1,415 @@ +/* + * @OSF_COPYRIGHT@ + */ + +#ifndef _PPC_ASM_H_ +#define _PPC_ASM_H_ + +#ifdef __ELF__ +#define __NO_UNDERSCORES__ 1 +#define __ASMNL__ ; +#else +#define __ASMNL__ @ +#endif + +#ifdef ASSEMBLER + +#ifdef __ELF__ +#define r0 0 +#define r1 1 +#define r2 2 +#define r3 3 +#define r4 4 +#define r5 5 +#define r6 6 +#define r7 7 +#define r8 8 +#define r9 9 +#define r10 10 +#define r11 11 +#define r12 12 +#define r13 13 +#define r14 14 +#define r15 15 +#define r16 16 +#define r17 17 +#define r18 18 +#define r19 19 +#define r20 20 +#define r21 21 +#define r22 22 +#define r23 23 +#define r24 24 +#define r25 25 +#define r26 26 +#define r27 27 +#define r28 28 +#define r29 29 +#define r30 30 +#define r31 31 + +#define f0 0 +#define f1 1 +#define f2 2 +#define f3 3 +#define f4 4 +#define f5 5 +#define f6 6 +#define f7 7 +#define f8 8 +#define f9 9 +#define f10 10 +#define f11 11 +#define f12 12 +#define f13 13 +#define f14 14 +#define f15 15 +#define f16 16 +#define f17 17 +#define f18 18 +#define f19 19 +#define f20 20 +#define f21 21 +#define f22 22 +#define f23 23 +#define f24 24 +#define f25 25 +#define f26 26 +#define f27 27 +#define f28 28 +#define f29 29 +#define f30 30 +#define f31 31 + +#define sr0 0 +#define sr1 1 +#define sr2 2 +#define sr3 3 +#define sr4 4 +#define sr5 5 +#define sr6 6 +#define sr7 7 +#define sr8 8 +#define sr9 9 +#define sr10 10 +#define sr11 11 +#define sr12 12 +#define sr13 13 +#define sr14 14 +#define sr15 15 +#define sr16 16 +#define sr17 17 +#define sr18 18 +#define sr19 19 +#define sr20 20 +#define sr21 21 +#define sr22 22 +#define sr23 23 +#define sr24 24 +#define sr25 25 +#define sr26 26 +#define sr27 27 +#define sr28 28 +#define sr29 29 +#define sr30 30 +#define sr31 31 +#endif + +#define ARG0 r3 +#define ARG1 r4 +#define ARG2 r5 +#define ARG3 r6 +#define ARG4 r7 +#define ARG5 r8 +#define ARG6 r9 +#define ARG7 r10 + +#define tmp0 r0 /* Temporary GPR remapping (603e specific) */ +#define tmp1 r1 +#define tmp2 r2 +#define tmp3 r3 + +/* SPR registers */ + +#define dmiss 976 /* ea that missed */ +#define dcmp 977 /* compare value for the va that missed */ +#define hash1 978 /* pointer to first hash pteg */ +#define hash2 979 /* pointer to second hash pteg */ +#define imiss 980 /* ea that missed */ +#define icmp 981 /* compare value for the va that missed */ +#define rpa 982 /* required physical address register */ + +#define iabr 1010 /* instruction address breakpoint register */ +#define pir 1023 /* Processor ID Register */ + +/* MQ register on the 601 */ +#define mq 0 /* spr number for mq register on 601 */ + +#define IBAT0U 528 +#define IBAT0L 529 +#define IBAT1U 530 +#define IBAT1L 531 +#define IBAT2U 532 +#define IBAT2L 533 +#define IBAT3U 534 +#define IBAT3L 535 +#define ibat0u 528 +#define ibat0l 529 +#define ibat1u 530 +#define ibat1l 531 +#define ibat2u 532 +#define ibat2l 533 +#define ibat3u 534 +#define ibat3l 535 + +#define DBAT0U 536 +#define DBAT0L 537 +#define DBAT1U 538 +#define DBAT1L 539 +#define DBAT2U 540 +#define DBAT2L 541 +#define DBAT3U 542 +#define DBAT3L 543 +#define dbat0u 536 +#define dbat0l 537 +#define dbat1u 538 +#define dbat1l 539 +#define dbat2u 540 +#define dbat2l 541 +#define dbat3u 542 +#define dbat3l 543 + +#define HID0 1008 +#define hid0 1008 +#define HID1 1009 +#define hid1 1009 +#define SDR1 25 +#define sprg0 272 +#define sprg1 273 +#define sprg2 274 +#define sprg3 275 +#define ppcDAR 19 +#define ppcdar 19 +#define srr0 26 +#define srr1 27 + +#define CR0 0 +#define CR1 1 +#define CR2 2 +#define CR3 3 +#define CR4 4 +#define CR5 5 +#define CR6 6 +#define CR7 7 + +#ifdef __ELF__ +#define cr0 0 +#define cr1 1 +#define cr2 2 +#define cr3 3 +#define cr4 4 +#define cr5 5 +#define cr6 6 +#define cr7 7 +#endif + +#define cr0_lt 0 +#define cr0_gt 1 +#define cr0_eq 2 +#define cr0_so 3 +#define cr0_un 3 + +/* + * Macros to access high and low word values of an address + */ + +#ifndef __ELF__ +#define HIGH_CADDR(x) ha16(x) +#define HIGH_ADDR(x) hi16(x) +#define LOW_ADDR(x) lo16(x) +#else +#define HIGH_CADDR(x) x@ha +#define HIGH_ADDR(x) x@h +#define LOW_ADDR(x) x@l +#endif /* __ELF__ */ + +#endif /* ASSEMBLER */ + +/* Tags are placed before Immediately Following Code (IFC) for the debugger + * to be able to deduce where to find various registers when backtracing + * + * We only define the values as we use them, see SVR4 ABI PowerPc Supplement + * for more details (defined in ELF spec). + */ + +#define TAG_NO_FRAME_USED 0x00000000 + +/* (should use genassym to get these offsets) */ + +#define FM_BACKPTR 0 +/* TODO NMGS FM_SIZE 8 is ok according to EABI specs, but gcc uses 16 */ +#ifdef __ELF__ +#define FM_LR_SAVE 4 /* gcc 2.7.1 is now following eabi spec correctly */ +#define FM_SIZE 16 /* minimum frame contents, backptr and LR save */ +#define FM_ARG0 8 +#else +#define FM_CR_SAVE 4 +#define FM_LR_SAVE 8 /* Rhapsody iS NOT following the ABI at the moment.. */ +#define FM_SIZE 72 /* minimum frame contents, backptr and LR save */ +#define FM_ARG0 56 +#endif + +#define FM_ELF_ARG0 8 +#define FM_MACHO_ARG0 56 +#define MACHO_SYSCALL_BEGIN 0x2000 +#define PK_SYSCALL_BEGIN 0x7000 + + +/* redzone is the area under the stack pointer which must be preserved + * when taking a trap, interrupt etc. This is no longer needed as gcc + * (2.7.2 and above) now follows ELF spec correctly and never loads/stores + * below the frame pointer + */ +#ifdef __ELF__ +#define FM_REDZONE 0 /* was ((32-14+1)*4) */ +#else +#define FM_REDZONE 224 /* is ((32-14+1)*4) */ +#endif + +#define COPYIN_ARG0_OFFSET FM_ARG0 + +#ifdef MACH_KERNEL_BUILD +#include +#else /* MACH_KERNEL */ +#define MACH_KDB 0 +#endif /* MACH_KERNEL */ + +#define BREAKPOINT_TRAP twge r2,r2 + +/* There is another definition of ALIGN for .c sources */ +#ifndef __LANGUAGE_ASSEMBLY +#define ALIGN 2 +#endif /* __LANGUAGE_ASSEMBLY */ + +#ifndef FALIGN +#define FALIGN 2 /* Align functions on words for now. Cachelines is better */ +#endif + +#define LB(x,n) n +#if __STDC__ +#ifndef __NO_UNDERSCORES__ +#define LCL(x) L ## x +#define EXT(x) _ ## x +#define LEXT(x) _ ## x ## : +#else +#define LCL(x) .L ## x +#define EXT(x) x +#define LEXT(x) x ## : +#endif +#define LBc(x,n) n ## : +#define LBb(x,n) n ## b +#define LBf(x,n) n ## f +#else /* __STDC__ */ +#ifndef __NO_UNDERSCORES__ +#define LCL(x) L/**/x +#define EXT(x) _/**/x +#define LEXT(x) _/**/x/**/: +#else /* __NO_UNDERSCORES__ */ +#define LCL(x) .L/**/x +#define EXT(x) x +#define LEXT(x) x/**/: +#endif /* __NO_UNDERSCORES__ */ +#define LBc(x,n) n/**/: +#define LBb(x,n) n/**/b +#define LBf(x,n) n/**/f +#endif /* __STDC__ */ + +#define String .asciz +#define Value .word +#define Times(a,b) (a*b) +#define Divide(a,b) (a/b) + +#define data16 .byte 0x66 +#define addr16 .byte 0x67 + +#if !GPROF +#define MCOUNT + +#elif defined(__SHARED__) +#define MCOUNT ; .data;\ + .align ALIGN;\ + LBc(x, 8) .long 0;\ + .text;\ + Gpush;\ + Gload;\ + leal Gotoff(LBb(x,8)),%edx;\ + Egaddr(%eax,_mcount_ptr);\ + Gpop;\ + call *(%eax); + +#else /* !GPROF, !__SHARED__ */ +#define MCOUNT ; .data;\ + .align ALIGN;\ + LBc(x, 8) .long 0;\ + .text;\ + movl $LBb(x,8),%edx;\ + call *EXT(_mcount_ptr); + +#endif /* GPROF */ + +#ifdef __ELF__ +#define ELF_FUNC(x) .type x,@function +#define ELF_DATA(x) .type x,@object +#define ELF_SIZE(x,s) .size x,s +#else +#define ELF_FUNC(x) +#define ELF_DATA(x) +#define ELF_SIZE(x,s) +#endif + +#ifdef __ELF__ +#define Entry(x,tag) .globl EXT(x); ELF_FUNC(EXT(x)); .long tag;.align FALIGN; LEXT(x) +#define ENTRY(x,tag) Entry(x,tag) MCOUNT +#define ENTRY2(x,y,tag) .globl EXT(x); .globl EXT(y); \ + ELF_FUNC(EXT(x)); ELF_FUNC(EXT(y)); \ + .align FALIGN; LEXT(x); LEXT(y) \ + MCOUNT +#if __STDC__ +#define ASENTRY(x) .globl x; .align FALIGN; x ## : ELF_FUNC(x) MCOUNT +#else +#define ASENTRY(x) .globl x; .align FALIGN; x: ELF_FUNC(x) MCOUNT +#endif /* __STDC__ */ +#define DATA(x) .globl EXT(x); ELF_DATA(EXT(x)); .align ALIGN; LEXT(x) + +#else /* __ELF__ */ + +#define Entry(x,tag) .text@.align FALIGN@ .globl EXT(x)@ LEXT(x) +#define ENTRY(x,tag) Entry(x,tag)@MCOUNT +#define ENTRY2(x,y,tag) .text@ .align FALIGN@ .globl EXT(x)@ .globl EXT(y)@ \ + LEXT(x)@ LEXT(y) @\ + MCOUNT +#if __STDC__ +#define ASENTRY(x) .globl x @ .align FALIGN; x ## @ MCOUNT +#else +#define ASENTRY(x) .globl x @ .align FALIGN; x @ MCOUNT +#endif /* __STDC__ */ +#define DATA(x) .globl EXT(x) @ .align ALIGN @ LEXT(x) +#endif + + + +#define End(x) ELF_SIZE(x,.-x) +#define END(x) End(EXT(x)) +#define ENDDATA(x) END(x) +#define Enddata(x) End(x) + +/* These defines are here for .c files that wish to reference global symbols + * within __asm__ statements. + */ +#ifndef __NO_UNDERSCORES__ +#define CC_SYM_PREFIX "_" +#else +#define CC_SYM_PREFIX "" +#endif /* __NO_UNDERSCORES__ */ + +#endif /* _PPC_ASM_H_ */ diff --git a/include/authentication.h b/include/authentication.h new file mode 100644 index 0000000..4fcd000 --- /dev/null +++ b/include/authentication.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2000 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 __AUTHENTICATION_H__ +#define __AUTHENTICATION_H__ + +extern char *groupNameForTask(int taskNum); +extern int isAuthenticatedAsAdministrator(void); +extern int isAuthenticatedAsAdministratorForTask(int taskNum); +extern int isAuthenticatedAsRoot(void); + +#endif /* __AUTHENTICATION_H__ */ diff --git a/include/bitstring.h b/include/bitstring.h new file mode 100644 index 0000000..d275de0 --- /dev/null +++ b/include/bitstring.h @@ -0,0 +1,164 @@ +/* + * Copyright (c) 2000 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@ + */ +/* + * Copyright (c) 1989, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Paul Vixie. + * + * 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. + * + * @(#)bitstring.h 8.1 (Berkeley) 7/19/93 + */ + +#ifndef _BITSTRING_H_ +#define _BITSTRING_H_ + +typedef unsigned char bitstr_t; + +/* internal macros */ + /* byte of the bitstring bit is in */ +#define _bit_byte(bit) \ + ((bit) >> 3) + + /* mask for the bit within its byte */ +#define _bit_mask(bit) \ + (1 << ((bit)&0x7)) + +/* external macros */ + /* bytes in a bitstring of nbits bits */ +#define bitstr_size(nbits) \ + ((((nbits) - 1) >> 3) + 1) + + /* allocate a bitstring */ +#define bit_alloc(nbits) \ + (bitstr_t *)calloc(1, \ + (unsigned int)bitstr_size(nbits) * sizeof(bitstr_t)) + + /* allocate a bitstring on the stack */ +#define bit_decl(name, nbits) \ + (name)[bitstr_size(nbits)] + + /* is bit N of bitstring name set? */ +#define bit_test(name, bit) \ + ((name)[_bit_byte(bit)] & _bit_mask(bit)) + + /* set bit N of bitstring name */ +#define bit_set(name, bit) \ + (name)[_bit_byte(bit)] |= _bit_mask(bit) + + /* clear bit N of bitstring name */ +#define bit_clear(name, bit) \ + (name)[_bit_byte(bit)] &= ~_bit_mask(bit) + + /* clear bits start ... stop in bitstring */ +#define bit_nclear(name, start, stop) { \ + register bitstr_t *_name = name; \ + register int _start = start, _stop = stop; \ + register int _startbyte = _bit_byte(_start); \ + register int _stopbyte = _bit_byte(_stop); \ + if (_startbyte == _stopbyte) { \ + _name[_startbyte] &= ((0xff >> (8 - (_start&0x7))) | \ + (0xff << ((_stop&0x7) + 1))); \ + } else { \ + _name[_startbyte] &= 0xff >> (8 - (_start&0x7)); \ + while (++_startbyte < _stopbyte) \ + _name[_startbyte] = 0; \ + _name[_stopbyte] &= 0xff << ((_stop&0x7) + 1); \ + } \ +} + + /* set bits start ... stop in bitstring */ +#define bit_nset(name, start, stop) { \ + register bitstr_t *_name = name; \ + register int _start = start, _stop = stop; \ + register int _startbyte = _bit_byte(_start); \ + register int _stopbyte = _bit_byte(_stop); \ + if (_startbyte == _stopbyte) { \ + _name[_startbyte] |= ((0xff << (_start&0x7)) & \ + (0xff >> (7 - (_stop&0x7)))); \ + } else { \ + _name[_startbyte] |= 0xff << ((_start)&0x7); \ + while (++_startbyte < _stopbyte) \ + _name[_startbyte] = 0xff; \ + _name[_stopbyte] |= 0xff >> (7 - (_stop&0x7)); \ + } \ +} + + /* find first bit clear in name */ +#define bit_ffc(name, nbits, value) { \ + register bitstr_t *_name = name; \ + register int _byte, _nbits = nbits; \ + register int _stopbyte = _bit_byte(_nbits), _value = -1; \ + for (_byte = 0; _byte < _stopbyte; ++_byte) \ + if (_name[_byte] != 0xff) { \ + _value = _byte << 3; \ + for (_stopbyte = _name[_byte]; (_stopbyte&0x1); \ + ++_value, _stopbyte >>= 1); \ + break; \ + } \ + *(value) = _value; \ +} + + /* find first bit set in name */ +#define bit_ffs(name, nbits, value) { \ + register bitstr_t *_name = name; \ + register int _byte, _nbits = nbits; \ + register int _stopbyte = _bit_byte(_nbits), _value = -1; \ + for (_byte = 0; _byte < _stopbyte; ++_byte) \ + if (_name[_byte]) { \ + _value = _byte << 3; \ + for (_stopbyte = _name[_byte]; !(_stopbyte&0x1); \ + ++_value, _stopbyte >>= 1); \ + break; \ + } \ + *(value) = _value; \ +} + +#endif /* !_BITSTRING_H_ */ diff --git a/include/c.h b/include/c.h new file mode 100644 index 0000000..905d271 --- /dev/null +++ b/include/c.h @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2000 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@ + */ +/* + * Standard C macros + * + ********************************************************************** + * HISTORY + * 02-Feb-86 Glenn Marcy (gm0w) at Carnegie-Mellon University + * Added check to allow multiple or recursive inclusion of this + * file. Added bool enum from machine/types.h for regular users + * that want a real boolean type. + * + * 29-Dec-85 Glenn Marcy (gm0w) at Carnegie-Mellon University + * Also change spacing of MAX and MIN to coincide with that of + * sys/param.h. + * + * 19-Nov-85 Glenn Marcy (gm0w) at Carnegie-Mellon University + * Changed the number of tabs between TRUE, FALSE and their + * respective values to match those in sys/types.h. + * + * 17-Dec-84 Glenn Marcy (gm0w) at Carnegie-Mellon University + * Only define TRUE and FALSE if not defined. Added caseE macro + * for using enumerated types in switch statements. + * + * 23-Apr-81 Mike Accetta (mja) at Carnegie-Mellon University + * Added "sizeofS" and "sizeofA" macros which expand to the size + * of a string constant and array respectively. + * + ********************************************************************** + */ + +#ifndef _C_INCLUDE_ +#define _C_INCLUDE_ + +#ifndef ABS +#define ABS(x) ((x)>=0?(x):-(x)) +#endif /* ABS */ +#ifndef MIN +#define MIN(a,b) (((a)<(b))?(a):(b)) +#endif /* MIN */ +#ifndef MAX +#define MAX(a,b) (((a)>(b))?(a):(b)) +#endif /* MAX */ + +#ifndef FALSE +#define FALSE 0 +#endif /* FALSE */ +#ifndef TRUE +#define TRUE 1 +#endif /* TRUE */ + +#define CERROR (-1) + +#ifndef bool +typedef enum { false = 0, true = 1 } bool; +#endif /* bool */ + +#define sizeofS(string) (sizeof(string) - 1) +#define sizeofA(array) (sizeof(array)/sizeof(array[0])) + +#define caseE(enum_type) case (int)(enum_type) + +#endif /* _C_INCLUDE_ */ diff --git a/include/crt_externs.h b/include/crt_externs.h new file mode 100644 index 0000000..94fc666 --- /dev/null +++ b/include/crt_externs.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ + +/* +** Prototypes for the functions to get environment information in +** the world of dynamic libraries. Lifted from .c file of same name. +** Fri Jun 23 12:56:47 PDT 1995 +** AOF (afreier@next.com) +*/ + +extern char ***_NSGetArgv(void); +extern int *_NSGetArgc(void); +extern char ***_NSGetEnviron(void); +extern char **_NSGetProgname(void); +extern struct mach_header *_NSGetMachExecuteHeader(void); diff --git a/include/ctype.h b/include/ctype.h new file mode 100644 index 0000000..244ae10 --- /dev/null +++ b/include/ctype.h @@ -0,0 +1,225 @@ +/* + * Copyright (c) 2000 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@ + */ +/* + * 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. + * + * @(#)ctype.h 8.4 (Berkeley) 1/21/94 + */ + +#ifndef _CTYPE_H_ +#define _CTYPE_H_ + +#include + +#define _A 0x00000100L /* Alpha */ +#define _C 0x00000200L /* Control */ +#define _D 0x00000400L /* Digit */ +#define _G 0x00000800L /* Graph */ +#define _L 0x00001000L /* Lower */ +#define _P 0x00002000L /* Punct */ +#define _S 0x00004000L /* Space */ +#define _U 0x00008000L /* Upper */ +#define _X 0x00010000L /* X digit */ +#define _B 0x00020000L /* Blank */ +#define _R 0x00040000L /* Print */ +#define _I 0x00080000L /* Ideogram */ +#define _T 0x00100000L /* Special */ +#define _Q 0x00200000L /* Phonogram */ + +#define _CTYPE_A _A +#define _CTYPE_C _C +#define _CTYPE_D _D +#define _CTYPE_G _G +#define _CTYPE_L _L +#define _CTYPE_P _P +#define _CTYPE_S _S +#define _CTYPE_U _U +#define _CTYPE_X _X +#define _CTYPE_B _B +#define _CTYPE_R _R +#define _CTYPE_I _I +#define _CTYPE_T _T +#define _CTYPE_Q _Q + +__BEGIN_DECLS +int isalnum __P((int)); +int isalpha __P((int)); +int iscntrl __P((int)); +int isdigit __P((int)); +int isgraph __P((int)); +int islower __P((int)); +int isprint __P((int)); +int ispunct __P((int)); +int isspace __P((int)); +int isupper __P((int)); +int isxdigit __P((int)); +int tolower __P((int)); +int toupper __P((int)); + +#if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE) +int digittoint __P((int)); +int isascii __P((int)); +int isblank __P((int)); +int ishexnumber __P((int)); +int isideogram __P((int)); +int isnumber __P((int)); +int isphonogram __P((int)); +int isrune __P((int)); +int isspecial __P((int)); +int toascii __P((int)); +#endif +__END_DECLS + + +#define isalnum(c) __istype((c), (_A|_D)) +#define isalpha(c) __istype((c), _A) +#define iscntrl(c) __istype((c), _C) +#define isdigit(c) __isctype((c), _D) /* ANSI -- locale independent */ +#define isgraph(c) __istype((c), _G) +#define islower(c) __istype((c), _L) +#define isprint(c) __istype((c), _R) +#define ispunct(c) __istype((c), _P) +#define isspace(c) __istype((c), _S) +#define isupper(c) __istype((c), _U) +#define isxdigit(c) __isctype((c), _X) /* ANSI -- locale independent */ +#define tolower(c) __tolower(c) +#define toupper(c) __toupper(c) + +#if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE) +#define digittoint(c) __maskrune((c), 0xFF) +#define isascii(c) ((c & ~0x7F) == 0) +#define isblank(c) __istype((c), _B) +#define ishexnumber(c) __istype((c), _X) +#define isideogram(c) __istype((c), _I) +#define isnumber(c) __istype((c), _D) +#define isphonogram(c) __istype((c), _T) +#define isrune(c) __istype((c), 0xFFFFFF00L) +#define isspecial(c) __istype((c), _Q) +#define toascii(c) ((c) & 0x7F) +#endif + +/* See comments in about _BSD_RUNE_T_. */ +__BEGIN_DECLS +unsigned long ___runetype __P((_BSD_CT_RUNE_T_)); +_BSD_CT_RUNE_T_ ___tolower __P((_BSD_CT_RUNE_T_)); +_BSD_CT_RUNE_T_ ___toupper __P((_BSD_CT_RUNE_T_)); +__END_DECLS + +/* + * _EXTERNALIZE_CTYPE_INLINES_ is defined in locale/nomacros.c to tell us + * to generate code for extern versions of all our inline functions. + */ +#ifdef _EXTERNALIZE_CTYPE_INLINES_ +#define _USE_CTYPE_INLINE_ +#define static +#define __inline +#endif + +/* + * 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)) + +static __inline int +__maskrune(_BSD_CT_RUNE_T_ _c, unsigned long _f) +{ + return ((_c < 0 || _c >= _CACHED_RUNES) ? ___runetype(_c) : + _CurrentRuneLocale->runetype[_c]) & _f; +} + +static __inline int +__istype(_BSD_CT_RUNE_T_ c, unsigned long f) +{ + return !!(__maskrune(c, f)); +} + +static __inline _BSD_CT_RUNE_T_ +__isctype(_BSD_CT_RUNE_T_ _c, unsigned long _f) +{ + return (_c < 0 || _c >= _CACHED_RUNES) ? 0 : + !!(_DefaultRuneLocale.runetype[_c] & _f); +} + +static __inline _BSD_CT_RUNE_T_ +__toupper(_BSD_CT_RUNE_T_ _c) +{ + return (_c < 0 || _c >= _CACHED_RUNES) ? ___toupper(_c) : + _CurrentRuneLocale->mapupper[_c]; +} + +static __inline _BSD_CT_RUNE_T_ +__tolower(_BSD_CT_RUNE_T_ _c) +{ + return (_c < 0 || _c >= _CACHED_RUNES) ? ___tolower(_c) : + _CurrentRuneLocale->maplower[_c]; +} + +#else /* not using inlines */ + +__BEGIN_DECLS +int __maskrune __P((_BSD_CT_RUNE_T_, unsigned long)); +int __istype __P((_BSD_CT_RUNE_T_, unsigned long)); +int __isctype __P((_BSD_CT_RUNE_T_, unsigned long)); +_BSD_CT_RUNE_T_ __toupper __P((_BSD_CT_RUNE_T_)); +_BSD_CT_RUNE_T_ __tolower __P((_BSD_CT_RUNE_T_)); +__END_DECLS +#endif /* using inlines */ + +#endif /* !_CTYPE_H_ */ diff --git a/include/db.h b/include/db.h new file mode 100644 index 0000000..1e4cce8 --- /dev/null +++ b/include/db.h @@ -0,0 +1,239 @@ +/* + * Copyright (c) 2000 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@ + */ +/*- + * Copyright (c) 1990, 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. + * + * @(#)db.h 8.4 (Berkeley) 2/21/94 + */ + +#ifndef _DB_H_ +#define _DB_H_ + +#include +#include + +#include + +#define RET_ERROR -1 /* Return values. */ +#define RET_SUCCESS 0 +#define RET_SPECIAL 1 + +#define MAX_PAGE_NUMBER 0xffffffff /* >= # of pages in a file */ +typedef u_int32_t pgno_t; +#define MAX_PAGE_OFFSET 65535 /* >= # of bytes in a page */ +typedef u_int16_t indx_t; +#define MAX_REC_NUMBER 0xffffffff /* >= # of records in a tree */ +typedef u_int32_t recno_t; + +/* Key/data structure -- a Data-Base Thang. */ +typedef struct { + void *data; /* data */ + size_t size; /* data length */ +} DBT; + +/* Routine flags. */ +#define R_CURSOR 1 /* del, put, seq */ +#define __R_UNUSED 2 /* UNUSED */ +#define R_FIRST 3 /* seq */ +#define R_IAFTER 4 /* put (RECNO) */ +#define R_IBEFORE 5 /* put (RECNO) */ +#define R_LAST 6 /* seq (BTREE, RECNO) */ +#define R_NEXT 7 /* seq */ +#define R_NOOVERWRITE 8 /* put */ +#define R_PREV 9 /* seq (BTREE, RECNO) */ +#define R_SETCURSOR 10 /* put (RECNO) */ +#define R_RECNOSYNC 11 /* sync (RECNO) */ + +typedef enum { DB_BTREE, DB_HASH, DB_RECNO } DBTYPE; + +/* + * !!! + * The following flags are included in the dbopen(3) call as part of the + * open(2) flags. In order to avoid conflicts with the open flags, start + * at the top of the 16 or 32-bit number space and work our way down. If + * the open flags were significantly expanded in the future, it could be + * a problem. Wish I'd left another flags word in the dbopen call. + * + * !!! + * None of this stuff is implemented yet. The only reason that it's here + * is so that the access methods can skip copying the key/data pair when + * the DB_LOCK flag isn't set. + */ +#if UINT_MAX > 65535 +#define DB_LOCK 0x20000000 /* Do locking. */ +#define DB_SHMEM 0x40000000 /* Use shared memory. */ +#define DB_TXN 0x80000000 /* Do transactions. */ +#else +#define DB_LOCK 0x2000 /* Do locking. */ +#define DB_SHMEM 0x4000 /* Use shared memory. */ +#define DB_TXN 0x8000 /* Do transactions. */ +#endif + +/* Access method description structure. */ +typedef struct __db { + DBTYPE type; /* Underlying db type. */ + int (*close) __P((struct __db *)); + int (*del) __P((const struct __db *, const DBT *, u_int)); + int (*get) __P((const struct __db *, const DBT *, DBT *, u_int)); + int (*put) __P((const struct __db *, DBT *, const DBT *, u_int)); + int (*seq) __P((const struct __db *, DBT *, DBT *, u_int)); + int (*sync) __P((const struct __db *, u_int)); + void *internal; /* Access method private. */ + int (*fd) __P((const struct __db *)); +} DB; + +#define BTREEMAGIC 0x053162 +#define BTREEVERSION 3 + +/* 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 */ + __P((const DBT *, const DBT *)); + size_t (*prefix) /* prefix function */ + __P((const DBT *, const DBT *)); + int lorder; /* byte order */ +} BTREEINFO; + +#define HASHMAGIC 0x061561 +#define HASHVERSION 2 + +/* 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 */ + u_int32_t /* hash function */ + (*hash) __P((const void *, size_t)); + int lorder; /* byte order */ +} HASHINFO; + +/* Structure used to pass parameters to the record routines. */ +typedef struct { +#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 */ + char *bfname; /* btree file name */ +} RECNOINFO; + +#ifdef __DBINTERFACE_PRIVATE +/* + * Little endian <==> big endian 32-bit swap macros. + * M_32_SWAP swap a memory location + * P_32_SWAP swap a referenced memory location + * P_32_COPY swap from one location to another + */ +#define M_32_SWAP(a) { \ + u_int32_t _tmp = a; \ + ((char *)&a)[0] = ((char *)&_tmp)[3]; \ + ((char *)&a)[1] = ((char *)&_tmp)[2]; \ + ((char *)&a)[2] = ((char *)&_tmp)[1]; \ + ((char *)&a)[3] = ((char *)&_tmp)[0]; \ +} +#define P_32_SWAP(a) { \ + u_int32_t _tmp = *(u_int32_t *)a; \ + ((char *)a)[0] = ((char *)&_tmp)[3]; \ + ((char *)a)[1] = ((char *)&_tmp)[2]; \ + ((char *)a)[2] = ((char *)&_tmp)[1]; \ + ((char *)a)[3] = ((char *)&_tmp)[0]; \ +} +#define P_32_COPY(a, b) { \ + ((char *)&(b))[0] = ((char *)&(a))[3]; \ + ((char *)&(b))[1] = ((char *)&(a))[2]; \ + ((char *)&(b))[2] = ((char *)&(a))[1]; \ + ((char *)&(b))[3] = ((char *)&(a))[0]; \ +} + +/* + * Little endian <==> big endian 16-bit swap macros. + * M_16_SWAP swap a memory location + * P_16_SWAP swap a referenced memory location + * P_16_COPY swap from one location to another + */ +#define M_16_SWAP(a) { \ + u_int16_t _tmp = a; \ + ((char *)&a)[0] = ((char *)&_tmp)[1]; \ + ((char *)&a)[1] = ((char *)&_tmp)[0]; \ +} +#define P_16_SWAP(a) { \ + u_int16_t _tmp = *(u_int16_t *)a; \ + ((char *)a)[0] = ((char *)&_tmp)[1]; \ + ((char *)a)[1] = ((char *)&_tmp)[0]; \ +} +#define P_16_COPY(a, b) { \ + ((char *)&(b))[0] = ((char *)&(a))[1]; \ + ((char *)&(b))[1] = ((char *)&(a))[0]; \ +} +#endif + +__BEGIN_DECLS +DB *dbopen __P((const char *, int, int, DBTYPE, const void *)); + +#ifdef __DBINTERFACE_PRIVATE +DB *__bt_open __P((const char *, int, int, const BTREEINFO *, int)); +DB *__hash_open __P((const char *, int, int, const HASHINFO *, int)); +DB *__rec_open __P((const char *, int, int, const RECNOINFO *, int)); +void __dbpanic __P((DB *dbp)); +#endif +__END_DECLS +#endif /* !_DB_H_ */ diff --git a/include/dirent.h b/include/dirent.h new file mode 100644 index 0000000..1a67741 --- /dev/null +++ b/include/dirent.h @@ -0,0 +1,124 @@ +/* + * Copyright (c) 2000 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@ + */ +/*- + * Copyright (c) 1989, 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. + * + * @(#)dirent.h 8.2 (Berkeley) 7/28/94 + */ + +#ifndef _DIRENT_H_ +#define _DIRENT_H_ + +/* + * The kernel defines the format of directory entries returned by + * the getdirentries(2) system call. + */ +#include + +#ifdef _POSIX_SOURCE +typedef void * DIR; +#else + +#define d_ino d_fileno /* backward compatibility */ + +/* definitions for library routines operating on directories. */ +#define DIRBLKSIZ 1024 + +/* structure describing an open directory. */ +typedef struct _dirdesc { + int dd_fd; /* file descriptor associated with directory */ + long dd_loc; /* offset in current buffer */ + long dd_size; /* amount of data returned by getdirentries */ + char *dd_buf; /* data buffer */ + int dd_len; /* size of data buffer */ + long dd_seek; /* magic cookie returned by getdirentries */ + long dd_rewind; /* magic cookie for rewinding */ + int dd_flags; /* flags for readdir */ +} DIR; + +#define dirfd(dirp) ((dirp)->dd_fd) + +/* flags for opendir2 */ +#define DTF_HIDEW 0x0001 /* hide whiteout entries */ +#define DTF_NODUP 0x0002 /* don't return duplicate names */ +#define DTF_REWIND 0x0004 /* rewind after reading union stack */ +#define __DTF_READALL 0x0008 /* everything has been read */ + +#ifndef NULL +#define NULL 0 +#endif + +#endif /* _POSIX_SOURCE */ + +#ifndef KERNEL + +#include + +__BEGIN_DECLS +DIR *opendir __P((const char *)); +struct dirent *readdir __P((DIR *)); +void rewinddir __P((DIR *)); +int closedir __P((DIR *)); +#ifndef _POSIX_SOURCE +DIR *__opendir2 __P((const char *, int)); +long telldir __P((const DIR *)); +void seekdir __P((DIR *, long)); +int scandir __P((const char *, struct dirent ***, + int (*)(struct dirent *), int (*)(const void *, const void *))); +int alphasort __P((const void *, const void *)); +int getdirentries __P((int, char *, int, long *)); +int readdir_r __P((DIR *, struct dirent *, struct dirent **)); +#endif /* not POSIX */ +__END_DECLS + +#endif /* !KERNEL */ + +#endif /* !_DIRENT_H_ */ diff --git a/include/disktab.h b/include/disktab.h new file mode 100644 index 0000000..386cb64 --- /dev/null +++ b/include/disktab.h @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2000 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@ + */ +/* + * Copyright (c) 1983, 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. + * + * @(#)disktab.h 8.1 (Berkeley) 6/2/93 + */ + +#ifndef _DISKTAB_H_ +#define _DISKTAB_H_ + +/* + * Disk description table, see disktab(5) + */ +#define DISKTAB "/etc/disktab" + +struct disktab { + char *d_name; /* drive name */ + char *d_type; /* drive type */ + int d_secsize; /* sector size in bytes */ + int d_ntracks; /* # tracks/cylinder */ + int d_nsectors; /* # sectors/track */ + int d_ncylinders; /* # cylinders */ + int d_rpm; /* revolutions/minute */ + int d_badsectforw; /* supports DEC bad144 std */ + int d_sectoffset; /* use sect rather than cyl offsets */ + struct partition { + int p_size; /* #sectors in partition */ + short p_bsize; /* block size in bytes */ + short p_fsize; /* frag size in bytes */ + } d_partitions[8]; +}; + +#endif /* !_DISKTAB_H_ */ diff --git a/include/err.h b/include/err.h new file mode 100644 index 0000000..59e6d22 --- /dev/null +++ b/include/err.h @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2000 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@ + */ +/*- + * 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. + * + * @(#)err.h 8.1 (Berkeley) 6/2/93 + */ + +#ifndef _ERR_H_ +#define _ERR_H_ + +/* + * Don't use va_list in the err/warn prototypes. Va_list is typedef'd in two + * places ( and ), 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 and use it. + */ +#include +#include + +__BEGIN_DECLS +__dead void err __P((int, const char *, ...)) __attribute__((__noreturn__)); +__dead void verr __P((int, const char *, _BSD_VA_LIST_)) __attribute__((__noreturn__)); +__dead void errx __P((int, const char *, ...)) __attribute__((__noreturn__)); +__dead void verrx __P((int, const char *, _BSD_VA_LIST_)) __attribute__((__noreturn__)); +void warn __P((const char *, ...)); +void vwarn __P((const char *, _BSD_VA_LIST_)); +void warnx __P((const char *, ...)); +void vwarnx __P((const char *, _BSD_VA_LIST_)); +__END_DECLS + +#endif /* !_ERR_H_ */ diff --git a/include/errno.h b/include/errno.h new file mode 100644 index 0000000..57f2f7b --- /dev/null +++ b/include/errno.h @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2000 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@ + */ +#include + diff --git a/include/fcntl.h b/include/fcntl.h new file mode 100644 index 0000000..d936d70 --- /dev/null +++ b/include/fcntl.h @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2000 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@ + */ +#include diff --git a/include/fnmatch.h b/include/fnmatch.h new file mode 100644 index 0000000..ae89fc0 --- /dev/null +++ b/include/fnmatch.h @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2000 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@ + */ +/*- + * 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. + * + * @(#)fnmatch.h 8.1 (Berkeley) 6/2/93 + */ + +#ifndef _FNMATCH_H_ +#define _FNMATCH_H_ + +#define FNM_NOMATCH 1 /* Match failed. */ + +#define FNM_NOESCAPE 0x01 /* Disable backslash escaping. */ +#define FNM_PATHNAME 0x02 /* Slash must be matched by slash. */ +#define FNM_PERIOD 0x04 /* Period must be matched by period. */ + +#if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE) +#define FNM_LEADING_DIR 0x08 /* Ignore / after Imatch. */ +#define FNM_CASEFOLD 0x10 /* Case insensitive search. */ +#define FNM_IGNORECASE FNM_CASEFOLD +#define FNM_FILE_NAME FNM_PATHNAME +#endif + +#include + +__BEGIN_DECLS +#ifndef _POSIX_SOURCE +int fnmatch __P((const char *, const char *, int)); +#endif +__END_DECLS + +#endif /* !_FNMATCH_H_ */ diff --git a/include/fsproperties.h b/include/fsproperties.h new file mode 100644 index 0000000..15db660 --- /dev/null +++ b/include/fsproperties.h @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2000 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 _FSPROPERTIES_H_ +#define _FSPROPERTIES_H_ + +/* Info plist keys */ +#define kFSMediaTypesKey "FSMediaTypes" +#define kFSPersonalitiesKey "FSPersonalities" + +/* Sub-keys for FSMediaTypes dictionaries */ +#define kFSMediaPropertiesKey "FSMediaProperties" +#define kFSProbeArgumentsKey "FSProbeArguments" +#define kFSProbeExecutableKey "FSProbeExecutable" +#define kFSProbeOrderKey "FSProbeOrder" + +/* Sub-keys for FSPersonalities dictionaries */ +#define kFSFormatArgumentsKey "FSFormatArguments" +#define kFSFormatContentMaskKey "FSFormatContentMask" +#define kFSFormatExecutableKey "FSFormatExecutable" +#define kFSFormatMinimumSizeKey "FSFormatMinimumSize" +#define kFSMountArgumentsKey "FSMountArguments" +#define kFSMountExecutableKey "FSMountExecutable" +#define kFSNameKey "FSName" +#define kFSRepairArgumentsKey "FSRepairArguments" +#define kFSRepairExecutableKey "FSRepairExecutable" +#define kFSVerificationArgumentsKey "FSVerificationArguments" +#define kFSVerificationExecutableKey "FSVerificationExecutable" + +#endif /* _FSPROPERTIES_H_ */ diff --git a/include/fstab.h b/include/fstab.h new file mode 100644 index 0000000..5427d34 --- /dev/null +++ b/include/fstab.h @@ -0,0 +1,100 @@ +/* + * Copyright (c) 2000 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@ + */ +/* + * Copyright (c) 1980, 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. + * + * @(#)fstab.h 8.1 (Berkeley) 6/2/93 + */ + +#ifndef _FSTAB_H_ +#define _FSTAB_H_ + +/* + * File system table, see fstab(5). + * + * Used by dump, mount, umount, swapon, fsck, df, ... + * + * For ufs fs_spec field is the block special name. Programs that want to + * use the character special name must create that name by prepending a 'r' + * after the right most slash. Quota files are always named "quotas", so + * if type is "rq", then use concatenation of fs_file and "quotas" to locate + * quota file. + */ +#define _PATH_FSTAB "/etc/fstab" +#define FSTAB "/etc/fstab" /* deprecated */ + +#define FSTAB_RW "rw" /* read/write device */ +#define FSTAB_RQ "rq" /* read/write with quotas */ +#define FSTAB_RO "ro" /* read-only device */ +#define FSTAB_SW "sw" /* swap device */ +#define FSTAB_XX "xx" /* ignore totally */ + +struct fstab { + char *fs_spec; /* block special device name */ + char *fs_file; /* file system path prefix */ + char *fs_vfstype; /* File system type, ufs, nfs */ + char *fs_mntops; /* Mount options ala -o */ + char *fs_type; /* FSTAB_* from fs_mntops */ + int fs_freq; /* dump frequency, in days */ + int fs_passno; /* pass number on parallel dump */ +}; + +#include + +__BEGIN_DECLS +struct fstab *getfsent __P((void)); +struct fstab *getfsspec __P((const char *)); +struct fstab *getfsfile __P((const char *)); +int setfsent __P((void)); +void endfsent __P((void)); +__END_DECLS + +#endif /* !_FSTAB_H_ */ diff --git a/include/fts.h b/include/fts.h new file mode 100644 index 0000000..3311bd3 --- /dev/null +++ b/include/fts.h @@ -0,0 +1,149 @@ +/* + * Copyright (c) 2000 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@ + */ +/* + * Copyright (c) 1989, 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. + * + * @(#)fts.h 8.3 (Berkeley) 8/14/94 + */ + +#ifndef _FTS_H_ +#define _FTS_H_ + +typedef struct { + struct _ftsent *fts_cur; /* current node */ + struct _ftsent *fts_child; /* linked list of children */ + struct _ftsent **fts_array; /* sort array */ + dev_t fts_dev; /* starting device # */ + char *fts_path; /* path for this descent */ + int fts_rfd; /* fd for root */ + int fts_pathlen; /* sizeof(path) */ + int fts_nitems; /* elements in the sort array */ + int (*fts_compar)(); /* compare function */ + +#define FTS_COMFOLLOW 0x001 /* follow command line symlinks */ +#define FTS_LOGICAL 0x002 /* logical walk */ +#define FTS_NOCHDIR 0x004 /* don't change directories */ +#define FTS_NOSTAT 0x008 /* don't get stat info */ +#define FTS_PHYSICAL 0x010 /* physical walk */ +#define FTS_SEEDOT 0x020 /* return dot and dot-dot */ +#define FTS_XDEV 0x040 /* don't cross devices */ +#define FTS_WHITEOUT 0x080 /* return whiteout information */ +#define FTS_OPTIONMASK 0x0ff /* valid user option mask */ + +#define FTS_NAMEONLY 0x100 /* (private) child names only */ +#define FTS_STOP 0x200 /* (private) unrecoverable error */ + int fts_options; /* fts_open options, global flags */ +} FTS; + +typedef struct _ftsent { + struct _ftsent *fts_cycle; /* cycle node */ + struct _ftsent *fts_parent; /* parent directory */ + struct _ftsent *fts_link; /* next file in directory */ + long fts_number; /* local numeric value */ + void *fts_pointer; /* local address value */ + char *fts_accpath; /* access path */ + 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) */ + + ino_t fts_ino; /* inode */ + dev_t fts_dev; /* device */ + nlink_t fts_nlink; /* link count */ + +#define FTS_ROOTPARENTLEVEL -1 +#define FTS_ROOTLEVEL 0 + short fts_level; /* depth (-1 to N) */ + +#define FTS_D 1 /* preorder directory */ +#define FTS_DC 2 /* directory that causes cycles */ +#define FTS_DEFAULT 3 /* none of the above */ +#define FTS_DNR 4 /* unreadable directory */ +#define FTS_DOT 5 /* dot or dot-dot */ +#define FTS_DP 6 /* postorder directory */ +#define FTS_ERR 7 /* error; errno is set */ +#define FTS_F 8 /* regular file */ +#define FTS_INIT 9 /* initialized only */ +#define FTS_NS 10 /* stat(2) failed */ +#define FTS_NSOK 11 /* no stat(2) requested */ +#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 */ + +#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 */ + +#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 */ + + struct stat *fts_statp; /* stat(2) information */ + char fts_name[1]; /* file name */ +} FTSENT; + +#include + +__BEGIN_DECLS +FTSENT *fts_children __P((FTS *, int)); +int fts_close __P((FTS *)); +FTS *fts_open __P((char * const *, int, + int (*)(const FTSENT **, const FTSENT **))); +FTSENT *fts_read __P((FTS *)); +int fts_set __P((FTS *, FTSENT *, int)); +__END_DECLS + +#endif /* !_FTS_H_ */ diff --git a/include/glob.h b/include/glob.h new file mode 100644 index 0000000..9a6d1f0 --- /dev/null +++ b/include/glob.h @@ -0,0 +1,111 @@ +/* + * Copyright (c) 2000 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@ + */ +/* + * Copyright (c) 1989, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Guido van Rossum. + * + * 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. + * + * @(#)glob.h 8.1 (Berkeley) 6/2/93 + */ + +#ifndef _GLOB_H_ +#define _GLOB_H_ + +#include + +struct stat; +typedef struct { + int gl_pathc; /* Count of total paths so far. */ + int gl_matchc; /* Count of paths matching pattern. */ + int gl_offs; /* Reserved at beginning of gl_pathv. */ + int gl_flags; /* Copy of flags parameter to glob. */ + char **gl_pathv; /* List of paths matching pattern. */ + /* Copy of errfunc parameter to glob. */ + int (*gl_errfunc) __P((const char *, int)); + + /* + * Alternate filesystem access methods for glob; replacement + * versions of closedir(3), readdir(3), opendir(3), stat(2) + * and lstat(2). + */ + void (*gl_closedir) __P((void *)); + struct dirent *(*gl_readdir) __P((void *)); + void *(*gl_opendir) __P((const char *)); + int (*gl_lstat) __P((const char *, struct stat *)); + int (*gl_stat) __P((const char *, struct stat *)); +} glob_t; + +#define GLOB_APPEND 0x0001 /* Append to output from previous call. */ +#define GLOB_DOOFFS 0x0002 /* Use gl_offs. */ +#define GLOB_ERR 0x0004 /* Return on error. */ +#define GLOB_MARK 0x0008 /* Append / to matching directories. */ +#define GLOB_NOCHECK 0x0010 /* Return pattern itself if nothing matches. */ +#define GLOB_NOSORT 0x0020 /* Don't sort. */ + +#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. */ +#define GLOB_NOMAGIC 0x0200 /* GLOB_NOCHECK without magic chars (csh). */ +#define GLOB_QUOTE 0x0400 /* Quote special chars with \. */ +#define GLOB_TILDE 0x0800 /* Expand tilde names from the passwd file. */ +#endif + +#define GLOB_NOSPACE (-1) /* Malloc call failed. */ +#define GLOB_ABEND (-2) /* Unignored error. */ + +__BEGIN_DECLS +int glob __P((const char *, int, int (*)(const char *, int), glob_t *)); +void globfree __P((glob_t *)); +__END_DECLS + +#endif /* !_GLOB_H_ */ diff --git a/include/grp.h b/include/grp.h new file mode 100644 index 0000000..6861981 --- /dev/null +++ b/include/grp.h @@ -0,0 +1,92 @@ +/* + * Copyright (c) 2000 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@ + */ +/*- + * 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. + * + * 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. + * + * @(#)grp.h 8.2 (Berkeley) 1/21/94 + */ + +#ifndef _GRP_H_ +#define _GRP_H_ + +#ifndef _POSIX_SOURCE +#define _PATH_GROUP "/etc/group" +#endif + +struct group { + char *gr_name; /* group name */ + char *gr_passwd; /* group password */ + gid_t gr_gid; /* group id */ + char **gr_mem; /* group members */ +}; + +#include + +__BEGIN_DECLS +struct group *getgrgid __P((gid_t)); +struct group *getgrnam __P((const char *)); +int getgrgid_r __P((gid_t, struct group *, char *, size_t, struct group **)); +int getgrnam_r __P((const char *, struct group *, char *, size_t, struct group **)); +#ifndef _POSIX_SOURCE +struct group *getgrent __P((void)); +int setgrent __P((void)); +void endgrent __P((void)); +void setgrfile __P((const char *)); +int setgroupent __P((int)); +#endif +__END_DECLS + +#endif /* !_GRP_H_ */ diff --git a/include/kvm.h b/include/kvm.h new file mode 100644 index 0000000..f513cb6 --- /dev/null +++ b/include/kvm.h @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2000 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@ + */ +/*- + * Copyright (c) 1989, 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. + * + * @(#)kvm.h 8.1 (Berkeley) 6/2/93 + */ + +#ifndef _KVM_H_ +#define _KVM_H_ + +/* Default version symbol. */ +#define VRS_SYM "_version" +#define VRS_KEY "VERSION" + +#include +#include + +__BEGIN_DECLS + +typedef struct __kvm kvm_t; + +struct kinfo_proc; +int kvm_close __P((kvm_t *)); +char **kvm_getargv __P((kvm_t *, const struct kinfo_proc *, int)); +char **kvm_getenvv __P((kvm_t *, const struct kinfo_proc *, int)); +char *kvm_geterr __P((kvm_t *)); +int kvm_getloadavg __P((kvm_t *, double [], int)); +char *kvm_getfiles __P((kvm_t *, int, int, int *)); +struct kinfo_proc * + kvm_getprocs __P((kvm_t *, int, int, int *)); +int kvm_nlist __P((kvm_t *, struct nlist *)); +kvm_t *kvm_open + __P((const char *, const char *, const char *, int, const char *)); +kvm_t *kvm_openfiles + __P((const char *, const char *, const char *, int, char *)); +int kvm_read __P((kvm_t *, unsigned long, void *, unsigned int)); +int kvm_write __P((kvm_t *, unsigned long, const void *, unsigned int)); + +__END_DECLS + +#endif /* !_KVM_H_ */ diff --git a/include/libc.h b/include/libc.h new file mode 100644 index 0000000..9125b3c --- /dev/null +++ b/include/libc.h @@ -0,0 +1,72 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ + +#ifndef LIBC_H +#define LIBC_H + +#include +#include +#include + +#ifdef __STRICT_BSD__ +#include +#include +#else +#include +#include +#include +#include +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +struct qelem { + struct qelem *q_forw; + struct qelem *q_back; + char *q_data; +}; + +extern kern_return_t map_fd(int fd, vm_offset_t offset, + vm_offset_t *addr, boolean_t find_space, vm_size_t numbytes); + + +#endif /* _LIBC_H */ diff --git a/include/libgen.h b/include/libgen.h new file mode 100644 index 0000000..a679433 --- /dev/null +++ b/include/libgen.h @@ -0,0 +1,49 @@ +/* $OpenBSD: libgen.h,v 1.4 1999/05/28 22:00:22 espie Exp $ */ +/* $FreeBSD: src/include/libgen.h,v 1.1.2.1 2000/11/12 18:01:51 adrian Exp $ */ + +/* + * Copyright (c) 1997 Todd C. Miller + * 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. 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 ARE 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 + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _LIBGEN_H_ +#define _LIBGEN_H_ + +#include + +__BEGIN_DECLS + +char *basename __P((const char *)); +char *dirname __P((const char *)); +#if 0 +char *regcmp __P((const char *, ...)); +char *regex __P((const char *, const char *, ...)); + +extern char *__loc1; +#endif + +__END_DECLS + +#endif /* _LIBGEN_H_ */ diff --git a/include/limits.h b/include/limits.h new file mode 100644 index 0000000..d2879c3 --- /dev/null +++ b/include/limits.h @@ -0,0 +1,108 @@ +/* + * Copyright (c) 2000 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@ + */ +/* $NetBSD: limits.h,v 1.8 1996/10/21 05:10:50 jtc Exp $ */ + +/* + * Copyright (c) 1988, 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. + * + * @(#)limits.h 8.2 (Berkeley) 1/4/94 + */ + +#ifndef _LIMITS_H_ +#define _LIMITS_H_ + +#include +#include + +#if !defined(_ANSI_SOURCE) +#define _POSIX_ARG_MAX 4096 +#define _POSIX_CHILD_MAX 6 +#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_PIPE_BUF 512 +#define _POSIX_SSIZE_MAX 32767 +#define _POSIX_STREAM_MAX 8 +#define _POSIX_TZNAME_MAX 3 + +#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_COLL_WEIGHTS_MAX 2 +#define _POSIX2_EQUIV_CLASS_MAX 2 +#define _POSIX2_EXPR_NEST_MAX 32 +#define _POSIX2_LINE_MAX 2048 +#define _POSIX2_RE_DUP_MAX 255 + +#define PTHREAD_STACK_MIN 8192 +#define PTHREAD_DESTRUCTOR_ITERATIONS 4 +#define PTHREAD_KEYS_MAX 128 + +#endif /* !_ANSI_SOURCE */ + +#if ( !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE) ) || defined(_XOPEN_SOURCE) +#define PASS_MAX 128 + +#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 + + +#endif /* !_LIMITS_H_ */ diff --git a/include/locale.h b/include/locale.h new file mode 100644 index 0000000..0c1a6bc --- /dev/null +++ b/include/locale.h @@ -0,0 +1,81 @@ +/* + * 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 + */ + +#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; +}; + +#ifndef NULL +#define NULL 0 +#endif + +#define LC_ALL 0 +#define LC_COLLATE 1 +#define LC_CTYPE 2 +#define LC_MONETARY 3 +#define LC_NUMERIC 4 +#define LC_TIME 5 +#define LC_MESSAGES 6 + +#define _LC_LAST 7 /* marks end */ + +#include + +__BEGIN_DECLS +struct lconv *localeconv __P((void)); +char *setlocale __P((int, const char *)); +__END_DECLS + +#endif /* _LOCALE_H_ */ diff --git a/include/memory.h b/include/memory.h new file mode 100644 index 0000000..49f8bd0 --- /dev/null +++ b/include/memory.h @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2000 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@ + */ +/* + * Copyright (c) 1988, 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. + * + * @(#)memory.h 8.1 (Berkeley) 6/2/93 + */ + +#include diff --git a/include/monitor.h b/include/monitor.h new file mode 100644 index 0000000..d9c14f3 --- /dev/null +++ b/include/monitor.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1988 NeXT, Inc. + * + * HISTORY + * 04-May-90 Created + */ + +#ifndef __MONITOR_HEADER__ +#define __MONITOR_HEADER__ + +extern void monstartup (char *lowpc, char *highpc); + +extern void monitor (char *lowpc, char *highpc, char *buf, int bufsiz, int cntsiz); + +extern void moncontrol (int mode); + +extern void monoutput (const char *filename); + +extern void moninit (void); + +extern void monreset (void); + +#endif /* __MONITOR_HEADER__ */ diff --git a/include/mpool.h b/include/mpool.h new file mode 100644 index 0000000..13f9551 --- /dev/null +++ b/include/mpool.h @@ -0,0 +1,156 @@ +/* + * Copyright (c) 2000 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@ + */ +/*- + * 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. + * + * @(#)mpool.h 8.1 (Berkeley) 6/2/93 + */ + +/* + * The memory pool scheme is a simple one. Each in memory page is referenced + * by a bucket which is threaded in three ways. All active pages are threaded + * on a hash chain (hashed by the page number) and an lru chain. Inactive + * pages are threaded on a free chain. Each reference to a memory pool is + * handed an MPOOL which is the opaque cookie passed to all of the memory + * routines. + */ +#define HASHSIZE 128 +#define HASHKEY(pgno) ((pgno - 1) % HASHSIZE) + +/* The BKT structures are the elements of the lists. */ +typedef struct BKT { + struct BKT *hnext; /* next hash bucket */ + struct BKT *hprev; /* previous hash bucket */ + struct BKT *cnext; /* next free/lru bucket */ + struct BKT *cprev; /* previous free/lru bucket */ + void *page; /* page */ + pgno_t pgno; /* page number */ + +#define MPOOL_DIRTY 0x01 /* page needs to be written */ +#define MPOOL_PINNED 0x02 /* page is pinned into memory */ + unsigned long flags; /* flags */ +} BKT; + +/* The BKTHDR structures are the heads of the lists. */ +typedef struct BKTHDR { + struct BKT *hnext; /* next hash bucket */ + struct BKT *hprev; /* previous hash bucket */ + struct BKT *cnext; /* next free/lru bucket */ + struct BKT *cprev; /* previous free/lru bucket */ +} BKTHDR; + +typedef struct MPOOL { + BKTHDR free; /* The free list. */ + BKTHDR lru; /* The LRU list. */ + BKTHDR hashtable[HASHSIZE]; /* Hashed list by page number. */ + 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. */ + int fd; /* File descriptor. */ + /* Page in conversion routine. */ + void (*pgin) __P((void *, pgno_t, void *)); + /* Page out conversion routine. */ + void (*pgout) __P((void *, pgno_t, void *)); + void *pgcookie; /* Cookie for page in/out routines. */ +#ifdef STATISTICS + 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; + +#ifdef __MPOOLINTERFACE_PRIVATE +/* Macros to insert/delete into/from hash chain. */ +#define rmhash(bp) { \ + (bp)->hprev->hnext = (bp)->hnext; \ + (bp)->hnext->hprev = (bp)->hprev; \ +} +#define inshash(bp, pg) { \ + hp = &mp->hashtable[HASHKEY(pg)]; \ + (bp)->hnext = hp->hnext; \ + (bp)->hprev = (struct BKT *)hp; \ + hp->hnext->hprev = (bp); \ + hp->hnext = (bp); \ +} + +/* Macros to insert/delete into/from lru and free chains. */ +#define rmchain(bp) { \ + (bp)->cprev->cnext = (bp)->cnext; \ + (bp)->cnext->cprev = (bp)->cprev; \ +} +#define inschain(bp, dp) { \ + (bp)->cnext = (dp)->cnext; \ + (bp)->cprev = (struct BKT *)(dp); \ + (dp)->cnext->cprev = (bp); \ + (dp)->cnext = (bp); \ +} +#endif + +__BEGIN_DECLS +MPOOL *mpool_open __P((DBT *, int, pgno_t, pgno_t)); +void mpool_filter __P((MPOOL *, void (*)(void *, pgno_t, void *), + void (*)(void *, pgno_t, void *), void *)); +void *mpool_new __P((MPOOL *, pgno_t *)); +void *mpool_get __P((MPOOL *, pgno_t, u_int)); +int mpool_put __P((MPOOL *, void *, u_int)); +int mpool_sync __P((MPOOL *)); +int mpool_close __P((MPOOL *)); +#ifdef STATISTICS +void mpool_stat __P((MPOOL *)); +#endif +__END_DECLS diff --git a/include/ndbm.h b/include/ndbm.h new file mode 100644 index 0000000..033a6ea --- /dev/null +++ b/include/ndbm.h @@ -0,0 +1,98 @@ +/* + * Copyright (c) 2000 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@ + */ +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Margo Seltzer. + * + * 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. + * + * @(#)ndbm.h 8.1 (Berkeley) 6/2/93 + */ + +#ifndef _NDBM_H_ +#define _NDBM_H_ + +#include + +/* Map dbm interface onto db(3). */ +#define DBM_RDONLY O_RDONLY + +/* Flags to dbm_store(). */ +#define DBM_INSERT 0 +#define DBM_REPLACE 1 + +/* + * The db(3) support for ndbm(3) always appends this suffix to the + * file name to avoid overwriting the user's original database. + */ +#define DBM_SUFFIX ".db" + +typedef struct { + char *dptr; + int dsize; +} datum; + +typedef DB DBM; +#define dbm_pagfno(a) DBM_PAGFNO_NOT_AVAILABLE + +__BEGIN_DECLS +void dbm_close __P((DBM *)); +int dbm_delete __P((DBM *, datum)); +datum dbm_fetch __P((DBM *, datum)); +datum dbm_firstkey __P((DBM *)); +long dbm_forder __P((DBM *, datum)); +datum dbm_nextkey __P((DBM *)); +DBM *dbm_open __P((const char *, int, int)); +int dbm_store __P((DBM *, datum, datum, int)); +int dbm_dirfno __P((DBM *)); +__END_DECLS + +#endif /* !_NDBM_H_ */ diff --git a/include/netdb.h b/include/netdb.h new file mode 100644 index 0000000..34102f2 --- /dev/null +++ b/include/netdb.h @@ -0,0 +1,259 @@ +/* + * Copyright (c) 2000 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@ + */ +/* + * ++Copyright++ 1980, 1983, 1988, 1993 + * - + * Copyright (c) 1980, 1983, 1988, 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. + * - + * Portions Copyright (c) 1993 by Digital Equipment Corporation. + * + * 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, and that + * the name of Digital Equipment Corporation not be used in advertising or + * publicity pertaining to distribution of the document or software without + * specific, written prior permission. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL + * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT + * CORPORATION 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. + * - + * --Copyright-- + */ + +/* + * @(#)netdb.h 8.1 (Berkeley) 6/2/93 + */ + +#ifndef _NETDB_H_ +#define _NETDB_H_ + +#include +#include + +#define _PATH_HEQUIV "/etc/hosts.equiv" +#define _PATH_HOSTS "/etc/hosts" +#define _PATH_NETWORKS "/etc/networks" +#define _PATH_PROTOCOLS "/etc/protocols" +#define _PATH_SERVICES "/etc/services" + +extern int h_errno; + +/* + * Structures returned by network data base library. All addresses are + * supplied in host order, and returned in network order (suitable for + * use in system calls). + */ +struct hostent { + char *h_name; /* official name of host */ + char **h_aliases; /* alias list */ + int h_addrtype; /* host address type */ + int h_length; /* length of address */ + char **h_addr_list; /* list of addresses from name server */ +#define h_addr h_addr_list[0] /* address, for backward compatiblity */ +}; + +/* + * Assumption here is that a network number + * fits in an unsigned long -- probably a poor one. + */ +struct netent { + char *n_name; /* official name of net */ + char **n_aliases; /* alias list */ + int n_addrtype; /* net address type */ + unsigned long n_net; /* network # */ +}; + +struct servent { + char *s_name; /* official service name */ + char **s_aliases; /* alias list */ + int s_port; /* port # */ + char *s_proto; /* protocol to use */ +}; + +struct protoent { + char *p_name; /* official protocol name */ + char **p_aliases; /* alias list */ + int p_proto; /* protocol # */ +}; + +struct addrinfo { + int ai_flags; /* AI_PASSIVE, AI_CANONNAME, AI_NUMERICHOST */ + int ai_family; /* PF_xxx */ + int ai_socktype; /* SOCK_xxx */ + int ai_protocol; /* 0 or IPPROTO_xxx for IPv4 and IPv6 */ + size_t ai_addrlen; /* length of ai_addr */ + char *ai_canonname; /* canonical name for hostname */ + struct sockaddr *ai_addr; /* binary address */ + struct addrinfo *ai_next; /* next structure in linked list */ +}; + +struct rpcent { + char *r_name; /* name of server for this rpc program */ + char **r_aliases; /* alias list */ + int r_number; /* rpc program number */ +}; + +/* + * Error return codes from gethostbyname() and gethostbyaddr() + * (left in extern int h_errno). + */ + +#define NETDB_INTERNAL -1 /* see errno */ +#define NETDB_SUCCESS 0 /* no problem */ +#define HOST_NOT_FOUND 1 /* Authoritative Answer Host not found */ +#define TRY_AGAIN 2 /* Non-Authoritative Host not found, or SERVERFAIL */ +#define NO_RECOVERY 3 /* Non recoverable errors, FORMERR, REFUSED, NOTIMP */ +#define NO_DATA 4 /* Valid name, no data record of requested type */ +#define NO_ADDRESS NO_DATA /* no address, look for MX record */ + +/* + * Error return codes from getaddrinfo() + */ +#define EAI_ADDRFAMILY 1 /* address family for hostname not supported */ +#define EAI_AGAIN 2 /* temporary failure in name resolution */ +#define EAI_BADFLAGS 3 /* invalid value for ai_flags */ +#define EAI_FAIL 4 /* non-recoverable failure in name resolution */ +#define EAI_FAMILY 5 /* ai_family not supported */ +#define EAI_MEMORY 6 /* memory allocation failure */ +#define EAI_NODATA 7 /* no address associated with hostname */ +#define EAI_NONAME 8 /* hostname nor servname provided, or not known */ +#define EAI_SERVICE 9 /* servname not supported for ai_socktype */ +#define EAI_SOCKTYPE 10 /* ai_socktype not supported */ +#define EAI_SYSTEM 11 /* system error returned in errno */ +#define EAI_BADHINTS 12 +#define EAI_PROTOCOL 13 +#define EAI_MAX 14 + +/* + * Flag values for getaddrinfo() + */ +#define AI_PASSIVE 0x00000001 /* get address to use bind() */ +#define AI_CANONNAME 0x00000002 /* fill ai_canonname */ +#define AI_NUMERICHOST 0x00000004 /* prevent name resolution */ +/* valid flags for addrinfo */ +#define AI_MASK (AI_PASSIVE | AI_CANONNAME | AI_NUMERICHOST) + +#define AI_ALL 0x00000100 /* IPv6 and IPv4-mapped (with AI_V4MAPPED) */ +#define AI_V4MAPPED_CFG 0x00000200 /* accept IPv4-mapped if kernel supports */ +#define AI_ADDRCONFIG 0x00000400 /* only if any address is assigned */ +#define AI_V4MAPPED 0x00000800 /* accept IPv4-mapped IPv6 address */ +/* special recommended flags for getipnodebyname */ +#define AI_DEFAULT (AI_V4MAPPED_CFG | AI_ADDRCONFIG) + +/* + * Constants for getnameinfo() + */ +#define NI_MAXHOST 1025 +#define NI_MAXSERV 32 + +/* + * Flag values for getnameinfo() + */ +#define NI_NOFQDN 0x00000001 +#define NI_NUMERICHOST 0x00000002 +#define NI_NAMEREQD 0x00000004 +#define NI_NUMERICSERV 0x00000008 +#define NI_DGRAM 0x00000010 +#define NI_WITHSCOPEID 0x00000020 + +/* + * Scope delimit character + */ +#define SCOPE_DELIMITER '%' + +__BEGIN_DECLS +void endhostent __P((void)); +void endnetent __P((void)); +void endprotoent __P((void)); +void endservent __P((void)); +void freehostent __P((struct hostent *)); +struct hostent *gethostbyaddr __P((const char *, int, int)); +struct hostent *gethostbyname __P((const char *)); +struct hostent *gethostbyname2 __P((const char *, int)); +struct hostent *gethostent __P((void)); +struct hostent *getipnodebyaddr __P((const void *, size_t, int, int *)); +struct hostent *getipnodebyname __P((const char *, int, int, int *)); +struct netent *getnetbyaddr __P((long, int)); +struct netent *getnetbyname __P((const char *)); +struct netent *getnetent __P((void)); +struct protoent *getprotobyname __P((const char *)); +struct protoent *getprotobynumber __P((int)); +struct protoent *getprotoent __P((void)); +struct servent *getservbyname __P((const char *, const char *)); +struct servent *getservbyport __P((int, const char *)); +struct servent *getservent __P((void)); +struct rpcent *getrpcbyname __P((const char *name)); +struct rpcent *getrpcbynumber __P((long number)); +struct rpcent *getrpcent __P((void)); +void setrpcent __P((int stayopen)); +void endrpcent __P((void)); + +void herror __P((const char *)); +char *hstrerror __P((int)); +void sethostent __P((int)); +/* void sethostfile __P((const char *)); */ +void setnetent __P((int)); +void setprotoent __P((int)); +void setservent __P((int)); + +char *gai_strerror __P((int)); +void freeaddrinfo __P((struct addrinfo *)); +int getaddrinfo __P((const char *, const char *, const struct addrinfo *, struct addrinfo **)); +int getnameinfo __P((const struct sockaddr *, size_t, char *, size_t, char *, size_t, int)); +__END_DECLS + +#endif /* !_NETDB_H_ */ diff --git a/include/nlist.h b/include/nlist.h new file mode 100644 index 0000000..828b4a7 --- /dev/null +++ b/include/nlist.h @@ -0,0 +1,106 @@ +/* + * Copyright (c) 2000 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@ + */ +/*- + * Copyright (c) 1991, 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. + * + * @(#)nlist.h 8.2 (Berkeley) 1/21/94 + */ + +#ifndef _NLIST_H_ +#define _NLIST_H_ + +/* + * Symbol table entry format. The #ifdef's are so that programs including + * nlist.h can initialize nlist structures statically. + */ +struct nlist { +#ifdef _AOUT_INCLUDE_ + union { + char *n_name; /* symbol name (in memory) */ + long n_strx; /* file string table offset (on disk) */ + } n_un; +#else + char *n_name; /* symbol name (in memory) */ +#endif + +#define N_UNDF 0x00 /* undefined */ +#define N_ABS 0x02 /* absolute address */ +#define N_TEXT 0x04 /* text segment */ +#define N_DATA 0x06 /* data segment */ +#define N_BSS 0x08 /* bss segment */ +#define N_COMM 0x12 /* common reference */ +#define N_FN 0x1e /* file name */ + +#define N_EXT 0x01 /* external (global) bit, OR'ed in */ +#define N_TYPE 0x1e /* mask for all the type bits */ + unsigned char n_type; /* type defines */ + + char n_other; /* spare */ +#define n_hash n_desc /* used internally by ld(1); XXX */ + short n_desc; /* used by stab entries */ + unsigned long n_value; /* address/value of the symbol */ +}; + +#define N_FORMAT "%08x" /* namelist value format; XXX */ +#define N_STAB 0x0e0 /* mask for debugger symbols -- stab(5) */ + +#include + +__BEGIN_DECLS +int nlist __P((const char *, struct nlist *)); +__END_DECLS + +#endif /* !_NLIST_H_ */ diff --git a/include/objc/Makefile.inc b/include/objc/Makefile.inc new file mode 100644 index 0000000..a4f8fad --- /dev/null +++ b/include/objc/Makefile.inc @@ -0,0 +1,2 @@ +OBJC_INSTHDRS += malloc.h zone.h +OBJC_INSTHDRS := ${OBJC_INSTHDRS:S/^/${.CURDIR}\/include\/objc\//} diff --git a/include/objc/malloc.h b/include/objc/malloc.h new file mode 100644 index 0000000..219f605 --- /dev/null +++ b/include/objc/malloc.h @@ -0,0 +1,151 @@ +/* + * Copyright (c) 1999 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@ + */ + +#import +#import + +/********* Type definitions ************/ + +typedef struct _malloc_zone_t { + /* Only zone implementors should depend on the layout of this structure; + Regular callers should use the access functions below */ + void *reserved1; + void *reserved2; + size_t (*size)(struct _malloc_zone_t *zone, const void *ptr); /* returns the size of a block or 0 if not in this zone; must be fast, especially for negative answers */ + void *(*malloc)(struct _malloc_zone_t *zone, size_t size); + void *(*calloc)(struct _malloc_zone_t *zone, size_t num_items, size_t size); /* same as malloc, but block returned is set to zero */ + void *(*valloc)(struct _malloc_zone_t *zone, size_t size); /* same as malloc, but block returned is set to zero and is guaranteed to be page aligned */ + void (*free)(struct _malloc_zone_t *zone, void *ptr); + void *(*realloc)(struct _malloc_zone_t *zone, void *ptr, size_t size); + void (*destroy)(struct _malloc_zone_t *zone); /* zone is destroyed and all memory reclaimed */ + const char *zone_name; + void *reserved3; + void *reserved4; + struct malloc_introspection_t *introspect; + void *reserved5; +} malloc_zone_t; + +/********* Creation and destruction ************/ + +extern malloc_zone_t *malloc_default_zone(void); + /* The initial zone */ + +extern malloc_zone_t *malloc_create_zone(vm_size_t start_size, unsigned flags); + /* Create a new zone */ + +extern void malloc_destroy_zone(malloc_zone_t *zone); + /* Destroys zone and everything it allocated */ + +/********* Block creation and manipulation ************/ + +extern void *malloc_zone_malloc(malloc_zone_t *zone, size_t size); + /* Allocates a new pointer of size size; zone must be non-NULL */ + +extern void *malloc_zone_calloc(malloc_zone_t *zone, size_t num_items, size_t size); + /* Allocates a new pointer of size num_items * size; block is cleared; zone must be non-NULL */ + +extern void *malloc_zone_valloc(malloc_zone_t *zone, size_t size); + /* Allocates a new pointer of size size; zone must be non-NULL; Pointer is guaranteed to be page-aligned and block is cleared */ + +extern void malloc_zone_free(malloc_zone_t *zone, void *ptr); + /* Frees pointer in zone; zone must be non-NULL */ + +extern void *malloc_zone_realloc(malloc_zone_t *zone, void *ptr, size_t size); + /* Enlarges block if necessary; zone must be non-NULL */ + +extern malloc_zone_t *malloc_zone_from_ptr(const void *ptr); + /* Returns the zone for a pointer, or NULL if not in any zone. + The ptr must have been returned from a malloc or realloc call. */ + +extern size_t malloc_size(const void *ptr); + /* Returns size of given ptr */ + +/********* Functions for zone implementors ************/ + +extern void malloc_zone_register(malloc_zone_t *zone); + /* Registers a freshly created zone; + Should typically be called after a zone has been created */ + +extern void malloc_zone_unregister(malloc_zone_t *zone); + /* De-registers a zone + Should typically be called before calling the zone destruction routine */ + +extern void malloc_set_zone_name(malloc_zone_t *zone, const char *name); + /* Sets the name of a zone */ + +extern const char *malloc_get_zone_name(malloc_zone_t *zone); + /* Returns the name of a zone */ + +typedef struct { + vm_address_t address; + vm_size_t size; +} vm_range_t; + +typedef kern_return_t memory_reader_t(task_t remote_task, vm_address_t remote_address, vm_size_t size, void **local_memory); + /* given a task, "reads" the memory at the given address and size +local_memory: set to a contiguous chunk of memory; validity of local_memory is assumed to be limited (until next call) */ + +#define MALLOC_PTR_IN_USE_RANGE_TYPE 1 /* for allocated pointers */ +#define MALLOC_PTR_REGION_RANGE_TYPE 2 /* for region containing pointers */ +#define MALLOC_ADMIN_REGION_RANGE_TYPE 4 /* for region used internally */ + +typedef void vm_range_recorder_t(task_t, void *, unsigned type, vm_range_t *, unsigned); + /* given a task and context, "records" the specified addresses */ + +typedef struct malloc_introspection_t { + kern_return_t (*enumerator)(task_t task, void *, unsigned type_mask, vm_address_t zone_address, memory_reader_t reader, vm_range_recorder_t recorder); /* enumerates all the malloc pointers in use */ + size_t (*good_size)(malloc_zone_t *zone, size_t size); + boolean_t (*check)(malloc_zone_t *zone); /* Consistency checker */ + void (*print)(malloc_zone_t *zone, boolean_t verbose); /* Prints zone */ + void (*log)(malloc_zone_t *zone, void *address); /* Enables logging of activity */ + void (*force_lock)(malloc_zone_t *zone); /* Forces locking zone */ + void (*force_unlock)(malloc_zone_t *zone); /* Forces unlocking zone */ +} malloc_introspection_t; + +extern void malloc_printf(const char *format, ...); + /* Convenience for logging errors and warnings; + No allocation is performed during execution of this function; + Only understand %p %d %x %s formats + */ + +/********* Functions for performance tools ************/ + +extern kern_return_t malloc_get_all_zones(task_t task, memory_reader_t reader, vm_address_t **addresses, unsigned *count); + /* Fills addresses and count with the addresses of the zones in task; + Note that the validity of the addresses returned correspond to the validity of the memory returned by reader */ + +/********* Debug helpers ************/ + +extern void malloc_zone_print_ptr_info(void *ptr); + /* print to stdout if this pointer is in the malloc heap, free status, and size */ + +extern boolean_t malloc_zone_check(malloc_zone_t *zone); + /* Checks zone is well formed; if !zone, checks all zones */ + +extern void malloc_zone_print(malloc_zone_t *zone, boolean_t verbose); + /* Prints summary on zone; if !zone, prints all zones */ + +extern void malloc_zone_log(malloc_zone_t *zone, void *address); + /* Controls logging of all activity; if !zone, for all zones; + If address==0 nothing is logged; + If address==-1 all activity is logged; + Else only the activity regarding address is logged */ diff --git a/include/objc/zone.h b/include/objc/zone.h new file mode 100644 index 0000000..94dd796 --- /dev/null +++ b/include/objc/zone.h @@ -0,0 +1,55 @@ +/* + * Copyright (c) 1999 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@ + */ + +#import + +typedef malloc_zone_t NXZone; + +#define NX_NOZONE ((NXZone *)0) + +/********* Interface to zone based malloc ************/ + +extern NXZone *NXDefaultMallocZone(void); + // Returns the default zone used by the malloc(3) calls + +extern NXZone *NXCreateZone(size_t startSize, size_t granularity, int canFree); + // Create a new zone with its own memory pool. + // canfree: if 0 the allocator will never free memory and mallocing will be fast + +extern void NXNameZone(NXZone *z, const char *name); + // name a zone; The string will be copied + +extern void *NXZoneMalloc(malloc_zone_t *zone, size_t size); + +extern void *NXZoneRealloc(malloc_zone_t *zone, void *ptr, size_t size); + +extern void *NXZoneCalloc(NXZone *zonep, size_t numElems, size_t byteSize); + // Allocates and then clears + +extern void NXZoneFree(malloc_zone_t *zone, void *ptr); + +extern void NXDestroyZone(malloc_zone_t *zone); + +extern NXZone *NXZoneFromPtr(void *ptr); + // Returns the zone for a pointer, or NX_NOZONE if not in any zone. + // The ptr must have been returned from a malloc or realloc call. + diff --git a/include/paths.h b/include/paths.h new file mode 100644 index 0000000..45a47aa --- /dev/null +++ b/include/paths.h @@ -0,0 +1,100 @@ +/* + * Copyright (c) 2000 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@ + */ +/* $OpenBSD: paths.h,v 1.10 1997/11/09 00:29:02 bri Exp $ */ +/* $NetBSD: paths.h,v 1.10 1997/04/23 09:41:38 lukem Exp $ */ + +/* + * Copyright (c) 1989, 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. + * + * @(#)paths.h 8.1 (Berkeley) 6/2/93 + */ + +#ifndef _PATHS_H_ +#define _PATHS_H_ + +/* Default search path. */ +#define _PATH_DEFPATH "/usr/bin:/bin" +/* All standard utilities path. */ +#define _PATH_STDPATH "/usr/bin:/bin:/usr/sbin:/sbin" + +#define _PATH_BSHELL "/bin/sh" +#define _PATH_CONSOLE "/dev/console" +#define _PATH_CSHELL "/bin/csh" +#define _PATH_DEFTAPE "/dev/nrst0" +#define _PATH_DEVDB "/var/run/dev.db" +#define _PATH_DEVNULL "/dev/null" +#define _PATH_DRUM "/dev/drum" +#define _PATH_FSIRAND "/sbin/fsirand" +#define _PATH_KMEM "/dev/kmem" +#define _PATH_KVMDB "/var/db/kvm.db" +#define _PATH_LOCALE "/usr/share/locale" +#define _PATH_MAILDIR "/var/mail" +#define _PATH_MAN "/usr/share/man" +#define _PATH_MEM "/dev/mem" +#define _PATH_NOLOGIN "/etc/nologin" +#define _PATH_RSH "/usr/bin/rsh" +#define _PATH_SENDMAIL "/usr/sbin/sendmail" +#define _PATH_SHELLS "/etc/shells" +#define _PATH_TTY "/dev/tty" +#define _PATH_UNIX "/mach" +#define _PATH_VI "/usr/bin/vi" + +/* Provide trailing slash, since mostly used for building pathnames. */ +#define _PATH_DEV "/dev/" +#define _PATH_TMP "/tmp/" +#define _PATH_UUCPLOCK "/var/spool/lock/" +#define _PATH_VARDB "/var/db/" +#define _PATH_VARRUN "/var/run/" +#define _PATH_VARTMP "/var/tmp/" + +#include + +#endif /* !_PATHS_H_ */ diff --git a/include/protocols/Makefile.inc b/include/protocols/Makefile.inc new file mode 100644 index 0000000..b7ea0cb --- /dev/null +++ b/include/protocols/Makefile.inc @@ -0,0 +1,6 @@ +PROTO_INSTHDRS += dumprestore.h \ + routed.h \ + rwhod.h \ + talkd.h \ + timed.h +PROTO_INSTHDRS := ${PROTO_INSTHDRS:S/^/${.CURDIR}\/include\/protocols\//} diff --git a/include/protocols/dumprestore.h b/include/protocols/dumprestore.h new file mode 100644 index 0000000..0912e7d --- /dev/null +++ b/include/protocols/dumprestore.h @@ -0,0 +1,133 @@ +/* + * Copyright (c) 2000 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@ + */ +/* + * Copyright (c) 1980, 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. + * + * @(#)dumprestore.h 8.2 (Berkeley) 1/21/94 + */ + +#ifndef _DUMPRESTORE_H_ +#define _DUMPRESTORE_H_ + +/* + * TP_BSIZE is the size of file blocks on the dump tapes. + * Note that TP_BSIZE must be a multiple of DEV_BSIZE. + * + * NTREC is the number of TP_BSIZE blocks that are written + * in each tape record. HIGHDENSITYTREC is the number of + * TP_BSIZE blocks that are written in each tape record on + * 6250 BPI or higher density tapes. + * + * TP_NINDIR is the number of indirect pointers in a TS_INODE + * or TS_ADDR record. Note that it must be a power of two. + */ +#define TP_BSIZE 1024 +#define NTREC 10 +#define HIGHDENSITYTREC 32 +#define TP_NINDIR (TP_BSIZE/2) +#define LBLSIZE 16 +#define NAMELEN 64 + +#define OFS_MAGIC (int)60011 +#define NFS_MAGIC (int)60012 +#define CHECKSUM (int)84446 + +union u_spcl { + char dummy[TP_BSIZE]; + struct s_spcl { + long c_type; /* record type (see below) */ + time_t c_date; /* date of this dump */ + time_t c_ddate; /* date of previous dump */ + long c_volume; /* dump volume number */ + daddr_t c_tapea; /* logical block of this record */ + ino_t c_inumber; /* number of inode */ + long c_magic; /* magic number (see above) */ + long c_checksum; /* record checksum */ + struct dinode c_dinode; /* ownership and mode of inode */ + long c_count; /* number of valid c_addr entries */ + char c_addr[TP_NINDIR]; /* 1 => data; 0 => hole in inode */ + char c_label[LBLSIZE]; /* dump label */ + long c_level; /* level of this dump */ + char c_filesys[NAMELEN]; /* name of dumpped file system */ + char c_dev[NAMELEN]; /* name of dumpped device */ + char c_host[NAMELEN]; /* name of dumpped host */ + long c_flags; /* additional information */ + long c_firstrec; /* first record on volume */ + long c_spare[32]; /* reserved for future uses */ + } s_spcl; +}; + +/* + * special record types + */ +#define TS_TAPE 1 /* dump tape header */ +#define TS_INODE 2 /* beginning of file record */ +#define TS_ADDR 4 /* continuation of file record */ +#define TS_BITS 3 /* map of inodes on tape */ +#define TS_CLRI 6 /* map of inodes deleted since last dump */ +#define TS_END 5 /* end of volume marker */ + +/* + * flag values + */ +#define DR_NEWHEADER 0x0001 /* new format tape header */ +#define DR_NEWINODEFMT 0x0002 /* new format inodes on tape */ + +#define DUMPOUTFMT "%-16s %c %s" /* for printf */ + /* name, level, ctime(date) */ +#define DUMPINFMT "%16s %c %[^\n]\n" /* inverse for scanf */ + +#endif /* !_DUMPRESTORE_H_ */ diff --git a/include/protocols/routed.h b/include/protocols/routed.h new file mode 100644 index 0000000..95533f3 --- /dev/null +++ b/include/protocols/routed.h @@ -0,0 +1,125 @@ +/* + * Copyright (c) 2000 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@ + */ +/*- + * Copyright (c) 1983, 1989, 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. + * + * @(#)routed.h 8.1 (Berkeley) 6/2/93 + */ + +#ifndef _ROUTED_H_ +#define _ROUTED_H_ + +/* + * Routing Information Protocol + * + * Derived from Xerox NS Routing Information Protocol + * by changing 32-bit net numbers to sockaddr's and + * padding stuff to 32-bit boundaries. + */ +#define RIPVERSION 1 + +struct netinfo { + struct sockaddr rip_dst; /* destination net/host */ + int rip_metric; /* cost of route */ +}; + +struct rip { + u_char rip_cmd; /* request/response */ + u_char rip_vers; /* protocol version # */ + u_char rip_res1[2]; /* pad to 32-bit boundary */ + union { + struct netinfo ru_nets[1]; /* variable length... */ + char ru_tracefile[1]; /* ditto ... */ + } ripun; +#define rip_nets ripun.ru_nets +#define rip_tracefile ripun.ru_tracefile +}; + +/* + * Packet types. + */ +#define RIPCMD_REQUEST 1 /* want info */ +#define RIPCMD_RESPONSE 2 /* responding to request */ +#define RIPCMD_TRACEON 3 /* turn tracing on */ +#define RIPCMD_TRACEOFF 4 /* turn it off */ + +#define RIPCMD_MAX 5 +#ifdef RIPCMDS +char *ripcmds[RIPCMD_MAX] = + { "#0", "REQUEST", "RESPONSE", "TRACEON", "TRACEOFF" }; +#endif + +#define HOPCNT_INFINITY 16 /* per Xerox NS */ +#define MAXPACKETSIZE 512 /* max broadcast size */ + +/* + * Timer values used in managing the routing table. + * Complete tables are broadcast every SUPPLY_INTERVAL seconds. + * If changes occur between updates, dynamic updates containing only changes + * may be sent. When these are sent, a timer is set for a random value + * between MIN_WAITTIME and MAX_WAITTIME, and no additional dynamic updates + * are sent until the timer expires. + * + * Every update of a routing entry forces an entry's timer to be reset. + * After EXPIRE_TIME without updates, the entry is marked invalid, + * but held onto until GARBAGE_TIME so that others may + * see it "be deleted". + */ +#define TIMER_RATE 30 /* alarm clocks every 30 seconds */ + +#define SUPPLY_INTERVAL 30 /* time to supply tables */ +#define MIN_WAITTIME 2 /* min. interval to broadcast changes */ +#define MAX_WAITTIME 5 /* max. time to delay changes */ + +#define EXPIRE_TIME 180 /* time to mark entry invalid */ +#define GARBAGE_TIME 240 /* time to garbage collect */ + +#endif /* !_ROUTED_H_ */ diff --git a/include/protocols/rwhod.h b/include/protocols/rwhod.h new file mode 100644 index 0000000..c054e63 --- /dev/null +++ b/include/protocols/rwhod.h @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2000 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@ + */ +/* + * Copyright (c) 1983, 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. + * + * @(#)rwhod.h 8.1 (Berkeley) 6/2/93 + */ + +#ifndef _RWHOD_H_ +#define _RWHOD_H_ + +/* + * rwho protocol packet format. + */ +struct outmp { + char out_line[8]; /* tty name */ + char out_name[8]; /* user id */ + long out_time; /* time on */ +}; + +struct whod { + char wd_vers; /* protocol version # */ + char wd_type; /* packet type, see below */ + char wd_pad[2]; + int wd_sendtime; /* time stamp by sender */ + int wd_recvtime; /* time stamp applied by receiver */ + char wd_hostname[32]; /* hosts's name */ + int wd_loadav[3]; /* load average as in uptime */ + int wd_boottime; /* time system booted */ + struct whoent { + struct outmp we_utmp; /* active tty info */ + int we_idle; /* tty idle time */ + } wd_we[1024 / sizeof (struct whoent)]; +}; + +#define WHODVERSION 1 +#define WHODTYPE_STATUS 1 /* host status */ + +#define _PATH_RWHODIR "/var/rwho" + +#endif /* !_RWHOD_H_ */ diff --git a/include/protocols/talkd.h b/include/protocols/talkd.h new file mode 100644 index 0000000..b8a2b97 --- /dev/null +++ b/include/protocols/talkd.h @@ -0,0 +1,135 @@ +/* + * Copyright (c) 2000 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@ + */ +/* + * Copyright (c) 1983, 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. + * + * @(#)talkd.h 8.1 (Berkeley) 6/2/93 + */ + +#ifndef _TALKD_H_ +#define _TALKD_H_ + +/* + * This describes the protocol used by the talk server and clients. + * + * The talk server acts a repository of invitations, responding to + * requests by clients wishing to rendezvous for the purpose of + * holding a conversation. In normal operation, a client, the caller, + * initiates a rendezvous by sending a CTL_MSG to the server of + * type LOOK_UP. This causes the server to search its invitation + * tables to check if an invitation currently exists for the caller + * (to speak to the callee specified in the message). If the lookup + * fails, the caller then sends an ANNOUNCE message causing the server + * to broadcast an announcement on the callee's login ports requesting + * contact. When the callee responds, the local server uses the + * recorded invitation to respond with the appropriate rendezvous + * address and the caller and callee client programs establish a + * stream connection through which the conversation takes place. + */ + +/* + * 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 */ +#define NAME_SIZE 12 + 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 */ +} 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 */ +} CTL_RESPONSE; + +#define TALK_VERSION 1 /* protocol version */ + +/* message type values */ +#define LEAVE_INVITE 0 /* leave invitation with server */ +#define LOOK_UP 1 /* check for invitation by callee */ +#define DELETE 2 /* delete invitation by caller */ +#define ANNOUNCE 3 /* announce invitation by caller */ + +/* answer values */ +#define SUCCESS 0 /* operation completed properly */ +#define NOT_HERE 1 /* callee not logged in */ +#define FAILED 2 /* operation failed for unexplained reason */ +#define MACHINE_UNKNOWN 3 /* caller's machine name unknown */ +#define PERMISSION_DENIED 4 /* callee's tty doesn't permit announce */ +#define UNKNOWN_REQUEST 5 /* request has invalid type value */ +#define BADVERSION 6 /* request has invalid protocol version */ +#define BADADDR 7 /* request has invalid addr value */ +#define BADCTLADDR 8 /* request has invalid ctl_addr value */ + +/* + * Operational parameters. + */ +#define MAX_LIFE 60 /* max time daemon saves invitations */ +/* RING_WAIT should be 10's of seconds less than MAX_LIFE */ +#define RING_WAIT 30 /* time to wait before resending invitation */ + +#endif /* !_TALKD_H_ */ diff --git a/include/protocols/timed.h b/include/protocols/timed.h new file mode 100644 index 0000000..e3e6263 --- /dev/null +++ b/include/protocols/timed.h @@ -0,0 +1,120 @@ +/* + * Copyright (c) 2000 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@ + */ +/* + * Copyright (c) 1983, 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. + * + * @(#)timed.h 8.1 (Berkeley) 6/2/93 + */ + +#ifndef _TIMED_H_ +#define _TIMED_H_ + +/* + * Time Synchronization Protocol + */ + +#define TSPVERSION 1 +#define ANYADDR NULL + +struct tsp { + u_char tsp_type; + u_char tsp_vers; + u_short tsp_seq; + union { + struct timeval tspu_time; + char tspu_hopcnt; + } tsp_u; + char tsp_name[MAXHOSTNAMELEN]; +}; + +#define tsp_time tsp_u.tspu_time +#define tsp_hopcnt tsp_u.tspu_hopcnt + +/* + * Command types. + */ +#define TSP_ANY 0 /* match any types */ +#define TSP_ADJTIME 1 /* send adjtime */ +#define TSP_ACK 2 /* generic acknowledgement */ +#define TSP_MASTERREQ 3 /* ask for master's name */ +#define TSP_MASTERACK 4 /* acknowledge master request */ +#define TSP_SETTIME 5 /* send network time */ +#define TSP_MASTERUP 6 /* inform slaves that master is up */ +#define TSP_SLAVEUP 7 /* slave is up but not polled */ +#define TSP_ELECTION 8 /* advance candidature for master */ +#define TSP_ACCEPT 9 /* support candidature of master */ +#define TSP_REFUSE 10 /* reject candidature of master */ +#define TSP_CONFLICT 11 /* two or more masters present */ +#define TSP_RESOLVE 12 /* masters' conflict resolution */ +#define TSP_QUIT 13 /* reject candidature if master is up */ +#define TSP_DATE 14 /* reset the time (date command) */ +#define TSP_DATEREQ 15 /* remote request to reset the time */ +#define TSP_DATEACK 16 /* acknowledge time setting */ +#define TSP_TRACEON 17 /* turn tracing on */ +#define TSP_TRACEOFF 18 /* turn tracing off */ +#define TSP_MSITE 19 /* find out master's site */ +#define TSP_MSITEREQ 20 /* remote master's site request */ +#define TSP_TEST 21 /* for testing election algo */ +#define TSP_SETDATE 22 /* New from date command */ +#define TSP_SETDATEREQ 23 /* New remote for above */ +#define TSP_LOOP 24 /* loop detection packet */ + +#define TSPTYPENUMBER 25 + +#ifdef TSPTYPES +char *tsptype[TSPTYPENUMBER] = + { "ANY", "ADJTIME", "ACK", "MASTERREQ", "MASTERACK", "SETTIME", "MASTERUP", + "SLAVEUP", "ELECTION", "ACCEPT", "REFUSE", "CONFLICT", "RESOLVE", "QUIT", + "DATE", "DATEREQ", "DATEACK", "TRACEON", "TRACEOFF", "MSITE", "MSITEREQ", + "TEST", "SETDATE", "SETDATEREQ", "LOOP" }; +#endif + +#endif /* !_TIMED_H_ */ diff --git a/include/pwd.h b/include/pwd.h new file mode 100644 index 0000000..91f6d91 --- /dev/null +++ b/include/pwd.h @@ -0,0 +1,128 @@ +/* + * Copyright (c) 2000 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@ + */ +/* $NetBSD: pwd.h,v 1.11 1997/08/16 13:47:21 lukem Exp $ */ + +/*- + * 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. + * Portions Copyright(C) 1995, Jason Downs. 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. + * + * @(#)pwd.h 8.2 (Berkeley) 1/21/94 + */ + +#ifndef _PWD_H_ +#define _PWD_H_ + +#include + +#ifndef _POSIX_SOURCE +#define _PATH_PASSWD "/etc/passwd" +#define _PATH_MASTERPASSWD "/etc/master.passwd" +#define _PATH_MASTERPASSWD_LOCK "/etc/ptmp" + +#define _PATH_MP_DB "/etc/pwd.db" +#define _PATH_SMP_DB "/etc/spwd.db" + +#define _PATH_PWD_MKDB "/usr/sbin/pwd_mkdb" + +#define _PW_KEYBYNAME '1' /* stored by name */ +#define _PW_KEYBYNUM '2' /* stored by entry in the "file" */ +#define _PW_KEYBYUID '3' /* stored by uid */ + +#define _PASSWORD_EFMT1 '_' /* extended encryption format */ + +#define _PASSWORD_LEN 128 /* max length, not counting NULL */ + +#define _PASSWORD_NOUID 0x01 /* flag for no specified uid. */ +#define _PASSWORD_NOGID 0x02 /* flag for no specified gid. */ +#define _PASSWORD_NOCHG 0x04 /* flag for no specified change. */ +#define _PASSWORD_NOEXP 0x08 /* flag for no specified expire. */ + +#define _PASSWORD_WARNDAYS 14 /* days to warn about expiry */ +#define _PASSWORD_CHGNOW -1 /* special day to force password + * change at next login */ +#endif + +struct passwd { + char *pw_name; /* user name */ + char *pw_passwd; /* encrypted password */ + uid_t pw_uid; /* user uid */ + gid_t pw_gid; /* user gid */ + 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 */ +}; + +#include + +__BEGIN_DECLS +struct passwd *getpwuid __P((uid_t)); +struct passwd *getpwnam __P((const char *)); +int getpwuid_r __P((uid_t, struct passwd *, char *, size_t, struct passwd **)); +int getpwnam_r __P((const char *, struct passwd *, char *, size_t, struct passwd **)); +#ifndef _POSIX_SOURCE +struct passwd *getpwent __P((void)); +#ifndef _XOPEN_SOURCE +int setpassent __P((int)); +#endif +int setpwent __P((void)); +void endpwent __P((void)); +#endif +__END_DECLS + +#endif /* !_PWD_H_ */ diff --git a/include/ranlib.h b/include/ranlib.h new file mode 100644 index 0000000..543b89a --- /dev/null +++ b/include/ranlib.h @@ -0,0 +1,100 @@ +/* + * Copyright (c) 2000 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@ + */ +/* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ +/* + * Copyright (c) 1990, 1982, 1985, 1986, 1988, 1993, 1994 + * 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. + * + * @(#)ranlib.h 8.1 (Berkeley) 6/2/93 + */ +#ifndef _RANLIB_H_ +#define _RANLIB_H_ + +#include /* off_t */ + +/* + * There are two known orders of table of contents for archives. The first is + * the order ranlib(1) originally produced and still produces without any + * options. This table of contents has the archive member name "__.SYMDEF" + * This order has the ranlib structures in the order the objects appear in the + * archive and the symbol names of those objects in the order of symbol table. + * The second know order is sorted by symbol name and is produced with the -s + * option to ranlib(1). This table of contents has the archive member name + * "__.SYMDEF SORTED" and many programs (notably the 1.0 version of ld(1) can't + * tell the difference between names because of the imbedded blank in the name + * and works with either table of contents). This second order is used by the + * post 1.0 link editor to produce faster linking. The original 1.0 version of + * ranlib(1) gets confused when it is run on a archive with the second type of + * table of contents because it and ar(1) which it uses use different ways to + * determined the member name (ar(1) treats all blanks in the name as + * significant and ranlib(1) only checks for the first one). + */ +#define SYMDEF "__.SYMDEF" +#define SYMDEF_SORTED "__.SYMDEF SORTED" + +#define RANLIBMAG "__.SYMDEF" /* archive file name */ +#define RANLIBSKEW 3 /* creation time offset */ + +/* + * Structure of the __.SYMDEF table of contents for an archive. + * __.SYMDEF begins with a long giving the size in bytes of the ranlib + * structures which immediately follow, and then continues with a string + * table consisting of a long giving the number of bytes of strings which + * follow and then the strings themselves. The ran_strx fields index the + * string table whose first byte is numbered 0. + */ +struct ranlib { + union { + off_t ran_strx; /* string table index of */ + char *ran_name; /* symbol defined by */ + } ran_un; + off_t ran_off; /* library member at this offset */ +}; +#endif /* ! _RANLIB_H_ */ diff --git a/include/regex.h b/include/regex.h new file mode 100644 index 0000000..ad48247 --- /dev/null +++ b/include/regex.h @@ -0,0 +1,127 @@ +/* + * Copyright (c) 2000 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@ + */ +/*- + * Copyright (c) 1992 Henry Spencer. + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Henry Spencer of the University of Toronto. + * + * 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. + * + * @(#)regex.h 8.2 (Berkeley) 1/3/94 + */ + +#ifndef _REGEX_H_ +#define _REGEX_H_ + +#include + +/* types */ +typedef off_t regoff_t; + +typedef struct { + int re_magic; + size_t re_nsub; /* number of parenthesized subexpressions */ + __const char *re_endp; /* end pointer for REG_PEND */ + struct re_guts *re_g; /* none of your business :-) */ +} regex_t; + +typedef struct { + regoff_t rm_so; /* start of match */ + regoff_t rm_eo; /* end of match */ +} regmatch_t; + +/* regcomp() flags */ +#define REG_BASIC 0000 +#define REG_EXTENDED 0001 +#define REG_ICASE 0002 +#define REG_NOSUB 0004 +#define REG_NEWLINE 0010 +#define REG_NOSPEC 0020 +#define REG_PEND 0040 +#define REG_DUMP 0200 + +/* regerror() flags */ +#define REG_NOMATCH 1 +#define REG_BADPAT 2 +#define REG_ECOLLATE 3 +#define REG_ECTYPE 4 +#define REG_EESCAPE 5 +#define REG_ESUBREG 6 +#define REG_EBRACK 7 +#define REG_EPAREN 8 +#define REG_EBRACE 9 +#define REG_BADBR 10 +#define REG_ERANGE 11 +#define REG_ESPACE 12 +#define REG_BADRPT 13 +#define REG_EMPTY 14 +#define REG_ASSERT 15 +#define REG_INVARG 16 +#define REG_ATOI 255 /* convert name to number (!) */ +#define REG_ITOA 0400 /* convert number to name (!) */ + +/* regexec() flags */ +#define REG_NOTBOL 00001 +#define REG_NOTEOL 00002 +#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 */ + +__BEGIN_DECLS +int regcomp __P((regex_t *, const char *, int)); +size_t regerror __P((int, const regex_t *, char *, size_t)); +int regexec __P((const regex_t *, + const char *, size_t, regmatch_t [], int)); +void regfree __P((regex_t *)); +__END_DECLS + +#endif /* !_REGEX_H_ */ diff --git a/include/regexp.h b/include/regexp.h new file mode 100644 index 0000000..97ce7e4 --- /dev/null +++ b/include/regexp.h @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2000 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@ + */ +/* + * 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 + +__BEGIN_DECLS +regexp *regcomp __P((const char *)); +int regexec __P((const regexp *, const char *)); +void regsub __P((const regexp *, const char *, char *)); +void regerror __P((const char *)); +__END_DECLS + +#endif /* !_REGEXP_H_ */ diff --git a/include/rune.h b/include/rune.h new file mode 100644 index 0000000..c1e2b88 --- /dev/null +++ b/include/rune.h @@ -0,0 +1,66 @@ +/*- + * 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.h 8.1 (Berkeley) 6/27/93 + */ + +#ifndef _RUNE_H_ +#define _RUNE_H_ + +#include +#include + +#define _PATH_LOCALE "/usr/share/locale" + +#define _INVALID_RUNE _CurrentRuneLocale->invalid_rune + +#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 __P((const char *, rune_t)); +char *mbrrune __P((const char *, rune_t)); +char *mbmb __P((const char *, char *)); +long fgetrune __P((FILE *)); +int fputrune __P((rune_t, FILE *)); +int fungetrune __P((rune_t, FILE *)); +int setrunelocale __P((char *)); +void setinvalidrune __P((rune_t)); +__END_DECLS + +#endif /*! _RUNE_H_ */ diff --git a/include/runetype.h b/include/runetype.h new file mode 100644 index 0000000..84ce83f --- /dev/null +++ b/include/runetype.h @@ -0,0 +1,110 @@ +/*- + * 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. + * + * @(#)runetype.h 8.1 (Berkeley) 6/2/93 + */ + +#ifndef _RUNETYPE_H_ +#define _RUNETYPE_H_ + +#include +#include + +#ifndef _BSD_RUNE_T_DEFINED_ +#define _BSD_RUNE_T_DEFINED_ +typedef _BSD_RUNE_T_ rune_t; +#endif + +#ifndef _BSD_SIZE_T_DEFINED_ +#define _BSD_SIZE_T_DEFINED_ +typedef _BSD_SIZE_T_ size_t; +#endif + +#ifndef _BSD_WCHAR_T_DEFINED_ +#define _BSD_WCHAR_T_DEFINED_ +typedef _BSD_WCHAR_T_ wchar_t; +#endif + +#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 */ +} _RuneEntry; + +typedef struct { + 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 */ + + rune_t (*sgetrune) + __P((const char *, size_t, char const **)); + int (*sputrune) + __P((rune_t, char *, size_t, char **)); + rune_t invalid_rune; + + unsigned long runetype[_CACHED_RUNES]; + rune_t maplower[_CACHED_RUNES]; + 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; + + 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 */ + +extern _RuneLocale _DefaultRuneLocale; +extern _RuneLocale *_CurrentRuneLocale; + +#endif /* !_RUNETYPE_H_ */ diff --git a/include/semaphore.h b/include/semaphore.h new file mode 100644 index 0000000..bde387f --- /dev/null +++ b/include/semaphore.h @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2000 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 _BSD_SEMAPHORE_H +#define _BSD_SEMAPHORE_H + +#include +#include + +#include + +#endif /* _BSD_SEMAPHORE_H */ diff --git a/include/setjmp.h b/include/setjmp.h new file mode 100644 index 0000000..51c8fd8 --- /dev/null +++ b/include/setjmp.h @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2000 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 _BSD_SETJMP_H +#define _BSD_SETJMP_H + +#include + +#endif /* _BSD_SETJMP_H */ diff --git a/include/sgtty.h b/include/sgtty.h new file mode 100644 index 0000000..59081aa --- /dev/null +++ b/include/sgtty.h @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2000 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@ + */ +/* + * Copyright (c) 1985, 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. + * + * @(#)sgtty.h 8.1 (Berkeley) 6/2/93 + */ + +#ifndef USE_OLD_TTY +#define USE_OLD_TTY +#endif +#include diff --git a/include/signal.h b/include/signal.h new file mode 100644 index 0000000..704547b --- /dev/null +++ b/include/signal.h @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2000 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@ + */ +/*- + * 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. + * + * @(#)signal.h 8.3 (Berkeley) 3/30/94 + */ + +#ifndef _USER_SIGNAL_H +#define _USER_SIGNAL_H + +#include +#include +#include + +#if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE) +extern __const char *__const sys_signame[NSIG]; +extern __const char *__const sys_siglist[NSIG]; +#endif + +__BEGIN_DECLS +int raise __P((int)); +#ifndef _ANSI_SOURCE +int kill __P((pid_t, int)); +int sigaction __P((int, const struct sigaction *, struct sigaction *)); +int sigaddset __P((sigset_t *, int)); +int sigdelset __P((sigset_t *, int)); +int sigemptyset __P((sigset_t *)); +int sigfillset __P((sigset_t *)); +int sigismember __P((const sigset_t *, int)); +int sigpending __P((sigset_t *)); +int sigprocmask __P((int, const sigset_t *, sigset_t *)); +int sigsuspend __P((const sigset_t *)); +#ifndef _POSIX_SOURCE +int killpg __P((pid_t, int)); +int sigblock __P((int)); +int siginterrupt __P((int, int)); +int sighold __P((int)); +int sigrelse __P((int)); +int sigpause __P((int)); +int sigreturn __P((struct sigcontext *)); +int sigsetmask __P((int)); +int sigvec __P((int, struct sigvec *, struct sigvec *)); +void psignal __P((unsigned int, const char *)); +#endif /* !_POSIX_SOURCE */ +#endif /* !_ANSI_SOURCE */ +__END_DECLS + +/* List definitions after function declarations, or Reiser cpp gets upset. */ +#define sigaddset(set, signo) (*(set) |= 1 << ((signo) - 1), 0) +#define sigdelset(set, signo) (*(set) &= ~(1 << ((signo) - 1)), 0) +#define sigemptyset(set) (*(set) = 0, 0) +#define sigfillset(set) (*(set) = ~(sigset_t)0, 0) +#define sigismember(set, signo) ((*(set) & (1 << ((signo) - 1))) != 0) + +#endif /* !_USER_SIGNAL_H */ diff --git a/include/stab.h b/include/stab.h new file mode 100644 index 0000000..e4ee83e --- /dev/null +++ b/include/stab.h @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2000 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@ + */ +/*- + * 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. + * + * @(#)stab.h 8.1 (Berkeley) 6/2/93 + */ + +/* + * The following are symbols used by various debuggers and by the Pascal + * compiler. Each of them must have one (or more) of the bits defined by + * the N_STAB mask set. + */ + +#define N_GSYM 0x20 /* global symbol */ +#define N_FNAME 0x22 /* F77 function name */ +#define N_FUN 0x24 /* procedure name */ +#define N_STSYM 0x26 /* data segment variable */ +#define N_LCSYM 0x28 /* bss segment variable */ +#define N_MAIN 0x2a /* main function name */ +#define N_PC 0x30 /* global Pascal symbol */ +#define N_RSYM 0x40 /* register variable */ +#define N_SLINE 0x44 /* text segment line number */ +#define N_DSLINE 0x46 /* data segment line number */ +#define N_BSLINE 0x48 /* bss segment line number */ +#define N_SSYM 0x60 /* structure/union element */ +#define N_SO 0x64 /* main source file name */ +#define N_LSYM 0x80 /* stack variable */ +#define N_BINCL 0x82 /* include file beginning */ +#define N_SOL 0x84 /* included source file name */ +#define N_PSYM 0xa0 /* parameter variable */ +#define N_EINCL 0xa2 /* include file end */ +#define N_ENTRY 0xa4 /* alternate entry point */ +#define N_LBRAC 0xc0 /* left bracket */ +#define N_EXCL 0xc2 /* deleted include file */ +#define N_RBRAC 0xe0 /* right bracket */ +#define N_BCOMM 0xe2 /* begin common */ +#define N_ECOMM 0xe4 /* end common */ +#define N_ECOML 0xe8 /* end common (local name) */ +#define N_LENG 0xfe /* length of preceding entry */ diff --git a/include/standards.h b/include/standards.h new file mode 100644 index 0000000..934b381 --- /dev/null +++ b/include/standards.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ + +#ifndef _STANDARDS_H +#define _STANDARDS_H + +#ifdef _POSIX_SOURCE + #ifndef __STRICT_ANSI__ + #define __STRICT_ANSI__ + #endif + #undef __STRICT_BSD__ +#endif /* _POSIX_SOURCE */ + +#endif /* _STANDARDS_H */ diff --git a/include/stddef.h b/include/stddef.h new file mode 100644 index 0000000..6835ac5 --- /dev/null +++ b/include/stddef.h @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2000 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@ + */ +/* $OpenBSD: stddef.h,v 1.2 1997/09/21 10:45:52 niklas Exp $ */ +/* $NetBSD: stddef.h,v 1.4 1994/10/26 00:56:26 cgd Exp $ */ + +/*- + * Copyright (c) 1990 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. + * + * @(#)stddef.h 5.5 (Berkeley) 4/3/91 + */ + +#ifndef __STDDEF_H__ +#define __STDDEF_H__ + +#include +#include + +typedef _BSD_PTRDIFF_T_ ptrdiff_t; + +#ifndef _BSD_SIZE_T_DEFINED_ +#define _BSD_SIZE_T_DEFINED_ +typedef _BSD_SIZE_T_ size_t; +#endif + +#if !defined(_ANSI_SOURCE) +#ifndef _BSD_RUNE_T_DEFINED_ +#define _BSD_RUNE_T_DEFINED_ +typedef _BSD_RUNE_T_ rune_t; +#endif +#endif + +#ifndef _BSD_WCHAR_T_DEFINED_ +#define _BSD_WCHAR_T_DEFINED_ +typedef _BSD_WCHAR_T_ wchar_t; +#endif + +#ifndef NULL +#define NULL 0 +#endif + +#define offsetof(type, member) __offsetof(type, member) + +#endif /* __STDDEF_H__ */ diff --git a/include/stdio.h b/include/stdio.h new file mode 100644 index 0000000..e87d94a --- /dev/null +++ b/include/stdio.h @@ -0,0 +1,404 @@ +/* + * Copyright (c) 2000 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@ + */ +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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. + * + * @(#)stdio.h 8.5 (Berkeley) 4/29/95 + */ + +#ifndef _STDIO_H_ +#define _STDIO_H_ + +#if !defined(_ANSI_SOURCE) && !defined(__STRICT_ANSI__) +#include +#endif + +#include + +#include +#ifndef _BSD_SIZE_T_DEFINED_ +#define _BSD_SIZE_T_DEFINED_ +typedef _BSD_SIZE_T_ size_t; +#endif + +#ifndef NULL +#define NULL 0 +#endif + +/* + * This is fairly grotesque, but pure ANSI code must not inspect the + * innards of an fpos_t anyway. The library internally uses off_t, + * which we assume is exactly as big as eight chars. (When we switch + * to gcc 2.4 we will use __attribute__ here.) + * + * WARNING: the alignment constraints on an off_t and the struct below + * differ on (e.g.) the SPARC. Hence, the placement of an fpos_t object + * in a structure will change if fpos_t's are not aligned on 8-byte + * boundaries. THIS IS A CROCK, but for now there is no way around it. + */ +#if !defined(_ANSI_SOURCE) && !defined(__STRICT_ANSI__) +typedef off_t fpos_t; +#else +typedef struct __sfpos { + char _pos[8]; +} fpos_t; +#endif + +#define _FSTDIO /* Define for new stdio with functions. */ + +/* + * NB: to fit things in six character monocase externals, the stdio + * code uses the prefix `__s' for stdio objects, typically followed + * by a three-character attempt at a mnemonic. + */ + +/* stdio buffers */ +struct __sbuf { + unsigned char *_base; + int _size; +}; + +/* + * stdio state variables. + * + * The following always hold: + * + * if (_flags&(__SLBF|__SWR)) == (__SLBF|__SWR), + * _lbfsize is -_bf._size, else _lbfsize is 0 + * if _flags&__SRD, _w is 0 + * if _flags&__SWR, _r is 0 + * + * This ensures that the getc and putc macros (or inline functions) never + * try to write or read from a file that is in `read' or `write' mode. + * (Moreover, they can, and do, automatically switch from read mode to + * write mode, and back, on "r+" and "w+" files.) + * + * _lbfsize is used only to make the inline line-buffered output stream + * code as compact as possible. + * + * _ub, _up, and _ur are used when ungetc() pushes back more characters + * than fit in the current _bf, or when ungetc() pushes back a character + * that does not match the previous one in _bf. When this happens, + * _ub._base becomes non-nil (i.e., a stream has ungetc() data iff + * _ub._base!=NULL) and _up and _ur save the current values of _p and _r. + * + * NB: see WARNING above before changing the layout of this structure! + */ +typedef struct __sFILE { + unsigned char *_p; /* current position in (some) buffer */ + int _r; /* read space left for getc() */ + int _w; /* write space left for putc() */ + short _flags; /* flags, below; this FILE is free if 0 */ + short _file; /* fileno, if Unix descriptor, else -1 */ + struct __sbuf _bf; /* the buffer (at least 1 byte, if !NULL) */ + int _lbfsize; /* 0 or -_bf._size, for inline putc */ + + /* operations */ + void *_cookie; /* cookie passed to io functions */ + int (*_close) __P((void *)); + int (*_read) __P((void *, char *, int)); + fpos_t (*_seek) __P((void *, fpos_t, int)); + int (*_write) __P((void *, const char *, int)); + + /* separate buffer for long sequences of ungetc() */ + struct __sbuf _ub; /* ungetc buffer */ + unsigned char *_up; /* saved _p when _p is doing ungetc data */ + int _ur; /* saved _r when _r is counting ungetc data */ + + /* tricks to meet minimum requirements even when malloc() fails */ + unsigned char _ubuf[3]; /* guarantee an ungetc() buffer */ + unsigned char _nbuf[1]; /* guarantee a getc() buffer */ + + /* separate buffer for fgetln() when line crosses buffer boundary */ + struct __sbuf _lb; /* buffer for fgetln() */ + + /* Unix stdio files get aligned to block boundaries on fseek() */ + int _blksize; /* stat.st_blksize (may be != _bf._size) */ + fpos_t _offset; /* current lseek offset (see WARNING) */ +} FILE; + +__BEGIN_DECLS +extern FILE __sF[]; +__END_DECLS + +#define __SLBF 0x0001 /* line buffered */ +#define __SNBF 0x0002 /* unbuffered */ +#define __SRD 0x0004 /* OK to read */ +#define __SWR 0x0008 /* OK to write */ + /* RD and WR are never simultaneously asserted */ +#define __SRW 0x0010 /* open for reading & writing */ +#define __SEOF 0x0020 /* found EOF */ +#define __SERR 0x0040 /* found error */ +#define __SMBF 0x0080 /* _buf is from malloc */ +#define __SAPP 0x0100 /* fdopen()ed in append mode */ +#define __SSTR 0x0200 /* this is an sprintf/snprintf string */ +#define __SOPT 0x0400 /* do fseek() optimisation */ +#define __SNPT 0x0800 /* do not do fseek() optimisation */ +#define __SOFF 0x1000 /* set iff _offset is in fact correct */ +#define __SMOD 0x2000 /* true => fgetln modified _p text */ +#define __SALC 0x4000 /* allocate string space dynamically */ + +/* + * The following three definitions are for ANSI C, which took them + * from System V, which brilliantly took internal interface macros and + * made them official arguments to setvbuf(), without renaming them. + * Hence, these ugly _IOxxx names are *supposed* to appear in user code. + * + * Although numbered as their counterparts above, the implementation + * does not rely on this. + */ +#define _IOFBF 0 /* setvbuf should set fully buffered */ +#define _IOLBF 1 /* setvbuf should set line buffered */ +#define _IONBF 2 /* setvbuf should set unbuffered */ + +#define BUFSIZ 1024 /* size of buffer used by setbuf */ +#define EOF (-1) + +/* + * FOPEN_MAX is a minimum maximum, and is the number of streams that + * stdio can provide without attempting to allocate further resources + * (which could fail). Do not use this for anything. + */ + /* must be == _POSIX_STREAM_MAX */ +#define FOPEN_MAX 20 /* must be <= OPEN_MAX */ +#define FILENAME_MAX 1024 /* must be <= PATH_MAX */ + +/* System V/ANSI C; this is the wrong way to do this, do *not* use these. */ +#ifndef _ANSI_SOURCE +#define P_tmpdir "/var/tmp/" +#endif +#define L_tmpnam 1024 /* XXX must be == PATH_MAX */ +#define TMP_MAX 308915776 + +#ifndef SEEK_SET +#define SEEK_SET 0 /* set file offset to offset */ +#endif +#ifndef SEEK_CUR +#define SEEK_CUR 1 /* set file offset to current plus offset */ +#endif +#ifndef SEEK_END +#define SEEK_END 2 /* set file offset to EOF plus offset */ +#endif + +#define stdin (&__sF[0]) +#define stdout (&__sF[1]) +#define stderr (&__sF[2]) + +/* + * Functions defined in ANSI C standard. + */ +__BEGIN_DECLS +void clearerr __P((FILE *)); +int fclose __P((FILE *)); +int feof __P((FILE *)); +int ferror __P((FILE *)); +int fflush __P((FILE *)); +int fgetc __P((FILE *)); +int fgetpos __P((FILE *, fpos_t *)); +char *fgets __P((char *, int, FILE *)); +FILE *fopen __P((const char *, const char *)); +int fprintf __P((FILE *, const char *, ...)); +int fputc __P((int, FILE *)); +int fputs __P((const char *, FILE *)); +size_t fread __P((void *, size_t, size_t, FILE *)); +FILE *freopen __P((const char *, const char *, FILE *)); +int fscanf __P((FILE *, const char *, ...)); +int fseek __P((FILE *, long, int)); +int fsetpos __P((FILE *, const fpos_t *)); +long ftell __P((FILE *)); +size_t fwrite __P((const void *, size_t, size_t, FILE *)); +int getc __P((FILE *)); +int getchar __P((void)); +char *gets __P((char *)); +#if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE) +extern __const int sys_nerr; /* perror(3) external variables */ +extern __const char *__const sys_errlist[]; +#endif +void perror __P((const char *)); +int printf __P((const char *, ...)); +int putc __P((int, FILE *)); +int putchar __P((int)); +int puts __P((const char *)); +int remove __P((const char *)); +int rename __P((const char *, const char *)); +void rewind __P((FILE *)); +int scanf __P((const char *, ...)); +void setbuf __P((FILE *, char *)); +int setvbuf __P((FILE *, char *, int, size_t)); +int sprintf __P((char *, const char *, ...)); +int sscanf __P((const char *, const char *, ...)); +FILE *tmpfile __P((void)); +char *tmpnam __P((char *)); +int ungetc __P((int, FILE *)); +int vfprintf __P((FILE *, const char *, _BSD_VA_LIST_)); +int vprintf __P((const char *, _BSD_VA_LIST_)); +int vsprintf __P((char *, const char *, _BSD_VA_LIST_)); +int asprintf __P((char **, const char *, ...)); +int vasprintf __P((char **, const char *, _BSD_VA_LIST_)); +__END_DECLS + +/* + * Functions defined in POSIX 1003.1. + */ +#ifndef _ANSI_SOURCE +#define L_cuserid 9 /* size for cuserid(); UT_NAMESIZE + 1 */ +#define L_ctermid 1024 /* size for ctermid(); PATH_MAX */ + +__BEGIN_DECLS +char *ctermid __P((char *)); +FILE *fdopen __P((int, const char *)); +int fileno __P((FILE *)); +__END_DECLS +#endif /* not ANSI */ + +/* + * Routines that are purely local. + */ +#if !defined (_ANSI_SOURCE) && !defined(_POSIX_SOURCE) +__BEGIN_DECLS +char *fgetln __P((FILE *, size_t *)); +int fpurge __P((FILE *)); +int fseeko __P((FILE *, fpos_t, int)); +fpos_t ftello __P((FILE *)); +int getw __P((FILE *)); +int pclose __P((FILE *)); +FILE *popen __P((const char *, const char *)); +int putw __P((int, FILE *)); +void setbuffer __P((FILE *, char *, int)); +int setlinebuf __P((FILE *)); +char *tempnam __P((const char *, const char *)); +int snprintf __P((char *, size_t, const char *, ...)); +int vsnprintf __P((char *, size_t, const char *, _BSD_VA_LIST_)); +int vscanf __P((const char *, _BSD_VA_LIST_)); +int vsscanf __P((const char *, const char *, _BSD_VA_LIST_)); +FILE *zopen __P((const char *, const char *, int)); +__END_DECLS + +/* + * This is a #define because the function is used internally and + * (unlike vfscanf) the name __svfscanf is guaranteed not to collide + * with a user function when _ANSI_SOURCE or _POSIX_SOURCE is defined. + */ +#define vfscanf __svfscanf + +/* + * Stdio function-access interface. + */ +__BEGIN_DECLS +FILE *funopen __P((const void *, + int (*)(void *, char *, int), + int (*)(void *, const char *, int), + fpos_t (*)(void *, fpos_t, int), + int (*)(void *))); +__END_DECLS +#define fropen(cookie, fn) funopen(cookie, fn, 0, 0, 0) +#define fwopen(cookie, fn) funopen(cookie, 0, fn, 0, 0) +#endif /* !_ANSI_SOURCE && !_POSIX_SOURCE */ + +/* + * Functions internal to the implementation. + */ +__BEGIN_DECLS +int __srget __P((FILE *)); +int __svfscanf __P((FILE *, const char *, _BSD_VA_LIST_)); +int __swbuf __P((int, FILE *)); +__END_DECLS + +/* + * The __sfoo macros are here so that we can + * define function versions in the C library. + */ +#define __sgetc(p) (--(p)->_r < 0 ? __srget(p) : (int)(*(p)->_p++)) +#if defined(__GNUC__) && defined(__STDC__) +static __inline int __sputc(int _c, FILE *_p) { + if (--_p->_w >= 0 || (_p->_w >= _p->_lbfsize && (char)_c != '\n')) + return (*_p->_p++ = _c); + else + return (__swbuf(_c, _p)); +} +#else +/* + * This has been tuned to generate reasonable code on the vax using pcc. + */ +#define __sputc(c, p) \ + (--(p)->_w < 0 ? \ + (p)->_w >= (p)->_lbfsize ? \ + (*(p)->_p = (c)), *(p)->_p != '\n' ? \ + (int)*(p)->_p++ : \ + __swbuf('\n', p) : \ + __swbuf((int)(c), p) : \ + (*(p)->_p = (c), (int)*(p)->_p++)) +#endif + +#define __sfeof(p) (((p)->_flags & __SEOF) != 0) +#define __sferror(p) (((p)->_flags & __SERR) != 0) +#define __sclearerr(p) ((void)((p)->_flags &= ~(__SERR|__SEOF))) +#define __sfileno(p) ((p)->_file) + +#define feof(p) __sfeof(p) +#define ferror(p) __sferror(p) +#define clearerr(p) __sclearerr(p) + +#ifndef _ANSI_SOURCE +#define fileno(p) __sfileno(p) +#endif + +#ifndef lint +#define getc(fp) __sgetc(fp) +#define putc(x, fp) __sputc(x, fp) +#endif /* lint */ + +#define getchar() getc(stdin) +#define putchar(x) putc(x, stdout) +#endif /* _STDIO_H_ */ diff --git a/include/stdlib.h b/include/stdlib.h new file mode 100644 index 0000000..4e79128 --- /dev/null +++ b/include/stdlib.h @@ -0,0 +1,218 @@ +/* + * Copyright (c) 2000 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@ + */ +/*- + * Copyright (c) 1990, 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. + * + * @(#)stdlib.h 8.5 (Berkeley) 5/19/95 + */ + +#ifndef _STDLIB_H_ +#define _STDLIB_H_ + +#include +#include + +#ifndef _BSD_SIZE_T_DEFINED_ +#define _BSD_SIZE_T_DEFINED_ +typedef _BSD_SIZE_T_ size_t; +#endif + +#if !defined(_ANSI_SOURCE) +#ifndef _BSD_RUNE_T_DEFINED_ +#define _BSD_RUNE_T_DEFINED_ +typedef _BSD_WCHAR_T_ rune_t; +#endif +#endif + +#ifndef _BSD_WCHAR_T_DEFINED_ +#define _BSD_WCHAR_T_DEFINED_ +typedef _BSD_WCHAR_T_ wchar_t; +#endif + +typedef struct { + int quot; /* quotient */ + int rem; /* remainder */ +} div_t; + +typedef struct { + long quot; /* quotient */ + long rem; /* remainder */ +} ldiv_t; + +#ifndef NULL +#define NULL 0 +#endif + +#define EXIT_FAILURE 1 +#define EXIT_SUCCESS 0 + +#define RAND_MAX 0x7fffffff + +extern int __mb_cur_max; +#define MB_CUR_MAX __mb_cur_max + +#include + +__BEGIN_DECLS +__dead void + abort __P((void)); +__pure int + abs __P((int)); +int atexit __P((void (*)(void))); +double atof __P((const char *)); +int atoi __P((const char *)); +long atol __P((const char *)); +void *bsearch __P((const void *, const void *, size_t, + size_t, int (*)(const void *, const void *))); +void *calloc __P((size_t, size_t)); +__pure div_t + div __P((int, int)); +__dead void + exit __P((int)); +void free __P((void *)); +char *getenv __P((const char *)); +__pure long + labs __P((long)); +__pure ldiv_t + ldiv __P((long, long)); +void *malloc __P((size_t)); +void qsort __P((void *, size_t, size_t, + int (*)(const void *, const void *))); +int rand __P((void)); +void *realloc __P((void *, size_t)); +void srand __P((unsigned)); +double strtod __P((const char *, char **)); +long strtol __P((const char *, char **, int)); +unsigned long + strtoul __P((const char *, char **, int)); +int system __P((const char *)); + +/* These are currently just stubs. */ +int mblen __P((const char *, size_t)); +size_t mbstowcs __P((wchar_t *, const char *, size_t)); +int wctomb __P((char *, wchar_t)); +int mbtowc __P((wchar_t *, const char *, size_t)); +size_t wcstombs __P((char *, const wchar_t *, size_t)); + +#ifndef _ANSI_SOURCE +int putenv __P((const char *)); +int setenv __P((const char *, const char *, int)); +#endif + +#if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE) +double drand48 __P((void)); +double erand48 __P((unsigned short[3])); +long jrand48 __P((unsigned short[3])); +void lcong48 __P((unsigned short[7])); +long lrand48 __P((void)); +long mrand48 __P((void)); +long nrand48 __P((unsigned short[3])); +unsigned short + *seed48 __P((unsigned short[3])); +void srand48 __P((long)); + +void *alloca __P((size_t)); /* built-in for gcc */ + /* getcap(3) functions */ +u_int32_t + arc4random __P((void)); +void arc4random_addrandom __P((unsigned char *dat, int datlen)); +void arc4random_stir __P((void)); +char *getbsize __P((int *, long *)); +char *cgetcap __P((char *, char *, int)); +int cgetclose __P((void)); +int cgetent __P((char **, char **, char *)); +int cgetfirst __P((char **, char **)); +int cgetmatch __P((char *, char *)); +int cgetnext __P((char **, char **)); +int cgetnum __P((char *, char *, long *)); +int cgetset __P((char *)); +int cgetstr __P((char *, char *, char **)); +int cgetustr __P((char *, char *, char **)); + +int daemon __P((int, int)); +char *devname __P((int, int)); +int getloadavg __P((double [], int)); + +long a64l __P((const char *)); +char *l64a __P((long)); + +char *group_from_gid __P((unsigned long, int)); +int heapsort __P((void *, size_t, size_t, + int (*)(const void *, const void *))); +char *initstate __P((unsigned long, char *, long)); +int mergesort __P((void *, size_t, size_t, + int (*)(const void *, const void *))); +int radixsort __P((const unsigned char **, int, const unsigned char *, + unsigned)); +int sradixsort __P((const unsigned char **, int, const unsigned char *, + unsigned)); +int rand_r __P((unsigned *)); +long random __P((void)); +void *reallocf __P((void *, size_t)); +char *realpath __P((const char *, char resolved_path[])); +char *setstate __P((char *)); +void srandom __P((unsigned long)); +char *user_from_uid __P((unsigned long, int)); +#ifndef __STRICT_ANSI__ +long long + strtoll(const char *, char **, int); +unsigned long long + strtoull(const char *, char **, int); +long long + strtoq __P((const char *, char **, int)); +unsigned long long + strtouq __P((const char *, char **, int)); +#endif +void unsetenv __P((const char *)); +#endif +__END_DECLS + +#endif /* _STDLIB_H_ */ diff --git a/include/string.h b/include/string.h new file mode 100644 index 0000000..7c63b12 --- /dev/null +++ b/include/string.h @@ -0,0 +1,117 @@ +/* + * Copyright (c) 2000 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@ + */ +/*- + * Copyright (c) 1990, 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. + * + * @(#)string.h 8.1 (Berkeley) 6/2/93 + */ + +#ifndef _STRING_H_ +#define _STRING_H_ +#include + +#ifndef _BSD_SIZE_T_DEFINED_ +#define _BSD_SIZE_T_DEFINED_ +typedef _BSD_SIZE_T_ size_t; +#endif + +#ifndef NULL +#define NULL 0 +#endif + +#include + +__BEGIN_DECLS +void *memchr __P((const void *, int, size_t)); +int memcmp __P((const void *, const void *, size_t)); +void *memcpy __P((void *, const void *, size_t)); +void *memmove __P((void *, const void *, size_t)); +void *memset __P((void *, int, size_t)); +char *strcat __P((char *, const char *)); +char *strchr __P((const char *, int)); +int strcmp __P((const char *, const char *)); +int strcoll __P((const char *, const char *)); +char *strcpy __P((char *, const char *)); +size_t strcspn __P((const char *, const char *)); +char *strerror __P((int)); +size_t strlen __P((const char *)); +char *strncat __P((char *, const char *, size_t)); +int strncmp __P((const char *, const char *, size_t)); +char *strncpy __P((char *, const char *, size_t)); +char *strpbrk __P((const char *, const char *)); +char *strrchr __P((const char *, int)); +size_t strspn __P((const char *, const char *)); +char *strstr __P((const char *, const char *)); +char *strtok __P((char *, const char *)); +size_t strxfrm __P((char *, const char *, size_t)); + +/* Nonstandard routines */ +#ifndef _ANSI_SOURCE +int bcmp __P((const void *, const void *, size_t)); +void bcopy __P((const void *, void *, size_t)); +void bzero __P((void *, size_t)); +int ffs __P((int)); +char *index __P((const char *, int)); +void *memccpy __P((void *, const void *, int, size_t)); +char *rindex __P((const char *, int)); +int strcasecmp __P((const char *, const char *)); +char *strdup __P((const char *)); +size_t strlcat __P((char *, const char *, size_t)); +size_t strlcpy __P((char *, const char *, size_t)); +void strmode __P((int, char *)); +int strncasecmp __P((const char *, const char *, size_t)); +char *strsep __P((char **, const char *)); +char *strtok_r __P((char *, const char *, char **)); +void swab __P((const void *, void *, size_t)); +#endif +__END_DECLS + +#endif /* _STRING_H_ */ diff --git a/include/strings.h b/include/strings.h new file mode 100644 index 0000000..56c3ae4 --- /dev/null +++ b/include/strings.h @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2000 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@ + */ +/*- + * Copyright (c) 1990, 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. + * + * @(#)strings.h 8.1 (Berkeley) 6/2/93 + */ + +#include diff --git a/include/struct.h b/include/struct.h new file mode 100644 index 0000000..ba8ac59 --- /dev/null +++ b/include/struct.h @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2000 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@ + */ +/*- + * Copyright (c) 1983, 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. + * + * @(#)struct.h 8.1 (Berkeley) 6/2/93 + */ + +#ifndef _STRUCT_H_ +#define _STRUCT_H_ + +/* Offset of the field in the structure. */ +#define fldoff(name, field) \ + ((int)&(((struct name *)0)->field)) + +/* Size of the field in the structure. */ +#define fldsiz(name, field) \ + (sizeof(((struct name *)0)->field)) + +/* Address of the structure from a field. */ +#define strbase(name, addr, field) \ + ((struct name *)((char *)(addr) - fldoff(name, field))) + +#endif /* !_STRUCT_H_ */ diff --git a/include/sysexits.h b/include/sysexits.h new file mode 100644 index 0000000..0a960a0 --- /dev/null +++ b/include/sysexits.h @@ -0,0 +1,139 @@ +/* + * Copyright (c) 2000 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@ + */ +/* + * Copyright (c) 1987, 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. + * + * @(#)sysexits.h 8.1 (Berkeley) 6/2/93 + */ + +#ifndef _SYSEXITS_H_ +#define _SYSEXITS_H_ + +/* + * SYSEXITS.H -- Exit status codes for system programs. + * + * This include file attempts to categorize possible error + * exit statuses for system programs, notably delivermail + * and the Berkeley network. + * + * Error numbers begin at EX__BASE to reduce the possibility of + * clashing with other exit statuses that random programs may + * already return. The meaning of the codes is approximately + * as follows: + * + * EX_USAGE -- The command was used incorrectly, e.g., with + * the wrong number of arguments, a bad flag, a bad + * syntax in a parameter, or whatever. + * EX_DATAERR -- The input data was incorrect in some way. + * This should only be used for user's data & not + * system files. + * EX_NOINPUT -- An input file (not a system file) did not + * exist or was not readable. This could also include + * errors like "No message" to a mailer (if it cared + * to catch it). + * EX_NOUSER -- The user specified did not exist. This might + * be used for mail addresses or remote logins. + * EX_NOHOST -- The host specified did not exist. This is used + * in mail addresses or network requests. + * EX_UNAVAILABLE -- A service is unavailable. This can occur + * if a support program or file does not exist. This + * can also be used as a catchall message when something + * you wanted to do doesn't work, but you don't know + * why. + * EX_SOFTWARE -- An internal software error has been detected. + * This should be limited to non-operating system related + * errors as possible. + * EX_OSERR -- An operating system error has been detected. + * This is intended to be used for such things as "cannot + * fork", "cannot create pipe", or the like. It includes + * things like getuid returning a user that does not + * exist in the passwd file. + * EX_OSFILE -- Some system file (e.g., /etc/passwd, /etc/utmp, + * etc.) does not exist, cannot be opened, or has some + * sort of error (e.g., syntax error). + * EX_CANTCREAT -- A (user specified) output file cannot be + * created. + * EX_IOERR -- An error occurred while doing I/O on some file. + * EX_TEMPFAIL -- temporary failure, indicating something that + * is not really an error. In sendmail, this means + * that a mailer (e.g.) could not create a connection, + * and the request should be reattempted later. + * EX_PROTOCOL -- the remote system returned something that + * was "not possible" during a protocol exchange. + * EX_NOPERM -- You did not have sufficient permission to + * perform the operation. This is not intended for + * file system problems, which should use NOINPUT or + * CANTCREAT, but rather for higher level permissions. + */ + +#define EX_OK 0 /* successful termination */ + +#define EX__BASE 64 /* base value for error messages */ + +#define EX_USAGE 64 /* command line usage error */ +#define EX_DATAERR 65 /* data format error */ +#define EX_NOINPUT 66 /* cannot open input */ +#define EX_NOUSER 67 /* addressee unknown */ +#define EX_NOHOST 68 /* host name unknown */ +#define EX_UNAVAILABLE 69 /* service unavailable */ +#define EX_SOFTWARE 70 /* internal software error */ +#define EX_OSERR 71 /* system error (e.g., can't fork) */ +#define EX_OSFILE 72 /* critical OS file missing */ +#define EX_CANTCREAT 73 /* can't create (user) output file */ +#define EX_IOERR 74 /* input/output error */ +#define EX_TEMPFAIL 75 /* temp failure; user is invited to retry */ +#define EX_PROTOCOL 76 /* remote error in protocol */ +#define EX_NOPERM 77 /* permission denied */ +#define EX_CONFIG 78 /* configuration error */ + +#define EX__MAX 78 /* maximum listed value */ + +#endif /* !_SYSEXITS_H_ */ diff --git a/include/syslog.h b/include/syslog.h new file mode 100644 index 0000000..455fe67 --- /dev/null +++ b/include/syslog.h @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2000 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@ + */ +#include + diff --git a/include/tar.h b/include/tar.h new file mode 100644 index 0000000..37d0edc --- /dev/null +++ b/include/tar.h @@ -0,0 +1,94 @@ +/* + * Copyright (c) 2000 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@ + */ +/*- + * Copyright (c) 1994 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chuck Karish of Mindcraft, 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. + * + * @(#)tar.h 8.2 (Berkeley) 1/4/94 + */ + +#ifndef _TAR_H +#define _TAR_H + +#define TMAGIC "ustar" /* ustar and a null */ +#define TMAGLEN 6 +#define TVERSION "00" /* 00 and no null */ +#define TVERSLEN 2 + +/* Values used in typeflag field */ +#define REGTYPE '0' /* Regular file */ +#define AREGTYPE '\0' /* Regular file */ +#define LNKTYPE '1' /* Link */ +#define SYMTYPE '2' /* Reserved */ +#define CHRTYPE '3' /* Character special */ +#define BLKTYPE '4' /* Block special */ +#define DIRTYPE '5' /* Directory */ +#define FIFOTYPE '6' /* FIFO special */ +#define CONTTYPE '7' /* Reserved */ + +/* Bits used in the mode field - values in octal */ +#define TSUID 04000 /* Set UID on execution */ +#define TSGID 02000 /* Set GID on execution */ +#define TSVTX 01000 /* Reserved */ + /* File permissions */ +#define TUREAD 00400 /* Read by owner */ +#define TUWRITE 00200 /* Write by owner */ +#define TUEXEC 00100 /* Execute/Search by owner */ +#define TGREAD 00040 /* Read by group */ +#define TGWRITE 00020 /* Write by group */ +#define TGEXEC 00010 /* Execute/Search by group */ +#define TOREAD 00004 /* Read by other */ +#define TOWRITE 00002 /* Write by other */ +#define TOEXEC 00001 /* Execute/Search by other */ + +#endif diff --git a/include/termios.h b/include/termios.h new file mode 100644 index 0000000..7ab55fe --- /dev/null +++ b/include/termios.h @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2000 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@ + */ +#include + diff --git a/include/time.h b/include/time.h new file mode 100644 index 0000000..f2e35f5 --- /dev/null +++ b/include/time.h @@ -0,0 +1,150 @@ +/* + * Copyright (c) 2000 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@ + */ +/* + * 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. + * + * 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. + * + * @(#)time.h 8.3 (Berkeley) 1/21/94 + */ + +#ifndef _TIME_H_ +#define _TIME_H_ + +#include + +#ifndef NULL +#define NULL 0 +#endif + +#ifndef _BSD_CLOCK_T_DEFINED_ +#define _BSD_CLOCK_T_DEFINED_ +typedef _BSD_CLOCK_T_ clock_t; +#endif + +#ifndef _BSD_TIME_T_DEFINED_ +#define _BSD_TIME_T_DEFINED_ +typedef _BSD_TIME_T_ time_t; +#endif + +#ifndef _BSD_SIZE_T_DEFINED_ +#define _BSD_SIZE_T_DEFINED_ +typedef _BSD_SIZE_T_ size_t; +#endif + +#ifndef _TIMESPEC_DECLARED +#define _TIMESPEC_DECLARED +struct timespec { + time_t tv_sec; /* seconds */ + long tv_nsec; /* and nanoseconds */ +}; +#endif + +struct tm { + int tm_sec; /* seconds after the minute [0-60] */ + int tm_min; /* minutes after the hour [0-59] */ + int tm_hour; /* hours since midnight [0-23] */ + int tm_mday; /* day of the month [1-31] */ + int tm_mon; /* months since January [0-11] */ + int tm_year; /* years since 1900 */ + int tm_wday; /* days since Sunday [0-6] */ + int tm_yday; /* days since January 1 [0-365] */ + int tm_isdst; /* Daylight Savings Time flag */ + long tm_gmtoff; /* offset from CUT in seconds */ + char *tm_zone; /* timezone abbreviation */ +}; + +#include /* Include file containing CLK_TCK. */ + +#define CLOCKS_PER_SEC (CLK_TCK) + +#include + +#ifndef _ANSI_SOURCE +extern char *tzname[]; +#endif + +__BEGIN_DECLS +char *asctime __P((const struct tm *)); +clock_t clock __P((void)); +char *ctime __P((const time_t *)); +double difftime __P((time_t, time_t)); +struct tm *gmtime __P((const time_t *)); +struct tm *localtime __P((const time_t *)); +time_t mktime __P((struct tm *)); +size_t strftime __P((char *, size_t, const char *, const struct tm *)); +time_t time __P((time_t *)); + +#ifndef _ANSI_SOURCE +void tzset __P((void)); +#endif /* not ANSI */ + +#if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE) +char *asctime_r __P((const struct tm *, char *)); +char *ctime_r __P((const time_t *, char *)); +struct tm *gmtime_r __P((const time_t *, struct tm *)); +struct tm *localtime_r __P((const time_t *, struct tm *)); +char *strptime __P((const char *, const char *, struct tm *)); +char *timezone __P((int, int)); +void tzsetwall __P((void)); +time_t timelocal __P((struct tm * const)); +time_t timegm __P((struct tm * const)); +#endif /* neither ANSI nor POSIX */ + +#if !defined(_ANSI_SOURCE) +int nanosleep __P((const struct timespec *, struct timespec *)); +#endif +__END_DECLS + +#endif /* !_TIME_H_ */ diff --git a/include/ttyent.h b/include/ttyent.h new file mode 100644 index 0000000..25ace7f --- /dev/null +++ b/include/ttyent.h @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2000 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@ + */ +/* + * Copyright (c) 1989, 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. + * + * @(#)ttyent.h 8.1 (Berkeley) 6/2/93 + */ + +#ifndef _TTYENT_H_ +#define _TTYENT_H_ + +#define _PATH_TTYS "/etc/ttys" + +#define _TTYS_OFF "off" +#define _TTYS_ON "on" +#define _TTYS_SECURE "secure" +#define _TTYS_WINDOW "window" +#define _TTYS_ONERROR "onerror" +#define _TTYS_ONOPTION "onoption" + +struct ttyent { + char *ty_name; /* terminal device name */ + char *ty_getty; /* command to execute, usually getty */ + char *ty_type; /* terminal type for termcap */ +#define TTY_ON 0x01 /* enable logins (start ty_getty program) */ +#define TTY_SECURE 0x02 /* allow uid of 0 to login */ + int ty_status; /* status flags */ + char *ty_window; /* command to start up window manager */ + char *ty_onerror; /* command to execute after getty failure */ + char *ty_onoption; /* command to execute after console login */ + char *ty_comment; /* comment field */ +}; + +#include + +__BEGIN_DECLS +struct ttyent *getttyent __P((void)); +struct ttyent *getttynam __P((const char *)); +int setttyent __P((void)); +int endttyent __P((void)); +__END_DECLS + +#endif /* !_TTYENT_H_ */ diff --git a/include/tzfile.h b/include/tzfile.h new file mode 100644 index 0000000..53bc180 --- /dev/null +++ b/include/tzfile.h @@ -0,0 +1,172 @@ +/* + * Copyright (c) 2000 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@ + */ +/* + * 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_ */ diff --git a/include/ucontext.h b/include/ucontext.h new file mode 100644 index 0000000..f658425 --- /dev/null +++ b/include/ucontext.h @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2002 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 _UCONTEXT_H_ +#define _UCONTEXT_H_ + +#include + +#endif /* _UCONTEXT_H_ */ diff --git a/include/ulimit.h b/include/ulimit.h new file mode 100644 index 0000000..55bb1a2 --- /dev/null +++ b/include/ulimit.h @@ -0,0 +1,9 @@ +#ifndef _ULIMIT_H +#define _ULIMIT_H + +#define UL_GETFSIZE 1 +#define UL_SETFSIZE 2 + +long int ulimit(int, ...); + +#endif /* _ULIMIT_H */ diff --git a/include/unistd.h b/include/unistd.h new file mode 100644 index 0000000..32f1c74 --- /dev/null +++ b/include/unistd.h @@ -0,0 +1,249 @@ +/* + * Copyright (c) 2000 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@ + */ +/*- + * Copyright (c) 1998-1999 Apple Computer, Inc. All Rights Reserved + * Copyright (c) 1991, 1993, 1994 + * 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. + * + * @(#)unistd.h 8.12 (Berkeley) 4/27/95 + * + * Copyright (c) 1998 Apple Compter, Inc. + * All Rights Reserved + */ + +/* History: + 7/14/99 EKN at Apple fixed getdirentriesattr from getdirentryattr + 3/26/98 CHW at Apple added real interface to searchfs call + 3/5/98 CHW at Apple added hfs semantic system calls headers +*/ + +#ifndef _UNISTD_H_ +#define _UNISTD_H_ + +#include +#include +#include + +#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 0 /* null pointer constant */ +#endif + +#define _POSIX_THREADS /* We support pthreads */ + +#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 + +__BEGIN_DECLS +__dead void + _exit __P((int)); +int access __P((const char *, int)); +unsigned int alarm __P((unsigned int)); +int chdir __P((const char *)); +int chown __P((const char *, uid_t, gid_t)); +int close __P((int)); +size_t confstr __P((int, char *, size_t)); +int dup __P((int)); +int dup2 __P((int, int)); +int execl __P((const char *, const char *, ...)); +int execle __P((const char *, const char *, ...)); +int execlp __P((const char *, const char *, ...)); +int execv __P((const char *, char * const *)); +int execve __P((const char *, char * const *, char * const *)); +int execvp __P((const char *, char * const *)); +pid_t fork __P((void)); +long fpathconf __P((int, int)); +char *getcwd __P((char *, size_t)); +gid_t getegid __P((void)); +uid_t geteuid __P((void)); +gid_t getgid __P((void)); +int getgroups __P((int, gid_t [])); +char *getlogin __P((void)); +pid_t getpgrp __P((void)); +pid_t getpid __P((void)); +pid_t getppid __P((void)); +uid_t getuid __P((void)); +int isatty __P((int)); +int link __P((const char *, const char *)); +off_t lseek __P((int, off_t, int)); +long pathconf __P((const char *, int)); +int pause __P((void)); +int pipe __P((int *)); +ssize_t read __P((int, void *, size_t)); +int rmdir __P((const char *)); +int setgid __P((gid_t)); +int setpgid __P((pid_t, pid_t)); +pid_t setsid __P((void)); +int setuid __P((uid_t)); +unsigned int sleep __P((unsigned int)); +long sysconf __P((int)); +pid_t tcgetpgrp __P((int)); +int tcsetpgrp __P((int, pid_t)); +char *ttyname __P((int)); +int unlink __P((const char *)); +ssize_t write __P((int, const void *, size_t)); + +extern char *optarg; /* getopt(3) external variables */ +extern int optind, opterr, optopt, optreset; +int getopt __P((int, char * const [], const char *)); + +#ifndef _POSIX_SOURCE +#ifdef __STDC__ +struct timeval; /* select(2) */ +#endif +int acct __P((const char *)); +int async_daemon __P((void)); +char *brk __P((const char *)); +int chroot __P((const char *)); +char *crypt __P((const char *, const char *)); +int des_cipher __P((const char *, char *, long, int)); +int des_setkey __P((const char *key)); +int encrypt __P((char *, int)); +void endusershell __P((void)); +int exect __P((const char *, char * const *, char * const *)); +int fchdir __P((int)); +int fchown __P((int, int, int)); +char *fflagstostr __P((u_long)); +int fsync __P((int)); +int ftruncate __P((int, off_t)); +int getdtablesize __P((void)); +int getgrouplist __P((const char *, int, int *, int *)); +long gethostid __P((void)); +int gethostname __P((char *, int)); +mode_t getmode __P((const void *, mode_t)); +__pure int + getpagesize __P((void)); +char *getpass __P((const char *)); +int getpgid __P((pid_t _pid)); +int getsid __P((pid_t _pid)); +char *getusershell __P((void)); +char *getwd __P((char *)); /* obsoleted by getcwd() */ +int initgroups __P((const char *, int)); +int iruserok __P((unsigned long, int, const char *, const char *)); +int issetugid __P((void)); +char *mkdtemp __P((char *)); +int mknod __P((const char *, mode_t, dev_t)); +int mkstemp __P((char *)); +int mkstemps __P((char *, int)); +char *mktemp __P((char *)); +int nfssvc __P((int, void *)); +int nice __P((int)); +ssize_t pread __P((int, void *, size_t, off_t)); +#if 0 +void psignal __P((unsigned int, const char *)); +extern __const char *__const sys_siglist[]; +#else +#include +#endif +int profil __P((char *, int, int, int)); +ssize_t pwrite __P((int, const void *, size_t, off_t)); +int rcmd __P((char **, int, const char *, + const char *, const char *, int *)); +char *re_comp __P((const char *)); +int re_exec __P((const char *)); +int readlink __P((const char *, char *, int)); +int reboot __P((int)); +int revoke __P((const char *)); +int rresvport __P((int *)); +int ruserok __P((const char *, int, const char *, const char *)); +char *sbrk __P((int)); +int select __P((int, fd_set *, fd_set *, fd_set *, struct timeval *)); +int setegid __P((gid_t)); +int seteuid __P((uid_t)); +int setgroups __P((int, const gid_t *)); +void sethostid __P((long)); +int sethostname __P((const char *, int)); +int setkey __P((const char *)); +int setlogin __P((const char *)); +void *setmode __P((const char *)); +int setpgrp __P((pid_t pid, pid_t pgrp)); /* obsoleted by setpgid() */ +int setregid __P((gid_t, gid_t)); +int setreuid __P((uid_t, uid_t)); +int setrgid __P((gid_t)); +int setruid __P((uid_t)); +void setusershell __P((void)); +int strtofflags __P((char **, u_long *, u_long *)); +int swapon __P((const char *)); +int symlink __P((const char *, const char *)); +void sync __P((void)); +int syscall __P((int, ...)); +int truncate __P((const char *, off_t)); +int ttyslot __P((void)); +unsigned int ualarm __P((unsigned int, unsigned int)); +int unwhiteout __P((const char *)); +int usleep __P((unsigned int)); +void *valloc __P((size_t)); +pid_t vfork __P((void)); + +extern char *suboptarg; /* getsubopt(3) external variable */ +int getsubopt __P((char **, char * const *, char **)); + +/* HFS & HFS Plus semantics system calls go here */ +int getattrlist __P((const char*,void*,void*,size_t,unsigned long)); +int setattrlist __P((const char*,void*,void*,size_t,unsigned long)); +int exchangedata __P((const char*,const char*,unsigned long)); +int checkuseraccess __P((const char*,uid_t,gid_t*,int,int,unsigned long)); +int getdirentriesattr __P((int,void*,void*,size_t,unsigned long*,unsigned long*,unsigned long*,unsigned long)); +int searchfs __P((const char*,void*,void*,unsigned long,unsigned long,void*)); + +int fsctl __P((const char *,unsigned long,void*,unsigned long)); + + +#endif /* !_POSIX_SOURCE */ +__END_DECLS + +#endif /* !_UNISTD_H_ */ diff --git a/include/util.h b/include/util.h new file mode 100644 index 0000000..42dbdab --- /dev/null +++ b/include/util.h @@ -0,0 +1,107 @@ +/* + * Copyright (c) 2000 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@ + */ +/* $NetBSD: util.h,v 1.10 1997/12/01 02:25:46 lukem Exp $ */ + +/*- + * Copyright (c) 1995 + * 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. + */ + +#ifndef _UTIL_H_ +#define _UTIL_H_ + +#include +#include +#include +#include +#include +#include +#include + +#define PIDLOCK_NONBLOCK 1 +#define PIDLOCK_USEHOSTNAME 2 + +#define FPARSELN_UNESCESC 0x01 +#define FPARSELN_UNESCCONT 0x02 +#define FPARSELN_UNESCCOMM 0x04 +#define FPARSELN_UNESCREST 0x08 +#define FPARSELN_UNESCALL 0x0f + +__BEGIN_DECLS +void login __P((struct utmp *)); +int login_tty __P((int)); +int logout __P((const char *)); +void logwtmp __P((const char *, const char *, const char *)); +int pw_lock __P((int retries)); +int pw_mkdb __P((void)); +int pw_abort __P((void)); +void pw_init __P((void)); +void pw_edit __P((int notsetuid, const char *filename)); +void pw_prompt __P((void)); +void pw_copy __P((int ffd, int tfd, struct passwd *pw, + struct passwd *old_pw)); +int pw_scan __P((char *bp, struct passwd *pw, int *flags)); +void pw_error __P((const char *name, int err, int eval)); +int openpty __P((int *, int *, char *, struct termios *, + struct winsize *)); +char *fparseln __P((FILE *, size_t *, size_t *, const char[3], int)); +pid_t forkpty __P((int *, char *, struct termios *, struct winsize *)); +int getmaxpartitions __P((void)); +int getrawpartition __P((void)); +int opendisk __P((const char *, int, char *, size_t, int)); +int pidlock __P((const char *, int, pid_t *, const char *)); +int ttylock __P((const char *, int, pid_t *)); +int ttyunlock __P((const char *)); +int ttyaction __P((char *tty, char *act, char *user)); +struct iovec; +char *ttymsg __P((struct iovec *, int, const char *, int)); +__END_DECLS + +#endif /* !_UTIL_H_ */ diff --git a/include/utime.h b/include/utime.h new file mode 100644 index 0000000..2326c06 --- /dev/null +++ b/include/utime.h @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2000 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@ + */ +/*- + * Copyright (c) 1990, 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. + * + * @(#)utime.h 8.1 (Berkeley) 6/2/93 + */ + +#ifndef _UTIME_H_ +#define _UTIME_H_ + +struct utimbuf { + time_t actime; /* Access time */ + time_t modtime; /* Modification time */ +}; + +#include + +__BEGIN_DECLS +int utime __P((const char *, const struct utimbuf *)); +__END_DECLS + +#endif /* !_UTIME_H_ */ diff --git a/include/utmp.h b/include/utmp.h new file mode 100644 index 0000000..0778052 --- /dev/null +++ b/include/utmp.h @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2000 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@ + */ +/* + * Copyright (c) 1988, 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. + * + * @(#)utmp.h 8.2 (Berkeley) 1/21/94 + */ + +#ifndef _UTMP_H_ +#define _UTMP_H_ + +#define _PATH_UTMP "/var/run/utmp" +#define _PATH_WTMP "/var/log/wtmp" +#define _PATH_LASTLOG "/var/log/lastlog" + +#define UT_NAMESIZE 8 +#define UT_LINESIZE 8 +#define UT_HOSTSIZE 16 + +struct lastlog { + time_t ll_time; + char ll_line[UT_LINESIZE]; + char ll_host[UT_HOSTSIZE]; +}; + +struct utmp { + char ut_line[UT_LINESIZE]; + char ut_name[UT_NAMESIZE]; + char ut_host[UT_HOSTSIZE]; + long ut_time; +}; + +#endif /* !_UTMP_H_ */ diff --git a/include/vis.h b/include/vis.h new file mode 100644 index 0000000..b9debf7 --- /dev/null +++ b/include/vis.h @@ -0,0 +1,105 @@ +/* + * Copyright (c) 2000 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@ + */ +/*- + * Copyright (c) 1990, 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. + * + * @(#)vis.h 8.1 (Berkeley) 6/2/93 + */ + +#ifndef _VIS_H_ +#define _VIS_H_ + +/* + * to select alternate encoding format + */ +#define VIS_OCTAL 0x01 /* use octal \ddd format */ +#define VIS_CSTYLE 0x02 /* use \[nrft0..] where appropiate */ + +/* + * to alter set of characters encoded (default is to encode all + * non-graphic except space, tab, and newline). + */ +#define VIS_SP 0x04 /* also encode space */ +#define VIS_TAB 0x08 /* also encode tab */ +#define VIS_NL 0x10 /* also encode newline */ +#define VIS_WHITE (VIS_SP | VIS_TAB | VIS_NL) +#define VIS_SAFE 0x20 /* only encode "unsafe" characters */ + +/* + * other + */ +#define VIS_NOSLASH 0x40 /* inhibit printing '\' */ + +/* + * unvis return codes + */ +#define UNVIS_VALID 1 /* character valid */ +#define UNVIS_VALIDPUSH 2 /* character valid, push back passed char */ +#define UNVIS_NOCHAR 3 /* valid sequence, no character produced */ +#define UNVIS_SYNBAD -1 /* unrecognized escape sequence */ +#define UNVIS_ERROR -2 /* decoder in unknown state (unrecoverable) */ + +/* + * unvis flags + */ +#define UNVIS_END 1 /* no more characters */ + +#include + +__BEGIN_DECLS +char *vis __P((char *, int, int, int)); +int strvis __P((char *, const char *, int)); +int strvisx __P((char *, const char *, size_t, int)); +int strunvis __P((char *, const char *)); +int unvis __P((char *, int, int *, int)); +__END_DECLS + +#endif /* !_VIS_H_ */ diff --git a/internat.subproj/Makefile b/internat.subproj/Makefile deleted file mode 100644 index e1ea59d..0000000 --- a/internat.subproj/Makefile +++ /dev/null @@ -1,50 +0,0 @@ -# -# Generated by the NeXT Project Builder. -# -# NOTE: Do NOT change this file -- Project Builder maintains it. -# -# Put all of your customizations in files called Makefile.preamble -# and Makefile.postamble (both optional), and Makefile will include them. -# - -NAME = internat - -PROJECTVERSION = 2.8 -PROJECT_TYPE = Component - -HFILES = NXCType.h - -CFILES = NXCType.c NXIsAlNum.c NXIsAlpha.c NXIsAscii.c NXIsCntrl.c\ - NXIsDigit.c NXIsGraph.c NXIsLower.c NXIsPrint.c NXIsPunct.c\ - NXIsSpace.c NXIsUpper.c NXIsXDigit.c NXToAscii.c NXToLower.c\ - _NXToLower.c NXToUpper.c _NXToUpper.c - -OTHERSRCS = Makefile.preamble Makefile Makefile.postamble - - -MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles -CODE_GEN_STYLE = DYNAMIC -MAKEFILE = subproj.make -LIBS = -DEBUG_LIBS = $(LIBS) -PROF_LIBS = $(LIBS) - - - - -NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc -WINDOWS_OBJCPLUS_COMPILER = $(DEVDIR)/gcc -PDO_UNIX_OBJCPLUS_COMPILER = $(NEXTDEV_BIN)/gcc -NEXTSTEP_JAVA_COMPILER = /usr/bin/javac -WINDOWS_JAVA_COMPILER = $(JDKBINDIR)/javac.exe -PDO_UNIX_JAVA_COMPILER = $(JDKBINDIR)/javac - -include $(MAKEFILEDIR)/platform.make - --include Makefile.preamble - -include $(MAKEFILEDIR)/$(MAKEFILE) - --include Makefile.postamble - --include Makefile.dependencies diff --git a/internat.subproj/Makefile.postamble b/internat.subproj/Makefile.postamble deleted file mode 100644 index df76c31..0000000 --- a/internat.subproj/Makefile.postamble +++ /dev/null @@ -1,5 +0,0 @@ -$(DSTROOT)$(PRIVATE_HDR_INSTALLDIR)$(MY_PRIVATE_HEADER_DIR_SUFFIX): - $(MKDIRS) $@ - -my_installhdrs: $(DSTROOT)$(PRIVATE_HDR_INSTALLDIR)$(MY_PRIVATE_HEADER_DIR_SUFFIX) - $(SILENT) $(FASTCP) $(MY_PRIVATE_HEADERS) $(DSTROOT)$(PRIVATE_HDR_INSTALLDIR)$(MY_PRIVATE_HEADER_DIR_SUFFIX) diff --git a/internat.subproj/Makefile.preamble b/internat.subproj/Makefile.preamble deleted file mode 100644 index ab01f68..0000000 --- a/internat.subproj/Makefile.preamble +++ /dev/null @@ -1,3 +0,0 @@ -MY_PRIVATE_HEADERS = NXCType.h -MY_PRIVATE_HEADER_DIR_SUFFIX = /objc -AFTER_INSTALLHDRS += my_installhdrs diff --git a/internat.subproj/NXCType.c b/internat.subproj/NXCType.c deleted file mode 100644 index a9932b1..0000000 --- a/internat.subproj/NXCType.c +++ /dev/null @@ -1,598 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#pragma CC_NO_MACH_TEXT_SECTIONS -/* - * Copyright 1990, NeXT, Inc. - */ - -/* - * This file contains global data and the size of the global data can NOT - * change or otherwise it would make the shared library incompatable. This - * file has NOT been padded to allow more data to be added to it because the - * sizeof(char) is not expected to change. - */ - -#include "NXCType.h" - -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, -}; - -/* - * Upper to lower and lower to upper table for NeXTStep encoding (256 - * characters). An entry of zero means it's not an upper or lower case - * thing (i.e., isn't alphabetic). Otherwise, the value at a given - * position is the opposite case equivalent. E.g., the entry for the - * "A" position is "a" and the entry for position "a" is "A". - * - * 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. - */ -const unsigned char _NX_ULTable_[256] = { -/* 0 .notdef */ 0, -/* 1 .notdef */ 0, -/* 2 .notdef */ 0, -/* 3 .notdef */ 0, -/* 4 .notdef */ 0, -/* 5 .notdef */ 0, -/* 6 .notdef */ 0, -/* 7 .notdef */ 0, -/* 8 .notdef */ 0, -/* 9 .notdef */ 0, -/* 10 .notdef */ 0, -/* 11 .notdef */ 0, -/* 12 .notdef */ 0, -/* 13 .notdef */ 0, -/* 14 .notdef */ 0, -/* 15 .notdef */ 0, -/* 16 .notdef */ 0, -/* 17 .notdef */ 0, -/* 18 .notdef */ 0, -/* 19 .notdef */ 0, -/* 20 .notdef */ 0, -/* 21 .notdef */ 0, -/* 22 .notdef */ 0, -/* 23 .notdef */ 0, -/* 24 .notdef */ 0, -/* 25 .notdef */ 0, -/* 26 .notdef */ 0, -/* 27 .notdef */ 0, -/* 28 .notdef */ 0, -/* 29 .notdef */ 0, -/* 30 .notdef */ 0, -/* 31 .notdef */ 0, -/* 32 space */ 0, -/* 33 exclam */ 0, -/* 34 quotedbl */ 0, -/* 35 numbersign */ 0, -/* 36 dollar */ 0, -/* 37 percent */ 0, -/* 38 ampersand */ 0, -/* 39 quoteright */ 0, -/* 40 parenleft */ 0, -/* 41 parenright */ 0, -/* 42 asterisk */ 0, -/* 43 plus */ 0, -/* 44 comma */ 0, -/* 45 hyphen */ 0, -/* 46 period */ 0, -/* 47 slash */ 0, -/* 48 zero */ 0, -/* 49 one */ 0, -/* 50 two */ 0, -/* 51 three */ 0, -/* 52 four */ 0, -/* 53 five */ 0, -/* 54 six */ 0, -/* 55 seven */ 0, -/* 56 eight */ 0, -/* 57 nine */ 0, -/* 58 colon */ 0, -/* 59 semicolon */ 0, -/* 60 less */ 0, -/* 61 equal */ 0, -/* 62 greater */ 0, -/* 63 question */ 0, -/* 64 at */ 0, -/* 65 A */ 97, -/* 66 B */ 98, -/* 67 C */ 99, -/* 68 D */ 100, -/* 69 E */ 101, -/* 70 F */ 102, -/* 71 G */ 103, -/* 72 H */ 104, -/* 73 I */ 105, -/* 74 J */ 106, -/* 75 K */ 107, -/* 76 L */ 108, -/* 77 M */ 109, -/* 78 N */ 110, -/* 79 O */ 111, -/* 80 P */ 112, -/* 81 Q */ 113, -/* 82 R */ 114, -/* 83 S */ 115, -/* 84 T */ 116, -/* 85 U */ 117, -/* 86 V */ 118, -/* 87 W */ 119, -/* 88 X */ 120, -/* 89 Y */ 121, -/* 90 Z */ 122, -/* 91 bracketleft */ 0, -/* 92 backslash */ 0, -/* 93 bracketright */ 0, -/* 94 asciicircum */ 0, -/* 95 underscore */ 0, -/* 96 quoteleft */ 0, -/* 97 a */ 65, -/* 98 b */ 66, -/* 99 c */ 67, -/* 100 d */ 68, -/* 101 e */ 69, -/* 102 f */ 70, -/* 103 g */ 71, -/* 104 h */ 72, -/* 105 i */ 73, -/* 106 j */ 74, -/* 107 k */ 75, -/* 108 l */ 76, -/* 109 m */ 77, -/* 110 n */ 78, -/* 111 o */ 79, -/* 112 p */ 80, -/* 113 q */ 81, -/* 114 r */ 82, -/* 115 s */ 83, -/* 116 t */ 84, -/* 117 u */ 85, -/* 118 v */ 86, -/* 119 w */ 87, -/* 120 x */ 88, -/* 121 y */ 89, -/* 122 z */ 90, -/* 123 braceleft */ 0, -/* 124 bar */ 0, -/* 125 braceright */ 0, -/* 126 asciitilde */ 0, -/* 127 .notdef */ 0, -/* 128 .notdef */ 0, -/* 129 Agrave */ 213, -/* 130 Aacute */ 214, -/* 131 Acircumflex */ 215, -/* 132 Atilde */ 216, -/* 133 Adieresis */ 217, -/* 134 Aring */ 218, -/* 135 Ccedilla */ 219, -/* 136 Egrave */ 220, -/* 137 Eacute */ 221, -/* 138 Ecircumflex */ 222, -/* 139 Edieresis */ 223, -/* 140 Igrave */ 224, -/* 141 Iacute */ 226, -/* 142 Icircumflex */ 228, -/* 143 Idieresis */ 229, -/* 144 Eth */ 230, -/* 145 Ntilde */ 231, -/* 146 Ograve */ 236, -/* 147 Oacute */ 237, -/* 148 Ocircumflex */ 238, -/* 149 Otilde */ 239, -/* 150 Odieresis */ 240, -/* 151 Ugrave */ 242, -/* 152 Uacute */ 243, -/* 153 Ucircumflex */ 244, -/* 154 Udieresis */ 246, -/* 155 Yacute */ 247, -/* 156 Thorn */ 252, -/* 157 mu */ 0, -/* 158 multiply */ 0, -/* 159 divide */ 0, -/* 160 copyright */ 0, -/* 161 exclamdown */ 0, -/* 162 cent */ 0, -/* 163 sterling */ 0, -/* 164 fraction */ 0, -/* 165 yen */ 0, -/* 166 florin */ 0, -/* 167 section */ 0, -/* 168 currency */ 0, -/* 169 quotesingle */ 0, -/* 170 quotedblleft */ 0, -/* 171 guillemotleft */ 0, -/* 172 guilsinglleft */ 0, -/* 173 guilsinglright */ 0, -/* 174 fi */ 174, /* is self */ -/* 175 fl */ 175, /* is self */ -/* 176 registered */ 0, -/* 177 endash */ 0, -/* 178 dagger */ 0, -/* 179 daggerdbl */ 0, -/* 180 periodcentered */ 0, -/* 181 brokenbar */ 0, -/* 182 paragraph */ 0, -/* 183 bullet */ 0, -/* 184 quotesinglbase */ 0, -/* 185 quotedblbase */ 0, -/* 186 quotedblright */ 0, -/* 187 guillemotright */ 0, -/* 188 ellipsis */ 0, -/* 189 perthousand */ 0, -/* 190 logicalnot */ 0, -/* 191 questiondown */ 0, -/* 192 onesuperior */ 0, -/* 193 grave */ 0, -/* 194 acute */ 0, -/* 195 circumflex */ 0, -/* 196 tilde */ 0, -/* 197 macron */ 0, -/* 198 breve */ 0, -/* 199 dotaccent */ 0, -/* 200 dieresis */ 0, -/* 201 twosuperior */ 0, -/* 202 ring */ 0, -/* 203 cedilla */ 0, -/* 204 threesuperior */ 0, -/* 205 hungarumlaut */ 0, -/* 206 ogonek */ 0, -/* 207 caron */ 0, -/* 208 emdash */ 0, -/* 209 plusminus */ 0, -/* 210 onequarter */ 0, -/* 211 onehalf */ 0, -/* 212 threequarters */ 0, -/* 213 agrave */ 129, -/* 214 aacute */ 130, -/* 215 acircumflex */ 131, -/* 216 atilde */ 132, -/* 217 adieresis */ 133, -/* 218 aring */ 134, -/* 219 ccedilla */ 135, -/* 220 egrave */ 136, -/* 221 eacute */ 137, -/* 222 ecircumflex */ 138, -/* 223 edieresis */ 139, -/* 224 igrave */ 140, -/* 225 AE */ 241, -/* 226 iacute */ 141, -/* 227 ordfeminine */ 0, -/* 228 icircumflex */ 142, -/* 229 idieresis */ 143, -/* 230 eth */ 144, -/* 231 ntilde */ 145, -/* 232 Lslash */ 248, -/* 233 Oslash */ 249, -/* 234 OE */ 250, -/* 235 ordmasculine */ 0, -/* 236 ograve */ 146, -/* 237 oacute */ 147, -/* 238 ocircumflex */ 148, -/* 239 otilde */ 149, -/* 240 odieresis */ 150, -/* 241 ae */ 225, -/* 242 ugrave */ 151, -/* 243 uacute */ 152, -/* 244 ucircumflex */ 153, -/* 245 dotlessi */ 245, /* is self */ -/* 246 udieresis */ 154, -/* 247 yacute */ 155, -/* 248 lslash */ 232, -/* 249 oslash */ 233, -/* 250 oe */ 234, -/* 251 germandbls */ 251, /* is self */ -/* 252 thorn */ 156, -/* 253 ydieresis */ 253, /* is self */ -/* 254 .notdef */ 0, -/* 255 .notdef */ 0 -}; - diff --git a/internat.subproj/NXCType.h b/internat.subproj/NXCType.h deleted file mode 100644 index 3c5407e..0000000 --- a/internat.subproj/NXCType.h +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* NXCType.h */ - -/* Copyright (c) 1990 NeXT, Inc. - 8/21/90 RM */ -/* patterned after ctype.h ; for 8-bit encoding, Europe only */ - -#ifndef _NXCTYPE_H -#define _NXCTYPE_H - -#include - -extern int NXIsAlNum(unsigned c); -extern int NXIsAlpha(unsigned c); -extern int NXIsCntrl(unsigned c); -extern int NXIsDigit(unsigned c); -extern int NXIsGraph(unsigned c); -extern int NXIsLower(unsigned c); -extern int NXIsPrint(unsigned c); -extern int NXIsPunct(unsigned c); -extern int NXIsSpace(unsigned c); -extern int NXIsUpper(unsigned c); -extern int NXIsXDigit(unsigned c); -extern int _NXToLower(unsigned c); -extern int _NXToUpper(unsigned c); -extern int NXToLower(unsigned c); -extern int NXToUpper(unsigned c); -extern int NXIsAscii(unsigned c); -extern unsigned char *NXToAscii(unsigned c); - -/* - * Data structures used by the internationized NX... versions of the - * ctype(3) routines. These structures are private to the above routines - * and should NOT be referenced by the application. - */ -extern const unsigned int _NX_CTypeTable_[]; /* char types */ -extern const unsigned char _NX_ULTable_[]; /* case conversion table */ - -#endif /* _NXCTYPE_H */ diff --git a/internat.subproj/NXIsAlNum.c b/internat.subproj/NXIsAlNum.c deleted file mode 100644 index 65e15e0..0000000 --- a/internat.subproj/NXIsAlNum.c +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright 1990, NeXT, Inc. - */ - -#include "NXCType.h" -#define FIXSIGNEDCHAR(i) if ((i & 0xFFFFFF80) == 0xFFFFFF80) i &= 0x000000FF - -int NXIsAlNum(c) - unsigned int c; -{ - FIXSIGNEDCHAR(c); - if (c < 256) - return ((unsigned int)((_NX_CTypeTable_ + 1)[c] & (_U|_L|_D))); - return 0; -} diff --git a/internat.subproj/NXIsAlpha.c b/internat.subproj/NXIsAlpha.c deleted file mode 100644 index b946d95..0000000 --- a/internat.subproj/NXIsAlpha.c +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright 1990, NeXT, Inc. - */ - -#include "NXCType.h" -#define FIXSIGNEDCHAR(i) if ((i & 0xFFFFFF80) == 0xFFFFFF80) i &= 0x000000FF - - -int NXIsAlpha(c) - unsigned int c; -{ - FIXSIGNEDCHAR(c); - if (c < 256) - return ((unsigned int)((_NX_CTypeTable_ + 1)[c] & (_U|_L))); - return 0; -} diff --git a/internat.subproj/NXIsAscii.c b/internat.subproj/NXIsAscii.c deleted file mode 100644 index f2545d4..0000000 --- a/internat.subproj/NXIsAscii.c +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright 1990, NeXT, Inc. - */ - -#include "NXCType.h" -#define FIXSIGNEDCHAR(i) if ((i & 0xFFFFFF80) == 0xFFFFFF80) i &= 0x000000FF - -NXIsAscii(c) - unsigned int c; -{ - FIXSIGNEDCHAR(c); - return (c <= 0177); -} diff --git a/internat.subproj/NXIsCntrl.c b/internat.subproj/NXIsCntrl.c deleted file mode 100644 index 71e154d..0000000 --- a/internat.subproj/NXIsCntrl.c +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright 1990, NeXT, Inc. - */ - -#include "NXCType.h" -#define FIXSIGNEDCHAR(i) if ((i & 0xFFFFFF80) == 0xFFFFFF80) i &= 0x000000FF - -int NXIsCntrl(c) - unsigned int c; -{ - FIXSIGNEDCHAR(c); - if (c < 256) - return ((unsigned int)((_NX_CTypeTable_ + 1)[c] & (_C))); - return 0; -} diff --git a/internat.subproj/NXIsDigit.c b/internat.subproj/NXIsDigit.c deleted file mode 100644 index 1ead0b3..0000000 --- a/internat.subproj/NXIsDigit.c +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright 1990, NeXT, Inc. - */ - -#include "NXCType.h" -#define FIXSIGNEDCHAR(i) if ((i & 0xFFFFFF80) == 0xFFFFFF80) i &= 0x000000FF - -int NXIsDigit(c) - unsigned int c; -{ - FIXSIGNEDCHAR(c); - if (c < 256) - return ((unsigned int)((_NX_CTypeTable_ + 1)[c] & (_D))); - return 0; -} diff --git a/internat.subproj/NXIsGraph.c b/internat.subproj/NXIsGraph.c deleted file mode 100644 index 39545d1..0000000 --- a/internat.subproj/NXIsGraph.c +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright 1990, NeXT, Inc. - */ - -#include "NXCType.h" -#define FIXSIGNEDCHAR(i) if ((i & 0xFFFFFF80) == 0xFFFFFF80) i &= 0x000000FF - -int NXIsGraph(c) - unsigned int c; -{ - FIXSIGNEDCHAR(c); - if (c < 256) - return ((unsigned int)((_NX_CTypeTable_ + 1)[c] & (_P|_U|_L|_D))); - return 1; - /* NOTE: for 3.0, everything > 256 is probably Kanji, so say is graphic */ -} diff --git a/internat.subproj/NXIsLower.c b/internat.subproj/NXIsLower.c deleted file mode 100644 index 1074676..0000000 --- a/internat.subproj/NXIsLower.c +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright 1990, NeXT, Inc. - */ - -#include "NXCType.h" -#define FIXSIGNEDCHAR(i) if ((i & 0xFFFFFF80) == 0xFFFFFF80) i &= 0x000000FF - -int NXIsLower(c) - unsigned int c; -{ - FIXSIGNEDCHAR(c); - if (c < 256) - return ((unsigned int)((_NX_CTypeTable_ + 1)[c] & (_L))); - return 0; -} diff --git a/internat.subproj/NXIsPrint.c b/internat.subproj/NXIsPrint.c deleted file mode 100644 index 29154e1..0000000 --- a/internat.subproj/NXIsPrint.c +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright 1990, NeXT, Inc. - */ - -#include "NXCType.h" -#define FIXSIGNEDCHAR(i) if ((i & 0xFFFFFF80) == 0xFFFFFF80) i &= 0x000000FF - -int NXIsPrint(c) - unsigned int c; -{ - FIXSIGNEDCHAR(c); - if (c < 256) - return ((unsigned int)((_NX_CTypeTable_ + 1)[c] & (_P|_U|_L|_D|_B))); - return 1; - /* NOTE: for 3.0, everything > 255 is probably Kanji, so say printable... */ -} diff --git a/internat.subproj/NXIsPunct.c b/internat.subproj/NXIsPunct.c deleted file mode 100644 index 188d694..0000000 --- a/internat.subproj/NXIsPunct.c +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright 1990, NeXT, Inc. - */ - -#include "NXCType.h" -#define FIXSIGNEDCHAR(i) if ((i & 0xFFFFFF80) == 0xFFFFFF80) i &= 0x000000FF - -int NXIsPunct(c) - unsigned int c; -{ - FIXSIGNEDCHAR(c); - if (c < 256) - return ((unsigned int)((_NX_CTypeTable_ + 1)[c] & (_P))); - return 0; -} diff --git a/internat.subproj/NXIsSpace.c b/internat.subproj/NXIsSpace.c deleted file mode 100644 index 35c6d50..0000000 --- a/internat.subproj/NXIsSpace.c +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright 1990, NeXT, Inc. - */ - -#include "NXCType.h" -#define FIXSIGNEDCHAR(i) if ((i & 0xFFFFFF80) == 0xFFFFFF80) i &= 0x000000FF - -int NXIsSpace(c) - unsigned int c; -{ - FIXSIGNEDCHAR(c); - if (c < 256) - return ((unsigned int)((_NX_CTypeTable_ + 1)[c] & (_S))); - return 0; -} diff --git a/internat.subproj/NXIsUpper.c b/internat.subproj/NXIsUpper.c deleted file mode 100644 index e23a927..0000000 --- a/internat.subproj/NXIsUpper.c +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright 1990, NeXT, Inc. - */ - -#include "NXCType.h" -#define FIXSIGNEDCHAR(i) if ((i & 0xFFFFFF80) == 0xFFFFFF80) i &= 0x000000FF - -int NXIsUpper(c) - unsigned int c; -{ - FIXSIGNEDCHAR(c); - if (c < 256) - return ((unsigned int)((_NX_CTypeTable_ + 1)[c] & (_U))); - return 0; -} diff --git a/internat.subproj/NXIsXDigit.c b/internat.subproj/NXIsXDigit.c deleted file mode 100644 index 785ca3f..0000000 --- a/internat.subproj/NXIsXDigit.c +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright 1990, NeXT, Inc. - */ - -#include "NXCType.h" -#define FIXSIGNEDCHAR(i) if ((i & 0xFFFFFF80) == 0xFFFFFF80) i &= 0x000000FF - -int NXIsXDigit(c) - unsigned int c; -{ - FIXSIGNEDCHAR(c); - if (c < 256) - return ((unsigned int)((_NX_CTypeTable_ + 1)[c] & (_D|_X))); - return 0; -} diff --git a/internat.subproj/NXToAscii.c b/internat.subproj/NXToAscii.c deleted file mode 100644 index b089fb2..0000000 --- a/internat.subproj/NXToAscii.c +++ /dev/null @@ -1,250 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright 1990, NeXT, Inc. - */ - -#include "NXCType.h" -#define FIXSIGNEDCHAR(i) if ((i & 0xFFFFFF80) == 0xFFFFFF80) i &= 0x000000FF - -unsigned char * -NXToAscii(c) - unsigned int c; -{ - static unsigned char woops[] = " "; - - FIXSIGNEDCHAR(c); - if (c < 128) { /* handle stuff already ASCII */ - woops[0] = c; - return (unsigned char *) woops; - } - switch (c) { - case 128: /* Figspace */ - return (unsigned char *) " "; - case 129: /* Agrave */ - case 130: /* Aacute */ - case 131: /* Acircumflex */ - case 132: /* Atilde */ - case 133: /* Adieresis */ - case 134: /* Aring */ - return (unsigned char *) "A"; - case 135: /* Ccedilla */ - return (unsigned char *) "C"; - case 136: /* Egrave */ - case 137: /* Eacute */ - case 138: /* Ecircumflex */ - case 139: /* Edieresis */ - return (unsigned char *) "E"; - case 140: /* Igrave */ - case 141: /* Iacute */ - case 142: /* Icircumflex */ - case 143: /* Idieresis */ - return (unsigned char *) "I"; - case 145: /* Ntilde */ - return (unsigned char *) "N"; - case 146: /* Ograve */ - case 147: /* Oacute */ - case 148: /* Ocircumflex */ - case 149: /* Otilde */ - case 150: /* Odieresis */ - case 233: /* Oslash */ - return (unsigned char *) "O"; - case 151: /* Ugrave */ - case 152: /* Uacute */ - case 153: /* Ucircumflex */ - case 154: /* Udieresis */ - return (unsigned char *) "U"; - case 155: /* Yacute */ - return (unsigned char *) "Y"; - case 230: /* eth */ - case 144: /* Eth */ - return (unsigned char *) "TH"; - case 156: /* Thorn */ - case 252: /* thorn */ - return (unsigned char *) "th"; - - case 174: /* fi */ - return (unsigned char *) "fi"; - case 175: /* fl */ - return (unsigned char *) "fl"; - - case 213: /* agrave */ - case 214: /* aacute */ - case 215: /* acircumflex */ - case 216: /* atilde */ - case 217: /* adieresis */ - case 218: /* aring */ - return (unsigned char *) "a"; - case 219: /* ccedilla */ - return (unsigned char *) "c"; - case 220: /* egrave */ - case 221: /* eacute */ - case 222: /* ecircumflex */ - case 223: /* edieresis */ - return (unsigned char *) "e"; - case 225: /* AE */ - return (unsigned char *) "AE"; - case 224: /* igrave */ - case 226: /* iacute */ - case 228: /* icircumflex */ - case 229: /* idieresis */ - return (unsigned char *) "i"; - case 231: /* ntilde */ - return (unsigned char *) "n"; - case 232: /* Lslash */ - return (unsigned char *) "L"; - case 234: /* OE */ - return (unsigned char *) "OE"; - case 236: /* ograve */ - case 237: /* oacute */ - case 238: /* ocircumflex */ - case 239: /* otilde */ - case 240: /* odieresis */ - case 249: /* oslash */ - return (unsigned char *) "o"; - case 241: /* ae */ - return (unsigned char *) "ae"; - case 242: /* ugrave */ - case 243: /* uacute */ - case 244: /* ucircumflex */ - case 246: /* udieresis */ - return (unsigned char *) "u"; - case 245: /* dotlessi */ - return (unsigned char *) "i"; - case 247: /* yacute */ - case 253: /* ydieresis */ - return (unsigned char *) "y"; - case 248: /* lslash */ - return (unsigned char *) "l"; - case 250: /* oe */ - return (unsigned char *) "oe"; - case 251: /* germandbls */ - return (unsigned char *) "ss"; - /* - * non-letter cases: - */ - case 158: /* multiply */ - return (unsigned char *) "x"; - case 159: /* divide */ - return (unsigned char *) "/"; - - case 161: /* exclamdown */ - return (unsigned char *) "!"; - case 169: /* quotesingle */ - return (unsigned char *) "'"; - - case 170: /* quotedblleft */ - case 186: /* quotedblright */ - case 185: /* quotedblbase */ - return (unsigned char *) "\""; - case 171: /* guillemotleft */ - return (unsigned char *) "<<"; - case 187: /* guillemotright */ - return (unsigned char *) ">>"; - case 184: /* quotesinglbase */ - return (unsigned char *) "'"; - case 172: /* guilsinglleft */ - return (unsigned char *) "<"; - case 173: /* guilsinglright */ - return (unsigned char *) ">"; - case 180: /* periodcentered */ - return (unsigned char *) "."; - case 181: /* brokenbar */ - return (unsigned char *) "|"; - case 183: /* bullet */ - return (unsigned char *) "*"; - case 188: /* ellipsis */ - return (unsigned char *) "..."; - case 191: /* questiondown */ - return (unsigned char *) "?"; - case 192: /* onesuperior */ - return (unsigned char *) "1"; - case 201: /* twosuperior */ - return (unsigned char *) "2"; - case 204: /* threesuperior */ - return (unsigned char *) "3"; - case 208: /* emdash */ - return (unsigned char *) "--"; - case 209: /* plusminus */ - return (unsigned char *) "+-"; - case 210: /* onequarter */ - return (unsigned char *) "1/4"; - case 211: /* onehalf */ - return (unsigned char *) "1/2"; - case 212: /* threequarters */ - return (unsigned char *) "3/4"; - case 227: /* ordfeminine */ - return (unsigned char *) "a"; - case 235: /* ordmasculine */ - return (unsigned char *) "o"; - case 157: /* mu */ - return (unsigned char *) "u"; - case 160: /* copyright */ - return (unsigned char *) "(C)"; - case 163: /* sterling */ - return (unsigned char *) "L"; - case 164: /* fraction */ - return (unsigned char *) "/"; - case 165: /* yen */ - return (unsigned char *) "Y"; - case 166: /* florin */ - return (unsigned char *) "f"; - case 176: /* registered */ - return (unsigned char *) "(R)"; - case 190: /* logicalnot */ - case 177: /* endash */ - return (unsigned char *) "-"; - case 178: /* dagger */ - return (unsigned char *) "+"; - case 179: /* daggerdbl */ - return (unsigned char *) "++"; - case 189: /* perthousand */ - return (unsigned char *) "0/00"; - case 193: /* grave */ - return (unsigned char *) "`"; - case 194: /* acute */ - return (unsigned char *) "'"; - case 195: /* circumflex */ - return (unsigned char *) "^"; - case 196: /* tilde */ - return (unsigned char *) "~"; - - /* - * Default & fallback cases: - */ - case 162: /* cent */ - case 167: /* section */ - case 168: /* currency */ - case 182: /* paragraph */ - case 197: /* macron */ - case 198: /* breve */ - case 199: /* dotaccent */ - case 200: /* dieresis */ - case 202: /* ring */ - case 203: /* cedilla */ - case 205: /* hungarumlaut */ - case 206: /* ogonek */ - case 207: /* caron */ - default: - return (unsigned char *) "_"; - } -} diff --git a/internat.subproj/NXToLower.c b/internat.subproj/NXToLower.c deleted file mode 100644 index 90ddc12..0000000 --- a/internat.subproj/NXToLower.c +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright 1990, NeXT, Inc. - */ - -#include "NXCType.h" -#define FIXSIGNEDCHAR(i) if ((i & 0xFFFFFF80) == 0xFFFFFF80) i &= 0x000000FF - -NXToLower(c) - unsigned int c; -{ - FIXSIGNEDCHAR(c); - return (NXIsUpper(c) ? ((unsigned int )(_NX_ULTable_)[c]) : c); -} diff --git a/internat.subproj/NXToUpper.c b/internat.subproj/NXToUpper.c deleted file mode 100644 index db23e6b..0000000 --- a/internat.subproj/NXToUpper.c +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright 1990, NeXT, Inc. - */ - -#include "NXCType.h" -#define FIXSIGNEDCHAR(i) if ((i & 0xFFFFFF80) == 0xFFFFFF80) i &= 0x000000FF - -NXToUpper(c) - unsigned int c; -{ - FIXSIGNEDCHAR(c); - return (NXIsLower(c) ? ((unsigned int )(_NX_ULTable_)[c]) : c); -} diff --git a/internat.subproj/PB.project b/internat.subproj/PB.project deleted file mode 100644 index 67c5990..0000000 --- a/internat.subproj/PB.project +++ /dev/null @@ -1,42 +0,0 @@ -{ - DYNAMIC_CODE_GEN = YES; - FILESTABLE = { - H_FILES = (NXCType.h); - OTHER_LINKED = ( - NXCType.c, - NXIsAlNum.c, - NXIsAlpha.c, - NXIsAscii.c, - NXIsCntrl.c, - NXIsDigit.c, - NXIsGraph.c, - NXIsLower.c, - NXIsPrint.c, - NXIsPunct.c, - NXIsSpace.c, - NXIsUpper.c, - NXIsXDigit.c, - NXToAscii.c, - NXToLower.c, - _NXToLower.c, - NXToUpper.c, - _NXToUpper.c - ); - OTHER_SOURCES = (Makefile.preamble, Makefile, Makefile.postamble); - SUBPROJECTS = (); - }; - LANGUAGE = English; - MAKEFILEDIR = "$(MAKEFILEPATH)/pb_makefiles"; - NEXTSTEP_BUILDTOOL = /bin/gnumake; - NEXTSTEP_JAVA_COMPILER = /usr/bin/javac; - NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc; - PDO_UNIX_BUILDTOOL = $NEXT_ROOT/Developer/bin/make; - PDO_UNIX_JAVA_COMPILER = "$(JDKBINDIR)/javac"; - PDO_UNIX_OBJCPLUS_COMPILER = "$(NEXTDEV_BIN)/gcc"; - PROJECTNAME = internat; - PROJECTTYPE = Component; - PROJECTVERSION = 2.8; - WINDOWS_BUILDTOOL = $NEXT_ROOT/Developer/Executables/make; - WINDOWS_JAVA_COMPILER = "$(JDKBINDIR)/javac.exe"; - WINDOWS_OBJCPLUS_COMPILER = "$(DEVDIR)/gcc"; -} diff --git a/internat.subproj/_NXToLower.c b/internat.subproj/_NXToLower.c deleted file mode 100644 index 0b10647..0000000 --- a/internat.subproj/_NXToLower.c +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright 1990, NeXT, Inc. - */ - -#include "NXCType.h" -#define FIXSIGNEDCHAR(i) if ((i & 0xFFFFFF80) == 0xFFFFFF80) i &= 0x000000FF - -_NXToLower(c) - unsigned int c; -{ - FIXSIGNEDCHAR(c); - if ((c < 256) && NXIsUpper(c)) - return ((unsigned int )(_NX_ULTable_)[c]); - return c; -} diff --git a/internat.subproj/_NXToUpper.c b/internat.subproj/_NXToUpper.c deleted file mode 100644 index e30b2ab..0000000 --- a/internat.subproj/_NXToUpper.c +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright 1990, NeXT, Inc. - */ - -#include "NXCType.h" -#define FIXSIGNEDCHAR(i) if ((i & 0xFFFFFF80) == 0xFFFFFF80) i &= 0x000000FF - -_NXToUpper(c) - unsigned int c; -{ - FIXSIGNEDCHAR(c); - if ((c < 256) && NXIsLower(c)) - return ((unsigned int )(_NX_ULTable_)[c]); - return c; -} diff --git a/internat/Makefile.inc b/internat/Makefile.inc new file mode 100644 index 0000000..2f3fdcc --- /dev/null +++ b/internat/Makefile.inc @@ -0,0 +1,6 @@ +.PATH: ${.CURDIR}/${MACHINE_ARCH}/internat ${.CURDIR}/internat + +SRCS += NXCType.c NXIsCntrl.c NXIsPrint.c NXIsXDigit.c _NXToLower.c \ + NXIsAlNum.c NXIsDigit.c NXIsPunct.c NXToAscii.c _NXToUpper.c \ + NXIsAlpha.c NXIsGraph.c NXIsSpace.c NXToLower.c \ + NXIsAscii.c NXIsLower.c NXIsUpper.c NXToUpper.c \ diff --git a/internat/NXCType.c b/internat/NXCType.c new file mode 100644 index 0000000..a9932b1 --- /dev/null +++ b/internat/NXCType.c @@ -0,0 +1,598 @@ +/* + * Copyright (c) 1999 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@ + */ +#pragma CC_NO_MACH_TEXT_SECTIONS +/* + * Copyright 1990, NeXT, Inc. + */ + +/* + * This file contains global data and the size of the global data can NOT + * change or otherwise it would make the shared library incompatable. This + * file has NOT been padded to allow more data to be added to it because the + * sizeof(char) is not expected to change. + */ + +#include "NXCType.h" + +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, +}; + +/* + * Upper to lower and lower to upper table for NeXTStep encoding (256 + * characters). An entry of zero means it's not an upper or lower case + * thing (i.e., isn't alphabetic). Otherwise, the value at a given + * position is the opposite case equivalent. E.g., the entry for the + * "A" position is "a" and the entry for position "a" is "A". + * + * 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. + */ +const unsigned char _NX_ULTable_[256] = { +/* 0 .notdef */ 0, +/* 1 .notdef */ 0, +/* 2 .notdef */ 0, +/* 3 .notdef */ 0, +/* 4 .notdef */ 0, +/* 5 .notdef */ 0, +/* 6 .notdef */ 0, +/* 7 .notdef */ 0, +/* 8 .notdef */ 0, +/* 9 .notdef */ 0, +/* 10 .notdef */ 0, +/* 11 .notdef */ 0, +/* 12 .notdef */ 0, +/* 13 .notdef */ 0, +/* 14 .notdef */ 0, +/* 15 .notdef */ 0, +/* 16 .notdef */ 0, +/* 17 .notdef */ 0, +/* 18 .notdef */ 0, +/* 19 .notdef */ 0, +/* 20 .notdef */ 0, +/* 21 .notdef */ 0, +/* 22 .notdef */ 0, +/* 23 .notdef */ 0, +/* 24 .notdef */ 0, +/* 25 .notdef */ 0, +/* 26 .notdef */ 0, +/* 27 .notdef */ 0, +/* 28 .notdef */ 0, +/* 29 .notdef */ 0, +/* 30 .notdef */ 0, +/* 31 .notdef */ 0, +/* 32 space */ 0, +/* 33 exclam */ 0, +/* 34 quotedbl */ 0, +/* 35 numbersign */ 0, +/* 36 dollar */ 0, +/* 37 percent */ 0, +/* 38 ampersand */ 0, +/* 39 quoteright */ 0, +/* 40 parenleft */ 0, +/* 41 parenright */ 0, +/* 42 asterisk */ 0, +/* 43 plus */ 0, +/* 44 comma */ 0, +/* 45 hyphen */ 0, +/* 46 period */ 0, +/* 47 slash */ 0, +/* 48 zero */ 0, +/* 49 one */ 0, +/* 50 two */ 0, +/* 51 three */ 0, +/* 52 four */ 0, +/* 53 five */ 0, +/* 54 six */ 0, +/* 55 seven */ 0, +/* 56 eight */ 0, +/* 57 nine */ 0, +/* 58 colon */ 0, +/* 59 semicolon */ 0, +/* 60 less */ 0, +/* 61 equal */ 0, +/* 62 greater */ 0, +/* 63 question */ 0, +/* 64 at */ 0, +/* 65 A */ 97, +/* 66 B */ 98, +/* 67 C */ 99, +/* 68 D */ 100, +/* 69 E */ 101, +/* 70 F */ 102, +/* 71 G */ 103, +/* 72 H */ 104, +/* 73 I */ 105, +/* 74 J */ 106, +/* 75 K */ 107, +/* 76 L */ 108, +/* 77 M */ 109, +/* 78 N */ 110, +/* 79 O */ 111, +/* 80 P */ 112, +/* 81 Q */ 113, +/* 82 R */ 114, +/* 83 S */ 115, +/* 84 T */ 116, +/* 85 U */ 117, +/* 86 V */ 118, +/* 87 W */ 119, +/* 88 X */ 120, +/* 89 Y */ 121, +/* 90 Z */ 122, +/* 91 bracketleft */ 0, +/* 92 backslash */ 0, +/* 93 bracketright */ 0, +/* 94 asciicircum */ 0, +/* 95 underscore */ 0, +/* 96 quoteleft */ 0, +/* 97 a */ 65, +/* 98 b */ 66, +/* 99 c */ 67, +/* 100 d */ 68, +/* 101 e */ 69, +/* 102 f */ 70, +/* 103 g */ 71, +/* 104 h */ 72, +/* 105 i */ 73, +/* 106 j */ 74, +/* 107 k */ 75, +/* 108 l */ 76, +/* 109 m */ 77, +/* 110 n */ 78, +/* 111 o */ 79, +/* 112 p */ 80, +/* 113 q */ 81, +/* 114 r */ 82, +/* 115 s */ 83, +/* 116 t */ 84, +/* 117 u */ 85, +/* 118 v */ 86, +/* 119 w */ 87, +/* 120 x */ 88, +/* 121 y */ 89, +/* 122 z */ 90, +/* 123 braceleft */ 0, +/* 124 bar */ 0, +/* 125 braceright */ 0, +/* 126 asciitilde */ 0, +/* 127 .notdef */ 0, +/* 128 .notdef */ 0, +/* 129 Agrave */ 213, +/* 130 Aacute */ 214, +/* 131 Acircumflex */ 215, +/* 132 Atilde */ 216, +/* 133 Adieresis */ 217, +/* 134 Aring */ 218, +/* 135 Ccedilla */ 219, +/* 136 Egrave */ 220, +/* 137 Eacute */ 221, +/* 138 Ecircumflex */ 222, +/* 139 Edieresis */ 223, +/* 140 Igrave */ 224, +/* 141 Iacute */ 226, +/* 142 Icircumflex */ 228, +/* 143 Idieresis */ 229, +/* 144 Eth */ 230, +/* 145 Ntilde */ 231, +/* 146 Ograve */ 236, +/* 147 Oacute */ 237, +/* 148 Ocircumflex */ 238, +/* 149 Otilde */ 239, +/* 150 Odieresis */ 240, +/* 151 Ugrave */ 242, +/* 152 Uacute */ 243, +/* 153 Ucircumflex */ 244, +/* 154 Udieresis */ 246, +/* 155 Yacute */ 247, +/* 156 Thorn */ 252, +/* 157 mu */ 0, +/* 158 multiply */ 0, +/* 159 divide */ 0, +/* 160 copyright */ 0, +/* 161 exclamdown */ 0, +/* 162 cent */ 0, +/* 163 sterling */ 0, +/* 164 fraction */ 0, +/* 165 yen */ 0, +/* 166 florin */ 0, +/* 167 section */ 0, +/* 168 currency */ 0, +/* 169 quotesingle */ 0, +/* 170 quotedblleft */ 0, +/* 171 guillemotleft */ 0, +/* 172 guilsinglleft */ 0, +/* 173 guilsinglright */ 0, +/* 174 fi */ 174, /* is self */ +/* 175 fl */ 175, /* is self */ +/* 176 registered */ 0, +/* 177 endash */ 0, +/* 178 dagger */ 0, +/* 179 daggerdbl */ 0, +/* 180 periodcentered */ 0, +/* 181 brokenbar */ 0, +/* 182 paragraph */ 0, +/* 183 bullet */ 0, +/* 184 quotesinglbase */ 0, +/* 185 quotedblbase */ 0, +/* 186 quotedblright */ 0, +/* 187 guillemotright */ 0, +/* 188 ellipsis */ 0, +/* 189 perthousand */ 0, +/* 190 logicalnot */ 0, +/* 191 questiondown */ 0, +/* 192 onesuperior */ 0, +/* 193 grave */ 0, +/* 194 acute */ 0, +/* 195 circumflex */ 0, +/* 196 tilde */ 0, +/* 197 macron */ 0, +/* 198 breve */ 0, +/* 199 dotaccent */ 0, +/* 200 dieresis */ 0, +/* 201 twosuperior */ 0, +/* 202 ring */ 0, +/* 203 cedilla */ 0, +/* 204 threesuperior */ 0, +/* 205 hungarumlaut */ 0, +/* 206 ogonek */ 0, +/* 207 caron */ 0, +/* 208 emdash */ 0, +/* 209 plusminus */ 0, +/* 210 onequarter */ 0, +/* 211 onehalf */ 0, +/* 212 threequarters */ 0, +/* 213 agrave */ 129, +/* 214 aacute */ 130, +/* 215 acircumflex */ 131, +/* 216 atilde */ 132, +/* 217 adieresis */ 133, +/* 218 aring */ 134, +/* 219 ccedilla */ 135, +/* 220 egrave */ 136, +/* 221 eacute */ 137, +/* 222 ecircumflex */ 138, +/* 223 edieresis */ 139, +/* 224 igrave */ 140, +/* 225 AE */ 241, +/* 226 iacute */ 141, +/* 227 ordfeminine */ 0, +/* 228 icircumflex */ 142, +/* 229 idieresis */ 143, +/* 230 eth */ 144, +/* 231 ntilde */ 145, +/* 232 Lslash */ 248, +/* 233 Oslash */ 249, +/* 234 OE */ 250, +/* 235 ordmasculine */ 0, +/* 236 ograve */ 146, +/* 237 oacute */ 147, +/* 238 ocircumflex */ 148, +/* 239 otilde */ 149, +/* 240 odieresis */ 150, +/* 241 ae */ 225, +/* 242 ugrave */ 151, +/* 243 uacute */ 152, +/* 244 ucircumflex */ 153, +/* 245 dotlessi */ 245, /* is self */ +/* 246 udieresis */ 154, +/* 247 yacute */ 155, +/* 248 lslash */ 232, +/* 249 oslash */ 233, +/* 250 oe */ 234, +/* 251 germandbls */ 251, /* is self */ +/* 252 thorn */ 156, +/* 253 ydieresis */ 253, /* is self */ +/* 254 .notdef */ 0, +/* 255 .notdef */ 0 +}; + diff --git a/internat/NXCType.h b/internat/NXCType.h new file mode 100644 index 0000000..3c5407e --- /dev/null +++ b/internat/NXCType.h @@ -0,0 +1,58 @@ +/* + * Copyright (c) 1999 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@ + */ +/* NXCType.h */ + +/* Copyright (c) 1990 NeXT, Inc. - 8/21/90 RM */ +/* patterned after ctype.h ; for 8-bit encoding, Europe only */ + +#ifndef _NXCTYPE_H +#define _NXCTYPE_H + +#include + +extern int NXIsAlNum(unsigned c); +extern int NXIsAlpha(unsigned c); +extern int NXIsCntrl(unsigned c); +extern int NXIsDigit(unsigned c); +extern int NXIsGraph(unsigned c); +extern int NXIsLower(unsigned c); +extern int NXIsPrint(unsigned c); +extern int NXIsPunct(unsigned c); +extern int NXIsSpace(unsigned c); +extern int NXIsUpper(unsigned c); +extern int NXIsXDigit(unsigned c); +extern int _NXToLower(unsigned c); +extern int _NXToUpper(unsigned c); +extern int NXToLower(unsigned c); +extern int NXToUpper(unsigned c); +extern int NXIsAscii(unsigned c); +extern unsigned char *NXToAscii(unsigned c); + +/* + * Data structures used by the internationized NX... versions of the + * ctype(3) routines. These structures are private to the above routines + * and should NOT be referenced by the application. + */ +extern const unsigned int _NX_CTypeTable_[]; /* char types */ +extern const unsigned char _NX_ULTable_[]; /* case conversion table */ + +#endif /* _NXCTYPE_H */ diff --git a/internat/NXIsAlNum.c b/internat/NXIsAlNum.c new file mode 100644 index 0000000..65e15e0 --- /dev/null +++ b/internat/NXIsAlNum.c @@ -0,0 +1,36 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright 1990, NeXT, Inc. + */ + +#include "NXCType.h" +#define FIXSIGNEDCHAR(i) if ((i & 0xFFFFFF80) == 0xFFFFFF80) i &= 0x000000FF + +int NXIsAlNum(c) + unsigned int c; +{ + FIXSIGNEDCHAR(c); + if (c < 256) + return ((unsigned int)((_NX_CTypeTable_ + 1)[c] & (_U|_L|_D))); + return 0; +} diff --git a/internat/NXIsAlpha.c b/internat/NXIsAlpha.c new file mode 100644 index 0000000..b946d95 --- /dev/null +++ b/internat/NXIsAlpha.c @@ -0,0 +1,37 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright 1990, NeXT, Inc. + */ + +#include "NXCType.h" +#define FIXSIGNEDCHAR(i) if ((i & 0xFFFFFF80) == 0xFFFFFF80) i &= 0x000000FF + + +int NXIsAlpha(c) + unsigned int c; +{ + FIXSIGNEDCHAR(c); + if (c < 256) + return ((unsigned int)((_NX_CTypeTable_ + 1)[c] & (_U|_L))); + return 0; +} diff --git a/internat/NXIsAscii.c b/internat/NXIsAscii.c new file mode 100644 index 0000000..f2545d4 --- /dev/null +++ b/internat/NXIsAscii.c @@ -0,0 +1,34 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright 1990, NeXT, Inc. + */ + +#include "NXCType.h" +#define FIXSIGNEDCHAR(i) if ((i & 0xFFFFFF80) == 0xFFFFFF80) i &= 0x000000FF + +NXIsAscii(c) + unsigned int c; +{ + FIXSIGNEDCHAR(c); + return (c <= 0177); +} diff --git a/internat/NXIsCntrl.c b/internat/NXIsCntrl.c new file mode 100644 index 0000000..71e154d --- /dev/null +++ b/internat/NXIsCntrl.c @@ -0,0 +1,36 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright 1990, NeXT, Inc. + */ + +#include "NXCType.h" +#define FIXSIGNEDCHAR(i) if ((i & 0xFFFFFF80) == 0xFFFFFF80) i &= 0x000000FF + +int NXIsCntrl(c) + unsigned int c; +{ + FIXSIGNEDCHAR(c); + if (c < 256) + return ((unsigned int)((_NX_CTypeTable_ + 1)[c] & (_C))); + return 0; +} diff --git a/internat/NXIsDigit.c b/internat/NXIsDigit.c new file mode 100644 index 0000000..1ead0b3 --- /dev/null +++ b/internat/NXIsDigit.c @@ -0,0 +1,36 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright 1990, NeXT, Inc. + */ + +#include "NXCType.h" +#define FIXSIGNEDCHAR(i) if ((i & 0xFFFFFF80) == 0xFFFFFF80) i &= 0x000000FF + +int NXIsDigit(c) + unsigned int c; +{ + FIXSIGNEDCHAR(c); + if (c < 256) + return ((unsigned int)((_NX_CTypeTable_ + 1)[c] & (_D))); + return 0; +} diff --git a/internat/NXIsGraph.c b/internat/NXIsGraph.c new file mode 100644 index 0000000..39545d1 --- /dev/null +++ b/internat/NXIsGraph.c @@ -0,0 +1,37 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright 1990, NeXT, Inc. + */ + +#include "NXCType.h" +#define FIXSIGNEDCHAR(i) if ((i & 0xFFFFFF80) == 0xFFFFFF80) i &= 0x000000FF + +int NXIsGraph(c) + unsigned int c; +{ + FIXSIGNEDCHAR(c); + if (c < 256) + return ((unsigned int)((_NX_CTypeTable_ + 1)[c] & (_P|_U|_L|_D))); + return 1; + /* NOTE: for 3.0, everything > 256 is probably Kanji, so say is graphic */ +} diff --git a/internat/NXIsLower.c b/internat/NXIsLower.c new file mode 100644 index 0000000..1074676 --- /dev/null +++ b/internat/NXIsLower.c @@ -0,0 +1,36 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright 1990, NeXT, Inc. + */ + +#include "NXCType.h" +#define FIXSIGNEDCHAR(i) if ((i & 0xFFFFFF80) == 0xFFFFFF80) i &= 0x000000FF + +int NXIsLower(c) + unsigned int c; +{ + FIXSIGNEDCHAR(c); + if (c < 256) + return ((unsigned int)((_NX_CTypeTable_ + 1)[c] & (_L))); + return 0; +} diff --git a/internat/NXIsPrint.c b/internat/NXIsPrint.c new file mode 100644 index 0000000..29154e1 --- /dev/null +++ b/internat/NXIsPrint.c @@ -0,0 +1,37 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright 1990, NeXT, Inc. + */ + +#include "NXCType.h" +#define FIXSIGNEDCHAR(i) if ((i & 0xFFFFFF80) == 0xFFFFFF80) i &= 0x000000FF + +int NXIsPrint(c) + unsigned int c; +{ + FIXSIGNEDCHAR(c); + if (c < 256) + return ((unsigned int)((_NX_CTypeTable_ + 1)[c] & (_P|_U|_L|_D|_B))); + return 1; + /* NOTE: for 3.0, everything > 255 is probably Kanji, so say printable... */ +} diff --git a/internat/NXIsPunct.c b/internat/NXIsPunct.c new file mode 100644 index 0000000..188d694 --- /dev/null +++ b/internat/NXIsPunct.c @@ -0,0 +1,36 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright 1990, NeXT, Inc. + */ + +#include "NXCType.h" +#define FIXSIGNEDCHAR(i) if ((i & 0xFFFFFF80) == 0xFFFFFF80) i &= 0x000000FF + +int NXIsPunct(c) + unsigned int c; +{ + FIXSIGNEDCHAR(c); + if (c < 256) + return ((unsigned int)((_NX_CTypeTable_ + 1)[c] & (_P))); + return 0; +} diff --git a/internat/NXIsSpace.c b/internat/NXIsSpace.c new file mode 100644 index 0000000..35c6d50 --- /dev/null +++ b/internat/NXIsSpace.c @@ -0,0 +1,36 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright 1990, NeXT, Inc. + */ + +#include "NXCType.h" +#define FIXSIGNEDCHAR(i) if ((i & 0xFFFFFF80) == 0xFFFFFF80) i &= 0x000000FF + +int NXIsSpace(c) + unsigned int c; +{ + FIXSIGNEDCHAR(c); + if (c < 256) + return ((unsigned int)((_NX_CTypeTable_ + 1)[c] & (_S))); + return 0; +} diff --git a/internat/NXIsUpper.c b/internat/NXIsUpper.c new file mode 100644 index 0000000..e23a927 --- /dev/null +++ b/internat/NXIsUpper.c @@ -0,0 +1,36 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright 1990, NeXT, Inc. + */ + +#include "NXCType.h" +#define FIXSIGNEDCHAR(i) if ((i & 0xFFFFFF80) == 0xFFFFFF80) i &= 0x000000FF + +int NXIsUpper(c) + unsigned int c; +{ + FIXSIGNEDCHAR(c); + if (c < 256) + return ((unsigned int)((_NX_CTypeTable_ + 1)[c] & (_U))); + return 0; +} diff --git a/internat/NXIsXDigit.c b/internat/NXIsXDigit.c new file mode 100644 index 0000000..785ca3f --- /dev/null +++ b/internat/NXIsXDigit.c @@ -0,0 +1,36 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright 1990, NeXT, Inc. + */ + +#include "NXCType.h" +#define FIXSIGNEDCHAR(i) if ((i & 0xFFFFFF80) == 0xFFFFFF80) i &= 0x000000FF + +int NXIsXDigit(c) + unsigned int c; +{ + FIXSIGNEDCHAR(c); + if (c < 256) + return ((unsigned int)((_NX_CTypeTable_ + 1)[c] & (_D|_X))); + return 0; +} diff --git a/internat/NXToAscii.c b/internat/NXToAscii.c new file mode 100644 index 0000000..b089fb2 --- /dev/null +++ b/internat/NXToAscii.c @@ -0,0 +1,250 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright 1990, NeXT, Inc. + */ + +#include "NXCType.h" +#define FIXSIGNEDCHAR(i) if ((i & 0xFFFFFF80) == 0xFFFFFF80) i &= 0x000000FF + +unsigned char * +NXToAscii(c) + unsigned int c; +{ + static unsigned char woops[] = " "; + + FIXSIGNEDCHAR(c); + if (c < 128) { /* handle stuff already ASCII */ + woops[0] = c; + return (unsigned char *) woops; + } + switch (c) { + case 128: /* Figspace */ + return (unsigned char *) " "; + case 129: /* Agrave */ + case 130: /* Aacute */ + case 131: /* Acircumflex */ + case 132: /* Atilde */ + case 133: /* Adieresis */ + case 134: /* Aring */ + return (unsigned char *) "A"; + case 135: /* Ccedilla */ + return (unsigned char *) "C"; + case 136: /* Egrave */ + case 137: /* Eacute */ + case 138: /* Ecircumflex */ + case 139: /* Edieresis */ + return (unsigned char *) "E"; + case 140: /* Igrave */ + case 141: /* Iacute */ + case 142: /* Icircumflex */ + case 143: /* Idieresis */ + return (unsigned char *) "I"; + case 145: /* Ntilde */ + return (unsigned char *) "N"; + case 146: /* Ograve */ + case 147: /* Oacute */ + case 148: /* Ocircumflex */ + case 149: /* Otilde */ + case 150: /* Odieresis */ + case 233: /* Oslash */ + return (unsigned char *) "O"; + case 151: /* Ugrave */ + case 152: /* Uacute */ + case 153: /* Ucircumflex */ + case 154: /* Udieresis */ + return (unsigned char *) "U"; + case 155: /* Yacute */ + return (unsigned char *) "Y"; + case 230: /* eth */ + case 144: /* Eth */ + return (unsigned char *) "TH"; + case 156: /* Thorn */ + case 252: /* thorn */ + return (unsigned char *) "th"; + + case 174: /* fi */ + return (unsigned char *) "fi"; + case 175: /* fl */ + return (unsigned char *) "fl"; + + case 213: /* agrave */ + case 214: /* aacute */ + case 215: /* acircumflex */ + case 216: /* atilde */ + case 217: /* adieresis */ + case 218: /* aring */ + return (unsigned char *) "a"; + case 219: /* ccedilla */ + return (unsigned char *) "c"; + case 220: /* egrave */ + case 221: /* eacute */ + case 222: /* ecircumflex */ + case 223: /* edieresis */ + return (unsigned char *) "e"; + case 225: /* AE */ + return (unsigned char *) "AE"; + case 224: /* igrave */ + case 226: /* iacute */ + case 228: /* icircumflex */ + case 229: /* idieresis */ + return (unsigned char *) "i"; + case 231: /* ntilde */ + return (unsigned char *) "n"; + case 232: /* Lslash */ + return (unsigned char *) "L"; + case 234: /* OE */ + return (unsigned char *) "OE"; + case 236: /* ograve */ + case 237: /* oacute */ + case 238: /* ocircumflex */ + case 239: /* otilde */ + case 240: /* odieresis */ + case 249: /* oslash */ + return (unsigned char *) "o"; + case 241: /* ae */ + return (unsigned char *) "ae"; + case 242: /* ugrave */ + case 243: /* uacute */ + case 244: /* ucircumflex */ + case 246: /* udieresis */ + return (unsigned char *) "u"; + case 245: /* dotlessi */ + return (unsigned char *) "i"; + case 247: /* yacute */ + case 253: /* ydieresis */ + return (unsigned char *) "y"; + case 248: /* lslash */ + return (unsigned char *) "l"; + case 250: /* oe */ + return (unsigned char *) "oe"; + case 251: /* germandbls */ + return (unsigned char *) "ss"; + /* + * non-letter cases: + */ + case 158: /* multiply */ + return (unsigned char *) "x"; + case 159: /* divide */ + return (unsigned char *) "/"; + + case 161: /* exclamdown */ + return (unsigned char *) "!"; + case 169: /* quotesingle */ + return (unsigned char *) "'"; + + case 170: /* quotedblleft */ + case 186: /* quotedblright */ + case 185: /* quotedblbase */ + return (unsigned char *) "\""; + case 171: /* guillemotleft */ + return (unsigned char *) "<<"; + case 187: /* guillemotright */ + return (unsigned char *) ">>"; + case 184: /* quotesinglbase */ + return (unsigned char *) "'"; + case 172: /* guilsinglleft */ + return (unsigned char *) "<"; + case 173: /* guilsinglright */ + return (unsigned char *) ">"; + case 180: /* periodcentered */ + return (unsigned char *) "."; + case 181: /* brokenbar */ + return (unsigned char *) "|"; + case 183: /* bullet */ + return (unsigned char *) "*"; + case 188: /* ellipsis */ + return (unsigned char *) "..."; + case 191: /* questiondown */ + return (unsigned char *) "?"; + case 192: /* onesuperior */ + return (unsigned char *) "1"; + case 201: /* twosuperior */ + return (unsigned char *) "2"; + case 204: /* threesuperior */ + return (unsigned char *) "3"; + case 208: /* emdash */ + return (unsigned char *) "--"; + case 209: /* plusminus */ + return (unsigned char *) "+-"; + case 210: /* onequarter */ + return (unsigned char *) "1/4"; + case 211: /* onehalf */ + return (unsigned char *) "1/2"; + case 212: /* threequarters */ + return (unsigned char *) "3/4"; + case 227: /* ordfeminine */ + return (unsigned char *) "a"; + case 235: /* ordmasculine */ + return (unsigned char *) "o"; + case 157: /* mu */ + return (unsigned char *) "u"; + case 160: /* copyright */ + return (unsigned char *) "(C)"; + case 163: /* sterling */ + return (unsigned char *) "L"; + case 164: /* fraction */ + return (unsigned char *) "/"; + case 165: /* yen */ + return (unsigned char *) "Y"; + case 166: /* florin */ + return (unsigned char *) "f"; + case 176: /* registered */ + return (unsigned char *) "(R)"; + case 190: /* logicalnot */ + case 177: /* endash */ + return (unsigned char *) "-"; + case 178: /* dagger */ + return (unsigned char *) "+"; + case 179: /* daggerdbl */ + return (unsigned char *) "++"; + case 189: /* perthousand */ + return (unsigned char *) "0/00"; + case 193: /* grave */ + return (unsigned char *) "`"; + case 194: /* acute */ + return (unsigned char *) "'"; + case 195: /* circumflex */ + return (unsigned char *) "^"; + case 196: /* tilde */ + return (unsigned char *) "~"; + + /* + * Default & fallback cases: + */ + case 162: /* cent */ + case 167: /* section */ + case 168: /* currency */ + case 182: /* paragraph */ + case 197: /* macron */ + case 198: /* breve */ + case 199: /* dotaccent */ + case 200: /* dieresis */ + case 202: /* ring */ + case 203: /* cedilla */ + case 205: /* hungarumlaut */ + case 206: /* ogonek */ + case 207: /* caron */ + default: + return (unsigned char *) "_"; + } +} diff --git a/internat/NXToLower.c b/internat/NXToLower.c new file mode 100644 index 0000000..90ddc12 --- /dev/null +++ b/internat/NXToLower.c @@ -0,0 +1,34 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright 1990, NeXT, Inc. + */ + +#include "NXCType.h" +#define FIXSIGNEDCHAR(i) if ((i & 0xFFFFFF80) == 0xFFFFFF80) i &= 0x000000FF + +NXToLower(c) + unsigned int c; +{ + FIXSIGNEDCHAR(c); + return (NXIsUpper(c) ? ((unsigned int )(_NX_ULTable_)[c]) : c); +} diff --git a/internat/NXToUpper.c b/internat/NXToUpper.c new file mode 100644 index 0000000..db23e6b --- /dev/null +++ b/internat/NXToUpper.c @@ -0,0 +1,34 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright 1990, NeXT, Inc. + */ + +#include "NXCType.h" +#define FIXSIGNEDCHAR(i) if ((i & 0xFFFFFF80) == 0xFFFFFF80) i &= 0x000000FF + +NXToUpper(c) + unsigned int c; +{ + FIXSIGNEDCHAR(c); + return (NXIsLower(c) ? ((unsigned int )(_NX_ULTable_)[c]) : c); +} diff --git a/internat/_NXToLower.c b/internat/_NXToLower.c new file mode 100644 index 0000000..0b10647 --- /dev/null +++ b/internat/_NXToLower.c @@ -0,0 +1,36 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright 1990, NeXT, Inc. + */ + +#include "NXCType.h" +#define FIXSIGNEDCHAR(i) if ((i & 0xFFFFFF80) == 0xFFFFFF80) i &= 0x000000FF + +_NXToLower(c) + unsigned int c; +{ + FIXSIGNEDCHAR(c); + if ((c < 256) && NXIsUpper(c)) + return ((unsigned int )(_NX_ULTable_)[c]); + return c; +} diff --git a/internat/_NXToUpper.c b/internat/_NXToUpper.c new file mode 100644 index 0000000..e30b2ab --- /dev/null +++ b/internat/_NXToUpper.c @@ -0,0 +1,36 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright 1990, NeXT, Inc. + */ + +#include "NXCType.h" +#define FIXSIGNEDCHAR(i) if ((i & 0xFFFFFF80) == 0xFFFFFF80) i &= 0x000000FF + +_NXToUpper(c) + unsigned int c; +{ + FIXSIGNEDCHAR(c); + if ((c < 256) && NXIsLower(c)) + return ((unsigned int )(_NX_ULTable_)[c]); + return c; +} diff --git a/locale.subproj/Makefile b/locale.subproj/Makefile deleted file mode 100644 index f126176..0000000 --- a/locale.subproj/Makefile +++ /dev/null @@ -1,46 +0,0 @@ -# -# Generated by the NeXT Project Builder. -# -# NOTE: Do NOT change this file -- Project Builder maintains it. -# -# Put all of your customizations in files called Makefile.preamble -# and Makefile.postamble (both optional), and Makefile will include them. -# - -NAME = locale - -PROJECTVERSION = 2.8 -PROJECT_TYPE = Component - -CFILES = ansi.c ctype.c euc.c frune.c isctype.c lconv.c localeconv.c\ - mbrune.c none.c rune.c runetable.c setlocale.c utf2.c - -OTHERSRCS = Makefile.preamble Makefile Makefile.postamble - - -MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles -CODE_GEN_STYLE = DYNAMIC -MAKEFILE = subproj.make -LIBS = -DEBUG_LIBS = $(LIBS) -PROF_LIBS = $(LIBS) - - - - -NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc -WINDOWS_OBJCPLUS_COMPILER = $(DEVDIR)/gcc -PDO_UNIX_OBJCPLUS_COMPILER = $(NEXTDEV_BIN)/gcc -NEXTSTEP_JAVA_COMPILER = /usr/bin/javac -WINDOWS_JAVA_COMPILER = $(JDKBINDIR)/javac.exe -PDO_UNIX_JAVA_COMPILER = $(JDKBINDIR)/javac - -include $(MAKEFILEDIR)/platform.make - --include Makefile.preamble - -include $(MAKEFILEDIR)/$(MAKEFILE) - --include Makefile.postamble - --include Makefile.dependencies diff --git a/locale.subproj/Makefile.postamble b/locale.subproj/Makefile.postamble deleted file mode 100644 index 411cde6..0000000 --- a/locale.subproj/Makefile.postamble +++ /dev/null @@ -1,100 +0,0 @@ -############################################################################### -# Makefile.postamble -# Copyright 1997, Apple Computer, Inc. -# -# Use this makefile, which is imported after all other makefiles, to -# override attributes for a project's Makefile environment. This allows you -# to take advantage of the environment set up by the other Makefiles. -# You can also define custom rules at the end of this file. -# -############################################################################### -# -# These variables are exported by the standard makefiles and can be -# used in any customizations you make. They are *outputs* of -# the Makefiles and should be used, not set. -# -# PRODUCTS: products to install. All of these products will be placed in -# the directory $(DSTROOT)$(INSTALLDIR) -# GLOBAL_RESOURCE_DIR: The directory to which resources are copied. -# LOCAL_RESOURCE_DIR: The directory to which localized resources are copied. -# OFILE_DIR: Directory into which .o object files are generated. -# DERIVED_SRC_DIR: Directory used for all other derived files -# -# ALL_CFLAGS: flags to pass when compiling .c files -# ALL_MFLAGS: flags to pass when compiling .m files -# ALL_CCFLAGS: flags to pass when compiling .cc, .cxx, and .C files -# ALL_MMFLAGS: flags to pass when compiling .mm, .mxx, and .M files -# ALL_PRECOMPFLAGS: flags to pass when precompiling .h files -# ALL_LDFLAGS: flags to pass when linking object files -# ALL_LIBTOOL_FLAGS: flags to pass when libtooling object files -# ALL_PSWFLAGS: flags to pass when processing .psw and .pswm (pswrap) files -# ALL_RPCFLAGS: flags to pass when processing .rpc (rpcgen) files -# ALL_YFLAGS: flags to pass when processing .y (yacc) files -# ALL_LFLAGS: flags to pass when processing .l (lex) files -# -# NAME: name of application, bundle, subproject, palette, etc. -# LANGUAGES: langages in which the project is written (default "English") -# English_RESOURCES: localized resources (e.g. nib's, images) of project -# GLOBAL_RESOURCES: non-localized resources of project -# -# SRCROOT: base directory in which to place the new source files -# SRCPATH: relative path from SRCROOT to present subdirectory -# -# INSTALLDIR: Directory the product will be installed into by 'install' target -# PUBLIC_HDR_INSTALLDIR: where to install public headers. Don't forget -# to prefix this with DSTROOT when you use it. -# PRIVATE_HDR_INSTALLDIR: where to install private headers. Don't forget -# to prefix this with DSTROOT when you use it. -# -# EXECUTABLE_EXT: Executable extension for the platform (i.e. .exe on Windows) -# -############################################################################### - -# Some compiler flags can be overridden here for certain build situations. -# -# WARNING_CFLAGS: flag used to set warning level (defaults to -Wmost) -# DEBUG_SYMBOLS_CFLAGS: debug-symbol flag passed to all builds (defaults -# to -g) -# DEBUG_BUILD_CFLAGS: flags passed during debug builds (defaults to -DDEBUG) -# OPTIMIZE_BUILD_CFLAGS: flags passed during optimized builds (defaults -# to -O) -# PROFILE_BUILD_CFLAGS: flags passed during profile builds (defaults -# to -pg -DPROFILE) -# LOCAL_DIR_INCLUDE_DIRECTIVE: flag used to add current directory to -# the include path (defaults to -I.) -# DEBUG_BUILD_LDFLAGS, OPTIMIZE_BUILD_LDFLAGS, PROFILE_BUILD_LDFLAGS: flags -# passed to ld/libtool (defaults to nothing) - - -# Library and Framework projects only: -# INSTALL_NAME_DIRECTIVE: This directive ensures that executables linked -# against the framework will run against the correct version even if -# the current version of the framework changes. You may override this -# to "" as an alternative to using the DYLD_LIBRARY_PATH during your -# development cycle, but be sure to restore it before installing. - - -# Ownership and permissions of files installed by 'install' target - -#INSTALL_AS_USER = root - # User/group ownership -#INSTALL_AS_GROUP = wheel - # (probably want to set both of these) -#INSTALL_PERMISSIONS = - # If set, 'install' chmod's executable to this - - -# Options to strip. Note: -S strips debugging symbols (executables can be stripped -# down further with -x or, if they load no bundles, with no options at all). - -#STRIPFLAGS = -S - - -######################################################################### -# Put rules to extend the behavior of the standard Makefiles here. Include them in -# the dependency tree via cvariables like AFTER_INSTALL in the Makefile.preamble. -# -# You should avoid redefining things like "install" or "app", as they are -# owned by the top-level Makefile API and no context has been set up for where -# derived files should go. -# diff --git a/locale.subproj/Makefile.preamble b/locale.subproj/Makefile.preamble deleted file mode 100644 index c1624b4..0000000 --- a/locale.subproj/Makefile.preamble +++ /dev/null @@ -1,137 +0,0 @@ -############################################################################### -# Makefile.preamble -# Copyright 1997, Apple Computer, Inc. -# -# Use this makefile for configuring the standard application makefiles -# associated with ProjectBuilder. It is included before the main makefile. -# In Makefile.preamble you set attributes for a project, so they are available -# to the project's makefiles. In contrast, you typically write additional rules or -# override built-in behavior in the Makefile.postamble. -# -# Each directory in a project tree (main project plus subprojects) should -# have its own Makefile.preamble and Makefile.postamble. -############################################################################### -# -# Before the main makefile is included for this project, you may set: -# -# MAKEFILEDIR: Directory in which to find $(MAKEFILE) -# MAKEFILE: Top level mechanism Makefile (e.g., app.make, bundle.make) - -# Compiler/linker flags added to the defaults: The OTHER_* variables will be -# inherited by all nested sub-projects, but the LOCAL_ versions of the same -# variables will not. Put your -I, -D, -U, and -L flags in ProjectBuilder's -# Build Attributes inspector if at all possible. To override the default flags -# that get passed to ${CC} (e.g. change -O to -O2), see Makefile.postamble. The -# variables below are *inputs* to the build process and distinct from the override -# settings done (less often) in the Makefile.postamble. -# -# OTHER_CFLAGS, LOCAL_CFLAGS: additional flags to pass to the compiler -# Note that $(OTHER_CFLAGS) and $(LOCAL_CFLAGS) are used for .h, ...c, .m, -# .cc, .cxx, .C, and .M files. There is no need to respecify the -# flags in OTHER_MFLAGS, etc. -# OTHER_MFLAGS, LOCAL_MFLAGS: additional flags for .m files -# OTHER_CCFLAGS, LOCAL_CCFLAGS: additional flags for .cc, .cxx, and ...C files -# OTHER_MMFLAGS, LOCAL_MMFLAGS: additional flags for .mm and .M files -# OTHER_PRECOMPFLAGS, LOCAL_PRECOMPFLAGS: additional flags used when -# precompiling header files -# OTHER_LDFLAGS, LOCAL_LDFLAGS: additional flags passed to ld and libtool -# OTHER_PSWFLAGS, LOCAL_PSWFLAGS: additional flags passed to pswrap -# OTHER_RPCFLAGS, LOCAL_RPCFLAGS: additional flags passed to rpcgen -# OTHER_YFLAGS, LOCAL_YFLAGS: additional flags passed to yacc -# OTHER_LFLAGS, LOCAL_LFLAGS: additional flags passed to lex - -# These variables provide hooks enabling you to add behavior at almost every -# stage of the make: -# -# BEFORE_PREBUILD: targets to build before installing headers for a subproject -# AFTER_PREBUILD: targets to build after installing headers for a subproject -# BEFORE_BUILD_RECURSION: targets to make before building subprojects -# BEFORE_BUILD: targets to make before a build, but after subprojects -# AFTER_BUILD: targets to make after a build -# -# BEFORE_INSTALL: targets to build before installing the product -# AFTER_INSTALL: targets to build after installing the product -# BEFORE_POSTINSTALL: targets to build before postinstalling every subproject -# AFTER_POSTINSTALL: targts to build after postinstalling every subproject -# -# BEFORE_INSTALLHDRS: targets to build before installing headers for a -# subproject -# AFTER_INSTALLHDRS: targets to build after installing headers for a subproject -# BEFORE_INSTALLSRC: targets to build before installing source for a subproject -# AFTER_INSTALLSRC: targets to build after installing source for a subproject -# -# BEFORE_DEPEND: targets to build before building dependencies for a -# subproject -# AFTER_DEPEND: targets to build after building dependencies for a -# subproject -# -# AUTOMATIC_DEPENDENCY_INFO: if YES, then the dependency file is -# updated every time the project is built. If NO, the dependency -# file is only built when the depend target is invoked. - -# Framework-related variables: -# FRAMEWORK_DLL_INSTALLDIR: On Windows platforms, this variable indicates -# where to put the framework's DLL. This variable defaults to -# $(INSTALLDIR)/../Executables - -# Library-related variables: -# PUBLIC_HEADER_DIR: Determines where public exported header files -# should be installed. Do not include $(DSTROOT) in this value -- -# it is prefixed automatically. For library projects you should -# set this to something like /Developer/Headers/$(NAME). Do not set -# this variable for framework projects unless you do not want the -# header files included in the framework. -# PRIVATE_HEADER_DIR: Determines where private exported header files -# should be installed. Do not include $(DSTROOT) in this value -- -# it is prefixed automatically. -# LIBRARY_STYLE: This may be either STATIC or DYNAMIC, and determines -# whether the libraries produced are statically linked when they -# are used or if they are dynamically loadable. This defaults to -# DYNAMIC. -# LIBRARY_DLL_INSTALLDIR: On Windows platforms, this variable indicates -# where to put the library's DLL. This variable defaults to -# $(INSTALLDIR)/../Executables -# -# INSTALL_AS_USER: owner of the intalled products (default root) -# INSTALL_AS_GROUP: group of the installed products (default wheel) -# INSTALL_PERMISSIONS: permissions of the installed product (default o+rX) -# -# OTHER_RECURSIVE_VARIABLES: The names of variables which you want to be -# passed on the command line to recursive invocations of make. Note that -# the values in OTHER_*FLAGS are inherited by subprojects automatically -- -# you do not have to (and shouldn't) add OTHER_*FLAGS to -# OTHER_RECURSIVE_VARIABLES. - -# Additional headers to export beyond those in the PB.project: -# OTHER_PUBLIC_HEADERS -# OTHER_PROJECT_HEADERS -# OTHER_PRIVATE_HEADERS - -# Additional files for the project's product: <> -# OTHER_RESOURCES: (non-localized) resources for this project -# OTHER_OFILES: relocatables to be linked into this project -# OTHER_LIBS: more libraries to link against -# OTHER_PRODUCT_DEPENDS: other dependencies of this project -# OTHER_SOURCEFILES: other source files maintained by .pre/postamble -# OTHER_GARBAGE: additional files to be removed by `make clean' - -# Set this to YES if you don't want a final libtool call for a library/framework. -# BUILD_OFILES_LIST_ONLY - -# To include a version string, project source must exist in a directory named -# $(NAME).%d[.%d][.%d] and the following line must be uncommented. -# OTHER_GENERATED_OFILES = $(VERS_OFILE) - -# This definition will suppress stripping of debug symbols when an executable -# is installed. By default it is YES. -# STRIP_ON_INSTALL = NO - -# Uncomment to suppress generation of a KeyValueCoding index when installing -# frameworks (This index is used by WOB and IB to determine keys available -# for an object). Set to YES by default. -# PREINDEX_FRAMEWORK = NO - -# Change this definition to install projects somewhere other than the -# standard locations. NEXT_ROOT defaults to "C:/Apple" on Windows systems -# and "" on other systems. -DSTROOT = $(HOME) diff --git a/locale.subproj/PB.project b/locale.subproj/PB.project deleted file mode 100644 index 25515a8..0000000 --- a/locale.subproj/PB.project +++ /dev/null @@ -1,37 +0,0 @@ -{ - DYNAMIC_CODE_GEN = YES; - FILESTABLE = { - H_FILES = (); - OTHER_LINKED = ( - ansi.c, - ctype.c, - euc.c, - frune.c, - isctype.c, - lconv.c, - localeconv.c, - mbrune.c, - none.c, - rune.c, - runetable.c, - setlocale.c, - utf2.c - ); - OTHER_SOURCES = (Makefile.preamble, Makefile, Makefile.postamble); - SUBPROJECTS = (); - }; - LANGUAGE = English; - MAKEFILEDIR = "$(MAKEFILEPATH)/pb_makefiles"; - NEXTSTEP_BUILDTOOL = /bin/gnumake; - NEXTSTEP_JAVA_COMPILER = /usr/bin/javac; - NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc; - PDO_UNIX_BUILDTOOL = $NEXT_ROOT/Developer/bin/make; - PDO_UNIX_JAVA_COMPILER = "$(JDKBINDIR)/javac"; - PDO_UNIX_OBJCPLUS_COMPILER = "$(NEXTDEV_BIN)/gcc"; - PROJECTNAME = locale; - PROJECTTYPE = Component; - PROJECTVERSION = 2.8; - WINDOWS_BUILDTOOL = $NEXT_ROOT/Developer/Executables/make; - WINDOWS_JAVA_COMPILER = "$(JDKBINDIR)/javac.exe"; - WINDOWS_OBJCPLUS_COMPILER = "$(DEVDIR)/gcc"; -} diff --git a/locale.subproj/ansi.c b/locale.subproj/ansi.c deleted file mode 100644 index cba06a3..0000000 --- a/locale.subproj/ansi.c +++ /dev/null @@ -1,166 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * 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 -#include -#include -#include - -int -mblen(s, n) - const char *s; - size_t n; -{ - char const *e; - - if (s == 0 || *s == 0) - return (0); /* No support for state dependent encodings. */ - - if (sgetrune(s, (int)n, &e) == _INVALID_RUNE) - return (s - e); - return (e - s); -} - -int -mbtowc(pwc, s, n) - wchar_t *pwc; - const char *s; - size_t n; -{ - char const *e; - rune_t r; - - if (s == 0 || *s == 0) - return (0); /* No support for state dependent encodings. */ - - if ((r = sgetrune(s, (int)n, &e)) == _INVALID_RUNE) - return (s - e); - if (pwc) - *pwc = r; - return (e - s); -} - -int -wctomb(s, wchar) - char *s; - wchar_t wchar; -{ - char *e; - - if (s == 0) - return (0); /* No support for state dependent encodings. */ - - if (wchar == 0) { - *s = 0; - return (1); - } - - sputrune(wchar, s, MB_CUR_MAX, &e); - return (e ? e - s : -1); -} - -size_t -mbstowcs(pwcs, s, n) - wchar_t *pwcs; - const char *s; - size_t n; -{ - char const *e; - int cnt = 0; - - if (!pwcs || !s) - return (-1); - - while (n-- > 0) { - *pwcs = sgetrune(s, MB_LEN_MAX, &e); - if (*pwcs == _INVALID_RUNE) - return (-1); - if (*pwcs++ == 0) - break; - s = e; - ++cnt; - } - return (cnt); -} - -size_t -wcstombs(s, pwcs, n) - char *s; - const wchar_t *pwcs; - size_t n; -{ - char *e; - int cnt = 0; - - if (!pwcs || !s) - return (-1); - - while (n > 0) { - if (*pwcs == 0) { - *s = 0; - break; - } - if (!sputrune(*pwcs++, s, (int)n, &e)) - return (-1); /* encoding error */ - if (!e) /* too long */ - return (cnt); - cnt += e - s; - s = e; - } - return (cnt); -} diff --git a/locale.subproj/ctype.c b/locale.subproj/ctype.c deleted file mode 100644 index 7dec737..0000000 --- a/locale.subproj/ctype.c +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * 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. - * - * 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. - */ - - -#define _U 0x01 -#define _L 0x02 -#define _N 0x04 -#define _S 0x08 -#define _P 0x10 -#define _C 0x20 -#define _X 0x40 -#define _B 0x80 - -const char __ctype[1 + 256] = { - 0, - _C, _C, _C, _C, _C, _C, _C, _C, - _C, _C|_S, _C|_S, _C|_S, _C|_S, _C|_S, _C, _C, - _C, _C, _C, _C, _C, _C, _C, _C, - _C, _C, _C, _C, _C, _C, _C, _C, - _S|_B, _P, _P, _P, _P, _P, _P, _P, - _P, _P, _P, _P, _P, _P, _P, _P, - _N, _N, _N, _N, _N, _N, _N, _N, - _N, _N, _P, _P, _P, _P, _P, _P, - _P, _U|_X, _U|_X, _U|_X, _U|_X, _U|_X, _U|_X, _U, - _U, _U, _U, _U, _U, _U, _U, _U, - _U, _U, _U, _U, _U, _U, _U, _U, - _U, _U, _U, _P, _P, _P, _P, _P, - _P, _L|_X, _L|_X, _L|_X, _L|_X, _L|_X, _L|_X, _L, - _L, _L, _L, _L, _L, _L, _L, _L, - _L, _L, _L, _L, _L, _L, _L, _L, - _L, _L, _L, _P, _P, _P, _P, _C -}; - -char *_ctype_ = __ctype; /* Backward compatibility. */ diff --git a/locale.subproj/euc.c b/locale.subproj/euc.c deleted file mode 100644 index 41394b9..0000000 --- a/locale.subproj/euc.c +++ /dev/null @@ -1,238 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * 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 - -#include -#include -#include -#include -#include - -rune_t _EUC_sgetrune __P((const char *, size_t, char const **)); -int _EUC_sputrune __P((rune_t, char *, size_t, char **)); - -typedef struct { - int count[4]; - rune_t bits[4]; - rune_t mask; -} _EucInfo; - -int -_EUC_init(rl) - _RuneLocale *rl; -{ - _EucInfo *ei; - int x; - char *v, *e; - - rl->sgetrune = _EUC_sgetrune; - rl->sputrune = _EUC_sputrune; - - if (!rl->variable) { - free(rl); - return (EFTYPE); - } - v = (char *) rl->variable; - - while (*v == ' ' || *v == '\t') - ++v; - - if ((ei = malloc(sizeof(_EucInfo))) == NULL) { - free(rl); - return (ENOMEM); - } - for (x = 0; x < 4; ++x) { - ei->count[x] = (int) strtol(v, &e, 0); - if (v == e || !(v = e)) { - free(rl); - free(ei); - return (EFTYPE); - } - while (*v == ' ' || *v == '\t') - ++v; - ei->bits[x] = (int) strtol(v, &e, 0); - if (v == e || !(v = e)) { - free(rl); - free(ei); - return (EFTYPE); - } - while (*v == ' ' || *v == '\t') - ++v; - } - ei->mask = (int)strtol(v, &e, 0); - if (v == e || !(v = e)) { - free(rl); - free(ei); - return (EFTYPE); - } - if (sizeof(_EucInfo) <= rl->variable_len) { - memcpy(rl->variable, ei, sizeof(_EucInfo)); - free(ei); - } else { - rl->variable = &ei; - } - rl->variable_len = sizeof(_EucInfo); - _CurrentRuneLocale = rl; - __mb_cur_max = 3; - return (0); -} - -#define CEI ((_EucInfo *)(_CurrentRuneLocale->variable)) - -#define _SS2 0x008e -#define _SS3 0x008f - -static inline int -_euc_set(c) - 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; -{ - rune_t rune = 0; - int len, set; - - if (n < 1 || (len = CEI->count[set = _euc_set(*string)]) > n) { - if (result) - *result = string; - return (_INVALID_RUNE); - } - 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 (result) - *result = string; - return ((rune & ~CEI->mask) | CEI->bits[set]); -} - -int -_EUC_sputrune(c, string, n, result) - rune_t c; - char *string, **result; - size_t n; -{ - rune_t m = c & CEI->mask; - rune_t nm = c & ~m; - int i, len; - - 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; - } else { - 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]; - if (n < len) { - if (result) - *result = NULL; - return (len); - } - *string++ = _SS2; - --i; - } else - if (m == CEI->bits[3]) { - i = len = CEI->count[3]; - if (n < len) { - if (result) - *result = NULL; - return (len); - } - *string++ = _SS3; - --i; - } else - goto CodeSet1; /* Bletch */ - while (i-- > 0) - *string++ = (nm >> (i << 3)) & 0xff; - if (result) - *result = string; - } - return (len); -} diff --git a/locale.subproj/frune.c b/locale.subproj/frune.c deleted file mode 100644 index a6adad9..0000000 --- a/locale.subproj/frune.c +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * 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 -#include -#include -#include - -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); -} - -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); -} - -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); -} diff --git a/locale.subproj/isctype.c b/locale.subproj/isctype.c deleted file mode 100644 index 593b8ed..0000000 --- a/locale.subproj/isctype.c +++ /dev/null @@ -1,193 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * 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. - */ - - -#define _ANSI_LIBRARY -#include - -#undef isalnum -int -isalnum(c) - int c; -{ - return(__istype((c), (_A|_D))); -} - -#undef isalpha -int -isalpha(c) - int c; -{ - return (__istype((c), _A)); -} - -#undef isascii -int -isascii(c) - int c; -{ - return((c & ~0x7F) == 0); -} - -#undef isblank -int -isblank(c) - int c; -{ - return (__istype((c), _B)); -} - -#undef iscntrl -int -iscntrl(c) - int c; -{ - return (__istype((c), _C)); -} - -#undef isdigit -int -isdigit(c) - int c; -{ - return (__isctype((c), _D)); -} - -#undef isgraph -int -isgraph(c) - int c; -{ - return (__istype((c), _G)); -} - -#undef islower -int -islower(c) - int c; -{ - return (__istype((c), _L)); -} - -#undef isprint -int -isprint(c) - int c; -{ - return (__istype((c), _R)); -} - -#undef ispunct -int -ispunct(c) - int c; -{ - return (__istype((c), _P)); -} - -#undef isspace -int -isspace(c) - int c; -{ - return (__istype((c), _S)); -} - -#undef isupper -int -isupper(c) - int c; -{ - return (__istype((c), _U)); -} - -#undef isxdigit -int -isxdigit(c) - int c; -{ - return (__isctype((c), _X)); -} - -#undef toascii -int -toascii(c) - int c; -{ - return (c & 0177); -} - -#undef tolower -int -tolower(c) - int c; -{ - return((c & _CRMASK) ? ___tolower(c) : _CurrentRuneLocale->maplower[c]); -} - -#undef toupper -int -toupper(c) - int c; -{ - return((c & _CRMASK) ? ___toupper(c) : _CurrentRuneLocale->mapupper[c]); -} diff --git a/locale.subproj/lconv.c b/locale.subproj/lconv.c deleted file mode 100644 index 786ca4a..0000000 --- a/locale.subproj/lconv.c +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * 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. - */ - - -#include -#include - -static char empty[] = ""; - -/* - * Default (C) locale conversion. - */ -static struct lconv C_lconv = { - ".", /* decimal_point */ - empty, /* thousands_sep */ - empty, /* grouping */ - empty, /* int_curr_symbol */ - empty, /* currency_symbol */ - empty, /* mon_decimal_point */ - empty, /* mon_thousands_sep */ - empty, /* mon_grouping */ - empty, /* positive_sign */ - empty, /* negative_sign */ - CHAR_MAX, /* int_frac_digits */ - CHAR_MAX, /* frac_digits */ - CHAR_MAX, /* p_cs_precedes */ - CHAR_MAX, /* p_sep_by_space */ - CHAR_MAX, /* n_cs_precedes */ - CHAR_MAX, /* n_sep_by_space */ - CHAR_MAX, /* p_sign_posn */ - CHAR_MAX, /* n_sign_posn */ -}; - -/* - * Current locale conversion. - */ -struct lconv *__lconv = &C_lconv; diff --git a/locale.subproj/localeconv.c b/locale.subproj/localeconv.c deleted file mode 100644 index 4393c9c..0000000 --- a/locale.subproj/localeconv.c +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * 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. - */ - - -#include - -/* - * Return the current locale conversion. - */ -struct lconv * -localeconv() -{ - extern struct lconv *__lconv; - - return (__lconv); -} diff --git a/locale.subproj/mbrune.c b/locale.subproj/mbrune.c deleted file mode 100644 index 105c4a7..0000000 --- a/locale.subproj/mbrune.c +++ /dev/null @@ -1,130 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * 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 -#include -#include -#include - -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); -} - -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); -} - -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); -} diff --git a/locale.subproj/none.c b/locale.subproj/none.c deleted file mode 100644 index 8c8c442..0000000 --- a/locale.subproj/none.c +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * 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 -#include -#include -#include -#include - -rune_t _none_sgetrune __P((const char *, size_t, char const **)); -int _none_sputrune __P((rune_t, char *, size_t, char **)); - -int -_none_init(rl) - _RuneLocale *rl; -{ - rl->sgetrune = _none_sgetrune; - rl->sputrune = _none_sputrune; - _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 c; - - if (n < 1) { - if (result) - *result = string; - return(_INVALID_RUNE); - } - if (result) - *result = string + 1; - return(*string & 0xff); -} - -int -_none_sputrune(c, string, n, result) - rune_t c; - char *string, **result; - size_t n; -{ - if (n >= 1) { - if (string) - *string = c; - if (result) - *result = string + 1; - } else if (result) - *result = (char *)0; - return(1); -} diff --git a/locale.subproj/rune.c b/locale.subproj/rune.c deleted file mode 100644 index 631c815..0000000 --- a/locale.subproj/rune.c +++ /dev/null @@ -1,352 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * 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 -#include - -#include -#include -#include -#include -#include -#include - -extern int _none_init __P((_RuneLocale *)); -extern int _UTF2_init __P((_RuneLocale *)); -extern int _EUC_init __P((_RuneLocale *)); -static _RuneLocale *_Read_RuneMagi __P((FILE *)); - -static char *PathLocale = 0; - -int -setrunelocale(encoding) - char *encoding; -{ - FILE *fp; - char name[PATH_MAX]; - _RuneLocale *rl; - - if (!encoding) - return(EFAULT); - - /* - * The "C" and "POSIX" locale are always here. - */ - if (!strcmp(encoding, "C") || !strcmp(encoding, "POSIX")) { - _CurrentRuneLocale = &_DefaultRuneLocale; - return(0); - } - - if (!PathLocale) - PathLocale = _PATH_LOCALE; - - sprintf(name, "%s/%s/LC_CTYPE", PathLocale, encoding); - - if ((fp = fopen(name, "r")) == NULL) - return(ENOENT); - - if ((rl = _Read_RuneMagi(fp)) == 0) { - fclose(fp); - return(EFTYPE); - } - - if (!rl->encoding[0] || !strcmp(rl->encoding, "UTF2")) { - return(_UTF2_init(rl)); - } else if (!strcmp(rl->encoding, "NONE")) { - return(_none_init(rl)); - } else if (!strcmp(rl->encoding, "EUC")) { - return(_EUC_init(rl)); - } else - return(EINVAL); -} - -void -setinvalidrune(ir) - rune_t ir; -{ - _INVALID_RUNE = ir; -} - -static _RuneLocale * -_Read_RuneMagi(fp) - FILE *fp; -{ - char *data; - void *np; - void *lastp; - _RuneLocale *rl; - _RuneEntry *rr; - struct stat sb; - int x; - - if (fstat(fileno(fp), &sb) < 0) - return(0); - - if (sb.st_size < sizeof(_RuneLocale)) - return(0); - - if ((data = malloc(sb.st_size)) == NULL) - return(0); - - rewind(fp); /* Someone might have read the magic number once already */ - - if (fread(data, sb.st_size, 1, fp) != 1) { - free(data); - return(0); - } - - rl = (_RuneLocale *)data; - lastp = data + sb.st_size; - - rl->variable = rl + 1; - - if (memcmp(rl->magic, _RUNE_MAGIC_1, sizeof(rl->magic))) { - free(data); - return(0); - } - - 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_ext.ranges = (_RuneEntry *)rl->variable; - rl->variable = rl->runetype_ext.ranges + rl->runetype_ext.nranges; - if (rl->variable > lastp) { - free(data); - return(0); - } - - rl->maplower_ext.ranges = (_RuneEntry *)rl->variable; - rl->variable = rl->maplower_ext.ranges + rl->maplower_ext.nranges; - if (rl->variable > lastp) { - free(data); - return(0); - } - - rl->mapupper_ext.ranges = (_RuneEntry *)rl->variable; - rl->variable = rl->mapupper_ext.ranges + rl->mapupper_ext.nranges; - if (rl->variable > lastp) { - free(data); - return(0); - } - - 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) { - free(data); - return(0); - } - while (len-- > 0) - rr[x].types[len] = ntohl(rr[x].types[len]); - } else - rr[x].types = 0; - } - - 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); - } - - 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); - } - if (((char *)rl->variable) + rl->variable_len > (char *)lastp) { - free(data); - return(0); - } - - /* - * Go out and zero pointers that should be zero. - */ - if (!rl->variable_len) - rl->variable = 0; - - if (!rl->runetype_ext.nranges) - rl->runetype_ext.ranges = 0; - - if (!rl->maplower_ext.nranges) - rl->maplower_ext.ranges = 0; - - if (!rl->mapupper_ext.nranges) - rl->mapupper_ext.ranges = 0; - - return(rl); -} - -unsigned long -___runetype(c) - _BSD_RUNE_T_ c; -{ - int x; - _RuneRange *rr = &_CurrentRuneLocale->runetype_ext; - _RuneEntry *re = rr->ranges; - - if (c == EOF) - return(0); - 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); - } - } - return(0L); -} - -_BSD_RUNE_T_ -___toupper(c) - _BSD_RUNE_T_ c; -{ - int x; - _RuneRange *rr = &_CurrentRuneLocale->mapupper_ext; - _RuneEntry *re = rr->ranges; - - if (c == EOF) - return(EOF); - for (x = 0; x < rr->nranges; ++x, ++re) { - if (c < re->min) - return(c); - if (c <= re->max) - return(re->map + c - re->min); - } - return(c); -} - -_BSD_RUNE_T_ -___tolower(c) - _BSD_RUNE_T_ c; -{ - int x; - _RuneRange *rr = &_CurrentRuneLocale->maplower_ext; - _RuneEntry *re = rr->ranges; - - if (c == EOF) - return(EOF); - for (x = 0; x < rr->nranges; ++x, ++re) { - if (c < re->min) - return(c); - if (c <= re->max) - return(re->map + c - re->min); - } - return(c); -} - - -#if !defined(_USE_CTYPE_INLINE_) && !defined(_USE_CTYPE_MACROS_) -/* - * See comments in - */ -int -__istype(c, f) - _BSD_RUNE_T_ c; - unsigned long f; -{ - return ((((c & _CRMASK) ? ___runetype(c) - : _CurrentRuneLocale->runetype[c]) & f) ? 1 : 0); -} - -int -__isctype(_BSD_RUNE_T_ c, unsigned long f) - _BSD_RUNE_T_ c; - unsigned long f; -{ - return ((((c & _CRMASK) ? 0 - : _DefaultRuneLocale.runetype[c]) & f) ? 1 : 0); -} - -_BSD_RUNE_T_ -toupper(c) - _BSD_RUNE_T_ c; -{ - return ((c & _CRMASK) ? - ___toupper(c) : _CurrentRuneLocale->mapupper[c]); -} - -_BSD_RUNE_T_ -tolower(c) - _BSD_RUNE_T_ c; -{ - return ((c & _CRMASK) ? - ___tolower(c) : _CurrentRuneLocale->maplower[c]); -} -#endif diff --git a/locale.subproj/runetable.c b/locale.subproj/runetable.c deleted file mode 100644 index 3d6df8a..0000000 --- a/locale.subproj/runetable.c +++ /dev/null @@ -1,178 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * 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 - -#include -#include - -extern rune_t _none_sgetrune __P((const char *, size_t, char const **)); -extern int _none_sputrune __P((rune_t, char *, size_t, char **)); -extern int _none_init __P((char *, char **)); - -const _RuneLocale _DefaultRuneLocale = { - _RUNE_MAGIC_1, - "none", - _none_sgetrune, - _none_sputrune, - 0xFFFD, - - { /*00*/ _C, _C, _C, _C, - _C, _C, _C, _C, - /*08*/ _C, _C|_S|_B, _C|_S, _C|_S, - _C|_S, _C|_S, _C, _C, - /*10*/ _C, _C, _C, _C, - _C, _C, _C, _C, - /*18*/ _C, _C, _C, _C, - _C, _C, _C, _C, - /*20*/ _S|_B|_R, _P|_R|_G, _P|_R|_G, _P|_R|_G, - _P|_R|_G, _P|_R|_G, _P|_R|_G, _P|_R|_G, - /*28*/ _P|_R|_G, _P|_R|_G, _P|_R|_G, _P|_R|_G, - _P|_R|_G, _P|_R|_G, _P|_R|_G, _P|_R|_G, - /*30*/ _D|_R|_G|_X|0, _D|_R|_G|_X|1, _D|_R|_G|_X|2, _D|_R|_G|_X|3, - _D|_R|_G|_X|4, _D|_R|_G|_X|5, _D|_R|_G|_X|6, _D|_R|_G|_X|7, - /*38*/ _D|_R|_G|_X|8, _D|_R|_G|_X|9, _P|_R|_G, _P|_R|_G, - _P|_R|_G, _P|_R|_G, _P|_R|_G, _P|_R|_G, - /*40*/ _P|_R|_G, _U|_X|_R|_G|_A|10, _U|_X|_R|_G|_A|11, _U|_X|_R|_G|_A|12, - _U|_X|_R|_G|_A|13, _U|_X|_R|_G|_A|14, _U|_X|_R|_G|_A|15, _U|_R|_G|_A, - /*48*/ _U|_R|_G|_A, _U|_R|_G|_A, _U|_R|_G|_A, _U|_R|_G|_A, - _U|_R|_G|_A, _U|_R|_G|_A, _U|_R|_G|_A, _U|_R|_G|_A, - /*50*/ _U|_R|_G|_A, _U|_R|_G|_A, _U|_R|_G|_A, _U|_R|_G|_A, - _U|_R|_G|_A, _U|_R|_G|_A, _U|_R|_G|_A, _U|_R|_G|_A, - /*58*/ _U|_R|_G|_A, _U|_R|_G|_A, _U|_R|_G|_A, _P|_R|_G, - _P|_R|_G, _P|_R|_G, _P|_R|_G, _P|_R|_G, - /*60*/ _P|_R|_G, _L|_X|_R|_G|_A|10, _L|_X|_R|_G|_A|11, _L|_X|_R|_G|_A|12, - _L|_X|_R|_G|_A|13, _L|_X|_R|_G|_A|14, _L|_X|_R|_G|_A|15, _L|_R|_G|_A, - /*68*/ _L|_R|_G|_A, _L|_R|_G|_A, _L|_R|_G|_A, _L|_R|_G|_A, - _L|_R|_G|_A, _L|_R|_G|_A, _L|_R|_G|_A, _L|_R|_G|_A, - /*70*/ _L|_R|_G|_A, _L|_R|_G|_A, _L|_R|_G|_A, _L|_R|_G|_A, - _L|_R|_G|_A, _L|_R|_G|_A, _L|_R|_G|_A, _L|_R|_G|_A, - /*78*/ _L|_R|_G|_A, _L|_R|_G|_A, _L|_R|_G|_A, _P|_R|_G, - _P|_R|_G, _P|_R|_G, _P|_R|_G, _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 = &_DefaultRuneLocale; - -int __mb_cur_max = 1; diff --git a/locale.subproj/setlocale.c b/locale.subproj/setlocale.c deleted file mode 100644 index 7dc8b93..0000000 --- a/locale.subproj/setlocale.c +++ /dev/null @@ -1,252 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1991, 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 -#include -#include -#include -#include - -/* - * Category names for getenv() - */ -static char *categories[_LC_LAST] = { - "LC_ALL", - "LC_COLLATE", - "LC_CTYPE", - "LC_MONETARY", - "LC_NUMERIC", - "LC_TIME", -}; - -/* - * Current locales for each category - */ -static char current_categories[_LC_LAST][32] = { - "C", - "C", - "C", - "C", - "C", - "C", -}; - -/* - * The locales we are going to try and load - */ -static char new_categories[_LC_LAST][32]; - -static char current_locale_string[_LC_LAST * 33]; -static char *PathLocale; - -static char *currentlocale __P((void)); -static char *loadlocale __P((int)); - -char * -setlocale(category, locale) - int category; - const char *locale; -{ - int found, i, len; - char *env, *r; - - if (!PathLocale) - PathLocale = _PATH_LOCALE; - - if (category < 0 || category >= _LC_LAST) - return (NULL); - - if (!locale) - return (category ? - current_categories[category] : currentlocale()); - - /* - * Default to the current locale for everything. - */ - for (i = 1; i < _LC_LAST; ++i) - (void)strcpy(new_categories[i], current_categories[i]); - - /* - * Now go fill up new_categories from the locale argument - */ - if (!*locale) { - env = getenv(categories[category]); - - if (!env) - env = getenv(categories[0]); - - if (!env) - env = getenv("LANG"); - - if (!env) - env = "C"; - - (void) strncpy(new_categories[category], env, 31); - new_categories[category][31] = 0; - if (!category) { - for (i = 1; i < _LC_LAST; ++i) { - if (!(env = getenv(categories[i]))) - env = new_categories[0]; - (void)strncpy(new_categories[i], env, 31); - new_categories[i][31] = 0; - } - } - } else if (category) { - (void)strncpy(new_categories[category], locale, 31); - new_categories[category][31] = 0; - } else { - if ((r = strchr(locale, '/')) == 0) { - for (i = 1; i < _LC_LAST; ++i) { - (void)strncpy(new_categories[i], locale, 31); - new_categories[i][31] = 0; - } - } else { - for (i = 1; r[1] == '/'; ++r); - if (!r[1]) - return (NULL); /* Hmm, just slashes... */ - do { - len = r - locale > 31 ? 31 : r - locale; - (void)strncpy(new_categories[i++], locale, len); - new_categories[i++][len] = 0; - locale = r; - while (*locale == '/') - ++locale; - while (*++r && *r != '/'); - } while (*locale); - while (i < _LC_LAST) - (void)strcpy(new_categories[i], - new_categories[i-1]); - } - } - - if (category) - return (loadlocale(category)); - - found = 0; - for (i = 1; i < _LC_LAST; ++i) - if (loadlocale(i) != NULL) - found = 1; - if (found) - return (currentlocale()); - return (NULL); -} - -static char * -currentlocale() -{ - int i; - - (void)strcpy(current_locale_string, current_categories[1]); - - for (i = 2; i < _LC_LAST; ++i) - if (strcmp(current_categories[1], current_categories[i])) { - (void)snprintf(current_locale_string, - sizeof(current_locale_string), "%s/%s/%s/%s/%s", - current_categories[1], current_categories[2], - current_categories[3], current_categories[4], - current_categories[5]); - break; - } - return (current_locale_string); -} - -static char * -loadlocale(category) - int category; -{ - char name[PATH_MAX]; - - if (strcmp(new_categories[category], - current_categories[category]) == 0) - return (current_categories[category]); - - if (category == LC_CTYPE) { - if (setrunelocale(new_categories[LC_CTYPE])) - return (NULL); - (void)strcpy(current_categories[LC_CTYPE], - new_categories[LC_CTYPE]); - return (current_categories[LC_CTYPE]); - } - - if (!strcmp(new_categories[category], "C") || - !strcmp(new_categories[category], "POSIX")) { - - /* - * Some day this will need to reset the locale to the default - * C locale. Since we have no way to change them as of yet, - * there is no need to reset them. - */ - (void)strcpy(current_categories[category], - new_categories[category]); - return (current_categories[category]); - } - - /* - * Some day we will actually look at this file. - */ - (void)snprintf(name, sizeof(name), "%s/%s/%s", - PathLocale, new_categories[category], categories[category]); - - switch (category) { - case LC_COLLATE: - case LC_MONETARY: - case LC_NUMERIC: - case LC_TIME: - return (NULL); - } -} diff --git a/locale.subproj/utf2.c b/locale.subproj/utf2.c deleted file mode 100644 index 1d4a69f..0000000 --- a/locale.subproj/utf2.c +++ /dev/null @@ -1,166 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * 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 -#include -#include -#include -#include - -rune_t _UTF2_sgetrune __P((const char *, size_t, char const **)); -int _UTF2_sputrune __P((rune_t, char *, size_t, char **)); - -static _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); - } -} diff --git a/locale/Makefile.inc b/locale/Makefile.inc new file mode 100644 index 0000000..f5c3b13 --- /dev/null +++ b/locale/Makefile.inc @@ -0,0 +1,26 @@ +# from @(#)Makefile.inc 8.1 (Berkeley) 6/4/93 +# $FreeBSD: src/lib/libc/locale/Makefile.inc,v 1.20 2001/05/03 15:12:52 phantom Exp $ + +# locale sources +.PATH: ${.CURDIR}/${MACHINE_ARCH}/locale ${.CURDIR}/locale + +SRCS+= ansi.c big5.c collate.c collcmp.c euc.c frune.c isctype.c \ + lconv.c localeconv.c mbrune.c mskanji.c nomacros.c none.c rune.c \ + runetype.c setinvalidrune.c setlocale.c setrunelocale.c table.c \ + tolower.c toupper.c utf2.c + +.if ${LIB} == "c" +MAN3+= ctype.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 isxdigit.3 mbrune.3 multibyte.3 nl_langinfo.3 rune.3 \ + setlocale.3 toascii.3 tolower.3 toupper.3 +MAN4+= euc.4 utf2.4 + +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+=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 +.endif diff --git a/locale/ansi.c b/locale/ansi.c new file mode 100644 index 0000000..c0871fe --- /dev/null +++ b/locale/ansi.c @@ -0,0 +1,151 @@ +/*- + * 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[] = "@(#)ansi.c 8.1 (Berkeley) 6/27/93"; +#endif /* LIBC_SCCS and not lint */ + +#include +#include +#include +#include + +int +mblen(s, n) + const char *s; + size_t n; +{ + char const *e; + + if (s == 0 || *s == 0) + return (0); /* No support for state dependent encodings. */ + + if (sgetrune(s, n, &e) == _INVALID_RUNE) + return (s - e); + return (e - s); +} + +int +mbtowc(pwc, s, n) + wchar_t *pwc; + const char *s; + size_t n; +{ + char const *e; + rune_t r; + + if (s == 0 || *s == 0) + return (0); /* No support for state dependent encodings. */ + + if ((r = sgetrune(s, n, &e)) == _INVALID_RUNE) + return (s - e); + if (pwc) + *pwc = r; + return (e - s); +} + +int +wctomb(s, wchar) + char *s; + wchar_t wchar; +{ + char *e; + + if (s == 0) + return (0); /* No support for state dependent encodings. */ + + if (wchar == 0) { + *s = 0; + return (1); + } + + sputrune(wchar, s, MB_CUR_MAX, &e); + return (e ? e - s : -1); +} + +size_t +mbstowcs(pwcs, s, n) + wchar_t *pwcs; + const char *s; + size_t n; +{ + char const *e; + int cnt = 0; + + if (!pwcs || !s) + return (-1); + + while (n-- > 0) { + *pwcs = sgetrune(s, MB_LEN_MAX, &e); + if (*pwcs == _INVALID_RUNE) + return (-1); + if (*pwcs++ == 0) + break; + s = e; + ++cnt; + } + return (cnt); +} + +size_t +wcstombs(s, pwcs, n) + char *s; + const wchar_t *pwcs; + size_t n; +{ + char *e; + int cnt, nb; + + if (!pwcs || !s || n > INT_MAX) + return (-1); + + nb = n; + cnt = 0; + while (nb > 0) { + if (*pwcs == 0) { + *s = 0; + break; + } + if (!sputrune(*pwcs++, s, nb, &e)) + return (-1); /* encoding error */ + if (!e) /* too long */ + return (cnt); + cnt += e - s; + nb -= e - s; + s = e; + } + return (cnt); +} diff --git a/locale/big5.c b/locale/big5.c new file mode 100644 index 0000000..87e2fd8 --- /dev/null +++ b/locale/big5.c @@ -0,0 +1,119 @@ +/*- + * 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. + * + * $FreeBSD: src/lib/libc/locale/big5.c,v 1.3.2.2 2001/03/05 10:02:54 obrien Exp $ + */ + +#if defined(LIBC_SCCS) && !defined(lint) +static char sccsid[] = "@(#)big5.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ + +#include +#include +#include +#include +#include + +rune_t _BIG5_sgetrune __P((const char *, size_t, char const **)); +int _BIG5_sputrune __P((rune_t, char *, size_t, char **)); + +int +_BIG5_init(rl) + _RuneLocale *rl; +{ + rl->sgetrune = _BIG5_sgetrune; + rl->sputrune = _BIG5_sputrune; + _CurrentRuneLocale = rl; + __mb_cur_max = 2; + return (0); +} + +static inline int +_big5_check(c) + 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; +{ + rune_t rune = 0; + int len; + + if (n < 1 || (len = _big5_check(*string)) > n) { + if (result) + *result = string; + return (_INVALID_RUNE); + } + 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); + } + } + else { + if (n >= 1) { + *string = c & 0xff; + if (result) + *result = string + 1; + return (1); + } + } + if (result) + *result = string; + return (0); + +} diff --git a/locale/collate.c b/locale/collate.c new file mode 100644 index 0000000..5ef2ebb --- /dev/null +++ b/locale/collate.c @@ -0,0 +1,212 @@ +/*- + * Copyright (c) 1995 Alex Tatmanjants + * at Electronni Visti IA, Kiev, Ukraine. + * 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 ``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 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/collate.c,v 1.21.2.1 2001/03/05 10:10:22 obrien Exp $ + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include "collate.h" +#include "setlocale.h" + +int __collate_load_error = 1; +int __collate_substitute_nontrivial; +char __collate_version[STR_LEN]; +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[TABLE_SIZE]; + +#define FREAD(a, b, c, d) \ + do { \ + if (fread(a, b, c, d) != c) { \ + fclose(d); \ + return -1; \ + } \ + } while(0) + +void __collate_err(int ex, const char *f) ; + +int +__collate_load_tables(encoding) + char *encoding; +{ + char buf[PATH_MAX]; + FILE *fp; + int i, save_load_error; + + save_load_error = __collate_load_error; + __collate_load_error = 1; + if (!encoding) { + __collate_load_error = save_load_error; + return -1; + } + if (!strcmp(encoding, "C") || !strcmp(encoding, "POSIX")) + return 0; + if (!_PathLocale) { + __collate_load_error = save_load_error; + return -1; + } + /* Range checking not needed, encoding has fixed size */ + (void) strcpy(buf, _PathLocale); + (void) strcat(buf, "/"); + (void) strcat(buf, encoding); + (void) strcat(buf, "/LC_COLLATE"); + if ((fp = fopen(buf, "r")) == NULL) { + __collate_load_error = save_load_error; + return -1; + } + FREAD(__collate_version, sizeof(__collate_version), 1, fp); + if (strcmp(__collate_version, COLLATE_VERSION) != 0) { + fclose(fp); + return -1; + } + FREAD(__collate_substitute_table, sizeof(__collate_substitute_table), + 1, fp); + FREAD(__collate_char_pri_table, sizeof(__collate_char_pri_table), 1, + fp); + FREAD(__collate_chain_pri_table, sizeof(__collate_chain_pri_table), 1, + fp); + fclose(fp); + __collate_load_error = 0; + + __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; + break; + } + } + + return 0; +} + +u_char * +__collate_substitute(s) + const u_char *s; +{ + int dest_len, len, nlen; + int delta = strlen(s); + u_char *dest_str = NULL; + + if(s == NULL || *s == '\0') + return __collate_strdup(""); + delta += delta / 8; + dest_str = malloc(dest_len = delta); + if(dest_str == NULL) + __collate_err(EX_OSERR, __FUNCTION__); + 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__); + } + strcpy(dest_str + len, __collate_substitute_table[*s++]); + len = nlen; + } + return dest_str; +} + +void +__collate_lookup(t, len, prim, sec) + const u_char *t; + int *len, *prim, *sec; +{ + struct __collate_st_chain_pri *p2; + + *len = 1; + *prim = *sec = 0; + for(p2 = __collate_chain_pri_table; p2->str[0]; p2++) { + if(strncmp(t, p2->str, strlen(p2->str)) == 0) { + *len = strlen(p2->str); + *prim = p2->prim; + *sec = p2->sec; + return; + } + } + *prim = __collate_char_pri_table[*t].prim; + *sec = __collate_char_pri_table[*t].sec; +} + +u_char * +__collate_strdup(s) + u_char *s; +{ + u_char *t = strdup(s); + + if (t == NULL) + __collate_err(EX_OSERR, __FUNCTION__); + return t; +} + +void +__collate_err(int ex, const char *f) +{ + char **__progname = _NSGetProgname(); + const char *s; + int serrno = errno; + + s = *__progname; + write(STDERR_FILENO, s, strlen(s)); + write(STDERR_FILENO, ": ", 2); + s = f; + write(STDERR_FILENO, s, strlen(s)); + write(STDERR_FILENO, ": ", 2); + s = strerror(serrno); + write(STDERR_FILENO, s, strlen(s)); + write(STDERR_FILENO, "\n", 1); + exit(ex); +} + +#ifdef COLLATE_DEBUG +void +__collate_print_tables() +{ + int i; + struct __collate_st_chain_pri *p2; + + printf("Substitute table:\n"); + for (i = 0; i < UCHAR_MAX + 1; i++) + if (i != *__collate_substitute_table[i]) + printf("\t'%c' --> \"%s\"\n", i, + __collate_substitute_table[i]); + printf("Chain priority table:\n"); + for (p2 = __collate_chain_pri_table; p2->str[0]; p2++) + printf("\t\"%s\" : %d %d\n\n", p2->str, p2->prim, p2->sec); + printf("Char priority table:\n"); + for (i = 0; i < UCHAR_MAX + 1; i++) + printf("\t'%c' : %d %d\n", i, __collate_char_pri_table[i].prim, + __collate_char_pri_table[i].sec); +} +#endif diff --git a/locale/collate.h b/locale/collate.h new file mode 100644 index 0000000..97d9c5b --- /dev/null +++ b/locale/collate.h @@ -0,0 +1,67 @@ +/*- + * Copyright (c) 1995 Alex Tatmanjants + * at Electronni Visti IA, Kiev, Ukraine. + * 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 ``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 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/collate.h,v 1.9 1999/09/12 21:15:14 dt Exp $ + */ + +#ifndef COLLATE_H_INCLUDED +#define COLLATE_H_INCLUDED + +#include +#include +#include + +#define STR_LEN 10 +#define TABLE_SIZE 100 +#define COLLATE_VERSION "1.0\n" + +struct __collate_st_char_pri { + int prim, sec; +}; +struct __collate_st_chain_pri { + u_char str[STR_LEN]; + int prim, sec; +}; + +extern int __collate_load_error; +extern int __collate_substitute_nontrivial; +extern char __collate_version[STR_LEN]; +extern u_char __collate_substitute_table[UCHAR_MAX + 1][STR_LEN]; +extern struct __collate_st_char_pri __collate_char_pri_table[UCHAR_MAX + 1]; +extern struct __collate_st_chain_pri __collate_chain_pri_table[TABLE_SIZE]; + +__BEGIN_DECLS +u_char *__collate_strdup __P((u_char *)); +u_char *__collate_substitute __P((const u_char *)); +int __collate_load_tables __P((char *)); +void __collate_lookup __P((const u_char *, int *, int *, int *)); +int __collate_range_cmp __P((int, int)); +#ifdef COLLATE_DEBUG +void __collate_print_tables __P((void)); +#endif +__END_DECLS + +#endif /* not COLLATE_H_INCLUDED */ diff --git a/locale/collcmp.c b/locale/collcmp.c new file mode 100644 index 0000000..b1e8e0a --- /dev/null +++ b/locale/collcmp.c @@ -0,0 +1,84 @@ +/* + * Copyright (C) 1996 by Andrey A. Chernov, Moscow, Russia. + * 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 ``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. + * + * $FreeBSD: src/lib/libc/locale/collcmp.c,v 1.12.2.1 2000/08/22 01:54:39 jhb Exp $ + */ + +#define ASCII_COMPATIBLE_COLLATE /* see share/colldef */ + +#include +#include "collate.h" +#ifndef ASCII_COMPATIBLE_COLLATE +#include +#endif + +/* + * Compare two characters converting collate information + * into ASCII-compatible range, it allows to handle + * "[a-z]"-type ranges with national characters. + */ + +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); +} diff --git a/locale/ctype.3 b/locale/ctype.3 new file mode 100644 index 0000000..f946e12 --- /dev/null +++ b/locale/ctype.3 @@ -0,0 +1,147 @@ +.\" 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.6.2.3 2001/12/14 18:33:54 ru Exp $ +.\" +.Dd June 4, 1993 +.Dt CTYPE 3 +.Os +.Sh NAME +.Nm isalnum , +.Nm isalpha , +.Nm isascii , +.Nm isblank , +.Nm iscntrl , +.Nm isdigit , +.Nm isgraph , +.Nm ishexnumber , +.Nm isideogram , +.Nm islower , +.Nm isnumber , +.Nm isphonogram , +.Nm isprint , +.Nm ispunct , +.Nm isrune , +.Nm isspace , +.Nm isspecial , +.Nm isupper , +.Nm isxdigit , +.Nm toascii , +.Nm tolower , +.Nm toupper +.Nd character classification macros +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In ctype.h +.Ft int +.Fn isalnum "int c" +.Ft int +.Fn isalpha "int c" +.Ft int +.Fn isascii "int c" +.Ft int +.Fn iscntrl "int c" +.Ft int +.Fn isdigit "int c" +.Ft int +.Fn isgraph "int c" +.Ft int +.Fn ishexnumber "int c" +.Ft int +.Fn isideogram "int c" +.Ft int +.Fn islower "int c" +.Ft int +.Fn isnumber "int c" +.Ft int +.Fn isphonogram "int c" +.Ft int +.Fn isspecial "int c" +.Ft int +.Fn isprint "int c" +.Ft int +.Fn ispunct "int c" +.Ft int +.Fn isrune "int c" +.Ft int +.Fn isspace "int c" +.Ft int +.Fn isupper "int c" +.Ft int +.Fn isxdigit "int c" +.Ft int +.Fn toascii "int c" +.Ft int +.Fn tolower "int c" +.Ft int +.Fn toupper "int c" +.Sh DESCRIPTION +The above functions perform character tests and conversions on the integer +.Ar c . +They are available as macros, defined in the include file +.Aq Pa ctype.h , +or as true functions in the C library. +See the specific manual pages for more information. +.Sh SEE ALSO +.Xr isalnum 3 , +.Xr isalpha 3 , +.Xr isascii 3 , +.Xr isblank 3 , +.Xr iscntrl 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 toascii 3 , +.Xr tolower 3 , +.Xr toupper 3 , +.Xr ascii 7 +.Sh STANDARDS +These functions, except for +.Fn digittoint , +.Fn isascii , +.Fn isblank , +.Fn ishexnumber , +.Fn isideogram , +.Fn isnumber , +.Fn isphonogram , +.Fn isrune , +.Fn isspecial +and +.Fn toascii , +conform to +.St -isoC . diff --git a/locale/euc.4 b/locale/euc.4 new file mode 100644 index 0000000..e7c9c92 --- /dev/null +++ b/locale/euc.4 @@ -0,0 +1,242 @@ +.\" 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.8.2.1 2001/07/22 12:06:40 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 diff --git a/locale/euc.c b/locale/euc.c new file mode 100644 index 0000000..4b7d9eb --- /dev/null +++ b/locale/euc.c @@ -0,0 +1,223 @@ +/*- + * 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. + * + * $FreeBSD: src/lib/libc/locale/euc.c,v 1.3.6.1 2000/06/04 21:47:39 ache Exp $ + */ + +#if defined(LIBC_SCCS) && !defined(lint) +static char sccsid[] = "@(#)euc.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ + +#include + +#include +#include +#include +#include +#include +#include + +rune_t _EUC_sgetrune __P((const char *, size_t, char const **)); +int _EUC_sputrune __P((rune_t, char *, size_t, char **)); + +typedef struct { + int count[4]; + rune_t bits[4]; + rune_t mask; +} _EucInfo; + +int +_EUC_init(rl) + _RuneLocale *rl; +{ + _EucInfo *ei; + int x; + char *v, *e; + + rl->sgetrune = _EUC_sgetrune; + rl->sputrune = _EUC_sputrune; + + if (!rl->variable) { + free(rl); + return (EFTYPE); + } + v = (char *) rl->variable; + + while (*v == ' ' || *v == '\t') + ++v; + + if ((ei = malloc(sizeof(_EucInfo))) == NULL) { + free(rl); + return (ENOMEM); + } + for (x = 0; x < 4; ++x) { + ei->count[x] = (int) strtol(v, &e, 0); + if (v == e || !(v = e)) { + free(rl); + free(ei); + return (EFTYPE); + } + while (*v == ' ' || *v == '\t') + ++v; + ei->bits[x] = (int) strtol(v, &e, 0); + if (v == e || !(v = e)) { + free(rl); + free(ei); + return (EFTYPE); + } + while (*v == ' ' || *v == '\t') + ++v; + } + ei->mask = (int)strtol(v, &e, 0); + if (v == e || !(v = e)) { + free(rl); + free(ei); + return (EFTYPE); + } + if (sizeof(_EucInfo) <= rl->variable_len) { + memcpy(rl->variable, ei, sizeof(_EucInfo)); + free(ei); + } else { + rl->variable = &ei; + } + rl->variable_len = sizeof(_EucInfo); + _CurrentRuneLocale = rl; + __mb_cur_max = 3; + return (0); +} + +#define CEI ((_EucInfo *)(_CurrentRuneLocale->variable)) + +#define _SS2 0x008e +#define _SS3 0x008f + +static inline int +_euc_set(c) + 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; +{ + rune_t rune = 0; + int len, set; + + if (n < 1 || (len = CEI->count[set = _euc_set(*string)]) > n) { + if (result) + *result = string; + return (_INVALID_RUNE); + } + 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 (result) + *result = string; + return ((rune & ~CEI->mask) | CEI->bits[set]); +} + +int +_EUC_sputrune(c, string, n, result) + rune_t c; + char *string, **result; + size_t n; +{ + rune_t m = c & CEI->mask; + rune_t nm = c & ~m; + int i, len; + + 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; + } else { + 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]; + if (n < len) { + if (result) + *result = NULL; + return (len); + } + *string++ = _SS2; + --i; + } else + if (m == CEI->bits[3]) { + i = len = CEI->count[3]; + if (n < len) { + if (result) + *result = NULL; + return (len); + } + *string++ = _SS3; + --i; + } else + goto CodeSet1; /* Bletch */ + while (i-- > 0) + *string++ = (nm >> (i << 3)) & 0xff; + if (result) + *result = string; + } + return (len); +} diff --git a/locale/frune.c b/locale/frune.c new file mode 100644 index 0000000..443d3ba --- /dev/null +++ b/locale/frune.c @@ -0,0 +1,103 @@ +/*- + * 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 +#include +#include +#include + +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); +} + +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); +} + +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); +} diff --git a/locale/isalnum.3 b/locale/isalnum.3 new file mode 100644 index 0000000..91d3112 --- /dev/null +++ b/locale/isalnum.3 @@ -0,0 +1,101 @@ +.\" Copyright (c) 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. +.\" +.\" @(#)isalnum.3 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD: src/lib/libc/locale/isalnum.3,v 1.7.2.7 2001/12/14 18:33:54 ru Exp $ +.\" +.Dd June 4, 1993 +.Dt ISALNUM 3 +.Os +.Sh NAME +.Nm isalnum +.Nd alphanumeric character test +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In ctype.h +.Ft int +.Fn isalnum "int c" +.Sh DESCRIPTION +The +.Fn isalnum +function tests for any character for which +.Xr isalpha 3 +or +.Xr isdigit 3 +is true. +For single C +.Va char Ns s +locales (see +.Xr multibyte 3 ) +the value of the argument is +representable as an +.Li unsigned char +or the value of +.Dv EOF . +In the ASCII character set, this includes the following characters +(with their numeric values shown in octal): +.Pp +.Bl -column \&000_``0''__ \&000_``0''__ \&000_``0''__ \&000_``0''__ \&000_``0''__ +.It "\&060\ ``0'' \t061\ ``1'' \t062\ ``2'' \t063\ ``3'' \t064\ ``4''" +.It "\&065\ ``5'' \t066\ ``6'' \t067\ ``7'' \t070\ ``8'' \t071\ ``9''" +.It "\&101\ ``A'' \t102\ ``B'' \t103\ ``C'' \t104\ ``D'' \t105\ ``E''" +.It "\&106\ ``F'' \t107\ ``G'' \t110\ ``H'' \t111\ ``I'' \t112\ ``J''" +.It "\&113\ ``K'' \t114\ ``L'' \t115\ ``M'' \t116\ ``N'' \t117\ ``O''" +.It "\&120\ ``P'' \t121\ ``Q'' \t122\ ``R'' \t123\ ``S'' \t124\ ``T''" +.It "\&125\ ``U'' \t126\ ``V'' \t127\ ``W'' \t130\ ``X'' \t131\ ``Y''" +.It "\&132\ ``Z'' \t141\ ``a'' \t142\ ``b'' \t143\ ``c'' \t144\ ``d''" +.It "\&145\ ``e'' \t146\ ``f'' \t147\ ``g'' \t150\ ``h'' \t151\ ``i''" +.It "\&152\ ``j'' \t153\ ``k'' \t154\ ``l'' \t155\ ``m'' \t156\ ``n''" +.It "\&157\ ``o'' \t160\ ``p'' \t161\ ``q'' \t162\ ``r'' \t163\ ``s''" +.It "\&164\ ``t'' \t165\ ``u'' \t166\ ``v'' \t167\ ``w'' \t170\ ``x''" +.It "\&171\ ``y'' \t172\ ``z''" +.El +.Sh RETURN VALUES +The +.Fn isalnum +function returns zero if the character tests false and +returns non-zero if the character tests true. +.Sh SEE ALSO +.Xr ctype 3 , +.Xr isalpha 3 , +.Xr isdigit 3 , +.Xr multibyte 3 , +.Xr ascii 7 +.Sh STANDARDS +The +.Fn isalnum +function conforms to +.St -isoC . diff --git a/locale/isalpha.3 b/locale/isalpha.3 new file mode 100644 index 0000000..ae00cf4 --- /dev/null +++ b/locale/isalpha.3 @@ -0,0 +1,99 @@ +.\" Copyright (c) 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. +.\" +.\" @(#)isalpha.3 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD: src/lib/libc/locale/isalpha.3,v 1.7.2.6 2001/12/14 18:33:54 ru Exp $ +.\" +.Dd June 4, 1993 +.Dt ISALPHA 3 +.Os +.Sh NAME +.Nm isalpha +.Nd alphabetic character test +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In ctype.h +.Ft int +.Fn isalpha "int c" +.Sh DESCRIPTION +The +.Fn isalpha +function tests for any character for which +.Xr isupper 3 +or +.Xr islower 3 +is true. +For single C +.Va char Ns s +locales (see +.Xr multibyte 3 ) +the value of the argument is +representable as an +.Li unsigned char +or the value of +.Dv EOF . +In the ASCII character set, this includes the following characters +(with their numeric values shown in octal): +.Pp +.Bl -column \&000_``0''__ \&000_``0''__ \&000_``0''__ \&000_``0''__ \&000_``0''__ +.It "\&101\ ``A'' \t102\ ``B'' \t103\ ``C'' \t104\ ``D'' \t105\ ``E''" +.It "\&106\ ``F'' \t107\ ``G'' \t110\ ``H'' \t111\ ``I'' \t112\ ``J''" +.It "\&113\ ``K'' \t114\ ``L'' \t115\ ``M'' \t116\ ``N'' \t117\ ``O''" +.It "\&120\ ``P'' \t121\ ``Q'' \t122\ ``R'' \t123\ ``S'' \t124\ ``T''" +.It "\&125\ ``U'' \t126\ ``V'' \t127\ ``W'' \t130\ ``X'' \t131\ ``Y''" +.It "\&132\ ``Z'' \t141\ ``a'' \t142\ ``b'' \t143\ ``c'' \t144\ ``d''" +.It "\&145\ ``e'' \t146\ ``f'' \t147\ ``g'' \t150\ ``h'' \t151\ ``i''" +.It "\&152\ ``j'' \t153\ ``k'' \t154\ ``l'' \t155\ ``m'' \t156\ ``n''" +.It "\&157\ ``o'' \t160\ ``p'' \t161\ ``q'' \t162\ ``r'' \t163\ ``s''" +.It "\&164\ ``t'' \t165\ ``u'' \t166\ ``v'' \t167\ ``w'' \t170\ ``x''" +.It "\&171\ ``y'' \t172\ ``z''" +.El +.Sh RETURN VALUES +The +.Fn isalpha +function returns zero if the character tests false and +returns non-zero if the character tests true. +.Sh SEE ALSO +.Xr ctype 3 , +.Xr islower 3 , +.Xr isupper 3 , +.Xr multibyte 3 , +.Xr ascii 7 +.Sh STANDARDS +The +.Fn isalpha +function conforms to +.St -isoC . diff --git a/locale/isascii.3 b/locale/isascii.3 new file mode 100644 index 0000000..071bb62 --- /dev/null +++ b/locale/isascii.3 @@ -0,0 +1,61 @@ +.\" Copyright (c) 1989, 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. +.\" +.\" @(#)isascii.3 8.2 (Berkeley) 12/11/93 +.\" $FreeBSD: src/lib/libc/locale/isascii.3,v 1.5.2.5 2001/12/14 18:33:54 ru Exp $ +.\" +.Dd December 11, 1993 +.Dt ISASCII 3 +.Os +.Sh NAME +.Nm isascii +.Nd test for ASCII character +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In ctype.h +.Ft int +.Fn isascii "int c" +.Sh DESCRIPTION +The +.Fn isascii +function tests for an +.Tn ASCII +character, which is any character +between 0 and octal 0177 inclusive. +.Sh SEE ALSO +.Xr ctype 3 , +.Xr ascii 7 +.Sh STANDARDS +The +.Fn isascii +function conforms to +.St -isoC . diff --git a/locale/isblank.3 b/locale/isblank.3 new file mode 100644 index 0000000..82587dc --- /dev/null +++ b/locale/isblank.3 @@ -0,0 +1,68 @@ +.\" 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. +.\" +.\" @(#)isblank.3 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD: src/lib/libc/locale/isblank.3,v 1.4.2.3 2001/12/14 18:33:54 ru Exp $ +.\" +.Dd June 4, 1993 +.Dt ISBLANK 3 +.Os +.Sh NAME +.Nm isblank +.Nd space or tab character test +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In ctype.h +.Ft int +.Fn isblank "int c" +.Sh DESCRIPTION +The +.Fn isblank +function tests for a space or tab character. +For single C +.Va char Ns s +locales (see +.Xr multibyte 3 ) +the value of the argument is +representable as an +.Li unsigned char +or the value of +.Dv EOF . +.Sh RETURN VALUES +The +.Fn isblank +function returns zero if the character tests false and +returns non-zero if the character tests true. +.Sh SEE ALSO +.Xr ctype 3 , +.Xr multibyte 3 , +.Xr ascii 7 diff --git a/locale/iscntrl.3 b/locale/iscntrl.3 new file mode 100644 index 0000000..be6dcc5 --- /dev/null +++ b/locale/iscntrl.3 @@ -0,0 +1,89 @@ +.\" Copyright (c) 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. +.\" +.\" @(#)iscntrl.3 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD: src/lib/libc/locale/iscntrl.3,v 1.6.2.5 2001/12/14 18:33:54 ru Exp $ +.\" +.Dd June 4, 1993 +.Dt ISCNTRL 3 +.Os +.Sh NAME +.Nm iscntrl +.Nd control character test +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In ctype.h +.Ft int +.Fn iscntrl "int c" +.Sh DESCRIPTION +The +.Fn iscntrl +function tests for any control character. +For single C +.Va char Ns s +locales (see +.Xr multibyte 3 ) +the value of the argument is +representable as an +.Li unsigned char +or the value of +.Dv EOF . +In the ASCII character set, this includes the following characters +(with their numeric values shown in octal): +.Pp +.Bl -column \&000_``0''__ \&000_``0''__ \&000_``0''__ \&000_``0''__ \&000_``0''__ +.It "\&000\ nul \t001\ soh \t002\ stx \t003\ etx \t004\ eot" +.It "\&005\ enq \t006\ ack \t007\ bel \t010\ bs \t011\ ht" +.It "\&012\ nl \t013\ vt \t014\ np \t015\ cr \t016\ so" +.It "\&017\ si \t020\ dle \t021\ dc1 \t022\ dc2 \t023\ dc3" +.It "\&024\ dc4 \t025\ nak \t026\ syn \t027\ etb \t030\ can" +.It "\&031\ em \t032\ sub \t033\ esc \t034\ fs \t035\ gs" +.It "\&036\ rs \t037\ us \t177\ del" +.El +.Sh RETURN VALUES +The +.Fn iscntrl +function returns zero if the character tests false and +returns non-zero if the character tests true. +.Sh SEE ALSO +.Xr ctype 3 , +.Xr multibyte 3 , +.Xr ascii 7 +.Sh STANDARDS +The +.Fn iscntrl +function conforms to +.St -isoC . diff --git a/locale/isctype.c b/locale/isctype.c new file mode 100644 index 0000000..7c718c7 --- /dev/null +++ b/locale/isctype.c @@ -0,0 +1,233 @@ +/* + * 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. + * + * $FreeBSD: src/lib/libc/locale/isctype.c,v 1.7 2000/02/08 07:43:24 obrien Exp $ + */ + +#if defined(LIBC_SCCS) && !defined(lint) +static char sccsid[] = "@(#)isctype.c 8.3 (Berkeley) 2/24/94"; +#endif /* LIBC_SCCS and not lint */ + +#include + +#undef digittoint +int +digittoint(c) + int c; +{ + return (__maskrune((c), 0xFF)); +} + +#undef isalnum +int +isalnum(c) + int c; +{ + return (__istype((c), _CTYPE_A|_CTYPE_D)); +} + +#undef isalpha +int +isalpha(c) + int c; +{ + return (__istype((c), _CTYPE_A)); +} + +#undef isascii +int +isascii(c) + int c; +{ + return (((c) & ~0x7F) == 0); +} + +#undef isblank +int +isblank(c) + int c; +{ + return (__istype((c), _CTYPE_B)); +} + +#undef iscntrl +int +iscntrl(c) + int c; +{ + return (__istype((c), _CTYPE_C)); +} + +#undef isdigit +int +isdigit(c) + int c; +{ + return (__isctype((c), _CTYPE_D)); +} + +#undef isgraph +int +isgraph(c) + int c; +{ + return (__istype((c), _CTYPE_G)); +} + +#undef ishexnumber +int +ishexnumber(c) + int c; +{ + return (__istype((c), _CTYPE_X)); +} + +#undef isideogram +int +isideogram(c) + int c; +{ + return (__istype((c), _CTYPE_I)); +} + +#undef islower +int +islower(c) + int c; +{ + return (__istype((c), _CTYPE_L)); +} + +#undef isnumber +int +isnumber(c) + int c; +{ + return (__istype((c), _CTYPE_D)); +} + +#undef isphonogram +int +isphonogram(c) + int c; +{ + return (__istype((c), _CTYPE_Q)); +} + +#undef isprint +int +isprint(c) + int c; +{ + return (__istype((c), _CTYPE_R)); +} + +#undef ispunct +int +ispunct(c) + int c; +{ + return (__istype((c), _CTYPE_P)); +} + +#undef isrune +int +isrune(c) + int c; +{ + return (__istype((c), 0xFFFFFF00L)); +} + +#undef isspace +int +isspace(c) + int c; +{ + return (__istype((c), _CTYPE_S)); +} + +#undef isspecial +int +isspecial(c) + int c; +{ + return (__istype((c), _CTYPE_T)); +} + +#undef isupper +int +isupper(c) + int c; +{ + return (__istype((c), _CTYPE_U)); +} + +#undef isxdigit +int +isxdigit(c) + int c; +{ + return (__isctype((c), _CTYPE_X)); +} + +#undef toascii +int +toascii(c) + int c; +{ + return ((c) & 0x7F); +} + +#undef tolower +int +tolower(c) + int c; +{ + return (__tolower(c)); +} + +#undef toupper +int +toupper(c) + int c; +{ + return (__toupper(c)); +} + diff --git a/locale/isdigit.3 b/locale/isdigit.3 new file mode 100644 index 0000000..9042f31 --- /dev/null +++ b/locale/isdigit.3 @@ -0,0 +1,84 @@ +.\" Copyright (c) 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. +.\" +.\" @(#)isdigit.3 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD: src/lib/libc/locale/isdigit.3,v 1.6.2.5 2001/12/14 18:33:54 ru Exp $ +.\" +.Dd June 4, 1993 +.Dt ISDIGIT 3 +.Os +.Sh NAME +.Nm isdigit +.Nd decimal-digit character test +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In ctype.h +.Ft int +.Fn isdigit "int c" +.Sh DESCRIPTION +The +.Fn isdigit +function tests for any decimal-digit character. +For single C +.Va char Ns s +locales (see +.Xr multibyte 3 ) +the value of the argument is +representable as an +.Li unsigned char +or the value of +.Dv EOF . +In the ASCII character set, this includes the following characters +(with their numeric values shown in octal): +.Pp +.Bl -column \&000_``0''__ \&000_``0''__ \&000_``0''__ \&000_``0''__ \&000_``0''__ +.It "\&060\ ``0'' \t061\ ``1'' \t062\ ``2'' \t063\ ``3'' \t064\ ``4''" +.It "\&065\ ``5'' \t066\ ``6'' \t067\ ``7'' \t070\ ``8'' \t071\ ``9''" +.El +.Sh RETURN VALUES +The +.Fn isdigit +function returns zero if the character tests false and +returns non-zero if the character tests true. +.Sh SEE ALSO +.Xr ctype 3 , +.Xr multibyte 3 , +.Xr ascii 7 +.Sh STANDARDS +The +.Fn isdigit +function conforms to +.St -isoC . diff --git a/locale/isgraph.3 b/locale/isgraph.3 new file mode 100644 index 0000000..02e7b13 --- /dev/null +++ b/locale/isgraph.3 @@ -0,0 +1,101 @@ +.\" Copyright (c) 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. +.\" +.\" @(#)isgraph.3 8.2 (Berkeley) 12/11/93 +.\" $FreeBSD: src/lib/libc/locale/isgraph.3,v 1.7.2.5 2001/12/14 18:33:54 ru Exp $ +.\" +.Dd December 11, 1993 +.Dt ISGRAPH 3 +.Os +.Sh NAME +.Nm isgraph +.Nd printing character test (space character exclusive) +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In ctype.h +.Ft int +.Fn isgraph "int c" +.Sh DESCRIPTION +The +.Fn isgraph +function tests for any printing character except space. +For single C +.Va char Ns s +locales (see +.Xr multibyte 3 ) +the value of the argument is +representable as an +.Li unsigned char +or the value of +.Dv EOF . +In the ASCII character set, this includes the following characters +(with their numeric values shown in octal): +.Pp +.Bl -column \&000_``0''__ \&000_``0''__ \&000_``0''__ \&000_``0''__ \&000_``0''__ +.It "\&041\ ``!'' \t042\ ``""'' \t043\ ``#'' \t044\ ``$'' \t045\ ``%''" +.It "\&046\ ``&'' \t047\ ``''' \t050\ ``('' \t051\ ``)'' \t052\ ``*''" +.It "\&053\ ``+'' \t054\ ``,'' \t055\ ``-'' \t056\ ``.'' \t057\ ``/''" +.It "\&060\ ``0'' \t061\ ``1'' \t062\ ``2'' \t063\ ``3'' \t064\ ``4''" +.It "\&065\ ``5'' \t066\ ``6'' \t067\ ``7'' \t070\ ``8'' \t071\ ``9''" +.It "\&072\ ``:'' \t073\ ``;'' \t074\ ``<'' \t075\ ``='' \t076\ ``>''" +.It "\&077\ ``?'' \t100\ ``@'' \t101\ ``A'' \t102\ ``B'' \t103\ ``C''" +.It "\&104\ ``D'' \t105\ ``E'' \t106\ ``F'' \t107\ ``G'' \t110\ ``H''" +.It "\&111\ ``I'' \t112\ ``J'' \t113\ ``K'' \t114\ ``L'' \t115\ ``M''" +.It "\&116\ ``N'' \t117\ ``O'' \t120\ ``P'' \t121\ ``Q'' \t122\ ``R''" +.It "\&123\ ``S'' \t124\ ``T'' \t125\ ``U'' \t126\ ``V'' \t127\ ``W''" +.It "\&130\ ``X'' \t131\ ``Y'' \t132\ ``Z'' \t133\ ``['' \t134\ ``\e\|''" +.It "\&135\ ``]'' \t136\ ``^'' \t137\ ``_'' \t140\ ```'' \t141\ ``a''" +.It "\&142\ ``b'' \t143\ ``c'' \t144\ ``d'' \t145\ ``e'' \t146\ ``f''" +.It "\&147\ ``g'' \t150\ ``h'' \t151\ ``i'' \t152\ ``j'' \t153\ ``k''" +.It "\&154\ ``l'' \t155\ ``m'' \t156\ ``n'' \t157\ ``o'' \t160\ ``p''" +.It "\&161\ ``q'' \t162\ ``r'' \t163\ ``s'' \t164\ ``t'' \t165\ ``u''" +.It "\&166\ ``v'' \t167\ ``w'' \t170\ ``x'' \t171\ ``y'' \t172\ ``z''" +.It "\&173\ ``{'' \t174\ ``|'' \t175\ ``}'' \t176\ ``~''" +.El +.Sh RETURN VALUES +The +.Fn isgraph +function returns zero if the character tests false and +returns non-zero if the character tests true. +.Sh SEE ALSO +.Xr ctype 3 , +.Xr multibyte 3 , +.Xr ascii 7 +.Sh STANDARDS +The +.Fn isgraph +function conforms to +.St -isoC . diff --git a/locale/islower.3 b/locale/islower.3 new file mode 100644 index 0000000..95358f7 --- /dev/null +++ b/locale/islower.3 @@ -0,0 +1,89 @@ +.\" Copyright (c) 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. +.\" +.\" @(#)islower.3 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD: src/lib/libc/locale/islower.3,v 1.7.2.5 2001/12/14 18:33:54 ru Exp $ +.\" +.Dd June 4, 1993 +.Dt ISLOWER 3 +.Os +.Sh NAME +.Nm islower +.Nd lower-case character test +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In ctype.h +.Ft int +.Fn islower "int c" +.Sh DESCRIPTION +The +.Fn islower +function tests for any lower-case letters. +For single C +.Va char Ns s +locales (see +.Xr multibyte 3 ) +the value of the argument is +representable as an +.Li unsigned char +or the value of +.Dv EOF . +In the ASCII character set, this includes the following characters +(with their numeric values shown in octal): +.Pp +.Bl -column \&000_``0''__ \&000_``0''__ \&000_``0''__ \&000_``0''__ \&000_``0''__ +.It "\&141\ ``a'' \t142\ ``b'' \t143\ ``c'' \t144\ ``d'' \t145\ ``e''" +.It "\&146\ ``f'' \t147\ ``g'' \t150\ ``h'' \t151\ ``i'' \t152\ ``j''" +.It "\&153\ ``k'' \t154\ ``l'' \t155\ ``m'' \t156\ ``n'' \t157\ ``o''" +.It "\&160\ ``p'' \t161\ ``q'' \t162\ ``r'' \t163\ ``s'' \t164\ ``t''" +.It "\&165\ ``u'' \t166\ ``v'' \t167\ ``w'' \t170\ ``x'' \t171\ ``y''" +.It "\&172\ ``z''" +.El +.Sh RETURN VALUES +The +.Fn islower +function returns zero if the character tests false and +returns non-zero if the character tests true. +.Sh SEE ALSO +.Xr ctype 3 , +.Xr multibyte 3 , +.Xr tolower 3 , +.Xr ascii 7 +.Sh STANDARDS +The +.Fn islower +function conforms to +.St -isoC . diff --git a/locale/isprint.3 b/locale/isprint.3 new file mode 100644 index 0000000..3f281fe --- /dev/null +++ b/locale/isprint.3 @@ -0,0 +1,101 @@ +.\" Copyright (c) 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. +.\" +.\" @(#)isprint.3 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD: src/lib/libc/locale/isprint.3,v 1.7.2.5 2001/12/14 18:33:54 ru Exp $ +.\" +.Dd June 4, 1993 +.Dt ISPRINT 3 +.Os +.Sh NAME +.Nm isprint +.Nd printing character test (space character inclusive) +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In ctype.h +.Ft int +.Fn isprint "int c" +.Sh DESCRIPTION +The +.Fn isprint +function tests for any printing character including space (' '). +For single C +.Va char Ns s +locales (see +.Xr multibyte 3 ) +the value of the argument is +representable as an +.Li unsigned char +or the value of +.Dv EOF . +In the ASCII character set, this includes the following characters +(with their numeric values shown in octal): +.Pp +.Bl -column \&000_``0''__ \&000_``0''__ \&000_``0''__ \&000_``0''__ \&000_``0''__ +.It "\&040\ sp \t041\ ``!'' \t042\ ``""'' \t043\ ``#'' \t044\ ``$''" +.It "\&045\ ``%'' \t046\ ``&'' \t047\ ``''' \t050\ ``('' \t051\ ``)''" +.It "\&052\ ``*'' \t053\ ``+'' \t054\ ``,'' \t055\ ``-'' \t056\ ``.''" +.It "\&057\ ``/'' \t060\ ``0'' \t061\ ``1'' \t062\ ``2'' \t063\ ``3''" +.It "\&064\ ``4'' \t065\ ``5'' \t066\ ``6'' \t067\ ``7'' \t070\ ``8''" +.It "\&071\ ``9'' \t072\ ``:'' \t073\ ``;'' \t074\ ``<'' \t075\ ``=''" +.It "\&076\ ``>'' \t077\ ``?'' \t100\ ``@'' \t101\ ``A'' \t102\ ``B''" +.It "\&103\ ``C'' \t104\ ``D'' \t105\ ``E'' \t106\ ``F'' \t107\ ``G''" +.It "\&110\ ``H'' \t111\ ``I'' \t112\ ``J'' \t113\ ``K'' \t114\ ``L''" +.It "\&115\ ``M'' \t116\ ``N'' \t117\ ``O'' \t120\ ``P'' \t121\ ``Q''" +.It "\&122\ ``R'' \t123\ ``S'' \t124\ ``T'' \t125\ ``U'' \t126\ ``V''" +.It "\&127\ ``W'' \t130\ ``X'' \t131\ ``Y'' \t132\ ``Z'' \t133\ ``[''" +.It "\&134\ ``\e\|'' \t135\ ``]'' \t136\ ``^'' \t137\ ``_'' \t140\ ```''" +.It "\&141\ ``a'' \t142\ ``b'' \t143\ ``c'' \t144\ ``d'' \t145\ ``e''" +.It "\&146\ ``f'' \t147\ ``g'' \t150\ ``h'' \t151\ ``i'' \t152\ ``j''" +.It "\&153\ ``k'' \t154\ ``l'' \t155\ ``m'' \t156\ ``n'' \t157\ ``o''" +.It "\&160\ ``p'' \t161\ ``q'' \t162\ ``r'' \t163\ ``s'' \t164\ ``t''" +.It "\&165\ ``u'' \t166\ ``v'' \t167\ ``w'' \t170\ ``x'' \t171\ ``y''" +.It "\&172\ ``z'' \t173\ ``{'' \t174\ ``|'' \t175\ ``}'' \t176\ ``~''" +.El +.Sh RETURN VALUES +The +.Fn isprint +function returns zero if the character tests false and +returns non-zero if the character tests true. +.Sh SEE ALSO +.Xr ctype 3 , +.Xr multibyte 3 , +.Xr ascii 7 +.Sh STANDARDS +The +.Fn isprint +function conforms to +.St -isoC . diff --git a/locale/ispunct.3 b/locale/ispunct.3 new file mode 100644 index 0000000..3d17042 --- /dev/null +++ b/locale/ispunct.3 @@ -0,0 +1,92 @@ +.\" Copyright (c) 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. +.\" +.\" @(#)ispunct.3 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD: src/lib/libc/locale/ispunct.3,v 1.7.2.5 2001/12/14 18:33:54 ru Exp $ +.\" +.Dd June 4, 1993 +.Dt ISPUNCT 3 +.Os +.Sh NAME +.Nm ispunct +.Nd punctuation character test +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In ctype.h +.Ft int +.Fn ispunct "int c" +.Sh DESCRIPTION +The +.Fn ispunct +function tests for any printing character except for space (' ') or a +character for which +.Xr isalnum 3 +is true. +For single C +.Va char Ns s +locales (see +.Xr multibyte 3 ) +the value of the argument is +representable as an +.Li unsigned char +or the value of +.Dv EOF . +In the ASCII character set, this includes the following characters +(with their numeric values shown in octal): +.Pp +.Bl -column \&000_``0''__ \&000_``0''__ \&000_``0''__ \&000_``0''__ \&000_``0''__ +.It "\&041\ ``!'' \t042\ ``""'' \t043\ ``#'' \t044\ ``$'' \t045\ ``%''" +.It "\&046\ ``&'' \t047\ ``''' \t050\ ``('' \t051\ ``)'' \t052\ ``*''" +.It "\&053\ ``+'' \t054\ ``,'' \t055\ ``-'' \t056\ ``.'' \t057\ ``/''" +.It "\&072\ ``:'' \t073\ ``;'' \t074\ ``<'' \t075\ ``='' \t076\ ``>''" +.It "\&077\ ``?'' \t100\ ``@'' \t133\ ``['' \t134\ ``\e\|'' \t135\ ``]''" +.It "\&136\ ``^'' \t137\ ``_'' \t140\ ```'' \t173\ ``{'' \t174\ ``|''" +.It "\&175\ ``}'' \t176\ ``~''" +.El +.Sh RETURN VALUES +The +.Fn ispunct +function returns zero if the character tests false and +returns non-zero if the character tests true. +.Sh SEE ALSO +.Xr ctype 3 , +.Xr multibyte 3 , +.Xr ascii 7 +.Sh STANDARDS +The +.Fn ispunct +function conforms to +.St -isoC . diff --git a/locale/isspace.3 b/locale/isspace.3 new file mode 100644 index 0000000..b53b3f9 --- /dev/null +++ b/locale/isspace.3 @@ -0,0 +1,84 @@ +.\" Copyright (c) 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. +.\" +.\" @(#)isspace.3 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD: src/lib/libc/locale/isspace.3,v 1.6.2.5 2001/12/14 18:33:54 ru Exp $ +.\" +.Dd June 4, 1993 +.Dt ISSPACE 3 +.Os +.Sh NAME +.Nm isspace +.Nd white-space character test +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In ctype.h +.Ft int +.Fn isspace "int c" +.Sh DESCRIPTION +The +.Fn isspace +function tests for the standard white-space characters. +For single C +.Va char Ns s +locales (see +.Xr multibyte 3 ) +the value of the argument is +representable as an +.Li unsigned char +or the value of +.Dv EOF . +In the ASCII character set, this includes the following characters +(with their numeric values shown in octal): +.Pp +.Bl -column \&000_``0''__ \&000_``0''__ \&000_``0''__ \&000_``0''__ \&000_``0''__ +.It "\&011\ ht \t012\ nl \t013\ vt \t014\ np \t015\ cr" +.It "\&040\ sp" +.El +.Sh RETURN VALUES +The +.Fn isspace +function returns zero if the character tests false and +returns non-zero if the character tests true. +.Sh SEE ALSO +.Xr ctype 3 , +.Xr multibyte 3 , +.Xr ascii 7 +.Sh STANDARDS +The +.Fn isspace +function conforms to +.St -isoC . diff --git a/locale/isupper.3 b/locale/isupper.3 new file mode 100644 index 0000000..af98c6b --- /dev/null +++ b/locale/isupper.3 @@ -0,0 +1,89 @@ +.\" Copyright (c) 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. +.\" +.\" @(#)isupper.3 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD: src/lib/libc/locale/isupper.3,v 1.8.2.5 2001/12/14 18:33:54 ru Exp $ +.\" +.Dd June 4, 1993 +.Dt ISUPPER 3 +.Os +.Sh NAME +.Nm isupper +.Nd upper-case character test +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In ctype.h +.Ft int +.Fn isupper "int c" +.Sh DESCRIPTION +The +.Fn isupper +function tests for any upper-case letter. +For single C +.Va char Ns s +locales (see +.Xr multibyte 3 ) +the value of the argument is +representable as an +.Li unsigned char +or the value of +.Dv EOF . +In the ASCII character set, this includes the following characters +(with their numeric values shown in octal): +.Pp +.Bl -column \&000_``0''__ \&000_``0''__ \&000_``0''__ \&000_``0''__ \&000_``0''__ +.It "\&101\ ``A'' \t102\ ``B'' \t103\ ``C'' \t104\ ``D'' \t105\ ``E''" +.It "\&106\ ``F'' \t107\ ``G'' \t110\ ``H'' \t111\ ``I'' \t112\ ``J''" +.It "\&113\ ``K'' \t114\ ``L'' \t115\ ``M'' \t116\ ``N'' \t117\ ``O''" +.It "\&120\ ``P'' \t121\ ``Q'' \t122\ ``R'' \t123\ ``S'' \t124\ ``T''" +.It "\&125\ ``U'' \t126\ ``V'' \t127\ ``W'' \t130\ ``X'' \t131\ ``Y''" +.It "\&132\ ``Z''" +.El +.Sh RETURN VALUES +The +.Fn isupper +function returns zero if the character tests false and +returns non-zero if the character tests true. +.Sh SEE ALSO +.Xr ctype 3 , +.Xr multibyte 3 , +.Xr toupper 3 , +.Xr ascii 7 +.Sh STANDARDS +The +.Fn isupper +function conforms to +.St -isoC . diff --git a/locale/isxdigit.3 b/locale/isxdigit.3 new file mode 100644 index 0000000..7fa9ceb --- /dev/null +++ b/locale/isxdigit.3 @@ -0,0 +1,87 @@ +.\" Copyright (c) 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. +.\" +.\" @(#)isxdigit.3 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD: src/lib/libc/locale/isxdigit.3,v 1.6.2.5 2001/12/14 18:33:54 ru Exp $ +.\" +.Dd June 4, 1993 +.Dt ISXDIGIT 3 +.Os +.Sh NAME +.Nm isxdigit +.Nd hexadecimal-digit character test +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In ctype.h +.Ft int +.Fn isxdigit "int c" +.Sh DESCRIPTION +The +.Fn isxdigit +function tests for any hexadecimal-digit character. +For single C +.Va char Ns s +locales (see +.Xr multibyte 3 ) +the value of the argument is +representable as an +.Li unsigned char +or the value of +.Dv EOF . +In the ASCII character set, this includes the following characters +(with their numeric values shown in octal): +.Pp +.Bl -column \&000_``0''__ \&000_``0''__ \&000_``0''__ \&000_``0''__ \&000_``0''__ +.It "\&060\ ``0'' \t061\ ``1'' \t062\ ``2'' \t063\ ``3'' \t064\ ``4''" +.It "\&065\ ``5'' \t066\ ``6'' \t067\ ``7'' \t070\ ``8'' \t071\ ``9''" +.It "\&101\ ``A'' \t102\ ``B'' \t103\ ``C'' \t104\ ``D'' \t105\ ``E''" +.It "\&106\ ``F'' \t141\ ``a'' \t142\ ``b'' \t143\ ``c'' \t144\ ``d''" +.It "\&145\ ``e'' \t146\ ``f''" +.El +.Sh RETURN VALUES +The +.Fn isxdigit +function returns zero if the character tests false and +returns non-zero if the character tests true. +.Sh SEE ALSO +.Xr ctype 3 , +.Xr multibyte 3 , +.Xr ascii 7 +.Sh STANDARDS +The +.Fn isxdigit +function conforms to +.St -isoC . diff --git a/locale/lconv.c b/locale/lconv.c new file mode 100644 index 0000000..f1212b0 --- /dev/null +++ b/locale/lconv.c @@ -0,0 +1,70 @@ +/* + * 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. + */ + +#if defined(LIBC_SCCS) && !defined(lint) +static char sccsid[] = "@(#)lconv.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ + +#include +#include + +static char empty[] = ""; + +/* + * Default (C) locale conversion. + */ +static struct lconv C_lconv = { + ".", /* decimal_point */ + empty, /* thousands_sep */ + empty, /* grouping */ + empty, /* int_curr_symbol */ + empty, /* currency_symbol */ + empty, /* mon_decimal_point */ + empty, /* mon_thousands_sep */ + empty, /* mon_grouping */ + empty, /* positive_sign */ + empty, /* negative_sign */ + CHAR_MAX, /* int_frac_digits */ + CHAR_MAX, /* frac_digits */ + CHAR_MAX, /* p_cs_precedes */ + CHAR_MAX, /* p_sep_by_space */ + CHAR_MAX, /* n_cs_precedes */ + CHAR_MAX, /* n_sep_by_space */ + CHAR_MAX, /* p_sign_posn */ + CHAR_MAX, /* n_sign_posn */ +}; + +/* + * Current locale conversion. + */ +struct lconv *__lconv = &C_lconv; diff --git a/locale/localeconv.c b/locale/localeconv.c new file mode 100644 index 0000000..825f52c --- /dev/null +++ b/locale/localeconv.c @@ -0,0 +1,51 @@ +/* + * 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. + */ + +#if defined(LIBC_SCCS) && !defined(lint) +static char sccsid[] = "@(#)localeconv.c 8.1 (Berkeley) 6/4/93"; +static char rcsid[] = + "$FreeBSD: src/lib/libc/locale/localeconv.c,v 1.1.1.1.14.1 2001/03/05 10:21:18 obrien Exp $"; +#endif /* LIBC_SCCS and not lint */ + +#include + +/* + * Return the current locale conversion. + */ +struct lconv * +localeconv() +{ + extern struct lconv *__lconv; + + return (__lconv); +} diff --git a/locale/mbrune.3 b/locale/mbrune.3 new file mode 100644 index 0000000..e6b6432 --- /dev/null +++ b/locale/mbrune.3 @@ -0,0 +1,160 @@ +.\" 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.6.2.4 2001/12/14 18:33:54 ru 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 +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 +.Ar 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 mbrune 3 , +.Xr rune 3 , +.Xr setlocale 3 , +.Xr euc 4 , +.Xr utf2 4 +.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 . diff --git a/locale/mbrune.c b/locale/mbrune.c new file mode 100644 index 0000000..92efe83 --- /dev/null +++ b/locale/mbrune.c @@ -0,0 +1,112 @@ +/*- + * 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 +#include +#include +#include + +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); +} + +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); +} + +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); +} diff --git a/locale/mskanji.c b/locale/mskanji.c new file mode 100644 index 0000000..16411f6 --- /dev/null +++ b/locale/mskanji.c @@ -0,0 +1,106 @@ +/* + * ja_JP.SJIS locale table for BSD4.4/rune + * version 1.0 + * (C) Sin'ichiro MIYATANI / Phase One, Inc + * May 12, 1995 + * + * 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 Phase One, Inc. + * 4. The name of Phase One, Inc. 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. + * + * $FreeBSD: src/lib/libc/locale/mskanji.c,v 1.2.8.2 2001/03/05 10:22:45 obrien Exp $ + */ + +#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 + +#include +#include +#include +#include + +rune_t _MSKanji_sgetrune __P((const char *, size_t, char const **)); +int _MSKanji_sputrune __P((rune_t, char *, size_t, char **)); + +int +_MSKanji_init(rl) + _RuneLocale *rl; +{ + rl->sgetrune = _MSKanji_sgetrune; + rl->sputrune = _MSKanji_sputrune; + + _CurrentRuneLocale = rl; + __mb_cur_max = 2; + return (0); +} + +rune_t +_MSKanji_sgetrune(string, n, result) + const char *string; + size_t n; + char const **result; +{ + rune_t rune = 0; + + if (n < 1 ) { + rune = _INVALID_RUNE; + } else { + rune = *( string++ ) & 0xff; + if ( ( rune > 0x80 && rune < 0xa0 ) + || ( rune >= 0xe0 && rune < 0xfa ) ) { + if ( n < 2 ) { + rune = (rune_t)_INVALID_RUNE; + --string; + } else { + rune = ( rune << 8 ) | ( *( string++ ) & 0xff ); + } + } + } + if (result) *result = string; + return rune; +} + +int +_MSKanji_sputrune(c, string, n, result) + rune_t c; + char *string, **result; + size_t n; +{ + int len, i; + + len = ( c > 0x100 ) ? 2 : 1; + if ( n < len ) { + if ( result ) *result = (char *) 0; + } else { + if ( result ) *result = string + len; + for ( i = len; i-- > 0; ) { + *( string++ ) = c >> ( i << 3 ); + } + } + return len; +} diff --git a/locale/multibyte.3 b/locale/multibyte.3 new file mode 100644 index 0000000..84a3d0e --- /dev/null +++ b/locale/multibyte.3 @@ -0,0 +1,245 @@ +.\" 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. +.\" +.\" @(#)multibyte.3 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD: src/lib/libc/locale/multibyte.3,v 1.6.2.5 2001/12/14 18:33:54 ru Exp $ +.\" +.Dd June 4, 1993 +.Dt MULTIBYTE 3 +.Os +.Sh NAME +.Nm mblen , +.Nm mbstowcs , +.Nm mbtowc , +.Nm wcstombs , +.Nm wctomb +.Nd multibyte character support for C +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In stdlib.h +.Ft int +.Fn mblen "const char *mbchar" "size_t nbytes" +.Ft size_t +.Fn mbstowcs "wchar_t *wcstring" "const char *mbstring" "size_t nwchars" +.Ft int +.Fn mbtowc "wchar_t *wcharp" "const char *mbchar" "size_t nbytes" +.Ft size_t +.Fn wcstombs "char *mbstring" "const wchar_t *wcstring" "size_t nbytes" +.Ft int +.Fn wctomb "char *mbchar" "wchar_t wchar" +.Sh DESCRIPTION +The basic elements of some written natural languages such as Chinese +cannot be represented uniquely with single C +.Va char Ns s . +The C standard supports two different ways of dealing with +extended natural language encodings, +.Em wide +characters and +.Em multibyte +characters. +Wide characters are an internal representation +which allows each basic element to map +to a single object of type +.Va wchar_t . +Multibyte characters are used for input and output +and code each basic element as a sequence of C +.Va char Ns s . +Individual basic elements may map into one or more +(up to +.Dv MB_CHAR_MAX ) +bytes in a multibyte character. +.Pp +The current locale +.Pq Xr setlocale 3 +governs the interpretation of wide and multibyte characters. +The locale category +.Dv LC_CTYPE +specifically controls this interpretation. +The +.Va wchar_t +type is wide enough to hold the largest value +in the wide character representations for all locales. +.Pp +Multibyte strings may contain +.Sq shift +indicators to switch to and from +particular modes within the given representation. +If explicit bytes are used to signal shifting, +these are not recognized as separate characters +but are lumped with a neighboring character. +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 +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 +with the +.Dv LC_CTYPE +or +.Dv LC_ALL +categories. +.Pp +For convenience in processing, +the wide character with value 0 +(the null wide character) +is recognized as the wide character string terminator, +and the character with value 0 +(the null byte) +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 multibyte characters are not supported in the current locale, +all of these functions will return \-1 if characters can be processed, +otherwise 0. +.Pp +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. +.Sh "SEE ALSO +.Xr mbrune 3 , +.Xr rune 3 , +.Xr setlocale 3 , +.Xr euc 4 , +.Xr utf2 4 +.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. diff --git a/locale/nl_langinfo.3 b/locale/nl_langinfo.3 new file mode 100644 index 0000000..a4ddf96 --- /dev/null +++ b/locale/nl_langinfo.3 @@ -0,0 +1,90 @@ +.\" Copyright (c) 2001 Alexey Zelkin +.\" 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 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. +.\" +.\" $FreeBSD: src/lib/libc/locale/nl_langinfo.3,v 1.2 2001/09/17 08:18:45 ache Exp $ +.\" +.Dd May 3, 2001 +.Dt NL_LANGINFO 3 +.Os +.Sh NAME +.Nm nl_langinfo +.Nd language information +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In langinfo.h +.Ft char * +.Fn nl_langinfo "nl_item item" +.Sh DESCRIPTION +The +.Fn nl_langinfo +function returns a pointer to a string containing information relevant to +the particular language or cultural area defined in the program's locale. +The manifest constant names and values of +.Fa item +are defined in +.Aq Pa langinfo.h . +.Pp +Calls to +.Fn setlocale +with a category corresponding to the category of +.Fa item , +or to the +category +.Dv LC_ALL , +may overwrite buffer pointed by the return value. +.Sh EXAMPLES +For example: +.Pp +.Dl nl_langinfo(ABDAY_1) +.Pp +would return a pointer to the string +.Qq Li Dom +if the identified language was +Portuguese, and +.Qq Li Sun +if the identified language was English. +.Sh RETURN VALUES +In a locale where langinfo data is not defined, +.Fn nl_langinfo +returns a pointer to the corresponding string in the +.Tn POSIX +locale. +In all locales, +.Fn nl_langinfo +returns a pointer to an empty string if +.Fa item +contains an invalid setting. +.Sh SEE ALSO +.Xr setlocale 3 +.Sh STANDARDS +The +.Fn nl_langinfo +function conforms to +.St -susv2 . +.Sh HISTORY +The +.Fn nl_langinfo +function first appeared in +.Fx 5.0 . diff --git a/locale/nomacros.c b/locale/nomacros.c new file mode 100644 index 0000000..45c0db7 --- /dev/null +++ b/locale/nomacros.c @@ -0,0 +1,9 @@ +/* + * Tell to generate extern versions of all its inline + * functions. The extern versions get called if the system doesn't + * support inlines or the user defines _DONT_USE_CTYPE_INLINE_ + * before including . + */ +#define _EXTERNALIZE_CTYPE_INLINES_ + +#include diff --git a/locale/none.c b/locale/none.c new file mode 100644 index 0000000..4fb7d7e --- /dev/null +++ b/locale/none.c @@ -0,0 +1,92 @@ +/*- + * 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. + * + * $FreeBSD: src/lib/libc/locale/none.c,v 1.2.8.1 2001/03/05 10:25:03 obrien Exp $ + */ + +#if defined(LIBC_SCCS) && !defined(lint) +static char sccsid[] = "@(#)none.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ + +#include +#include +#include +#include + +rune_t _none_sgetrune __P((const char *, size_t, char const **)); +int _none_sputrune __P((rune_t, char *, size_t, char **)); + +int +_none_init(rl) + _RuneLocale *rl; +{ + rl->sgetrune = _none_sgetrune; + rl->sputrune = _none_sputrune; + _CurrentRuneLocale = rl; + __mb_cur_max = 1; + return(0); +} + +rune_t +_none_sgetrune(string, n, result) + const char *string; + size_t n; + char const **result; +{ + if (n < 1) { + if (result) + *result = string; + return(_INVALID_RUNE); + } + if (result) + *result = string + 1; + return(*string & 0xff); +} + +int +_none_sputrune(c, string, n, result) + rune_t c; + char *string, **result; + size_t n; +{ + if (n >= 1) { + if (string) + *string = c; + if (result) + *result = string + 1; + } else if (result) + *result = (char *)0; + return(1); +} diff --git a/locale/rune.3 b/locale/rune.3 new file mode 100644 index 0000000..570e73d --- /dev/null +++ b/locale/rune.3 @@ -0,0 +1,277 @@ +.\" 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.10.2.6 2001/12/14 18:33:54 ru Exp $ +.\" +.Dd December 11, 1993 +.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 +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 +.Fn setrunelocale +was successful. +.It Bq Er EFAULT +.Fa locale +was +.Dv NULL . +.It Bq Er ENOENT +The locale could not be found. +.It Bq Er EFTYPE +The file found was not a valid file. +.It Bq Er EINVAL +The encoding indicated by the locale was unknown. +.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 +.Sh NOTES +The ANSI C type +.Em wchar_t +is the same as +.Em rune_t . +.Em Rune_t +was chosen to accent the purposeful choice of not basing the +system with the ANSI C +primitives, which were, shall we say, less aesthetic. +.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" +as a much more sane alternative to the ANSI multibyte and +wide character support. +.\"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. +.Pp +All of the ANSI multibyte and wide character +support functions are built using the rune functions. diff --git a/locale/rune.c b/locale/rune.c new file mode 100644 index 0000000..5531c76 --- /dev/null +++ b/locale/rune.c @@ -0,0 +1,175 @@ +/*- + * 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. + * + * $FreeBSD: src/lib/libc/locale/rune.c,v 1.5.8.1 2001/03/05 10:26:02 obrien Exp $ + */ + +#if defined(LIBC_SCCS) && !defined(lint) +static char sccsid[] = "@(#)rune.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ + +#include +#include +#include +#include +#include +#include + +_RuneLocale * +_Read_RuneMagi(fp) + FILE *fp; +{ + char *data; + void *lastp; + _RuneLocale *rl; + _RuneEntry *rr; + struct stat sb; + int x; + + if (fstat(fileno(fp), &sb) < 0) + return(0); + + if (sb.st_size < sizeof(_RuneLocale)) + return(0); + + if ((data = malloc(sb.st_size)) == NULL) + return(0); + + rewind(fp); /* Someone might have read the magic number once already */ + + if (fread(data, sb.st_size, 1, fp) != 1) { + free(data); + return(0); + } + + rl = (_RuneLocale *)data; + lastp = data + sb.st_size; + + rl->variable = rl + 1; + + if (memcmp(rl->magic, _RUNE_MAGIC_1, sizeof(rl->magic))) { + free(data); + return(0); + } + + 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_ext.ranges = (_RuneEntry *)rl->variable; + rl->variable = rl->runetype_ext.ranges + rl->runetype_ext.nranges; + if (rl->variable > lastp) { + free(data); + return(0); + } + + rl->maplower_ext.ranges = (_RuneEntry *)rl->variable; + rl->variable = rl->maplower_ext.ranges + rl->maplower_ext.nranges; + if (rl->variable > lastp) { + free(data); + return(0); + } + + rl->mapupper_ext.ranges = (_RuneEntry *)rl->variable; + rl->variable = rl->mapupper_ext.ranges + rl->mapupper_ext.nranges; + if (rl->variable > lastp) { + free(data); + return(0); + } + + 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) { + free(data); + return(0); + } + while (len-- > 0) + rr[x].types[len] = ntohl(rr[x].types[len]); + } else + rr[x].types = 0; + } + + 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); + } + + 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); + } + if (((char *)rl->variable) + rl->variable_len > (char *)lastp) { + free(data); + return(0); + } + + /* + * Go out and zero pointers that should be zero. + */ + if (!rl->variable_len) + rl->variable = 0; + + if (!rl->runetype_ext.nranges) + rl->runetype_ext.ranges = 0; + + if (!rl->maplower_ext.nranges) + rl->maplower_ext.ranges = 0; + + if (!rl->mapupper_ext.nranges) + rl->mapupper_ext.ranges = 0; + + return(rl); +} diff --git a/locale/runetype.c b/locale/runetype.c new file mode 100644 index 0000000..9f5228c --- /dev/null +++ b/locale/runetype.c @@ -0,0 +1,65 @@ +/*- + * 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. + * + * $FreeBSD: src/lib/libc/locale/runetype.c,v 1.5.8.1 2000/06/04 21:47:39 ache Exp $ + */ + +#include +#include + +unsigned long +___runetype(c) + _BSD_CT_RUNE_T_ c; +{ + int x; + _RuneRange *rr = &_CurrentRuneLocale->runetype_ext; + _RuneEntry *re = rr->ranges; + + 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); + } + } + + return(0L); +} diff --git a/locale/setinvalidrune.c b/locale/setinvalidrune.c new file mode 100644 index 0000000..45a2a47 --- /dev/null +++ b/locale/setinvalidrune.c @@ -0,0 +1,44 @@ +/*- + * 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 + +void +setinvalidrune(ir) + rune_t ir; +{ + _INVALID_RUNE = ir; +} diff --git a/locale/setlocale.3 b/locale/setlocale.3 new file mode 100644 index 0000000..b0cdfb6 --- /dev/null +++ b/locale/setlocale.3 @@ -0,0 +1,338 @@ +.\" 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. +.\" +.\" @(#)setlocale.3 8.1 (Berkeley) 6/9/93 +.\" $FreeBSD: src/lib/libc/locale/setlocale.3,v 1.15.2.5 2001/12/14 18:33:55 ru Exp $ +.\" +.Dd June 9, 1993 +.Dt SETLOCALE 3 +.Os +.Sh NAME +.Nm setlocale , +.Nm localeconv +.Nd natural language formatting for C +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In locale.h +.Ft char * +.Fn setlocale "int category" "const char *locale" +.Ft struct lconv * +.Fn localeconv "void" +.Sh DESCRIPTION +The +.Fn setlocale +function sets the C library's notion +of natural language formatting style +for particular sets of routines. +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 +function recognizes several categories of routines. +These are the categories and the sets of routines they select: +.Pp +.Bl -tag -width LC_MONETARY +.It Dv LC_ALL +Set the entire locale generically. +.It Dv LC_COLLATE +Set a locale for string collation routines. +This controls alphabetic ordering in +.Fn strcoll +and +.Fn strxfrm . +.It Dv LC_CTYPE +Set a locale for the +.Xr ctype 3 , +.Xr mbrune 3 , +.Xr multibyte 3 +and +.Xr rune 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. +.It Dv LC_MESSAGES +Set a locale for message catalogs, see +.Xr catopen 3 +function. +.It Dv LC_MONETARY +Set a locale for formatting monetary values; +this affects the +.Fn localeconv +function. +.It Dv LC_NUMERIC +Set a locale for formatting numbers. +This controls the formatting of decimal points +in input and output of floating point numbers +in functions such as +.Fn printf +and +.Fn scanf , +as well as values returned by +.Fn localeconv . +.It Dv LC_TIME +Set a locale for formatting dates and times using the +.Fn strftime +function. +.El +.Pp +Only three locales are defined by default, +the empty string +.Li "\&""\|"" +which denotes the native environment, and the +.Li "\&""C"" +and +.Li "\&""POSIX"" +locales, which denote the C language environment. +A +.Fa locale +argument of +.Dv NULL +causes +.Fn setlocale +to return the current locale. +By default, C programs start in the +.Li "\&""C"" +locale. +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; +}; +.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. +.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. +.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 setlocale +function returns +.Dv NULL +and fails to change the locale +if the given combination of +.Fa category +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 FILES +.Bl -tag -width /usr/share/locale/locale/category -compact +.It Pa $PATH_LOCALE/ Ns Em locale/category +.It Pa /usr/share/locale/ Ns Em locale/category +locale file for the locale +.Em locale +and the category +.Em category . +.El +.Sh SEE ALSO +.Xr colldef 1 , +.Xr mklocale 1 , +.Xr catopen 3 , +.Xr ctype 3 , +.Xr mbrune 3 , +.Xr multibyte 3 , +.Xr rune 3 , +.Xr strcoll 3 , +.Xr strxfrm 3 , +.Xr euc 4 , +.Xr utf2 4 +.Sh STANDARDS +The +.Fn setlocale +and +.Fn localeconv +functions conform to +.St -isoC . +.Sh HISTORY +The +.Fn setlocale +and +.Fn localeconv +functions first appeared in +.Bx 4.4 . +.Sh BUGS +The current implementation supports only the +.Li "\&""C"" +and +.Li "\&""POSIX"" +locales for all but the +.Dv LC_COLLATE , +.Dv LC_CTYPE , +and +.Dv LC_TIME +categories. +.Pp +In spite of the gnarly currency support in +.Fn localeconv , +the standards don't include any functions +for generalized currency formatting. +.Pp +Use of +.Dv LC_MONETARY +could lead to misleading results until we have a real time currency +conversion function. +.Dv LC_NUMERIC +and +.Dv LC_TIME +are personal choices and should not be wrapped up with the other categories. diff --git a/locale/setlocale.c b/locale/setlocale.c new file mode 100644 index 0000000..3ec6fca --- /dev/null +++ b/locale/setlocale.c @@ -0,0 +1,307 @@ +/* + * Copyright (c) 1991, 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. + */ + +#ifdef LIBC_RCS +static const char rcsid[] = + "$FreeBSD: src/lib/libc/locale/setlocale.c,v 1.25.2.4 2001/03/05 13:08:42 ru Exp $"; +#endif + +#if defined(LIBC_SCCS) && !defined(lint) +static char sccsid[] = "@(#)setlocale.c 8.1 (Berkeley) 7/4/93"; +#endif /* LIBC_SCCS and not lint */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include "collate.h" +#include "setlocale.h" + +/* + * Category names for getenv() + */ +static char *categories[_LC_LAST] = { + "LC_ALL", + "LC_COLLATE", + "LC_CTYPE", + "LC_MONETARY", + "LC_NUMERIC", + "LC_TIME", + "LC_MESSAGES" +}; + +/* + * Current locales for each category + */ +static char current_categories[_LC_LAST][ENCODING_LEN + 1] = { + "C", + "C", + "C", + "C", + "C", + "C", + "C" +}; + +/* + * The locales we are going to try and load + */ +static char new_categories[_LC_LAST][ENCODING_LEN + 1]; +static char saved_categories[_LC_LAST][ENCODING_LEN + 1]; + +static char current_locale_string[_LC_LAST * (ENCODING_LEN + 1/*"/"*/ + 1)]; + +static char *currentlocale __P((void)); +static char *loadlocale __P((int)); +static int stub_load_locale __P((const char *)); + +extern int __time_load_locale __P((const char *)); /* strftime.c */ + +char * +setlocale(category, locale) + int category; + const char *locale; +{ + int i, j, len; + char *env, *r; + + if (category < LC_ALL || category >= _LC_LAST) + return (NULL); + + if (!locale) + return (category != LC_ALL ? + current_categories[category] : currentlocale()); + + /* + * Default to the current locale for everything. + */ + for (i = 1; i < _LC_LAST; ++i) + (void)strcpy(new_categories[i], current_categories[i]); + + /* + * Now go fill up new_categories from the locale argument + */ + if (!*locale) { + env = getenv("LC_ALL"); + + if (category != LC_ALL && (!env || !*env)) + env = getenv(categories[category]); + + if (!env || !*env) + env = getenv("LANG"); + + if (!env || !*env || strchr(env, '/')) + env = "C"; + + (void) strncpy(new_categories[category], env, ENCODING_LEN); + new_categories[category][ENCODING_LEN] = '\0'; + if (category == LC_ALL) { + for (i = 1; i < _LC_LAST; ++i) { + if (!(env = getenv(categories[i])) || !*env) + env = new_categories[LC_ALL]; + (void)strncpy(new_categories[i], env, ENCODING_LEN); + new_categories[i][ENCODING_LEN] = '\0'; + } + } + } else if (category != LC_ALL) { + (void)strncpy(new_categories[category], locale, ENCODING_LEN); + new_categories[category][ENCODING_LEN] = '\0'; + } else { + if ((r = strchr(locale, '/')) == NULL) { + for (i = 1; i < _LC_LAST; ++i) { + (void)strncpy(new_categories[i], locale, ENCODING_LEN); + new_categories[i][ENCODING_LEN] = '\0'; + } + } else { + for (i = 1; r[1] == '/'; ++r); + if (!r[1]) + return (NULL); /* Hmm, just slashes... */ + do { + len = r - locale > ENCODING_LEN ? ENCODING_LEN : r - locale; + (void)strncpy(new_categories[i], locale, len); + new_categories[i][len] = '\0'; + i++; + locale = r; + while (*locale == '/') + ++locale; + while (*++r && *r != '/'); + } while (*locale); + while (i < _LC_LAST) { + (void)strcpy(new_categories[i], + new_categories[i-1]); + i++; + } + } + } + + if (category) + return (loadlocale(category)); + + for (i = 1; i < _LC_LAST; ++i) { + (void)strcpy(saved_categories[i], current_categories[i]); + if (loadlocale(i) == NULL) { + for (j = 1; j < i; j++) { + (void)strcpy(new_categories[j], + saved_categories[j]); + /* XXX can fail too */ + (void)loadlocale(j); + } + return (NULL); + } + } + return (currentlocale()); +} + +static char * +currentlocale() +{ + int i; + + (void)strcpy(current_locale_string, current_categories[1]); + + for (i = 2; i < _LC_LAST; ++i) + if (strcmp(current_categories[1], current_categories[i])) { + for (i = 2; i < _LC_LAST; ++i) { + (void) strcat(current_locale_string, "/"); + (void) strcat(current_locale_string, current_categories[i]); + } + break; + } + return (current_locale_string); +} + +static char * +loadlocale(category) + int category; +{ + char *ret; + char *new = new_categories[category]; + char *old = current_categories[category]; + + 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 (NULL); + _PathLocale = strdup(p); + if (_PathLocale == NULL) + return (NULL); + } else + _PathLocale = _PATH_LOCALE; + } + + if (strcmp(new, old) == 0) + return (old); + + if (category == LC_CTYPE) { + ret = setrunelocale(new) ? NULL : new; + if (!ret) + (void)setrunelocale(old); + else + (void)strcpy(old, new); + return (ret); + } + + if (category == LC_COLLATE) { + ret = (__collate_load_tables(new) < 0) ? NULL : new; + if (!ret) + (void)__collate_load_tables(old); + else + (void)strcpy(old, new); + return (ret); + } + + if (category == LC_TIME) { + ret = (__time_load_locale(new) < 0) ? NULL : new; + if (!ret) + (void)__time_load_locale(old); + else + (void)strcpy(old, new); + return (ret); + } + + if (category == LC_MONETARY || + category == LC_MESSAGES || + category == LC_NUMERIC) { + ret = stub_load_locale(new) ? NULL : new; + if (!ret) + (void)stub_load_locale(old); + else + (void)strcpy(old, new); + return (ret); + } + + /* Just in case...*/ + return (NULL); +} + +static int +stub_load_locale(encoding) +const char *encoding; +{ + char name[PATH_MAX]; + struct stat st; + + if (!encoding) + return(1); + /* + * The "C" and "POSIX" locale are always here. + */ + if (!strcmp(encoding, "C") || !strcmp(encoding, "POSIX")) + return(0); + if (!_PathLocale) + return(1); + /* Range checking not needed, encoding has fixed size */ + strcpy(name, _PathLocale); + strcat(name, "/"); + strcat(name, encoding); +#if 0 + /* + * Some day we will actually look at this file. + */ +#endif + return (stat(name, &st) != 0 || !S_ISDIR(st.st_mode)); +} diff --git a/locale/setlocale.h b/locale/setlocale.h new file mode 100644 index 0000000..f3b2a22 --- /dev/null +++ b/locale/setlocale.h @@ -0,0 +1,34 @@ +#ifndef _SETLOCALE_H +#define _SETLOCALE_H +/* + * Copyright (C) 1997 by Andrey A. Chernov, Moscow, Russia. + * 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 ``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. + */ + +#define ENCODING_LEN 31 +#define CATEGORY_LEN 11 + +extern char *_PathLocale; + +#endif /* SETLOCALE_H */ diff --git a/locale/setrunelocale.c b/locale/setrunelocale.c new file mode 100644 index 0000000..509fac2 --- /dev/null +++ b/locale/setrunelocale.c @@ -0,0 +1,121 @@ +/*- + * 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. + * + * $FreeBSD: src/lib/libc/locale/setrunelocale.c,v 1.14.6.1 2000/06/04 21:47:39 ache Exp $ + */ + +#include +#include +#include +#include +#include +#include +#include +#include "setlocale.h" + +extern int _none_init __P((_RuneLocale *)); +extern int _UTF2_init __P((_RuneLocale *)); +extern int _EUC_init __P((_RuneLocale *)); +extern int _BIG5_init __P((_RuneLocale *)); +extern int _MSKanji_init __P((_RuneLocale *)); +extern _RuneLocale *_Read_RuneMagi __P((FILE *)); + +int +setrunelocale(encoding) + char *encoding; +{ + FILE *fp; + char name[PATH_MAX]; + _RuneLocale *rl; + + if (!encoding || strlen(encoding) > ENCODING_LEN) + return(EFAULT); + + /* + * The "C" and "POSIX" locale are always here. + */ + if (!strcmp(encoding, "C") || !strcmp(encoding, "POSIX")) { + _CurrentRuneLocale = &_DefaultRuneLocale; + return(0); + } + + 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(EFAULT); + _PathLocale = strdup(p); + if (_PathLocale == NULL) + return (errno); + } else + _PathLocale = _PATH_LOCALE; + } + /* Range checking not needed, encoding length already checked above */ + (void) strcpy(name, _PathLocale); + (void) strcat(name, "/"); + (void) strcat(name, encoding); + (void) strcat(name, "/LC_CTYPE"); + + if ((fp = fopen(name, "r")) == NULL) + return(ENOENT); + + if ((rl = _Read_RuneMagi(fp)) == 0) { + fclose(fp); + return(EFTYPE); + } + fclose(fp); + + if (!rl->encoding[0]) + return(EINVAL); + else if (!strcmp(rl->encoding, "NONE")) + return(_none_init(rl)); + else if (!strcmp(rl->encoding, "UTF2")) + return(_UTF2_init(rl)); + else if (!strcmp(rl->encoding, "EUC")) + return(_EUC_init(rl)); + else if (!strcmp(rl->encoding, "BIG5")) + return(_BIG5_init(rl)); + else if (!strcmp(rl->encoding, "MSKanji")) + return(_MSKanji_init(rl)); + else + return(EINVAL); +} + diff --git a/locale/table.c b/locale/table.c new file mode 100644 index 0000000..4771c56 --- /dev/null +++ b/locale/table.c @@ -0,0 +1,258 @@ +/*- + * 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. + * + * $FreeBSD: src/lib/libc/locale/table.c,v 1.13.2.1 2000/06/04 21:47:39 ache Exp $ + */ + +#if defined(LIBC_SCCS) && !defined(lint) +static char sccsid[] = "@(#)table.c 8.1 (Berkeley) 6/27/93"; +#endif /* LIBC_SCCS and not lint */ + +#include +#include + +extern rune_t _none_sgetrune __P((const char *, size_t, char const **)); +extern int _none_sputrune __P((rune_t, char *, size_t, char **)); +extern int _none_init __P((char *, char **)); + +_RuneLocale _DefaultRuneLocale = { + _RUNE_MAGIC_1, + "NONE", + _none_sgetrune, + _none_sputrune, + 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 = &_DefaultRuneLocale; + +int __mb_cur_max = 1; + +char *_PathLocale; diff --git a/locale/toascii.3 b/locale/toascii.3 new file mode 100644 index 0000000..82099ef --- /dev/null +++ b/locale/toascii.3 @@ -0,0 +1,72 @@ +.\" 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. +.\" +.\" @(#)toascii.3 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD: src/lib/libc/locale/toascii.3,v 1.4.2.2 2001/12/14 18:33:55 ru Exp $ +.\" +.Dd June 4, 1993 +.Dt TOASCII 3 +.Os +.Sh NAME +.Nm toascii +.Nd convert a byte to 7-bit ASCII +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In ctype.h +.Ft int +.Fn toascii "int c" +.Sh DESCRIPTION +The +.Fn toascii +function strips all but the low 7 bits from a letter, +including parity or other marker bits. +.Sh RETURN VALUES +The +.Fn toascii +function always returns a valid ASCII character. +.Sh SEE ALSO +.Xr isalnum 3 , +.Xr isalpha 3 , +.Xr isascii 3 , +.Xr iscntrl 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 diff --git a/locale/tolower.3 b/locale/tolower.3 new file mode 100644 index 0000000..761948c --- /dev/null +++ b/locale/tolower.3 @@ -0,0 +1,92 @@ +.\" Copyright (c) 1989, 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. +.\" +.\" @(#)tolower.3 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD: src/lib/libc/locale/tolower.3,v 1.6.2.4 2001/12/14 18:33:55 ru Exp $ +.\" +.Dd June 4, 1993 +.Dt TOLOWER 3 +.Os +.Sh NAME +.Nm tolower +.Nd upper case to lower case letter conversion +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In ctype.h +.Ft int +.Fn tolower "int c" +.Sh DESCRIPTION +The +.Fn tolower +function converts an upper-case letter to the corresponding lower-case +letter. +For single C +.Va char Ns s +locales (see +.Xr multibyte 3 ) +the value of the argument is +representable as an +.Li unsigned char +or the value of +.Dv EOF . +.Sh RETURN VALUES +If the argument is an upper-case letter, the +.Fn tolower +function returns the corresponding lower-case letter if there is +one; otherwise the argument is returned unchanged. +.Sh SEE ALSO +.Xr isalnum 3 , +.Xr isalpha 3 , +.Xr isascii 3 , +.Xr iscntrl 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 multibyte 3 , +.Xr stdio 3 , +.Xr toascii 3 , +.Xr toupper 3 , +.Xr ascii 7 +.Sh STANDARDS +The +.Fn tolower +function conforms to +.St -isoC . diff --git a/locale/tolower.c b/locale/tolower.c new file mode 100644 index 0000000..3ed1840 --- /dev/null +++ b/locale/tolower.c @@ -0,0 +1,61 @@ +/*- + * 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. + * + * $FreeBSD: src/lib/libc/locale/tolower.c,v 1.5.8.1 2000/06/04 21:47:39 ache Exp $ + */ + +#include +#include + +_BSD_CT_RUNE_T_ +___tolower(c) + _BSD_CT_RUNE_T_ c; +{ + int x; + _RuneRange *rr = &_CurrentRuneLocale->maplower_ext; + _RuneEntry *re = rr->ranges; + + 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); + } + + return(c); +} diff --git a/locale/toupper.3 b/locale/toupper.3 new file mode 100644 index 0000000..e4edd22 --- /dev/null +++ b/locale/toupper.3 @@ -0,0 +1,92 @@ +.\" Copyright (c) 1989, 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. +.\" +.\" @(#)toupper.3 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD: src/lib/libc/locale/toupper.3,v 1.5.2.5 2001/12/14 18:33:55 ru Exp $ +.\" +.Dd June 4, 1993 +.Dt TOUPPER 3 +.Os +.Sh NAME +.Nm toupper +.Nd lower case to upper case letter conversion +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In ctype.h +.Ft int +.Fn toupper "int c" +.Sh DESCRIPTION +The +.Fn toupper +function converts a lower-case letter to the corresponding +upper-case letter. +For single C +.Va char Ns s +locales (see +.Xr multibyte 3 ) +the value of the argument is +representable as an +.Li unsigned char +or the value of +.Dv EOF . +.Sh RETURN VALUES +If the argument is a lower-case letter, the +.Fn toupper +function returns the corresponding upper-case letter if there is +one; otherwise the argument is returned unchanged. +.Sh SEE ALSO +.Xr isalnum 3 , +.Xr isalpha 3 , +.Xr isascii 3 , +.Xr iscntrl 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 multibyte 3 , +.Xr stdio 3 , +.Xr toascii 3 , +.Xr tolower 3 , +.Xr ascii 7 +.Sh STANDARDS +The +.Fn toupper +function conforms to +.St -isoC . diff --git a/locale/toupper.c b/locale/toupper.c new file mode 100644 index 0000000..9fbe9d7 --- /dev/null +++ b/locale/toupper.c @@ -0,0 +1,61 @@ +/*- + * 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. + * + * $FreeBSD: src/lib/libc/locale/toupper.c,v 1.5.8.1 2000/06/04 21:47:39 ache Exp $ + */ + +#include +#include + +_BSD_CT_RUNE_T_ +___toupper(c) + _BSD_CT_RUNE_T_ c; +{ + int x; + _RuneRange *rr = &_CurrentRuneLocale->mapupper_ext; + _RuneEntry *re = rr->ranges; + + 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); + } + + return(c); +} diff --git a/locale/utf2.4 b/locale/utf2.4 new file mode 100644 index 0000000..3b81b9c --- /dev/null +++ b/locale/utf2.4 @@ -0,0 +1,88 @@ +.\" 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.8.2.1 2001/03/06 16:45:58 ru Exp $ +.\" +.Dd June 4, 1993 +.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 +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 diff --git a/locale/utf2.c b/locale/utf2.c new file mode 100644 index 0000000..5219434 --- /dev/null +++ b/locale/utf2.c @@ -0,0 +1,149 @@ +/*- + * 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. + * + * $FreeBSD: src/lib/libc/locale/utf2.c,v 1.3.2.2 2001/03/05 10:27:18 obrien Exp $ + */ + +#if defined(LIBC_SCCS) && !defined(lint) +static char sccsid[] = "@(#)utf2.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ + +#include +#include +#include +#include + +rune_t _UTF2_sgetrune __P((const char *, size_t, char const **)); +int _UTF2_sputrune __P((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); + } +} diff --git a/mach.subproj/Makefile b/mach.subproj/Makefile deleted file mode 100644 index 68ed0b6..0000000 --- a/mach.subproj/Makefile +++ /dev/null @@ -1,65 +0,0 @@ -# -# Generated by the Apple Project Builder. -# -# NOTE: Do NOT change this file -- Project Builder maintains it. -# -# Put all of your customizations in files called Makefile.preamble -# and Makefile.postamble (both optional), and Makefile will include them. -# - -NAME = mach - -PROJECTVERSION = 2.8 -PROJECT_TYPE = Component - -HFILES = externs.h - -OTHERLINKED = mach_traps.s - -CFILES = clock_sleep.c error_codes.c exc_catcher.c exc_catcher_state.c\ - exc_catcher_state_identity.c fprintf_stderr.c mach_error.c\ - mach_error_string.c mach_init.c mach_init_ports.c mach_msg.c\ - mach_msg_destroy.c mach_msg_receive.c mach_msg_send.c\ - mach_msg_server.c mach_subsystem_join.c mig_allocate.c\ - mig_deallocate.c mig_reply_setup.c mig_strncpy.c\ - ms_thread_switch.c panic.c port_obj.c sbrk.c semaphore.c\ - slot_name.c mach_absolute_time.c - -SUBPROJECTS = headers.subproj servers.subproj - -OTHERSRCS = Makefile.preamble Makefile Makefile.postamble\ - bootstrap.defs clock.defs clock_reply.defs err_ipc.sub\ - err_kern.sub err_mach_ipc.sub err_server.sub err_us.sub\ - exc.defs ledger.defs mach_port.defs notify.defs\ - clock_priv.defs host_priv.defs host_security.defs\ - lock_set.defs processor.defs processor_set.defs task.defs\ - thread_act.defs vm_map.defs mach_host.defs - -OTHERLINKEDOFILES = mach_traps.o - -MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles -CODE_GEN_STYLE = DYNAMIC -MAKEFILE = subproj.make -LIBS = -DEBUG_LIBS = $(LIBS) -PROF_LIBS = $(LIBS) - - - - -NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc -WINDOWS_OBJCPLUS_COMPILER = $(DEVDIR)/gcc -PDO_UNIX_OBJCPLUS_COMPILER = $(NEXTDEV_BIN)/gcc -NEXTSTEP_JAVA_COMPILER = /usr/bin/javac -WINDOWS_JAVA_COMPILER = $(JDKBINDIR)/javac.exe -PDO_UNIX_JAVA_COMPILER = $(JDKBINDIR)/javac - -include $(MAKEFILEDIR)/platform.make - --include Makefile.preamble - -include $(MAKEFILEDIR)/$(MAKEFILE) - --include Makefile.postamble - --include Makefile.dependencies diff --git a/mach.subproj/Makefile.postamble b/mach.subproj/Makefile.postamble deleted file mode 100644 index e69de29..0000000 diff --git a/mach.subproj/Makefile.preamble b/mach.subproj/Makefile.preamble deleted file mode 100644 index c8f3ba4..0000000 --- a/mach.subproj/Makefile.preamble +++ /dev/null @@ -1,37 +0,0 @@ -PUBLIC_HDR_INSTALL_DIR = /usr/include -PRIVATE_HDR_INSTALL_DIR = $(SYSTEM_LIBRARY_DIR)/Frameworks/System.framework/Versions/B/PrivateHeaders -PUBLIC_HEADER_DIR_SUFFIX = /mach -PRIVATE_HEADER_DIR_SUFFIX = /mach -OTHER_PUBLIC_HEADERS = bootstrap.h \ - clock.h \ - clock_priv.h \ - mach_host.h \ - host_priv.h \ - host_security.h \ - ledger.h \ - lock_set.h \ - processor.h \ - processor_set.h \ - task.h \ - thread_act.h \ - vm_map.h \ - mach_port.h -OTHER_PROJECT_HEADERS = lock_set.h vm_map.h -OTHER_OFILES = excUser.o \ - excServer.o \ - ledgerUser.o \ - notifyUser.o \ - processorUser.o \ - processor_setUser.o \ - taskUser.o \ - vm_mapUser.o \ - thread_actUser.o \ - bootstrapUser.o \ - lock_setUser.o \ - mach_portUser.o \ - clockUser.o \ - clock_privUser.o \ - mach_hostUser.o \ - host_privUser.o \ - host_securityUser.o - diff --git a/mach.subproj/PB.project b/mach.subproj/PB.project deleted file mode 100644 index 9a4126c..0000000 --- a/mach.subproj/PB.project +++ /dev/null @@ -1,78 +0,0 @@ -{ - DYNAMIC_CODE_GEN = YES; - FILESTABLE = { - H_FILES = (externs.h); - OTHER_LINKED = ( - clock_sleep.c, - error_codes.c, - exc_catcher.c, - exc_catcher_state.c, - exc_catcher_state_identity.c, - fprintf_stderr.c, - mach_error.c, - mach_error_string.c, - mach_init.c, - mach_init_ports.c, - mach_msg.c, - mach_msg_destroy.c, - mach_msg_receive.c, - mach_msg_send.c, - mach_msg_server.c, - mach_subsystem_join.c, - mach_traps.s, - mig_allocate.c, - mig_deallocate.c, - mig_reply_setup.c, - mig_strncpy.c, - ms_thread_switch.c, - panic.c, - port_obj.c, - sbrk.c, - semaphore.c, - slot_name.c, - mach_absolute_time.c - ); - OTHER_SOURCES = ( - Makefile.preamble, - Makefile, - Makefile.postamble, - bootstrap.defs, - clock.defs, - clock_reply.defs, - err_ipc.sub, - err_kern.sub, - err_mach_ipc.sub, - err_server.sub, - err_us.sub, - exc.defs, - ledger.defs, - mach_port.defs, - notify.defs, - clock_priv.defs, - host_priv.defs, - host_security.defs, - lock_set.defs, - processor.defs, - processor_set.defs, - task.defs, - thread_act.defs, - vm_map.defs, - mach_host.defs - ); - SUBPROJECTS = (headers.subproj, servers.subproj); - }; - LANGUAGE = English; - MAKEFILEDIR = "$(MAKEFILEPATH)/pb_makefiles"; - NEXTSTEP_BUILDTOOL = /bin/gnumake; - NEXTSTEP_JAVA_COMPILER = /usr/bin/javac; - NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc; - PDO_UNIX_BUILDTOOL = $NEXT_ROOT/Developer/bin/make; - PDO_UNIX_JAVA_COMPILER = "$(JDKBINDIR)/javac"; - PDO_UNIX_OBJCPLUS_COMPILER = "$(NEXTDEV_BIN)/gcc"; - PROJECTNAME = mach; - PROJECTTYPE = Component; - PROJECTVERSION = 2.8; - WINDOWS_BUILDTOOL = $NEXT_ROOT/Developer/Executables/make; - WINDOWS_JAVA_COMPILER = "$(JDKBINDIR)/javac.exe"; - WINDOWS_OBJCPLUS_COMPILER = "$(DEVDIR)/gcc"; -} diff --git a/mach.subproj/bootstrap.defs b/mach.subproj/bootstrap.defs deleted file mode 100644 index 8f57322..0000000 --- a/mach.subproj/bootstrap.defs +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include diff --git a/mach.subproj/clock.defs b/mach.subproj/clock.defs deleted file mode 100644 index 1695171..0000000 --- a/mach.subproj/clock.defs +++ /dev/null @@ -1 +0,0 @@ -#include diff --git a/mach.subproj/clock_priv.defs b/mach.subproj/clock_priv.defs deleted file mode 100644 index d419faf..0000000 --- a/mach.subproj/clock_priv.defs +++ /dev/null @@ -1 +0,0 @@ -#include diff --git a/mach.subproj/clock_reply.defs b/mach.subproj/clock_reply.defs deleted file mode 100644 index b0e0f5b..0000000 --- a/mach.subproj/clock_reply.defs +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include diff --git a/mach.subproj/clock_sleep.c b/mach.subproj/clock_sleep.c deleted file mode 100644 index e96fcc2..0000000 --- a/mach.subproj/clock_sleep.c +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include -#include -#include - -kern_return_t clock_sleep(mach_port_t clock_name, - sleep_type_t clock_type, - mach_timespec_t sleep_time, - mach_timespec_t *wake_time) { - - return clock_sleep_trap(clock_name, clock_type, sleep_time.tv_sec, sleep_time.tv_nsec, wake_time); -} diff --git a/mach.subproj/err_ipc.sub b/mach.subproj/err_ipc.sub deleted file mode 100644 index 9c763cc..0000000 --- a/mach.subproj/err_ipc.sub +++ /dev/null @@ -1,99 +0,0 @@ -/* - * @OSF_COPYRIGHT@ - */ - -/* - * Mach Operating System - * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University - * All Rights Reserved. - * - * Permission to use, copy, modify and distribute this software and its - * documentation is hereby granted, provided that both the copyright - * notice and this permission notice appear in all copies of the - * software, derivative works or modified versions, and any portions - * thereof, and that both notices appear in supporting documentation. - * - * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS - * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR - * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. - * - * Carnegie Mellon requests users of this software to return to - * - * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU - * School of Computer Science - * Carnegie Mellon University - * Pittsburgh PA 15213-3890 - * - * any improvements or extensions that they make and grant Carnegie the - * rights to redistribute these changes. - */ - -/* - * File: err_ipc.sub - * Author: Douglas Orr, Carnegie Mellon University - * Date: Mar, 1988 - * - * Definitions of error strings for original IPC - */ - -static const char * err_codes_send[] = { - "(ipc/send) unknown error", /* -100 */ - "(ipc/send) invalid memory", /* -101 */ - "(ipc/send) invalid port", /* -102 */ - "(ipc/send) timed out", /* -103 */ - "(ipc/send) unused error", /* -104 */ - "(ipc/send) will notify", /* -105 */ - "(ipc/send) notify in progress", /* -106 */ - "(ipc/send) kernel refused message", /* -107 */ - "(ipc/send) send interrupted", /* -108 */ - "(ipc/send) send message too large", /* -109 */ - "(ipc/send) send message too small", /* -110 */ - "(ipc/send) message size changed while being copied", /* -111 */ -}; - -static const char * err_codes_rcv[] = { - "(ipc/rcv) unknown error", /* -200 */ - "(ipc/rcv) invalid memory", /* -201 */ - "(ipc/rcv) invalid port", /* -202 */ - "(ipc/rcv) receive timed out", /* -203 */ - "(ipc/rcv) message too large", /* -204 */ - "(ipc/rcv) no space for message data", /* -205 */ - "(ipc/rcv) only sender remaining", /* -206 */ - "(ipc/rcv) receive interrupted", /* -207 */ - "(ipc/rcv) port receiver changed or port became enabled", /* -208 */ -}; - -static const char * err_codes_mig[] = { - "(ipc/mig) type check failure in message interface", /* 0 (-300) */ - "(ipc/mig) wrong return message ID", /* 1 */ - "(ipc/mig) server detected error", /* 2 */ - "(ipc/mig) bad message ID", /* 3 */ - "(ipc/mig) server found wrong arguments", /* 4 */ - "(ipc/mig) no reply should be sent", /* 5 */ - "(ipc/mig) server raised exception", /* 6 */ - "(ipc/mig) user specified array not large enough for return info", /* 7 */ -}; - -/* err_ipc subsystems */ -static struct error_subsystem err_ipc_sub[] = { - /* ipc/0; */ - { - (char *)"(ipc/send)", - errlib_count(err_codes_send), - (char **)err_codes_send, - }, - /* ipc/1; */ - { - (char *)"(ipc/rcv)", - errlib_count(err_codes_rcv), - (char **)err_codes_rcv, - - }, - /* ipc/2 */ - { - (char *)"(ipc/mig)", - errlib_count(err_codes_mig), - (char **)err_codes_mig, - }, - -}; diff --git a/mach.subproj/err_kern.sub b/mach.subproj/err_kern.sub deleted file mode 100644 index 5103603..0000000 --- a/mach.subproj/err_kern.sub +++ /dev/null @@ -1,182 +0,0 @@ -/* - * @OSF_COPYRIGHT@ - */ - -/* - * Mach Operating System - * Copyright (c) 1991,1990,1989 Carnegie Mellon University - * All Rights Reserved. - * - * Permission to use, copy, modify and distribute this software and its - * documentation is hereby granted, provided that both the copyright - * notice and this permission notice appear in all copies of the - * software, derivative works or modified versions, and any portions - * thereof, and that both notices appear in supporting documentation. - * - * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS - * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR - * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. - * - * Carnegie Mellon requests users of this software to return to - * - * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU - * School of Computer Science - * Carnegie Mellon University - * Pittsburgh PA 15213-3890 - * - * any improvements or extensions that they make and grant Carnegie the - * rights to redistribute these changes. - */ - -/* - * File: err_kern.sub - * Author: Douglas Orr, Carnegie Mellon University - * Date: Mar, 1988 - * - * error codes for Mach and Unix kernels - */ - -static const char * err_codes_kern[] = { - "(os/kern) successful", /* 0 */ - "(os/kern) invalid address", - "(os/kern) protection failure", - "(os/kern) no space available", - "(os/kern) invalid argument", - "(os/kern) failure", /* 5 */ - "(os/kern) resource shortage", - "(os/kern) not receiver", - "(os/kern) no access", - "(os/kern) memory failure", - "(os/kern) memory error", /* 10 */ - "(os/kern) already in set", - "(os/kern) not in set", - "(os/kern) name exists", - "(os/kern) aborted", - "(os/kern) invalid name", /* 15 */ - "(os/kern) invalid task", - "(os/kern) invalid right", - "(os/kern) invalid value", - "(os/kern) urefs overflow", - "(os/kern) invalid capability", /* 20 */ - "(os/kern) right exists", - "(os/kern) invalid host", - "(os/kern) memory present", - "(os/kern) memory data moved", - "(os/kern) memory restart copy", /* 25 */ - "(os/kern) invalid processor set", - "(os/kern) policy limit", - "(os/kern) invalid policy", - "(os/kern) invalid object", - "(os/kern) already waiting", /* 30 */ - "(os/kern) default set", - "(os/kern) exception protected", - "(os/kern) invalid ledger", - "(os/kern) invalid memory control", - "(os/kern) invalid security", /* 35 */ - "(os/kern) not depressed", - "(os/kern) object terminated", - "(os/kern) lock set destroyed", - "(os/kern) lock unstable", - "(os/kern) lock owned by another", /* 40 */ - "(os/kern) lock owned by self", - "(os/kern) semaphore destroyed", - "(os/kern) RPC terminated", - "(os/kern) terminate orphan", - "(os/kern) let orphan continue", /* 45 */ - "(os/kern) service not supported", - "(os/kern) remote node down", -}; - -static const char * err_codes_unix[] = { - NO_SUCH_ERROR, - "(os/unix) no rights to object", - "(os/unix) file or directory does not exist", - "(os/unix) no such process", - "(os/unix) interrupted system call", - "(os/unix) i/o error", - "(os/unix) device does not exist", - "(os/unix) argument list is too long", - "(os/unix) invalid executable object format", - "(os/unix) bad file descriptor number", - "(os/unix) no child processes are present", - "(os/unix) no more processes are available", - "(os/unix) insufficient memory", - "(os/unix) access denied", - "(os/unix) memory access fault", - "(os/unix) block device required for operation", - "(os/unix) mount device busy", - "(os/unix) file already exists", - "(os/unix) cross device link", - "(os/unix) device does not exist", - "(os/unix) object is not a directory", - "(os/unix) object is a directory", - "(os/unix) invalid argument", - "(os/unix) internal file table overflow", - "(os/unix) maximum number of open files reached", - "(os/unix) object is not a tty-like device", - "(os/unix) executable object is in use", - "(os/unix) file is too large", - "(os/unix) no space is left on device", - "(os/unix) illegal seek attempt", - "(os/unix) read-only file system", - "(os/unix) too many links", - "(os/unix) broken pipe", - "(os/unix) argument is too large", - "(os/unix) result is out of range", - "(os/unix) operation on device would block", - "(os/unix) operation is now in progress", - "(os/unix) operation is already in progress", - "(os/unix) socket operation attempted on non-socket object", - "(os/unix) destination address is required", - "(os/unix) message is too long", - "(os/unix) protocol type is incorrect for socket", - "(os/unix) protocol type is not availaible", - "(os/unix) protocol type is not supported", - "(os/unix) socket type is not supported", - "(os/unix) operation is not supported on sockets", - "(os/unix) protocol family is not supported", - "(os/unix) address family is not supported by protocol family", - "(os/unix) address is already in use", - "(os/unix) can't assign requested address", - "(os/unix) network is down", - "(os/unix) network is unreachable", - "(os/unix) network dropped connection on reset", - "(os/unix) software aborted connection", - "(os/unix) connection reset by peer", - "(os/unix) no buffer space is available", - "(os/unix) socket is already connected", - "(os/unix) socket is not connected", - "(os/unix) can't send after socket shutdown", - "(os/unix) too many references; can't splice", - "(os/unix) connection timed out", - "(os/unix) connection was refused", - "(os/unix) too many levels of symbolic links", - "(os/unix) file name exceeds system maximum limit", - "(os/unix) host is down", - "(os/unix) there is no route to host", - "(os/unix) directory is not empty", - "(os/unix) quota on number of processes exceeded", - "(os/unix) quota on number of users exceeded", - "(os/unix) quota on available disk space exceeded", -}; - -static struct error_subsystem err_os_sub[] = { - { - (char *)"(os/kern)", - errlib_count(err_codes_kern), - (char **)err_codes_kern, - }, - { - (char *)"(os/?)", - 0, - }, - { - (char *)"(os/?)", - 0, - }, - { - (char *)"(os/unix)", - errlib_count(err_codes_unix), - (char **)err_codes_unix, - }, -}; diff --git a/mach.subproj/err_mach_ipc.sub b/mach.subproj/err_mach_ipc.sub deleted file mode 100644 index 6db64fb..0000000 --- a/mach.subproj/err_mach_ipc.sub +++ /dev/null @@ -1,119 +0,0 @@ -/* - * @OSF_COPYRIGHT@ - */ - -/* - * Mach Operating System - * Copyright (c) 1991,1990,1989 Carnegie Mellon University - * All Rights Reserved. - * - * Permission to use, copy, modify and distribute this software and its - * documentation is hereby granted, provided that both the copyright - * notice and this permission notice appear in all copies of the - * software, derivative works or modified versions, and any portions - * thereof, and that both notices appear in supporting documentation. - * - * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS - * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR - * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. - * - * Carnegie Mellon requests users of this software to return to - * - * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU - * School of Computer Science - * Carnegie Mellon University - * Pittsburgh PA 15213-3890 - * - * any improvements or extensions that they make and grant Carnegie the - * rights to redistribute these changes. - */ - -/* - * File: err_mach_ipc.sub - * Author: Richard Draves, Carnegie Mellon University - * Date: Jan, 1990 - * - * Error string definitions for the new Mach IPC - */ - -static const char * err_codes_mach_send[] = { - /* 0 */ "(ipc/send) no error", - /* 1 */ "(ipc/send) send in progress", - /* 2 */ "(ipc/send) invalid data", - /* 3 */ "(ipc/send) invalid destination port", - /* 4 */ "(ipc/send) timed out", - /* 5 */ "(ipc/send) will notify", - /* 6 */ "(ipc/send) notify in progress", - /* 7 */ "(ipc/send) interrupted", - /* 8 */ "(ipc/send) msg too small", - /* 9 */ "(ipc/send) invalid reply port", - /* 10 */ "(ipc/send) invalid port right", - /* 11 */ "(ipc/send) invalid notify port", - /* 12 */ "(ipc/send) invalid memory", - /* 13 */ "(ipc/send) no msg buffer", - /* 14 */ "(ipc/send) no notify possible", - /* 15 */ "(ipc/send) invalid msg-type", - /* 16 */ "(ipc/send) invalid msg-header", - /* 17 */ "(ipc/send) invalid msg-trailer", - /* 18 */ "(ipc/send) DIPC transport failure", - /* 19 */ "(ipc/send) DIPC port migrated", - /* 20 */ "(ipc/send) DIPC resend failed", - /* 21 */ "(ipc/send) out-of-line buffer too large", -}; - -static const char * err_codes_mach_rcv[] = { - /* 0 */ "(ipc/rcv) no error", - /* 1 */ "(ipc/rcv) receive in progress", - /* 2 */ "(ipc/rcv) invalid name", - /* 3 */ "(ipc/rcv) timed out", - /* 4 */ "(ipc/rcv) msg too large", - /* 5 */ "(ipc/rcv) interrupted", - /* 6 */ "(ipc/rcv) port changed", - /* 7 */ "(ipc/rcv) invalid notify port", - /* 8 */ "(ipc/rcv) invalid data", - /* 9 */ "(ipc/rcv) port died", - /* 10 */ "(ipc/rcv) port in set", - /* 11 */ "(ipc/rcv) header error", - /* 12 */ "(ipc/rcv) body error", - /* 13 */ "(ipc/rcv) invalid scatter list entry", - /* 14 */ "(ipc/rcv) overwrite region too small", - /* 15 */ "(ipc/rcv) invalid msg-trailer", - /* 16 */ "(ipc/rcv) DIPC transport error", -}; - -static const char * err_codes_mach_mig[] = { - /* 0 */ "(ipc/mig) client type check failure", - /* 1 */ "(ipc/mig) wrong reply message ID", - /* 2 */ "(ipc/mig) server detected error", - /* 3 */ "(ipc/mig) bad request message ID", - /* 4 */ "(ipc/mig) server type check failure", - /* 5 */ "(ipc/mig) no reply should be sent", - /* 6 */ "(ipc/mig) server raised exception", - /* 7 */ "(ipc/mig) array not large enough", - /* 8 */ "(ipc/mig) server died", - /* 9 */ "(ipc/mig) unknown trailer format", -}; - -/* err_mach_ipc subsystems */ -static struct error_subsystem err_mach_ipc_sub[] = { - /* ipc/0; */ - { - (char *)"(ipc/send)", - errlib_count(err_codes_mach_send), - (char **)err_codes_mach_send, - }, - /* ipc/1; */ - { - (char *)"(ipc/rcv)", - errlib_count(err_codes_mach_rcv), - (char **)err_codes_mach_rcv, - - }, - /* ipc/2 */ - { - (char *)"(ipc/mig)", - errlib_count(err_codes_mach_mig), - (char **)err_codes_mach_mig, - }, - -}; diff --git a/mach.subproj/err_server.sub b/mach.subproj/err_server.sub deleted file mode 100644 index fcbe91b..0000000 --- a/mach.subproj/err_server.sub +++ /dev/null @@ -1,357 +0,0 @@ -/* - * @OSF_COPYRIGHT@ - */ - -/* - * Mach Operating System - * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University - * All Rights Reserved. - * - * Permission to use, copy, modify and distribute this software and its - * documentation is hereby granted, provided that both the copyright - * notice and this permission notice appear in all copies of the - * software, derivative works or modified versions, and any portions - * thereof, and that both notices appear in supporting documentation. - * - * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS - * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR - * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. - * - * Carnegie Mellon requests users of this software to return to - * - * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU - * School of Computer Science - * Carnegie Mellon University - * Pittsburgh PA 15213-3890 - * - * any improvements or extensions that they make and grant Carnegie the - * rights to redistribute these changes. - */ - -/* - * File: err_server.sub - * Author: Douglas Orr, Carnegie Mellon University - * Date: Mar, 1988 - * - * Definitions of Servers error strings - */ - -static const char * err_codes_netname[] = { /* 0 */ - "(server/netname) name is not yours", - "(server/netname) name not checked in", - "(server/netname) no such host", - "(server/netname) host not found", -}; -static const char * err_codes_env_mgr[] = { /* 1 */ - NO_SUCH_ERROR, - "(server/env_mgr) variable not found", - "(server/env_mgr) wrong type of variable", - "(server/env_mgr) unknown port", - "(server/env_mgr) read only environment", - "(server/env_mgr) no more connections available", - "(server/env_mgr) port table full", - "(server/env_mgr) attempting to enter a null port ", -}; -static const char * err_codes_execd[] = { /* 2 */ - NO_SUCH_ERROR, - "(server/execd) could not find file to run", - "(server/execd) userid or password incorrect", - "(server/execd) fork failed", -}; -static const char * err_codes_netmemory[] = { /* 3 */ - "(server/netmemory) successful", - "(server/netmemory) invalid argument", - "(server/netmemory) resource shortage", -}; -static const char * err_codes_ufs[] = { /* 4 */ - NO_SUCH_ERROR, -/* XXX "(server/ufs) invalid port", */ -}; - -static const char * err_codes_task_master[] = { /* 5 */ - "(server/task_master) GENERIC ERROR", - "(server/task_master) invalid tm_task port", - "(server/task_master) invalid task id", - "(server/task_master) invalid kernel port", - "(server/task_master) invalid job group", - "(server/task_master) invalid action", -}; - -static const char * err_codes_ns[] = { /* 6 */ - "(server/ns) GENERIC ERROR", - "(server/ns) invalid handle", - "(server/ns) name not found", - "(server/ns) name already exists", - "(server/ns) name too long", - "(server/ns) path too long", - "(server/ns) invalid name", - "(server/ns) not a directory", - "(server/ns) is a directory", - "(server/ns) directory not empty", - "(server/ns) infinite retry loop in resolver", - "(server/ns) infinite forwarding loop in resolver", - "(server/ns) invalid prefix", - "(server/ns) prefix table overflow", - "(server/ns) bad format for directory", - "(server/ns) unknown entry type", - "(server/ns) invalid generation", - "(server/ns) entry not reserved", -}; - -static const char * err_codes_io[] = { /* 7 */ - "(server/io) GENERIC ERROR", - "(server/io) invalid offset", - "(server/io) invalid size", - "(server/io) invalid mode", - "(server/io) invalid strategy", - "(server/io) operation rejected under current I/O strategy", -}; - -static const char * err_codes_auth[] = { /* 8 */ - "(server/auth) GENERIC ERROR", - "(server/auth) bad private port", - "(server/auth) bad name", - "(server/auth) not primary", - "(server/auth) bad pauthsword", - "(server/auth) bad group", - "(server/auth) duplicate id", - "(server/auth) duplicate name", - "(server/auth) not secondary", -}; - -static const char * err_codes_us[] = { /* 9 */ - "(server/us) GENERIC ERROR", - "(server/us) unknown error", - "(server/us) object not found", - "(server/us) object exists", - "(server/us) object busy", - "(server/us) object not started", - "(server/us) object dead", - "(server/us) invalid args", - "(server/us) invalid access", - "(server/us) invalid format", - "(server/us) invalid buffer size", - "(server/us) access denied", - "(server/us) resource exhausted", - "(server/us) quota exceeded", - "(server/us) limit exceeded", - "(server/us) not implemented", - "(server/us) not supported", - "(server/us) hardware error", - "(server/us) retry required", - "(server/us) not authenticated", - "(server/us) exclusive access", - "(server/us) timeout", - "(server/us) bad reference count", - "(server/us) internal error", -}; - -static const char * err_codes_sunrpc[] = { /* 10 */ - "(server/sunrpc) GENERIC ERROR", - "(server/sunrpc) cannot encode arguments", - "(server/sunrpc) cannot decode results", - "(server/sunrpc) failure in sending call", - "(server/sunrpc) failure in receiving result", - "(server/sunrpc) call timed out", - "(server/sunrpc) rpc versions not compatible", - "(server/sunrpc) authentication error", - "(server/sunrpc) program not available", - "(server/sunrpc) program version mismatched", - "(server/sunrpc) procedure unavailable", - "(server/sunrpc) decode arguments error", - "(server/sunrpc) generic other problem", - "(server/sunrpc) unknown host name", - "(server/sunrpc) portmapper failed", - "(server/sunrpc) remote program not registered", - "(server/sunrpc) unspecified error", - "(server/sunrpc) unknown protocol", -}; - -static const char * err_codes_machobj[] = { /* 11 */ - "(server/object system) GENERIC ERROR", - "(server/object system) object not found", - "(server/object system) no such operation", - "(server/object system) undefined ipc method arguments", - "(server/object system) too many arguments to method", - "(server/object system) bad ipc message format", -}; - -static const char * err_codes_loader[] = { /* 12 */ - "(server/loader) GENERIC ERROR", - "(server/loader) object file not relocated", - "(server/loader) unknown file type", - "(server/loader) symbol not found", - "(server/loader) symbol multiply defined", - "(server/loader) memory region overlap", -}; - - -static const char * err_codes_exception[] = { /* 13 */ - "(server/exception) GENERIC ERROR", - "(server/exception) invalid access", - "(server/exception) invalid instruction", - "(server/exception) arithmetic exception", - "(server/exception) emulation exception", - "(server/exception) software exception", - "(server/exception) breakpoint exception", -}; - -static const char * err_codes_ux_signal[] = { /* 14 */ - "(server/unix-signal) GENERIC ERROR", - "(server/unix-signal) hangup", - "(server/unix-signal) interrupt", - "(server/unix-signal) quit", - "(server/unix-signal) undefined", - "(server/unix-signal) undefined", - "(server/unix-signal) undefined", - "(server/unix-signal) undefined", - "(server/unix-signal) kill", - "(server/unix-signal) undefined", - "(server/unix-signal) undefined", - "(server/unix-signal) system error", - "(server/unix-signal) pipe signal", - "(server/unix-signal) alarm", - "(server/unix-signal) terminate", - "(server/unix-signal) urgent i/o", - "(server/unix-signal) stop", - "(server/unix-signal) terminal stop", - "(server/unix-signal) continue", - "(server/unix-signal) child death", - "(server/unix-signal) tty input", - "(server/unix-signal) tty output", - "(server/unix-signal) i/o signal", - "(server/unix-signal) cpu time limit exceeded", - "(server/unix-signal) file size exceeded", - "(server/unix-signal) virtual alarm", - "(server/unix-signal) profile signal", - "(server/unix-signal) window size change", - "(server/unix-signal) user-defined signal 1", - "(server/unix-signal) user-defined signal 2", -}; - -static const char * err_codes_xkernel[] = { /* 15 */ - "(server/xkernel) GENERIC ERROR", - "(server/xkernel) map full", - "(server/xkernel) inconsistent bind", - "(server/xkernel) cannot resolve", - "(server/xkernel) cannot unbind", - "(server/xkernel) invalid type", - "(server/xkernel) invalid opcode", - "(server/xkernel) buffer too small", - "(server/xkernel) invalid ev code", - "(server/xkernel) event not registered", - "(server/xkernel) invalid open", - "(server/xkernel) already open", - "(server/xkernel) bad addr", -}; - - -/* err_server subsystems */ -static struct error_subsystem err_server_sub[] = { - /* server/0; */ - { - (char *)"(server/netname)", - errlib_count(err_codes_netname), - (char **)err_codes_netname, - }, - /* server/1; */ - { - (char *)"(server/env_mgr)", - errlib_count(err_codes_env_mgr), - (char **)err_codes_env_mgr, - }, - /* server/2; */ - { - (char *)"(server/execd)", - errlib_count(err_codes_execd), - (char **)err_codes_execd, - }, - /* server/3; */ - { - (char *)"(server/netmemory)", - errlib_count(err_codes_netmemory), - (char **)err_codes_netmemory, - }, - /* server/4; */ - { - (char *)"(server/ufs)", - errlib_count(err_codes_ufs), - (char **)err_codes_ufs, - }, - /* server/5; */ - { - (char *)"(server/task_master)", - errlib_count(err_codes_task_master), - (char **)err_codes_task_master, - }, - /* server/6; */ - { - (char *)"(server/ns)", - errlib_count(err_codes_ns), - (char **)err_codes_ns, - }, - - /* server/7; i/o subsystem */ - { - (char *)"(server/io)", - errlib_count(err_codes_io), - (char **)err_codes_io, - }, - - /* server/8; authentication server */ - { - (char *)"(server/auth)", - errlib_count(err_codes_auth), - (char **)err_codes_auth, - }, - - /* server/9; generic US system */ - { - (char *)"(server/us)", - errlib_count(err_codes_us), - (char **)err_codes_us, - }, - - /* server/10; SUN RPC package */ - { - (char *)"(server/sunrpc)", - errlib_count(err_codes_sunrpc), - (char **)err_codes_sunrpc, - }, - - /* server/11; MachObject system */ - { - (char *)"(server/object system)", - errlib_count(err_codes_machobj), - (char **)err_codes_machobj, - }, - - /* server/12; loader */ - { - (char *)"(server/loader)", - errlib_count(err_codes_loader), - (char **)err_codes_loader, - }, - - /* server/13; mach exception */ - { - (char *)"(server/exception)", - errlib_count(err_codes_exception), - (char **)err_codes_exception, - }, - - /* server/14; unix signal */ - { - (char *)"(server/unix-signal)", - errlib_count(err_codes_ux_signal), - (char **)err_codes_ux_signal, - }, - - /* server/15; xkernel */ - { - (char *)"(server/xkernel)", - errlib_count(err_codes_xkernel), - (char **)err_codes_xkernel, - }, - -}; diff --git a/mach.subproj/err_us.sub b/mach.subproj/err_us.sub deleted file mode 100644 index 8db68f6..0000000 --- a/mach.subproj/err_us.sub +++ /dev/null @@ -1,45 +0,0 @@ -/* - * @OSF_COPYRIGHT@ - */ - -/* - * Mach Operating System - * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University - * All Rights Reserved. - * - * Permission to use, copy, modify and distribute this software and its - * documentation is hereby granted, provided that both the copyright - * notice and this permission notice appear in all copies of the - * software, derivative works or modified versions, and any portions - * thereof, and that both notices appear in supporting documentation. - * - * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS - * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR - * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. - * - * Carnegie Mellon requests users of this software to return to - * - * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU - * School of Computer Science - * Carnegie Mellon University - * Pittsburgh PA 15213-3890 - * - * any improvements or extensions that they make and grant Carnegie the - * rights to redistribute these changes. - */ - -/* - * File: err_us.sub - * Author: Douglas Orr, Carnegie Mellon University - * Date: Mar, 1988 - * - * A place to define User errors - */ - - -/* err_us subsystems */ -static struct error_subsystem err_us_sub[] = { - { - (char *)0, - }, -}; diff --git a/mach.subproj/error_codes.c b/mach.subproj/error_codes.c deleted file mode 100644 index b46cd61..0000000 --- a/mach.subproj/error_codes.c +++ /dev/null @@ -1,79 +0,0 @@ -/* - * @OSF_COPYRIGHT@ - */ -/* - * Mach Operating System - * Copyright (c) 1991,1990,1989 Carnegie Mellon University - * All Rights Reserved. - * - * Permission to use, copy, modify and distribute this software and its - * documentation is hereby granted, provided that both the copyright - * notice and this permission notice appear in all copies of the - * software, derivative works or modified versions, and any portions - * thereof, and that both notices appear in supporting documentation. - * - * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS - * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR - * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. - * - * Carnegie Mellon requests users of this software to return to - * - * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU - * School of Computer Science - * Carnegie Mellon University - * Pittsburgh PA 15213-3890 - * - * any improvements or extensions that they make and grant Carnegie the - * rights to redistribute these changes. - */ - -/* - * File: error_codes.c - * Author: Douglas Orr, Carnegie Mellon University - * Date: Mar, 1988 - * - * Generic error code interface - */ - -#include -#include -#include "err_kern.sub" -#include "err_us.sub" -#include "err_server.sub" -#include "err_ipc.sub" -#include "err_mach_ipc.sub" - -struct error_system errors[err_max_system+1] = { - /* 0; err_kern */ - { - errlib_count(err_os_sub), - (char *)"(operating system/?) unknown subsystem error", - err_os_sub, - }, - /* 1; err_us */ - { - errlib_count(err_us_sub), - (char *)"(user space/?) unknown subsystem error", - err_us_sub, - }, - /* 2; err_server */ - { - errlib_count(err_server_sub), - (char *)"(server/?) unknown subsystem error", - err_server_sub, - }, - /* 3 (& 3f); err_ipc */ - { - errlib_count(err_ipc_sub), - (char *)"(ipc/?) unknown subsystem error", - err_ipc_sub, - }, - /* 4; err_mach_ipc */ - { - errlib_count(err_mach_ipc_sub), - (char *)"(ipc/?) unknown subsystem error", - err_mach_ipc_sub, - }, -}; - -int error_system_count = errlib_count(errors); diff --git a/mach.subproj/exc.defs b/mach.subproj/exc.defs deleted file mode 100644 index 9bdb234..0000000 --- a/mach.subproj/exc.defs +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#define catch_ internal_catch_ -#include diff --git a/mach.subproj/exc_catcher.c b/mach.subproj/exc_catcher.c deleted file mode 100644 index 1125ed3..0000000 --- a/mach.subproj/exc_catcher.c +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * catch_exception_raise will be implemented by user programs - * This implementation is provided to resolve the reference in - * exc_server(). - */ - -#include -#include -#include -#include -#include - -__private_extern__ kern_return_t internal_catch_exception_raise ( - mach_port_t exception_port, - mach_port_t thread, - mach_port_t task, - exception_type_t exception, - exception_data_t code, - mach_msg_type_number_t codeCnt) -{ -#if defined(__DYNAMIC__) - static int checkForFunction = 0; - /* This will be non-zero if the user has defined this function */ - static kern_return_t (*func)(mach_port_t, mach_port_t, mach_port_t, exception_type_t, exception_data_t, mach_msg_type_number_t); - if (checkForFunction == 0) { - checkForFunction = 1; - _dyld_lookup_and_bind("_catch_exception_raise", (unsigned long *)&func, (void **)0); - } - if (func == 0) { - /* The user hasn't defined catch_exception_raise in their binary */ - abort(); - } - return (*func)(exception_port, thread, task, exception, code, codeCnt); -#else - extern kern_return_t catch_exception_raise(mach_port_t, mach_port_t, mach_port_t, exception_type_t, exception_data_t, mach_msg_type_number_t); - return catch_exception_raise(exception_port, thread, task, exception, code, codeCnt); -#endif -} - diff --git a/mach.subproj/exc_catcher_state.c b/mach.subproj/exc_catcher_state.c deleted file mode 100644 index 61cefb3..0000000 --- a/mach.subproj/exc_catcher_state.c +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * catch_exception_raise_state will be implemented by user programs - * This implementation is provided to resolve the reference in - * exc_server(). - */ - -#include -#include -#include -#include -#include - -__private_extern__ kern_return_t internal_catch_exception_raise_state ( - mach_port_t exception_port, - exception_type_t exception, - exception_data_t code, - mach_msg_type_number_t codeCnt, - int *flavor, - thread_state_t old_state, - mach_msg_type_number_t old_stateCnt, - thread_state_t new_state, - mach_msg_type_number_t *new_stateCnt) -{ -#if defined(__DYNAMIC__) - static int checkForFunction = 0; - /* This will be non-zero if the user has defined this function */ - static kern_return_t (*func)(mach_port_t, exception_type_t, exception_data_t, mach_msg_type_number_t, int *, thread_state_t, mach_msg_type_number_t, thread_state_t, mach_msg_type_number_t *); - if (checkForFunction == 0) { - checkForFunction = 1; - _dyld_lookup_and_bind("_catch_exception_raise_state", (unsigned long *)&func, (void **)0); - } - if (func == 0) { - /* The user hasn't defined catch_exception_raise in their binary */ - abort(); - } - return (*func)(exception_port, exception, code, codeCnt, flavor, old_state, old_stateCnt, new_state, new_stateCnt); -#else - extern kern_return_t catch_exception_raise_state(mach_port_t, exception_type_t, exception_data_t, mach_msg_type_number_t, int *, thread_state_t, mach_msg_type_number_t, thread_state_t, mach_msg_type_number_t *); - return catch_exception_raise_state(exception_port, exception, code, codeCnt, flavor, old_state, old_stateCnt, new_state, new_stateCnt); -#endif -} diff --git a/mach.subproj/exc_catcher_state_identity.c b/mach.subproj/exc_catcher_state_identity.c deleted file mode 100644 index ac2ea37..0000000 --- a/mach.subproj/exc_catcher_state_identity.c +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * catch_exception_raise_state_identity will be implemented by user programs - * This implementation is provided to resolve the reference in - * exc_server(). - */ - -#include -#include -#include -#include -#include - -__private_extern__ kern_return_t internal_catch_exception_raise_state_identity ( - mach_port_t exception_port, - mach_port_t thread, - mach_port_t task, - exception_type_t exception, - exception_data_t code, - mach_msg_type_number_t codeCnt, - int *flavor, - thread_state_t old_state, - mach_msg_type_number_t old_stateCnt, - thread_state_t new_state, - mach_msg_type_number_t *new_stateCnt) -{ -#if defined(__DYNAMIC__) - static int checkForFunction = 0; - /* This will be non-zero if the user has defined this function */ - static kern_return_t (*func)(mach_port_t, mach_port_t, mach_port_t, exception_type_t, exception_data_t, mach_msg_type_number_t, int *, thread_state_t, mach_msg_type_number_t, thread_state_t, mach_msg_type_number_t *); - if (checkForFunction == 0) { - checkForFunction = 1; - _dyld_lookup_and_bind("_catch_exception_raise_state_identity", (unsigned long *)&func, (void **)0); - } - if (func == 0) { - /* The user hasn't defined catch_exception_raise in their binary */ - abort(); - } - return (*func)(exception_port, thread, task, exception, code, codeCnt, flavor, old_state, old_stateCnt, new_state, new_stateCnt); -#else - extern kern_return_t catch_exception_raise_state_identity(mach_port_t, mach_port_t, mach_port_t, exception_type_t, exception_data_t, mach_msg_type_number_t, int *, thread_state_t, mach_msg_type_number_t, thread_state_t, mach_msg_type_number_t *); - return catch_exception_raise_state_identity(exception_port, thread, task, exception, code, codeCnt, flavor, old_state, old_stateCnt, new_state, new_stateCnt); -#endif -} diff --git a/mach.subproj/externs.h b/mach.subproj/externs.h deleted file mode 100644 index 0110179..0000000 --- a/mach.subproj/externs.h +++ /dev/null @@ -1,15 +0,0 @@ -/* - * @OSF_COPYRIGHT@ - */ - -#include -#include -#include -#include - -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); - -extern char *mach_error_string_int(mach_error_t, boolean_t *); diff --git a/mach.subproj/fprintf_stderr.c b/mach.subproj/fprintf_stderr.c deleted file mode 100644 index a2f70f7..0000000 --- a/mach.subproj/fprintf_stderr.c +++ /dev/null @@ -1,35 +0,0 @@ -/* - * @OSF_FREE_COPYRIGHT@ - * - */ - -#include -#include -#include -#include - -int (*vprintf_stderr_func)(const char *format, va_list ap); - - -/* This function allows the writing of a mach error message to an - * application-controllable output method, the default being to - * use printf if no other method is specified by the application. - * - * To override, set the global (static) function pointer vprintf_stderr to - * a function which takes the same parameters as vprintf. - */ - -int fprintf_stderr(const char *format, ...) -{ - va_list args; - int retval; - - va_start(args, format); - if (vprintf_stderr_func == NULL) - retval = vprintf(format, args); - else - retval = (*vprintf_stderr_func)(format, args); - va_end(args); - - return retval; -} diff --git a/mach.subproj/headers.subproj/Makefile b/mach.subproj/headers.subproj/Makefile deleted file mode 100644 index f82584e..0000000 --- a/mach.subproj/headers.subproj/Makefile +++ /dev/null @@ -1,53 +0,0 @@ -# -# Generated by the Apple Project Builder. -# -# NOTE: Do NOT change this file -- Project Builder maintains it. -# -# Put all of your customizations in files called Makefile.preamble -# and Makefile.postamble (both optional), and Makefile will include them. -# - -NAME = headers - -PROJECTVERSION = 2.8 -PROJECT_TYPE = Component - -HFILES = errorlib.h mach.h mach_error.h mach_init.h mach_interface.h\ - mig_errors.h port_obj.h sync.h vm_task.h - -OTHERSRCS = Makefile.preamble Makefile Makefile.postamble - -MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles -CODE_GEN_STYLE = DYNAMIC -MAKEFILE = subproj.make -NEXTSTEP_INSTALLDIR = /Local/Developer/System -LIBS = -DEBUG_LIBS = $(LIBS) -PROF_LIBS = $(LIBS) - - -PUBLIC_HEADERS = errorlib.h mach.h mach_error.h mach_init.h\ - mig_errors.h port_obj.h mach_interface.h sync.h - - - -NEXTSTEP_BUILD_OUTPUT_DIR = /Local/Public/Sandbox/$(USER)/BUILD/$(NAME) - -NEXTSTEP_PUBLIC_HEADERS_DIR = /usr/include - -NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc -WINDOWS_OBJCPLUS_COMPILER = $(DEVDIR)/gcc -PDO_UNIX_OBJCPLUS_COMPILER = $(NEXTDEV_BIN)/gcc -NEXTSTEP_JAVA_COMPILER = /usr/bin/javac -WINDOWS_JAVA_COMPILER = $(JDKBINDIR)/javac.exe -PDO_UNIX_JAVA_COMPILER = $(JDKBINDIR)/javac - -include $(MAKEFILEDIR)/platform.make - --include Makefile.preamble - -include $(MAKEFILEDIR)/$(MAKEFILE) - --include Makefile.postamble - --include Makefile.dependencies diff --git a/mach.subproj/headers.subproj/Makefile.postamble b/mach.subproj/headers.subproj/Makefile.postamble deleted file mode 100644 index 411cde6..0000000 --- a/mach.subproj/headers.subproj/Makefile.postamble +++ /dev/null @@ -1,100 +0,0 @@ -############################################################################### -# Makefile.postamble -# Copyright 1997, Apple Computer, Inc. -# -# Use this makefile, which is imported after all other makefiles, to -# override attributes for a project's Makefile environment. This allows you -# to take advantage of the environment set up by the other Makefiles. -# You can also define custom rules at the end of this file. -# -############################################################################### -# -# These variables are exported by the standard makefiles and can be -# used in any customizations you make. They are *outputs* of -# the Makefiles and should be used, not set. -# -# PRODUCTS: products to install. All of these products will be placed in -# the directory $(DSTROOT)$(INSTALLDIR) -# GLOBAL_RESOURCE_DIR: The directory to which resources are copied. -# LOCAL_RESOURCE_DIR: The directory to which localized resources are copied. -# OFILE_DIR: Directory into which .o object files are generated. -# DERIVED_SRC_DIR: Directory used for all other derived files -# -# ALL_CFLAGS: flags to pass when compiling .c files -# ALL_MFLAGS: flags to pass when compiling .m files -# ALL_CCFLAGS: flags to pass when compiling .cc, .cxx, and .C files -# ALL_MMFLAGS: flags to pass when compiling .mm, .mxx, and .M files -# ALL_PRECOMPFLAGS: flags to pass when precompiling .h files -# ALL_LDFLAGS: flags to pass when linking object files -# ALL_LIBTOOL_FLAGS: flags to pass when libtooling object files -# ALL_PSWFLAGS: flags to pass when processing .psw and .pswm (pswrap) files -# ALL_RPCFLAGS: flags to pass when processing .rpc (rpcgen) files -# ALL_YFLAGS: flags to pass when processing .y (yacc) files -# ALL_LFLAGS: flags to pass when processing .l (lex) files -# -# NAME: name of application, bundle, subproject, palette, etc. -# LANGUAGES: langages in which the project is written (default "English") -# English_RESOURCES: localized resources (e.g. nib's, images) of project -# GLOBAL_RESOURCES: non-localized resources of project -# -# SRCROOT: base directory in which to place the new source files -# SRCPATH: relative path from SRCROOT to present subdirectory -# -# INSTALLDIR: Directory the product will be installed into by 'install' target -# PUBLIC_HDR_INSTALLDIR: where to install public headers. Don't forget -# to prefix this with DSTROOT when you use it. -# PRIVATE_HDR_INSTALLDIR: where to install private headers. Don't forget -# to prefix this with DSTROOT when you use it. -# -# EXECUTABLE_EXT: Executable extension for the platform (i.e. .exe on Windows) -# -############################################################################### - -# Some compiler flags can be overridden here for certain build situations. -# -# WARNING_CFLAGS: flag used to set warning level (defaults to -Wmost) -# DEBUG_SYMBOLS_CFLAGS: debug-symbol flag passed to all builds (defaults -# to -g) -# DEBUG_BUILD_CFLAGS: flags passed during debug builds (defaults to -DDEBUG) -# OPTIMIZE_BUILD_CFLAGS: flags passed during optimized builds (defaults -# to -O) -# PROFILE_BUILD_CFLAGS: flags passed during profile builds (defaults -# to -pg -DPROFILE) -# LOCAL_DIR_INCLUDE_DIRECTIVE: flag used to add current directory to -# the include path (defaults to -I.) -# DEBUG_BUILD_LDFLAGS, OPTIMIZE_BUILD_LDFLAGS, PROFILE_BUILD_LDFLAGS: flags -# passed to ld/libtool (defaults to nothing) - - -# Library and Framework projects only: -# INSTALL_NAME_DIRECTIVE: This directive ensures that executables linked -# against the framework will run against the correct version even if -# the current version of the framework changes. You may override this -# to "" as an alternative to using the DYLD_LIBRARY_PATH during your -# development cycle, but be sure to restore it before installing. - - -# Ownership and permissions of files installed by 'install' target - -#INSTALL_AS_USER = root - # User/group ownership -#INSTALL_AS_GROUP = wheel - # (probably want to set both of these) -#INSTALL_PERMISSIONS = - # If set, 'install' chmod's executable to this - - -# Options to strip. Note: -S strips debugging symbols (executables can be stripped -# down further with -x or, if they load no bundles, with no options at all). - -#STRIPFLAGS = -S - - -######################################################################### -# Put rules to extend the behavior of the standard Makefiles here. Include them in -# the dependency tree via cvariables like AFTER_INSTALL in the Makefile.preamble. -# -# You should avoid redefining things like "install" or "app", as they are -# owned by the top-level Makefile API and no context has been set up for where -# derived files should go. -# diff --git a/mach.subproj/headers.subproj/Makefile.preamble b/mach.subproj/headers.subproj/Makefile.preamble deleted file mode 100644 index 817860a..0000000 --- a/mach.subproj/headers.subproj/Makefile.preamble +++ /dev/null @@ -1 +0,0 @@ -PUBLIC_HEADER_DIR_SUFFIX = /mach diff --git a/mach.subproj/headers.subproj/PB.project b/mach.subproj/headers.subproj/PB.project deleted file mode 100644 index 7448712..0000000 --- a/mach.subproj/headers.subproj/PB.project +++ /dev/null @@ -1,45 +0,0 @@ -{ - DYNAMIC_CODE_GEN = YES; - FILESTABLE = { - H_FILES = ( - errorlib.h, - mach.h, - mach_error.h, - mach_init.h, - mach_interface.h, - mig_errors.h, - port_obj.h, - sync.h, - vm_task.h - ); - OTHER_SOURCES = (Makefile.preamble, Makefile, Makefile.postamble); - PUBLIC_HEADERS = ( - errorlib.h, - mach.h, - mach_error.h, - mach_init.h, - mig_errors.h, - port_obj.h, - mach_interface.h, - sync.h - ); - SUBPROJECTS = (); - }; - LANGUAGE = English; - MAKEFILEDIR = "$(MAKEFILEPATH)/pb_makefiles"; - NEXTSTEP_BUILDDIR = "/Local/Public/Sandbox/$(USER)/BUILD/$(NAME)"; - NEXTSTEP_BUILDTOOL = /bin/gnumake; - NEXTSTEP_INSTALLDIR = /Local/Developer/System; - NEXTSTEP_JAVA_COMPILER = /usr/bin/javac; - NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc; - NEXTSTEP_PUBLICHEADERSDIR = /usr/include; - PDO_UNIX_BUILDTOOL = $NEXT_ROOT/Developer/bin/make; - PDO_UNIX_JAVA_COMPILER = "$(JDKBINDIR)/javac"; - PDO_UNIX_OBJCPLUS_COMPILER = "$(NEXTDEV_BIN)/gcc"; - PROJECTNAME = headers; - PROJECTTYPE = Component; - PROJECTVERSION = 2.8; - WINDOWS_BUILDTOOL = $NEXT_ROOT/Developer/Executables/make; - WINDOWS_JAVA_COMPILER = "$(JDKBINDIR)/javac.exe"; - WINDOWS_OBJCPLUS_COMPILER = "$(DEVDIR)/gcc"; -} diff --git a/mach.subproj/headers.subproj/errorlib.h b/mach.subproj/headers.subproj/errorlib.h deleted file mode 100644 index aa270da..0000000 --- a/mach.subproj/headers.subproj/errorlib.h +++ /dev/null @@ -1,70 +0,0 @@ -/* - * @OSF_COPYRIGHT@ - */ - -/* - * Mach Operating System - * Copyright (c) 1991,1990,1989 Carnegie Mellon University - * All Rights Reserved. - * - * Permission to use, copy, modify and distribute this software and its - * documentation is hereby granted, provided that both the copyright - * notice and this permission notice appear in all copies of the - * software, derivative works or modified versions, and any portions - * thereof, and that both notices appear in supporting documentation. - * - * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS - * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR - * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. - * - * Carnegie Mellon requests users of this software to return to - * - * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU - * School of Computer Science - * Carnegie Mellon University - * Pittsburgh PA 15213-3890 - * - * any improvements or extensions that they make and grant Carnegie the - * rights to redistribute these changes. - */ - -/* - * File: errorlib.h - * Author: Douglas Orr, Carnegie Mellon University - * Date: Mar. 1988 - * - * Error bases for subsytems errors. - */ - -#include - -#define MACH_IPC_SEND_MOD (err_mach_ipc|err_sub(0)) -#define MACH_IPC_RCV_MOD (err_mach_ipc|err_sub(1)) -#define MACH_IPC_MIG_MOD (err_mach_ipc|err_sub(2)) - -#define IPC_SEND_MOD (err_ipc|err_sub(0)) -#define IPC_RCV_MOD (err_ipc|err_sub(1)) -#define IPC_MIG_MOD (err_ipc|err_sub(2)) - -#define SERV_NETNAME_MOD (err_server|err_sub(0)) -#define SERV_ENV_MOD (err_server|err_sub(1)) -#define SERV_EXECD_MOD (err_server|err_sub(2)) - - -#define NO_SUCH_ERROR "unknown error code" - -struct error_subsystem { - char * subsys_name; - int max_code; - char * * codes; -}; - -struct error_system { - int max_sub; - char * bad_sub; - struct error_subsystem * subsystem; -}; - -extern struct error_system errors[err_max_system+1]; - -#define errlib_count(s) (sizeof(s)/sizeof(s[0])) diff --git a/mach.subproj/headers.subproj/mach.h b/mach.subproj/headers.subproj/mach.h deleted file mode 100644 index 9fa02f3..0000000 --- a/mach.subproj/headers.subproj/mach.h +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Mach Operating System - * Copyright (c) 1991,1990,1989 Carnegie Mellon University - * All Rights Reserved. - * - * Permission to use, copy, modify and distribute this software and its - * documentation is hereby granted, provided that both the copyright - * notice and this permission notice appear in all copies of the - * software, derivative works or modified versions, and any portions - * thereof, and that both notices appear in supporting documentation. - * - * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" - * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR - * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. - * - * Carnegie Mellon requests users of this software to return to - * - * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU - * School of Computer Science - * Carnegie Mellon University - * Pittsburgh PA 15213-3890 - * - * any improvements or extensions that they make and grant Carnegie Mellon - * the rights to redistribute these changes. - */ - -/* - * Includes all the types that a normal user - * of Mach programs should need - */ - -#ifndef _MACH_H_ -#define _MACH_H_ - -#define __MACH30__ -#define MACH_IPC_FLAVOR UNTYPED - -#include -#include -#include -#include -#include -#include -/* - * Standard prototypes - */ -extern void panic_init(mach_port_t); -extern void panic(const char *, ...); - -extern void safe_gets(char *, - char *, - int); - -extern void slot_name(cpu_type_t, - cpu_subtype_t, - char **, - char **); - -extern void mig_reply_setup(mach_msg_header_t *, - mach_msg_header_t *); - -extern void mach_msg_destroy(mach_msg_header_t *); - -extern mach_msg_return_t mach_msg_receive(mach_msg_header_t *); - -extern mach_msg_return_t mach_msg_send(mach_msg_header_t *); - -extern mach_msg_return_t mach_msg_server_once(boolean_t (*) - (mach_msg_header_t *, - mach_msg_header_t *), - mach_msg_size_t, - mach_port_t, - mach_msg_options_t); -extern mach_msg_return_t mach_msg_server(boolean_t (*) - (mach_msg_header_t *, - mach_msg_header_t *), - mach_msg_size_t, - mach_port_t, - mach_msg_options_t); - -#ifdef MACH_KERNEL -extern void *sbrk(int); - -extern int brk(void *); - -#endif -/* - * Prototypes for compatibility - */ -extern kern_return_t clock_get_res(mach_port_t, - clock_res_t *); -extern kern_return_t clock_set_res(mach_port_t, - clock_res_t); - -extern kern_return_t clock_sleep(mach_port_t, - int, - mach_timespec_t, - mach_timespec_t *); -#endif /* _MACH_H_ */ diff --git a/mach.subproj/headers.subproj/mach_error.h b/mach.subproj/headers.subproj/mach_error.h deleted file mode 100644 index b60fcf9..0000000 --- a/mach.subproj/headers.subproj/mach_error.h +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Mach Operating System - * Copyright (c) 1991,1990,1989 Carnegie Mellon University - * All Rights Reserved. - * - * Permission to use, copy, modify and distribute this software and its - * documentation is hereby granted, provided that both the copyright - * notice and this permission notice appear in all copies of the - * software, derivative works or modified versions, and any portions - * thereof, and that both notices appear in supporting documentation. - * - * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS - * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR - * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. - * - * Carnegie Mellon requests users of this software to return to - * - * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU - * School of Computer Science - * Carnegie Mellon University - * Pittsburgh PA 15213-3890 - * - * any improvements or extensions that they make and grant Carnegie the - * rights to redistribute these changes. - */ - -/* - * File: mach_error.h - * Author: Douglas Orr, Carnegie Mellon University - * Date: Mar. 1988 - * - * Definitions of routines in mach_error.c - */ - -#ifndef _MACH_ERROR_ -#define _MACH_ERROR_ 1 - -#include - -char *mach_error_string( -/* - * Returns a string appropriate to the error argument given - */ - mach_error_t error_value - ); - -void mach_error( -/* - * Prints an appropriate message on the standard error stream - */ - char *str, - mach_error_t error_value - ); - -char *mach_error_type( -/* - * Returns a string with the error system, subsystem and code - */ - mach_error_t error_value - ); - -#endif /* _MACH_ERROR_ */ diff --git a/mach.subproj/headers.subproj/mach_init.h b/mach.subproj/headers.subproj/mach_init.h deleted file mode 100644 index c9521cf..0000000 --- a/mach.subproj/headers.subproj/mach_init.h +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Mach Operating System - * Copyright (c) 1991,1990,1989,1988,1987,1986 Carnegie Mellon University - * All Rights Reserved. - * - * Permission to use, copy, modify and distribute this software and its - * documentation is hereby granted, provided that both the copyright - * notice and this permission notice appear in all copies of the - * software, derivative works or modified versions, and any portions - * thereof, and that both notices appear in supporting documentation. - * - * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" - * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR - * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. - * - * Carnegie Mellon requests users of this software to return to - * - * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU - * School of Computer Science - * Carnegie Mellon University - * Pittsburgh PA 15213-3890 - * - * any improvements or extensions that they make and grant Carnegie Mellon - * the rights to redistribute these changes. - */ - -/* - * Items provided by the Mach environment initialization. - */ - -#ifndef _MACH_INIT_ -#define _MACH_INIT_ 1 - -#include -#include - -/* - * Kernel-related ports; how a task/thread controls itself - */ - -extern mach_port_t mach_task_self_; - -extern mach_port_t mach_task_self(void); -extern mach_port_t mach_host_self(void); -extern mach_port_t mach_thread_self(void); - -#define mach_task_self() mach_task_self_ - -#define current_task() mach_task_self() - -#include -/* - * Other important ports in the Mach user environment - */ - -extern mach_port_t bootstrap_port; -extern mach_port_t name_server_port; -extern mach_port_t environment_port; -extern mach_port_t service_port; - -/* - * Where these ports occur in the "mach_ports_register" - * collection... only servers or the runtime library need know. - */ - -#define NAME_SERVER_SLOT 0 -#define ENVIRONMENT_SLOT 1 -#define SERVICE_SLOT 2 - -#define MACH_PORTS_SLOTS_USED 3 - -/* - * Globally interesting numbers. - * These macros assume vm_page_size is a power-of-2. - */ - -extern vm_size_t vm_page_size; - -#define trunc_page(x) ((x) & (~(vm_page_size - 1))) -#define round_page(x) trunc_page((x) + (vm_page_size - 1)) - -/* - * fprintf_stderr uses vprintf_stderr_func to produce - * error messages, this can be overridden by a user - * application to point to a user-specified output function - */ - -extern int (*vprintf_stderr_func)(const char *format, va_list ap); - - -#endif /* _MACH_INIT_ */ diff --git a/mach.subproj/headers.subproj/mach_interface.h b/mach.subproj/headers.subproj/mach_interface.h deleted file mode 100644 index 6373e90..0000000 --- a/mach.subproj/headers.subproj/mach_interface.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (C) Apple Computer 1998 - * ALL Rights Reserved - */ -/* - * This file represents the interfaces that used to come - * from creating the user headers from the mach.defs file. - * Because mach.defs was decomposed, this file now just - * wraps up all the new interface headers generated from - * each of the new .defs resulting from that decomposition. - */ -#ifndef _MACH_INTERFACE_H_ -#define _MACH_INTERFACE_H_ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#endif /* _MACH_INTERFACE_H_ */ diff --git a/mach.subproj/headers.subproj/mig_errors.h b/mach.subproj/headers.subproj/mig_errors.h deleted file mode 100644 index 2344e84..0000000 --- a/mach.subproj/headers.subproj/mig_errors.h +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Copyright 1996 1995 by Open Software Foundation, Inc. 1997 1996 1995 1994 1993 1992 1991 - * 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 appears in all copies and - * that both the copyright notice and this permission notice appear in - * supporting documentation. - * - * OSF DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE - * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE. - * - * IN NO EVENT SHALL OSF BE LIABLE FOR ANY SPECIAL, INDIRECT, OR - * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM - * LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT, - * NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION - * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -/* - * MkLinux - */ - -/* - * Mach Operating System - * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University - * All Rights Reserved. - * - * Permission to use, copy, modify and distribute this software and its - * documentation is hereby granted, provided that both the copyright - * notice and this permission notice appear in all copies of the - * software, derivative works or modified versions, and any portions - * thereof, and that both notices appear in supporting documentation. - * - * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" - * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR - * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. - * - * Carnegie Mellon requests users of this software to return to - * - * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU - * School of Computer Science - * Carnegie Mellon University - * Pittsburgh PA 15213-3890 - * - * any improvements or extensions that they make and grant Carnegie Mellon - * the rights to redistribute these changes. - */ - -/* - * Mach Interface Generator errors - * - */ - -#ifndef _MACH_MIG_ERRORS_H_ -#define _MACH_MIG_ERRORS_H_ - -#include -#include -#include -#include - -/* - * These error codes should be specified as system 4, subsytem 2. - * But alas backwards compatibility makes that impossible. - * The problem is old clients of new servers (eg, the kernel) - * which get strange large error codes when there is a Mig problem - * in the server. Unfortunately, the IPC system doesn't have - * the knowledge to convert the codes in this situation. - */ - -#define MIG_TYPE_ERROR -300 /* client type check failure */ -#define MIG_REPLY_MISMATCH -301 /* wrong reply message ID */ -#define MIG_REMOTE_ERROR -302 /* server detected error */ -#define MIG_BAD_ID -303 /* bad request message ID */ -#define MIG_BAD_ARGUMENTS -304 /* server type check failure */ -#define MIG_NO_REPLY -305 /* no reply should be send */ -#define MIG_EXCEPTION -306 /* server raised exception */ -#define MIG_ARRAY_TOO_LARGE -307 /* array not large enough */ -#define MIG_SERVER_DIED -308 /* server died */ -#define MIG_TRAILER_ERROR -309 /* trailer has an unknown format */ - -#include - -typedef struct { - mach_msg_header_t Head; - NDR_record_t NDR; - kern_return_t RetCode; -} mig_reply_error_t; - -typedef struct mig_symtab { - char *ms_routine_name; - int ms_routine_number; - void (*ms_routine)(void); /* Since the functions in the - * symbol table have unknown - * signatures, this is the best - * we can do... - */ -} mig_symtab_t; - -/* Client side reply port allocate */ -extern mach_port_t mig_get_reply_port(void); - -/* Client side reply port deallocate */ -extern void mig_dealloc_reply_port(mach_port_t reply_port); - -/* Client side reply port "deallocation" */ -extern void mig_put_reply_port(mach_port_t reply_port); - -/* Allocate memory for out-of-stack mig structures */ -extern char *mig_user_allocate(vm_size_t size); - -/* Deallocate memory used for out-of-stack mig structures */ -extern void mig_user_deallocate(char *data, vm_size_t size); - -/* Bounded string copy */ -extern int mig_strncpy( - char *dest, - char *src, - int len); - -#endif /* _MACH_MIG_ERRORS_H_ */ diff --git a/mach.subproj/headers.subproj/port_obj.h b/mach.subproj/headers.subproj/port_obj.h deleted file mode 100644 index 796972c..0000000 --- a/mach.subproj/headers.subproj/port_obj.h +++ /dev/null @@ -1,71 +0,0 @@ -/* - * @OSF_COPYRIGHT@ - */ - -/* - * Define a service to map from a kernel-generated port name - * to server-defined "type" and "value" data to be associated - * with the port. - */ - -#ifndef PORT_OBJ_H -#define PORT_OBJ_H - -#include - -struct port_obj_tentry { - void *pos_value; - int pos_type; -}; - -extern void port_obj_init(int); -extern struct port_obj_tentry *port_obj_table; -extern int port_obj_table_size; - -#ifndef PORT_OBJ_ASSERT - -#define port_set_obj_value_type(pname, value, type) \ -do { \ - int ndx; \ - \ - if (!port_obj_table) \ - port_obj_init(port_obj_table_size); \ - ndx = MACH_PORT_INDEX(pname); \ - port_obj_table[ndx].pos_value = (value); \ - port_obj_table[ndx].pos_type = (type); \ -} while (0) - -#define port_get_obj_value(pname) \ - (port_obj_table[MACH_PORT_INDEX(pname)].pos_value) - -#define port_get_obj_type(pname) \ - (port_obj_table[MACH_PORT_INDEX(pname)].pos_type) - -#else /* PORT_OBJ_ASSERT */ - -#define port_set_obj_value_type(pname, value, type) \ -do { \ - int ndx; \ - \ - if (!port_obj_table) \ - port_obj_init(port_obj_table_size); \ - ndx = MACH_PORT_INDEX(pname); \ - assert(ndx > 0); \ - assert(ndx < port_obj_table_size); \ - port_obj_table[ndx].pos_value = (value); \ - port_obj_table[ndx].pos_type = (type); \ -} while (0) - -#define port_get_obj_value(pname) \ - ((MACH_PORT_INDEX(pname) < (unsigned)port_obj_table_size) ? \ - port_obj_table[MACH_PORT_INDEX(pname)].pos_value : \ - (panic("port_get_obj_value: index too big"), (void *)-1)) - -#define port_get_obj_type(pname) \ - ((MACH_PORT_INDEX(pname) < (unsigned)port_obj_table_size) ? \ - port_obj_table[MACH_PORT_INDEX(pname)].pos_type : \ - (panic("port_get_obj_type: index too big"), -1)) - -#endif /* PORT_OBJ_ASSERT */ - -#endif /* PORT_OBJ_H */ diff --git a/mach.subproj/headers.subproj/sync.h b/mach.subproj/headers.subproj/sync.h deleted file mode 100644 index e327d10..0000000 --- a/mach.subproj/headers.subproj/sync.h +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* -** This file contains compatibilty wrapper header for things that used -** to be generated from mach/sync.defs. Now that code is split into two -** different interface generator files, so include the two resulting -** headers here. -*/ -#include -#include diff --git a/mach.subproj/headers.subproj/vm_task.h b/mach.subproj/headers.subproj/vm_task.h deleted file mode 100644 index 8ae7856..0000000 --- a/mach.subproj/headers.subproj/vm_task.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 2000 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@ - */ -/* -** This file contains compatibilty wrapper header for things that are -** generated from mach/vm_map.defs into mach/vm_map.h. -** -** This file will go away eventually - please switch. -*/ -#include diff --git a/mach.subproj/host_priv.defs b/mach.subproj/host_priv.defs deleted file mode 100644 index 060900d..0000000 --- a/mach.subproj/host_priv.defs +++ /dev/null @@ -1 +0,0 @@ -#include diff --git a/mach.subproj/host_security.defs b/mach.subproj/host_security.defs deleted file mode 100644 index 96999e5..0000000 --- a/mach.subproj/host_security.defs +++ /dev/null @@ -1 +0,0 @@ -#include diff --git a/mach.subproj/ledger.defs b/mach.subproj/ledger.defs deleted file mode 100644 index c7e9270..0000000 --- a/mach.subproj/ledger.defs +++ /dev/null @@ -1 +0,0 @@ -#include diff --git a/mach.subproj/lock_set.defs b/mach.subproj/lock_set.defs deleted file mode 100644 index c62bb42..0000000 --- a/mach.subproj/lock_set.defs +++ /dev/null @@ -1 +0,0 @@ -#include diff --git a/mach.subproj/mach_absolute_time.c b/mach.subproj/mach_absolute_time.c deleted file mode 100644 index 04491ef..0000000 --- a/mach.subproj/mach_absolute_time.c +++ /dev/null @@ -1,19 +0,0 @@ -#include -#include - -extern mach_port_t clock_port; - -uint64_t mach_absolute_time(void) { -#if defined(__ppc__) - __asm__ volatile("0: mftbu r3"); - __asm__ volatile("mftb r4"); - __asm__ volatile("mftbu r0"); - __asm__ volatile("cmpw r0,r3"); - __asm__ volatile("bne- 0b"); -#else - mach_timespec_t now; - (void)clock_get_time(clock_port, &now); - return (uint64_t)now.tv_sec * NSEC_PER_SEC + now.tv_nsec; -#endif -} - diff --git a/mach.subproj/mach_error.c b/mach.subproj/mach_error.c deleted file mode 100644 index df35b48..0000000 --- a/mach.subproj/mach_error.c +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Mach Operating System - * Copyright (c) 1991,1990,1989 Carnegie Mellon University - * All Rights Reserved. - * - * Permission to use, copy, modify and distribute this software and its - * documentation is hereby granted, provided that both the copyright - * notice and this permission notice appear in all copies of the - * software, derivative works or modified versions, and any portions - * thereof, and that both notices appear in supporting documentation. - * - * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" - * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR - * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. - * - * Carnegie Mellon requests users of this software to return to - * - * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU - * School of Computer Science - * Carnegie Mellon University - * Pittsburgh PA 15213-3890 - * - * any improvements or extensions that they make and grant Carnegie Mellon - * the rights to redistribute these changes. - */ - -/* - * File: mach_error.c - * Author: Douglas Orr, Carnegie Mellon University - * Date: Mar 1988 - * - * interprets structured mach error codes and prints - * or returns a descriptive string. - */ - -#include -#include -#include -#include "externs.h" - -void -mach_error( str, err ) - char *str; - mach_error_t err; -{ - char * err_str; - char buf[1024]; - boolean_t diag; - - err_str=mach_error_string_int(err, &diag); - - if ( diag ) { - sprintf( buf, "%s %s (%x)", mach_error_type(err), err_str, err ); - err_str = buf; - } - - fprintf_stderr("%s %s\n", str, err_str); -} diff --git a/mach.subproj/mach_error_string.c b/mach.subproj/mach_error_string.c deleted file mode 100644 index 846d2b8..0000000 --- a/mach.subproj/mach_error_string.c +++ /dev/null @@ -1,112 +0,0 @@ -/* - * @OSF_COPYRIGHT@ - */ -/* - * Mach Operating System - * Copyright (c) 1991,1990,1989 Carnegie Mellon University - * All Rights Reserved. - * - * Permission to use, copy, modify and distribute this software and its - * documentation is hereby granted, provided that both the copyright - * notice and this permission notice appear in all copies of the - * software, derivative works or modified versions, and any portions - * thereof, and that both notices appear in supporting documentation. - * - * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" - * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR - * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. - * - * Carnegie Mellon requests users of this software to return to - * - * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU - * School of Computer Science - * Carnegie Mellon University - * Pittsburgh PA 15213-3890 - * - * any improvements or extensions that they make and grant Carnegie Mellon - * the rights to redistribute these changes. - */ - -#include -#include -#include -#include -#include "externs.h" - -static void do_compat(mach_error_t *); - -static void -do_compat(mach_error_t *org_err) -{ - mach_error_t err = *org_err; - - /* - * map old error numbers to - * to new error sys & subsystem - */ - - if ((-200 < err) && (err <= -100)) - err = -(err + 100) | IPC_SEND_MOD; - else if ((-300 < err) && (err <= -200)) - err = -(err + 200) | IPC_RCV_MOD; - else if ((-400 < err) && (err <= -300)) - err = -(err + 300) | MACH_IPC_MIG_MOD; - else if ((1000 <= err) && (err < 1100)) - err = (err - 1000) | SERV_NETNAME_MOD; - else if ((1600 <= err) && (err < 1700)) - err = (err - 1600) | SERV_ENV_MOD; - else if ((27600 <= err) && (err < 27700)) - err = (err - 27600) | SERV_EXECD_MOD; - - *org_err = err; -} - -char * -mach_error_type(mach_error_t err) -{ - int sub, system; - - do_compat( &err ); - - sub = err_get_sub(err); - system = err_get_system(err); - - if (system > err_max_system || sub >= errors[system].max_sub) - return((char *)"(?/?)"); - return(errors[system].subsystem[sub].subsys_name); -} - -boolean_t mach_error_full_diag = FALSE; - -char * -mach_error_string_int(mach_error_t err, boolean_t *diag) -{ - int sub, system, code; - - do_compat( &err ); - - sub = err_get_sub(err); - system = err_get_system(err); - code = err_get_code(err); - - *diag = TRUE; - - if (system > err_max_system) - return((char *)"(?/?) unknown error system"); - if (sub >= errors[system].max_sub) - return(errors[system].bad_sub); - if (code >= errors[system].subsystem[sub].max_code) - return ((char *)NO_SUCH_ERROR); - - *diag = mach_error_full_diag; - return( errors[system].subsystem[sub].codes[code] ); -} - -char * -mach_error_string(mach_error_t err) -{ - boolean_t diag; - - return mach_error_string_int( err, &diag ); - -} diff --git a/mach.subproj/mach_host.defs b/mach.subproj/mach_host.defs deleted file mode 100644 index e3d6c22..0000000 --- a/mach.subproj/mach_host.defs +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include diff --git a/mach.subproj/mach_init.c b/mach.subproj/mach_init.c deleted file mode 100644 index 2d3bd9c..0000000 --- a/mach.subproj/mach_init.c +++ /dev/null @@ -1,219 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Mach Operating System - * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University - * All Rights Reserved. - * - * Permission to use, copy, modify and distribute this software and its - * documentation is hereby granted, provided that both the copyright - * notice and this permission notice appear in all copies of the - * software, derivative works or modified versions, and any portions - * thereof, and that both notices appear in supporting documentation. - * - * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" - * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR - * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. - * - * Carnegie Mellon requests users of this software to return to - * - * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU - * School of Computer Science - * Carnegie Mellon University - * Pittsburgh PA 15213-3890 - * - * any improvements or extensions that they make and grant Carnegie Mellon - * the rights to redistribute these changes. - */ - -#include -#include -#include -#include -#include -#include -#include "externs.h" - -mach_port_t mach_task_self_ = MACH_PORT_NULL; -mach_port_t mach_host_self_ = MACH_PORT_NULL; -kern_return_t _host_semaphore_traps_return_ = KERN_SUCCESS; - -vm_size_t vm_page_size; - -/* - * Forward internal declarations for automatic mach_init during - * fork() implementation. - */ -/* fork() calls through atfork_child_routine */ -void (*_atfork_child_routine)(void); - -static void mach_atfork_child_routine(void); -static boolean_t first = TRUE; -static void (*previous_atfork_child_routine)(void); -extern int mach_init(void); -extern void _pthread_set_self(void *); -extern void cthread_set_self(void *); - - -static void mach_atfork_child_routine(void) -{ - /* - * If an (*_atfork_child_routine)() was registered when - * mach_init was first called, then call that routine - * prior to performing our re-initialization. This ensures - * that the post-fork handlers are called in exactly the - * same order as the crt0 (exec) handlers. Any library - * that makes use of the _atfork_child_routine must follow - * the same technique. - */ - if (previous_atfork_child_routine) { - (*previous_atfork_child_routine)(); - } - mach_init(); -} - -mach_port_t -mach_host_self() -{ - return(host_self_trap()); -} - -int mach_init_doit(int forkchild) -{ - mach_msg_type_number_t host_info_size = 0; - - /* - * Get the important ports into the cached values, - * as required by "mach_init.h". - */ - - mach_task_self_ = task_self_trap(); - mach_host_self_ = host_self_trap(); - - - if (!forkchild) { - /* - * Set up the post-fork child handler in the libc stub - * to invoke this routine if this process forks. Save the - * previous value in order that we can call that handler - * prior to performing our postfork work. - */ - - first = FALSE; - previous_atfork_child_routine = _atfork_child_routine; - _atfork_child_routine = mach_atfork_child_routine; - _pthread_set_self(0); - cthread_set_self(0); - } - - /* - * Initialize the single mig reply port - */ - - mig_init(0); - - /* - * Cache some other valuable system constants - */ - _host_semaphore_traps_return_ = host_info(mach_host_self_, - HOST_SEMAPHORE_TRAPS, - 0, - &host_info_size); - - (void)host_page_size(mach_host_self_, &vm_page_size); - - mach_init_ports(); - -#if WE_REALLY_NEED_THIS_GDB_HACK - /* - * Check to see if GDB wants us to stop - */ - { - task_user_data_data_t user_data; - mach_msg_type_number_t user_data_count = TASK_USER_DATA_COUNT; - - user_data.user_data = 0; - (void)task_info(mach_task_self_, TASK_USER_DATA, - (task_info_t)&user_data, &user_data_count); -#define MACH_GDB_RUN_MAGIC_NUMBER 1 -#ifdef MACH_GDB_RUN_MAGIC_NUMBER - /* This magic number is set in mach-aware gdb - * for RUN command to allow us to suspend user's - * executable (linked with this libmach!) - * with the code below. - * This hack should disappear when gdb improves. - */ - if ((int)user_data.user_data == MACH_GDB_RUN_MAGIC_NUMBER) { - kern_return_t ret; - user_data.user_data = 0; - - ret = task_suspend (mach_task_self_); - if (ret != KERN_SUCCESS) { - while(1) (void)task_terminate(mach_task_self_); - } - } -#undef MACH_GDB_RUN_MAGIC_NUMBER -#endif /* MACH_GDB_RUN_MAGIC_NUMBER */ - } -#endif /* WE_REALLY_NEED_THIS_GDB_HACK */ - - /* - * Reserve page 0 so that the program doesn't get it as - * the result of a vm_allocate() or whatever. - */ - { - vm_offset_t zero_page_start; - - zero_page_start = 0; - (void)vm_map(mach_task_self_, &zero_page_start, vm_page_size, - 0, FALSE, MEMORY_OBJECT_NULL, 0, TRUE, - VM_PROT_NONE, VM_PROT_NONE, VM_INHERIT_COPY); - /* ignore result, we don't care if it failed */ - } - return(0); -} - -int mach_init(void) -{ - return(mach_init_doit(0)); -} - -int (*mach_init_routine)(void) = mach_init; -int fork_mach_init() -{ - /* called only from child */ - return(mach_init_doit(1)); -} - -#undef mach_task_self - -mach_port_t -mach_task_self() -{ - return(task_self_trap()); -} - -mach_port_t -mach_thread_self() -{ - return(thread_self_trap()); -} diff --git a/mach.subproj/mach_init_ports.c b/mach.subproj/mach_init_ports.c deleted file mode 100644 index 8853ef7..0000000 --- a/mach.subproj/mach_init_ports.c +++ /dev/null @@ -1,105 +0,0 @@ -/* - * @OSF_COPYRIGHT@ - */ - -/* - * Mach Operating System - * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University - * All Rights Reserved. - * - * Permission to use, copy, modify and distribute this software and its - * documentation is hereby granted, provided that both the copyright - * notice and this permission notice appear in all copies of the - * software, derivative works or modified versions, and any portions - * thereof, and that both notices appear in supporting documentation. - * - * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" - * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR - * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. - * - * Carnegie Mellon requests users of this software to return to - * - * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU - * School of Computer Science - * Carnegie Mellon University - * Pittsburgh PA 15213-3890 - * - * any improvements or extensions that they make and grant Carnegie Mellon - * the rights to redistribute these changes. - */ - -#include -#include "externs.h" - -mach_port_t bootstrap_port = MACH_PORT_NULL; -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; -mach_port_t clock_port = MACH_PORT_NULL; -mach_port_t thread_recycle_port = MACH_PORT_NULL; - -void -mach_init_ports(void) -{ - mach_port_array_t ports; - mach_msg_type_number_t ports_count; - kern_return_t kr; - - /* - * Find those ports important to every task. - */ - kr = task_get_special_port(mach_task_self(), - TASK_BOOTSTRAP_PORT, - &bootstrap_port); - if (kr != KERN_SUCCESS) - return; - - kr = mach_ports_lookup(mach_task_self(), &ports, - &ports_count); - if ((kr != KERN_SUCCESS) || - (ports_count < MACH_PORTS_SLOTS_USED)) - return; - - name_server_port = ports[NAME_SERVER_SLOT]; - environment_port = ports[ENVIRONMENT_SLOT]; - service_port = ports[SERVICE_SLOT]; - - /* get rid of out-of-line data so brk has a chance of working */ - - (void) vm_deallocate(mach_task_self(), - (vm_offset_t) ports, - (vm_size_t) (ports_count * sizeof *ports)); - - /* Get the clock service port for nanosleep */ - kr = host_get_clock_service(mach_host_self(), SYSTEM_CLOCK, &clock_port); - if (kr != KERN_SUCCESS) { - abort(); - } - kr = mach_port_allocate(mach_task_self(), MACH_PORT_RIGHT_RECEIVE, &thread_recycle_port); - if (kr != KERN_SUCCESS) { - abort(); - } - kr = mach_port_insert_right(mach_task_self(), thread_recycle_port, thread_recycle_port, MACH_MSG_TYPE_MAKE_SEND); - if (kr != KERN_SUCCESS) { - abort(); - } -} - -#ifdef notdef -/* will have problems with dylib build --> not needed anyway */ -#ifndef lint -/* - * Routines which our library must suck in, to avoid - * a later library from referencing them and getting - * the wrong version. - */ -extern void _replacements(void); - -void -_replacements(void) -{ - (void)sbrk(0); /* Pull in our sbrk/brk */ - (void)malloc(0); /* Pull in our malloc package */ -} -#endif /* lint */ -#endif /* notdef */ diff --git a/mach.subproj/mach_msg.c b/mach.subproj/mach_msg.c deleted file mode 100644 index d7a1d92..0000000 --- a/mach.subproj/mach_msg.c +++ /dev/null @@ -1,148 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Mach Operating System - * Copyright (c) 1991,1990,1989 Carnegie Mellon University - * All Rights Reserved. - * - * Permission to use, copy, modify and distribute this software and its - * documentation is hereby granted, provided that both the copyright - * notice and this permission notice appear in all copies of the - * software, derivative works or modified versions, and any portions - * thereof, and that both notices appear in supporting documentation. - * - * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" - * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR - * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. - * - * Carnegie Mellon requests users of this software to return to - * - * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU - * School of Computer Science - * Carnegie Mellon University - * Pittsburgh PA 15213-3890 - * - * any improvements or extensions that they make and grant Carnegie Mellon - * the rights to redistribute these changes. - */ - -#include -#include - -#define LIBMACH_OPTIONS (MACH_SEND_INTERRUPT|MACH_RCV_INTERRUPT) - -mach_msg_return_t -mach_msg(msg, option, send_size, rcv_size, rcv_name, timeout, notify) - mach_msg_header_t *msg; - mach_msg_option_t option; - mach_msg_size_t send_size; - mach_msg_size_t rcv_size; - mach_port_t rcv_name; - mach_msg_timeout_t timeout; - mach_port_t notify; -{ - mach_msg_return_t mr; - - /* - * Consider the following cases: - * 1) Errors in pseudo-receive (eg, MACH_SEND_INTERRUPTED - * plus special bits). - * 2) Use of MACH_SEND_INTERRUPT/MACH_RCV_INTERRUPT options. - * 3) RPC calls with interruptions in one/both halves. - * - * We refrain from passing the option bits that we implement - * to the kernel. This prevents their presence from inhibiting - * the kernel's fast paths (when it checks the option value). - */ - - mr = mach_msg_overwrite_trap(msg, option &~ LIBMACH_OPTIONS, - send_size, rcv_size, rcv_name, - timeout, notify, MACH_MSG_NULL, 0); - if (mr == MACH_MSG_SUCCESS) - return MACH_MSG_SUCCESS; - - if ((option & MACH_SEND_INTERRUPT) == 0) - while (mr == MACH_SEND_INTERRUPTED) - mr = mach_msg_overwrite_trap(msg, - option &~ LIBMACH_OPTIONS, - send_size, rcv_size, rcv_name, - timeout, notify, MACH_MSG_NULL, 0); - - if ((option & MACH_RCV_INTERRUPT) == 0) - while (mr == MACH_RCV_INTERRUPTED) - mr = mach_msg_overwrite_trap(msg, - option &~ (LIBMACH_OPTIONS|MACH_SEND_MSG), - 0, rcv_size, rcv_name, - timeout, notify, MACH_MSG_NULL, 0); - - return mr; -} - -mach_msg_return_t -mach_msg_overwrite(msg, option, send_size, rcv_limit, rcv_name, timeout, - notify, rcv_msg, rcv_msg_size) - mach_msg_header_t *msg; - mach_msg_option_t option; - mach_msg_size_t send_size; - mach_msg_size_t rcv_limit; - mach_port_t rcv_name; - mach_msg_timeout_t timeout; - mach_port_t notify; - mach_msg_header_t *rcv_msg; - mach_msg_size_t rcv_msg_size; -{ - mach_msg_return_t mr; - - /* - * Consider the following cases: - * 1) Errors in pseudo-receive (eg, MACH_SEND_INTERRUPTED - * plus special bits). - * 2) Use of MACH_SEND_INTERRUPT/MACH_RCV_INTERRUPT options. - * 3) RPC calls with interruptions in one/both halves. - * - * We refrain from passing the option bits that we implement - * to the kernel. This prevents their presence from inhibiting - * the kernel's fast paths (when it checks the option value). - */ - - mr = mach_msg_overwrite_trap(msg, option &~ LIBMACH_OPTIONS, - send_size, rcv_limit, rcv_name, - timeout, notify, rcv_msg, rcv_msg_size); - if (mr == MACH_MSG_SUCCESS) - return MACH_MSG_SUCCESS; - - if ((option & MACH_SEND_INTERRUPT) == 0) - while (mr == MACH_SEND_INTERRUPTED) - mr = mach_msg_overwrite_trap(msg, - option &~ LIBMACH_OPTIONS, - send_size, rcv_limit, rcv_name, - timeout, notify, rcv_msg, rcv_msg_size); - - if ((option & MACH_RCV_INTERRUPT) == 0) - while (mr == MACH_RCV_INTERRUPTED) - mr = mach_msg_overwrite_trap(msg, - option &~ (LIBMACH_OPTIONS|MACH_SEND_MSG), - 0, rcv_limit, rcv_name, - timeout, notify, rcv_msg, rcv_msg_size); - - return mr; -} diff --git a/mach.subproj/mach_msg_destroy.c b/mach.subproj/mach_msg_destroy.c deleted file mode 100644 index 008ee99..0000000 --- a/mach.subproj/mach_msg_destroy.c +++ /dev/null @@ -1,169 +0,0 @@ -/* - * @OSF_COPYRIGHT@ - */ - -/* - * Mach Operating System - * Copyright (c) 1991,1990 Carnegie Mellon University - * All Rights Reserved. - * - * Permission to use, copy, modify and distribute this software and its - * documentation is hereby granted, provided that both the copyright - * notice and this permission notice appear in all copies of the - * software, derivative works or modified versions, and any portions - * thereof, and that both notices appear in supporting documentation. - * - * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" - * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR - * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. - * - * Carnegie Mellon requests users of this software to return to - * - * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU - * School of Computer Science - * Carnegie Mellon University - * Pittsburgh PA 15213-3890 - * - * any improvements or extensions that they make and grant Carnegie Mellon - * the rights to redistribute these changes. - */ - -#include -#include -#include - -static void mach_msg_destroy_port(mach_port_t, mach_msg_type_name_t); -static void mach_msg_destroy_memory(vm_offset_t, vm_size_t); - -/* - * Routine: mach_msg_destroy - * Purpose: - * mach_msg_destroy is useful in two contexts. - * - * First, it can deallocate all port rights and - * out-of-line memory in a received message. - * When a server receives a request it doesn't want, - * it needs this functionality. - * - * Second, it can mimic the side-effects of a msg-send - * operation. The effect is as if the message were sent - * and then destroyed inside the kernel. When a server - * can't send a reply (because the client died), - * it needs this functionality. - */ -void -mach_msg_destroy(mach_msg_header_t *msg) -{ - mach_msg_bits_t mbits = msg->msgh_bits; - - /* - * The msgh_local_port field doesn't hold a port right. - * The receive operation consumes the destination port right. - */ - - mach_msg_destroy_port(msg->msgh_remote_port, MACH_MSGH_BITS_REMOTE(mbits)); - - if (mbits & MACH_MSGH_BITS_COMPLEX) { - mach_msg_body_t *body; - mach_msg_descriptor_t *saddr, *eaddr; - - body = (mach_msg_body_t *) (msg + 1); - saddr = (mach_msg_descriptor_t *) - ((mach_msg_base_t *) msg + 1); - eaddr = saddr + body->msgh_descriptor_count; - - for ( ; saddr < eaddr; saddr++) { - switch (saddr->type.type) { - - case MACH_MSG_PORT_DESCRIPTOR: { - mach_msg_port_descriptor_t *dsc; - - /* - * Destroy port rights carried in the message - */ - dsc = &saddr->port; - mach_msg_destroy_port(dsc->name, dsc->disposition); - break; - } - - case MACH_MSG_OOL_DESCRIPTOR : { - mach_msg_ool_descriptor_t *dsc; - - /* - * Destroy memory carried in the message - */ - dsc = &saddr->out_of_line; - if (dsc->deallocate) { - mach_msg_destroy_memory((vm_offset_t)dsc->address, - dsc->size); - } - break; - } - - case MACH_MSG_OOL_PORTS_DESCRIPTOR : { - mach_port_t *ports; - mach_msg_ool_ports_descriptor_t *dsc; - mach_msg_type_number_t j; - - /* - * Destroy port rights carried in the message - */ - dsc = &saddr->ool_ports; - ports = (mach_port_t *) dsc->address; - for (j = 0; j < dsc->count; j++, ports++) { - mach_msg_destroy_port(*ports, dsc->disposition); - } - - /* - * Destroy memory carried in the message - */ - if (dsc->deallocate) { - mach_msg_destroy_memory((vm_offset_t)dsc->address, - dsc->count * sizeof(mach_port_t)); - } - break; - } - } - } - } -} - -static void -mach_msg_destroy_port(mach_port_t port, mach_msg_type_name_t type) -{ - if (MACH_PORT_VALID(port)) switch (type) { - case MACH_MSG_TYPE_MOVE_SEND: - case MACH_MSG_TYPE_MOVE_SEND_ONCE: - /* destroy the send/send-once right */ - (void) mach_port_deallocate(mach_task_self(), port); - break; - - case MACH_MSG_TYPE_MOVE_RECEIVE: - /* destroy the receive right */ - (void) mach_port_mod_refs(mach_task_self(), port, - MACH_PORT_RIGHT_RECEIVE, -1); - break; - - case MACH_MSG_TYPE_MAKE_SEND: - /* create a send right and then destroy it */ - (void) mach_port_insert_right(mach_task_self(), port, - port, MACH_MSG_TYPE_MAKE_SEND); - (void) mach_port_deallocate(mach_task_self(), port); - break; - - case MACH_MSG_TYPE_MAKE_SEND_ONCE: - /* create a send-once right and then destroy it */ - (void) mach_port_extract_right(mach_task_self(), port, - MACH_MSG_TYPE_MAKE_SEND_ONCE, - &port, &type); - (void) mach_port_deallocate(mach_task_self(), port); - break; - } -} - -static void -mach_msg_destroy_memory(vm_offset_t addr, vm_size_t size) -{ - if (size != 0) - (void) vm_deallocate(mach_task_self(), addr, size); -} diff --git a/mach.subproj/mach_msg_receive.c b/mach.subproj/mach_msg_receive.c deleted file mode 100644 index 8d7f260..0000000 --- a/mach.subproj/mach_msg_receive.c +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Mach Operating System - * Copyright (c) 1991,1990,1989 Carnegie Mellon University - * All Rights Reserved. - * - * Permission to use, copy, modify and distribute this software and its - * documentation is hereby granted, provided that both the copyright - * notice and this permission notice appear in all copies of the - * software, derivative works or modified versions, and any portions - * thereof, and that both notices appear in supporting documentation. - * - * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" - * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR - * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. - * - * Carnegie Mellon requests users of this software to return to - * - * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU - * School of Computer Science - * Carnegie Mellon University - * Pittsburgh PA 15213-3890 - * - * any improvements or extensions that they make and grant Carnegie Mellon - * the rights to redistribute these changes. - */ - -#include -#include - -mach_msg_return_t -mach_msg_receive(mach_msg_header_t *msg) -{ - return mach_msg(msg, MACH_RCV_MSG, - 0, msg->msgh_size, msg->msgh_local_port, - MACH_MSG_TIMEOUT_NONE, MACH_PORT_NULL); -} diff --git a/mach.subproj/mach_msg_send.c b/mach.subproj/mach_msg_send.c deleted file mode 100644 index 80180dd..0000000 --- a/mach.subproj/mach_msg_send.c +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Mach Operating System - * Copyright (c) 1991,1990,1989 Carnegie Mellon University - * All Rights Reserved. - * - * Permission to use, copy, modify and distribute this software and its - * documentation is hereby granted, provided that both the copyright - * notice and this permission notice appear in all copies of the - * software, derivative works or modified versions, and any portions - * thereof, and that both notices appear in supporting documentation. - * - * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" - * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR - * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. - * - * Carnegie Mellon requests users of this software to return to - * - * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU - * School of Computer Science - * Carnegie Mellon University - * Pittsburgh PA 15213-3890 - * - * any improvements or extensions that they make and grant Carnegie Mellon - * the rights to redistribute these changes. - */ - -#include -#include - -mach_msg_return_t -mach_msg_send(mach_msg_header_t *msg) -{ - return mach_msg(msg, MACH_SEND_MSG, - msg->msgh_size, 0, MACH_PORT_NULL, - MACH_MSG_TIMEOUT_NONE, MACH_PORT_NULL); -} diff --git a/mach.subproj/mach_msg_server.c b/mach.subproj/mach_msg_server.c deleted file mode 100644 index 4144c7a..0000000 --- a/mach.subproj/mach_msg_server.c +++ /dev/null @@ -1,265 +0,0 @@ -/* - * @OSF_COPYRIGHT@ - */ - -/* - * Mach Operating System - * Copyright (c) 1991,1990 Carnegie Mellon University - * All Rights Reserved. - * - * Permission to use, copy, modify and distribute this software and its - * documentation is hereby granted, provided that both the copyright - * notice and this permission notice appear in all copies of the - * software, derivative works or modified versions, and any portions - * thereof, and that both notices appear in supporting documentation. - * - * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" - * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR - * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. - * - * Carnegie Mellon requests users of this software to return to - * - * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU - * School of Computer Science - * Carnegie Mellon University - * Pittsburgh PA 15213-3890 - * - * any improvements or extensions that they make and grant Carnegie Mellon - * the rights to redistribute these changes. - */ - -#include -#include -#include -#include -#include -#include -#include - -/* - * Routine: mach_msg_server_once - * Purpose: - * A simple generic server function. It allows more flexibility - * than mach_msg_server by processing only one message request - * and then returning to the user. Note that more in the way - * of error codes are returned to the user; specifically, any - * failing error from mach_msg_overwrite_trap will be returned - * (though errors from the demux routine or the routine it calls - * will not be). - */ -mach_msg_return_t -mach_msg_server_once( - boolean_t (*demux)(mach_msg_header_t *, mach_msg_header_t *), - mach_msg_size_t max_size, - mach_port_t rcv_name, - mach_msg_options_t options) -{ - mig_reply_error_t *bufRequest = 0, *bufReply = 0, *bufTemp; - register mach_msg_return_t mr; - register kern_return_t kr; - - if ((kr = vm_allocate(mach_task_self(), - (vm_address_t *)&bufRequest, - max_size + MAX_TRAILER_SIZE, - VM_MAKE_TAG(VM_MEMORY_MACH_MSG)|TRUE)) != KERN_SUCCESS) - return kr; - if ((kr = vm_allocate(mach_task_self(), - (vm_address_t *)&bufReply, - max_size + MAX_TRAILER_SIZE, - VM_MAKE_TAG(VM_MEMORY_MACH_MSG)|TRUE)) != KERN_SUCCESS) - return kr; - - mr = mach_msg_overwrite_trap(&bufRequest->Head, MACH_RCV_MSG|options, - 0, max_size, rcv_name, - MACH_MSG_TIMEOUT_NONE, MACH_PORT_NULL, - (mach_msg_header_t *) 0, 0); - if (mr == MACH_MSG_SUCCESS) { - /* we have a request message */ - - (void) (*demux)(&bufRequest->Head, &bufReply->Head); - - if (!(bufReply->Head.msgh_bits & MACH_MSGH_BITS_COMPLEX) && - bufReply->RetCode != KERN_SUCCESS) { - if (bufReply->RetCode == MIG_NO_REPLY) - /* - * This return code is a little tricky-- - * it appears that the demux routine found an - * error of some sort, but since that error - * would not normally get returned either to - * the local user or the remote one, we pretend it's - * ok. - */ - return KERN_SUCCESS; - - /* don't destroy the reply port right, - so we can send an error message */ - bufRequest->Head.msgh_remote_port = MACH_PORT_NULL; - mach_msg_destroy(&bufRequest->Head); - } - - if (bufReply->Head.msgh_remote_port == MACH_PORT_NULL) { - /* no reply port, so destroy the reply */ - if (bufReply->Head.msgh_bits & MACH_MSGH_BITS_COMPLEX) - mach_msg_destroy(&bufReply->Head); - - return KERN_SUCCESS; - } - - /* send reply. */ - - bufTemp = bufRequest; - bufRequest = bufReply; - bufReply = bufTemp; - - /* - * We don't want to block indefinitely because the client - * isn't receiving messages from the reply port. - * If we have a send-once right for the reply port, then - * this isn't a concern because the send won't block. - * If we have a send right, we need to use MACH_SEND_TIMEOUT. - * To avoid falling off the kernel's fast RPC path unnecessarily, - * we only supply MACH_SEND_TIMEOUT when absolutely necessary. - */ - - mr = mach_msg_overwrite_trap(&bufRequest->Head, - (MACH_MSGH_BITS_REMOTE(bufRequest->Head.msgh_bits) == - MACH_MSG_TYPE_MOVE_SEND_ONCE) ? - MACH_SEND_MSG|options : - MACH_SEND_MSG|MACH_SEND_TIMEOUT|options, - bufRequest->Head.msgh_size, 0, MACH_PORT_NULL, - 0, MACH_PORT_NULL, (mach_msg_header_t *) 0, 0); - } - /* Has a message error occurred? */ - - switch (mr) { - case MACH_SEND_INVALID_DEST: - case MACH_SEND_TIMED_OUT: - /* the reply can't be delivered, so destroy it */ - mach_msg_destroy(&bufRequest->Head); - return KERN_SUCCESS; /* Matches error hiding behavior in - mach_msg_server. */ - - case MACH_RCV_TOO_LARGE: - return KERN_SUCCESS; /* Matches error hiding behavior in - mach_msg_server. */ - - default: - /* Includes success case. */ - (void)vm_deallocate(mach_task_self(), - (vm_address_t) bufRequest, - max_size + MAX_TRAILER_SIZE); - (void)vm_deallocate(mach_task_self(), - (vm_address_t) bufReply, - max_size + MAX_TRAILER_SIZE); - return mr; - } -} - -/* - * Routine: mach_msg_server - * Purpose: - * A simple generic server function. Note that changes here - * should be considered for duplication above. - */ -mach_msg_return_t -mach_msg_server( - boolean_t (*demux)(mach_msg_header_t *, mach_msg_header_t *), - mach_msg_size_t max_size, - mach_port_t rcv_name, - mach_msg_options_t options) -{ - mig_reply_error_t *bufRequest = 0, *bufReply = 0, *bufTemp; - register mach_msg_return_t mr; - register kern_return_t kr; - - if ((kr = vm_allocate(mach_task_self(), - (vm_address_t *)&bufRequest, - max_size + MAX_TRAILER_SIZE, - VM_MAKE_TAG(VM_MEMORY_MACH_MSG)|TRUE)) != KERN_SUCCESS) - return kr; - if ((kr = vm_allocate(mach_task_self(), - (vm_address_t *)&bufReply, - max_size + MAX_TRAILER_SIZE, - VM_MAKE_TAG(VM_MEMORY_MACH_MSG)|TRUE)) != KERN_SUCCESS) - return kr; - - for (;;) { - get_request: - mr = mach_msg_overwrite_trap(&bufRequest->Head, MACH_RCV_MSG|options, - 0, max_size, rcv_name, - MACH_MSG_TIMEOUT_NONE, MACH_PORT_NULL, - (mach_msg_header_t *) 0, 0); - while (mr == MACH_MSG_SUCCESS) { - /* we have a request message */ - - (void) (*demux)(&bufRequest->Head, &bufReply->Head); - - if (!(bufReply->Head.msgh_bits & MACH_MSGH_BITS_COMPLEX) && - bufReply->RetCode != KERN_SUCCESS) { - if (bufReply->RetCode == MIG_NO_REPLY) - goto get_request; - - /* don't destroy the reply port right, - so we can send an error message */ - bufRequest->Head.msgh_remote_port = MACH_PORT_NULL; - mach_msg_destroy(&bufRequest->Head); - } - - if (bufReply->Head.msgh_remote_port == MACH_PORT_NULL) { - /* no reply port, so destroy the reply */ - if (bufReply->Head.msgh_bits & MACH_MSGH_BITS_COMPLEX) - mach_msg_destroy(&bufReply->Head); - - goto get_request; - } - - /* send reply and get next request */ - - bufTemp = bufRequest; - bufRequest = bufReply; - bufReply = bufTemp; - - /* - * We don't want to block indefinitely because the client - * isn't receiving messages from the reply port. - * If we have a send-once right for the reply port, then - * this isn't a concern because the send won't block. - * If we have a send right, we need to use MACH_SEND_TIMEOUT. - * To avoid falling off the kernel's fast RPC path unnecessarily, - * we only supply MACH_SEND_TIMEOUT when absolutely necessary. - */ - - mr = mach_msg_overwrite_trap(&bufRequest->Head, - (MACH_MSGH_BITS_REMOTE(bufRequest->Head.msgh_bits) == - MACH_MSG_TYPE_MOVE_SEND_ONCE) ? - MACH_SEND_MSG|MACH_RCV_MSG|options : - MACH_SEND_MSG|MACH_SEND_TIMEOUT|MACH_RCV_MSG|options, - bufRequest->Head.msgh_size, max_size, rcv_name, - 0, MACH_PORT_NULL, (mach_msg_header_t *) 0, 0); - } - - /* a message error occurred */ - - switch (mr) { - case MACH_SEND_INVALID_DEST: - case MACH_SEND_TIMED_OUT: - /* the reply can't be delivered, so destroy it */ - mach_msg_destroy(&bufRequest->Head); - break; - - case MACH_RCV_TOO_LARGE: - /* the kernel destroyed the request */ - break; - - default: - /* should only happen if the server is buggy */ - (void)vm_deallocate(mach_task_self(), - (vm_address_t) bufRequest, - max_size + MAX_TRAILER_SIZE); - (void)vm_deallocate(mach_task_self(), - (vm_address_t) bufReply, - max_size + MAX_TRAILER_SIZE); - return mr; - } - } -} diff --git a/mach.subproj/mach_port.defs b/mach.subproj/mach_port.defs deleted file mode 100644 index 935d58f..0000000 --- a/mach.subproj/mach_port.defs +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include diff --git a/mach.subproj/mach_subsystem_join.c b/mach.subproj/mach_subsystem_join.c deleted file mode 100644 index a22504a..0000000 --- a/mach.subproj/mach_subsystem_join.c +++ /dev/null @@ -1,153 +0,0 @@ -/* - * @OSF_COPYRIGHT@ - */ - -#include /* To get NULL */ -#include -#include -#include - -#if 0 -# include -# define debug(x) printf x -#else -# define debug(x) -#endif - -/* - * Routine: mach_subsystem_join - * Purpose: - * Create a new subsystem, suitable for registering with - * mach_subsystem_create, that consists of the union of - * the routines of subsys_1 and subsys_2. - * - * Warning: - * If there is a big gap between the routine numbers of - * the two subsystems, a correspondingly large amount of - * space will be wasted in the new subsystem. - */ -rpc_subsystem_t -mach_subsystem_join(rpc_subsystem_t subsys_1, /* First input subsystem */ - rpc_subsystem_t subsys_2, /* Second input subsystem */ - unsigned int *num_bytes_p, /* Size of output subsystem */ - void *(*malloc_func)(int) /* Allocation routine to use */ - ) -{ - rpc_subsystem_t sp, subsys_new; - int num_routines, num_args, num_bytes; - int i, j; - struct routine_arg_descriptor *ap; - struct routine_descriptor *rp; - - /* Make sure the two routine number ranges do not overlap: - */ - if (subsys_1->start <= subsys_2->start && subsys_1->end > subsys_2->start - || - subsys_2->start <= subsys_1->start && subsys_2->end > subsys_1->start) - return NULL; - - /* Arrange that subsys_1 is the subsystem with the lower numbered - * routines: - */ - if (subsys_2->start < subsys_1->start || - subsys_2->end < subsys_1->end) { - /* Exchange the two input subsystem pointers: */ - sp = subsys_2; subsys_2 = subsys_1; subsys_1 = sp; - } - - debug(("subys_join: Lower subsys: (%d, %d); Higher subsys: (%d, %d)\n", - subsys_1->start, subsys_1->end, subsys_2->start, subsys_2->end)); - - /* - * Calculate size needed for new subsystem and allocate it: - */ - num_args = 0; - sp = subsys_1; - do { - int nr; - - nr = sp->end - sp->start; - num_routines += nr; - - for (rp = &sp->routine[0]; rp < &sp->routine[nr]; rp++) { - /* Make sure this routine is non-null: */ - if (rp->impl_routine != NULL) - num_args += rp->descr_count; - } - if (sp == subsys_2) - break; - sp = subsys_2; - } while (1); - num_routines = subsys_2->end - subsys_1->start; - - /* A struct rpc_subsystem, which is just a template for a real - * subsystem descriptor, has one dummy routine descriptor in it - * and one arg descriptor, so we have to subtract these out, when - * calculating room for the routine and arg arrays: - */ - num_bytes = sizeof(struct rpc_subsystem) + - (num_routines - 1) * sizeof(struct routine_descriptor) + - (num_args - 1) * sizeof(struct routine_arg_descriptor); - - debug(("subys_new: %x; #routines: %d; #args: %d; #bytes: %d\n", - subsys_new, num_routines, num_args, num_bytes)); - - subsys_new = (rpc_subsystem_t) (*malloc_func)(num_bytes); - if (subsys_new == NULL) - return NULL; - - /* Initialize the new subsystem, then copy the lower-numbered - * subsystem into the new subsystem, then the higher-numbered one: - */ - - subsys_new->subsystem = NULL; /* Reserved for system use */ - subsys_new->start = subsys_1->start; - subsys_new->end = subsys_2->end; - subsys_new->maxsize = subsys_1->maxsize > subsys_2->maxsize ? - subsys_1->maxsize : subsys_2->maxsize; - subsys_new->base_addr = (vm_address_t)subsys_new; - - /* Point ap at the beginning of the arg_descriptors for the - * joined subystem, i.e. just after the end of the combined - * array of routine descriptors: - */ - ap = (struct routine_arg_descriptor *) - &(subsys_new->routine[num_routines]); - rp = &(subsys_new->routine[0]); - - /* Copy subsys_1 into subsys_new: */ - debug(("subys_join: Copying lower subsys: rp=%x, ap=%x\n", rp, ap)); - for (i = 0; i < subsys_1->end - subsys_1->start; i++, rp++) { - *rp = subsys_1->routine[i]; - if (rp->impl_routine != NULL) { - rp->arg_descr = ap; - for (j = 0; j < rp->descr_count; j++) - *ap++ = subsys_1->routine[i].arg_descr[j]; - } else - rp->arg_descr = NULL; - } - - /* Fill in the gap, if any, between subsys_1 routine numbers - * and subsys_2 routine numbers: - */ - for (i = subsys_1->end; i < subsys_2->start; i++, rp++) { - rp->impl_routine = NULL; - rp->arg_descr = NULL; - } - - /* Copy subsys_2 into subsys_new: */ - debug(("subys_join: Copying higher subsys: rp=%x, ap=%x\n", rp, ap)); - for (i = 0; i < subsys_2->end - subsys_2->start; i++, rp++) { - *rp = subsys_2->routine[i]; - if (rp->impl_routine != NULL) { - rp->arg_descr = ap; - for (j = 0; j < rp->descr_count; j++) - *ap++ = subsys_2->routine[i].arg_descr[j]; - } else - rp->arg_descr = NULL; - } - debug(("subys_join: Done: rp=%x, ap=%x\n", rp, ap)); - - *num_bytes_p = num_bytes; - return subsys_new; -} diff --git a/mach.subproj/mach_traps.s b/mach.subproj/mach_traps.s deleted file mode 100644 index 59c9b0a..0000000 --- a/mach.subproj/mach_traps.s +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Mach Operating System - * Copyright (c) 1991,1990,1989,1988,1987,1986 Carnegie Mellon University - * All Rights Reserved. - * - * Permission to use, copy, modify and distribute this software and its - * documentation is hereby granted, provided that both the copyright - * notice and this permission notice appear in all copies of the - * software, derivative works or modified versions, and any portions - * thereof, and that both notices appear in supporting documentation. - * - * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" - * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR - * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. - * - * Carnegie Mellon requests users of this software to return to - * - * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU - * School of Computer Science - * Carnegie Mellon University - * Pittsburgh PA 15213-3890 - * - * any improvements or extensions that they make and grant Carnegie Mellon - * the rights to redistribute these changes. - */ - -#include diff --git a/mach.subproj/mig_allocate.c b/mach.subproj/mig_allocate.c deleted file mode 100644 index 38db1ac..0000000 --- a/mach.subproj/mig_allocate.c +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Mach Operating System - * Copyright (c) 1991 Carnegie Mellon University - * All Rights Reserved. - * - * Permission to use, copy, modify and distribute this software and its - * documentation is hereby granted, provided that both the copyright - * notice and this permission notice appear in all copies of the - * software, derivative works or modified versions, and any portions - * thereof, and that both notices appear in supporting documentation. - * - * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" - * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR - * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. - * - * Carnegie Mellon requests users of this software to return to - * - * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU - * School of Computer Science - * Carnegie Mellon University - * Pittsburgh PA 15213-3890 - * - * any improvements or extensions that they make and grant Carnegie Mellon - * the rights to redistribute these changes. - */ - -/* - * Memory allocation routine for MiG interfaces. - */ -#include -#include -#include "externs.h" - -void -mig_allocate(vm_address_t *addr_p, vm_size_t size) -{ - if (vm_allocate(mach_task_self(), - addr_p, - size, - VM_MAKE_TAG(VM_MEMORY_MACH_MSG)|TRUE) - != KERN_SUCCESS) - *addr_p = 0; -} diff --git a/mach.subproj/mig_deallocate.c b/mach.subproj/mig_deallocate.c deleted file mode 100644 index 5ee1c3f..0000000 --- a/mach.subproj/mig_deallocate.c +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Mach Operating System - * Copyright (c) 1991 Carnegie Mellon University - * All Rights Reserved. - * - * Permission to use, copy, modify and distribute this software and its - * documentation is hereby granted, provided that both the copyright - * notice and this permission notice appear in all copies of the - * software, derivative works or modified versions, and any portions - * thereof, and that both notices appear in supporting documentation. - * - * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" - * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR - * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. - * - * Carnegie Mellon requests users of this software to return to - * - * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU - * School of Computer Science - * Carnegie Mellon University - * Pittsburgh PA 15213-3890 - * - * any improvements or extensions that they make and grant Carnegie Mellon - * the rights to redistribute these changes. - */ - -/* - * Memory deallocation routine for MiG interfaces. - */ -#include -#include "externs.h" - -void -mig_deallocate(vm_address_t addr, vm_size_t size) -{ - (void) vm_deallocate(mach_task_self(), - addr, - size); -} diff --git a/mach.subproj/mig_reply_setup.c b/mach.subproj/mig_reply_setup.c deleted file mode 100644 index b18ec76..0000000 --- a/mach.subproj/mig_reply_setup.c +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Mach Operating System - * Copyright (c) 1991 Carnegie Mellon University - * All Rights Reserved. - * - * Permission to use, copy, modify and distribute this software and its - * documentation is hereby granted, provided that both the copyright - * notice and this permission notice appear in all copies of the - * software, derivative works or modified versions, and any portions - * thereof, and that both notices appear in supporting documentation. - * - * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" - * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR - * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. - * - * Carnegie Mellon requests users of this software to return to - * - * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU - * School of Computer Science - * Carnegie Mellon University - * Pittsburgh PA 15213-3890 - * - * any improvements or extensions that they make and grant Carnegie Mellon - * the rights to redistribute these changes. - */ - -/* - * Routine to set up a MiG reply message from a request message. - * - * Knows about the MiG reply message ID convention: - * reply_id = request_id + 100 - * - * For typed IPC sets up the RetCode type field. Does NOT set a - * return code value. - */ - -#include -#include -#include - -void -mig_reply_setup(mach_msg_header_t *request, mach_msg_header_t *reply) -{ -#define InP (request) -#define OutP ((mig_reply_error_t *) reply) - - OutP->Head.msgh_bits = - MACH_MSGH_BITS(MACH_MSGH_BITS_LOCAL(InP->msgh_bits), 0); - OutP->Head.msgh_size = sizeof(mig_reply_error_t); - OutP->Head.msgh_remote_port = InP->msgh_local_port; - OutP->Head.msgh_local_port = MACH_PORT_NULL; - OutP->Head.msgh_id = InP->msgh_id + 100; - OutP->NDR = NDR_record; -} diff --git a/mach.subproj/mig_strncpy.c b/mach.subproj/mig_strncpy.c deleted file mode 100644 index fe2a314..0000000 --- a/mach.subproj/mig_strncpy.c +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Mach Operating System - * Copyright (c) 1991,1990,1989 Carnegie Mellon University - * All Rights Reserved. - * - * Permission to use, copy, modify and distribute this software and its - * documentation is hereby granted, provided that both the copyright - * notice and this permission notice appear in all copies of the - * software, derivative works or modified versions, and any portions - * thereof, and that both notices appear in supporting documentation. - * - * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" - * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR - * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. - * - * Carnegie Mellon requests users of this software to return to - * - * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU - * School of Computer Science - * Carnegie Mellon University - * Pittsburgh PA 15213-3890 - * - * any improvements or extensions that they make and grant Carnegie Mellon - * the rights to redistribute these changes. - */ -/* - * mig_strncpy.c - by Joshua Block - * - * mig_strncpy -- Bounded string copy. Does what the library routine strncpy - * OUGHT to do: Copies the (null terminated) string in src into dest, a - * buffer of length len. Assures that the copy is still null terminated - * and doesn't overflow the buffer, truncating the copy if necessary. - * - * Parameters: - * - * dest - Pointer to destination buffer. - * - * src - Pointer to source string. - * - * len - Length of destination buffer. - * - * Result: - * length of string copied, INCLUDING the trailing 0. - */ -#include - -int -mig_strncpy( - register char *dest, - register char *src, - register int len) -{ - register int i; - - if (len <= 0) - return 0; - - for (i=1; i -#include -#include -#include -#include - -kern_return_t -thread_switch( - mach_port_t thread, - int option, - mach_msg_timeout_t option_time) -{ - kern_return_t result; - - result = syscall_thread_switch(thread, option, option_time); - return (result); -} diff --git a/mach.subproj/notify.defs b/mach.subproj/notify.defs deleted file mode 100644 index 2014be5..0000000 --- a/mach.subproj/notify.defs +++ /dev/null @@ -1 +0,0 @@ -#include diff --git a/mach.subproj/panic.c b/mach.subproj/panic.c deleted file mode 100644 index 2411d52..0000000 --- a/mach.subproj/panic.c +++ /dev/null @@ -1,58 +0,0 @@ -/* - * @OSF_COPYRIGHT@ - */ - -/* - * Mach Operating System - * Copyright (c) 1991,1990,1989 Carnegie Mellon University - * All Rights Reserved. - * - * Permission to use, copy, modify and distribute this software and its - * documentation is hereby granted, provided that both the copyright - * notice and this permission notice appear in all copies of the - * software, derivative works or modified versions, and any portions - * thereof, and that both notices appear in supporting documentation. - * - * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" - * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR - * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. - * - * Carnegie Mellon requests users of this software to return to - * - * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU - * School of Computer Science - * Carnegie Mellon University - * Pittsburgh PA 15213-3890 - * - * any improvements or extensions that they make and grant Carnegie Mellon - * the rights to redistribute these changes. - */ - -#include -#include -#include -#include - -static mach_port_t master_host_port; - -void -panic_init(mach_port_t port) -{ - master_host_port = port; -} - -/*VARARGS1*/ -void -panic(const char *s, ...) -{ - va_list listp; - - printf("panic: "); - va_start(listp, s); - vprintf(s, listp); - va_end(listp); - printf("\n"); - -#define RB_DEBUGGER 0x1000 /* enter debugger NOW */ - (void) host_reboot(master_host_port, RB_DEBUGGER); -} diff --git a/mach.subproj/port_obj.c b/mach.subproj/port_obj.c deleted file mode 100644 index 4d63221..0000000 --- a/mach.subproj/port_obj.c +++ /dev/null @@ -1,29 +0,0 @@ -/* - * @OSF_COPYRIGHT@ - */ - -/* - * Define a service to map from a kernel-generated port name - * to server-defined "type" and "value" data to be associated - * with the port. - */ -#include -#include - -#define DEFAULT_TABLE_SIZE (64 * 1024) - -struct port_obj_tentry *port_obj_table; -int port_obj_table_size = DEFAULT_TABLE_SIZE; - -void port_obj_init( - int maxsize) -{ - kern_return_t kr; - - kr = vm_allocate(mach_task_self(), - (vm_offset_t *)&port_obj_table, - (vm_size_t)(maxsize * sizeof (*port_obj_table)), - TRUE); - if (kr != KERN_SUCCESS) - panic("port_obj_init: can't vm_allocate"); -} diff --git a/mach.subproj/processor.defs b/mach.subproj/processor.defs deleted file mode 100644 index bc58140..0000000 --- a/mach.subproj/processor.defs +++ /dev/null @@ -1 +0,0 @@ -#include diff --git a/mach.subproj/processor_set.defs b/mach.subproj/processor_set.defs deleted file mode 100644 index 5504bc9..0000000 --- a/mach.subproj/processor_set.defs +++ /dev/null @@ -1 +0,0 @@ -#include \ No newline at end of file diff --git a/mach.subproj/sbrk.c b/mach.subproj/sbrk.c deleted file mode 100644 index 5b47642..0000000 --- a/mach.subproj/sbrk.c +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * File: sbrk.c - * - * Unix compatibility for sbrk system call. - * - * HISTORY - * 09-Mar-90 Gregg Kellogg (gk) at NeXT. - * include instead of - * - * 14-Feb-89 Avadis Tevanian (avie) at NeXT. - * Total rewrite using a fixed area of VM from break region. - */ - -#include /* for vm_allocate, vm_offset_t */ -#include -#include /* 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) - int size; -{ - vm_offset_t addr; - kern_return_t ret; - caddr_t ocurbrk; - extern int end; - - if (sbrk_needs_init) { - sbrk_needs_init = FALSE; - /* - * Allocate a big region to simulate break region. - */ - 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); - } - - if (size <= 0) - return((caddr_t)sbrk_curbrk); - sbrk_curbrk += size; - sbrk_region_size -= size; - if (sbrk_region_size < 0) - return((caddr_t)-1); - return((caddr_t)(sbrk_curbrk - size)); -} - -caddr_t brk(x) - caddr_t x; -{ - return((caddr_t)-1); -} - diff --git a/mach.subproj/semaphore.c b/mach.subproj/semaphore.c deleted file mode 100644 index e0ac63b..0000000 --- a/mach.subproj/semaphore.c +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright (c) 2000 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@ - */ -/* - * catch_exception_raise will be implemented by user programs - * This implementation is provided to resolve the reference in - * exc_server(). - */ - -#include -#include -#include -#include -#include -#include - -extern kern_return_t _host_semaphore_traps_return_; - -kern_return_t semaphore_signal( - mach_port_t signal_semaphore) -{ - return semaphore_signal_trap(signal_semaphore); -} - -kern_return_t semaphore_signal_all( - mach_port_t signal_semaphore) -{ - return semaphore_signal_all_trap(signal_semaphore); -} - -kern_return_t semaphore_signal_thread( - mach_port_t signal_semaphore, - mach_port_t thread_act) -{ - return semaphore_signal_thread_trap(signal_semaphore, thread_act); -} - -kern_return_t semaphore_wait ( - mach_port_t wait_semaphore) -{ - return semaphore_wait_trap(wait_semaphore); -} - -kern_return_t semaphore_timedwait ( - mach_port_t wait_semaphore, - mach_timespec_t wait_time) -{ - return semaphore_timedwait_trap(wait_semaphore, - wait_time.tv_sec, - wait_time.tv_nsec); -} - -kern_return_t semaphore_wait_signal ( - mach_port_t wait_semaphore, - mach_port_t signal_semaphore) -{ - return semaphore_wait_signal_trap(wait_semaphore, signal_semaphore); -} - -kern_return_t semaphore_timedwait_signal ( - mach_port_t wait_semaphore, - mach_port_t signal_semaphore, - mach_timespec_t wait_time) -{ - return semaphore_timedwait_signal_trap(wait_semaphore, - signal_semaphore, - wait_time.tv_sec, - wait_time.tv_nsec); -} diff --git a/mach.subproj/servers.subproj/Makefile b/mach.subproj/servers.subproj/Makefile deleted file mode 100644 index e00ee97..0000000 --- a/mach.subproj/servers.subproj/Makefile +++ /dev/null @@ -1,49 +0,0 @@ -# -# Generated by the NeXT Project Builder. -# -# NOTE: Do NOT change this file -- Project Builder maintains it. -# -# Put all of your customizations in files called Makefile.preamble -# and Makefile.postamble (both optional), and Makefile will include them. -# - -NAME = servers - -PROJECTVERSION = 2.8 -PROJECT_TYPE = Component - -HFILES = bootstrap_defs.h key_defs.h ls_defs.h netname_defs.h\ - nm_defs.h - -OTHERSRCS = Makefile.preamble Makefile Makefile.postamble\ - bootstrap.defs netname.defs - -MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles -CODE_GEN_STYLE = DYNAMIC -MAKEFILE = subproj.make -LIBS = -DEBUG_LIBS = $(LIBS) -PROF_LIBS = $(LIBS) - - -PUBLIC_HEADERS = bootstrap_defs.h key_defs.h ls_defs.h netname_defs.h\ - nm_defs.h - - - -NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc -WINDOWS_OBJCPLUS_COMPILER = $(DEVDIR)/gcc -PDO_UNIX_OBJCPLUS_COMPILER = $(NEXTDEV_BIN)/gcc -NEXTSTEP_JAVA_COMPILER = /usr/bin/javac -WINDOWS_JAVA_COMPILER = $(JDKBINDIR)/javac.exe -PDO_UNIX_JAVA_COMPILER = $(JDKBINDIR)/javac - -include $(MAKEFILEDIR)/platform.make - --include Makefile.preamble - -include $(MAKEFILEDIR)/$(MAKEFILE) - --include Makefile.postamble - --include Makefile.dependencies diff --git a/mach.subproj/servers.subproj/Makefile.postamble b/mach.subproj/servers.subproj/Makefile.postamble deleted file mode 100644 index 411cde6..0000000 --- a/mach.subproj/servers.subproj/Makefile.postamble +++ /dev/null @@ -1,100 +0,0 @@ -############################################################################### -# Makefile.postamble -# Copyright 1997, Apple Computer, Inc. -# -# Use this makefile, which is imported after all other makefiles, to -# override attributes for a project's Makefile environment. This allows you -# to take advantage of the environment set up by the other Makefiles. -# You can also define custom rules at the end of this file. -# -############################################################################### -# -# These variables are exported by the standard makefiles and can be -# used in any customizations you make. They are *outputs* of -# the Makefiles and should be used, not set. -# -# PRODUCTS: products to install. All of these products will be placed in -# the directory $(DSTROOT)$(INSTALLDIR) -# GLOBAL_RESOURCE_DIR: The directory to which resources are copied. -# LOCAL_RESOURCE_DIR: The directory to which localized resources are copied. -# OFILE_DIR: Directory into which .o object files are generated. -# DERIVED_SRC_DIR: Directory used for all other derived files -# -# ALL_CFLAGS: flags to pass when compiling .c files -# ALL_MFLAGS: flags to pass when compiling .m files -# ALL_CCFLAGS: flags to pass when compiling .cc, .cxx, and .C files -# ALL_MMFLAGS: flags to pass when compiling .mm, .mxx, and .M files -# ALL_PRECOMPFLAGS: flags to pass when precompiling .h files -# ALL_LDFLAGS: flags to pass when linking object files -# ALL_LIBTOOL_FLAGS: flags to pass when libtooling object files -# ALL_PSWFLAGS: flags to pass when processing .psw and .pswm (pswrap) files -# ALL_RPCFLAGS: flags to pass when processing .rpc (rpcgen) files -# ALL_YFLAGS: flags to pass when processing .y (yacc) files -# ALL_LFLAGS: flags to pass when processing .l (lex) files -# -# NAME: name of application, bundle, subproject, palette, etc. -# LANGUAGES: langages in which the project is written (default "English") -# English_RESOURCES: localized resources (e.g. nib's, images) of project -# GLOBAL_RESOURCES: non-localized resources of project -# -# SRCROOT: base directory in which to place the new source files -# SRCPATH: relative path from SRCROOT to present subdirectory -# -# INSTALLDIR: Directory the product will be installed into by 'install' target -# PUBLIC_HDR_INSTALLDIR: where to install public headers. Don't forget -# to prefix this with DSTROOT when you use it. -# PRIVATE_HDR_INSTALLDIR: where to install private headers. Don't forget -# to prefix this with DSTROOT when you use it. -# -# EXECUTABLE_EXT: Executable extension for the platform (i.e. .exe on Windows) -# -############################################################################### - -# Some compiler flags can be overridden here for certain build situations. -# -# WARNING_CFLAGS: flag used to set warning level (defaults to -Wmost) -# DEBUG_SYMBOLS_CFLAGS: debug-symbol flag passed to all builds (defaults -# to -g) -# DEBUG_BUILD_CFLAGS: flags passed during debug builds (defaults to -DDEBUG) -# OPTIMIZE_BUILD_CFLAGS: flags passed during optimized builds (defaults -# to -O) -# PROFILE_BUILD_CFLAGS: flags passed during profile builds (defaults -# to -pg -DPROFILE) -# LOCAL_DIR_INCLUDE_DIRECTIVE: flag used to add current directory to -# the include path (defaults to -I.) -# DEBUG_BUILD_LDFLAGS, OPTIMIZE_BUILD_LDFLAGS, PROFILE_BUILD_LDFLAGS: flags -# passed to ld/libtool (defaults to nothing) - - -# Library and Framework projects only: -# INSTALL_NAME_DIRECTIVE: This directive ensures that executables linked -# against the framework will run against the correct version even if -# the current version of the framework changes. You may override this -# to "" as an alternative to using the DYLD_LIBRARY_PATH during your -# development cycle, but be sure to restore it before installing. - - -# Ownership and permissions of files installed by 'install' target - -#INSTALL_AS_USER = root - # User/group ownership -#INSTALL_AS_GROUP = wheel - # (probably want to set both of these) -#INSTALL_PERMISSIONS = - # If set, 'install' chmod's executable to this - - -# Options to strip. Note: -S strips debugging symbols (executables can be stripped -# down further with -x or, if they load no bundles, with no options at all). - -#STRIPFLAGS = -S - - -######################################################################### -# Put rules to extend the behavior of the standard Makefiles here. Include them in -# the dependency tree via cvariables like AFTER_INSTALL in the Makefile.preamble. -# -# You should avoid redefining things like "install" or "app", as they are -# owned by the top-level Makefile API and no context has been set up for where -# derived files should go. -# diff --git a/mach.subproj/servers.subproj/Makefile.preamble b/mach.subproj/servers.subproj/Makefile.preamble deleted file mode 100644 index 5cee34d..0000000 --- a/mach.subproj/servers.subproj/Makefile.preamble +++ /dev/null @@ -1,3 +0,0 @@ -OTHER_PUBLIC_HEADERS = bootstrap.h netname.h -OTHER_OFILES = bootstrapUser.o netnameUser.o -PUBLIC_HEADER_DIR_SUFFIX = /servers diff --git a/mach.subproj/servers.subproj/PB.project b/mach.subproj/servers.subproj/PB.project deleted file mode 100644 index d9b8447..0000000 --- a/mach.subproj/servers.subproj/PB.project +++ /dev/null @@ -1,23 +0,0 @@ -{ - DYNAMIC_CODE_GEN = YES; - FILESTABLE = { - H_FILES = (bootstrap_defs.h, key_defs.h, ls_defs.h, netname_defs.h, nm_defs.h); - OTHER_SOURCES = (Makefile.preamble, Makefile, Makefile.postamble, bootstrap.defs, netname.defs); - PUBLIC_HEADERS = (bootstrap_defs.h, key_defs.h, ls_defs.h, netname_defs.h, nm_defs.h); - SUBPROJECTS = (); - }; - LANGUAGE = English; - MAKEFILEDIR = "$(MAKEFILEPATH)/pb_makefiles"; - NEXTSTEP_BUILDTOOL = /bin/gnumake; - NEXTSTEP_JAVA_COMPILER = /usr/bin/javac; - NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc; - PDO_UNIX_BUILDTOOL = $NEXT_ROOT/Developer/bin/make; - PDO_UNIX_JAVA_COMPILER = "$(JDKBINDIR)/javac"; - PDO_UNIX_OBJCPLUS_COMPILER = "$(NEXTDEV_BIN)/gcc"; - PROJECTNAME = servers; - PROJECTTYPE = Component; - PROJECTVERSION = 2.8; - WINDOWS_BUILDTOOL = $NEXT_ROOT/Developer/Executables/make; - WINDOWS_JAVA_COMPILER = "$(JDKBINDIR)/javac.exe"; - WINDOWS_OBJCPLUS_COMPILER = "$(DEVDIR)/gcc"; -} diff --git a/mach.subproj/servers.subproj/bootstrap.defs b/mach.subproj/servers.subproj/bootstrap.defs deleted file mode 100644 index 0daa753..0000000 --- a/mach.subproj/servers.subproj/bootstrap.defs +++ /dev/null @@ -1,307 +0,0 @@ -/* - * bootstrap -- fundamental service initiator and port server - * Mike DeMoney, NeXT, Inc. - * Copyright, 1990. All rights reserved. - * - * bootstrap.defs -- Mig interface definition - */ - -subsystem bootstrap 400; - -/* - * Interface: Bootstrap server - * - * The bootstrap server is the first user-mode task initiated by the Mach - * kernel at system boot time. The bootstrap server provides two services, - * it initiates other system tasks, and manages a table of name-port bindings - * for fundamental system services (e.g. the NetMsgServer, and the Unix - * emulation service). - * - * The file /etc/bootstrap.conf is read by bootstrap to determine other system - * services to initiate at system boot time. The format of this file is - * described later. - * - * Name-port bindings can be established with the bootstrap server by either - * of two mechanisms: - * - * 1. The binding can be indicated in the file /etc/bootstrap.conf. In this - * case, bootstrap will immediately create a port and bind the indicated name - * with that port. At a later time, a service may "checkin" for the name-port - * binding and will be returned receive rights for the bound port. Lookup's - * on bindings created by this mechanism will return send rights to the port, - * even if no service has "checked-in". In this case, requests sent to the - * bound port will be queued until a server has checked-in and can satisfy the - * request. - * - * 2. Bindings can be established dynamically via a "register" request. In - * this case, the register request provides bootstrap with a name and send - * rights for a port. Bootstrap will provide send rights for the bound port - * to any requestor via the lookup request. - * - * Bootstrap provides its service port to descendant tasks via the Mach - * "bootstrap" special task port. All direct descendants of bootstrap receive - * a "privileged" bootstrap service port. System services that initiate - * untrusted tasks should replace the Mach bootstrap task special port with - * a subset bootstrap port to prevent them from infecting the namespace. - * - * The bootstrap server creates a "backup" port for each service that it - * creates. This is used to detect when a checked out service is no longer - * being served. The bootstrap server regains all rights to the port and - * it is marked available for check-out again. This allows crashed servers to - * resume service to previous clients. Lookup's on this named port will - * continue to be serviced by bootstrap while holding receive rights for the - * bound port. A client may detect that the service is inactive via the. - * bootstrap status request. If the service re-registers rather than - * "checking-in" the original bound port is destroyed. - * - * The status of a named service may be obtained via the "status" request. - * A service is "active" if a name-port binding exists and receive rights - * to the bound port are held by a task other than bootstrap. - * - * Bootstrap initiates server tasks and creates initial name-port bindings as - * directed by the configuration file /etc/bootstrap.conf. This file has - * entries with the following formats: - * - * services [ SERVICE_NAME ]+ ; - * - * E.g: - * services OldService=1 SomeService; - * - * Creates a port and binds the name "OldService" to it. - * For compatability, assigns the port via mach_ports_register to - * slot 1. Also creates a port and binds the name "SomeService". - * - * self [ SERVICE_NAME ]+ ; - * - * E.g: - * self BootStrapService; - * - * Provides a binding to bootstrap's own service port named - * "BootStrapService". - * - * [restartable] server SERVER_FILE_AND_ARGS [ services ... ] ; - * - * E.g: - * server "/usr/etc/sigserver -i" services UnixSignalService; - * - * Initiates the server task "/usr/etc/sigserver" with - * command-line argument "-i", and also creates a name-port - * binding for the name UnixSignalService. Checkin requests for - * UnixSignalService are only accepted via the bootstrap service - * port passed to/usr/etc/sigserver. If the "restartable" option - * had been specified, bootstrap will reinitiate the server task - * if it receives notification that all of the server's service - * ports have been destroyed or deallocated. The server command - * may be specified without surrounding quotes if it does not - * include blanks. - * - * init SERVER_FILE_AND_ARGS [ services ... ] ; - * - * E.g: - * init /etc/init services NetMsgService=0 PSWindowService=4; - * - * Functions like "server" request above, except process is - * started as pid 1. Illegal if bootstrap itself was not - * initiated as pid 1. - * - * forward; - * - * If present, bootstrap will forward unknown lookup requests to - * its bootstrap service port (if not PORT_NULL), and forward any - * reply to the original requester. - * - * # Comment string up to end of line. - * - * A line terminated comment starts with a sharp sign (#). - * - * Lexical notes: Strings are either enclosed in double quotes ("), or must - * start with a letter or underscore (_) and followed by a string of - * alphanumerics and underscores; backslash (\) escapes the following - * character. Strings are limited to a (large) length. Numbers must be - * decimal. Blanks and newlines may be freely used outside of strings. - */ - -#include -import ; - -type name_t = c_string[128]; -type name_array_t = ^array [] of name_t; -type bool_array_t = ^array [] of boolean_t; - -serverprefix x_; - -/* old service_checkin */ -skip; -/* old service_status */ -skip; - -/* - * kern_return_t - * bootstrap_check_in(mach_port_t bootstrap_port, - * name_t service_name, - * port_all_t *service_port) - * - * Returns all rights to service_port of service named by service_name. - * - * Errors: Returns appropriate kernel errors on rpc failure. - * Returns BOOTSTRAP_UNKNOWN_SERVICE, if service does not exist. - * Returns BOOTSTRAP_NOT_PRIVILEGED, if request directed to - * bootstrap port without privilege. - * Returns BOOTSTRAP_SERVICE_ACTIVE, if service has already been - * registered or checked-in. - */ -routine bootstrap_check_in( - bootstrap_port : mach_port_t; - service_name : name_t; - out service_port : mach_port_move_receive_t); - -/* - * kern_return_t - * bootstrap_register(mach_port_t bootstrap_port, - * name_t service_name, - * mach_port_t service_port) - * - * Registers send rights for the port service_port for the service named by - * service_name. Attempts to registering a service where an active binding - * already exists are rejected. On the otherhand, registering a service where - * and inactive binding exists (i.e. bootstrap currently holds receive rights - * for the service port) is allowed; in this case the previous service port - * will be deallocated. Restarting services wishing to resume service for - * previous clients must first attempt to checkin to the service in order to - * recover the previous service port. - * - * Errors: Returns appropriate kernel errors on rpc failure. - * Returns BOOTSTRAP_NOT_PRIVILEGED, if request directed to - * bootstrap port without privilege. - * Returns BOOTSTRAP_NAME_IN_USE, if service has already been - * register or checked-in. - */ -routine bootstrap_register( - bootstrap_port : mach_port_t; - service_name : name_t; - service_port : mach_port_t); - -/* - * kern_return_t - * bootstrap_look_up(mach_port_t bootstrap_port, - * name_t service_name, - * mach_port_t *service_port) - * - * Returns send rights for the service port of the service named by - * service_name in service_port. Service is not guaranteed to be active. - * - * Errors: Returns appropriate kernel errors on rpc failure. - * Returns BOOTSTRAP_UNKNOWN_SERVICE, if service does not exist. - */ -routine bootstrap_look_up( - bootstrap_port : mach_port_t; - service_name : name_t; - out service_port : mach_port_t); - -/* - * kern_return_t - * bootstrap_look_up_array(mach_port_t bootstrap_port, - * name_array_t service_names, - * int service_names_cnt, - * port_array_t *service_port, - * int *service_ports_cnt, - * boolean_t *all_services_known) - * - * Returns port send rights in corresponding entries of the array service_ports - * for all services named in the array service_names. Service_ports_cnt is - * returned and will always equal service_names_cnt (assuming service_names_cnt - * is greater than or equal to zero). - * - * Errors: Returns appropriate kernel errors on rpc failure. - * Returns BOOTSTRAP_NO_MEMORY, if server couldn't obtain memory - * for response. - * Unknown service names have the corresponding service port set - * to PORT_NULL. - * If all services are known, all_services_known is true on - * return, if any service is unknown, it's false. - */ -routine bootstrap_look_up_array( - bootstrap_port : mach_port_t; - service_names : name_array_t; - out service_ports : mach_port_array_t; - out all_services_known: boolean_t); - -/* old bootstrap_get_unpriv_port */ -skip; - -/* - * kern_return_t - * bootstrap_status(mach_port_t bootstrap_port, - * name_t service_name, - * boolean_t *service_active); - * - * Returns: service_active is true if service is available. - * - * Errors: Returns appropriate kernel errors on rpc failure. - * Returns BOOTSTRAP_UNKNOWN_SERVICE, if service does not exist. - */ -routine bootstrap_status( - bootstrap_port : mach_port_t; - service_name : name_t; - out service_active : boolean_t); - -/* - * kern_return_t - * bootstrap_info(port_t bootstrap_port, - * name_array_t *service_names, - * int *service_names_cnt, - * name_array_t *server_names, - * int *server_names_cnt, - * bool_array_t *service_active, - * int *service_active_cnt); - * - * Errors: Returns appropriate kernel errors on rpc failure. - */ -routine bootstrap_info( - bootstrap_port : mach_port_t; - out service_names : name_array_t, dealloc; - out server_names : name_array_t, dealloc; - out service_active : bool_array_t, dealloc); - -/* - * kern_return_t - * bootstrap_subset(mach_port_t bootstrap_port, - * mach_port_t requestor_port, - * mach_port_t *subset_port); - * - * Returns a new port to use as a bootstrap port. This port behaves - * exactly like the previous bootstrap_port, except that ports dynamically - * registered via bootstrap_register() are available only to users of this - * specific subset_port. Lookups on the subset_port will return ports - * registered with this port specifically, and ports registered with - * ancestors of this subset_port. Duplications of services already - * registered with an ancestor port may be registered with the subset port - * are allowed. Services already advertised may then be effectively removed - * by registering PORT_NULL for the service. - * When it is detected that the requestor_port is destroied the subset - * port and all services advertized by it are destroied as well. - * - * Errors: Returns appropriate kernel errors on rpc failure. - */ -routine bootstrap_subset( - bootstrap_port : mach_port_t; - requestor_port : mach_port_t; - out subset_port : mach_port_t); - -/* - * kern_return_t - * bootstrap_create_service(mach_port_t bootstrap_port, - * name_t service_name, - * mach_port_t *service_port) - * - * Creates a service named "service_name" and returns send rights to that - * port in "service_port." The port may later be checked in as if this - * port were configured in the bootstrap configuration file. - * - * Errors: Returns appropriate kernel errors on rpc failure. - * Returns BOOTSTRAP_SERVICE_ACTIVE, if service already exists. - */ -routine bootstrap_create_service( - bootstrap_port : mach_port_t; - service_name : name_t; - out service_port : mach_port_t); diff --git a/mach.subproj/servers.subproj/bootstrap_defs.h b/mach.subproj/servers.subproj/bootstrap_defs.h deleted file mode 100644 index 18a8ca8..0000000 --- a/mach.subproj/servers.subproj/bootstrap_defs.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * bootstrap -- fundamental service initiator and port server - * Mike DeMoney, NeXT, Inc. - * Copyright, 1990. All rights reserved. - * - * bootstrap_defs.h -- bootstrap service data types and constants - * See bootstrap.defs for description of bootstrap services. - */ - -#ifndef _BOOTSTRAP_DEFS_ -#define _BOOTSTRAP_DEFS_ -#import - -#define BOOTSTRAP_MAX_NAME_LEN 128 -#define BOOTSTRAP_MAX_CMD_LEN 512 - -typedef char name_t[BOOTSTRAP_MAX_NAME_LEN]; -typedef char cmd_t[BOOTSTRAP_MAX_CMD_LEN]; -typedef name_t *name_array_t; -typedef boolean_t *bool_array_t; - -#define BOOTSTRAP_MAX_LOOKUP_COUNT 20 - -#define BOOTSTRAP_SUCCESS 0 -#define BOOTSTRAP_NOT_PRIVILEGED 1100 -#define BOOTSTRAP_NAME_IN_USE 1101 -#define BOOTSTRAP_UNKNOWN_SERVICE 1102 -#define BOOTSTRAP_SERVICE_ACTIVE 1103 -#define BOOTSTRAP_BAD_COUNT 1104 -#define BOOTSTRAP_NO_MEMORY 1105 - -#endif /* _BOOTSTRAP_DEFS_ */ diff --git a/mach.subproj/servers.subproj/key_defs.h b/mach.subproj/servers.subproj/key_defs.h deleted file mode 100644 index a44d526..0000000 --- a/mach.subproj/servers.subproj/key_defs.h +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Mach Operating System - * Copyright (c) 1987 Carnegie-Mellon University - * All rights reserved. The CMU software License Agreement specifies - * the terms and conditions for use and redistribution. - */ - -/* - * Definitions of encryption keys etc.. - */ - -/* - * HISTORY: - * 5-Jun-87 Robert Sansom (rds) at Carnegie Mellon University - * Added macros to convert keys between network and host order. - * - * 12-Apr-87 Robert Sansom (rds) at Carnegie Mellon University - * Added KEY_IS_NULL. - * - * 2-Feb-87 Robert Sansom (rds) at Carnegie Mellon University - * Added KEY_EQUAL. - * - * 5-Nov-86 Robert Sansom (rds) at Carnegie-Mellon University - * Started. - * - */ - -#ifndef _KEY_DEFS_ -#define _KEY_DEFS_ - -/* - * An encrytion key. - */ -typedef union { - unsigned char key_bytes[16]; - unsigned long key_longs[4]; -} key_t, *key_ptr_t; - -#define KEY_EQUAL(key1, key2) \ - ((key1.key_longs[0] == key2.key_longs[0]) \ - && (key1.key_longs[1] == key2.key_longs[1]) \ - && (key1.key_longs[2] == key2.key_longs[2]) \ - && (key1.key_longs[3] == key2.key_longs[3])) - -#define KEY_IS_NULL(key) \ - (((key).key_longs[0] == 0) && ((key).key_longs[1] == 0) \ - && ((key).key_longs[2] == 0) && ((key).key_longs[3] == 0)) - - -/* - * Macros to convert keys between network and host byte order. - */ -#define NTOH_KEY(key) { \ - (key).key_longs[0] = ntohl((key).key_longs[0]); \ - (key).key_longs[1] = ntohl((key).key_longs[1]); \ - (key).key_longs[2] = ntohl((key).key_longs[2]); \ - (key).key_longs[3] = ntohl((key).key_longs[3]); \ -} - -#define HTON_KEY(key) { \ - (key).key_longs[0] = htonl((key).key_longs[0]); \ - (key).key_longs[1] = htonl((key).key_longs[1]); \ - (key).key_longs[2] = htonl((key).key_longs[2]); \ - (key).key_longs[3] = htonl((key).key_longs[3]); \ -} - -/* - * Structure used to transmit or store a token or a key. - */ -typedef union { - key_t si_key; - key_t si_token; -} secure_info_t, *secure_info_ptr_t; - -/* - * Security Level of ports and messages. - */ -#define PORT_NOT_SECURE 0 -#define MESSAGE_NOT_SECURE 0 - -#endif /* _KEY_DEFS_ */ diff --git a/mach.subproj/servers.subproj/ls_defs.h b/mach.subproj/servers.subproj/ls_defs.h deleted file mode 100644 index 9dc2fe7..0000000 --- a/mach.subproj/servers.subproj/ls_defs.h +++ /dev/null @@ -1,232 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Mach Operating System - * Copyright (c) 1989 Carnegie-Mellon University - * Copyright (c) 1988 Carnegie-Mellon University - * Copyright (c) 1987 Carnegie-Mellon University - * All rights reserved. The CMU software License Agreement specifies - * the terms and conditions for use and redistribution. - */ - -/* - * Definitions for the logstat module. - */ - - -#ifndef _LS_DEFS_ -#define _LS_DEFS_ - -#include - -/* - * Definition for a log record. - */ -typedef struct { - long code; - long thread; - long a1; - long a2; - long a3; - long a4; - long a5; - long a6; -} log_rec_t; - -typedef log_rec_t *log_ptr_t; - -/* - * Statistics record. - */ -typedef struct { - int datagram_pkts_sent; - int datagram_pkts_rcvd; - int srr_requests_sent; - int srr_bcasts_sent; - int srr_requests_rcvd; - int srr_bcasts_rcvd; - int srr_replies_sent; - int srr_replies_rcvd; - int srr_retries_sent; - int srr_retries_rcvd; - int srr_cfailures_sent; - int srr_cfailures_rcvd; - int deltat_dpkts_sent; - int deltat_acks_rcvd; - int deltat_dpkts_rcvd; - int deltat_acks_sent; - int deltat_oldpkts_rcvd; - int deltat_oospkts_rcvd; - int deltat_retries_sent; - int deltat_retries_rcvd; - int deltat_cfailures_sent; - int deltat_cfailures_rcvd; - int deltat_aborts_sent; - int deltat_aborts_rcvd; - int vmtp_requests_sent; - int vmtp_requests_rcvd; - int vmtp_replies_sent; - int vmtp_replies_rcvd; - int ipc_in_messages; - int ipc_out_messages; - int ipc_unblocks_sent; - int ipc_unblocks_rcvd; - int pc_requests_sent; - int pc_requests_rcvd; - int pc_replies_rcvd; - int pc_startups_rcvd; - int nn_requests_sent; - int nn_requests_rcvd; - int nn_replies_rcvd; - int po_ro_hints_sent; - int po_ro_hints_rcvd; - int po_token_requests_sent; - int po_token_requests_rcvd; - int po_token_replies_rcvd; - int po_xfer_requests_sent; - int po_xfer_requests_rcvd; - int po_xfer_replies_rcvd; - int po_deaths_sent; - int po_deaths_rcvd; - int ps_requests_sent; - int ps_requests_rcvd; - int ps_replies_rcvd; - int ps_auth_requests_sent; - int ps_auth_requests_rcvd; - int ps_auth_replies_rcvd; - int mallocs_or_vm_allocates; - int mem_allocs; - int mem_deallocs; - int mem_allocobjs; - int mem_deallocobjs; - int pkts_encrypted; - int pkts_decrypted; - int vmtp_segs_encrypted; - int vmtp_segs_decrypted; - int tcp_requests_sent; - int tcp_replies_sent; - int tcp_requests_rcvd; - int tcp_replies_rcvd; - int tcp_send; - int tcp_recv; - int tcp_connect; - int tcp_accept; - int tcp_close; -} stat_t; - -typedef stat_t *stat_ptr_t; - - -/* - * Debugging flags record. - */ -typedef struct { - int print_level; - int ipc_in; - int ipc_out; - int tracing; - int vmtp; - int netname; - int deltat; - int tcp; - int mem; -} debug_t; - -typedef debug_t *debug_ptr_t; - - -/* - * Parameters record. - */ -typedef struct { - int srr_max_tries; - int srr_retry_sec; - int srr_retry_usec; - int deltat_max_tries; - int deltat_retry_sec; - int deltat_retry_usec; - int deltat_msg_life; - int pc_checkup_interval; - int crypt_algorithm; - int transport_default; - int conf_network; - int conf_netport; - int timer_quantum; - int tcp_conn_steady; - int tcp_conn_opening; - int tcp_conn_max; - int compat; - int syslog; - int old_nmmonitor; -} param_t; - -typedef param_t *param_ptr_t; - - -/* - * Port statistics record. - */ -typedef struct { - u_int port_id; - u_int alive; - u_int nport_id_high; - u_int nport_id_low; - u_int nport_receiver; - u_int nport_owner; - u_int messages_sent; - u_int messages_rcvd; - u_int send_rights_sent; - u_int send_rights_rcvd_sender; - u_int send_rights_rcvd_recown; - u_int rcv_rights_xferd; - u_int own_rights_xferd; - u_int all_rights_xferd; - u_int tokens_sent; - u_int tokens_requested; - u_int xfer_hints_sent; - u_int xfer_hints_rcvd; -} port_stat_t, *port_stat_ptr_t; - -extern port_stat_ptr_t port_stat_cur; -extern port_stat_ptr_t port_stat_end; -extern struct mutex port_stat_lock; - - -/* - * Types for the mem_list operation. - * - * XXX These must be faked, because we cannot include mem.h here - * (mutual includes). - */ -typedef char *mem_class_ptr_t; -typedef char *mem_nam_ptr_t; -typedef int *mem_bucket_ptr_t; - - -/* - * Definitions for print_level. - */ -#define LS_PRINT_NEVER 5 -#define LS_PRINT_LOG 3 -#define LS_PRINT_ALWAYS 0 - -#endif /* _LS_DEFS_ */ diff --git a/mach.subproj/servers.subproj/netname.defs b/mach.subproj/servers.subproj/netname.defs deleted file mode 100644 index 264495c..0000000 --- a/mach.subproj/servers.subproj/netname.defs +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Mach Operating System - * Copyright (c) 1987 Carnegie-Mellon University - * All rights reserved. The CMU software License Agreement specifies - * the terms and conditions for use and redistribution. - */ - -/* - * Mig definitions for Network Name Service. - */ - -/* - * HISTORY: - * 30-May-87 Robert Sansom (rds) at Carnegie Mellon University - * Changes for the new mig. - * - * 20-Oct-86 Robert Sansom (rds) at Carnegie Mellon University - * New network name service interface. - * Added a serverprefix. - */ - -#include - -import ; - -subsystem netname 1040; - -serverprefix _; - - -type netname_name_t = c_string[*:80]; - -routine netname_check_in(server_port : mach_port_t; - port_name : netname_name_t; - signature : mach_port_t; - port_id : mach_port_t); - -routine netname_look_up(server_port : mach_port_t; - host_name : netname_name_t; - port_name : netname_name_t; - out port_id : mach_port_t); - -routine netname_check_out(server_port : mach_port_t; - port_name : netname_name_t; - signature : mach_port_t); - -routine netname_version(server_port : mach_port_t; - out version : netname_name_t); - diff --git a/mach.subproj/servers.subproj/netname_defs.h b/mach.subproj/servers.subproj/netname_defs.h deleted file mode 100644 index 8dcffcb..0000000 --- a/mach.subproj/servers.subproj/netname_defs.h +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Mach Operating System - * Copyright (c) 1987 Carnegie-Mellon University - * All rights reserved. The CMU software License Agreement specifies - * the terms and conditions for use and redistribution. - */ - -/* - * Definitions for the mig interface to the network name service. - */ - -/* - * HISTORY: - * 28-Jul-88 Mary R. Thompson (mrt) at Carnegie Mellon - * Copied definitions of NAME_NOT_YOURS and NAME_NOT_CHECKED_IN - * from the old netname_defs.h so that old code would not break - * - * 8-Mar-88 Daniel Julin (dpj) at Carnegie-Mellon University - * Added NETNAME_INVALID_PORT. - * - * 28-Feb-88 Daniel Julin (dpj) at Carnegie-Mellon University - * Added NETNAME_PENDING. - * - * 23-Dec-86 Robert Sansom (rds) at Carnegie Mellon University - * Copied from the previous version of the network server. - * - */ - -#ifndef _NETNAME_DEFS_ -#define _NETNAME_DEFS_ - -#define NETNAME_SUCCESS (0) -#define NETNAME_PENDING (-1) -#define NETNAME_NOT_YOURS (1000) -#define NAME_NOT_YOURS (1000) -#define NETNAME_NOT_CHECKED_IN (1001) -#define NAME_NOT_CHECKED_IN (1001) -#define NETNAME_NO_SUCH_HOST (1002) -#define NETNAME_HOST_NOT_FOUND (1003) -#define NETNAME_INVALID_PORT (1004) - -typedef char netname_name_t[80]; - -#endif /* NETNAME_DEFS_ */ diff --git a/mach.subproj/servers.subproj/nm_defs.h b/mach.subproj/servers.subproj/nm_defs.h deleted file mode 100644 index 641a2e7..0000000 --- a/mach.subproj/servers.subproj/nm_defs.h +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Mach Operating System - * Copyright (c) 1987 Carnegie-Mellon University - * All rights reserved. The CMU software License Agreement specifies - * the terms and conditions for use and redistribution. - */ - -/* - * Random definitions for the network service that everyone needs! - */ - -/* - * HISTORY: - * 27-Mar-90 Gregg Kellogg (gk) at NeXT - * include rather than - * - * 24-Aug-88 Daniel Julin (dpj) at Carnegie-Mellon University - * Replace sys/mach_ipc_netport.h with kern/ipc_netport.h. Sigh. - * - * 24-May-88 Daniel Julin (dpj) at Carnegie-Mellon University - * Replace mach_ipc_vmtp.h with mach_ipc_netport.h. - * - * 4-Sep-87 Daniel Julin (dpj) at Carnegie-Mellon University - * Fixed for new kernel include files which declare a lot - * of network server stuff internally, because of the NETPORT - * option. - * - * 5-Nov-86 Robert Sansom (rds) at Carnegie-Mellon University - * Started. - * - */ - -#ifndef _NM_DEFS_ -#define _NM_DEFS_ - -/* - * netaddr_t is declared with the kernel files, - * in . - */ -#include - -#ifdef notdef -typedef unsigned long netaddr_t; -#endif /* notdef */ - -typedef union { - struct { - unsigned char ia_net_owner; - unsigned char ia_net_node_type; - unsigned char ia_host_high; - unsigned char ia_host_low; - } ia_bytes; - netaddr_t ia_netaddr; -} ip_addr_t; - -#endif /* _NM_DEFS_ */ - diff --git a/mach.subproj/slot_name.c b/mach.subproj/slot_name.c deleted file mode 100644 index 814ea0a..0000000 --- a/mach.subproj/slot_name.c +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * File: slot_name.c - * Author: Avadis Tevanian, Jr. - * - * Copyright (C) 1987, Avadis Tevanian, Jr. - * - * Convert machine slot values to human readable strings. - * - * HISTORY - * 26-Jan-88 Mary Thompson (mrt) at Carnegie Mellon - * added case for CUP_SUBTYPE_RT_APC - * - * 28-Feb-87 Avadis Tevanian (avie) at Carnegie-Mellon University - * Created. - * - */ - -#include -#include -#include - -/* - * Convert the specified cpu_type/cpu_subtype pair to their - * human readable form. - */ -void slot_name(cpu_type, cpu_subtype, cpu_name, cpu_subname) - cpu_type_t cpu_type; - cpu_subtype_t cpu_subtype; - char **cpu_name, **cpu_subname; -{ - register char *name = "Unknown CPU"; - register char *subname = ""; - const NXArchInfo *ai = NXGetArchInfoFromCpuType(cpu_type, cpu_subtype); - if (ai != NULL) { - name = ai->name; - subname = ai->description; - } - *cpu_name = name; - *cpu_subname = subname; -} - -kern_return_t msg_rpc(void) { - return KERN_FAILURE; -} - -kern_return_t msg_send(void) { - return KERN_FAILURE; -} - -kern_return_t msg_receive(void) { - return KERN_FAILURE; -} - -mach_port_t task_self_(void) { - return mach_task_self(); -} - -mach_port_t host_self(void) { - return mach_host_self(); -} - diff --git a/mach.subproj/task.defs b/mach.subproj/task.defs deleted file mode 100644 index af6399f..0000000 --- a/mach.subproj/task.defs +++ /dev/null @@ -1 +0,0 @@ -#include \ No newline at end of file diff --git a/mach.subproj/thread_act.defs b/mach.subproj/thread_act.defs deleted file mode 100644 index 8c515f8..0000000 --- a/mach.subproj/thread_act.defs +++ /dev/null @@ -1 +0,0 @@ -#include \ No newline at end of file diff --git a/mach.subproj/vm_map.defs b/mach.subproj/vm_map.defs deleted file mode 100644 index 36aa954..0000000 --- a/mach.subproj/vm_map.defs +++ /dev/null @@ -1 +0,0 @@ -#include diff --git a/mach/Makefile.inc b/mach/Makefile.inc new file mode 100644 index 0000000..10bda18 --- /dev/null +++ b/mach/Makefile.inc @@ -0,0 +1,103 @@ +.PATH: ${.CURDIR}/${MACHINE_ARCH}/mach ${.CURDIR}/mach + +.include "${.CURDIR}/mach/headers/Makefile.inc" +.include "${.CURDIR}/mach/servers/Makefile.inc" + +# machine-dependent mach sources +.if exists(${.CURDIR}/${MACHINE_ARCH}/mach/Makefile.inc) +.include "${.CURDIR}/${MACHINE_ARCH}/mach/Makefile.inc" +.endif + +MIGDEFS += \ + clock.defs \ + clock_priv.defs \ + host_priv.defs \ + host_security.defs \ + ledger.defs \ + lock_set.defs \ + mach_port.defs \ + mach_host.defs \ + processor.defs \ + processor_set.defs \ + task.defs \ + thread_act.defs \ + vm_map.defs + +#MIGHDRS = ${MIGDEFS:S/.defs$/.h/:S/^/${.CURDIR}\/mach\//} +MIGHDRS = ${MIGDEFS:S/.defs$/.h/} +MIGHDRS += clock_reply.h +MACH_INSTHDRS += ${MIGHDRS} + +# These files are generated from the .defs files +MIGSRCS = ${MIGDEFS:S/.defs$/User.c/} + +SRCS+= ${MIGDEFS:S/.defs$/User.defs/} \ + bootstrap_ports.c \ + clock_sleep.c \ + error_codes.c \ + excServer.c \ + excUser.c \ + exc_catcher.c \ + exc_catcher_state.c \ + exc_catcher_state_identity.c \ + fprintf_stderr.c \ + mig_allocate.c \ + mig_deallocate.c \ + mig_reply_setup.c \ + mig_strncpy.c \ + mach_error.c \ + mach_error_string.c \ + mach_init.c \ + mach_init_ports.c \ + mach_msg.c \ + mach_traps.s \ + ms_thread_switch.c \ + notifyUser.c \ + panic.c \ + port_obj.c \ + sbrk.c \ + semaphore.c \ + slot_name.c + +CLEANFILES += ${MIGHDRS} ${MIGHDRS:S/.h$/User.c/} \ + ${MIGHDRS:S/.h/Server.c/} exc.h excUser.c excServer.c \ + notify.h notifyUser.c notifyServer.c + +${MIGDEFS:S/.defs$/User.So/}: + mig -user ${.TARGET:S/.So$/.c/} \ + -server ${.TARGET:S/User.So$/Server.c/} \ + -header ${.TARGET:S/User.So$/.h/} \ + ${.CURDIR}/mach/${.TARGET:S/User.So$/.defs/} + ${CC} ${CFLAGS} -Os -c ${.TARGET:S/.So$/.c/}\ + -o ${.TARGET} +${MIGDEFS:S/.defs$/User.do/}: + mig -user ${.TARGET:S/.do$/.c/} \ + -server ${.TARGET:S/User.do$/Server.c/} \ + -header ${.TARGET:S/User.do$/.h/} \ + ${.CURDIR}/mach/${.TARGET:S/User.do$/.defs/} + ${CC} -g -DDEBUG ${CFLAGS} -c ${.TARGET:S/.do$/.c/}\ + -o ${.TARGET} +${MIGDEFS:S/.defs$/User.po/}: + mig -user ${.TARGET:S/.po$/.c/} \ + -server ${.TARGET:S/User.po$/Server.c/} \ + -header ${.TARGET:S/User.po$/.h/} \ + ${.CURDIR}/mach/${.TARGET:S/User.po$/.defs/} + ${CC} -pg -DPROFILE ${CFLAGS} -c ${.TARGET:S/.po$/.c/}\ + -o ${.TARGET} +${MIGDEFS:S/.defs$/User.o/}: + mig -user ${.TARGET:S/.o$/.c/} \ + -server ${.TARGET:S/User.o$/Server.c/} \ + -header ${.TARGET:S/User.o$/.h/} \ + ${.CURDIR}/mach/${.TARGET:S/User.o$/.defs/} + ${CC} -static ${CFLAGS} -c ${.TARGET:S/.o$/.c/}\ + -o ${.TARGET} + +excServer.c: ${.CURDIR}/mach/exc.defs + mig -user excUser.c -server excServer.c -header exc.h \ + ${.CURDIR}/mach/exc.defs +excUser.c: ${.CURDIR}/mach/exc.defs + mig -user excUser.c -server excServer.c -header exc.h \ + ${.CURDIR}/mach/exc.defs +notifyUser.c: ${.CURDIR}/mach/notify.defs + mig -user notifyUser.c -server notifyServer.c -header notify.h \ + ${.CURDIR}/mach/notify.defs diff --git a/mach/bootstrap_ports.c b/mach/bootstrap_ports.c new file mode 100644 index 0000000..9cd19d2 --- /dev/null +++ b/mach/bootstrap_ports.c @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2002 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@ + */ +/* + * Mach Operating System + * Copyright (c) 1991,1990,1989 Carnegie Mellon University + * All Rights Reserved. + * + * Permission to use, copy, modify and distribute this software and its + * documentation is hereby granted, provided that both the copyright + * notice and this permission notice appear in all copies of the + * software, derivative works or modified versions, and any portions + * thereof, and that both notices appear in supporting documentation. + * + * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" + * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR + * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. + * + * Carnegie Mellon requests users of this software to return to + * + * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU + * School of Computer Science + * Carnegie Mellon University + * Pittsburgh PA 15213-3890 + * + * any improvements or extensions that they make and grant Carnegie Mellon + * the rights to redistribute these changes. + */ + +#include + +/* + * Stub out the old bootstrap_ports() API, as some applications need + * it to exist. We do not publish a prototype for this, and the stub + * WILL disappear in a future release. + */ +kern_return_t +bootstrap_ports( + mach_port_t bootstrap, + mach_port_t *priv_host, + mach_port_t *device_master, + mach_port_t *wired_ledger, + mach_port_t *paged_ledger, + mach_port_t *host_security) +{ + return KERN_FAILURE; +} + diff --git a/mach/clock.defs b/mach/clock.defs new file mode 100644 index 0000000..1695171 --- /dev/null +++ b/mach/clock.defs @@ -0,0 +1 @@ +#include diff --git a/mach/clock_priv.defs b/mach/clock_priv.defs new file mode 100644 index 0000000..d419faf --- /dev/null +++ b/mach/clock_priv.defs @@ -0,0 +1 @@ +#include diff --git a/mach/clock_reply.defs b/mach/clock_reply.defs new file mode 100644 index 0000000..b0e0f5b --- /dev/null +++ b/mach/clock_reply.defs @@ -0,0 +1,22 @@ +/* + * Copyright (c) 1999 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@ + */ +#include diff --git a/mach/clock_sleep.c b/mach/clock_sleep.c new file mode 100644 index 0000000..e96fcc2 --- /dev/null +++ b/mach/clock_sleep.c @@ -0,0 +1,32 @@ +/* + * Copyright (c) 1999 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@ + */ +#include +#include +#include + +kern_return_t clock_sleep(mach_port_t clock_name, + sleep_type_t clock_type, + mach_timespec_t sleep_time, + mach_timespec_t *wake_time) { + + return clock_sleep_trap(clock_name, clock_type, sleep_time.tv_sec, sleep_time.tv_nsec, wake_time); +} diff --git a/mach/err_ipc.sub b/mach/err_ipc.sub new file mode 100644 index 0000000..9c763cc --- /dev/null +++ b/mach/err_ipc.sub @@ -0,0 +1,99 @@ +/* + * @OSF_COPYRIGHT@ + */ + +/* + * Mach Operating System + * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University + * All Rights Reserved. + * + * Permission to use, copy, modify and distribute this software and its + * documentation is hereby granted, provided that both the copyright + * notice and this permission notice appear in all copies of the + * software, derivative works or modified versions, and any portions + * thereof, and that both notices appear in supporting documentation. + * + * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS + * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR + * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. + * + * Carnegie Mellon requests users of this software to return to + * + * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU + * School of Computer Science + * Carnegie Mellon University + * Pittsburgh PA 15213-3890 + * + * any improvements or extensions that they make and grant Carnegie the + * rights to redistribute these changes. + */ + +/* + * File: err_ipc.sub + * Author: Douglas Orr, Carnegie Mellon University + * Date: Mar, 1988 + * + * Definitions of error strings for original IPC + */ + +static const char * err_codes_send[] = { + "(ipc/send) unknown error", /* -100 */ + "(ipc/send) invalid memory", /* -101 */ + "(ipc/send) invalid port", /* -102 */ + "(ipc/send) timed out", /* -103 */ + "(ipc/send) unused error", /* -104 */ + "(ipc/send) will notify", /* -105 */ + "(ipc/send) notify in progress", /* -106 */ + "(ipc/send) kernel refused message", /* -107 */ + "(ipc/send) send interrupted", /* -108 */ + "(ipc/send) send message too large", /* -109 */ + "(ipc/send) send message too small", /* -110 */ + "(ipc/send) message size changed while being copied", /* -111 */ +}; + +static const char * err_codes_rcv[] = { + "(ipc/rcv) unknown error", /* -200 */ + "(ipc/rcv) invalid memory", /* -201 */ + "(ipc/rcv) invalid port", /* -202 */ + "(ipc/rcv) receive timed out", /* -203 */ + "(ipc/rcv) message too large", /* -204 */ + "(ipc/rcv) no space for message data", /* -205 */ + "(ipc/rcv) only sender remaining", /* -206 */ + "(ipc/rcv) receive interrupted", /* -207 */ + "(ipc/rcv) port receiver changed or port became enabled", /* -208 */ +}; + +static const char * err_codes_mig[] = { + "(ipc/mig) type check failure in message interface", /* 0 (-300) */ + "(ipc/mig) wrong return message ID", /* 1 */ + "(ipc/mig) server detected error", /* 2 */ + "(ipc/mig) bad message ID", /* 3 */ + "(ipc/mig) server found wrong arguments", /* 4 */ + "(ipc/mig) no reply should be sent", /* 5 */ + "(ipc/mig) server raised exception", /* 6 */ + "(ipc/mig) user specified array not large enough for return info", /* 7 */ +}; + +/* err_ipc subsystems */ +static struct error_subsystem err_ipc_sub[] = { + /* ipc/0; */ + { + (char *)"(ipc/send)", + errlib_count(err_codes_send), + (char **)err_codes_send, + }, + /* ipc/1; */ + { + (char *)"(ipc/rcv)", + errlib_count(err_codes_rcv), + (char **)err_codes_rcv, + + }, + /* ipc/2 */ + { + (char *)"(ipc/mig)", + errlib_count(err_codes_mig), + (char **)err_codes_mig, + }, + +}; diff --git a/mach/err_kern.sub b/mach/err_kern.sub new file mode 100644 index 0000000..5103603 --- /dev/null +++ b/mach/err_kern.sub @@ -0,0 +1,182 @@ +/* + * @OSF_COPYRIGHT@ + */ + +/* + * Mach Operating System + * Copyright (c) 1991,1990,1989 Carnegie Mellon University + * All Rights Reserved. + * + * Permission to use, copy, modify and distribute this software and its + * documentation is hereby granted, provided that both the copyright + * notice and this permission notice appear in all copies of the + * software, derivative works or modified versions, and any portions + * thereof, and that both notices appear in supporting documentation. + * + * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS + * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR + * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. + * + * Carnegie Mellon requests users of this software to return to + * + * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU + * School of Computer Science + * Carnegie Mellon University + * Pittsburgh PA 15213-3890 + * + * any improvements or extensions that they make and grant Carnegie the + * rights to redistribute these changes. + */ + +/* + * File: err_kern.sub + * Author: Douglas Orr, Carnegie Mellon University + * Date: Mar, 1988 + * + * error codes for Mach and Unix kernels + */ + +static const char * err_codes_kern[] = { + "(os/kern) successful", /* 0 */ + "(os/kern) invalid address", + "(os/kern) protection failure", + "(os/kern) no space available", + "(os/kern) invalid argument", + "(os/kern) failure", /* 5 */ + "(os/kern) resource shortage", + "(os/kern) not receiver", + "(os/kern) no access", + "(os/kern) memory failure", + "(os/kern) memory error", /* 10 */ + "(os/kern) already in set", + "(os/kern) not in set", + "(os/kern) name exists", + "(os/kern) aborted", + "(os/kern) invalid name", /* 15 */ + "(os/kern) invalid task", + "(os/kern) invalid right", + "(os/kern) invalid value", + "(os/kern) urefs overflow", + "(os/kern) invalid capability", /* 20 */ + "(os/kern) right exists", + "(os/kern) invalid host", + "(os/kern) memory present", + "(os/kern) memory data moved", + "(os/kern) memory restart copy", /* 25 */ + "(os/kern) invalid processor set", + "(os/kern) policy limit", + "(os/kern) invalid policy", + "(os/kern) invalid object", + "(os/kern) already waiting", /* 30 */ + "(os/kern) default set", + "(os/kern) exception protected", + "(os/kern) invalid ledger", + "(os/kern) invalid memory control", + "(os/kern) invalid security", /* 35 */ + "(os/kern) not depressed", + "(os/kern) object terminated", + "(os/kern) lock set destroyed", + "(os/kern) lock unstable", + "(os/kern) lock owned by another", /* 40 */ + "(os/kern) lock owned by self", + "(os/kern) semaphore destroyed", + "(os/kern) RPC terminated", + "(os/kern) terminate orphan", + "(os/kern) let orphan continue", /* 45 */ + "(os/kern) service not supported", + "(os/kern) remote node down", +}; + +static const char * err_codes_unix[] = { + NO_SUCH_ERROR, + "(os/unix) no rights to object", + "(os/unix) file or directory does not exist", + "(os/unix) no such process", + "(os/unix) interrupted system call", + "(os/unix) i/o error", + "(os/unix) device does not exist", + "(os/unix) argument list is too long", + "(os/unix) invalid executable object format", + "(os/unix) bad file descriptor number", + "(os/unix) no child processes are present", + "(os/unix) no more processes are available", + "(os/unix) insufficient memory", + "(os/unix) access denied", + "(os/unix) memory access fault", + "(os/unix) block device required for operation", + "(os/unix) mount device busy", + "(os/unix) file already exists", + "(os/unix) cross device link", + "(os/unix) device does not exist", + "(os/unix) object is not a directory", + "(os/unix) object is a directory", + "(os/unix) invalid argument", + "(os/unix) internal file table overflow", + "(os/unix) maximum number of open files reached", + "(os/unix) object is not a tty-like device", + "(os/unix) executable object is in use", + "(os/unix) file is too large", + "(os/unix) no space is left on device", + "(os/unix) illegal seek attempt", + "(os/unix) read-only file system", + "(os/unix) too many links", + "(os/unix) broken pipe", + "(os/unix) argument is too large", + "(os/unix) result is out of range", + "(os/unix) operation on device would block", + "(os/unix) operation is now in progress", + "(os/unix) operation is already in progress", + "(os/unix) socket operation attempted on non-socket object", + "(os/unix) destination address is required", + "(os/unix) message is too long", + "(os/unix) protocol type is incorrect for socket", + "(os/unix) protocol type is not availaible", + "(os/unix) protocol type is not supported", + "(os/unix) socket type is not supported", + "(os/unix) operation is not supported on sockets", + "(os/unix) protocol family is not supported", + "(os/unix) address family is not supported by protocol family", + "(os/unix) address is already in use", + "(os/unix) can't assign requested address", + "(os/unix) network is down", + "(os/unix) network is unreachable", + "(os/unix) network dropped connection on reset", + "(os/unix) software aborted connection", + "(os/unix) connection reset by peer", + "(os/unix) no buffer space is available", + "(os/unix) socket is already connected", + "(os/unix) socket is not connected", + "(os/unix) can't send after socket shutdown", + "(os/unix) too many references; can't splice", + "(os/unix) connection timed out", + "(os/unix) connection was refused", + "(os/unix) too many levels of symbolic links", + "(os/unix) file name exceeds system maximum limit", + "(os/unix) host is down", + "(os/unix) there is no route to host", + "(os/unix) directory is not empty", + "(os/unix) quota on number of processes exceeded", + "(os/unix) quota on number of users exceeded", + "(os/unix) quota on available disk space exceeded", +}; + +static struct error_subsystem err_os_sub[] = { + { + (char *)"(os/kern)", + errlib_count(err_codes_kern), + (char **)err_codes_kern, + }, + { + (char *)"(os/?)", + 0, + }, + { + (char *)"(os/?)", + 0, + }, + { + (char *)"(os/unix)", + errlib_count(err_codes_unix), + (char **)err_codes_unix, + }, +}; diff --git a/mach/err_mach_ipc.sub b/mach/err_mach_ipc.sub new file mode 100644 index 0000000..6db64fb --- /dev/null +++ b/mach/err_mach_ipc.sub @@ -0,0 +1,119 @@ +/* + * @OSF_COPYRIGHT@ + */ + +/* + * Mach Operating System + * Copyright (c) 1991,1990,1989 Carnegie Mellon University + * All Rights Reserved. + * + * Permission to use, copy, modify and distribute this software and its + * documentation is hereby granted, provided that both the copyright + * notice and this permission notice appear in all copies of the + * software, derivative works or modified versions, and any portions + * thereof, and that both notices appear in supporting documentation. + * + * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS + * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR + * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. + * + * Carnegie Mellon requests users of this software to return to + * + * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU + * School of Computer Science + * Carnegie Mellon University + * Pittsburgh PA 15213-3890 + * + * any improvements or extensions that they make and grant Carnegie the + * rights to redistribute these changes. + */ + +/* + * File: err_mach_ipc.sub + * Author: Richard Draves, Carnegie Mellon University + * Date: Jan, 1990 + * + * Error string definitions for the new Mach IPC + */ + +static const char * err_codes_mach_send[] = { + /* 0 */ "(ipc/send) no error", + /* 1 */ "(ipc/send) send in progress", + /* 2 */ "(ipc/send) invalid data", + /* 3 */ "(ipc/send) invalid destination port", + /* 4 */ "(ipc/send) timed out", + /* 5 */ "(ipc/send) will notify", + /* 6 */ "(ipc/send) notify in progress", + /* 7 */ "(ipc/send) interrupted", + /* 8 */ "(ipc/send) msg too small", + /* 9 */ "(ipc/send) invalid reply port", + /* 10 */ "(ipc/send) invalid port right", + /* 11 */ "(ipc/send) invalid notify port", + /* 12 */ "(ipc/send) invalid memory", + /* 13 */ "(ipc/send) no msg buffer", + /* 14 */ "(ipc/send) no notify possible", + /* 15 */ "(ipc/send) invalid msg-type", + /* 16 */ "(ipc/send) invalid msg-header", + /* 17 */ "(ipc/send) invalid msg-trailer", + /* 18 */ "(ipc/send) DIPC transport failure", + /* 19 */ "(ipc/send) DIPC port migrated", + /* 20 */ "(ipc/send) DIPC resend failed", + /* 21 */ "(ipc/send) out-of-line buffer too large", +}; + +static const char * err_codes_mach_rcv[] = { + /* 0 */ "(ipc/rcv) no error", + /* 1 */ "(ipc/rcv) receive in progress", + /* 2 */ "(ipc/rcv) invalid name", + /* 3 */ "(ipc/rcv) timed out", + /* 4 */ "(ipc/rcv) msg too large", + /* 5 */ "(ipc/rcv) interrupted", + /* 6 */ "(ipc/rcv) port changed", + /* 7 */ "(ipc/rcv) invalid notify port", + /* 8 */ "(ipc/rcv) invalid data", + /* 9 */ "(ipc/rcv) port died", + /* 10 */ "(ipc/rcv) port in set", + /* 11 */ "(ipc/rcv) header error", + /* 12 */ "(ipc/rcv) body error", + /* 13 */ "(ipc/rcv) invalid scatter list entry", + /* 14 */ "(ipc/rcv) overwrite region too small", + /* 15 */ "(ipc/rcv) invalid msg-trailer", + /* 16 */ "(ipc/rcv) DIPC transport error", +}; + +static const char * err_codes_mach_mig[] = { + /* 0 */ "(ipc/mig) client type check failure", + /* 1 */ "(ipc/mig) wrong reply message ID", + /* 2 */ "(ipc/mig) server detected error", + /* 3 */ "(ipc/mig) bad request message ID", + /* 4 */ "(ipc/mig) server type check failure", + /* 5 */ "(ipc/mig) no reply should be sent", + /* 6 */ "(ipc/mig) server raised exception", + /* 7 */ "(ipc/mig) array not large enough", + /* 8 */ "(ipc/mig) server died", + /* 9 */ "(ipc/mig) unknown trailer format", +}; + +/* err_mach_ipc subsystems */ +static struct error_subsystem err_mach_ipc_sub[] = { + /* ipc/0; */ + { + (char *)"(ipc/send)", + errlib_count(err_codes_mach_send), + (char **)err_codes_mach_send, + }, + /* ipc/1; */ + { + (char *)"(ipc/rcv)", + errlib_count(err_codes_mach_rcv), + (char **)err_codes_mach_rcv, + + }, + /* ipc/2 */ + { + (char *)"(ipc/mig)", + errlib_count(err_codes_mach_mig), + (char **)err_codes_mach_mig, + }, + +}; diff --git a/mach/err_server.sub b/mach/err_server.sub new file mode 100644 index 0000000..fcbe91b --- /dev/null +++ b/mach/err_server.sub @@ -0,0 +1,357 @@ +/* + * @OSF_COPYRIGHT@ + */ + +/* + * Mach Operating System + * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University + * All Rights Reserved. + * + * Permission to use, copy, modify and distribute this software and its + * documentation is hereby granted, provided that both the copyright + * notice and this permission notice appear in all copies of the + * software, derivative works or modified versions, and any portions + * thereof, and that both notices appear in supporting documentation. + * + * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS + * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR + * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. + * + * Carnegie Mellon requests users of this software to return to + * + * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU + * School of Computer Science + * Carnegie Mellon University + * Pittsburgh PA 15213-3890 + * + * any improvements or extensions that they make and grant Carnegie the + * rights to redistribute these changes. + */ + +/* + * File: err_server.sub + * Author: Douglas Orr, Carnegie Mellon University + * Date: Mar, 1988 + * + * Definitions of Servers error strings + */ + +static const char * err_codes_netname[] = { /* 0 */ + "(server/netname) name is not yours", + "(server/netname) name not checked in", + "(server/netname) no such host", + "(server/netname) host not found", +}; +static const char * err_codes_env_mgr[] = { /* 1 */ + NO_SUCH_ERROR, + "(server/env_mgr) variable not found", + "(server/env_mgr) wrong type of variable", + "(server/env_mgr) unknown port", + "(server/env_mgr) read only environment", + "(server/env_mgr) no more connections available", + "(server/env_mgr) port table full", + "(server/env_mgr) attempting to enter a null port ", +}; +static const char * err_codes_execd[] = { /* 2 */ + NO_SUCH_ERROR, + "(server/execd) could not find file to run", + "(server/execd) userid or password incorrect", + "(server/execd) fork failed", +}; +static const char * err_codes_netmemory[] = { /* 3 */ + "(server/netmemory) successful", + "(server/netmemory) invalid argument", + "(server/netmemory) resource shortage", +}; +static const char * err_codes_ufs[] = { /* 4 */ + NO_SUCH_ERROR, +/* XXX "(server/ufs) invalid port", */ +}; + +static const char * err_codes_task_master[] = { /* 5 */ + "(server/task_master) GENERIC ERROR", + "(server/task_master) invalid tm_task port", + "(server/task_master) invalid task id", + "(server/task_master) invalid kernel port", + "(server/task_master) invalid job group", + "(server/task_master) invalid action", +}; + +static const char * err_codes_ns[] = { /* 6 */ + "(server/ns) GENERIC ERROR", + "(server/ns) invalid handle", + "(server/ns) name not found", + "(server/ns) name already exists", + "(server/ns) name too long", + "(server/ns) path too long", + "(server/ns) invalid name", + "(server/ns) not a directory", + "(server/ns) is a directory", + "(server/ns) directory not empty", + "(server/ns) infinite retry loop in resolver", + "(server/ns) infinite forwarding loop in resolver", + "(server/ns) invalid prefix", + "(server/ns) prefix table overflow", + "(server/ns) bad format for directory", + "(server/ns) unknown entry type", + "(server/ns) invalid generation", + "(server/ns) entry not reserved", +}; + +static const char * err_codes_io[] = { /* 7 */ + "(server/io) GENERIC ERROR", + "(server/io) invalid offset", + "(server/io) invalid size", + "(server/io) invalid mode", + "(server/io) invalid strategy", + "(server/io) operation rejected under current I/O strategy", +}; + +static const char * err_codes_auth[] = { /* 8 */ + "(server/auth) GENERIC ERROR", + "(server/auth) bad private port", + "(server/auth) bad name", + "(server/auth) not primary", + "(server/auth) bad pauthsword", + "(server/auth) bad group", + "(server/auth) duplicate id", + "(server/auth) duplicate name", + "(server/auth) not secondary", +}; + +static const char * err_codes_us[] = { /* 9 */ + "(server/us) GENERIC ERROR", + "(server/us) unknown error", + "(server/us) object not found", + "(server/us) object exists", + "(server/us) object busy", + "(server/us) object not started", + "(server/us) object dead", + "(server/us) invalid args", + "(server/us) invalid access", + "(server/us) invalid format", + "(server/us) invalid buffer size", + "(server/us) access denied", + "(server/us) resource exhausted", + "(server/us) quota exceeded", + "(server/us) limit exceeded", + "(server/us) not implemented", + "(server/us) not supported", + "(server/us) hardware error", + "(server/us) retry required", + "(server/us) not authenticated", + "(server/us) exclusive access", + "(server/us) timeout", + "(server/us) bad reference count", + "(server/us) internal error", +}; + +static const char * err_codes_sunrpc[] = { /* 10 */ + "(server/sunrpc) GENERIC ERROR", + "(server/sunrpc) cannot encode arguments", + "(server/sunrpc) cannot decode results", + "(server/sunrpc) failure in sending call", + "(server/sunrpc) failure in receiving result", + "(server/sunrpc) call timed out", + "(server/sunrpc) rpc versions not compatible", + "(server/sunrpc) authentication error", + "(server/sunrpc) program not available", + "(server/sunrpc) program version mismatched", + "(server/sunrpc) procedure unavailable", + "(server/sunrpc) decode arguments error", + "(server/sunrpc) generic other problem", + "(server/sunrpc) unknown host name", + "(server/sunrpc) portmapper failed", + "(server/sunrpc) remote program not registered", + "(server/sunrpc) unspecified error", + "(server/sunrpc) unknown protocol", +}; + +static const char * err_codes_machobj[] = { /* 11 */ + "(server/object system) GENERIC ERROR", + "(server/object system) object not found", + "(server/object system) no such operation", + "(server/object system) undefined ipc method arguments", + "(server/object system) too many arguments to method", + "(server/object system) bad ipc message format", +}; + +static const char * err_codes_loader[] = { /* 12 */ + "(server/loader) GENERIC ERROR", + "(server/loader) object file not relocated", + "(server/loader) unknown file type", + "(server/loader) symbol not found", + "(server/loader) symbol multiply defined", + "(server/loader) memory region overlap", +}; + + +static const char * err_codes_exception[] = { /* 13 */ + "(server/exception) GENERIC ERROR", + "(server/exception) invalid access", + "(server/exception) invalid instruction", + "(server/exception) arithmetic exception", + "(server/exception) emulation exception", + "(server/exception) software exception", + "(server/exception) breakpoint exception", +}; + +static const char * err_codes_ux_signal[] = { /* 14 */ + "(server/unix-signal) GENERIC ERROR", + "(server/unix-signal) hangup", + "(server/unix-signal) interrupt", + "(server/unix-signal) quit", + "(server/unix-signal) undefined", + "(server/unix-signal) undefined", + "(server/unix-signal) undefined", + "(server/unix-signal) undefined", + "(server/unix-signal) kill", + "(server/unix-signal) undefined", + "(server/unix-signal) undefined", + "(server/unix-signal) system error", + "(server/unix-signal) pipe signal", + "(server/unix-signal) alarm", + "(server/unix-signal) terminate", + "(server/unix-signal) urgent i/o", + "(server/unix-signal) stop", + "(server/unix-signal) terminal stop", + "(server/unix-signal) continue", + "(server/unix-signal) child death", + "(server/unix-signal) tty input", + "(server/unix-signal) tty output", + "(server/unix-signal) i/o signal", + "(server/unix-signal) cpu time limit exceeded", + "(server/unix-signal) file size exceeded", + "(server/unix-signal) virtual alarm", + "(server/unix-signal) profile signal", + "(server/unix-signal) window size change", + "(server/unix-signal) user-defined signal 1", + "(server/unix-signal) user-defined signal 2", +}; + +static const char * err_codes_xkernel[] = { /* 15 */ + "(server/xkernel) GENERIC ERROR", + "(server/xkernel) map full", + "(server/xkernel) inconsistent bind", + "(server/xkernel) cannot resolve", + "(server/xkernel) cannot unbind", + "(server/xkernel) invalid type", + "(server/xkernel) invalid opcode", + "(server/xkernel) buffer too small", + "(server/xkernel) invalid ev code", + "(server/xkernel) event not registered", + "(server/xkernel) invalid open", + "(server/xkernel) already open", + "(server/xkernel) bad addr", +}; + + +/* err_server subsystems */ +static struct error_subsystem err_server_sub[] = { + /* server/0; */ + { + (char *)"(server/netname)", + errlib_count(err_codes_netname), + (char **)err_codes_netname, + }, + /* server/1; */ + { + (char *)"(server/env_mgr)", + errlib_count(err_codes_env_mgr), + (char **)err_codes_env_mgr, + }, + /* server/2; */ + { + (char *)"(server/execd)", + errlib_count(err_codes_execd), + (char **)err_codes_execd, + }, + /* server/3; */ + { + (char *)"(server/netmemory)", + errlib_count(err_codes_netmemory), + (char **)err_codes_netmemory, + }, + /* server/4; */ + { + (char *)"(server/ufs)", + errlib_count(err_codes_ufs), + (char **)err_codes_ufs, + }, + /* server/5; */ + { + (char *)"(server/task_master)", + errlib_count(err_codes_task_master), + (char **)err_codes_task_master, + }, + /* server/6; */ + { + (char *)"(server/ns)", + errlib_count(err_codes_ns), + (char **)err_codes_ns, + }, + + /* server/7; i/o subsystem */ + { + (char *)"(server/io)", + errlib_count(err_codes_io), + (char **)err_codes_io, + }, + + /* server/8; authentication server */ + { + (char *)"(server/auth)", + errlib_count(err_codes_auth), + (char **)err_codes_auth, + }, + + /* server/9; generic US system */ + { + (char *)"(server/us)", + errlib_count(err_codes_us), + (char **)err_codes_us, + }, + + /* server/10; SUN RPC package */ + { + (char *)"(server/sunrpc)", + errlib_count(err_codes_sunrpc), + (char **)err_codes_sunrpc, + }, + + /* server/11; MachObject system */ + { + (char *)"(server/object system)", + errlib_count(err_codes_machobj), + (char **)err_codes_machobj, + }, + + /* server/12; loader */ + { + (char *)"(server/loader)", + errlib_count(err_codes_loader), + (char **)err_codes_loader, + }, + + /* server/13; mach exception */ + { + (char *)"(server/exception)", + errlib_count(err_codes_exception), + (char **)err_codes_exception, + }, + + /* server/14; unix signal */ + { + (char *)"(server/unix-signal)", + errlib_count(err_codes_ux_signal), + (char **)err_codes_ux_signal, + }, + + /* server/15; xkernel */ + { + (char *)"(server/xkernel)", + errlib_count(err_codes_xkernel), + (char **)err_codes_xkernel, + }, + +}; diff --git a/mach/err_us.sub b/mach/err_us.sub new file mode 100644 index 0000000..8db68f6 --- /dev/null +++ b/mach/err_us.sub @@ -0,0 +1,45 @@ +/* + * @OSF_COPYRIGHT@ + */ + +/* + * Mach Operating System + * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University + * All Rights Reserved. + * + * Permission to use, copy, modify and distribute this software and its + * documentation is hereby granted, provided that both the copyright + * notice and this permission notice appear in all copies of the + * software, derivative works or modified versions, and any portions + * thereof, and that both notices appear in supporting documentation. + * + * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS + * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR + * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. + * + * Carnegie Mellon requests users of this software to return to + * + * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU + * School of Computer Science + * Carnegie Mellon University + * Pittsburgh PA 15213-3890 + * + * any improvements or extensions that they make and grant Carnegie the + * rights to redistribute these changes. + */ + +/* + * File: err_us.sub + * Author: Douglas Orr, Carnegie Mellon University + * Date: Mar, 1988 + * + * A place to define User errors + */ + + +/* err_us subsystems */ +static struct error_subsystem err_us_sub[] = { + { + (char *)0, + }, +}; diff --git a/mach/error_codes.c b/mach/error_codes.c new file mode 100644 index 0000000..184969d --- /dev/null +++ b/mach/error_codes.c @@ -0,0 +1,79 @@ +/* + * @OSF_COPYRIGHT@ + */ +/* + * Mach Operating System + * Copyright (c) 1991,1990,1989 Carnegie Mellon University + * All Rights Reserved. + * + * Permission to use, copy, modify and distribute this software and its + * documentation is hereby granted, provided that both the copyright + * notice and this permission notice appear in all copies of the + * software, derivative works or modified versions, and any portions + * thereof, and that both notices appear in supporting documentation. + * + * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS + * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR + * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. + * + * Carnegie Mellon requests users of this software to return to + * + * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU + * School of Computer Science + * Carnegie Mellon University + * Pittsburgh PA 15213-3890 + * + * any improvements or extensions that they make and grant Carnegie the + * rights to redistribute these changes. + */ + +/* + * File: error_codes.c + * Author: Douglas Orr, Carnegie Mellon University + * Date: Mar, 1988 + * + * Generic error code interface + */ + +#include +#include "errorlib.h" +#include "err_kern.sub" +#include "err_us.sub" +#include "err_server.sub" +#include "err_ipc.sub" +#include "err_mach_ipc.sub" + +__private_extern__ struct error_system _mach_errors[err_max_system+1] = { + /* 0; err_kern */ + { + errlib_count(err_os_sub), + (char *)"(operating system/?) unknown subsystem error", + err_os_sub, + }, + /* 1; err_us */ + { + errlib_count(err_us_sub), + (char *)"(user space/?) unknown subsystem error", + err_us_sub, + }, + /* 2; err_server */ + { + errlib_count(err_server_sub), + (char *)"(server/?) unknown subsystem error", + err_server_sub, + }, + /* 3 (& 3f); err_ipc */ + { + errlib_count(err_ipc_sub), + (char *)"(ipc/?) unknown subsystem error", + err_ipc_sub, + }, + /* 4; err_mach_ipc */ + { + errlib_count(err_mach_ipc_sub), + (char *)"(ipc/?) unknown subsystem error", + err_mach_ipc_sub, + }, +}; + +int error_system_count = errlib_count(_mach_errors); diff --git a/mach/errorlib.h b/mach/errorlib.h new file mode 100644 index 0000000..df06289 --- /dev/null +++ b/mach/errorlib.h @@ -0,0 +1,73 @@ +/* + * @OSF_COPYRIGHT@ + */ + +/* + * Mach Operating System + * Copyright (c) 1991,1990,1989 Carnegie Mellon University + * All Rights Reserved. + * + * Permission to use, copy, modify and distribute this software and its + * documentation is hereby granted, provided that both the copyright + * notice and this permission notice appear in all copies of the + * software, derivative works or modified versions, and any portions + * thereof, and that both notices appear in supporting documentation. + * + * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS + * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR + * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. + * + * Carnegie Mellon requests users of this software to return to + * + * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU + * School of Computer Science + * Carnegie Mellon University + * Pittsburgh PA 15213-3890 + * + * any improvements or extensions that they make and grant Carnegie the + * rights to redistribute these changes. + */ + +/* + * File: errorlib.h + * Author: Douglas Orr, Carnegie Mellon University + * Date: Mar. 1988 + * + * Error bases for subsytems errors. + */ + +#include +#include + +#define MACH_IPC_SEND_MOD (err_mach_ipc|err_sub(0)) +#define MACH_IPC_RCV_MOD (err_mach_ipc|err_sub(1)) +#define MACH_IPC_MIG_MOD (err_mach_ipc|err_sub(2)) + +#define IPC_SEND_MOD (err_ipc|err_sub(0)) +#define IPC_RCV_MOD (err_ipc|err_sub(1)) +#define IPC_MIG_MOD (err_ipc|err_sub(2)) + +#define SERV_NETNAME_MOD (err_server|err_sub(0)) +#define SERV_ENV_MOD (err_server|err_sub(1)) +#define SERV_EXECD_MOD (err_server|err_sub(2)) + + +#define NO_SUCH_ERROR "unknown error code" + +struct error_subsystem { + char * subsys_name; + int max_code; + char * * codes; +}; + +struct error_system { + int max_sub; + char * bad_sub; + struct error_subsystem * subsystem; +}; + +__private_extern__ struct error_system _mach_errors[err_max_system+1]; + +__private_extern__ char *mach_error_string_int(mach_error_t, boolean_t *); + +#define errlib_count(s) (sizeof(s)/sizeof(s[0])) diff --git a/mach/exc.defs b/mach/exc.defs new file mode 100644 index 0000000..9bdb234 --- /dev/null +++ b/mach/exc.defs @@ -0,0 +1,23 @@ +/* + * Copyright (c) 1999 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@ + */ +#define catch_ internal_catch_ +#include diff --git a/mach/exc_catcher.c b/mach/exc_catcher.c new file mode 100644 index 0000000..1125ed3 --- /dev/null +++ b/mach/exc_catcher.c @@ -0,0 +1,60 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * catch_exception_raise will be implemented by user programs + * This implementation is provided to resolve the reference in + * exc_server(). + */ + +#include +#include +#include +#include +#include + +__private_extern__ kern_return_t internal_catch_exception_raise ( + mach_port_t exception_port, + mach_port_t thread, + mach_port_t task, + exception_type_t exception, + exception_data_t code, + mach_msg_type_number_t codeCnt) +{ +#if defined(__DYNAMIC__) + static int checkForFunction = 0; + /* This will be non-zero if the user has defined this function */ + static kern_return_t (*func)(mach_port_t, mach_port_t, mach_port_t, exception_type_t, exception_data_t, mach_msg_type_number_t); + if (checkForFunction == 0) { + checkForFunction = 1; + _dyld_lookup_and_bind("_catch_exception_raise", (unsigned long *)&func, (void **)0); + } + if (func == 0) { + /* The user hasn't defined catch_exception_raise in their binary */ + abort(); + } + return (*func)(exception_port, thread, task, exception, code, codeCnt); +#else + extern kern_return_t catch_exception_raise(mach_port_t, mach_port_t, mach_port_t, exception_type_t, exception_data_t, mach_msg_type_number_t); + return catch_exception_raise(exception_port, thread, task, exception, code, codeCnt); +#endif +} + diff --git a/mach/exc_catcher_state.c b/mach/exc_catcher_state.c new file mode 100644 index 0000000..61cefb3 --- /dev/null +++ b/mach/exc_catcher_state.c @@ -0,0 +1,62 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * catch_exception_raise_state will be implemented by user programs + * This implementation is provided to resolve the reference in + * exc_server(). + */ + +#include +#include +#include +#include +#include + +__private_extern__ kern_return_t internal_catch_exception_raise_state ( + mach_port_t exception_port, + exception_type_t exception, + exception_data_t code, + mach_msg_type_number_t codeCnt, + int *flavor, + thread_state_t old_state, + mach_msg_type_number_t old_stateCnt, + thread_state_t new_state, + mach_msg_type_number_t *new_stateCnt) +{ +#if defined(__DYNAMIC__) + static int checkForFunction = 0; + /* This will be non-zero if the user has defined this function */ + static kern_return_t (*func)(mach_port_t, exception_type_t, exception_data_t, mach_msg_type_number_t, int *, thread_state_t, mach_msg_type_number_t, thread_state_t, mach_msg_type_number_t *); + if (checkForFunction == 0) { + checkForFunction = 1; + _dyld_lookup_and_bind("_catch_exception_raise_state", (unsigned long *)&func, (void **)0); + } + if (func == 0) { + /* The user hasn't defined catch_exception_raise in their binary */ + abort(); + } + return (*func)(exception_port, exception, code, codeCnt, flavor, old_state, old_stateCnt, new_state, new_stateCnt); +#else + extern kern_return_t catch_exception_raise_state(mach_port_t, exception_type_t, exception_data_t, mach_msg_type_number_t, int *, thread_state_t, mach_msg_type_number_t, thread_state_t, mach_msg_type_number_t *); + return catch_exception_raise_state(exception_port, exception, code, codeCnt, flavor, old_state, old_stateCnt, new_state, new_stateCnt); +#endif +} diff --git a/mach/exc_catcher_state_identity.c b/mach/exc_catcher_state_identity.c new file mode 100644 index 0000000..ac2ea37 --- /dev/null +++ b/mach/exc_catcher_state_identity.c @@ -0,0 +1,64 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * catch_exception_raise_state_identity will be implemented by user programs + * This implementation is provided to resolve the reference in + * exc_server(). + */ + +#include +#include +#include +#include +#include + +__private_extern__ kern_return_t internal_catch_exception_raise_state_identity ( + mach_port_t exception_port, + mach_port_t thread, + mach_port_t task, + exception_type_t exception, + exception_data_t code, + mach_msg_type_number_t codeCnt, + int *flavor, + thread_state_t old_state, + mach_msg_type_number_t old_stateCnt, + thread_state_t new_state, + mach_msg_type_number_t *new_stateCnt) +{ +#if defined(__DYNAMIC__) + static int checkForFunction = 0; + /* This will be non-zero if the user has defined this function */ + static kern_return_t (*func)(mach_port_t, mach_port_t, mach_port_t, exception_type_t, exception_data_t, mach_msg_type_number_t, int *, thread_state_t, mach_msg_type_number_t, thread_state_t, mach_msg_type_number_t *); + if (checkForFunction == 0) { + checkForFunction = 1; + _dyld_lookup_and_bind("_catch_exception_raise_state_identity", (unsigned long *)&func, (void **)0); + } + if (func == 0) { + /* The user hasn't defined catch_exception_raise in their binary */ + abort(); + } + return (*func)(exception_port, thread, task, exception, code, codeCnt, flavor, old_state, old_stateCnt, new_state, new_stateCnt); +#else + extern kern_return_t catch_exception_raise_state_identity(mach_port_t, mach_port_t, mach_port_t, exception_type_t, exception_data_t, mach_msg_type_number_t, int *, thread_state_t, mach_msg_type_number_t, thread_state_t, mach_msg_type_number_t *); + return catch_exception_raise_state_identity(exception_port, thread, task, exception, code, codeCnt, flavor, old_state, old_stateCnt, new_state, new_stateCnt); +#endif +} diff --git a/mach/externs.h b/mach/externs.h new file mode 100644 index 0000000..515646f --- /dev/null +++ b/mach/externs.h @@ -0,0 +1,14 @@ +/* + * @OSF_COPYRIGHT@ + */ + +#include +#include +#include +#include + +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); + diff --git a/mach/fprintf_stderr.c b/mach/fprintf_stderr.c new file mode 100644 index 0000000..a2f70f7 --- /dev/null +++ b/mach/fprintf_stderr.c @@ -0,0 +1,35 @@ +/* + * @OSF_FREE_COPYRIGHT@ + * + */ + +#include +#include +#include +#include + +int (*vprintf_stderr_func)(const char *format, va_list ap); + + +/* This function allows the writing of a mach error message to an + * application-controllable output method, the default being to + * use printf if no other method is specified by the application. + * + * To override, set the global (static) function pointer vprintf_stderr to + * a function which takes the same parameters as vprintf. + */ + +int fprintf_stderr(const char *format, ...) +{ + va_list args; + int retval; + + va_start(args, format); + if (vprintf_stderr_func == NULL) + retval = vprintf(format, args); + else + retval = (*vprintf_stderr_func)(format, args); + va_end(args); + + return retval; +} diff --git a/mach/headers/Makefile.inc b/mach/headers/Makefile.inc new file mode 100644 index 0000000..a01b9f7 --- /dev/null +++ b/mach/headers/Makefile.inc @@ -0,0 +1,8 @@ +MACH_INSTHDRS += mach.h \ + mach_error.h \ + mach_init.h \ + mach_interface.h \ + port_obj.h \ + sync.h \ + vm_task.h +MACH_INSTHDRS := ${MACH_INSTHDRS:S/^/${.CURDIR}\/mach\/headers\//} diff --git a/mach/headers/errorlib.h b/mach/headers/errorlib.h new file mode 100644 index 0000000..aa270da --- /dev/null +++ b/mach/headers/errorlib.h @@ -0,0 +1,70 @@ +/* + * @OSF_COPYRIGHT@ + */ + +/* + * Mach Operating System + * Copyright (c) 1991,1990,1989 Carnegie Mellon University + * All Rights Reserved. + * + * Permission to use, copy, modify and distribute this software and its + * documentation is hereby granted, provided that both the copyright + * notice and this permission notice appear in all copies of the + * software, derivative works or modified versions, and any portions + * thereof, and that both notices appear in supporting documentation. + * + * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS + * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR + * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. + * + * Carnegie Mellon requests users of this software to return to + * + * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU + * School of Computer Science + * Carnegie Mellon University + * Pittsburgh PA 15213-3890 + * + * any improvements or extensions that they make and grant Carnegie the + * rights to redistribute these changes. + */ + +/* + * File: errorlib.h + * Author: Douglas Orr, Carnegie Mellon University + * Date: Mar. 1988 + * + * Error bases for subsytems errors. + */ + +#include + +#define MACH_IPC_SEND_MOD (err_mach_ipc|err_sub(0)) +#define MACH_IPC_RCV_MOD (err_mach_ipc|err_sub(1)) +#define MACH_IPC_MIG_MOD (err_mach_ipc|err_sub(2)) + +#define IPC_SEND_MOD (err_ipc|err_sub(0)) +#define IPC_RCV_MOD (err_ipc|err_sub(1)) +#define IPC_MIG_MOD (err_ipc|err_sub(2)) + +#define SERV_NETNAME_MOD (err_server|err_sub(0)) +#define SERV_ENV_MOD (err_server|err_sub(1)) +#define SERV_EXECD_MOD (err_server|err_sub(2)) + + +#define NO_SUCH_ERROR "unknown error code" + +struct error_subsystem { + char * subsys_name; + int max_code; + char * * codes; +}; + +struct error_system { + int max_sub; + char * bad_sub; + struct error_subsystem * subsystem; +}; + +extern struct error_system errors[err_max_system+1]; + +#define errlib_count(s) (sizeof(s)/sizeof(s[0])) diff --git a/mach/headers/mach.h b/mach/headers/mach.h new file mode 100644 index 0000000..d37344e --- /dev/null +++ b/mach/headers/mach.h @@ -0,0 +1,126 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Mach Operating System + * Copyright (c) 1991,1990,1989 Carnegie Mellon University + * All Rights Reserved. + * + * Permission to use, copy, modify and distribute this software and its + * documentation is hereby granted, provided that both the copyright + * notice and this permission notice appear in all copies of the + * software, derivative works or modified versions, and any portions + * thereof, and that both notices appear in supporting documentation. + * + * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" + * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR + * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. + * + * Carnegie Mellon requests users of this software to return to + * + * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU + * School of Computer Science + * Carnegie Mellon University + * Pittsburgh PA 15213-3890 + * + * any improvements or extensions that they make and grant Carnegie Mellon + * the rights to redistribute these changes. + */ + +/* + * Includes all the types that a normal user + * of Mach programs should need + */ + +#ifndef _MACH_H_ +#define _MACH_H_ + +#define __MACH30__ +#define MACH_IPC_FLAVOR UNTYPED + +#include +#include +#include +#include +#include +#include +#include + +#include /* for compatibility only */ +#include +#include + +/* + * Standard prototypes + */ +extern void panic_init(mach_port_t); +extern void panic(const char *, ...); + +extern void safe_gets(char *, + char *, + int); + +extern void slot_name(cpu_type_t, + cpu_subtype_t, + char **, + char **); + +extern void mig_reply_setup(mach_msg_header_t *, + mach_msg_header_t *); + +extern void mach_msg_destroy(mach_msg_header_t *); + +extern mach_msg_return_t mach_msg_receive(mach_msg_header_t *); + +extern mach_msg_return_t mach_msg_send(mach_msg_header_t *); + +extern mach_msg_return_t mach_msg_server_once(boolean_t (*) + (mach_msg_header_t *, + mach_msg_header_t *), + mach_msg_size_t, + mach_port_t, + mach_msg_options_t); +extern mach_msg_return_t mach_msg_server(boolean_t (*) + (mach_msg_header_t *, + mach_msg_header_t *), + mach_msg_size_t, + mach_port_t, + mach_msg_options_t); + +#ifdef MACH_KERNEL +extern void *sbrk(int); + +extern int brk(void *); + +#endif +/* + * Prototypes for compatibility + */ +extern kern_return_t clock_get_res(mach_port_t, + clock_res_t *); +extern kern_return_t clock_set_res(mach_port_t, + clock_res_t); + +extern kern_return_t clock_sleep(mach_port_t, + int, + mach_timespec_t, + mach_timespec_t *); +#endif /* _MACH_H_ */ diff --git a/mach/headers/mach_error.h b/mach/headers/mach_error.h new file mode 100644 index 0000000..b60fcf9 --- /dev/null +++ b/mach/headers/mach_error.h @@ -0,0 +1,83 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Mach Operating System + * Copyright (c) 1991,1990,1989 Carnegie Mellon University + * All Rights Reserved. + * + * Permission to use, copy, modify and distribute this software and its + * documentation is hereby granted, provided that both the copyright + * notice and this permission notice appear in all copies of the + * software, derivative works or modified versions, and any portions + * thereof, and that both notices appear in supporting documentation. + * + * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS + * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR + * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. + * + * Carnegie Mellon requests users of this software to return to + * + * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU + * School of Computer Science + * Carnegie Mellon University + * Pittsburgh PA 15213-3890 + * + * any improvements or extensions that they make and grant Carnegie the + * rights to redistribute these changes. + */ + +/* + * File: mach_error.h + * Author: Douglas Orr, Carnegie Mellon University + * Date: Mar. 1988 + * + * Definitions of routines in mach_error.c + */ + +#ifndef _MACH_ERROR_ +#define _MACH_ERROR_ 1 + +#include + +char *mach_error_string( +/* + * Returns a string appropriate to the error argument given + */ + mach_error_t error_value + ); + +void mach_error( +/* + * Prints an appropriate message on the standard error stream + */ + char *str, + mach_error_t error_value + ); + +char *mach_error_type( +/* + * Returns a string with the error system, subsystem and code + */ + mach_error_t error_value + ); + +#endif /* _MACH_ERROR_ */ diff --git a/mach/headers/mach_init.h b/mach/headers/mach_init.h new file mode 100644 index 0000000..c9521cf --- /dev/null +++ b/mach/headers/mach_init.h @@ -0,0 +1,112 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Mach Operating System + * Copyright (c) 1991,1990,1989,1988,1987,1986 Carnegie Mellon University + * All Rights Reserved. + * + * Permission to use, copy, modify and distribute this software and its + * documentation is hereby granted, provided that both the copyright + * notice and this permission notice appear in all copies of the + * software, derivative works or modified versions, and any portions + * thereof, and that both notices appear in supporting documentation. + * + * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" + * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR + * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. + * + * Carnegie Mellon requests users of this software to return to + * + * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU + * School of Computer Science + * Carnegie Mellon University + * Pittsburgh PA 15213-3890 + * + * any improvements or extensions that they make and grant Carnegie Mellon + * the rights to redistribute these changes. + */ + +/* + * Items provided by the Mach environment initialization. + */ + +#ifndef _MACH_INIT_ +#define _MACH_INIT_ 1 + +#include +#include + +/* + * Kernel-related ports; how a task/thread controls itself + */ + +extern mach_port_t mach_task_self_; + +extern mach_port_t mach_task_self(void); +extern mach_port_t mach_host_self(void); +extern mach_port_t mach_thread_self(void); + +#define mach_task_self() mach_task_self_ + +#define current_task() mach_task_self() + +#include +/* + * Other important ports in the Mach user environment + */ + +extern mach_port_t bootstrap_port; +extern mach_port_t name_server_port; +extern mach_port_t environment_port; +extern mach_port_t service_port; + +/* + * Where these ports occur in the "mach_ports_register" + * collection... only servers or the runtime library need know. + */ + +#define NAME_SERVER_SLOT 0 +#define ENVIRONMENT_SLOT 1 +#define SERVICE_SLOT 2 + +#define MACH_PORTS_SLOTS_USED 3 + +/* + * Globally interesting numbers. + * These macros assume vm_page_size is a power-of-2. + */ + +extern vm_size_t vm_page_size; + +#define trunc_page(x) ((x) & (~(vm_page_size - 1))) +#define round_page(x) trunc_page((x) + (vm_page_size - 1)) + +/* + * fprintf_stderr uses vprintf_stderr_func to produce + * error messages, this can be overridden by a user + * application to point to a user-specified output function + */ + +extern int (*vprintf_stderr_func)(const char *format, va_list ap); + + +#endif /* _MACH_INIT_ */ diff --git a/mach/headers/mach_interface.h b/mach/headers/mach_interface.h new file mode 100644 index 0000000..6373e90 --- /dev/null +++ b/mach/headers/mach_interface.h @@ -0,0 +1,27 @@ +/* + * Copyright (C) Apple Computer 1998 + * ALL Rights Reserved + */ +/* + * This file represents the interfaces that used to come + * from creating the user headers from the mach.defs file. + * Because mach.defs was decomposed, this file now just + * wraps up all the new interface headers generated from + * each of the new .defs resulting from that decomposition. + */ +#ifndef _MACH_INTERFACE_H_ +#define _MACH_INTERFACE_H_ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#endif /* _MACH_INTERFACE_H_ */ diff --git a/mach/headers/port_obj.h b/mach/headers/port_obj.h new file mode 100644 index 0000000..796972c --- /dev/null +++ b/mach/headers/port_obj.h @@ -0,0 +1,71 @@ +/* + * @OSF_COPYRIGHT@ + */ + +/* + * Define a service to map from a kernel-generated port name + * to server-defined "type" and "value" data to be associated + * with the port. + */ + +#ifndef PORT_OBJ_H +#define PORT_OBJ_H + +#include + +struct port_obj_tentry { + void *pos_value; + int pos_type; +}; + +extern void port_obj_init(int); +extern struct port_obj_tentry *port_obj_table; +extern int port_obj_table_size; + +#ifndef PORT_OBJ_ASSERT + +#define port_set_obj_value_type(pname, value, type) \ +do { \ + int ndx; \ + \ + if (!port_obj_table) \ + port_obj_init(port_obj_table_size); \ + ndx = MACH_PORT_INDEX(pname); \ + port_obj_table[ndx].pos_value = (value); \ + port_obj_table[ndx].pos_type = (type); \ +} while (0) + +#define port_get_obj_value(pname) \ + (port_obj_table[MACH_PORT_INDEX(pname)].pos_value) + +#define port_get_obj_type(pname) \ + (port_obj_table[MACH_PORT_INDEX(pname)].pos_type) + +#else /* PORT_OBJ_ASSERT */ + +#define port_set_obj_value_type(pname, value, type) \ +do { \ + int ndx; \ + \ + if (!port_obj_table) \ + port_obj_init(port_obj_table_size); \ + ndx = MACH_PORT_INDEX(pname); \ + assert(ndx > 0); \ + assert(ndx < port_obj_table_size); \ + port_obj_table[ndx].pos_value = (value); \ + port_obj_table[ndx].pos_type = (type); \ +} while (0) + +#define port_get_obj_value(pname) \ + ((MACH_PORT_INDEX(pname) < (unsigned)port_obj_table_size) ? \ + port_obj_table[MACH_PORT_INDEX(pname)].pos_value : \ + (panic("port_get_obj_value: index too big"), (void *)-1)) + +#define port_get_obj_type(pname) \ + ((MACH_PORT_INDEX(pname) < (unsigned)port_obj_table_size) ? \ + port_obj_table[MACH_PORT_INDEX(pname)].pos_type : \ + (panic("port_get_obj_type: index too big"), -1)) + +#endif /* PORT_OBJ_ASSERT */ + +#endif /* PORT_OBJ_H */ diff --git a/mach/headers/sync.h b/mach/headers/sync.h new file mode 100644 index 0000000..e327d10 --- /dev/null +++ b/mach/headers/sync.h @@ -0,0 +1,29 @@ +/* + * Copyright (c) 1999 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@ + */ +/* +** This file contains compatibilty wrapper header for things that used +** to be generated from mach/sync.defs. Now that code is split into two +** different interface generator files, so include the two resulting +** headers here. +*/ +#include +#include diff --git a/mach/headers/vm_task.h b/mach/headers/vm_task.h new file mode 100644 index 0000000..8ae7856 --- /dev/null +++ b/mach/headers/vm_task.h @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2000 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@ + */ +/* +** This file contains compatibilty wrapper header for things that are +** generated from mach/vm_map.defs into mach/vm_map.h. +** +** This file will go away eventually - please switch. +*/ +#include diff --git a/mach/host_priv.defs b/mach/host_priv.defs new file mode 100644 index 0000000..060900d --- /dev/null +++ b/mach/host_priv.defs @@ -0,0 +1 @@ +#include diff --git a/mach/host_security.defs b/mach/host_security.defs new file mode 100644 index 0000000..96999e5 --- /dev/null +++ b/mach/host_security.defs @@ -0,0 +1 @@ +#include diff --git a/mach/ledger.defs b/mach/ledger.defs new file mode 100644 index 0000000..c7e9270 --- /dev/null +++ b/mach/ledger.defs @@ -0,0 +1 @@ +#include diff --git a/mach/lock_set.defs b/mach/lock_set.defs new file mode 100644 index 0000000..c62bb42 --- /dev/null +++ b/mach/lock_set.defs @@ -0,0 +1 @@ +#include diff --git a/mach/mach_error.c b/mach/mach_error.c new file mode 100644 index 0000000..5d95954 --- /dev/null +++ b/mach/mach_error.c @@ -0,0 +1,79 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Mach Operating System + * Copyright (c) 1991,1990,1989 Carnegie Mellon University + * All Rights Reserved. + * + * Permission to use, copy, modify and distribute this software and its + * documentation is hereby granted, provided that both the copyright + * notice and this permission notice appear in all copies of the + * software, derivative works or modified versions, and any portions + * thereof, and that both notices appear in supporting documentation. + * + * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" + * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR + * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. + * + * Carnegie Mellon requests users of this software to return to + * + * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU + * School of Computer Science + * Carnegie Mellon University + * Pittsburgh PA 15213-3890 + * + * any improvements or extensions that they make and grant Carnegie Mellon + * the rights to redistribute these changes. + */ + +/* + * File: mach_error.c + * Author: Douglas Orr, Carnegie Mellon University + * Date: Mar 1988 + * + * interprets structured mach error codes and prints + * or returns a descriptive string. + */ + +#include +#include +#include +#include "errorlib.h" + +void +mach_error( str, err ) + char *str; + mach_error_t err; +{ + char * err_str; + char buf[1024]; + boolean_t diag; + + err_str=mach_error_string_int(err, &diag); + + if ( diag ) { + sprintf( buf, "%s %s (%x)", mach_error_type(err), err_str, err ); + err_str = buf; + } + + fprintf_stderr("%s %s\n", str, err_str); +} diff --git a/mach/mach_error_string.c b/mach/mach_error_string.c new file mode 100644 index 0000000..5934f1c --- /dev/null +++ b/mach/mach_error_string.c @@ -0,0 +1,113 @@ +/* + * @OSF_COPYRIGHT@ + */ +/* + * Mach Operating System + * Copyright (c) 1991,1990,1989 Carnegie Mellon University + * All Rights Reserved. + * + * Permission to use, copy, modify and distribute this software and its + * documentation is hereby granted, provided that both the copyright + * notice and this permission notice appear in all copies of the + * software, derivative works or modified versions, and any portions + * thereof, and that both notices appear in supporting documentation. + * + * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" + * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR + * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. + * + * Carnegie Mellon requests users of this software to return to + * + * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU + * School of Computer Science + * Carnegie Mellon University + * Pittsburgh PA 15213-3890 + * + * any improvements or extensions that they make and grant Carnegie Mellon + * the rights to redistribute these changes. + */ + +#include +#include +#include + +#include "errorlib.h" +#include "externs.h" + +static void do_compat(mach_error_t *); + +static void +do_compat(mach_error_t *org_err) +{ + mach_error_t err = *org_err; + + /* + * map old error numbers to + * to new error sys & subsystem + */ + + if ((-200 < err) && (err <= -100)) + err = -(err + 100) | IPC_SEND_MOD; + else if ((-300 < err) && (err <= -200)) + err = -(err + 200) | IPC_RCV_MOD; + else if ((-400 < err) && (err <= -300)) + err = -(err + 300) | MACH_IPC_MIG_MOD; + else if ((1000 <= err) && (err < 1100)) + err = (err - 1000) | SERV_NETNAME_MOD; + else if ((1600 <= err) && (err < 1700)) + err = (err - 1600) | SERV_ENV_MOD; + else if ((27600 <= err) && (err < 27700)) + err = (err - 27600) | SERV_EXECD_MOD; + + *org_err = err; +} + +char * +mach_error_type(mach_error_t err) +{ + int sub, system; + + do_compat( &err ); + + sub = err_get_sub(err); + system = err_get_system(err); + + if (system > err_max_system || sub >= _mach_errors[system].max_sub) + return((char *)"(?/?)"); + return(_mach_errors[system].subsystem[sub].subsys_name); +} + +boolean_t mach_error_full_diag = FALSE; + +__private_extern__ char * +mach_error_string_int(mach_error_t err, boolean_t *diag) +{ + int sub, system, code; + + do_compat( &err ); + + sub = err_get_sub(err); + system = err_get_system(err); + code = err_get_code(err); + + *diag = TRUE; + + if (system > err_max_system) + return((char *)"(?/?) unknown error system"); + if (sub >= _mach_errors[system].max_sub) + return(_mach_errors[system].bad_sub); + if (code >= _mach_errors[system].subsystem[sub].max_code) + return ((char *)NO_SUCH_ERROR); + + *diag = mach_error_full_diag; + return( _mach_errors[system].subsystem[sub].codes[code] ); +} + +char * +mach_error_string(mach_error_t err) +{ + boolean_t diag; + + return mach_error_string_int( err, &diag ); + +} diff --git a/mach/mach_host.defs b/mach/mach_host.defs new file mode 100644 index 0000000..e3d6c22 --- /dev/null +++ b/mach/mach_host.defs @@ -0,0 +1,22 @@ +/* + * Copyright (c) 1999 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@ + */ +#include diff --git a/mach/mach_init.c b/mach/mach_init.c new file mode 100644 index 0000000..8bb2f53 --- /dev/null +++ b/mach/mach_init.c @@ -0,0 +1,227 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Mach Operating System + * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University + * All Rights Reserved. + * + * Permission to use, copy, modify and distribute this software and its + * documentation is hereby granted, provided that both the copyright + * notice and this permission notice appear in all copies of the + * software, derivative works or modified versions, and any portions + * thereof, and that both notices appear in supporting documentation. + * + * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" + * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR + * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. + * + * Carnegie Mellon requests users of this software to return to + * + * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU + * School of Computer Science + * Carnegie Mellon University + * Pittsburgh PA 15213-3890 + * + * any improvements or extensions that they make and grant Carnegie Mellon + * the rights to redistribute these changes. + */ + +#include +#include +#include +#include +#include +#include +#include "externs.h" + +mach_port_t mach_task_self_ = MACH_PORT_NULL; +mach_port_t mach_host_self_ = MACH_PORT_NULL; + +__private_extern__ kern_return_t _host_mach_msg_trap_return_; + +vm_size_t vm_page_size; + +/* + * Forward internal declarations for automatic mach_init during + * fork() implementation. + */ +/* fork() calls through atfork_child_routine */ +void (*_atfork_child_routine)(void); + +static void mach_atfork_child_routine(void); +static boolean_t first = TRUE; +static void (*previous_atfork_child_routine)(void); +extern int mach_init(void); +extern void _pthread_set_self(void *); +extern void cthread_set_self(void *); + + +static void mach_atfork_child_routine(void) +{ + /* + * If an (*_atfork_child_routine)() was registered when + * mach_init was first called, then call that routine + * prior to performing our re-initialization. This ensures + * that the post-fork handlers are called in exactly the + * same order as the crt0 (exec) handlers. Any library + * that makes use of the _atfork_child_routine must follow + * the same technique. + */ + if (previous_atfork_child_routine) { + (*previous_atfork_child_routine)(); + } + mach_init(); +} + +mach_port_t +mach_host_self() +{ + return(host_self_trap()); +} + +int mach_init_doit(int forkchild) +{ + mach_msg_type_number_t host_info_size; + host_t host; + + /* + * Get the important ports into the cached values, + * as required by "mach_init.h". + */ + + mach_task_self_ = task_self_trap(); + host = host_self_trap(); + + + if (!forkchild) { + /* + * Set up the post-fork child handler in the libc stub + * to invoke this routine if this process forks. Save the + * previous value in order that we can call that handler + * prior to performing our postfork work. + */ + + first = FALSE; + previous_atfork_child_routine = _atfork_child_routine; + _atfork_child_routine = mach_atfork_child_routine; + _pthread_set_self(0); + cthread_set_self(0); + } + + /* + * Initialize the single mig reply port + */ + + mig_init(0); + + /* + * Cache some other valuable system constants + */ + +#ifdef HOST_MACH_MSG_TRAP + host_info_size = 0; + _host_mach_msg_trap_return_ = host_info(host, + HOST_MACH_MSG_TRAP, + 0, + &host_info_size); +#endif + + (void)host_page_size(host, &vm_page_size); + + mach_port_deallocate(mach_task_self_, host); + + mach_init_ports(); + +#if WE_REALLY_NEED_THIS_GDB_HACK + /* + * Check to see if GDB wants us to stop + */ + { + task_user_data_data_t user_data; + mach_msg_type_number_t user_data_count = TASK_USER_DATA_COUNT; + + user_data.user_data = 0; + (void)task_info(mach_task_self_, TASK_USER_DATA, + (task_info_t)&user_data, &user_data_count); +#define MACH_GDB_RUN_MAGIC_NUMBER 1 +#ifdef MACH_GDB_RUN_MAGIC_NUMBER + /* This magic number is set in mach-aware gdb + * for RUN command to allow us to suspend user's + * executable (linked with this libmach!) + * with the code below. + * This hack should disappear when gdb improves. + */ + if ((int)user_data.user_data == MACH_GDB_RUN_MAGIC_NUMBER) { + kern_return_t ret; + user_data.user_data = 0; + + ret = task_suspend (mach_task_self_); + if (ret != KERN_SUCCESS) { + while(1) (void)task_terminate(mach_task_self_); + } + } +#undef MACH_GDB_RUN_MAGIC_NUMBER +#endif /* MACH_GDB_RUN_MAGIC_NUMBER */ + } +#endif /* WE_REALLY_NEED_THIS_GDB_HACK */ + + /* + * Reserve page 0 so that the program doesn't get it as + * the result of a vm_allocate() or whatever. + */ + { + vm_offset_t zero_page_start; + + zero_page_start = 0; + (void)vm_map(mach_task_self_, &zero_page_start, vm_page_size, + 0, FALSE, MEMORY_OBJECT_NULL, 0, TRUE, + VM_PROT_NONE, VM_PROT_NONE, VM_INHERIT_COPY); + /* ignore result, we don't care if it failed */ + } + return(0); +} + +int mach_init(void) +{ + return(mach_init_doit(0)); +} + +int (*mach_init_routine)(void) = mach_init; +int fork_mach_init() +{ + /* called only from child */ + return(mach_init_doit(1)); +} + +#undef mach_task_self + +mach_port_t +mach_task_self() +{ + return(task_self_trap()); +} + +mach_port_t +mach_thread_self() +{ + return(thread_self_trap()); +} diff --git a/mach/mach_init_ports.c b/mach/mach_init_ports.c new file mode 100644 index 0000000..b178e57 --- /dev/null +++ b/mach/mach_init_ports.c @@ -0,0 +1,104 @@ +/* + * @OSF_COPYRIGHT@ + */ + +/* + * Mach Operating System + * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University + * All Rights Reserved. + * + * Permission to use, copy, modify and distribute this software and its + * documentation is hereby granted, provided that both the copyright + * notice and this permission notice appear in all copies of the + * software, derivative works or modified versions, and any portions + * thereof, and that both notices appear in supporting documentation. + * + * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" + * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR + * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. + * + * Carnegie Mellon requests users of this software to return to + * + * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU + * School of Computer Science + * Carnegie Mellon University + * Pittsburgh PA 15213-3890 + * + * any improvements or extensions that they make and grant Carnegie Mellon + * the rights to redistribute these changes. + */ + +#include +#include "externs.h" + +mach_port_t bootstrap_port = MACH_PORT_NULL; +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; +mach_port_t clock_port = MACH_PORT_NULL; +mach_port_t thread_recycle_port = MACH_PORT_NULL; + +void +mach_init_ports(void) +{ + mach_port_array_t ports; + mach_msg_type_number_t ports_count; + kern_return_t kr; + host_t host; + + /* + * Find those ports important to every task. + */ + kr = task_get_special_port(mach_task_self(), + TASK_BOOTSTRAP_PORT, + &bootstrap_port); + if (kr != KERN_SUCCESS) + return; + + kr = mach_ports_lookup(mach_task_self(), &ports, + &ports_count); + if ((kr != KERN_SUCCESS) || + (ports_count < MACH_PORTS_SLOTS_USED)) + return; + + name_server_port = ports[NAME_SERVER_SLOT]; + environment_port = ports[ENVIRONMENT_SLOT]; + service_port = ports[SERVICE_SLOT]; + + /* get rid of out-of-line data so brk has a chance of working */ + + (void) vm_deallocate(mach_task_self(), + (vm_offset_t) ports, + (vm_size_t) (ports_count * sizeof *ports)); + + /* 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(); + } + mach_port_deallocate(mach_task_self(), host); + kr = mach_port_allocate(mach_task_self(), MACH_PORT_RIGHT_RECEIVE, &thread_recycle_port); + if (kr != KERN_SUCCESS) { + abort(); + } +} + +#ifdef notdef +/* will have problems with dylib build --> not needed anyway */ +#ifndef lint +/* + * Routines which our library must suck in, to avoid + * a later library from referencing them and getting + * the wrong version. + */ +extern void _replacements(void); + +void +_replacements(void) +{ + (void)sbrk(0); /* Pull in our sbrk/brk */ + (void)malloc(0); /* Pull in our malloc package */ +} +#endif /* lint */ +#endif /* notdef */ diff --git a/mach/mach_msg.c b/mach/mach_msg.c new file mode 100644 index 0000000..ac5b433 --- /dev/null +++ b/mach/mach_msg.c @@ -0,0 +1,626 @@ +/* + * Copyright (c) 1999-2002 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@ + */ +/* + * Mach Operating System + * Copyright (c) 1991,1990,1989 Carnegie Mellon University + * All Rights Reserved. + * + * Permission to use, copy, modify and distribute this software and its + * documentation is hereby granted, provided that both the copyright + * notice and this permission notice appear in all copies of the + * software, derivative works or modified versions, and any portions + * thereof, and that both notices appear in supporting documentation. + * + * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" + * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR + * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. + * + * Carnegie Mellon requests users of this software to return to + * + * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU + * School of Computer Science + * Carnegie Mellon University + * Pittsburgh PA 15213-3890 + * + * any improvements or extensions that they make and grant Carnegie Mellon + * the rights to redistribute these changes. + */ + +#include +#include +#include +#include +#include +#include +#include + +#ifdef HOST_MACH_MSG_TRAP +__private_extern__ kern_return_t _host_mach_msg_trap_return_ = KERN_FAILURE; + +#define MACH_MSG_TRAP(msg, opt, ssize, rsize, rname, to, not) \ + ((_host_mach_msg_trap_return_ == KERN_SUCCESS) ? \ + mach_msg_trap((msg), (opt), (ssize), (rsize), (rname), (to), (not)) : \ + mach_msg_overwrite_trap((msg), (opt), (ssize), (rsize), (rname), \ + (to), (not), MACH_MSG_NULL, 0)) + +#else + +#define MACH_MSG_TRAP(msg, opt, ssize, rsize, rname, to, not) \ + mach_msg_overwrite_trap((msg), (opt), (ssize), (rsize), (rname), \ + (to), (not), MACH_MSG_NULL, 0)) +#endif + +#define LIBMACH_OPTIONS (MACH_SEND_INTERRUPT|MACH_RCV_INTERRUPT) + +/* + * Routine: mach_msg + * Purpose: + * Send and/or receive a message. If the message operation + * is interrupted, and the user did not request an indication + * of that fact, then restart the appropriate parts of the + * operation. + */ +mach_msg_return_t +mach_msg(msg, option, send_size, rcv_size, rcv_name, timeout, notify) + mach_msg_header_t *msg; + mach_msg_option_t option; + mach_msg_size_t send_size; + mach_msg_size_t rcv_size; + mach_port_t rcv_name; + mach_msg_timeout_t timeout; + mach_port_t notify; +{ + mach_msg_return_t mr; + + /* + * Consider the following cases: + * 1) Errors in pseudo-receive (eg, MACH_SEND_INTERRUPTED + * plus special bits). + * 2) Use of MACH_SEND_INTERRUPT/MACH_RCV_INTERRUPT options. + * 3) RPC calls with interruptions in one/both halves. + * + * We refrain from passing the option bits that we implement + * to the kernel. This prevents their presence from inhibiting + * the kernel's fast paths (when it checks the option value). + */ + + mr = MACH_MSG_TRAP(msg, option &~ LIBMACH_OPTIONS, + send_size, rcv_size, rcv_name, + timeout, notify); + if (mr == MACH_MSG_SUCCESS) + return MACH_MSG_SUCCESS; + + if ((option & MACH_SEND_INTERRUPT) == 0) + while (mr == MACH_SEND_INTERRUPTED) + mr = MACH_MSG_TRAP(msg, + option &~ LIBMACH_OPTIONS, + send_size, rcv_size, rcv_name, + timeout, notify); + + if ((option & MACH_RCV_INTERRUPT) == 0) + while (mr == MACH_RCV_INTERRUPTED) + mr = MACH_MSG_TRAP(msg, + option &~ (LIBMACH_OPTIONS|MACH_SEND_MSG), + 0, rcv_size, rcv_name, + timeout, notify); + + return mr; +} + +/* + * Routine: mach_msg_overwrite + * Purpose: + * Send and/or receive a message. If the message operation + * is interrupted, and the user did not request an indication + * of that fact, then restart the appropriate parts of the + * operation. + * + * Distinct send and receive buffers may be specified. If + * no separate receive buffer is specified, the msg parameter + * will be used for both send and receive operations. + * + * In addition to a distinct receive buffer, that buffer may + * already contain scatter control information to direct the + * receiving of the message. + */ +mach_msg_return_t +mach_msg_overwrite(msg, option, send_size, rcv_limit, rcv_name, timeout, + notify, rcv_msg, rcv_scatter_size) + mach_msg_header_t *msg; + mach_msg_option_t option; + mach_msg_size_t send_size; + mach_msg_size_t rcv_limit; + mach_port_t rcv_name; + mach_msg_timeout_t timeout; + mach_port_t notify; + mach_msg_header_t *rcv_msg; + mach_msg_size_t rcv_scatter_size; +{ + mach_msg_return_t mr; + + /* + * Consider the following cases: + * 1) Errors in pseudo-receive (eg, MACH_SEND_INTERRUPTED + * plus special bits). + * 2) Use of MACH_SEND_INTERRUPT/MACH_RCV_INTERRUPT options. + * 3) RPC calls with interruptions in one/both halves. + * + * We refrain from passing the option bits that we implement + * to the kernel. This prevents their presence from inhibiting + * the kernel's fast paths (when it checks the option value). + */ + + mr = mach_msg_overwrite_trap(msg, option &~ LIBMACH_OPTIONS, + send_size, rcv_limit, rcv_name, + timeout, notify, rcv_msg, rcv_scatter_size); + if (mr == MACH_MSG_SUCCESS) + return MACH_MSG_SUCCESS; + + if ((option & MACH_SEND_INTERRUPT) == 0) + while (mr == MACH_SEND_INTERRUPTED) + mr = mach_msg_overwrite_trap(msg, + option &~ LIBMACH_OPTIONS, + send_size, rcv_limit, rcv_name, + timeout, notify, rcv_msg, rcv_scatter_size); + + if ((option & MACH_RCV_INTERRUPT) == 0) + while (mr == MACH_RCV_INTERRUPTED) + mr = mach_msg_overwrite_trap(msg, + option &~ (LIBMACH_OPTIONS|MACH_SEND_MSG), + 0, rcv_limit, rcv_name, + timeout, notify, rcv_msg, rcv_scatter_size); + + return mr; +} + + +mach_msg_return_t +mach_msg_send(mach_msg_header_t *msg) +{ + return mach_msg(msg, MACH_SEND_MSG, + msg->msgh_size, 0, MACH_PORT_NULL, + MACH_MSG_TIMEOUT_NONE, MACH_PORT_NULL); +} + +mach_msg_return_t +mach_msg_receive(mach_msg_header_t *msg) +{ + return mach_msg(msg, MACH_RCV_MSG, + 0, msg->msgh_size, msg->msgh_local_port, + MACH_MSG_TIMEOUT_NONE, MACH_PORT_NULL); +} + + +static void +mach_msg_destroy_port(mach_port_t port, mach_msg_type_name_t type) +{ + if (MACH_PORT_VALID(port)) switch (type) { + case MACH_MSG_TYPE_MOVE_SEND: + case MACH_MSG_TYPE_MOVE_SEND_ONCE: + /* destroy the send/send-once right */ + (void) mach_port_deallocate(mach_task_self(), port); + break; + + case MACH_MSG_TYPE_MOVE_RECEIVE: + /* destroy the receive right */ + (void) mach_port_mod_refs(mach_task_self(), port, + MACH_PORT_RIGHT_RECEIVE, -1); + break; + + case MACH_MSG_TYPE_MAKE_SEND: + /* create a send right and then destroy it */ + (void) mach_port_insert_right(mach_task_self(), port, + port, MACH_MSG_TYPE_MAKE_SEND); + (void) mach_port_deallocate(mach_task_self(), port); + break; + + case MACH_MSG_TYPE_MAKE_SEND_ONCE: + /* create a send-once right and then destroy it */ + (void) mach_port_extract_right(mach_task_self(), port, + MACH_MSG_TYPE_MAKE_SEND_ONCE, + &port, &type); + (void) mach_port_deallocate(mach_task_self(), port); + break; + } +} + +static void +mach_msg_destroy_memory(vm_offset_t addr, vm_size_t size) +{ + if (size != 0) + (void) vm_deallocate(mach_task_self(), addr, size); +} + + +/* + * Routine: mach_msg_destroy + * Purpose: + * mach_msg_destroy is useful in two contexts. + * + * First, it can deallocate all port rights and + * out-of-line memory in a received message. + * When a server receives a request it doesn't want, + * it needs this functionality. + * + * Second, it can mimic the side-effects of a msg-send + * operation. The effect is as if the message were sent + * and then destroyed inside the kernel. When a server + * can't send a reply (because the client died), + * it needs this functionality. + */ +void +mach_msg_destroy(mach_msg_header_t *msg) +{ + mach_msg_bits_t mbits = msg->msgh_bits; + + /* + * The msgh_local_port field doesn't hold a port right. + * The receive operation consumes the destination port right. + */ + + mach_msg_destroy_port(msg->msgh_remote_port, MACH_MSGH_BITS_REMOTE(mbits)); + + if (mbits & MACH_MSGH_BITS_COMPLEX) { + mach_msg_body_t *body; + mach_msg_descriptor_t *saddr, *eaddr; + + body = (mach_msg_body_t *) (msg + 1); + saddr = (mach_msg_descriptor_t *) + ((mach_msg_base_t *) msg + 1); + eaddr = saddr + body->msgh_descriptor_count; + + for ( ; saddr < eaddr; saddr++) { + switch (saddr->type.type) { + + case MACH_MSG_PORT_DESCRIPTOR: { + mach_msg_port_descriptor_t *dsc; + + /* + * Destroy port rights carried in the message + */ + dsc = &saddr->port; + mach_msg_destroy_port(dsc->name, dsc->disposition); + break; + } + + case MACH_MSG_OOL_DESCRIPTOR : { + mach_msg_ool_descriptor_t *dsc; + + /* + * Destroy memory carried in the message + */ + dsc = &saddr->out_of_line; + if (dsc->deallocate) { + mach_msg_destroy_memory((vm_offset_t)dsc->address, + dsc->size); + } + break; + } + + case MACH_MSG_OOL_PORTS_DESCRIPTOR : { + mach_port_t *ports; + mach_msg_ool_ports_descriptor_t *dsc; + mach_msg_type_number_t j; + + /* + * Destroy port rights carried in the message + */ + dsc = &saddr->ool_ports; + ports = (mach_port_t *) dsc->address; + for (j = 0; j < dsc->count; j++, ports++) { + mach_msg_destroy_port(*ports, dsc->disposition); + } + + /* + * Destroy memory carried in the message + */ + if (dsc->deallocate) { + mach_msg_destroy_memory((vm_offset_t)dsc->address, + dsc->count * sizeof(mach_port_t)); + } + break; + } + } + } + } +} + +/* + * Routine: mach_msg_server_once + * Purpose: + * A simple generic server function. It allows more flexibility + * than mach_msg_server by processing only one message request + * and then returning to the user. Note that more in the way + * of error codes are returned to the user; specifically, any + * failing error from mach_msg calls will be returned + * (though errors from the demux routine or the routine it + * calls will not be). + */ +mach_msg_return_t +mach_msg_server_once( + boolean_t (*demux)(mach_msg_header_t *, mach_msg_header_t *), + mach_msg_size_t max_size, + mach_port_t rcv_name, + mach_msg_options_t options) +{ + mig_reply_error_t *bufRequest, *bufReply; + mach_msg_size_t request_size; + mach_msg_size_t request_alloc; + mach_msg_size_t trailer_alloc; + mach_msg_size_t reply_alloc; + mach_msg_return_t mr; + kern_return_t kr; + mach_port_t self = mach_task_self(); + + options &= ~(MACH_SEND_MSG|MACH_RCV_MSG); + + trailer_alloc = REQUESTED_TRAILER_SIZE(options); + request_alloc = round_page(max_size + trailer_alloc); + + request_size = (options & MACH_RCV_LARGE) ? + request_alloc : max_size + trailer_alloc; + + reply_alloc = round_page((options & MACH_SEND_TRAILER) ? + (max_size + MAX_TRAILER_SIZE) : + max_size); + + kr = vm_allocate(self, + (vm_address_t *)&bufReply, + reply_alloc, + VM_MAKE_TAG(VM_MEMORY_MACH_MSG)|TRUE); + if (kr != KERN_SUCCESS) + return kr; + + for (;;) { + mach_msg_size_t new_request_alloc; + + kr = vm_allocate(self, + (vm_address_t *)&bufRequest, + request_alloc, + VM_MAKE_TAG(VM_MEMORY_MACH_MSG)|TRUE); + if (kr != KERN_SUCCESS) { + vm_deallocate(self, + (vm_address_t)bufReply, + reply_alloc); + return kr; + } + + mr = mach_msg(&bufRequest->Head, MACH_RCV_MSG|options, + 0, request_size, rcv_name, + MACH_MSG_TIMEOUT_NONE, MACH_PORT_NULL); + + if (!((mr == MACH_RCV_TOO_LARGE) && (options & MACH_RCV_LARGE))) + break; + + new_request_alloc = round_page(bufRequest->Head.msgh_size + + trailer_alloc); + vm_deallocate(self, + (vm_address_t) bufRequest, + request_alloc); + request_size = request_alloc = new_request_alloc; + } + + if (mr == MACH_MSG_SUCCESS) { + /* we have a request message */ + + (void) (*demux)(&bufRequest->Head, &bufReply->Head); + + if (!(bufReply->Head.msgh_bits & MACH_MSGH_BITS_COMPLEX)) { + if (bufReply->RetCode == MIG_NO_REPLY) + bufReply->Head.msgh_remote_port = MACH_PORT_NULL; + else if ((bufReply->RetCode != KERN_SUCCESS) && + (bufRequest->Head.msgh_bits & MACH_MSGH_BITS_COMPLEX)) { + /* destroy the request - but not the reply port */ + bufRequest->Head.msgh_remote_port = MACH_PORT_NULL; + mach_msg_destroy(&bufRequest->Head); + } + } + + /* + * We don't want to block indefinitely because the client + * isn't receiving messages from the reply port. + * If we have a send-once right for the reply port, then + * this isn't a concern because the send won't block. + * If we have a send right, we need to use MACH_SEND_TIMEOUT. + * To avoid falling off the kernel's fast RPC path unnecessarily, + * we only supply MACH_SEND_TIMEOUT when absolutely necessary. + */ + if (bufReply->Head.msgh_remote_port != MACH_PORT_NULL) { + + mr = mach_msg(&bufReply->Head, + (MACH_MSGH_BITS_REMOTE(bufReply->Head.msgh_bits) == + MACH_MSG_TYPE_MOVE_SEND_ONCE) ? + MACH_SEND_MSG|options : + MACH_SEND_MSG|MACH_SEND_TIMEOUT|options, + bufReply->Head.msgh_size, 0, MACH_PORT_NULL, + MACH_MSG_TIMEOUT_NONE, MACH_PORT_NULL); + + if ((mr != MACH_SEND_INVALID_DEST) && + (mr != MACH_SEND_TIMED_OUT)) + goto done_once; + mr = MACH_MSG_SUCCESS; + } + if (bufReply->Head.msgh_bits & MACH_MSGH_BITS_COMPLEX) + mach_msg_destroy(&bufReply->Head); + } + + done_once: + (void)vm_deallocate(self, + (vm_address_t) bufRequest, + request_alloc); + (void)vm_deallocate(self, + (vm_address_t) bufReply, + reply_alloc); + return mr; +} + +/* + * Routine: mach_msg_server + * Purpose: + * A simple generic server function. Note that changes here + * should be considered for duplication above. + */ +mach_msg_return_t +mach_msg_server( + boolean_t (*demux)(mach_msg_header_t *, mach_msg_header_t *), + mach_msg_size_t max_size, + mach_port_t rcv_name, + mach_msg_options_t options) +{ + mig_reply_error_t *bufRequest, *bufReply; + mach_msg_size_t request_size; + mach_msg_size_t new_request_alloc; + mach_msg_size_t request_alloc; + mach_msg_size_t trailer_alloc; + mach_msg_size_t reply_alloc; + mach_msg_return_t mr; + kern_return_t kr; + mach_port_t self = mach_task_self(); + + options &= ~(MACH_SEND_MSG|MACH_RCV_MSG); + + reply_alloc = round_page((options & MACH_SEND_TRAILER) ? + (max_size + MAX_TRAILER_SIZE) : max_size); + + kr = vm_allocate(self, + (vm_address_t *)&bufReply, + reply_alloc, + VM_MAKE_TAG(VM_MEMORY_MACH_MSG)|TRUE); + if (kr != KERN_SUCCESS) + return kr; + + request_alloc = 0; + trailer_alloc = REQUESTED_TRAILER_SIZE(options); + new_request_alloc = round_page(max_size + trailer_alloc); + + request_size = (options & MACH_RCV_LARGE) ? + new_request_alloc : max_size + trailer_alloc; + + for (;;) { + if (request_alloc < new_request_alloc) { + request_alloc = new_request_alloc; + kr = vm_allocate(self, + (vm_address_t *)&bufRequest, + request_alloc, + VM_MAKE_TAG(VM_MEMORY_MACH_MSG)|TRUE); + if (kr != KERN_SUCCESS) { + vm_deallocate(self, + (vm_address_t)bufReply, + reply_alloc); + return kr; + } + } + + mr = mach_msg(&bufRequest->Head, MACH_RCV_MSG|options, + 0, request_size, rcv_name, + MACH_MSG_TIMEOUT_NONE, MACH_PORT_NULL); + + while (mr == MACH_MSG_SUCCESS) { + /* we have another request message */ + + (void) (*demux)(&bufRequest->Head, &bufReply->Head); + + if (!(bufReply->Head.msgh_bits & MACH_MSGH_BITS_COMPLEX)) { + if (bufReply->RetCode == MIG_NO_REPLY) + bufReply->Head.msgh_remote_port = MACH_PORT_NULL; + else if ((bufReply->RetCode != KERN_SUCCESS) && + (bufRequest->Head.msgh_bits & MACH_MSGH_BITS_COMPLEX)) { + /* destroy the request - but not the reply port */ + bufRequest->Head.msgh_remote_port = MACH_PORT_NULL; + mach_msg_destroy(&bufRequest->Head); + } + } + + /* + * We don't want to block indefinitely because the client + * isn't receiving messages from the reply port. + * If we have a send-once right for the reply port, then + * this isn't a concern because the send won't block. + * If we have a send right, we need to use MACH_SEND_TIMEOUT. + * To avoid falling off the kernel's fast RPC path, + * we only supply MACH_SEND_TIMEOUT when absolutely necessary. + */ + if (bufReply->Head.msgh_remote_port != MACH_PORT_NULL) { + if (request_alloc == reply_alloc) { + mig_reply_error_t *bufTemp; + + mr = mach_msg( + &bufReply->Head, + (MACH_MSGH_BITS_REMOTE(bufReply->Head.msgh_bits) == + MACH_MSG_TYPE_MOVE_SEND_ONCE) ? + MACH_SEND_MSG|MACH_RCV_MSG|options : + MACH_SEND_MSG|MACH_RCV_MSG|MACH_SEND_TIMEOUT|options, + bufReply->Head.msgh_size, request_size, rcv_name, + MACH_MSG_TIMEOUT_NONE, MACH_PORT_NULL); + + /* swap request and reply */ + bufTemp = bufRequest; + bufRequest = bufReply; + bufReply = bufTemp; + + } else { + mr = mach_msg_overwrite( + &bufReply->Head, + (MACH_MSGH_BITS_REMOTE(bufReply->Head.msgh_bits) == + MACH_MSG_TYPE_MOVE_SEND_ONCE) ? + MACH_SEND_MSG|MACH_RCV_MSG|options : + MACH_SEND_MSG|MACH_RCV_MSG|MACH_SEND_TIMEOUT|options, + bufReply->Head.msgh_size, request_size, rcv_name, + MACH_MSG_TIMEOUT_NONE, MACH_PORT_NULL, + &bufRequest->Head, request_size); + } + + if ((mr != MACH_SEND_INVALID_DEST) && + (mr != MACH_SEND_TIMED_OUT)) + continue; + } + if (bufReply->Head.msgh_bits & MACH_MSGH_BITS_COMPLEX) + mach_msg_destroy(&bufReply->Head); + + mr = mach_msg(&bufRequest->Head, MACH_RCV_MSG|options, + 0, request_size, rcv_name, + MACH_MSG_TIMEOUT_NONE, MACH_PORT_NULL); + + } /* while (mr == MACH_MSG_SUCCESS) */ + + if ((mr == MACH_RCV_TOO_LARGE) && (options & MACH_RCV_LARGE)) { + new_request_alloc = round_page(bufRequest->Head.msgh_size + + trailer_alloc); + request_size = new_request_alloc; + vm_deallocate(self, + (vm_address_t) bufRequest, + request_alloc); + continue; + } + + break; + + } /* for(;;) */ + + (void)vm_deallocate(self, + (vm_address_t) bufRequest, + request_alloc); + (void)vm_deallocate(self, + (vm_address_t) bufReply, + reply_alloc); + return mr; +} diff --git a/mach/mach_port.defs b/mach/mach_port.defs new file mode 100644 index 0000000..935d58f --- /dev/null +++ b/mach/mach_port.defs @@ -0,0 +1,22 @@ +/* + * Copyright (c) 1999 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@ + */ +#include diff --git a/mach/mach_traps.s b/mach/mach_traps.s new file mode 100644 index 0000000..59c9b0a --- /dev/null +++ b/mach/mach_traps.s @@ -0,0 +1,48 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Mach Operating System + * Copyright (c) 1991,1990,1989,1988,1987,1986 Carnegie Mellon University + * All Rights Reserved. + * + * Permission to use, copy, modify and distribute this software and its + * documentation is hereby granted, provided that both the copyright + * notice and this permission notice appear in all copies of the + * software, derivative works or modified versions, and any portions + * thereof, and that both notices appear in supporting documentation. + * + * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" + * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR + * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. + * + * Carnegie Mellon requests users of this software to return to + * + * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU + * School of Computer Science + * Carnegie Mellon University + * Pittsburgh PA 15213-3890 + * + * any improvements or extensions that they make and grant Carnegie Mellon + * the rights to redistribute these changes. + */ + +#include diff --git a/mach/mig_allocate.c b/mach/mig_allocate.c new file mode 100644 index 0000000..38db1ac --- /dev/null +++ b/mach/mig_allocate.c @@ -0,0 +1,64 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Mach Operating System + * Copyright (c) 1991 Carnegie Mellon University + * All Rights Reserved. + * + * Permission to use, copy, modify and distribute this software and its + * documentation is hereby granted, provided that both the copyright + * notice and this permission notice appear in all copies of the + * software, derivative works or modified versions, and any portions + * thereof, and that both notices appear in supporting documentation. + * + * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" + * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR + * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. + * + * Carnegie Mellon requests users of this software to return to + * + * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU + * School of Computer Science + * Carnegie Mellon University + * Pittsburgh PA 15213-3890 + * + * any improvements or extensions that they make and grant Carnegie Mellon + * the rights to redistribute these changes. + */ + +/* + * Memory allocation routine for MiG interfaces. + */ +#include +#include +#include "externs.h" + +void +mig_allocate(vm_address_t *addr_p, vm_size_t size) +{ + if (vm_allocate(mach_task_self(), + addr_p, + size, + VM_MAKE_TAG(VM_MEMORY_MACH_MSG)|TRUE) + != KERN_SUCCESS) + *addr_p = 0; +} diff --git a/mach/mig_deallocate.c b/mach/mig_deallocate.c new file mode 100644 index 0000000..5ee1c3f --- /dev/null +++ b/mach/mig_deallocate.c @@ -0,0 +1,60 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Mach Operating System + * Copyright (c) 1991 Carnegie Mellon University + * All Rights Reserved. + * + * Permission to use, copy, modify and distribute this software and its + * documentation is hereby granted, provided that both the copyright + * notice and this permission notice appear in all copies of the + * software, derivative works or modified versions, and any portions + * thereof, and that both notices appear in supporting documentation. + * + * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" + * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR + * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. + * + * Carnegie Mellon requests users of this software to return to + * + * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU + * School of Computer Science + * Carnegie Mellon University + * Pittsburgh PA 15213-3890 + * + * any improvements or extensions that they make and grant Carnegie Mellon + * the rights to redistribute these changes. + */ + +/* + * Memory deallocation routine for MiG interfaces. + */ +#include +#include "externs.h" + +void +mig_deallocate(vm_address_t addr, vm_size_t size) +{ + (void) vm_deallocate(mach_task_self(), + addr, + size); +} diff --git a/mach/mig_reply_setup.c b/mach/mig_reply_setup.c new file mode 100644 index 0000000..b18ec76 --- /dev/null +++ b/mach/mig_reply_setup.c @@ -0,0 +1,75 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Mach Operating System + * Copyright (c) 1991 Carnegie Mellon University + * All Rights Reserved. + * + * Permission to use, copy, modify and distribute this software and its + * documentation is hereby granted, provided that both the copyright + * notice and this permission notice appear in all copies of the + * software, derivative works or modified versions, and any portions + * thereof, and that both notices appear in supporting documentation. + * + * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" + * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR + * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. + * + * Carnegie Mellon requests users of this software to return to + * + * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU + * School of Computer Science + * Carnegie Mellon University + * Pittsburgh PA 15213-3890 + * + * any improvements or extensions that they make and grant Carnegie Mellon + * the rights to redistribute these changes. + */ + +/* + * Routine to set up a MiG reply message from a request message. + * + * Knows about the MiG reply message ID convention: + * reply_id = request_id + 100 + * + * For typed IPC sets up the RetCode type field. Does NOT set a + * return code value. + */ + +#include +#include +#include + +void +mig_reply_setup(mach_msg_header_t *request, mach_msg_header_t *reply) +{ +#define InP (request) +#define OutP ((mig_reply_error_t *) reply) + + OutP->Head.msgh_bits = + MACH_MSGH_BITS(MACH_MSGH_BITS_LOCAL(InP->msgh_bits), 0); + OutP->Head.msgh_size = sizeof(mig_reply_error_t); + OutP->Head.msgh_remote_port = InP->msgh_local_port; + OutP->Head.msgh_local_port = MACH_PORT_NULL; + OutP->Head.msgh_id = InP->msgh_id + 100; + OutP->NDR = NDR_record; +} diff --git a/mach/mig_strncpy.c b/mach/mig_strncpy.c new file mode 100644 index 0000000..662cc4f --- /dev/null +++ b/mach/mig_strncpy.c @@ -0,0 +1,85 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Mach Operating System + * Copyright (c) 1991,1990,1989 Carnegie Mellon University + * All Rights Reserved. + * + * Permission to use, copy, modify and distribute this software and its + * documentation is hereby granted, provided that both the copyright + * notice and this permission notice appear in all copies of the + * software, derivative works or modified versions, and any portions + * thereof, and that both notices appear in supporting documentation. + * + * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" + * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR + * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. + * + * Carnegie Mellon requests users of this software to return to + * + * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU + * School of Computer Science + * Carnegie Mellon University + * Pittsburgh PA 15213-3890 + * + * any improvements or extensions that they make and grant Carnegie Mellon + * the rights to redistribute these changes. + */ +/* + * mig_strncpy.c - by Joshua Block + * + * mig_strncpy -- Bounded string copy. Does what the library routine strncpy + * OUGHT to do: Copies the (null terminated) string in src into dest, a + * buffer of length len. Assures that the copy is still null terminated + * and doesn't overflow the buffer, truncating the copy if necessary. + * + * Parameters: + * + * dest - Pointer to destination buffer. + * + * src - Pointer to source string. + * + * len - Length of destination buffer. + * + * Result: + * length of string copied, INCLUDING the trailing 0. + */ +#include + +int +mig_strncpy( + register char *dest, + register const char *src, + register int len) +{ + register int i; + + if (len <= 0) + return 0; + + for (i=1; i +#include +#include +#include +#include + +kern_return_t +thread_switch( + mach_port_t thread, + int option, + mach_msg_timeout_t option_time) +{ + kern_return_t result; + + result = syscall_thread_switch(thread, option, option_time); + return (result); +} diff --git a/mach/notify.defs b/mach/notify.defs new file mode 100644 index 0000000..2014be5 --- /dev/null +++ b/mach/notify.defs @@ -0,0 +1 @@ +#include diff --git a/mach/panic.c b/mach/panic.c new file mode 100644 index 0000000..2411d52 --- /dev/null +++ b/mach/panic.c @@ -0,0 +1,58 @@ +/* + * @OSF_COPYRIGHT@ + */ + +/* + * Mach Operating System + * Copyright (c) 1991,1990,1989 Carnegie Mellon University + * All Rights Reserved. + * + * Permission to use, copy, modify and distribute this software and its + * documentation is hereby granted, provided that both the copyright + * notice and this permission notice appear in all copies of the + * software, derivative works or modified versions, and any portions + * thereof, and that both notices appear in supporting documentation. + * + * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" + * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR + * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. + * + * Carnegie Mellon requests users of this software to return to + * + * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU + * School of Computer Science + * Carnegie Mellon University + * Pittsburgh PA 15213-3890 + * + * any improvements or extensions that they make and grant Carnegie Mellon + * the rights to redistribute these changes. + */ + +#include +#include +#include +#include + +static mach_port_t master_host_port; + +void +panic_init(mach_port_t port) +{ + master_host_port = port; +} + +/*VARARGS1*/ +void +panic(const char *s, ...) +{ + va_list listp; + + printf("panic: "); + va_start(listp, s); + vprintf(s, listp); + va_end(listp); + printf("\n"); + +#define RB_DEBUGGER 0x1000 /* enter debugger NOW */ + (void) host_reboot(master_host_port, RB_DEBUGGER); +} diff --git a/mach/port_obj.c b/mach/port_obj.c new file mode 100644 index 0000000..4d63221 --- /dev/null +++ b/mach/port_obj.c @@ -0,0 +1,29 @@ +/* + * @OSF_COPYRIGHT@ + */ + +/* + * Define a service to map from a kernel-generated port name + * to server-defined "type" and "value" data to be associated + * with the port. + */ +#include +#include + +#define DEFAULT_TABLE_SIZE (64 * 1024) + +struct port_obj_tentry *port_obj_table; +int port_obj_table_size = DEFAULT_TABLE_SIZE; + +void port_obj_init( + int maxsize) +{ + kern_return_t kr; + + kr = vm_allocate(mach_task_self(), + (vm_offset_t *)&port_obj_table, + (vm_size_t)(maxsize * sizeof (*port_obj_table)), + TRUE); + if (kr != KERN_SUCCESS) + panic("port_obj_init: can't vm_allocate"); +} diff --git a/mach/processor.defs b/mach/processor.defs new file mode 100644 index 0000000..bc58140 --- /dev/null +++ b/mach/processor.defs @@ -0,0 +1 @@ +#include diff --git a/mach/processor_set.defs b/mach/processor_set.defs new file mode 100644 index 0000000..5504bc9 --- /dev/null +++ b/mach/processor_set.defs @@ -0,0 +1 @@ +#include \ No newline at end of file diff --git a/mach/sbrk.c b/mach/sbrk.c new file mode 100644 index 0000000..5b47642 --- /dev/null +++ b/mach/sbrk.c @@ -0,0 +1,76 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * File: sbrk.c + * + * Unix compatibility for sbrk system call. + * + * HISTORY + * 09-Mar-90 Gregg Kellogg (gk) at NeXT. + * include instead of + * + * 14-Feb-89 Avadis Tevanian (avie) at NeXT. + * Total rewrite using a fixed area of VM from break region. + */ + +#include /* for vm_allocate, vm_offset_t */ +#include +#include /* 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) + int size; +{ + vm_offset_t addr; + kern_return_t ret; + caddr_t ocurbrk; + extern int end; + + if (sbrk_needs_init) { + sbrk_needs_init = FALSE; + /* + * Allocate a big region to simulate break region. + */ + 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); + } + + if (size <= 0) + return((caddr_t)sbrk_curbrk); + sbrk_curbrk += size; + sbrk_region_size -= size; + if (sbrk_region_size < 0) + return((caddr_t)-1); + return((caddr_t)(sbrk_curbrk - size)); +} + +caddr_t brk(x) + caddr_t x; +{ + return((caddr_t)-1); +} + diff --git a/mach/semaphore.c b/mach/semaphore.c new file mode 100644 index 0000000..3b94c46 --- /dev/null +++ b/mach/semaphore.c @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2000 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@ + */ + +#include +#include +#include +#include +#include +#include + +kern_return_t semaphore_signal( + mach_port_t signal_semaphore) +{ + return semaphore_signal_trap(signal_semaphore); +} + +kern_return_t semaphore_signal_all( + mach_port_t signal_semaphore) +{ + return semaphore_signal_all_trap(signal_semaphore); +} + +kern_return_t semaphore_signal_thread( + mach_port_t signal_semaphore, + mach_port_t thread_act) +{ + return semaphore_signal_thread_trap(signal_semaphore, thread_act); +} + +kern_return_t semaphore_wait ( + mach_port_t wait_semaphore) +{ + return semaphore_wait_trap(wait_semaphore); +} + +kern_return_t semaphore_timedwait ( + mach_port_t wait_semaphore, + mach_timespec_t wait_time) +{ + return semaphore_timedwait_trap(wait_semaphore, + wait_time.tv_sec, + wait_time.tv_nsec); +} + +kern_return_t semaphore_wait_signal ( + mach_port_t wait_semaphore, + mach_port_t signal_semaphore) +{ + return semaphore_wait_signal_trap(wait_semaphore, signal_semaphore); +} + +kern_return_t semaphore_timedwait_signal ( + mach_port_t wait_semaphore, + mach_port_t signal_semaphore, + mach_timespec_t wait_time) +{ + return semaphore_timedwait_signal_trap(wait_semaphore, + signal_semaphore, + wait_time.tv_sec, + wait_time.tv_nsec); +} diff --git a/mach/servers/Makefile.inc b/mach/servers/Makefile.inc new file mode 100644 index 0000000..d0ff159 --- /dev/null +++ b/mach/servers/Makefile.inc @@ -0,0 +1,45 @@ +.PATH: ${.CURDIR}/${MACHINE_ARCH}/mach/servers ${.CURDIR}/mach/servers + +SRVMIGDEFS += srvbootstrap.defs netname.defs + +SRVMIGHDRS = ${SRVMIGDEFS:S/.defs$/.h/} +#SRVMIGHDRS = ${SRVMIGDEFS:S/.defs$/.h/:S/^/${.CURDIR}\/mach\/servers\//} +SRVMIGSRCS = ${SRVMIGDEFS:S/.defs$/User.c/} + +SRVHDRS = bootstrap_defs.h netname_defs.h key_defs.h nm_defs.h ls_defs.h +SRVHDRS := ${SRVHDRS:S/^/${.CURDIR}\/mach\/servers\//} +SRVHDRS += ${SRVMIGHDRS} + +SRCS+= ${SRVMIGDEFS:S/.defs$/User.defs/} + +CLEANFILES += ${SRVMIGHDRS} ${SRVMIGHDRS:S/.h$/User.c/} \ + ${SRVMIGHDRS:S/.h$/Server.c/} + +${SRVMIGDEFS:S/.defs$/User.So/}: + mig -user ${.TARGET:S/.So$/.c/} \ + -server ${.TARGET:S/User.So$/Server.c/} \ + -header ${.TARGET:S/User.So$/.h/} \ + ${.CURDIR}/mach/servers/${.TARGET:S/User.So$/.defs/} + ${CC} ${CFLAGS} -Os -c ${.TARGET:S/.So$/.c/}\ + -o ${.TARGET} +${SRVMIGDEFS:S/.defs$/User.do/}: + mig -user ${.TARGET:S/.do$/.c/} \ + -server ${.TARGET:S/User.do$/Server.c/} \ + -header ${.TARGET:S/User.do$/.h/} \ + ${.CURDIR}/mach/servers/${.TARGET:S/User.do$/.defs/} + ${CC} -g -DDEBUG ${CFLAGS} -c ${.TARGET:S/.do$/.c/}\ + -o ${.TARGET} +${SRVMIGDEFS:S/.defs$/User.po/}: + mig -user ${.TARGET:S/.po$/.c/} \ + -server ${.TARGET:S/User.po$/Server.c/} \ + -header ${.TARGET:S/User.po$/.h/} \ + ${.CURDIR}/mach/servers/${.TARGET:S/User.po$/.defs/} + ${CC} -pg -DPROFILE ${CFLAGS} -c ${.TARGET:S/.po$/.c/}\ + -o ${.TARGET} +${SRVMIGDEFS:S/.defs$/User.o/}: + mig -user ${.TARGET:S/.o$/.c/} \ + -server ${.TARGET:S/User.o$/Server.c/} \ + -header ${.TARGET:S/User.o$/.h/} \ + ${.CURDIR}/mach/servers/${.TARGET:S/User.o$/.defs/} + ${CC} -static ${CFLAGS} -c ${.TARGET:S/.o$/.c/}\ + -o ${.TARGET} diff --git a/mach/servers/bootstrap_defs.h b/mach/servers/bootstrap_defs.h new file mode 100644 index 0000000..1bcd27d --- /dev/null +++ b/mach/servers/bootstrap_defs.h @@ -0,0 +1,60 @@ +/* + * Copyright (c) 1999-2002 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@ + */ +/* + * bootstrap -- fundamental service initiator and port server + * Mike DeMoney, NeXT, Inc. + * Copyright, 1990. All rights reserved. + * + * bootstrap_defs.h -- bootstrap service data types and constants + * See bootstrap.defs for description of bootstrap services. + */ + +#ifndef _BOOTSTRAP_DEFS_ +#define _BOOTSTRAP_DEFS_ +#import + +#define BOOTSTRAP_MAX_NAME_LEN 128 +#define BOOTSTRAP_MAX_CMD_LEN 512 + +typedef char name_t[BOOTSTRAP_MAX_NAME_LEN]; +typedef char cmd_t[BOOTSTRAP_MAX_CMD_LEN]; +typedef name_t *name_array_t; +typedef int bootstrap_status_t; +typedef bootstrap_status_t *bootstrap_status_array_t; + +typedef boolean_t *bool_array_t; + +#define BOOTSTRAP_MAX_LOOKUP_COUNT 20 + +#define BOOTSTRAP_SUCCESS 0 +#define BOOTSTRAP_NOT_PRIVILEGED 1100 +#define BOOTSTRAP_NAME_IN_USE 1101 +#define BOOTSTRAP_UNKNOWN_SERVICE 1102 +#define BOOTSTRAP_SERVICE_ACTIVE 1103 +#define BOOTSTRAP_BAD_COUNT 1104 +#define BOOTSTRAP_NO_MEMORY 1105 + +#define BOOTSTRAP_STATUS_INACTIVE 0 +#define BOOTSTRAP_STATUS_ACTIVE 1 +#define BOOTSTRAP_STATUS_ON_DEMAND 2 + +#endif /* _BOOTSTRAP_DEFS_ */ diff --git a/mach/servers/key_defs.h b/mach/servers/key_defs.h new file mode 100644 index 0000000..a44d526 --- /dev/null +++ b/mach/servers/key_defs.h @@ -0,0 +1,102 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Mach Operating System + * Copyright (c) 1987 Carnegie-Mellon University + * All rights reserved. The CMU software License Agreement specifies + * the terms and conditions for use and redistribution. + */ + +/* + * Definitions of encryption keys etc.. + */ + +/* + * HISTORY: + * 5-Jun-87 Robert Sansom (rds) at Carnegie Mellon University + * Added macros to convert keys between network and host order. + * + * 12-Apr-87 Robert Sansom (rds) at Carnegie Mellon University + * Added KEY_IS_NULL. + * + * 2-Feb-87 Robert Sansom (rds) at Carnegie Mellon University + * Added KEY_EQUAL. + * + * 5-Nov-86 Robert Sansom (rds) at Carnegie-Mellon University + * Started. + * + */ + +#ifndef _KEY_DEFS_ +#define _KEY_DEFS_ + +/* + * An encrytion key. + */ +typedef union { + unsigned char key_bytes[16]; + unsigned long key_longs[4]; +} key_t, *key_ptr_t; + +#define KEY_EQUAL(key1, key2) \ + ((key1.key_longs[0] == key2.key_longs[0]) \ + && (key1.key_longs[1] == key2.key_longs[1]) \ + && (key1.key_longs[2] == key2.key_longs[2]) \ + && (key1.key_longs[3] == key2.key_longs[3])) + +#define KEY_IS_NULL(key) \ + (((key).key_longs[0] == 0) && ((key).key_longs[1] == 0) \ + && ((key).key_longs[2] == 0) && ((key).key_longs[3] == 0)) + + +/* + * Macros to convert keys between network and host byte order. + */ +#define NTOH_KEY(key) { \ + (key).key_longs[0] = ntohl((key).key_longs[0]); \ + (key).key_longs[1] = ntohl((key).key_longs[1]); \ + (key).key_longs[2] = ntohl((key).key_longs[2]); \ + (key).key_longs[3] = ntohl((key).key_longs[3]); \ +} + +#define HTON_KEY(key) { \ + (key).key_longs[0] = htonl((key).key_longs[0]); \ + (key).key_longs[1] = htonl((key).key_longs[1]); \ + (key).key_longs[2] = htonl((key).key_longs[2]); \ + (key).key_longs[3] = htonl((key).key_longs[3]); \ +} + +/* + * Structure used to transmit or store a token or a key. + */ +typedef union { + key_t si_key; + key_t si_token; +} secure_info_t, *secure_info_ptr_t; + +/* + * Security Level of ports and messages. + */ +#define PORT_NOT_SECURE 0 +#define MESSAGE_NOT_SECURE 0 + +#endif /* _KEY_DEFS_ */ diff --git a/mach/servers/ls_defs.h b/mach/servers/ls_defs.h new file mode 100644 index 0000000..9dc2fe7 --- /dev/null +++ b/mach/servers/ls_defs.h @@ -0,0 +1,232 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Mach Operating System + * Copyright (c) 1989 Carnegie-Mellon University + * Copyright (c) 1988 Carnegie-Mellon University + * Copyright (c) 1987 Carnegie-Mellon University + * All rights reserved. The CMU software License Agreement specifies + * the terms and conditions for use and redistribution. + */ + +/* + * Definitions for the logstat module. + */ + + +#ifndef _LS_DEFS_ +#define _LS_DEFS_ + +#include + +/* + * Definition for a log record. + */ +typedef struct { + long code; + long thread; + long a1; + long a2; + long a3; + long a4; + long a5; + long a6; +} log_rec_t; + +typedef log_rec_t *log_ptr_t; + +/* + * Statistics record. + */ +typedef struct { + int datagram_pkts_sent; + int datagram_pkts_rcvd; + int srr_requests_sent; + int srr_bcasts_sent; + int srr_requests_rcvd; + int srr_bcasts_rcvd; + int srr_replies_sent; + int srr_replies_rcvd; + int srr_retries_sent; + int srr_retries_rcvd; + int srr_cfailures_sent; + int srr_cfailures_rcvd; + int deltat_dpkts_sent; + int deltat_acks_rcvd; + int deltat_dpkts_rcvd; + int deltat_acks_sent; + int deltat_oldpkts_rcvd; + int deltat_oospkts_rcvd; + int deltat_retries_sent; + int deltat_retries_rcvd; + int deltat_cfailures_sent; + int deltat_cfailures_rcvd; + int deltat_aborts_sent; + int deltat_aborts_rcvd; + int vmtp_requests_sent; + int vmtp_requests_rcvd; + int vmtp_replies_sent; + int vmtp_replies_rcvd; + int ipc_in_messages; + int ipc_out_messages; + int ipc_unblocks_sent; + int ipc_unblocks_rcvd; + int pc_requests_sent; + int pc_requests_rcvd; + int pc_replies_rcvd; + int pc_startups_rcvd; + int nn_requests_sent; + int nn_requests_rcvd; + int nn_replies_rcvd; + int po_ro_hints_sent; + int po_ro_hints_rcvd; + int po_token_requests_sent; + int po_token_requests_rcvd; + int po_token_replies_rcvd; + int po_xfer_requests_sent; + int po_xfer_requests_rcvd; + int po_xfer_replies_rcvd; + int po_deaths_sent; + int po_deaths_rcvd; + int ps_requests_sent; + int ps_requests_rcvd; + int ps_replies_rcvd; + int ps_auth_requests_sent; + int ps_auth_requests_rcvd; + int ps_auth_replies_rcvd; + int mallocs_or_vm_allocates; + int mem_allocs; + int mem_deallocs; + int mem_allocobjs; + int mem_deallocobjs; + int pkts_encrypted; + int pkts_decrypted; + int vmtp_segs_encrypted; + int vmtp_segs_decrypted; + int tcp_requests_sent; + int tcp_replies_sent; + int tcp_requests_rcvd; + int tcp_replies_rcvd; + int tcp_send; + int tcp_recv; + int tcp_connect; + int tcp_accept; + int tcp_close; +} stat_t; + +typedef stat_t *stat_ptr_t; + + +/* + * Debugging flags record. + */ +typedef struct { + int print_level; + int ipc_in; + int ipc_out; + int tracing; + int vmtp; + int netname; + int deltat; + int tcp; + int mem; +} debug_t; + +typedef debug_t *debug_ptr_t; + + +/* + * Parameters record. + */ +typedef struct { + int srr_max_tries; + int srr_retry_sec; + int srr_retry_usec; + int deltat_max_tries; + int deltat_retry_sec; + int deltat_retry_usec; + int deltat_msg_life; + int pc_checkup_interval; + int crypt_algorithm; + int transport_default; + int conf_network; + int conf_netport; + int timer_quantum; + int tcp_conn_steady; + int tcp_conn_opening; + int tcp_conn_max; + int compat; + int syslog; + int old_nmmonitor; +} param_t; + +typedef param_t *param_ptr_t; + + +/* + * Port statistics record. + */ +typedef struct { + u_int port_id; + u_int alive; + u_int nport_id_high; + u_int nport_id_low; + u_int nport_receiver; + u_int nport_owner; + u_int messages_sent; + u_int messages_rcvd; + u_int send_rights_sent; + u_int send_rights_rcvd_sender; + u_int send_rights_rcvd_recown; + u_int rcv_rights_xferd; + u_int own_rights_xferd; + u_int all_rights_xferd; + u_int tokens_sent; + u_int tokens_requested; + u_int xfer_hints_sent; + u_int xfer_hints_rcvd; +} port_stat_t, *port_stat_ptr_t; + +extern port_stat_ptr_t port_stat_cur; +extern port_stat_ptr_t port_stat_end; +extern struct mutex port_stat_lock; + + +/* + * Types for the mem_list operation. + * + * XXX These must be faked, because we cannot include mem.h here + * (mutual includes). + */ +typedef char *mem_class_ptr_t; +typedef char *mem_nam_ptr_t; +typedef int *mem_bucket_ptr_t; + + +/* + * Definitions for print_level. + */ +#define LS_PRINT_NEVER 5 +#define LS_PRINT_LOG 3 +#define LS_PRINT_ALWAYS 0 + +#endif /* _LS_DEFS_ */ diff --git a/mach/servers/netname.defs b/mach/servers/netname.defs new file mode 100644 index 0000000..264495c --- /dev/null +++ b/mach/servers/netname.defs @@ -0,0 +1,49 @@ +/* + * Mach Operating System + * Copyright (c) 1987 Carnegie-Mellon University + * All rights reserved. The CMU software License Agreement specifies + * the terms and conditions for use and redistribution. + */ + +/* + * Mig definitions for Network Name Service. + */ + +/* + * HISTORY: + * 30-May-87 Robert Sansom (rds) at Carnegie Mellon University + * Changes for the new mig. + * + * 20-Oct-86 Robert Sansom (rds) at Carnegie Mellon University + * New network name service interface. + * Added a serverprefix. + */ + +#include + +import ; + +subsystem netname 1040; + +serverprefix _; + + +type netname_name_t = c_string[*:80]; + +routine netname_check_in(server_port : mach_port_t; + port_name : netname_name_t; + signature : mach_port_t; + port_id : mach_port_t); + +routine netname_look_up(server_port : mach_port_t; + host_name : netname_name_t; + port_name : netname_name_t; + out port_id : mach_port_t); + +routine netname_check_out(server_port : mach_port_t; + port_name : netname_name_t; + signature : mach_port_t); + +routine netname_version(server_port : mach_port_t; + out version : netname_name_t); + diff --git a/mach/servers/netname_defs.h b/mach/servers/netname_defs.h new file mode 100644 index 0000000..8dcffcb --- /dev/null +++ b/mach/servers/netname_defs.h @@ -0,0 +1,65 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Mach Operating System + * Copyright (c) 1987 Carnegie-Mellon University + * All rights reserved. The CMU software License Agreement specifies + * the terms and conditions for use and redistribution. + */ + +/* + * Definitions for the mig interface to the network name service. + */ + +/* + * HISTORY: + * 28-Jul-88 Mary R. Thompson (mrt) at Carnegie Mellon + * Copied definitions of NAME_NOT_YOURS and NAME_NOT_CHECKED_IN + * from the old netname_defs.h so that old code would not break + * + * 8-Mar-88 Daniel Julin (dpj) at Carnegie-Mellon University + * Added NETNAME_INVALID_PORT. + * + * 28-Feb-88 Daniel Julin (dpj) at Carnegie-Mellon University + * Added NETNAME_PENDING. + * + * 23-Dec-86 Robert Sansom (rds) at Carnegie Mellon University + * Copied from the previous version of the network server. + * + */ + +#ifndef _NETNAME_DEFS_ +#define _NETNAME_DEFS_ + +#define NETNAME_SUCCESS (0) +#define NETNAME_PENDING (-1) +#define NETNAME_NOT_YOURS (1000) +#define NAME_NOT_YOURS (1000) +#define NETNAME_NOT_CHECKED_IN (1001) +#define NAME_NOT_CHECKED_IN (1001) +#define NETNAME_NO_SUCH_HOST (1002) +#define NETNAME_HOST_NOT_FOUND (1003) +#define NETNAME_INVALID_PORT (1004) + +typedef char netname_name_t[80]; + +#endif /* NETNAME_DEFS_ */ diff --git a/mach/servers/nm_defs.h b/mach/servers/nm_defs.h new file mode 100644 index 0000000..641a2e7 --- /dev/null +++ b/mach/servers/nm_defs.h @@ -0,0 +1,78 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Mach Operating System + * Copyright (c) 1987 Carnegie-Mellon University + * All rights reserved. The CMU software License Agreement specifies + * the terms and conditions for use and redistribution. + */ + +/* + * Random definitions for the network service that everyone needs! + */ + +/* + * HISTORY: + * 27-Mar-90 Gregg Kellogg (gk) at NeXT + * include rather than + * + * 24-Aug-88 Daniel Julin (dpj) at Carnegie-Mellon University + * Replace sys/mach_ipc_netport.h with kern/ipc_netport.h. Sigh. + * + * 24-May-88 Daniel Julin (dpj) at Carnegie-Mellon University + * Replace mach_ipc_vmtp.h with mach_ipc_netport.h. + * + * 4-Sep-87 Daniel Julin (dpj) at Carnegie-Mellon University + * Fixed for new kernel include files which declare a lot + * of network server stuff internally, because of the NETPORT + * option. + * + * 5-Nov-86 Robert Sansom (rds) at Carnegie-Mellon University + * Started. + * + */ + +#ifndef _NM_DEFS_ +#define _NM_DEFS_ + +/* + * netaddr_t is declared with the kernel files, + * in . + */ +#include + +#ifdef notdef +typedef unsigned long netaddr_t; +#endif /* notdef */ + +typedef union { + struct { + unsigned char ia_net_owner; + unsigned char ia_net_node_type; + unsigned char ia_host_high; + unsigned char ia_host_low; + } ia_bytes; + netaddr_t ia_netaddr; +} ip_addr_t; + +#endif /* _NM_DEFS_ */ + diff --git a/mach/servers/srvbootstrap.defs b/mach/servers/srvbootstrap.defs new file mode 100644 index 0000000..43a0b60 --- /dev/null +++ b/mach/servers/srvbootstrap.defs @@ -0,0 +1,360 @@ +/* + * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This 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@ + */ +/* + * bootstrap -- fundamental service initiator and port server + * Mike DeMoney, NeXT, Inc. + * Copyright, 1990. All rights reserved. + * + * bootstrap.defs -- Mig interface definition + */ + +subsystem bootstrap 400; + +/* + * Interface: Bootstrap server + * + * The bootstrap server is the first user-mode task initiated by the Mach + * kernel at system boot time. The bootstrap server provides two services, + * it initiates other system tasks, and manages a table of name-port bindings + * for fundamental system services (e.g. lookupd, Window Manager, etc...). + * + * Name-port bindings can be established with the bootstrap server by either + * of two mechanisms: + * + * 1. The binding can be indicated, in advance of the service that backs it + * being available, via a "service create" request. In this case, bootstrap + * will immediately create a port and bind the indicated name with that port. + * At a later time, a service may "checkin" for the name-port + * binding and will be returned receive rights for the bound port. Lookup's + * on bindings created by this mechanism will return send rights to the port, + * even if no service has "checked-in". In this case, requests sent to the + * bound port will be queued until a server has checked-in and can satisfy the + * request. + * + * 2. Bindings can be established dynamically via a "register" request. In + * this case, the register request provides bootstrap with a name and send + * rights for a port. Bootstrap will provide send rights for the bound port + * to any requestor via the lookup request. + * + * Bootstrap provides its service port to descendant tasks via the Mach + * "bootstrap" special task port. All direct descendants of bootstrap receive + * a "privileged" bootstrap service port. System services that initiate + * untrusted tasks should replace the Mach bootstrap task special port with + * a subset bootstrap port to prevent them from infecting the namespace. + * + * The bootstrap server creates a "backup" port for each service that it + * creates. This is used to detect when a checked out service is no longer + * being served. The bootstrap server regains all rights to the port and + * it is marked available for check-out again. This allows crashed servers to + * resume service to previous clients. Lookup's on this named port will + * continue to be serviced by bootstrap while holding receive rights for the + * bound port. A client may detect that the service is inactive via the + * bootstrap status request. If an inactive service re-registers rather + * than "checking-in" the original bound port is destroyed. + * + * The status of a named service may be obtained via the "status" request. + * A service is "active" if a name-port binding exists and receive rights + * to the bound port are held by a task other than bootstrap. + * + * The bootstrap server may also (re)start server processes associated with + * with a set of services. The definition of the server process is done + * through the "create server" request. The server will be launched in the + * same bootstrap context in which it was registered. + */ + +#include +#include +import ; + +type cmd_t = c_string[512]; +type name_t = c_string[128]; +type cmd_array_t = ^array [] of cmd_t; +type name_array_t = ^array [] of name_t; +type bootstrap_status_t = integer_t; +type bootstrap_status_array_t = ^array [] of bootstrap_status_t; + +serverprefix x_; + +/* + * kern_return_t + * bootstrap_create_server(mach_port_t bootstrap_port, + * cmd_t server_command, + * integer_t server_uid, + * boolean_t on_demand, + * mach_port_t *server_port) + * + * Declares a server that mach_init will re-spawn within the specified + * bootstrap context. The server is considered already "active" + * (i.e. will not be re-spawned) until the returned server_port is + * deallocated. + * + * In the meantime, services can be declared against the server, + * by using the server_port as the privileged bootstrap target of + * subsequent bootstrap_create_service() calls. + * + * When mach_init re-spawns the server, its task bootstrap port + * is set to the privileged sever_port. Through this special + * bootstrap port, it can access all of parent bootstrap's context + * (and all services are created in the parent's namespace). But + * all additional service declarations (and declaration removals) + * will be associated with this particular server. + * + * Only a holder of the server_port privilege bootstrap port can + * check in or register over those services. + * + * When all services associated with a server are deleted, and the server + * exits, it will automatically be deleted itself. + * + * If the server is declared "on_demand," then a non-running server + * will be re-launched on first use of one of the service ports + * registered against it. Otherwise, it will be re-launched + * immediately upon exiting (whether any client is actively using + * any of the service ports or not). + * + * Errors: Returns appropriate kernel errors on rpc failure. + * Returns BOOTSTRAP_NOT_PRIVILEGED, bootstrap or uid invalid. + */ +routine bootstrap_create_server( + bootstrap_port : mach_port_t; + server_cmd : cmd_t; + server_uid : integer_t; + on_demand : boolean_t; + ServerSecToken token : security_token_t; + out server_port : mach_port_make_send_t); + +/* + * kern_return_t + * bootstrap_unprivileged(mach_port_t bootstrap_port, + * mach_port_t *unpriv_port) + * + * Given a bootstrap port, return its unprivileged equivalent. If + * the port is already unprivileged, another reference to the same + * port is returned. + * + * This is most often used by servers, which are launched with their + * bootstrap port set to the privileged port for the server, to get + * an unprivileged version of the same port for use by its unprivileged + * children (or any offspring that it does not want to count as part + * of the "server" for mach_init registration and re-launch purposes). + */ +routine bootstrap_unprivileged( + bootstrap_port : mach_port_t; + out unpriv_port : mach_port_t); + +/* + * kern_return_t + * bootstrap_check_in(mach_port_t bootstrap_port, + * name_t service_name, + * mach_port_t *service_port) + * + * Returns the receive right for the service named by service_name. The + * service must have previously been declared in this bootstrap context via + * a call to bootstrap_create_service(). Attempts to check_in a service + * which is already active are not allowed. + * + * If the service was declared as being associated with a server, the + * check_in must come from the server's privileged port (server_port). + * + * Errors: Returns appropriate kernel errors on rpc failure. + * Returns BOOTSTRAP_UNKNOWN_SERVICE, if service does not exist. + * Returns BOOTSTRAP_NOT_PRIVILEGED, if request directed to + * bootstrap port without privilege. + * Returns BOOTSTRAP_SERVICE_ACTIVE, if service has already been + * registered or checked-in. + */ +routine bootstrap_check_in( + bootstrap_port : mach_port_t; + service_name : name_t; + out service_port : mach_port_move_receive_t); + +/* + * kern_return_t + * bootstrap_register(mach_port_t bootstrap_port, + * name_t service_name, + * mach_port_t service_port) + * + * Registers a send right for service_port with the service identified by + * service_name. Attempts to register a service where an active binding + * already exists are rejected. + * + * If the service was previously declared with bootstrap_create_service(), + * but is not currently active, this call can be used to undeclare the + * service. The bootstrap port used must have sufficient privilege to + * do so. (Registering MACH_PORT_NULL is especially useful for shutting + * down declared services). + * + * Errors: Returns appropriate kernel errors on rpc failure. + * Returns BOOTSTRAP_NOT_PRIVILEGED, if request directed to + * bootstrap port without privilege. + * Returns BOOTSTRAP_NAME_IN_USE, if service has already been + * register or checked-in. + */ +routine bootstrap_register( + bootstrap_port : mach_port_t; + service_name : name_t; + service_port : mach_port_t); + +/* + * kern_return_t + * bootstrap_look_up(mach_port_t bootstrap_port, + * name_t service_name, + * mach_port_t *service_port) + * + * Returns a send right for the service port declared/registered under the + * name service_name. The service is not guaranteed to be active. Use the + * bootstrap_status call to determine the status of the service. + * + * Errors: Returns appropriate kernel errors on rpc failure. + * Returns BOOTSTRAP_UNKNOWN_SERVICE, if service does not exist. + */ +routine bootstrap_look_up( + bootstrap_port : mach_port_t; + service_name : name_t; + out service_port : mach_port_t); + +/* + * kern_return_t + * bootstrap_look_up_array(mach_port_t bootstrap_port, + * name_array_t service_names, + * int service_names_cnt, + * port_array_t *service_port, + * int *service_ports_cnt, + * boolean_t *all_services_known) + * + * Returns port send rights in corresponding entries of the array service_ports + * for all services named in the array service_names. Service_ports_cnt is + * returned and will always equal service_names_cnt (assuming service_names_cnt + * is greater than or equal to zero). + * + * Errors: Returns appropriate kernel errors on rpc failure. + * Returns BOOTSTRAP_NO_MEMORY, if server couldn't obtain memory + * for response. + * Unknown service names have the corresponding service port set + * to PORT_NULL. + * If all services are known, all_services_known is true on + * return, if any service is unknown, it's false. + */ +routine bootstrap_look_up_array( + bootstrap_port : mach_port_t; + service_names : name_array_t; + out service_ports : mach_port_array_t; + out all_services_known: boolean_t); + +/* + * kern_return_t + * bootstrap_parent(mach_port_t bootstrap_port, + * mach_port_t *parent_port); + * + * Given a bootstrap subset port, return the parent bootstrap port. + * If the specified bootstrap port is already the root subset, + * MACH_PORT_NULL will be returned. + * + * Errors: + * Returns BOOTSTRAP_NOT_PRIVILEGED if the caller is not running + * with an effective user id of root (as determined by the security + * token in the message trailer). + */ +routine bootstrap_parent( + bootstrap_port : mach_port_t; + ServerSecToken token : security_token_t; + out parent_port : mach_port_t); + +/* + * kern_return_t + * bootstrap_status(mach_port_t bootstrap_port, + * name_t service_name, + * bootstrap_status_t *service_active); + * + * Returns: service_active indicates if service is active, inactive, or + * associated with a launch-on-demand server. + * + * Errors: Returns appropriate kernel errors on rpc failure. + * Returns BOOTSTRAP_UNKNOWN_SERVICE, if service does not exist. + */ +routine bootstrap_status( + bootstrap_port : mach_port_t; + service_name : name_t; + out service_active : bootstrap_status_t); + +/* + * kern_return_t + * bootstrap_info(port_t bootstrap_port, + * name_array_t *service_names, + * int *service_names_cnt, + * name_array_t *server_names, + * int *server_names_cnt, + * bool_array_t *service_active, + * int *service_active_cnt); + * + * Errors: Returns appropriate kernel errors on rpc failure. + */ +routine bootstrap_info( + bootstrap_port : mach_port_t; + out service_names : name_array_t, dealloc; + out server_names : name_array_t, dealloc; + out service_active : bootstrap_status_array_t, dealloc); + +/* + * kern_return_t + * bootstrap_subset(mach_port_t bootstrap_port, + * mach_port_t requestor_port, + * mach_port_t *subset_port); + * + * Returns a new port to use as a bootstrap port. This port behaves + * exactly like the previous bootstrap_port, except that ports dynamically + * registered via bootstrap_register() are available only to users of this + * specific subset_port. Lookups on the subset_port will return ports + * registered with this port specifically, and ports registered with + * ancestors of this subset_port. Duplications of services already + * registered with an ancestor port may be registered with the subset port + * are allowed. Services already advertised may then be effectively removed + * by registering PORT_NULL for the service. + * When it is detected that the requestor_port is destroyed the subset + * port and all services advertized by it are destroied as well. + * + * Errors: Returns appropriate kernel errors on rpc failure. + */ +routine bootstrap_subset( + bootstrap_port : mach_port_t; + requestor_port : mach_port_t; + out subset_port : mach_port_t); + +/* + * kern_return_t + * bootstrap_create_service(mach_port_t bootstrap_port, + * name_t service_name, + * mach_port_t *service_port) + * + * Creates a service named "service_name" and returns send rights to that + * port in "service_port." The port may later be checked in as if this + * port were configured in the bootstrap configuration file. + * + * Errors: Returns appropriate kernel errors on rpc failure. + * Returns BOOTSTRAP_SERVICE_ACTIVE, if service already exists. + */ +routine bootstrap_create_service( + bootstrap_port : mach_port_t; + service_name : name_t; + out service_port : mach_port_t); + diff --git a/mach/slot_name.c b/mach/slot_name.c new file mode 100644 index 0000000..814ea0a --- /dev/null +++ b/mach/slot_name.c @@ -0,0 +1,82 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * File: slot_name.c + * Author: Avadis Tevanian, Jr. + * + * Copyright (C) 1987, Avadis Tevanian, Jr. + * + * Convert machine slot values to human readable strings. + * + * HISTORY + * 26-Jan-88 Mary Thompson (mrt) at Carnegie Mellon + * added case for CUP_SUBTYPE_RT_APC + * + * 28-Feb-87 Avadis Tevanian (avie) at Carnegie-Mellon University + * Created. + * + */ + +#include +#include +#include + +/* + * Convert the specified cpu_type/cpu_subtype pair to their + * human readable form. + */ +void slot_name(cpu_type, cpu_subtype, cpu_name, cpu_subname) + cpu_type_t cpu_type; + cpu_subtype_t cpu_subtype; + char **cpu_name, **cpu_subname; +{ + register char *name = "Unknown CPU"; + register char *subname = ""; + const NXArchInfo *ai = NXGetArchInfoFromCpuType(cpu_type, cpu_subtype); + if (ai != NULL) { + name = ai->name; + subname = ai->description; + } + *cpu_name = name; + *cpu_subname = subname; +} + +kern_return_t msg_rpc(void) { + return KERN_FAILURE; +} + +kern_return_t msg_send(void) { + return KERN_FAILURE; +} + +kern_return_t msg_receive(void) { + return KERN_FAILURE; +} + +mach_port_t task_self_(void) { + return mach_task_self(); +} + +mach_port_t host_self(void) { + return mach_host_self(); +} + diff --git a/mach/task.defs b/mach/task.defs new file mode 100644 index 0000000..af6399f --- /dev/null +++ b/mach/task.defs @@ -0,0 +1 @@ +#include \ No newline at end of file diff --git a/mach/thread_act.defs b/mach/thread_act.defs new file mode 100644 index 0000000..8c515f8 --- /dev/null +++ b/mach/thread_act.defs @@ -0,0 +1 @@ +#include \ No newline at end of file diff --git a/mach/vm_map.defs b/mach/vm_map.defs new file mode 100644 index 0000000..36aa954 --- /dev/null +++ b/mach/vm_map.defs @@ -0,0 +1 @@ +#include diff --git a/net.subproj/Makefile b/net.subproj/Makefile deleted file mode 100644 index 7417017..0000000 --- a/net.subproj/Makefile +++ /dev/null @@ -1,47 +0,0 @@ -# -# Generated by the NeXT Project Builder. -# -# NOTE: Do NOT change this file -- Project Builder maintains it. -# -# Put all of your customizations in files called Makefile.preamble -# and Makefile.postamble (both optional), and Makefile will include them. -# - -NAME = net - -PROJECTVERSION = 2.8 -PROJECT_TYPE = Component - -CFILES = inet_addr.c inet_lnaof.c inet_makeaddr.c inet_netof.c\ - inet_network.c inet_ntoa.c iso_addr.c linkaddr.c ns_addr.c\ - ns_ntoa.c nsap_addr.c recv.c - -OTHERSRCS = Makefile.preamble Makefile Makefile.postamble - - -MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles -CODE_GEN_STYLE = DYNAMIC -MAKEFILE = subproj.make -LIBS = -DEBUG_LIBS = $(LIBS) -PROF_LIBS = $(LIBS) - - - - -NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc -WINDOWS_OBJCPLUS_COMPILER = $(DEVDIR)/gcc -PDO_UNIX_OBJCPLUS_COMPILER = $(NEXTDEV_BIN)/gcc -NEXTSTEP_JAVA_COMPILER = /usr/bin/javac -WINDOWS_JAVA_COMPILER = $(JDKBINDIR)/javac.exe -PDO_UNIX_JAVA_COMPILER = $(JDKBINDIR)/javac - -include $(MAKEFILEDIR)/platform.make - --include Makefile.preamble - -include $(MAKEFILEDIR)/$(MAKEFILE) - --include Makefile.postamble - --include Makefile.dependencies diff --git a/net.subproj/Makefile.postamble b/net.subproj/Makefile.postamble deleted file mode 100644 index 411cde6..0000000 --- a/net.subproj/Makefile.postamble +++ /dev/null @@ -1,100 +0,0 @@ -############################################################################### -# Makefile.postamble -# Copyright 1997, Apple Computer, Inc. -# -# Use this makefile, which is imported after all other makefiles, to -# override attributes for a project's Makefile environment. This allows you -# to take advantage of the environment set up by the other Makefiles. -# You can also define custom rules at the end of this file. -# -############################################################################### -# -# These variables are exported by the standard makefiles and can be -# used in any customizations you make. They are *outputs* of -# the Makefiles and should be used, not set. -# -# PRODUCTS: products to install. All of these products will be placed in -# the directory $(DSTROOT)$(INSTALLDIR) -# GLOBAL_RESOURCE_DIR: The directory to which resources are copied. -# LOCAL_RESOURCE_DIR: The directory to which localized resources are copied. -# OFILE_DIR: Directory into which .o object files are generated. -# DERIVED_SRC_DIR: Directory used for all other derived files -# -# ALL_CFLAGS: flags to pass when compiling .c files -# ALL_MFLAGS: flags to pass when compiling .m files -# ALL_CCFLAGS: flags to pass when compiling .cc, .cxx, and .C files -# ALL_MMFLAGS: flags to pass when compiling .mm, .mxx, and .M files -# ALL_PRECOMPFLAGS: flags to pass when precompiling .h files -# ALL_LDFLAGS: flags to pass when linking object files -# ALL_LIBTOOL_FLAGS: flags to pass when libtooling object files -# ALL_PSWFLAGS: flags to pass when processing .psw and .pswm (pswrap) files -# ALL_RPCFLAGS: flags to pass when processing .rpc (rpcgen) files -# ALL_YFLAGS: flags to pass when processing .y (yacc) files -# ALL_LFLAGS: flags to pass when processing .l (lex) files -# -# NAME: name of application, bundle, subproject, palette, etc. -# LANGUAGES: langages in which the project is written (default "English") -# English_RESOURCES: localized resources (e.g. nib's, images) of project -# GLOBAL_RESOURCES: non-localized resources of project -# -# SRCROOT: base directory in which to place the new source files -# SRCPATH: relative path from SRCROOT to present subdirectory -# -# INSTALLDIR: Directory the product will be installed into by 'install' target -# PUBLIC_HDR_INSTALLDIR: where to install public headers. Don't forget -# to prefix this with DSTROOT when you use it. -# PRIVATE_HDR_INSTALLDIR: where to install private headers. Don't forget -# to prefix this with DSTROOT when you use it. -# -# EXECUTABLE_EXT: Executable extension for the platform (i.e. .exe on Windows) -# -############################################################################### - -# Some compiler flags can be overridden here for certain build situations. -# -# WARNING_CFLAGS: flag used to set warning level (defaults to -Wmost) -# DEBUG_SYMBOLS_CFLAGS: debug-symbol flag passed to all builds (defaults -# to -g) -# DEBUG_BUILD_CFLAGS: flags passed during debug builds (defaults to -DDEBUG) -# OPTIMIZE_BUILD_CFLAGS: flags passed during optimized builds (defaults -# to -O) -# PROFILE_BUILD_CFLAGS: flags passed during profile builds (defaults -# to -pg -DPROFILE) -# LOCAL_DIR_INCLUDE_DIRECTIVE: flag used to add current directory to -# the include path (defaults to -I.) -# DEBUG_BUILD_LDFLAGS, OPTIMIZE_BUILD_LDFLAGS, PROFILE_BUILD_LDFLAGS: flags -# passed to ld/libtool (defaults to nothing) - - -# Library and Framework projects only: -# INSTALL_NAME_DIRECTIVE: This directive ensures that executables linked -# against the framework will run against the correct version even if -# the current version of the framework changes. You may override this -# to "" as an alternative to using the DYLD_LIBRARY_PATH during your -# development cycle, but be sure to restore it before installing. - - -# Ownership and permissions of files installed by 'install' target - -#INSTALL_AS_USER = root - # User/group ownership -#INSTALL_AS_GROUP = wheel - # (probably want to set both of these) -#INSTALL_PERMISSIONS = - # If set, 'install' chmod's executable to this - - -# Options to strip. Note: -S strips debugging symbols (executables can be stripped -# down further with -x or, if they load no bundles, with no options at all). - -#STRIPFLAGS = -S - - -######################################################################### -# Put rules to extend the behavior of the standard Makefiles here. Include them in -# the dependency tree via cvariables like AFTER_INSTALL in the Makefile.preamble. -# -# You should avoid redefining things like "install" or "app", as they are -# owned by the top-level Makefile API and no context has been set up for where -# derived files should go. -# diff --git a/net.subproj/Makefile.preamble b/net.subproj/Makefile.preamble deleted file mode 100644 index c1624b4..0000000 --- a/net.subproj/Makefile.preamble +++ /dev/null @@ -1,137 +0,0 @@ -############################################################################### -# Makefile.preamble -# Copyright 1997, Apple Computer, Inc. -# -# Use this makefile for configuring the standard application makefiles -# associated with ProjectBuilder. It is included before the main makefile. -# In Makefile.preamble you set attributes for a project, so they are available -# to the project's makefiles. In contrast, you typically write additional rules or -# override built-in behavior in the Makefile.postamble. -# -# Each directory in a project tree (main project plus subprojects) should -# have its own Makefile.preamble and Makefile.postamble. -############################################################################### -# -# Before the main makefile is included for this project, you may set: -# -# MAKEFILEDIR: Directory in which to find $(MAKEFILE) -# MAKEFILE: Top level mechanism Makefile (e.g., app.make, bundle.make) - -# Compiler/linker flags added to the defaults: The OTHER_* variables will be -# inherited by all nested sub-projects, but the LOCAL_ versions of the same -# variables will not. Put your -I, -D, -U, and -L flags in ProjectBuilder's -# Build Attributes inspector if at all possible. To override the default flags -# that get passed to ${CC} (e.g. change -O to -O2), see Makefile.postamble. The -# variables below are *inputs* to the build process and distinct from the override -# settings done (less often) in the Makefile.postamble. -# -# OTHER_CFLAGS, LOCAL_CFLAGS: additional flags to pass to the compiler -# Note that $(OTHER_CFLAGS) and $(LOCAL_CFLAGS) are used for .h, ...c, .m, -# .cc, .cxx, .C, and .M files. There is no need to respecify the -# flags in OTHER_MFLAGS, etc. -# OTHER_MFLAGS, LOCAL_MFLAGS: additional flags for .m files -# OTHER_CCFLAGS, LOCAL_CCFLAGS: additional flags for .cc, .cxx, and ...C files -# OTHER_MMFLAGS, LOCAL_MMFLAGS: additional flags for .mm and .M files -# OTHER_PRECOMPFLAGS, LOCAL_PRECOMPFLAGS: additional flags used when -# precompiling header files -# OTHER_LDFLAGS, LOCAL_LDFLAGS: additional flags passed to ld and libtool -# OTHER_PSWFLAGS, LOCAL_PSWFLAGS: additional flags passed to pswrap -# OTHER_RPCFLAGS, LOCAL_RPCFLAGS: additional flags passed to rpcgen -# OTHER_YFLAGS, LOCAL_YFLAGS: additional flags passed to yacc -# OTHER_LFLAGS, LOCAL_LFLAGS: additional flags passed to lex - -# These variables provide hooks enabling you to add behavior at almost every -# stage of the make: -# -# BEFORE_PREBUILD: targets to build before installing headers for a subproject -# AFTER_PREBUILD: targets to build after installing headers for a subproject -# BEFORE_BUILD_RECURSION: targets to make before building subprojects -# BEFORE_BUILD: targets to make before a build, but after subprojects -# AFTER_BUILD: targets to make after a build -# -# BEFORE_INSTALL: targets to build before installing the product -# AFTER_INSTALL: targets to build after installing the product -# BEFORE_POSTINSTALL: targets to build before postinstalling every subproject -# AFTER_POSTINSTALL: targts to build after postinstalling every subproject -# -# BEFORE_INSTALLHDRS: targets to build before installing headers for a -# subproject -# AFTER_INSTALLHDRS: targets to build after installing headers for a subproject -# BEFORE_INSTALLSRC: targets to build before installing source for a subproject -# AFTER_INSTALLSRC: targets to build after installing source for a subproject -# -# BEFORE_DEPEND: targets to build before building dependencies for a -# subproject -# AFTER_DEPEND: targets to build after building dependencies for a -# subproject -# -# AUTOMATIC_DEPENDENCY_INFO: if YES, then the dependency file is -# updated every time the project is built. If NO, the dependency -# file is only built when the depend target is invoked. - -# Framework-related variables: -# FRAMEWORK_DLL_INSTALLDIR: On Windows platforms, this variable indicates -# where to put the framework's DLL. This variable defaults to -# $(INSTALLDIR)/../Executables - -# Library-related variables: -# PUBLIC_HEADER_DIR: Determines where public exported header files -# should be installed. Do not include $(DSTROOT) in this value -- -# it is prefixed automatically. For library projects you should -# set this to something like /Developer/Headers/$(NAME). Do not set -# this variable for framework projects unless you do not want the -# header files included in the framework. -# PRIVATE_HEADER_DIR: Determines where private exported header files -# should be installed. Do not include $(DSTROOT) in this value -- -# it is prefixed automatically. -# LIBRARY_STYLE: This may be either STATIC or DYNAMIC, and determines -# whether the libraries produced are statically linked when they -# are used or if they are dynamically loadable. This defaults to -# DYNAMIC. -# LIBRARY_DLL_INSTALLDIR: On Windows platforms, this variable indicates -# where to put the library's DLL. This variable defaults to -# $(INSTALLDIR)/../Executables -# -# INSTALL_AS_USER: owner of the intalled products (default root) -# INSTALL_AS_GROUP: group of the installed products (default wheel) -# INSTALL_PERMISSIONS: permissions of the installed product (default o+rX) -# -# OTHER_RECURSIVE_VARIABLES: The names of variables which you want to be -# passed on the command line to recursive invocations of make. Note that -# the values in OTHER_*FLAGS are inherited by subprojects automatically -- -# you do not have to (and shouldn't) add OTHER_*FLAGS to -# OTHER_RECURSIVE_VARIABLES. - -# Additional headers to export beyond those in the PB.project: -# OTHER_PUBLIC_HEADERS -# OTHER_PROJECT_HEADERS -# OTHER_PRIVATE_HEADERS - -# Additional files for the project's product: <> -# OTHER_RESOURCES: (non-localized) resources for this project -# OTHER_OFILES: relocatables to be linked into this project -# OTHER_LIBS: more libraries to link against -# OTHER_PRODUCT_DEPENDS: other dependencies of this project -# OTHER_SOURCEFILES: other source files maintained by .pre/postamble -# OTHER_GARBAGE: additional files to be removed by `make clean' - -# Set this to YES if you don't want a final libtool call for a library/framework. -# BUILD_OFILES_LIST_ONLY - -# To include a version string, project source must exist in a directory named -# $(NAME).%d[.%d][.%d] and the following line must be uncommented. -# OTHER_GENERATED_OFILES = $(VERS_OFILE) - -# This definition will suppress stripping of debug symbols when an executable -# is installed. By default it is YES. -# STRIP_ON_INSTALL = NO - -# Uncomment to suppress generation of a KeyValueCoding index when installing -# frameworks (This index is used by WOB and IB to determine keys available -# for an object). Set to YES by default. -# PREINDEX_FRAMEWORK = NO - -# Change this definition to install projects somewhere other than the -# standard locations. NEXT_ROOT defaults to "C:/Apple" on Windows systems -# and "" on other systems. -DSTROOT = $(HOME) diff --git a/net.subproj/PB.project b/net.subproj/PB.project deleted file mode 100644 index 172eb9c..0000000 --- a/net.subproj/PB.project +++ /dev/null @@ -1,36 +0,0 @@ -{ - DYNAMIC_CODE_GEN = YES; - FILESTABLE = { - H_FILES = (); - OTHER_LINKED = ( - inet_addr.c, - inet_lnaof.c, - inet_makeaddr.c, - inet_netof.c, - inet_network.c, - inet_ntoa.c, - iso_addr.c, - linkaddr.c, - ns_addr.c, - ns_ntoa.c, - nsap_addr.c, - recv.c - ); - OTHER_SOURCES = (Makefile.preamble, Makefile, Makefile.postamble); - SUBPROJECTS = (); - }; - LANGUAGE = English; - MAKEFILEDIR = "$(MAKEFILEPATH)/pb_makefiles"; - NEXTSTEP_BUILDTOOL = /bin/gnumake; - NEXTSTEP_JAVA_COMPILER = /usr/bin/javac; - NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc; - PDO_UNIX_BUILDTOOL = $NEXT_ROOT/Developer/bin/make; - PDO_UNIX_JAVA_COMPILER = "$(JDKBINDIR)/javac"; - PDO_UNIX_OBJCPLUS_COMPILER = "$(NEXTDEV_BIN)/gcc"; - PROJECTNAME = net; - PROJECTTYPE = Component; - PROJECTVERSION = 2.8; - WINDOWS_BUILDTOOL = $NEXT_ROOT/Developer/Executables/make; - WINDOWS_JAVA_COMPILER = "$(JDKBINDIR)/javac.exe"; - WINDOWS_OBJCPLUS_COMPILER = "$(DEVDIR)/gcc"; -} diff --git a/net.subproj/inet_addr.c b/net.subproj/inet_addr.c deleted file mode 100644 index 646a95d..0000000 --- a/net.subproj/inet_addr.c +++ /dev/null @@ -1,170 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1983, 1990, 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 -#include -#include -#include - -/* - * Ascii internet address interpretation routine. - * The value returned is in network order. - */ -u_long -inet_addr(cp) - register const char *cp; -{ - struct in_addr val; - - if (inet_aton(cp, &val)) - return (val.s_addr); - return (INADDR_NONE); -} - -/* - * Check whether "cp" is a valid ascii representation - * of an Internet address and convert to a binary address. - * Returns 1 if the address is valid, 0 if not. - * This replaces inet_addr, the return value from which - * cannot distinguish between failure and a local broadcast address. - */ -int -inet_aton(cp, addr) - register const char *cp; - struct in_addr *addr; -{ - register u_long val; - register int base, n; - register char c; - u_int parts[4]; - register u_int *pp = parts; - - for (;;) { - /* - * Collect number up to ``.''. - * Values are specified as for C: - * 0x=hex, 0=octal, other=decimal. - */ - val = 0; base = 10; - if (*cp == '0') { - if (*++cp == 'x' || *cp == 'X') - base = 16, cp++; - else - base = 8; - } - while ((c = *cp) != '\0') { - if (isascii(c) && isdigit(c)) { - val = (val * base) + (c - '0'); - cp++; - continue; - } - if (base == 16 && isascii(c) && isxdigit(c)) { - val = (val << 4) + - (c + 10 - (islower(c) ? 'a' : 'A')); - cp++; - continue; - } - break; - } - if (*cp == '.') { - /* - * Internet format: - * a.b.c.d - * a.b.c (with c treated as 16-bits) - * a.b (with b treated as 24 bits) - */ - if (pp >= parts + 3 || val > 0xff) - return (0); - *pp++ = val, cp++; - } else - break; - } - /* - * Check for trailing characters. - */ - if (*cp && (!isascii(*cp) || !isspace(*cp))) - return (0); - /* - * Concoct the address according to - * the number of parts specified. - */ - n = pp - parts + 1; - switch (n) { - - case 1: /* a -- 32 bits */ - break; - - case 2: /* a.b -- 8.24 bits */ - if (val > 0xffffff) - return (0); - val |= parts[0] << 24; - break; - - case 3: /* a.b.c -- 8.8.16 bits */ - if (val > 0xffff) - return (0); - val |= (parts[0] << 24) | (parts[1] << 16); - break; - - case 4: /* a.b.c.d -- 8.8.8.8 bits */ - if (val > 0xff) - return (0); - val |= (parts[0] << 24) | (parts[1] << 16) | (parts[2] << 8); - break; - } - if (addr) - addr->s_addr = htonl(val); - return (1); -} diff --git a/net.subproj/inet_lnaof.c b/net.subproj/inet_lnaof.c deleted file mode 100644 index 99e72ba..0000000 --- a/net.subproj/inet_lnaof.c +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1983, 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 -#include -#include - -/* - * Return the local network address portion of an - * internet address; handles class a/b/c network - * number formats. - */ -u_long -inet_lnaof(in) - struct in_addr in; -{ - register u_long i = ntohl(in.s_addr); - - if (IN_CLASSA(i)) - return ((i)&IN_CLASSA_HOST); - else if (IN_CLASSB(i)) - return ((i)&IN_CLASSB_HOST); - else - return ((i)&IN_CLASSC_HOST); -} diff --git a/net.subproj/inet_makeaddr.c b/net.subproj/inet_makeaddr.c deleted file mode 100644 index 8789c19..0000000 --- a/net.subproj/inet_makeaddr.c +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1983, 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 -#include -#include - -/* - * Formulate an Internet address from network + host. Used in - * building addresses stored in the ifnet structure. - */ -struct in_addr -inet_makeaddr(net, host) - u_long net, host; -{ - u_long addr; - - if (net < 128) - addr = (net << IN_CLASSA_NSHIFT) | (host & IN_CLASSA_HOST); - else if (net < 65536) - addr = (net << IN_CLASSB_NSHIFT) | (host & IN_CLASSB_HOST); - else if (net < 16777216L) - addr = (net << IN_CLASSC_NSHIFT) | (host & IN_CLASSC_HOST); - else - addr = net | host; - addr = htonl(addr); - return (*(struct in_addr *)&addr); -} diff --git a/net.subproj/inet_netof.c b/net.subproj/inet_netof.c deleted file mode 100644 index c371654..0000000 --- a/net.subproj/inet_netof.c +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1983, 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 -#include -#include - -/* - * Return the network number from an internet - * address; handles class a/b/c network #'s. - */ -u_long -inet_netof(in) - struct in_addr in; -{ - register u_long i = ntohl(in.s_addr); - - if (IN_CLASSA(i)) - return (((i)&IN_CLASSA_NET) >> IN_CLASSA_NSHIFT); - else if (IN_CLASSB(i)) - return (((i)&IN_CLASSB_NET) >> IN_CLASSB_NSHIFT); - else - return (((i)&IN_CLASSC_NET) >> IN_CLASSC_NSHIFT); -} diff --git a/net.subproj/inet_network.c b/net.subproj/inet_network.c deleted file mode 100644 index 07d6e7f..0000000 --- a/net.subproj/inet_network.c +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1983, 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 -#include -#include -#include - -/* - * Internet network address interpretation routine. - * The library routines call this routine to interpret - * network numbers. - */ -u_long -inet_network(cp) - register const char *cp; -{ - register u_long val, base, n; - register char c; - u_long parts[4], *pp = parts; - register int i; - -again: - val = 0; base = 10; - if (*cp == '0') - base = 8, cp++; - if (*cp == 'x' || *cp == 'X') - base = 16, cp++; - while (c = *cp) { - if (isdigit(c)) { - val = (val * base) + (c - '0'); - cp++; - continue; - } - if (base == 16 && isxdigit(c)) { - val = (val << 4) + (c + 10 - (islower(c) ? 'a' : 'A')); - cp++; - continue; - } - break; - } - if (*cp == '.') { - if (pp >= parts + 4) - return (INADDR_NONE); - *pp++ = val, cp++; - goto again; - } - if (*cp && !isspace(*cp)) - return (INADDR_NONE); - *pp++ = val; - n = pp - parts; - if (n > 4) - return (INADDR_NONE); - for (val = 0, i = 0; i < n; i++) { - val <<= 8; - val |= parts[i] & 0xff; - } - return (val); -} diff --git a/net.subproj/inet_ntoa.c b/net.subproj/inet_ntoa.c deleted file mode 100644 index e91f1ea..0000000 --- a/net.subproj/inet_ntoa.c +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1983, 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. - */ - - -/* - * Convert network-format internet address - * to base 256 d.d.d.d representation. - */ -#include -#include -#include -#include - -char * -inet_ntoa(in) - struct in_addr in; -{ - static char b[18]; - register char *p; - - p = (char *)∈ -#define UC(b) (((int)b)&0xff) - (void)snprintf(b, sizeof(b), - "%d.%d.%d.%d", UC(p[0]), UC(p[1]), UC(p[2]), UC(p[3])); - return (b); -} diff --git a/net.subproj/iso_addr.c b/net.subproj/iso_addr.c deleted file mode 100644 index 3267fa8..0000000 --- a/net.subproj/iso_addr.c +++ /dev/null @@ -1,137 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1989, 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 -#include -#include - -/* States*/ -#define VIRGIN 0 -#define GOTONE 1 -#define GOTTWO 2 -/* Inputs */ -#define DIGIT (4*0) -#define END (4*1) -#define DELIM (4*2) - -struct iso_addr * -iso_addr(addr) - register const char *addr; -{ - static struct iso_addr out_addr; - register char *cp = out_addr.isoa_genaddr; - char *cplim = cp + sizeof(out_addr.isoa_genaddr); - register int byte = 0, state = VIRGIN, new; - - bzero((char *)&out_addr, sizeof(out_addr)); - do { - if ((*addr >= '0') && (*addr <= '9')) { - new = *addr - '0'; - } else if ((*addr >= 'a') && (*addr <= 'f')) { - new = *addr - 'a' + 10; - } else if ((*addr >= 'A') && (*addr <= 'F')) { - new = *addr - 'A' + 10; - } else if (*addr == 0) - state |= END; - else - state |= DELIM; - addr++; - switch (state /* | INPUT */) { - case GOTTWO | DIGIT: - *cp++ = byte; /*FALLTHROUGH*/ - case VIRGIN | DIGIT: - state = GOTONE; byte = new; continue; - case GOTONE | DIGIT: - state = GOTTWO; byte = new + (byte << 4); continue; - default: /* | DELIM */ - state = VIRGIN; *cp++ = byte; byte = 0; continue; - case GOTONE | END: - case GOTTWO | END: - *cp++ = byte; /* FALLTHROUGH */ - case VIRGIN | END: - break; - } - break; - } while (cp < cplim); - out_addr.isoa_len = cp - out_addr.isoa_genaddr; - return (&out_addr); -} -static char hexlist[] = "0123456789abcdef"; - -char * -iso_ntoa(isoa) - const struct iso_addr *isoa; -{ - static char obuf[64]; - register char *out = obuf; - register int i; - register u_char *in = (u_char *)isoa->isoa_genaddr; - u_char *inlim = in + isoa->isoa_len; - - out[1] = 0; - while (in < inlim) { - i = *in++; - *out++ = '.'; - if (i > 0xf) { - out[1] = hexlist[i & 0xf]; - i >>= 4; - out[0] = hexlist[i]; - out += 2; - } else - *out++ = hexlist[i]; - } - *out = 0; - return(obuf + 1); -} diff --git a/net.subproj/linkaddr.c b/net.subproj/linkaddr.c deleted file mode 100644 index ffaafff..0000000 --- a/net.subproj/linkaddr.c +++ /dev/null @@ -1,176 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 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 -#include -#include -#include - -/* States*/ -#define NAMING 0 -#define GOTONE 1 -#define GOTTWO 2 -#define RESET 3 -/* Inputs */ -#define DIGIT (4*0) -#define END (4*1) -#define DELIM (4*2) -#define LETTER (4*3) - -void -link_addr(addr, sdl) - register const char *addr; - register struct sockaddr_dl *sdl; -{ - register char *cp = sdl->sdl_data; - char *cplim = sdl->sdl_len + (char *)sdl; - register int byte = 0, state = NAMING, new; - - bzero((char *)&sdl->sdl_family, sdl->sdl_len - 1); - sdl->sdl_family = AF_LINK; - do { - state &= ~LETTER; - if ((*addr >= '0') && (*addr <= '9')) { - new = *addr - '0'; - } else if ((*addr >= 'a') && (*addr <= 'f')) { - new = *addr - 'a' + 10; - } else if ((*addr >= 'A') && (*addr <= 'F')) { - new = *addr - 'A' + 10; - } else if (*addr == 0) { - state |= END; - } else if (state == NAMING && - (((*addr >= 'A') && (*addr <= 'Z')) || - ((*addr >= 'a') && (*addr <= 'z')))) - state |= LETTER; - else - state |= DELIM; - addr++; - switch (state /* | INPUT */) { - case NAMING | DIGIT: - case NAMING | LETTER: - *cp++ = addr[-1]; - continue; - case NAMING | DELIM: - state = RESET; - sdl->sdl_nlen = cp - sdl->sdl_data; - continue; - case GOTTWO | DIGIT: - *cp++ = byte; - /* FALLTHROUGH */ - case RESET | DIGIT: - state = GOTONE; - byte = new; - continue; - case GOTONE | DIGIT: - state = GOTTWO; - byte = new + (byte << 4); - continue; - default: /* | DELIM */ - state = RESET; - *cp++ = byte; - byte = 0; - continue; - case GOTONE | END: - case GOTTWO | END: - *cp++ = byte; - /* FALLTHROUGH */ - case RESET | END: - break; - } - break; - } while (cp < cplim); - sdl->sdl_alen = cp - LLADDR(sdl); - new = cp - (char *)sdl; - if (new > sizeof(*sdl)) - sdl->sdl_len = new; - return; -} - -static char hexlist[] = "0123456789abcdef"; - -char * -link_ntoa(sdl) - register const struct sockaddr_dl *sdl; -{ - static char obuf[64]; - register char *out = obuf; - register int i; - register u_char *in = (u_char *)LLADDR(sdl); - u_char *inlim = in + sdl->sdl_alen; - int firsttime = 1; - - if (sdl->sdl_nlen) { - bcopy(sdl->sdl_data, obuf, sdl->sdl_nlen); - out += sdl->sdl_nlen; - if (sdl->sdl_alen) - *out++ = ':'; - } - while (in < inlim) { - if (firsttime) - firsttime = 0; - else - *out++ = '.'; - i = *in++; - if (i > 0xf) { - out[1] = hexlist[i & 0xf]; - i >>= 4; - out[0] = hexlist[i]; - out += 2; - } else - *out++ = hexlist[i]; - } - *out = 0; - return (obuf); -} diff --git a/net.subproj/ns_addr.c b/net.subproj/ns_addr.c deleted file mode 100644 index 7e98719..0000000 --- a/net.subproj/ns_addr.c +++ /dev/null @@ -1,245 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1986, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * J.Q. Johnson. - * - * 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 -#include -#include -#include - -static struct ns_addr addr, zero_addr; - -static void Field(), cvtbase(); - -struct ns_addr -ns_addr(name) - const char *name; -{ - char separator; - char *hostname, *socketname, *cp; - char buf[50]; - - (void)strncpy(buf, name, sizeof(buf) - 1); - buf[sizeof(buf) - 1] = '\0'; - - /* - * First, figure out what he intends as a field separtor. - * Despite the way this routine is written, the prefered - * form 2-272.AA001234H.01777, i.e. XDE standard. - * Great efforts are made to insure backward compatability. - */ - if (hostname = strchr(buf, '#')) - separator = '#'; - else { - hostname = strchr(buf, '.'); - if ((cp = strchr(buf, ':')) && - ((hostname && cp < hostname) || (hostname == 0))) { - hostname = cp; - separator = ':'; - } else - separator = '.'; - } - if (hostname) - *hostname++ = 0; - - addr = zero_addr; - Field(buf, addr.x_net.c_net, 4); - if (hostname == 0) - return (addr); /* No separator means net only */ - - socketname = strchr(hostname, separator); - if (socketname) { - *socketname++ = 0; - Field(socketname, (u_char *)&addr.x_port, 2); - } - - Field(hostname, addr.x_host.c_host, 6); - - return (addr); -} - -static void -Field(buf, out, len) - char *buf; - u_char *out; - int len; -{ - register char *bp = buf; - int i, ibase, base16 = 0, base10 = 0, clen = 0; - int hb[6], *hp; - char *fmt; - - /* - * first try 2-273#2-852-151-014#socket - */ - if ((*buf != '-') && - (1 < (i = sscanf(buf, "%d-%d-%d-%d-%d", - &hb[0], &hb[1], &hb[2], &hb[3], &hb[4])))) { - cvtbase(1000L, 256, hb, i, out, len); - return; - } - /* - * try form 8E1#0.0.AA.0.5E.E6#socket - */ - if (1 < (i = sscanf(buf,"%x.%x.%x.%x.%x.%x", - &hb[0], &hb[1], &hb[2], &hb[3], &hb[4], &hb[5]))) { - cvtbase(256L, 256, hb, i, out, len); - return; - } - /* - * try form 8E1#0:0:AA:0:5E:E6#socket - */ - if (1 < (i = sscanf(buf,"%x:%x:%x:%x:%x:%x", - &hb[0], &hb[1], &hb[2], &hb[3], &hb[4], &hb[5]))) { - cvtbase(256L, 256, hb, i, out, len); - return; - } - /* - * This is REALLY stretching it but there was a - * comma notation separting shorts -- definitely non standard - */ - if (1 < (i = sscanf(buf,"%x,%x,%x", - &hb[0], &hb[1], &hb[2]))) { - hb[0] = htons(hb[0]); hb[1] = htons(hb[1]); - hb[2] = htons(hb[2]); - cvtbase(65536L, 256, hb, i, out, len); - return; - } - - /* Need to decide if base 10, 16 or 8 */ - while (*bp) switch (*bp++) { - - case '0': case '1': case '2': case '3': case '4': case '5': - case '6': case '7': case '-': - break; - - case '8': case '9': - base10 = 1; - break; - - case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': - case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': - base16 = 1; - break; - - case 'x': case 'X': - *--bp = '0'; - base16 = 1; - break; - - case 'h': case 'H': - base16 = 1; - /* fall into */ - - default: - *--bp = 0; /* Ends Loop */ - } - if (base16) { - fmt = "%3x"; - ibase = 4096; - } else if (base10 == 0 && *buf == '0') { - fmt = "%3o"; - ibase = 512; - } else { - fmt = "%3d"; - ibase = 1000; - } - - for (bp = buf; *bp++; ) clen++; - if (clen == 0) clen++; - if (clen > 18) clen = 18; - i = ((clen - 1) / 3) + 1; - bp = clen + buf - 3; - hp = hb + i - 1; - - while (hp > hb) { - (void)sscanf(bp, fmt, hp); - bp[0] = 0; - hp--; - bp -= 3; - } - (void)sscanf(buf, fmt, hp); - cvtbase((long)ibase, 256, hb, i, out, len); -} - -static void -cvtbase(oldbase,newbase,input,inlen,result,reslen) - long oldbase; - int newbase; - int input[]; - int inlen; - unsigned char result[]; - int reslen; -{ - int d, e; - long sum; - - e = 1; - while (e > 0 && reslen > 0) { - d = 0; e = 0; sum = 0; - /* long division: input=input/newbase */ - while (d < inlen) { - sum = sum*oldbase + (long) input[d]; - e += (sum > 0); - input[d++] = sum / newbase; - sum %= newbase; - } - result[--reslen] = sum; /* accumulate remainder */ - } - for (d=0; d < reslen; d++) - result[d] = 0; -} diff --git a/net.subproj/ns_ntoa.c b/net.subproj/ns_ntoa.c deleted file mode 100644 index e038815..0000000 --- a/net.subproj/ns_ntoa.c +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1986, 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 -#include -#include - -char * -ns_ntoa(addr) - struct ns_addr addr; -{ - static char obuf[40]; - union { union ns_net net_e; u_long long_e; } net; - u_short port = htons(addr.x_port); - register char *cp; - char *cp2; - register u_char *up = addr.x_host.c_host; - u_char *uplim = up + 6; - static char *spectHex(); - - net.net_e = addr.x_net; - sprintf(obuf, "%lx", ntohl(net.long_e)); - cp = spectHex(obuf); - cp2 = cp + 1; - while (*up==0 && up < uplim) up++; - if (up == uplim) { - if (port) { - sprintf(cp, ".0"); - cp += 2; - } - } else { - sprintf(cp, ".%x", *up++); - while (up < uplim) { - while (*cp) cp++; - sprintf(cp, "%02x", *up++); - } - cp = spectHex(cp2); - } - if (port) { - sprintf(cp, ".%x", port); - spectHex(cp + 1); - } - return (obuf); -} - -static char * -spectHex(p0) - char *p0; -{ - int ok = 0; - int nonzero = 0; - register char *p = p0; - for (; *p; p++) switch (*p) { - - case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': - *p += ('A' - 'a'); - /* fall into . . . */ - case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': - ok = 1; - case '1': case '2': case '3': case '4': case '5': - case '6': case '7': case '8': case '9': - nonzero = 1; - } - if (nonzero && !ok) { *p++ = 'H'; *p = 0; } - return (p); -} diff --git a/net.subproj/nsap_addr.c b/net.subproj/nsap_addr.c deleted file mode 100644 index 2c5ebaa..0000000 --- a/net.subproj/nsap_addr.c +++ /dev/null @@ -1,115 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#if defined(LIBC_SCCS) && !defined(lint) -static char rcsid[] = "$Id: nsap_addr.c,v 1.3 2000/06/09 04:01:52 wsanchez Exp $"; -#endif /* LIBC_SCCS and not lint */ - -#include -#include -#include -#include -#include -#include - -#if !defined(isxdigit) /* XXX - could be a function */ -static int -isxdigit(c) - register int c; -{ - return ((c >= '0') && (c <= '9')) || ((c >= 'A') && (c <= 'F')); -} -#endif - -static char -xtob(c) - register int c; -{ - return (c - (((c >= '0') && (c <= '9')) ? '0' : '7')); -} - -u_int -inet_nsap_addr(ascii, binary, maxlen) - const char *ascii; - u_char *binary; - int maxlen; -{ - register u_char c, nib; - u_int len = 0; - - while ((c = *ascii++) != '\0' && len < maxlen) { - if (c == '.' || c == '+' || c == '/') - continue; - if (!isascii(c)) - return (0); - if (islower(c)) - c = toupper(c); - if (isxdigit(c)) { - nib = xtob(c); - if (c = *ascii++) { - c = toupper(c); - if (isxdigit(c)) { - *binary++ = (nib << 4) | xtob(c); - len++; - } else - return (0); - } - else - return (0); - } - else - return (0); - } - return (len); -} - -char * -inet_nsap_ntoa(binlen, binary, ascii) - int binlen; - register const u_char *binary; - register char *ascii; -{ - register int nib; - int i; - static char tmpbuf[255*3]; - char *start; - - if (ascii) - start = ascii; - else { - ascii = tmpbuf; - start = tmpbuf; - } - - if (binlen > 255) - binlen = 255; - - for (i = 0; i < binlen; i++) { - nib = *binary >> 4; - *ascii++ = nib + (nib < 10 ? '0' : '7'); - nib = *binary++ & 0x0f; - *ascii++ = nib + (nib < 10 ? '0' : '7'); - if (((i % 2) == 0 && (i + 1) < binlen)) - *ascii++ = '.'; - } - *ascii = '\0'; - return (start); -} diff --git a/net.subproj/recv.c b/net.subproj/recv.c deleted file mode 100644 index 42645fa..0000000 --- a/net.subproj/recv.c +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1988, 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 -#include - -#include - -ssize_t recv(s, buf, len, flags) - int s, flags; - size_t len; - void *buf; -{ - return (recvfrom(s, buf, len, flags, NULL, 0)); -} diff --git a/net/Makefile.inc b/net/Makefile.inc new file mode 100644 index 0000000..7fe1474 --- /dev/null +++ b/net/Makefile.inc @@ -0,0 +1,54 @@ +# from @(#)Makefile.inc 8.2 (Berkeley) 9/5/93 +# $FreeBSD: src/lib/libc/net/Makefile.inc,v 1.43 2001/10/23 06:22:14 imp Exp $ + +# machine-independent net sources +.PATH: ${.CURDIR}/${MACHINE_ARCH}/net ${.CURDIR}/net + +SRCS+= inet_addr.c inet_netof.c \ + inet_lnaof.c inet_network.c linkaddr.c nsap_addr.c \ + inet_makeaddr.c inet_ntoa.c recv.c + + +CFLAGS+=-DINET6 -I${.OBJDIR} + +YFLAGS+=-p_nsyy +LFLAGS+=-P_nsyy + +CLEANFILES+=nsparser.c nslexer.c nsparser.h + +nsparser.h: nsparser.c + mv y.tab.h ${.TARGET} + +nslexer.c: nslexer.l nsparser.h + ${LEX} ${LFLAGS} -o/dev/stdout ${.IMPSRC} | \ + sed -e '/YY_BUF_SIZE/s/16384/1024/' >${.TARGET} + +# machine-dependent net sources +.if exists(${.CURDIR}/${MACHINE_ARCH}/net/Makefile.inc) +.include "${.CURDIR}/${MACHINE_ARCH}/net/Makefile.inc" +.endif + +.if ${LIB} == "c" +MAN3+= addr2ascii.3 byteorder.3 ethers.3 hesiod.3 \ + inet.3 inet_net.3 \ + nsdispatch.3 rcmdsh.3 resolver.3 +# not installed: iso_addr.3 ns.3 + +MLINKS+=addr2ascii.3 ascii2addr.3 +MLINKS+=byteorder.3 htonl.3 byteorder.3 htons.3 byteorder.3 ntohl.3 \ + byteorder.3 ntohs.3 +MLINKS+=ethers.3 ether_aton.3 ethers.3 ether_hostton.3 ethers.3 ether_line.3 \ + ethers.3 ether_ntoa.3 ethers.3 ether_ntohost.3 +MLINKS+=inet.3 addr.3 inet.3 inet_addr.3 inet.3 inet_aton.3 \ + inet.3 inet_lnaof.3 inet.3 inet_makeaddr.3 inet.3 inet_netof.3 \ + inet.3 inet_network.3 inet.3 inet_ntoa.3 \ + inet.3 inet_ntop.3 inet.3 inet_pton.3 \ + inet.3 network.3 inet.3 ntoa.3 +MLINKS+=inet_net.3 inet_net_ntop.3 inet_net.3 inet_net_pton.3 +#MLINKS+=ns.3 ns_addr.3 ns.3 ns_ntoa.3 +MLINKS+=resolver.3 dn_comp.3 resolver.3 dn_expand.3 resolver.3 res_init.3 \ + resolver.3 res_mkquery.3 resolver.3 res_query.3 \ + resolver.3 res_search.3 resolver.3 res_send.3 resolver.3 dn_skipname.3 \ + resolver.3 ns_get16.3 resolver.3 ns_get32.3 \ + resolver.3 ns_put16.3 resolver.3 ns_put32.3 +.endif diff --git a/net/addr2ascii.3 b/net/addr2ascii.3 new file mode 100644 index 0000000..10b1ac7 --- /dev/null +++ b/net/addr2ascii.3 @@ -0,0 +1,222 @@ +.\" +.\" Copyright 1996 Massachusetts Institute of Technology +.\" +.\" Permission to use, copy, modify, and distribute this software and +.\" its documentation for any purpose and without fee is hereby +.\" granted, provided that both the above copyright notice and this +.\" permission notice appear in all copies, that both the above +.\" copyright notice and this permission notice appear in all +.\" supporting documentation, and that the name of M.I.T. not be used +.\" in advertising or publicity pertaining to distribution of the +.\" software without specific, written prior permission. M.I.T. makes +.\" no representations about the suitability of this software for any +.\" purpose. It is provided "as is" without express or implied +.\" warranty. +.\" +.\" THIS SOFTWARE IS PROVIDED BY M.I.T. ``AS IS''. M.I.T. DISCLAIMS +.\" ALL EXPRESS OR IMPLIED WARRANTIES WITH REGARD TO THIS SOFTWARE, +.\" INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +.\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT +.\" SHALL M.I.T. 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. +.\" +.\" $ANA: addr2ascii.3,v 1.1 1996/06/13 18:41:46 wollman Exp $ +.\" $FreeBSD: src/lib/libc/net/addr2ascii.3,v 1.12 2001/10/01 16:08:55 ru Exp $ +.\" +.Dd June 13, 1996 +.Dt ADDR2ASCII 3 +.Os +.Sh NAME +.Nm addr2ascii , +.Nm ascii2addr +.Nd Generic address formatting routines +.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" +.Ft int +.Fn ascii2addr "int af" "const char *ascii" "void *result" +.Sh DESCRIPTION +The routines +.Fn addr2ascii +and +.Fn ascii2addr +are used to convert network addresses between binary form and a +printable form appropriate to the address family. Both functions take +an +.Fa af +argument, specifying the address family to be used in the conversion +process. +(Currently, only the +.Dv AF_INET +and +.Dv AF_LINK +address families are supported.) +.Pp +The +.Fn addr2ascii +function +is used to convert binary, network-format addresses into printable +form. In addition to +.Fa af , +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 +.Fa buf +argument is an optional pointer to a caller-allocated buffer to hold +the result; if a null pointer is passed, +.Fn addr2ascii +uses a statically-allocated buffer. +.Pp +The +.Fn ascii2addr +function performs the inverse operation to +.Fn addr2ascii . +In addition to +.Fa af , +it takes two parameters, +.Fa ascii +and +.Fa result . +The +.Fa ascii +parameter is a pointer to the string which is to be converted into +binary. The +.Fa result +parameter is a pointer to an appropriate network address structure for +the specified family. +.Pp +The following gives the appropriate structure to use for binary +addresses in the specified family: +.Pp +.Bl -tag -width AF_INETxxxx -compact +.It Dv AF_INET +.Li struct in_addr +(in +.Aq Pa netinet/in.h ) +.It Dv AF_LINK +.Li struct sockaddr_dl +(in +.Aq Pa net/if_dl.h ) +.\" .It Dv AF_INET6 +.\" .Li struct in6_addr +.\" (in +.\" .Aq Pa netinet6/in6.h ) +.El +.Sh RETURN VALUES +The +.Fn addr2ascii +function returns the address of the buffer it was passed, or a static +buffer if the a null pointer was passed; on failure, it returns a null +pointer. +The +.Fn ascii2addr +function returns the length of the binary address in bytes, or -1 on +failure. +.Sh EXAMPLES +The +.Xr inet 3 +functions +.Fn inet_ntoa +and +.Fn inet_aton +could be implemented thusly: +.Bd -literal -offset indent +#include +#include +#include +#include + +char * +inet_ntoa(struct in_addr addr) +{ + return addr2ascii(AF_INET, &addr, sizeof addr, 0); +} + +int +inet_aton(const char *ascii, struct in_addr *addr) +{ + return (ascii2addr(AF_INET, ascii, addr) + == sizeof(*addr)); +} +.Ed +.Pp +In actuality, this cannot be done because +.Fn addr2ascii +and +.Fn ascii2addr +are implemented in terms of the +.Xr inet 3 +functions, rather than the other way around. +.Sh ERRORS +When a failure is returned, +.Li errno +is set to one of the following values: +.Bl -tag -width Er +.It Bq Er ENAMETOOLONG +The +.Fn addr2ascii +routine was passed a +.Fa len +parameter which was inappropriate for the address family given by +.Fa af . +.It Bq Er EPROTONOSUPPORT +Either routine was passed an +.Fa af +parameter other than +.Dv AF_INET +or +.Dv AF_LINK . +.It Bq Er EINVAL +The string passed to +.Fn ascii2addr +was improperly formatted for address family +.Fa af . +.El +.Sh SEE ALSO +.Xr inet 3 , +.Xr linkaddr 3 , +.Xr inet 4 +.Sh HISTORY +An interface close to this one was originally suggested by Craig +Partridge. This particular interface originally appeared in the +.Tn INRIA +.Tn IPv6 +implementation. +.Sh AUTHORS +Code and documentation by +.An Garrett A. Wollman , +MIT Laboratory for Computer Science. +.Sh BUGS +The original implementations supported IPv6. This support should +eventually be resurrected. The +.Tn NRL +implementation also included support for the +.Dv AF_ISO +and +.Dv AF_NS +address families. +.Pp +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 +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. diff --git a/net/byteorder.3 b/net/byteorder.3 new file mode 100644 index 0000000..527bae4 --- /dev/null +++ b/net/byteorder.3 @@ -0,0 +1,84 @@ +.\" Copyright (c) 1983, 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. +.\" +.\" @(#)byteorder.3 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD: src/lib/libc/net/byteorder.3,v 1.8 2001/10/01 16:08:55 ru Exp $ +.\" +.Dd June 4, 1993 +.Dt BYTEORDER 3 +.Os +.Sh NAME +.Nm htonl , +.Nm htons , +.Nm ntohl , +.Nm ntohs +.Nd convert values between host and network byte order +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In arpa/inet.h +.Ft uint32_t +.Fn htonl "uint32_t hostlong" +.Ft uint16_t +.Fn htons "uint16_t hostshort" +.Ft uint32_t +.Fn ntohl "uint32_t netlong" +.Ft uint16_t +.Fn ntohs "uint16_t netshort" +.Sh DESCRIPTION +These routines convert 16 and 32 bit quantities between network +byte order and host byte order. +On machines which have a byte order which is the same as the network +order, routines are defined as null macros. +.Pp +These routines are most often used in conjunction with Internet +addresses and ports as returned by +.Xr gethostbyname 3 +and +.Xr getservent 3 . +.Sh SEE ALSO +.Xr gethostbyname 3 , +.Xr getservent 3 +.Sh STANDARDS +The +.Nm byteorder +functions are expected to conform with IEEE Std POSIX.1-200x +.Pq Dq POSIX.1 . +.Sh HISTORY +The +.Nm byteorder +functions appeared in +.Bx 4.2 . +.Sh BUGS +On the +.Tn VAX +bytes are handled backwards from most everyone else in +the world. This is not expected to be fixed in the near future. diff --git a/net/ethers.3 b/net/ethers.3 new file mode 100644 index 0000000..36a8268 --- /dev/null +++ b/net/ethers.3 @@ -0,0 +1,197 @@ +.\" Copyright (c) 1995 +.\" Bill Paul . 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 Bill Paul. +.\" 4. Neither the name of the author nor the names of any co-contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY Bill Paul 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. +.\" +.\" $FreeBSD: src/lib/libc/net/ethers.3,v 1.18 2001/10/01 16:08:55 ru Exp $ +.\" +.Dd April 12, 1995 +.Dt ETHERS 3 +.Os +.Sh NAME +.Nm ethers , +.Nm ether_line , +.Nm ether_aton , +.Nm ether_ntoa , +.Nm ether_ntohost , +.Nm ether_hostton +.Nd Ethernet address conversion and lookup routines +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In sys/types.h +.In sys/socket.h +.In net/ethernet.h +.Ft int +.Fn ether_line "const char *l" "struct ether_addr *e" "char *hostname" +.Ft struct ether_addr * +.Fn ether_aton "const char *a" +.Ft char * +.Fn ether_ntoa "const struct ether_addr *n" +.Ft int +.Fn ether_ntohost "char *hostname" "const struct ether_addr *e" +.Ft int +.Fn ether_hostton "const char *hostname" "struct ether_addr *e" +.Sh DESCRIPTION +These functions operate on ethernet addresses using an +.Ar ether_addr +structure, which is defined in the header file +.Aq Pa netinet/if_ether.h : +.Bd -literal -offset indent +/* + * The number of bytes in an ethernet (MAC) address. + */ +#define ETHER_ADDR_LEN 6 + +/* + * Structure of a 48-bit Ethernet address. + */ +struct ether_addr { + u_char octet[ETHER_ADDR_LEN]; +}; +.Ed +.Pp +The function +.Fn ether_line +scans +.Ar l , +an +.Tn ASCII +string in +.Xr ethers 5 +format and sets +.Ar e +to the ethernet address specified in the string and +.Ar h +to the hostname. +This function is used to parse lines from +.Pa /etc/ethers +into their component parts. +.Pp +The +.Fn ether_aton +function converts an +.Tn ASCII +representation of an ethernet address into an +.Ar ether_addr +structure. +Likewise, +.Fn ether_ntoa +converts an ethernet address specified as an +.Ar ether_addr +structure into an +.Tn ASCII +string. +.Pp +The +.Fn ether_ntohost +and +.Fn ether_hostton +functions map ethernet addresses to their corresponding hostnames +as specified in the +.Pa /etc/ethers +database. +.Fn ether_ntohost +converts from ethernet address to hostname, and +.Fn ether_hostton +converts from hostname to ethernet address. +.Sh RETURN VALUES +.Fn ether_line +returns zero on success and non-zero if it was unable to parse +any part of the supplied line +.Ar l . +It returns the extracted ethernet address in the supplied +.Ar ether_addr +structure +.Ar e +and the hostname in the supplied string +.Ar h . +.Pp +On success, +.Fn ether_ntoa +returns a pointer to a string containing an +.Tn ASCII +representation of an ethernet address. +If it is unable to convert +the supplied +.Ar ether_addr +structure, it returns a +.Dv NULL +pointer. +Likewise, +.Fn ether_aton +returns a pointer to an +.Ar ether_addr +structure on success and a +.Dv NULL +pointer on failure. +.Pp +The +.Fn ether_ntohost +and +.Fn ether_hostton +functions both return zero on success or non-zero if they were +unable to find a match in the +.Pa /etc/ethers +database. +.Sh NOTES +The user must insure that the hostname strings passed to the +.Fn ether_line , +.Fn ether_ntohost +and +.Fn ether_hostton +functions are large enough to contain the returned hostnames. +.Sh NIS INTERACTION +If the +.Pa /etc/ethers +contains a line with a single + in it, the +.Fn ether_ntohost +and +.Fn ether_hostton +functions will attempt to consult the NIS +.Pa ethers.byname +and +.Pa ethers.byaddr +maps in addition to the data in the +.Pa /etc/ethers +file. +.Sh SEE ALSO +.Xr yp 4 , +.Xr ethers 5 +.Sh BUGS +The +.Fn ether_aton +and +.Fn ether_ntoa +functions returns values that are stored in static memory areas +which may be overwritten the next time they are called. +.Sh HISTORY +This particular implementation of the +.Nm +library functions were written for and first appeared in +.Fx 2.1 . diff --git a/net/getaddrinfo.3 b/net/getaddrinfo.3 new file mode 100644 index 0000000..1ae9e9a --- /dev/null +++ b/net/getaddrinfo.3 @@ -0,0 +1,619 @@ +.\" $FreeBSD: src/lib/libc/net/getaddrinfo.3,v 1.17 2001/10/01 16:08:55 ru Exp $ +.\" $KAME: getaddrinfo.3,v 1.22 2000/08/09 21:16:17 itojun Exp $ +.\" +.\" Copyright (c) 1983, 1987, 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. +.\" +.\" From: @(#)gethostbyname.3 8.4 (Berkeley) 5/25/95 +.\" +.Dd May 25, 1995 +.Dt GETADDRINFO 3 +.Os +.\" +.Sh NAME +.Nm getaddrinfo , +.Nm freeaddrinfo , +.Nm gai_strerror +.Nd nodename-to-address translation in protocol-independent manner +.\" +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In sys/types.h +.In sys/socket.h +.In netdb.h +.Ft int +.Fn getaddrinfo "const char *nodename" "const char *servname" \ +"const struct addrinfo *hints" "struct addrinfo **res" +.Ft void +.Fn freeaddrinfo "struct addrinfo *ai" +.Ft "char *" +.Fn gai_strerror "int ecode" +.\" +.Sh DESCRIPTION +The +.Fn getaddrinfo +function is defined for protocol-independent nodename-to-address translation. +It performs the functionality of +.Xr gethostbyname 3 +and +.Xr getservbyname 3 , +but in a more sophisticated manner. +.Pp +The +.Li addrinfo +structure is defined as a result of including the +.Aq Pa netdb.h +header: +.Bd -literal -offset +struct addrinfo { + int ai_flags; /* AI_PASSIVE, AI_CANONNAME, AI_NUMERICHOST */ + int ai_family; /* PF_xxx */ + int ai_socktype; /* SOCK_xxx */ + int ai_protocol; /* 0 or IPPROTO_xxx for IPv4 and IPv6 */ + size_t ai_addrlen; /* length of ai_addr */ + char *ai_canonname; /* canonical name for nodename */ + struct sockaddr *ai_addr; /* binary address */ + struct addrinfo *ai_next; /* next structure in linked list */ +}; +.Ed +.Pp +The +.Fa nodename +and +.Fa servname +arguments are pointers to null-terminated strings or +.Dv NULL . +One or both of these two arguments must be a +.Pf non Dv -NULL +pointer. +In the normal client scenario, both the +.Fa nodename +and +.Fa servname +are specified. +In the normal server scenario, only the +.Fa servname +is specified. +A +.Pf non Dv -NULL +.Fa nodename +string can be either a node name or a numeric host address string +(i.e., a dotted-decimal IPv4 address or an IPv6 hex address). +A +.Pf non Dv -NULL +.Fa servname +string can be either a service name or a decimal port number. +.Pp +The caller can optionally pass an +.Li addrinfo +structure, pointed to by the third argument, +to provide hints concerning the type of socket that the caller supports. +In this +.Fa hints +structure all members other than +.Fa ai_flags , +.Fa ai_family , +.Fa ai_socktype , +and +.Fa ai_protocol +must be zero or a +.Dv NULL +pointer. +A value of +.Dv PF_UNSPEC +for +.Fa ai_family +means the caller will accept any protocol family. +A value of 0 for +.Fa ai_socktype +means the caller will accept any socket type. +A value of 0 for +.Fa ai_protocol +means the caller will accept any protocol. +For example, if the caller handles only TCP and not UDP, then the +.Fa ai_socktype +member of the hints structure should be set to +.Dv SOCK_STREAM +when +.Fn getaddrinfo +is called. +If the caller handles only IPv4 and not IPv6, then the +.Fa ai_family +member of the +.Fa hints +structure should be set to +.Dv PF_INET +when +.Fn getaddrinfo +is called. +If the third argument to +.Fn getaddrinfo +is a +.Dv NULL +pointer, this is the same as if the caller had filled in an +.Li addrinfo +structure initialized to zero with +.Fa ai_family +set to +.Dv PF_UNSPEC . +.Pp +Upon successful return a pointer to a linked list of one or more +.Li addrinfo +structures is returned through the final argument. +The caller can process each +.Li addrinfo +structure in this list by following the +.Fa ai_next +pointer, until a +.Dv NULL +pointer is encountered. +In each returned +.Li addrinfo +structure the three members +.Fa ai_family , +.Fa ai_socktype , +and +.Fa ai_protocol +are the corresponding arguments for a call to the +.Fn socket +function. +In each +.Li addrinfo +structure the +.Fa ai_addr +member points to a filled-in socket address structure whose length is +specified by the +.Fa ai_addrlen +member. +.Pp +If the +.Dv AI_PASSIVE +bit is set in the +.Fa ai_flags +member of the +.Fa hints +structure, then the caller plans to use the returned socket address +structure in a call to +.Fn bind . +In this case, if the +.Fa nodename +argument is a +.Dv NULL +pointer, then the IP address portion of the socket +address structure will be set to +.Dv INADDR_ANY +for an IPv4 address or +.Dv IN6ADDR_ANY_INIT +for an IPv6 address. +.Pp +If the +.Dv AI_PASSIVE +bit is not set in the +.Fa ai_flags +member of the +.Fa hints +structure, then the returned socket address structure will be ready for a +call to +.Fn connect +(for a connection-oriented protocol) +or either +.Fn connect , +.Fn sendto , +or +.Fn sendmsg +(for a connectionless protocol). +In this case, if the +.Fa nodename +argument is a +.Dv NULL +pointer, then the IP address portion of the +socket address structure will be set to the loopback address. +.Pp +If the +.Dv AI_CANONNAME +bit is set in the +.Fa ai_flags +member of the +.Fa hints +structure, then upon successful return the +.Fa ai_canonname +member of the first +.Li addrinfo +structure in the linked list will point to a null-terminated string +containing the canonical name of the specified +.Fa nodename . +.Pp +If the +.Dv AI_NUMERICHOST +bit is set in the +.Fa ai_flags +member of the +.Fa hints +structure, then a +.Pf non Dv -NULL +.Fa nodename +string must be a numeric host address string. +Otherwise an error of +.Dv EAI_NONAME +is returned. +This flag prevents any type of name resolution service (e.g., the DNS) +from being called. +.Pp +The arguments to +.Fn getaddrinfo +must be sufficiently consistent and unambiguous. +Here are some problem cases you may encounter: +.Bl -bullet +.It +.Fn getaddrinfo +will fail if the members in the +.Fa hints +structure are not consistent. +For example, for internet address families, +.Fn getaddrinfo +will fail if you specify +.Dv SOCK_STREAM +to +.Fa ai_socktype +while you specify +.Dv IPPROTO_UDP +to +.Fa ai_protocol . +.It +If you specify a +.Fa servname +which is defined only for certain +.Fa ai_socktype , +.Fn getaddrinfo +will fail because the arguments are not consistent. +For example, +.Fn getaddrinfo +will return an error if you ask for +.Dq Li tftp +service on +.Dv SOCK_STREAM . +.It +For internet address families, if you specify +.Fa servname +while you set +.Fa ai_socktype +to +.Dv SOCK_RAW , +.Fn getaddrinfo +will fail, because service names are not defined for the internet +.Dv SOCK_RAW +space. +.It +If you specify numeric +.Fa servname , +while leaving +.Fa ai_socktype +and +.Fa ai_protocol +unspecified, +.Fn getaddrinfo +will fail. +This is because the numeric +.Fa servname +does not identify any socket type, and +.Fn getaddrinfo +is not allowed to glob the argument in such case. +.El +.Pp +All of the information returned by +.Fn getaddrinfo +is dynamically allocated: +the +.Li addrinfo +structures, the socket address structures, and canonical node name +strings pointed to by the addrinfo structures. +To return this information to the system the function +.Fn freeaddrinfo +is called. +The +.Fa addrinfo +structure pointed to by the +.Fa ai argument +is freed, along with any dynamic storage pointed to by the structure. +This operation is repeated until a +.Dv NULL +.Fa ai_next +pointer is encountered. +.Pp +To aid applications in printing error messages based on the +.Dv EAI_xxx +codes returned by +.Fn getaddrinfo , +.Fn gai_strerror +is defined. +The argument is one of the +.Dv EAI_xxx +values defined earlier and the return value points to a string describing +the error. +If the argument is not one of the +.Dv EAI_xxx +values, the function still returns a pointer to a string whose contents +indicate an unknown error. +.\" +.Sh EXTENSIONS +This implementation supports numeric IPv6 address notation with the +experimental scope identifier. +By appending a percent sign and scope identifier to the address, you +can specify the value of the +.Li sin6_scope_id +field of the socket address. +This makes management of scoped address easier, +and allows cut-and-paste input of scoped addresses. +.Pp +At the moment the code supports only link-local addresses in this format. +The scope identifier is hardcoded to name of hardware interface associated +with the link, +(such as +.Li ne0 ) . +For example, +.Dq Li fe80::1%ne0 , +which means +.Do +.Li fe80::1 +on the link associated with the +.Li ne0 +interface +.Dc . +.Pp +This implementation is still very experimental and non-standard. +The current implementation assumes a one-to-one relationship between +interfaces and links, which is not necessarily true according to the +specification. +.\" +.Sh EXAMPLES +The following code tries to connect to +.Dq Li www.kame.net +service +.Dq Li http . +via stream socket. +It loops through all the addresses available, regardless of the address family. +If the destination resolves to an IPv4 address, it will use an +.Dv AF_INET +socket. +Similarly, if it resolves to IPv6, an +.Dv AF_INET6 +socket is used. +Observe that there is no hardcoded reference to particular address family. +The code works even if +.Fn getaddrinfo +returns addresses that are not IPv4/v6. +.Bd -literal -offset indent +struct addrinfo hints, *res, *res0; +int error; +int s; +const char *cause = NULL; + +memset(&hints, 0, sizeof(hints)); +hints.ai_family = PF_UNSPEC; +hints.ai_socktype = SOCK_STREAM; +error = getaddrinfo("www.kame.net", "http", &hints, &res0); +if (error) { + errx(1, "%s", gai_strerror(error)); + /*NOTREACHED*/ +} +s = -1; +cause = "no addresses"; +errno = EADDRNOTAVAIL; +for (res = res0; res; res = res->ai_next) { + s = socket(res->ai_family, res->ai_socktype, + res->ai_protocol); + if (s < 0) { + cause = "socket"; + continue; + } + + if (connect(s, res->ai_addr, res->ai_addrlen) < 0) { + cause = "connect"; + close(s); + s = -1; + continue; + } + + break; /* okay we got one */ +} +if (s < 0) { + err(1, cause); + /*NOTREACHED*/ +} +freeaddrinfo(res0); +.Ed +.Pp +The following example tries to open a wildcard listening socket onto service +.Dq Li http , +for all the address families available. +.Bd -literal -offset indent +struct addrinfo hints, *res, *res0; +int error; +int s[MAXSOCK]; +int nsock; +const char *cause = NULL; + +memset(&hints, 0, sizeof(hints)); +hints.ai_family = PF_UNSPEC; +hints.ai_socktype = SOCK_STREAM; +hints.ai_flags = AI_PASSIVE; +error = getaddrinfo(NULL, "http", &hints, &res0); +if (error) { + errx(1, "%s", gai_strerror(error)); + /*NOTREACHED*/ +} +nsock = 0; +for (res = res0; res && nsock < MAXSOCK; res = res->ai_next) { + s[nsock] = socket(res->ai_family, res->ai_socktype, + res->ai_protocol); + if (s[nsock] < 0) { + cause = "socket"; + continue; + } + + if (bind(s[nsock], res->ai_addr, res->ai_addrlen) < 0) { + cause = "bind"; + close(s[nsock]); + continue; + } + + if (listen(s[nsock], SOMAXCONN) < 0) { + cause = "listen"; + close(s[nsock]); + continue; + } + + nsock++; +} +if (nsock == 0) { + err(1, cause); + /*NOTREACHED*/ +} +freeaddrinfo(res0); +.Ed +.\" +.Sh FILES +.Bl -tag -width /etc/nsswitch.conf -compact +.It Pa /etc/hosts +.It Pa /etc/nsswitch.conf +.It Pa /etc/resolv.conf +.El +.\" +.Sh DIAGNOSTICS +Error return status from +.Fn getaddrinfo +is zero on success and non-zero on errors. +Non-zero error codes are defined in +.Aq Pa netdb.h , +and as follows: +.Pp +.Bl -tag -width EAI_ADDRFAMILY -compact +.It Dv EAI_ADDRFAMILY +Address family for +.Fa nodename +not supported. +.It Dv EAI_AGAIN +Temporary failure in name resolution. +.It Dv EAI_BADFLAGS +Invalid value for +.Fa ai_flags . +.It Dv EAI_FAIL +Non-recoverable failure in name resolution. +.It Dv EAI_FAMILY +.Fa ai_family +not supported. +.It Dv EAI_MEMORY +Memory allocation failure. +.It Dv EAI_NODATA +No address associated with +.Fa nodename . +.It Dv EAI_NONAME +.Fa nodename +nor +.Fa servname +provided, or not known. +.It Dv EAI_SERVICE +.Fa servname +not supported for +.Fa ai_socktype . +.It Dv EAI_SOCKTYPE +.Fa ai_socktype +not supported. +.It Dv EAI_SYSTEM +System error returned in +.Va errno . +.It Dv EAI_BADHINTS +Invalid value for +.Fa hints . +.It Dv EAI_PROTOCOL +Resolved protocol is unknown. +.It Dv EAI_MAX +Unknown error. +.El +.Pp +If called with an appropriate argument, +.Fn gai_strerror +returns a pointer to a string describing the given error code. +If the argument is not one of the +.Dv EAI_xxx +values, the function still returns a pointer to a string whose contents +indicate an unknown error. +.\" +.Sh SEE ALSO +.Xr gethostbyname 3 , +.Xr getnameinfo 3 , +.Xr getservbyname 3 , +.Xr hosts 5 , +.Xr services 5 , +.Xr hostname 7 , +.Xr named 8 +.Pp +.Rs +.%A R. Gilligan +.%A S. Thomson +.%A J. Bound +.%A W. Stevens +.%T Basic Socket Interface Extensions for IPv6 +.%R RFC2553 +.%D March 1999 +.Re +.Rs +.%A Tatsuya Jinmei +.%A Atsushi Onoe +.%T "An Extension of Format for IPv6 Scoped Addresses" +.%R internet draft +.%N draft-ietf-ipngwg-scopedaddr-format-02.txt +.%O work in progress material +.Re +.Rs +.%A Craig Metz +.%T Protocol Independence Using the Sockets API +.%B "Proceedings of the freenix track: 2000 USENIX annual technical conference" +.%D June 2000 +.Re +.\" +.Sh HISTORY +The implementation first appeared in WIDE Hydrangea IPv6 protocol stack kit. +.\" +.Sh STANDARDS +The +.Fn getaddrinfo +function is defined in +.St -p1003.1g-2000 , +and documented in +.Dq Basic Socket Interface Extensions for IPv6 +(RFC2553). +.\" +.Sh BUGS +The current implementation is not thread-safe. +.Pp +The text was shamelessly copied from RFC2553. diff --git a/net/gethostbyname.3 b/net/gethostbyname.3 new file mode 100644 index 0000000..8efba37 --- /dev/null +++ b/net/gethostbyname.3 @@ -0,0 +1,380 @@ +.\" Copyright (c) 1983, 1987, 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. +.\" +.\" From: @(#)gethostbyname.3 8.4 (Berkeley) 5/25/95 +.\" $FreeBSD: src/lib/libc/net/gethostbyname.3,v 1.25 2001/10/01 16:08:55 ru Exp $ +.\" +.Dd May 25, 1995 +.Dt GETHOSTBYNAME 3 +.Os +.Sh NAME +.Nm gethostbyname , +.Nm gethostbyname2 , +.Nm gethostbyaddr , +.Nm gethostent , +.Nm sethostent , +.Nm endhostent , +.Nm herror , +.Nm hstrerror +.Nd get network host entry +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In netdb.h +.Vt extern int h_errno ; +.Ft struct hostent * +.Fn gethostbyname "const char *name" +.Ft struct hostent * +.Fn gethostbyname2 "const char *name" "int af" +.Ft struct hostent * +.Fn gethostbyaddr "const char *addr" "int len" "int type" +.Ft struct hostent * +.Fn gethostent void +.Ft void +.Fn sethostent "int stayopen" +.Ft void +.Fn endhostent void +.Ft void +.Fn herror "const char *string" +.Ft const char * +.Fn hstrerror "int err" +.Sh DESCRIPTION +.Bf -symbolic +The +.Xr getaddrinfo 3 +and +.Xr getnameinfo 3 +functions are preferred over the +.Fn gethostbyname , +.Fn gethostbyname2 , +and +.Fn gethostbyaddr +functions. +.Ef +.Pp +The +.Fn gethostbyname , +.Fn gethostbyname2 +and +.Fn gethostbyaddr +functions +each return a pointer to an object with the +following structure describing an internet host +referenced by name or by address, respectively. +.Pp +The +.Fa name +parameter passed to +.Fn gethostbyname +or +.Fn gethostbyname2 +should point to a +.Dv NUL Ns -terminated +hostname. +The +.Fa addr +parameter passed to +.Fn gethostbyaddr +should point to an address which is +.Fa len +bytes long, +in binary form +(i.e. not an IP address in human readable +.Tn ASCII +form). +The +.Fa type +parameter specifies the address family +(e.g.\& +.Dv AF_INET , AF_INET6 , +etc.) of this address. +.Pp +The structure returned contains either the information obtained from the name +server, +.Xr named 8 , +broken-out fields from a line in +.Pa /etc/hosts , +or database entries supplied by the +.Xr yp 4 +system. +The order of the lookups is controlled by the +.Sq hosts +entry in +.Xr nsswitch.conf 5 . +.Bd -literal +struct hostent { + char *h_name; /* official name of host */ + char **h_aliases; /* alias list */ + int h_addrtype; /* host address type */ + int h_length; /* length of address */ + char **h_addr_list; /* list of addresses from name server */ +}; +#define h_addr h_addr_list[0] /* address, for backward compatibility */ +.Ed +.Pp +The members of this structure are: +.Bl -tag -width h_addr_list +.It Va h_name +Official name of the host. +.It Va h_aliases +A +.Dv NULL Ns -terminated +array of alternate names for the host. +.It Va h_addrtype +The type of address being returned; usually +.Dv AF_INET . +.It Va h_length +The length, in bytes, of the address. +.It Va h_addr_list +A +.Dv NULL Ns -terminated +array of network addresses for the host. +Host addresses are returned in network byte order. +.It Va h_addr +The first address in +.Va h_addr_list ; +this is for backward compatibility. +.El +.Pp +When using the nameserver, +.Fn gethostbyname +and +.Fn gethostbyname2 +will search for the named host in the current domain and its parents +unless the name ends in a dot. +If the name contains no dot, and if the environment variable +.Dq Ev HOSTALIASES +contains the name of an alias file, the alias file will first be searched +for an alias matching the input name. +See +.Xr hostname 7 +for the domain search procedure and the alias file format. +.Pp +The +.Fn gethostbyname2 +function is an evolution of +.Fn gethostbyname +which is intended to allow lookups in address families other than +.Dv AF_INET , +for example +.Dv AF_INET6 . +.Pp +The +.Fn sethostent +function +may be used to request the use of a connected +.Tn TCP +socket for queries. +If the +.Fa stayopen +flag is non-zero, +this sets the option to send all queries to the name server using +.Tn TCP +and to retain the connection after each call to +.Fn gethostbyname , +.Fn gethostbyname2 +or +.Fn gethostbyaddr . +Otherwise, queries are performed using +.Tn UDP +datagrams. +.Pp +The +.Fn endhostent +function +closes the +.Tn TCP +connection. +.Pp +The +.Fn herror +function writes a message to the diagnostic output consisting of the +string parameter +.Fa s , +the constant string +.Qq Li ":\ " , +and a message corresponding to the value of +.Va h_errno . +.Pp +The +.Fn hstrerror +function returns a string which is the message text corresponding to the +value of the +.Fa err +parameter. +.Sh FILES +.Bl -tag -width /etc/nsswitch.conf -compact +.It Pa /etc/hosts +.It Pa /etc/nsswitch.conf +.It Pa /etc/resolv.conf +.El +.Sh EXAMPLES +Print out the hostname associated with a specific IP address: +.Bd -literal -offset indent +const char *ipstr = "127.0.0.1"; +struct in_addr ip; +struct hostent *hp; + +if (!inet_aton(ipstr, &ip)) + errx(1, "can't parse IP address %s", ipstr); + +if ((hp = gethostbyaddr((const char *)&ip, + sizeof ip, AF_INET)) == NULL) + errx(1, "no name associated with %s", ipstr); + +printf("name associated with %s is %s\en", ipstr, hp->h_name); +.Ed +.Sh DIAGNOSTICS +Error return status from +.Fn gethostbyname , +.Fn gethostbyname2 +and +.Fn gethostbyaddr +is indicated by return of a +.Dv NULL +pointer. +The external integer +.Va h_errno +may then be checked to see whether this is a temporary failure +or an invalid or unknown host. +The routine +.Fn herror +can be used to print an error message describing the failure. +If its argument +.Fa string +is +.Pf non- Dv NULL , +it is printed, followed by a colon and a space. +The error message is printed with a trailing newline. +.Pp +The variable +.Va h_errno +can have the following values: +.Bl -tag -width HOST_NOT_FOUND +.It Dv HOST_NOT_FOUND +No such host is known. +.It Dv TRY_AGAIN +This is usually a temporary error +and means that the local server did not receive +a response from an authoritative server. +A retry at some later time may succeed. +.It Dv NO_RECOVERY +Some unexpected server failure was encountered. +This is a non-recoverable error. +.It Dv NO_DATA +The requested name is valid but does not have an IP address; +this is not a temporary error. +This means that the name is known to the name server but there is no address +associated with this name. +Another type of request to the name server using this domain name +will result in an answer; +for example, a mail-forwarder may be registered for this domain. +.El +.Sh SEE ALSO +.Xr getaddrinfo 3 , +.Xr getnameinfo 3 , +.Xr inet_aton 3 , +.Xr resolver 3 , +.Xr hosts 5 , +.Xr hostname 7 , +.Xr named 8 +.Sh CAVEAT +The +.Fn gethostent +function +is defined, and +.Fn sethostent +and +.Fn endhostent +are redefined, +when +.Xr libc 3 +is built to use only the routines to lookup in +.Pa /etc/hosts +and not the name server. +.Pp +The +.Fn gethostent +function +reads the next line of +.Pa /etc/hosts , +opening the file if necessary. +.Pp +The +.Fn sethostent +function +opens and/or rewinds the file +.Pa /etc/hosts . +If the +.Fa stayopen +argument is non-zero, +the file will not be closed after each call to +.Fn gethostbyname , +.Fn gethostbyname2 +or +.Fn gethostbyaddr . +.Pp +The +.Fn endhostent +function +closes the file. +.Sh HISTORY +The +.Fn herror +function appeared in +.Bx 4.3 . +The +.Fn endhostent , +.Fn gethostbyaddr , +.Fn gethostbyname , +.Fn gethostent , +and +.Fn sethostent +functions appeared in +.Bx 4.2 . +The +.Fn gethostbyname2 +function first appeared in +.Tn BIND +version 4.9.4. +.Sh BUGS +These functions use static data storage; +if the data is needed for future use, it should be +copied before any subsequent calls overwrite it. +Only the Internet +address format is currently understood. +.Pp +.Fn gethostbyname2 +cannot perform +.Dv AF_INET6 +lookups over NIS. +.Xr getaddrinfo 3 +must be used instead. diff --git a/net/getifaddrs.3 b/net/getifaddrs.3 new file mode 100644 index 0000000..47e5004 --- /dev/null +++ b/net/getifaddrs.3 @@ -0,0 +1,164 @@ +.\" $FreeBSD: src/lib/libc/net/getifaddrs.3,v 1.6 2001/10/01 16:08:55 ru Exp $ +.\" $KAME: getifaddrs.3,v 1.4 2000/05/17 14:13:14 itojun Exp $ +.\" BSDI getifaddrs.3,v 2.5 2000/02/23 14:51:59 dab Exp +.\" +.\" Copyright (c) 1995, 1999 +.\" Berkeley Software Design, Inc. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" +.\" THIS SOFTWARE IS PROVIDED BY Berkeley Software Design, Inc. ``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 Berkeley Software Design, Inc. 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 October 12, 1995 +.Dt GETIFADDRS 3 +.Os +.Sh NAME +.Nm getifaddrs +.Nd get interface addresses +.Sh SYNOPSIS +.In sys/types.h +.In sys/socket.h +.In ifaddrs.h +.Ft int +.Fn getifaddrs "struct ifaddrs **ifap" +.Ft void +.Fn freeifaddrs "struct ifaddrs *ifp" +.Sh DESCRIPTION +The +.Fn getifaddrs +function stores a reference to a linked list of the network interfaces +on the local machine in the memory referenced by +.Fa ifap . +The list consists of +.Nm ifaddrs +structures, as defined in the include file +.Aq Pa ifaddrs.h . +The +.Nm ifaddrs +structure contains at least the following entries: +.Bd -literal + struct ifaddrs *ifa_next; /* Pointer to next struct */ + char *ifa_name; /* Interface name */ + u_int ifa_flags; /* Interface flags */ + struct sockaddr *ifa_addr; /* Interface address */ + struct sockaddr *ifa_netmask; /* Interface netmask */ + struct sockaddr *ifa_broadaddr; /* Interface broadcast address */ + struct sockaddr *ifa_dstaddr; /* P2P interface destination */ + void *ifa_data; /* Address specific data */ +.Ed +.Pp +The +.Li ifa_next +field contains a pointer to the next structure on the list. +This field is +.Dv NULL +in last structure on the list. +.Pp +The +.Li ifa_name +field contains the interface name. +.Pp +The +.Li ifa_flags +field contains the interface flags, as set by +.Xr ifconfig 8 +utility. +.Pp +The +.Li ifa_addr +field references either the address of the interface or the link level +address of the interface, if one exists, otherwise it is NULL. +(The +.Li sa_family +field of the +.Li ifa_addr +field should be consulted to determine the format of the +.Li ifa_addr +address.) +.Pp +The +.Li ifa_netmask +field references the netmask associated with +.Li ifa_addr , +if one is set, otherwise it is NULL. +.Pp +The +.Li ifa_broadaddr +field, +which should only be referenced for non-P2P interfaces, +references the broadcast address associated with +.Li ifa_addr , +if one exists, otherwise it is NULL. +.Pp +The +.Li ifa_dstaddr +field references the destination address on a P2P interface, +if one exists, otherwise it is NULL. +.Pp +The +.Li ifa_data +field references address family specific data. For +.Dv AF_LINK +addresses it contains a pointer to the +.Fa struct if_data +(as defined in include file +.Aq Pa net/if.h ) +which contains various interface attributes and statistics. +For all other address families, it contains a pointer to the +.Fa struct ifa_data +(as defined in include file +.Aq Pa net/if.h ) +which contains per-address interface statistics. +.Pp +The data returned by +.Fn getifaddrs +is dynamically allocated and should be freed using +.Fn freeifaddrs +when no longer needed. +.Sh RETURN VALUES +.Rv -std getifaddrs +.Sh ERRORS +The +.Fn getifaddrs +may fail and set +.Va errno +for any of the errors specified for the library routines +.Xr ioctl 2 , +.Xr socket 2 , +.Xr malloc 3 +or +.Xr sysctl 3 . +.Sh BUGS +If both +.Aq Pa net/if.h +and +.Aq Pa ifaddrs.h +are being included, +.Aq Pa net/if.h +.Em must +be included before +.Aq Pa ifaddrs.h . +.Sh SEE ALSO +.Xr ioctl 2 , +.Xr socket 2 , +.Xr sysctl 3 , +.Xr networking 4 , +.Xr ifconfig 8 +.Sh HISTORY +The +.Nm +implementation first appeared in BSDi +.Bsx . diff --git a/net/getipnodebyname.3 b/net/getipnodebyname.3 new file mode 100644 index 0000000..5b8ea1e --- /dev/null +++ b/net/getipnodebyname.3 @@ -0,0 +1,461 @@ +.\" $FreeBSD: src/lib/libc/net/getipnodebyname.3,v 1.8 2001/10/01 16:08:55 ru Exp $ +.\" $KAME: getipnodebyname.3,v 1.6 2000/08/09 21:16:17 itojun Exp $ +.\" +.\" Copyright (c) 1983, 1987, 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. +.\" +.\" From: @(#)gethostbyname.3 8.4 (Berkeley) 5/25/95 +.\" +.Dd May 25, 1995 +.Dt GETIPNODEBYNAME 3 +.Os +.\" +.Sh NAME +.Nm getipnodebyname , +.Nm getipnodebyaddr , +.Nm freehostent +.Nd nodename-to-address and address-to-nodename translation +.\" +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In sys/types.h +.In sys/socket.h +.In netdb.h +.Ft "struct hostent *" +.Fn getipnodebyname "const char *name" "int af" "int flags" "int *error_num" +.Ft "struct hostent *" +.Fn getipnodebyaddr "const void *src" "size_t len" "int af" "int *error_num" +.Ft void +.Fn freehostent "struct hostent *ptr" +.\" +.Sh DESCRIPTION +.Fn getipnodebyname +and +.Fn getipnodebyaddr +functions are very similar to +.Xr gethostbyname 3 , +.Xr gethostbyname2 3 +and +.Xr gethostbyaddr 3 . +The functions cover all the functionalities provided by the older ones, +and provide better interface to programmers. +The functions require additional arguments, +.Ar af , +and +.Ar flags , +for specifying address family and operation mode. +The additional arguments allow programmer to get address for a nodename, +for specific address family +(such as +.Dv AF_INET +or +.Dv AF_INET6 ) . +The functions also require an additional pointer argument, +.Ar error_num +to return the appropriate error code, +to support thread safe error code returns. +.Pp +The type and usage of the return value, +.Li "struct hostent" +is described in +.Xr gethostbyname 3 . +.Pp +For +.Fn getipnodebyname , +the +.Ar name +argument can be either a node name or a numeric address +string +(i.e., a dotted-decimal IPv4 address or an IPv6 hex address). +The +.Ar af +argument specifies the address family, either +.Dv AF_INET +or +.Dv AF_INET6 . +The +.Ar flags +argument specifies the types of addresses that are searched for, +and the types of addresses that are returned. +We note that a special flags value of +.Dv AI_DEFAULT +(defined below) +should handle most applications. +That is, porting simple applications to use IPv6 replaces the call +.Bd -literal -offset + hptr = gethostbyname(name); +.Ed +.Pp +with +.Bd -literal -offset + hptr = getipnodebyname(name, AF_INET6, AI_DEFAULT, &error_num); +.Ed +.Pp +Applications desiring finer control over the types of addresses +searched for and returned, can specify other combinations of the +.Ar flags +argument. +.Pp +A +.Ar flags +of +.Li 0 +implies a strict interpretation of the +.Ar af +argument: +.Bl -bullet +.It +If +.Ar flags +is 0 and +.Ar af +is +.Dv AF_INET , +then the caller wants only IPv4 addresses. +A query is made for +.Li A +records. +If successful, the IPv4 addresses are returned and the +.Li h_length +member of the +.Li hostent +structure will be 4, else the function returns a +.Dv NULL +pointer. +.It +If +.Ar flags +is 0 and if +.Ar af +is +.Li AF_INET6 , +then the caller wants only IPv6 addresses. +A query is made for +.Li AAAA +records. +If successful, the IPv6 addresses are returned and the +.Li h_length +member of the +.Li hostent +structure will be 16, else the function returns a +.Dv NULL +pointer. +.El +.Pp +Other constants can be logically-ORed into the +.Ar flags +argument, to modify the behavior of the function. +.Bl -bullet +.It +If the +.Dv AI_V4MAPPED +flag is specified along with an +.Ar af +of +.Dv AF_INET6 , +then the caller will accept IPv4-mapped IPv6 addresses. +That is, if no +.Li AAAA +records are found then a query is made for +.Li A +records and any found are returned as IPv4-mapped IPv6 addresses +.Li ( h_length +will be 16). +The +.Dv AI_V4MAPPED +flag is ignored unless +.Ar af +equals +.Dv AF_INET6 . +.It +The +.Dv AI_V4MAPPED_CFG +flag is exact same as the +.Dv AI_V4MAPPED +flag only if the kernel supports IPv4-mapped IPv6 address. +.It +If the +.Dv AI_ALL +flag is used in conjunction with the +.Dv AI_V4MAPPED +flag, and only used with the IPv6 address family. +When +.Dv AI_ALL +is logically or'd with +.Dv AI_V4MAPPED +flag then the caller wants all addresses: IPv6 and IPv4-mapped IPv6. +A query is first made for +.Li AAAA +records and if successful, the +IPv6 addresses are returned. Another query is then made for +.Li A +records and any found are returned as IPv4-mapped IPv6 addresses. +.Li h_length +will be 16. Only if both queries fail does the function +return a +.Dv NULL +pointer. This flag is ignored unless af equals +AF_INET6. If both +.Dv AI_ALL +and +.Dv AI_V4MAPPED +are specified, +.Dv AI_ALL +takes precedence. +.It +The +.Dv AI_ADDRCONFIG +flag specifies that a query for +.Li AAAA +records +should occur only if the node has at least one IPv6 source +address configured and a query for +.Li A +records should occur only if the node has at least one IPv4 source address +configured. +.Pp +For example, if the node has no IPv6 source addresses configured, +and +.Ar af +equals AF_INET6, and the node name being looked up has both +.Li AAAA +and +.Li A +records, then: +(a) if only +.Dv AI_ADDRCONFIG +is +specified, the function returns a +.Dv NULL +pointer; +(b) if +.Dv AI_ADDRCONFIG +| +.Dv AI_V4MAPPED +is specified, the +.Li A +records are returned as IPv4-mapped IPv6 addresses; +.El +.Pp +The special flags value of +.Dv AI_DEFAULT +is defined as +.Bd -literal -offset + #define AI_DEFAULT (AI_V4MAPPED_CFG | AI_ADDRCONFIG) +.Ed +.Pp +We noted that the +.Fn getipnodebyname +function must allow the +.Ar name +argument to be either a node name or a literal address string +(i.e., a dotted-decimal IPv4 address or an IPv6 hex address). +This saves applications from having to call +.Xr inet_pton 3 +to handle literal address strings. +When the +.Ar name +argument is a literal address string, +the +.Ar flags +argument is always ignored. +.Pp +There are four scenarios based on the type of literal address string +and the value of the +.Ar af +argument. +The two simple cases are when +.Ar name +is a dotted-decimal IPv4 address and +.Ar af +equals +.Dv AF_INET , +or when +.Ar name +is an IPv6 hex address and +.Ar af +equals +.Dv AF_INET6 . +The members of the +returned hostent structure are: +.Li h_name +points to a copy of the +.Ar name +argument, +.Li h_aliases +is a +.Dv NULL +pointer, +.Li h_addrtype +is a copy of the +.Ar af +argument, +.Li h_length +is either 4 +(for +.Dv AF_INET ) +or 16 +(for +.Dv AF_INET6 ) , +.Li h_addr_list[0] +is a pointer to the 4-byte or 16-byte binary address, +and +.Li h_addr_list[1] +is a +.Dv NULL +pointer. +.Pp +When +.Ar name +is a dotted-decimal IPv4 address and +.Ar af +equals +.Dv AF_INET6 , +and +.Dv AI_V4MAPPED +is specified, +an IPv4-mapped IPv6 address is returned: +.Li h_name +points to an IPv6 hex address containing the IPv4-mapped IPv6 address, +.Li h_aliases +is a +.Dv NULL +pointer, +.Li h_addrtype +is +.Dv AF_INET6 , +.Li h_length +is 16, +.Li h_addr_list[0] +is a pointer to the 16-byte binary address, and +.Li h_addr_list[1] +is a +.Dv NULL +pointer. +.Pp +It is an error when +.Ar name +is an IPv6 hex address and +.Ar af +equals +.Dv AF_INET . +The function's return value is a +.Dv NULL +pointer and the value pointed to by +.Ar error_num +equals +.Dv HOST_NOT_FOUND . +.Pp +.Fn getipnodebyaddr +takes almost the same argument as +.Xr gethostbyaddr 3 , +but adds a pointer to return an error number. +Additionally it takes care of IPv4-mapped IPv6 addresses, +and IPv4-compatible IPv6 addresses. +.Pp +.Fn getipnodebyname +and +.Fn getipnodebyaddr +dynamically allocate the structure to be returned to the caller. +.Fn freehostent +reclaims memory region allocated and returned by +.Fn getipnodebyname +or +.Fn getipnodebyaddr . +.\" +.Sh FILES +.Bl -tag -width /etc/nsswitch.conf -compact +.It Pa /etc/hosts +.It Pa /etc/nsswitch.conf +.It Pa /etc/resolv.conf +.El +.\" +.Sh DIAGNOSTICS +.Fn getipnodebyname +and +.Fn getipnodebyaddr +returns +.Dv NULL +on errors. +The integer values pointed to by +.Ar error_num +may then be checked to see whether this is a temporary failure +or an invalid or unknown host. +The meanings of each error code are described in +.Xr gethostbyname 3 . +.\" +.Sh SEE ALSO +.Xr gethostbyaddr 3 , +.Xr gethostbyname 3 , +.Xr hosts 5 , +.Xr nsswitch.conf 5 , +.Xr services 5 , +.Xr hostname 7 , +.Xr named 8 +.Pp +.Rs +.%A R. Gilligan +.%A S. Thomson +.%A J. Bound +.%A W. Stevens +.%T Basic Socket Interface Extensions for IPv6 +.%R RFC2553 +.%D March 1999 +.Re +.\" +.Sh HISTORY +The implementation first appeared in KAME advanced networking kit. +.\" +.Sh STANDARDS +.Fn getipnodebyname +and +.Fn getipnodebyaddr +are documented in +.Dq Basic Socket Interface Extensions for IPv6 +(RFC2553). +.\" +.Sh BUGS +.Fn getipnodebyname +and +.Fn getipnodebyaddr +do not handle scoped IPv6 address properly. +If you use these functions, +your program will not be able to handle scoped IPv6 addresses. +For IPv6 address manipulation, +.Fn getaddrinfo 3 +and +.Fn getnameinfo 3 +are recommended. +.Pp +The current implementation is not thread-safe. +.Pp +The text was shamelessly copied from RFC2553. diff --git a/net/getnameinfo.3 b/net/getnameinfo.3 new file mode 100644 index 0000000..d7afa2f --- /dev/null +++ b/net/getnameinfo.3 @@ -0,0 +1,311 @@ +.\" $FreeBSD: src/lib/libc/net/getnameinfo.3,v 1.11 2001/10/01 16:08:55 ru Exp $ +.\" $KAME: getnameinfo.3,v 1.17 2000/08/09 21:16:17 itojun Exp $ +.\" +.\" Copyright (c) 1983, 1987, 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. +.\" +.\" From: @(#)gethostbyname.3 8.4 (Berkeley) 5/25/95 +.\" +.Dd May 25, 1995 +.Dt GETNAMEINFO 3 +.Os +.\" +.Sh NAME +.Nm getnameinfo +.Nd address-to-nodename translation in protocol-independent manner +.\" +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In sys/types.h +.In sys/socket.h +.In netdb.h +.Ft int +.Fn getnameinfo "const struct sockaddr *sa" "socklen_t salen" \ +"char *host" "size_t hostlen" "char *serv" "size_t servlen" "int flags" +.\" +.Sh DESCRIPTION +The +.Fn getnameinfo +function is defined for protocol-independent address-to-nodename translation. +Its functionality is a reverse conversion of +.Xr getaddrinfo 3 , +and implements similar functionality with +.Xr gethostbyaddr 3 +and +.Xr getservbyport 3 +in more sophisticated manner. +.Pp +This function looks up an IP address and port number provided by the +caller in the DNS and system-specific database, and returns text +strings for both in buffers provided by the caller. +The function indicates successful completion by a zero return value; +a non-zero return value indicates failure. +.Pp +The first argument, +.Fa sa , +points to either a +.Li sockaddr_in +structure (for IPv4) or a +.Li sockaddr_in6 +structure (for IPv6) that holds the IP address and port number. +The +.Fa salen +argument gives the length of the +.Li sockaddr_in +or +.Li sockaddr_in6 +structure. +.Pp +The function returns the nodename associated with the IP address in +the buffer pointed to by the +.Fa host +argument. +The caller provides the size of this buffer via the +.Fa hostlen +argument. +The service name associated with the port number is returned in the buffer +pointed to by +.Fa serv , +and the +.Fa servlen +argument gives the length of this buffer. +The caller specifies not to return either string by providing a zero +value for the +.Fa hostlen +or +.Fa servlen +arguments. +Otherwise, the caller must provide buffers large enough to hold the +nodename and the service name, including the terminating null characters. +.Pp +Unfortunately most systems do not provide constants that specify the +maximum size of either a fully-qualified domain name or a service name. +Therefore to aid the application in allocating buffers for these two +returned strings the following constants are defined in +.Aq Pa netdb.h : +.Bd -literal -offset +#define NI_MAXHOST 1025 +#define NI_MAXSERV 32 +.Ed +.Pp +The first value is actually defined as the constant +.Dv MAXDNAME +in recent versions of BIND's +.Aq Pa arpa/nameser.h +header +(older versions of BIND define this constant to be 256) +and the second is a guess based on the services listed in the current +Assigned Numbers RFC. +.Pp +The final argument is a +.Fa flag +that changes the default actions of this function. +By default the fully-qualified domain name (FQDN) for the host is +looked up in the DNS and returned. +If the flag bit +.Dv NI_NOFQDN +is set, only the nodename portion of the FQDN is returned for local hosts. +.Pp +If the +.Fa flag +bit +.Dv NI_NUMERICHOST +is set, or if the host's name cannot be located in the DNS, +the numeric form of the host's address is returned instead of its name +(e.g., by calling +.Fn inet_ntop +instead of +.Fn getnodebyaddr ) . +If the +.Fa flag +bit +.Dv NI_NAMEREQD +is set, an error is returned if the host's name cannot be located in the DNS. +.Pp +If the flag bit +.Dv NI_NUMERICSERV +is set, the numeric form of the service address is returned +(e.g., its port number) +instead of its name. +The two +.Dv NI_NUMERICxxx +flags are required to support the +.Fl n +flag that many commands provide. +.Pp +A fifth flag bit, +.Dv NI_DGRAM , +specifies that the service is a datagram service, and causes +.Fn getservbyport +to be called with a second argument of +.Dq udp +instead of its default of +.Dq tcp . +This is required for the few ports (512-514) +that have different services for UDP and TCP. +.Pp +These +.Dv NI_xxx +flags are defined in +.Aq Pa netdb.h . +.\" +.Sh EXTENSION +The implementation allows experimental numeric IPv6 address notation with +scope identifier. +IPv6 link-local address will appear as string like +.Dq Li fe80::1%ne0 , +if +.Dv NI_WITHSCOPEID +bit is enabled in +.Ar flags +argument. +Refer to +.Xr getaddrinfo 3 +for the notation. +.\" +.Sh EXAMPLES +The following code tries to get numeric hostname, and service name, +for given socket address. +Observe that there is no hardcoded reference to particular address family. +.Bd -literal -offset indent +struct sockaddr *sa; /* input */ +char hbuf[NI_MAXHOST], sbuf[NI_MAXSERV]; + +if (getnameinfo(sa, sa->sa_len, hbuf, sizeof(hbuf), sbuf, + sizeof(sbuf), NI_NUMERICHOST | NI_NUMERICSERV)) { + errx(1, "could not get numeric hostname"); + /*NOTREACHED*/ +} +printf("host=%s, serv=%s\\n", hbuf, sbuf); +.Ed +.Pp +The following version checks if the socket address has reverse address mapping. +.Bd -literal -offset indent +struct sockaddr *sa; /* input */ +char hbuf[NI_MAXHOST]; + +if (getnameinfo(sa, sa->sa_len, hbuf, sizeof(hbuf), NULL, 0, + NI_NAMEREQD)) { + errx(1, "could not resolve hostname"); + /*NOTREACHED*/ +} +printf("host=%s\\n", hbuf); +.Ed +.\" +.Sh FILES +.Bl -tag -width /etc/nsswitch.conf -compact +.It Pa /etc/hosts +.It Pa /etc/nsswitch.conf +.It Pa /etc/resolv.conf +.El +.\" +.Sh DIAGNOSTICS +The function indicates successful completion by a zero return value; +a non-zero return value indicates failure. +Error codes are as below: +.Bl -tag -width Er +.It Bq Er EAI_AGAIN +The name could not be resolved at this time. +Future attempts may succeed. +.It Bq Er EAI_BADFLAGS +The flags had an invalid value. +.It Bq Er EAI_FAIL +A non-recoverable error occurred. +.It Bq Er EAI_FAMILY +The address family was not recognized or the address length was invalid +for the specified family. +.It Bq Er EAI_MEMORY +There was a memory allocation failure. +.It Bq Er EAI_NONAME +The name does not resolve for the supplied parameters. +.Dv NI_NAMEREQD +is set and the host's name cannot be located, +or both nodename and servname were null. +.It Bq Er EAI_SYSTEM +A system error occurred. +The error code can be found in errno. +.El +.\" +.Sh SEE ALSO +.Xr getaddrinfo 3 , +.Xr gethostbyaddr 3 , +.Xr getservbyport 3 , +.Xr hosts 5 , +.Xr services 5 , +.Xr hostname 7 , +.Xr named 8 +.Pp +.Rs +.%A R. Gilligan +.%A S. Thomson +.%A J. Bound +.%A W. Stevens +.%T Basic Socket Interface Extensions for IPv6 +.%R RFC2553 +.%D March 1999 +.Re +.Rs +.%A Tatsuya Jinmei +.%A Atsushi Onoe +.%T "An Extension of Format for IPv6 Scoped Addresses" +.%R internet draft +.%N draft-ietf-ipngwg-scopedaddr-format-02.txt +.%O work in progress material +.Re +.Rs +.%A Craig Metz +.%T Protocol Independence Using the Sockets API +.%B "Proceedings of the freenix track: 2000 USENIX annual technical conference" +.%D June 2000 +.Re +.\" +.Sh HISTORY +The implementation first appeared in WIDE Hydrangea IPv6 protocol stack kit. +.\" +.Sh STANDARDS +The +.Fn getaddrinfo +function is defined in +.St -p1003.1g-2000 , +and documented in +.Dq Basic Socket Interface Extensions for IPv6 +(RFC2553). +.\" +.Sh BUGS +The current implementation is not thread-safe. +.Pp +The text was shamelessly copied from RFC2553. +.Pp +The type of the 2nd argument should be +.Li socklen_t +for RFC2553 conformance. +The current code is based on pre-RFC2553 specification. diff --git a/net/getnetent.3 b/net/getnetent.3 new file mode 100644 index 0000000..7a60a67 --- /dev/null +++ b/net/getnetent.3 @@ -0,0 +1,172 @@ +.\" Copyright (c) 1983, 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. +.\" +.\" @(#)getnetent.3 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD: src/lib/libc/net/getnetent.3,v 1.16 2001/10/01 16:08:55 ru Exp $ +.\" +.Dd June 4, 1993 +.Dt GETNETENT 3 +.Os +.Sh NAME +.Nm getnetent , +.Nm getnetbyaddr , +.Nm getnetbyname , +.Nm setnetent , +.Nm endnetent +.Nd get network entry +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In netdb.h +.Ft struct netent * +.Fn getnetent void +.Ft struct netent * +.Fn getnetbyname "const char *name" +.Ft struct netent * +.Fn getnetbyaddr "unsigned long net" "int type" +.Ft void +.Fn setnetent "int stayopen" +.Ft void +.Fn endnetent void +.Sh DESCRIPTION +The +.Fn getnetent , +.Fn getnetbyname , +and +.Fn getnetbyaddr +functions +each return a pointer to an object with the +following structure describing an internet network. +This structure contains either the information obtained +from the nameserver, +.Xr named 8 , +broken-out fields of a line in the network data base +.Pa /etc/networks , +or entries supplied by the +.Xr yp 4 +system. The order of the lookups is controlled by the +`networks' entry in +.Xr nsswitch.conf 5 . +.Pp +.Bd -literal -offset indent +struct netent { + char *n_name; /* official name of net */ + char **n_aliases; /* alias list */ + int n_addrtype; /* net number type */ + unsigned long n_net; /* net number */ +}; +.Ed +.Pp +The members of this structure are: +.Bl -tag -width n_addrtype +.It Fa n_name +The official name of the network. +.It Fa n_aliases +A zero terminated list of alternate names for the network. +.It Fa n_addrtype +The type of the network number returned; currently only AF_INET. +.It Fa n_net +The network number. Network numbers are returned in machine byte +order. +.El +.Pp +The +.Fn getnetent +function +reads the next line of the file, opening the file if necessary. +.Pp +The +.Fn setnetent +function +opens and rewinds the file. If the +.Fa stayopen +flag is non-zero, +the net data base will not be closed after each call to +.Fn getnetbyname +or +.Fn getnetbyaddr . +.Pp +The +.Fn endnetent +function +closes the file. +.Pp +The +.Fn getnetbyname +function +and +.Fn getnetbyaddr +sequentially search from the beginning +of the file until a matching +net name or +net address and type is found, +or until +.Dv EOF +is encountered. +The +.Fa type +must be +.Dv AF_INET . +Network numbers are supplied in host order. +.Sh FILES +.Bl -tag -width /etc/nsswitch.conf -compact +.It Pa /etc/networks +.It Pa /etc/nsswitch.conf +.It Pa /etc/resolv.conf +.El +.Sh DIAGNOSTICS +Null pointer +(0) returned on +.Dv EOF +or error. +.Sh SEE ALSO +.Xr networks 5 +.Pp +.%T RFC 1101 +.Sh HISTORY +The +.Fn getnetent , +.Fn getnetbyaddr , +.Fn getnetbyname , +.Fn setnetent , +and +.Fn endnetent +functions appeared in +.Bx 4.2 . +.Sh BUGS +The data space used by +these functions is static; if future use requires the data, it should be +copied before any subsequent calls to these functions overwrite it. +Only Internet network +numbers are currently understood. +Expecting network numbers to fit +in no more than 32 bits is probably +naive. diff --git a/net/getprotoent.3 b/net/getprotoent.3 new file mode 100644 index 0000000..18b5654 --- /dev/null +++ b/net/getprotoent.3 @@ -0,0 +1,149 @@ +.\" Copyright (c) 1983, 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. +.\" +.\" @(#)getprotoent.3 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD: src/lib/libc/net/getprotoent.3,v 1.8 2001/10/01 16:08:55 ru Exp $ +.\" +.Dd June 4, 1993 +.Dt GETPROTOENT 3 +.Os +.Sh NAME +.Nm getprotoent , +.Nm getprotobynumber , +.Nm getprotobyname , +.Nm setprotoent , +.Nm endprotoent +.Nd get protocol entry +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In netdb.h +.Ft struct protoent * +.Fn getprotoent void +.Ft struct protoent * +.Fn getprotobyname "const char *name" +.Ft struct protoent * +.Fn getprotobynumber "int proto" +.Ft void +.Fn setprotoent "int stayopen" +.Ft void +.Fn endprotoent void +.Sh DESCRIPTION +The +.Fn getprotoent , +.Fn getprotobyname , +and +.Fn getprotobynumber +functions +each return a pointer to an object with the +following structure +containing the broken-out +fields of a line in the network protocol data base, +.Pa /etc/protocols . +.Bd -literal -offset indent +.Pp +struct protoent { + char *p_name; /* official name of protocol */ + char **p_aliases; /* alias list */ + int p_proto; /* protocol number */ +}; +.Ed +.Pp +The members of this structure are: +.Bl -tag -width p_aliases +.It Fa p_name +The official name of the protocol. +.It Fa p_aliases +A zero terminated list of alternate names for the protocol. +.It Fa p_proto +The protocol number. +.El +.Pp +The +.Fn getprotoent +function +reads the next line of the file, opening the file if necessary. +.Pp +The +.Fn setprotoent +function +opens and rewinds the file. If the +.Fa stayopen +flag is non-zero, +the net data base will not be closed after each call to +.Fn getprotobyname +or +.Fn getprotobynumber . +.Pp +The +.Fn endprotoent +function +closes the file. +.Pp +The +.Fn getprotobyname +function +and +.Fn getprotobynumber +sequentially search from the beginning +of the file until a matching +protocol name or +protocol number is found, +or until +.Dv EOF +is encountered. +.Sh RETURN VALUES +Null pointer +(0) returned on +.Dv EOF +or error. +.Sh FILES +.Bl -tag -width /etc/protocols -compact +.It Pa /etc/protocols +.El +.Sh SEE ALSO +.Xr protocols 5 +.Sh HISTORY +The +.Fn getprotoent , +.Fn getprotobynumber , +.Fn getprotobyname , +.Fn setprotoent , +and +.Fn endprotoent +functions appeared in +.Bx 4.2 . +.Sh BUGS +These functions use a static data space; +if the data is needed for future use, it should be +copied before any subsequent calls overwrite it. +Only the Internet +protocols are currently understood. diff --git a/net/getservent.3 b/net/getservent.3 new file mode 100644 index 0000000..3d398bd --- /dev/null +++ b/net/getservent.3 @@ -0,0 +1,158 @@ +.\" Copyright (c) 1983, 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. +.\" +.\" From: @(#)getservent.3 8.3 (Berkeley) 1/12/94 +.\" $FreeBSD: src/lib/libc/net/getservent.3,v 1.12 2001/10/01 16:08:55 ru Exp $ +.\" +.Dd July 9, 1995 +.Dt GETSERVENT 3 +.Os +.Sh NAME +.Nm getservent , +.Nm getservbyport , +.Nm getservbyname , +.Nm setservent , +.Nm endservent +.Nd get service entry +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In netdb.h +.Ft struct servent * +.Fn getservent +.Ft struct servent * +.Fn getservbyname "const char *name" "const char *proto" +.Ft struct servent * +.Fn getservbyport "int port" "const char *proto" +.Ft void +.Fn setservent "int stayopen" +.Ft void +.Fn endservent void +.Sh DESCRIPTION +The +.Fn getservent , +.Fn getservbyname , +and +.Fn getservbyport +functions +each return a pointer to an object with the +following structure +containing the broken-out +fields of a line in the network services data base, +.Pa /etc/services . +.Bd -literal -offset indent +struct servent { + char *s_name; /* official name of service */ + char **s_aliases; /* alias list */ + int s_port; /* port service resides at */ + char *s_proto; /* protocol to use */ +}; +.Ed +.Pp +The members of this structure are: +.Bl -tag -width s_aliases +.It Fa s_name +The official name of the service. +.It Fa s_aliases +A zero terminated list of alternate names for the service. +.It Fa s_port +The port number at which the service resides. +Port numbers are returned in network byte order. +.It Fa s_proto +The name of the protocol to use when contacting the +service. +.El +.Pp +The +.Fn getservent +function +reads the next line of the file, opening the file if necessary. +.Pp +The +.Fn setservent +function +opens and rewinds the file. If the +.Fa stayopen +flag is non-zero, +the net data base will not be closed after each call to +.Fn getservbyname +or +.Fn getservbyport . +.Pp +The +.Fn endservent +function +closes the file. +.Pp +The +.Fn getservbyname +and +.Fn getservbyport +functions +sequentially search from the beginning +of the file until a matching +protocol name or +port number (which must be specified in +network byte order) is found, +or until +.Dv EOF +is encountered. +If a protocol name is also supplied (non- +.Dv NULL ) , +searches must also match the protocol. +.Sh FILES +.Bl -tag -width /etc/services -compact +.It Pa /etc/services +.El +.Sh DIAGNOSTICS +Null pointer +(0) returned on +.Dv EOF +or error. +.Sh SEE ALSO +.Xr getprotoent 3 , +.Xr services 5 +.Sh HISTORY +The +.Fn getservent , +.Fn getservbyport , +.Fn getservbyname , +.Fn setservent , +and +.Fn endservent +functions appeared in +.Bx 4.2 . +.Sh BUGS +These functions use static data storage; +if the data is needed for future use, it should be +copied before any subsequent calls overwrite it. +Expecting port numbers to fit in a 32 bit +quantity is probably naive. diff --git a/net/hesiod.3 b/net/hesiod.3 new file mode 100644 index 0000000..8de1f92 --- /dev/null +++ b/net/hesiod.3 @@ -0,0 +1,159 @@ +.\" $NetBSD: hesiod.3,v 1.1 1999/01/25 03:43:04 lukem Exp $ +.\" $FreeBSD: src/lib/libc/net/hesiod.3,v 1.3 2001/10/01 16:08:55 ru Exp $ +.\" +.\" from: #Id: hesiod.3,v 1.9.2.1 1997/01/03 21:02:23 ghudson Exp # +.\" +.\" Copyright 1988, 1996 by the Massachusetts Institute of Technology. +.\" +.\" 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 copyright +.\" notice and this permission notice appear in supporting +.\" documentation, and that the name of M.I.T. not be used in +.\" advertising or publicity pertaining to distribution of the +.\" software without specific, written prior permission. +.\" M.I.T. makes no representations about the suitability of +.\" this software for any purpose. It is provided "as is" +.\" without express or implied warranty. +.\" +.Dd November 30, 1996 +.Dt HESIOD 3 +.Os +.Sh NAME +.Nm hesiod , +.Nm hesiod_init , +.Nm hesiod_resolve , +.Nm hesiod_free_list , +.Nm hesiod_to_bind , +.Nm hesiod_end +.Nd Hesiod name server interface library +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In hesiod.h +.Ft int +.Fn hesiod_init "void **context" +.Ft char ** +.Fn hesiod_resolve "void *context" "const char *name" "const char *type" +.Ft void +.Fn hesiod_free_list "void *context" "char **list" +.Ft char * +.Fn hesiod_to_bind "void *context" "const char *name" "const char *type" +.Ft void +.Fn hesiod_end "void *context" +.Sh DESCRIPTION +This family of functions allows you to perform lookups of Hesiod +information, which is stored as text records in the Domain Name +Service. +To perform lookups, you must first initialize a +.Fa context , +an opaque object which stores information used internally by the +library between calls. +.Fn hesiod_init +initializes a context, storing a pointer to the context in the +location pointed to by the +.Fa context +argument. +.Fn hesiod_end +frees the resources used by a context. +.Pp +.Fn hesiod_resolve +is the primary interface to the library. +If successful, it returns a +list of one or more strings giving the records matching +.Fa name +and +.Fa type . +The last element of the list is followed by a +.Dv NULL +pointer. +It is the +caller's responsibility to call +.Fn hesiod_free_list +to free the resources used by the returned list. +.Pp +.Fn hesiod_to_bind +converts +.Fa name +and +.Fa type +into the DNS name used by +.Fn hesiod_resolve . +It is the caller's responsibility to free the returned string using +.Fn free . +.Sh RETURN VALUES +.Rv -std hesiod_init +On failure, +.Fn hesiod_resolve +and +.Fn hesiod_to_bind +return +.Dv NULL +and set the global variable +.Va errno +to indicate the error. +.Sh ENVIRONMENT +.Bl -tag -width HESIOD_CONFIG +.It Ev HES_DOMAIN +If the environment variable +.Ev HES_DOMAIN +is set, it will override the domain in the Hesiod configuration file. +.It Ev HESIOD_CONFIG +If the environment variable +.Ev HESIOD_CONFIG +is set, it specifies the location of the Hesiod configuration file. +.El +.Sh SEE ALSO +.Xr hesiod.conf 5 , +.Xr named 8 +.Rs +.%T "Hesiod - Project Athena Technical Plan -- Name Service" +.Re +.Sh ERRORS +Hesiod calls may fail because of: +.Bl -tag -width Er +.It Bq Er ENOMEM +Insufficient memory was available to carry out the requested +operation. +.It Bq Er ENOEXEC +.Fn hesiod_init +failed because the Hesiod configuration file was invalid. +.It Bq Er ECONNREFUSED +.Fn hesiod_resolve +failed because no name server could be contacted to answer the query. +.It Bq Er EMSGSIZE +.Fn hesiod_resolve +or +.Fn hesiod_to_bind +failed because the query or response was too big to fit into the +packet buffers. +.It Bq Er ENOENT +.Fn hesiod_resolve +failed because the name server had no text records matching +.Fa name +and +.Fa type , +or +.Fn hesiod_to_bind +failed because the +.Fa name +argument had a domain extension which could not be resolved with type +.Dq rhs\-extension +in the local Hesiod domain. +.El +.Sh AUTHORS +.An Steve Dyer , +IBM/Project Athena +.An Greg Hudson , +MIT Team Athena +.Pp +Copyright 1987, 1988, 1995, 1996 by the Massachusetts Institute of Technology. +.Sh BUGS +The strings corresponding to the +.Va errno +values set by the Hesiod functions are not particularly indicative of +what went wrong, especially for +.Er ENOEXEC +and +.Er ENOENT . diff --git a/net/if_indextoname.3 b/net/if_indextoname.3 new file mode 100644 index 0000000..4b5bff5 --- /dev/null +++ b/net/if_indextoname.3 @@ -0,0 +1,142 @@ +.\" Copyright (c) 1983, 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. +.\" +.\" From: @(#)rcmd.3 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD: src/lib/libc/net/if_indextoname.3,v 1.7 2001/10/01 16:08:55 ru Exp $ +.\" +.Dd May 21, 1998 +.Dt IF_NAMETOINDEX 3 +.Os +.Sh NAME +.Nm if_nametoindex , +.Nm if_indextoname , +.Nm if_nameindex , +.Nm if_freenameindex +.Nd convert interface index to name, and vice versa +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In sys/types.h +.In sys/socket.h +.In net/if.h +.Ft "unsigned int" +.Fn if_nametoindex "const char *ifname" +.Ft "char *" +.Fn if_indextoname "unsigned int ifindex" "char *ifname" +.Ft "struct if_nameindex *" +.Fn if_nameindex "void" +.Ft "void" +.Fn if_freenameindex "struct if_nameindex *ptr" +.Sh DESCRIPTION +The functions map interface index to readable interface name +(such as +.Dq Li lo0 ) , +and vice versa. +.Pp +.Fn if_nametoindex +converts readable interface name to interface index +.Pp positive integer value . +If the specified interface does not exist, 0 will be returned. +.Pp +.Fn if_indextoname +converts interface index to readable interface name. +The +.Fa ifname +argument must point to a buffer of at least +.Dv IF_NAMESIZE +bytes into which the interface name corresponding to the specified index is +returned. +.Dv ( IF_NAMESIZE +is also defined in +.Aq Pa net/if.h +and its value includes a terminating null byte at the end of the +interface name.) +This pointer is also the return value of the function. +If there is no interface corresponding to the specified index, +.Dv NULL +is returned. +.Pp +.Fn if_nameindex +returns an array of +.Fa if_nameindex +structures. +.Fa if_nametoindex +is also defined in +.Aq Pa net/if.h , +and is as follows: +.Bd -literal -offset +struct if_nameindex { + unsigned int if_index; /* 1, 2, ... */ + char *if_name; /* null terminated name: "le0", ... */ +}; +.Ed +.Pp +The end of the array of structures is indicated by a structure with +an +.Fa if_index +of 0 and an +.Fa if_name +of +.Dv NULL . +The function returns a +.Dv NULL +pointer upon an error. +The memory used for this array of structures along with the interface +names pointed to by the +.Fa if_name +members is obtained dynamically. +This memory is freed by the +.Fn if_freenameindex +function. +.Pp +.Fn if_freenameindex +takes a pointer that was returned by +.Fn if_nameindex +as argument +.Pq Fa ptr , +and it reclaims the region allocated. +.Sh DIAGNOSTICS +.Fn if_nametoindex +returns 0 on error, positive integer on success. +.Fn if_indextoname +and +.Fn if_nameindex +return +.Dv NULL +on errors. +.Sh SEE ALSO +R. Gilligan, S. Thomson, J. Bound, and W. Stevens, +``Basic Socket Interface Extensions for IPv6,'' RFC2553, March 1999. +.Sh HISTORY +The implementation first appeared in WIDE Hydrangea IPv6 protocol stack kit. +.Sh STANDARDS +These functions are defined in ``Basic Socket Interface Extensions for IPv6'' +(RFC2533). diff --git a/net/inet.3 b/net/inet.3 new file mode 100644 index 0000000..c65d1dc --- /dev/null +++ b/net/inet.3 @@ -0,0 +1,271 @@ +.\" Copyright (c) 1983, 1990, 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. +.\" +.\" From: @(#)inet.3 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD: src/lib/libc/net/inet.3,v 1.19 2001/10/01 16:08:55 ru Exp $ +.\" +.Dd June 17, 1996 +.Dt INET 3 +.Os +.Sh NAME +.Nm inet_aton , +.Nm inet_addr , +.Nm inet_network , +.Nm inet_ntoa , +.Nm inet_ntop , +.Nm inet_pton , +.Nm inet_makeaddr , +.Nm inet_lnaof , +.Nm inet_netof +.Nd Internet address manipulation routines +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In sys/types.h +.In sys/socket.h +.In netinet/in.h +.In arpa/inet.h +.Ft int +.Fn inet_aton "const char *cp" "struct in_addr *pin" +.Ft in_addr_t +.Fn inet_addr "const char *cp" +.Ft in_addr_t +.Fn inet_network "const char *cp" +.Ft char * +.Fn inet_ntoa "struct in_addr in" +.Ft const char * +.Fn inet_ntop "int af" "const void *src" "char *dst" "size_t size" +.Ft int +.Fn inet_pton "int af" "const char *src" "void *dst" +.Ft struct in_addr +.Fn inet_makeaddr "in_addr_t net" "in_addr_t lna" +.Ft in_addr_t +.Fn inet_lnaof "struct in_addr in" +.Ft in_addr_t +.Fn inet_netof "struct in_addr in" +.Sh DESCRIPTION +The routines +.Fn inet_aton , +.Fn inet_addr +and +.Fn inet_network +interpret character strings representing +numbers expressed in the Internet standard +.Ql .\& +notation. +.Pp +The +.Fn inet_pton +function converts a presentation format address (that is, printable form +as held in a character string) to network format (usually a +.Ft struct in_addr +or some other internal binary representation, in network byte order). +It returns 1 if the address was valid for the specified address family, or +0 if the address wasn't parseable in the specified address family, or -1 +if some system error occurred (in which case +.Va errno +will have been set). +This function is presently valid for +.Dv AF_INET +and +.Dv AF_INET6 . +.Pp +The +.Fn inet_aton +routine interprets the specified character string as an Internet address, +placing the address into the structure provided. +It returns 1 if the string was successfully interpreted, +or 0 if the string is invalid. +The +.Fn inet_addr +and +.Fn inet_network +functions return numbers suitable for use +as Internet addresses and Internet network +numbers, respectively. +.Pp +The function +.Fn inet_ntop +converts an address 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). +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. +This function is presently valid for +.Dv AF_INET +and +.Dv AF_INET6 . +.Pp +The routine +.Fn inet_ntoa +takes an Internet address and returns an +.Tn ASCII +string representing the address in +.Ql .\& +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 +.Fn inet_netof +and +.Fn inet_lnaof +break apart Internet host addresses, returning +the network number and local network address part, +respectively. +.Pp +All Internet addresses are returned in network +order (bytes ordered from left to right). +All network numbers and local address parts are +returned as machine byte order integer values. +.Sh INTERNET ADDRESSES +Values specified using the +.Ql .\& +notation take one +of the following forms: +.Bd -literal -offset indent +a.b.c.d +a.b.c +a.b +a +.Ed +.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 +that when an Internet address is viewed as a 32-bit +integer quantity on the +.Tn VAX +the bytes referred to +above appear as +.Dq Li d.c.b.a . +That is, +.Tn VAX +bytes are +ordered from right to left. +.Pp +When a three part address is specified, the last +part is interpreted as a 16-bit quantity and placed +in the right-most two bytes of the network address. +This makes the three part address format convenient +for specifying Class B network addresses as +.Dq Li 128.net.host . +.Pp +When a two part address is supplied, the last part +is interpreted as a 24-bit quantity and placed in +the right most three bytes of the network address. +This makes the two part address format convenient +for specifying Class A network addresses as +.Dq Li net.host . +.Pp +When only one part is given, the value is stored +directly in the network address without any byte +rearrangement. +.Pp +All numbers supplied as +.Dq parts +in a +.Ql .\& +notation +may be decimal, octal, or hexadecimal, as specified +in the C language (i.e., a leading 0x or 0X implies +hexadecimal; otherwise, a leading 0 implies octal; +otherwise, the number is interpreted as decimal). +.Pp +The +.Fn inet_aton +and +.Fn inet_ntoa +functions are semi-deprecated in favor of the +.Xr addr2ascii 3 +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 +functions for some time. +.Sh DIAGNOSTICS +The constant +.Dv INADDR_NONE +is returned by +.Fn inet_addr +and +.Fn inet_network +for malformed requests. +.Sh SEE ALSO +.Xr addr2ascii 3 , +.Xr byteorder 3 , +.Xr gethostbyname 3 , +.Xr getnetent 3 , +.Xr inet_net 3 , +.Xr hosts 5 , +.Xr networks 5 +.Rs +.%R RFC +.%N 2373 +.%D July 1998 +.%T "IP Version 6 Addressing Architecture" +.Re +.Sh STANDARDS +The +.Fn inet_ntop +and +.Fn inet_pton +functions conform to +.St -xns5.2 . +Note that +.Fn inet_pton +does not accept 1-, 2-, or 3-part dotted addresses; all four parts +must be specified. +This is a narrower input set than that accepted by +.Fn inet_aton . +.Sh HISTORY +These +functions appeared in +.Bx 4.2 . +.Sh BUGS +The value +.Dv INADDR_NONE +(0xffffffff) is a valid broadcast address, but +.Fn inet_addr +cannot return that value without indicating failure. +The newer +.Fn inet_aton +function does not share this problem. +The problem of host byte ordering versus network byte ordering is +confusing. +The string returned by +.Fn inet_ntoa +resides in a static memory area. +.Pp +Inet_addr should return a +.Fa struct in_addr . diff --git a/net/inet6_option_space.3 b/net/inet6_option_space.3 new file mode 100644 index 0000000..4ef8047 --- /dev/null +++ b/net/inet6_option_space.3 @@ -0,0 +1,445 @@ +.\" Copyright (c) 1983, 1987, 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. +.\" +.\" $Id: inet6_option_space.3,v 1.1 2001/12/18 01:21:21 bbraun Exp $ +.\" $FreeBSD: src/lib/libc/net/inet6_option_space.3,v 1.8 2001/10/01 16:08:55 ru Exp $ +.\" +.Dd December 10, 1999 +.Dt INET6_OPTION_SPACE 3 +.Os +.\" +.Sh NAME +.Nm inet6_option_space , +.Nm inet6_option_init , +.Nm inet6_option_append , +.Nm inet6_option_alloc , +.Nm inet6_option_next , +.Nm inet6_option_find +.Nd IPv6 Hop-by-Hop and Destination Options manipulation +.\" +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In sys/types.h +.In netinet/in.h +.Ft "int" +.Fn inet6_option_space "int nbytes" +.Ft "int" +.Fn inet6_option_init "void *bp" "struct cmsghdr **cmsgp" "int type" +.Ft "int" +.Fn inet6_option_append "struct cmsghdr *cmsg" "const u_int8_t *typep" "int multx" "int plusy" +.Ft "u_int8_t *" +.Fn inet6_option_alloc "struct cmsghdr *cmsg" "int datalen" "int multx" "int plusy" +.Ft "int" +.Fn inet6_option_next "const struct cmsghdr *cmsg" "u_int8_t **tptrp" +.Ft "int" +.Fn inet6_option_find "const struct cmsghdr *cmsg" "u_int8_t **tptrp" "int type" +.\" +.Sh DESCRIPTION +.\" +Building and parsing the Hop-by-Hop and Destination options is +complicated due to alignment constranints, padding and +ancillary data manipulation. +RFC2292 defines a set of functions to help the application. +The function prototypes for +these functions are all in the +.Aq Li netinet/in.h +header. +.\" +.Ss inet6_option_space +.Fn inet6_option_space +returns the number of bytes required to hold an option when it is stored as +ancillary data, including the +.Li cmsghdr +structure at the beginning, +and any padding at the end +(to make its size a multiple of 8 bytes). +The argument is the size of the structure defining the option, +which must include any pad bytes at the beginning +(the value +.Li y +in the alignment term +.Dq Li "xn + y" ) , +the type byte, the length byte, and the option data. +.Pp +Note: If multiple options are stored in a single ancillary data +object, which is the recommended technique, this function +overestimates the amount of space required by the size of +.Li N-1 +.Li cmsghdr +structures, +where +.Li N +is the number of options to be stored in the object. +This is of little consequence, since it is assumed that most +Hop-by-Hop option headers and Destination option headers carry only +one option +(appendix B of [RFC-2460]). +.\" +.Ss inet6_option_init +.Fn inet6_option_init +is called once per ancillary data object that will +contain either Hop-by-Hop or Destination options. +It returns +.Li 0 +on success or +.Li -1 +on an error. +.Pp +.Fa bp +is a pointer to previously allocated space that will contain the +ancillary data object. +It must be large enough to contain all the +individual options to be added by later calls to +.Fn inet6_option_append +and +.Fn inet6_option_alloc . +.Pp +.Fa cmsgp +is a pointer to a pointer to a +.Li cmsghdr +structure. +.Fa *cmsgp +is initialized by this function to point to the +.Li cmsghdr +structure constructed by this function in the buffer pointed to by +.Fa bp . +.Pp +.Fa type +is either +.Dv IPV6_HOPOPTS +or +.Dv IPV6_DSTOPTS . +This +.Fa type +is stored in the +.Li cmsg_type +member of the +.Li cmsghdr +structure pointed to by +.Fa *cmsgp . +.\" +.Ss inet6_option_append +This function appends a Hop-by-Hop option or a Destination option +into an ancillary data object that has been initialized by +.Fn inet6_option_init . +This function returns +.Li 0 +if it succeeds or +.Li -1 +on an error. +.Pp +.Fa cmsg +is a pointer to the +.Li cmsghdr +structure that must have been +initialized by +.Fn inet6_option_init . +.Pp +.Fa typep +is a pointer to the 8-bit option type. +It is assumed that this +field is immediately followed by the 8-bit option data length field, +which is then followed immediately by the option data. +The caller +initializes these three fields +(the type-length-value, or TLV) +before calling this function. +.Pp +The option type must have a value from +.Li 2 +to +.Li 255 , +inclusive. +.Li ( 0 +and +.Li 1 +are reserved for the +.Li Pad1 +and +.Li PadN +options, respectively.) +.Pp +The option data length must have a value between +.Li 0 +and +.Li 255 , +inclusive, and is the length of the option data that follows. +.Pp +.Fa multx +is the value +.Li x +in the alignment term +.Dq Li xn + y . +It must have a value of +.Li 1 , +.Li 2 , +.Li 4 , +or +.Li 8 . +.Pp +.Fa plusy +is the value +.Li y +in the alignment term +.Dq Li xn + y . +It must have a value between +.Li 0 +and +.Li 7 , +inclusive. +.\" +.Ss inet6_option_alloc +This function appends a Hop-by-Hop option or a Destination option +into an ancillary data object that has been initialized by +.Fn inet6_option_init . +This function returns a pointer to the 8-bit +option type field that starts the option on success, or +.Dv NULL +on an error. +.Pp +The difference between this function and +.Fn inet6_option_append +is that the latter copies the contents of a previously built option into +the ancillary data object while the current function returns a +pointer to the space in the data object where the option's TLV must +then be built by the caller. +.Pp +.Fa cmsg +is a pointer to the +.Li cmsghdr +structure that must have been +initialized by +.Fn inet6_option_init . +.Pp +.Fa datalen +is the value of the option data length byte for this option. +This value is required as an argument to allow the function to +determine if padding must be appended at the end of the option. +(The +.Fn inet6_option_append +function does not need a data length argument +since the option data length must already be stored by the caller.) +.Pp +.Fa multx +is the value +.Li x +in the alignment term +.Dq Li xn + y . +It must have a value of +.Li 1 , +.Li 2 , +.Li 4 , +or +.Li 8 . +.Pp +.Fa plusy +is the value +.Li y +in the alignment term +.Dq Li xn + y . +It must have a value between +.Li 0 +and +.Li 7 , +inclusive. +.\" +.Ss inet6_option_next +This function processes the next Hop-by-Hop option or Destination +option in an ancillary data object. +If another option remains to be +processed, the return value of the function is +.Li 0 +and +.Fa *tptrp +points to +the 8-bit option type field +(which is followed by the 8-bit option +data length, followed by the option data). +If no more options remain +to be processed, the return value is +.Li -1 +and +.Fa *tptrp +is +.Dv NULL . +If an error occurs, the return value is +.Li -1 +and +.Fa *tptrp +is not +.Dv NULL . +.Pp +.Fa cmsg +is a pointer to +.Li cmsghdr +structure of which +.Li cmsg_level +equals +.Dv IPPROTO_IPV6 +and +.Li cmsg_type +equals either +.Dv IPV6_HOPOPTS +or +.Dv IPV6_DSTOPTS . +.Pp +.Fa tptrp +is a pointer to a pointer to an 8-bit byte and +.Fa *tptrp +is used +by the function to remember its place in the ancillary data object +each time the function is called. +The first time this function is +called for a given ancillary data object, +.Fa *tptrp +must be set to +.Dv NULL . +.Pp +Each time this function returns success, +.Fa *tptrp +points to the 8-bit +option type field for the next option to be processed. +.\" +.Ss inet6_option_find +This function is similar to the previously described +.Fn inet6_option_next +function, except this function lets the caller +specify the option type to be searched for, instead of always +returning the next option in the ancillary data object. +.Fa cmsg +is a +pointer to +.Li cmsghdr +structure of which +.Li cmsg_level +equals +.Dv IPPROTO_IPV6 +and +.Li cmsg_type +equals either +.Dv IPV6_HOPOPTS +or +.Dv IPV6_DSTOPTS . +.Pp +.Fa tptrp +is a pointer to a pointer to an 8-bit byte and +.Fa *tptrp +is used +by the function to remember its place in the ancillary data object +each time the function is called. +The first time this function is +called for a given ancillary data object, +.Fa *tptrp +must be set to +.Dv NULL . +.Pa +This function starts searching for an option of the specified type +beginning after the value of +.Fa *tptrp . +If an option of the specified +type is located, this function returns +.Li 0 +and +.Fa *tptrp +points to the 8- +bit option type field for the option of the specified type. +If an +option of the specified type is not located, the return value is +.Li -1 +and +.Fa *tptrp +is +.Dv NULL . +If an error occurs, the return value is +.Li -1 +and +.Fa *tptrp +is not +.Dv NULL . +.\" +.Sh DIAGNOSTICS +.Fn inet6_option_init +and +.Fn inet6_option_append +return +.Li 0 +on success or +.Li -1 +on an error. +.Pp +.Fn inet6_option_alloc +returns +.Dv NULL +on an error. +.Pp +On errors, +.Fn inet6_option_next +and +.Fn inet6_option_find +return +.Li -1 +setting +.Fa *tptrp +to non +.Dv NULL +value. +.\" +.Sh EXAMPLES +RFC2292 gives comprehensive examples in chapter 6. +.\" +.Sh SEE ALSO +.Rs +.%A W. Stevens +.%A M. Thomas +.%T "Advanced Sockets API for IPv6" +.%N RFC2292 +.%D February 1998 +.Re +.Rs +.%A S. Deering +.%A R. Hinden +.%T "Internet Protocol, Version 6 (IPv6) Specification" +.%N RFC2460 +.%D December 1998 +.Re +.\" +.Sh HISTORY +The implementation first appeared in KAME advanced networking kit. +.\" +.Sh STANDARDS +The functions +are documented in +.Dq Advanced Sockets API for IPv6 +(RFC2292). +.\" +.Sh BUGS +The text was shamelessly copied from RFC2292. diff --git a/net/inet6_rthdr_space.3 b/net/inet6_rthdr_space.3 new file mode 100644 index 0000000..42a4662 --- /dev/null +++ b/net/inet6_rthdr_space.3 @@ -0,0 +1,323 @@ +.\" Copyright (c) 1983, 1987, 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. +.\" +.\" $Id: inet6_rthdr_space.3,v 1.1 2001/12/18 01:21:22 bbraun Exp $ +.\" $FreeBSD: src/lib/libc/net/inet6_rthdr_space.3,v 1.8 2001/10/01 16:08:55 ru Exp $ +.\" +.Dd December 10, 1999 +.Dt INET6_RTHDR_SPACE 3 +.Os +.\" +.Sh NAME +.Nm inet6_rthdr_space , +.Nm inet6_rthdr_init , +.Nm inet6_rthdr_add , +.Nm inet6_rthdr_lasthop , +.Nm inet6_rthdr_reverse , +.Nm inet6_rthdr_segments , +.Nm inet6_rthdr_getaddr , +.Nm inet6_rthdr_getflags +.Nd IPv6 Routing Header Options manipulation +.\" +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In sys/types.h +.In netinet/in.h +.Ft size_t +.Fn inet6_rthdr_space "int type" "int segments" +.Ft "struct cmsghdr *" +.Fn inet6_rthdr_init "void *bp" "int type" +.Ft int +.Fn inet6_rthdr_add "struct cmsghdr *cmsg" "const struct in6_addr *addr" "unsigned int flags" +.Ft int +.Fn inet6_rthdr_lasthop "struct cmsghdr *cmsg" "unsigned int flags" +.Ft int +.Fn inet6_rthdr_reverse "const struct cmsghdr *in" "struct cmsghdr *out" +.Ft int +.Fn inet6_rthdr_segments "const struct cmsghdr *cmsg" +.Ft "struct in6_addr *" +.Fn inet6_rthdr_getaddr "struct cmsghdr *cmsg" "int index" +.Ft int +.Fn inet6_rthdr_getflags "const struct cmsghdr *cmsg" "int index" +.\" +.Sh DESCRIPTION +RFC2292 IPv6 advanced API defines eight +functions that the application calls to build and examine a Routing +header. Four functions build a Routing header: +.Bl -hang +.It Fn inet6_rthdr_space +return #bytes required for ancillary data +.It Fn inet6_rthdr_init +initialize ancillary data for Routing header +.It Fn inet6_rthdr_add +add IPv6 address & flags to Routing header +.It Fn inet6_rthdr_lasthop +specify the flags for the final hop +.El +.Pp +Four functions deal with a returned Routing header: +.Bl -hang +.It Fn inet6_rthdr_reverse +reverse a Routing header +.It Fn inet6_rthdr_segments +return #segments in a Routing header +.It Fn inet6_rthdr_getaddr +fetch one address from a Routing header +.It Fn inet6_rthdr_getflags +fetch one flag from a Routing header +.El +.Pp +The function prototypes for these functions are all in the +.Aq Li netinet/in.h +header. +.\" +.Ss inet6_rthdr_space +This function returns the number of bytes required to hold a Routing +header of the specified +.Fa type +containing the specified number of +.Fa segments +(addresses). +For an IPv6 Type 0 Routing header, the number +of segments must be between 1 and 23, inclusive. The return value +includes the size of the cmsghdr structure that precedes the Routing +header, and any required padding. +.Pp +If the return value is 0, then either the type of the Routing header +is not supported by this implementation or the number of segments is +invalid for this type of Routing header. +.Pp +Note: This function returns the size but does not allocate the space +required for the ancillary data. +This allows an application to +allocate a larger buffer, if other ancillary data objects are +desired, since all the ancillary data objects must be specified to +.Xr sendmsg 2 +as a single +.Li msg_control +buffer. +.\" +.Ss inet6_rthdr_init +This function initializes the buffer pointed to by +.Fa bp +to contain a +.Li cmsghdr +structure followed by a Routing header of the specified +.Fa type . +The +.Li cmsg_len +member of the +.Li cmsghdr +structure is initialized to the +size of the structure plus the amount of space required by the +Routing header. +The +.Li cmsg_level +and +.Li cmsg_type +members are also initialized as required. +.Pp +The caller must allocate the buffer and its size can be determined by +calling +.Fn inet6_rthdr_space . +.Pp +Upon success the return value is the pointer to the +.Li cmsghdr +structure, and this is then used as the first argument to the next +two functions. +Upon an error the return value is +.Dv NULL . +.\" +.Ss inet6_rthdr_add +This function adds the address pointed to by +.Fa addr +to the end of the +Routing header being constructed and sets the type of this hop to the +value of +.Fa flags . +For an IPv6 Type 0 Routing header, +.Fa flags +must be +either +.Dv IPV6_RTHDR_LOOSE +or +.Dv IPV6_RTHDR_STRICT . +.Pp +If successful, the +.Li cmsg_len +member of the +.Li cmsghdr +structure is +updated to account for the new address in the Routing header and the +return value of the function is 0. +Upon an error the return value of +the function is -1. +.\" +.Ss inet6_rthdr_lasthop +This function specifies the Strict/Loose flag for the final hop of a +Routing header. +For an IPv6 Type 0 Routing header, +.Fa flags +must be either +.Dv IPV6_RTHDR_LOOSE +or +.Dv IPV6_RTHDR_STRICT . +.Pp +The return value of the function is 0 upon success, or -1 upon an error. +.Pp +Notice that a Routing header specifying +.Li N +intermediate nodes requires +.Li N+1 +Strict/Loose flags. +This requires +.Li N +calls to +.Fn inet6_rthdr_add +followed by one call to +.Fn inet6_rthdr_lasthop . +.\" +.Ss inet6_rthdr_reverse +This function is not yet implemented. +When implemented, this should behave as follows. +.Pp +This function takes a Routing header that was received as ancillary +data +(pointed to by the first argument, +.Fa in ) +and writes a new Routing +header that sends datagrams along the reverse of that route. +Both +arguments are allowed to point to the same buffer +(that is, the reversal can occur in place). +.Pp +The return value of the function is 0 on success, or -1 upon an +error. +.\" +.Ss inet6_rthdr_segments +This function returns the number of segments +(addresses) +contained in +the Routing header described by +.Fa cmsg . +On success the return value is +between 1 and 23, inclusive. +The return value of the function is -1 upon an error. +.\" +.Ss inet6_rthdr_getaddr +This function returns a pointer to the IPv6 address specified by +.Fa index +(which must have a value between 1 and the value returned by +.Fn inet6_rthdr_segments ) +in the Routing header described by +.Fa cmsg . +An +application should first call +.Fn inet6_rthdr_segments +to obtain the number of segments in the Routing header. +.Pp +Upon an error the return value of the function is +.Dv NULL . +.\" +.Ss inet6_rthdr_getflags +This function returns the flags value specified by +.Fa index +(which must +have a value between 0 and the value returned by +.Fn inet6_rthdr_segments ) +in the Routing header described by +.Fa cmsg . +For an IPv6 Type 0 Routing header the return value will be either +.Dv IPV6_RTHDR_LOOSE +or +.Dv IPV6_RTHDR_STRICT . +.Pp +Upon an error the return value of the function is -1. +.Pp +Note: Addresses are indexed starting at 1, and flags starting at 0, +to maintain consistency with the terminology and figures in RFC2460. +.\" +.Sh DIAGNOSTICS +.Fn inet6_rthdr_space +returns 0 on errors. +.Pp +.Fn inet6_rthdr_add , +.Fn inet6_rthdr_lasthop +and +.Fn inet6_rthdr_reverse +return 0 on success, and returns -1 on error. +.Pp +.Fn inet6_rthdr_init +and +.Fn inet6_rthdr_getaddr +return +.Dv NULL +on error. +.Pp +.Fn inet6_rthdr_segments +and +.Fn inet6_rthdr_getflags +return -1 on error. +.\" +.Sh EXAMPLES +RFC2292 gives comprehensive examples in chapter 8. +.\" +.Sh SEE ALSO +.Rs +.%A W. Stevens +.%A M. Thomas +.%T "Advanced Sockets API for IPv6" +.%N RFC2292 +.%D February 1998 +.Re +.Rs +.%A S. Deering +.%A R. Hinden +.%T "Internet Protocol, Version 6 (IPv6) Specification" +.%N RFC2460 +.%D December 1998 +.Re +.\" +.Sh HISTORY +The implementation first appeared in KAME advanced networking kit. +.\" +.Sh STANDARDS +The functions +are documented in +.Dq Advanced Sockets API for IPv6 +(RFC2292). +.\" +.Sh BUGS +The text was shamelessly copied from RFC2292. +.Pp +.Fn inet6_rthdr_reverse +is not implemented yet. diff --git a/net/inet_addr.c b/net/inet_addr.c new file mode 100644 index 0000000..305bec1 --- /dev/null +++ b/net/inet_addr.c @@ -0,0 +1,179 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1983, 1990, 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 +#include +#include +#include +#include + +/* + * Ascii internet address interpretation routine. + * The value returned is in network order. + */ +u_long +inet_addr(cp) + register const char *cp; +{ + struct in_addr val; + + if (inet_aton(cp, &val)) + return (val.s_addr); + return (INADDR_NONE); +} + +/* + * Check whether "cp" is a valid ascii representation + * of an Internet address and convert to a binary address. + * Returns 1 if the address is valid, 0 if not. + * This replaces inet_addr, the return value from which + * cannot distinguish between failure and a local broadcast address. + */ +int +inet_aton(cp, addr) + register const char *cp; + struct in_addr *addr; +{ + u_long parts[4]; + u_int32_t val; + char *c; + char *endptr; + int gotend, n; + + c = (char *)cp; + n = 0; + /* + * Run through the string, grabbing numbers until + * the end of the string, or some error + */ + gotend = 0; + while (!gotend) { + errno = 0; + val = strtoul(c, &endptr, 0); + + if (errno == ERANGE) /* Fail completely if it overflowed. */ + return (0); + + /* + * If the whole string is invalid, endptr will equal + * c.. this way we can make sure someone hasn't + * gone '.12' or something which would get past + * the next check. + */ + if (endptr == c) + return (0); + parts[n] = val; + c = endptr; + + /* Check the next character past the previous number's end */ + switch (*c) { + case '.' : + /* Make sure we only do 3 dots .. */ + if (n == 3) /* Whoops. Quit. */ + return (0); + n++; + c++; + break; + + case '\0': + gotend = 1; + break; + + default: + if (isspace((unsigned char)*c)) { + gotend = 1; + break; + } else + return (0); /* Invalid character, so fail */ + } + + } + + /* + * Concoct the address according to + * the number of parts specified. + */ + + switch (n) { + case 0: /* a -- 32 bits */ + /* + * Nothing is necessary here. Overflow checking was + * already done in strtoul(). + */ + break; + case 1: /* a.b -- 8.24 bits */ + if (val > 0xffffff || parts[0] > 0xff) + return (0); + val |= parts[0] << 24; + break; + + case 2: /* a.b.c -- 8.8.16 bits */ + if (val > 0xffff || parts[0] > 0xff || parts[1] > 0xff) + return (0); + val |= (parts[0] << 24) | (parts[1] << 16); + break; + + case 3: /* a.b.c.d -- 8.8.8.8 bits */ + if (val > 0xff || parts[0] > 0xff || parts[1] > 0xff || + parts[2] > 0xff) + return (0); + val |= (parts[0] << 24) | (parts[1] << 16) | (parts[2] << 8); + break; + } + + if (addr != NULL) + addr->s_addr = htonl(val); + return (1); +} diff --git a/net/inet_lnaof.c b/net/inet_lnaof.c new file mode 100644 index 0000000..99e72ba --- /dev/null +++ b/net/inet_lnaof.c @@ -0,0 +1,77 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1983, 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 +#include +#include + +/* + * Return the local network address portion of an + * internet address; handles class a/b/c network + * number formats. + */ +u_long +inet_lnaof(in) + struct in_addr in; +{ + register u_long i = ntohl(in.s_addr); + + if (IN_CLASSA(i)) + return ((i)&IN_CLASSA_HOST); + else if (IN_CLASSB(i)) + return ((i)&IN_CLASSB_HOST); + else + return ((i)&IN_CLASSC_HOST); +} diff --git a/net/inet_makeaddr.c b/net/inet_makeaddr.c new file mode 100644 index 0000000..8789c19 --- /dev/null +++ b/net/inet_makeaddr.c @@ -0,0 +1,80 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1983, 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 +#include +#include + +/* + * Formulate an Internet address from network + host. Used in + * building addresses stored in the ifnet structure. + */ +struct in_addr +inet_makeaddr(net, host) + u_long net, host; +{ + u_long addr; + + if (net < 128) + addr = (net << IN_CLASSA_NSHIFT) | (host & IN_CLASSA_HOST); + else if (net < 65536) + addr = (net << IN_CLASSB_NSHIFT) | (host & IN_CLASSB_HOST); + else if (net < 16777216L) + addr = (net << IN_CLASSC_NSHIFT) | (host & IN_CLASSC_HOST); + else + addr = net | host; + addr = htonl(addr); + return (*(struct in_addr *)&addr); +} diff --git a/net/inet_net.3 b/net/inet_net.3 new file mode 100644 index 0000000..1d43bcc --- /dev/null +++ b/net/inet_net.3 @@ -0,0 +1,157 @@ +.\" $NetBSD: inet_net.3,v 1.4 1999/03/22 19:44:52 garbled Exp $ +.\" +.\" Copyright (c) 1997 The NetBSD Foundation, Inc. +.\" All rights reserved. +.\" +.\" This code is derived from software contributed to The NetBSD Foundation +.\" by Luke Mewburn. +.\" +.\" 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. +.\" +.\" $FreeBSD: src/lib/libc/net/inet_net.3,v 1.1 2001/08/31 10:54:44 ru Exp $ +.\" +.Dd June 18, 1997 +.Dt INET_NET 3 +.Os +.Sh NAME +.Nm inet_net_ntop , +.Nm inet_net_pton +.Nd Internet network number manipulation routines +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In sys/types.h +.In sys/socket.h +.In netinet/in.h +.In arpa/inet.h +.Ft char * +.Fn inet_net_ntop "int af" "const void *src" "int bits" "char *dst" "size_t size" +.Ft int +.Fn inet_net_pton "int af" "const char *src" "void *dst" "size_t size" +.Sh DESCRIPTION +The +.Fn inet_net_ntop +function converts an Internet network number from network format (usually a +.Vt "struct in_addr" +or some other binary form, in network byte order) to CIDR presentation format +(suitable for external display purposes). +.Fa bits +is the number of bits in +.Fa src +that are the network number. +It returns +.Dv NULL +if a system error occurs (in which case, +.Va errno +will have been set), or it returns a pointer to the destination string. +.Pp +The +.Fn inet_net_pton +function converts a presentation format Internet network number (that is, +printable form as held in a character string) to network format (usually a +.Vt "struct in_addr" +or some other internal binary representation, in network byte order). +It returns the number of bits (either computed based on the class, or +specified with /CIDR), or \-1 if a failure occurred +(in which case +.Va errno +will have been set. +It will be set to +.Er ENOENT +if the Internet network number was not valid). +.Pp +The only value for +.Fa af +currently supported is +.Dv AF_INET . +.Fa size +is the size of the result buffer +.Fa dst . +.Pp +.Sh NETWORK NUMBERS (IP VERSION 4) +Internet network numbers may be specified in one of the following forms: +.Bd -literal -offset indent +a.b.c.d/bits +a.b.c.d +a.b.c +a.b +a +.Ed +.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 network number. +Note +that when an Internet network number is viewed as a 32-bit +integer quantity on a system that uses little-endian +byte order (such as the +.Tn Intel 386 , 486 , +and +.Tn Pentium +processors) the bytes referred to above appear as +.Dq Li d.c.b.a . +That is, little-endian bytes are ordered from right to left. +.Pp +When a three part number is specified, the last +part is interpreted as a 16-bit quantity and placed +in the rightmost two bytes of the Internet network number. +This makes the three part number format convenient +for specifying Class B network numbers as +.Dq Li 128.net.host . +.Pp +When a two part number is supplied, the last part +is interpreted as a 24-bit quantity and placed in +the rightmost three bytes of the Internet network number. +This makes the two part number format convenient +for specifying Class A network numbers as +.Dq Li net.host . +.Pp +When only one part is given, the value is stored +directly in the Internet network number without any byte +rearrangement. +.Pp +All numbers supplied as +.Dq parts +in a +.Ql \&. +notation +may be decimal, octal, or hexadecimal, as specified +in the C language (i.e., a leading 0x or 0X implies +hexadecimal; otherwise, a leading 0 implies octal; +otherwise, the number is interpreted as decimal). +.Sh SEE ALSO +.Xr byteorder 3 , +.Xr inet 3 , +.Xr networks 5 +.Sh HISTORY +The +.Fn inet_net_ntop +and +.Fn inet_net_pton +functions appeared in BIND 4.9.4. diff --git a/net/inet_netof.c b/net/inet_netof.c new file mode 100644 index 0000000..c371654 --- /dev/null +++ b/net/inet_netof.c @@ -0,0 +1,76 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1983, 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 +#include +#include + +/* + * Return the network number from an internet + * address; handles class a/b/c network #'s. + */ +u_long +inet_netof(in) + struct in_addr in; +{ + register u_long i = ntohl(in.s_addr); + + if (IN_CLASSA(i)) + return (((i)&IN_CLASSA_NET) >> IN_CLASSA_NSHIFT); + else if (IN_CLASSB(i)) + return (((i)&IN_CLASSB_NET) >> IN_CLASSB_NSHIFT); + else + return (((i)&IN_CLASSC_NET) >> IN_CLASSC_NSHIFT); +} diff --git a/net/inet_network.c b/net/inet_network.c new file mode 100644 index 0000000..07d6e7f --- /dev/null +++ b/net/inet_network.c @@ -0,0 +1,111 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1983, 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 +#include +#include +#include + +/* + * Internet network address interpretation routine. + * The library routines call this routine to interpret + * network numbers. + */ +u_long +inet_network(cp) + register const char *cp; +{ + register u_long val, base, n; + register char c; + u_long parts[4], *pp = parts; + register int i; + +again: + val = 0; base = 10; + if (*cp == '0') + base = 8, cp++; + if (*cp == 'x' || *cp == 'X') + base = 16, cp++; + while (c = *cp) { + if (isdigit(c)) { + val = (val * base) + (c - '0'); + cp++; + continue; + } + if (base == 16 && isxdigit(c)) { + val = (val << 4) + (c + 10 - (islower(c) ? 'a' : 'A')); + cp++; + continue; + } + break; + } + if (*cp == '.') { + if (pp >= parts + 4) + return (INADDR_NONE); + *pp++ = val, cp++; + goto again; + } + if (*cp && !isspace(*cp)) + return (INADDR_NONE); + *pp++ = val; + n = pp - parts; + if (n > 4) + return (INADDR_NONE); + for (val = 0, i = 0; i < n; i++) { + val <<= 8; + val |= parts[i] & 0xff; + } + return (val); +} diff --git a/net/inet_ntoa.c b/net/inet_ntoa.c new file mode 100644 index 0000000..e91f1ea --- /dev/null +++ b/net/inet_ntoa.c @@ -0,0 +1,77 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1983, 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. + */ + + +/* + * Convert network-format internet address + * to base 256 d.d.d.d representation. + */ +#include +#include +#include +#include + +char * +inet_ntoa(in) + struct in_addr in; +{ + static char b[18]; + register char *p; + + p = (char *)∈ +#define UC(b) (((int)b)&0xff) + (void)snprintf(b, sizeof(b), + "%d.%d.%d.%d", UC(p[0]), UC(p[1]), UC(p[2]), UC(p[3])); + return (b); +} diff --git a/net/linkaddr.3 b/net/linkaddr.3 new file mode 100644 index 0000000..1d66463 --- /dev/null +++ b/net/linkaddr.3 @@ -0,0 +1,140 @@ +.\" 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: @(#)linkaddr.3 8.1 (Berkeley) 7/28/93 +.\" $FreeBSD: src/lib/libc/net/linkaddr.3,v 1.12 2001/10/01 16:08:56 ru Exp $ +.\" +.Dd June 17, 1996 +.Dt LINK_ADDR 3 +.Os +.Sh NAME +.Nm link_addr , +.Nm link_ntoa +.Nd elementary address specification routines for link level access +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In sys/types.h +.In sys/socket.h +.In net/if_dl.h +.Ft void +.Fn link_addr "const char *addr" "struct sockaddr_dl *sdl" +.Ft char * +.Fn link_ntoa "const struct sockaddr_dl *sdl" +.Sh DESCRIPTION +The routine +.Fn link_addr +interprets character strings representing +link-level addresses, returning binary information suitable +for use in system calls. +The routine +.Fn link_ntoa +takes +a link-level +address and returns an +.Tn ASCII +string representing some of the information present, +including the link level address itself, and the interface name +or number, if present. +This facility is experimental and is +still subject to change. +.Pp +For +.Fn link_addr , +the string +.Fa addr +may contain +an optional network interface identifier of the form +.Dq "name unit-number" , +suitable for the first argument to +.Xr ifconfig 8 , +followed in all cases by a colon and +an interface address in the form of +groups of hexadecimal digits +separated by periods. +Each group represents a byte of address; +address bytes are filled left to right from +low order bytes through high order bytes. +.Pp +.\" A regular expression may make this format clearer: +.\" .Bd -literal -offset indent +.\" ([a-z]+[0-9]+:)?[0-9a-f]+(\e.[0-9a-f]+)* +.\" .Ed +.\" .Pp +Thus +.Li le0:8.0.9.13.d.30 +represents an ethernet address +to be transmitted on the first Lance ethernet interface. +.Pp +The direct use of these functions is deprecated in favor of the +.Xr addr2ascii 3 +interface; however, portable programs cannot rely on the latter as it is +not yet widely implemented. +.Sh RETURN VALUES +.Fn link_ntoa +always returns a null terminated string. +.Fn link_addr +has no return value. +(See +.Sx BUGS . ) +.Sh SEE ALSO +.Xr addr2ascii 3 +.\" .Xr iso 4 +.Sh HISTORY +The +.Fn link_addr +and +.Fn link_ntoa +functions appeared in +.Bx 4.3 Reno . +.Sh BUGS +The returned values for link_ntoa +reside in a static memory area. +.Pp +The function +.Fn link_addr +should diagnose improperly formed input, and there should be an unambiguous +way to recognize this. +.Pp +If the +.Va sdl_len +field of the link socket address +.Fa sdl +is 0, +.Fn link_ntoa +will not insert a colon before the interface address bytes. +If this translated address is given to +.Fn link_addr +without inserting an initial colon, +the latter will not interpret it correctly. diff --git a/net/linkaddr.c b/net/linkaddr.c new file mode 100644 index 0000000..ffaafff --- /dev/null +++ b/net/linkaddr.c @@ -0,0 +1,176 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 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 +#include +#include +#include + +/* States*/ +#define NAMING 0 +#define GOTONE 1 +#define GOTTWO 2 +#define RESET 3 +/* Inputs */ +#define DIGIT (4*0) +#define END (4*1) +#define DELIM (4*2) +#define LETTER (4*3) + +void +link_addr(addr, sdl) + register const char *addr; + register struct sockaddr_dl *sdl; +{ + register char *cp = sdl->sdl_data; + char *cplim = sdl->sdl_len + (char *)sdl; + register int byte = 0, state = NAMING, new; + + bzero((char *)&sdl->sdl_family, sdl->sdl_len - 1); + sdl->sdl_family = AF_LINK; + do { + state &= ~LETTER; + if ((*addr >= '0') && (*addr <= '9')) { + new = *addr - '0'; + } else if ((*addr >= 'a') && (*addr <= 'f')) { + new = *addr - 'a' + 10; + } else if ((*addr >= 'A') && (*addr <= 'F')) { + new = *addr - 'A' + 10; + } else if (*addr == 0) { + state |= END; + } else if (state == NAMING && + (((*addr >= 'A') && (*addr <= 'Z')) || + ((*addr >= 'a') && (*addr <= 'z')))) + state |= LETTER; + else + state |= DELIM; + addr++; + switch (state /* | INPUT */) { + case NAMING | DIGIT: + case NAMING | LETTER: + *cp++ = addr[-1]; + continue; + case NAMING | DELIM: + state = RESET; + sdl->sdl_nlen = cp - sdl->sdl_data; + continue; + case GOTTWO | DIGIT: + *cp++ = byte; + /* FALLTHROUGH */ + case RESET | DIGIT: + state = GOTONE; + byte = new; + continue; + case GOTONE | DIGIT: + state = GOTTWO; + byte = new + (byte << 4); + continue; + default: /* | DELIM */ + state = RESET; + *cp++ = byte; + byte = 0; + continue; + case GOTONE | END: + case GOTTWO | END: + *cp++ = byte; + /* FALLTHROUGH */ + case RESET | END: + break; + } + break; + } while (cp < cplim); + sdl->sdl_alen = cp - LLADDR(sdl); + new = cp - (char *)sdl; + if (new > sizeof(*sdl)) + sdl->sdl_len = new; + return; +} + +static char hexlist[] = "0123456789abcdef"; + +char * +link_ntoa(sdl) + register const struct sockaddr_dl *sdl; +{ + static char obuf[64]; + register char *out = obuf; + register int i; + register u_char *in = (u_char *)LLADDR(sdl); + u_char *inlim = in + sdl->sdl_alen; + int firsttime = 1; + + if (sdl->sdl_nlen) { + bcopy(sdl->sdl_data, obuf, sdl->sdl_nlen); + out += sdl->sdl_nlen; + if (sdl->sdl_alen) + *out++ = ':'; + } + while (in < inlim) { + if (firsttime) + firsttime = 0; + else + *out++ = '.'; + i = *in++; + if (i > 0xf) { + out[1] = hexlist[i & 0xf]; + i >>= 4; + out[0] = hexlist[i]; + out += 2; + } else + *out++ = hexlist[i]; + } + *out = 0; + return (obuf); +} diff --git a/net/ns.3 b/net/ns.3 new file mode 100644 index 0000000..be8d155 --- /dev/null +++ b/net/ns.3 @@ -0,0 +1,133 @@ +.\" Copyright (c) 1986, 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. +.\" +.\" @(#)ns.3 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD: src/lib/libc/net/ns.3,v 1.10 2001/10/01 16:08:56 ru Exp $ +.\" +.Dd June 4, 1993 +.Dt NS 3 +.Os +.Sh NAME +.Nm ns_addr , +.Nm ns_ntoa +.Nd Xerox +.Tn NS Ns (tm) +address conversion routines +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In sys/types.h +.In netns/ns.h +.Ft struct ns_addr +.Fn ns_addr "char *cp" +.Ft char * +.Fn ns_ntoa "struct ns_addr ns" +.Sh DESCRIPTION +The routine +.Fn ns_addr +interprets character strings representing +.Tn XNS +addresses, returning binary information suitable +for use in system calls. +The routine +.Fn ns_ntoa +takes +.Tn XNS +addresses and returns +.Tn ASCII +strings representing the address in a +notation in common use in the Xerox Development Environment: +.Bd -ragged -offset indent +.. +.Ed +.Pp +Trailing zero fields are suppressed, and each number is printed in hexadecimal, +in a format suitable for input to +.Fn ns_addr . +Any fields lacking super-decimal digits will have a +trailing +.Ql H +appended. +.Pp +Unfortunately, no universal standard exists for representing +.Tn XNS +addresses. +An effort has been made to insure that +.Fn ns_addr +be compatible with most formats in common use. +It will first separate an address into 1 to 3 fields using a single delimiter +chosen from +period +.Ql \&. , +colon +.Ql \&: +or pound-sign +.Ql \&# . +Each field is then examined for byte separators (colon or period). +If there are byte separators, each subfield separated is taken to be +a small hexadecimal number, and the entirety is taken as a network-byte-ordered +quantity to be zero extended in the high-network-order bytes. +Next, the field is inspected for hyphens, in which case +the field is assumed to be a number in decimal notation +with hyphens separating the millenia. +Next, the field is assumed to be a number: +It is interpreted +as hexadecimal if there is a leading +.Ql 0x +(as in C), +a trailing +.Ql H +(as in Mesa), or there are any super-decimal digits present. +It is interpreted as octal is there is a leading +.Ql 0 +and there are no super-octal digits. +Otherwise, it is converted as a decimal number. +.Sh RETURN VALUES +None. (See +.Sx BUGS . ) +.Sh SEE ALSO +.Xr hosts 5 , +.Xr networks 5 +.Sh HISTORY +The +.Fn ns_addr +and +.Fn ns_toa +functions appeared in +.Bx 4.3 . +.Sh BUGS +The string returned by +.Fn ns_ntoa +resides in a static memory area. +The function +.Fn ns_addr +should diagnose improperly formed input, and there should be an unambiguous +way to recognize this. diff --git a/net/nsap_addr.c b/net/nsap_addr.c new file mode 100644 index 0000000..fd3cc99 --- /dev/null +++ b/net/nsap_addr.c @@ -0,0 +1,122 @@ +/* + * Copyright (c) 1999 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@ + */ +#if defined(LIBC_SCCS) && !defined(lint) +static char rcsid[] = "$Id: nsap_addr.c,v 1.4 2002/05/17 21:00:31 bbraun Exp $"; +#endif /* LIBC_SCCS and not lint */ + +#include +#include +#include +#include +#include +#include +#include + +#if !defined(isxdigit) /* XXX - could be a function */ +static int +isxdigit(c) + register int c; +{ + return ((c >= '0') && (c <= '9')) || ((c >= 'A') && (c <= 'F')); +} +#endif + +static char +xtob(c) + register int c; +{ + return (c - (((c >= '0') && (c <= '9')) ? '0' : '7')); +} + +u_int +inet_nsap_addr(ascii, binary, maxlen) + const char *ascii; + u_char *binary; + int maxlen; +{ + register u_char c, nib; + u_int len = 0; + + while ((c = *ascii++) != '\0' && len < maxlen) { + if (c == '.' || c == '+' || c == '/') + continue; + if (!isascii(c)) + return (0); + if (islower(c)) + c = toupper(c); + if (isxdigit(c)) { + nib = xtob(c); + if (c = *ascii++) { + c = toupper(c); + if (isxdigit(c)) { + *binary++ = (nib << 4) | xtob(c); + len++; + } else + return (0); + } + else + return (0); + } + else + return (0); + } + return (len); +} + +char * +inet_nsap_ntoa(binlen, binary, ascii) + int binlen; + register const u_char *binary; + register char *ascii; +{ + register int nib; + int i; + static char *tmpbuf = NULL; + char *start; + + if( tmpbuf == NULL ) { + tmpbuf = malloc(255*3); + if( tmpbuf == NULL ) + return NULL; + } + + if (ascii) + start = ascii; + else { + ascii = tmpbuf; + start = tmpbuf; + } + + if (binlen > 255) + binlen = 255; + + for (i = 0; i < binlen; i++) { + nib = *binary >> 4; + *ascii++ = nib + (nib < 10 ? '0' : '7'); + nib = *binary++ & 0x0f; + *ascii++ = nib + (nib < 10 ? '0' : '7'); + if (((i % 2) == 0 && (i + 1) < binlen)) + *ascii++ = '.'; + } + *ascii = '\0'; + return (start); +} diff --git a/net/nsdispatch.3 b/net/nsdispatch.3 new file mode 100644 index 0000000..708f97c --- /dev/null +++ b/net/nsdispatch.3 @@ -0,0 +1,231 @@ +.\" $NetBSD: nsdispatch.3,v 1.8 1999/03/22 19:44:53 garbled Exp $ +.\" $FreeBSD: src/lib/libc/net/nsdispatch.3,v 1.5 2001/10/01 16:08:56 ru Exp $ +.\" +.\" Copyright (c) 1997, 1998, 1999 The NetBSD Foundation, Inc. +.\" All rights reserved. +.\" +.\" This code is derived from software contributed to The NetBSD Foundation +.\" by Luke Mewburn. +.\" +.\" 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 January 19, 1999 +.Dt NSDISPATCH 3 +.Os +.Sh NAME +.Nm nsdispatch +.Nd name-service switch dispatcher routine +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In nsswitch.h +.Ft int +.Fo nsdispatch +.Fa "void *retval" +.Fa "const ns_dtab dtab[]" +.Fa "const char *database" +.Fa "const char *method" +.Fa "const ns_src defaults[]" +.Fa "..." +.Fc +.Sh DESCRIPTION +The +.Fn nsdispatch +function invokes the callback functions specified in +.Va dtab +in the order given in +.Pa /etc/nsswitch.conf +for the database +.Va database +until a successful entry is found. +.Pp +.Va retval +is passed to each callback function to modify as necessary +(to pass back to the caller of +.Fn nsdispatch ) +.Pp +.Va dtab +is an array of +.Va ns_dtab +structures, which have the following format: +.Bd -literal -offset indent +typedef struct { + const char *src; + int (*cb)(void *retval, void *cb_data, va_list ap); + void *cb_data; +} ns_dtab; +.Ed +.Pp +.Bd -ragged -offset indent +For each source type that is implemented, an entry with +.Va src +set to the name of the source, +.Va cb +defined as a function which handles that source, and +.Va cb_data +is used to pass arbritrary data to the callback function. +The last entry in +.Va dtab +should contain +.Dv NULL +values for +.Va src , +.Va cb , +and +.Va cb_data . +.Ed +.Pp +.Va method +is usually the name of the function calling +.Fn nsdispatch . +When dynamic loading is supported, a symbol constructed from +.Va database , +the current source, and +.Va method +will be used as the name to invoke the dynamically loaded function. +.Pp +.Va defaults +contains a list of default sources to try in the case of +a missing or corrupt +.Xr nsswitch.conf 5 , +or if there isn't a relevant entry for +.Va database . +It is an array of +.Va ns_src +structures, which have the following format: +.Bd -literal -offset indent +typedef struct { + const char *src; + u_int32_t flags; +} ns_src; +.Ed +.Pp +.Bd -ragged -offset indent +For each default source type, an entry with +.Va src +set to the name of the source, and +.Va flags +set to the relevant flags +(usually +.Dv NS_SUCCESS ; +refer to +.Sx Callback return values +for more information). +The last entry in +.Va defaults +should have +.Va src +set to +.Dv NULL +and +.Va flags +set to 0. +.Pp +For convenience, a global variable defined as: +.Dl extern const ns_src __nsdefaultsrc[]; +exists which contains a single default entry for +.Sq files +for use by callers which don't require complicated default rules. +.Ed +.Pp +.Sq Va ... +are optional extra arguments, which +are passed to the appropriate callback function as a variable argument +list of the type +.Va va_list . +.Ss Valid source types +Whilst there is support for arbitrary sources, the following +#defines for commonly implementated sources are available: +.Bl -column NS_COMPAT COMPAT -offset indent +.It Sy "#define value" +.It "NSSRC_FILES ""files""" +.It "NSSRC_DNS ""dns""" +.It "NSSRC_NIS ""nis""" +.It "NSSRC_COMPAT ""compat""" +.El +.Pp +Refer to +.Xr nsswitch.conf 5 +for a complete description of what each source type is. +.Pp +.Ss Callback return values +The callback functions should return one of the following values +depending upon status of the lookup: +.Bl -column NS_NOTFOUND -offset indent +.It Sy "Return value Status code" +.It "NS_SUCCESS success" +.It "NS_NOTFOUND notfound" +.It "NS_UNAVAIL unavail" +.It "NS_TRYAGAIN tryagain" +.El +.Pp +Refer to +.Xr nsswitch.conf 5 +for a complete description of what each status code is. +.Pp +.Nm +returns the value of the callback that caused the dispatcher to finish, +or NS_NOTFOUND otherwise. +.Sh SEE ALSO +.Xr hesiod 3 , +.Xr stdarg 3 , +.Xr ypclnt 3 , +.Xr nsswitch.conf 5 +.Sh HISTORY +The +.Nm +routines first appeared in +.Fx 4.1 . +They were imported from the +.Nx +Project, +where they appeared first in +.Nx 1.4 . +.Sh AUTHORS +Luke Mewburn +.Aq lukem@netbsd.org +wrote this freely distributable name-service switch implementation, +using ideas from the +.Tn ULTRIX +.Xr svc.conf 5 +and +.Tn Solaris +.Xr nsswitch.conf 4 +manual pages. +.Sh BUGS +The +.Nm +routines are not thread safe. +This will be rectified in the future. +.Pp +Currently there is no support for dynamically loadable dispatcher callback +functions. +It is anticipated that this will be added in the future in the back-end +without requiring changes to code that invokes +.Fn nsdispatch . diff --git a/net/rcmd.3 b/net/rcmd.3 new file mode 100644 index 0000000..9479a23 --- /dev/null +++ b/net/rcmd.3 @@ -0,0 +1,298 @@ +.\" Copyright (c) 1983, 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. +.\" +.\" From: @(#)rcmd.3 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD: src/lib/libc/net/rcmd.3,v 1.20 2001/10/01 16:08:56 ru Exp $ +.\" +.Dd March 3, 2000 +.Dt RCMD 3 +.Os +.Sh NAME +.Nm rcmd , +.Nm rresvport , +.Nm iruserok , +.Nm ruserok , +.Nm rcmd_af , +.Nm rresvport_af , +.Nm iruserok_sa +.Nd routines for returning a stream to a remote command +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In unistd.h +.Ft int +.Fn rcmd "char **ahost" "int inport" "const char *locuser" "const char *remuser" "const char *cmd" "int *fd2p" +.Ft int +.Fn rresvport "int *port" +.Ft int +.Fn iruserok "u_long raddr" "int superuser" "const char *ruser" "const char *luser" +.Ft int +.Fn ruserok "const char *rhost" "int superuser" "const char *ruser" "const char *luser" +.Ft int +.Fn rcmd_af "char **ahost" "int inport" "const char *locuser" "const char *remuser" "const char *cmd" "int *fd2p" "int af" +.Ft int +.Fn rresvport_af "int *port" "int af" +.Ft int +.Fn iruserok_sa "const void *addr" "int addrlen" "int superuser" "const char *ruser" "const char *luser" +.Sh DESCRIPTION +The +.Fn rcmd +function +is used by the super-user to execute a command on +a remote machine using an authentication scheme based +on reserved port numbers. +The +.Fn rresvport +function +returns a descriptor to a socket +with an address in the privileged port space. +The +.Fn ruserok +function +is used by servers +to authenticate clients requesting service with +.Fn rcmd . +All three functions are present in the same file and are used +by the +.Xr rshd 8 +server (among others). +.Pp +The +.Fn rcmd +function +looks up the host +.Fa *ahost +using +.Xr gethostbyname 3 , +returning -1 if the host does not exist. +Otherwise +.Fa *ahost +is set to the standard name of the host +and a connection is established to a server +residing at the well-known Internet port +.Fa inport . +.Pp +If the connection succeeds, +a socket in the Internet domain of type +.Dv SOCK_STREAM +is returned to the caller, and given to the remote +command as +.Em stdin +and +.Em stdout . +If +.Fa fd2p +is non-zero, then an auxiliary channel to a control +process will be set up, and a descriptor for it will be placed +in +.Fa *fd2p . +The control process will return diagnostic +output from the command (unit 2) on this channel, and will also +accept bytes on this channel as being +.Tn UNIX +signal numbers, to be +forwarded to the process group of the command. +If +.Fa fd2p +is 0, then the +.Em stderr +(unit 2 of the remote +command) will be made the same as the +.Em stdout +and no +provision is made for sending arbitrary signals to the remote process, +although you may be able to get its attention by using out-of-band data. +.Pp +The protocol is described in detail in +.Xr rshd 8 . +.Pp +The +.Fn rresvport +function is used to obtain a socket to which an address with a Privileged +Internet port is bound. +This socket is suitable for use by +.Fn rcmd +and several other functions. +Privileged Internet ports are those in the range 0 to 1023. +Only the super-user is allowed to bind an address of this sort +to a socket. +.Pp +The +.Fn iruserok +and +.Fn ruserok +functions take a remote host's IP address or name, as returned by the +.Xr gethostbyname 3 +routines, two user names and a flag indicating whether the local user's +name is that of the super-user. +Then, if the user is +.Em NOT +the super-user, it checks the +.Pa /etc/hosts.equiv +file. +If that lookup is not done, or is unsuccessful, the +.Pa .rhosts +in the local user's home directory is checked to see if the request for +service is allowed. +.Pp +If this file does not exist, is not a regular file, is owned by anyone +other than the user or the super-user, or is writable by anyone other +than the owner, the check automatically fails. +Zero is returned if the machine name is listed in the +.Dq Pa hosts.equiv +file, or the host and remote user name are found in the +.Dq Pa .rhosts +file; otherwise +.Fn iruserok +and +.Fn ruserok +return -1. +If the local domain (as obtained from +.Xr gethostname 3 ) +is the same as the remote domain, only the machine name need be specified. +.Pp +The +.Fn iruserok +function is strongly preferred for security reasons. +It requires trusting the local DNS at most, while the +.Fn ruserok +function requires trusting the entire DNS, which can be spoofed. +.Pp +The functions with an +.Dq Li _af +or +.Dq Li _sa +suffix, i.e., +.Fn rcmd_af , +.Fn rresvport_af +and +.Fn iruserok_sa , +work the same as the corresponding functions without a +suffix, except that they are capable of handling both IPv6 and IPv4 ports. +.Pp +The +.Dq Li _af +suffix means that the function has an additional +.Fa af +argument which is used to specify the address family, +(see below). +The +.Fa af +argument extension is implemented for functions +that have no binary address argument. +Instead, the +.Fa af +argument specifies which address family is desired. +.Pp +The +.Dq Li _sa +suffix means that the function has general socket address and +length arguments. +As the socket address is a protocol independent data structure, +IPv4 and IPv6 socket address can be passed as desired. +The +.Fa sa +argument extension is implemented for functions +that pass a protocol dependent binary address argument. +The argument needs to be replaced with a more general address structure +to support multiple address families in a general way. +.Pp +The functions with neither an +.Dq Li _af +suffix nor an +.Dq Li _sa +suffix work for IPv4 only, except for +.Fn ruserok +which can handle both IPv6 and IPv4. +To switch the address family, the +.Fa af +argument must be filled with +.Dv AF_INET , +or +.Dv AF_INET6 . +For +.Fn rcmd_af , +.Dv PF_UNSPEC +is also allowed. +.Sh DIAGNOSTICS +The +.Fn rcmd +function +returns a valid socket descriptor on success. +It returns -1 on error and prints a diagnostic message +on the standard error. +.Pp +The +.Fn rresvport +function +returns a valid, bound socket descriptor on success. +It returns -1 on error with the global value +.Va errno +set according to the reason for failure. +The error code +.Er EAGAIN +is overloaded to mean ``All network ports in use.'' +.Sh SEE ALSO +.Xr rlogin 1 , +.Xr rsh 1 , +.Xr intro 2 , +.Xr rexec 3 , +.Xr rexecd 8 , +.Xr rlogind 8 , +.Xr rshd 8 +.Pp +.Rs +.%A W. Stevens +.%A M. Thomas +.%T "Advanced Socket API for IPv6" +.%O RFC2292 +.Re +.Rs +.%A W. Stevens +.%A M. Thomas +.%A E. Nordmark +.%T "Advanced Socket API for IPv6" +.%O draft-ietf-ipngwg-rfc2292bis-01.txt +.Re +.Sh HISTORY +Most of these +functions appeared in +.Bx 4.2 . +.Fn rresvport_af +appeared in RFC2292, and was implemented by the WIDE project +for the Hydrangea IPv6 protocol stack kit. +.Fn rcmd_af +appeared in draft-ietf-ipngwg-rfc2292bis-01.txt, +and was implemented in the WIDE/KAME IPv6 protocol stack kit. +.Fn iruserok_sa +appeared in discussion on the IETF ipngwg mailing list, +and was implemented in +.Fx 4.0 . diff --git a/net/rcmdsh.3 b/net/rcmdsh.3 new file mode 100644 index 0000000..43e6a8d --- /dev/null +++ b/net/rcmdsh.3 @@ -0,0 +1,116 @@ +.\" $OpenBSD: rcmdsh.3,v 1.6 1999/07/05 04:41:00 aaron Exp $ +.\" +.\" Copyright (c) 1983, 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. +.\" +.\" $FreeBSD: src/lib/libc/net/rcmdsh.3,v 1.2 2001/11/09 15:19:25 ru Exp $ +.\" +.Dd September 1, 1996 +.Dt RCMDSH 3 +.Os +.Sh NAME +.Nm rcmdsh +.Nd return a stream to a remote command without superuser +.Sh SYNOPSIS +.In unistd.h +.Ft int +.Fo rcmdsh +.Fa "char **ahost" +.Fa "int inport" +.Fa "const char *locuser" +.Fa "const char *remuser" +.Fa "const char *cmd" +.Fa "const char *rshprog" +.Fc +.Sh DESCRIPTION +The +.Fn rcmdsh +function +is used by normal users to execute a command on +a remote machine using an authentication scheme based +on reserved port numbers using +.Xr rshd 8 +or the value of +.Fa rshprog +(if +.No non- Ns Dv NULL ) . +.Pp +The +.Fn rcmdsh +function +looks up the host +.Fa *ahost +using +.Xr gethostbyname 3 , +returning \-1 if the host does not exist. +Otherwise +.Fa *ahost +is set to the standard name of the host +and a connection is established to a server +residing at the well-known Internet port +.Dq Li shell/tcp +(or whatever port is used by +.Fa rshprog ) . +The parameter +.Fa inport +is ignored; it is only included to provide an interface similar to +.Xr rcmd 3 . +.Pp +If the connection succeeds, +a socket in the +.Ux +domain of type +.Dv SOCK_STREAM +is returned to the caller, and given to the remote +command as stdin, stdout, and stderr. +.Sh RETURN VALUES +The +.Fn rcmdsh +function +returns a valid socket descriptor on success. +Otherwise, \-1 is returned +and a diagnostic message is printed on the standard error. +.Sh SEE ALSO +.Xr rsh 1 , +.Xr socketpair 2 , +.Xr rcmd 3 , +.Xr rshd 8 +.Sh BUGS +If +.Xr rsh 1 +encounters an error, a file descriptor is still returned instead of \-1. +.Sh HISTORY +The +.Fn rcmdsh +function first appeared in +.Ox 2.0 , +and made its way into +.Fx 5.0 . diff --git a/net/recv.c b/net/recv.c new file mode 100644 index 0000000..42645fa --- /dev/null +++ b/net/recv.c @@ -0,0 +1,66 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1988, 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 +#include + +#include + +ssize_t recv(s, buf, len, flags) + int s, flags; + size_t len; + void *buf; +{ + return (recvfrom(s, buf, len, flags, NULL, 0)); +} diff --git a/net/resolver.3 b/net/resolver.3 new file mode 100644 index 0000000..1417598 --- /dev/null +++ b/net/resolver.3 @@ -0,0 +1,422 @@ +.\" Copyright (c) 1985, 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. +.\" +.\" @(#)resolver.3 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD: src/lib/libc/net/resolver.3,v 1.21 2001/10/01 16:08:56 ru Exp $ +.\" +.Dd June 4, 1993 +.Dt RESOLVER 3 +.Os +.Sh NAME +.Nm res_query , +.Nm res_search , +.Nm res_mkquery , +.Nm res_send , +.Nm res_init , +.Nm dn_comp , +.Nm dn_expand , +.Nm dn_skipname , +.Nm ns_get16 , +.Nm ns_get32 , +.Nm ns_put16 , +.Nm ns_put32 +.Nd resolver routines +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In sys/types.h +.In netinet/in.h +.In arpa/nameser.h +.In resolv.h +.Ft int +.Fo res_query +.Fa "const char *dname" +.Fa "int class" +.Fa "int type" +.Fa "u_char *answer" +.Fa "int anslen" +.Fc +.Ft int +.Fo res_search +.Fa "const char *dname" +.Fa "int class" +.Fa "int type" +.Fa "u_char *answer" +.Fa "int anslen" +.Fc +.Ft int +.Fo res_mkquery +.Fa "int op" +.Fa "const char *dname" +.Fa "int class" +.Fa "int type" +.Fa "const u_char *data" +.Fa "int datalen" +.Fa "const u_char *newrr_in" +.Fa "u_char *buf" +.Fa "int buflen" +.Fc +.Ft int +.Fo res_send +.Fa "const u_char *msg" +.Fa "int msglen" +.Fa "u_char *answer" +.Fa "int anslen" +.Fc +.Ft int +.Fn res_init +.Ft int +.Fo dn_comp +.Fa "const char *exp_dn" +.Fa "u_char *comp_dn" +.Fa "int length" +.Fa "u_char **dnptrs" +.Fa "u_char **lastdnptr" +.Fc +.Ft int +.Fo dn_expand +.Fa "const u_char *msg" +.Fa "const u_char *eomorig" +.Fa "const u_char *comp_dn" +.Fa "char *exp_dn" +.Fa "int length" +.Fc +.Ft int +.Fn dn_skipname "const u_char *comp_dn" "const u_char *eom" +.Ft u_int +.Fn ns_get16 "const u_char *src" +.Ft u_long +.Fn ns_get32 "const u_char *src" +.Ft void +.Fn ns_put16 "u_int src" "u_char *dst" +.Ft void +.Fn ns_put32 "u_long src" "u_char *dst" +.Sh DESCRIPTION +These routines are used for making, sending and interpreting +query and reply messages with Internet domain name servers. +.Pp +Global configuration and state information that is used by the +resolver routines is kept in the structure +.Em _res . +Most of the values have reasonable defaults and can be ignored. +Options +stored in +.Em _res.options +are defined in +.Pa resolv.h +and are as follows. +Options are stored as a simple bit mask containing the bitwise ``or'' +of the options enabled. +.Bl -tag -width RES_USE_INET6 +.It Dv RES_INIT +True if the initial name server address and default domain name are +initialized (i.e., +.Fn res_init +has been called). +.It Dv RES_DEBUG +Print debugging messages. +.It Dv RES_AAONLY +Accept authoritative answers only. +With this option, +.Fn res_send +should continue until it finds an authoritative answer or finds an error. +Currently this is not implemented. +.It Dv RES_USEVC +Use +.Tn TCP +connections for queries instead of +.Tn UDP +datagrams. +.It Dv RES_STAYOPEN +Used with +.Dv RES_USEVC +to keep the +.Tn TCP +connection open between +queries. +This is useful only in programs that regularly do many queries. +.Tn UDP +should be the normal mode used. +.It Dv RES_IGNTC +Unused currently (ignore truncation errors, i.e., don't retry with +.Tn TCP ) . +.It Dv RES_RECURSE +Set the recursion-desired bit in queries. +This is the default. +.Pf ( Fn res_send +does not do iterative queries and expects the name server +to handle recursion.) +.It Dv RES_DEFNAMES +If set, +.Fn res_search +will append the default domain name to single-component names +(those that do not contain a dot). +This option is enabled by default. +.It Dv RES_DNSRCH +If this option is set, +.Fn res_search +will search for host names in the current domain and in parent domains; see +.Xr hostname 7 . +This is used by the standard host lookup routine +.Xr gethostbyname 3 . +This option is enabled by default. +.It Dv RES_NOALIASES +This option turns off the user level aliasing feature controlled by the +.Dq Ev HOSTALIASES +environment variable. Network daemons should set this option. +.It Dv RES_USE_INET6 +Enables support for IPv6-only applications. +This causes IPv4 addresses to be returned as an IPv4 mapped address. +For example, +.Li 10.1.1.1 +will be returned as +.Li ::ffff:10.1.1.1 . +The option is meaningful with certain kernel configuration only. +.It Dv RES_USE_EDNS0 +Enables support for OPT pseudo-RR for EDNS0 extension. +With the option, resolver code will attach OPT pseudo-RR into DNS queries, +to inform of our receive buffer size. +The option will allow DNS servers to take advantage of non-default receive +buffer size, and to send larger replies. +DNS query packets with EDNS0 extension is not compatible with +non-EDNS0 DNS servers. +.El +.Pp +The +.Fn res_init +routine +reads the configuration file (if any; see +.Xr resolver 5 ) +to get the default domain name, +search list and +the Internet address of the local name server(s). +If no server is configured, the host running +the resolver is tried. +The current domain name is defined by the hostname +if not specified in the configuration file; +it can be overridden by the environment variable +.Ev LOCALDOMAIN . +This environment variable may contain several blank-separated +tokens if you wish to override the +.Em "search list" +on a per-process basis. This is similar to the +.Em search +command in the configuration file. +Another environment variable +.Dq Ev RES_OPTIONS +can be set to +override certain internal resolver options which are otherwise +set by changing fields in the +.Em _res +structure or are inherited from the configuration file's +.Em options +command. The syntax of the +.Dq Ev RES_OPTIONS +environment variable is explained in +.Xr resolver 5 . +Initialization normally occurs on the first call +to one of the following routines. +.Pp +The +.Fn res_query +function provides an interface to the server query mechanism. +It constructs a query, sends it to the local server, +awaits a response, and makes preliminary checks on the reply. +The query requests information of the specified +.Fa type +and +.Fa class +for the specified fully-qualified domain name +.Fa dname . +The reply message is left in the +.Fa answer +buffer with length +.Fa anslen +supplied by the caller. +.Pp +The +.Fn res_search +routine makes a query and awaits a response like +.Fn res_query , +but in addition, it implements the default and search rules +controlled by the +.Dv RES_DEFNAMES +and +.Dv RES_DNSRCH +options. +It returns the first successful reply. +.Pp +The remaining routines are lower-level routines used by +.Fn res_query . +The +.Fn res_mkquery +function +constructs a standard query message and places it in +.Fa buf . +It returns the size of the query, or \-1 if the query is +larger than +.Fa buflen . +The query type +.Fa op +is usually +.Dv QUERY , +but can be any of the query types defined in +.Aq Pa arpa/nameser.h . +The domain name for the query is given by +.Fa dname . +.Fa Newrr +is currently unused but is intended for making update messages. +.Pp +The +.Fn res_send +routine +sends a pre-formatted query and returns an answer. +It will call +.Fn res_init +if +.Dv RES_INIT +is not set, send the query to the local name server, and +handle timeouts and retries. +The length of the reply message is returned, or +\-1 if there were errors. +.Pp +The +.Fn dn_comp +function +compresses the domain name +.Fa exp_dn +and stores it in +.Fa comp_dn . +The size of the compressed name is returned or \-1 if there were errors. +The size of the array pointed to by +.Fa comp_dn +is given by +.Fa length . +The compression uses +an array of pointers +.Fa dnptrs +to previously-compressed names in the current message. +The first pointer points to +the beginning of the message and the list ends with +.Dv NULL . +The limit to the array is specified by +.Fa lastdnptr . +A side effect of +.Fn dn_comp +is to update the list of pointers for +labels inserted into the message +as the name is compressed. +If +.Em dnptr +is +.Dv NULL , +names are not compressed. +If +.Fa lastdnptr +is +.Dv NULL , +the list of labels is not updated. +.Pp +The +.Fn dn_expand +entry +expands the compressed domain name +.Fa comp_dn +to a full domain name +The compressed name is contained in a query or reply message; +.Fa msg +is a pointer to the beginning of the message. +The uncompressed name is placed in the buffer indicated by +.Fa exp_dn +which is of size +.Fa length . +The size of compressed name is returned or \-1 if there was an error. +.Pp +The +.Fn dn_skipname +function skips over a compressed domain name, which starts at a location +pointed to by +.Fa comp_dn . +The compressed name is contained in a query or reply message; +.Fa eom +is a pointer to the end of the message. +The size of compressed name is returned or \-1 if there was +an error. +.Pp +The +.Fn ns_get16 +function gets a 16-bit quantity from a buffer pointed to by +.Fa src . +.Pp +The +.Fn ns_get32 +function gets a 32-bit quantity from a buffer pointed to by +.Fa src . +.Pp +The +.Fn ns_put16 +function puts a 16-bit quantity +.Fa src +to a buffer pointed to by +.Fa dst . +.Pp +The +.Fn ns_put32 +function puts a 32-bit quantity +.Fa src +to a buffer pointed to by +.Fa dst . +.Sh FILES +.Bl -tag -width /etc/resolv.conf +.It Pa /etc/resolv.conf +The configuration file, +see +.Xr resolver 5 . +.El +.Sh SEE ALSO +.Xr gethostbyname 3 , +.Xr resolver 5 , +.Xr hostname 7 , +.Xr named 8 +.Pp +.%T RFC1032 , +.%T RFC1033 , +.%T RFC1034 , +.%T RFC1035 , +.%T RFC974 +.Rs +.%T "Name Server Operations Guide for BIND" +.Re +.Sh HISTORY +The +.Nm +function appeared in +.Bx 4.3 . diff --git a/nls/Makefile.inc b/nls/Makefile.inc new file mode 100644 index 0000000..66329a2 --- /dev/null +++ b/nls/Makefile.inc @@ -0,0 +1,10 @@ +# from $NetBSD: Makefile.inc,v 1.7 1995/02/27 13:06:20 cgd Exp $ +# $FreeBSD: src/lib/libc/nls/Makefile.inc,v 1.7 2001/03/27 17:26:48 ru Exp $ + +.PATH: ${.CURDIR}/../libc/nls + +SRCS+= msgcat.c + +.if ${LIB} == "c" +MAN+= catclose.3 catgets.3 catopen.3 +.endif diff --git a/posix1e/Makefile.inc b/posix1e/Makefile.inc new file mode 100644 index 0000000..42b2aa6 --- /dev/null +++ b/posix1e/Makefile.inc @@ -0,0 +1,92 @@ +# $FreeBSD: src/lib/libc/posix1e/Makefile.inc,v 1.6 2001/09/01 00:00:50 rwatson Exp $ + +MAINTAINER= rwatson@FreeBSD.org + +.PATH: ${.CURDIR}/../libc/posix1e + +SRCS+= 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 + +.if ${LIB} == "c" + +MAN+= acl.3 \ + acl_add_perm.3 \ + acl_calc_mask.3 \ + acl_clear_perms.3 \ + acl_copy_entry.3 \ + acl_create_entry.3 \ + acl_delete.3 \ + acl_delete_entry.3 \ + acl_delete_perm.3 \ + acl_dup.3 \ + acl_free.3 \ + acl_from_text.3 \ + acl_get.3 \ + acl_get_entry.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_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 + +MLINKS+=acl_delete.3 acl_delete_def_file.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_get.3 acl_get_fd.3 \ + acl_get.3 acl_get_fd_np.3 \ + acl_set.3 acl_set_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 + +.endif diff --git a/ppc/gen/Makefile.inc b/ppc/gen/Makefile.inc new file mode 100644 index 0000000..6344540 --- /dev/null +++ b/ppc/gen/Makefile.inc @@ -0,0 +1,6 @@ +SRCS += abs.s bzero.s mcount.s strcmp.c strncmp.c \ + ecvt.c remque.c strcpy.c strncpy.c \ + bcmp.c ffs.s insque.c setjmperr.c strlen.s \ + bcopy.s fp.h isinf.c strcat.c strncat.c \ + mcount.s + diff --git a/ppc/gen/abs.s b/ppc/gen/abs.s new file mode 100644 index 0000000..3d7ae3c --- /dev/null +++ b/ppc/gen/abs.s @@ -0,0 +1,62 @@ +/* + * Copyright (c) 1999 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@ + */ +/* Copyright (c) 1992,1997 NeXT Software, Inc. All rights reserved. + * + * File: libc/gen/ppc/abs.s + * Author: Derek B Clegg, NeXT Software, Inc. + * + * HISTORY + * 24-Jan-1997 Umesh Vaishampayan (umeshv@NeXT.com) + * Ported to PPC. + * 10-Nov-92 Derek B Clegg (dclegg@next.com) + * Created. + * 13-Jan-93 Derek B Clegg (dclegg@next.com) + * Optimized. + * + * ANSI X3.159-1989: + * int abs(int j); + * + * Description: + * The `abs' function computes the absolute value of an integer `j'. + * If the result cannot be represented, the behavior is undefined. + * Returns: + * The `abs' function returns the absolute value. + */ +#include +#include + +/* We calculate abs(x) as + * s = x >> 31; + * y = x + s; + * return y ^ s; + * + * If x >= 0, then s = 0, so clearly we return x. On the other hand, if + * x < 0, then we may write x as ~z + 1, where z = -x. In this case, + * s = -1, so y = x - 1 = ~z, and hence we return -1 ^ (x - 1) = -1 ^ ~z + * = z = -x. + */ +LEAF(_abs) + srawi a1,a0,31 + add a2,a1,a0 + xor a0,a2,a1 + blr +END(_abs) diff --git a/ppc/gen/assymdefs.c b/ppc/gen/assymdefs.c new file mode 100644 index 0000000..80ecae8 --- /dev/null +++ b/ppc/gen/assymdefs.c @@ -0,0 +1,87 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * assymdefs.c -- list of symbols to #define in assym.h + */ +#import +#define __TARGET_ARCHITECTURE__ "ppc" +#import +#import +#import +#import "genassym.h" + +void +assymdefs(void) +{ + /* This is required for `setjmp' to work. */ + assert(offsetof(struct _jmp_buf, csr[18]) + == offsetof(struct _jmp_buf, fp)); + + comment(MAJOR, "Structure Offsets"); + comment(MINOR, "jmpbuf_t offsets and constants"); + + PRINT_OFFSET(struct _jmp_buf *, magic); + PRINT_OFFSET(struct _jmp_buf *, sp); + PRINT_OFFSET(struct _jmp_buf *, csr[0]); + PRINT_OFFSET(struct _jmp_buf *, csr[17]); + PRINT_OFFSET(struct _jmp_buf *, fp); + PRINT_OFFSET(struct _jmp_buf *, toc); + PRINT_OFFSET(struct _jmp_buf *, cr); + PRINT_OFFSET(struct _jmp_buf *, lr); + PRINT_OFFSET(struct _jmp_buf *, fpr[0]); + PRINT_OFFSET(struct _jmp_buf *, fpr[1]); + PRINT_OFFSET(struct _jmp_buf *, fpr[2]); + PRINT_OFFSET(struct _jmp_buf *, fpr[3]); + PRINT_OFFSET(struct _jmp_buf *, fpr[4]); + PRINT_OFFSET(struct _jmp_buf *, fpr[5]); + PRINT_OFFSET(struct _jmp_buf *, fpr[6]); + PRINT_OFFSET(struct _jmp_buf *, fpr[7]); + PRINT_OFFSET(struct _jmp_buf *, fpr[8]); + PRINT_OFFSET(struct _jmp_buf *, fpr[9]); + PRINT_OFFSET(struct _jmp_buf *, fpr[10]); + PRINT_OFFSET(struct _jmp_buf *, fpr[11]); + PRINT_OFFSET(struct _jmp_buf *, fpr[12]); + PRINT_OFFSET(struct _jmp_buf *, fpr[13]); + PRINT_OFFSET(struct _jmp_buf *, fpr[14]); + PRINT_OFFSET(struct _jmp_buf *, fpr[15]); + PRINT_OFFSET(struct _jmp_buf *, fpr[16]); + PRINT_OFFSET(struct _jmp_buf *, fpr[17]); + PRINT_OFFSET(struct _jmp_buf *, fpscr); + PRINT_OFFSET(struct _jmp_buf *, sig_onstack); + PRINT_OFFSET(struct _jmp_buf *, sig_mask); + PRINT_CONSTANT(_JMP_BUF_MAGICNUM); + + comment(MINOR, "sigcontext offsets, sizes, and constants"); + PRINT_SIZEOF(struct sigcontext); + PRINT_OFFSET(struct sigcontext *, sc_onstack); + PRINT_OFFSET(struct sigcontext *, sc_mask); + PRINT_OFFSET(struct sigcontext *, sc_sp); + PRINT_OFFSET(struct sigcontext *, sc_cia); + PRINT_OFFSET(struct sigcontext *, sc_regs_saved); + PRINT_OFFSET(struct sigcontext *, sc_a0); + PRINT_ENUM(REGS_SAVED_NONE); + + comment(MINOR, "struct sigstack offsets and sizes"); + PRINT_SIZEOF(struct sigstack); + PRINT_OFFSET(struct sigstack *, ss_sp); + PRINT_OFFSET(struct sigstack *, ss_onstack); +} diff --git a/ppc/gen/bcmp.c b/ppc/gen/bcmp.c new file mode 100644 index 0000000..b9fdb04 --- /dev/null +++ b/ppc/gen/bcmp.c @@ -0,0 +1,41 @@ +/* + * Copyright (c) 1999 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@ + */ +/* Copyright (c) 1992, 1997 NeXT Software, Inc. All rights reserved. + * + * File: libc/gen/ppc/bcmp.c + * + * Byte-compare routine. + * + * HISTORY + * 24-Jan-1997 Umesh Vaishampayan (umeshv@NeXT.com) + * Ported to PPC. + */ + +#import + +#undef bcmp + +int +bcmp(const void *b1, const void *b2, size_t length) +{ + return memcmp(b1, b2, length); +} diff --git a/ppc/gen/bcopy.s b/ppc/gen/bcopy.s new file mode 100644 index 0000000..2020f15 --- /dev/null +++ b/ppc/gen/bcopy.s @@ -0,0 +1,1159 @@ +/* + * Copyright (c) 2002 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@ + */ +/* ======================================= + * BCOPY, MEMCPY, and MEMMOVE for Mac OS X + * ======================================= + * + * Version of 6/17/2002, for G3, G4, and G4+. + * + * There are many paths through this code, depending on length, reverse/forward, + * processor type, and alignment. We use reverse paths only when the operands + * overlap and the destination is higher than the source. They are not quite as + * fast as the forward paths. + * + * Judicious use of DCBTs, just far enough ahead to minimize waiting, is critical in + * the inner loops for long operands. DST is less effective than DCBT, because it + * can get out of sync with the inner loop. DCBTST is usually not a win, so we + * don't use it except during initialization when we're not using the LSU. + * We don't DCBT on G3, which only handles one load miss at a time. + * + * We don't use DCBZ, because it takes an alignment exception on uncached memory + * like frame buffers. Bcopy to frame buffers must work. This hurts G3 in the + * cold-cache case, but G4 can use DCBA (which does not take alignment exceptions.) + * + * Using DCBA on G4 is a tradeoff. For the cold-cache case it can be a big win, + * since it avoids the read of destination cache lines. But for the hot-cache case + * it is always slower, because of the cycles spent needlessly zeroing data. Some + * machines store-gather and can cancel the read if all bytes of a line are stored, + * others cannot. Unless explicitly told which is better, we time loops with and + * without DCBA and use the fastest. Note that we never DCBA in reverse loops, + * since by definition they are overlapped so dest lines will be in the cache. + * + * For longer operands we use an 8-element branch table, based on the CPU type, + * to select the appropriate inner loop. The branch table is indexed as follows: + * + * bit 10000 set if a Reverse move is required + * bits 01100 set on the relative operand alignment: 0=unaligned, 1=word, + * 2=doubleword, and 3=quadword. + * + * By "relatively" n-byte aligned, we mean the source and destination are a multiple + * of n bytes apart (they need not be absolutely aligned.) + * + * The branch table for the running CPU type is pointed to by LBranchTablePtr. + * Initially, LBranchtablePtr points to G3's table, since that is the lowest + * common denominator that will run on any CPU. Later, pthread initialization + * sets up the _cpu_capabilities vector and calls _bcopy_initialize, which sets + * up the correct pointer for the running CPU. + * + * We distinguish between "short", "medium", and "long" operands: + * short (<= 32 bytes) most common case, minimum path length is important + * medium (> 32, < kLong) too short for Altivec or use of cache ops like DCBA + * long (>= kLong) long enough for cache ops and to amortize use of Altivec + * + * WARNING: kLong must be >=96, due to implicit assumptions about operand length. + */ +#define kLong 96 + +/* Register usage. Note we use R2, so this code will not run in a PEF/CFM + * environment. Note also the rather delicate way we assign multiple uses + * to the same register. Beware. + * + * r0 = "w7" or "r0" (NB: cannot use r0 for any constant such as "c16") + * r2 = "w8" or VRSave ("rv") + * r3 = not used, as memcpy and memmove return 1st parameter as a value + * r4 = source ptr ("rs") + * r5 = count of bytes to move ("rc") + * r6 = "w1", "c16", or "cm17" + * r7 = "w2", "c32", or "cm33" + * r8 = "w3", "c48", or "cm49" + * r9 = "w4", "c64", or "cm1" + * r10 = "w5", "c96", or "cm97" + * r11 = "w6", "c128", "cm129", or return address ("ra") + * r12 = destination ptr ("rd") + * f0-f8 = used for moving 8-byte aligned data + * v0 = permute vector ("vp") + * v1-v4 = qw's loaded from source ("v1", "v2", "v3", and "v4") + * v5-v7 = permuted qw's ("vx", "vy", and "vz") + */ +#define rs r4 +#define rd r12 +#define rc r5 +#define ra r11 +#define rv r2 + +#define w1 r6 +#define w2 r7 +#define w3 r8 +#define w4 r9 +#define w5 r10 +#define w6 r11 +#define w7 r0 +#define w8 r2 + +#define c16 r6 +#define cm17 r6 +#define c32 r7 +#define cm33 r7 +#define c48 r8 +#define cm49 r8 +#define c64 r9 +#define cm1 r9 +#define c96 r10 +#define cm97 r10 +#define c128 r11 +#define cm129 r11 + +#define vp v0 +#define vx v5 +#define vy v6 +#define vz v7 + +#define VRSave 256 + +#include + +// The branch tables, 8 entries per CPU type. +// NB: we depend on 5 low-order 0s in the address of branch tables. + + .data + .align 5 // must be 32-byte aligned + + // G3 (the default CPU type) + +LG3: + .long LForwardWord // 000: forward, unaligned + .long LForwardFloat // 001: forward, 4-byte aligned + .long LForwardFloat // 010: forward, 8-byte aligned + .long LForwardFloat // 011: forward, 16-byte aligned + .long LReverseWord // 100: reverse, unaligned + .long LReverseFloat // 101: reverse, 4-byte aligned + .long LReverseFloat // 110: reverse, 8-byte aligned + .long LReverseFloat // 111: reverse, 16-byte aligned + + // G4s that benefit from DCBA. + +LG4UseDcba: + .long LForwardVecUnal32Dcba // 000: forward, unaligned + .long LForwardVecUnal32Dcba // 001: forward, 4-byte aligned + .long LForwardVecUnal32Dcba // 010: forward, 8-byte aligned + .long LForwardVecAlig32Dcba // 011: forward, 16-byte aligned + .long LReverseVectorUnal32 // 100: reverse, unaligned + .long LReverseVectorUnal32 // 101: reverse, 4-byte aligned + .long LReverseVectorUnal32 // 110: reverse, 8-byte aligned + .long LReverseVectorAligned32 // 111: reverse, 16-byte aligned + + // G4s that should not use DCBA. + +LG4NoDcba: + .long LForwardVecUnal32NoDcba // 000: forward, unaligned + .long LForwardVecUnal32NoDcba // 001: forward, 4-byte aligned + .long LForwardVecUnal32NoDcba // 010: forward, 8-byte aligned + .long LForwardVecAlig32NoDcba // 011: forward, 16-byte aligned + .long LReverseVectorUnal32 // 100: reverse, unaligned + .long LReverseVectorUnal32 // 101: reverse, 4-byte aligned + .long LReverseVectorUnal32 // 110: reverse, 8-byte aligned + .long LReverseVectorAligned32 // 111: reverse, 16-byte aligned + + +// Pointer to the 8-element branch table for running CPU type: + +LBranchTablePtr: + .long LG3 // default to G3 until "bcopy_initialize" called + + +// The CPU capability vector, initialized in pthread_init(). +// "_bcopy_initialize" uses this to set up LBranchTablePtr: + + .globl __cpu_capabilities +__cpu_capabilities: + .long 0 + +// Bit definitions for _cpu_capabilities: + +#define kHasAltivec 0x01 +#define k64Bit 0x02 +#define kCache32 0x04 +#define kCache64 0x08 +#define kCache128 0x10 +#define kUseDcba 0x20 +#define kNoDcba 0x40 + + +.text +.globl _bcopy +.globl _memcpy +.globl _memmove +.globl __bcopy_initialize + + +// Main entry points. + + .align 5 +_bcopy: // void bcopy(const void *src, void *dst, size_t len) + mr r10,r3 // reverse source and dest ptrs, to be like memcpy + mr r3,r4 + mr r4,r10 +_memcpy: // void* memcpy(void *dst, void *src, size_t len) +_memmove: // void* memmove(void *dst, const void *src, size_t len) + cmplwi cr7,rc,32 // length <= 32 bytes? + sub. w1,r3,rs // must move in reverse if (rd-rs)=1) + mtctr w4 // prepare loop count + beq+ 2f // source already aligned + + lwzx w2,w3,rs // get 1st aligned word (which we might partially overwrite) + add rs,rs,w3 // word-align source ptr + stw w1,0(rd) // store all (w3) bytes at once to avoid a loop + add rd,rd,w3 + mr w1,w2 // first aligned word to w1 + b 2f + + .align 4 // align inner loops +1: // loop over 16-byte chunks + lwz w1,0(rs) +2: + lwz w2,4(rs) + lwz w3,8(rs) + lwz w4,12(rs) + addi rs,rs,16 + stw w1,0(rd) + stw w2,4(rd) + stw w3,8(rd) + stw w4,12(rd) + addi rd,rd,16 + bdnz 1b + + b LShort16 + + +// Medium, doubleword aligned. We use floating point. Note that G4+ has bigger latencies +// and reduced throughput for floating pt loads and stores; future processors will probably +// have even worse lfd/stfd performance. We use it here because it is so important for G3, +// and not slower for G4+. But we only do so for doubleword aligned operands, whereas the +// G3-only long operand loops use floating pt even for word-aligned operands. +// w2 = neg(rs) +// w1 = first 4 bytes of source + +LMediumAligned: + andi. w3,w2,7 // already aligned? + sub rc,rc,w3 // adjust count by 0-7 bytes + lfdx f0,rs,w3 // pre-fetch first aligned source doubleword + srwi w4,rc,5 // get count of 32-byte chunks (might be 0 if unaligned) + mtctr w4 + beq- LForwardFloatLoop1 // already aligned + + cmpwi w4,0 // are there any 32-byte chunks to xfer? + lwz w2,4(rs) // get 2nd (unaligned) source word + add rs,rs,w3 // doubleword align source pointer + stw w1,0(rd) // store first 8 bytes of source to align... + stw w2,4(rd) // ...which could overwrite source + add rd,rd,w3 // doubleword align destination + bne+ LForwardFloatLoop1 // at least 1 chunk, so enter loop + + subi rc,rc,8 // unfortunate degenerate case: no chunks to xfer + stfd f0,0(rd) // must store f1 since source might have been overwriten + addi rs,rs,8 + addi rd,rd,8 + b LShort + + +// Medium reverse moves. This loop runs on all processors. + +LMediumReverse: + add rs,rs,rc // point to other end of operands when in reverse + add rd,rd,rc + andi. w3,rs,3 // w3 <- #bytes to word align source + lwz w1,-4(rs) // pre-fetch 1st 4 bytes of source + sub rc,rc,w3 // adjust count + srwi w4,rc,4 // get count of 16-byte chunks (>=1) + mtcrf 0x01,rc // remaining byte count (0-15) to cr7 for LShortReverse16 + mtctr w4 // prepare loop count + beq+ 2f // source already aligned + + sub rs,rs,w3 // word-align source ptr + lwz w2,-4(rs) // get 1st aligned word which we may overwrite + stw w1,-4(rd) // store all 4 bytes to align without a loop + sub rd,rd,w3 + mr w1,w2 // shift 1st aligned source word to w1 + b 2f + +1: + lwz w1,-4(rs) +2: + lwz w2,-8(rs) + lwz w3,-12(rs) + lwzu w4,-16(rs) + stw w1,-4(rd) + stw w2,-8(rd) + stw w3,-12(rd) + stwu w4,-16(rd) + bdnz 1b + + b LShortReverse16 + + +// Long operands. Use branch table to decide which loop to use. +// w1 = (rd-rs), used to determine alignment + +LLong: + xor w4,w1,rc // we must move reverse if (rd-rs)=1) + mtctr r0 // prepare loop count + beq+ 1f // dest already aligned + + lwz w2,0(rs) // get first 4 bytes of source + lwzx w1,w3,rs // get source bytes we might overwrite + add rs,rs,w3 // adjust source ptr + stw w2,0(rd) // store all 4 bytes to avoid a loop + add rd,rd,w3 // word-align destination + b 2f +1: + lwz w1,0(rs) +2: + lwz w2,4(rs) + lwz w3,8(rs) + lwz w4,12(rs) + lwz w5,16(rs) + lwz w6,20(rs) + lwz w7,24(rs) + lwz w8,28(rs) + addi rs,rs,32 + stw w1,0(rd) + stw w2,4(rd) + stw w3,8(rd) + stw w4,12(rd) + stw w5,16(rd) + stw w6,20(rd) + stw w7,24(rd) + stw w8,28(rd) + addi rd,rd,32 + bdnz 1b + + b LShort + + +// G3, forward, long, word aligned. We use floating pt even when only word aligned. +// w1 = neg(rd) + +LForwardFloat: + andi. w3,w1,7 // W3 <- #bytes to doubleword-align destination + mtlr ra // restore return address + sub rc,rc,w3 // adjust count for alignment + srwi r0,rc,5 // number of 32-byte chunks to xfer (>=1) + mtctr r0 // prepare loop count + beq LForwardFloatLoop // dest already aligned + + lwz w1,0(rs) // get first 8 bytes of source + lwz w2,4(rs) + lfdx f0,w3,rs // get source bytes we might overwrite + add rs,rs,w3 // word-align source ptr + stw w1,0(rd) // store all 8 bytes to avoid a loop + stw w2,4(rd) + add rd,rd,w3 + b LForwardFloatLoop1 + + .align 4 // align since this loop is executed by G4s too +LForwardFloatLoop: + lfd f0,0(rs) +LForwardFloatLoop1: // enter here from LMediumAligned and above + lfd f1,8(rs) + lfd f2,16(rs) + lfd f3,24(rs) + addi rs,rs,32 + stfd f0,0(rd) + stfd f1,8(rd) + stfd f2,16(rd) + stfd f3,24(rd) + addi rd,rd,32 + bdnz LForwardFloatLoop + + b LShort + + +// G4 Forward, long, 16-byte aligned, 32-byte cache ops, use DCBA and DCBT. +// r0/cr0 = #bytes to 32-byte align + +LForwardVecAlig32Dcba: + bnel+ LAlign32 // align destination iff necessary + bl LPrepareForwardVectors + mtlr ra // restore return address before loading c128 + li c128,128 + b 1f // enter aligned loop + + .align 5 // long loop heads should be at least 16-byte aligned +1: // loop over aligned 64-byte chunks + dcbt c96,rs // pre-fetch three cache lines ahead + dcbt c128,rs // and four + lvx v1,0,rs + lvx v2,c16,rs + lvx v3,c32,rs + lvx v4,c48,rs + addi rs,rs,64 + dcba 0,rd // avoid read of destination cache lines + stvx v1,0,rd + stvx v2,c16,rd + dcba c32,rd + stvx v3,c32,rd + stvx v4,c48,rd + addi rd,rd,64 + bdnz 1b + +LForwardVectorAlignedEnd: // r0/cr0=#quadwords, rv=VRSave, cr7=low 4 bits of rc, cr6 set on cr7 + beq- 3f // no leftover quadwords + mtctr r0 +2: // loop over remaining quadwords (1-7) + lvx v1,0,rs + addi rs,rs,16 + stvx v1,0,rd + addi rd,rd,16 + bdnz 2b +3: + mtspr VRSave,rv // restore bitmap of live vr's + bne cr6,LShort16 // handle last 0-15 bytes if any + blr + + +// G4 Forward, long, 16-byte aligned, 32-byte cache, use DCBT but not DCBA. +// r0/cr0 = #bytes to 32-byte align + +LForwardVecAlig32NoDcba: + bnel+ LAlign32 // align destination iff necessary + bl LPrepareForwardVectors + mtlr ra // restore return address before loading c128 + li c128,128 + b 1f // enter aligned loop + + .align 4 // balance 13-word loop between QWs... + nop // ...which improves performance 5% +/- + nop +1: // loop over aligned 64-byte chunks + dcbt c96,rs // pre-fetch three cache lines ahead + dcbt c128,rs // and four + lvx v1,0,rs + lvx v2,c16,rs + lvx v3,c32,rs + lvx v4,c48,rs + addi rs,rs,64 + stvx v1,0,rd + stvx v2,c16,rd + stvx v3,c32,rd + stvx v4,c48,rd + addi rd,rd,64 + bdnz 1b + + b LForwardVectorAlignedEnd + + +// G4 Forward, long, unaligned, 32-byte cache ops, use DCBT and DCBA. At least on +// some CPUs, this routine is no slower than the simpler aligned version that does +// not use permutes. But it cannot be used with aligned operands, because of the +// way it prefetches source QWs. +// r0/cr0 = #bytes to 32-byte align + +LForwardVecUnal32Dcba: + bnel+ LAlign32 // align destination iff necessary + bl LPrepareForwardVectors + lvx v1,0,rs // prime loop + mtlr ra // restore return address before loading c128 + lvsl vp,0,rs // get permute vector to shift left + li c128,128 + b 1f // enter aligned loop + + .align 4 // long loop heads should be at least 16-byte aligned +1: // loop over aligned 64-byte destination chunks + lvx v2,c16,rs + dcbt c96,rs // touch 3rd cache line ahead + lvx v3,c32,rs + dcbt c128,rs // touch 4th cache line ahead + lvx v4,c48,rs + addi rs,rs,64 + vperm vx,v1,v2,vp + lvx v1,0,rs + vperm vy,v2,v3,vp + dcba 0,rd // avoid read of destination lines + stvx vx,0,rd + vperm vz,v3,v4,vp + stvx vy,c16,rd + dcba c32,rd + vperm vx,v4,v1,vp + stvx vz,c32,rd + stvx vx,c48,rd + addi rd,rd,64 + bdnz 1b + +LForwardVectorUnalignedEnd: // r0/cr0=#QWs, rv=VRSave, v1=next QW, cr7=(rc & F), cr6 set on cr7 + beq- 3f // no leftover quadwords + mtctr r0 +2: // loop over remaining quadwords + lvx v2,c16,rs + addi rs,rs,16 + vperm vx,v1,v2,vp + vor v1,v2,v2 // v1 <- v2 + stvx vx,0,rd + addi rd,rd,16 + bdnz 2b +3: + mtspr VRSave,rv // restore bitmap of live vr's + bne cr6,LShort16 // handle last 0-15 bytes if any + blr + + +// G4 Forward, long, unaligned, 32-byte cache ops, use DCBT but not DCBA. +// r0/cr0 = #bytes to 32-byte align + +LForwardVecUnal32NoDcba: + bnel+ LAlign32 // align destination iff necessary + bl LPrepareForwardVectors + lvx v1,0,rs // prime loop + mtlr ra // restore return address before loading c128 + lvsl vp,0,rs // get permute vector to shift left + li c128,128 + b 1f // enter aligned loop + + .align 4 + nop // balance 17-word loop between QWs + nop +1: // loop over aligned 64-byte destination chunks + lvx v2,c16,rs + dcbt c96,rs // touch 3rd cache line ahead + lvx v3,c32,rs + dcbt c128,rs // touch 4th cache line ahead + lvx v4,c48,rs + addi rs,rs,64 + vperm vx,v1,v2,vp + lvx v1,0,rs + vperm vy,v2,v3,vp + stvx vx,0,rd + vperm vz,v3,v4,vp + stvx vy,c16,rd + vperm vx,v4,v1,vp + stvx vz,c32,rd + stvx vx,c48,rd + addi rd,rd,64 + bdnz 1b + + b LForwardVectorUnalignedEnd + + +// G3 Reverse, long, unaligned. + +LReverseWord: + bl LAlign8Reverse // 8-byte align destination + mtlr ra // restore return address + srwi r0,rc,5 // get count of 32-byte chunks to xfer (> 1) + mtctr r0 +1: + lwz w1,-4(rs) + lwz w2,-8(rs) + lwz w3,-12(rs) + lwz w4,-16(rs) + stw w1,-4(rd) + lwz w5,-20(rs) + stw w2,-8(rd) + lwz w6,-24(rs) + stw w3,-12(rd) + lwz w7,-28(rs) + stw w4,-16(rd) + lwzu w8,-32(rs) + stw w5,-20(rd) + stw w6,-24(rd) + stw w7,-28(rd) + stwu w8,-32(rd) + bdnz 1b + + b LShortReverse + + +// G3 Reverse, long, word aligned. + +LReverseFloat: + bl LAlign8Reverse // 8-byte align + mtlr ra // restore return address + srwi r0,rc,5 // get count of 32-byte chunks to xfer (> 1) + mtctr r0 +1: + lfd f0,-8(rs) + lfd f1,-16(rs) + lfd f2,-24(rs) + lfdu f3,-32(rs) + stfd f0,-8(rd) + stfd f1,-16(rd) + stfd f2,-24(rd) + stfdu f3,-32(rd) + bdnz 1b + + b LShortReverse + + +// G4 Reverse, long, 16-byte aligned, 32-byte DCBT but no DCBA. + +LReverseVectorAligned32: + bl LAlign32Reverse // 32-byte align destination iff necessary + bl LPrepareReverseVectors + mtlr ra // restore return address before loading cm129 + li cm129,-129 + b 1f // enter aligned loop + + .align 4 + nop // must start in 3rd word of QW... + nop // ...to keep balanced +1: // loop over aligned 64-byte chunks + dcbt cm97,rs // pre-fetch three cache lines ahead + dcbt cm129,rs // and four + lvx v1,cm1,rs + lvx v2,cm17,rs + lvx v3,cm33,rs + lvx v4,cm49,rs + subi rs,rs,64 + stvx v1,cm1,rd + stvx v2,cm17,rd + stvx v3,cm33,rd + stvx v4,cm49,rd + subi rd,rd,64 + bdnz 1b + +LReverseVectorAlignedEnd: // cr0/r0=#quadwords, rv=VRSave, cr7=low 4 bits of rc, cr6 set on cr7 + beq 3f // no leftover quadwords + mtctr r0 +2: // loop over 1-3 quadwords + lvx v1,cm1,rs + subi rs,rs,16 + stvx v1,cm1,rd + subi rd,rd,16 + bdnz 2b +3: + mtspr VRSave,rv // restore bitmap of live vr's + bne cr6,LShortReverse16 // handle last 0-15 bytes iff any + blr + + +// G4 Reverse, long, unaligned, 32-byte DCBT. + +LReverseVectorUnal32: + bl LAlign32Reverse // align destination iff necessary + bl LPrepareReverseVectors + lvx v1,cm1,rs // prime loop + mtlr ra // restore return address before loading cm129 + lvsl vp,0,rs // get permute vector to shift left + li cm129,-129 + b 1f // enter aligned loop + + .align 4 + nop // start loop in 3rd word on QW to balance + nop +1: // loop over aligned 64-byte destination chunks + lvx v2,cm17,rs + dcbt cm97,rs // touch in 3rd source block + lvx v3,cm33,rs + dcbt cm129,rs // touch in 4th + lvx v4,cm49,rs + subi rs,rs,64 + vperm vx,v2,v1,vp + lvx v1,cm1,rs + vperm vy,v3,v2,vp + stvx vx,cm1,rd + vperm vz,v4,v3,vp + stvx vy,cm17,rd + vperm vx,v1,v4,vp + stvx vz,cm33,rd + stvx vx,cm49,rd + subi rd,rd,64 + bdnz 1b + +LReverseVectorUnalignedEnd: // r0/cr0=#QWs, rv=VRSave, v1=source QW, cr7=low 4 bits of rc, cr6 set on cr7 + beq 3f // no leftover quadwords + mtctr r0 +2: // loop over 1-3 quadwords + lvx v2,cm17,rs + subi rs,rs,16 + vperm vx,v2,v1,vp + vor v1,v2,v2 // v1 <- v2 + stvx vx,cm1,rd + subi rd,rd,16 + bdnz 2b +3: + mtspr VRSave,rv // restore bitmap of live vr's + bne cr6,LShortReverse16 // handle last 0-15 bytes iff any + blr + + +// Subroutine to prepare for 64-byte forward vector loops. +// Returns many things: +// ctr = number of 64-byte chunks to move +// r0/cr0 = leftover QWs to move +// cr7 = low 4 bits of rc (ie, leftover byte count 0-15) +// cr6 = beq if leftover byte count is 0 +// c16..c96 loaded +// rv = original value of VRSave +// NB: c128 not set (if needed), since it is still "ra" + +LPrepareForwardVectors: + mfspr rv,VRSave // get bitmap of live vector registers + srwi r0,rc,6 // get count of 64-byte chunks to move (>=1) + oris w1,rv,0xFF00 // we use v0-v7 + mtcrf 0x01,rc // prepare for moving last 0-15 bytes in LShort16 + rlwinm w3,rc,0,28,31 // move last 0-15 byte count to w3 too + mtspr VRSave,w1 // update mask + li c16,16 // get constants used in ldvx/stvx + li c32,32 + mtctr r0 // set up loop count + cmpwi cr6,w3,0 // set cr6 on leftover byte count + li c48,48 + li c96,96 + rlwinm. r0,rc,28,30,31 // get number of quadword leftovers (0-3) and set cr0 + blr + + +// Subroutine to prepare for 64-byte reverse vector loops. +// Returns many things: +// ctr = number of 64-byte chunks to move +// r0/cr0 = leftover QWs to move +// cr7 = low 4 bits of rc (ie, leftover byte count 0-15) +// cr6 = beq if leftover byte count is 0 +// cm1..cm97 loaded +// rv = original value of VRSave +// NB: cm129 not set (if needed), since it is still "ra" + +LPrepareReverseVectors: + mfspr rv,VRSave // get bitmap of live vector registers + srwi r0,rc,6 // get count of 64-byte chunks to move (>=1) + oris w1,rv,0xFF00 // we use v0-v7 + mtcrf 0x01,rc // prepare for moving last 0-15 bytes in LShortReverse16 + rlwinm w3,rc,0,28,31 // move last 0-15 byte count to w3 too + mtspr VRSave,w1 // update mask + li cm1,-1 // get constants used in ldvx/stvx + li cm17,-17 + mtctr r0 // set up loop count + cmpwi cr6,w3,0 // set cr6 on leftover byte count + li cm33,-33 + li cm49,-49 + rlwinm. r0,rc,28,30,31 // get number of quadword leftovers (0-3) and set cr0 + li cm97,-97 + blr + + +// Subroutine to align destination on a 32-byte boundary. +// r0 = number of bytes to xfer (0-31) + +LAlign32: + mtcrf 0x01,r0 // length to cr (faster to change 1 CR at a time) + mtcrf 0x02,r0 + sub rc,rc,r0 // adjust length + bf 31,1f // skip if no odd bit + lbz w1,0(rs) + addi rs,rs,1 + stb w1,0(rd) + addi rd,rd,1 +1: + bf 30,2f // halfword to move? + lhz w1,0(rs) + addi rs,rs,2 + sth w1,0(rd) + addi rd,rd,2 +2: + bf 29,3f // word? + lwz w1,0(rs) + addi rs,rs,4 + stw w1,0(rd) + addi rd,rd,4 +3: + bf 28,4f // doubleword? + lwz w1,0(rs) + lwz w2,4(rs) + addi rs,rs,8 + stw w1,0(rd) + stw w2,4(rd) + addi rd,rd,8 +4: + bflr 27 // done if no quadword to move + lwz w1,0(rs) + lwz w2,4(rs) + lwz w3,8(rs) + lwz w4,12(rs) + addi rs,rs,16 + stw w1,0(rd) + stw w2,4(rd) + stw w3,8(rd) + stw w4,12(rd) + addi rd,rd,16 + blr + +// Subroutine to align destination if necessary on a 32-byte boundary for reverse moves. +// rs and rd still point to low end of operands +// we adjust rs and rd to point to last byte moved + +LAlign32Reverse: + add rd,rd,rc // point to last byte moved (ie, 1 past end of operands) + add rs,rs,rc + andi. r0,rd,0x1F // r0 <- #bytes that must be moved to align destination + mtcrf 0x01,r0 // length to cr (faster to change 1 CR at a time) + mtcrf 0x02,r0 + sub rc,rc,r0 // update length + beqlr- // destination already 32-byte aligned + + bf 31,1f // odd byte? + lbzu w1,-1(rs) + stbu w1,-1(rd) +1: + bf 30,2f // halfword to move? + lhzu w1,-2(rs) + sthu w1,-2(rd) +2: + bf 29,3f // word? + lwzu w1,-4(rs) + stwu w1,-4(rd) +3: + bf 28,4f // doubleword? + lwz w1,-4(rs) + lwzu w2,-8(rs) + stw w1,-4(rd) + stwu w2,-8(rd +4: + bflr 27 // done if no quadwords + lwz w1,-4(rs) + lwz w2,-8(rs) + lwz w3,-12(rs) + lwzu w4,-16(rs) + stw w1,-4(rd) + stw w2,-8(rd) + stw w3,-12(rd) + stwu w4,-16(rd) + blr + + +// Subroutine to align destination on an 8-byte boundary for reverse moves. +// rs and rd still point to low end of operands +// we adjust rs and rd to point to last byte moved + +LAlign8Reverse: + add rd,rd,rc // point to last byte moved (ie, 1 past end of operands) + add rs,rs,rc + andi. r0,rd,0x7 // r0 <- #bytes that must be moved to align destination + beqlr- // destination already 8-byte aligned + mtctr r0 // set up for loop + sub rc,rc,r0 // update length +1: + lbzu w1,-1(rs) + stbu w1,-1(rd) + bdnz 1b + + blr + + +// Called by pthread initialization to set up the branch table pointer based on +// the CPU capability vector. This routine may be called more than once (for +// example, during testing.) + +// Size of the buffer we use to do DCBA timing on G4: +#define kBufSiz 1024 + +// Stack frame size, which contains the 128-byte-aligned buffer: +#define kSFSize (kBufSiz+128+16) + +// Iterations of the timing loop: +#define kLoopCnt 5 + +// Bit in cr5 used as a flag in timing loop: +#define kDCBA 22 + +__bcopy_initialize: // int _bcopy_initialize(void) + mflr ra // get return + stw ra,8(r1) // save + stwu r1,-kSFSize(r1) // carve our temp buffer from the stack + addi w6,r1,127+16 // get base address... + rlwinm w6,w6,0,0,24 // ...of our buffer, 128-byte aligned + bcl 20,31,1f // get our PIC base +1: + mflr w1 + addis w2,w1,ha16(__cpu_capabilities - 1b) + lwz w3,lo16(__cpu_capabilities - 1b)(w2) + andi. r0,w3,kUseDcba+kNoDcba+kCache32+k64Bit+kHasAltivec + cmpwi r0,kCache32+kHasAltivec // untyped G4? + li w8,0 // assume no need to test + bne 2f // not an untyped G4, so do not test + + // G4, but neither kUseDcba or kNoDcba are set. Time and select fastest. + + crset kDCBA // first, use DCBA + bl LTest32 // time it + mr w8,w4 // w8 <- best time using DCBA + srwi r0,w8,3 // bias 12 pct in favor of not using DCBA... + add w8,w8,r0 // ...because DCBA is always slower with warm cache + crclr kDCBA + bl LTest32 // w4 <- best time without DCBA + cmplw w8,w4 // which is better? + li w8,kUseDcba // assume using DCBA is faster + blt 2f + li w8,kNoDcba // no DCBA is faster + + // What branch table to use? + +2: // here with w8 = 0, kUseDcba, or kNoDcba + bcl 20,31,4f // get our PIC base again +4: + mflr w1 + addis w2,w1,ha16(__cpu_capabilities - 4b) + lwz w3,lo16(__cpu_capabilities - 4b)(w2) + or w3,w3,w8 // add in kUseDcba or kNoDcba if untyped G4 + mr r3,w8 // return dynamic selection, if any (used in testing) + + andi. r0,w3,kHasAltivec+k64Bit+kCache128+kCache64+kCache32+kUseDcba+kNoDcba + cmpwi r0,kHasAltivec+kCache32+kUseDcba // G4 with DCBA? + addis w4,w1,ha16(LG4UseDcba - 4b) + addi w4,w4,lo16(LG4UseDcba - 4b) + beq 5f + + andi. r0,w3,kHasAltivec+k64Bit+kCache128+kCache64+kCache32+kUseDcba+kNoDcba + cmpwi r0,kHasAltivec+kCache32+kNoDcba // G4 without DCBA? + addis w4,w1,ha16(LG4NoDcba - 4b) + addi w4,w4,lo16(LG4NoDcba - 4b) + beq 5f + + andi. r0,w3,kHasAltivec+k64Bit+kCache128+kCache64+kCache32 + cmpwi r0,kCache32 // G3? + addis w4,w1,ha16(LG3 - 4b) + addi w4,w4,lo16(LG3 - 4b) + beq 5f + + // Map unrecognized CPU types to G3 (lowest common denominator) + +5: // w4 <- branch table pointer + addis w5,w1,ha16(LBranchTablePtr - 4b) + stw w4,lo16(LBranchTablePtr - 4b)(w5) + lwz ra,kSFSize+8(r1) // recover return address + mtlr ra // restore it + lwz r1,0(r1) // pop off our stack frame + blr // return dynamic selection (or 0) in r3 + + +// Subroutine to time a 32-byte cache. +// kDCBA = set if we should use DCBA +// w6 = base of buffer to use for test (kBufSiz bytes) +// w4 = we return time of fastest loop in w4 + +LTest32: + li w1,kLoopCnt // number of times to loop + li w4,-1 // initialize fastest time +1: + mr rd,w6 // initialize buffer ptr + li r0,kBufSiz/32 // r0 <- cache blocks to test + mtctr r0 +2: + dcbf 0,rd // first, force the blocks out of the cache + addi rd,rd,32 + bdnz 2b + sync // make sure all the flushes take + mr rd,w6 // re-initialize buffer ptr + mtctr r0 // reset cache-block count + mftbu w5 // remember upper half so we can check for carry + mftb w2 // start the timer +3: // loop over cache blocks + bf kDCBA,4f // should we DCBA? + dcba 0,rd +4: + stfd f1,0(rd) // store the entire cache block + stfd f1,8(rd) + stfd f1,16(rd) + stfd f1,24(rd) + addi rd,rd,32 + bdnz 3b + mftb w3 + mftbu r0 + cmpw r0,w5 // did timebase carry? + bne 1b // yes, retest rather than fuss + sub w3,w3,w2 // w3 <- time for this loop + cmplw w3,w4 // faster than current best? + bge 5f // no + mr w4,w3 // remember fastest time through loop +5: + subi w1,w1,1 // decrement outer loop count + cmpwi w1,0 // more to go? + bne 1b // loop if so + blr + \ No newline at end of file diff --git a/ppc/gen/bzero.s b/ppc/gen/bzero.s new file mode 100644 index 0000000..bb313e9 --- /dev/null +++ b/ppc/gen/bzero.s @@ -0,0 +1,202 @@ +/* + * Copyright (c) 2000 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@ + */ +// +// ============================= +// BZERO and MEMSET FOR Mac OS X +// ============================= +// +// We use DCBZ, and therefore are dependent on the cache block size (32.) +// Bzero and memset need to be in the same file since they are tightly +// coupled, so we can use bzero for memset of 0 without incurring extra +// overhead. (The issue is that bzero must preserve r3 for memset.) +// +// 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 + +#include + + .text + .align 5 + .globl _bzero + .globl _memset + +// ************* +// * B Z E R O * +// ************* + +_bzero: // void bzero(void *b, size_t len); + cmplwi cr1,rc,32 // too short for DCBZ? + li rv,0 // get a 0 +Lbzero1: // enter from memset with cr1 and rv set up + neg r5,r3 // start to compute bytes to align + mr rp,r3 // make copy of operand ptr + andi. r6,r5,0x1F // r6 <- bytes to align on cache block + blt- cr1,Ltail // <32, so skip DCBZs + beq- cr0,Ldcbz // already aligned + + // align on 32-byte boundary + + mtcrf 0x01,r6 // move length to cr7 (faster if only 1 cr) + andi. r7,r6,16 // test bit 27 by hand + sub rc,rc,r6 // adjust length + bf 31,1f // test bits of count + stb rv,0(rp) + addi rp,rp,1 +1: + bf 30,2f + sth rv,0(rp) + addi rp,rp,2 +2: + bf 29,3f + stw rv,0(rp) + addi rp,rp,4 +3: + bf 28,4f + stw rv,0(rp) + stw rv,4(rp) + addi rp,rp,8 +4: + beq Ldcbz + stw rv,0(rp) + stw rv,4(rp) + stw rv,8(rp) + stw rv,12(rp) + addi rp,rp,16 + + // DCBZ 32-byte cache blocks +Ldcbz: + srwi. r5,rc,5 // r5 <- number of cache blocks to zero + beq Ltail // none + mtctr r5 // set up loop count + andi. rc,rc,0x1F // will there be leftovers? +1: + dcbz 0,rp // zero 32 bytes + addi rp,rp,32 + bdnz 1b + beqlr // no leftovers so done + + // store up to 31 trailing bytes + // 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 + + +// *************** +// * M E M S E T * +// *************** + + .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 + cmplwi cr1,r5,32 // length < 32 ? + beq Lbzero1 // memset of 0 is just a 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 (faster if only 1 cr) + 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) + srwi 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 diff --git a/ppc/gen/ecvt.c b/ppc/gen/ecvt.c new file mode 100644 index 0000000..1146030 --- /dev/null +++ b/ppc/gen/ecvt.c @@ -0,0 +1,237 @@ +/* + * Copyright (c) 1999 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@ + */ +/* 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 + +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 + */ + diff --git a/ppc/gen/ffs.s b/ppc/gen/ffs.s new file mode 100644 index 0000000..bb4963a --- /dev/null +++ b/ppc/gen/ffs.s @@ -0,0 +1,49 @@ +/* + * Copyright (c) 1999 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@ + */ +/* Copyright (c) 1992, 1997 NeXT Software, Inc. All rights reserved. + * + * File: libc/gen/ppc/ffs.s + * + * Find the first bit set (starting with the least significant bit). + * + * HISTORY + * + * 24-Jan-1997 Umesh Vaishampayan (umeshv@NeXT.com) + * Ported to PPC. + * + * 19-Jan-1998 Matt Watson (mwatson@apple.com) + * Simplified + * + * 10-Mar-1998 Matt Watson (mwatson@apple.com) + * Correctified + * + */ + +.text +.align 2 +.globl _ffs +_ffs: + neg r0,r3 + and r3,r0,r3 + cntlzw r3,r3 + subfic r3,r3,32 + blr diff --git a/ppc/gen/fp.h b/ppc/gen/fp.h new file mode 100644 index 0000000..0934658 --- /dev/null +++ b/ppc/gen/fp.h @@ -0,0 +1,62 @@ +/* + * Copyright (c) 1999 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@ + */ +/* Copyright (c) 1992, NeXT Computer, Inc. All rights reserved. + * + * File: libc/m98k/gen/fp.h + * Author: Derek B Clegg, NeXT Computer, Inc. + * + * HISTORY + * 11-Nov-92 Derek B Clegg (dclegg@next.com) + * Created. + * + * Common definitions for floating-point numbers. + */ + +/* The following definitions for for double precision IEEE format numbers. */ + +#define EXPONENT_BIAS 1023 + +#define SIGN_BITS 1 +#define EXPONENT_BITS 11 +#define FRACTION_BITS 52 +#define HI_FRACTION_BITS 20 +#define LO_FRACTION_BITS 32 + +struct double_format { + unsigned sign: SIGN_BITS; + unsigned exponent: EXPONENT_BITS; + unsigned hi_fraction: HI_FRACTION_BITS; + unsigned lo_fraction: LO_FRACTION_BITS; +}; + +union dbl { + struct double_format s; + unsigned int u[2]; + double value; +}; + +#define PlusInfinity (1.0/0.0) +#define MinusInfinity (-1.0/0.0) + +#define not_a_number(x) ((x) != (x)) +#define positive_infinity(x) ((x) == PlusInfinity) +#define negative_infinity(x) ((x) == MinusInfinity) diff --git a/ppc/gen/genassym.c b/ppc/gen/genassym.c new file mode 100644 index 0000000..ca608b1 --- /dev/null +++ b/ppc/gen/genassym.c @@ -0,0 +1,205 @@ +/* + * Copyright (c) 1999 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@ + */ +#import +#import +#import +#import + +#import "genassym.h" + +#define NAME_LEN 30 + +char *progname; + +unsigned bit_num(char *reg_type, char *field, unsigned bits) +{ + unsigned bit; + unsigned mask; + + for (bit = 0, mask = 0x1; + (mask & bits) == 0 && mask; + mask <<= 1, bit += 1) + continue; + if (mask) + return bit; + fprintf(stderr, "%s: Bad BIT_POS for %s.%s\n", progname, + reg_type, field); + exit(1); +} + +unsigned field_width(char *reg_type, char *field, unsigned bits) +{ + unsigned width; + + while (bits && (bits & 0x1) == 0) + bits >>= 1; + for (width = 0; (bits & 0x1) == 1; bits >>= 1, width += 1) + continue; + if (bits == 0 && width) + return width; + fprintf(stderr, "%s: Bad BIT_FIELD for %s.%s\n", progname, + reg_type, field); + exit(1); +} + +unsigned log2(unsigned val, char *type) +{ + unsigned l2 = 0; + + if (val == 0) { + fprintf(stderr, "log2: sizeof(%s) is zero!\n", type); + exit(1); + } + while ((val & 0x1) == 0) { + l2 += 1; + val >>= 1; + } + if (val != 0x1) { + fprintf(stderr, "log2: sizeof(%s) is not power of two!\n", + type); + exit(1); + } + return l2; +} + +const char *skip_white(const char *cp) +{ + while (*cp && isspace(*cp)) + cp += 1; + return cp; +} + +const char *strip_prefix(const char *cp, const char *prefix) +{ + int len; + + cp = skip_white(cp); + len = strlen(prefix); + if (strncmp(cp, prefix, len) == 0 && isspace(*(cp+len))) + cp += len; + return cp; +} + +void +print_define(const char *prefix, const char *type_name, const char *field) +{ + const char *cp; + int col = 0; + + printf("#define\t"); + if (prefix != NULL && *prefix != '\0') { + printf("%s", prefix); + col += strlen(prefix); + } + if (type_name != NULL && *type_name != '\0') { + cp = strip_prefix(type_name, "struct"); + cp = strip_prefix(cp, "enum"); + cp = skip_white(cp); + if (*cp != '\0' && col != 0) { + putchar('_'); + col += 1; + } + for (; *cp != '\0'; cp++) { + if (isspace(*cp)) + break; + if (*cp == '*') + break; + if (strncmp(cp, "_t", 2) == 0 && !isalnum(cp[2])) + break; + putchar(isalpha(*cp) ? toupper(*cp) : *cp); + col += 1; + + } + } + if (field != NULL && *field != '\0') { + if (col != 0) { + putchar('_'); + col++; + } + for (cp = field; *cp != 0; cp++) { + if (*cp == '.') + putchar('_'); + else if (*cp == '[') + putchar('_'); + else if (*cp == ']') + continue; + else if (!isspace(*cp)) + putchar(isalpha(*cp) ? toupper(*cp) : *cp); + col++; + } + } + if (col == 0) { + fprintf(stderr, "%s: Bad call to print_define\n", progname); + exit(1); + } + do { + putchar(' '); + col += 1; + } while (col < NAME_LEN); +} + +void print_dec(int val) +{ + printf("%d\n", val); +} + +void print_hex(unsigned val) +{ + printf("%#010x\n", val); +} + +void print_str(const char *str) +{ + printf("%s\n", str); +} + +void comment(cmt_level_t level, const char *cmt) +{ + switch (level) { + case MAJOR: + printf("\n\n"); + printf("/*\n"); + printf(" * %s\n", cmt); + printf(" */\n"); + break; + case MINOR: + printf("\n"); + printf("/* %s */\n", cmt); + printf("\n"); + break; + default: + fprintf(stderr, "%s: Bad comment level\n", progname); + exit(1); + } +} + +void main(int argc, char **argv) +{ + progname = argv[0]; + + printf("/* assym.h -- generated by genassym */\n"); + printf("/* DON'T EDIT THIS -- change assymdefs.c */\n"); + + assymdefs(); + + exit(0); +} diff --git a/ppc/gen/genassym.h b/ppc/gen/genassym.h new file mode 100644 index 0000000..729dfa9 --- /dev/null +++ b/ppc/gen/genassym.h @@ -0,0 +1,126 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * genassym.h -- macros of use with genassym.c and assymdefs.c + */ + +#import +#import + +#define PRINT_OFFSET(ptr_type, field) \ +MACRO_BEGIN \ + print_define("", #ptr_type, #field); \ + print_hex((unsigned) &(((ptr_type)0)->field)); \ +MACRO_END + +#define PRINT_BIT_FIELD(reg_type, field) \ +MACRO_BEGIN \ + reg_type __reg; \ + CONTENTS(__reg) = 0; \ + __reg.field = (typeof (__reg.field)) -1; \ + print_define("", #reg_type, #field); \ + print_hex(CONTENTS(__reg)); \ +MACRO_END + +#define PRINT_ENUM(item) \ +MACRO_BEGIN \ + print_define("", "", #item); \ + print_hex((unsigned)item); \ +MACRO_END + +#define PRINT_DEFINE(macro) \ +MACRO_BEGIN \ + print_define("", "", #macro); \ + print_str(STRINGIFY(macro)); \ +MACRO_END + +#define PRINT_CONSTANT(macro) \ +MACRO_BEGIN \ + print_define("", "", #macro); \ + print_hex((unsigned)macro); \ +MACRO_END + +#define PRINT_REGADDR(macro) \ +MACRO_BEGIN \ + print_define("", "", #macro); \ + print_hex((unsigned) ¯o); \ +MACRO_END + +#define PRINT_REG_PAIR(struct_ptr, name0, name1) \ +MACRO_BEGIN \ + print_define("", #struct_ptr, #name0 "_" #name1); \ + print_hex((unsigned) &(((struct_ptr)0)->U_##name0##_##name1)); \ +MACRO_END + +#define PRINT_BIT_POS(reg_type, field) \ +MACRO_BEGIN \ + reg_type __reg; \ + CONTENTS(__reg) = 0; \ + __reg.field = 1; \ + print_define("", #reg_type, #field "_BIT"); \ + print_dec((int) bit_num(#reg_type, #field, CONTENTS(__reg))); \ +MACRO_END + +#define PRINT_FIELD_INFO(reg_type, field) \ +MACRO_BEGIN \ + reg_type __reg; \ + CONTENTS(__reg) = 0; \ + __reg.field = -1; \ + print_define("", #reg_type, #field "_OFF"); \ + print_dec((int) bit_num(#reg_type, #field, CONTENTS(__reg))); \ + print_define("", #reg_type, #field "_WIDTH"); \ + print_dec((int) field_width(#reg_type, #field, CONTENTS(__reg)));\ +MACRO_END + +#define PRINT_L2_SIZE(type) \ +MACRO_BEGIN \ + print_define("L2_SIZEOF", #type, ""); \ + print_dec((int) log2(sizeof(type), #type)); \ +MACRO_END + +#define PRINT_SIZEOF(type) \ +MACRO_BEGIN \ + print_define("SIZEOF", #type, ""); \ + print_dec((int) sizeof(type)); \ +MACRO_END + +#define PRINT_L2_CONSTANT(macro) \ +MACRO_BEGIN \ + print_define("L2", "", #macro); \ + print_dec((int) log2(macro, #macro)); \ +MACRO_END + +typedef enum { + MAJOR, MINOR +} cmt_level_t; + +extern void comment(cmt_level_t level, const char *cmt); +extern void print_define(const char *prefix, const char *type_name, + const char *field); +extern void print_dec(int val); +extern void print_hex(unsigned val); +extern void print_str(const char *str); +extern unsigned bit_num(char *reg_type, char *field, unsigned bits); +extern unsigned field_width(char *reg_type, char *field, unsigned bits); +extern unsigned log2(unsigned val, char *type); +extern void assymdefs(void); + diff --git a/ppc/gen/insque.c b/ppc/gen/insque.c new file mode 100644 index 0000000..17f0b48 --- /dev/null +++ b/ppc/gen/insque.c @@ -0,0 +1,55 @@ +/* + * Copyright (c) 1999 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@ + */ +/* Copyright (c) 1992, 1997 NeXT Software, Inc. All rights reserved. + * + * File: libc/gen/ppc/insque.c + * + * struct qelem { + * struct qelem *q_forw; + * struct qelem *q_back; + * char q_data[]; + * }; + * + * void insque(struct qelem *elem, struct qelem *prev); + * + * Inserts queue entry `elem' into a queue after element `prev'. + * + * HISTORY +* 24-Jan-1997 Umesh Vaishampayan (umeshv@NeXT.com) +* Ported to PPC. + * 10-Nov-92 Derek B Clegg (dclegg@next.com) + * Created. + */ +#include + +void +insque(struct qelem *elem, struct qelem *prev) +{ + struct qelem *next; + + next = prev->q_forw; + prev->q_forw = elem; + if (next != 0) + next->q_back = elem; + elem->q_forw = next; + elem->q_back = prev; +} diff --git a/ppc/gen/isinf.c b/ppc/gen/isinf.c new file mode 100644 index 0000000..b98587d --- /dev/null +++ b/ppc/gen/isinf.c @@ -0,0 +1,54 @@ +/* + * Copyright (c) 1999 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@ + */ +/* Copyright (c) 1992, 1997 NeXT Software, Inc. All rights reserved. + * + * File: libc/gen/ppc/isinf.c + * Author: Derek B Clegg, NeXT Software, Inc. + * + * HISTORY +* 24-Jan-1997 Umesh Vaishampayan (umeshv@NeXT.com) +* Ported to PPC. + * 11-Nov-92 Derek B Clegg (dclegg@next.com) + * Created. + * + * int isinf(double value); + * + * Returns 1 if `value' is equal to positive IEEE infinity, -1 if `value' + * is equal to negative IEEE infinity, 0 otherwise. + * + * An IEEE infinity is a double value with the maximum biased exponent value + * (2047) and a zero fraction value. + */ +#import "fp.h" + +int +isinf(double value) +{ + union dbl d; + + d.value = value; + if (d.u[0] == 0x7FF00000 && d.u[1] == 0) + return 1; + if (d.u[0] == 0xFFF00000 && d.u[1] == 0) + return -1; + return 0; +} diff --git a/ppc/gen/mcount.s b/ppc/gen/mcount.s new file mode 100644 index 0000000..2c73e3d --- /dev/null +++ b/ppc/gen/mcount.s @@ -0,0 +1,43 @@ +/* + * Copyright (c) 1999 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@ + */ +/* Copyright 1997 Apple Computer, Inc. +** +** 10 June 1997 - Created by mwatson@apple.com +** +*/ + +#include + + .text + .align 2 + .globl mcount +mcount: + mflr r0 + stw r0,8(r1) + stwu r1,-64(r1) + mflr r4 + CALL_EXTERN(_moncount) + addi r1,r1,64 + lwz r0,8(r1) + mtlr r0 + blr + diff --git a/ppc/gen/remque.c b/ppc/gen/remque.c new file mode 100644 index 0000000..9e032c5 --- /dev/null +++ b/ppc/gen/remque.c @@ -0,0 +1,55 @@ +/* + * Copyright (c) 1999 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@ + */ +/* Copyright (c) 1992, 1997 NeXT Software, Inc. All rights reserved. + * + * File: libc/gen/ppc/remque.c + * + * struct qelem { + * struct qelem *q_forw; + * struct qelem *q_back; + * char q_data[]; + * }; + * + * void remque(struct qelem *entry); + * + * Removes `entry' from a queue. + * + * HISTORY + * 24-Jan-1997 Umesh Vaishampayan (umeshv@NeXT.com) + * Ported to PPC. + * 10-Nov-92 Derek B Clegg (dclegg@next.com) + * Created. + */ +#import + +void +remque(struct qelem *elem) +{ + struct qelem *next, *prev; + + next = elem->q_forw; + prev = elem->q_back; + if (next != 0) + next->q_back = prev; + if (prev != 0) + prev->q_forw = next; +} diff --git a/ppc/gen/setjmperr.c b/ppc/gen/setjmperr.c new file mode 100644 index 0000000..3df3b7d --- /dev/null +++ b/ppc/gen/setjmperr.c @@ -0,0 +1,44 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1980 Regents of the University of California. + * All rights reserved. The Berkeley software License Agreement + * specifies the terms and conditions for redistribution. + */ + +#if defined(LIBC_SCCS) && !defined(lint) +static char sccsid[] = "@(#)setjmperr.c 5.2 (Berkeley) 3/9/86"; +#endif LIBC_SCCS and not lint + +#define ERRMSG "longjmp botch\n" + +/* + * This routine is called from longjmp() when an error occurs. + * Programs that wish to exit gracefully from this error may + * write their own versions. + * If this routine returns, the program is aborted. + */ +void +longjmperror(void) +{ + write(2, ERRMSG, sizeof(ERRMSG)); +} diff --git a/ppc/gen/strcat.c b/ppc/gen/strcat.c new file mode 100644 index 0000000..ef5c208 --- /dev/null +++ b/ppc/gen/strcat.c @@ -0,0 +1,44 @@ +/* + * Copyright (c) 1999 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@ + */ +/* Copyright (c) 1991, 1997 NeXT Software, Inc. All rights reserved. + * + * File: libc/gen/ppc/strcat.c + * Author: Mike DeMoney, NeXT Software, Inc. + * + * This file contains machine dependent code for string copy + * + * HISTORY + * 24-Jan-1997 Umesh Vaishampayan (umeshv@NeXT.com) + * Ported to PPC. + * 9-Nov-92 Derek B Clegg (dclegg@next.com) + * Ported to m98k. + * 4-Jun-91 Mike DeMoney (mike@next.com) + * Created. + */ +#import + +char * +strcat(char *s1, const char *s2) +{ + strcpy(&s1[strlen(s1)], s2); + return s1; +} diff --git a/ppc/gen/strcmp.c b/ppc/gen/strcmp.c new file mode 100644 index 0000000..b51e8a5 --- /dev/null +++ b/ppc/gen/strcmp.c @@ -0,0 +1,53 @@ +/* + * Copyright (c) 1999 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@ + */ +/* Copyright (c) 1992, 1997 NeXT Software, Inc. All rights reserved. + * + * File: libc/gen/ppc/strcmp.c + * + * This file contains machine dependent code for string comparison + * on NeXT 88K-based products. + * + * HISTORY + * 24-Jan-1997 Umesh Vaishampayan (umeshv@NeXT.com) + * Ported to PPC. + * 24-Nov-92 Derek B Clegg (dclegg@next.com) + * Created. + */ +#import + +/* This routine should be optimized. */ + +/* ANSI sez: + * The `strcmp' function compares the string pointed to by `s1' to the + * string pointed to by `s2'. + * The `strcmp' function returns an integer greater than, equal to, or less + * than zero, according as the string pointed to by `s1' is greater than, + * equal to, or less than the string pointed to by `s2'. [4.11.4.2] + */ +int +strcmp(const char *s1, const char *s2) +{ + for ( ; *s1 == *s2; s1++, s2++) + if (*s1 == '\0') + return 0; + return ((*(unsigned char *)s1 < *(unsigned char *)s2) ? -1 : +1); +} diff --git a/ppc/gen/strcpy.c b/ppc/gen/strcpy.c new file mode 100644 index 0000000..a4c78b4 --- /dev/null +++ b/ppc/gen/strcpy.c @@ -0,0 +1,52 @@ +/* + * Copyright (c) 1999 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@ + */ +/* Copyright (c) 1992, 1997 NeXT Software, Inc. All rights reserved. + * + * File: libc/gen/ppc/strcpy.c + * + * This file contains machine dependent code for string copy + * + * HISTORY + * 24-Jan-1997 Umesh Vaishampayan (umeshv@NeXT.com) + * Ported to PPC. + * 24-Nov-92 Derek B Clegg (dclegg@next.com) + * Created. + */ +#import + +/* XXX This routine should be optimized. */ + +/* ANSI sez: + * The `strcpy' function copies the string pointed to by `s2' (including + * the terminating null character) into the array pointed to by `s1'. + * If copying takes place between objects that overlap, the behavior + * is undefined. + * The `strcpy' function returns the value of `s1'. [4.11.2.3] + */ +char * +strcpy(char *s1, const char *s2) +{ + char *s = s1; + while ((*s++ = *s2++) != 0) + ; + return (s1); +} diff --git a/ppc/gen/strlen.s b/ppc/gen/strlen.s new file mode 100644 index 0000000..a633cf7 --- /dev/null +++ b/ppc/gen/strlen.s @@ -0,0 +1,111 @@ +/* + * Copyright (c) 2000-2001 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@ + */ +; +; +; Strlen, optimized for PPC. The routine we use is 2-3x faster +; then the simple loop which checks each byte for zero. +; For 0- and 1-byte strings, the simple routine is faster, but +; only by a few cycles. The algorithm used was adapted from the +; Mac OS 9 stdCLib strcopy routine, which was originally +; written by Gary Davidian. It relies on the following rather +; inobvious but very efficient test: +; +; y = dataWord + 0xFEFEFEFF +; z = ~dataWord & 0x80808080 +; if ( y & z ) = 0 then all bytes in dataWord are non-zero +; +; The test maps any non-zero byte to zeros and any zero byte to 0x80, +; with one exception: 0x01 bytes preceeding the first zero are also +; mapped to 0x80. +; +#include +; +; int strlen(ptr) +; +; + + .align 5 + .globl EXT(strlen) +LEXT(strlen) + + andi. r4,r3,0x03 ; test alignment first + mr r9,r3 ; store the original address for later use.... + bne LalignSource ; align the source addr if not already aligned +Llentry: + lis r5,hi16(0xFEFEFEFF) + lis r6,hi16(0x80808080) + subi r3,r3,0x04 ; pre-decrement r3 for the lwzu + ori r5,r5,lo16(0xFEFEFEFF) ; r5=0xFEFEFEFF + ori r6,r6,lo16(0x80808080) ; r6=0x80808080 + +LLoop: + lwzu r8,4(r3) ; get the first 4 bytes and increment address + add r4,r5,r8 ; r4= data + 0xFEFEFEFF + andc r7,r6,r8 ; r7= ~data & 0x80808080 + and. r4,r4,r7 ; r4= r4 & r7 + beq LLoop ; if r4 is zero, then all bytes are non-zero + +; Now we know one of the bytes in r8 is zero, +; we just have to figure out which one. +; We have mapped 0 bytes to 0x80, and nonzero bytes to 0x00, +; with one exception: +; 0x01 bytes preceeding the first zero are also mapped to 0x80. +; So we have to mask out the 0x80s caused by 0x01s before +; counting leading zeroes to get the bytes in last word. + + rlwinm r5,r8,7,0,31 ; move 0x01 bits to 0x80 position + subf r3,r9,r3 ; start to compute string length + andc r4,r4,r5 ; turn off false hits from 0x0100 worst case + cntlzw r7,r4 ; now we can count leading 0s + srwi r7,r7,3 ; convert 0,8,16,24 to 0,1,2,3 + add r3,r3,r7 ; add in nonzero bytes in last word + blr + +; We must align the source address for two reasons: to avoid spurious page +; faults, and for speed. +; r4 = low 2 bits of address (1,2, or 3) +; r3 = address +; r9 = original address (still same as r3) + +LalignSource: + lbz r5,0(r3) ; get the first byte... + subic. r4,r4,2 ; test for 1, 2 or 3 bytes + addi r3,r3,1 ; increment address + addi r6,r9,1 ; now r6==r3 + cmpwi cr1,r5,0 ; zero? + beq cr1,Lreturn ; if its zero return zero + bgt Llentry ; address is aligned now if low bits were 3 + + lbz r5,0(r3) ; get the next byte... + addi r3,r3,1 ; increment address + cmpwi cr1,r5,0 ; zero? + beq cr1,Lreturn ; if its zero return one + beq Llentry ; addr is aligned now if low bits were 2 + + lbz r5,0(r3) ; get the next byte... + addi r3,r3,1 ; increment address + cmpwi cr1,r5,0 ; zero? + bne cr1,Llentry ; not zero, continue check (now aligned) +Lreturn: + sub r3,r3,r6 ; get string length (0, 1, or 2) + blr + diff --git a/ppc/gen/strncat.c b/ppc/gen/strncat.c new file mode 100644 index 0000000..9f9ef54 --- /dev/null +++ b/ppc/gen/strncat.c @@ -0,0 +1,52 @@ +/* + * Copyright (c) 1999 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@ + */ +/* Copyright (c) 1991, 1997 NeXT Software, Inc. All rights reserved. + * + * File: libc/gen/ppc/strncat.c + * Author: Mike DeMoney, NeXT Software, Inc. + * + * This file contains machine dependent code for string copy + * + * HISTORY + * 24-Jan-1997 Umesh Vaishampayan (umeshv@NeXT.com) + * Ported to PPC. + * 23-Nov-92 Derek B Clegg (dclegg@next.com) + * Ported to m98k. + * 4-Jun-91 Mike DeMoney (mike@next.com) + * Created. + */ +#import + +char * +strncat(char *s1, const char *s2, size_t n) +{ + unsigned len1 = strlen(s1); + unsigned len2 = strlen(s2); + + if (len2 < n) { + strcpy(&s1[len1], s2); + } else { + strncpy(&s1[len1], s2, n); + s1[len1 + n] = '\0'; + } + return s1; +} diff --git a/ppc/gen/strncmp.c b/ppc/gen/strncmp.c new file mode 100644 index 0000000..bd54d2d --- /dev/null +++ b/ppc/gen/strncmp.c @@ -0,0 +1,56 @@ +/* + * Copyright (c) 1999 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@ + */ +/* Copyright (c) 1992, 1997 NeXT Software, Inc. All rights reserved. + * + * File: libc/gen/ppc/strncmp.c + * + * This file contains machine dependent code for string comparison + * + * HISTORY + * 24-Jan-1997 Umesh Vaishampayan (umeshv@NeXT.com) + * Ported to PPC. + * 24-Nov-92 Derek B Clegg (dclegg@next.com) + * Created. + */ +#import + +/* This routine should be optimized. */ + +/* ANSI sez: + * The `strncmp' function compares not more than `n' characters (characters + * that follow a null character are not compared) from the array pointed to + * by `s1' to the array pointed to by `s2'. + * The `strncmp' function returns an integer greater than, equal to, or less + * than zero, according as the possibly null-terminated array pointed to by + * `s1' is greater than, equal to, or less than the possibly null-terminated + * array pointed to by `s2'. [4.11.4.4] + */ +int +strncmp(const char *s1, const char *s2, size_t n) +{ + for ( ; n > 0; s1++, s2++, --n) + if (*s1 != *s2) + return ((*(unsigned char *)s1 < *(unsigned char *)s2) ? -1 : +1); + else if (*s1 == '\0') + return 0; + return 0; +} diff --git a/ppc/gen/strncpy.c b/ppc/gen/strncpy.c new file mode 100644 index 0000000..1fd6e26 --- /dev/null +++ b/ppc/gen/strncpy.c @@ -0,0 +1,61 @@ +/* + * Copyright (c) 1999 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@ + */ +/* Copyright (c) 1992, 1997 NeXT Software, Inc. All rights reserved. + * + * File: libc/gen/ppc/strncpy.c + * + * This file contains machine dependent code for string copy + * + * HISTORY + * 24-Jan-1997 Umesh Vaishampayan (umeshv@NeXT.com) + * Ported to PPC. + * 24-Nov-92 Derek B Clegg (dclegg@next.com) + * Created. + */ +#import + +/* This routine should be optimized. */ + +/* ANSI sez: + * The `strncpy' function copies not more than `n' characters (characters + * that follow a null character are not copied) from the array pointed to + * by `s2' to the array pointed to by `s1'. If copying takes place between + * objects that overlap, the behavior is undefined. + * If the array pointed to by `s2' is a string that is shorter than `n' + * characters, null characters are appended to the copy in the array + * pointed to by `s1', until `n' characters in all have been written. + * The `strncpy' function returns the value of `s1'. [4.11.2.4] + */ +char * +strncpy(char *s1, const char *s2, size_t n) +{ + char *s = s1; + while (n > 0 && *s2 != '\0') { + *s++ = *s2++; + --n; + } + while (n > 0) { + *s++ = '\0'; + --n; + } + return s1; +} diff --git a/ppc/mach/Makefile.inc b/ppc/mach/Makefile.inc new file mode 100644 index 0000000..e35f6ab --- /dev/null +++ b/ppc/mach/Makefile.inc @@ -0,0 +1 @@ +SRCS += mach_absolute_time.s diff --git a/ppc/mach/mach_absolute_time.s b/ppc/mach/mach_absolute_time.s new file mode 100644 index 0000000..7ed2293 --- /dev/null +++ b/ppc/mach/mach_absolute_time.s @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2002 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@ + */ + +#if defined(__ppc__) +.text +.align 2 +.globl _mach_absolute_time +_mach_absolute_time: +1: mftbu r3 + mftb r4 + mftbu r0 + cmpw r0,r3 + bne- 1b + blr +#endif diff --git a/ppc/sys/ATPgetreq.s b/ppc/sys/ATPgetreq.s new file mode 100644 index 0000000..3033717 --- /dev/null +++ b/ppc/sys/ATPgetreq.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(ATPgetreq, 3) + blr + diff --git a/ppc/sys/ATPgetrsp.s b/ppc/sys/ATPgetrsp.s new file mode 100644 index 0000000..f5f25ab --- /dev/null +++ b/ppc/sys/ATPgetrsp.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(ATPgetrsp, 3) + blr + diff --git a/ppc/sys/ATPsndreq.s b/ppc/sys/ATPsndreq.s new file mode 100644 index 0000000..076c33f --- /dev/null +++ b/ppc/sys/ATPsndreq.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(ATPsndreq, 3) + blr + diff --git a/ppc/sys/ATPsndrsp.s b/ppc/sys/ATPsndrsp.s new file mode 100644 index 0000000..00cca6d --- /dev/null +++ b/ppc/sys/ATPsndrsp.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(ATPsndrsp, 3) + blr + diff --git a/ppc/sys/ATgetmsg.s b/ppc/sys/ATgetmsg.s new file mode 100644 index 0000000..529a298 --- /dev/null +++ b/ppc/sys/ATgetmsg.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(ATgetmsg, 3) + blr + diff --git a/ppc/sys/ATputmsg.s b/ppc/sys/ATputmsg.s new file mode 100644 index 0000000..61e085f --- /dev/null +++ b/ppc/sys/ATputmsg.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(ATputmsg, 3) + blr + diff --git a/ppc/sys/ATsocket.s b/ppc/sys/ATsocket.s new file mode 100644 index 0000000..f53d7d0 --- /dev/null +++ b/ppc/sys/ATsocket.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(ATsocket, 3) + blr + diff --git a/ppc/sys/Makefile.inc b/ppc/sys/Makefile.inc new file mode 100644 index 0000000..1338cea --- /dev/null +++ b/ppc/sys/Makefile.inc @@ -0,0 +1,195 @@ +SRCS+= ATPgetreq.s \ + ATPgetrsp.s \ + ATPsndreq.s \ + ATPsndrsp.s \ + ATgetmsg.s \ + ATputmsg.s \ + ATsocket.s \ + _exit.s \ + _getlogin.s \ + _longjmp.s \ + _pthread_kill.s \ + _setjmp.s \ + _setlogin.s \ + _sysctl.s \ + accept.s \ + access.s \ + acct.s \ + add_profil.s \ + adjtime.s \ + bind.s \ + cerror.s \ + chdir.s \ + checkuseraccess.s \ + chflags.s \ + chmod.s \ + chown.s \ + chroot.s \ + close.s \ + connect.s \ + cthread.s \ + dup.s \ + dup2.s \ + exchangedata.s \ + execve.s \ + fchdir.s \ + fchflags.s \ + fchmod.s \ + fchown.s \ + fcntl.s \ + flock.s \ + fork.s \ + fpathconf.s \ + fstat.s \ + fstatfs.s \ + fstatv.s \ + fsync.s \ + ftruncate.s \ + futimes.s \ + getattrlist.s \ + getdirentries.s \ + getdirentriesattr.s \ + getegid.s \ + geteuid.s \ + getfh.s \ + getfsstat.s \ + getgid.s \ + getgroups.s \ + getitimer.s \ + getpeername.s \ + getpgrp.s \ + getpgid.s \ + getpid.s \ + getppid.s \ + getpriority.s \ + getrlimit.s \ + getrusage.s \ + getsid.s \ + getsockname.s \ + getsockopt.s \ + ppc_gettimeofday.s \ + getuid.s \ + ioctl.s \ + issetugid.s \ + kill.s \ + ktrace.s \ + link.s \ + listen.s \ + load_shared_file.s \ + longjmp.s \ + lseek.s \ + lstat.s \ + lstatv.s \ + madvise.s \ + mincore.s \ + minherit.s \ + mkcomplex.s \ + mkdir.s \ + mkfifo.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 \ + nfssvc.s \ + open.s \ + pathconf.s \ + pipe.s \ + posix_madvise.s \ + processor_facilities.s \ + pread.s \ + profil.s \ + pwrite.s \ + ptrace.s \ + pthread_sigmask.s \ + quota.s \ + quotactl.s \ + read.s \ + readlink.s \ + readv.s \ + reboot.s \ + recvfrom.s \ + recvmsg.s \ + rename.s \ + reset_shared_file.s \ + revoke.s \ + rmdir.s \ + searchfs.s \ + select.s \ + sem_close.s \ + sem_destroy.s \ + sem_getvalue.s \ + sem_init.s \ + sem_open.s \ + sem_post.s \ + sem_trywait.s \ + sem_unlink.s \ + sem_wait.s \ + semconfig.s \ + semctl.s \ + semget.s \ + semop.s \ + semsys.s \ + sendmsg.s \ + sendto.s \ + setattrlist.s \ + setegid.s \ + seteuid.s \ + setgid.s \ + setgroups.s \ + setitimer.s \ + setjmp.s \ + setpgid.s \ + setpriority.s \ + setprivexec.s \ + setquota.s \ + setrlimit.s \ + setsid.s \ + setsockopt.s \ + settimeofday.s \ + setuid.s \ + shm_open.s \ + shm_unlink.s \ + shmat.s \ + shmctl.s \ + shmdt.s \ + shmget.s \ + shmsys.s \ + shutdown.s \ + sigaltstack.s \ + sigpending.s \ + sigprocmask.s \ + sigreturn.s \ + sigwait.s \ + socket.s \ + socketpair.s \ + stat.s \ + statfs.s \ + statv.s \ + swapon.s \ + symlink.s \ + sync.s \ + syscall.s \ + systable.s \ + truncate.s \ + umask.s \ + undelete.s \ + unlink.s \ + unmount.s \ + ur_cthread.s \ + utimes.s \ + vfork.s \ + wait4.s \ + write.s \ + writev.s diff --git a/ppc/sys/SYS.h b/ppc/sys/SYS.h new file mode 100644 index 0000000..7a56a8e --- /dev/null +++ b/ppc/sys/SYS.h @@ -0,0 +1,163 @@ +/* + * Copyright (c) 1999 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@ + */ +/* Copyright (c) 1992 NeXT Computer, Inc. All rights reserved. + * + * File: SYS.h + * + * Definition of the user side of the UNIX system call interface + * for M98K. + * + * Errors are flagged by the location of the trap return (ie., which + * instruction is executed upon rfi): + * + * SC PC + 4: Error (typically branch to cerror()) + * SC PC + 8: Success + * + * HISTORY + * 18-Nov-92 Ben Fathi (benf@next.com) + * Ported to m98k. + * + * 9-Jan-92 Peter King (king@next.com) + * Created. + */ + +#define KERNEL_PRIVATE 1 +/* + * Header files. + */ +#import +#import +#import +#import + +/* From rhapsody kernel mach/ppc/syscall_sw.h */ +#define kernel_trap_args_0 +#define kernel_trap_args_1 +#define kernel_trap_args_2 +#define kernel_trap_args_3 +#define kernel_trap_args_4 +#define kernel_trap_args_5 +#define kernel_trap_args_6 +#define kernel_trap_args_7 + +/* + * simple_kernel_trap -- Mach system calls with 8 or less args + * Args are passed in a0 - a7, system call number in r0. + * Do a "sc" instruction to enter kernel. + */ +#define simple_kernel_trap(trap_name, trap_number) \ + .globl _##trap_name @\ +_##trap_name: @\ + li r0,trap_number @\ + sc @\ + blr @\ + END(trap_name) + +#define kernel_trap_0(trap_name,trap_number) \ + simple_kernel_trap(trap_name,trap_number) + +#define kernel_trap_1(trap_name,trap_number) \ + simple_kernel_trap(trap_name,trap_number) + +#define kernel_trap_2(trap_name,trap_number) \ + simple_kernel_trap(trap_name,trap_number) + +#define kernel_trap_3(trap_name,trap_number) \ + simple_kernel_trap(trap_name,trap_number) + +#define kernel_trap_4(trap_name,trap_number) \ + simple_kernel_trap(trap_name,trap_number) + +#define kernel_trap_5(trap_name,trap_number) \ + simple_kernel_trap(trap_name,trap_number) + +#define kernel_trap_6(trap_name,trap_number) \ + simple_kernel_trap(trap_name,trap_number) + +#define kernel_trap_7(trap_name,trap_number) \ + simple_kernel_trap(trap_name,trap_number) + +#define kernel_trap_8(trap_name,trap_number) \ + simple_kernel_trap(trap_name,trap_number) + +#define kernel_trap_9(trap_name,trap_number) \ + simple_kernel_trap(trap_name,trap_number) + +/* End of rhapsody kernel mach/ppc/syscall_sw.h */ + +/* + * Macros. + */ + +#define SYSCALL(name, nargs) \ + .globl cerror @\ +LEAF(_##name) @\ + kernel_trap_args_##nargs @\ + li r0,SYS_##name @\ + sc @\ + b 1f @\ + b 2f @\ +1: BRANCH_EXTERN(cerror) @\ +.text \ +2: nop + +#define SYSCALL_NONAME(name, nargs) \ + .globl cerror @\ + kernel_trap_args_##nargs @\ + li r0,SYS_##name @\ + sc @\ + b 1f @\ + b 2f @\ +1: BRANCH_EXTERN(cerror) @\ +.text \ +2: nop + +#define PSEUDO(pseudo, name, nargs) \ +LEAF(_##pseudo) @\ + SYSCALL_NONAME(name, nargs) + + +#undef END +#import + +#if !defined(SYS_getdirentriesattr) +#define SYS_getdirentriesattr 222 +#endif + +#if !defined(SYS_semsys) +#define SYS_semsys 251 +#define SYS_msgsys 252 +#define SYS_shmsys 253 +#define SYS_semctl 254 +#define SYS_semget 255 +#define SYS_semop 256 +#define SYS_semconfig 257 +#define SYS_msgctl 258 +#define SYS_msgget 259 +#define SYS_msgsnd 260 +#define SYS_msgrcv 261 +#define SYS_shmat 262 +#define SYS_shmctl 263 +#define SYS_shmdt 264 +#define SYS_shmget 265 +#endif + diff --git a/ppc/sys/_exit.s b/ppc/sys/_exit.s new file mode 100644 index 0000000..fd3a59e --- /dev/null +++ b/ppc/sys/_exit.s @@ -0,0 +1,25 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +PSEUDO(_exit, exit, 1) + blr diff --git a/ppc/sys/_getlogin.s b/ppc/sys/_getlogin.s new file mode 100644 index 0000000..e0eb958 --- /dev/null +++ b/ppc/sys/_getlogin.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +PSEUDO(_getlogin, getlogin, 0) + blr + diff --git a/ppc/sys/_longjmp.s b/ppc/sys/_longjmp.s new file mode 100644 index 0000000..6bdeb02 --- /dev/null +++ b/ppc/sys/_longjmp.s @@ -0,0 +1,224 @@ +/* + * Copyright (c) 1999 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@ + */ + +/* void _longjmp(jmp_buf env, int val); */ + +/* int _longjmp(jmp_buf env); */ +/* + * Copyright (c) 1998 Apple Computer, Inc. All rights reserved. + * + * File: sys/ppc/_longjmp.s + * + * Implements _longjmp() + * + * History: + * 8 September 1998 Matt Watson (mwatson@apple.com) + * Created. Derived from longjmp.s + */ + +#include +#include "_setjmp.h" + +#define VRSave 256 + +/* special flag bit definitions copied from /osfmk/ppc/thread_act.h */ + +#define floatUsedbit 1 +#define vectorUsedbit 2 + + +#if defined(__DYNAMIC__) + .data + .non_lazy_symbol_pointer + .align 2 +L_memmove$non_lazy_ptr: + .indirect_symbol _memmove + .long 0 + .non_lazy_symbol_pointer + .align 2 +L__cpu_has_altivec$non_lazy_ptr: + .indirect_symbol __cpu_has_altivec + .long 0 + .text +#endif + +LEAF(__longjmp) + + ; need to restore FPRs or VRs? + + lwz r5,JMP_flags(r3) + lwz r6,JMP_addr_at_setjmp(r3) + rlwinm r7,r5,0,vectorUsedbit,vectorUsedbit + rlwinm r8,r5,0,floatUsedbit,floatUsedbit + cmpw cr1,r3,r6 ; jmp_buf still at same address? + cmpwi cr3,r7,0 ; set cr3 iff VRs in use (non-volatile CR) + cmpwi cr4,r8,0 ; set cr4 iff FPRs in use (non-volatile CR) + beq+ cr1,LRestoreVRs + + ; jmp_buf was moved since setjmp (or is uninitialized.) + ; We must move VRs and FPRs to be quadword aligned at present address. + + stw r3,JMP_addr_at_setjmp(r3) ; update, in case we longjmp to this again + mr r31,r4 ; save "val" arg across memmove + mr r30,r3 ; and jmp_buf ptr + addi r3,r3,JMP_vr_base_addr + addi r4,r6,JMP_vr_base_addr + rlwinm r3,r3,0,0,27 ; r3 <- QW aligned addr where they should be + rlwinm r4,r4,0,0,27 ; r4 <- QW aligned addr where they originally were + sub r7,r4,r6 ; r7 <- offset of VRs/FPRs within jmp_buf + add r4,r30,r7 ; r4 <- where they are now + li r5,(JMP_buf_end - JMP_vr_base_addr) +#if defined(__DYNAMIC__) + bcl 20,31,1f ; Get pic-base +1: mflr r12 + addis r12, r12, ha16(L_memmove$non_lazy_ptr - 1b) + lwz r12, lo16(L_memmove$non_lazy_ptr - 1b)(r12) + mtctr r12 ; Get address left by dyld + bctrl +#else + bl _memmove +#endif + mr r3,r30 + mr r4,r31 + + ; Restore VRs iff any + ; cr3 - bne if VRs + ; cr4 - bne if FPRs + +LRestoreVRs: + beq+ cr3,LZeroVRSave ; no VRs + lwz r0,JMP_vrsave(r3) + addi r6,r3,JMP_vr_base_addr + cmpwi r0,0 ; any live VRs? + mtspr VRSave,r0 + beq+ LRestoreFPRs + lvx v20,0,r6 + li r7,16*1 + lvx v21,r7,r6 + li r7,16*2 + lvx v22,r7,r6 + li r7,16*3 + lvx v23,r7,r6 + li r7,16*4 + lvx v24,r7,r6 + li r7,16*5 + lvx v25,r7,r6 + li r7,16*6 + lvx v26,r7,r6 + li r7,16*7 + lvx v27,r7,r6 + li r7,16*8 + lvx v28,r7,r6 + li r7,16*9 + lvx v29,r7,r6 + li r7,16*10 + lvx v30,r7,r6 + li r7,16*11 + lvx v31,r7,r6 + b LRestoreFPRs ; skip zeroing VRSave + + ; Zero VRSave iff Altivec is supported, but VRs were not in use + ; at setjmp time. This covers the case where VRs are first used after + ; the setjmp but before the longjmp, and where VRSave is nonzero at + ; the longjmp. We need to zero it now, or it will always remain + ; nonzero since they are sticky bits. + +LZeroVRSave: +#if defined(__DYNAMIC__) + bcl 20,31,1f +1: mflr r9 ; get our address + addis r6,r9,ha16(L__cpu_has_altivec$non_lazy_ptr - 1b) + lwz r7,lo16(L__cpu_has_altivec$non_lazy_ptr - 1b)(r6) + lwz r7,0(r7) ; load the flag +#else + lis r7, ha16(__cpu_has_altivec) + lwz r7, lo16(__cpu_has_altivec)(r7) +#endif + cmpwi r7,0 + li r8,0 + beq LRestoreFPRs ; no Altivec, so skip + mtspr VRSave,r8 + + ; Restore FPRs if any + ; cr4 - bne iff FPRs + +LRestoreFPRs: + beq cr4,LRestoreGPRs ; FPRs not in use at setjmp + addi r6,r3,JMP_fp_base_addr + rlwinm r6,r6,0,0,27 ; mask off low 4 bits to qw align + lfd f14,0*8(r6) + lfd f15,1*8(r6) + lfd f16,2*8(r6) + lfd f17,3*8(r6) + lfd f18,4*8(r6) + lfd f19,5*8(r6) + lfd f20,6*8(r6) + lfd f21,7*8(r6) + lfd f22,8*8(r6) + lfd f23,9*8(r6) + lfd f24,10*8(r6) + lfd f25,11*8(r6) + lfd f26,12*8(r6) + lfd f27,13*8(r6) + lfd f28,14*8(r6) + lfd f29,15*8(r6) + lfd f30,16*8(r6) + lfd f31,17*8(r6) + + ; Restore GPRs + +LRestoreGPRs: + lwz r31, JMP_r31(r3) + /* r1, r14-r30 */ + lwz r1, JMP_r1 (r3) + lwz r2, JMP_r2 (r3) + lwz r13, JMP_r13(r3) + lwz r14, JMP_r14(r3) + lwz r15, JMP_r15(r3) + lwz r16, JMP_r16(r3) + lwz r17, JMP_r17(r3) + lwz r18, JMP_r18(r3) + lwz r19, JMP_r19(r3) + lwz r20, JMP_r20(r3) + lwz r21, JMP_r21(r3) + lwz r22, JMP_r22(r3) + lwz r23, JMP_r23(r3) + lwz r24, JMP_r24(r3) + lwz r25, JMP_r25(r3) + lwz r26, JMP_r26(r3) + lwz r27, JMP_r27(r3) + lwz r28, JMP_r28(r3) + lwz r29, JMP_r29(r3) + lwz r30, JMP_r30(r3) + lwz r0, JMP_cr(r3) + mtcrf 0xff,r0 + lwz r0, JMP_lr(r3) + mtlr r0 + lwz r0, JMP_ctr(r3) ; XXX ctr is volatile + mtctr r0 + lwz r0, JMP_xer(r3) ; XXX xer is volatile + mtxer r0 + mr. r3, r4 + bnelr + li r3, 1 + blr + diff --git a/ppc/sys/_pthread_kill.s b/ppc/sys/_pthread_kill.s new file mode 100644 index 0000000..22a9562 --- /dev/null +++ b/ppc/sys/_pthread_kill.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(__pthread_kill, 2) + blr + diff --git a/ppc/sys/_setjmp.h b/ppc/sys/_setjmp.h new file mode 100644 index 0000000..8a78817 --- /dev/null +++ b/ppc/sys/_setjmp.h @@ -0,0 +1,75 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1998, Apple Computer Inc. All rights reserved. + * + * File: _setjmp.h + * + * Defines for register offsets in the save area. + * + */ + +/* NOTE: jmp_bufs are only 4-byte aligned. This means we + * need to pad before the VR and FPR save areas, so that they + * can be naturally aligned in the buffer. In case a jmp_buf + * is bcopy'd to a different alignment between the setjmp + * and longjmp, we need to save the jmp_buf address in the + * jmp_buf at setjmp time, so we can realign before reloading. + */ + +#define JMP_r1 0x00 +#define JMP_r2 0x04 +#define JMP_r13 0x08 +#define JMP_r14 0x0c +#define JMP_r15 0x10 +#define JMP_r16 0x14 +#define JMP_r17 0x18 +#define JMP_r18 0x1c +#define JMP_r19 0x20 +#define JMP_r20 0x24 +#define JMP_r21 0x28 +#define JMP_r22 0x2c +#define JMP_r23 0x30 +#define JMP_r24 0x34 +#define JMP_r25 0x38 +#define JMP_r26 0x3c +#define JMP_r27 0x40 +#define JMP_r28 0x44 +#define JMP_r29 0x48 +#define JMP_r30 0x4c +#define JMP_r31 0x50 +#define JMP_lr 0x54 +#define JMP_cr 0x58 +#define JMP_ctr 0x5c +#define JMP_xer 0x60 +#define JMP_sig 0x64 +#define JMP_SIGFLAG 0x68 +#define JMP_flags 0x6c +#define JMP_vrsave 0x70 +#define JMP_addr_at_setjmp 0x74 +/* 12 bytes padding here */ +#define JMP_vr_base_addr 0x84 +/* save room for 12 VRs (v20-v31), or 0xC0 bytes */ +#define JMP_fp_base_addr 0x144 +/* save room for 18 FPRs (f14-f31), or 0x90 bytes */ +#define JMP_buf_end 0x1d4 + diff --git a/ppc/sys/_setjmp.s b/ppc/sys/_setjmp.s new file mode 100644 index 0000000..c69f9ad --- /dev/null +++ b/ppc/sys/_setjmp.s @@ -0,0 +1,154 @@ +/* + * Copyright (c) 1999 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@ + */ + +/* int _setjmp(jmp_buf env); */ +/* + * Copyright (c) 1998 Apple Computer, Inc. All rights reserved. + * + * File: sys/ppc/_setjmp.s + * + * Implements _setjmp() + * + * History: + * 8 September 1998 Matt Watson (mwatson@apple.com) + * Created. Derived from setjmp.s + */ + + +#include +#include "_setjmp.h" + +#define VRSave 256 + +/* special flag bit definitions copied from /osfmk/ppc/thread_act.h */ + +#define floatUsedbit 1 +#define vectorUsedbit 2 + +#define FlagsFastTrap 0x7FF3 + + +LEAF(__setjmp) + stw r31, JMP_r31(r3) + /* r1, r2, r13-r30 */ + stw r1, JMP_r1(r3) + stw r2, JMP_r2(r3) + stw r13, JMP_r13(r3) + stw r14, JMP_r14(r3) + stw r15, JMP_r15(r3) + stw r16, JMP_r16(r3) + stw r17, JMP_r17(r3) + stw r18, JMP_r18(r3) + stw r19, JMP_r19(r3) + stw r20, JMP_r20(r3) + stw r21, JMP_r21(r3) + stw r22, JMP_r22(r3) + mfcr r0 + stw r23, JMP_r23(r3) + stw r24, JMP_r24(r3) + mflr r5 + stw r25, JMP_r25(r3) + stw r26, JMP_r26(r3) + mfctr r6 ; XXX ctr is volatile + stw r27, JMP_r27(r3) + stw r28, JMP_r28(r3) + mfxer r7 ; XXX xer is volatile + stw r29, JMP_r29(r3) + stw r30, JMP_r30(r3) + stw r0, JMP_cr(r3) + stw r5, JMP_lr(r3) + stw r6, JMP_ctr(r3) + stw r7, JMP_xer(r3) + + mr r31,r3 ; save jmp_buf ptr + li r0,FlagsFastTrap + sc ; get FPR-inuse and VR-inuse flags from kernel + rlwinm r4,r3,0,floatUsedbit,floatUsedbit + rlwinm. r5,r3,0,vectorUsedbit,vectorUsedbit + cmpwi cr1,r4,0 ; set CR1 bne iff FPRs in use + stw r3,JMP_flags(r31) + stw r31,JMP_addr_at_setjmp(r31) + mr r3,r31 ; restore jmp_buf ptr + lwz r31,JMP_r31(r31) + beq LSaveFPRsIfNecessary ; skip if vectorUsedbit was 0 + + ; must save VRs and VRSAVE + + mfspr r4,VRSave + andi. r0,r4,0xFFF ; we only care about v20-v31 + stw r0,JMP_vrsave(r3) ; set up effective VRSAVE + beq LSaveFPRsIfNecessary ; no live non-volatile VRs + addi r6,r3,JMP_vr_base_addr + stvx v20,0,r6 + li r4,16*1 + stvx v21,r4,r6 + li r4,16*2 + stvx v22,r4,r6 + li r4,16*3 + stvx v23,r4,r6 + li r4,16*4 + stvx v24,r4,r6 + li r4,16*5 + stvx v25,r4,r6 + li r4,16*6 + stvx v26,r4,r6 + li r4,16*7 + stvx v27,r4,r6 + li r4,16*8 + stvx v28,r4,r6 + li r4,16*9 + stvx v29,r4,r6 + li r4,16*10 + stvx v30,r4,r6 + li r4,16*11 + stvx v31,r4,r6 + + ; must save FPRs if they are live in this thread + ; CR1 = bne iff FPRs are in use + +LSaveFPRsIfNecessary: + beq cr1,LExit ; FPRs not in use + addi r6,r3,JMP_fp_base_addr + rlwinm r6,r6,0,0,27 ; mask off low 4 bits to qw align + stfd f14,0*8(r6) + stfd f15,1*8(r6) + stfd f16,2*8(r6) + stfd f17,3*8(r6) + stfd f18,4*8(r6) + stfd f19,5*8(r6) + stfd f20,6*8(r6) + stfd f21,7*8(r6) + stfd f22,8*8(r6) + stfd f23,9*8(r6) + stfd f24,10*8(r6) + stfd f25,11*8(r6) + stfd f26,12*8(r6) + stfd f27,13*8(r6) + stfd f28,14*8(r6) + stfd f29,15*8(r6) + stfd f30,16*8(r6) + stfd f31,17*8(r6) + +LExit: + li r3, 0 + blr + diff --git a/ppc/sys/_setlogin.s b/ppc/sys/_setlogin.s new file mode 100644 index 0000000..997db69 --- /dev/null +++ b/ppc/sys/_setlogin.s @@ -0,0 +1,25 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +PSEUDO(_setlogin, setlogin, 0) + blr diff --git a/ppc/sys/_sysctl.s b/ppc/sys/_sysctl.s new file mode 100644 index 0000000..8e29463 --- /dev/null +++ b/ppc/sys/_sysctl.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(__sysctl, 6) + blr + diff --git a/ppc/sys/accept.s b/ppc/sys/accept.s new file mode 100644 index 0000000..672331c --- /dev/null +++ b/ppc/sys/accept.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(accept, 3) + blr + diff --git a/ppc/sys/access.s b/ppc/sys/access.s new file mode 100644 index 0000000..5cd4fb9 --- /dev/null +++ b/ppc/sys/access.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(access, 2) + blr + diff --git a/ppc/sys/acct.s b/ppc/sys/acct.s new file mode 100644 index 0000000..387d35d --- /dev/null +++ b/ppc/sys/acct.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(acct, 1) + blr + diff --git a/ppc/sys/add_profil.s b/ppc/sys/add_profil.s new file mode 100644 index 0000000..d30b6dd --- /dev/null +++ b/ppc/sys/add_profil.s @@ -0,0 +1,25 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(add_profil, 4) + blr diff --git a/ppc/sys/adjtime.s b/ppc/sys/adjtime.s new file mode 100644 index 0000000..11f80da --- /dev/null +++ b/ppc/sys/adjtime.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(adjtime, 2) + blr + diff --git a/ppc/sys/assym.h b/ppc/sys/assym.h new file mode 100644 index 0000000..49d8a8f --- /dev/null +++ b/ppc/sys/assym.h @@ -0,0 +1,155 @@ +/* + * Copyright (c) 1999 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 _ASSYM_H_ +#define _ASSYM_H_ +#define PCB_FLOAT_STATE 208 +#define PCB_FS_F0 208 +#define PCB_FS_F1 216 +#define PCB_FS_F2 224 +#define PCB_FS_F3 232 +#define PCB_FS_F4 240 +#define PCB_FS_F5 248 +#define PCB_FS_F6 256 +#define PCB_FS_F7 264 +#define PCB_FS_F8 272 +#define PCB_FS_F9 280 +#define PCB_FS_F10 288 +#define PCB_FS_F11 296 +#define PCB_FS_F12 304 +#define PCB_FS_F13 312 +#define PCB_FS_F14 320 +#define PCB_FS_F15 328 +#define PCB_FS_F16 336 +#define PCB_FS_F17 344 +#define PCB_FS_F18 352 +#define PCB_FS_F19 360 +#define PCB_FS_F20 368 +#define PCB_FS_F21 376 +#define PCB_FS_F22 384 +#define PCB_FS_F23 392 +#define PCB_FS_F24 400 +#define PCB_FS_F25 408 +#define PCB_FS_F26 416 +#define PCB_FS_F27 424 +#define PCB_FS_F28 432 +#define PCB_FS_F29 440 +#define PCB_FS_F30 448 +#define PCB_FS_F31 456 +#define PCB_FS_FPSCR 464 +#define PCB_SAVED_STATE 0 +#define PCB_KSP 472 +#define PCB_SR0 476 +#define PCB_SIZE 480 +#define SS_R0 8 +#define SS_R1 12 +#define SS_R2 16 +#define SS_R3 20 +#define SS_R4 24 +#define SS_R5 28 +#define SS_R6 32 +#define SS_R7 36 +#define SS_R8 40 +#define SS_R9 44 +#define SS_R10 48 +#define SS_R11 52 +#define SS_R12 56 +#define SS_R13 60 +#define SS_R14 64 +#define SS_R15 68 +#define SS_R16 72 +#define SS_R17 76 +#define SS_R18 80 +#define SS_R19 84 +#define SS_R20 88 +#define SS_R21 92 +#define SS_R22 96 +#define SS_R23 100 +#define SS_R24 104 +#define SS_R25 108 +#define SS_R26 112 +#define SS_R27 116 +#define SS_R28 120 +#define SS_R29 124 +#define SS_R30 128 +#define SS_R31 132 +#define SS_CR 136 +#define SS_XER 140 +#define SS_LR 144 +#define SS_CTR 148 +#define SS_SRR0 0 +#define SS_SRR1 4 +#define SS_MQ 152 +#define SS_SR_COPYIN 160 +#define SS_SIZE 176 +#define PP_SAVE_CR 0 +#define PP_SAVE_SRR0 4 +#define PP_SAVE_SRR1 8 +#define PP_SAVE_DAR 12 +#define PP_SAVE_DSISR 16 +#define PP_SAVE_SPRG0 20 +#define PP_SAVE_SPRG1 24 +#define PP_SAVE_SPRG2 28 +#define PP_SAVE_SPRG3 32 +#define PP_SAVE_EXCEPTION_TYPE 36 +#define PP_CPU_DATA 52 +#define PP_PHYS_EXCEPTION_HANDLERS 40 +#define PP_VIRT_PER_PROC 44 +#define PP_ACTIVE_STACKS 56 +#define PP_NEED_AST 60 +#define PP_FPU_PCB 64 +#define KS_PCB 16276 +#define KS_R1 16280 +#define KS_R2 16284 +#define KS_R13 16288 +#define KS_LR 16364 +#define KS_CR 16368 +#define KS_SIZE 96 +#define KSTK_SIZE 16372 +#define THREAD_PCB 36 +#define THREAD_KERNEL_STACK 40 +#define THREAD_SWAPFUNC 48 +#define THREAD_RECOVER 116 +#define THREAD_TASK 12 +#define TASK_VMMAP 8 +#define TASK_MACH_EXC_PORT 96 +#define VMMAP_PMAP 32 +#define PMAP_SPACE 4 +#define MACH_TRAP_OFFSET_POW2 4 +#define MACH_TRAP_ARGC 0 +#define MACH_TRAP_FUNCTION 4 +#define HOST_SELF 0 +#define CPU_ACTIVE_THREAD 0 +#define FM_SIZE 56 +#define ARG_SIZE 16 +#define LA_SIZE 24 +#define FM_BACKPTR 0 +#define FM_LR_SAVE 8 +#define FM_TOC_SAVE 20 +#define RPA_SIZE 32 +#define SPA_SIZE 16 +#define FM_ARG0 56 +#define FM_REDZONE 0 + +#define SIZEOF_SIGCATCH 4 +#define SIGCATCH_HANDLER 0x00000000 + +#endif /* _ASSYM_H_ */ diff --git a/ppc/sys/assymdefs.c b/ppc/sys/assymdefs.c new file mode 100644 index 0000000..685b750 --- /dev/null +++ b/ppc/sys/assymdefs.c @@ -0,0 +1,128 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * assymdefs.c -- list of symbols to #define in assym.h + */ + +#import +#import + +#define __TARGET_ARCHITECTURE__ "ppc" +#import +#import "sigcatch.h" + +#import "genassym.h" + +void +assymdefs(void) +{ + comment(MAJOR, "Structure Offsets"); + + comment(MINOR, "struct sigcontext offsets and sizes"); + PRINT_SIZEOF(struct sigcontext); + PRINT_OFFSET(struct sigcontext *, sc_regs_saved); + PRINT_OFFSET(struct sigcontext *, sc_sp); + PRINT_OFFSET(struct sigcontext *, sc_cia); + PRINT_OFFSET(struct sigcontext *, sc_a0); + PRINT_OFFSET(struct sigcontext *, sc_a1); + PRINT_OFFSET(struct sigcontext *, sc_a2); + PRINT_OFFSET(struct sigcontext *, sc_ep); + PRINT_OFFSET(struct sigcontext *, sc_mq); + PRINT_OFFSET(struct sigcontext *, sc_lr); + PRINT_OFFSET(struct sigcontext *, sc_cr); + PRINT_OFFSET(struct sigcontext *, sc_ctr); + PRINT_OFFSET(struct sigcontext *, sc_xer); + PRINT_OFFSET(struct sigcontext *, sc_fpscr); + PRINT_OFFSET(struct sigcontext *, sc_zt); + PRINT_OFFSET(struct sigcontext *, sc_a3); + PRINT_OFFSET(struct sigcontext *, sc_a4); + PRINT_OFFSET(struct sigcontext *, sc_a5); + PRINT_OFFSET(struct sigcontext *, sc_a6); + PRINT_OFFSET(struct sigcontext *, sc_a7); + PRINT_OFFSET(struct sigcontext *, sc_at); + PRINT_OFFSET(struct sigcontext *, sc_ft0); + PRINT_OFFSET(struct sigcontext *, sc_fa0); + PRINT_OFFSET(struct sigcontext *, sc_fa1); + PRINT_OFFSET(struct sigcontext *, sc_fa2); + PRINT_OFFSET(struct sigcontext *, sc_fa3); + PRINT_OFFSET(struct sigcontext *, sc_fa4); + PRINT_OFFSET(struct sigcontext *, sc_fa5); + PRINT_OFFSET(struct sigcontext *, sc_fa6); + PRINT_OFFSET(struct sigcontext *, sc_fa7); + PRINT_OFFSET(struct sigcontext *, sc_fa8); + PRINT_OFFSET(struct sigcontext *, sc_fa9); + PRINT_OFFSET(struct sigcontext *, sc_fa10); + PRINT_OFFSET(struct sigcontext *, sc_fa11); + PRINT_OFFSET(struct sigcontext *, sc_fa12); + PRINT_OFFSET(struct sigcontext *, sc_s17); + PRINT_OFFSET(struct sigcontext *, sc_s16); + PRINT_OFFSET(struct sigcontext *, sc_s15); + PRINT_OFFSET(struct sigcontext *, sc_s14); + PRINT_OFFSET(struct sigcontext *, sc_s13); + PRINT_OFFSET(struct sigcontext *, sc_s12); + PRINT_OFFSET(struct sigcontext *, sc_s11); + PRINT_OFFSET(struct sigcontext *, sc_s10); + PRINT_OFFSET(struct sigcontext *, sc_s9); + PRINT_OFFSET(struct sigcontext *, sc_s8); + PRINT_OFFSET(struct sigcontext *, sc_s7); + PRINT_OFFSET(struct sigcontext *, sc_s6); + PRINT_OFFSET(struct sigcontext *, sc_s5); + PRINT_OFFSET(struct sigcontext *, sc_s4); + PRINT_OFFSET(struct sigcontext *, sc_s3); + PRINT_OFFSET(struct sigcontext *, sc_s2); + PRINT_OFFSET(struct sigcontext *, sc_s1); + PRINT_OFFSET(struct sigcontext *, sc_s0); + PRINT_OFFSET(struct sigcontext *, sc_toc); + PRINT_OFFSET(struct sigcontext *, sc_fp); + PRINT_OFFSET(struct sigcontext *, sc_fs17); + PRINT_OFFSET(struct sigcontext *, sc_fs16); + PRINT_OFFSET(struct sigcontext *, sc_fs15); + PRINT_OFFSET(struct sigcontext *, sc_fs14); + PRINT_OFFSET(struct sigcontext *, sc_fs13); + PRINT_OFFSET(struct sigcontext *, sc_fs12); + PRINT_OFFSET(struct sigcontext *, sc_fs11); + PRINT_OFFSET(struct sigcontext *, sc_fs10); + PRINT_OFFSET(struct sigcontext *, sc_fs9); + PRINT_OFFSET(struct sigcontext *, sc_fs8); + PRINT_OFFSET(struct sigcontext *, sc_fs7); + PRINT_OFFSET(struct sigcontext *, sc_fs6); + PRINT_OFFSET(struct sigcontext *, sc_fs5); + PRINT_OFFSET(struct sigcontext *, sc_fs4); + PRINT_OFFSET(struct sigcontext *, sc_fs3); + PRINT_OFFSET(struct sigcontext *, sc_fs2); + PRINT_OFFSET(struct sigcontext *, sc_fs1); + PRINT_OFFSET(struct sigcontext *, sc_fs0); + PRINT_ENUM(REGS_SAVED_NONE); + PRINT_ENUM(REGS_SAVED_CALLER); + PRINT_ENUM(REGS_SAVED_ALL); + + comment(MINOR, "struct sigstack offsets and sizes"); + PRINT_SIZEOF(struct sigstack); + PRINT_OFFSET(struct sigstack *, ss_sp); + PRINT_OFFSET(struct sigstack *, ss_onstack); + + comment(MINOR, "sigcatch_t offsets"); + PRINT_SIZEOF(sigcatch_t); + PRINT_OFFSET(sigcatch_t *, handler); +// PRINT_OFFSET(sigcatch_t *, flags); + PRINT_CONSTANT(SV_SAVE_REGS); +} diff --git a/ppc/sys/bind.s b/ppc/sys/bind.s new file mode 100644 index 0000000..e694ae0 --- /dev/null +++ b/ppc/sys/bind.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(bind, 3) + blr + diff --git a/ppc/sys/cerror.s b/ppc/sys/cerror.s new file mode 100644 index 0000000..5753534 --- /dev/null +++ b/ppc/sys/cerror.s @@ -0,0 +1,36 @@ +/* + * Copyright (c) 1999 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@ + */ +/* Copyright (c) 1992 NeXT Computer, Inc. All rights reserved. + */ + +#import +#import + + .globl _errno + +NESTED(cerror, 0, 1, 0, 0) + REG_TO_EXTERN(r3,_errno) + CALL_EXTERN(_cthread_set_errno_self) + li32 r3,-1 + li32 r4,-1 /* in case a 64-bit value is returned */ + RETURN +END(cerror) diff --git a/ppc/sys/chdir.s b/ppc/sys/chdir.s new file mode 100644 index 0000000..bec9ec4 --- /dev/null +++ b/ppc/sys/chdir.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(chdir, 1) + blr + diff --git a/ppc/sys/checkuseraccess.s b/ppc/sys/checkuseraccess.s new file mode 100644 index 0000000..a3df1da --- /dev/null +++ b/ppc/sys/checkuseraccess.s @@ -0,0 +1,27 @@ +/* + * Copyright (c) 1999 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@ + */ +/* Copyright 1998 Apple Computer, Inc. */ + +#include "SYS.h" + +SYSCALL(checkuseraccess, 0) + blr diff --git a/ppc/sys/chflags.s b/ppc/sys/chflags.s new file mode 100644 index 0000000..8969b30 --- /dev/null +++ b/ppc/sys/chflags.s @@ -0,0 +1,25 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(chflags, 2) + blr diff --git a/ppc/sys/chmod.s b/ppc/sys/chmod.s new file mode 100644 index 0000000..d3b242a --- /dev/null +++ b/ppc/sys/chmod.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(chmod, 2) + blr + diff --git a/ppc/sys/chown.s b/ppc/sys/chown.s new file mode 100644 index 0000000..d05ce9a --- /dev/null +++ b/ppc/sys/chown.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(chown, 3) + blr + diff --git a/ppc/sys/chroot.s b/ppc/sys/chroot.s new file mode 100644 index 0000000..c2a061e --- /dev/null +++ b/ppc/sys/chroot.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(chroot, 1) + blr + diff --git a/ppc/sys/close.s b/ppc/sys/close.s new file mode 100644 index 0000000..fc1d293 --- /dev/null +++ b/ppc/sys/close.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(close, 1) + blr + diff --git a/ppc/sys/connect.s b/ppc/sys/connect.s new file mode 100644 index 0000000..5e7d6d3 --- /dev/null +++ b/ppc/sys/connect.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(connect, 3) + blr + diff --git a/ppc/sys/cthread.s b/ppc/sys/cthread.s new file mode 100644 index 0000000..c456ba7 --- /dev/null +++ b/ppc/sys/cthread.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ + .text + .align 2 + .globl __pthread_set_self +__pthread_set_self: + li r0, 0x7FF1 + sc + blr diff --git a/ppc/sys/dup.s b/ppc/sys/dup.s new file mode 100644 index 0000000..fe70d58 --- /dev/null +++ b/ppc/sys/dup.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(dup, 2) + blr + diff --git a/ppc/sys/dup2.s b/ppc/sys/dup2.s new file mode 100644 index 0000000..ef1e13d --- /dev/null +++ b/ppc/sys/dup2.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(dup2, 2) + blr + diff --git a/ppc/sys/exchangedata.s b/ppc/sys/exchangedata.s new file mode 100644 index 0000000..7a990fc --- /dev/null +++ b/ppc/sys/exchangedata.s @@ -0,0 +1,27 @@ +/* + * Copyright (c) 1999 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@ + */ +/* Copyright 1998 Apple Computer, Inc. */ + +#include "SYS.h" + +SYSCALL(exchangedata, 0) + blr diff --git a/ppc/sys/execve.s b/ppc/sys/execve.s new file mode 100644 index 0000000..0c0172b --- /dev/null +++ b/ppc/sys/execve.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(execve, 3) + blr + diff --git a/ppc/sys/fchdir.s b/ppc/sys/fchdir.s new file mode 100644 index 0000000..19aa46e --- /dev/null +++ b/ppc/sys/fchdir.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(fchdir, 1) + blr + diff --git a/ppc/sys/fchflags.s b/ppc/sys/fchflags.s new file mode 100644 index 0000000..9e0749d --- /dev/null +++ b/ppc/sys/fchflags.s @@ -0,0 +1,25 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(fchflags, 2) + blr diff --git a/ppc/sys/fchmod.s b/ppc/sys/fchmod.s new file mode 100644 index 0000000..e4a0eb8 --- /dev/null +++ b/ppc/sys/fchmod.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(fchmod, 2) + blr + diff --git a/ppc/sys/fchown.s b/ppc/sys/fchown.s new file mode 100644 index 0000000..48b477b --- /dev/null +++ b/ppc/sys/fchown.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(fchown, 3) + blr + diff --git a/ppc/sys/fcntl.s b/ppc/sys/fcntl.s new file mode 100644 index 0000000..83a060c --- /dev/null +++ b/ppc/sys/fcntl.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(fcntl, 3) + blr + diff --git a/ppc/sys/flock.s b/ppc/sys/flock.s new file mode 100644 index 0000000..c422536 --- /dev/null +++ b/ppc/sys/flock.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(flock, 2) + blr + diff --git a/ppc/sys/fork.s b/ppc/sys/fork.s new file mode 100644 index 0000000..fc038ab --- /dev/null +++ b/ppc/sys/fork.s @@ -0,0 +1,165 @@ +/* + * Copyright (c) 1999 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@ + */ +/* Copyright (c) 1992 NeXT Computer, Inc. All rights reserved. + * + * File: libc/ppc/sys/fork.s + * + * HISTORY + * 18-Nov-92 Ben Fathi (benf@next.com) + * Created from M88K sources + * + * 11-Jan-92 Peter King (king@next.com) + * Created from M68K sources + */ + +#import +#import +#import +#import + +/* We use 8 bytes for LOCAL_VAR(1) and LOCAL_VAR(2) */ +NESTED(_fork, 8, 0, 0, 0) + CALL_EXTERN(__cthread_fork_prepare) +#if defined(__DYNAMIC__) +.cstring +LC1: + .ascii "__dyld_fork_prepare\0" +.text + .align 2 + mflr r0 + bl 1f +1: mflr r3 + mtlr r0 + addis r3,r3,ha16(LC1-1b) + addi r3,r3,lo16(LC1-1b) + addi r4,r1,LOCAL_VAR(1) + bl __dyld_func_lookup + lwz r3,LOCAL_VAR(1)(r1) + mtspr ctr,r3 + bctrl +#endif + li r0,SYS_fork + sc + b Lbotch // error return + + cmpwi r4,0 + beq Lparent // parent, since a1 == 0 in parent, + // 1 in child +#if defined(__DYNAMIC__) +.cstring +LC3: + .ascii "__dyld_fork_child\0" +.text + .align 2 + mflr r0 + bl 1f +1: mflr r3 + mtlr r0 + addis r3,r3,ha16(LC3-1b) + addi r3,r3,lo16(LC3-1b) + addi r4,r1,LOCAL_VAR(1) + bl __dyld_func_lookup + lwz r3,LOCAL_VAR(1)(r1) + mtspr ctr,r3 + bctrl +#endif + li r3,0x0 // clear cached pid in child + REG_TO_EXTERN(r3,__current_pid) + CALL_EXTERN(_fork_mach_init) + CALL_EXTERN(__cthread_fork_child) +#if defined(__DYNAMIC__) +.cstring +LC4: + .ascii "__dyld_fork_child_final\0" +.text + .align 2 + mflr r0 + bl 1f +1: mflr r3 + mtlr r0 + addis r3,r3,ha16(LC4-1b) + addi r3,r3,lo16(LC4-1b) + addi r4,r1,LOCAL_VAR(1) + bl __dyld_func_lookup + lwz r3,LOCAL_VAR(1)(r1) + mtspr ctr,r3 + bctrl +#endif + + li r3,0 + b Lreturn + +Lparent: +#if defined(__DYNAMIC__) + stw r3,LOCAL_VAR(2)(r1) // save child pid + mflr r0 + bl 1f +1: mflr r3 + mtlr r0 + addis r3,r3,ha16(LC2-1b) + addi r3,r3,lo16(LC2-1b) + addi r4,r1,LOCAL_VAR(1) + bl __dyld_func_lookup + lwz r3,LOCAL_VAR(1)(r1) + mtspr ctr,r3 + bctrl +#endif + CALL_EXTERN(__cthread_fork_parent) +#if defined(__DYNAMIC__) + lwz r3,LOCAL_VAR(2)(r1) +#endif + b Lreturn + +Lbotch: +#if defined(__DYNAMIC__) +.cstring +LC2: + .ascii "__dyld_fork_parent\0" +.text + .align 2 + stw r3,LOCAL_VAR(2)(r1) // save error value + mflr r0 + bl 1f +1: mflr r3 + mtlr r0 + addis r3,r3,ha16(LC2-1b) + addi r3,r3,lo16(LC2-1b) + addi r4,r1,LOCAL_VAR(1) + bl __dyld_func_lookup + lwz r3,LOCAL_VAR(1)(r1) + mtspr ctr,r3 + bctrl + lwz r3,LOCAL_VAR(2)(r1) // restore error value for cerror + +#endif + CALL_EXTERN(cerror) + /* + * We use cthread_fork_parent() to clean up after a fork error + * (unlock cthreads and mailloc packages) so the parent + * process can Malloc() after fork() errors without + * deadlocking. + */ + CALL_EXTERN_AGAIN(__cthread_fork_parent) + li32 r3,-1 // error return +Lreturn: RETURN +END(_fork) + diff --git a/ppc/sys/fpathconf.s b/ppc/sys/fpathconf.s new file mode 100644 index 0000000..a4666fc --- /dev/null +++ b/ppc/sys/fpathconf.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(fpathconf, 2) + blr + diff --git a/ppc/sys/fstat.s b/ppc/sys/fstat.s new file mode 100644 index 0000000..dcc424a --- /dev/null +++ b/ppc/sys/fstat.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(fstat, 2) + blr + diff --git a/ppc/sys/fstatfs.s b/ppc/sys/fstatfs.s new file mode 100644 index 0000000..27b0ad3 --- /dev/null +++ b/ppc/sys/fstatfs.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(fstatfs, 2) + blr + diff --git a/ppc/sys/fstatv.s b/ppc/sys/fstatv.s new file mode 100644 index 0000000..57cded8 --- /dev/null +++ b/ppc/sys/fstatv.s @@ -0,0 +1,27 @@ +/* + * Copyright (c) 1999 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@ + */ +/* Copyright 1998 Apple Computer, Inc. */ + +#include "SYS.h" + +SYSCALL(fstatv, 0) + blr diff --git a/ppc/sys/fsync.s b/ppc/sys/fsync.s new file mode 100644 index 0000000..5ff3afa --- /dev/null +++ b/ppc/sys/fsync.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(fsync, 1) + blr + diff --git a/ppc/sys/ftruncate.s b/ppc/sys/ftruncate.s new file mode 100644 index 0000000..30eb15c --- /dev/null +++ b/ppc/sys/ftruncate.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(ftruncate, 2) + blr + diff --git a/ppc/sys/futimes.s b/ppc/sys/futimes.s new file mode 100644 index 0000000..478a8af --- /dev/null +++ b/ppc/sys/futimes.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(futimes, 2) + blr + diff --git a/ppc/sys/genassym.c b/ppc/sys/genassym.c new file mode 100644 index 0000000..ca608b1 --- /dev/null +++ b/ppc/sys/genassym.c @@ -0,0 +1,205 @@ +/* + * Copyright (c) 1999 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@ + */ +#import +#import +#import +#import + +#import "genassym.h" + +#define NAME_LEN 30 + +char *progname; + +unsigned bit_num(char *reg_type, char *field, unsigned bits) +{ + unsigned bit; + unsigned mask; + + for (bit = 0, mask = 0x1; + (mask & bits) == 0 && mask; + mask <<= 1, bit += 1) + continue; + if (mask) + return bit; + fprintf(stderr, "%s: Bad BIT_POS for %s.%s\n", progname, + reg_type, field); + exit(1); +} + +unsigned field_width(char *reg_type, char *field, unsigned bits) +{ + unsigned width; + + while (bits && (bits & 0x1) == 0) + bits >>= 1; + for (width = 0; (bits & 0x1) == 1; bits >>= 1, width += 1) + continue; + if (bits == 0 && width) + return width; + fprintf(stderr, "%s: Bad BIT_FIELD for %s.%s\n", progname, + reg_type, field); + exit(1); +} + +unsigned log2(unsigned val, char *type) +{ + unsigned l2 = 0; + + if (val == 0) { + fprintf(stderr, "log2: sizeof(%s) is zero!\n", type); + exit(1); + } + while ((val & 0x1) == 0) { + l2 += 1; + val >>= 1; + } + if (val != 0x1) { + fprintf(stderr, "log2: sizeof(%s) is not power of two!\n", + type); + exit(1); + } + return l2; +} + +const char *skip_white(const char *cp) +{ + while (*cp && isspace(*cp)) + cp += 1; + return cp; +} + +const char *strip_prefix(const char *cp, const char *prefix) +{ + int len; + + cp = skip_white(cp); + len = strlen(prefix); + if (strncmp(cp, prefix, len) == 0 && isspace(*(cp+len))) + cp += len; + return cp; +} + +void +print_define(const char *prefix, const char *type_name, const char *field) +{ + const char *cp; + int col = 0; + + printf("#define\t"); + if (prefix != NULL && *prefix != '\0') { + printf("%s", prefix); + col += strlen(prefix); + } + if (type_name != NULL && *type_name != '\0') { + cp = strip_prefix(type_name, "struct"); + cp = strip_prefix(cp, "enum"); + cp = skip_white(cp); + if (*cp != '\0' && col != 0) { + putchar('_'); + col += 1; + } + for (; *cp != '\0'; cp++) { + if (isspace(*cp)) + break; + if (*cp == '*') + break; + if (strncmp(cp, "_t", 2) == 0 && !isalnum(cp[2])) + break; + putchar(isalpha(*cp) ? toupper(*cp) : *cp); + col += 1; + + } + } + if (field != NULL && *field != '\0') { + if (col != 0) { + putchar('_'); + col++; + } + for (cp = field; *cp != 0; cp++) { + if (*cp == '.') + putchar('_'); + else if (*cp == '[') + putchar('_'); + else if (*cp == ']') + continue; + else if (!isspace(*cp)) + putchar(isalpha(*cp) ? toupper(*cp) : *cp); + col++; + } + } + if (col == 0) { + fprintf(stderr, "%s: Bad call to print_define\n", progname); + exit(1); + } + do { + putchar(' '); + col += 1; + } while (col < NAME_LEN); +} + +void print_dec(int val) +{ + printf("%d\n", val); +} + +void print_hex(unsigned val) +{ + printf("%#010x\n", val); +} + +void print_str(const char *str) +{ + printf("%s\n", str); +} + +void comment(cmt_level_t level, const char *cmt) +{ + switch (level) { + case MAJOR: + printf("\n\n"); + printf("/*\n"); + printf(" * %s\n", cmt); + printf(" */\n"); + break; + case MINOR: + printf("\n"); + printf("/* %s */\n", cmt); + printf("\n"); + break; + default: + fprintf(stderr, "%s: Bad comment level\n", progname); + exit(1); + } +} + +void main(int argc, char **argv) +{ + progname = argv[0]; + + printf("/* assym.h -- generated by genassym */\n"); + printf("/* DON'T EDIT THIS -- change assymdefs.c */\n"); + + assymdefs(); + + exit(0); +} diff --git a/ppc/sys/genassym.h b/ppc/sys/genassym.h new file mode 100644 index 0000000..729dfa9 --- /dev/null +++ b/ppc/sys/genassym.h @@ -0,0 +1,126 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * genassym.h -- macros of use with genassym.c and assymdefs.c + */ + +#import +#import + +#define PRINT_OFFSET(ptr_type, field) \ +MACRO_BEGIN \ + print_define("", #ptr_type, #field); \ + print_hex((unsigned) &(((ptr_type)0)->field)); \ +MACRO_END + +#define PRINT_BIT_FIELD(reg_type, field) \ +MACRO_BEGIN \ + reg_type __reg; \ + CONTENTS(__reg) = 0; \ + __reg.field = (typeof (__reg.field)) -1; \ + print_define("", #reg_type, #field); \ + print_hex(CONTENTS(__reg)); \ +MACRO_END + +#define PRINT_ENUM(item) \ +MACRO_BEGIN \ + print_define("", "", #item); \ + print_hex((unsigned)item); \ +MACRO_END + +#define PRINT_DEFINE(macro) \ +MACRO_BEGIN \ + print_define("", "", #macro); \ + print_str(STRINGIFY(macro)); \ +MACRO_END + +#define PRINT_CONSTANT(macro) \ +MACRO_BEGIN \ + print_define("", "", #macro); \ + print_hex((unsigned)macro); \ +MACRO_END + +#define PRINT_REGADDR(macro) \ +MACRO_BEGIN \ + print_define("", "", #macro); \ + print_hex((unsigned) ¯o); \ +MACRO_END + +#define PRINT_REG_PAIR(struct_ptr, name0, name1) \ +MACRO_BEGIN \ + print_define("", #struct_ptr, #name0 "_" #name1); \ + print_hex((unsigned) &(((struct_ptr)0)->U_##name0##_##name1)); \ +MACRO_END + +#define PRINT_BIT_POS(reg_type, field) \ +MACRO_BEGIN \ + reg_type __reg; \ + CONTENTS(__reg) = 0; \ + __reg.field = 1; \ + print_define("", #reg_type, #field "_BIT"); \ + print_dec((int) bit_num(#reg_type, #field, CONTENTS(__reg))); \ +MACRO_END + +#define PRINT_FIELD_INFO(reg_type, field) \ +MACRO_BEGIN \ + reg_type __reg; \ + CONTENTS(__reg) = 0; \ + __reg.field = -1; \ + print_define("", #reg_type, #field "_OFF"); \ + print_dec((int) bit_num(#reg_type, #field, CONTENTS(__reg))); \ + print_define("", #reg_type, #field "_WIDTH"); \ + print_dec((int) field_width(#reg_type, #field, CONTENTS(__reg)));\ +MACRO_END + +#define PRINT_L2_SIZE(type) \ +MACRO_BEGIN \ + print_define("L2_SIZEOF", #type, ""); \ + print_dec((int) log2(sizeof(type), #type)); \ +MACRO_END + +#define PRINT_SIZEOF(type) \ +MACRO_BEGIN \ + print_define("SIZEOF", #type, ""); \ + print_dec((int) sizeof(type)); \ +MACRO_END + +#define PRINT_L2_CONSTANT(macro) \ +MACRO_BEGIN \ + print_define("L2", "", #macro); \ + print_dec((int) log2(macro, #macro)); \ +MACRO_END + +typedef enum { + MAJOR, MINOR +} cmt_level_t; + +extern void comment(cmt_level_t level, const char *cmt); +extern void print_define(const char *prefix, const char *type_name, + const char *field); +extern void print_dec(int val); +extern void print_hex(unsigned val); +extern void print_str(const char *str); +extern unsigned bit_num(char *reg_type, char *field, unsigned bits); +extern unsigned field_width(char *reg_type, char *field, unsigned bits); +extern unsigned log2(unsigned val, char *type); +extern void assymdefs(void); + diff --git a/ppc/sys/getattrlist.s b/ppc/sys/getattrlist.s new file mode 100644 index 0000000..b2b9a72 --- /dev/null +++ b/ppc/sys/getattrlist.s @@ -0,0 +1,27 @@ +/* + * Copyright (c) 1999 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@ + */ +/* Copyright 1998 Apple Computer, Inc. */ + +#include "SYS.h" + +SYSCALL(getattrlist, 0) + blr diff --git a/ppc/sys/getdirentries.s b/ppc/sys/getdirentries.s new file mode 100644 index 0000000..51e308b --- /dev/null +++ b/ppc/sys/getdirentries.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(getdirentries, 4) + blr + diff --git a/ppc/sys/getdirentriesattr.s b/ppc/sys/getdirentriesattr.s new file mode 100644 index 0000000..989b481 --- /dev/null +++ b/ppc/sys/getdirentriesattr.s @@ -0,0 +1,27 @@ +/* + * Copyright (c) 1999 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@ + */ +/* Copyright 1998 Apple Computer, Inc. */ + +#include "SYS.h" + +SYSCALL(getdirentriesattr, 0) + blr diff --git a/ppc/sys/getegid.s b/ppc/sys/getegid.s new file mode 100644 index 0000000..1d5959c --- /dev/null +++ b/ppc/sys/getegid.s @@ -0,0 +1,31 @@ +/* + * Copyright (c) 1999 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@ + */ +/* Copyright (c) 1992 NeXT Computer, Inc. All rights reserved. */ + +#import + +#import "SYS.h" + +PSEUDO(getegid,getgid,0) + mr a0,a1 + blr + diff --git a/ppc/sys/geteuid.s b/ppc/sys/geteuid.s new file mode 100644 index 0000000..fc71756 --- /dev/null +++ b/ppc/sys/geteuid.s @@ -0,0 +1,31 @@ +/* + * Copyright (c) 1999 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@ + */ +/* Copyright (c) 1992 NeXT Computer, Inc. All rights reserved. */ + +#import + +#import "SYS.h" + +PSEUDO(geteuid,getuid,0) + mr a0,a1 + blr + diff --git a/ppc/sys/getfh.s b/ppc/sys/getfh.s new file mode 100644 index 0000000..fb377fd --- /dev/null +++ b/ppc/sys/getfh.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(getfh, 2) + blr + diff --git a/ppc/sys/getfsstat.s b/ppc/sys/getfsstat.s new file mode 100644 index 0000000..0e013f8 --- /dev/null +++ b/ppc/sys/getfsstat.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(getfsstat, 3) + blr + diff --git a/ppc/sys/getgid.s b/ppc/sys/getgid.s new file mode 100644 index 0000000..79c52fe --- /dev/null +++ b/ppc/sys/getgid.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(getgid, 0) + blr + diff --git a/ppc/sys/getgroups.s b/ppc/sys/getgroups.s new file mode 100644 index 0000000..2284f9b --- /dev/null +++ b/ppc/sys/getgroups.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(getgroups, 2) + blr + diff --git a/ppc/sys/getitimer.s b/ppc/sys/getitimer.s new file mode 100644 index 0000000..35075cf --- /dev/null +++ b/ppc/sys/getitimer.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(getitimer, 2) + blr + diff --git a/ppc/sys/getpeername.s b/ppc/sys/getpeername.s new file mode 100644 index 0000000..ca29d16 --- /dev/null +++ b/ppc/sys/getpeername.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(getpeername, 3) + blr + diff --git a/ppc/sys/getpgid.s b/ppc/sys/getpgid.s new file mode 100644 index 0000000..fb6a4e4 --- /dev/null +++ b/ppc/sys/getpgid.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(getpgid, 1) + blr + diff --git a/ppc/sys/getpgrp.s b/ppc/sys/getpgrp.s new file mode 100644 index 0000000..ba45913 --- /dev/null +++ b/ppc/sys/getpgrp.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(getpgrp, 1) + blr + diff --git a/ppc/sys/getpid.s b/ppc/sys/getpid.s new file mode 100644 index 0000000..02e2b59 --- /dev/null +++ b/ppc/sys/getpid.s @@ -0,0 +1,53 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + .data + EXPORT(__current_pid) + .long 0 + +TEXT +LEAF(_getpid) +#if defined(__DYNAMIC__) + mflr r0 + bcl 20,31,1f +1: + mflr r5 + mtlr r0 + addis r5, r5, ha16(__current_pid - 1b) + addi r5, r5, lo16(__current_pid - 1b) +#else + lis r5,ha16(__current_pid) + ori r5,r5,lo16(__current_pid) +#endif + lwz r3,0(r5) // get the cached pid + cmpwi r3,0 // if positive, + bgtlr+ // return it + + SYSCALL_NONAME(getpid, 0) + + lwarx r4,0,r5 // see if we can cache it + cmpwi r4,0 // we cant if there are any + bltlr- // vforks in progress + + stwcx. r3,0,r5 // ignore cache conflicts + blr +END(_getpid) diff --git a/ppc/sys/getppid.s b/ppc/sys/getppid.s new file mode 100644 index 0000000..209b0b3 --- /dev/null +++ b/ppc/sys/getppid.s @@ -0,0 +1,31 @@ +/* + * Copyright (c) 1999 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@ + */ +/* Copyright (c) 1992 NeXT Computer, Inc. All rights reserved. */ + +#import + +#import "SYS.h" + +PSEUDO(getppid,getpid,0) + mr a0,a1 + blr + diff --git a/ppc/sys/getpriority.s b/ppc/sys/getpriority.s new file mode 100644 index 0000000..8235428 --- /dev/null +++ b/ppc/sys/getpriority.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(getpriority, 2) + blr + diff --git a/ppc/sys/getrlimit.s b/ppc/sys/getrlimit.s new file mode 100644 index 0000000..0f02bea --- /dev/null +++ b/ppc/sys/getrlimit.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(getrlimit, 2) + blr + diff --git a/ppc/sys/getrusage.s b/ppc/sys/getrusage.s new file mode 100644 index 0000000..c01f157 --- /dev/null +++ b/ppc/sys/getrusage.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(getrusage, 2) + blr + diff --git a/ppc/sys/getsid.s b/ppc/sys/getsid.s new file mode 100644 index 0000000..f6c262d --- /dev/null +++ b/ppc/sys/getsid.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(getsid, 1) + blr + diff --git a/ppc/sys/getsockname.s b/ppc/sys/getsockname.s new file mode 100644 index 0000000..df3ed97 --- /dev/null +++ b/ppc/sys/getsockname.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(getsockname, 3) + blr + diff --git a/ppc/sys/getsockopt.s b/ppc/sys/getsockopt.s new file mode 100644 index 0000000..6b90c2f --- /dev/null +++ b/ppc/sys/getsockopt.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(getsockopt, 5) + blr + diff --git a/ppc/sys/getuid.s b/ppc/sys/getuid.s new file mode 100644 index 0000000..45610de --- /dev/null +++ b/ppc/sys/getuid.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(getuid, 0) + blr + diff --git a/ppc/sys/ioctl.s b/ppc/sys/ioctl.s new file mode 100644 index 0000000..79347cf --- /dev/null +++ b/ppc/sys/ioctl.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(ioctl, 3) + blr + diff --git a/ppc/sys/issetugid.s b/ppc/sys/issetugid.s new file mode 100644 index 0000000..41bde6f --- /dev/null +++ b/ppc/sys/issetugid.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(issetugid, 0) + blr + diff --git a/ppc/sys/kill.s b/ppc/sys/kill.s new file mode 100644 index 0000000..244276e --- /dev/null +++ b/ppc/sys/kill.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(kill, 2) + blr + diff --git a/ppc/sys/ktrace.s b/ppc/sys/ktrace.s new file mode 100644 index 0000000..b396926 --- /dev/null +++ b/ppc/sys/ktrace.s @@ -0,0 +1,25 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(ktrace, 4) + blr diff --git a/ppc/sys/link.s b/ppc/sys/link.s new file mode 100644 index 0000000..741d98a --- /dev/null +++ b/ppc/sys/link.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(link, 2) + blr + diff --git a/ppc/sys/listen.s b/ppc/sys/listen.s new file mode 100644 index 0000000..3c01971 --- /dev/null +++ b/ppc/sys/listen.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(listen, 2) + blr + diff --git a/ppc/sys/load_shared_file.s b/ppc/sys/load_shared_file.s new file mode 100644 index 0000000..53b7c62 --- /dev/null +++ b/ppc/sys/load_shared_file.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(load_shared_file, 7) + blr + diff --git a/ppc/sys/longjmp.s b/ppc/sys/longjmp.s new file mode 100644 index 0000000..63d6806 --- /dev/null +++ b/ppc/sys/longjmp.s @@ -0,0 +1,63 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1998 Apple Computer, Inc. All rights reserved. + * + * File: sys/ppc/longjmp.s + * + * Implements siglongjmp(), longjmp(), _longjmp() + * + * NOTE: Scatterloading this file will BREAK the functions. + * + * History: + * 30-Aug-1998 Umesh Vaishampayan (umeshv@apple.com) + * Created. Derived from _setjmp.s, setjmp.c and setjmp.s + */ + +#include "SYS.h" +#include +#include "_setjmp.h" + +/* + * longjmp routines + */ + +/* void siglongjmp(sigjmp_buf env, int val); */ + +LEAF(_siglongjmp) + lwz r0, JMP_SIGFLAG(r3) ; load sigflag saved by siglongjmp() + cmpwi cr1,r0,0 ; this changes cr1[EQ] which is volatile + beq- cr1, L__longjmp ; if r0 == 0 do _longjmp() + ; else *** fall through *** to longjmp() + +/* void longjmp(jmp_buf env, int val); */ + +LEAF(_longjmp) +L_longjmp: + mr r30, r3 + mr r31, r4 + lwz r3, JMP_sig(r3) ; restore the signal mask + CALL_EXTERN(_sigsetmask) + mr r4, r31 + mr r3, r30 +L__longjmp: + BRANCH_EXTERN(__longjmp) diff --git a/ppc/sys/lseek.s b/ppc/sys/lseek.s new file mode 100644 index 0000000..0cce603 --- /dev/null +++ b/ppc/sys/lseek.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(lseek, 3) + blr + diff --git a/ppc/sys/lstat.s b/ppc/sys/lstat.s new file mode 100644 index 0000000..9454192 --- /dev/null +++ b/ppc/sys/lstat.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(lstat, 2) + blr + diff --git a/ppc/sys/lstatv.s b/ppc/sys/lstatv.s new file mode 100644 index 0000000..3c09ab4 --- /dev/null +++ b/ppc/sys/lstatv.s @@ -0,0 +1,27 @@ +/* + * Copyright (c) 1999 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@ + */ +/* Copyright 1998 Apple Computer, Inc. */ + +#include "SYS.h" + +SYSCALL(lstatv, 0) + blr diff --git a/ppc/sys/madvise.s b/ppc/sys/madvise.s new file mode 100644 index 0000000..1a0c3af --- /dev/null +++ b/ppc/sys/madvise.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* Copyright 1998 Apple Computer, Inc. */ + +#include "SYS.h" + +SYSCALL(madvise, 3) + blr + diff --git a/ppc/sys/mincore.s b/ppc/sys/mincore.s new file mode 100644 index 0000000..0c794cf --- /dev/null +++ b/ppc/sys/mincore.s @@ -0,0 +1,27 @@ +/* + * Copyright (c) 1999 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@ + */ +/* Copyright 1998 Apple Computer, Inc. */ + +#include "SYS.h" + +SYSCALL(mincore, 3) + blr diff --git a/ppc/sys/minherit.s b/ppc/sys/minherit.s new file mode 100644 index 0000000..a17397b --- /dev/null +++ b/ppc/sys/minherit.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(minherit, 3) + blr + diff --git a/ppc/sys/mkcomplex.s b/ppc/sys/mkcomplex.s new file mode 100644 index 0000000..011508b --- /dev/null +++ b/ppc/sys/mkcomplex.s @@ -0,0 +1,27 @@ +/* + * Copyright (c) 1999 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@ + */ +/* Copyright 1998 Apple Computer, Inc. */ + +#include "SYS.h" + +SYSCALL(mkcomplex, 0) + blr diff --git a/ppc/sys/mkdir.s b/ppc/sys/mkdir.s new file mode 100644 index 0000000..b9816c1 --- /dev/null +++ b/ppc/sys/mkdir.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(mkdir, 2) + blr + diff --git a/ppc/sys/mkfifo.s b/ppc/sys/mkfifo.s new file mode 100644 index 0000000..d8483c9 --- /dev/null +++ b/ppc/sys/mkfifo.s @@ -0,0 +1,25 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(mkfifo, 2) + blr diff --git a/ppc/sys/mknod.s b/ppc/sys/mknod.s new file mode 100644 index 0000000..9017fee --- /dev/null +++ b/ppc/sys/mknod.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(mknod, 3) + blr + diff --git a/ppc/sys/mlock.s b/ppc/sys/mlock.s new file mode 100644 index 0000000..3297c9e --- /dev/null +++ b/ppc/sys/mlock.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(mlock, 3) + blr + diff --git a/ppc/sys/mlockall.s b/ppc/sys/mlockall.s new file mode 100644 index 0000000..de14a8a --- /dev/null +++ b/ppc/sys/mlockall.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(mlockall, 3) + blr + diff --git a/ppc/sys/mmap.s b/ppc/sys/mmap.s new file mode 100644 index 0000000..b8dcac9 --- /dev/null +++ b/ppc/sys/mmap.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(mmap, 6) + blr + diff --git a/ppc/sys/mount.s b/ppc/sys/mount.s new file mode 100644 index 0000000..cf61211 --- /dev/null +++ b/ppc/sys/mount.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +/* Copyright (c) 1992 NeXT Computer, Inc. All rights reserved. */ + +#import +#import "SYS.h" + +SYSCALL(mount, 4) + blr diff --git a/ppc/sys/mprotect.s b/ppc/sys/mprotect.s new file mode 100644 index 0000000..a266bb5 --- /dev/null +++ b/ppc/sys/mprotect.s @@ -0,0 +1,27 @@ +/* + * Copyright (c) 1999 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@ + */ +/* Copyright 1998 Apple Computer, Inc. */ + +#include "SYS.h" + +SYSCALL(mprotect, 3) + blr diff --git a/ppc/sys/msgctl.s b/ppc/sys/msgctl.s new file mode 100644 index 0000000..a56f61d --- /dev/null +++ b/ppc/sys/msgctl.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(msgctl, 3) + blr + diff --git a/ppc/sys/msgget.s b/ppc/sys/msgget.s new file mode 100644 index 0000000..45aa533 --- /dev/null +++ b/ppc/sys/msgget.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(msgget, 3) + blr + diff --git a/ppc/sys/msgrcv.s b/ppc/sys/msgrcv.s new file mode 100644 index 0000000..9afa905 --- /dev/null +++ b/ppc/sys/msgrcv.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(msgrcv, 3) + blr + diff --git a/ppc/sys/msgsnd.s b/ppc/sys/msgsnd.s new file mode 100644 index 0000000..71d1954 --- /dev/null +++ b/ppc/sys/msgsnd.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(msgsnd, 3) + blr + diff --git a/ppc/sys/msgsys.s b/ppc/sys/msgsys.s new file mode 100644 index 0000000..7e0036f --- /dev/null +++ b/ppc/sys/msgsys.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(msgsys, 3) + blr + diff --git a/ppc/sys/msync.s b/ppc/sys/msync.s new file mode 100644 index 0000000..eb6fb6e --- /dev/null +++ b/ppc/sys/msync.s @@ -0,0 +1,27 @@ +/* + * Copyright (c) 1999 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@ + */ +/* Copyright 1998 Apple Computer, Inc. */ + +#include "SYS.h" + +SYSCALL(msync, 2) + blr diff --git a/ppc/sys/munlock.s b/ppc/sys/munlock.s new file mode 100644 index 0000000..1306a1f --- /dev/null +++ b/ppc/sys/munlock.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(munlock, 3) + blr + diff --git a/ppc/sys/munlockall.s b/ppc/sys/munlockall.s new file mode 100644 index 0000000..49f3585 --- /dev/null +++ b/ppc/sys/munlockall.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(munlockall, 3) + blr + diff --git a/ppc/sys/munmap.s b/ppc/sys/munmap.s new file mode 100644 index 0000000..7ea41da --- /dev/null +++ b/ppc/sys/munmap.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(munmap, 2) + blr + diff --git a/ppc/sys/new_system_shared_regions.s b/ppc/sys/new_system_shared_regions.s new file mode 100644 index 0000000..15c107e --- /dev/null +++ b/ppc/sys/new_system_shared_regions.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(new_system_shared_regions, 0) + blr + diff --git a/ppc/sys/nfssvc.s b/ppc/sys/nfssvc.s new file mode 100644 index 0000000..bf152ce --- /dev/null +++ b/ppc/sys/nfssvc.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(nfssvc, 1) + blr + diff --git a/ppc/sys/open.s b/ppc/sys/open.s new file mode 100644 index 0000000..31e98c7 --- /dev/null +++ b/ppc/sys/open.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(open, 3) + blr + diff --git a/ppc/sys/pathconf.s b/ppc/sys/pathconf.s new file mode 100644 index 0000000..443bdd7 --- /dev/null +++ b/ppc/sys/pathconf.s @@ -0,0 +1,25 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(pathconf, 2) + blr diff --git a/ppc/sys/pipe.s b/ppc/sys/pipe.s new file mode 100644 index 0000000..a26568d --- /dev/null +++ b/ppc/sys/pipe.s @@ -0,0 +1,33 @@ +/* + * Copyright (c) 1999 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@ + */ +/* Copyright (c) 1992 NeXT Computer, Inc. All rights reserved. */ + +#import "SYS.h" + +LEAF(_pipe) + stw r3,ARG(1)(r1) // preserve fildes on stack + SYSCALL_NONAME(pipe, 0) + lwz r11,ARG(1)(r1) // restore fildes + stw r3,0(r11) + stw r4,4(r11) + li r3,0 + blr diff --git a/ppc/sys/posix_madvise.s b/ppc/sys/posix_madvise.s new file mode 100644 index 0000000..259a9b4 --- /dev/null +++ b/ppc/sys/posix_madvise.s @@ -0,0 +1,27 @@ +/* + * Copyright (c) 1999 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@ + */ +/* Copyright 1998 Apple Computer, Inc. */ + +#include "SYS.h" + +PSEUDO(posix_madvise, madvise, 3) + blr diff --git a/ppc/sys/ppc_gettimeofday.s b/ppc/sys/ppc_gettimeofday.s new file mode 100644 index 0000000..5632789 --- /dev/null +++ b/ppc/sys/ppc_gettimeofday.s @@ -0,0 +1,42 @@ +/* + * Copyright (c) 1999 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@ + */ +/* Copyright 1998 Apple Computer, Inc. */ + +#include "SYS.h" + + .globl cerror +LEAF(___ppc_gettimeofday) + li r0,SYS_gettimeofday + mr r12,r3 + sc + b 1f + b 2f +1: BRANCH_EXTERN(cerror) +2: + mr. r12,r12 + beq 3f + stw r3,0(r12) + stw r4,4(r12) + li r3,0 +3: + blr + diff --git a/ppc/sys/pread.s b/ppc/sys/pread.s new file mode 100644 index 0000000..fcab3d5 --- /dev/null +++ b/ppc/sys/pread.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(pread, 4) + blr + diff --git a/ppc/sys/processor_facilities.h b/ppc/sys/processor_facilities.h new file mode 100644 index 0000000..f82e7a5 --- /dev/null +++ b/ppc/sys/processor_facilities.h @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2000 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@ + */ + +/* Does the current CPU have Altivec support? */ +extern int _cpu_has_altivec; + +/* What processor facilities is the current thread using? */ +#define floatUsed 0x40000000 +#define vectorUsed 0x20000000 + +extern int processor_facilities_used(void); diff --git a/ppc/sys/processor_facilities.s b/ppc/sys/processor_facilities.s new file mode 100644 index 0000000..87ebeb6 --- /dev/null +++ b/ppc/sys/processor_facilities.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2000 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@ + */ +.globl _processor_facilities_used +_processor_facilities_used: + li r0,0x7FF3 + sc + blr diff --git a/ppc/sys/profil.s b/ppc/sys/profil.s new file mode 100644 index 0000000..150565f --- /dev/null +++ b/ppc/sys/profil.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(profil, 4) + blr + diff --git a/ppc/sys/pthread_sigmask.s b/ppc/sys/pthread_sigmask.s new file mode 100644 index 0000000..69657d4 --- /dev/null +++ b/ppc/sys/pthread_sigmask.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(pthread_sigmask, 3) + blr + diff --git a/ppc/sys/ptrace.s b/ppc/sys/ptrace.s new file mode 100644 index 0000000..2bb6255 --- /dev/null +++ b/ppc/sys/ptrace.s @@ -0,0 +1,30 @@ +/* + * Copyright (c) 1999 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@ + */ +/* Copyright (c) 1992 NeXT Computer, Inc. All rights reserved. */ + +#import "SYS.h" + +LEAF(_ptrace) + li r7,0 + REG_TO_EXTERN(r7,_errno) +SYSCALL_NONAME(ptrace, 4) + blr diff --git a/ppc/sys/pwrite.s b/ppc/sys/pwrite.s new file mode 100644 index 0000000..f23bf5c --- /dev/null +++ b/ppc/sys/pwrite.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(pwrite, 4) + blr + diff --git a/ppc/sys/quota.s b/ppc/sys/quota.s new file mode 100644 index 0000000..d299496 --- /dev/null +++ b/ppc/sys/quota.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +#define SYS_quota 149 + +SYSCALL(quota, 4) + blr + diff --git a/ppc/sys/quotactl.s b/ppc/sys/quotactl.s new file mode 100644 index 0000000..78e71bc --- /dev/null +++ b/ppc/sys/quotactl.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(quotactl, 3) + blr + diff --git a/ppc/sys/read.s b/ppc/sys/read.s new file mode 100644 index 0000000..11ef4b7 --- /dev/null +++ b/ppc/sys/read.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(read, 3) + blr + diff --git a/ppc/sys/readlink.s b/ppc/sys/readlink.s new file mode 100644 index 0000000..48e113e --- /dev/null +++ b/ppc/sys/readlink.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(readlink, 3) + blr + diff --git a/ppc/sys/readv.s b/ppc/sys/readv.s new file mode 100644 index 0000000..b002966 --- /dev/null +++ b/ppc/sys/readv.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(readv, 3) + blr + diff --git a/ppc/sys/reboot.s b/ppc/sys/reboot.s new file mode 100644 index 0000000..90bc47b --- /dev/null +++ b/ppc/sys/reboot.s @@ -0,0 +1,27 @@ +/* + * Copyright (c) 1999 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@ + */ +/* Copyright (c) 1992 NeXT Computer, Inc. All rights reserved */ + +#import "SYS.h" + +SYSCALL(reboot, 2) + BRANCH_EXTERN(_abort) diff --git a/ppc/sys/recvfrom.s b/ppc/sys/recvfrom.s new file mode 100644 index 0000000..567b3e8 --- /dev/null +++ b/ppc/sys/recvfrom.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(recvfrom, 6) + blr + diff --git a/ppc/sys/recvmsg.s b/ppc/sys/recvmsg.s new file mode 100644 index 0000000..aeb5106 --- /dev/null +++ b/ppc/sys/recvmsg.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(recvmsg, 3) + blr + diff --git a/ppc/sys/rename.s b/ppc/sys/rename.s new file mode 100644 index 0000000..a2adfd0 --- /dev/null +++ b/ppc/sys/rename.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(rename, 2) + blr + diff --git a/ppc/sys/reset_shared_file.s b/ppc/sys/reset_shared_file.s new file mode 100644 index 0000000..a43aba6 --- /dev/null +++ b/ppc/sys/reset_shared_file.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(reset_shared_file, 3) + blr + diff --git a/ppc/sys/revoke.s b/ppc/sys/revoke.s new file mode 100644 index 0000000..3e2ae5a --- /dev/null +++ b/ppc/sys/revoke.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(revoke, 1) + blr + diff --git a/ppc/sys/rmdir.s b/ppc/sys/rmdir.s new file mode 100644 index 0000000..245e79d --- /dev/null +++ b/ppc/sys/rmdir.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(rmdir, 1) + blr + diff --git a/ppc/sys/s.template b/ppc/sys/s.template new file mode 100644 index 0000000..171d0ed --- /dev/null +++ b/ppc/sys/s.template @@ -0,0 +1,6 @@ +/* Copyright 1998 Apple Computer, Inc. */ + +#include "SYS.h" + +SYSCALL($FILENAMESANSEXTENSION$, 0) + blr diff --git a/ppc/sys/searchfs.s b/ppc/sys/searchfs.s new file mode 100644 index 0000000..6d04cda --- /dev/null +++ b/ppc/sys/searchfs.s @@ -0,0 +1,27 @@ +/* + * Copyright (c) 1999 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@ + */ +/* Copyright 1998 Apple Computer, Inc. */ + +#include "SYS.h" + +SYSCALL(searchfs, 0) + blr diff --git a/ppc/sys/select.s b/ppc/sys/select.s new file mode 100644 index 0000000..f23d513 --- /dev/null +++ b/ppc/sys/select.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(select, 5) + blr + diff --git a/ppc/sys/sem_close.s b/ppc/sys/sem_close.s new file mode 100644 index 0000000..cee016c --- /dev/null +++ b/ppc/sys/sem_close.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(sem_close, 1) + blr + diff --git a/ppc/sys/sem_destroy.s b/ppc/sys/sem_destroy.s new file mode 100644 index 0000000..b9339c0 --- /dev/null +++ b/ppc/sys/sem_destroy.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(sem_destroy, 1) + blr + diff --git a/ppc/sys/sem_getvalue.s b/ppc/sys/sem_getvalue.s new file mode 100644 index 0000000..72317b5 --- /dev/null +++ b/ppc/sys/sem_getvalue.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(sem_getvalue, 2) + blr + diff --git a/ppc/sys/sem_init.s b/ppc/sys/sem_init.s new file mode 100644 index 0000000..06fd281 --- /dev/null +++ b/ppc/sys/sem_init.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(sem_init, 3) + blr + diff --git a/ppc/sys/sem_open.s b/ppc/sys/sem_open.s new file mode 100644 index 0000000..c997c38 --- /dev/null +++ b/ppc/sys/sem_open.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(sem_open, 4) + blr + diff --git a/ppc/sys/sem_post.s b/ppc/sys/sem_post.s new file mode 100644 index 0000000..4c58ce4 --- /dev/null +++ b/ppc/sys/sem_post.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(sem_post, 1) + blr + diff --git a/ppc/sys/sem_trywait.s b/ppc/sys/sem_trywait.s new file mode 100644 index 0000000..7c0d846 --- /dev/null +++ b/ppc/sys/sem_trywait.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(sem_trywait, 1) + blr + diff --git a/ppc/sys/sem_unlink.s b/ppc/sys/sem_unlink.s new file mode 100644 index 0000000..9ddb3d8 --- /dev/null +++ b/ppc/sys/sem_unlink.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(sem_unlink, 1) + blr + diff --git a/ppc/sys/sem_wait.s b/ppc/sys/sem_wait.s new file mode 100644 index 0000000..c5d166d --- /dev/null +++ b/ppc/sys/sem_wait.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(sem_wait, 1) + blr + diff --git a/ppc/sys/semconfig.s b/ppc/sys/semconfig.s new file mode 100644 index 0000000..ac9fc2f --- /dev/null +++ b/ppc/sys/semconfig.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(semconfig, 3) + blr + diff --git a/ppc/sys/semctl.s b/ppc/sys/semctl.s new file mode 100644 index 0000000..847bd99 --- /dev/null +++ b/ppc/sys/semctl.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(semctl, 3) + blr + diff --git a/ppc/sys/semget.s b/ppc/sys/semget.s new file mode 100644 index 0000000..a5339bd --- /dev/null +++ b/ppc/sys/semget.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(semget, 3) + blr + diff --git a/ppc/sys/semop.s b/ppc/sys/semop.s new file mode 100644 index 0000000..bb743b3 --- /dev/null +++ b/ppc/sys/semop.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(semop, 3) + blr + diff --git a/ppc/sys/semsys.s b/ppc/sys/semsys.s new file mode 100644 index 0000000..a6c38d6 --- /dev/null +++ b/ppc/sys/semsys.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(semsys, 3) + blr + diff --git a/ppc/sys/sendmsg.s b/ppc/sys/sendmsg.s new file mode 100644 index 0000000..d5843d4 --- /dev/null +++ b/ppc/sys/sendmsg.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(sendmsg, 3) + blr + diff --git a/ppc/sys/sendto.s b/ppc/sys/sendto.s new file mode 100644 index 0000000..3ba2164 --- /dev/null +++ b/ppc/sys/sendto.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(sendto, 6) + blr + diff --git a/ppc/sys/setattrlist.s b/ppc/sys/setattrlist.s new file mode 100644 index 0000000..136332b --- /dev/null +++ b/ppc/sys/setattrlist.s @@ -0,0 +1,27 @@ +/* + * Copyright (c) 1999 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@ + */ +/* Copyright 1998 Apple Computer, Inc. */ + +#include "SYS.h" + +SYSCALL(setattrlist, 0) + blr diff --git a/ppc/sys/setegid.s b/ppc/sys/setegid.s new file mode 100644 index 0000000..c0c16f2 --- /dev/null +++ b/ppc/sys/setegid.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(setegid, 1) + blr + diff --git a/ppc/sys/seteuid.s b/ppc/sys/seteuid.s new file mode 100644 index 0000000..9ecfa30 --- /dev/null +++ b/ppc/sys/seteuid.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(seteuid, 1) + blr + diff --git a/ppc/sys/setgid.s b/ppc/sys/setgid.s new file mode 100644 index 0000000..eefae95 --- /dev/null +++ b/ppc/sys/setgid.s @@ -0,0 +1,25 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(setgid, 1) + blr diff --git a/ppc/sys/setgroups.s b/ppc/sys/setgroups.s new file mode 100644 index 0000000..ee55f69 --- /dev/null +++ b/ppc/sys/setgroups.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(setgroups, 2) + blr + diff --git a/ppc/sys/setitimer.s b/ppc/sys/setitimer.s new file mode 100644 index 0000000..26ba852 --- /dev/null +++ b/ppc/sys/setitimer.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(setitimer, 3) + blr + diff --git a/ppc/sys/setjmp.s b/ppc/sys/setjmp.s new file mode 100644 index 0000000..78fbc76 --- /dev/null +++ b/ppc/sys/setjmp.s @@ -0,0 +1,68 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1998 Apple Computer, Inc. All rights reserved. + * + * File: sys/ppc/setjmp.s + * + * Implements sigsetjmp(), setjmp(), _setjmp() + * + * NOTE: Scatterloading this file will BREAK the functions. + * + * History: + * 30-Aug-1998 Umesh Vaishampayan (umeshv@apple.com) + * Created. Derived from _setjmp.s, setjmp.c and setjmp.s + */ + +#include "SYS.h" +#include +#include "_setjmp.h" + +/* + * setjmp routines + */ + +/* int sigsetjmp(sigjmp_buf env, int savemask); */ + +LEAF(_sigsetjmp) + cmpwi cr1,r4,0 ; this changes cr1[EQ] which is volatile + stw r4, JMP_SIGFLAG(r3) ; save the sigflag for use by siglongjmp() + beq- cr1, L__setjmp ; if r4 == 0 do _setjmp() + ; else *** fall through *** to setjmp() + +/* int setjmp(jmp_buf env); */ + +LEAF(_setjmp) +L_setjmp: + mflr r0 + stw r31, JMP_r31(r3) + stw r0, JMP_lr(r3) + mr r31, r3 + li r3, 0 ; get the previous signal mask + CALL_EXTERN(_sigblock) + stw r3, JMP_sig(r31) ; save the previous mask + mr r3, r31 + lwz r0, JMP_lr(r3) + mtlr r0 + lwz r31, JMP_r31(r3) +L__setjmp: + BRANCH_EXTERN(__setjmp) diff --git a/ppc/sys/setpgid.s b/ppc/sys/setpgid.s new file mode 100644 index 0000000..55dea92 --- /dev/null +++ b/ppc/sys/setpgid.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(setpgid, 2) + blr + diff --git a/ppc/sys/setpriority.s b/ppc/sys/setpriority.s new file mode 100644 index 0000000..f550c21 --- /dev/null +++ b/ppc/sys/setpriority.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(setpriority, 3) + blr + diff --git a/ppc/sys/setprivexec.s b/ppc/sys/setprivexec.s new file mode 100644 index 0000000..dfcb10e --- /dev/null +++ b/ppc/sys/setprivexec.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(setprivexec, 3) + blr + diff --git a/ppc/sys/setquota.s b/ppc/sys/setquota.s new file mode 100644 index 0000000..edc8f40 --- /dev/null +++ b/ppc/sys/setquota.s @@ -0,0 +1,27 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +#define SYS_setquota 148 + +SYSCALL(setquota, 2) + blr diff --git a/ppc/sys/setrlimit.s b/ppc/sys/setrlimit.s new file mode 100644 index 0000000..36796f0 --- /dev/null +++ b/ppc/sys/setrlimit.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(setrlimit, 2) + blr + diff --git a/ppc/sys/setsid.s b/ppc/sys/setsid.s new file mode 100644 index 0000000..793019c --- /dev/null +++ b/ppc/sys/setsid.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(setsid, 0) + blr + diff --git a/ppc/sys/setsockopt.s b/ppc/sys/setsockopt.s new file mode 100644 index 0000000..a5eb732 --- /dev/null +++ b/ppc/sys/setsockopt.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(setsockopt, 5) + blr + diff --git a/ppc/sys/settimeofday.s b/ppc/sys/settimeofday.s new file mode 100644 index 0000000..322876f --- /dev/null +++ b/ppc/sys/settimeofday.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(settimeofday, 2) + blr + diff --git a/ppc/sys/setuid.s b/ppc/sys/setuid.s new file mode 100644 index 0000000..d9d5dff --- /dev/null +++ b/ppc/sys/setuid.s @@ -0,0 +1,25 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(setuid, 1) + blr diff --git a/ppc/sys/shm_open.s b/ppc/sys/shm_open.s new file mode 100644 index 0000000..28c8418 --- /dev/null +++ b/ppc/sys/shm_open.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(shm_open, 3) + blr + diff --git a/ppc/sys/shm_unlink.s b/ppc/sys/shm_unlink.s new file mode 100644 index 0000000..514dbf9 --- /dev/null +++ b/ppc/sys/shm_unlink.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(shm_unlink, 3) + blr + diff --git a/ppc/sys/shmat.s b/ppc/sys/shmat.s new file mode 100644 index 0000000..f0752cc --- /dev/null +++ b/ppc/sys/shmat.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(shmat, 3) + blr + diff --git a/ppc/sys/shmctl.s b/ppc/sys/shmctl.s new file mode 100644 index 0000000..ef50a7f --- /dev/null +++ b/ppc/sys/shmctl.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(shmctl, 3) + blr + diff --git a/ppc/sys/shmdt.s b/ppc/sys/shmdt.s new file mode 100644 index 0000000..ca48fc6 --- /dev/null +++ b/ppc/sys/shmdt.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(shmdt, 3) + blr + diff --git a/ppc/sys/shmget.s b/ppc/sys/shmget.s new file mode 100644 index 0000000..c9237ed --- /dev/null +++ b/ppc/sys/shmget.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(shmget, 3) + blr + diff --git a/ppc/sys/shmsys.s b/ppc/sys/shmsys.s new file mode 100644 index 0000000..846b113 --- /dev/null +++ b/ppc/sys/shmsys.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(shmsys, 3) + blr + diff --git a/ppc/sys/shutdown.s b/ppc/sys/shutdown.s new file mode 100644 index 0000000..65970a1 --- /dev/null +++ b/ppc/sys/shutdown.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(shutdown, 2) + blr + diff --git a/ppc/sys/sigaltstack.s b/ppc/sys/sigaltstack.s new file mode 100644 index 0000000..1e28861 --- /dev/null +++ b/ppc/sys/sigaltstack.s @@ -0,0 +1,25 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(sigaltstack, 3) + blr diff --git a/ppc/sys/sigpending.s b/ppc/sys/sigpending.s new file mode 100644 index 0000000..8da6e14 --- /dev/null +++ b/ppc/sys/sigpending.s @@ -0,0 +1,25 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(sigpending, 1) + blr diff --git a/ppc/sys/sigprocmask.s b/ppc/sys/sigprocmask.s new file mode 100644 index 0000000..08ee95f --- /dev/null +++ b/ppc/sys/sigprocmask.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(sigprocmask, 3) + blr + diff --git a/ppc/sys/sigreturn.s b/ppc/sys/sigreturn.s new file mode 100644 index 0000000..2f7f0f3 --- /dev/null +++ b/ppc/sys/sigreturn.s @@ -0,0 +1,54 @@ +/* + * Copyright (c) 1999 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@ + */ +/* Copyright (c) 1992 NeXT Computer, Inc. All rights reserved. + * + * File: libc/m98k/sys/sigreturn.s + * + * The sigreturn() system call. + * + * The M98K sigcontext structure is more robust than older cousins. + * This routine is responsible for restoring register state + * based on the setting of sc_regs_saved before trapping into the + * kernel. See + * + * HISTORY + * 18-Nov-92 Ben Fathi (benf@next.com) + * Ported to m98k. + * + * 13-Jan-92 Peter King (king@next.com) + * Created. + */ + +#import "assym.h" +#import "SYS.h" + +/* + * r3 = sigcontext pointer + */ + +LEAF(_sigreturn) + + /* Now call the kernel routine to restore the rest */ + + SYSCALL_NONAME(sigreturn, 1) + blr +END(_sigreturn) diff --git a/ppc/sys/sigwait.s b/ppc/sys/sigwait.s new file mode 100644 index 0000000..a879b4d --- /dev/null +++ b/ppc/sys/sigwait.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(sigwait, 2) + blr + diff --git a/ppc/sys/socket.s b/ppc/sys/socket.s new file mode 100644 index 0000000..db1141a --- /dev/null +++ b/ppc/sys/socket.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(socket, 3) + blr + diff --git a/ppc/sys/socketpair.s b/ppc/sys/socketpair.s new file mode 100644 index 0000000..55e96dc --- /dev/null +++ b/ppc/sys/socketpair.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(socketpair, 5) + blr + diff --git a/ppc/sys/stat.s b/ppc/sys/stat.s new file mode 100644 index 0000000..4b731d4 --- /dev/null +++ b/ppc/sys/stat.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(stat, 2) + blr + diff --git a/ppc/sys/statfs.s b/ppc/sys/statfs.s new file mode 100644 index 0000000..e2833c3 --- /dev/null +++ b/ppc/sys/statfs.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(statfs, 2) + blr + diff --git a/ppc/sys/statv.s b/ppc/sys/statv.s new file mode 100644 index 0000000..1979fea --- /dev/null +++ b/ppc/sys/statv.s @@ -0,0 +1,27 @@ +/* + * Copyright (c) 1999 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@ + */ +/* Copyright 1998 Apple Computer, Inc. */ + +#include "SYS.h" + +SYSCALL(statv, 0) + blr diff --git a/ppc/sys/swapon.s b/ppc/sys/swapon.s new file mode 100644 index 0000000..b6af343 --- /dev/null +++ b/ppc/sys/swapon.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(swapon, 1) + blr + diff --git a/ppc/sys/symlink.s b/ppc/sys/symlink.s new file mode 100644 index 0000000..9c8bb6e --- /dev/null +++ b/ppc/sys/symlink.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(symlink, 2) + blr + diff --git a/ppc/sys/sync.s b/ppc/sys/sync.s new file mode 100644 index 0000000..308892e --- /dev/null +++ b/ppc/sys/sync.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(sync, 0) + blr + diff --git a/ppc/sys/syscall.s b/ppc/sys/syscall.s new file mode 100644 index 0000000..fec2d28 --- /dev/null +++ b/ppc/sys/syscall.s @@ -0,0 +1,27 @@ +/* + * Copyright (c) 1999 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@ + */ +/* Copyright (c) 1992 NeXT Computer, Inc. All rights reserved. */ + +#include "SYS.h" + +PSEUDO(syscall, syscall, 7) + blr diff --git a/ppc/sys/systable.s b/ppc/sys/systable.s new file mode 100644 index 0000000..6c24f1c --- /dev/null +++ b/ppc/sys/systable.s @@ -0,0 +1,25 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(table, 5) + blr diff --git a/ppc/sys/truncate.s b/ppc/sys/truncate.s new file mode 100644 index 0000000..0b43058 --- /dev/null +++ b/ppc/sys/truncate.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(truncate, 2) + blr + diff --git a/ppc/sys/umask.s b/ppc/sys/umask.s new file mode 100644 index 0000000..b5b594b --- /dev/null +++ b/ppc/sys/umask.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(umask, 1) + blr + diff --git a/ppc/sys/undelete.s b/ppc/sys/undelete.s new file mode 100644 index 0000000..d26927f --- /dev/null +++ b/ppc/sys/undelete.s @@ -0,0 +1,25 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(undelete, 1) + blr diff --git a/ppc/sys/unlink.s b/ppc/sys/unlink.s new file mode 100644 index 0000000..ef6071a --- /dev/null +++ b/ppc/sys/unlink.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(unlink, 1) + blr + diff --git a/ppc/sys/unmount.s b/ppc/sys/unmount.s new file mode 100644 index 0000000..20e114b --- /dev/null +++ b/ppc/sys/unmount.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(unmount, 1) + blr + diff --git a/ppc/sys/ur_cthread.s b/ppc/sys/ur_cthread.s new file mode 100644 index 0000000..50ff2be --- /dev/null +++ b/ppc/sys/ur_cthread.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1999 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@ + */ + .text + .align 2 + .globl _pthread_self +_pthread_self: + li r0, 0x7FF2 + sc + blr diff --git a/ppc/sys/utimes.s b/ppc/sys/utimes.s new file mode 100644 index 0000000..abb5f14 --- /dev/null +++ b/ppc/sys/utimes.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(utimes, 2) + blr + diff --git a/ppc/sys/vfork.s b/ppc/sys/vfork.s new file mode 100644 index 0000000..99aff4d --- /dev/null +++ b/ppc/sys/vfork.s @@ -0,0 +1,211 @@ +/* + * Copyright (c) 1999 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@ + */ +/* Copyright (c) 1998 Apple Computer, Inc. All rights reserved. + * + * File: libc/ppc/sys/vfork.s + * + * HISTORY + * 23-Jun-1998 Umesh Vaishampayan (umeshv@apple.com) + * Created from fork.s + * + */ +#if 0 +#import +#import +#import +#import + +/* We use 8 bytes for LOCAL_VAR(1) and LOCAL_VAR(2) */ +NESTED(_vfork, 8, 0, 0, 0) + CALL_EXTERN(__cthread_fork_prepare) +#if defined(__DYNAMIC__) +.cstring +LC1: + .ascii "__dyld_fork_prepare\0" +.text + .align 2 + mflr r0 + bl 1f +1: mflr r3 + mtlr r0 + addis r3,r3,ha16(LC1-1b) + addi r3,r3,lo16(LC1-1b) + addi r4,r1,LOCAL_VAR(1) + bl __dyld_func_lookup + lwz r3,LOCAL_VAR(1)(r1) + mtspr ctr,r3 + bctrl +#endif + li r0,SYS_vfork + sc + b Lbotch // error return + + cmpwi r4,0 + beq Lparent // parent, since a1 == 0 in parent, + // 1 in child +#if defined(__DYNAMIC__) +.cstring +LC3: + .ascii "__dyld_fork_child\0" +.text + .align 2 + mflr r0 + bl 1f +1: mflr r3 + mtlr r0 + addis r3,r3,ha16(LC3-1b) + addi r3,r3,lo16(LC3-1b) + addi r4,r1,LOCAL_VAR(1) + bl __dyld_func_lookup + lwz r3,LOCAL_VAR(1)(r1) + mtspr ctr,r3 + bctrl +#endif + li r3,0 + REG_TO_EXTERN(r3, EXT(_current_pid)) + CALL_EXTERN(_fork_mach_init) + CALL_EXTERN(__cthread_fork_child) +#if defined(__DYNAMIC__) +.cstring +LC4: + .ascii "__dyld_fork_child_final\0" +.text + .align 2 + mflr r0 + bl 1f +1: mflr r3 + mtlr r0 + addis r3,r3,ha16(LC4-1b) + addi r3,r3,lo16(LC4-1b) + addi r4,r1,LOCAL_VAR(1) + bl __dyld_func_lookup + lwz r3,LOCAL_VAR(1)(r1) + mtspr ctr,r3 + bctrl +#endif + + li r3,0 + b Lreturn + +Lparent: +#if defined(__DYNAMIC__) + stw r3,LOCAL_VAR(2)(r1) // save child pid + mflr r0 + bl 1f +1: mflr r3 + mtlr r0 + addis r3,r3,ha16(LC2-1b) + addi r3,r3,lo16(LC2-1b) + addi r4,r1,LOCAL_VAR(1) + bl __dyld_func_lookup + lwz r3,LOCAL_VAR(1)(r1) + mtspr ctr,r3 + bctrl +#endif + CALL_EXTERN(__cthread_fork_parent) +#if defined(__DYNAMIC__) + lwz r3,LOCAL_VAR(2)(r1) +#endif + b Lreturn + +Lbotch: +#if defined(__DYNAMIC__) +.cstring +LC2: + .ascii "__dyld_fork_parent\0" +.text + .align 2 + stw r3,LOCAL_VAR(2)(r1) // save error value + mflr r0 + bl 1f +1: mflr r3 + mtlr r0 + addis r3,r3,ha16(LC2-1b) + addi r3,r3,lo16(LC2-1b) + addi r4,r1,LOCAL_VAR(1) + bl __dyld_func_lookup + lwz r3,LOCAL_VAR(1)(r1) + mtspr ctr,r3 + bctrl + lwz r3,LOCAL_VAR(2)(r1) // restore error value for cerror + +#endif + CALL_EXTERN(cerror) + /* + * We use cthread_fork_parent() to clean up after a fork error + * (unlock cthreads and mailloc packages) so the parent + * process can Malloc() after fork() errors without + * deadlocking. + */ + CALL_EXTERN_AGAIN(__cthread_fork_parent) + li32 r3,-1 // error return +Lreturn: RETURN +END(_vfork) +#else +#include "SYS.h" + +LEAF(_vfork) +#if defined(__DYNAMIC__) + PICIFY(__current_pid) + mr r5,PICIFY_REG + NON_LAZY_STUB(__current_pid) +#else + lis r5,ha16(__current_pid) + ori r5,r5,lo16(__current_pid) +#endif +2: + lwarx r6,0,r5 // dont cache pid across vfork + cmpwi r6,0 + ble- 3f // is another vfork in progress + li r6,0 // if not, erase the stored pid +3: + addi r6,r6,-1 // count the parallel vforks in + stwcx. r6,0,r5 // negative cached pid values + bne- 2b + + li r0,SYS_vfork + sc + b Lbotch // error return + + cmpwi r4,0 + beq Lparent // parent, since a1 == 0 in parent, + + li r3,0 // child + blr + +Lparent: + lwarx r6,0,r5 // were back, decrement vfork count + addi r6,r6,1 + stwcx. r6,0,r5 + bne- Lparent + blr + +Lbotch: + lwarx r6,0,r5 // never went, decrement vfork count + addi r6,r6,1 + stwcx. r6,0,r5 + bne- Lbotch + + BRANCH_EXTERN(cerror) +END(_vfork) +#endif + diff --git a/ppc/sys/wait4.s b/ppc/sys/wait4.s new file mode 100644 index 0000000..56c6921 --- /dev/null +++ b/ppc/sys/wait4.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(wait4, 4) + blr + diff --git a/ppc/sys/write.s b/ppc/sys/write.s new file mode 100644 index 0000000..ef0833d --- /dev/null +++ b/ppc/sys/write.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(write, 3) + blr + diff --git a/ppc/sys/writev.s b/ppc/sys/writev.s new file mode 100644 index 0000000..499ce7f --- /dev/null +++ b/ppc/sys/writev.s @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1999 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@ + */ +#include "SYS.h" + +SYSCALL(writev, 3) + blr + diff --git a/pthreads.subproj/Makefile b/pthreads.subproj/Makefile deleted file mode 100644 index 5aaeca9..0000000 --- a/pthreads.subproj/Makefile +++ /dev/null @@ -1,63 +0,0 @@ -# -# Generated by the NeXT Project Builder. -# -# NOTE: Do NOT change this file -- Project Builder maintains it. -# -# Put all of your customizations in files called Makefile.preamble -# and Makefile.postamble (both optional), and Makefile will include them. -# - -NAME = pthreads - -PROJECTVERSION = 2.8 -PROJECT_TYPE = Component - -HFILES = posix_sched.h pthread.h pthread_impl.h pthread_internals.h\ - pthread_machdep.h sched.h - -OTHERLINKED = lock.s stack.s - -CFILES = pthread.c pthread_cond.c pthread_mutex.c pthread_tsd.c\ - thread_setup.c - -OTHERSRCS = Makefile.preamble Makefile Makefile.postamble\ - mk_pthread_impl.c - -OTHERLINKEDOFILES = lock.o stack.o - -MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles -CODE_GEN_STYLE = DYNAMIC -MAKEFILE = subproj.make -NEXTSTEP_INSTALLDIR = /Local/Developer/System -LIBS = -DEBUG_LIBS = $(LIBS) -PROF_LIBS = $(LIBS) - - -NEXTSTEP_PB_CFLAGS = -D__POSIX_LIB__ -PUBLIC_HEADERS = sched.h pthread_impl.h pthread.h - -PROJECT_HEADERS = pthread_internals.h sched.h pthread_impl.h pthread.h - - - -NEXTSTEP_BUILD_OUTPUT_DIR = /Local/Public/Sandbox/$(USER)/BUILD/$(NAME) - -NEXTSTEP_PUBLIC_HEADERS_DIR = /usr/include - -NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc -WINDOWS_OBJCPLUS_COMPILER = $(DEVDIR)/gcc -PDO_UNIX_OBJCPLUS_COMPILER = $(NEXTDEV_BIN)/gcc -NEXTSTEP_JAVA_COMPILER = /usr/bin/javac -WINDOWS_JAVA_COMPILER = $(JDKBINDIR)/javac.exe -PDO_UNIX_JAVA_COMPILER = $(JDKBINDIR)/javac - -include $(MAKEFILEDIR)/platform.make - --include Makefile.preamble - -include $(MAKEFILEDIR)/$(MAKEFILE) - --include Makefile.postamble - --include Makefile.dependencies diff --git a/pthreads.subproj/Makefile.postamble b/pthreads.subproj/Makefile.postamble deleted file mode 100644 index 411cde6..0000000 --- a/pthreads.subproj/Makefile.postamble +++ /dev/null @@ -1,100 +0,0 @@ -############################################################################### -# Makefile.postamble -# Copyright 1997, Apple Computer, Inc. -# -# Use this makefile, which is imported after all other makefiles, to -# override attributes for a project's Makefile environment. This allows you -# to take advantage of the environment set up by the other Makefiles. -# You can also define custom rules at the end of this file. -# -############################################################################### -# -# These variables are exported by the standard makefiles and can be -# used in any customizations you make. They are *outputs* of -# the Makefiles and should be used, not set. -# -# PRODUCTS: products to install. All of these products will be placed in -# the directory $(DSTROOT)$(INSTALLDIR) -# GLOBAL_RESOURCE_DIR: The directory to which resources are copied. -# LOCAL_RESOURCE_DIR: The directory to which localized resources are copied. -# OFILE_DIR: Directory into which .o object files are generated. -# DERIVED_SRC_DIR: Directory used for all other derived files -# -# ALL_CFLAGS: flags to pass when compiling .c files -# ALL_MFLAGS: flags to pass when compiling .m files -# ALL_CCFLAGS: flags to pass when compiling .cc, .cxx, and .C files -# ALL_MMFLAGS: flags to pass when compiling .mm, .mxx, and .M files -# ALL_PRECOMPFLAGS: flags to pass when precompiling .h files -# ALL_LDFLAGS: flags to pass when linking object files -# ALL_LIBTOOL_FLAGS: flags to pass when libtooling object files -# ALL_PSWFLAGS: flags to pass when processing .psw and .pswm (pswrap) files -# ALL_RPCFLAGS: flags to pass when processing .rpc (rpcgen) files -# ALL_YFLAGS: flags to pass when processing .y (yacc) files -# ALL_LFLAGS: flags to pass when processing .l (lex) files -# -# NAME: name of application, bundle, subproject, palette, etc. -# LANGUAGES: langages in which the project is written (default "English") -# English_RESOURCES: localized resources (e.g. nib's, images) of project -# GLOBAL_RESOURCES: non-localized resources of project -# -# SRCROOT: base directory in which to place the new source files -# SRCPATH: relative path from SRCROOT to present subdirectory -# -# INSTALLDIR: Directory the product will be installed into by 'install' target -# PUBLIC_HDR_INSTALLDIR: where to install public headers. Don't forget -# to prefix this with DSTROOT when you use it. -# PRIVATE_HDR_INSTALLDIR: where to install private headers. Don't forget -# to prefix this with DSTROOT when you use it. -# -# EXECUTABLE_EXT: Executable extension for the platform (i.e. .exe on Windows) -# -############################################################################### - -# Some compiler flags can be overridden here for certain build situations. -# -# WARNING_CFLAGS: flag used to set warning level (defaults to -Wmost) -# DEBUG_SYMBOLS_CFLAGS: debug-symbol flag passed to all builds (defaults -# to -g) -# DEBUG_BUILD_CFLAGS: flags passed during debug builds (defaults to -DDEBUG) -# OPTIMIZE_BUILD_CFLAGS: flags passed during optimized builds (defaults -# to -O) -# PROFILE_BUILD_CFLAGS: flags passed during profile builds (defaults -# to -pg -DPROFILE) -# LOCAL_DIR_INCLUDE_DIRECTIVE: flag used to add current directory to -# the include path (defaults to -I.) -# DEBUG_BUILD_LDFLAGS, OPTIMIZE_BUILD_LDFLAGS, PROFILE_BUILD_LDFLAGS: flags -# passed to ld/libtool (defaults to nothing) - - -# Library and Framework projects only: -# INSTALL_NAME_DIRECTIVE: This directive ensures that executables linked -# against the framework will run against the correct version even if -# the current version of the framework changes. You may override this -# to "" as an alternative to using the DYLD_LIBRARY_PATH during your -# development cycle, but be sure to restore it before installing. - - -# Ownership and permissions of files installed by 'install' target - -#INSTALL_AS_USER = root - # User/group ownership -#INSTALL_AS_GROUP = wheel - # (probably want to set both of these) -#INSTALL_PERMISSIONS = - # If set, 'install' chmod's executable to this - - -# Options to strip. Note: -S strips debugging symbols (executables can be stripped -# down further with -x or, if they load no bundles, with no options at all). - -#STRIPFLAGS = -S - - -######################################################################### -# Put rules to extend the behavior of the standard Makefiles here. Include them in -# the dependency tree via cvariables like AFTER_INSTALL in the Makefile.preamble. -# -# You should avoid redefining things like "install" or "app", as they are -# owned by the top-level Makefile API and no context has been set up for where -# derived files should go. -# diff --git a/pthreads.subproj/Makefile.preamble b/pthreads.subproj/Makefile.preamble deleted file mode 100644 index c1624b4..0000000 --- a/pthreads.subproj/Makefile.preamble +++ /dev/null @@ -1,137 +0,0 @@ -############################################################################### -# Makefile.preamble -# Copyright 1997, Apple Computer, Inc. -# -# Use this makefile for configuring the standard application makefiles -# associated with ProjectBuilder. It is included before the main makefile. -# In Makefile.preamble you set attributes for a project, so they are available -# to the project's makefiles. In contrast, you typically write additional rules or -# override built-in behavior in the Makefile.postamble. -# -# Each directory in a project tree (main project plus subprojects) should -# have its own Makefile.preamble and Makefile.postamble. -############################################################################### -# -# Before the main makefile is included for this project, you may set: -# -# MAKEFILEDIR: Directory in which to find $(MAKEFILE) -# MAKEFILE: Top level mechanism Makefile (e.g., app.make, bundle.make) - -# Compiler/linker flags added to the defaults: The OTHER_* variables will be -# inherited by all nested sub-projects, but the LOCAL_ versions of the same -# variables will not. Put your -I, -D, -U, and -L flags in ProjectBuilder's -# Build Attributes inspector if at all possible. To override the default flags -# that get passed to ${CC} (e.g. change -O to -O2), see Makefile.postamble. The -# variables below are *inputs* to the build process and distinct from the override -# settings done (less often) in the Makefile.postamble. -# -# OTHER_CFLAGS, LOCAL_CFLAGS: additional flags to pass to the compiler -# Note that $(OTHER_CFLAGS) and $(LOCAL_CFLAGS) are used for .h, ...c, .m, -# .cc, .cxx, .C, and .M files. There is no need to respecify the -# flags in OTHER_MFLAGS, etc. -# OTHER_MFLAGS, LOCAL_MFLAGS: additional flags for .m files -# OTHER_CCFLAGS, LOCAL_CCFLAGS: additional flags for .cc, .cxx, and ...C files -# OTHER_MMFLAGS, LOCAL_MMFLAGS: additional flags for .mm and .M files -# OTHER_PRECOMPFLAGS, LOCAL_PRECOMPFLAGS: additional flags used when -# precompiling header files -# OTHER_LDFLAGS, LOCAL_LDFLAGS: additional flags passed to ld and libtool -# OTHER_PSWFLAGS, LOCAL_PSWFLAGS: additional flags passed to pswrap -# OTHER_RPCFLAGS, LOCAL_RPCFLAGS: additional flags passed to rpcgen -# OTHER_YFLAGS, LOCAL_YFLAGS: additional flags passed to yacc -# OTHER_LFLAGS, LOCAL_LFLAGS: additional flags passed to lex - -# These variables provide hooks enabling you to add behavior at almost every -# stage of the make: -# -# BEFORE_PREBUILD: targets to build before installing headers for a subproject -# AFTER_PREBUILD: targets to build after installing headers for a subproject -# BEFORE_BUILD_RECURSION: targets to make before building subprojects -# BEFORE_BUILD: targets to make before a build, but after subprojects -# AFTER_BUILD: targets to make after a build -# -# BEFORE_INSTALL: targets to build before installing the product -# AFTER_INSTALL: targets to build after installing the product -# BEFORE_POSTINSTALL: targets to build before postinstalling every subproject -# AFTER_POSTINSTALL: targts to build after postinstalling every subproject -# -# BEFORE_INSTALLHDRS: targets to build before installing headers for a -# subproject -# AFTER_INSTALLHDRS: targets to build after installing headers for a subproject -# BEFORE_INSTALLSRC: targets to build before installing source for a subproject -# AFTER_INSTALLSRC: targets to build after installing source for a subproject -# -# BEFORE_DEPEND: targets to build before building dependencies for a -# subproject -# AFTER_DEPEND: targets to build after building dependencies for a -# subproject -# -# AUTOMATIC_DEPENDENCY_INFO: if YES, then the dependency file is -# updated every time the project is built. If NO, the dependency -# file is only built when the depend target is invoked. - -# Framework-related variables: -# FRAMEWORK_DLL_INSTALLDIR: On Windows platforms, this variable indicates -# where to put the framework's DLL. This variable defaults to -# $(INSTALLDIR)/../Executables - -# Library-related variables: -# PUBLIC_HEADER_DIR: Determines where public exported header files -# should be installed. Do not include $(DSTROOT) in this value -- -# it is prefixed automatically. For library projects you should -# set this to something like /Developer/Headers/$(NAME). Do not set -# this variable for framework projects unless you do not want the -# header files included in the framework. -# PRIVATE_HEADER_DIR: Determines where private exported header files -# should be installed. Do not include $(DSTROOT) in this value -- -# it is prefixed automatically. -# LIBRARY_STYLE: This may be either STATIC or DYNAMIC, and determines -# whether the libraries produced are statically linked when they -# are used or if they are dynamically loadable. This defaults to -# DYNAMIC. -# LIBRARY_DLL_INSTALLDIR: On Windows platforms, this variable indicates -# where to put the library's DLL. This variable defaults to -# $(INSTALLDIR)/../Executables -# -# INSTALL_AS_USER: owner of the intalled products (default root) -# INSTALL_AS_GROUP: group of the installed products (default wheel) -# INSTALL_PERMISSIONS: permissions of the installed product (default o+rX) -# -# OTHER_RECURSIVE_VARIABLES: The names of variables which you want to be -# passed on the command line to recursive invocations of make. Note that -# the values in OTHER_*FLAGS are inherited by subprojects automatically -- -# you do not have to (and shouldn't) add OTHER_*FLAGS to -# OTHER_RECURSIVE_VARIABLES. - -# Additional headers to export beyond those in the PB.project: -# OTHER_PUBLIC_HEADERS -# OTHER_PROJECT_HEADERS -# OTHER_PRIVATE_HEADERS - -# Additional files for the project's product: <> -# OTHER_RESOURCES: (non-localized) resources for this project -# OTHER_OFILES: relocatables to be linked into this project -# OTHER_LIBS: more libraries to link against -# OTHER_PRODUCT_DEPENDS: other dependencies of this project -# OTHER_SOURCEFILES: other source files maintained by .pre/postamble -# OTHER_GARBAGE: additional files to be removed by `make clean' - -# Set this to YES if you don't want a final libtool call for a library/framework. -# BUILD_OFILES_LIST_ONLY - -# To include a version string, project source must exist in a directory named -# $(NAME).%d[.%d][.%d] and the following line must be uncommented. -# OTHER_GENERATED_OFILES = $(VERS_OFILE) - -# This definition will suppress stripping of debug symbols when an executable -# is installed. By default it is YES. -# STRIP_ON_INSTALL = NO - -# Uncomment to suppress generation of a KeyValueCoding index when installing -# frameworks (This index is used by WOB and IB to determine keys available -# for an object). Set to YES by default. -# PREINDEX_FRAMEWORK = NO - -# Change this definition to install projects somewhere other than the -# standard locations. NEXT_ROOT defaults to "C:/Apple" on Windows systems -# and "" on other systems. -DSTROOT = $(HOME) diff --git a/pthreads.subproj/PB.project b/pthreads.subproj/PB.project deleted file mode 100644 index cb9a7f3..0000000 --- a/pthreads.subproj/PB.project +++ /dev/null @@ -1,44 +0,0 @@ -{ - DYNAMIC_CODE_GEN = YES; - FILESTABLE = { - H_FILES = ( - posix_sched.h, - pthread.h, - pthread_impl.h, - pthread_internals.h, - pthread_machdep.h, - sched.h - ); - OTHER_LINKED = ( - lock.s, - pthread.c, - pthread_cond.c, - pthread_mutex.c, - pthread_tsd.c, - stack.s, - thread_setup.c - ); - OTHER_SOURCES = (Makefile.preamble, Makefile, Makefile.postamble, mk_pthread_impl.c); - PROJECT_HEADERS = (pthread_internals.h, sched.h, pthread_impl.h, pthread.h); - PUBLIC_HEADERS = (sched.h, pthread_impl.h, pthread.h); - SUBPROJECTS = (); - }; - LANGUAGE = English; - MAKEFILEDIR = "$(MAKEFILEPATH)/pb_makefiles"; - NEXTSTEP_BUILDDIR = "/Local/Public/Sandbox/$(USER)/BUILD/$(NAME)"; - NEXTSTEP_BUILDTOOL = /bin/gnumake; - NEXTSTEP_COMPILEROPTIONS = "-D__POSIX_LIB__"; - NEXTSTEP_INSTALLDIR = /Local/Developer/System; - NEXTSTEP_JAVA_COMPILER = /usr/bin/javac; - NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc; - NEXTSTEP_PUBLICHEADERSDIR = /usr/include; - PDO_UNIX_BUILDTOOL = $NEXT_ROOT/Developer/bin/make; - PDO_UNIX_JAVA_COMPILER = "$(JDKBINDIR)/javac"; - PDO_UNIX_OBJCPLUS_COMPILER = "$(NEXTDEV_BIN)/gcc"; - PROJECTNAME = pthreads; - PROJECTTYPE = Component; - PROJECTVERSION = 2.8; - WINDOWS_BUILDTOOL = $NEXT_ROOT/Developer/Executables/make; - WINDOWS_JAVA_COMPILER = "$(JDKBINDIR)/javac.exe"; - WINDOWS_OBJCPLUS_COMPILER = "$(DEVDIR)/gcc"; -} diff --git a/pthreads.subproj/lock.s b/pthreads.subproj/lock.s deleted file mode 100644 index baac7af..0000000 --- a/pthreads.subproj/lock.s +++ /dev/null @@ -1,136 +0,0 @@ -/* - * Copyright 1996 1995 by Open Software Foundation, Inc. 1997 1996 1995 1994 1993 1992 1991 - * 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 appears in all copies and - * that both the copyright notice and this permission notice appear in - * supporting documentation. - * - * OSF DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE - * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE. - * - * IN NO EVENT SHALL OSF BE LIABLE FOR ANY SPECIAL, INDIRECT, OR - * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM - * LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT, - * NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION - * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - * - */ -/* - * MkLinux - */ - -#if defined(__ppc__) - -#import -#import - -/* void spin_lock(int *p); - * - * Lock the lock pointed to by `p'. Spin (possibly forever) until - * the lock is available. Test and test and set logic used. - */ - -.text - -LEAF(__spin_lock_try) -1: - lwarx r5,0,r3 // Read the lock - addi r4,0,0x1 // Lock value - cmpwi r5,0x0 // Is it busy? - bne- 2f // Yes, return 0 - stwcx. r4,0,r3 // Try to lock the lock - bne- 1b // Lost reservation, try again - addi r3,0,1 // Got the lock - isync // Sync instruction stream - blr // Return 1 -2: addi r3,0,0 // Could not get the lock - blr // Return 0 -END(__spin_lock_try) - -.globl _spin_lock -LEAF(__spin_lock) -_spin_lock: - addi r4,0,0x1 // Lock value -1: - lwarx r5,0,r3 // Read the lock - cmpwi r5,0x0 // Is it busy? - bne- 1b // Yes, spin - stwcx. r4,0,r3 // Try to lock the lock - bne- 1b // Lost reservation, try again - isync // Sync instruction stream - blr // Got it, return -END(__spin_lock) - -/* void spin_unlock(int *p); - * - * Unlock the lock pointed to by p. - */ -.globl _spin_unlock -LEAF(__spin_unlock) -_spin_unlock: - sync - li32 r4,0 - stw r4,0(r3) - blr -END(__spin_unlock) - -#elif defined(__i386__) - -#include - -/* - * void - * _spin_lock(p) - * int *p; - * - * Lock the lock pointed to by p. Spin (possibly forever) until the next - * lock is available. - */ - TEXT - -.globl _spin_lock_try -LEAF(__spin_lock_try, 0) -_spin_lock_try: - movl 4(%esp),%ecx - movl $1,%eax - xchgl (%ecx),%eax - xorl $1,%eax -END(__spin_lock_try) - -.globl _spin_lock -LEAF(__spin_lock, 0) -_spin_lock: - movl 4(%esp), %ecx -1: - movl (%ecx), %eax - orl %eax, %eax - jnz 1b - movl $0xFFFFFFFF, %eax - xchgl %eax, (%ecx) - orl %eax, %eax - jnz 1b -END(__spin_lock) - - -/* - * void - * _spin_unlock(p) - * int *p; - * - * Unlock the lock pointed to by p. - */ -.globl _spin_unlock -LEAF(__spin_unlock, 0) -_spin_unlock: - movl $0, %eax - movl 4(%esp), %ecx - xchgl %eax, (%ecx) -END(__spin_unlock) - -#else -#error spin_locks not defined for this architecture -#endif diff --git a/pthreads.subproj/mk_pthread_impl.c b/pthreads.subproj/mk_pthread_impl.c deleted file mode 100644 index 67b8c1b..0000000 --- a/pthreads.subproj/mk_pthread_impl.c +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright 1996 1995 by Open Software Foundation, Inc. 1997 1996 1995 1994 1993 1992 1991 - * 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 appears in all copies and - * that both the copyright notice and this permission notice appear in - * supporting documentation. - * - * OSF DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE - * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE. - * - * IN NO EVENT SHALL OSF BE LIABLE FOR ANY SPECIAL, INDIRECT, OR - * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM - * LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT, - * NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION - * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - * - */ -/* - * MkLinux - */ - -/* - * This program will generate the stuff necessary to "publish" the POSIX - * header in a machine dependent fashion. - */ - -#include -#include - -int -main(void) -{ - printf("#ifndef _PTHREAD_IMPL_H_\n"); - printf("#define _PTHREAD_IMPL_H_\n"); - printf("/*\n"); - 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("/*\n"); - printf(" * [Internal] data structure signatures\n"); - printf(" */\n"); - printf("#define _PTHREAD_MUTEX_SIG_init 0x%08X\n", _PTHREAD_MUTEX_SIG_init); - printf("#define _PTHREAD_COND_SIG_init 0x%08X\n", _PTHREAD_COND_SIG_init); - printf("#define _PTHREAD_ONCE_SIG_init 0x%08X\n", _PTHREAD_ONCE_SIG_init); - printf("/*\n"); - printf(" * POSIX scheduling policies \n"); - printf(" */\n"); - printf("#define SCHED_OTHER %d\n", SCHED_OTHER); - printf("#define SCHED_FIFO %d\n", SCHED_FIFO); - printf("#define SCHED_RR %d\n", SCHED_RR); - printf("\n"); - printf("#define __SCHED_PARAM_SIZE__ %ld\n", (long) sizeof(struct sched_param)-sizeof(int)); - printf("\n"); - printf("#endif _PTHREAD_IMPL_H_\n"); - - exit(0); -} diff --git a/pthreads.subproj/posix_sched.h b/pthreads.subproj/posix_sched.h deleted file mode 100644 index b9badf1..0000000 --- a/pthreads.subproj/posix_sched.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright 1996 1995 by Open Software Foundation, Inc. 1997 1996 1995 1994 1993 1992 1991 - * 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 appears in all copies and - * that both the copyright notice and this permission notice appear in - * supporting documentation. - * - * OSF DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE - * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE. - * - * IN NO EVENT SHALL OSF BE LIABLE FOR ANY SPECIAL, INDIRECT, OR - * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM - * LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT, - * NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION - * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - * - */ -/* - * MkLinux - */ - -/* - * POSIX Realtime Scheduling Framework - IEEE 1003.1b - */ - -#ifndef _POSIX_SCHED_H -#define _POSIX_SCHED_H - -struct sched_param -{ - int sched_priority; - int quantum; -}; - -/* - * POSIX scheduling policies - */ - -#define SCHED_OTHER POLICY_TIMESHARE -#define SCHED_FIFO POLICY_FIFO -#define SCHED_RR POLICY_RR - -#endif /* _POSIX_SCHED_H */ diff --git a/pthreads.subproj/pthread.c b/pthreads.subproj/pthread.c deleted file mode 100644 index 3a927bd..0000000 --- a/pthreads.subproj/pthread.c +++ /dev/null @@ -1,1256 +0,0 @@ -/* - * Copyright 1996 1995 by Open Software Foundation, Inc. 1997 1996 1995 1994 1993 1992 1991 - * 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 appears in all copies and - * that both the copyright notice and this permission notice appear in - * supporting documentation. - * - * OSF DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE - * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE. - * - * IN NO EVENT SHALL OSF BE LIABLE FOR ANY SPECIAL, INDIRECT, OR - * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM - * LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT, - * NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION - * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - * - */ -/* - * MkLinux - */ - -/* - * POSIX Pthread Library - */ - -#define __POSIX_LIB__ -#include -#include /* For printf(). */ -#include -#include /* For __mach_errno_addr() prototype. */ -#include -#include -#include -#include -#include - -#include "pthread_internals.h" - -/* Per-thread kernel support */ -extern void _pthread_set_self(pthread_t); -extern void mig_init(int); - -/* Needed to tell the malloc subsystem we're going multithreaded */ -extern void set_malloc_singlethreaded(int); - -/* Used when we need to call into the kernel with no reply port */ -extern pthread_lock_t reply_port_lock; - -/* - * [Internal] stack support - */ - -size_t _pthread_stack_size = 0; -int _spin_tries = 0; -#if !defined(__ppc__) -int _cpu_has_altivec = 0; -#endif - -/* This global should be used (carefully) by anyone needing to know if a pthread has been -** created. -*/ -int __is_threaded = 0; - -/* These are used to keep track of a semaphore pool shared by mutexes and condition -** variables. -*/ - -static semaphore_t *sem_pool = NULL; -static int sem_pool_count = 0; -static int sem_pool_current = 0; -static pthread_lock_t sem_pool_lock = LOCK_INITIALIZER; - -static int default_priority; -static int max_priority; -static int min_priority; - -extern mach_port_t thread_recycle_port; - -#define STACK_LOWEST(sp) ((sp) & ~__pthread_stack_mask) -#define STACK_RESERVED (sizeof (struct _pthread)) - -#ifdef STACK_GROWS_UP - -/* The stack grows towards higher addresses: - |struct _pthread|user stack---------------->| - ^STACK_BASE ^STACK_START - ^STACK_SELF - ^STACK_LOWEST */ -#define STACK_BASE(sp) STACK_LOWEST(sp) -#define STACK_START(stack_low) (STACK_BASE(stack_low) + STACK_RESERVED) -#define STACK_SELF(sp) STACK_BASE(sp) - -#else - -/* The stack grows towards lower addresses: - |<----------------user stack|struct _pthread| - ^STACK_LOWEST ^STACK_START ^STACK_BASE - ^STACK_SELF */ - -#define STACK_BASE(sp) (((sp) | __pthread_stack_mask) + 1) -#define STACK_START(stack_low) (STACK_BASE(stack_low) - STACK_RESERVED) -#define STACK_SELF(sp) STACK_START(sp) - -#endif - -/* Set the base address to use as the stack pointer, before adjusting due to the ABI */ - -static int -_pthread_allocate_stack(pthread_attr_t *attrs, vm_address_t *stack) -{ - kern_return_t kr; -#if 1 - assert(attrs->stacksize >= PTHREAD_STACK_MIN); - if (attrs->stackaddr != NULL) { - assert(((vm_offset_t)(attrs->stackaddr) & (vm_page_size - 1)) == 0); - *stack = (vm_address_t)attrs->stackaddr; - return 0; - } - kr = vm_allocate(mach_task_self(), stack, attrs->stacksize + vm_page_size, VM_MAKE_TAG(VM_MEMORY_STACK)| TRUE); - if (kr != KERN_SUCCESS) { - return EAGAIN; - } -#ifdef STACK_GROWS_UP - /* The guard page is the page one higher than the stack */ - /* The stack base is at the lowest address */ - kr = vm_protect(mach_task_self(), *stack + attrs->stacksize, vm_page_size, FALSE, VM_PROT_NONE); -#else - /* The guard page is at the lowest address */ - /* The stack base is the highest address */ - kr = vm_protect(mach_task_self(), *stack, vm_page_size, FALSE, VM_PROT_NONE); - *stack += attrs->stacksize + vm_page_size; -#endif - -#else - vm_address_t cur_stack = (vm_address_t)0; - if (free_stacks == 0) - { - /* Allocating guard pages is done by doubling - * the actual stack size, since STACK_BASE() needs - * to have stacks aligned on stack_size. Allocating just - * one page takes as much memory as allocating more pages - * since it will remain one entry in the vm map. - * Besides, allocating more than one page allows tracking the - * overflow pattern when the overflow is bigger than one page. - */ -#ifndef NO_GUARD_PAGES -# define GUARD_SIZE(a) (2*(a)) -# define GUARD_MASK(a) (((a)<<1) | 1) -#else -# define GUARD_SIZE(a) (a) -# define GUARD_MASK(a) (a) -#endif - while (lowest_stack > GUARD_SIZE(__pthread_stack_size)) - { - lowest_stack -= GUARD_SIZE(__pthread_stack_size); - /* Ensure stack is there */ - kr = vm_allocate(mach_task_self(), - &lowest_stack, - GUARD_SIZE(__pthread_stack_size), - FALSE); -#ifndef NO_GUARD_PAGES - if (kr == KERN_SUCCESS) { -# ifdef STACK_GROWS_UP - kr = vm_protect(mach_task_self(), - lowest_stack+__pthread_stack_size, - __pthread_stack_size, - FALSE, VM_PROT_NONE); -# else /* STACK_GROWS_UP */ - kr = vm_protect(mach_task_self(), - lowest_stack, - __pthread_stack_size, - FALSE, VM_PROT_NONE); - lowest_stack += __pthread_stack_size; -# endif /* STACK_GROWS_UP */ - if (kr == KERN_SUCCESS) - break; - } -#else - if (kr == KERN_SUCCESS) - break; -#endif - } - if (lowest_stack > 0) - free_stacks = (vm_address_t *)lowest_stack; - else - { - /* Too bad. We'll just have to take what comes. - Use vm_map instead of vm_allocate so we can - specify alignment. */ - kr = vm_map(mach_task_self(), &lowest_stack, - GUARD_SIZE(__pthread_stack_size), - GUARD_MASK(__pthread_stack_mask), - TRUE /* anywhere */, MEMORY_OBJECT_NULL, - 0, FALSE, VM_PROT_DEFAULT, VM_PROT_ALL, - VM_INHERIT_DEFAULT); - /* This really shouldn't fail and if it does I don't - know what to do. */ -#ifndef NO_GUARD_PAGES - if (kr == KERN_SUCCESS) { -# ifdef STACK_GROWS_UP - kr = vm_protect(mach_task_self(), - lowest_stack+__pthread_stack_size, - __pthread_stack_size, - FALSE, VM_PROT_NONE); -# else /* STACK_GROWS_UP */ - kr = vm_protect(mach_task_self(), - lowest_stack, - __pthread_stack_size, - FALSE, VM_PROT_NONE); - lowest_stack += __pthread_stack_size; -# endif /* STACK_GROWS_UP */ - } -#endif - free_stacks = (vm_address_t *)lowest_stack; - lowest_stack = 0; - } - *free_stacks = 0; /* No other free stacks */ - } - cur_stack = STACK_START((vm_address_t) free_stacks); - free_stacks = (vm_address_t *)*free_stacks; - cur_stack = _adjust_sp(cur_stack); /* Machine dependent stack fudging */ -#endif - return 0; -} - -/* - * Destroy a thread attribute structure - */ -int -pthread_attr_destroy(pthread_attr_t *attr) -{ - if (attr->sig == _PTHREAD_ATTR_SIG) - { - return (ESUCCESS); - } else - { - return (EINVAL); /* Not an attribute structure! */ - } -} - -/* - * Get the 'detach' state from a thread attribute structure. - * Note: written as a helper function for info hiding - */ -int -pthread_attr_getdetachstate(const pthread_attr_t *attr, - int *detachstate) -{ - if (attr->sig == _PTHREAD_ATTR_SIG) - { - *detachstate = attr->detached; - return (ESUCCESS); - } else - { - return (EINVAL); /* Not an attribute structure! */ - } -} - -/* - * Get the 'inherit scheduling' info from a thread attribute structure. - * Note: written as a helper function for info hiding - */ -int -pthread_attr_getinheritsched(const pthread_attr_t *attr, - int *inheritsched) -{ - if (attr->sig == _PTHREAD_ATTR_SIG) - { - *inheritsched = attr->inherit; - return (ESUCCESS); - } else - { - return (EINVAL); /* Not an attribute structure! */ - } -} - -/* - * Get the scheduling parameters from a thread attribute structure. - * Note: written as a helper function for info hiding - */ -int -pthread_attr_getschedparam(const pthread_attr_t *attr, - struct sched_param *param) -{ - if (attr->sig == _PTHREAD_ATTR_SIG) - { - *param = attr->param; - return (ESUCCESS); - } else - { - return (EINVAL); /* Not an attribute structure! */ - } -} - -/* - * Get the scheduling policy from a thread attribute structure. - * Note: written as a helper function for info hiding - */ -int -pthread_attr_getschedpolicy(const pthread_attr_t *attr, - int *policy) -{ - if (attr->sig == _PTHREAD_ATTR_SIG) - { - *policy = attr->policy; - return (ESUCCESS); - } else - { - return (EINVAL); /* Not an attribute structure! */ - } -} - -static const size_t DEFAULT_STACK_SIZE = DFLSSIZ; -/* - * Initialize a thread attribute structure to default values. - */ -int -pthread_attr_init(pthread_attr_t *attr) -{ - attr->stacksize = DEFAULT_STACK_SIZE; - attr->stackaddr = NULL; - attr->sig = _PTHREAD_ATTR_SIG; - attr->policy = _PTHREAD_DEFAULT_POLICY; - attr->param.sched_priority = default_priority; - attr->param.quantum = 10; /* quantum isn't public yet */ - attr->inherit = _PTHREAD_DEFAULT_INHERITSCHED; - attr->detached = PTHREAD_CREATE_JOINABLE; - attr->freeStackOnExit = TRUE; - return (ESUCCESS); -} - -/* - * Set the 'detach' state in a thread attribute structure. - * Note: written as a helper function for info hiding - */ -int -pthread_attr_setdetachstate(pthread_attr_t *attr, - int detachstate) -{ - if (attr->sig == _PTHREAD_ATTR_SIG) - { - if ((detachstate == PTHREAD_CREATE_JOINABLE) || - (detachstate == PTHREAD_CREATE_DETACHED)) - { - attr->detached = detachstate; - return (ESUCCESS); - } else - { - return (EINVAL); - } - } else - { - return (EINVAL); /* Not an attribute structure! */ - } -} - -/* - * Set the 'inherit scheduling' state in a thread attribute structure. - * Note: written as a helper function for info hiding - */ -int -pthread_attr_setinheritsched(pthread_attr_t *attr, - int inheritsched) -{ - if (attr->sig == _PTHREAD_ATTR_SIG) - { - if ((inheritsched == PTHREAD_INHERIT_SCHED) || - (inheritsched == PTHREAD_EXPLICIT_SCHED)) - { - attr->inherit = inheritsched; - return (ESUCCESS); - } else - { - return (EINVAL); - } - } else - { - return (EINVAL); /* Not an attribute structure! */ - } -} - -/* - * Set the scheduling paramters in a thread attribute structure. - * Note: written as a helper function for info hiding - */ -int -pthread_attr_setschedparam(pthread_attr_t *attr, - const struct sched_param *param) -{ - if (attr->sig == _PTHREAD_ATTR_SIG) - { - /* TODO: Validate sched_param fields */ - attr->param = *param; - return (ESUCCESS); - } else - { - return (EINVAL); /* Not an attribute structure! */ - } -} - -/* - * Set the scheduling policy in a thread attribute structure. - * Note: written as a helper function for info hiding - */ -int -pthread_attr_setschedpolicy(pthread_attr_t *attr, - int policy) -{ - if (attr->sig == _PTHREAD_ATTR_SIG) - { - if ((policy == SCHED_OTHER) || - (policy == SCHED_RR) || - (policy == SCHED_FIFO)) - { - attr->policy = policy; - return (ESUCCESS); - } else - { - return (EINVAL); - } - } else - { - return (EINVAL); /* Not an attribute structure! */ - } -} - -/* - * Set the scope for the thread. - * We currently only provide PTHREAD_SCOPE_SYSTEM - */ -int -pthread_attr_setscope(pthread_attr_t *attr, - int scope) -{ - if (attr->sig == _PTHREAD_ATTR_SIG) { - if (scope == PTHREAD_SCOPE_SYSTEM) { - /* No attribute yet for the scope */ - return (ESUCCESS); - } else if (scope == PTHREAD_SCOPE_PROCESS) { - return (ENOTSUP); - } - } - return (EINVAL); /* Not an attribute structure! */ -} - -/* - * Get the scope for the thread. - * We currently only provide PTHREAD_SCOPE_SYSTEM - */ -int -pthread_attr_getscope(pthread_attr_t *attr, - int *scope) -{ - if (attr->sig == _PTHREAD_ATTR_SIG) { - *scope = PTHREAD_SCOPE_SYSTEM; - return (ESUCCESS); - } - return (EINVAL); /* Not an attribute structure! */ -} - -/* Get the base stack address of the given thread */ -int -pthread_attr_getstackaddr(const pthread_attr_t *attr, void **stackaddr) -{ - if (attr->sig == _PTHREAD_ATTR_SIG) { - *stackaddr = attr->stackaddr; - return (ESUCCESS); - } else { - return (EINVAL); /* Not an attribute structure! */ - } -} - -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)) { - attr->stackaddr = stackaddr; - attr->freeStackOnExit = FALSE; - return (ESUCCESS); - } else { - return (EINVAL); /* Not an attribute structure! */ - } -} - -int -pthread_attr_getstacksize(const pthread_attr_t *attr, size_t *stacksize) -{ - if (attr->sig == _PTHREAD_ATTR_SIG) { - *stacksize = attr->stacksize; - return (ESUCCESS); - } else { - return (EINVAL); /* Not an attribute structure! */ - } -} - -int -pthread_attr_setstacksize(pthread_attr_t *attr, size_t stacksize) -{ - if ((attr->sig == _PTHREAD_ATTR_SIG) && ((stacksize % vm_page_size) == 0) && (stacksize >= PTHREAD_STACK_MIN)) { - attr->stacksize = stacksize; - return (ESUCCESS); - } else { - return (EINVAL); /* Not an attribute structure! */ - } -} - -/* - * Create and start execution of a new thread. - */ - -static void -_pthread_body(pthread_t self) -{ - _pthread_set_self(self); - pthread_exit((self->fun)(self->arg)); -} - -int -_pthread_create(pthread_t t, - const pthread_attr_t *attrs, - vm_address_t stack, - const mach_port_t kernel_thread) -{ - int res; - kern_return_t kern_res; - res = ESUCCESS; - do - { - memset(t, 0, sizeof(*t)); - t->stacksize = attrs->stacksize; - t->stackaddr = (void *)stack; - t->kernel_thread = kernel_thread; - t->detached = attrs->detached; - t->inherit = attrs->inherit; - t->policy = attrs->policy; - t->param = attrs->param; - t->freeStackOnExit = attrs->freeStackOnExit; - t->mutexes = (struct _pthread_mutex *)NULL; - t->sig = _PTHREAD_SIG; - t->reply_port = MACH_PORT_NULL; - t->cthread_self = NULL; - LOCK_INIT(t->lock); - t->cancel_state = PTHREAD_CANCEL_ENABLE | PTHREAD_CANCEL_DEFERRED; - t->cleanup_stack = (struct _pthread_handler_rec *)NULL; - pthread_setschedparam(t, t->policy, &t->param); - /* Create control semaphores */ - if (t->detached == PTHREAD_CREATE_JOINABLE) - { - PTHREAD_MACH_CALL(semaphore_create(mach_task_self(), - &t->death, - SYNC_POLICY_FIFO, - 0), kern_res); - if (kern_res != KERN_SUCCESS) - { - printf("Can't create 'death' semaphore: %d\n", kern_res); - res = EINVAL; /* Need better error here? */ - break; - } - PTHREAD_MACH_CALL(semaphore_create(mach_task_self(), - &t->joiners, - SYNC_POLICY_FIFO, - 0), kern_res); - if (kern_res != KERN_SUCCESS) - { - printf("Can't create 'joiners' semaphore: %d\n", kern_res); - res = EINVAL; /* Need better error here? */ - break; - } - t->num_joiners = 0; - } else - { - t->death = MACH_PORT_NULL; - } - } while (0); - return (res); -} - -int -_pthread_is_threaded(void) -{ - return __is_threaded; -} - -mach_port_t -pthread_mach_thread_np(pthread_t t) -{ - return t->kernel_thread; -} - -size_t -pthread_get_stacksize_np(pthread_t t) -{ - return t->stacksize; -} - -void * -pthread_get_stackaddr_np(pthread_t t) -{ - return t->stackaddr; -} - -mach_port_t -_pthread_reply_port(pthread_t t) -{ - return t->reply_port; -} - -static int -_pthread_create_suspended(pthread_t *thread, - const pthread_attr_t *attr, - void *(*start_routine)(void *), - void *arg, - int suspended) -{ - pthread_attr_t _attr, *attrs; - vm_address_t stack; - int res; - pthread_t t; - kern_return_t kern_res; - mach_port_t kernel_thread; - if ((attrs = (pthread_attr_t *)attr) == (pthread_attr_t *)NULL) - { /* Set up default paramters */ - attrs = &_attr; - pthread_attr_init(attrs); - } else if (attrs->sig != _PTHREAD_ATTR_SIG) { - return EINVAL; - } - res = ESUCCESS; - do - { - /* Allocate a stack for the thread */ - if ((res = _pthread_allocate_stack(attrs, &stack)) != 0) { - break; - } - t = (pthread_t)malloc(sizeof(struct _pthread)); - *thread = t; - /* Create the Mach thread for this thread */ - PTHREAD_MACH_CALL(thread_create(mach_task_self(), &kernel_thread), kern_res); - if (kern_res != KERN_SUCCESS) - { - printf("Can't create thread: %d\n", kern_res); - res = EINVAL; /* Need better error here? */ - break; - } - if ((res = _pthread_create(t, attrs, stack, kernel_thread)) != 0) - { - break; - } - t->arg = arg; - t->fun = start_routine; - /* Now set it up to execute */ - _pthread_setup(t, _pthread_body, stack); - /* Send it on it's way */ - set_malloc_singlethreaded(0); - __is_threaded = 1; - if (suspended == 0) { - PTHREAD_MACH_CALL(thread_resume(kernel_thread), kern_res); - } - if (kern_res != KERN_SUCCESS) - { - printf("Can't resume thread: %d\n", kern_res); - res = EINVAL; /* Need better error here? */ - break; - } - } while (0); - return (res); -} - -int -pthread_create(pthread_t *thread, - const pthread_attr_t *attr, - void *(*start_routine)(void *), - void *arg) -{ - return _pthread_create_suspended(thread, attr, start_routine, arg, 0); -} - -int -pthread_create_suspended_np(pthread_t *thread, - const pthread_attr_t *attr, - void *(*start_routine)(void *), - void *arg) -{ - return _pthread_create_suspended(thread, attr, start_routine, arg, 1); -} - -/* - * Make a thread 'undetached' - no longer 'joinable' with other threads. - */ -int -pthread_detach(pthread_t thread) -{ - kern_return_t kern_res; - int num_joiners; - mach_port_t death; - if (thread->sig == _PTHREAD_SIG) - { - LOCK(thread->lock); - if (thread->detached == PTHREAD_CREATE_JOINABLE) - { - thread->detached = PTHREAD_CREATE_DETACHED; - num_joiners = thread->num_joiners; - death = thread->death; - thread->death = MACH_PORT_NULL; - UNLOCK(thread->lock); - if (num_joiners > 0) - { - /* Wake up a joiner */ - PTHREAD_MACH_CALL(semaphore_signal(thread->joiners), kern_res); - } - /* Destroy 'control' semaphores */ - PTHREAD_MACH_CALL(semaphore_destroy(mach_task_self(), - thread->joiners), kern_res); - PTHREAD_MACH_CALL(semaphore_destroy(mach_task_self(), - death), kern_res); - return (ESUCCESS); - } else if (thread->detached == _PTHREAD_EXITED) { - UNLOCK(thread->lock); - pthread_join(thread, NULL); - return ESUCCESS; - } else - { - UNLOCK(thread->lock); - return (EINVAL); - } - } else - { - return (ESRCH); /* Not a valid thread */ - } -} - -/* Announce that there is a thread ready to be reclaimed for pthread_create */ -/* or terminated by pthread_exit. If the thread is reused, it will have its */ -/* thread state set and will continue in the thread body function. If it is */ -/* terminated, it will be yanked out from under the mach_msg() call. */ - -static void _pthread_become_available(pthread_t thread) { - mach_msg_empty_rcv_t msg = { { 0 } }; - kern_return_t ret; - - if (thread->reply_port == MACH_PORT_NULL) { - thread->reply_port = mach_reply_port(); - } - msg.header.msgh_size = sizeof msg - sizeof msg.trailer; - msg.header.msgh_remote_port = thread_recycle_port; - msg.header.msgh_local_port = MACH_PORT_NULL; - msg.header.msgh_id = (int)thread; - msg.header.msgh_bits = MACH_MSGH_BITS(MACH_MSG_TYPE_COPY_SEND, 0); - ret = mach_msg(&msg.header, MACH_SEND_MSG | MACH_RCV_MSG, - msg.header.msgh_size, sizeof msg, - thread->reply_port, MACH_MSG_TIMEOUT_NONE, - MACH_PORT_NULL); - while (1) { - ret = thread_suspend(thread->kernel_thread); - } - /* We should never get here */ -} - -/* Check to see if any threads are available. Return immediately */ - -static kern_return_t _pthread_check_for_available_threads(mach_msg_empty_rcv_t *msg) { - return mach_msg(&msg->header, MACH_RCV_MSG|MACH_RCV_TIMEOUT, 0, - sizeof(mach_msg_empty_rcv_t), thread_recycle_port, 0, - MACH_PORT_NULL); -} - -/* Terminate all available threads and deallocate their stacks */ -static void _pthread_reap_threads(void) { - kern_return_t ret; - mach_msg_empty_rcv_t msg = { { 0 } }; - while((ret = _pthread_check_for_available_threads(&msg)) == KERN_SUCCESS) { - pthread_t th = (pthread_t)msg.header.msgh_id; - mach_port_t kernel_thread = th->kernel_thread; - mach_port_t reply_port = th->reply_port; - vm_size_t size = (vm_size_t)th->stacksize + vm_page_size; - vm_address_t addr = (vm_address_t)th->stackaddr; -#if !defined(STACK_GROWS_UP) - addr -= size; -#endif - ret = thread_terminate(kernel_thread); - if (ret != KERN_SUCCESS) { - fprintf(stderr, "thread_terminate() failed: %s\n", - mach_error_string(ret)); - } - ret = mach_port_destroy(mach_task_self(), reply_port); - if (ret != KERN_SUCCESS) { - fprintf(stderr, - "mach_port_destroy(thread_reply) failed: %s\n", - mach_error_string(ret)); - } - if (th->freeStackOnExit) { - ret = vm_deallocate(mach_task_self(), addr, size); - if (ret != KERN_SUCCESS) { - fprintf(stderr, - "vm_deallocate(stack) failed: %s\n", - mach_error_string(ret)); - } - } - free(th); - } - assert(ret == MACH_RCV_TIMED_OUT); -} - -/* For compatibility... */ - -pthread_t -_pthread_self() { - return pthread_self(); -} - -/* - * Terminate a thread. - */ -void -pthread_exit(void *value_ptr) -{ - pthread_t self = pthread_self(); - struct _pthread_handler_rec *handler; - kern_return_t kern_res; - int num_joiners; - while ((handler = self->cleanup_stack) != 0) - { - (handler->routine)(handler->arg); - self->cleanup_stack = handler->next; - } - _pthread_tsd_cleanup(self); - LOCK(self->lock); - if (self->detached == PTHREAD_CREATE_JOINABLE) - { - self->detached = _PTHREAD_EXITED; - self->exit_value = value_ptr; - num_joiners = self->num_joiners; - UNLOCK(self->lock); - if (num_joiners > 0) - { - /* POSIX says that multiple pthread_join() calls on */ - /* the same thread are undefined so we just wake up */ - /* the first one to join */ - PTHREAD_MACH_CALL(semaphore_signal(self->joiners), kern_res); - } - do { - PTHREAD_MACH_CALL(semaphore_wait(self->death), kern_res); - } while (kern_res == KERN_ABORTED); - } else - UNLOCK(self->lock); - /* Destroy thread & reclaim resources */ - if (self->death) - { - PTHREAD_MACH_CALL(semaphore_destroy(mach_task_self(), self->joiners), kern_res); - PTHREAD_MACH_CALL(semaphore_destroy(mach_task_self(), self->death), kern_res); - } - if (self->detached == _PTHREAD_CREATE_PARENT) { - exit((int)(self->exit_value)); - } - - _pthread_reap_threads(); - - _pthread_become_available(self); -} - -/* - * 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; - if (thread->sig == _PTHREAD_SIG) - { - LOCK(thread->lock); - if (thread->detached == PTHREAD_CREATE_JOINABLE) - { - thread->num_joiners++; - UNLOCK(thread->lock); - do { - PTHREAD_MACH_CALL(semaphore_wait(thread->joiners), kern_res); - } while (kern_res == KERN_ABORTED); - LOCK(thread->lock); - thread->num_joiners--; - } - if (thread->detached == _PTHREAD_EXITED) - { - if (thread->num_joiners == 0) - { /* Give the result to this thread */ - if (value_ptr) - { - *value_ptr = thread->exit_value; - } - UNLOCK(thread->lock); - PTHREAD_MACH_CALL(semaphore_signal(thread->death), kern_res); - return (ESUCCESS); - } else - { /* This 'joiner' missed the catch! */ - UNLOCK(thread->lock); - return (ESRCH); - } - } else - { /* The thread has become anti-social! */ - UNLOCK(thread->lock); - return (EINVAL); - } - } else - { - return (ESRCH); /* Not a valid thread */ - } -} - -/* - * Get the scheduling policy and scheduling paramters for a thread. - */ -int -pthread_getschedparam(pthread_t thread, - int *policy, - struct sched_param *param) -{ - if (thread->sig == _PTHREAD_SIG) - { - *policy = thread->policy; - *param = thread->param; - return (ESUCCESS); - } else - { - return (ESRCH); /* Not a valid thread structure */ - } -} - -/* - * Set the scheduling policy and scheduling paramters for a thread. - */ -int -pthread_setschedparam(pthread_t thread, - int policy, - const struct sched_param *param) -{ - policy_base_data_t bases; - policy_base_t base; - mach_msg_type_number_t count; - kern_return_t ret; - - if (thread->sig == _PTHREAD_SIG) - { - switch (policy) - { - case SCHED_OTHER: - bases.ts.base_priority = param->sched_priority; - base = (policy_base_t)&bases.ts; - count = POLICY_TIMESHARE_BASE_COUNT; - break; - case SCHED_FIFO: - bases.fifo.base_priority = param->sched_priority; - base = (policy_base_t)&bases.fifo; - count = POLICY_FIFO_BASE_COUNT; - break; - case SCHED_RR: - bases.rr.base_priority = param->sched_priority; - /* quantum isn't public yet */ - bases.rr.quantum = param->quantum; - base = (policy_base_t)&bases.rr; - count = POLICY_RR_BASE_COUNT; - break; - default: - return (EINVAL); - } - thread->policy = policy; - thread->param = *param; - ret = thread_policy(thread->kernel_thread, policy, base, count, TRUE); - if (ret != KERN_SUCCESS) - { - return (EINVAL); - } - return (ESUCCESS); - } else - { - return (ESRCH); /* Not a valid thread structure */ - } -} - -/* - * Get the minimum priority for the given policy - */ -int -sched_get_priority_min(int policy) -{ - return default_priority - 16; -} - -/* - * Get the maximum priority for the given policy - */ -int -sched_get_priority_max(int policy) -{ - return default_priority + 16; -} - -/* - * Determine if two thread identifiers represent the same thread. - */ -int -pthread_equal(pthread_t t1, - pthread_t t2) -{ - return (t1 == t2); -} - -void -cthread_set_self(void *cself) -{ - pthread_t self = pthread_self(); - if ((self == (pthread_t)NULL) || (self->sig != _PTHREAD_SIG)) { - _pthread_set_self(cself); - return; - } - self->cthread_self = cself; -} - -void * -ur_cthread_self(void) { - pthread_t self = pthread_self(); - if ((self == (pthread_t)NULL) || (self->sig != _PTHREAD_SIG)) { - return (void *)self; - } - return self->cthread_self; -} - -/* - * Execute a function exactly one time in a thread-safe fashion. - */ -int -pthread_once(pthread_once_t *once_control, - void (*init_routine)(void)) -{ - LOCK(once_control->lock); - if (once_control->sig == _PTHREAD_ONCE_SIG_init) - { - (*init_routine)(); - once_control->sig = _PTHREAD_ONCE_SIG; - } - UNLOCK(once_control->lock); - 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) -{ - 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); - } - 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); - *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); - *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); -} - -/* - * Perform package initialization - called automatically when application starts - */ - -/* 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}; - -static int -pthread_init(void) -{ - pthread_attr_t _attr, *attrs; - pthread_t thread; - kern_return_t kr; - host_basic_info_data_t basic_info; - host_priority_info_data_t priority_info; - host_info_t info; - host_flavor_t flavor; - mach_msg_type_number_t count; - int mib[2]; - size_t len; - int hasvectorunit, numcpus; - - count = HOST_PRIORITY_INFO_COUNT; - info = (host_info_t)&priority_info; - flavor = HOST_PRIORITY_INFO; - kr = host_info(mach_host_self(), flavor, info, &count); - if (kr != KERN_SUCCESS) - printf("host_info failed (%d); probably need privilege.\n", kr); - else { - default_priority = priority_info.user_priority; - min_priority = priority_info.minimum_priority; - max_priority = priority_info.maximum_priority; - } - attrs = &_attr; - pthread_attr_init(attrs); - _pthread_set_self(&_thread); - - _pthread_create(&_thread, attrs, USRSTACK, mach_thread_self()); - thread = &_thread; - thread->detached = _PTHREAD_CREATE_PARENT; - - /* See if we're on a multiprocessor and set _spin_tries if so. */ - mib[0] = CTL_HW; - mib[1] = HW_NCPU; - len = sizeof(numcpus); - if (sysctl(mib, 2, &numcpus, &len, NULL, 0) == 0) { - if (numcpus > 1) { - _spin_tries = MP_SPIN_TRIES; - } - } else { - count = HOST_BASIC_INFO_COUNT; - info = (host_info_t)&basic_info; - flavor = HOST_BASIC_INFO; - kr = host_info(mach_host_self(), flavor, info, &count); - if (kr != KERN_SUCCESS) - printf("host_info failed (%d)\n", kr); - else { - if (basic_info.avail_cpus > 1) - _spin_tries = MP_SPIN_TRIES; - /* This is a crude test */ - if (basic_info.cpu_subtype >= CPU_SUBTYPE_POWERPC_7400) - _cpu_has_altivec = 1; - } - } - mib[0] = CTL_HW; - mib[1] = HW_VECTORUNIT; - len = sizeof(hasvectorunit); - if (sysctl(mib, 2, &hasvectorunit, &len, NULL, 0) == 0) { - _cpu_has_altivec = hasvectorunit; - } - mig_init(1); /* enable multi-threaded mig interfaces */ - return 0; -} - -int sched_yield(void) -{ - swtch_pri(0); - return 0; -} - -/* This is the "magic" that gets the initialization routine called when the application starts */ -int (*_cthread_init_routine)(void) = pthread_init; - -/* Get a semaphore from the pool, growing it if necessary */ - -__private_extern__ semaphore_t new_sem_from_pool(void) { - kern_return_t res; - semaphore_t sem; - int i; - - LOCK(sem_pool_lock); - if (sem_pool_current == sem_pool_count) { - sem_pool_count += 16; - sem_pool = realloc(sem_pool, sem_pool_count * sizeof(semaphore_t)); - for (i = sem_pool_current; i < sem_pool_count; i++) { - PTHREAD_MACH_CALL(semaphore_create(mach_task_self(), &sem_pool[i], SYNC_POLICY_FIFO, 0), res); - } - } - sem = sem_pool[sem_pool_current++]; - UNLOCK(sem_pool_lock); - return sem; -} - -/* Put a semaphore back into the pool */ -__private_extern__ void restore_sem_to_pool(semaphore_t sem) { - LOCK(sem_pool_lock); - sem_pool[--sem_pool_current] = sem; - UNLOCK(sem_pool_lock); -} - -static void sem_pool_reset(void) { - LOCK(sem_pool_lock); - sem_pool_count = 0; - sem_pool_current = 0; - sem_pool = NULL; - UNLOCK(sem_pool_lock); -} - -__private_extern__ void _pthread_fork_child(void) { - /* Just in case somebody had it locked... */ - UNLOCK(sem_pool_lock); - sem_pool_reset(); -} - diff --git a/pthreads.subproj/pthread.h b/pthreads.subproj/pthread.h deleted file mode 100644 index 0f1ea58..0000000 --- a/pthreads.subproj/pthread.h +++ /dev/null @@ -1,267 +0,0 @@ -/* - * Copyright 1996 1995 by Open Software Foundation, Inc. 1997 1996 1995 1994 1993 1992 1991 - * 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 appears in all copies and - * that both the copyright notice and this permission notice appear in - * supporting documentation. - * - * OSF DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE - * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE. - * - * IN NO EVENT SHALL OSF BE LIABLE FOR ANY SPECIAL, INDIRECT, OR - * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM - * LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT, - * NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION - * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - * - */ -/* - * MkLinux - */ - -/* - * POSIX Threads - IEEE 1003.1c - */ - -#ifndef _POSIX_PTHREAD_H -#define _POSIX_PTHREAD_H - -#ifndef __POSIX_LIB__ -#include -#endif -#include -#include -#include -#include -#include -#include - -/* - * These symbols indicate which [optional] features are available - * They can be tested at compile time via '#ifdef XXX' - * The way to check for pthreads is like so: - - * #include - * #ifdef _POSIX_THREADS - * #include - * #endif - - */ - -/* These will be moved to unistd.h */ - - -/* These two should be defined also */ -#undef _POSIX_THREAD_PROCESS_SHARED -#undef _POSIX_THREAD_SAFE_FUNCTIONS - -/* - * Note: These data structures are meant to be opaque. Only enough - * structure is exposed to support initializers. - * All of the typedefs will be moved to - */ - -#include - -__BEGIN_DECLS -/* - * Threads - */ - - -/* - * Cancel cleanup handler management. Note, since these are implemented as macros, - * they *MUST* occur in matched pairs! - */ - -#define pthread_cleanup_push(func, val) \ - { \ - struct _pthread_handler_rec __handler; \ - pthread_t __self = pthread_self(); \ - __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); \ - } - -/* - * Thread attributes - */ - -#define PTHREAD_CREATE_JOINABLE 1 -#define PTHREAD_CREATE_DETACHED 2 - -#define PTHREAD_INHERIT_SCHED 1 -#define PTHREAD_EXPLICIT_SCHED 2 - -#define PTHREAD_CANCEL_ENABLE 0x01 /* Cancel takes place at next cancellation point */ -#define PTHREAD_CANCEL_DISABLE 0x00 /* Cancel postponed */ -#define PTHREAD_CANCEL_DEFERRED 0x02 /* Cancel waits until cancellation point */ -#define PTHREAD_CANCEL_ASYNCHRONOUS 0x00 /* Cancel occurs immediately */ - -/* We only support PTHREAD_SCOPE_SYSTEM */ -#define PTHREAD_SCOPE_SYSTEM 1 -#define PTHREAD_SCOPE_PROCESS 2 - -/* Who defines this? */ - -#if !defined(ENOTSUP) -#define ENOTSUP 89 -#endif -/* - * Mutex attributes - */ -#define PTHREAD_PRIO_NONE 0 -#define PTHREAD_PRIO_INHERIT 1 -#define PTHREAD_PRIO_PROTECT 2 - -/* - * Mutex variables - */ - -#define PTHREAD_MUTEX_INITIALIZER {_PTHREAD_MUTEX_SIG_init} - -/* - * Condition variable attributes - */ - -/* - * Condition variables - */ - -#define PTHREAD_COND_INITIALIZER {_PTHREAD_COND_SIG_init} - -/* - * Initialization control (once) variables - */ - -#define PTHREAD_ONCE_INIT {_PTHREAD_ONCE_SIG_init} - -/* - * Thread Specific Data - keys - */ - -#include - -/* - * Prototypes for all PTHREAD interfaces - */ -int pthread_attr_destroy __P((pthread_attr_t *attr)); -int pthread_attr_getdetachstate __P((const pthread_attr_t *attr, - int *detachstate)); -int pthread_attr_getinheritsched __P((const pthread_attr_t *attr, - int *inheritsched)); -int pthread_attr_getschedparam __P((const pthread_attr_t *attr, - struct sched_param *param)); -int pthread_attr_getschedpolicy __P((const pthread_attr_t *attr, - int *policy)); -int pthread_attr_getstackaddr __P((const pthread_attr_t *attr, - void **stackaddr)); -int pthread_attr_getstacksize __P((const pthread_attr_t *attr, - size_t *stacksize)); -int pthread_attr_init __P((pthread_attr_t *attr)); -int pthread_attr_setdetachstate __P((pthread_attr_t *attr, - int detachstate)); -int pthread_attr_setinheritsched __P((pthread_attr_t *attr, - int inheritsched)); -int pthread_attr_setschedparam __P((pthread_attr_t *attr, - const struct sched_param *param)); -int pthread_attr_setschedpolicy __P((pthread_attr_t *attr, - int policy)); -int pthread_attr_setstackaddr __P((pthread_attr_t *attr, - void *stackaddr)); -int pthread_attr_setstacksize __P((pthread_attr_t *attr, - size_t stacksize)); -int pthread_cancel __P((pthread_t thread)); -int pthread_setcancelstate __P((int state, int *oldstate)); -int pthread_setcanceltype __P((int type, int *oldtype)); -void pthread_testcancel __P((void)); -int pthread_cond_broadcast __P((pthread_cond_t *cond)); -int pthread_cond_destroy __P((pthread_cond_t *cond)); -int pthread_cond_init __P((pthread_cond_t *cond, - const pthread_condattr_t *attr)); -int pthread_cond_signal __P((pthread_cond_t *cond)); -int pthread_cond_wait __P((pthread_cond_t *cond, - pthread_mutex_t *mutex)); -int pthread_cond_timedwait __P((pthread_cond_t *cond, - pthread_mutex_t *mutex, - const struct timespec *abstime)); -int pthread_cond_timedwait_relative_np __P((pthread_cond_t *cond, - pthread_mutex_t *mutex, - const struct timespec *reltime)); -int pthread_create __P((pthread_t *thread, - const pthread_attr_t *attr, - void *(*start_routine)(void *), - void *arg)); -int pthread_detach __P((pthread_t thread)); -int pthread_equal __P((pthread_t t1, - pthread_t t2)); -void pthread_exit __P((void *value_ptr)); -int pthread_getschedparam __P((pthread_t thread, - int *policy, - struct sched_param *param)); -int pthread_join __P((pthread_t thread, - void **value_ptr)); -int pthread_mutex_destroy __P((pthread_mutex_t *mutex)); -int pthread_mutex_getprioceiling __P((const pthread_mutex_t *mutex, - int *prioceiling)); -int pthread_mutex_init __P((pthread_mutex_t *mutex, - const pthread_mutexattr_t *attr)); -int pthread_mutex_lock __P((pthread_mutex_t *mutex)); -int pthread_mutex_setprioceiling __P((pthread_mutex_t *mutex, - int prioceiling, - int *old_prioceiling)); -int pthread_mutex_trylock __P((pthread_mutex_t *mutex)); -int pthread_mutex_unlock __P((pthread_mutex_t *mutex)); -int pthread_mutexattr_destroy __P((pthread_mutexattr_t *attr)); -int pthread_mutexattr_getprioceiling __P((const pthread_mutexattr_t *attr, - int *prioceiling)); -int pthread_mutexattr_getprotocol __P((const pthread_mutexattr_t *attr, - int *protocol)); -int pthread_mutexattr_init __P((pthread_mutexattr_t *attr)); -int pthread_mutexattr_setprioceiling __P((pthread_mutexattr_t *attr, - int prioceiling)); -int pthread_mutexattr_setprotocol __P((pthread_mutexattr_t *attr, - int protocol)); -int pthread_once __P((pthread_once_t *once_control, - void (*init_routine)(void))); -pthread_t pthread_self __P((void)); -int pthread_setschedparam __P((pthread_t thread, - int policy, - const struct sched_param *param)); -int pthread_key_create __P((pthread_key_t *key, - void (*destructor)(void *))); -int pthread_key_delete __P((pthread_key_t key)); -int pthread_setspecific __P((pthread_key_t key, - const void *value)); -void *pthread_getspecific __P((pthread_key_t key)); -int pthread_attr_getscope __P((pthread_attr_t *, int *)); -int pthread_attr_setscope __P((pthread_attr_t *, int)); - -/* returns non-zero if pthread_create or cthread_fork have been called */ -int pthread_is_threaded_np __P((void)); - -/* return the mach thread bound to the pthread */ -mach_port_t pthread_mach_thread_np __P((pthread_t)); -size_t pthread_get_stacksize_np __P((pthread_t)); -void * pthread_get_stackaddr_np __P((pthread_t)); - -/* Like pthread_cond_signal(), but only wake up the specified pthread */ -int pthread_cond_signal_thread_np __P((pthread_cond_t *, pthread_t)); - -/* Like pthread_create(), but leaves the thread suspended */ -int pthread_create_suspended_np __P((pthread_t *thread, - const pthread_attr_t *attr, - void *(*start_routine)(void *), - void *arg)); -__END_DECLS -#endif /* _POSIX_PTHREAD_H */ diff --git a/pthreads.subproj/pthread_cond.c b/pthreads.subproj/pthread_cond.c deleted file mode 100644 index 4eee4a5..0000000 --- a/pthreads.subproj/pthread_cond.c +++ /dev/null @@ -1,330 +0,0 @@ -/* - * Copyright 1996 1995 by Open Software Foundation, Inc. 1997 1996 1995 1994 1993 1992 1991 - * 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 appears in all copies and - * that both the copyright notice and this permission notice appear in - * supporting documentation. - * - * OSF DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE - * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE. - * - * IN NO EVENT SHALL OSF BE LIABLE FOR ANY SPECIAL, INDIRECT, OR - * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM - * LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT, - * NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION - * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ -/* - * MkLinux - */ - -/* - * POSIX Pthread Library - */ - -#include "pthread_internals.h" -#include /* For struct timespec and getclock(). */ -#include - - /* - * Destroy a condition variable. - */ -int -pthread_cond_destroy(pthread_cond_t *cond) -{ - if (cond->sig == _PTHREAD_COND_SIG) - { - LOCK(cond->lock); - if (cond->busy != (pthread_mutex_t *)NULL) - { - UNLOCK(cond->lock); - return (EBUSY); - } else - { - cond->sig = _PTHREAD_NO_SIG; - UNLOCK(cond->lock); - return (ESUCCESS); - } - } else - return (EINVAL); /* Not an initialized condition variable structure */ -} - -/* - * Initialize a condition variable. Note: 'attr' is ignored. - */ -int -pthread_cond_init(pthread_cond_t *cond, - const pthread_condattr_t *attr) -{ - LOCK_INIT(cond->lock); - cond->sig = _PTHREAD_COND_SIG; - cond->next = (pthread_cond_t *)NULL; - cond->prev = (pthread_cond_t *)NULL; - cond->busy = (pthread_mutex_t *)NULL; - cond->waiters = 0; - cond->sigspending = 0; - cond->sem = MACH_PORT_NULL; - return (ESUCCESS); -} - -/* - * Signal a condition variable, waking up all threads waiting for it. - */ -int -pthread_cond_broadcast(pthread_cond_t *cond) -{ - kern_return_t kern_res; - int res; - if (cond->sig == _PTHREAD_COND_SIG_init) { - if ((res = pthread_cond_init(cond, NULL)) != 0) { - return (res); - } - } - if (cond->sig != _PTHREAD_COND_SIG) { - /* Not a condition variable */ - return (EINVAL); - } - LOCK(cond->lock); - if (cond->sem == MACH_PORT_NULL) { - /* Avoid kernel call since there are no waiters... */ - UNLOCK(cond->lock); - return (ESUCCESS); - } - cond->sigspending++; - UNLOCK(cond->lock); - PTHREAD_MACH_CALL(semaphore_signal_all(cond->sem), kern_res); - LOCK(cond->lock); - cond->sigspending--; - if (cond->waiters == 0 && cond->sigspending == 0) { - restore_sem_to_pool(cond->sem); - cond->sem = MACH_PORT_NULL; - } - UNLOCK(cond->lock); - if (kern_res != KERN_SUCCESS) { - return (EINVAL); - } - return (ESUCCESS); -} - -/* - * Signal a condition variable, waking a specified thread. - */ -int -pthread_cond_signal_thread_np(pthread_cond_t *cond, pthread_t thread) -{ - kern_return_t kern_res; - if (cond->sig == _PTHREAD_COND_SIG_init) { - int res; - if ((res = pthread_cond_init(cond, NULL)) != 0) { - return (res); - } - } - if (cond->sig != _PTHREAD_COND_SIG) { - return (EINVAL); /* Not a condition variable */ - } - LOCK(cond->lock); - if (cond->sem == MACH_PORT_NULL) { - /* Avoid kernel call since there are not enough waiters... */ - UNLOCK(cond->lock); - return (ESUCCESS); - } - cond->sigspending++; - UNLOCK(cond->lock); - if (thread == (pthread_t)NULL) { - kern_res = semaphore_signal_thread(cond->sem, MACH_PORT_NULL); - if (kern_res == KERN_INVALID_ARGUMENT) { - PTHREAD_MACH_CALL(semaphore_signal(cond->sem), kern_res); - } else if (kern_res == KERN_NOT_WAITING) { - kern_res = KERN_SUCCESS; - } - } else if (thread->sig == _PTHREAD_SIG) { - PTHREAD_MACH_CALL(semaphore_signal_thread(cond->sem, thread->kernel_thread), kern_res); - } else { - kern_res = KERN_FAILURE; - } - LOCK(cond->lock); - cond->sigspending--; - if (cond->waiters == 0 && cond->sigspending == 0) { - restore_sem_to_pool(cond->sem); - cond->sem = MACH_PORT_NULL; - } - UNLOCK(cond->lock); - if (kern_res != KERN_SUCCESS) { - return (EINVAL); - } - return (ESUCCESS); -} - -/* - * Signal a condition variable, waking only one thread. - */ -int -pthread_cond_signal(pthread_cond_t *cond) -{ - return pthread_cond_signal_thread_np(cond, NULL); -} - -/* - * Manage a list of condition variables associated with a mutex - */ - -static void -_pthread_cond_add(pthread_cond_t *cond, pthread_mutex_t *mutex) -{ - pthread_cond_t *c; - LOCK(mutex->lock); - if ((c = mutex->busy) != (pthread_cond_t *)NULL) - { - c->prev = cond; - } - cond->next = c; - cond->prev = (pthread_cond_t *)NULL; - mutex->busy = cond; - UNLOCK(mutex->lock); - if (cond->sem == MACH_PORT_NULL) { - cond->sem = new_sem_from_pool(); - } -} - -static void -_pthread_cond_remove(pthread_cond_t *cond, pthread_mutex_t *mutex) -{ - pthread_cond_t *n, *p; - LOCK(mutex->lock); - if ((n = cond->next) != (pthread_cond_t *)NULL) - { - n->prev = cond->prev; - } - if ((p = cond->prev) != (pthread_cond_t *)NULL) - { - p->next = cond->next; - } else - { /* This is the first in the list */ - mutex->busy = n; - } - UNLOCK(mutex->lock); - if (cond->sigspending == 0) { - restore_sem_to_pool(cond->sem); - cond->sem = MACH_PORT_NULL; - } -} - -/* - * 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 -_pthread_cond_wait(pthread_cond_t *cond, - pthread_mutex_t *mutex, - const struct timespec *abstime, - int isRelative) -{ - int res; - kern_return_t kern_res; - pthread_mutex_t *busy; - mach_timespec_t then; - if (cond->sig == _PTHREAD_COND_SIG_init) { - if ((res = pthread_cond_init(cond, NULL)) != 0) { - return (res); - } - } - if (cond->sig != _PTHREAD_COND_SIG) { - /* Not a condition variable */ - return (EINVAL); - } - - if (abstime) { - 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 += 1000000000; /* nsec/sec */ - then.tv_sec--; - } - if (((int)then.tv_sec < 0) || - ((then.tv_sec == 0) && (then.tv_nsec == 0))) { - return ETIMEDOUT; - } - } else { - then.tv_sec = abstime->tv_sec; - then.tv_nsec = abstime->tv_nsec; - } - } - LOCK(cond->lock); - busy = cond->busy; - if ((busy != (pthread_mutex_t *)NULL) && (busy != mutex)) { - /* Must always specify the same mutex! */ - UNLOCK(cond->lock); - return (EINVAL); - } - cond->waiters++; - if (cond->waiters == 1) { - _pthread_cond_add(cond, mutex); - cond->busy = mutex; - } - UNLOCK(cond->lock); - LOCK(mutex->lock); - if (mutex->sem == MACH_PORT_NULL) { - mutex->sem = new_sem_from_pool(); - } - mutex->cond_lock = 1; - UNLOCK(mutex->lock); - 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); - } - LOCK(cond->lock); - cond->waiters--; - if (cond->waiters == 0) { - _pthread_cond_remove(cond, mutex); - cond->busy = (pthread_mutex_t *)NULL; - } - UNLOCK(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); - } else { - return (EINVAL); - } -} - -int -pthread_cond_wait(pthread_cond_t *cond, - pthread_mutex_t *mutex) -{ - return (_pthread_cond_wait(cond, mutex, (struct timespec *)NULL, 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)); -} - diff --git a/pthreads.subproj/pthread_impl.h b/pthreads.subproj/pthread_impl.h deleted file mode 100644 index ef83dee..0000000 --- a/pthreads.subproj/pthread_impl.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef _PTHREAD_IMPL_H_ -#define _PTHREAD_IMPL_H_ -/* - * Internal implementation details - */ - -/* This whole header file will disappear, so don't depend on it... */ - -#ifndef __POSIX_LIB__ - -/* - * [Internal] data structure signatures - */ -#define _PTHREAD_MUTEX_SIG_init 0x32AAABA7 -#define _PTHREAD_COND_SIG_init 0x3CB0B1BB -#define _PTHREAD_ONCE_SIG_init 0x30B1BCBA -/* - * POSIX scheduling policies - */ -#define SCHED_OTHER 1 -#define SCHED_FIFO 4 -#define SCHED_RR 2 - -#define __SCHED_PARAM_SIZE__ 4 - -#endif /* __POSIX_LIB__ */ - -#endif /* _PTHREAD_IMPL_H_ */ diff --git a/pthreads.subproj/pthread_internals.h b/pthreads.subproj/pthread_internals.h deleted file mode 100644 index 2cfde61..0000000 --- a/pthreads.subproj/pthread_internals.h +++ /dev/null @@ -1,250 +0,0 @@ -/* - * Copyright 1996 1995 by Open Software Foundation, Inc. 1997 1996 1995 1994 1993 1992 1991 - * 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 appears in all copies and - * that both the copyright notice and this permission notice appear in - * supporting documentation. - * - * OSF DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE - * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE. - * - * IN NO EVENT SHALL OSF BE LIABLE FOR ANY SPECIAL, INDIRECT, OR - * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM - * LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT, - * NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION - * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - * - */ -/* - * MkLinux - */ - -/* - * POSIX Threads - IEEE 1003.1c - */ - -#ifndef _POSIX_PTHREAD_INTERNALS_H -#define _POSIX_PTHREAD_INTERNALS_H - - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include /* For generic MACH support */ - - -#ifndef __POSIX_LIB__ -#define __POSIX_LIB__ -#endif - -#include "posix_sched.h" /* For POSIX scheduling policy & parameter */ -#include "pthread_machdep.h" /* Machine-dependent definitions. */ - -extern kern_return_t syscall_thread_switch(mach_port_name_t, int, mach_msg_timeout_t); - -/* - * Compiled-in limits - */ -#undef _POSIX_THREAD_KEYS_MAX -#define _POSIX_THREAD_KEYS_MAX 128 - -/* - * Threads - */ -typedef struct _pthread -{ - long sig; /* Unique signature for this structure */ - struct _pthread_handler_rec *cleanup_stack; - pthread_lock_t lock; /* Used for internal mutex on structure */ - int detached; - int inherit; - int policy; - struct sched_param param; - struct _pthread_mutex *mutexes; - mach_port_t joiners; /* pthread_join() uses this to wait for death's call */ - int num_joiners; - void *exit_value; - mach_port_t death; /* pthread_exit() uses this to wait for the hearse */ - mach_port_t kernel_thread; /* kernel thread this thread is bound to */ - void *(*fun)(void*);/* Thread start routine */ - void *arg; /* Argment for thread start routine */ - int cancel_state; /* Whether thread can be cancelled */ - int err_no; /* thread-local errno */ - void *tsd[_POSIX_THREAD_KEYS_MAX]; /* Thread specific data */ - 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() */ - boolean_t freeStackOnExit;/* Should we free the stack when we're done? */ -} *pthread_t; - - -/* - * Thread attributes - */ -typedef struct -{ - long sig; /* Unique signature for this structure */ - pthread_lock_t lock; /* Used for internal mutex on structure */ - int detached; - int inherit; - int policy; - struct sched_param param; - 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; - -/* - * Mutex attributes - */ -typedef struct -{ - long sig; /* Unique signature for this structure */ - int prioceiling; - int protocol; -} pthread_mutexattr_t; - -/* - * Mutex variables - */ -typedef struct _pthread_mutex -{ - long sig; /* Unique signature for this structure */ - pthread_lock_t lock; /* Used for internal mutex on structure */ - int prioceiling; - int priority; /* Priority to restore when mutex unlocked */ - int protocol; - pthread_t owner; /* Which thread has this mutex locked */ - struct _pthread_mutex *next, *prev; /* List of other mutexes he owns */ - struct _pthread_cond *busy; /* List of condition variables using this mutex */ - int waiters:31, /* Count of threads waiting for this mutex */ - cond_lock:1; /* Is there a condition locking me? */ - mach_port_t sem; /* Semaphore used for waiting */ -} pthread_mutex_t; - -/* - * Condition variable attributes - */ -typedef struct -{ - long sig; /* Unique signature for this structure */ - int unsupported; -} pthread_condattr_t; - -/* - * Condition variables - */ -typedef struct _pthread_cond -{ - long sig; /* Unique signature for this structure */ - pthread_lock_t lock; /* Used for internal mutex on structure */ - mach_port_t sem; /* Kernel semaphore */ - struct _pthread_cond *next, *prev; /* List of condition variables using mutex */ - struct _pthread_mutex *busy; /* mutex associated with variable */ - int waiters:16, /* Number of threads waiting */ - sigspending:16; /* Number of outstanding signals */ -} pthread_cond_t; - -/* - * Initialization control (once) variables - */ -typedef struct -{ - long sig; /* Unique signature for this structure */ - pthread_lock_t lock; /* Used for internal mutex on structure */ -} pthread_once_t; - -#include "pthread.h" - -#define _PTHREAD_DEFAULT_INHERITSCHED PTHREAD_INHERIT_SCHED -#define _PTHREAD_DEFAULT_PROTOCOL PTHREAD_PRIO_NONE -#define _PTHREAD_DEFAULT_PRIOCEILING 0 -#define _PTHREAD_DEFAULT_POLICY SCHED_OTHER -#define _PTHREAD_DEFAULT_STACKSIZE 0x80000 /* 512K */ - -#define _PTHREAD_NO_SIG 0x00000000 -#define _PTHREAD_MUTEX_ATTR_SIG 0x4D545841 /* 'MTXA' */ -#define _PTHREAD_MUTEX_SIG 0x4D555458 /* 'MUTX' */ -#define _PTHREAD_MUTEX_SIG_init 0x32AAABA7 /* [almost] ~'MUTX' */ -#define _PTHREAD_COND_SIG 0x434F4E44 /* 'COND' */ -#define _PTHREAD_COND_SIG_init 0x3CB0B1BB /* [almost] ~'COND' */ -#define _PTHREAD_ATTR_SIG 0x54484441 /* 'THDA' */ -#define _PTHREAD_ONCE_SIG 0x4F4E4345 /* 'ONCE' */ -#define _PTHREAD_ONCE_SIG_init 0x30B1BCBA /* [almost] ~'ONCE' */ -#define _PTHREAD_SIG 0x54485244 /* 'THRD' */ - -#define _PTHREAD_EXITED 3 -#define _PTHREAD_CREATE_PARENT 4 - -#define _PTHREAD_CANCEL_STATE_MASK 0xFE -#define _PTHREAD_CANCEL_TYPE_MASK 0xFD -#define _PTHREAD_CANCEL_PENDING 0x10 /* pthread_cancel() has been called for this thread */ - -extern boolean_t swtch_pri(int); - -/* Number of times to spin when the lock is unavailable and we are on a - multiprocessor. On a uniprocessor we yield the processor immediately. */ -#define MP_SPIN_TRIES 1000 -extern int _spin_tries; -extern int __is_threaded; -extern int _cpu_has_altivec; - -/* Internal mutex locks for data structures */ -#define TRY_LOCK(v) (!__is_threaded || _spin_lock_try((pthread_lock_t *)&(v))) -#define LOCK(v) \ -do { \ - if (__is_threaded) { \ - int tries = _spin_tries; \ - \ - while (!_spin_lock_try((pthread_lock_t *)&(v))) { \ - if (tries-- > 0) \ - continue; \ - \ - syscall_thread_switch(THREAD_NULL, SWITCH_OPTION_DEPRESS, 1); \ - tries = _spin_tries; \ - } \ - } \ -} while (0) -#define UNLOCK(v) \ -do { \ - if (__is_threaded) \ - _spin_unlock((pthread_lock_t *)&(v)); \ -} while (0) - -#ifndef ESUCCESS -#define ESUCCESS 0 -#endif - -#ifndef PTHREAD_MACH_CALL -#define PTHREAD_MACH_CALL(expr, ret) (ret) = (expr) -#endif - -/* Prototypes. */ - -/* Functions defined in machine-dependent files. */ -extern vm_address_t _sp(void); -extern vm_address_t _adjust_sp(vm_address_t sp); -extern void _spin_lock(pthread_lock_t *lockp); -extern int _spin_lock_try(pthread_lock_t *lockp); -extern void _spin_unlock(pthread_lock_t *lockp); -extern void _pthread_setup(pthread_t th, void (*f)(pthread_t), vm_address_t sp); - -extern void _pthread_tsd_cleanup(pthread_t self); - -__private_extern__ semaphore_t new_sem_from_pool(void); -__private_extern__ void restore_sem_to_pool(semaphore_t); -#endif /* _POSIX_PTHREAD_INTERNALS_H */ diff --git a/pthreads.subproj/pthread_machdep.h b/pthreads.subproj/pthread_machdep.h deleted file mode 100644 index 57a3f24..0000000 --- a/pthreads.subproj/pthread_machdep.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 1996 1995 by Open Software Foundation, Inc. 1997 1996 1995 1994 1993 1992 1991 - * 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 appears in all copies and - * that both the copyright notice and this permission notice appear in - * supporting documentation. - * - * OSF DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE - * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE. - * - * IN NO EVENT SHALL OSF BE LIABLE FOR ANY SPECIAL, INDIRECT, OR - * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM - * LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT, - * NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION - * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ -/* - * MkLinux - */ - -/* Machine-dependent definitions for pthread internals. */ - -typedef long pthread_lock_t; - -#define LOCK_INIT(l) ((l) = 0) -#define LOCK_INITIALIZER 0 - -#undef STACK_GROWS_UP diff --git a/pthreads.subproj/pthread_mutex.c b/pthreads.subproj/pthread_mutex.c deleted file mode 100644 index 427026a..0000000 --- a/pthreads.subproj/pthread_mutex.c +++ /dev/null @@ -1,420 +0,0 @@ -/* - * Copyright 1996 1995 by Open Software Foundation, Inc. 1997 1996 1995 1994 1993 1992 1991 - * 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 appears in all copies and - * that both the copyright notice and this permission notice appear in - * supporting documentation. - * - * OSF DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE - * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE. - * - * IN NO EVENT SHALL OSF BE LIABLE FOR ANY SPECIAL, INDIRECT, OR - * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM - * LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT, - * NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION - * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - * - */ -/* - * MkLinux - */ - -/* - * POSIX Pthread Library - * -- Mutex variable support - */ - -#include "pthread_internals.h" - -/* - * Destroy a mutex variable. - */ -int -pthread_mutex_destroy(pthread_mutex_t *mutex) -{ - if (mutex->sig != _PTHREAD_MUTEX_SIG) - return (EINVAL); - if ((mutex->owner != (pthread_t)NULL) || - (mutex->busy != (pthread_cond_t *)NULL)) - return (EBUSY); - mutex->sig = _PTHREAD_NO_SIG; - return (ESUCCESS); -} - -/* - * Initialize a mutex variable, possibly with additional attributes. - */ -int -pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *attr) -{ - LOCK_INIT(mutex->lock); - mutex->sig = _PTHREAD_MUTEX_SIG; - if (attr) - { - if (attr->sig != _PTHREAD_MUTEX_ATTR_SIG) - return (EINVAL); - mutex->prioceiling = attr->prioceiling; - mutex->protocol = attr->protocol; - } else - { - mutex->prioceiling = _PTHREAD_DEFAULT_PRIOCEILING; - mutex->protocol = _PTHREAD_DEFAULT_PROTOCOL; - } - mutex->owner = (pthread_t)NULL; - mutex->next = (pthread_mutex_t *)NULL; - mutex->prev = (pthread_mutex_t *)NULL; - mutex->busy = (pthread_cond_t *)NULL; - mutex->waiters = 0; - mutex->cond_lock = 0; - mutex->sem = MACH_PORT_NULL; - return (ESUCCESS); -} - -/* - * Manage a list of mutex variables owned by a thread - */ -#if defined(DEBUG) -static void -_pthread_mutex_add(pthread_mutex_t *mutex) -{ - pthread_mutex_t *m; - pthread_t self = pthread_self(); - if (self != (pthread_t)0) { - mutex->owner = self; - if ((m = self->mutexes) != (pthread_mutex_t *)NULL) - { /* Add to list */ - m->prev = mutex; - } - mutex->next = m; - mutex->prev = (pthread_mutex_t *)NULL; - self->mutexes = mutex; - } -} - -static void -_pthread_mutex_remove(pthread_mutex_t *mutex, pthread_t self) -{ - pthread_mutex_t *n, *prev; - if ((n = mutex->next) != (pthread_mutex_t *)NULL) - { - n->prev = mutex->prev; - } - if ((prev = mutex->prev) != (pthread_mutex_t *)NULL) - { - prev->next = mutex->next; - } else - { /* This is the first in the list */ - if (self != (pthread_t)0) { - self->mutexes = n; - } - } - mutex->owner = (pthread_t)NULL; -} -#endif - -/* - * Lock a mutex. - * TODO: Priority inheritance stuff - */ -int -pthread_mutex_lock(pthread_mutex_t *mutex) -{ - kern_return_t kern_res; - - if (mutex->sig == _PTHREAD_MUTEX_SIG_init) - { - int res; - if (res = pthread_mutex_init(mutex, NULL)) - return (res); - } - if (mutex->sig != _PTHREAD_MUTEX_SIG) - return (EINVAL); /* Not a mutex variable */ - LOCK(mutex->lock); - if (mutex->waiters || (mutex->owner != (pthread_t)NULL)) - { - mutex->waiters++; - if (mutex->sem == MACH_PORT_NULL) { - mutex->sem = new_sem_from_pool(); - } - UNLOCK(mutex->lock); - do { - PTHREAD_MACH_CALL(semaphore_wait(mutex->sem), kern_res); - } while (kern_res == KERN_ABORTED); - LOCK(mutex->lock); - mutex->waiters--; - if (mutex->waiters == 0) { - restore_sem_to_pool(mutex->sem); - mutex->sem = MACH_PORT_NULL; - } - if (mutex->cond_lock) { - mutex->cond_lock = 0; - } - } -#if defined(DEBUG) - _pthread_mutex_add(mutex); -#else - mutex->owner = (pthread_t)0x12141968; -#endif - UNLOCK(mutex->lock); - return (ESUCCESS); -} - -/* - * Attempt to lock a mutex, but don't block if this isn't possible. - */ -int -pthread_mutex_trylock(pthread_mutex_t *mutex) -{ - kern_return_t kern_res; - - if (mutex->sig == _PTHREAD_MUTEX_SIG_init) - { - int res; - if (res = pthread_mutex_init(mutex, NULL)) - return (res); - } - if (mutex->sig != _PTHREAD_MUTEX_SIG) - return (EINVAL); /* Not a mutex variable */ - if (!TRY_LOCK(mutex->lock)) { - return (EBUSY); - } - if (mutex->waiters || - ((mutex->owner != (pthread_t)NULL) && (mutex->cond_lock == 0))) - { - UNLOCK(mutex->lock); - return (EBUSY); - } else - { -#if defined(DEBUG) - _pthread_mutex_add(mutex); -#else - mutex->owner = (pthread_t)0x12141968; -#endif - if (mutex->cond_lock) { - PTHREAD_MACH_CALL(semaphore_wait(mutex->sem), kern_res); - mutex->cond_lock = 0; - restore_sem_to_pool(mutex->sem); - mutex->sem = MACH_PORT_NULL; - } - UNLOCK(mutex->lock); - return (ESUCCESS); - } -} - -/* - * Unlock a mutex. - * TODO: Priority inheritance stuff - */ -int -pthread_mutex_unlock(pthread_mutex_t *mutex) -{ - kern_return_t kern_res; - int waiters; - if (mutex->sig == _PTHREAD_MUTEX_SIG_init) - { - int res; - if (res = pthread_mutex_init(mutex, NULL)) - return (res); - } - if (mutex->sig != _PTHREAD_MUTEX_SIG) - return (EINVAL); /* Not a mutex variable */ - LOCK(mutex->lock); -#if defined(DEBUG) - if (mutex->owner != pthread_self()) - { - UNLOCK(mutex->lock); - abort(); - return (EPERM); - } else -#endif - { -#if defined(DEBUG) - _pthread_mutex_remove(mutex, mutex->owner); -#else - mutex->owner = (pthread_t)NULL; -#endif - waiters = mutex->waiters; - UNLOCK(mutex->lock); - if (waiters) - { - PTHREAD_MACH_CALL(semaphore_signal(mutex->sem), kern_res); - } - return (ESUCCESS); - } -} - -/* - * Fetch the priority ceiling value from a mutex variable. - * Note: written as a 'helper' function to hide implementation details. - */ -int -pthread_mutex_getprioceiling(const pthread_mutex_t *mutex, - int *prioceiling) -{ - if (mutex->sig == _PTHREAD_MUTEX_SIG) - { - *prioceiling = mutex->prioceiling; - return (ESUCCESS); - } else - { - return (EINVAL); /* Not an initialized 'attribute' structure */ - } -} - -/* - * Set the priority ceiling for a mutex. - * Note: written as a 'helper' function to hide implementation details. - */ -int -pthread_mutex_setprioceiling(pthread_mutex_t *mutex, - int prioceiling, - int *old_prioceiling) -{ - if (mutex->sig == _PTHREAD_MUTEX_SIG) - { - if ((prioceiling >= -999) || - (prioceiling <= 999)) - { - *old_prioceiling = mutex->prioceiling; - mutex->prioceiling = prioceiling; - return (ESUCCESS); - } else - { - return (EINVAL); /* Invalid parameter */ - } - } else - { - return (EINVAL); /* Not an initialized 'attribute' structure */ - } -} - -/* - * Destroy a mutex attribute structure. - */ -int -pthread_mutexattr_destroy(pthread_mutexattr_t *attr) -{ - attr->sig = _PTHREAD_NO_SIG; /* Uninitialized */ - return (ESUCCESS); -} - -/* - * Get the priority ceiling value from a mutex attribute structure. - * Note: written as a 'helper' function to hide implementation details. - */ -int -pthread_mutexattr_getprioceiling(const pthread_mutexattr_t *attr, - int *prioceiling) -{ - if (attr->sig == _PTHREAD_MUTEX_ATTR_SIG) - { - *prioceiling = attr->prioceiling; - return (ESUCCESS); - } else - { - return (EINVAL); /* Not an initialized 'attribute' structure */ - } -} - -/* - * Get the mutex 'protocol' value from a mutex attribute structure. - * Note: written as a 'helper' function to hide implementation details. - */ -int -pthread_mutexattr_getprotocol(const pthread_mutexattr_t *attr, - int *protocol) -{ - if (attr->sig == _PTHREAD_MUTEX_ATTR_SIG) - { - *protocol = attr->protocol; - return (ESUCCESS); - } else - { - return (EINVAL); /* Not an initialized 'attribute' structure */ - } -} - -/* - * Initialize a mutex attribute structure to system defaults. - */ -int -pthread_mutexattr_init(pthread_mutexattr_t *attr) -{ - attr->prioceiling = _PTHREAD_DEFAULT_PRIOCEILING; - attr->protocol = _PTHREAD_DEFAULT_PROTOCOL; - attr->sig = _PTHREAD_MUTEX_ATTR_SIG; - return (ESUCCESS); -} - -/* - * Set the priority ceiling value in a mutex attribute structure. - * Note: written as a 'helper' function to hide implementation details. - */ -int -pthread_mutexattr_setprioceiling(pthread_mutexattr_t *attr, - int prioceiling) -{ - if (attr->sig == _PTHREAD_MUTEX_ATTR_SIG) - { - if ((prioceiling >= -999) || - (prioceiling <= 999)) - { - attr->prioceiling = prioceiling; - return (ESUCCESS); - } else - { - return (EINVAL); /* Invalid parameter */ - } - } else - { - return (EINVAL); /* Not an initialized 'attribute' structure */ - } -} - -/* - * Set the mutex 'protocol' value in a mutex attribute structure. - * Note: written as a 'helper' function to hide implementation details. - */ -int -pthread_mutexattr_setprotocol(pthread_mutexattr_t *attr, - int protocol) -{ - if (attr->sig == _PTHREAD_MUTEX_ATTR_SIG) - { - if ((protocol == PTHREAD_PRIO_NONE) || - (protocol == PTHREAD_PRIO_INHERIT) || - (protocol == PTHREAD_PRIO_PROTECT)) - { - attr->protocol = protocol; - return (ESUCCESS); - } else - { - return (EINVAL); /* Invalid parameter */ - } - } else - { - return (EINVAL); /* Not an initialized 'attribute' structure */ - } -} - -int mutex_try_lock(int *x) { - return _spin_lock_try((pthread_lock_t *)x); -} - -void mutex_wait_lock(int *x) { - for (;;) { - if( _spin_lock_try((pthread_lock_t *)x)) { - return; - } - swtch_pri(0); - } -} - -void cthread_yield(void) { - sched_yield(); -} - diff --git a/pthreads.subproj/pthread_tsd.c b/pthreads.subproj/pthread_tsd.c deleted file mode 100644 index f8cfb6b..0000000 --- a/pthreads.subproj/pthread_tsd.c +++ /dev/null @@ -1,167 +0,0 @@ -/* - * Copyright 1996 1995 by Open Software Foundation, Inc. 1997 1996 1995 1994 1993 1992 1991 - * 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 appears in all copies and - * that both the copyright notice and this permission notice appear in - * supporting documentation. - * - * OSF DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE - * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE. - * - * IN NO EVENT SHALL OSF BE LIABLE FOR ANY SPECIAL, INDIRECT, OR - * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM - * LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT, - * NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION - * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - * - */ -/* - * MkLinux - */ - -/* - * POSIX Pthread Library - * Thread Specific Data support - */ - -#include "pthread_internals.h" - -static struct -{ - int created; /* Set TRUE if 'create_key' used this slot */ - void (*destructor)(void *); -} _pthread_keys[_POSIX_THREAD_KEYS_MAX]; -static pthread_lock_t tds_lock = LOCK_INITIALIZER; - -/* - * Create a new key for thread specific data - */ -int -pthread_key_create(pthread_key_t *key, - void (*destructor)(void *)) -{ - int res, i; - LOCK(tds_lock); - res = ENOMEM; /* No 'free' keys */ - for (i = 0; i < _POSIX_THREAD_KEYS_MAX; i++) - { - if (_pthread_keys[i].created == FALSE) - { - _pthread_keys[i].created = TRUE; - _pthread_keys[i].destructor = destructor; - *key = i+1; - res = ESUCCESS; - break; - } - } - UNLOCK(tds_lock); - return (res); -} - -/* - * Destroy a thread specific data key - */ -int -pthread_key_delete(pthread_key_t key) -{ - int res; - LOCK(tds_lock); - if ((key >= 1) && (key <= _POSIX_THREAD_KEYS_MAX)) - { - if (_pthread_keys[key-1].created) - { - _pthread_keys[key-1].created = FALSE; - res = ESUCCESS; - } else - { - res = EINVAL; - } - } else - { /* Invalid key */ - res = EINVAL; - } - UNLOCK(tds_lock); - return (res); -} - -/* - * Set the thread private value for a given key. - * We do not take the spinlock for this or pthread_getspecific. - * The assignment to self->tsd[] is thread-safe because we never - * refer to the tsd[] of a thread other than pthread_self(). - * The reference to _pthread_keys[...].created could race with a - * pthread_key_delete() but in this case the behaviour is allowed - * to be undefined. - */ -int -pthread_setspecific(pthread_key_t key, - const void *value) -{ - int res; - pthread_t self; - if ((key >= 1) && (key <= _POSIX_THREAD_KEYS_MAX)) - { - if (_pthread_keys[key-1].created) - { - self = pthread_self(); - self->tsd[key-1] = (void *) value; - res = ESUCCESS; - } else - { - res = EINVAL; - } - } else - { /* Invalid key */ - res = EINVAL; - } - return (res); -} - -/* - * Fetch the thread private value for a given key. - * This is potentially a very heavily-used operation so we do only - * a minimum of checks. - */ -void * -pthread_getspecific(pthread_key_t key) -{ - pthread_t self; - void *res; - if ((key >= 1) && (key <= _POSIX_THREAD_KEYS_MAX)) - { - self = pthread_self(); - res = self->tsd[key-1]; - } else - { /* Invalid key - no error, just NULL */ - res = (void *)NULL; - } - return (res); -} - -/* - * Clean up thread specific data as thread 'dies' - */ -void -_pthread_tsd_cleanup(pthread_t self) -{ - int i, j; - void *param; - for (j = 0; j < PTHREAD_DESTRUCTOR_ITERATIONS; j++) - { - for (i = 0; i < _POSIX_THREAD_KEYS_MAX; i++) - { - if (_pthread_keys[i].created && (param = self->tsd[i])) - { - self->tsd[i] = (void *)NULL; - if (_pthread_keys[i].destructor) - { - (_pthread_keys[i].destructor)(param); - } - } - } - } -} diff --git a/pthreads.subproj/sched.h b/pthreads.subproj/sched.h deleted file mode 100644 index d67a482..0000000 --- a/pthreads.subproj/sched.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef _SCHED_H_ -#define _SCHED_H_ - -#include - -/* - * Scheduling paramters - */ -#ifndef __POSIX_LIB__ -struct sched_param { int sched_priority; char opaque[__SCHED_PARAM_SIZE__]; }; -#endif - -extern int sched_yield(void); -extern int sched_get_priority_min(int); -extern int sched_get_priority_max(int); -#endif /* _SCHED_H_ */ - diff --git a/pthreads.subproj/stack.s b/pthreads.subproj/stack.s deleted file mode 100644 index 7548bbf..0000000 --- a/pthreads.subproj/stack.s +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright 1996 1995 by Open Software Foundation, Inc. 1997 1996 1995 1994 1993 1992 1991 - * 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 appears in all copies and - * that both the copyright notice and this permission notice appear in - * supporting documentation. - * - * OSF DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE - * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE. - * - * IN NO EVENT SHALL OSF BE LIABLE FOR ANY SPECIAL, INDIRECT, OR - * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM - * LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT, - * NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION - * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - * - */ -/* - * MkLinux - */ - -.text - -#if defined(__ppc__) -#import -#import - -/* - * void *_sp(void) - */ - -LEAF(__sp) - mr r3,r1 - blr - -/* - * void *_adjust_sp(void *sp) - */ -LEAF(__adjust_sp) - subi r3,r3,0x100 /* Stack frame padding */ - blr - -#elif defined(__i386__) - -#import -/* - * void *_sp(void) - */ - -LEAF(__sp,0) - movl %esp,%eax - ret - -/* - * void *_adjust_sp(void *sp) - */ -LEAF(__adjust_sp,0) - movl 4(%esp),%eax - subl $0x100,%eax - ret - -#else -#error sp functions not defined for this architecture -#endif - diff --git a/pthreads.subproj/thread_setup.c b/pthreads.subproj/thread_setup.c deleted file mode 100644 index 13502dc..0000000 --- a/pthreads.subproj/thread_setup.c +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright 1996 1995 by Open Software Foundation, Inc. 1997 1996 1995 1994 1993 1992 1991 - * 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 appears in all copies and - * that both the copyright notice and this permission notice appear in - * supporting documentation. - * - * OSF DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE - * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE. - * - * IN NO EVENT SHALL OSF BE LIABLE FOR ANY SPECIAL, INDIRECT, OR - * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM - * LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT, - * NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION - * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - * - */ -/* - * MkLinux - */ - -/* - * Machine specific support for thread initialization - */ - -#if defined(__ppc__) -#include -#endif - -#include "pthread_internals.h" - -/* - * Set up the initial state of a MACH thread - */ -void -_pthread_setup(pthread_t thread, - void (*routine)(pthread_t), - vm_address_t vsp) -{ - kern_return_t r; - unsigned int count; -#if defined(__ppc__) - struct ppc_thread_state state; - struct ppc_thread_state *ts = &state; - - /* - * Set up PowerPC registers. - */ - count = PPC_THREAD_STATE_COUNT; - PTHREAD_MACH_CALL(thread_get_state(thread->kernel_thread, - PPC_THREAD_STATE, - (thread_state_t) &state, - &count), - r); - - ts->srr0 = (int) routine; - ts->r1 = vsp - C_ARGSAVE_LEN - C_RED_ZONE; - ts->r3 = (int)thread; - PTHREAD_MACH_CALL(thread_set_state(thread->kernel_thread, - PPC_THREAD_STATE, - (thread_state_t) &state, - PPC_THREAD_STATE_COUNT), - r); -#elif defined(__i386__) - i386_thread_state_t state; - i386_thread_state_t *ts = &state; - int *sp = (int *) vsp; - - /* - * Set up i386 registers & function call. - */ - count = i386_THREAD_STATE_COUNT; - PTHREAD_MACH_CALL(thread_get_state(thread->kernel_thread, - i386_THREAD_STATE, - (thread_state_t) &state, - &count), - r); - ts->eip = (int) routine; - *--sp = (int) thread; /* argument to function */ - *--sp = 0; /* fake return address */ - ts->esp = (int) sp; /* set stack pointer */ - PTHREAD_MACH_CALL(thread_set_state(thread->kernel_thread, - i386_THREAD_STATE, - (thread_state_t) &state, - i386_THREAD_STATE_COUNT), - r); - -#else -#error _pthread_setup not defined for this architecture -#endif -} diff --git a/pthreads/Makefile.inc b/pthreads/Makefile.inc new file mode 100644 index 0000000..acd3d05 --- /dev/null +++ b/pthreads/Makefile.inc @@ -0,0 +1,70 @@ +.PATH: ${.CURDIR}/${MACHINE_ARCH}/pthreads ${.CURDIR}/pthreads + +SRCS += pthread_cond.c pthread_tsd.c pthread.c \ + pthread_mutex.c thread_setup.c lock.s stack.s pthread_rwlock.c + +PTHREADS_INSTHDRS += pthread.h pthread_impl.h sched.h +PTHREADS_INSTHDRS := ${PTHREADS_INSTHDRS:S/^/${.CURDIR}\/pthreads\//} +INSTHDRS += ${PTHREADS_INSTHDRS} + +.if ${LIB} == "c" +MAN3+= pthread.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 \ + pthread_cond_timedwait.3 pthread_cond_wait.3 \ + pthread_create.3 pthread_detach.3 \ + pthread_equal.3 pthread_exit.3 \ + pthread_getschedparam.3 pthread_getspecific.3 \ + pthread_join.3 pthread_key_create.3 \ + pthread_key_delete.3 pthread_mutex_destroy.3 \ + pthread_mutex_init.3 pthread_mutex_lock.3 \ + pthread_mutex_trylock.3 pthread_mutex_unlock.3 \ + pthread_mutexattr.3 pthread_once.3 \ + pthread_self.3 pthread_setcancelstate.3 \ + pthread_setspecific.3 pthread_condattr.3 \ + pthread_rwlock_destroy.3 pthread_rwlock_init.3 \ + pthread_rwlock_rdlock.3 pthread_rwlock_unlock.3 \ + pthread_rwlock_wrlock.3 pthread_rwlockattr_destroy.3 \ + pthread_rwlockattr_getpshared.3 pthread_rwlockattr_init.3 \ + pthread_rwlockattr_setpshared.3 + +MLINKS+=pthread_attr.3 pthread_attr_destroy.3 \ + pthread_attr.3 pthread_attr_getdetachstate.3 \ + pthread_attr.3 pthread_attr_getinheritsched.3 \ + pthread_attr.3 pthread_attr_getschedparam.3 \ + pthread_attr.3 pthread_attr_getschedpolicy.3 \ + pthread_attr.3 pthread_attr_getscope.3 \ + pthread_attr.3 pthread_attr_getstackaddr.3 \ + pthread_attr.3 pthread_attr_getstacksize.3 \ + pthread_attr.3 pthread_attr_init.3 \ + pthread_attr.3 pthread_attr_setdetachstate.3 \ + pthread_attr.3 pthread_attr_setinheritsched.3 \ + pthread_attr.3 pthread_attr_setschedparam.3 \ + pthread_attr.3 pthread_attr_setschedpolicy.3 \ + pthread_attr.3 pthread_attr_setscope.3 \ + pthread_attr.3 pthread_attr_setstackaddr.3 \ + pthread_attr.3 pthread_attr_setstacksize.3 + +MLINKS+=pthread_getschedparam.3 pthread_setschedparam.3 + +MLINKS+=pthread_mutexattr.3 pthread_mutexattr_destroy.3 \ + pthread_mutexattr.3 pthread_mutexattr_getprioceiling.3 \ + pthread_mutexattr.3 pthread_mutexattr_getprotocol.3 \ + pthread_mutexattr.3 pthread_mutexattr_init.3 \ + pthread_mutexattr.3 pthread_mutexattr_setprioceiling.3 \ + pthread_mutexattr.3 pthread_mutexattr_setprotocol.3 + +MLINKS+=pthread_setcancelstate.3 pthread_setcanceltype.3 \ + pthread_setcancelstate.3 pthread_testcancel.3 + +MLINKS+=pthread_condattr.3 pthread_condattr_init.3 \ + pthread_condattr.3 pthread_condattr_destroy.3 + +MLINKS+=pthread_rwlock_rdlock.3 pthread_rwlock_tryrdlock.3 + +MLINKS+=pthread_rwlock_wrlock.3 pthread_rwlock_trywrlock.3 + +.endif + + diff --git a/pthreads/lock.s b/pthreads/lock.s new file mode 100644 index 0000000..257bc1b --- /dev/null +++ b/pthreads/lock.s @@ -0,0 +1,142 @@ +/* + * Copyright 1996 1995 by Open Software Foundation, Inc. 1997 1996 1995 1994 1993 1992 1991 + * 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 appears in all copies and + * that both the copyright notice and this permission notice appear in + * supporting documentation. + * + * OSF DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE. + * + * IN NO EVENT SHALL OSF BE LIABLE FOR ANY SPECIAL, INDIRECT, OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM + * LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT, + * NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION + * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + */ +/* + * MkLinux + */ + +#if defined(__ppc__) + +#import +#import + +/* void spin_lock(int *p); + * + * Lock the lock pointed to by `p'. Spin (possibly forever) until + * the lock is available. Test and test and set logic used. + */ + +.text + +LEAF(__spin_lock_try) +1: + lwarx r5,0,r3 // Read the lock + addi r4,0,0x1 // Lock value + cmpwi r5,0x0 // Is it busy? + bne- 2f // Yes, return 0 + stwcx. r4,0,r3 // Try to lock the lock + bne- 1b // Lost reservation, try again + addi r3,0,1 // Got the lock + isync // Sync instruction stream + blr // Return 1 +2: addi r3,0,0 // Could not get the lock + blr // Return 0 +END(__spin_lock_try) + +.globl _spin_lock +LEAF(__spin_lock) +_spin_lock: +1: + lwarx r5,0,r3 // Read the lock + addi r4,0,0x1 // Lock value + cmpwi r5,0x0 // Is it busy? + bne- 2f // Yes, goto retry logic + stwcx. r4,0,r3 // Try to lock the lock + bne- 1b // Lost reservation, try again + isync // Sync instruction stream + blr // Return +2: + CALL_EXTERN(__spin_lock_retry) + blr // Return +END(__spin_lock) + +/* void spin_unlock(int *p); + * + * Unlock the lock pointed to by p. + */ +.globl _spin_unlock +LEAF(__spin_unlock) +_spin_unlock: + sync + li32 r4,0 + stw r4,0(r3) + blr +END(__spin_unlock) + +#elif defined(__i386__) + +#include + +/* + * void + * _spin_lock(p) + * int *p; + * + * Lock the lock pointed to by p. Spin (possibly forever) until the next + * lock is available. + */ + TEXT + +.globl _spin_lock_try +LEAF(__spin_lock_try, 0) +_spin_lock_try: + movl 4(%esp),%ecx + movl $1,%eax + xchgl (%ecx),%eax + xorl $1,%eax +END(__spin_lock_try) + +.globl _spin_lock +LEAF(__spin_lock, 0) +_spin_lock: + movl 4(%esp), %ecx + movl (%ecx), %eax + orl %eax, %eax + jnz 1f + movl $0xFFFFFFFF, %eax + xchgl %eax, (%ecx) + orl %eax, %eax + jz 2f +1: pushl %ecx + CALL_EXTERN(__spin_lock_retry) + addl $4, %esp +2: +END(__spin_lock) + + +/* + * void + * _spin_unlock(p) + * int *p; + * + * Unlock the lock pointed to by p. + */ +.globl _spin_unlock +LEAF(__spin_unlock, 0) +_spin_unlock: + movl $0, %eax + movl 4(%esp), %ecx + xchgl %eax, (%ecx) +END(__spin_unlock) + +#else +#error spin_locks not defined for this architecture +#endif diff --git a/pthreads/mk_pthread_impl.c b/pthreads/mk_pthread_impl.c new file mode 100644 index 0000000..67b8c1b --- /dev/null +++ b/pthreads/mk_pthread_impl.c @@ -0,0 +1,68 @@ +/* + * Copyright 1996 1995 by Open Software Foundation, Inc. 1997 1996 1995 1994 1993 1992 1991 + * 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 appears in all copies and + * that both the copyright notice and this permission notice appear in + * supporting documentation. + * + * OSF DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE. + * + * IN NO EVENT SHALL OSF BE LIABLE FOR ANY SPECIAL, INDIRECT, OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM + * LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT, + * NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION + * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + */ +/* + * MkLinux + */ + +/* + * This program will generate the stuff necessary to "publish" the POSIX + * header in a machine dependent fashion. + */ + +#include +#include + +int +main(void) +{ + printf("#ifndef _PTHREAD_IMPL_H_\n"); + printf("#define _PTHREAD_IMPL_H_\n"); + printf("/*\n"); + 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("/*\n"); + printf(" * [Internal] data structure signatures\n"); + printf(" */\n"); + printf("#define _PTHREAD_MUTEX_SIG_init 0x%08X\n", _PTHREAD_MUTEX_SIG_init); + printf("#define _PTHREAD_COND_SIG_init 0x%08X\n", _PTHREAD_COND_SIG_init); + printf("#define _PTHREAD_ONCE_SIG_init 0x%08X\n", _PTHREAD_ONCE_SIG_init); + printf("/*\n"); + printf(" * POSIX scheduling policies \n"); + printf(" */\n"); + printf("#define SCHED_OTHER %d\n", SCHED_OTHER); + printf("#define SCHED_FIFO %d\n", SCHED_FIFO); + printf("#define SCHED_RR %d\n", SCHED_RR); + printf("\n"); + printf("#define __SCHED_PARAM_SIZE__ %ld\n", (long) sizeof(struct sched_param)-sizeof(int)); + printf("\n"); + printf("#endif _PTHREAD_IMPL_H_\n"); + + exit(0); +} diff --git a/pthreads/posix_sched.h b/pthreads/posix_sched.h new file mode 100644 index 0000000..b9badf1 --- /dev/null +++ b/pthreads/posix_sched.h @@ -0,0 +1,47 @@ +/* + * Copyright 1996 1995 by Open Software Foundation, Inc. 1997 1996 1995 1994 1993 1992 1991 + * 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 appears in all copies and + * that both the copyright notice and this permission notice appear in + * supporting documentation. + * + * OSF DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE. + * + * IN NO EVENT SHALL OSF BE LIABLE FOR ANY SPECIAL, INDIRECT, OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM + * LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT, + * NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION + * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + */ +/* + * MkLinux + */ + +/* + * POSIX Realtime Scheduling Framework - IEEE 1003.1b + */ + +#ifndef _POSIX_SCHED_H +#define _POSIX_SCHED_H + +struct sched_param +{ + int sched_priority; + int quantum; +}; + +/* + * POSIX scheduling policies + */ + +#define SCHED_OTHER POLICY_TIMESHARE +#define SCHED_FIFO POLICY_FIFO +#define SCHED_RR POLICY_RR + +#endif /* _POSIX_SCHED_H */ diff --git a/pthreads/pthread.3 b/pthreads/pthread.3 new file mode 100644 index 0000000..444e361 --- /dev/null +++ b/pthreads/pthread.3 @@ -0,0 +1,435 @@ +.\" Portions Copyright (c) 2001 Apple Computer, Inc. All Rights Reserved. +.\" Copyright (c) 1996 John Birrell . +.\" 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 John Birrell. +.\" 4. Neither the name of the author nor the names of any co-contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL 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. +.\" +.\" $FreeBSD: src/share/man/man3/pthread.3,v 1.12.2.4 2001/08/17 13:08:36 ru Exp $ +.\" +.Dd November 5, 2001 +.Dt PTHREAD 3 +.Os Darwin +.Sh NAME +.Nm pthread +.Nd POSIX thread functions +.Sh SYNOPSIS +.Fd #include +.Sh DESCRIPTION +POSIX threads are a set of functions that support applications with +requirements for multiple flows of control, called +.Fa threads , +within a process. +Multithreading is used to improve the performance of a +program. +.Pp +The POSIX thread functions are summarized in this section in the following +groups: +.Bl -bullet -offset indent +.It +Thread Routines +.It +Attribute Object Routines +.It +Mutex Routines +.It +Condition Variable Routines +.It +Read/Write Lock Routines +.It +Per-Thread Context Routines +.It +Cleanup Routines +.El +.Sh THREAD ROUTINES +.Bl -tag -width Er +.It Xo +.Ft int +.Fn pthread_create "pthread_t *thread" "const pthread_attr_t *attr" "void *(*start_routine)(void *)" "void *arg" +.Xc +Creates a new thread of execution. +.It Xo +.Ft int +.Fn pthread_detach "pthread_t thread" +.Xc +Marks a thread for deletion. +.It Xo +.Ft int +.Fn pthread_equal "pthread_t t1" "pthread_t t2" +.Xc +Compares two thread IDs. +.It Xo +.Ft void +.Fn pthread_exit "void *value_ptr" +.Xc +Terminates the calling thread. +.It Xo +.Ft int +.Fn pthread_join "pthread_t thread" "void **value_ptr" +.Xc +Causes the calling thread to wait for the termination of the specified thread. +.It Xo +.Ft int +.Fn pthread_cancel "pthread_t thread" +.Xc +Cancels execution of a thread. +.It Xo +.Ft int +.Fn pthread_once "pthread_once_t *once_control" "void (*init_routine)(void)" +.Xc +Calls an initialization routine once. +.It Xo +.Ft pthread_t +.Fn pthread_self void +.Xc +Returns the thread ID of the calling thread. +.El +.Sh ATTRIBUTE OBJECT ROUTINES +.Bl -tag -width Er +.It Xo +.Ft int +.Fn pthread_attr_destroy "pthread_attr_t *attr" +.Xc +Destroy a thread attributes object. +.It Xo +.Ft int +.Fn pthread_attr_getinheritsched "const pthread_attr_t *attr" "int *inheritsched" +.Xc +Get the inherit scheduling attribute from a thread attributes object. +.It Xo +.Ft int +.Fn pthread_attr_getschedparam "const pthread_attr_t *attr" "struct sched_param *param" +.Xc +Get the scheduling parameter attribute from a thread attributes object. +.It Xo +.Ft int +.Fn pthread_attr_getschedpolicy "const pthread_attr_t *attr" "int *policy" +.Xc +Get the scheduling policy attribute from a thread attributes object. +.It Xo +.Ft int +.Fn pthread_attr_getscope "const pthread_attr_t *attr" "int *contentionscope" +.Xc +Get the contention scope attribute from a thread attributes object. +.It Xo +.Ft int +.Fn pthread_attr_getstacksize "const pthread_attr_t *attr" "size_t *stacksize" +.Xc +Get the stack size attribute from a thread attributes object. +.It Xo +.Ft int +.Fn pthread_attr_getstackaddr "const pthread_attr_t *attr" "void **stackaddr" +.Xc +Get the stack address attribute from a thread attributes object. +.It Xo +.Ft int +.Fn pthread_attr_getdetachstate "const pthread_attr_t *attr" "int *detachstate" +.Xc +Get the detach state attribute from a thread attributes object. +.It Xo +.Ft int +.Fn pthread_attr_init "pthread_attr_t *attr" +.Xc +Initialize a thread attributes object with default values. +.It Xo +.Ft int +.Fn pthread_attr_setinheritsched "pthread_attr_t *attr" "int inheritsched" +.Xc +Set the inherit scheduling attribute in a thread attributes object. +.It Xo +.Ft int +.Fn pthread_attr_setschedparam "pthread_attr_t *attr" "const struct sched_param *param" +.Xc +Set the scheduling parameter attribute in a thread attributes object. +.It Xo +.Ft int +.Fn pthread_attr_setschedpolicy "pthread_attr_t *attr" "int policy" +.Xc +Set the scheduling policy attribute in a thread attributes object. +.It Xo +.Ft int +.Fn pthread_attr_setscope "pthread_attr_t *attr" "int contentionscope" +.Xc +Set the contention scope attribute in a thread attributes object. +.It Xo +.Ft int +.Fn pthread_attr_setstacksize "pthread_attr_t *attr" "size_t stacksize" +.Xc +Set the stack size attribute in a thread attributes object. +.It Xo +.Ft int +.Fn pthread_attr_setstackaddr "pthread_attr_t *attr" "void *stackaddr" +.Xc +Set the stack address attribute in a thread attributes object. +.It Xo +.Ft int +.Fn pthread_attr_setdetachstate "pthread_attr_t *attr" "int detachstate" +.Xc +Set the detach state in a thread attributes object. +.El +.Sh MUTEX ROUTINES +.Bl -tag -width Er +.It Xo +.Ft int +.Fn pthread_mutexattr_destroy "pthread_mutexattr_t *attr" +.Xc +Destroy a mutex attributes object. +.It Xo +.Ft int +.Fn pthread_mutexattr_init "pthread_mutexattr_t *attr" +.Xc +Initialize a mutex attributes object with default values. +.It Xo +.Ft int +.Fn pthread_mutex_destroy "pthread_mutex_t *mutex" +.Xc +Destroy a mutex. +.It Xo +.Ft int +.Fn pthread_mutex_init "pthread_mutex_t *mutex" "const pthread_mutexattr_t *attr" +.Xc +Initialize a mutex with specified attributes. +.It Xo +.Ft int +.Fn pthread_mutex_lock "pthread_mutex_t *mutex" +.Xc +Lock a mutex and block until it becomes available. +.It Xo +.Ft int +.Fn pthread_mutex_trylock "pthread_mutex_t *mutex" +.Xc +Try to lock a mutex, but don't block if the mutex is locked by another thread, +including the current thread. +.It Xo +.Ft int +.Fn pthread_mutex_unlock "pthread_mutex_t *mutex" +.Xc +Unlock a mutex. +.El +.Sh CONDITION VARIABLE ROUTINES +.Bl -tag -width Er +.It Xo +.Ft int +.Fn pthread_condattr_init "pthread_condattr_t *attr" +.Xc +Initialize a condition variable attributes object with default values. +.It Xo +.Ft int +.Fn pthread_condattr_destroy "pthread_condattr_t *attr" +.Xc +Destroy a condition variable attributes object. +.It Xo +.Ft int +.Fn pthread_cond_broadcast "pthread_cond_t *cond" +.Xc +Unblock all threads currently blocked on the specified condition variable. +.It Xo +.Ft int +.Fn pthread_cond_destroy "pthread_cond_t *cond" +.Xc +Destroy a condition variable. +.It Xo +.Ft int +.Fn pthread_cond_init "pthread_cond_t *cond" "const pthread_condattr_t *attr" +.Xc +Initialize a condition variable with specified attributes. +.It Xo +.Ft int +.Fn pthread_cond_signal "pthread_cond_t *cond" +.Xc +Unblock at least one of the threads blocked on the specified condition variable. +.It Xo +.Ft int +.Fn pthread_cond_timedwait "pthread_cond_t *cond" "pthread_mutex_t *mutex" "const struct timespec *abstime" +.Xc +Wait no longer than the specified time for a condition and lock the specified mutex. +.It Xo +.Ft int +.Fn pthread_cond_wait "pthread_cond_t *" "pthread_mutex_t *mutex" +.Xc +Wait for a condition and lock the specified mutex. +.El +.Sh READ/WRITE LOCK ROUTINES +.Bl -tag -width Er +.It Xo +.Ft int +.Fn pthread_rwlock_destroy "pthread_rwlock_t *lock" +.Xc +Destroy a read/write lock object. +.It Xo +.Ft int +.Fn pthread_rwlock_init "pthread_rwlock_t *lock" "const pthread_rwlockattr_t *attr" +.Xc +Initialize a read/write lock object. +.It Xo +.Ft int +.Fn pthread_rwlock_rdlock "pthread_rwlock_t *lock" +.Xc +Lock a read/write lock for reading, blocking until the lock can be +acquired. +.It Xo +.Ft int +.Fn pthread_rwlock_tryrdlock "pthread_rwlock_t *lock" +.Xc +Attempt to lock a read/write lock for reading, without blocking if the +lock is unavailable. +.It Xo +.Ft int +.Fn pthread_rwlock_trywrlock "pthread_rwlock_t *lock" +.Xc +Attempt to lock a read/write lock for writing, without blocking if the +lock is unavailable. +.It Xo +.Ft int +.Fn pthread_rwlock_unlock "pthread_rwlock_t *lock" +.Xc +Unlock a read/write lock. +.It Xo +.Ft int +.Fn pthread_rwlock_wrlock "pthread_rwlock_t *lock" +.Xc +Lock a read/write lock for writing, blocking until the lock can be +acquired. +.It Xo +.Ft int +.Fn pthread_rwlockattr_destroy "pthread_rwlockattr_t *attr" +.Xc +Destroy a read/write lock attribute object. +.It Xo +.Ft int +.Fn pthread_rwlockattr_getpshared "const pthread_rwlockattr_t *attr" "int *pshared" +.Xc +Retrieve the process shared setting for the read/write lock attribute +object. +.It Xo +.Ft int +.Fn pthread_rwlockattr_init "pthread_rwlockattr_t *attr" +.Xc +Initialize a read/write lock attribute object. +.It Xo +.Ft int +.Fn pthread_rwlockattr_setpshared "pthread_rwlockattr_t *attr" "int pshared" +.Xc +Set the process shared setting for the read/write lock attribute object. +.El +.Sh PER-THREAD CONTEXT ROUTINES +.Bl -tag -width Er +.It Xo +.Ft int +.Fn pthread_key_create "pthread_key_t *key" "void (*routine)(void *)" +.Xc +Create a thread-specific data key. +.It Xo +.Ft int +.Fn pthread_key_delete "pthread_key_t key" +.Xc +Delete a thread-specific data key. +.It Xo +.Ft "void *" +.Fn pthread_getspecific "pthread_key_t key" +.Xc +Get the thread-specific value for the specified key. +.It Xo +.Ft int +.Fn pthread_setspecific "pthread_key_t key" "const void *value_ptr" +.Xc +Set the thread-specific value for the specified key. +.El +.Sh CLEANUP ROUTINES +.Bl -tag -width Er +.It Xo +.Ft void +.Fn pthread_cleanup_pop "int execute" +.Xc +Remove the routine at the top of the calling thread's cancellation cleanup +stack and optionally invoke it. +.It Xo +.Ft void +.Fn pthread_cleanup_push "void (*routine)(void *)" "void *routine_arg" +.Xc +Push the specified cancellation cleanup handler onto the calling thread's +cancellation stack. +.El +.Sh INSTALLATION +The default system libraries include +.Nm +funcitons. No additional libraries or CFLAGS are necessary to use this API. +.Sh SEE ALSO +.Xr pthread_cleanup_pop 3 , +.Xr pthread_cleanup_push 3 , +.Xr pthread_cond_broadcast 3 , +.Xr pthread_cond_destroy 3 , +.Xr pthread_cond_init 3 , +.Xr pthread_cond_signal 3 , +.Xr pthread_cond_timedwait 3 , +.Xr pthread_cond_wait 3 , +.Xr pthread_create 3 , +.Xr pthread_detach 3 , +.Xr pthread_equal 3 , +.Xr pthread_exit 3 , +.Xr pthread_getspecific 3 , +.Xr pthread_join 3 , +.Xr pthread_key_delete 3 , +.Xr pthread_mutex_destroy 3 , +.Xr pthread_mutex_init 3 , +.Xr pthread_mutex_lock 3 , +.Xr pthread_mutex_trylock 3 , +.Xr pthread_mutex_unlock 3 , +.Xr pthread_once 3 , +.Xr pthread_rwlockattr_destroy 3 , +.Xr pthread_rwlockattr_getpshared 3 , +.Xr pthread_rwlockattr_init 3 , +.Xr pthread_rwlockattr_setpshared 3 , +.Xr pthread_rwlock_destroy 3 , +.Xr pthread_rwlock_init 3 , +.Xr pthread_rwlock_rdlock 3 , +.Xr pthread_rwlock_unlock 3 , +.Xr pthread_rwlock_wrlock 3 , +.Xr pthread_self 3 , +.Xr pthread_setspecific 3 +.Sh STANDARDS +The functions in +.Fa libc +with the +.Fa pthread_ +prefix and not +.Fa _np +suffix or +.Fa pthread_rwlock +prefix conform to +.St -p1003.1-96 . +.Pp +The functions in libc with the +.Fa pthread_ +prefix and +.Fa _np +suffix are non-portable extensions to POSIX threads. +.Pp +The functions in libc with the +.Fa pthread_rwlock +prefix are extensions created by The Open Group as part of the +.St -susv2 . diff --git a/pthreads/pthread.c b/pthreads/pthread.c new file mode 100644 index 0000000..14d7446 --- /dev/null +++ b/pthreads/pthread.c @@ -0,0 +1,1431 @@ +/* + * Copyright 1996 1995 by Open Software Foundation, Inc. 1997 1996 1995 1994 1993 1992 1991 + * 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 appears in all copies and + * that both the copyright notice and this permission notice appear in + * supporting documentation. + * + * OSF DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE. + * + * IN NO EVENT SHALL OSF BE LIABLE FOR ANY SPECIAL, INDIRECT, OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM + * LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT, + * NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION + * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + */ +/* + * MkLinux + */ + +/* + * POSIX Pthread Library + */ + +#define __POSIX_LIB__ +#include +#include /* For printf(). */ +#include +#include /* For __mach_errno_addr() prototype. */ +#include +#include +#include +#include +#include +#include + +#include "pthread_internals.h" + +/* Per-thread kernel support */ +extern void _pthread_set_self(pthread_t); +extern void mig_init(int); + +/* Needed to tell the malloc subsystem we're going multithreaded */ +extern void set_malloc_singlethreaded(int); + +/* Used when we need to call into the kernel with no reply port */ +extern pthread_lock_t reply_port_lock; + +/* 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}; + +/* This global should be used (carefully) by anyone needing to know if a +** pthread has been created. +*/ +int __is_threaded = 0; +static int _pthread_count = 1; + +static pthread_lock_t _pthread_count_lock = LOCK_INITIALIZER; + +/* Same implementation as LOCK, but without the __is_threaded check */ +int _spin_tries = 0; +__private_extern__ void _spin_lock_retry(pthread_lock_t *lock) +{ + int tries = _spin_tries; + do { + if (tries-- > 0) + continue; + syscall_thread_switch(THREAD_NULL, SWITCH_OPTION_DEPRESS, 1); + tries = _spin_tries; + } while(!_spin_lock_try(lock)); +} + +/* Apparently, bcopy doesn't declare _cpu_has_altivec anymore */ +int _cpu_has_altivec = 0; + +extern mach_port_t thread_recycle_port; + +/* These are used to keep track of a semaphore pool shared by mutexes and condition +** variables. +*/ + +static semaphore_t *sem_pool = NULL; +static int sem_pool_count = 0; +static int sem_pool_current = 0; +static pthread_lock_t sem_pool_lock = LOCK_INITIALIZER; + +static int default_priority; +static int max_priority; +static int min_priority; +static int pthread_concurrency; + +/* + * [Internal] stack support + */ +size_t _pthread_stack_size = 0; +#define STACK_LOWEST(sp) ((sp) & ~__pthread_stack_mask) +#define STACK_RESERVED (sizeof (struct _pthread)) + +#ifdef STACK_GROWS_UP + +/* The stack grows towards higher addresses: + |struct _pthread|user stack---------------->| + ^STACK_BASE ^STACK_START + ^STACK_SELF + ^STACK_LOWEST */ +#define STACK_BASE(sp) STACK_LOWEST(sp) +#define STACK_START(stack_low) (STACK_BASE(stack_low) + STACK_RESERVED) +#define STACK_SELF(sp) STACK_BASE(sp) + +#else + +/* The stack grows towards lower addresses: + |<----------------user stack|struct _pthread| + ^STACK_LOWEST ^STACK_START ^STACK_BASE + ^STACK_SELF */ + +#define STACK_BASE(sp) (((sp) | __pthread_stack_mask) + 1) +#define STACK_START(stack_low) (STACK_BASE(stack_low) - STACK_RESERVED) +#define STACK_SELF(sp) STACK_START(sp) + +#endif + +#if defined(__ppc__) +static const vm_address_t PTHREAD_STACK_HINT = 0xF0000000; +#elif defined(__i386__) +static const vm_address_t PTHREAD_STACK_HINT = 0xB0000000; +#else +#error Need to define a stack address hint for this architecture +#endif + +/* Set the base address to use as the stack pointer, before adjusting due to the ABI */ + +static int +_pthread_allocate_stack(pthread_attr_t *attrs, void **stack) +{ + kern_return_t kr; +#if 1 + assert(attrs->stacksize >= PTHREAD_STACK_MIN); + if (attrs->stackaddr != NULL) { + assert(((vm_address_t)(attrs->stackaddr) & (vm_page_size - 1)) == 0); + *stack = attrs->stackaddr; + return 0; + } + + *((vm_address_t *)stack) = PTHREAD_STACK_HINT; + kr = vm_map(mach_task_self(), (vm_address_t *)stack, + attrs->stacksize + vm_page_size, + vm_page_size-1, + VM_MAKE_TAG(VM_MEMORY_STACK)| VM_FLAGS_ANYWHERE , MEMORY_OBJECT_NULL, + 0, FALSE, VM_PROT_DEFAULT, VM_PROT_ALL, + VM_INHERIT_DEFAULT); + if (kr != KERN_SUCCESS) + kr = vm_allocate(mach_task_self(), + (vm_address_t *)stack, attrs->stacksize + vm_page_size, + VM_MAKE_TAG(VM_MEMORY_STACK)| VM_FLAGS_ANYWHERE); + if (kr != KERN_SUCCESS) { + return EAGAIN; + } + #ifdef STACK_GROWS_UP + /* The guard page is the page one higher than the stack */ + /* The stack base is at the lowest address */ + kr = vm_protect(mach_task_self(), *stack + attrs->stacksize, vm_page_size, FALSE, VM_PROT_NONE); + #else + /* The guard page is at the lowest address */ + /* The stack base is the highest address */ + kr = vm_protect(mach_task_self(), (vm_address_t)*stack, vm_page_size, FALSE, VM_PROT_NONE); + *stack += attrs->stacksize + vm_page_size; + #endif + +#else + vm_address_t cur_stack = (vm_address_t)0; + if (free_stacks == 0) + { + /* Allocating guard pages is done by doubling + * the actual stack size, since STACK_BASE() needs + * to have stacks aligned on stack_size. Allocating just + * one page takes as much memory as allocating more pages + * since it will remain one entry in the vm map. + * Besides, allocating more than one page allows tracking the + * overflow pattern when the overflow is bigger than one page. + */ +#ifndef NO_GUARD_PAGES +# define GUARD_SIZE(a) (2*(a)) +# define GUARD_MASK(a) (((a)<<1) | 1) +#else +# define GUARD_SIZE(a) (a) +# define GUARD_MASK(a) (a) +#endif + while (lowest_stack > GUARD_SIZE(__pthread_stack_size)) + { + lowest_stack -= GUARD_SIZE(__pthread_stack_size); + /* Ensure stack is there */ + kr = vm_allocate(mach_task_self(), + &lowest_stack, + GUARD_SIZE(__pthread_stack_size), + FALSE); +#ifndef NO_GUARD_PAGES + if (kr == KERN_SUCCESS) { +# ifdef STACK_GROWS_UP + kr = vm_protect(mach_task_self(), + lowest_stack+__pthread_stack_size, + __pthread_stack_size, + FALSE, VM_PROT_NONE); +# else /* STACK_GROWS_UP */ + kr = vm_protect(mach_task_self(), + lowest_stack, + __pthread_stack_size, + FALSE, VM_PROT_NONE); + lowest_stack += __pthread_stack_size; +# endif /* STACK_GROWS_UP */ + if (kr == KERN_SUCCESS) + break; + } +#else + if (kr == KERN_SUCCESS) + break; +#endif + } + if (lowest_stack > 0) + free_stacks = (vm_address_t *)lowest_stack; + else + { + /* Too bad. We'll just have to take what comes. + Use vm_map instead of vm_allocate so we can + specify alignment. */ + kr = vm_map(mach_task_self(), &lowest_stack, + GUARD_SIZE(__pthread_stack_size), + GUARD_MASK(__pthread_stack_mask), + TRUE /* anywhere */, MEMORY_OBJECT_NULL, + 0, FALSE, VM_PROT_DEFAULT, VM_PROT_ALL, + VM_INHERIT_DEFAULT); + /* This really shouldn't fail and if it does I don't + know what to do. */ +#ifndef NO_GUARD_PAGES + if (kr == KERN_SUCCESS) { +# ifdef STACK_GROWS_UP + kr = vm_protect(mach_task_self(), + lowest_stack+__pthread_stack_size, + __pthread_stack_size, + FALSE, VM_PROT_NONE); +# else /* STACK_GROWS_UP */ + kr = vm_protect(mach_task_self(), + lowest_stack, + __pthread_stack_size, + FALSE, VM_PROT_NONE); + lowest_stack += __pthread_stack_size; +# endif /* STACK_GROWS_UP */ + } +#endif + free_stacks = (vm_address_t *)lowest_stack; + lowest_stack = 0; + } + *free_stacks = 0; /* No other free stacks */ + } + cur_stack = STACK_START((vm_address_t) free_stacks); + free_stacks = (vm_address_t *)*free_stacks; + cur_stack = _adjust_sp(cur_stack); /* Machine dependent stack fudging */ +#endif + return 0; +} + +static pthread_attr_t _pthread_attr_default = {0}; + +/* + * Destroy a thread attribute structure + */ +int +pthread_attr_destroy(pthread_attr_t *attr) +{ + if (attr->sig == _PTHREAD_ATTR_SIG) + { + return (ESUCCESS); + } else + { + return (EINVAL); /* Not an attribute structure! */ + } +} + +/* + * Get the 'detach' state from a thread attribute structure. + * Note: written as a helper function for info hiding + */ +int +pthread_attr_getdetachstate(const pthread_attr_t *attr, + int *detachstate) +{ + if (attr->sig == _PTHREAD_ATTR_SIG) + { + *detachstate = attr->detached; + return (ESUCCESS); + } else + { + return (EINVAL); /* Not an attribute structure! */ + } +} + +/* + * Get the 'inherit scheduling' info from a thread attribute structure. + * Note: written as a helper function for info hiding + */ +int +pthread_attr_getinheritsched(const pthread_attr_t *attr, + int *inheritsched) +{ + if (attr->sig == _PTHREAD_ATTR_SIG) + { + *inheritsched = attr->inherit; + return (ESUCCESS); + } else + { + return (EINVAL); /* Not an attribute structure! */ + } +} + +/* + * Get the scheduling parameters from a thread attribute structure. + * Note: written as a helper function for info hiding + */ +int +pthread_attr_getschedparam(const pthread_attr_t *attr, + struct sched_param *param) +{ + if (attr->sig == _PTHREAD_ATTR_SIG) + { + *param = attr->param; + return (ESUCCESS); + } else + { + return (EINVAL); /* Not an attribute structure! */ + } +} + +/* + * Get the scheduling policy from a thread attribute structure. + * Note: written as a helper function for info hiding + */ +int +pthread_attr_getschedpolicy(const pthread_attr_t *attr, + int *policy) +{ + if (attr->sig == _PTHREAD_ATTR_SIG) + { + *policy = attr->policy; + return (ESUCCESS); + } else + { + return (EINVAL); /* Not an attribute structure! */ + } +} + +static const size_t DEFAULT_STACK_SIZE = DFLSSIZ; +/* + * Initialize a thread attribute structure to default values. + */ +int +pthread_attr_init(pthread_attr_t *attr) +{ + attr->stacksize = DEFAULT_STACK_SIZE; + attr->stackaddr = NULL; + attr->sig = _PTHREAD_ATTR_SIG; + attr->policy = _PTHREAD_DEFAULT_POLICY; + attr->param.sched_priority = default_priority; + attr->param.quantum = 10; /* quantum isn't public yet */ + attr->inherit = _PTHREAD_DEFAULT_INHERITSCHED; + attr->detached = PTHREAD_CREATE_JOINABLE; + attr->freeStackOnExit = TRUE; + return (ESUCCESS); +} + +/* + * Set the 'detach' state in a thread attribute structure. + * Note: written as a helper function for info hiding + */ +int +pthread_attr_setdetachstate(pthread_attr_t *attr, + int detachstate) +{ + if (attr->sig == _PTHREAD_ATTR_SIG) + { + if ((detachstate == PTHREAD_CREATE_JOINABLE) || + (detachstate == PTHREAD_CREATE_DETACHED)) + { + attr->detached = detachstate; + return (ESUCCESS); + } else + { + return (EINVAL); + } + } else + { + return (EINVAL); /* Not an attribute structure! */ + } +} + +/* + * Set the 'inherit scheduling' state in a thread attribute structure. + * Note: written as a helper function for info hiding + */ +int +pthread_attr_setinheritsched(pthread_attr_t *attr, + int inheritsched) +{ + if (attr->sig == _PTHREAD_ATTR_SIG) + { + if ((inheritsched == PTHREAD_INHERIT_SCHED) || + (inheritsched == PTHREAD_EXPLICIT_SCHED)) + { + attr->inherit = inheritsched; + return (ESUCCESS); + } else + { + return (EINVAL); + } + } else + { + return (EINVAL); /* Not an attribute structure! */ + } +} + +/* + * Set the scheduling paramters in a thread attribute structure. + * Note: written as a helper function for info hiding + */ +int +pthread_attr_setschedparam(pthread_attr_t *attr, + const struct sched_param *param) +{ + if (attr->sig == _PTHREAD_ATTR_SIG) + { + /* TODO: Validate sched_param fields */ + attr->param = *param; + return (ESUCCESS); + } else + { + return (EINVAL); /* Not an attribute structure! */ + } +} + +/* + * Set the scheduling policy in a thread attribute structure. + * Note: written as a helper function for info hiding + */ +int +pthread_attr_setschedpolicy(pthread_attr_t *attr, + int policy) +{ + if (attr->sig == _PTHREAD_ATTR_SIG) + { + if ((policy == SCHED_OTHER) || + (policy == SCHED_RR) || + (policy == SCHED_FIFO)) + { + attr->policy = policy; + return (ESUCCESS); + } else + { + return (EINVAL); + } + } else + { + return (EINVAL); /* Not an attribute structure! */ + } +} + +/* + * Set the scope for the thread. + * We currently only provide PTHREAD_SCOPE_SYSTEM + */ +int +pthread_attr_setscope(pthread_attr_t *attr, + int scope) +{ + if (attr->sig == _PTHREAD_ATTR_SIG) { + if (scope == PTHREAD_SCOPE_SYSTEM) { + /* No attribute yet for the scope */ + return (ESUCCESS); + } else if (scope == PTHREAD_SCOPE_PROCESS) { + return (ENOTSUP); + } + } + return (EINVAL); /* Not an attribute structure! */ +} + +/* + * Get the scope for the thread. + * We currently only provide PTHREAD_SCOPE_SYSTEM + */ +int +pthread_attr_getscope(pthread_attr_t *attr, + int *scope) +{ + if (attr->sig == _PTHREAD_ATTR_SIG) { + *scope = PTHREAD_SCOPE_SYSTEM; + return (ESUCCESS); + } + return (EINVAL); /* Not an attribute structure! */ +} + +/* Get the base stack address of the given thread */ +int +pthread_attr_getstackaddr(const pthread_attr_t *attr, void **stackaddr) +{ + if (attr->sig == _PTHREAD_ATTR_SIG) { + *stackaddr = attr->stackaddr; + return (ESUCCESS); + } else { + return (EINVAL); /* Not an attribute structure! */ + } +} + +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)) { + attr->stackaddr = stackaddr; + attr->freeStackOnExit = FALSE; + return (ESUCCESS); + } else { + return (EINVAL); /* Not an attribute structure! */ + } +} + +int +pthread_attr_getstacksize(const pthread_attr_t *attr, size_t *stacksize) +{ + if (attr->sig == _PTHREAD_ATTR_SIG) { + *stacksize = attr->stacksize; + return (ESUCCESS); + } else { + return (EINVAL); /* Not an attribute structure! */ + } +} + +int +pthread_attr_setstacksize(pthread_attr_t *attr, size_t stacksize) +{ + if ((attr->sig == _PTHREAD_ATTR_SIG) && ((stacksize % vm_page_size) == 0) && (stacksize >= PTHREAD_STACK_MIN)) { + attr->stacksize = stacksize; + return (ESUCCESS); + } else { + return (EINVAL); /* Not an attribute structure! */ + } +} + +int +pthread_attr_getstack(const pthread_attr_t *attr, void **stackaddr, size_t * stacksize) +{ + if (attr->sig == _PTHREAD_ATTR_SIG) { + *stackaddr = attr->stackaddr; + *stacksize = attr->stacksize; + return (ESUCCESS); + } else { + return (EINVAL); /* Not an attribute structure! */ + } +} + +int +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)) { + attr->stackaddr = stackaddr; + attr->freeStackOnExit = FALSE; + attr->stacksize = stacksize; + return (ESUCCESS); + } else { + return (EINVAL); /* Not an attribute structure! */ + } +} + +/* + * Create and start execution of a new thread. + */ + +static void +_pthread_body(pthread_t self) +{ + _pthread_set_self(self); + pthread_exit((self->fun)(self->arg)); +} + +int +_pthread_create(pthread_t t, + const pthread_attr_t *attrs, + void *stack, + const mach_port_t kernel_thread) +{ + int res; + res = ESUCCESS; + + do + { + memset(t, 0, sizeof(*t)); + t->stacksize = attrs->stacksize; + t->stackaddr = (void *)stack; + t->kernel_thread = kernel_thread; + t->detached = attrs->detached; + t->inherit = attrs->inherit; + t->policy = attrs->policy; + t->param = attrs->param; + t->freeStackOnExit = attrs->freeStackOnExit; + t->mutexes = (struct _pthread_mutex *)NULL; + t->sig = _PTHREAD_SIG; + t->reply_port = MACH_PORT_NULL; + t->cthread_self = NULL; + LOCK_INIT(t->lock); + t->cancel_state = PTHREAD_CANCEL_ENABLE | PTHREAD_CANCEL_DEFERRED; + t->cleanup_stack = (struct _pthread_handler_rec *)NULL; + t->death = SEMAPHORE_NULL; + + if (kernel_thread != MACH_PORT_NULL) + pthread_setschedparam(t, t->policy, &t->param); + } while (0); + return (res); +} + +/* Need to deprecate this in future */ +int +_pthread_is_threaded(void) +{ + return __is_threaded; +} + +/* Non portable public api to know whether this process has(had) atleast one thread + * apart from main thread. There could be race if there is a thread in the process of + * creation at the time of call . It does not tell whether there are more than one thread + * at this point of time. + */ +int +pthread_is_threaded_np(void) +{ + return (__is_threaded); +} + +mach_port_t +pthread_mach_thread_np(pthread_t t) +{ + thread_t kernel_thread; + + /* Wait for the creator to initialize it */ + while ((kernel_thread = t->kernel_thread) == MACH_PORT_NULL) + sched_yield(); + + return kernel_thread; +} + +size_t +pthread_get_stacksize_np(pthread_t t) +{ + return t->stacksize; +} + +void * +pthread_get_stackaddr_np(pthread_t t) +{ + return t->stackaddr; +} + +mach_port_t +_pthread_reply_port(pthread_t t) +{ + return t->reply_port; +} + + +/* returns non-zero if the current thread is the main thread */ +int +pthread_main_np(void) +{ + pthread_t self = pthread_self(); + + return ((self->detached & _PTHREAD_CREATE_PARENT) == _PTHREAD_CREATE_PARENT); +} + +static int +_pthread_create_suspended(pthread_t *thread, + const pthread_attr_t *attr, + void *(*start_routine)(void *), + void *arg, + int suspended) +{ + pthread_attr_t *attrs; + void *stack; + int res; + pthread_t t; + kern_return_t kern_res; + mach_port_t kernel_thread = MACH_PORT_NULL; + int needresume; + + if ((attrs = (pthread_attr_t *)attr) == (pthread_attr_t *)NULL) + { /* Set up default paramters */ + attrs = &_pthread_attr_default; + } else if (attrs->sig != _PTHREAD_ATTR_SIG) { + return EINVAL; + } + res = ESUCCESS; + + /* In default policy (ie SCHED_OTHER) only sched_priority is used. Check for + * any change in priority or policy is needed here. + */ + if (((attrs->policy != _PTHREAD_DEFAULT_POLICY) || + (attrs->param.sched_priority != default_priority)) && (suspended == 0)) { + needresume = 1; + suspended = 1; + } else + needresume = 0; + + do + { + /* Allocate a stack for the thread */ + if ((res = _pthread_allocate_stack(attrs, &stack)) != 0) { + break; + } + t = (pthread_t)malloc(sizeof(struct _pthread)); + *thread = t; + if (suspended) { + /* Create the Mach thread for this thread */ + PTHREAD_MACH_CALL(thread_create(mach_task_self(), &kernel_thread), kern_res); + if (kern_res != KERN_SUCCESS) + { + printf("Can't create thread: %d\n", kern_res); + res = EINVAL; /* Need better error here? */ + break; + } + } + if ((res = _pthread_create(t, attrs, stack, kernel_thread)) != 0) + { + break; + } + set_malloc_singlethreaded(0); + __is_threaded = 1; + LOCK(_pthread_count_lock); + _pthread_count++; + UNLOCK(_pthread_count_lock); + + /* Send it on it's way */ + t->arg = arg; + t->fun = start_routine; + /* Now set it up to execute */ + _pthread_setup(t, _pthread_body, stack, suspended, needresume); + } while (0); + return (res); +} + +int +pthread_create(pthread_t *thread, + const pthread_attr_t *attr, + void *(*start_routine)(void *), + void *arg) +{ + return _pthread_create_suspended(thread, attr, start_routine, arg, 0); +} + +int +pthread_create_suspended_np(pthread_t *thread, + const pthread_attr_t *attr, + void *(*start_routine)(void *), + void *arg) +{ + return _pthread_create_suspended(thread, attr, start_routine, arg, 1); +} + +/* + * Make a thread 'undetached' - no longer 'joinable' with other threads. + */ +int +pthread_detach(pthread_t thread) +{ + if (thread->sig == _PTHREAD_SIG) + { + LOCK(thread->lock); + if (thread->detached & PTHREAD_CREATE_JOINABLE) + { + if (thread->detached & _PTHREAD_EXITED) { + UNLOCK(thread->lock); + pthread_join(thread, NULL); + return ESUCCESS; + } else { + semaphore_t death = thread->death; + + thread->detached &= ~PTHREAD_CREATE_JOINABLE; + thread->detached |= PTHREAD_CREATE_DETACHED; + UNLOCK(thread->lock); + if (death) + (void) semaphore_signal(death); + return (ESUCCESS); + } + } else { + UNLOCK(thread->lock); + return (EINVAL); + } + } else { + return (ESRCH); /* Not a valid thread */ + } +} + + +/* + * pthread_kill call to system call + */ + + +int +pthread_kill ( + pthread_t th, + int sig) +{ + int error = 0; + + if ((sig < 0) || (sig > NSIG)) + return(EINVAL); + + if (th && (th->sig == _PTHREAD_SIG)) { + error = __pthread_kill(pthread_mach_thread_np(th), sig); + if (error == -1) + error = errno; + return(error); + } + else + return(ESRCH); +} + +/* Announce that there are pthread resources ready to be reclaimed in a */ +/* subsequent pthread_exit or reaped by pthread_join. In either case, the Mach */ +/* 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; + kern_return_t ret; + + msg.header.msgh_bits = MACH_MSGH_BITS(MACH_MSG_TYPE_MAKE_SEND, + MACH_MSG_TYPE_MOVE_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; + ret = mach_msg_send(&msg.header); + assert(ret == MACH_MSG_SUCCESS); +} + +/* Reap the resources for available threads */ +static +int _pthread_reap_thread(pthread_t th, mach_port_t kernel_thread, void **value_ptr) { + mach_port_type_t ptype; + kern_return_t ret; + task_t self; + + self = mach_task_self(); + if (kernel_thread != MACH_PORT_DEAD) { + ret = mach_port_type(self, kernel_thread, &ptype); + if (ret == KERN_SUCCESS && ptype != MACH_PORT_TYPE_DEAD_NAME) { + /* not quite dead yet... */ + return EAGAIN; + } + ret = mach_port_deallocate(self, kernel_thread); + if (ret != KERN_SUCCESS) { + fprintf(stderr, + "mach_port_deallocate(kernel_thread) failed: %s\n", + mach_error_string(ret)); + } + } + + if (th->reply_port != MACH_PORT_NULL) { + ret = mach_port_mod_refs(self, th->reply_port, + MACH_PORT_RIGHT_RECEIVE, -1); + if (ret != KERN_SUCCESS) { + fprintf(stderr, + "mach_port_mod_refs(reply_port) failed: %s\n", + mach_error_string(ret)); + } + } + + if (th->freeStackOnExit) { + vm_address_t addr = (vm_address_t)th->stackaddr; + vm_size_t size; + + size = (vm_size_t)th->stacksize + vm_page_size; + +#if !defined(STACK_GROWS_UP) + addr -= size; +#endif + ret = vm_deallocate(self, addr, size); + if (ret != KERN_SUCCESS) { + fprintf(stderr, + "vm_deallocate(stack) failed: %s\n", + mach_error_string(ret)); + } + } + + if (value_ptr) + *value_ptr = th->exit_value; + + if (th != &_thread) + free(th); + + return ESUCCESS; +} + +static +void _pthread_reap_threads(void) +{ + mach_msg_empty_rcv_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, + 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; + + if (_pthread_reap_thread(thread, kernel_thread, (void **)0) == EAGAIN) + { + /* not dead yet, put it back for someone else to reap, stop here */ + _pthread_become_available(thread, kernel_thread); + return; + } + ret = mach_msg(&msg.header, MACH_RCV_MSG|MACH_RCV_TIMEOUT, 0, + sizeof(mach_msg_empty_rcv_t), thread_recycle_port, + MACH_MSG_TIMEOUT_NONE, MACH_PORT_NULL); + } +} + +/* For compatibility... */ + +pthread_t +_pthread_self() { + return pthread_self(); +} + +/* + * Terminate a thread. + */ +void +pthread_exit(void *value_ptr) +{ + struct _pthread_handler_rec *handler; + pthread_t self = pthread_self(); + 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) + { + (handler->routine)(handler->arg); + self->cleanup_stack = handler->next; + } + _pthread_tsd_cleanup(self); + + _pthread_reap_threads(); + + LOCK(self->lock); + self->detached |= _PTHREAD_EXITED; + + if (self->detached & PTHREAD_CREATE_JOINABLE) { + mach_port_t death = self->death; + self->exit_value = value_ptr; + UNLOCK(self->lock); + /* the joiner will need a kernel thread reference, leave ours for it */ + if (death) { + PTHREAD_MACH_CALL(semaphore_signal(death), kern_res); + if (kern_res != KERN_SUCCESS) + fprintf(stderr, + "semaphore_signal(death) failed: %s\n", + mach_error_string(kern_res)); + } + } else { + UNLOCK(self->lock); + /* with no joiner, we let become available consume our cached ref */ + _pthread_become_available(self, pthread_mach_thread_np(self)); + } + + LOCK(_pthread_count_lock); + thread_count = --_pthread_count; + UNLOCK(_pthread_count_lock); + if (thread_count <= 0) + exit(0); + + /* Use a new reference to terminate ourselves. Should never return. */ + PTHREAD_MACH_CALL(thread_terminate(mach_thread_self()), kern_res); + fprintf(stderr, "thread_terminate(mach_thread_self()) failed: %s\n", + mach_error_string(kern_res)); + abort(); +} + +/* + * 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 (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); + } + + /* ... 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; +} + +/* + * Get the scheduling policy and scheduling paramters for a thread. + */ +int +pthread_getschedparam(pthread_t thread, + int *policy, + struct sched_param *param) +{ + if (thread->sig == _PTHREAD_SIG) + { + *policy = thread->policy; + *param = thread->param; + return (ESUCCESS); + } else + { + return (ESRCH); /* Not a valid thread structure */ + } +} + +/* + * Set the scheduling policy and scheduling paramters for a thread. + */ +int +pthread_setschedparam(pthread_t thread, + int policy, + const struct sched_param *param) +{ + policy_base_data_t bases; + policy_base_t base; + mach_msg_type_number_t count; + kern_return_t ret; + + if (thread->sig == _PTHREAD_SIG) + { + switch (policy) + { + case SCHED_OTHER: + bases.ts.base_priority = param->sched_priority; + base = (policy_base_t)&bases.ts; + count = POLICY_TIMESHARE_BASE_COUNT; + break; + case SCHED_FIFO: + bases.fifo.base_priority = param->sched_priority; + base = (policy_base_t)&bases.fifo; + count = POLICY_FIFO_BASE_COUNT; + break; + case SCHED_RR: + bases.rr.base_priority = param->sched_priority; + /* quantum isn't public yet */ + bases.rr.quantum = param->quantum; + base = (policy_base_t)&bases.rr; + count = POLICY_RR_BASE_COUNT; + break; + default: + return (EINVAL); + } + thread->policy = policy; + thread->param = *param; + ret = thread_policy(pthread_mach_thread_np(thread), policy, base, count, TRUE); + if (ret != KERN_SUCCESS) + { + return (EINVAL); + } + return (ESUCCESS); + } else + { + return (ESRCH); /* Not a valid thread structure */ + } +} + +/* + * Get the minimum priority for the given policy + */ +int +sched_get_priority_min(int policy) +{ + return default_priority - 16; +} + +/* + * Get the maximum priority for the given policy + */ +int +sched_get_priority_max(int policy) +{ + return default_priority + 16; +} + +/* + * Determine if two thread identifiers represent the same thread. + */ +int +pthread_equal(pthread_t t1, + pthread_t t2) +{ + return (t1 == t2); +} + +void +cthread_set_self(void *cself) +{ + pthread_t self = pthread_self(); + if ((self == (pthread_t)NULL) || (self->sig != _PTHREAD_SIG)) { + _pthread_set_self(cself); + return; + } + self->cthread_self = cself; +} + +void * +ur_cthread_self(void) { + pthread_t self = pthread_self(); + if ((self == (pthread_t)NULL) || (self->sig != _PTHREAD_SIG)) { + return (void *)self; + } + return self->cthread_self; +} + +/* + * Execute a function exactly one time in a thread-safe fashion. + */ +int +pthread_once(pthread_once_t *once_control, + void (*init_routine)(void)) +{ + LOCK(once_control->lock); + if (once_control->sig == _PTHREAD_ONCE_SIG_init) + { + (*init_routine)(); + once_control->sig = _PTHREAD_ONCE_SIG; + } + UNLOCK(once_control->lock); + 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) +{ + 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); + } + 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) +{ + return(pthread_concurrency); +} + +int +pthread_setconcurrency(int new_level) +{ + pthread_concurrency = new_level; + return(ESUCCESS); +} + +/* + * Perform package initialization - called automatically when application starts + */ + +extern int _cpu_capabilities; + +#define kHasAltivec 0x01 +#define kCache32 0x04 +#define kUseDcba 0x20 +#define kNoDcba 0x40 + +static int +pthread_init(void) +{ + pthread_attr_t *attrs; + pthread_t thread; + kern_return_t kr; + host_basic_info_data_t basic_info; + host_priority_info_data_t priority_info; + host_info_t info; + host_flavor_t flavor; + host_t host; + mach_msg_type_number_t count; + int mib[2]; + size_t len; + int hasvectorunit, numcpus; + + extern int _bcopy_initialize(void); + int dynamic_choice; + + + count = HOST_PRIORITY_INFO_COUNT; + info = (host_info_t)&priority_info; + flavor = HOST_PRIORITY_INFO; + host = mach_host_self(); + kr = host_info(host, flavor, info, &count); + if (kr != KERN_SUCCESS) + printf("host_info failed (%d); probably need privilege.\n", kr); + else { + default_priority = priority_info.user_priority; + min_priority = priority_info.minimum_priority; + max_priority = priority_info.maximum_priority; + } + attrs = &_pthread_attr_default; + pthread_attr_init(attrs); + + thread = &_thread; + _pthread_set_self(thread); + _pthread_create(thread, attrs, (void *)USRSTACK, mach_thread_self()); + thread->detached = PTHREAD_CREATE_JOINABLE|_PTHREAD_CREATE_PARENT; + + /* See if we're on a multiprocessor and set _spin_tries if so. */ + mib[0] = CTL_HW; + mib[1] = HW_NCPU; + len = sizeof(numcpus); + if (sysctl(mib, 2, &numcpus, &len, NULL, 0) == 0) { + if (numcpus > 1) { + _spin_tries = MP_SPIN_TRIES; + } + } else { + count = HOST_BASIC_INFO_COUNT; + info = (host_info_t)&basic_info; + flavor = HOST_BASIC_INFO; + kr = host_info(host, flavor, info, &count); + if (kr != KERN_SUCCESS) + printf("host_info failed (%d)\n", kr); + else { + if (basic_info.avail_cpus > 1) + _spin_tries = MP_SPIN_TRIES; + /* This is a crude test */ + if (basic_info.cpu_subtype >= CPU_SUBTYPE_POWERPC_7400) + _cpu_has_altivec = 1; + } + } + mach_port_deallocate(mach_task_self(), host); + + mib[0] = CTL_HW; + mib[1] = HW_VECTORUNIT; + len = sizeof(hasvectorunit); + if (sysctl(mib, 2, &hasvectorunit, &len, NULL, 0) == 0) { + _cpu_has_altivec = hasvectorunit; + } + if (_cpu_has_altivec) { // G4, let bcopy decide whether to use dcba + _cpu_capabilities = kCache32 + kHasAltivec; + } else { // G3, no altivec and no dcba + _cpu_capabilities = kCache32 + kNoDcba; + } + + dynamic_choice = _bcopy_initialize(); // returns 0, kUseDcba, or kNoDcba + _cpu_capabilities |= dynamic_choice; // remember dynamic choice, if any + mig_init(1); /* enable multi-threaded mig interfaces */ + return 0; +} + +int sched_yield(void) +{ + swtch_pri(0); + return 0; +} + +/* This is the "magic" that gets the initialization routine called when the application starts */ +int (*_cthread_init_routine)(void) = pthread_init; + +/* Get a semaphore from the pool, growing it if necessary */ + +__private_extern__ semaphore_t new_sem_from_pool(void) { + kern_return_t res; + semaphore_t sem; + int i; + + LOCK(sem_pool_lock); + if (sem_pool_current == sem_pool_count) { + sem_pool_count += 16; + sem_pool = realloc(sem_pool, sem_pool_count * sizeof(semaphore_t)); + for (i = sem_pool_current; i < sem_pool_count; i++) { + PTHREAD_MACH_CALL(semaphore_create(mach_task_self(), &sem_pool[i], SYNC_POLICY_FIFO, 0), res); + } + } + sem = sem_pool[sem_pool_current++]; + UNLOCK(sem_pool_lock); + return sem; +} + +/* Put a semaphore back into the pool */ +__private_extern__ void restore_sem_to_pool(semaphore_t sem) { + LOCK(sem_pool_lock); + sem_pool[--sem_pool_current] = sem; + UNLOCK(sem_pool_lock); +} + +static void sem_pool_reset(void) { + LOCK(sem_pool_lock); + sem_pool_count = 0; + sem_pool_current = 0; + sem_pool = NULL; + UNLOCK(sem_pool_lock); +} + +__private_extern__ void _pthread_fork_child(void) { + /* Just in case somebody had it locked... */ + UNLOCK(sem_pool_lock); + sem_pool_reset(); + UNLOCK(_pthread_count_lock); + _pthread_count = 1; +} + diff --git a/pthreads/pthread.h b/pthreads/pthread.h new file mode 100644 index 0000000..d110560 --- /dev/null +++ b/pthreads/pthread.h @@ -0,0 +1,327 @@ +/* + * Copyright 1996 1995 by Open Software Foundation, Inc. 1997 1996 1995 1994 1993 1992 1991 + * 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 appears in all copies and + * that both the copyright notice and this permission notice appear in + * supporting documentation. + * + * OSF DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE. + * + * IN NO EVENT SHALL OSF BE LIABLE FOR ANY SPECIAL, INDIRECT, OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM + * LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT, + * NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION + * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + */ +/* + * MkLinux + */ + +/* + * POSIX Threads - IEEE 1003.1c + */ + +#ifndef _POSIX_PTHREAD_H +#define _POSIX_PTHREAD_H + +#ifndef __POSIX_LIB__ +#include +#endif +#include +#include +#include +#include +#include +#include + +#ifndef _POSIX_C_SOURCE +#include +#endif /* ! _POSIX_C_SOURCE */ + +/* + * These symbols indicate which [optional] features are available + * They can be tested at compile time via '#ifdef XXX' + * The way to check for pthreads is like so: + + * #include + * #ifdef _POSIX_THREADS + * #include + * #endif + + */ + +/* These will be moved to unistd.h */ + + +/* These two should be defined also */ +#undef _POSIX_THREAD_PROCESS_SHARED +#undef _POSIX_THREAD_SAFE_FUNCTIONS + +/* + * Note: These data structures are meant to be opaque. Only enough + * structure is exposed to support initializers. + * All of the typedefs will be moved to + */ + +#include + +__BEGIN_DECLS +/* + * Threads + */ + + +/* + * Cancel cleanup handler management. Note, since these are implemented as macros, + * they *MUST* occur in matched pairs! + */ + +#define pthread_cleanup_push(func, val) \ + { \ + struct _pthread_handler_rec __handler; \ + pthread_t __self = pthread_self(); \ + __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); \ + } + +/* + * Thread attributes + */ + +#define PTHREAD_CREATE_JOINABLE 1 +#define PTHREAD_CREATE_DETACHED 2 + +#define PTHREAD_INHERIT_SCHED 1 +#define PTHREAD_EXPLICIT_SCHED 2 + +#define PTHREAD_CANCEL_ENABLE 0x01 /* Cancel takes place at next cancellation point */ +#define PTHREAD_CANCEL_DISABLE 0x00 /* Cancel postponed */ +#define PTHREAD_CANCEL_DEFERRED 0x02 /* Cancel waits until cancellation point */ +#define PTHREAD_CANCEL_ASYNCHRONOUS 0x00 /* Cancel occurs immediately */ + +/* We only support PTHREAD_SCOPE_SYSTEM */ +#define PTHREAD_SCOPE_SYSTEM 1 +#define PTHREAD_SCOPE_PROCESS 2 + +/* We only support PTHREAD_PROCESS_PRIVATE */ +#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_PRIO_NONE 0 +#define PTHREAD_PRIO_INHERIT 1 +#define PTHREAD_PRIO_PROTECT 2 + +/* + * Mutex type attributes + */ +#define PTHREAD_MUTEX_NORMAL 0 +#define PTHREAD_MUTEX_ERRORCHECK 1 +#define PTHREAD_MUTEX_RECURSIVE 2 +#define PTHREAD_MUTEX_DEFAULT PTHREAD_MUTEX_NORMAL +/* + * Mutex variables + */ + +#define PTHREAD_MUTEX_INITIALIZER {_PTHREAD_MUTEX_SIG_init, {}} + +/* + * Condition variable attributes + */ + +/* + * Condition variables + */ + +#define PTHREAD_COND_INITIALIZER {_PTHREAD_COND_SIG_init, {}} + +/* + * Initialization control (once) variables + */ + +#define PTHREAD_ONCE_INIT {_PTHREAD_ONCE_SIG_init, {}} + +/* + * Thread Specific Data - keys + */ + +#include + +/* + * Prototypes for all PTHREAD interfaces + */ +int pthread_attr_destroy __P((pthread_attr_t *attr)); +int pthread_attr_getdetachstate __P((const pthread_attr_t *attr, + int *detachstate)); +int pthread_attr_getinheritsched __P((const pthread_attr_t *attr, + int *inheritsched)); +int pthread_attr_getschedparam __P((const pthread_attr_t *attr, + struct sched_param *param)); +int pthread_attr_getschedpolicy __P((const pthread_attr_t *attr, + int *policy)); +int pthread_attr_getstackaddr __P((const pthread_attr_t *attr, + void **stackaddr)); +int pthread_attr_getstacksize __P((const pthread_attr_t *attr, + size_t *stacksize)); +int pthread_attr_getstack __P((const pthread_attr_t *attr, + void **stackaddr, size_t *stacksize)); +int pthread_attr_init __P((pthread_attr_t *attr)); +int pthread_attr_setdetachstate __P((pthread_attr_t *attr, + int detachstate)); +int pthread_attr_setinheritsched __P((pthread_attr_t *attr, + int inheritsched)); +int pthread_attr_setschedparam __P((pthread_attr_t *attr, + const struct sched_param *param)); +int pthread_attr_setschedpolicy __P((pthread_attr_t *attr, + int policy)); +int pthread_attr_setstackaddr __P((pthread_attr_t *attr, + void *stackaddr)); +int pthread_attr_setstacksize __P((pthread_attr_t *attr, + size_t stacksize)); +int pthread_attr_setstack __P((pthread_attr_t *attr, + void *stackaddr, size_t stacksize)); +int pthread_cancel __P((pthread_t thread)); +int pthread_setcancelstate __P((int state, int *oldstate)); +int pthread_setcanceltype __P((int type, int *oldtype)); +void pthread_testcancel __P((void)); +int pthread_cond_broadcast __P((pthread_cond_t *cond)); +int pthread_cond_destroy __P((pthread_cond_t *cond)); +int pthread_cond_init __P((pthread_cond_t *cond, + const pthread_condattr_t *attr)); +int pthread_cond_signal __P((pthread_cond_t *cond)); +int pthread_cond_wait __P((pthread_cond_t *cond, + pthread_mutex_t *mutex)); +int pthread_cond_timedwait __P((pthread_cond_t *cond, + pthread_mutex_t *mutex, + const struct timespec *abstime)); +int pthread_condattr_init __P((pthread_condattr_t *attr)); +int pthread_condattr_destroy __P((pthread_condattr_t *attr)); +int pthread_condattr_getpshared __P((const pthread_condattr_t *attr, + int *pshared)); +int pthread_condattr_setpshared __P((pthread_condattr_t *attr, + int pshared)); +int pthread_create __P((pthread_t *thread, + const pthread_attr_t *attr, + void *(*start_routine)(void *), + void *arg)); +int pthread_detach __P((pthread_t thread)); +int pthread_equal __P((pthread_t t1, + pthread_t t2)); +void pthread_exit __P((void *value_ptr)); +int pthread_kill __P((pthread_t, int)); +int pthread_sigmask __P((int, const sigset_t *, sigset_t *)); +int sigwait __P((const sigset_t *, int *)); +int pthread_getschedparam __P((pthread_t thread, + int *policy, + struct sched_param *param)); +int pthread_join __P((pthread_t thread, + void **value_ptr)); +int pthread_mutex_destroy __P((pthread_mutex_t *mutex)); +int pthread_mutex_getprioceiling __P((const pthread_mutex_t *mutex, + int *prioceiling)); +int pthread_mutex_init __P((pthread_mutex_t *mutex, + const pthread_mutexattr_t *attr)); +int pthread_mutex_lock __P((pthread_mutex_t *mutex)); +int pthread_mutex_setprioceiling __P((pthread_mutex_t *mutex, + int prioceiling, + int *old_prioceiling)); +int pthread_mutex_trylock __P((pthread_mutex_t *mutex)); +int pthread_mutex_unlock __P((pthread_mutex_t *mutex)); +int pthread_mutexattr_destroy __P((pthread_mutexattr_t *attr)); +int pthread_mutexattr_getprioceiling __P((const pthread_mutexattr_t *attr, + int *prioceiling)); +int pthread_mutexattr_getprotocol __P((const pthread_mutexattr_t *attr, + int *protocol)); +int pthread_mutexattr_getpshared __P((const pthread_mutexattr_t *attr, + int *pshared)); +int pthread_mutexattr_gettype __P((const pthread_mutexattr_t *attr, + int *type)); +int pthread_mutexattr_init __P((pthread_mutexattr_t *attr)); +int pthread_mutexattr_setprioceiling __P((pthread_mutexattr_t *attr, + int prioceiling)); +int pthread_mutexattr_setprotocol __P((pthread_mutexattr_t *attr, + int protocol)); +int pthread_mutexattr_settype __P((pthread_mutexattr_t *attr, + int type)); +int pthread_mutexattr_setpshared __P((pthread_mutexattr_t *attr, + int pshared)); +int pthread_once __P((pthread_once_t *once_control, + void (*init_routine)(void))); +pthread_t pthread_self __P((void)); +int pthread_setschedparam __P((pthread_t thread, + int policy, + const struct sched_param *param)); +int pthread_key_create __P((pthread_key_t *key, + void (*destructor)(void *))); +int pthread_key_delete __P((pthread_key_t key)); +int pthread_setspecific __P((pthread_key_t key, + const void *value)); +void *pthread_getspecific __P((pthread_key_t key)); +int pthread_attr_getscope __P((pthread_attr_t *, int *)); +int pthread_attr_setscope __P((pthread_attr_t *, int)); +int pthread_getconcurrency __P((void)); +int pthread_setconcurrency __P((int)); +int pthread_rwlock_destroy __P((pthread_rwlock_t * rwlock)); +int pthread_rwlock_init __P((pthread_rwlock_t * rwlock, + const pthread_rwlockattr_t *attr)); +int pthread_rwlock_rdlock __P((pthread_rwlock_t *rwlock)); +int pthread_rwlock_tryrdlock __P((pthread_rwlock_t *rwlock)); +int pthread_rwlock_wrlock __P((pthread_rwlock_t *rwlock)); +int pthread_rwlock_trywrlock __P((pthread_rwlock_t *rwlock)); +int pthread_rwlock_unlock __P((pthread_rwlock_t *rwlock)); +int pthread_rwlockattr_init __P((pthread_rwlockattr_t *attr)); +int pthread_rwlockattr_destroy __P((pthread_rwlockattr_t *attr)); +int pthread_rwlockattr_getpshared __P((const pthread_rwlockattr_t *attr, + int *pshared)); +int pthread_rwlockattr_setpshared __P((pthread_rwlockattr_t *attr, + int pshared)); + +#ifndef _POSIX_C_SOURCE +/* returns non-zero if pthread_create or cthread_fork have been called */ +int pthread_is_threaded_np __P((void)); + +/* returns non-zero if the current thread is the main thread */ +int pthread_main_np __P((void)); + +/* return the mach thread bound to the pthread */ +mach_port_t pthread_mach_thread_np __P((pthread_t)); +size_t pthread_get_stacksize_np __P((pthread_t)); +void * pthread_get_stackaddr_np __P((pthread_t)); + +/* Like pthread_cond_signal(), but only wake up the specified pthread */ +int pthread_cond_signal_thread_np __P((pthread_cond_t *, pthread_t)); + +/* Like pthread_cond_timedwait, but use a relative timeout */ +int pthread_cond_timedwait_relative_np __P((pthread_cond_t *cond, + pthread_mutex_t *mutex, + const struct timespec *reltime)); + +/* Like pthread_create(), but leaves the thread suspended */ +int pthread_create_suspended_np __P((pthread_t *thread, + const pthread_attr_t *attr, + void *(*start_routine)(void *), + void *arg)); +void pthread_yield_np __P((void)); +#endif /* ! _POSIX_C_SOURCE */ +__END_DECLS +#endif /* _POSIX_PTHREAD_H */ diff --git a/pthreads/pthread_attr.3 b/pthreads/pthread_attr.3 new file mode 100644 index 0000000..4926715 --- /dev/null +++ b/pthreads/pthread_attr.3 @@ -0,0 +1,211 @@ +.\" Copyright (C) 2000 Jason Evans . +.\" 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(s), this list of conditions and the following disclaimer as +.\" the first lines of this file unmodified other than the possible +.\" addition of one or more copyright notices. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice(s), 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 COPYRIGHT HOLDER(S) ``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 COPYRIGHT HOLDER(S) 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_r/man/pthread_attr.3,v 1.4.2.5 2001/08/17 15:42:51 ru Exp $ +.Dd April 28, 2000 +.Dt PTHREAD_ATTR 3 +.Os +.Sh NAME +.Nm pthread_attr_init , +.Nm pthread_attr_destroy , +.Nm pthread_attr_setstacksize , +.Nm pthread_attr_getstacksize , +.Nm pthread_attr_setstackaddr , +.Nm pthread_attr_getstackaddr , +.Nm pthread_attr_setdetachstate , +.Nm pthread_attr_getdetachstate , +.Nm pthread_attr_setinheritsched , +.Nm pthread_attr_getinheritsched , +.Nm pthread_attr_setschedparam , +.Nm pthread_attr_getschedparam , +.Nm pthread_attr_setschedpolicy , +.Nm pthread_attr_getschedpolicy , +.Nm pthread_attr_setscope , +.Nm pthread_attr_getscope +.Nd thread attribute operations +.Sh SYNOPSIS +.Fd #include +.Ft int +.Fn pthread_attr_init "pthread_attr_t *attr" +.Ft int +.Fn pthread_attr_destroy "pthread_attr_t *attr" +.Ft int +.Fn pthread_attr_setstacksize "pthread_attr_t *attr" "size_t stacksize" +.Ft int +.Fn pthread_attr_getstacksize "const pthread_attr_t *attr" "size_t *stacksize" +.Ft int +.Fn pthread_attr_setstackaddr "pthread_attr_t *attr" "void *stackaddr" +.Ft int +.Fn pthread_attr_getstackaddr "const pthread_attr_t *attr" "void **stackaddr" +.Ft int +.Fn pthread_attr_setdetachstate "pthread_attr_t *attr" "int detachstate" +.Ft int +.Fn pthread_attr_getdetachstate "const pthread_attr_t *attr" "int *detachstate" +.Ft int +.Fn pthread_attr_setinheritsched "pthread_attr_t *attr" "int inheritsched" +.Ft int +.Fn pthread_attr_getinheritsched "const pthread_attr_t *attr" "int *inheritsched" +.Ft int +.Fn pthread_attr_setschedparam "pthread_attr_t *attr" "const struct sched_param *param" +.Ft int +.Fn pthread_attr_getschedparam "const pthread_attr_t *attr" "struct sched_param *param" +.Ft int +.Fn pthread_attr_setschedpolicy "pthread_attr_t *attr" "int policy" +.Ft int +.Fn pthread_attr_getschedpolicy "const pthread_attr_t *attr" "int *policy" +.Ft int +.Fn pthread_attr_setscope "pthread_attr_t *attr" "int contentionscope" +.Ft int +.Fn pthread_attr_getscope "const pthread_attr_t *attr" "int *contentionscope" +.Sh DESCRIPTION +Thread attributes are used to specify parameters to +.Fn pthread_create . +One attribute object can be used in multiple calls to +.Fn pthread_create , +with or without modifications between calls. +.Pp +The +.Fn pthread_attr_init +function initializes +.Fa attr +with all the default thread attributes. +.Pp +The +.Fn pthread_attr_destroy +function destroys +.Fa attr . +.Pp +The +.Fn pthread_attr_set* +functions set the attribute that corresponds to each function name. +.Pp +The +.Fn pthread_attr_get* +functions copy the value of the attribute that corresponds to each function name +to the location pointed to by the second function parameter. +.Sh RETURN VALUES +If successful, these functions return 0. +Otherwise, an error number is returned to indicate the error. +.Sh ERRORS +.Fn pthread_attr_init +will fail if: +.Bl -tag -width Er +.It Bq Er ENOMEM +Out of memory. +.El +.Pp +.Fn pthread_attr_destroy +will fail if: +.Bl -tag -width Er +.It Bq Er EINVAL +Invalid value for +.Fa attr . +.El +.Pp +.Fn pthread_attr_setstacksize +will fail if: +.Bl -tag -width Er +.It Bq Er EINVAL +.Fa stacksize +is less than +.Dv PTHREAD_STACK_MIN . +.El +.Pp +.Fn pthread_attr_setdetachstate +will fail if: +.Bl -tag -width Er +.It Bq Er EINVAL +Invalid value for +.Fa detachstate . +.El +.Pp +.Fn pthread_attr_setinheritsched +will fail if: +.Bl -tag -width Er +.It Bq Er EINVAL +Invalid value for +.Fa attr . +.El +.Pp +.Fn pthread_attr_setschedparam +will fail if: +.Bl -tag -width Er +.It Bq Er EINVAL +Invalid value for +.Fa attr . +.It Bq Er ENOTSUP +Invalid value for +.Fa param . +.El +.Pp +.Fn pthread_attr_setschedpolicy +will fail if: +.Bl -tag -width Er +.It Bq Er EINVAL +Invalid value for +.Fa attr . +.It Bq Er ENOTSUP +Invalid or unsupported value for +.Fa policy . +.El +.Pp +.Fn pthread_attr_setscope +will fail if: +.Bl -tag -width Er +.It Bq Er EINVAL +Invalid value for +.Fa attr . +.It Bq Er ENOTSUP +Invalid or unsupported value for +.Fa contentionscope . +.El +.Sh SEE ALSO +.Xr pthread_create 3 +.Sh STANDARDS +.Fn pthread_attr_init , +.Fn pthread_attr_destroy , +.Fn pthread_attr_setstacksize , +.Fn pthread_attr_getstacksize , +.Fn pthread_attr_setstackaddr , +.Fn pthread_attr_getstackaddr , +.Fn pthread_attr_setdetachstate , +and +.Fn pthread_attr_getdetachstate +conform to +.St -p1003.1-96 +.Pp +.Fn pthread_attr_setinheritsched , +.Fn pthread_attr_getinheritsched , +.Fn pthread_attr_setschedparam , +.Fn pthread_attr_getschedparam , +.Fn pthread_attr_setschedpolicy , +.Fn pthread_attr_getschedpolicy , +.Fn pthread_attr_setscope , +and +.Fn pthread_attr_getscope +conform to +.St -susv2 diff --git a/pthreads/pthread_cancel.3 b/pthreads/pthread_cancel.3 new file mode 100644 index 0000000..fae332e --- /dev/null +++ b/pthreads/pthread_cancel.3 @@ -0,0 +1,77 @@ +.\" $FreeBSD: src/lib/libc_r/man/pthread_cancel.3,v 1.3.2.3 2001/03/06 16:46:08 ru Exp $ +.Dd January 17, 1999 +.Dt PTHREAD_CANCEL 3 +.Os +.Sh NAME +.Nm pthread_cancel +.Nd cancel execution of a thread +.Sh SYNOPSIS +.Fd #include +.Ft int +.Fn pthread_cancel "pthread_t thread" +.Sh DESCRIPTION +The +.Fn pthread_cancel +function requests that +.Fa thread +be canceled. +The target thread's cancelability state and type determines +when the cancellation takes effect. +When the cancellation is acted on, +the cancellation cleanup handlers for +.Fa thread +are called. +When the last cancellation cleanup handler returns, +the thread-specific data destructor functions will be called for +.Fa thread . +When the last destructor function returns, +.Fa thread +will be terminated. +.Pp +The cancellation processing in the target thread runs asynchronously with +respect to the calling thread returning from +.Fn pthread_cancel . +.Pp +A status of +.Dv PTHREAD_CANCELED +is made available to any threads joining with the target. +The symbolic +constant +.Dv PTHREAD_CANCELED +expands to a constant expression of type +.Ft "(void *)" , +whose value matches no pointer to an object in memory nor the value +.Dv NULL . +.Sh RETURN VALUES +If successful, the +.Fn pthread_cancel +functions will return zero. +Otherwise an error number will be returned to +indicate the error. +.Sh ERRORS +.Fn pthread_cancel +will fail if: +.Bl -tag -width Er +.It Bq Er ESRCH +No thread could be found corresponding to that specified by the given +thread ID. +.El +.Sh SEE ALSO +.Xr pthread_cleanup_pop 3 , +.Xr pthread_cleanup_push 3 , +.Xr pthread_exit 3 , +.Xr pthread_join 3 , +.Xr pthread_setcancelstate 3 , +.Xr pthread_setcanceltype 3 , +.Xr pthread_testcancel 3 +.Sh STANDARDS +.Fn pthread_cancel +conforms to +.St -p1003.1-96 . +.Sh AUTHORS +This man page was written by +.An David Leonard Aq d@openbsd.org +for the +.Ox +implementation of +.Fn pthread_cancel . diff --git a/pthreads/pthread_cleanup_pop.3 b/pthreads/pthread_cleanup_pop.3 new file mode 100644 index 0000000..a965922 --- /dev/null +++ b/pthreads/pthread_cleanup_pop.3 @@ -0,0 +1,62 @@ +.\" Copyright (c) 1997 Brian Cully +.\" 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. Neither the name of the author nor the names of any co-contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL 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. +.\" +.\" $FreeBSD: src/lib/libc_r/man/pthread_cleanup_pop.3,v 1.5.2.3 2001/08/17 15:42:51 ru Exp $ +.\" +.Dd July 30, 1998 +.Dt PTHREAD_CLEANUP_POP 3 +.Os +.Sh NAME +.Nm pthread_cleanup_pop +.Nd call the first cleanup routine +.Sh SYNOPSIS +.Fd #include +.Ft void +.Fn pthread_cleanup_pop "int execute" +.Sh DESCRIPTION +The +.Fn pthread_cleanup_pop +function pops the top cleanup routine off of the current threads cleanup +routine stack, and, if +.Fa execute +is non-zero, it will execute the function. +If there is no cleanup routine +then +.Fn pthread_cleanup_pop +does nothing. +.Sh RETURN VALUES +.Fn pthread_cleanup_pop +does not return any value. +.Sh ERRORS +None +.Sh SEE ALSO +.Xr pthread_cleanup_push 3 , +.Xr pthread_exit 3 +.Sh STANDARDS +.Fn pthread_cleanup_pop +conforms to +.St -p1003.1-96 . diff --git a/pthreads/pthread_cleanup_push.3 b/pthreads/pthread_cleanup_push.3 new file mode 100644 index 0000000..5a8aa9d --- /dev/null +++ b/pthreads/pthread_cleanup_push.3 @@ -0,0 +1,64 @@ +.\" Copyright (c) 1997 Brian Cully +.\" 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. Neither the name of the author nor the names of any co-contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL 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. +.\" +.\" $FreeBSD: src/lib/libc_r/man/pthread_cleanup_push.3,v 1.5.2.4 2001/08/17 15:42:51 ru Exp $ +.\" +.Dd July 30, 1998 +.Dt PTHREAD_CLEANUP_PUSH 3 +.Os +.Sh NAME +.Nm pthread_cleanup_push +.Nd add a cleanup function for thread exit +.Sh SYNOPSIS +.Fd #include +.Ft void +.Fn pthread_cleanup_push "void \*[lp]*cleanup_routine\*[rp]\*[lp]void *\*[rp]" "void *arg" +.Sh DESCRIPTION +The +.Fn pthread_cleanup_push +function adds +.Fa cleanup_routine +to the top of the stack of cleanup handlers that +get called when the current thread exits. +.Pp +When +.Fa cleanup_routine +is called, it is passed +.Fa arg +as its only argument. +.Sh RETURN VALUES +.Fn pthread_cleanup_push +does not return any value. +.Sh ERRORS +None +.Sh SEE ALSO +.Xr pthread_cleanup_pop 3 , +.Xr pthread_exit 3 +.Sh STANDARDS +.Fn pthread_cleanup_push +conforms to +.St -p1003.1-96 . diff --git a/pthreads/pthread_cond.c b/pthreads/pthread_cond.c new file mode 100644 index 0000000..409f231 --- /dev/null +++ b/pthreads/pthread_cond.c @@ -0,0 +1,383 @@ +/* + * Copyright 1996 1995 by Open Software Foundation, Inc. 1997 1996 1995 1994 1993 1992 1991 + * 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 appears in all copies and + * that both the copyright notice and this permission notice appear in + * supporting documentation. + * + * OSF DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE. + * + * IN NO EVENT SHALL OSF BE LIABLE FOR ANY SPECIAL, INDIRECT, OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM + * LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT, + * NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION + * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ +/* + * MkLinux + */ + +/* + * POSIX Pthread Library + */ + +#include "pthread_internals.h" +#include /* For struct timespec and getclock(). */ +#include + + /* + * Destroy a condition variable. + */ +int +pthread_cond_destroy(pthread_cond_t *cond) +{ + if (cond->sig == _PTHREAD_COND_SIG) + { + LOCK(cond->lock); + if (cond->busy != (pthread_mutex_t *)NULL) + { + UNLOCK(cond->lock); + return (EBUSY); + } else + { + cond->sig = _PTHREAD_NO_SIG; + UNLOCK(cond->lock); + return (ESUCCESS); + } + } else + return (EINVAL); /* Not an initialized condition variable structure */ +} + +/* + * Initialize a condition variable. Note: 'attr' is ignored. + */ +int +pthread_cond_init(pthread_cond_t *cond, + const pthread_condattr_t *attr) +{ + LOCK_INIT(cond->lock); + cond->sig = _PTHREAD_COND_SIG; + cond->next = (pthread_cond_t *)NULL; + cond->prev = (pthread_cond_t *)NULL; + cond->busy = (pthread_mutex_t *)NULL; + cond->waiters = 0; + cond->sigspending = 0; + cond->sem = MACH_PORT_NULL; + return (ESUCCESS); +} + +/* + * Signal a condition variable, waking up all threads waiting for it. + */ +int +pthread_cond_broadcast(pthread_cond_t *cond) +{ + kern_return_t kern_res; + int res; + if (cond->sig == _PTHREAD_COND_SIG_init) { + if ((res = pthread_cond_init(cond, NULL)) != 0) { + return (res); + } + } + if (cond->sig != _PTHREAD_COND_SIG) { + /* Not a condition variable */ + return (EINVAL); + } + LOCK(cond->lock); + if (cond->sem == MACH_PORT_NULL) { + /* Avoid kernel call since there are no waiters... */ + UNLOCK(cond->lock); + return (ESUCCESS); + } + cond->sigspending++; + UNLOCK(cond->lock); + PTHREAD_MACH_CALL(semaphore_signal_all(cond->sem), kern_res); + LOCK(cond->lock); + cond->sigspending--; + if (cond->waiters == 0 && cond->sigspending == 0) { + restore_sem_to_pool(cond->sem); + cond->sem = MACH_PORT_NULL; + } + UNLOCK(cond->lock); + if (kern_res != KERN_SUCCESS) { + return (EINVAL); + } + return (ESUCCESS); +} + +/* + * Signal a condition variable, waking a specified thread. + */ +int +pthread_cond_signal_thread_np(pthread_cond_t *cond, pthread_t thread) +{ + kern_return_t kern_res; + if (cond->sig == _PTHREAD_COND_SIG_init) { + int res; + if ((res = pthread_cond_init(cond, NULL)) != 0) { + return (res); + } + } + if (cond->sig != _PTHREAD_COND_SIG) { + return (EINVAL); /* Not a condition variable */ + } + LOCK(cond->lock); + if (cond->sem == MACH_PORT_NULL) { + /* Avoid kernel call since there are not enough waiters... */ + UNLOCK(cond->lock); + return (ESUCCESS); + } + cond->sigspending++; + UNLOCK(cond->lock); + if (thread == (pthread_t)NULL) { + kern_res = semaphore_signal_thread(cond->sem, MACH_PORT_NULL); + if (kern_res == KERN_INVALID_ARGUMENT) { + PTHREAD_MACH_CALL(semaphore_signal(cond->sem), kern_res); + } else if (kern_res == KERN_NOT_WAITING) { + kern_res = KERN_SUCCESS; + } + } else if (thread->sig == _PTHREAD_SIG) { + PTHREAD_MACH_CALL(semaphore_signal_thread( + cond->sem, pthread_mach_thread_np(thread)), kern_res); + } else { + kern_res = KERN_FAILURE; + } + LOCK(cond->lock); + cond->sigspending--; + if (cond->waiters == 0 && cond->sigspending == 0) { + restore_sem_to_pool(cond->sem); + cond->sem = MACH_PORT_NULL; + } + UNLOCK(cond->lock); + if (kern_res != KERN_SUCCESS) { + return (EINVAL); + } + return (ESUCCESS); +} + +/* + * Signal a condition variable, waking only one thread. + */ +int +pthread_cond_signal(pthread_cond_t *cond) +{ + return pthread_cond_signal_thread_np(cond, NULL); +} + +/* + * Manage a list of condition variables associated with a mutex + */ + +static void +_pthread_cond_add(pthread_cond_t *cond, pthread_mutex_t *mutex) +{ + pthread_cond_t *c; + LOCK(mutex->lock); + if ((c = mutex->busy) != (pthread_cond_t *)NULL) + { + c->prev = cond; + } + cond->next = c; + cond->prev = (pthread_cond_t *)NULL; + mutex->busy = cond; + UNLOCK(mutex->lock); + if (cond->sem == MACH_PORT_NULL) { + cond->sem = new_sem_from_pool(); + } +} + +static void +_pthread_cond_remove(pthread_cond_t *cond, pthread_mutex_t *mutex) +{ + pthread_cond_t *n, *p; + LOCK(mutex->lock); + if ((n = cond->next) != (pthread_cond_t *)NULL) + { + n->prev = cond->prev; + } + if ((p = cond->prev) != (pthread_cond_t *)NULL) + { + p->next = cond->next; + } else + { /* This is the first in the list */ + mutex->busy = n; + } + UNLOCK(mutex->lock); + if (cond->sigspending == 0) { + restore_sem_to_pool(cond->sem); + cond->sem = MACH_PORT_NULL; + } +} + +/* + * 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 +_pthread_cond_wait(pthread_cond_t *cond, + pthread_mutex_t *mutex, + const struct timespec *abstime, + int isRelative) +{ + int res; + kern_return_t kern_res; + pthread_mutex_t *busy; + mach_timespec_t then; + if (cond->sig == _PTHREAD_COND_SIG_init) { + if ((res = pthread_cond_init(cond, NULL)) != 0) { + return (res); + } + } + if (cond->sig != _PTHREAD_COND_SIG) { + /* Not a condition variable */ + return (EINVAL); + } + + if (abstime) { + 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))) { + return ETIMEDOUT; + } + } else { + then.tv_sec = abstime->tv_sec; + then.tv_nsec = abstime->tv_nsec; + } + if (then.tv_nsec >= NSEC_PER_SEC) { + return EINVAL; + } + } + LOCK(cond->lock); + busy = cond->busy; + if ((busy != (pthread_mutex_t *)NULL) && (busy != mutex)) { + /* Must always specify the same mutex! */ + UNLOCK(cond->lock); + return (EINVAL); + } + cond->waiters++; + if (cond->waiters == 1) { + _pthread_cond_add(cond, mutex); + cond->busy = mutex; + } + UNLOCK(cond->lock); + LOCK(mutex->lock); + if (mutex->sem == MACH_PORT_NULL) { + mutex->sem = new_sem_from_pool(); + } + mutex->cond_lock = 1; + UNLOCK(mutex->lock); + 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); + } + LOCK(cond->lock); + cond->waiters--; + if (cond->waiters == 0) { + _pthread_cond_remove(cond, mutex); + cond->busy = (pthread_mutex_t *)NULL; + } + UNLOCK(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); + } else { + return (EINVAL); + } +} + +int +pthread_cond_wait(pthread_cond_t *cond, + pthread_mutex_t *mutex) +{ + return (_pthread_cond_wait(cond, mutex, (struct timespec *)NULL, 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)); +} + +int +pthread_condattr_init(pthread_condattr_t *attr) +{ + attr->sig = _PTHREAD_COND_ATTR_SIG; + return (ESUCCESS); +} + +int +pthread_condattr_destroy(pthread_condattr_t *attr) +{ + attr->sig = _PTHREAD_NO_SIG; /* Uninitialized */ + return (ESUCCESS); +} + +int +pthread_condattr_getpshared(const pthread_condattr_t *attr, + int *pshared) +{ + if (attr->sig == _PTHREAD_COND_ATTR_SIG) + { + *pshared = (int)PTHREAD_PROCESS_PRIVATE; + return (ESUCCESS); + } else + { + return (EINVAL); /* Not an initialized 'attribute' structure */ + } +} + + +int +pthread_condattr_setpshared(pthread_condattr_t * attr, int pshared) +{ + if (attr->sig == _PTHREAD_COND_ATTR_SIG) + { + if ( pshared == PTHREAD_PROCESS_PRIVATE) + { + /* attr->pshared = pshared */ + return (ESUCCESS); + } else + { + return (EINVAL); /* Invalid parameter */ + } + } else + { + return (EINVAL); /* Not an initialized 'attribute' structure */ + } + +} + diff --git a/pthreads/pthread_cond_broadcast.3 b/pthreads/pthread_cond_broadcast.3 new file mode 100644 index 0000000..27600a6 --- /dev/null +++ b/pthreads/pthread_cond_broadcast.3 @@ -0,0 +1,68 @@ +.\" Copyright (c) 1997 Brian Cully +.\" 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. Neither the name of the author nor the names of any co-contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL 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. +.\" +.\" $FreeBSD: src/lib/libc_r/man/pthread_cond_broadcast.3,v 1.5.2.4 2001/08/17 15:42:51 ru Exp $ +.\" +.Dd July 28, 1998 +.Dt PTHREAD_COND_BROADCAST 3 +.Os +.Sh NAME +.Nm pthread_cond_broadcast +.Nd unblock all threads waiting for a condition variable +.Sh SYNOPSIS +.Fd #include +.Ft int +.Fn pthread_cond_broadcast "pthread_cond_t *cond" +.Sh DESCRIPTION +The +.Fn pthread_cond_broadcast +function unblocks all threads waiting for the condition variable +.Fa cond . +.Sh RETURN VALUES +If successful, the +.Fn pthread_cond_broadcast +function will return zero, otherwise an error number will be returned +to indicate the error. +.Sh ERRORS +.Fn pthread_cond_broadcast +will fail if: +.Bl -tag -width Er +.It Bq Er EINVAL +The value specified by +.Fa cond +is invalid. +.El +.Sh SEE ALSO +.Xr pthread_cond_destroy 3 , +.Xr pthread_cond_init 3 , +.Xr pthread_cond_signal 3 , +.Xr pthread_cond_timedwait 3 , +.Xr pthread_cond_wait 3 +.Sh STANDARDS +.Fn pthread_cond_broadcast +conforms to +.St -p1003.1-96 . diff --git a/pthreads/pthread_cond_destroy.3 b/pthreads/pthread_cond_destroy.3 new file mode 100644 index 0000000..6b0ecc2 --- /dev/null +++ b/pthreads/pthread_cond_destroy.3 @@ -0,0 +1,72 @@ +.\" Copyright (c) 1997 Brian Cully +.\" 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. Neither the name of the author nor the names of any co-contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL 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. +.\" +.\" $FreeBSD: src/lib/libc_r/man/pthread_cond_destroy.3,v 1.6.2.4 2001/08/17 15:42:51 ru Exp $ +.\" +.Dd July 28, 1998 +.Dt PTHREAD_COND_DESTROY 3 +.Os +.Sh NAME +.Nm pthread_cond_destroy +.Nd destroy a condition variable +.Sh SYNOPSIS +.Fd #include +.Ft int +.Fn pthread_cond_destroy "pthread_cond_t *cond" +.Sh DESCRIPTION +The +.Fn pthread_cond_destroy +function frees the resources allocated by the condition variable +.Fa cond . +.Sh RETURN VALUES +If successful, the +.Fn pthread_cond_destroy +function will return zero, otherwise an error number will be returned +to indicate the error. +.Sh ERRORS +.Fn pthread_cond_destroy +will fail if: +.Bl -tag -width Er +.It Bq Er EINVAL +The value specified by +.Fa cond +is invalid. +.It Bq Er EBUSY +The variable +.Fa cond +is locked by another thread. +.El +.Sh SEE ALSO +.Xr pthread_cond_broadcast 3 , +.Xr pthread_cond_init 3 , +.Xr pthread_cond_signal 3 , +.Xr pthread_cond_timedwait 3 , +.Xr pthread_cond_wait 3 +.Sh STANDARDS +.Fn pthread_cond_destroy +conforms to +.St -p1003.1-96 . diff --git a/pthreads/pthread_cond_init.3 b/pthreads/pthread_cond_init.3 new file mode 100644 index 0000000..ec30f86 --- /dev/null +++ b/pthreads/pthread_cond_init.3 @@ -0,0 +1,78 @@ +.\" Copyright (c) 1997 Brian Cully +.\" 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. Neither the name of the author nor the names of any co-contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL 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. +.\" +.\" $FreeBSD: src/lib/libc_r/man/pthread_cond_init.3,v 1.6.2.5 2001/08/17 15:42:51 ru Exp $ +.\" +.Dd July 28, 1998 +.Dt PTHREAD_COND_INIT 3 +.Os +.Sh NAME +.Nm pthread_cond_init +.Nd create a condition variable +.Sh SYNOPSIS +.Fd #include +.Ft int +.Fn pthread_cond_init "pthread_cond_t *cond" "const pthread_condattr_t *attr" +.Sh DESCRIPTION +The +.Fn pthread_cond_init +function creates a new condition variable, with attributes specified with +.Fa attr . +If +.Fa attr +is NULL the default attributes are used. +.Sh RETURN VALUES +If successful, the +.Fn pthread_cond_init +function will return zero and put the new condition variable id into +.Fa cond , +otherwise an error number will be returned to indicate the error. +.Sh ERRORS +.Fn pthread_cond_init +will fail if: +.Bl -tag -width Er +.It Bq Er EINVAL +The value specified by +.Fa attr +is invalid. +.It Bq Er ENOMEM +The process cannot allocate enough memory to create another condition +variable. +.It Bq Er EAGAIN +The system temporarily lacks the resources to create another condition +variable. +.El +.Sh SEE ALSO +.Xr pthread_cond_broadcast 3 , +.Xr pthread_cond_destroy 3 , +.Xr pthread_cond_signal 3 , +.Xr pthread_cond_timedwait 3 , +.Xr pthread_cond_wait 3 +.Sh STANDARDS +.Fn pthread_cond_init +conforms to +.St -p1003.1-96 . diff --git a/pthreads/pthread_cond_signal.3 b/pthreads/pthread_cond_signal.3 new file mode 100644 index 0000000..06078a9 --- /dev/null +++ b/pthreads/pthread_cond_signal.3 @@ -0,0 +1,68 @@ +.\" Copyright (c) 1997 Brian Cully +.\" 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. Neither the name of the author nor the names of any co-contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL 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. +.\" +.\" $FreeBSD: src/lib/libc_r/man/pthread_cond_signal.3,v 1.5.2.4 2001/08/17 15:42:51 ru Exp $ +.\" +.Dd July 28, 1998 +.Dt PTHREAD_COND_SIGNAL 3 +.Os +.Sh NAME +.Nm pthread_cond_signal +.Nd unblock a thread waiting for a condition variable +.Sh SYNOPSIS +.Fd #include +.Ft int +.Fn pthread_cond_signal "pthread_cond_t *cond" +.Sh DESCRIPTION +The +.Fn pthread_cond_signal +function unblocks one thread waiting for the condition variable +.Fa cond . +.Sh RETURN VALUES +If successful, the +.Fn pthread_cond_signal +function will return zero, otherwise an error number will be returned +to indicate the error. +.Sh ERRORS +.Fn pthread_cond_signal +will fail if: +.Bl -tag -width Er +.It Bq Er EINVAL +The value specified by +.Fa cond +is invalid. +.El +.Sh SEE ALSO +.Xr pthread_cond_broadcast 3 , +.Xr pthread_cond_destroy 3 , +.Xr pthread_cond_init 3 , +.Xr pthread_cond_timedwait 3 , +.Xr pthread_cond_wait 3 +.Sh STANDARDS +.Fn pthread_cond_signal +conforms to +.St -p1003.1-96 . diff --git a/pthreads/pthread_cond_timedwait.3 b/pthreads/pthread_cond_timedwait.3 new file mode 100644 index 0000000..3ff427d --- /dev/null +++ b/pthreads/pthread_cond_timedwait.3 @@ -0,0 +1,87 @@ +.\" Copyright (c) 1997 Brian Cully +.\" 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. Neither the name of the author nor the names of any co-contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL 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. +.\" +.\" $FreeBSD: src/lib/libc_r/man/pthread_cond_timedwait.3,v 1.8.2.6 2001/08/17 15:42:51 ru Exp $ +.\" +.Dd July 28, 1998 +.Dt PTHREAD_COND_TIMEDWAIT 3 +.Os +.Sh NAME +.Nm pthread_cond_timedwait +.Nd "wait on a condition variable for a specific amount of time" +.Sh SYNOPSIS +.Fd #include +.Ft int +.Fn pthread_cond_timedwait "pthread_cond_t *cond" "pthread_mutex_t *mutex" "const struct timespec *abstime" +.Sh DESCRIPTION +The +.Fn pthread_cond_timedwait +function atomically blocks the current thread waiting on the condition +variable specified by +.Fa cond , +and unblocks the mutex specified by +.Fa mutex . +The waiting thread unblocks only after another thread calls +.Xr pthread_cond_signal 3 , +or +.Xr pthread_cond_broadcast 3 +with the same condition variable, or if the system time reaches the +time specified in +.Fa abstime , +and the current thread reacquires the lock on +.Fa mutex . +.Sh RETURN VALUES +If successful, the +.Fn pthread_cond_timedwait +function will return zero. +Otherwise an error number will be returned to +indicate the error. +.Sh ERRORS +.Fn pthread_cond_timedwait +will fail if: +.Bl -tag -width Er +.It Bq Er EINVAL +The value specified by +.Fa cond , +.Fa mutex +or +.Fa abstime +is invalid. +.It Bq Er ETIMEDOUT +The system time has reached or exceeded the time specified in +.Fa abstime . +.El +.Sh SEE ALSO +.Xr pthread_cond_broadcast 3 , +.Xr pthread_cond_destroy 3 , +.Xr pthread_cond_init 3 , +.Xr pthread_cond_signal 3 , +.Xr pthread_cond_wait 3 +.Sh STANDARDS +.Fn pthread_cond_timedwait +conforms to +.St -p1003.1-96 . diff --git a/pthreads/pthread_cond_wait.3 b/pthreads/pthread_cond_wait.3 new file mode 100644 index 0000000..d64c49e --- /dev/null +++ b/pthreads/pthread_cond_wait.3 @@ -0,0 +1,75 @@ +.\" Portions Copyright (c) 2001 Apple Computer, Inc. All Rights Reserved. +.\" Copyright (c) 1997 Brian Cully +.\" 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. Neither the name of the author nor the names of any co-contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL 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. +.\" +.\" $FreeBSD: src/lib/libc_r/man/pthread_cond_wait.3,v 1.8.2.4 2001/08/17 15:42:51 ru Exp $ +.\" +.Dd November 5, 2001 +.Dt PTHREAD_COND_WAIT 3 +.Os Darwin +.Sh NAME +.Nm pthread_cond_wait +.Nd wait on a condition variable +.Sh SYNOPSIS +.Fd #include +.Ft int +.Fn pthread_cond_wait "pthread_cond_t *cond" "pthread_mutex_t *mutex" +.Sh DESCRIPTION +The +.Fn pthread_cond_wait +function atomically unlocks the +.Fa mutex +argument and waits on the +.Fa cond +argument. +.Sh RETURN VALUES +If successful, the +.Fn pthread_cond_wait +function will return zero. +Otherwise an error number will be returned to +indicate the error. +.Sh ERRORS +.Fn pthread_cond_wait +will fail if: +.Bl -tag -width Er +.It Bq Er EINVAL +The value specified by +.Fa cond +or the value specified by +.Fa mutex +is invalid. +.El +.Sh SEE ALSO +.Xr pthread_cond_broadcast 3 , +.Xr pthread_cond_destroy 3 , +.Xr pthread_cond_init 3 , +.Xr pthread_cond_signal 3 , +.Xr pthread_cond_timedwait 3 +.Sh STANDARDS +.Fn pthread_cond_wait +conforms to +.St -p1003.1-96 . diff --git a/pthreads/pthread_condattr.3 b/pthreads/pthread_condattr.3 new file mode 100644 index 0000000..e63da0d --- /dev/null +++ b/pthreads/pthread_condattr.3 @@ -0,0 +1,83 @@ +.\" Copyright (C) 2000 Jason Evans . +.\" 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(s), this list of conditions and the following disclaimer as +.\" the first lines of this file unmodified other than the possible +.\" addition of one or more copyright notices. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice(s), 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 COPYRIGHT HOLDER(S) ``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 COPYRIGHT HOLDER(S) 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_r/man/pthread_condattr.3,v 1.9 2001/10/01 16:09:09 ru Exp $ +.Dd April 28, 2000 +.Dt PTHREAD_CONDATTR 3 +.Os +.Sh NAME +.Nm pthread_condattr_init , +.Nm pthread_condattr_destroy +.Nd condition attribute operations +.Sh SYNOPSIS +.In pthread.h +.Ft int +.Fn pthread_condattr_init "pthread_condattr_t *attr" +.Ft int +.Fn pthread_condattr_destroy "pthread_condattr_t *attr" +.Sh DESCRIPTION +Condition attribute objects are used to specify parameters to +.Fn pthread_cond_init . +.Fx Ns 's +implementation of conditions does not support any non-default +attributes, so these functions are not very useful, though they are required to +to be present by +.Tn POSIX . +.Pp +The +.Fn pthread_condattr_init +function initializes a condition attribute object with the default attributes. +.Pp +The +.Fn pthread_condattr_destroy +function destroys a condition attribute object. +.Sh RETURN VALUES +If successful, these functions return 0. +Otherwise, an error number is returned to indicate the error. +.Sh ERRORS +.Fn pthread_condattr_init +will fail if: +.Bl -tag -width Er +.It Bq Er ENOMEM +Out of memory. +.El +.Pp +.Fn pthread_condattr_destroy +will fail if: +.Bl -tag -width Er +.It Bq Er EINVAL +Invalid value for +.Fa attr . +.El +.Sh SEE ALSO +.Xr pthread_cond_init 3 +.Sh STANDARDS +.Fn pthread_condattr_init +and +.Fn pthread_condattr_destroy +conform to +.St -p1003.1-96 diff --git a/pthreads/pthread_create.3 b/pthreads/pthread_create.3 new file mode 100644 index 0000000..c495109 --- /dev/null +++ b/pthreads/pthread_create.3 @@ -0,0 +1,119 @@ +.\" Copyright (c) 1996 John Birrell . +.\" 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 John Birrell. +.\" 4. Neither the name of the author nor the names of any co-contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL 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. +.\" +.\" $FreeBSD: src/lib/libc_r/man/pthread_create.3,v 1.9.2.4 2001/08/17 15:42:51 ru Exp $ +.\" +.Dd April 4, 1996 +.Dt PTHREAD_CREATE 3 +.Os +.Sh NAME +.Nm pthread_create +.Nd create a new thread +.Sh SYNOPSIS +.Fd #include +.Ft int +.Fn pthread_create "pthread_t *thread" "const pthread_attr_t *attr" "void *(*start_routine)(void *)" "void *arg" +.Sh DESCRIPTION +The +.Fn pthread_create +function is used to create a new thread, with attributes specified by +.Fa attr , +within a process. +If +.Fa attr +is NULL, the default attributes are used. +If the attributes specified by +.Fa attr +are modified later, the thread's attributes are not affected. +Upon +successful completion +.Fn pthread_create +will store the ID of the created thread in the location specified by +.Fa thread . +.Pp +The thread is created executing +.Fa start_routine +with +.Fa arg +as its sole argument. +If the +.Fa start_routine +returns, the effect is as if there was an implicit call to +.Fn pthread_exit +using the return value of +.Fa start_routine +as the exit status. +Note that the thread in which +.Fn main +was originally invoked differs from this. +When it returns from +.Fn main , +the effect is as if there was an implicit call to +.Fn exit +using the return value of +.Fn main +as the exit status. +.Pp +The signal state of the new thread is initialized as: +.Bl -bullet -offset indent +.It +The signal mask is inherited from the creating thread. +.It +The set of signals pending for the new thread is empty. +.El +.Sh RETURN VALUES +If successful, the +.Fn pthread_create +function will return zero. +Otherwise an error number will be returned to +indicate the error. +.Sh ERRORS +.Fn pthread_create +will fail if: +.Bl -tag -width Er +.It Bq Er EAGAIN +The system lacked the necessary resources to create another thread, or +the system-imposed limit on the total number of threads in a process +[PTHREAD_THREADS_MAX] would be exceeded. +.It Bq Er EINVAL +The value specified by +.Fa attr +is invalid. +.El +.Sh SEE ALSO +.Xr fork 2 , +.Xr pthread_cleanup_pop 3 , +.Xr pthread_cleanup_push 3 , +.Xr pthread_exit 3 , +.Xr pthread_join 3 +.Sh STANDARDS +.Fn pthread_create +conforms to +.St -p1003.1-96 . diff --git a/pthreads/pthread_detach.3 b/pthreads/pthread_detach.3 new file mode 100644 index 0000000..3608bc3 --- /dev/null +++ b/pthreads/pthread_detach.3 @@ -0,0 +1,87 @@ +.\" Copyright (c) 1996-1998 John Birrell . +.\" 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 John Birrell. +.\" 4. Neither the name of the author nor the names of any co-contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL 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. +.\" +.\" $FreeBSD: src/lib/libc_r/man/pthread_detach.3,v 1.6.2.5 2001/08/17 15:42:51 ru Exp $ +.\" +.Dd April 4, 1996 +.Dt PTHREAD_DETACH 3 +.Os +.Sh NAME +.Nm pthread_detach +.Nd detach a thread +.Sh SYNOPSIS +.Fd #include +.Ft int +.Fn pthread_detach "pthread_t thread" +.Sh DESCRIPTION +The +.Fn pthread_detach +function is used to indicate to the implementation that storage for the +thread +.Fa thread +can be reclaimed when the thread terminates. +If +.Fa thread +has not terminated, +.Fn pthread_detach +will not cause it to terminate. +The effect of multiple +.Fn pthread_detach +calls on the same target thread is unspecified. +.Sh RETURN VALUES +If successful, the +.Fn pthread_detach +function will return zero. +Otherwise an error number will be returned to +indicate the error. +Note that the function does not change the value +of errno as it did for some drafts of the standard. +These early drafts +also passed a pointer to pthread_t as the argument. +Beware! +.Sh ERRORS +.Fn pthread_detach +will fail if: +.Bl -tag -width Er +.It Bq Er EINVAL +The implementation has detected that the value specified by +.Fa thread +does not refer to a joinable thread. +.It Bq Er ESRCH +No thread could be found corresponding to that specified by the given +thread ID, +.Fa thread . +.El +.Sh SEE ALSO +.Xr pthread_join 3 +.Sh STANDARDS +.Fn pthread_detach +conforms to +.St -p1003.1-96 . diff --git a/pthreads/pthread_equal.3 b/pthreads/pthread_equal.3 new file mode 100644 index 0000000..37b2c01 --- /dev/null +++ b/pthreads/pthread_equal.3 @@ -0,0 +1,66 @@ +.\" Copyright (c) 1996 John Birrell . +.\" 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 John Birrell. +.\" 4. Neither the name of the author nor the names of any co-contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL 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. +.\" +.\" $FreeBSD: src/lib/libc_r/man/pthread_equal.3,v 1.4.2.5 2001/08/17 15:42:51 ru Exp $ +.\" +.Dd April 4, 1996 +.Dt PTHREAD_EQUAL 3 +.Os +.Sh NAME +.Nm pthread_equal +.Nd compare thread IDs +.Sh SYNOPSIS +.Fd #include +.Ft int +.Fn pthread_equal "pthread_t t1" "pthread_t t2" +.Sh DESCRIPTION +The +.Fn pthread_equal +function compares the thread IDs +.Fa t1 +and +.Fa t2 . +.Sh RETURN VALUES +The +.Fn pthread_equal +function will return non-zero if the thread IDs +.Fa t1 +and +.Fa t2 +correspond to the same thread, otherwise it will return zero. +.Sh ERRORS +None. +.Sh SEE ALSO +.Xr pthread_create 3 , +.Xr pthread_exit 3 +.Sh STANDARDS +.Fn pthread_equal +conforms to +.St -p1003.1-96 . diff --git a/pthreads/pthread_exit.3 b/pthreads/pthread_exit.3 new file mode 100644 index 0000000..3bb690a --- /dev/null +++ b/pthreads/pthread_exit.3 @@ -0,0 +1,102 @@ +.\" Copyright (c) 1996 John Birrell . +.\" 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 John Birrell. +.\" 4. Neither the name of the author nor the names of any co-contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL 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. +.\" +.\" $FreeBSD: src/lib/libc_r/man/pthread_exit.3,v 1.8.2.6 2001/08/17 15:42:51 ru Exp $ +.\" +.Dd April 4, 1996 +.Dt PTHREAD_EXIT 3 +.Os +.Sh NAME +.Nm pthread_exit +.Nd terminate the calling thread +.Sh SYNOPSIS +.Fd #include +.Ft void +.Fn pthread_exit "void *value_ptr" +.Sh DESCRIPTION +The +.Fn pthread_exit +function terminates the calling thread and makes the value +.Fa value_ptr +available to any successful join with the terminating thread. +Any +cancellation cleanup handlers that have been pushed and are not yet popped +are popped in the reverse order that they were pushed and then executed. +After all cancellation handlers have been executed, if the thread has any +thread-specific data, appropriate destructor functions are called in an +unspecified order. +Thread termination does not release any application +visible process resources, including, but not limited to, mutexes and +file descriptors, nor does it perform any process level cleanup +actions, including, but not limited to, calling +.Fn atexit +routines that may exist. +.Pp +An implicit call to +.Fn pthread_exit +is made when a thread other than the thread in which +.Fn main +was first invoked returns from the start routine that was used to create +it. The function's return value serves as the thread's exit status. +.Pp +The behavior of +.Fn pthread_exit +is undefined if called from a cancellation handler or destructor function +that was invoked as the result of an implicit or explicit call to +.Fn pthread_exit . +.Pp +After a thread has terminated, the result of access to local (auto) +variables of the thread is undefined. +Thus, references to local variables +of the exiting thread should not be used for the +.Fn pthread_exit +.Fa value_ptr +parameter value. +.Pp +The process will exit with an exit status of 0 after the last thread has +been terminated. +The behavior is as if the implementation called +.Fn exit +with a zero argument at thread termination time. +.Sh RETURN VALUES +The +.Fn pthread_exit +function cannot return to its caller. +.Sh ERRORS +None. +.Sh SEE ALSO +.Xr _exit 2 , +.Xr exit 3 , +.Xr pthread_create 3 , +.Xr pthread_join 3 +.Sh STANDARDS +.Fn pthread_exit +conforms to +.St -p1003.1-96 . diff --git a/pthreads/pthread_getschedparam.3 b/pthreads/pthread_getschedparam.3 new file mode 100644 index 0000000..e00454b --- /dev/null +++ b/pthreads/pthread_getschedparam.3 @@ -0,0 +1,88 @@ +.\" Copyright (C) 2000 Jason Evans . +.\" 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(s), this list of conditions and the following disclaimer as +.\" the first lines of this file unmodified other than the possible +.\" addition of one or more copyright notices. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice(s), 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 COPYRIGHT HOLDER(S) ``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 COPYRIGHT HOLDER(S) 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_r/man/pthread_schedparam.3,v 1.2.2.4 2001/08/17 15:42:52 ru Exp $ +.Dd May 1, 2000 +.Dt PTHREAD_SCHEDPARAM 3 +.Os +.Sh NAME +.Nm pthread_setschedparam , +.Nm pthread_getschedparam +.Nd thread scheduling parameter manipulation +.Sh SYNOPSIS +.Fd #include +.Ft int +.Fn pthread_setschedparam "pthread_t thread" "int policy" "const struct sched_param *param" +.Ft int +.Fn pthread_getschedparam "pthread_t thread" "int *policy" "struct sched_param *param" +.Sh DESCRIPTION +The +.Fn pthread_setschedparam +and +.Fn pthread_getschedparam +functions set and get the scheduling parameters of individual threads. +The scheduling policy for a thread can either be +.Dv SCHED_FIFO +(first in, first out) or +.Dv SCHED_RR +(round-robin). +The thread priority (accessed via +.Va param->sched_priority ) +must be at least +.Dv PTHREAD_MIN_PRIORITY +and no more than +.Dv PTHREAD_MAX_PRIORITY . +.Sh RETURN VALUES +If successful, these functions return 0. +Otherwise, an error number is returned to indicate the error. +.Sh ERRORS +.Fn pthread_setschedparam +will fail if: +.Bl -tag -width Er +.It Bq Er EINVAL +Invalid value for +.Va policy . +.It Bq Er ENOTSUP +Invalid value for scheduling parameters. +.It Bq Er ESRCH +Non-existent thread +.Va thread . +.El +.Pp +.Fn pthread_getschedparam +will fail if: +.Bl -tag -width Er +.It Bq Er ESRCH +Non-existent thread +.Va thread . +.El +.Sh STANDARDS +.Fn pthread_setschedparam +and +.Fn pthread_getschedparam +conform to +.St -susv2 diff --git a/pthreads/pthread_getspecific.3 b/pthreads/pthread_getspecific.3 new file mode 100644 index 0000000..d53ba46 --- /dev/null +++ b/pthreads/pthread_getspecific.3 @@ -0,0 +1,81 @@ +.\" Copyright (c) 1996 John Birrell . +.\" 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 John Birrell. +.\" 4. Neither the name of the author nor the names of any co-contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL 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. +.\" +.\" $FreeBSD: src/lib/libc_r/man/pthread_getspecific.3,v 1.6.2.3 2001/08/17 15:42:51 ru Exp $ +.\" +.Dd April 4, 1996 +.Dt PTHREAD_GETSPECIFIC 3 +.Os +.Sh NAME +.Nm pthread_getspecific +.Nd get a thread-specific data value +.Sh SYNOPSIS +.Fd #include +.Ft void * +.Fn pthread_getspecific "pthread_key_t key" +.Sh DESCRIPTION +The +.Fn pthread_getspecific +function returns the value currently bound to the specified +.Fa key +on behalf of the calling thread. +.Pp +The effect of calling +.Fn pthread_getspecific +with a +.Fa key +value not obtained from +.Fn pthread_key_create +or after +.Fa key +has been deleted with +.Fn pthread_key_delete +is undefined. +.Pp +.Fn pthread_getspecific +may be called from a thread-specific data destructor function. +.Sh RETURN VALUES +The +.Fn pthread_getspecific +function will return the thread-specific data value associated with the given +.Fa key . +If no thread-specific data value is associated with +.Fa key , +then the value NULL is returned. +.Sh ERRORS +None. +.Sh SEE ALSO +.Xr pthread_key_create 3 , +.Xr pthread_key_delete 3 , +.Xr pthread_setspecific 3 +.Sh STANDARDS +.Fn pthread_getspecific +conforms to +.St -p1003.1-96 . diff --git a/pthreads/pthread_impl.h b/pthreads/pthread_impl.h new file mode 100644 index 0000000..ef83dee --- /dev/null +++ b/pthreads/pthread_impl.h @@ -0,0 +1,28 @@ +#ifndef _PTHREAD_IMPL_H_ +#define _PTHREAD_IMPL_H_ +/* + * Internal implementation details + */ + +/* This whole header file will disappear, so don't depend on it... */ + +#ifndef __POSIX_LIB__ + +/* + * [Internal] data structure signatures + */ +#define _PTHREAD_MUTEX_SIG_init 0x32AAABA7 +#define _PTHREAD_COND_SIG_init 0x3CB0B1BB +#define _PTHREAD_ONCE_SIG_init 0x30B1BCBA +/* + * POSIX scheduling policies + */ +#define SCHED_OTHER 1 +#define SCHED_FIFO 4 +#define SCHED_RR 2 + +#define __SCHED_PARAM_SIZE__ 4 + +#endif /* __POSIX_LIB__ */ + +#endif /* _PTHREAD_IMPL_H_ */ diff --git a/pthreads/pthread_internals.h b/pthreads/pthread_internals.h new file mode 100644 index 0000000..6a26786 --- /dev/null +++ b/pthreads/pthread_internals.h @@ -0,0 +1,277 @@ +/* + * Copyright 1996 1995 by Open Software Foundation, Inc. 1997 1996 1995 1994 1993 1992 1991 + * 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 appears in all copies and + * that both the copyright notice and this permission notice appear in + * supporting documentation. + * + * OSF DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE. + * + * IN NO EVENT SHALL OSF BE LIABLE FOR ANY SPECIAL, INDIRECT, OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM + * LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT, + * NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION + * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + */ +/* + * MkLinux + */ + +/* + * POSIX Threads - IEEE 1003.1c + */ + +#ifndef _POSIX_PTHREAD_INTERNALS_H +#define _POSIX_PTHREAD_INTERNALS_H + + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include /* For generic MACH support */ + + +#ifndef __POSIX_LIB__ +#define __POSIX_LIB__ +#endif + +#include "posix_sched.h" /* For POSIX scheduling policy & parameter */ +#include "pthread_machdep.h" /* Machine-dependent definitions. */ + +extern kern_return_t syscall_thread_switch(mach_port_name_t, int, mach_msg_timeout_t); + +/* + * Compiled-in limits + */ +#undef _POSIX_THREAD_KEYS_MAX +#define _POSIX_THREAD_KEYS_MAX 128 + +/* + * Threads + */ +typedef struct _pthread +{ + long sig; /* Unique signature for this structure */ + struct _pthread_handler_rec *cleanup_stack; + pthread_lock_t lock; /* Used for internal mutex on structure */ + int detached; + int inherit; + int policy; + struct sched_param param; + struct _pthread_mutex *mutexes; + struct _pthread *joiner; + int pad1; + 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 *(*fun)(void*);/* Thread start routine */ + void *arg; /* Argment for thread start routine */ + int cancel_state; /* Whether thread can be cancelled */ + int err_no; /* thread-local errno */ + void *tsd[_POSIX_THREAD_KEYS_MAX]; /* Thread specific data */ + 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() */ + boolean_t freeStackOnExit;/* Should we free the stack when we're done? */ +} *pthread_t; + + +/* + * Thread attributes + */ +typedef struct +{ + long sig; /* Unique signature for this structure */ + pthread_lock_t lock; /* Used for internal mutex on structure */ + int detached; + int inherit; + int policy; + struct sched_param param; + 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; + +/* + * Mutex attributes + */ +typedef struct +{ + long sig; /* Unique signature for this structure */ + int prioceiling; + u_int32_t protocol:2, /* protocol attribute */ + type:2, /* mutex type */ + rfu:28; +} pthread_mutexattr_t; + +/* + * Mutex variables + */ +typedef struct _pthread_mutex +{ + long sig; /* Unique signature for this structure */ + pthread_lock_t lock; /* Used for internal mutex on structure */ + int waiters:30, /* Count of threads waiting for this mutex */ + def:1, + cond_lock:1; /* Is there a condition locking me? */ + pthread_t owner; /* Which thread has this mutex locked */ + mach_port_t sem; /* Semaphore used for waiting */ + u_int32_t protocol:2, /* protocol */ + type:2, /* mutex type */ + rfu:12, + lock_count:16; + struct _pthread_mutex *next, *prev; /* List of other mutexes he owns */ + struct _pthread_cond *busy; /* List of condition variables using this mutex */ + int prioceiling; + int priority; /* Priority to restore when mutex unlocked */ +} pthread_mutex_t; + +/* + * Condition variable attributes + */ +typedef struct +{ + long sig; /* Unique signature for this structure */ + int unsupported; +} pthread_condattr_t; + +/* + * Condition variables + */ +typedef struct _pthread_cond +{ + long sig; /* Unique signature for this structure */ + pthread_lock_t lock; /* Used for internal mutex on structure */ + mach_port_t sem; /* Kernel semaphore */ + struct _pthread_cond *next, *prev; /* List of condition variables using mutex */ + struct _pthread_mutex *busy; /* mutex associated with variable */ + int waiters:16, /* Number of threads waiting */ + sigspending:16; /* Number of outstanding signals */ +} pthread_cond_t; + +/* + * Initialization control (once) variables + */ +typedef struct +{ + long sig; /* Unique signature for this structure */ + pthread_lock_t lock; /* Used for internal mutex on structure */ +} pthread_once_t; + +typedef struct { + long sig; /* Unique signature for this structure */ + int pshared; + int rfu[2]; /* reserved for future use */ +} pthread_rwlockattr_t; + +typedef struct { + long sig; + pthread_mutex_t lock; /* monitor lock */ + int state; + pthread_cond_t read_signal; + pthread_cond_t write_signal; + int blocked_writers; + int pshared; + int rfu[3]; +} pthread_rwlock_t; + +#include "pthread.h" + +#define _PTHREAD_DEFAULT_INHERITSCHED PTHREAD_INHERIT_SCHED +#define _PTHREAD_DEFAULT_PROTOCOL PTHREAD_PRIO_NONE +#define _PTHREAD_DEFAULT_PRIOCEILING 0 +#define _PTHREAD_DEFAULT_POLICY SCHED_OTHER +#define _PTHREAD_DEFAULT_STACKSIZE 0x80000 /* 512K */ + +#define _PTHREAD_NO_SIG 0x00000000 +#define _PTHREAD_MUTEX_ATTR_SIG 0x4D545841 /* 'MTXA' */ +#define _PTHREAD_MUTEX_SIG 0x4D555458 /* 'MUTX' */ +#define _PTHREAD_MUTEX_SIG_init 0x32AAABA7 /* [almost] ~'MUTX' */ +#define _PTHREAD_COND_ATTR_SIG 0x434E4441 /* 'CNDA' */ +#define _PTHREAD_COND_SIG 0x434F4E44 /* 'COND' */ +#define _PTHREAD_COND_SIG_init 0x3CB0B1BB /* [almost] ~'COND' */ +#define _PTHREAD_ATTR_SIG 0x54484441 /* 'THDA' */ +#define _PTHREAD_ONCE_SIG 0x4F4E4345 /* 'ONCE' */ +#define _PTHREAD_ONCE_SIG_init 0x30B1BCBA /* [almost] ~'ONCE' */ +#define _PTHREAD_SIG 0x54485244 /* 'THRD' */ +#define _PTHREAD_RWLOCK_ATTR_SIG 0x52574C41 /* 'RWLA' */ +#define _PTHREAD_RWLOCK_SIG 0x52574C4B /* 'RWLK' */ +#define _PTHREAD_RWLOCK_SIG_init 0x2DA8B3B4 /* [almost] ~'RWLK' */ + +#define _PTHREAD_CREATE_PARENT 4 +#define _PTHREAD_EXITED 8 + +#define _PTHREAD_CANCEL_STATE_MASK 0xFE +#define _PTHREAD_CANCEL_TYPE_MASK 0xFD +#define _PTHREAD_CANCEL_PENDING 0x10 /* pthread_cancel() has been called for this thread */ + +extern boolean_t swtch_pri(int); + +/* Number of times to spin when the lock is unavailable and we are on a + multiprocessor. On a uniprocessor we yield the processor immediately. */ +#define MP_SPIN_TRIES 1000 +extern int _spin_tries; +extern int __is_threaded; +extern int _cpu_has_altivec; + +/* Internal mutex locks for data structures */ +#define TRY_LOCK(v) (!__is_threaded || _spin_lock_try((pthread_lock_t *)&(v))) +#define LOCK(v) \ +do { \ + if (__is_threaded) { \ + int tries = _spin_tries; \ + \ + while (!_spin_lock_try((pthread_lock_t *)&(v))) { \ + if (tries-- > 0) \ + continue; \ + \ + syscall_thread_switch(THREAD_NULL, SWITCH_OPTION_DEPRESS, 1); \ + tries = _spin_tries; \ + } \ + } \ +} while (0) +#define UNLOCK(v) \ +do { \ + if (__is_threaded) \ + _spin_unlock((pthread_lock_t *)&(v)); \ +} while (0) + +#ifndef ESUCCESS +#define ESUCCESS 0 +#endif + +#ifndef PTHREAD_MACH_CALL +#define PTHREAD_MACH_CALL(expr, ret) (ret) = (expr) +#endif + +/* Prototypes. */ + +/* Functions defined in machine-dependent files. */ +extern vm_address_t _sp(void); +extern vm_address_t _adjust_sp(vm_address_t sp); +extern void _spin_lock(pthread_lock_t *lockp); +extern int _spin_lock_try(pthread_lock_t *lockp); +extern void _spin_unlock(pthread_lock_t *lockp); +extern void _pthread_setup(pthread_t th, void (*f)(pthread_t), void *sp, int suspended, int needresume); + +extern void _pthread_tsd_cleanup(pthread_t self); + +__private_extern__ semaphore_t new_sem_from_pool(void); +__private_extern__ void restore_sem_to_pool(semaphore_t); +#endif /* _POSIX_PTHREAD_INTERNALS_H */ diff --git a/pthreads/pthread_join.3 b/pthreads/pthread_join.3 new file mode 100644 index 0000000..9fcbfab --- /dev/null +++ b/pthreads/pthread_join.3 @@ -0,0 +1,102 @@ +.\" Copyright (c) 1996-1998 John Birrell . +.\" 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 John Birrell. +.\" 4. Neither the name of the author nor the names of any co-contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL 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. +.\" +.\" $FreeBSD: src/lib/libc_r/man/pthread_join.3,v 1.7.2.4 2001/08/17 15:42:51 ru Exp $ +.\" +.Dd April 4, 1996 +.Dt PTHREAD_JOIN 3 +.Os +.Sh NAME +.Nm pthread_join +.Nd wait for thread termination +.Sh SYNOPSIS +.Fd #include +.Ft int +.Fn pthread_join "pthread_t thread" "void **value_ptr" +.Sh DESCRIPTION +The +.Fn pthread_join +function suspends execution of the calling thread until the target +.Fa thread +terminates unless the target +.Fa thread +has already terminated. +.Pp +On return from a successful +.Fn pthread_join +call with a non-NULL +.Fa value_ptr +argument, the value passed to +.Fn pthread_exit +by the terminating thread is stored in the location referenced by +.Fa value_ptr . +When a +.Fn pthread_join +returns successfully, the target thread has been terminated. +The results +of multiple simultaneous calls to +.Fn pthread_join +specifying the same target thread are undefined. +If the thread calling +.Fn pthread_join +is cancelled, then the target thread is not detached. +.Pp +A thread that has exited but remains unjoined counts against +[_POSIX_THREAD_THREADS_MAX]. +.Sh RETURN VALUES +If successful, the +.Fn pthread_join +function will return zero. +Otherwise an error number will be returned to +indicate the error. +.Sh ERRORS +.Fn pthread_join +will fail if: +.Bl -tag -width Er +.It Bq Er EINVAL +The implementation has detected that the value specified by +.Fa thread +does not refer to a joinable thread. +.It Bq Er ESRCH +No thread could be found corresponding to that specified by the given +thread ID, +.Fa thread . +.It Bq Er EDEADLK +A deadlock was detected or the value of +.Fa thread +specifies the calling thread. +.El +.Sh SEE ALSO +.Xr wait 2 , +.Xr pthread_create 3 +.Sh STANDARDS +.Fn pthread_join +conforms to +.St -p1003.1-96 . diff --git a/pthreads/pthread_key_create.3 b/pthreads/pthread_key_create.3 new file mode 100644 index 0000000..82a8a1c --- /dev/null +++ b/pthreads/pthread_key_create.3 @@ -0,0 +1,105 @@ +.\" Copyright (c) 1996 John Birrell . +.\" 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 John Birrell. +.\" 4. Neither the name of the author nor the names of any co-contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL 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. +.\" +.\" $FreeBSD: src/lib/libc_r/man/pthread_key_create.3,v 1.6.2.4 2001/08/17 15:42:51 ru Exp $ +.\" +.Dd April 4, 1996 +.Dt PTHREAD_KEY_CREATE 3 +.Os +.Sh NAME +.Nm pthread_key_create +.Nd thread-specific data key creation +.Sh SYNOPSIS +.Fd #include +.Ft int +.Fn pthread_key_create "pthread_key_t *key" "void (*destructor)(void *)" +.Sh DESCRIPTION +The +.Fn pthread_key_create +function creates a thread-specific data key visible to all threads in the +process. +Key values provided by +.Fn pthread_key_create +are opaque objects used to locate thread-specific data. +Although the same +key value may be used by different threads, the values bound to the key +by +.Fn pthread_setspecific +are maintained on a per-thread basis and persist for the life of the calling +thread. +.Pp +Upon key creation, the value NULL is associated with the new key in all +active threads. +Upon thread creation, the value NULL is associated with all +defined keys in the new thread. +.Pp +An optional destructor function may be associated with each key value. +At +thread exit, if a key value has a non-NULL destructor pointer, and the +thread has a non-NULL value associated with the key, the function pointed +to is called with the current associated value as its sole argument. +The +order of destructor calls is unspecified if more than one destructor exists +for a thread when it exits. +.Pp +If, after all the destructors have been called for all non-NULL values +with associated destructors, there are still some non-NULL values with +associated destructors, then the process is repeated. +If, after at least +[PTHREAD_DESTRUCTOR_ITERATIONS] iterations of destructor calls for +outstanding non-NULL values, there are still some non-NULL values with +associated destructors, the implementation stops calling destructors. +.Sh RETURN VALUES +If successful, the +.Fn pthread_key_create +function will store the newly created key value at the location specified by +.Fa key +and returns zero. +Otherwise an error number will be returned to indicate +the error. +.Sh ERRORS +.Fn pthread_key_create +will fail if: +.Bl -tag -width Er +.It Bq Er EAGAIN +The system lacked the necessary resources to create another thread-specific +data key, or the system-imposed limit on the total number of keys per process +[PTHREAD_KEYS_MAX] would be exceeded. +.It Bq Er ENOMEM +Insufficient memory exists to create the key. +.El +.Sh SEE ALSO +.Xr pthread_getspecific 3 , +.Xr pthread_key_delete 3 , +.Xr pthread_setspecific 3 +.Sh STANDARDS +.Fn pthread_key_create +conforms to +.St -p1003.1-96 . diff --git a/pthreads/pthread_key_delete.3 b/pthreads/pthread_key_delete.3 new file mode 100644 index 0000000..9e4a1ae --- /dev/null +++ b/pthreads/pthread_key_delete.3 @@ -0,0 +1,96 @@ +.\" Copyright (c) 1996 John Birrell . +.\" 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 John Birrell. +.\" 4. Neither the name of the author nor the names of any co-contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL 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. +.\" +.\" $FreeBSD: src/lib/libc_r/man/pthread_key_delete.3,v 1.6.2.4 2001/08/17 15:42:51 ru Exp $ +.\" +.Dd April 4, 1996 +.Dt PTHREAD_KEY_DELETE 3 +.Os +.Sh NAME +.Nm pthread_key_delete +.Nd delete a thread-specific data key +.Sh SYNOPSIS +.Fd #include +.Ft int +.Fn pthread_key_delete "pthread_key_t key" +.Sh DESCRIPTION +The +.Fn pthread_key_delete +function deletes a thread-specific data key previously returned by +.Fn pthread_key_create . +The thread-specific data values associated with +.Fa key +need not be NULL at the time that +.Fn pthread_key_delete +is called. +It is the responsibility of the application to free any +application storage or perform any cleanup actions for data structures +related to the deleted key or associated thread-specific data in any threads; +this cleanup can be done either before or after +.Fn pthread_key_delete +is called. +Any attempt to use +.Fa key +following the call to +.Fn pthread_key_delete +results in undefined behavior. +.Pp +The +.Fn pthread_key_delete +function is callable from within destructor functions. +Destructor functions +are not invoked by +.Fn pthread_key_delete . +Any destructor function that may have been associated with +.Fa key +will no longer be called upon thread exit. +.Sh RETURN VALUES +If successful, the +.Fn pthread_key_delete +function will return zero. +Otherwise an error number will be returned to +indicate the error. +.Sh ERRORS +.Fn pthread_key_delete +will fail if: +.Bl -tag -width Er +.It Bq Er EINVAL +The +.Fa key +value is invalid. +.El +.Sh SEE ALSO +.Xr pthread_getspecific 3 , +.Xr pthread_key_create 3 , +.Xr pthread_setspecific 3 +.Sh STANDARDS +.Fn pthread_key_delete +conforms to +.St -p1003.1-96 . diff --git a/pthreads/pthread_machdep.h b/pthreads/pthread_machdep.h new file mode 100644 index 0000000..57a3f24 --- /dev/null +++ b/pthreads/pthread_machdep.h @@ -0,0 +1,32 @@ +/* + * Copyright 1996 1995 by Open Software Foundation, Inc. 1997 1996 1995 1994 1993 1992 1991 + * 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 appears in all copies and + * that both the copyright notice and this permission notice appear in + * supporting documentation. + * + * OSF DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE. + * + * IN NO EVENT SHALL OSF BE LIABLE FOR ANY SPECIAL, INDIRECT, OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM + * LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT, + * NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION + * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ +/* + * MkLinux + */ + +/* Machine-dependent definitions for pthread internals. */ + +typedef long pthread_lock_t; + +#define LOCK_INIT(l) ((l) = 0) +#define LOCK_INITIALIZER 0 + +#undef STACK_GROWS_UP diff --git a/pthreads/pthread_mutex.c b/pthreads/pthread_mutex.c new file mode 100644 index 0000000..c82a692 --- /dev/null +++ b/pthreads/pthread_mutex.c @@ -0,0 +1,597 @@ +/* + * Copyright 1996 1995 by Open Software Foundation, Inc. 1997 1996 1995 1994 1993 1992 1991 + * 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 appears in all copies and + * that both the copyright notice and this permission notice appear in + * supporting documentation. + * + * OSF DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE. + * + * IN NO EVENT SHALL OSF BE LIABLE FOR ANY SPECIAL, INDIRECT, OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM + * LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT, + * NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION + * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + */ +/* + * MkLinux + */ + +/* + * POSIX Pthread Library + * -- Mutex variable support + */ + +#include "pthread_internals.h" + +/* + * Destroy a mutex variable. + */ +int +pthread_mutex_destroy(pthread_mutex_t *mutex) +{ + if (mutex->sig != _PTHREAD_MUTEX_SIG) + return (EINVAL); + if ((mutex->owner != (pthread_t)NULL) || + (mutex->busy != (pthread_cond_t *)NULL)) + return (EBUSY); + mutex->sig = _PTHREAD_NO_SIG; + return (ESUCCESS); +} + +/* + * Initialize a mutex variable, possibly with additional attributes. + */ +int +pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *attr) +{ + LOCK_INIT(mutex->lock); + mutex->sig = _PTHREAD_MUTEX_SIG; + if (attr) + { + if (attr->sig != _PTHREAD_MUTEX_ATTR_SIG) + return (EINVAL); + mutex->prioceiling = attr->prioceiling; + mutex->protocol = attr->protocol; + mutex->type = attr->type; + if ((mutex->type == PTHREAD_MUTEX_DEFAULT) || (mutex->type == PTHREAD_MUTEX_NORMAL)) + mutex->def = 1; + else + mutex->def = 0; + } else { + mutex->prioceiling = _PTHREAD_DEFAULT_PRIOCEILING; + mutex->protocol = _PTHREAD_DEFAULT_PROTOCOL; + mutex->type = PTHREAD_MUTEX_DEFAULT; + mutex->def = 1; + } + mutex->lock_count = 0; + mutex->owner = (pthread_t)NULL; + mutex->next = (pthread_mutex_t *)NULL; + mutex->prev = (pthread_mutex_t *)NULL; + mutex->busy = (pthread_cond_t *)NULL; + mutex->waiters = 0; + mutex->cond_lock = 0; + mutex->sem = MACH_PORT_NULL; + return (ESUCCESS); +} + +/* + * Manage a list of mutex variables owned by a thread + */ +#if defined(DEBUG) +static void +_pthread_mutex_add(pthread_mutex_t *mutex, pthread_t self) +{ + pthread_mutex_t *m; + if (self != (pthread_t)0) { + if ((m = self->mutexes) != (pthread_mutex_t *)NULL) + { /* Add to list */ + m->prev = mutex; + } + mutex->next = m; + mutex->prev = (pthread_mutex_t *)NULL; + self->mutexes = mutex; + } +} + +static void +_pthread_mutex_remove(pthread_mutex_t *mutex, pthread_t self) +{ + pthread_mutex_t *n, *prev; + if ((n = mutex->next) != (pthread_mutex_t *)NULL) + { + n->prev = mutex->prev; + } + if ((prev = mutex->prev) != (pthread_mutex_t *)NULL) + { + prev->next = mutex->next; + } else + { /* This is the first in the list */ + if (self != (pthread_t)0) { + self->mutexes = n; + } + } +} +#endif + +/* + * Lock a mutex. + * TODO: Priority inheritance stuff + */ +int +pthread_mutex_lock(pthread_mutex_t *mutex) +{ + kern_return_t kern_res; + pthread_t self; + int slowpath; + + if (mutex->sig == _PTHREAD_MUTEX_SIG_init) + { + int res; + if (res = pthread_mutex_init(mutex, NULL)) + return (res); + } + if (mutex->sig != _PTHREAD_MUTEX_SIG) + return (EINVAL); /* Not a mutex variable */ + +#if !defined(DEBUG) + if (mutex->def) { + slowpath = 0; + self = (pthread_t)0x12141968; + } else +#endif /* DEBUG */ + { + slowpath = 1; + self = pthread_self(); + } + + LOCK(mutex->lock); + + if (mutex->waiters || (mutex->owner != (pthread_t)NULL)) + { + if(slowpath && (mutex->owner == self)) { + if(mutex->type == PTHREAD_MUTEX_ERRORCHECK ) { + UNLOCK(mutex->lock); + return(EDEADLK); + } else if (mutex->type == PTHREAD_MUTEX_RECURSIVE ) { + if (mutex->lock_count >= USHRT_MAX){ + UNLOCK(mutex->lock); + return(EAGAIN); + } + mutex->lock_count++; + UNLOCK(mutex->lock); + return(ESUCCESS); + } + } + mutex->waiters++; + if (mutex->sem == MACH_PORT_NULL) { + mutex->sem = new_sem_from_pool(); + } + UNLOCK(mutex->lock); + do { + PTHREAD_MACH_CALL(semaphore_wait(mutex->sem), kern_res); + } while (kern_res == KERN_ABORTED); + LOCK(mutex->lock); + mutex->waiters--; + if (mutex->waiters == 0) { + restore_sem_to_pool(mutex->sem); + mutex->sem = MACH_PORT_NULL; + } + if (mutex->cond_lock) { + mutex->cond_lock = 0; + } + } +#if defined(DEBUG) + _pthread_mutex_add(mutex, self); +#endif + mutex->owner = self; + if (slowpath && (mutex->type == PTHREAD_MUTEX_RECURSIVE)) + mutex->lock_count = 1; + UNLOCK(mutex->lock); + return (ESUCCESS); +} + +/* + * Attempt to lock a mutex, but don't block if this isn't possible. + */ +int +pthread_mutex_trylock(pthread_mutex_t *mutex) +{ + kern_return_t kern_res; + pthread_t self; + int slowpath; + + if (mutex->sig == _PTHREAD_MUTEX_SIG_init) + { + int res; + if (res = pthread_mutex_init(mutex, NULL)) + return (res); + } + if (mutex->sig != _PTHREAD_MUTEX_SIG) + return (EINVAL); /* Not a mutex variable */ + +#if !defined(DEBUG) + if (mutex->def) { + slowpath = 0; + self = (pthread_t)0x12141968; + } else +#endif /* DEBUG */ + { + slowpath = 1; + self = pthread_self(); + } + + if (!TRY_LOCK(mutex->lock)) { + return (EBUSY); + } + + if(slowpath && (mutex->owner == self) && (mutex->type == PTHREAD_MUTEX_RECURSIVE )) { + if (mutex->lock_count >= USHRT_MAX) { + UNLOCK(mutex->lock); + return(EAGAIN); + } + mutex->lock_count++; + UNLOCK(mutex->lock); + return(ESUCCESS); + } + + if (mutex->waiters || + ((mutex->owner != (pthread_t)NULL) && (mutex->cond_lock == 0))) + { + UNLOCK(mutex->lock); + return (EBUSY); + } else { +#if defined(DEBUG) + _pthread_mutex_add(mutex, self); +#endif + mutex->owner = (pthread_t)self; + if (mutex->cond_lock) { + PTHREAD_MACH_CALL(semaphore_wait(mutex->sem), kern_res); + mutex->cond_lock = 0; + restore_sem_to_pool(mutex->sem); + mutex->sem = MACH_PORT_NULL; + } + if (slowpath && (mutex->type == PTHREAD_MUTEX_RECURSIVE)) + mutex->lock_count = 1; + UNLOCK(mutex->lock); + return (ESUCCESS); + } +} + +/* + * Unlock a mutex. + * TODO: Priority inheritance stuff + */ +int +pthread_mutex_unlock(pthread_mutex_t *mutex) +{ + kern_return_t kern_res; + int waiters; + pthread_t self; + int slowpath; + + if (mutex->sig == _PTHREAD_MUTEX_SIG_init) + { + int res; + if (res = pthread_mutex_init(mutex, NULL)) + return (res); + } + if (mutex->sig != _PTHREAD_MUTEX_SIG) + return (EINVAL); /* Not a mutex variable */ + +#if !defined(DEBUG) + if (mutex->def) { + slowpath = 0; + self = (pthread_t)0x12141968; + } else +#endif /* DEBUG */ + { + slowpath = 1; + self = pthread_self(); + } + + LOCK(mutex->lock); + +#if defined(DEBUG) + if (mutex->owner != self) +#else + if (slowpath + && ((mutex->type == PTHREAD_MUTEX_ERRORCHECK ) + || (mutex->type == PTHREAD_MUTEX_RECURSIVE )) + && (mutex->owner != self)) +#endif /* DEBUG */ + { + UNLOCK(mutex->lock); +#if defined(DEBUG) + abort(); +#endif + return(EPERM); + } + + if (slowpath && (mutex->type == PTHREAD_MUTEX_RECURSIVE) && --mutex->lock_count) { + UNLOCK(mutex->lock); + return (ESUCCESS); + + } else { +#if defined(DEBUG) + _pthread_mutex_remove(mutex, mutex->owner); +#endif /* DEBUG */ + waiters = mutex->waiters; + mutex->owner = (pthread_t)NULL; + UNLOCK(mutex->lock); + if (waiters) + { + PTHREAD_MACH_CALL(semaphore_signal(mutex->sem), kern_res); + } + return (ESUCCESS); + + } +} + +/* + * Fetch the priority ceiling value from a mutex variable. + * Note: written as a 'helper' function to hide implementation details. + */ +int +pthread_mutex_getprioceiling(const pthread_mutex_t *mutex, + int *prioceiling) +{ + if (mutex->sig == _PTHREAD_MUTEX_SIG) + { + *prioceiling = mutex->prioceiling; + return (ESUCCESS); + } else + { + return (EINVAL); /* Not an initialized 'attribute' structure */ + } +} + +/* + * Set the priority ceiling for a mutex. + * Note: written as a 'helper' function to hide implementation details. + */ +int +pthread_mutex_setprioceiling(pthread_mutex_t *mutex, + int prioceiling, + int *old_prioceiling) +{ + if (mutex->sig == _PTHREAD_MUTEX_SIG) + { + if ((prioceiling >= -999) || + (prioceiling <= 999)) + { + *old_prioceiling = mutex->prioceiling; + mutex->prioceiling = prioceiling; + return (ESUCCESS); + } else + { + return (EINVAL); /* Invalid parameter */ + } + } else + { + return (EINVAL); /* Not an initialized 'attribute' structure */ + } +} + +/* + * Destroy a mutex attribute structure. + */ +int +pthread_mutexattr_destroy(pthread_mutexattr_t *attr) +{ + attr->sig = _PTHREAD_NO_SIG; /* Uninitialized */ + return (ESUCCESS); +} + +/* + * Get the priority ceiling value from a mutex attribute structure. + * Note: written as a 'helper' function to hide implementation details. + */ +int +pthread_mutexattr_getprioceiling(const pthread_mutexattr_t *attr, + int *prioceiling) +{ + if (attr->sig == _PTHREAD_MUTEX_ATTR_SIG) + { + *prioceiling = attr->prioceiling; + return (ESUCCESS); + } else + { + return (EINVAL); /* Not an initialized 'attribute' structure */ + } +} + +/* + * Get the mutex 'protocol' value from a mutex attribute structure. + * Note: written as a 'helper' function to hide implementation details. + */ +int +pthread_mutexattr_getprotocol(const pthread_mutexattr_t *attr, + int *protocol) +{ + if (attr->sig == _PTHREAD_MUTEX_ATTR_SIG) + { + *protocol = attr->protocol; + return (ESUCCESS); + } else + { + return (EINVAL); /* Not an initialized 'attribute' structure */ + } +} +/* + * Get the mutex 'type' value from a mutex attribute structure. + * Note: written as a 'helper' function to hide implementation details. + */ +int +pthread_mutexattr_gettype(const pthread_mutexattr_t *attr, + int *type) +{ + if (attr->sig == _PTHREAD_MUTEX_ATTR_SIG) + { + *type = attr->type; + return (ESUCCESS); + } else + { + return (EINVAL); /* Not an initialized 'attribute' structure */ + } +} + +/* + * + */ +int +pthread_mutexattr_getpshared(const pthread_mutexattr_t *attr, int *pshared) +{ + if (attr->sig == _PTHREAD_MUTEX_ATTR_SIG) + { + *pshared = (int)PTHREAD_PROCESS_PRIVATE; + return (ESUCCESS); + } else + { + return (EINVAL); /* Not an initialized 'attribute' structure */ + } +} + +/* + * Initialize a mutex attribute structure to system defaults. + */ +int +pthread_mutexattr_init(pthread_mutexattr_t *attr) +{ + attr->prioceiling = _PTHREAD_DEFAULT_PRIOCEILING; + attr->protocol = _PTHREAD_DEFAULT_PROTOCOL; + attr->type = PTHREAD_MUTEX_DEFAULT; + attr->sig = _PTHREAD_MUTEX_ATTR_SIG; + return (ESUCCESS); +} + +/* + * Set the priority ceiling value in a mutex attribute structure. + * Note: written as a 'helper' function to hide implementation details. + */ +int +pthread_mutexattr_setprioceiling(pthread_mutexattr_t *attr, + int prioceiling) +{ + if (attr->sig == _PTHREAD_MUTEX_ATTR_SIG) + { + if ((prioceiling >= -999) || + (prioceiling <= 999)) + { + attr->prioceiling = prioceiling; + return (ESUCCESS); + } else + { + return (EINVAL); /* Invalid parameter */ + } + } else + { + return (EINVAL); /* Not an initialized 'attribute' structure */ + } +} + +/* + * Set the mutex 'protocol' value in a mutex attribute structure. + * Note: written as a 'helper' function to hide implementation details. + */ +int +pthread_mutexattr_setprotocol(pthread_mutexattr_t *attr, + int protocol) +{ + if (attr->sig == _PTHREAD_MUTEX_ATTR_SIG) + { + if ((protocol == PTHREAD_PRIO_NONE) || + (protocol == PTHREAD_PRIO_INHERIT) || + (protocol == PTHREAD_PRIO_PROTECT)) + { + attr->protocol = protocol; + return (ESUCCESS); + } else + { + return (EINVAL); /* Invalid parameter */ + } + } else + { + return (EINVAL); /* Not an initialized 'attribute' structure */ + } +} +/* + * Set the mutex 'type' value in a mutex attribute structure. + * Note: written as a 'helper' function to hide implementation details. + */ +int +pthread_mutexattr_settype(pthread_mutexattr_t *attr, + int type) +{ + if (attr->sig == _PTHREAD_MUTEX_ATTR_SIG) + { + if ((type == PTHREAD_MUTEX_NORMAL) || + (type == PTHREAD_MUTEX_ERRORCHECK) || + (type == PTHREAD_MUTEX_RECURSIVE) || + (type == PTHREAD_MUTEX_DEFAULT)) + { + attr->type = type; + return (ESUCCESS); + } else + { + return (EINVAL); /* Invalid parameter */ + } + } else + { + return (EINVAL); /* Not an initialized 'attribute' structure */ + } +} + +/* + * + */ +int +pthread_mutexattr_setpshared(pthread_mutexattr_t *attr, int pshared) +{ + if (attr->sig == _PTHREAD_MUTEX_ATTR_SIG) + { + if (pshared == PTHREAD_PROCESS_PRIVATE) + { + /* attr->pshared = protocol; */ + return (ESUCCESS); + } else + { + return (EINVAL); /* Invalid parameter */ + } + } else + { + return (EINVAL); /* Not an initialized 'attribute' structure */ + } +} + +int mutex_try_lock(int *x) { + return _spin_lock_try((pthread_lock_t *)x); +} + +void mutex_wait_lock(int *x) { + for (;;) { + if( _spin_lock_try((pthread_lock_t *)x)) { + return; + } + swtch_pri(0); + } +} + +void +cthread_yield(void) +{ + sched_yield(); +} + +void +pthread_yield_np (void) +{ + sched_yield(); +} + diff --git a/pthreads/pthread_mutex_destroy.3 b/pthreads/pthread_mutex_destroy.3 new file mode 100644 index 0000000..d00d976 --- /dev/null +++ b/pthreads/pthread_mutex_destroy.3 @@ -0,0 +1,70 @@ +.\" Copyright (c) 1997 Brian Cully +.\" 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. Neither the name of the author nor the names of any co-contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL 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. +.\" +.\" $FreeBSD: src/lib/libc_r/man/pthread_mutex_destroy.3,v 1.5.2.4 2001/08/17 15:42:51 ru Exp $ +.\" +.Dd July 29, 1998 +.Dt PTHREAD_MUTEX_DESTROY 3 +.Os +.Sh NAME +.Nm pthread_mutex_destroy +.Nd free resources allocated for a mutex +.Sh SYNOPSIS +.Fd #include +.Ft int +.Fn pthread_mutex_destroy "pthread_mutex_t *mutex" +.Sh DESCRIPTION +The +.Fn pthread_mutex_destroy +function frees the resources allocated for +.Fa mutex . +.Sh RETURN VALUES +If successful, +.Fn pthread_mutex_destroy +will return zero, otherwise an error number will be returned to +indicate the error. +.Sh ERRORS +.Fn pthread_mutex_destroy +will fail if: +.Bl -tag -width Er +.It Bq Er EINVAL +The value specified by +.Fa mutex +is invalid. +.It Bq Er EBUSY +.Fa Mutex +is locked by another thread. +.El +.Sh SEE ALSO +.Xr pthread_mutex_init 3 , +.Xr pthread_mutex_lock 3 , +.Xr pthread_mutex_trylock 3 , +.Xr pthread_mutex_unlock 3 +.Sh STANDARDS +.Fn pthread_mutex_destroy +conforms to +.St -p1003.1-96 . diff --git a/pthreads/pthread_mutex_init.3 b/pthreads/pthread_mutex_init.3 new file mode 100644 index 0000000..bd6e2f5 --- /dev/null +++ b/pthreads/pthread_mutex_init.3 @@ -0,0 +1,75 @@ +.\" Copyright (c) 1997 Brian Cully +.\" 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. Neither the name of the author nor the names of any co-contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL 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. +.\" +.\" $FreeBSD: src/lib/libc_r/man/pthread_mutex_init.3,v 1.6.2.4 2001/08/17 15:42:51 ru Exp $ +.\" +.Dd July 29, 1998 +.Dt PTHREAD_MUTEX_INIT 3 +.Os +.Sh NAME +.Nm pthread_mutex_init +.Nd create a mutex +.Sh SYNOPSIS +.Fd #include +.Ft int +.Fn pthread_mutex_init "pthread_mutex_t *mutex" "const pthread_mutexattr_t *attr" +.Sh DESCRIPTION +The +.Fn pthread_mutex_init +function creates a new mutex, with attributes specified with +.Fa attr . +If +.Fa attr +is NULL the default attributes are used. +.Sh RETURN VALUES +If successful, +.Fn pthread_mutex_init +will return zero and put the new mutex id into +.Fa mutex , +otherwise an error number will be returned to indicate the error. +.Sh ERRORS +.Fn pthread_mutex_init +will fail if: +.Bl -tag -width Er +.It Bq Er EINVAL +The value specified by +.Fa attr +is invalid. +.It Bq Er ENOMEM +The process cannot allocate enough memory to create another mutex. +.It Bq Er EAGAIN +The temporarily lacks the resources to create another mutex. +.El +.Sh SEE ALSO +.Xr pthread_mutex_destroy 3 , +.Xr pthread_mutex_lock 3 , +.Xr pthread_mutex_trylock 3 , +.Xr pthread_mutex_unlock 3 +.Sh STANDARDS +.Fn pthread_mutex_init +conforms to +.St -p1003.1-96 . diff --git a/pthreads/pthread_mutex_lock.3 b/pthreads/pthread_mutex_lock.3 new file mode 100644 index 0000000..468bd0c --- /dev/null +++ b/pthreads/pthread_mutex_lock.3 @@ -0,0 +1,72 @@ +.\" Copyright (c) 1997 Brian Cully +.\" 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. Neither the name of the author nor the names of any co-contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL 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. +.\" +.\" $FreeBSD: src/lib/libc_r/man/pthread_mutex_lock.3,v 1.5.2.4 2001/08/17 15:42:51 ru Exp $ +.\" +.Dd July 30, 1998 +.Dt PTHREAD_MUTEX_LOCK 3 +.Os +.Sh NAME +.Nm pthread_mutex_lock +.Nd lock a mutex +.Sh SYNOPSIS +.Fd #include +.Ft int +.Fn pthread_mutex_lock "pthread_mutex_t *mutex" +.Sh DESCRIPTION +The +.Fn pthread_mutex_lock +function locks +.Fa mutex . +If the mutex is already locked, the calling thread will block until the +mutex becomes available. +.Sh RETURN VALUES +If successful, +.Fn pthread_mutex_lock +will return zero, otherwise an error number will be returned to +indicate the error. +.Sh ERRORS +.Fn pthread_mutex_lock +will fail if: +.Bl -tag -width Er +.It Bq Er EINVAL +The value specified by +.Fa mutex +is invalid. +.It Bq Er EDEADLK +A deadlock would occur if the thread blocked waiting for +.Fa mutex . +.El +.Sh SEE ALSO +.Xr pthread_mutex_destroy 3 , +.Xr pthread_mutex_init 3 , +.Xr pthread_mutex_trylock 3 , +.Xr pthread_mutex_unlock 3 +.Sh STANDARDS +.Fn pthread_mutex_lock +conforms to +.St -p1003.1-96 . diff --git a/pthreads/pthread_mutex_trylock.3 b/pthreads/pthread_mutex_trylock.3 new file mode 100644 index 0000000..87fac64 --- /dev/null +++ b/pthreads/pthread_mutex_trylock.3 @@ -0,0 +1,73 @@ +.\" Copyright (c) 1997 Brian Cully +.\" 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. Neither the name of the author nor the names of any co-contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL 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. +.\" +.\" $FreeBSD: src/lib/libc_r/man/pthread_mutex_trylock.3,v 1.5.2.4 2001/08/17 15:42:51 ru Exp $ +.\" +.Dd July 30, 1998 +.Dt PTHREAD_MUTEX_TRYLOCK 3 +.Os +.Sh NAME +.Nm pthread_mutex_trylock +.Nd attempt to lock a mutex without blocking +.Sh SYNOPSIS +.Fd #include +.Ft int +.Fn pthread_mutex_trylock "pthread_mutex_t *mutex" +.Sh DESCRIPTION +The +.Fn pthread_mutex_trylock +function locks +.Fa mutex . +If the mutex is already locked, +.Fn pthread_mutex_trylock +will not block waiting for the mutex, but will return an error condition. +.Sh RETURN VALUES +If successful, +.Fn pthread_mutex_trylock +will return zero, otherwise an error number will be returned to +indicate the error. +.Sh ERRORS +.Fn pthread_mutex_trylock +will fail if: +.Bl -tag -width Er +.It Bq Er EINVAL +The value specified by +.Fa mutex +is invalid. +.It Bq Er EBUSY +.Fa Mutex +is already locked. +.El +.Sh SEE ALSO +.Xr pthread_mutex_destroy 3 , +.Xr pthread_mutex_init 3 , +.Xr pthread_mutex_lock 3 , +.Xr pthread_mutex_unlock 3 +.Sh STANDARDS +.Fn pthread_mutex_trylock +conforms to +.St -p1003.1-96 . diff --git a/pthreads/pthread_mutex_unlock.3 b/pthreads/pthread_mutex_unlock.3 new file mode 100644 index 0000000..38c509f --- /dev/null +++ b/pthreads/pthread_mutex_unlock.3 @@ -0,0 +1,72 @@ +.\" Copyright (c) 1997 Brian Cully +.\" 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. Neither the name of the author nor the names of any co-contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL 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. +.\" +.\" $FreeBSD: src/lib/libc_r/man/pthread_mutex_unlock.3,v 1.5.2.4 2001/08/17 15:42:51 ru Exp $ +.\" +.Dd July 30, 1998 +.Dt PTHREAD_MUTEX_UNLOCK 3 +.Os +.Sh NAME +.Nm pthread_mutex_unlock +.Nd unlock a mutex +.Sh SYNOPSIS +.Fd #include +.Ft int +.Fn pthread_mutex_unlock "pthread_mutex_t *mutex" +.Sh DESCRIPTION +If the current thread holds the lock on +.Fa mutex , +then the +.Fn pthread_mutex_unlock +function unlocks +.Fa mutex . +.Sh RETURN VALUES +If successful, +.Fn pthread_mutex_unlock +will return zero, otherwise an error number will be returned to +indicate the error. +.Sh ERRORS +.Fn pthread_mutex_trylock +will fail if: +.Bl -tag -width Er +.It Bq Er EINVAL +The value specified by +.Fa mutex +is invalid. +.It Bq Er EPERM +The current thread does not hold a lock on +.Fa mutex . +.El +.Sh SEE ALSO +.Xr pthread_mutex_destroy 3 , +.Xr pthread_mutex_init 3 , +.Xr pthread_mutex_lock 3 , +.Xr pthread_mutex_trylock 3 +.Sh STANDARDS +.Fn pthread_mutex_unlock +conforms to +.St -p1003.1-96 . diff --git a/pthreads/pthread_mutexattr.3 b/pthreads/pthread_mutexattr.3 new file mode 100644 index 0000000..7588739 --- /dev/null +++ b/pthreads/pthread_mutexattr.3 @@ -0,0 +1,175 @@ +.\" Copyright (C) 2000 Jason Evans . +.\" 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(s), this list of conditions and the following disclaimer as +.\" the first lines of this file unmodified other than the possible +.\" addition of one or more copyright notices. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice(s), 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 COPYRIGHT HOLDER(S) ``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 COPYRIGHT HOLDER(S) 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_r/man/pthread_mutexattr.3,v 1.2.2.5 2001/08/17 15:42:52 ru Exp $ +.Dd May 1, 2000 +.Dt PTHREAD_MUTEXATTR 3 +.Os +.Sh NAME +.Nm pthread_mutexattr_init , +.Nm pthread_mutexattr_destroy , +.Nm pthread_mutexattr_setprioceiling , +.Nm pthread_mutexattr_getprioceiling , +.Nm pthread_mutexattr_setprotocol , +.Nm pthread_mutexattr_getprotocol , +.Nm pthread_mutexattr_settype , +.Nm pthread_mutexattr_gettype +.Nd mutex attribute operations +.Sh SYNOPSIS +.Fd #include +.Ft int +.Fn pthread_mutexattr_init "pthread_mutexattr_t *attr" +.Ft int +.Fn pthread_mutexattr_destroy "pthread_mutexattr_t *attr" +.Ft int +.Fn pthread_mutexattr_setprioceiling "pthread_mutexattr_t *attr" "int prioceiling" +.Ft int +.Fn pthread_mutexattr_getprioceiling "pthread_mutexattr_t *attr" "int *prioceiling" +.Ft int +.Fn pthread_mutexattr_setprotocol "pthread_mutexattr_t *attr" "int protocol" +.Ft int +.Fn pthread_mutexattr_getprotocol "pthread_mutexattr_t *attr" "int *protocol" +.Ft int +.Fn pthread_mutexattr_settype "pthread_mutexattr_t *attr" "int type" +.Ft int +.Fn pthread_mutexattr_gettype "pthread_mutexattr_t *attr" "int *type" +.Sh DESCRIPTION +Mutex attributes are used to specify parameters to +.Fn pthread_mutex_init . +One attribute object can be used in multiple calls to +.Fn pthread_mutex_init , +with or without modifications between calls. +.Pp +The +.Fn pthread_mutexattr_init +function initializes +.Fa attr +with all the default mutex attributes. +.Pp +The +.Fn pthread_mutexattr_destroy +function destroys +.Fa attr . +.Pp +The +.Fn pthread_mutexattr_set* +functions set the attribute that corresponds to each function name. +.Pp +The +.Fn pthread_mutexattr_get* +functions copy the value of the attribute that corresponds to each function name +to the location pointed to by the second function parameter. +.Sh RETURN VALUES +If successful, these functions return 0. +Otherwise, an error number is returned to indicacte the error. +.Sh ERRORS +.Fn pthread_mutexattr_init +will fail if: +.Bl -tag -width Er +.It Bq Er ENOMEM +Out of memory. +.El +.Pp +.Fn pthread_mutexattr_destroy +will fail if: +.Bl -tag -width Er +.It Bq Er EINVAL +Invalid value for +.Fa attr . +.El +.Pp +.Fn pthread_mutexattr_setprioceiling +will fail if: +.Bl -tag -width Er +.It Bq Er EINVAL +Invalid value for +.Fa attr , +or invalid value for +.Fa prioceiling . +.El +.Pp +.Fn pthread_mutexattr_getprioceiling +will fail if: +.Bl -tag -width Er +.It Bq Er EINVAL +Invalid value for +.Fa attr . +.El +.Pp +.Fn pthread_mutexattr_setprotocol +will fail if: +.Bl -tag -width Er +.It Bq Er EINVAL +Invalid value for +.Fa attr , +or invalid value for +.Fa protocol . +.El +.Pp +.Fn pthread_mutexattr_getprotocol +will fail if: +.Bl -tag -width Er +.It Bq Er EINVAL +Invalid value for +.Fa attr . +.El +.Pp +.Fn pthread_mutexattr_settype +will fail if: +.Bl -tag -width Er +.It Bq Er EINVAL +Invalid value for +.Fa attr , +or invalid value for +.Fa type . +.El +.Pp +.Fn pthread_mutexattr_gettype +will fail if: +.Bl -tag -width Er +.It Bq Er EINVAL +Invalid value for +.Fa attr . +.El +.Sh SEE ALSO +.Xr pthread_mutex_init 3 +.Sh STANDARDS +.Fn pthread_mutexattr_init +and +.Fn pthread_mutexattr_destroy +conform to +.St -p1003.1-96 +.Pp +.Fn pthread_mutexattr_setprioceiling , +.Fn pthread_mutexattr_getprioceiling , +.Fn pthread_mutexattr_setprotocol , +.Fn pthread_mutexattr_getprotocol , +.Fn pthread_mutexattr_settype , +and +.Fn pthread_mutexattr_gettype +conform to +.St -susv2 diff --git a/pthreads/pthread_once.3 b/pthreads/pthread_once.3 new file mode 100644 index 0000000..d9d5685 --- /dev/null +++ b/pthreads/pthread_once.3 @@ -0,0 +1,103 @@ +.\" Copyright (c) 1996 John Birrell . +.\" 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 John Birrell. +.\" 4. Neither the name of the author nor the names of any co-contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL 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. +.\" +.\" $FreeBSD: src/lib/libc_r/man/pthread_once.3,v 1.6.2.6 2001/08/17 15:42:52 ru Exp $ +.\" +.Dd April 4, 1996 +.Dt PTHREAD_ONCE 3 +.Os +.Sh NAME +.Nm pthread_once +.Nd dynamic package initialization +.Sh SYNOPSIS +.Fd #include +.Pp +pthread_once_t +.Fa once_control += PTHREAD_ONCE_INIT; +.Ft int +.Fn pthread_once "pthread_once_t *once_control" "void (*init_routine)(void)" +.Sh DESCRIPTION +The first call to +.Fn pthread_once +by any thread in a process, with a given +.Fa once_control , +will call the +.Fn init_routine +with no arguments. +Subsequent calls to +.Fn pthread_once +with the same +.Fa once_control +will not call the +.Fn init_routine . +On return from +.Fn pthread_once , +it is guaranteed that +.Fn init_routine +has completed. +The +.Fa once_control +parameter is used to determine whether the associated initialization +routine has been called. +.Pp +The function +.Fn pthread_once +is not a cancellation point. +However, if +.Fn init_routine +is a cancellation point and is cancelled, the effect on +.Fa once_control is as if +.Fn pthread_once +was never called. +.Pp +The constant +.Fa PTHREAD_ONCE_INIT +is defined by header +.Aq Pa pthread.h . +.Pp +The behavior of +.Fn pthread_once +is undefined if +.Fa once_control +has automatic storage duration or is not initialized by +.Fa PTHREAD_ONCE_INIT . +.Sh RETURN VALUES +If successful, the +.Fn pthread_once +function will return zero. +Otherwise an error number will be returned to +indicate the error. +.Sh ERRORS +None. +.Sh STANDARDS +.Fn pthread_once +conforms to +.St -p1003.1-96 . diff --git a/pthreads/pthread_rwlock.c b/pthreads/pthread_rwlock.c new file mode 100644 index 0000000..978ed80 --- /dev/null +++ b/pthreads/pthread_rwlock.c @@ -0,0 +1,319 @@ +/*- + * Copyright (c) 1998 Alex Nash + * 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_r/uthread/uthread_rwlock.c,v 1.6 2001/04/10 04:19:20 deischen Exp $ + */ + +/* + * POSIX Pthread Library + * -- Read Write Lock support + * 4/24/02: A. Ramesh + * Ported from FreeBSD + */ + +#include "pthread_internals.h" + +/* maximum number of times a read lock may be obtained */ +#define MAX_READ_LOCKS (INT_MAX - 1) + +int +pthread_rwlock_destroy(pthread_rwlock_t *rwlock) +{ + + if (rwlock->sig != _PTHREAD_RWLOCK_SIG) { + return(EINVAL); + } else { + pthread_mutex_destroy(&rwlock->lock); + pthread_cond_destroy(&rwlock->read_signal); + pthread_cond_destroy(&rwlock->write_signal); + rwlock->sig = _PTHREAD_NO_SIG; + return(ESUCCESS); + } +} + +int +pthread_rwlock_init(pthread_rwlock_t *rwlock, const pthread_rwlockattr_t *attr) +{ + int ret; + + /* initialize the lock */ + if ((ret = pthread_mutex_init(&rwlock->lock, NULL)) != 0) + return(ret); + else { + /* initialize the read condition signal */ + ret = pthread_cond_init(&rwlock->read_signal, NULL); + + if (ret != 0) { + pthread_mutex_destroy(&rwlock->lock); + return(ret); + } else { + /* initialize the write condition signal */ + ret = pthread_cond_init(&rwlock->write_signal, NULL); + + if (ret != 0) { + pthread_cond_destroy(&rwlock->read_signal); + pthread_mutex_destroy(&rwlock->lock); + return(ret); + } else { + /* success */ + rwlock->state = 0; + rwlock->blocked_writers = 0; + rwlock->sig = _PTHREAD_RWLOCK_SIG; + return(ESUCCESS); + } + } + } +} + +int +pthread_rwlock_rdlock(pthread_rwlock_t *rwlock) +{ + int ret; + + if (rwlock->sig == _PTHREAD_RWLOCK_SIG_init) { + if ((ret = pthread_rwlock_init(rwlock, NULL)) != 0) { + return(ret); + } + } + + if (rwlock->sig != _PTHREAD_RWLOCK_SIG) + return(EINVAL); + /* grab the monitor lock */ + if ((ret = pthread_mutex_lock(&rwlock->lock)) != 0) + return(ret); + + /* give writers priority over readers */ + while (rwlock->blocked_writers || rwlock->state < 0) { + ret = pthread_cond_wait(&rwlock->read_signal, &rwlock->lock); + + if (ret != 0) { + /* can't do a whole lot if this fails */ + pthread_mutex_unlock(&rwlock->lock); + return(ret); + } + } + + /* check lock count */ + if (rwlock->state == MAX_READ_LOCKS) + ret = EAGAIN; + else + ++rwlock->state; /* indicate we are locked for reading */ + + /* + * Something is really wrong if this call fails. Returning + * error won't do because we've already obtained the read + * lock. Decrementing 'state' is no good because we probably + * don't have the monitor lock. + */ + pthread_mutex_unlock(&rwlock->lock); + + return(ret); +} + +int +pthread_rwlock_tryrdlock(pthread_rwlock_t *rwlock) +{ + int ret; + + /* check for static initialization */ + if (rwlock->sig == _PTHREAD_RWLOCK_SIG_init) { + if ((ret = pthread_rwlock_init(rwlock, NULL)) != 0) { + return(ret); + } + } + + if (rwlock->sig != _PTHREAD_RWLOCK_SIG) + return(EINVAL); + /* grab the monitor lock */ + if ((ret = pthread_mutex_lock(&rwlock->lock)) != 0) + return(ret); + + /* give writers priority over readers */ + if (rwlock->blocked_writers || rwlock->state < 0) + ret = EBUSY; + else if (rwlock->state == MAX_READ_LOCKS) + ret = EAGAIN; /* too many read locks acquired */ + else + ++rwlock->state; /* indicate we are locked for reading */ + + /* see the comment on this in pthread_rwlock_rdlock */ + pthread_mutex_unlock(&rwlock->lock); + + return(ret); +} + +int +pthread_rwlock_trywrlock(pthread_rwlock_t *rwlock) +{ + int ret; + + /* check for static initialization */ + if (rwlock->sig == _PTHREAD_RWLOCK_SIG_init) { + if ((ret = pthread_rwlock_init(rwlock, NULL)) != 0) { + return(ret); + } + } + + if (rwlock->sig != _PTHREAD_RWLOCK_SIG) + return(EINVAL); + /* grab the monitor lock */ + if ((ret = pthread_mutex_lock(&rwlock->lock)) != 0) + return(ret); + + if (rwlock->state != 0) + ret = EBUSY; + else + /* indicate we are locked for writing */ + rwlock->state = -1; + + /* see the comment on this in pthread_rwlock_rdlock */ + pthread_mutex_unlock(&rwlock->lock); + + return(ret); +} + +int +pthread_rwlock_unlock(pthread_rwlock_t *rwlock) +{ + int ret; + + if (rwlock->sig != _PTHREAD_RWLOCK_SIG) + return(EINVAL); + /* grab the monitor lock */ + if ((ret = pthread_mutex_lock(&rwlock->lock)) != 0) + return(ret); + + if (rwlock->state > 0) { + if (--rwlock->state == 0 && rwlock->blocked_writers) + ret = pthread_cond_signal(&rwlock->write_signal); + } else if (rwlock->state < 0) { + rwlock->state = 0; + + if (rwlock->blocked_writers) + ret = pthread_cond_signal(&rwlock->write_signal); + else + ret = pthread_cond_broadcast(&rwlock->read_signal); + } else + ret = EINVAL; + + /* see the comment on this in pthread_rwlock_rdlock */ + pthread_mutex_unlock(&rwlock->lock); + + return(ret); +} + +int +pthread_rwlock_wrlock(pthread_rwlock_t *rwlock) +{ + int ret; + + /* check for static initialization */ + if (rwlock->sig == _PTHREAD_RWLOCK_SIG_init) { + if ((ret = pthread_rwlock_init(rwlock, NULL)) != 0) { + return(ret); + } + } + + if (rwlock->sig != _PTHREAD_RWLOCK_SIG) + return(EINVAL); + /* grab the monitor lock */ + if ((ret = pthread_mutex_lock(&rwlock->lock)) != 0) + return(ret); + + while (rwlock->state != 0) { + ++rwlock->blocked_writers; + + ret = pthread_cond_wait(&rwlock->write_signal, &rwlock->lock); + + if (ret != 0) { + --rwlock->blocked_writers; + pthread_mutex_unlock(&rwlock->lock); + return(ret); + } + + --rwlock->blocked_writers; + } + + /* indicate we are locked for writing */ + rwlock->state = -1; + + /* see the comment on this in pthread_rwlock_rdlock */ + pthread_mutex_unlock(&rwlock->lock); + + return(ret); +} + +int +pthread_rwlockattr_init(pthread_rwlockattr_t *attr) +{ + attr->sig = _PTHREAD_RWLOCK_ATTR_SIG; + attr->pshared = PTHREAD_PROCESS_PRIVATE; + return (ESUCCESS); +} + +int +pthread_rwlockattr_destroy(pthread_rwlockattr_t *attr) +{ + attr->sig = _PTHREAD_NO_SIG; /* Uninitialized */ + attr->pshared = 0; + return (ESUCCESS); +} + +int +pthread_rwlockattr_getpshared(const pthread_rwlockattr_t *attr, + int *pshared) +{ + if (attr->sig == _PTHREAD_RWLOCK_ATTR_SIG) + { + /* *pshared = (int)attr->pshared; */ + *pshared = (int)PTHREAD_PROCESS_PRIVATE; + return (ESUCCESS); + } else + { + return (EINVAL); /* Not an initialized 'attribute' structure */ + } +} + + +int +pthread_rwlockattr_setpshared(pthread_rwlockattr_t * attr, int pshared) +{ + if (attr->sig == _PTHREAD_RWLOCK_ATTR_SIG) + { + if ( pshared == PTHREAD_PROCESS_PRIVATE) + { + attr->pshared = pshared ; + return (ESUCCESS); + } else + { + return (EINVAL); /* Invalid parameter */ + } + } else + { + return (EINVAL); /* Not an initialized 'attribute' structure */ + } + +} + diff --git a/pthreads/pthread_rwlock_destroy.3 b/pthreads/pthread_rwlock_destroy.3 new file mode 100644 index 0000000..2e77f37 --- /dev/null +++ b/pthreads/pthread_rwlock_destroy.3 @@ -0,0 +1,80 @@ +.\" Copyright (c) 1998 Alex Nash +.\" 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_r/man/pthread_rwlock_destroy.3,v 1.6 2001/10/01 16:09:09 ru Exp $ +.\" +.Dd August 4, 1998 +.Dt PTHREAD_RWLOCK_DESTROY 3 +.Os +.Sh NAME +.Nm pthread_rwlock_destroy +.Nd destroy a read/write lock +.Sh SYNOPSIS +.In pthread.h +.Ft int +.Fn pthread_rwlock_destroy "pthread_rwlock_t *lock" +.Sh DESCRIPTION +The +.Fn pthread_rwlock_destroy +function is used to destroy a read/write lock previously created with +.Fn pthread_rwlock_init . +.Sh RETURN VALUES +If successful, the +.Fn pthread_rwlock_destroy +function will return zero. Otherwise an error number will be returned +to indicate the error. +.Sh SEE ALSO +.Xr pthread_rwlock_init 3 +.Sh STANDARDS +The +.Fn pthread_rwlock_destroy +function is expected to conform to +.St -susv2 . +.Sh ERRORS +The +.Fn pthread_rwlock_destroy +function will fail if: +.Bl -tag -width Er +.It Bq Er EPERM +The caller does not have the privilege to perform the operation. +.El +.Pp +The +.Fn pthread_rwlock_destroy +function may fail if: +.Bl -tag -width Er +.It Bq Er EBUSY +The system has detected an attempt to destroy the object referenced by +.Fa lock +while it is locked. +.It Bq Er EINVAL +The value specified by +.Fa lock +is invalid. +.El +.Sh HISTORY +The +.Fn pthread_rwlock_destroy +function first appeared in +.Fx 3.0 . diff --git a/pthreads/pthread_rwlock_init.3 b/pthreads/pthread_rwlock_init.3 new file mode 100644 index 0000000..6a47d38 --- /dev/null +++ b/pthreads/pthread_rwlock_init.3 @@ -0,0 +1,99 @@ +.\" Copyright (c) 1998 Alex Nash +.\" 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_r/man/pthread_rwlock_init.3,v 1.5 2001/10/01 16:09:09 ru Exp $ +.\" +.Dd August 4, 1998 +.Dt PTHREAD_RWLOCK_INIT 3 +.Os +.Sh NAME +.Nm pthread_rwlock_init +.Nd initialize a read/write lock +.Sh SYNOPSIS +.In pthread.h +.Ft int +.Fn pthread_rwlock_init "pthread_rwlock_t *lock" "const pthread_rwlockattr_t *attr" +.Sh DESCRIPTION +The +.Fn pthread_rwlock_init +function is used to initialize a read/write lock, with attributes +specified by +.Fa attr . +If +.Fa attr +is NULL, the default read/write lock attributes are used. +.Pp +The results of calling +.Fn pthread_rwlock_init +with an already initialized lock are undefined. +.Sh RETURN VALUES +If successful, the +.Fn pthread_rwlock_init +function will return zero. Otherwise an error number will be returned +to indicate the error. +.Sh SEE ALSO +.Xr pthread_rwlockattr_init 3 , +.Xr pthread_rwlockattr_setpshared 3 , +.Xr pthread_rwlock_destroy 3 +.Sh STANDARDS +The +.Fn pthread_rwlock_init +function is expected to conform to +.St -susv2 . +.Sh ERRORS +The +.Fn pthread_rwlock_init +function will fail if: +.Bl -tag -width Er +.It Bq Er EAGAIN +The system lacked the necessary resources (other than memory) to +initialize the lock. +.It Bq Er ENOMEM +Insufficient memory exists to initialize the lock. +.It Bq Er EPERM +The caller does not have sufficient privilege to perform the +operation. +.El +.Pp +The +.Fn pthread_rwlock_init +function may fail if: +.Bl -tag -width Er +.It Bq Er EBUSY +The system has detected an attempt to re-initialize the object +referenced by +.Fa lock , +a previously initialized but not yet destroyed read/write lock. +.It Bq Er EINVAL +The value specified by +.Fa attr +is invalid. +.El +.Sh HISTORY +The +.Fn pthread_rwlock_init +function first appeared in +.Fx 3.0 . +.Sh BUGS +The PTHREAD_PROCESS_SHARED attribute is not supported. diff --git a/pthreads/pthread_rwlock_rdlock.3 b/pthreads/pthread_rwlock_rdlock.3 new file mode 100644 index 0000000..b703359 --- /dev/null +++ b/pthreads/pthread_rwlock_rdlock.3 @@ -0,0 +1,122 @@ +.\" Copyright (c) 1998 Alex Nash +.\" 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_r/man/pthread_rwlock_rdlock.3,v 1.4 2001/10/01 16:09:09 ru Exp $ +.\" +.Dd August 4, 1998 +.Dt PTHREAD_RWLOCK_RDLOCK 3 +.Os +.Sh NAME +.Nm pthread_rwlock_rdlock , +.Nm pthread_rwlock_tryrdlock +.Nd acquire a read/write lock for reading +.Sh SYNOPSIS +.In pthread.h +.Ft int +.Fn pthread_rwlock_rdlock "pthread_rwlock_t *lock" +.Ft int +.Fn pthread_rwlock_tryrdlock "pthread_rwlock_t *lock" +.Sh DESCRIPTION +The +.Fn pthread_rwlock_rdlock +function acquires a read lock on +.Fa lock +provided that +.Fa lock +is not presently held for writing and no writer threads are +presently blocked on the lock. If the read lock cannot be +immediately acquired, the calling thread blocks until it can +acquire the lock. +.Pp +The +.Fn pthread_rwlock_tryrdlock +function performs the same action, but does not block if the lock +cannot be immediately obtained (i.e. the lock is held for writing +or there are waiting writers). +.Pp +A thread may hold multiple concurrent read locks. If so, +.Fn pthread_rwlock_unlock +must be called once for each lock obtained. +.Pp +The results of acquiring a read lock while the calling thread holds +a write lock are undefined. +.Sh IMPLEMENTATION NOTES +To prevent writer starvation, writers are favored over readers. +.Sh RETURN VALUES +If successful, the +.Fn pthread_rwlock_rdlock +and +.Fn pthread_rwlock_tryrdlock +functions will return zero. Otherwise an error number will be returned +to indicate the error. +.Sh SEE ALSO +.Xr pthread_rwlock_init 3 , +.Xr pthread_rwlock_trywrlock 3 , +.Xr pthread_rwlock_unlock 3 , +.Xr pthread_rwlock_wrlock 3 +.Sh STANDARDS +The +.Fn pthread_rwlock_rdlock +and +.Fn pthread_rwlock_tryrdlock +functions are expected to conform to +.St -susv2 . +.Sh ERRORS +The +.Fn pthread_rwlock_tryrdlock +function will fail if: +.Bl -tag -width Er +.It Bq Er EBUSY +The lock could not be acquired because a writer holds the lock or +was blocked on it. +.El +.Pp +The +.Fn pthread_rwlock_rdlock +and +.Fn pthread_rwlock_tryrdlock +functions may fail if: +.Bl -tag -width Er +.It Bq Er EAGAIN +The lock could not be acquired because the maximum number of read locks +against +.Fa lock +has been exceeded. +.It Bq Er EDEADLK +The current thread already owns +.Fa lock +for writing. +.It Bq Er EINVAL +The value specified by +.Fa lock +is invalid. +.It Bq Er ENOMEM +Insufficient memory exists to initialize the lock (applies to +statically initialized locks only). +.El +.Sh HISTORY +The +.Fn pthread_rwlock_rdlock +function first appeared in +.Fx 3.0 . diff --git a/pthreads/pthread_rwlock_unlock.3 b/pthreads/pthread_rwlock_unlock.3 new file mode 100644 index 0000000..4384cec --- /dev/null +++ b/pthreads/pthread_rwlock_unlock.3 @@ -0,0 +1,79 @@ +.\" Copyright (c) 1998 Alex Nash +.\" 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_r/man/pthread_rwlock_unlock.3,v 1.4 2001/10/01 16:09:09 ru Exp $ +.\" +.Dd August 4, 1998 +.Dt PTHREAD_RWLOCK_UNLOCK 3 +.Os +.Sh NAME +.Nm pthread_rwlock_unlock +.Nd release a read/write lock +.Sh SYNOPSIS +.In pthread.h +.Ft int +.Fn pthread_rwlock_unlock "pthread_rwlock_t *lock" +.Sh DESCRIPTION +The +.Fn pthread_rwlock_unlock +function is used to release the read/write lock previously obtained by +.Fn pthread_rwlock_rdlock , +.Fn pthread_rwlock_wrlock , +.Fn pthread_rwlock_tryrdlock , +or +.Fn pthread_rwlock_trywrlock . +.Sh RETURN VALUES +If successful, the +.Fn pthread_rwlock_unlock +function will return zero. Otherwise an error number will be returned +to indicate the error. +.Pp +The results are undefined if +.Fa lock +is not held by the calling thread. +.Sh SEE ALSO +.Xr pthread_rwlock_rdlock 3 , +.Xr pthread_rwlock_wrlock 3 +.Sh STANDARDS +The +.Fn pthread_rwlock_unlock +function is expected to conform to +.St -susv2 . +.Sh ERRORS +The +.Fn pthread_rwlock_unlock +function may fail if: +.Bl -tag -width Er +.It Bq Er EINVAL +The value specified by +.Fa lock +is invalid. +.It Bq Er EPERM +The current thread does not own the read/write lock. +.El +.Sh HISTORY +The +.Fn pthread_rwlock_unlock +function first appeared in +.Fx 3.0 . diff --git a/pthreads/pthread_rwlock_wrlock.3 b/pthreads/pthread_rwlock_wrlock.3 new file mode 100644 index 0000000..f30df5a --- /dev/null +++ b/pthreads/pthread_rwlock_wrlock.3 @@ -0,0 +1,102 @@ +.\" Copyright (c) 1998 Alex Nash +.\" 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_r/man/pthread_rwlock_wrlock.3,v 1.4 2001/10/01 16:09:09 ru Exp $ +.\" +.Dd August 4, 1998 +.Dt PTHREAD_RWLOCK_WRLOCK 3 +.Os +.Sh NAME +.Nm pthread_rwlock_wrlock , +.Nm pthread_rwlock_trywrlock +.Nd acquire a read/write lock for writing +.Sh SYNOPSIS +.In pthread.h +.Ft int +.Fn pthread_rwlock_wrlock "pthread_rwlock_t *lock" +.Ft int +.Fn pthread_rwlock_trywrlock "pthread_rwlock_t *lock" +.Sh DESCRIPTION +The +.Fn pthread_rwlock_wrlock +function blocks until a write lock can be acquired against +.Fa lock . +The +.Fn pthread_rwlock_trywrlock +function performs the same action, but does not block if the lock +cannot be immediately obtained. +.Pp +The results are undefined if the calling thread already holds the +lock at the time the call is made. +.Sh IMPLEMENTATION NOTES +To prevent writer starvation, writers are favored over readers. +.Sh RETURN VALUES +If successful, the +.Fn pthread_rwlock_wrlock +and +.Fn pthread_rwlock_trywrlock +functions will return zero. Otherwise an error number will be returned +to indicate the error. +.Sh SEE ALSO +.Xr pthread_rwlock_trywrlock 3 , +.Xr pthread_rwlock_unlock 3 , +.Xr pthread_rwlock_wrlock 3 +.Sh STANDARDS +The +.Fn pthread_rwlock_wrlock +and +.Fn pthread_rwlock_trywrlock +functions are expected to conform to +.St -susv2 . +.Sh ERRORS +The +.Fn pthread_rwlock_trywrlock +function will fail if: +.Bl -tag -width Er +.It Bq Er EBUSY +The calling thread is not able to acquire the lock without blocking. +.El +.Pp +The +.Fn pthread_rwlock_wrlock +and +.Fn pthread_rwlock_trywrlock +functions may fail if: +.Bl -tag -width Er +.It Bq Er EDEADLK +The calling thread already owns the read/write lock (for reading +or writing). +.It Bq Er EINVAL +The value specified by +.Fa lock +is invalid. +.It Bq Er ENOMEM +Insufficient memory exists to initialize the lock (applies to +statically initialized locks only). +.El +.Sh HISTORY +The +.Fn pthread_rwlock_wrlock +function first appeared in +.Fx 3.0 . diff --git a/pthreads/pthread_rwlockattr_destroy.3 b/pthreads/pthread_rwlockattr_destroy.3 new file mode 100644 index 0000000..5a7a143 --- /dev/null +++ b/pthreads/pthread_rwlockattr_destroy.3 @@ -0,0 +1,68 @@ +.\" Copyright (c) 1998 Alex Nash +.\" 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_r/man/pthread_rwlockattr_destroy.3,v 1.6 2001/10/01 16:09:09 ru Exp $ +.\" +.Dd August 4, 1998 +.Dt PTHREAD_RWLOCKATTR_DESTROY 3 +.Os +.Sh NAME +.Nm pthread_rwlockattr_destroy +.Nd destroy a read/write lock +.Sh SYNOPSIS +.In pthread.h +.Ft int +.Fn pthread_rwlockattr_destroy "pthread_rwlockattr_t *attr" +.Sh DESCRIPTION +The +.Fn pthread_rwlockattr_destroy +function is used to destroy a read/write lock attribute object +previously created with +.Fn pthread_rwlockattr_init . +.Sh RETURN VALUES +If successful, the +.Fn pthread_rwlockattr_destroy +function will return zero. Otherwise an error number will be returned +to indicate the error. +.Sh SEE ALSO +.Xr pthread_rwlockattr_init 3 +.Sh STANDARDS +The +.Fn pthread_rwlockattr_destroy +function is expected to conform to +.St -susv2 . +.Sh ERRORS +.Fn pthread_rwlockattr_destroy +may fail if: +.Bl -tag -width Er +.It Bq Er EINVAL +The value specified by +.Fa attr +is invalid. +.El +.Sh HISTORY +The +.Fn pthread_rwlockattr_destroy +function first appeared in +.Fx 3.0 . diff --git a/pthreads/pthread_rwlockattr_getpshared.3 b/pthreads/pthread_rwlockattr_getpshared.3 new file mode 100644 index 0000000..a07c37b --- /dev/null +++ b/pthreads/pthread_rwlockattr_getpshared.3 @@ -0,0 +1,80 @@ +.\" Copyright (c) 1998 Alex Nash +.\" 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_r/man/pthread_rwlockattr_getpshared.3,v 1.8 2001/10/01 16:09:09 ru Exp $ +.\" +.Dd March 22, 1999 +.Dt PTHREAD_RWLOCKATTR_GETPSHARED 3 +.Os +.Sh NAME +.Nm pthread_rwlockattr_getpshared +.Nd get the process shared attribute +.Sh SYNOPSIS +.In pthread.h +.Ft int +.Fn pthread_rwlockattr_getpshared "const pthread_rwlockattr_t *attr" "int *pshared" +.Sh DESCRIPTION +The +.Fn pthread_rwlockattr_getpshared +function is used to get the process shared setting of a read/write +lock attribute object. The setting is returned via +.Fa pshared , +and may be one of two values: +.Bl -tag -width PTHREAD_PROCESS_PRIVATE +.It Dv PTHREAD_PROCESS_SHARED +Any thread of any process that has access to the memory where the +read/write lock resides can manipulate the lock. +.It Dv PTHREAD_PROCESS_PRIVATE +Only threads created within the same process as the thread that +initialized the read/write lock can manipulate the lock. This is +the default value. +.El +.Sh RETURN VALUES +If successful, the +.Fn pthread_rwlockattr_getpshared +function will return zero. Otherwise an error number will be returned +to indicate the error. +.Sh SEE ALSO +.Xr pthread_rwlockattr_init 3 , +.Xr pthread_rwlockattr_setpshared 3 , +.Xr pthread_rwlock_init 3 +.Sh STANDARDS +The +.Fn pthread_rwlockattr_getpshared +function is expected to conform to +.St -susv2 . +.Sh ERRORS +.Fn pthread_rwlockattr_getpshared +may fail if: +.Bl -tag -width Er +.It Bq Er EINVAL +The value specified by +.Fa attr +is invalid. +.El +.Sh HISTORY +The +.Fn pthread_rwlockattr_getpshared +function first appeared in +.Fx 3.0 . diff --git a/pthreads/pthread_rwlockattr_init.3 b/pthreads/pthread_rwlockattr_init.3 new file mode 100644 index 0000000..6d125e6 --- /dev/null +++ b/pthreads/pthread_rwlockattr_init.3 @@ -0,0 +1,67 @@ +.\" Copyright (c) 1998 Alex Nash +.\" 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_r/man/pthread_rwlockattr_init.3,v 1.6 2001/10/01 16:09:09 ru Exp $ +.\" +.Dd August 4, 1998 +.Dt PTHREAD_RWLOCKATTR_INIT 3 +.Os +.Sh NAME +.Nm pthread_rwlockattr_init +.Nd initialize a read/write lock +.Sh SYNOPSIS +.In pthread.h +.Ft int +.Fn pthread_rwlockattr_init "pthread_rwlockattr_t *attr" +.Sh DESCRIPTION +The +.Fn pthread_rwlockattr_init +function is used to initialize a read/write lock attributes object. +.Sh RETURN VALUES +If successful, the +.Fn pthread_rwlockattr_init +function will return zero. Otherwise an error number will be returned +to indicate the error. +.Sh SEE ALSO +.Xr pthread_rwlockattr_destroy 3 , +.Xr pthread_rwlockattr_getpshared 3 , +.Xr pthread_rwlockattr_setpshared 3 , +.Xr pthread_rwlock_init 3 +.Sh STANDARDS +The +.Fn pthread_rwlockattr_init +function is expected to conform to +.St -susv2 . +.Sh ERRORS +.Fn pthread_rwlockattr_init +will fail if: +.Bl -tag -width Er +.It Bq Er ENOMEM +Insufficient memory exists to initialize the attribute object. +.El +.Sh HISTORY +The +.Fn pthread_rwlockattr_init +function first appeared in +.Fx 3.0 . diff --git a/pthreads/pthread_rwlockattr_setpshared.3 b/pthreads/pthread_rwlockattr_setpshared.3 new file mode 100644 index 0000000..9824c63 --- /dev/null +++ b/pthreads/pthread_rwlockattr_setpshared.3 @@ -0,0 +1,88 @@ +.\" Copyright (c) 1998 Alex Nash +.\" 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_r/man/pthread_rwlockattr_setpshared.3,v 1.7 2001/10/01 16:09:09 ru Exp $ +.\" +.Dd August 4, 1998 +.Dt PTHREAD_RWLOCKATTR_SETPSHARED 3 +.Os +.Sh NAME +.Nm pthread_rwlockattr_setpshared +.Nd set the process shared attribute +.Sh SYNOPSIS +.In pthread.h +.Ft int +.Fn pthread_rwlockattr_setpshared "pthread_rwlockattr_t *attr" "int pshared" +.Sh DESCRIPTION +The +.Fn pthread_rwlockattr_setpshared +function sets the process shared attribute of +.Fa attr +to the value referenced by +.Fa pshared . +.Fa pshared +may be one of two values: +.Bl -tag -width PTHREAD_PROCESS_PRIVATE +.It Dv PTHREAD_PROCESS_SHARED +Any thread of any process that has access to the memory where the +read/write lock resides can manipulate the lock. +.It Dv PTHREAD_PROCESS_PRIVATE +Only threads created within the same process as the thread that +initialized the read/write lock can manipulate the lock. This is +the default value. +.El +.Sh RETURN VALUES +If successful, the +.Fn pthread_rwlockattr_setpshared +function will return zero. Otherwise an error number will be returned +to indicate the error. +.Sh SEE ALSO +.Xr pthread_rwlockattr_init 3 , +.Xr pthread_rwlockattr_setpshared 3 , +.Xr pthread_rwlock_init 3 +.Sh STANDARDS +The +.Fn pthread_rwlockattr_setpshared +function is expected to conform to +.St -susv2 . +.Sh ERRORS +.Fn pthread_rwlockattr_setpshared +will fail if: +.Bl -tag -width Er +.It Bq Er EINVAL +The value specified by +.Fa attr +or +.Fa pshared +is invalid. +.El +.Sh HISTORY +The +.Fn pthread_rwlockattr_setpshared +function first appeared in +.Fx 3.0 . +.Sh BUGS +The +.Dv PTHREAD_PROCESS_SHARED +attribute is not supported. diff --git a/pthreads/pthread_self.3 b/pthreads/pthread_self.3 new file mode 100644 index 0000000..d7c2bcd --- /dev/null +++ b/pthreads/pthread_self.3 @@ -0,0 +1,59 @@ +.\" Copyright (c) 1996 John Birrell . +.\" 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 John Birrell. +.\" 4. Neither the name of the author nor the names of any co-contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL 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. +.\" +.\" $FreeBSD: src/lib/libc_r/man/pthread_self.3,v 1.4.2.4 2001/08/17 15:42:52 ru Exp $ +.\" +.Dd April 4, 1996 +.Dt PTHREAD_SELF 3 +.Os +.Sh NAME +.Nm pthread_self +.Nd get the calling thread's ID +.Sh SYNOPSIS +.Fd #include +.Ft pthread_t +.Fn pthread_self "void" +.Sh DESCRIPTION +The +.Fn pthread_self +function returns the thread ID of the calling thread. +.Sh RETURN VALUES +The +.Fn pthread_self +function returns the thread ID of the calling thread. +.Sh ERRORS +None. +.Sh SEE ALSO +.Xr pthread_create 3 , +.Xr pthread_equal 3 +.Sh STANDARDS +.Fn pthread_self +conforms to +.St -p1003.1-96 . diff --git a/pthreads/pthread_setcancelstate.3 b/pthreads/pthread_setcancelstate.3 new file mode 100644 index 0000000..c68970c --- /dev/null +++ b/pthreads/pthread_setcancelstate.3 @@ -0,0 +1,199 @@ +.\" $FreeBSD: src/lib/libc_r/man/pthread_testcancel.3,v 1.2.2.3 2001/08/17 15:42:52 ru Exp $ +.Dd January 17, 1999 +.Dt PTHREAD_TESTCANCEL 3 +.Os +.Sh NAME +.Nm pthread_setcancelstate , +.Nm pthread_setcanceltype , +.Nm pthread_testcancel +.Nd set cancelability state +.Sh SYNOPSIS +.Fd #include +.Ft int +.Fn pthread_setcancelstate "int state" "int *oldstate" +.Ft int +.Fn pthread_setcanceltype "int type" "int *oldtype" +.Ft void +.Fn pthread_testcancel "void" +.Sh DESCRIPTION +The +.Fn pthread_setcancelstate +function atomically both sets the calling thread's cancelability state +to the indicated +.Fa state +and returns the previous cancelability state at the location referenced by +.Fa oldstate . +Legal values for +.Fa state +are +.Dv PTHREAD_CANCEL_ENABLE +and +.Dv PTHREAD_CANCEL_DISABLE . +.Pp +The +.Fn pthread_setcanceltype +function atomically both sets the calling thread's cancelability type +to the indicated +.Fa type +and returns the previous cancelability type at the location referenced by +.Fa oldtype . +Legal values for +.Fa type +are +.Dv PTHREAD_CANCEL_DEFERRED +and +.Dv PTHREAD_CANCEL_ASYNCHRONOUS . +.Pp +The cancelability state and type of any newly created threads, including the +thread in which +.Fn main +was first invoked, are +.Dv PTHREAD_CANCEL_ENABLE +and +.Dv PTHREAD_CANCEL_DEFERRED +respectively. +.Pp +The +.Fn pthread_testcancel +function creates a cancellation point in the calling thread. +The +.Fn pthread_testcancel +function has no effect if cancelability is disabled. +.Pp +.Ss Cancelability States +The cancelability state of a thread determines the action taken upon +receipt of a cancellation request. +The thread may control cancellation in +a number of ways. +.Pp +Each thread maintains its own +.Dq cancelability state +which may be encoded in two bits: +.Bl -hang +.It Em Cancelability Enable +When cancelability is +.Dv PTHREAD_CANCEL_DISABLE , +cancellation requests against the target thread are held pending. +.It Em Cancelability Type +When cancelability is enabled and the cancelability type is +.Dv PTHREAD_CANCEL_ASYNCHRONOUS , +new or pending cancellation requests may be acted upon at any time. +When cancelability is enabled and the cancelability type is +.Dv PTHREAD_CANCEL_DEFERRED , +cancellation requests are held pending until a cancellation point (see +below) is reached. +If cancelability is disabled, the setting of the +cancelability type has no immediate effect as all cancellation requests +are held pending; however, once cancelability is enabled again the new +type will be in effect. +.El +.Ss Cancellation Points +Cancellation points will occur when a thread is executing the following +functions: +.Fn close , +.Fn creat , +.Fn fcntl , +.Fn fsync , +.Fn msync , +.Fn nanosleep , +.Fn open , +.Fn pause , +.Fn pthread_cond_timedwait , +.Fn pthread_cond_wait , +.Fn pthread_join , +.Fn pthread_testcancel , +.Fn read , +.Fn sigwaitinfo , +.Fn sigsuspend , +.Fn sigwait , +.Fn sleep , +.Fn system , +.Fn tcdrain , +.Fn wait , +.Fn waitpid , +.Fn write . +.Sh RETURN VALUES +If successful, the +.Fn pthread_setcancelstate +and +.Fn pthread_setcanceltype +functions will return zero. +Otherwise, an error number shall be returned to +indicate the error. +.Pp +The +.Fn pthread_setcancelstate +and +.Fn pthread_setcanceltype +functions are used to control the points at which a thread may be +asynchronously canceled. +For cancellation control to be usable in modular +fashion, some rules must be followed. +.Pp +For purposes of this discussion, consider an object to be a generalization +of a procedure. +It is a set of procedures and global variables written as +a unit and called by clients not known by the object. +Objects may depend +on other objects. +.Pp +First, cancelability should only be disabled on entry to an object, never +explicitly enabled. +On exit from an object, the cancelability state should +always be restored to its value on entry to the object. +.Pp +This follows from a modularity argument: if the client of an object (or the +client of an object that uses that object) has disabled cancelability, it is +because the client doesn't want to have to worry about how to clean up if the +thread is canceled while executing some sequence of actions. +If an object +is called in such a state and it enables cancelability and a cancellation +request is pending for that thread, then the thread will be canceled, +contrary to the wish of the client that disabled. +.Pp +Second, the cancelability type may be explicitly set to either +.Em deferred +or +.Em asynchronous +upon entry to an object. +But as with the cancelability state, on exit from +an object that cancelability type should always be restored to its value on +entry to the object. +.Pp +Finally, only functions that are cancel-safe may be called from a thread that +is asynchronously cancelable. +.Sh ERRORS +The function +.Fn pthread_setcancelstate +may fail with: +.Bl -tag -width Er +.It Bq Er EINVAL +The specified state is not +.Dv PTHREAD_CANCEL_ENABLE +or +.Dv PTHREAD_CANCEL_DISABLE . +.El +.Pp +The function +.Fn pthread_setcanceltype +may fail with: +.Bl -tag -width Er +.It Bq Er EINVAL +The specified state is not +.Dv PTHREAD_CANCEL_DEFERRED +or +.Dv PTHREAD_CANCEL_ASYNCHRONOUS . +.El +.Sh SEE ALSO +.Xr pthread_cancel 3 +.Sh STANDARDS +.Fn pthread_testcancel +conforms to +.St -p1003.1-96 . +.Sh AUTHORS +This man page was written by +.An David Leonard Aq d@openbsd.org +for the +.Ox +implementation of +.Xr pthread_cancel 3 . diff --git a/pthreads/pthread_setspecific.3 b/pthreads/pthread_setspecific.3 new file mode 100644 index 0000000..f820eb8 --- /dev/null +++ b/pthreads/pthread_setspecific.3 @@ -0,0 +1,93 @@ +.\" Copyright (c) 1996 John Birrell . +.\" 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 John Birrell. +.\" 4. Neither the name of the author nor the names of any co-contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL 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. +.\" +.\" $FreeBSD: src/lib/libc_r/man/pthread_setspecific.3,v 1.6.2.4 2001/08/17 15:42:52 ru Exp $ +.\" +.Dd April 4, 1996 +.Dt PTHREAD_SETSPECIFIC 3 +.Os +.Sh NAME +.Nm pthread_setspecific +.Nd set a thread-specific data value +.Sh SYNOPSIS +.Fd #include +.Ft int +.Fn pthread_setspecific "pthread_key_t key" "const void *value" +.Sh DESCRIPTION +The +.Fn pthread_setspecific +function associates a thread-specific value with a +.Fa key +obtained via a previous call to +.Fn pthread_key_create . +Different threads man bind different values to the same key. +These values are +typically pointers to blocks of dynamically allocated memory that have been +reserved for use by the calling thread. +.Pp +The effect of calling +.Fn pthread_setspecific +with a key value not obtained from +.Fn pthread_key_create +or after +.Fa key +has been deleted with +.Fn pthread_key_delete +is undefined. +.Pp +.Fn pthread_setspecific +may be called from a thread-specific data destructor function, however this +may result in lost storage or infinite loops. +.Sh RETURN VALUES +If successful, the +.Fn pthread_setspecific +function will return zero. +Otherwise an error number will be returned to +indicate the error. +.Sh ERRORS +.Fn pthread_setspecific +will fail if: +.Bl -tag -width Er +.It Bq Er ENOMEM +Insufficient memory exists to associate the value with the +.Fa key . +.It Bq Er EINVAL +The +.Fa key +value is invalid. +.El +.Sh SEE ALSO +.Xr pthread_getspecific 3 , +.Xr pthread_key_create 3 , +.Xr pthread_key_delete 3 +.Sh STANDARDS +.Fn pthread_setspecific +conforms to +.St -p1003.1-96 . diff --git a/pthreads/pthread_tsd.c b/pthreads/pthread_tsd.c new file mode 100644 index 0000000..f8cfb6b --- /dev/null +++ b/pthreads/pthread_tsd.c @@ -0,0 +1,167 @@ +/* + * Copyright 1996 1995 by Open Software Foundation, Inc. 1997 1996 1995 1994 1993 1992 1991 + * 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 appears in all copies and + * that both the copyright notice and this permission notice appear in + * supporting documentation. + * + * OSF DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE. + * + * IN NO EVENT SHALL OSF BE LIABLE FOR ANY SPECIAL, INDIRECT, OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM + * LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT, + * NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION + * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + */ +/* + * MkLinux + */ + +/* + * POSIX Pthread Library + * Thread Specific Data support + */ + +#include "pthread_internals.h" + +static struct +{ + int created; /* Set TRUE if 'create_key' used this slot */ + void (*destructor)(void *); +} _pthread_keys[_POSIX_THREAD_KEYS_MAX]; +static pthread_lock_t tds_lock = LOCK_INITIALIZER; + +/* + * Create a new key for thread specific data + */ +int +pthread_key_create(pthread_key_t *key, + void (*destructor)(void *)) +{ + int res, i; + LOCK(tds_lock); + res = ENOMEM; /* No 'free' keys */ + for (i = 0; i < _POSIX_THREAD_KEYS_MAX; i++) + { + if (_pthread_keys[i].created == FALSE) + { + _pthread_keys[i].created = TRUE; + _pthread_keys[i].destructor = destructor; + *key = i+1; + res = ESUCCESS; + break; + } + } + UNLOCK(tds_lock); + return (res); +} + +/* + * Destroy a thread specific data key + */ +int +pthread_key_delete(pthread_key_t key) +{ + int res; + LOCK(tds_lock); + if ((key >= 1) && (key <= _POSIX_THREAD_KEYS_MAX)) + { + if (_pthread_keys[key-1].created) + { + _pthread_keys[key-1].created = FALSE; + res = ESUCCESS; + } else + { + res = EINVAL; + } + } else + { /* Invalid key */ + res = EINVAL; + } + UNLOCK(tds_lock); + return (res); +} + +/* + * Set the thread private value for a given key. + * We do not take the spinlock for this or pthread_getspecific. + * The assignment to self->tsd[] is thread-safe because we never + * refer to the tsd[] of a thread other than pthread_self(). + * The reference to _pthread_keys[...].created could race with a + * pthread_key_delete() but in this case the behaviour is allowed + * to be undefined. + */ +int +pthread_setspecific(pthread_key_t key, + const void *value) +{ + int res; + pthread_t self; + if ((key >= 1) && (key <= _POSIX_THREAD_KEYS_MAX)) + { + if (_pthread_keys[key-1].created) + { + self = pthread_self(); + self->tsd[key-1] = (void *) value; + res = ESUCCESS; + } else + { + res = EINVAL; + } + } else + { /* Invalid key */ + res = EINVAL; + } + return (res); +} + +/* + * Fetch the thread private value for a given key. + * This is potentially a very heavily-used operation so we do only + * a minimum of checks. + */ +void * +pthread_getspecific(pthread_key_t key) +{ + pthread_t self; + void *res; + if ((key >= 1) && (key <= _POSIX_THREAD_KEYS_MAX)) + { + self = pthread_self(); + res = self->tsd[key-1]; + } else + { /* Invalid key - no error, just NULL */ + res = (void *)NULL; + } + return (res); +} + +/* + * Clean up thread specific data as thread 'dies' + */ +void +_pthread_tsd_cleanup(pthread_t self) +{ + int i, j; + void *param; + for (j = 0; j < PTHREAD_DESTRUCTOR_ITERATIONS; j++) + { + for (i = 0; i < _POSIX_THREAD_KEYS_MAX; i++) + { + if (_pthread_keys[i].created && (param = self->tsd[i])) + { + self->tsd[i] = (void *)NULL; + if (_pthread_keys[i].destructor) + { + (_pthread_keys[i].destructor)(param); + } + } + } + } +} diff --git a/pthreads/sched.h b/pthreads/sched.h new file mode 100644 index 0000000..d67a482 --- /dev/null +++ b/pthreads/sched.h @@ -0,0 +1,17 @@ +#ifndef _SCHED_H_ +#define _SCHED_H_ + +#include + +/* + * Scheduling paramters + */ +#ifndef __POSIX_LIB__ +struct sched_param { int sched_priority; char opaque[__SCHED_PARAM_SIZE__]; }; +#endif + +extern int sched_yield(void); +extern int sched_get_priority_min(int); +extern int sched_get_priority_max(int); +#endif /* _SCHED_H_ */ + diff --git a/pthreads/stack.s b/pthreads/stack.s new file mode 100644 index 0000000..7548bbf --- /dev/null +++ b/pthreads/stack.s @@ -0,0 +1,69 @@ +/* + * Copyright 1996 1995 by Open Software Foundation, Inc. 1997 1996 1995 1994 1993 1992 1991 + * 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 appears in all copies and + * that both the copyright notice and this permission notice appear in + * supporting documentation. + * + * OSF DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE. + * + * IN NO EVENT SHALL OSF BE LIABLE FOR ANY SPECIAL, INDIRECT, OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM + * LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT, + * NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION + * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + */ +/* + * MkLinux + */ + +.text + +#if defined(__ppc__) +#import +#import + +/* + * void *_sp(void) + */ + +LEAF(__sp) + mr r3,r1 + blr + +/* + * void *_adjust_sp(void *sp) + */ +LEAF(__adjust_sp) + subi r3,r3,0x100 /* Stack frame padding */ + blr + +#elif defined(__i386__) + +#import +/* + * void *_sp(void) + */ + +LEAF(__sp,0) + movl %esp,%eax + ret + +/* + * void *_adjust_sp(void *sp) + */ +LEAF(__adjust_sp,0) + movl 4(%esp),%eax + subl $0x100,%eax + ret + +#else +#error sp functions not defined for this architecture +#endif + diff --git a/pthreads/thread_setup.c b/pthreads/thread_setup.c new file mode 100644 index 0000000..28c08f5 --- /dev/null +++ b/pthreads/thread_setup.c @@ -0,0 +1,125 @@ +/* + * Copyright 1996 1995 by Open Software Foundation, Inc. 1997 1996 1995 1994 1993 1992 1991 + * 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 appears in all copies and + * that both the copyright notice and this permission notice appear in + * supporting documentation. + * + * OSF DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE. + * + * IN NO EVENT SHALL OSF BE LIABLE FOR ANY SPECIAL, INDIRECT, OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM + * LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT, + * NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION + * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + */ +/* + * MkLinux + */ + +/* + * Machine specific support for thread initialization + */ + +#if defined(__ppc__) +#include +#endif + +#include "pthread_internals.h" + +/* + * Set up the initial state of a MACH thread + */ +void +_pthread_setup(pthread_t thread, + void (*routine)(pthread_t), + void *vsp, int suspended, + int needresume) +{ + kern_return_t r; + unsigned int count; +#if defined(__ppc__) + struct ppc_thread_state state = {0}; + struct ppc_thread_state *ts = &state; + + /* + * Set up PowerPC registers. + */ + count = PPC_THREAD_STATE_COUNT; + if (suspended) { + PTHREAD_MACH_CALL(thread_get_state(thread->kernel_thread, + PPC_THREAD_STATE, + (thread_state_t) &state, + &count), + r); + } + ts->srr0 = (int) routine; + ts->r1 = (uintptr_t)vsp - C_ARGSAVE_LEN - C_RED_ZONE; + ts->r3 = (int)thread; + /* Incase of needresume, suspend is always set */ + if (suspended) { + PTHREAD_MACH_CALL(thread_set_state(thread->kernel_thread, + PPC_THREAD_STATE, + (thread_state_t) &state, + PPC_THREAD_STATE_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, + (thread_state_t) ts, + PPC_THREAD_STATE_COUNT, + &thread->kernel_thread), + r); + } +#elif defined(__i386__) + i386_thread_state_t state = {0}; + i386_thread_state_t *ts = &state; + int *sp = vsp; + + /* + * Set up i386 registers & function call. + */ + count = i386_THREAD_STATE_COUNT; + if (suspended) { + PTHREAD_MACH_CALL(thread_get_state(thread->kernel_thread, + i386_THREAD_STATE, + (thread_state_t) &state, + &count), + r); + } + ts->eip = (int) routine; + *--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, + i386_THREAD_STATE, + (thread_state_t) &state, + i386_THREAD_STATE_COUNT), + r); + if (needresume) + PTHREAD_MACH_CALL(thread_resume(thread->kernel_thread), + r); + } else { + PTHREAD_MACH_CALL(thread_create_running(mach_task_self(), + i386_THREAD_STATE, + (thread_state_t) ts, + i386_THREAD_STATE_COUNT, + &thread->kernel_thread), + r); + } + +#else +#error _pthread_setup not defined for this architecture +#endif +} diff --git a/quad/Makefile.inc b/quad/Makefile.inc new file mode 100644 index 0000000..679f6cc --- /dev/null +++ b/quad/Makefile.inc @@ -0,0 +1,19 @@ +# from @(#)Makefile.inc 8.1 (Berkeley) 6/4/93 +# $FreeBSD: src/lib/libc/quad/Makefile.inc,v 1.8 1999/08/28 00:00:27 peter Exp $ + +# Quad support, if needed +.PATH: ${.CURDIR}/../libc/${MACHINE_ARCH}/quad ${.CURDIR}/../libc/quad + +.if ${MACHINE_ARCH} == "i386" + +SRCS+= cmpdi2.c divdi3.c moddi3.c qdivrem.c ucmpdi2.c udivdi3.c umoddi3.c + +.else + +SRCS+= adddi3.c anddi3.c ashldi3.c ashrdi3.c cmpdi2.c divdi3.c fixdfdi.c \ + fixsfdi.c fixunsdfdi.c fixunssfdi.c floatdidf.c floatdisf.c \ + floatunsdidf.c iordi3.c lshldi3.c lshrdi3.c moddi3.c muldi3.c \ + negdi2.c notdi2.c qdivrem.c subdi3.c ucmpdi2.c udivdi3.c umoddi3.c \ + xordi3.c + +.endif diff --git a/regex.subproj/Makefile b/regex.subproj/Makefile deleted file mode 100644 index df9cdf6..0000000 --- a/regex.subproj/Makefile +++ /dev/null @@ -1,47 +0,0 @@ -# -# Generated by the NeXT Project Builder. -# -# NOTE: Do NOT change this file -- Project Builder maintains it. -# -# Put all of your customizations in files called Makefile.preamble -# and Makefile.postamble (both optional), and Makefile will include them. -# - -NAME = regex - -PROJECTVERSION = 2.8 -PROJECT_TYPE = Component - -HFILES = cclass.h cname.h regex2.h utils.h - -CFILES = regcomp.c regerror.c regexec.c regfree.c - -OTHERSRCS = Makefile.preamble Makefile Makefile.postamble engine.c - - -MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles -CODE_GEN_STYLE = DYNAMIC -MAKEFILE = subproj.make -LIBS = -DEBUG_LIBS = $(LIBS) -PROF_LIBS = $(LIBS) - - - - -NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc -WINDOWS_OBJCPLUS_COMPILER = $(DEVDIR)/gcc -PDO_UNIX_OBJCPLUS_COMPILER = $(NEXTDEV_BIN)/gcc -NEXTSTEP_JAVA_COMPILER = /usr/bin/javac -WINDOWS_JAVA_COMPILER = $(JDKBINDIR)/javac.exe -PDO_UNIX_JAVA_COMPILER = $(JDKBINDIR)/javac - -include $(MAKEFILEDIR)/platform.make - --include Makefile.preamble - -include $(MAKEFILEDIR)/$(MAKEFILE) - --include Makefile.postamble - --include Makefile.dependencies diff --git a/regex.subproj/Makefile.postamble b/regex.subproj/Makefile.postamble deleted file mode 100644 index 411cde6..0000000 --- a/regex.subproj/Makefile.postamble +++ /dev/null @@ -1,100 +0,0 @@ -############################################################################### -# Makefile.postamble -# Copyright 1997, Apple Computer, Inc. -# -# Use this makefile, which is imported after all other makefiles, to -# override attributes for a project's Makefile environment. This allows you -# to take advantage of the environment set up by the other Makefiles. -# You can also define custom rules at the end of this file. -# -############################################################################### -# -# These variables are exported by the standard makefiles and can be -# used in any customizations you make. They are *outputs* of -# the Makefiles and should be used, not set. -# -# PRODUCTS: products to install. All of these products will be placed in -# the directory $(DSTROOT)$(INSTALLDIR) -# GLOBAL_RESOURCE_DIR: The directory to which resources are copied. -# LOCAL_RESOURCE_DIR: The directory to which localized resources are copied. -# OFILE_DIR: Directory into which .o object files are generated. -# DERIVED_SRC_DIR: Directory used for all other derived files -# -# ALL_CFLAGS: flags to pass when compiling .c files -# ALL_MFLAGS: flags to pass when compiling .m files -# ALL_CCFLAGS: flags to pass when compiling .cc, .cxx, and .C files -# ALL_MMFLAGS: flags to pass when compiling .mm, .mxx, and .M files -# ALL_PRECOMPFLAGS: flags to pass when precompiling .h files -# ALL_LDFLAGS: flags to pass when linking object files -# ALL_LIBTOOL_FLAGS: flags to pass when libtooling object files -# ALL_PSWFLAGS: flags to pass when processing .psw and .pswm (pswrap) files -# ALL_RPCFLAGS: flags to pass when processing .rpc (rpcgen) files -# ALL_YFLAGS: flags to pass when processing .y (yacc) files -# ALL_LFLAGS: flags to pass when processing .l (lex) files -# -# NAME: name of application, bundle, subproject, palette, etc. -# LANGUAGES: langages in which the project is written (default "English") -# English_RESOURCES: localized resources (e.g. nib's, images) of project -# GLOBAL_RESOURCES: non-localized resources of project -# -# SRCROOT: base directory in which to place the new source files -# SRCPATH: relative path from SRCROOT to present subdirectory -# -# INSTALLDIR: Directory the product will be installed into by 'install' target -# PUBLIC_HDR_INSTALLDIR: where to install public headers. Don't forget -# to prefix this with DSTROOT when you use it. -# PRIVATE_HDR_INSTALLDIR: where to install private headers. Don't forget -# to prefix this with DSTROOT when you use it. -# -# EXECUTABLE_EXT: Executable extension for the platform (i.e. .exe on Windows) -# -############################################################################### - -# Some compiler flags can be overridden here for certain build situations. -# -# WARNING_CFLAGS: flag used to set warning level (defaults to -Wmost) -# DEBUG_SYMBOLS_CFLAGS: debug-symbol flag passed to all builds (defaults -# to -g) -# DEBUG_BUILD_CFLAGS: flags passed during debug builds (defaults to -DDEBUG) -# OPTIMIZE_BUILD_CFLAGS: flags passed during optimized builds (defaults -# to -O) -# PROFILE_BUILD_CFLAGS: flags passed during profile builds (defaults -# to -pg -DPROFILE) -# LOCAL_DIR_INCLUDE_DIRECTIVE: flag used to add current directory to -# the include path (defaults to -I.) -# DEBUG_BUILD_LDFLAGS, OPTIMIZE_BUILD_LDFLAGS, PROFILE_BUILD_LDFLAGS: flags -# passed to ld/libtool (defaults to nothing) - - -# Library and Framework projects only: -# INSTALL_NAME_DIRECTIVE: This directive ensures that executables linked -# against the framework will run against the correct version even if -# the current version of the framework changes. You may override this -# to "" as an alternative to using the DYLD_LIBRARY_PATH during your -# development cycle, but be sure to restore it before installing. - - -# Ownership and permissions of files installed by 'install' target - -#INSTALL_AS_USER = root - # User/group ownership -#INSTALL_AS_GROUP = wheel - # (probably want to set both of these) -#INSTALL_PERMISSIONS = - # If set, 'install' chmod's executable to this - - -# Options to strip. Note: -S strips debugging symbols (executables can be stripped -# down further with -x or, if they load no bundles, with no options at all). - -#STRIPFLAGS = -S - - -######################################################################### -# Put rules to extend the behavior of the standard Makefiles here. Include them in -# the dependency tree via cvariables like AFTER_INSTALL in the Makefile.preamble. -# -# You should avoid redefining things like "install" or "app", as they are -# owned by the top-level Makefile API and no context has been set up for where -# derived files should go. -# diff --git a/regex.subproj/Makefile.preamble b/regex.subproj/Makefile.preamble deleted file mode 100644 index c1624b4..0000000 --- a/regex.subproj/Makefile.preamble +++ /dev/null @@ -1,137 +0,0 @@ -############################################################################### -# Makefile.preamble -# Copyright 1997, Apple Computer, Inc. -# -# Use this makefile for configuring the standard application makefiles -# associated with ProjectBuilder. It is included before the main makefile. -# In Makefile.preamble you set attributes for a project, so they are available -# to the project's makefiles. In contrast, you typically write additional rules or -# override built-in behavior in the Makefile.postamble. -# -# Each directory in a project tree (main project plus subprojects) should -# have its own Makefile.preamble and Makefile.postamble. -############################################################################### -# -# Before the main makefile is included for this project, you may set: -# -# MAKEFILEDIR: Directory in which to find $(MAKEFILE) -# MAKEFILE: Top level mechanism Makefile (e.g., app.make, bundle.make) - -# Compiler/linker flags added to the defaults: The OTHER_* variables will be -# inherited by all nested sub-projects, but the LOCAL_ versions of the same -# variables will not. Put your -I, -D, -U, and -L flags in ProjectBuilder's -# Build Attributes inspector if at all possible. To override the default flags -# that get passed to ${CC} (e.g. change -O to -O2), see Makefile.postamble. The -# variables below are *inputs* to the build process and distinct from the override -# settings done (less often) in the Makefile.postamble. -# -# OTHER_CFLAGS, LOCAL_CFLAGS: additional flags to pass to the compiler -# Note that $(OTHER_CFLAGS) and $(LOCAL_CFLAGS) are used for .h, ...c, .m, -# .cc, .cxx, .C, and .M files. There is no need to respecify the -# flags in OTHER_MFLAGS, etc. -# OTHER_MFLAGS, LOCAL_MFLAGS: additional flags for .m files -# OTHER_CCFLAGS, LOCAL_CCFLAGS: additional flags for .cc, .cxx, and ...C files -# OTHER_MMFLAGS, LOCAL_MMFLAGS: additional flags for .mm and .M files -# OTHER_PRECOMPFLAGS, LOCAL_PRECOMPFLAGS: additional flags used when -# precompiling header files -# OTHER_LDFLAGS, LOCAL_LDFLAGS: additional flags passed to ld and libtool -# OTHER_PSWFLAGS, LOCAL_PSWFLAGS: additional flags passed to pswrap -# OTHER_RPCFLAGS, LOCAL_RPCFLAGS: additional flags passed to rpcgen -# OTHER_YFLAGS, LOCAL_YFLAGS: additional flags passed to yacc -# OTHER_LFLAGS, LOCAL_LFLAGS: additional flags passed to lex - -# These variables provide hooks enabling you to add behavior at almost every -# stage of the make: -# -# BEFORE_PREBUILD: targets to build before installing headers for a subproject -# AFTER_PREBUILD: targets to build after installing headers for a subproject -# BEFORE_BUILD_RECURSION: targets to make before building subprojects -# BEFORE_BUILD: targets to make before a build, but after subprojects -# AFTER_BUILD: targets to make after a build -# -# BEFORE_INSTALL: targets to build before installing the product -# AFTER_INSTALL: targets to build after installing the product -# BEFORE_POSTINSTALL: targets to build before postinstalling every subproject -# AFTER_POSTINSTALL: targts to build after postinstalling every subproject -# -# BEFORE_INSTALLHDRS: targets to build before installing headers for a -# subproject -# AFTER_INSTALLHDRS: targets to build after installing headers for a subproject -# BEFORE_INSTALLSRC: targets to build before installing source for a subproject -# AFTER_INSTALLSRC: targets to build after installing source for a subproject -# -# BEFORE_DEPEND: targets to build before building dependencies for a -# subproject -# AFTER_DEPEND: targets to build after building dependencies for a -# subproject -# -# AUTOMATIC_DEPENDENCY_INFO: if YES, then the dependency file is -# updated every time the project is built. If NO, the dependency -# file is only built when the depend target is invoked. - -# Framework-related variables: -# FRAMEWORK_DLL_INSTALLDIR: On Windows platforms, this variable indicates -# where to put the framework's DLL. This variable defaults to -# $(INSTALLDIR)/../Executables - -# Library-related variables: -# PUBLIC_HEADER_DIR: Determines where public exported header files -# should be installed. Do not include $(DSTROOT) in this value -- -# it is prefixed automatically. For library projects you should -# set this to something like /Developer/Headers/$(NAME). Do not set -# this variable for framework projects unless you do not want the -# header files included in the framework. -# PRIVATE_HEADER_DIR: Determines where private exported header files -# should be installed. Do not include $(DSTROOT) in this value -- -# it is prefixed automatically. -# LIBRARY_STYLE: This may be either STATIC or DYNAMIC, and determines -# whether the libraries produced are statically linked when they -# are used or if they are dynamically loadable. This defaults to -# DYNAMIC. -# LIBRARY_DLL_INSTALLDIR: On Windows platforms, this variable indicates -# where to put the library's DLL. This variable defaults to -# $(INSTALLDIR)/../Executables -# -# INSTALL_AS_USER: owner of the intalled products (default root) -# INSTALL_AS_GROUP: group of the installed products (default wheel) -# INSTALL_PERMISSIONS: permissions of the installed product (default o+rX) -# -# OTHER_RECURSIVE_VARIABLES: The names of variables which you want to be -# passed on the command line to recursive invocations of make. Note that -# the values in OTHER_*FLAGS are inherited by subprojects automatically -- -# you do not have to (and shouldn't) add OTHER_*FLAGS to -# OTHER_RECURSIVE_VARIABLES. - -# Additional headers to export beyond those in the PB.project: -# OTHER_PUBLIC_HEADERS -# OTHER_PROJECT_HEADERS -# OTHER_PRIVATE_HEADERS - -# Additional files for the project's product: <> -# OTHER_RESOURCES: (non-localized) resources for this project -# OTHER_OFILES: relocatables to be linked into this project -# OTHER_LIBS: more libraries to link against -# OTHER_PRODUCT_DEPENDS: other dependencies of this project -# OTHER_SOURCEFILES: other source files maintained by .pre/postamble -# OTHER_GARBAGE: additional files to be removed by `make clean' - -# Set this to YES if you don't want a final libtool call for a library/framework. -# BUILD_OFILES_LIST_ONLY - -# To include a version string, project source must exist in a directory named -# $(NAME).%d[.%d][.%d] and the following line must be uncommented. -# OTHER_GENERATED_OFILES = $(VERS_OFILE) - -# This definition will suppress stripping of debug symbols when an executable -# is installed. By default it is YES. -# STRIP_ON_INSTALL = NO - -# Uncomment to suppress generation of a KeyValueCoding index when installing -# frameworks (This index is used by WOB and IB to determine keys available -# for an object). Set to YES by default. -# PREINDEX_FRAMEWORK = NO - -# Change this definition to install projects somewhere other than the -# standard locations. NEXT_ROOT defaults to "C:/Apple" on Windows systems -# and "" on other systems. -DSTROOT = $(HOME) diff --git a/regex.subproj/PB.project b/regex.subproj/PB.project deleted file mode 100644 index 2ef71b3..0000000 --- a/regex.subproj/PB.project +++ /dev/null @@ -1,23 +0,0 @@ -{ - DYNAMIC_CODE_GEN = YES; - FILESTABLE = { - H_FILES = (cclass.h, cname.h, regex2.h, utils.h); - OTHER_LINKED = (regcomp.c, regerror.c, regexec.c, regfree.c); - OTHER_SOURCES = (Makefile.preamble, Makefile, Makefile.postamble, engine.c); - SUBPROJECTS = (); - }; - LANGUAGE = English; - MAKEFILEDIR = "$(MAKEFILEPATH)/pb_makefiles"; - NEXTSTEP_BUILDTOOL = /bin/gnumake; - NEXTSTEP_JAVA_COMPILER = /usr/bin/javac; - NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc; - PDO_UNIX_BUILDTOOL = $NEXT_ROOT/Developer/bin/make; - PDO_UNIX_JAVA_COMPILER = "$(JDKBINDIR)/javac"; - PDO_UNIX_OBJCPLUS_COMPILER = "$(NEXTDEV_BIN)/gcc"; - PROJECTNAME = regex; - PROJECTTYPE = Component; - PROJECTVERSION = 2.8; - WINDOWS_BUILDTOOL = $NEXT_ROOT/Developer/Executables/make; - WINDOWS_JAVA_COMPILER = "$(JDKBINDIR)/javac.exe"; - WINDOWS_OBJCPLUS_COMPILER = "$(DEVDIR)/gcc"; -} diff --git a/regex.subproj/cclass.h b/regex.subproj/cclass.h deleted file mode 100644 index 028b6ed..0000000 --- a/regex.subproj/cclass.h +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1992, 1993, 1994 - * 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. - */ - -/* character-class table */ -static struct cclass { - char *name; - char *chars; - char *multis; -} cclasses[] = { - "alnum", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\ -0123456789", "", - "alpha", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", - "", - "blank", " \t", "", - "cntrl", "\007\b\t\n\v\f\r\1\2\3\4\5\6\16\17\20\21\22\23\24\ -\25\26\27\30\31\32\33\34\35\36\37\177", "", - "digit", "0123456789", "", - "graph", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\ -0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~", - "", - "lower", "abcdefghijklmnopqrstuvwxyz", - "", - "print", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\ -0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ ", - "", - "punct", "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~", - "", - "space", "\t\n\v\f\r ", "", - "upper", "ABCDEFGHIJKLMNOPQRSTUVWXYZ", - "", - "xdigit", "0123456789ABCDEFabcdef", - "", - NULL, 0, "" -}; diff --git a/regex.subproj/cname.h b/regex.subproj/cname.h deleted file mode 100644 index 1abcd7c..0000000 --- a/regex.subproj/cname.h +++ /dev/null @@ -1,159 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1992, 1993, 1994 - * 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. - */ - -/* character-name table */ -static const struct cname { - char *name; - char code; -} cnames[] = { - "NUL", '\0', - "SOH", '\001', - "STX", '\002', - "ETX", '\003', - "EOT", '\004', - "ENQ", '\005', - "ACK", '\006', - "BEL", '\007', - "alert", '\007', - "BS", '\010', - "backspace", '\b', - "HT", '\011', - "tab", '\t', - "LF", '\012', - "newline", '\n', - "VT", '\013', - "vertical-tab", '\v', - "FF", '\014', - "form-feed", '\f', - "CR", '\015', - "carriage-return", '\r', - "SO", '\016', - "SI", '\017', - "DLE", '\020', - "DC1", '\021', - "DC2", '\022', - "DC3", '\023', - "DC4", '\024', - "NAK", '\025', - "SYN", '\026', - "ETB", '\027', - "CAN", '\030', - "EM", '\031', - "SUB", '\032', - "ESC", '\033', - "IS4", '\034', - "FS", '\034', - "IS3", '\035', - "GS", '\035', - "IS2", '\036', - "RS", '\036', - "IS1", '\037', - "US", '\037', - "space", ' ', - "exclamation-mark", '!', - "quotation-mark", '"', - "number-sign", '#', - "dollar-sign", '$', - "percent-sign", '%', - "ampersand", '&', - "apostrophe", '\'', - "left-parenthesis", '(', - "right-parenthesis", ')', - "asterisk", '*', - "plus-sign", '+', - "comma", ',', - "hyphen", '-', - "hyphen-minus", '-', - "period", '.', - "full-stop", '.', - "slash", '/', - "solidus", '/', - "zero", '0', - "one", '1', - "two", '2', - "three", '3', - "four", '4', - "five", '5', - "six", '6', - "seven", '7', - "eight", '8', - "nine", '9', - "colon", ':', - "semicolon", ';', - "less-than-sign", '<', - "equals-sign", '=', - "greater-than-sign", '>', - "question-mark", '?', - "commercial-at", '@', - "left-square-bracket", '[', - "backslash", '\\', - "reverse-solidus", '\\', - "right-square-bracket", ']', - "circumflex", '^', - "circumflex-accent", '^', - "underscore", '_', - "low-line", '_', - "grave-accent", '`', - "left-brace", '{', - "left-curly-bracket", '{', - "vertical-line", '|', - "right-brace", '}', - "right-curly-bracket", '}', - "tilde", '~', - "DEL", '\177', - NULL, 0, -}; diff --git a/regex.subproj/engine.c b/regex.subproj/engine.c deleted file mode 100644 index 3f7856a..0000000 --- a/regex.subproj/engine.c +++ /dev/null @@ -1,1109 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1992, 1993, 1994 - * 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. - */ - -/* - * The matching engine and friends. This file is #included by regexec.c - * after suitable #defines of a variety of macros used herein, so that - * different state representations can be used without duplicating masses - * of code. - */ - -#ifdef SNAMES -#define matcher smatcher -#define fast sfast -#define slow sslow -#define dissect sdissect -#define backref sbackref -#define step sstep -#define print sprint -#define at sat -#define match smat -#endif -#ifdef LNAMES -#define matcher lmatcher -#define fast lfast -#define slow lslow -#define dissect ldissect -#define backref lbackref -#define step lstep -#define print lprint -#define at lat -#define match lmat -#endif - -/* another structure passed up and down to avoid zillions of parameters */ -struct match { - struct re_guts *g; - int eflags; - regmatch_t *pmatch; /* [nsub+1] (0 element unused) */ - char *offp; /* offsets work from here */ - char *beginp; /* start of string -- virtual NUL precedes */ - char *endp; /* end of string -- virtual NUL here */ - char *coldp; /* can be no match starting before here */ - char **lastpos; /* [nplus+1] */ - STATEVARS; - states st; /* current states */ - states fresh; /* states for a fresh start */ - states tmp; /* temporary */ - states empty; /* empty set of states */ -}; - -/* ========= begin header generated by ./mkh ========= */ -#ifdef __cplusplus -extern "C" { -#endif - -/* === engine.c === */ -static int matcher __P((struct re_guts *g, char *string, size_t nmatch, regmatch_t pmatch[], int eflags)); -static char *dissect __P((struct match *m, char *start, char *stop, sopno startst, sopno stopst)); -static char *backref __P((struct match *m, char *start, char *stop, sopno startst, sopno stopst, sopno lev)); -static char *fast __P((struct match *m, char *start, char *stop, sopno startst, sopno stopst)); -static char *slow __P((struct match *m, char *start, char *stop, sopno startst, sopno stopst)); -static states step __P((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) -#ifdef REDEBUG -static void print __P((struct match *m, char *caption, states st, int ch, FILE *d)); -#endif -#ifdef REDEBUG -static void at __P((struct match *m, char *title, char *start, char *stop, sopno startst, sopno stopst)); -#endif -#ifdef REDEBUG -static char *pchar __P((int ch)); -#endif - -#ifdef __cplusplus -} -#endif -/* ========= end header generated by ./mkh ========= */ - -#ifdef REDEBUG -#define SP(t, s, c) print(m, t, s, c, stdout) -#define AT(t, p1, p2, s1, s2) at(m, t, p1, p2, s1, s2) -#define NOTE(str) { if (m->eflags®_TRACE) printf("=%s\n", (str)); } -#else -#define SP(t, s, c) /* nothing */ -#define AT(t, p1, p2, s1, s2) /* nothing */ -#define NOTE(s) /* nothing */ -#endif - -/* - - matcher - the actual matching engine - == static int matcher(register struct re_guts *g, char *string, \ - == size_t nmatch, regmatch_t pmatch[], int eflags); - */ -static int /* 0 success, REG_NOMATCH failure */ -matcher(g, string, nmatch, pmatch, eflags) -register struct re_guts *g; -char *string; -size_t nmatch; -regmatch_t pmatch[]; -int eflags; -{ - register char *endp; - register int i; - struct match mv; - register struct match *m = &mv; - register char *dp; - const register sopno gf = g->firststate+1; /* +1 for OEND */ - const register sopno gl = g->laststate; - char *start; - char *stop; - - /* simplify the situation where possible */ - if (g->cflags®_NOSUB) - nmatch = 0; - if (eflags®_STARTEND) { - start = string + pmatch[0].rm_so; - stop = string + pmatch[0].rm_eo; - } else { - start = string; - stop = start + strlen(start); - } - if (stop < start) - return(REG_INVARG); - - /* prescreening; this does wonders for this rather slow code */ - if (g->must != NULL) { - for (dp = start; dp < stop; dp++) - if (*dp == g->must[0] && stop - dp >= g->mlen && - memcmp(dp, g->must, (size_t)g->mlen) == 0) - break; - if (dp == stop) /* we didn't find g->must */ - return(REG_NOMATCH); - } - - /* match struct setup */ - m->g = g; - m->eflags = eflags; - m->pmatch = NULL; - m->lastpos = NULL; - m->offp = string; - m->beginp = start; - m->endp = stop; - STATESETUP(m, 4); - SETUP(m->st); - SETUP(m->fresh); - SETUP(m->tmp); - SETUP(m->empty); - CLEAR(m->empty); - - /* this loop does only one repetition except for backrefs */ - for (;;) { - endp = fast(m, start, stop, gf, gl); - if (endp == NULL) { /* a miss */ - STATETEARDOWN(m); - return(REG_NOMATCH); - } - if (nmatch == 0 && !g->backrefs) - break; /* no further info needed */ - - /* where? */ - assert(m->coldp != NULL); - for (;;) { - NOTE("finding start"); - endp = slow(m, m->coldp, stop, gf, gl); - if (endp != NULL) - break; - assert(m->coldp < m->endp); - m->coldp++; - } - if (nmatch == 1 && !g->backrefs) - break; /* no further info needed */ - - /* oh my, he wants the subexpressions... */ - if (m->pmatch == NULL) - m->pmatch = (regmatch_t *)malloc((m->g->nsub + 1) * - sizeof(regmatch_t)); - if (m->pmatch == NULL) { - STATETEARDOWN(m); - return(REG_ESPACE); - } - for (i = 1; i <= m->g->nsub; i++) - m->pmatch[i].rm_so = m->pmatch[i].rm_eo = -1; - if (!g->backrefs && !(m->eflags®_BACKR)) { - NOTE("dissecting"); - dp = dissect(m, m->coldp, endp, gf, gl); - } else { - if (g->nplus > 0 && m->lastpos == NULL) - m->lastpos = (char **)malloc((g->nplus+1) * - sizeof(char *)); - if (g->nplus > 0 && m->lastpos == NULL) { - free(m->pmatch); - STATETEARDOWN(m); - return(REG_ESPACE); - } - NOTE("backref dissect"); - dp = backref(m, m->coldp, endp, gf, gl, (sopno)0); - } - if (dp != NULL) - break; - - /* uh-oh... we couldn't find a subexpression-level match */ - assert(g->backrefs); /* must be back references doing it */ - assert(g->nplus == 0 || m->lastpos != NULL); - for (;;) { - if (dp != NULL || endp <= m->coldp) - break; /* defeat */ - NOTE("backoff"); - endp = slow(m, m->coldp, endp-1, gf, gl); - if (endp == NULL) - break; /* defeat */ - /* try it on a shorter possibility */ -#ifndef NDEBUG - for (i = 1; i <= m->g->nsub; i++) { - assert(m->pmatch[i].rm_so == -1); - assert(m->pmatch[i].rm_eo == -1); - } -#endif - NOTE("backoff dissect"); - dp = backref(m, m->coldp, endp, gf, gl, (sopno)0); - } - assert(dp == NULL || dp == endp); - if (dp != NULL) /* found a shorter one */ - break; - - /* despite initial appearances, there is no match here */ - NOTE("false alarm"); - start = m->coldp + 1; /* recycle starting later */ - assert(start <= stop); - } - - /* fill in the details if requested */ - if (nmatch > 0) { - pmatch[0].rm_so = m->coldp - m->offp; - pmatch[0].rm_eo = endp - m->offp; - } - if (nmatch > 1) { - assert(m->pmatch != NULL); - for (i = 1; i < nmatch; i++) - if (i <= m->g->nsub) - pmatch[i] = m->pmatch[i]; - else { - pmatch[i].rm_so = -1; - pmatch[i].rm_eo = -1; - } - } - - if (m->pmatch != NULL) - free((char *)m->pmatch); - if (m->lastpos != NULL) - free((char *)m->lastpos); - STATETEARDOWN(m); - return(0); -} - -/* - - dissect - figure out what matched what, no back references - == static char *dissect(register struct match *m, char *start, \ - == char *stop, sopno startst, sopno stopst); - */ -static char * /* == stop (success) always */ -dissect(m, start, stop, startst, stopst) -register struct match *m; -char *start; -char *stop; -sopno startst; -sopno stopst; -{ - register int i; - register sopno ss; /* start sop of current subRE */ - register sopno es; /* end sop of current subRE */ - register char *sp; /* start of string matched by it */ - register char *stp; /* string matched by it cannot pass here */ - register char *rest; /* start of rest of string */ - register char *tail; /* string unmatched by rest of RE */ - register sopno ssub; /* start sop of subsubRE */ - register sopno esub; /* end sop of subsubRE */ - register char *ssp; /* start of string matched by subsubRE */ - register char *sep; /* end of string matched by subsubRE */ - register char *oldssp; /* previous ssp */ - register char *dp; - - AT("diss", start, stop, startst, stopst); - sp = start; - for (ss = startst; ss < stopst; ss = es) { - /* identify end of subRE */ - es = ss; - switch (OP(m->g->strip[es])) { - case OPLUS_: - case OQUEST_: - es += OPND(m->g->strip[es]); - break; - case OCH_: - while (OP(m->g->strip[es]) != O_CH) - es += OPND(m->g->strip[es]); - break; - } - es++; - - /* figure out what it matched */ - switch (OP(m->g->strip[ss])) { - case OEND: - assert(nope); - break; - case OCHAR: - sp++; - break; - case OBOL: - case OEOL: - case OBOW: - case OEOW: - break; - case OANY: - case OANYOF: - sp++; - break; - case OBACK_: - case O_BACK: - assert(nope); - break; - /* cases where length of match is hard to find */ - case OQUEST_: - stp = stop; - for (;;) { - /* how long could this one be? */ - rest = slow(m, sp, stp, ss, es); - assert(rest != NULL); /* it did match */ - /* could the rest match the rest? */ - tail = slow(m, rest, stop, es, stopst); - if (tail == stop) - break; /* yes! */ - /* no -- try a shorter match for this one */ - stp = rest - 1; - assert(stp >= sp); /* it did work */ - } - ssub = ss + 1; - esub = es - 1; - /* did innards match? */ - if (slow(m, sp, rest, ssub, esub) != NULL) { - dp = dissect(m, sp, rest, ssub, esub); - assert(dp == rest); - } else /* no */ - assert(sp == rest); - sp = rest; - break; - case OPLUS_: - stp = stop; - for (;;) { - /* how long could this one be? */ - rest = slow(m, sp, stp, ss, es); - assert(rest != NULL); /* it did match */ - /* could the rest match the rest? */ - tail = slow(m, rest, stop, es, stopst); - if (tail == stop) - break; /* yes! */ - /* no -- try a shorter match for this one */ - stp = rest - 1; - assert(stp >= sp); /* it did work */ - } - ssub = ss + 1; - esub = es - 1; - ssp = sp; - oldssp = ssp; - for (;;) { /* find last match of innards */ - sep = slow(m, ssp, rest, ssub, esub); - if (sep == NULL || sep == ssp) - break; /* failed or matched null */ - oldssp = ssp; /* on to next try */ - ssp = sep; - } - if (sep == NULL) { - /* last successful match */ - sep = ssp; - ssp = oldssp; - } - assert(sep == rest); /* must exhaust substring */ - assert(slow(m, ssp, sep, ssub, esub) == rest); - dp = dissect(m, ssp, sep, ssub, esub); - assert(dp == sep); - sp = rest; - break; - case OCH_: - stp = stop; - for (;;) { - /* how long could this one be? */ - rest = slow(m, sp, stp, ss, es); - assert(rest != NULL); /* it did match */ - /* could the rest match the rest? */ - tail = slow(m, rest, stop, es, stopst); - if (tail == stop) - break; /* yes! */ - /* no -- try a shorter match for this one */ - stp = rest - 1; - assert(stp >= sp); /* it did work */ - } - ssub = ss + 1; - esub = ss + OPND(m->g->strip[ss]) - 1; - assert(OP(m->g->strip[esub]) == OOR1); - for (;;) { /* find first matching branch */ - if (slow(m, sp, rest, ssub, esub) == rest) - break; /* it matched all of it */ - /* that one missed, try next one */ - assert(OP(m->g->strip[esub]) == OOR1); - esub++; - assert(OP(m->g->strip[esub]) == OOR2); - ssub = esub + 1; - esub += OPND(m->g->strip[esub]); - if (OP(m->g->strip[esub]) == OOR2) - esub--; - else - assert(OP(m->g->strip[esub]) == O_CH); - } - dp = dissect(m, sp, rest, ssub, esub); - assert(dp == rest); - sp = rest; - break; - case O_PLUS: - case O_QUEST: - case OOR1: - case OOR2: - case O_CH: - assert(nope); - break; - case OLPAREN: - i = OPND(m->g->strip[ss]); - assert(0 < i && i <= m->g->nsub); - m->pmatch[i].rm_so = sp - m->offp; - break; - case ORPAREN: - i = OPND(m->g->strip[ss]); - assert(0 < i && i <= m->g->nsub); - m->pmatch[i].rm_eo = sp - m->offp; - break; - default: /* uh oh */ - assert(nope); - break; - } - } - - assert(sp == stop); - return(sp); -} - -/* - - backref - figure out what matched what, figuring in back references - == static char *backref(register struct match *m, char *start, \ - == char *stop, sopno startst, sopno stopst, sopno lev); - */ -static char * /* == stop (success) or NULL (failure) */ -backref(m, start, stop, startst, stopst, lev) -register struct match *m; -char *start; -char *stop; -sopno startst; -sopno stopst; -sopno lev; /* PLUS nesting level */ -{ - register int i; - register sopno ss; /* start sop of current subRE */ - register char *sp; /* start of string matched by it */ - register sopno ssub; /* start sop of subsubRE */ - register sopno esub; /* end sop of subsubRE */ - register char *ssp; /* start of string matched by subsubRE */ - register char *dp; - register size_t len; - register int hard; - register sop s; - register regoff_t offsave; - register cset *cs; - - AT("back", start, stop, startst, stopst); - sp = start; - - /* get as far as we can with easy stuff */ - hard = 0; - for (ss = startst; !hard && ss < stopst; ss++) - switch (OP(s = m->g->strip[ss])) { - case OCHAR: - if (sp == stop || *sp++ != (char)OPND(s)) - return(NULL); - break; - case OANY: - if (sp == stop) - return(NULL); - sp++; - break; - case OANYOF: - cs = &m->g->sets[OPND(s)]; - if (sp == stop || !CHIN(cs, *sp++)) - return(NULL); - break; - case OBOL: - if ( (sp == m->beginp && !(m->eflags®_NOTBOL)) || - (sp < m->endp && *(sp-1) == '\n' && - (m->g->cflags®_NEWLINE)) ) - { /* yes */ } - else - return(NULL); - break; - case OEOL: - if ( (sp == m->endp && !(m->eflags®_NOTEOL)) || - (sp < m->endp && *sp == '\n' && - (m->g->cflags®_NEWLINE)) ) - { /* yes */ } - else - return(NULL); - break; - case OBOW: - if (( (sp == m->beginp && !(m->eflags®_NOTBOL)) || - (sp < m->endp && *(sp-1) == '\n' && - (m->g->cflags®_NEWLINE)) || - (sp > m->beginp && - !ISWORD(*(sp-1))) ) && - (sp < m->endp && ISWORD(*sp)) ) - { /* yes */ } - else - return(NULL); - break; - case OEOW: - 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))) ) - { /* yes */ } - else - return(NULL); - break; - case O_QUEST: - break; - case OOR1: /* matches null but needs to skip */ - ss++; - s = m->g->strip[ss]; - do { - assert(OP(s) == OOR2); - ss += OPND(s); - } while (OP(s = m->g->strip[ss]) != O_CH); - /* note that the ss++ gets us past the O_CH */ - break; - default: /* have to make a choice */ - hard = 1; - break; - } - if (!hard) { /* that was it! */ - if (sp != stop) - return(NULL); - return(sp); - } - ss--; /* adjust for the for's final increment */ - - /* the hard stuff */ - AT("hard", sp, stop, ss, stopst); - s = m->g->strip[ss]; - switch (OP(s)) { - case OBACK_: /* the vilest depths */ - i = OPND(s); - assert(0 < i && i <= m->g->nsub); - if (m->pmatch[i].rm_eo == -1) - return(NULL); - assert(m->pmatch[i].rm_so != -1); - len = m->pmatch[i].rm_eo - m->pmatch[i].rm_so; - assert(stop - m->beginp >= len); - if (sp > stop - len) - return(NULL); /* not enough left to match */ - ssp = m->offp + m->pmatch[i].rm_so; - if (memcmp(sp, ssp, len) != 0) - return(NULL); - while (m->g->strip[ss] != SOP(O_BACK, i)) - ss++; - return(backref(m, sp+len, stop, ss+1, stopst, lev)); - break; - case OQUEST_: /* to null or not */ - dp = backref(m, sp, stop, ss+1, stopst, lev); - if (dp != NULL) - return(dp); /* not */ - return(backref(m, sp, stop, ss+OPND(s)+1, stopst, lev)); - break; - case OPLUS_: - assert(m->lastpos != NULL); - assert(lev+1 <= m->g->nplus); - m->lastpos[lev+1] = sp; - return(backref(m, sp, stop, ss+1, stopst, lev+1)); - break; - case O_PLUS: - if (sp == m->lastpos[lev]) /* last pass matched null */ - return(backref(m, sp, stop, ss+1, stopst, lev-1)); - /* try another pass */ - m->lastpos[lev] = sp; - dp = backref(m, sp, stop, ss-OPND(s)+1, stopst, lev); - if (dp == NULL) - return(backref(m, sp, stop, ss+1, stopst, lev-1)); - else - return(dp); - break; - case OCH_: /* find the right one, if any */ - ssub = ss + 1; - esub = ss + OPND(s) - 1; - assert(OP(m->g->strip[esub]) == OOR1); - for (;;) { /* find first matching branch */ - dp = backref(m, sp, stop, ssub, esub, lev); - if (dp != NULL) - return(dp); - /* that one missed, try next one */ - if (OP(m->g->strip[esub]) == O_CH) - return(NULL); /* there is none */ - esub++; - assert(OP(m->g->strip[esub]) == OOR2); - ssub = esub + 1; - esub += OPND(m->g->strip[esub]); - if (OP(m->g->strip[esub]) == OOR2) - esub--; - else - assert(OP(m->g->strip[esub]) == O_CH); - } - break; - case OLPAREN: /* must undo assignment if rest fails */ - i = OPND(s); - assert(0 < i && i <= m->g->nsub); - offsave = m->pmatch[i].rm_so; - m->pmatch[i].rm_so = sp - m->offp; - dp = backref(m, sp, stop, ss+1, stopst, lev); - if (dp != NULL) - return(dp); - m->pmatch[i].rm_so = offsave; - return(NULL); - break; - case ORPAREN: /* must undo assignment if rest fails */ - i = OPND(s); - assert(0 < i && i <= m->g->nsub); - offsave = m->pmatch[i].rm_eo; - m->pmatch[i].rm_eo = sp - m->offp; - dp = backref(m, sp, stop, ss+1, stopst, lev); - if (dp != NULL) - return(dp); - m->pmatch[i].rm_eo = offsave; - return(NULL); - break; - default: /* uh oh */ - assert(nope); - break; - } - - /* "can't happen" */ - assert(nope); - /* NOTREACHED */ -} - -/* - - fast - step through the string at top speed - == static char *fast(register struct match *m, char *start, \ - == char *stop, sopno startst, sopno stopst); - */ -static char * /* where tentative match ended, or NULL */ -fast(m, start, stop, startst, stopst) -register struct match *m; -char *start; -char *stop; -sopno startst; -sopno stopst; -{ - register states st = m->st; - register states fresh = m->fresh; - register states tmp = m->tmp; - register char *p = start; - register int c = (start == m->beginp) ? OUT : *(start-1); - register int lastc; /* previous c */ - register int flagch; - register int i; - register char *coldp; /* last p after which no match was underway */ - - CLEAR(st); - SET1(st, startst); - st = step(m->g, startst, stopst, st, NOTHING, st); - ASSIGN(fresh, st); - SP("start", st, *p); - coldp = NULL; - for (;;) { - /* next character */ - lastc = c; - c = (p == m->endp) ? OUT : *p; - if (EQ(st, fresh)) - coldp = p; - - /* is there an EOL and/or BOL between lastc and c? */ - flagch = '\0'; - i = 0; - if ( (lastc == '\n' && m->g->cflags®_NEWLINE) || - (lastc == OUT && !(m->eflags®_NOTBOL)) ) { - flagch = BOL; - i = m->g->nbol; - } - if ( (c == '\n' && m->g->cflags®_NEWLINE) || - (c == OUT && !(m->eflags®_NOTEOL)) ) { - flagch = (flagch == BOL) ? BOLEOL : EOL; - i += m->g->neol; - } - if (i != 0) { - for (; i > 0; i--) - st = step(m->g, startst, stopst, st, flagch, st); - SP("boleol", st, c); - } - - /* how about a word boundary? */ - if ( (flagch == BOL || (lastc != OUT && !ISWORD(lastc))) && - (c != OUT && ISWORD(c)) ) { - flagch = BOW; - } - if ( (lastc != OUT && ISWORD(lastc)) && - (flagch == EOL || (c != OUT && !ISWORD(c))) ) { - flagch = EOW; - } - if (flagch == BOW || flagch == EOW) { - st = step(m->g, startst, stopst, st, flagch, st); - SP("boweow", st, c); - } - - /* are we done? */ - if (ISSET(st, stopst) || p == stop) - break; /* NOTE BREAK OUT */ - - /* no, we must deal with this character */ - ASSIGN(tmp, st); - ASSIGN(st, fresh); - assert(c != OUT); - 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++; - } - - assert(coldp != NULL); - m->coldp = coldp; - if (ISSET(st, stopst)) - return(p+1); - else - return(NULL); -} - -/* - - slow - step through the string more deliberately - == static char *slow(register struct match *m, char *start, \ - == char *stop, sopno startst, sopno stopst); - */ -static char * /* where it ended */ -slow(m, start, stop, startst, stopst) -register struct match *m; -char *start; -char *stop; -sopno startst; -sopno stopst; -{ - register states st = m->st; - register states empty = m->empty; - register states tmp = m->tmp; - register char *p = start; - register int c = (start == m->beginp) ? OUT : *(start-1); - register int lastc; /* previous c */ - register int flagch; - register int i; - register char *matchp; /* last p at which a match ended */ - - AT("slow", start, stop, startst, stopst); - CLEAR(st); - SET1(st, startst); - SP("sstart", st, *p); - st = step(m->g, startst, stopst, st, NOTHING, st); - matchp = NULL; - for (;;) { - /* next character */ - lastc = c; - c = (p == m->endp) ? OUT : *p; - - /* is there an EOL and/or BOL between lastc and c? */ - flagch = '\0'; - i = 0; - if ( (lastc == '\n' && m->g->cflags®_NEWLINE) || - (lastc == OUT && !(m->eflags®_NOTBOL)) ) { - flagch = BOL; - i = m->g->nbol; - } - if ( (c == '\n' && m->g->cflags®_NEWLINE) || - (c == OUT && !(m->eflags®_NOTEOL)) ) { - flagch = (flagch == BOL) ? BOLEOL : EOL; - i += m->g->neol; - } - if (i != 0) { - for (; i > 0; i--) - st = step(m->g, startst, stopst, st, flagch, st); - SP("sboleol", st, c); - } - - /* how about a word boundary? */ - if ( (flagch == BOL || (lastc != OUT && !ISWORD(lastc))) && - (c != OUT && ISWORD(c)) ) { - flagch = BOW; - } - if ( (lastc != OUT && ISWORD(lastc)) && - (flagch == EOL || (c != OUT && !ISWORD(c))) ) { - flagch = EOW; - } - if (flagch == BOW || flagch == EOW) { - st = step(m->g, startst, stopst, st, flagch, st); - SP("sboweow", st, c); - } - - /* are we done? */ - if (ISSET(st, stopst)) - matchp = p; - if (EQ(st, empty) || p == stop) - break; /* NOTE BREAK OUT */ - - /* no, we must deal with this character */ - ASSIGN(tmp, st); - ASSIGN(st, empty); - assert(c != OUT); - 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++; - } - - return(matchp); -} - - -/* - - step - map set of states reachable before char to set reachable after - == static states step(register struct re_guts *g, sopno start, sopno stop, \ - == register states bef, int ch, register 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(g, start, stop, bef, ch, aft) -register struct re_guts *g; -sopno start; /* start state within strip */ -sopno stop; /* state after stop state within strip */ -register states bef; /* states reachable before */ -int ch; /* character or NONCHAR code */ -register states aft; /* states already known reachable after */ -{ - register cset *cs; - register sop s; - register sopno pc; - register onestate here; /* note, macros know this name */ - register sopno look; - register int i; - - for (pc = start, INIT(here, pc); pc != stop; pc++, INC(here)) { - s = g->strip[pc]; - switch (OP(s)) { - case OEND: - assert(pc == stop-1); - break; - case OCHAR: - /* only characters can match */ - assert(!NONCHAR(ch) || ch != (char)OPND(s)); - if (ch == (char)OPND(s)) - FWD(aft, bef, 1); - break; - case OBOL: - if (ch == BOL || ch == BOLEOL) - FWD(aft, bef, 1); - break; - case OEOL: - if (ch == EOL || ch == BOLEOL) - FWD(aft, bef, 1); - break; - case OBOW: - if (ch == BOW) - FWD(aft, bef, 1); - break; - case OEOW: - if (ch == EOW) - FWD(aft, bef, 1); - break; - case OANY: - if (!NONCHAR(ch)) - FWD(aft, bef, 1); - break; - case OANYOF: - cs = &g->sets[OPND(s)]; - if (!NONCHAR(ch) && CHIN(cs, ch)) - FWD(aft, bef, 1); - break; - case OBACK_: /* ignored here */ - case O_BACK: - FWD(aft, aft, 1); - break; - case OPLUS_: /* forward, this is just an empty */ - FWD(aft, aft, 1); - break; - case O_PLUS: /* both forward and back */ - FWD(aft, aft, 1); - i = ISSETBACK(aft, OPND(s)); - BACK(aft, aft, OPND(s)); - if (!i && ISSETBACK(aft, OPND(s))) { - /* oho, must reconsider loop body */ - pc -= OPND(s) + 1; - INIT(here, pc); - } - break; - case OQUEST_: /* two branches, both forward */ - FWD(aft, aft, 1); - FWD(aft, aft, OPND(s)); - break; - case O_QUEST: /* just an empty */ - FWD(aft, aft, 1); - break; - case OLPAREN: /* not significant here */ - case ORPAREN: - FWD(aft, aft, 1); - break; - case OCH_: /* mark the first two branches */ - FWD(aft, aft, 1); - assert(OP(g->strip[pc+OPND(s)]) == OOR2); - FWD(aft, aft, OPND(s)); - break; - case OOR1: /* done a branch, find the O_CH */ - if (ISSTATEIN(aft, here)) { - for (look = 1; - OP(s = g->strip[pc+look]) != O_CH; - look += OPND(s)) - assert(OP(s) == OOR2); - FWD(aft, aft, look); - } - break; - case OOR2: /* propagate OCH_'s marking */ - FWD(aft, aft, 1); - if (OP(g->strip[pc+OPND(s)]) != O_CH) { - assert(OP(g->strip[pc+OPND(s)]) == OOR2); - FWD(aft, aft, OPND(s)); - } - break; - case O_CH: /* just empty */ - FWD(aft, aft, 1); - break; - default: /* ooooops... */ - assert(nope); - break; - } - } - - return(aft); -} - -#ifdef REDEBUG -/* - - print - print a set of states - == #ifdef REDEBUG - == static void print(struct match *m, char *caption, states st, \ - == int ch, FILE *d); - == #endif - */ -static void -print(m, caption, st, ch, d) -struct match *m; -char *caption; -states st; -int ch; -FILE *d; -{ - register struct re_guts *g = m->g; - register int i; - register int first = 1; - - if (!(m->eflags®_TRACE)) - return; - - fprintf(d, "%s", caption); - if (ch != '\0') - fprintf(d, " %s", pchar(ch)); - for (i = 0; i < g->nstates; i++) - if (ISSET(st, i)) { - fprintf(d, "%s%d", (first) ? "\t" : ", ", i); - first = 0; - } - fprintf(d, "\n"); -} - -/* - - at - print current situation - == #ifdef REDEBUG - == static void at(struct match *m, char *title, char *start, char *stop, \ - == sopno startst, sopno stopst); - == #endif - */ -static void -at(m, title, start, stop, startst, stopst) -struct match *m; -char *title; -char *start; -char *stop; -sopno startst; -sopno stopst; -{ - if (!(m->eflags®_TRACE)) - return; - - printf("%s %s-", title, pchar(*start)); - printf("%s ", pchar(*stop)); - printf("%ld-%ld\n", (long)startst, (long)stopst); -} - -#ifndef PCHARDONE -#define PCHARDONE /* never again */ -/* - - pchar - make a character printable - == #ifdef REDEBUG - == static char *pchar(int ch); - == #endif - * - * Is this identical to regchar() over in debug.c? Well, yes. But a - * duplicate here avoids having a debugging-capable regexec.o tied to - * a matching debug.o, and this is convenient. It all disappears in - * the non-debug compilation anyway, so it doesn't matter much. - */ -static char * /* -> representation */ -pchar(ch) -int ch; -{ - static char pbuf[10]; - - if (isprint(ch) || ch == ' ') - sprintf(pbuf, "%c", ch); - else - sprintf(pbuf, "\\%o", ch); - return(pbuf); -} -#endif -#endif - -#undef matcher -#undef fast -#undef slow -#undef dissect -#undef backref -#undef step -#undef print -#undef at -#undef match diff --git a/regex.subproj/regcomp.c b/regex.subproj/regcomp.c deleted file mode 100644 index e2e0bf3..0000000 --- a/regex.subproj/regcomp.c +++ /dev/null @@ -1,1712 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1992, 1993, 1994 - * 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. - */ - -#include -#include -#include -#include -#include -#include -#include - -#include "utils.h" -#include "regex2.h" - -#include "cclass.h" -#include "cname.h" - -/* - * parse structure, passed up and down to avoid global variables and - * other clumsinesses - */ -struct parse { - char *next; /* next character in RE */ - char *end; /* end of string (-> NUL normally) */ - int error; /* has an error been seen? */ - sop *strip; /* malloced strip */ - sopno ssize; /* malloced strip size (allocated) */ - sopno slen; /* malloced strip length (used) */ - int ncsalloc; /* number of csets allocated */ - struct re_guts *g; -# define NPAREN 10 /* we need to remember () 1-9 for back refs */ - sopno pbegin[NPAREN]; /* -> ( ([0] unused) */ - sopno pend[NPAREN]; /* -> ) ([0] unused) */ -}; - -/* ========= begin header generated by ./mkh ========= */ -#ifdef __cplusplus -extern "C" { -#endif - -/* === regcomp.c === */ -static void p_ere __P((struct parse *p, int stop)); -static void p_ere_exp __P((struct parse *p)); -static void p_str __P((struct parse *p)); -static void p_bre __P((struct parse *p, int end1, int end2)); -static int p_simp_re __P((struct parse *p, int starordinary)); -static int p_count __P((struct parse *p)); -static void p_bracket __P((struct parse *p)); -static void p_b_term __P((struct parse *p, cset *cs)); -static void p_b_cclass __P((struct parse *p, cset *cs)); -static void p_b_eclass __P((struct parse *p, cset *cs)); -static char p_b_symbol __P((struct parse *p)); -static char p_b_coll_elem __P((struct parse *p, int endc)); -static char othercase __P((int ch)); -static void bothcases __P((struct parse *p, int ch)); -static void ordinary __P((struct parse *p, int ch)); -static void nonnewline __P((struct parse *p)); -static void repeat __P((struct parse *p, sopno start, int from, int to)); -static int seterr __P((struct parse *p, int e)); -static cset *allocset __P((struct parse *p)); -static void freeset __P((struct parse *p, cset *cs)); -static int freezeset __P((struct parse *p, cset *cs)); -static int firstch __P((struct parse *p, cset *cs)); -static int nch __P((struct parse *p, cset *cs)); -static void mcadd __P((struct parse *p, cset *cs, char *cp)); -static void mcsub __P((cset *cs, char *cp)); -static int mcin __P((cset *cs, char *cp)); -static char *mcfind __P((cset *cs, char *cp)); -static void mcinvert __P((struct parse *p, cset *cs)); -static void mccase __P((struct parse *p, cset *cs)); -static int isinsets __P((struct re_guts *g, int c)); -static int samesets __P((struct re_guts *g, int c1, int c2)); -static void categorize __P((struct parse *p, struct re_guts *g)); -static sopno dupl __P((struct parse *p, sopno start, sopno finish)); -static void doemit __P((struct parse *p, sop op, size_t opnd)); -static void doinsert __P((struct parse *p, sop op, size_t opnd, sopno pos)); -static void dofwd __P((struct parse *p, sopno pos, sop value)); -static void enlarge __P((struct parse *p, sopno size)); -static void stripsnug __P((struct parse *p, struct re_guts *g)); -static void findmust __P((struct parse *p, struct re_guts *g)); -static sopno pluscount __P((struct parse *p, struct re_guts *g)); - -#ifdef __cplusplus -} -#endif -/* ========= end header generated by ./mkh ========= */ - -static char nuls[10]; /* place to point scanner in event of error */ - -/* - * macros for use with parse structure - * BEWARE: these know that the parse structure is named `p' !!! - */ -#define PEEK() (*p->next) -#define PEEK2() (*(p->next+1)) -#define MORE() (p->next < p->end) -#define MORE2() (p->next+1 < p->end) -#define SEE(c) (MORE() && PEEK() == (c)) -#define SEETWO(a, b) (MORE() && MORE2() && PEEK() == (a) && PEEK2() == (b)) -#define EAT(c) ((SEE(c)) ? (NEXT(), 1) : 0) -#define EATTWO(a, b) ((SEETWO(a, b)) ? (NEXT2(), 1) : 0) -#define NEXT() (p->next++) -#define NEXT2() (p->next += 2) -#define NEXTn(n) (p->next += (n)) -#define GETNEXT() (*p->next++) -#define SETERROR(e) seterr(p, (e)) -#define REQUIRE(co, e) ((co) || SETERROR(e)) -#define MUSTSEE(c, e) (REQUIRE(MORE() && PEEK() == (c), e)) -#define MUSTEAT(c, e) (REQUIRE(MORE() && GETNEXT() == (c), e)) -#define MUSTNOTSEE(c, e) (REQUIRE(!MORE() || PEEK() != (c), e)) -#define EMIT(op, sopnd) doemit(p, (sop)(op), (size_t)(sopnd)) -#define INSERT(op, pos) doinsert(p, (sop)(op), HERE()-(pos)+1, pos) -#define AHEAD(pos) dofwd(p, pos, HERE()-(pos)) -#define ASTERN(sop, pos) EMIT(sop, HERE()-pos) -#define HERE() (p->slen) -#define THERE() (p->slen - 1) -#define THERETHERE() (p->slen - 2) -#define DROP(n) (p->slen -= (n)) - -#ifndef NDEBUG -static int never = 0; /* for use in asserts; shuts lint up */ -#else -#define never 0 /* some s have bugs too */ -#endif - -/* - - regcomp - interface for parser and compilation - = extern int regcomp(regex_t *, const char *, int); - = #define REG_BASIC 0000 - = #define REG_EXTENDED 0001 - = #define REG_ICASE 0002 - = #define REG_NOSUB 0004 - = #define REG_NEWLINE 0010 - = #define REG_NOSPEC 0020 - = #define REG_PEND 0040 - = #define REG_DUMP 0200 - */ -int /* 0 success, otherwise REG_something */ -regcomp(preg, pattern, cflags) -regex_t *preg; -const char *pattern; -int cflags; -{ - struct parse pa; - register struct re_guts *g; - register struct parse *p = &pa; - register int i; - register size_t len; -#ifdef REDEBUG -# define GOODFLAGS(f) (f) -#else -# define GOODFLAGS(f) ((f)&~REG_DUMP) -#endif - - cflags = GOODFLAGS(cflags); - if ((cflags®_EXTENDED) && (cflags®_NOSPEC)) - return(REG_INVARG); - - if (cflags®_PEND) { - if (preg->re_endp < pattern) - return(REG_INVARG); - len = preg->re_endp - pattern; - } else - 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)); - if (g == NULL) - return(REG_ESPACE); - p->ssize = len/(size_t)2*(size_t)3 + (size_t)1; /* ugh */ - p->strip = (sop *)malloc(p->ssize * sizeof(sop)); - p->slen = 0; - if (p->strip == NULL) { - free((char *)g); - return(REG_ESPACE); - } - - /* set things up */ - p->g = g; - p->next = (char *)pattern; /* convenience; we do not modify it */ - p->end = p->next + len; - p->error = 0; - p->ncsalloc = 0; - for (i = 0; i < NPAREN; i++) { - 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->nbol = 0; - g->neol = 0; - g->must = 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 */ - EMIT(OEND, 0); - g->firststate = THERE(); - if (cflags®_EXTENDED) - p_ere(p, OUT); - else if (cflags®_NOSPEC) - p_str(p); - else - p_bre(p, OUT, OUT); - EMIT(OEND, 0); - g->laststate = THERE(); - - /* tidy up loose ends and fill things in */ - categorize(p, g); - stripsnug(p, g); - findmust(p, g); - g->nplus = pluscount(p, g); - g->magic = MAGIC2; - preg->re_nsub = g->nsub; - preg->re_g = g; - preg->re_magic = MAGIC1; -#ifndef REDEBUG - /* not debugging, so can't rely on the assert() in regexec() */ - if (g->iflags&BAD) - SETERROR(REG_ASSERT); -#endif - - /* win or lose, we're done */ - if (p->error != 0) /* lose */ - regfree(preg); - return(p->error); -} - -/* - - p_ere - ERE parser top level, concatenation and alternation - == static void p_ere(register struct parse *p, int stop); - */ -static void -p_ere(p, stop) -register struct parse *p; -int stop; /* character this ERE should end at */ -{ - register char c; - register sopno prevback; - register sopno prevfwd; - register sopno conc; - register int first = 1; /* is this the first alternative? */ - - for (;;) { - /* do a bunch of concatenated expressions */ - conc = HERE(); - while (MORE() && (c = PEEK()) != '|' && c != stop) - p_ere_exp(p); - REQUIRE(HERE() != conc, REG_EMPTY); /* require nonempty */ - - if (!EAT('|')) - break; /* NOTE BREAK OUT */ - - if (first) { - INSERT(OCH_, conc); /* offset is wrong */ - prevfwd = conc; - prevback = conc; - first = 0; - } - ASTERN(OOR1, prevback); - prevback = THERE(); - AHEAD(prevfwd); /* fix previous offset */ - prevfwd = HERE(); - EMIT(OOR2, 0); /* offset is very wrong */ - } - - if (!first) { /* tail-end fixups */ - AHEAD(prevfwd); - ASTERN(O_CH, prevback); - } - - assert(!MORE() || SEE(stop)); -} - -/* - - p_ere_exp - parse one subERE, an atom possibly followed by a repetition op - == static void p_ere_exp(register struct parse *p); - */ -static void -p_ere_exp(p) -register struct parse *p; -{ - register char c; - register sopno pos; - register int count; - register int count2; - register sopno subno; - int wascaret = 0; - - assert(MORE()); /* caller should have ensured this */ - c = GETNEXT(); - - pos = HERE(); - switch (c) { - case '(': - REQUIRE(MORE(), REG_EPAREN); - p->g->nsub++; - subno = p->g->nsub; - if (subno < NPAREN) - p->pbegin[subno] = HERE(); - EMIT(OLPAREN, subno); - if (!SEE(')')) - p_ere(p, ')'); - if (subno < NPAREN) { - p->pend[subno] = HERE(); - assert(p->pend[subno] != 0); - } - EMIT(ORPAREN, subno); - MUSTEAT(')', REG_EPAREN); - break; -#ifndef POSIX_MISTAKE - case ')': /* happens only if no current unmatched ( */ - /* - * You may ask, why the ifndef? Because I didn't notice - * this until slightly too late for 1003.2, and none of the - * other 1003.2 regular-expression reviewers noticed it at - * all. So an unmatched ) is legal POSIX, at least until - * we can get it fixed. - */ - SETERROR(REG_EPAREN); - break; -#endif - case '^': - EMIT(OBOL, 0); - p->g->iflags |= USEBOL; - p->g->nbol++; - wascaret = 1; - break; - case '$': - EMIT(OEOL, 0); - p->g->iflags |= USEEOL; - p->g->neol++; - break; - case '|': - SETERROR(REG_EMPTY); - break; - case '*': - case '+': - case '?': - SETERROR(REG_BADRPT); - break; - case '.': - if (p->g->cflags®_NEWLINE) - nonnewline(p); - else - EMIT(OANY, 0); - break; - case '[': - p_bracket(p); - break; - case '\\': - REQUIRE(MORE(), REG_EESCAPE); - c = GETNEXT(); - ordinary(p, c); - break; - case '{': /* okay as ordinary except if digit follows */ - REQUIRE(!MORE() || !isdigit(PEEK()), REG_BADRPT); - /* FALLTHROUGH */ - default: - ordinary(p, c); - break; - } - - if (!MORE()) - return; - c = PEEK(); - /* we call { a repetition if followed by a digit */ - if (!( c == '*' || c == '+' || c == '?' || - (c == '{' && MORE2() && isdigit(PEEK2())) )) - return; /* no repetition, we're done */ - NEXT(); - - REQUIRE(!wascaret, REG_BADRPT); - switch (c) { - case '*': /* implemented as +? */ - /* this case does not require the (y|) trick, noKLUDGE */ - INSERT(OPLUS_, pos); - ASTERN(O_PLUS, pos); - INSERT(OQUEST_, pos); - ASTERN(O_QUEST, pos); - break; - case '+': - INSERT(OPLUS_, pos); - ASTERN(O_PLUS, pos); - break; - case '?': - /* KLUDGE: emit y? as (y|) until subtle bug gets fixed */ - INSERT(OCH_, pos); /* offset slightly wrong */ - ASTERN(OOR1, pos); /* this one's right */ - AHEAD(pos); /* fix the OCH_ */ - EMIT(OOR2, 0); /* offset very wrong... */ - AHEAD(THERE()); /* ...so fix it */ - ASTERN(O_CH, THERETHERE()); - break; - case '{': - count = p_count(p); - if (EAT(',')) { - if (isdigit(PEEK())) { - count2 = p_count(p); - REQUIRE(count <= count2, REG_BADBR); - } else /* single number with comma */ - count2 = INFINITY; - } else /* just a single number */ - count2 = count; - repeat(p, pos, count, count2); - if (!EAT('}')) { /* error heuristics */ - while (MORE() && PEEK() != '}') - NEXT(); - REQUIRE(MORE(), REG_EBRACE); - SETERROR(REG_BADBR); - } - break; - } - - if (!MORE()) - return; - c = PEEK(); - if (!( c == '*' || c == '+' || c == '?' || - (c == '{' && MORE2() && isdigit(PEEK2())) ) ) - return; - SETERROR(REG_BADRPT); -} - -/* - - p_str - string (no metacharacters) "parser" - == static void p_str(register struct parse *p); - */ -static void -p_str(p) -register struct parse *p; -{ - REQUIRE(MORE(), REG_EMPTY); - while (MORE()) - ordinary(p, GETNEXT()); -} - -/* - - p_bre - BRE parser top level, anchoring and concatenation - == static void p_bre(register struct parse *p, register int end1, \ - == register int end2); - * 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. - * The amount of lookahead needed to avoid this kludge is excessive. - */ -static void -p_bre(p, end1, end2) -register struct parse *p; -register int end1; /* first terminating character */ -register int end2; /* second terminating character */ -{ - register sopno start = HERE(); - register int first = 1; /* first subexpression? */ - register int wasdollar = 0; - - if (EAT('^')) { - EMIT(OBOL, 0); - p->g->iflags |= USEBOL; - p->g->nbol++; - } - while (MORE() && !SEETWO(end1, end2)) { - wasdollar = p_simp_re(p, first); - first = 0; - } - if (wasdollar) { /* oops, that was a trailing anchor */ - DROP(1); - EMIT(OEOL, 0); - p->g->iflags |= USEEOL; - p->g->neol++; - } - - REQUIRE(HERE() != start, REG_EMPTY); /* require nonempty */ -} - -/* - - p_simp_re - parse a simple RE, an atom possibly followed by a repetition - == static int p_simp_re(register struct parse *p, int starordinary); - */ -static int /* was the simple RE an unbackslashed $? */ -p_simp_re(p, starordinary) -register struct parse *p; -int starordinary; /* is a leading * an ordinary character? */ -{ - register int c; - register int count; - register int count2; - register sopno pos; - register int i; - register sopno subno; -# define BACKSL (1<g->cflags®_NEWLINE) - nonnewline(p); - else - EMIT(OANY, 0); - break; - case '[': - p_bracket(p); - break; - case BACKSL|'{': - SETERROR(REG_BADRPT); - break; - case BACKSL|'(': - p->g->nsub++; - subno = p->g->nsub; - if (subno < NPAREN) - p->pbegin[subno] = HERE(); - EMIT(OLPAREN, subno); - /* the MORE here is an error heuristic */ - if (MORE() && !SEETWO('\\', ')')) - p_bre(p, '\\', ')'); - if (subno < NPAREN) { - p->pend[subno] = HERE(); - assert(p->pend[subno] != 0); - } - EMIT(ORPAREN, subno); - REQUIRE(EATTWO('\\', ')'), REG_EPAREN); - break; - case BACKSL|')': /* should not get here -- must be user */ - case BACKSL|'}': - SETERROR(REG_EPAREN); - break; - case BACKSL|'1': - case BACKSL|'2': - case BACKSL|'3': - case BACKSL|'4': - case BACKSL|'5': - case BACKSL|'6': - case BACKSL|'7': - case BACKSL|'8': - case BACKSL|'9': - i = (c&~BACKSL) - '0'; - assert(i < NPAREN); - if (p->pend[i] != 0) { - assert(i <= p->g->nsub); - EMIT(OBACK_, i); - assert(p->pbegin[i] != 0); - assert(OP(p->strip[p->pbegin[i]]) == OLPAREN); - assert(OP(p->strip[p->pend[i]]) == ORPAREN); - (void) dupl(p, p->pbegin[i]+1, p->pend[i]); - EMIT(O_BACK, i); - } else - SETERROR(REG_ESUBREG); - p->g->backrefs = 1; - break; - case '*': - REQUIRE(starordinary, REG_BADRPT); - /* FALLTHROUGH */ - default: - ordinary(p, c &~ BACKSL); - break; - } - - if (EAT('*')) { /* implemented as +? */ - /* this case does not require the (y|) trick, noKLUDGE */ - INSERT(OPLUS_, pos); - ASTERN(O_PLUS, pos); - INSERT(OQUEST_, pos); - ASTERN(O_QUEST, pos); - } else if (EATTWO('\\', '{')) { - count = p_count(p); - if (EAT(',')) { - if (MORE() && isdigit(PEEK())) { - count2 = p_count(p); - REQUIRE(count <= count2, REG_BADBR); - } else /* single number with comma */ - count2 = INFINITY; - } else /* just a single number */ - count2 = count; - repeat(p, pos, count, count2); - if (!EATTWO('\\', '}')) { /* error heuristics */ - while (MORE() && !SEETWO('\\', '}')) - NEXT(); - REQUIRE(MORE(), REG_EBRACE); - SETERROR(REG_BADBR); - } - } else if (c == (unsigned char)'$') /* $ (but not \$) ends it */ - return(1); - - return(0); -} - -/* - - p_count - parse a repetition count - == static int p_count(register struct parse *p); - */ -static int /* the value */ -p_count(p) -register struct parse *p; -{ - register int count = 0; - register int ndigits = 0; - - while (MORE() && isdigit(PEEK()) && count <= DUPMAX) { - count = count*10 + (GETNEXT() - '0'); - ndigits++; - } - - REQUIRE(ndigits > 0 && count <= DUPMAX, REG_BADBR); - return(count); -} - -/* - - p_bracket - parse a bracketed character list - == static void p_bracket(register 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) -register struct parse *p; -{ - register char c; - register cset *cs = allocset(p); - register int invert = 0; - - /* Dept of Truly Sickening Special-Case Kludges */ - if (p->next + 5 < p->end && strncmp(p->next, "[:<:]]", 6) == 0) { - EMIT(OBOW, 0); - NEXTn(6); - return; - } - if (p->next + 5 < p->end && strncmp(p->next, "[:>:]]", 6) == 0) { - EMIT(OEOW, 0); - NEXTn(6); - return; - } - - if (EAT('^')) - invert++; /* make note to invert set at end */ - if (EAT(']')) - CHadd(cs, ']'); - else if (EAT('-')) - CHadd(cs, '-'); - while (MORE() && PEEK() != ']' && !SEETWO('-', ']')) - p_b_term(p, cs); - if (EAT('-')) - CHadd(cs, '-'); - MUSTEAT(']', REG_EBRACK); - - if (p->error != 0) /* don't mess things up further */ - return; - - if (p->g->cflags®_ICASE) { - register int i; - register 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) { - register 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 (nch(p, cs) == 1) { /* optimize singleton sets */ - ordinary(p, firstch(p, cs)); - freeset(p, cs); - } else - EMIT(OANYOF, freezeset(p, cs)); -} - -/* - - p_b_term - parse one term of a bracketed character list - == static void p_b_term(register struct parse *p, register cset *cs); - */ -static void -p_b_term(p, cs) -register struct parse *p; -register cset *cs; -{ - register char c; - register char start, finish; - register int i; - - /* classify what we've got */ - switch ((MORE()) ? PEEK() : '\0') { - case '[': - c = (MORE2()) ? PEEK2() : '\0'; - break; - case '-': - SETERROR(REG_ERANGE); - return; /* NOTE RETURN */ - break; - default: - c = '\0'; - break; - } - - switch (c) { - case ':': /* character class */ - NEXT2(); - REQUIRE(MORE(), REG_EBRACK); - c = PEEK(); - REQUIRE(c != '-' && c != ']', REG_ECTYPE); - p_b_cclass(p, cs); - REQUIRE(MORE(), REG_EBRACK); - REQUIRE(EATTWO(':', ']'), REG_ECTYPE); - break; - case '=': /* equivalence class */ - NEXT2(); - REQUIRE(MORE(), REG_EBRACK); - c = PEEK(); - REQUIRE(c != '-' && c != ']', REG_ECOLLATE); - p_b_eclass(p, cs); - REQUIRE(MORE(), REG_EBRACK); - 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 */ - NEXT(); - if (EAT('-')) - finish = '-'; - else - finish = p_b_symbol(p); - } else - finish = start; -/* xxx what about signed chars here... */ - REQUIRE(start <= finish, REG_ERANGE); - for (i = start; i <= finish; i++) - CHadd(cs, i); - break; - } -} - -/* - - p_b_cclass - parse a character-class name and deal with it - == static void p_b_cclass(register struct parse *p, register cset *cs); - */ -static void -p_b_cclass(p, cs) -register struct parse *p; -register cset *cs; -{ - register char *sp = p->next; - register struct cclass *cp; - register size_t len; - register char *u; - register char c; - - while (MORE() && isalpha(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 */ - SETERROR(REG_ECTYPE); - return; - } - - u = cp->chars; - while ((c = *u++) != '\0') - CHadd(cs, c); - for (u = cp->multis; *u != '\0'; u += strlen(u) + 1) - MCadd(p, cs, u); -} - -/* - - p_b_eclass - parse an equivalence-class name and deal with it - == static void p_b_eclass(register struct parse *p, register cset *cs); - * - * This implementation is incomplete. xxx - */ -static void -p_b_eclass(p, cs) -register struct parse *p; -register cset *cs; -{ - register char c; - - c = p_b_coll_elem(p, '='); - CHadd(cs, c); -} - -/* - - p_b_symbol - parse a character or [..]ed multicharacter collating symbol - == static char p_b_symbol(register struct parse *p); - */ -static char /* value of symbol */ -p_b_symbol(p) -register struct parse *p; -{ - register char value; - - REQUIRE(MORE(), REG_EBRACK); - if (!EATTWO('[', '.')) - return(GETNEXT()); - - /* collating symbol */ - value = p_b_coll_elem(p, '.'); - REQUIRE(EATTWO('.', ']'), REG_ECOLLATE); - return(value); -} - -/* - - p_b_coll_elem - parse a collating-element name and look it up - == static char p_b_coll_elem(register struct parse *p, int endc); - */ -static char /* value of collating element */ -p_b_coll_elem(p, endc) -register struct parse *p; -int endc; /* name ended by endc,']' */ -{ - register char *sp = p->next; - register struct cname *cp; - register int len; - register char c; - - while (MORE() && !SEETWO(endc, ']')) - NEXT(); - if (!MORE()) { - SETERROR(REG_EBRACK); - return(0); - } - len = p->next - sp; - 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 */ - return(0); -} - -/* - - othercase - return the case counterpart of an alphabetic - == static char othercase(int ch); - */ -static char /* if no counterpart, return ch */ -othercase(ch) -int ch; -{ - assert(isalpha(ch)); - if (isupper(ch)) - return(tolower(ch)); - else if (islower(ch)) - return(toupper(ch)); - else /* peculiar, but could happen */ - return(ch); -} - -/* - - bothcases - emit a dualcase version of a two-case character - == static void bothcases(register struct parse *p, int ch); - * - * Boy, is this implementation ever a kludge... - */ -static void -bothcases(p, ch) -register struct parse *p; -int ch; -{ - register char *oldnext = p->next; - register char *oldend = p->end; - char bracket[3]; - - assert(othercase(ch) != ch); /* p_bracket() would recurse */ - p->next = bracket; - p->end = bracket+2; - bracket[0] = ch; - bracket[1] = ']'; - bracket[2] = '\0'; - p_bracket(p); - assert(p->next == bracket+2); - p->next = oldnext; - p->end = oldend; -} - -/* - - ordinary - emit an ordinary character - == static void ordinary(register struct parse *p, register int ch); - */ -static void -ordinary(p, ch) -register struct parse *p; -register int ch; -{ - register cat_t *cap = p->g->categories; - - if ((p->g->cflags®_ICASE) && isalpha(ch) && othercase(ch) != ch) - bothcases(p, ch); - else { - EMIT(OCHAR, (unsigned char)ch); - if (cap[ch] == 0) - cap[ch] = p->g->ncategories++; - } -} - -/* - - nonnewline - emit REG_NEWLINE version of OANY - == static void nonnewline(register struct parse *p); - * - * Boy, is this implementation ever a kludge... - */ -static void -nonnewline(p) -register struct parse *p; -{ - register char *oldnext = p->next; - register char *oldend = p->end; - char bracket[4]; - - p->next = bracket; - p->end = bracket+3; - bracket[0] = '^'; - bracket[1] = '\n'; - bracket[2] = ']'; - bracket[3] = '\0'; - p_bracket(p); - assert(p->next == bracket+3); - p->next = oldnext; - p->end = oldend; -} - -/* - - repeat - generate code for a bounded repetition, recursively if needed - == static void repeat(register struct parse *p, sopno start, int from, int to); - */ -static void -repeat(p, start, from, to) -register struct parse *p; -sopno start; /* operand from here to end of strip */ -int from; /* repeated from this number */ -int to; /* to this number of times (maybe INFINITY) */ -{ - register sopno finish = HERE(); -# define N 2 -# define INF 3 -# define REP(f, t) ((f)*8 + (t)) -# define MAP(n) (((n) <= 1) ? (n) : ((n) == INFINITY) ? INF : N) - register sopno copy; - - if (p->error != 0) /* head off possible runaway recursion */ - return; - - assert(from <= to); - - switch (REP(MAP(from), MAP(to))) { - case REP(0, 0): /* must be user doing this */ - DROP(finish-start); /* drop the operand */ - break; - case REP(0, 1): /* as x{1,1}? */ - case REP(0, N): /* as x{1,n}? */ - case REP(0, INF): /* as x{1,}? */ - /* KLUDGE: emit y? as (y|) until subtle bug gets fixed */ - INSERT(OCH_, start); /* offset is wrong... */ - repeat(p, start+1, 1, to); - ASTERN(OOR1, start); - AHEAD(start); /* ... fix it */ - EMIT(OOR2, 0); - AHEAD(THERE()); - ASTERN(O_CH, THERETHERE()); - break; - case REP(1, 1): /* trivial case */ - /* done */ - break; - case REP(1, N): /* as x?x{1,n-1} */ - /* KLUDGE: emit y? as (y|) until subtle bug gets fixed */ - INSERT(OCH_, start); - ASTERN(OOR1, start); - AHEAD(start); - EMIT(OOR2, 0); /* offset very wrong... */ - AHEAD(THERE()); /* ...so fix it */ - ASTERN(O_CH, THERETHERE()); - copy = dupl(p, start+1, finish+1); - assert(copy == finish+4); - repeat(p, copy, 1, to-1); - break; - case REP(1, INF): /* as x+ */ - INSERT(OPLUS_, start); - ASTERN(O_PLUS, start); - break; - case REP(N, N): /* as xx{m-1,n-1} */ - copy = dupl(p, start, finish); - repeat(p, copy, from-1, to-1); - break; - case REP(N, INF): /* as xx{n-1,INF} */ - copy = dupl(p, start, finish); - repeat(p, copy, from-1, to); - break; - default: /* "can't happen" */ - SETERROR(REG_ASSERT); /* just in case */ - break; - } -} - -/* - - seterr - set an error condition - == static int seterr(register struct parse *p, int e); - */ -static int /* useless but makes type checking happy */ -seterr(p, e) -register struct parse *p; -int e; -{ - if (p->error == 0) /* keep earliest error condition */ - p->error = e; - p->next = nuls; /* try to bring things to a halt */ - p->end = nuls; - return(0); /* make the return value well-defined */ -} - -/* - - allocset - allocate a set of characters for [] - == static cset *allocset(register struct parse *p); - */ -static cset * -allocset(p) -register struct parse *p; -{ - register int no = p->g->ncsets++; - register size_t nc; - register size_t nbytes; - register cset *cs; - register size_t css = (size_t)p->g->csetsize; - register int i; - - 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 *)realloc((char *)p->g->sets, - nc * sizeof(cset)); - if (p->g->setbits == NULL) - p->g->setbits = (uch *)malloc(nbytes); - else { - p->g->setbits = (uch *)realloc((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 */ - } - } - - 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; - - return(cs); -} - -/* - - freeset - free a now-unused set - == static void freeset(register struct parse *p, register cset *cs); - */ -static void -freeset(p, cs) -register struct parse *p; -register cset *cs; -{ - register int i; - register cset *top = &p->g->sets[p->g->ncsets]; - register size_t css = (size_t)p->g->csetsize; - - for (i = 0; i < css; i++) - CHsub(cs, i); - if (cs == top-1) /* recover only the easy case */ - p->g->ncsets--; -} - -/* - - freezeset - final processing on a set of characters - == static int freezeset(register struct parse *p, register 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) -register struct parse *p; -register cset *cs; -{ - register uch h = cs->hash; - register int i; - register cset *top = &p->g->sets[p->g->ncsets]; - register cset *cs2; - register 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(register struct parse *p, register cset *cs); - */ -static int /* character; there is no "none" value */ -firstch(p, cs) -register struct parse *p; -register cset *cs; -{ - register int i; - register 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 */ -} - -/* - - nch - number of characters in a set - == static int nch(register struct parse *p, register cset *cs); - */ -static int -nch(p, cs) -register struct parse *p; -register cset *cs; -{ - register int i; - register size_t css = (size_t)p->g->csetsize; - register int n = 0; - - for (i = 0; i < css; i++) - if (CHIN(cs, i)) - n++; - return(n); -} - -/* - - mcadd - add a collating element to a cset - == static void mcadd(register struct parse *p, register cset *cs, \ - == register char *cp); - */ -static void -mcadd(p, cs, cp) -register struct parse *p; -register cset *cs; -register char *cp; -{ - register size_t oldend = cs->smultis; - - cs->smultis += strlen(cp) + 1; - if (cs->multis == NULL) - cs->multis = malloc(cs->smultis); - else - cs->multis = realloc(cs->multis, cs->smultis); - if (cs->multis == NULL) { - SETERROR(REG_ESPACE); - return; - } - - (void) strcpy(cs->multis + oldend - 1, cp); - cs->multis[cs->smultis - 1] = '\0'; -} - -/* - - mcsub - subtract a collating element from a cset - == static void mcsub(register cset *cs, register char *cp); - */ -static void -mcsub(cs, cp) -register cset *cs; -register char *cp; -{ - register char *fp = mcfind(cs, cp); - register size_t len = strlen(fp); - - assert(fp != NULL); - (void) memmove(fp, fp + len + 1, - cs->smultis - (fp + len + 1 - cs->multis)); - cs->smultis -= len; - - if (cs->smultis == 0) { - free(cs->multis); - cs->multis = NULL; - return; - } - - cs->multis = realloc(cs->multis, cs->smultis); - assert(cs->multis != NULL); -} - -/* - - mcin - is a collating element in a cset? - == static int mcin(register cset *cs, register char *cp); - */ -static int -mcin(cs, cp) -register cset *cs; -register char *cp; -{ - return(mcfind(cs, cp) != NULL); -} - -/* - - mcfind - find a collating element in a cset - == static char *mcfind(register cset *cs, register char *cp); - */ -static char * -mcfind(cs, cp) -register cset *cs; -register char *cp; -{ - register 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); -} - -/* - - mcinvert - invert the list of collating elements in a cset - == static void mcinvert(register struct parse *p, register cset *cs); - * - * This would have to know the set of possibilities. Implementation - * is deferred. - */ -static void -mcinvert(p, cs) -register struct parse *p; -register cset *cs; -{ - assert(cs->multis == NULL); /* xxx */ -} - -/* - - mccase - add case counterparts of the list of collating elements in a cset - == static void mccase(register struct parse *p, register cset *cs); - * - * This would have to know the set of possibilities. Implementation - * is deferred. - */ -static void -mccase(p, cs) -register struct parse *p; -register cset *cs; -{ - assert(cs->multis == NULL); /* xxx */ -} - -/* - - isinsets - is this character in any sets? - == static int isinsets(register struct re_guts *g, int c); - */ -static int /* predicate */ -isinsets(g, c) -register struct re_guts *g; -int c; -{ - register uch *col; - register int i; - register int ncols = (g->ncsets+(CHAR_BIT-1)) / CHAR_BIT; - register unsigned uc = (unsigned char)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(register struct re_guts *g, int c1, int c2); - */ -static int /* predicate */ -samesets(g, c1, c2) -register struct re_guts *g; -int c1; -int c2; -{ - register uch *col; - register int i; - register int ncols = (g->ncsets+(CHAR_BIT-1)) / CHAR_BIT; - register unsigned uc1 = (unsigned char)c1; - register unsigned uc2 = (unsigned char)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, register struct re_guts *g); - */ -static void -categorize(p, g) -struct parse *p; -register struct re_guts *g; -{ - register cat_t *cats = g->categories; - register int c; - register int c2; - register cat_t cat; - - /* avoid making error situations worse */ - if (p->error != 0) - 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; - } -} - -/* - - dupl - emit a duplicate of a bunch of sops - == static sopno dupl(register struct parse *p, sopno start, sopno finish); - */ -static sopno /* start of duplicate */ -dupl(p, start, finish) -register struct parse *p; -sopno start; /* from here */ -sopno finish; /* to this less one */ -{ - register sopno ret = HERE(); - register sopno len = finish - start; - - assert(finish >= start); - if (len == 0) - return(ret); - enlarge(p, p->ssize + len); /* this many unexpected additions */ - assert(p->ssize >= p->slen + len); - (void) memcpy((char *)(p->strip + p->slen), - (char *)(p->strip + start), (size_t)len*sizeof(sop)); - p->slen += len; - return(ret); -} - -/* - - doemit - emit a strip operator - == static void doemit(register struct parse *p, sop op, size_t opnd); - * - * It might seem better to implement this as a macro with a function as - * hard-case backup, but it's just too big and messy unless there are - * some changes to the data structures. Maybe later. - */ -static void -doemit(p, op, opnd) -register struct parse *p; -sop op; -size_t opnd; -{ - /* avoid making error situations worse */ - if (p->error != 0) - return; - - /* deal with oversize operands ("can't happen", more or less) */ - assert(opnd < 1<slen >= p->ssize) - enlarge(p, (p->ssize+1) / 2 * 3); /* +50% */ - assert(p->slen < p->ssize); - - /* finally, it's all reduced to the easy case */ - p->strip[p->slen++] = SOP(op, opnd); -} - -/* - - doinsert - insert a sop into the strip - == static void doinsert(register struct parse *p, sop op, size_t opnd, sopno pos); - */ -static void -doinsert(p, op, opnd, pos) -register struct parse *p; -sop op; -size_t opnd; -sopno pos; -{ - register sopno sn; - register sop s; - register int i; - - /* avoid making error situations worse */ - if (p->error != 0) - return; - - sn = HERE(); - EMIT(op, opnd); /* do checks, ensure space */ - assert(HERE() == sn+1); - s = p->strip[sn]; - - /* adjust paren pointers */ - assert(pos > 0); - for (i = 1; i < NPAREN; i++) { - if (p->pbegin[i] >= pos) { - p->pbegin[i]++; - } - if (p->pend[i] >= pos) { - p->pend[i]++; - } - } - - memmove((char *)&p->strip[pos+1], (char *)&p->strip[pos], - (HERE()-pos-1)*sizeof(sop)); - p->strip[pos] = s; -} - -/* - - dofwd - complete a forward reference - == static void dofwd(register struct parse *p, sopno pos, sop value); - */ -static void -dofwd(p, pos, value) -register struct parse *p; -register sopno pos; -sop value; -{ - /* avoid making error situations worse */ - if (p->error != 0) - return; - - assert(value < 1<strip[pos] = OP(p->strip[pos]) | value; -} - -/* - - enlarge - enlarge the strip - == static void enlarge(register struct parse *p, sopno size); - */ -static void -enlarge(p, size) -register struct parse *p; -register sopno size; -{ - register sop *sp; - - if (p->ssize >= size) - return; - - sp = (sop *)realloc(p->strip, size*sizeof(sop)); - if (sp == NULL) { - SETERROR(REG_ESPACE); - return; - } - p->strip = sp; - p->ssize = size; -} - -/* - - stripsnug - compact the strip - == static void stripsnug(register struct parse *p, register struct re_guts *g); - */ -static void -stripsnug(p, g) -register struct parse *p; -register struct re_guts *g; -{ - g->nstates = p->slen; - g->strip = (sop *)realloc((char *)p->strip, p->slen * sizeof(sop)); - if (g->strip == NULL) { - SETERROR(REG_ESPACE); - g->strip = p->strip; - } -} - -/* - - findmust - fill in must and mlen with longest mandatory literal string - == static void findmust(register struct parse *p, register struct re_guts *g); - * - * This algorithm could do fancy things like analyzing the operands of | - * for common subsequences. Someday. This code is simple and finds most - * of the interesting cases. - * - * Note that must and mlen got initialized during setup. - */ -static void -findmust(p, g) -struct parse *p; -register struct re_guts *g; -{ - register sop *scan; - sop *start; - register sop *newstart; - register sopno newlen; - register sop s; - register char *cp; - register sopno i; - - /* avoid making error situations worse */ - if (p->error != 0) - return; - - /* find the longest OCHAR sequence in strip */ - newlen = 0; - scan = g->strip + 1; - do { - s = *scan++; - switch (OP(s)) { - case OCHAR: /* sequence member */ - if (newlen == 0) /* new sequence */ - newstart = scan - 1; - newlen++; - break; - case OPLUS_: /* things that don't break one */ - case OLPAREN: - case ORPAREN: - break; - case OQUEST_: /* things that must be skipped */ - case OCH_: - scan--; - do { - scan += OPND(s); - s = *scan; - /* assert() interferes w debug printouts */ - if (OP(s) != O_QUEST && OP(s) != O_CH && - OP(s) != OOR2) { - g->iflags |= BAD; - return; - } - } while (OP(s) != O_QUEST && OP(s) != O_CH); - /* fallthrough */ - default: /* things that break a sequence */ - if (newlen > g->mlen) { /* ends one */ - start = newstart; - g->mlen = newlen; - } - newlen = 0; - break; - } - } while (OP(s) != OEND); - - if (g->mlen == 0) /* there isn't one */ - return; - - /* turn it into a character string */ - g->must = malloc((size_t)g->mlen + 1); - if (g->must == NULL) { /* argh; just forget it */ - g->mlen = 0; - return; - } - cp = g->must; - scan = start; - for (i = g->mlen; i > 0; i--) { - while (OP(s = *scan++) != OCHAR) - continue; - assert(cp < g->must + g->mlen); - *cp++ = (char)OPND(s); - } - assert(cp == g->must + g->mlen); - *cp++ = '\0'; /* just on general principles */ -} - -/* - - pluscount - count + nesting - == static sopno pluscount(register struct parse *p, register struct re_guts *g); - */ -static sopno /* nesting depth */ -pluscount(p, g) -struct parse *p; -register struct re_guts *g; -{ - register sop *scan; - register sop s; - register sopno plusnest = 0; - register sopno maxnest = 0; - - if (p->error != 0) - return(0); /* there may not be an OEND */ - - scan = g->strip + 1; - do { - s = *scan++; - switch (OP(s)) { - case OPLUS_: - plusnest++; - break; - case O_PLUS: - if (plusnest > maxnest) - maxnest = plusnest; - plusnest--; - break; - } - } while (OP(s) != OEND); - if (plusnest != 0) - g->iflags |= BAD; - return(maxnest); -} diff --git a/regex.subproj/regerror.c b/regex.subproj/regerror.c deleted file mode 100644 index 6d7da99..0000000 --- a/regex.subproj/regerror.c +++ /dev/null @@ -1,198 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1992, 1993, 1994 - * 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. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)regerror.c 8.4 (Berkeley) 3/20/94"; -#endif /* LIBC_SCCS and not lint */ - -#include -#include -#include -#include -#include -#include -#include - -#include "utils.h" - -/* ========= begin header generated by ./mkh ========= */ -#ifdef __cplusplus -extern "C" { -#endif - -/* === regerror.c === */ -static char *regatoi __P((const regex_t *preg, char *localbuf)); - -#ifdef __cplusplus -} -#endif -/* ========= end header generated by ./mkh ========= */ -/* - = #define REG_NOMATCH 1 - = #define REG_BADPAT 2 - = #define REG_ECOLLATE 3 - = #define REG_ECTYPE 4 - = #define REG_EESCAPE 5 - = #define REG_ESUBREG 6 - = #define REG_EBRACK 7 - = #define REG_EPAREN 8 - = #define REG_EBRACE 9 - = #define REG_BADBR 10 - = #define REG_ERANGE 11 - = #define REG_ESPACE 12 - = #define REG_BADRPT 13 - = #define REG_EMPTY 14 - = #define REG_ASSERT 15 - = #define REG_INVARG 16 - = #define REG_ATOI 255 // convert name to number (!) - = #define REG_ITOA 0400 // convert number to name (!) - */ -static struct rerr { - int code; - char *name; - char *explain; -} rerrs[] = { - REG_NOMATCH, "REG_NOMATCH", "regexec() failed to match", - REG_BADPAT, "REG_BADPAT", "invalid regular expression", - REG_ECOLLATE, "REG_ECOLLATE", "invalid collating element", - REG_ECTYPE, "REG_ECTYPE", "invalid character class", - REG_EESCAPE, "REG_EESCAPE", "trailing backslash (\\)", - REG_ESUBREG, "REG_ESUBREG", "invalid backreference number", - REG_EBRACK, "REG_EBRACK", "brackets ([ ]) not balanced", - REG_EPAREN, "REG_EPAREN", "parentheses not balanced", - REG_EBRACE, "REG_EBRACE", "braces not balanced", - REG_BADBR, "REG_BADBR", "invalid repetition count(s)", - REG_ERANGE, "REG_ERANGE", "invalid character range", - REG_ESPACE, "REG_ESPACE", "out of memory", - REG_BADRPT, "REG_BADRPT", "repetition-operator operand invalid", - 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", - 0, "", "*** unknown regexp error code ***", -}; - -/* - - regerror - the interface to error numbers - = extern size_t regerror(int, const regex_t *, char *, size_t); - */ -/* ARGSUSED */ -size_t -regerror(errcode, preg, errbuf, errbuf_size) -int errcode; -const regex_t *preg; -char *errbuf; -size_t errbuf_size; -{ - register struct rerr *r; - register size_t len; - register int target = errcode &~ REG_ITOA; - register char *s; - char convbuf[50]; - - if (errcode == REG_ATOI) - s = regatoi(preg, convbuf); - else { - for (r = rerrs; r->code != 0; r++) - if (r->code == target) - break; - - if (errcode®_ITOA) { - if (r->code != 0) - (void) strcpy(convbuf, r->name); - else - sprintf(convbuf, "REG_0x%x", target); - assert(strlen(convbuf) < sizeof(convbuf)); - s = convbuf; - } else - s = r->explain; - } - - len = strlen(s) + 1; - if (errbuf_size > 0) { - if (errbuf_size > len) - (void) strcpy(errbuf, s); - else { - (void) strncpy(errbuf, s, errbuf_size-1); - errbuf[errbuf_size-1] = '\0'; - } - } - - return(len); -} - -/* - - regatoi - internal routine to implement REG_ATOI - == static char *regatoi(const regex_t *preg, char *localbuf); - */ -static char * -regatoi(preg, localbuf) -const regex_t *preg; -char *localbuf; -{ - register struct rerr *r; - register size_t siz; - register char *p; - - for (r = rerrs; r->code != 0; r++) - if (strcmp(r->name, preg->re_endp) == 0) - break; - if (r->code == 0) - return("0"); - - sprintf(localbuf, "%d", r->code); - return(localbuf); -} diff --git a/regex.subproj/regex2.h b/regex.subproj/regex2.h deleted file mode 100644 index d68f62b..0000000 --- a/regex.subproj/regex2.h +++ /dev/null @@ -1,191 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1992, 1993, 1994 - * 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. - */ - -/* - * First, the stuff that ends up in the outside-world include file - = typedef off_t regoff_t; - = typedef struct { - = int re_magic; - = size_t re_nsub; // number of parenthesized subexpressions - = const char *re_endp; // end pointer for REG_PEND - = struct re_guts *re_g; // none of your business :-) - = } regex_t; - = typedef struct { - = regoff_t rm_so; // start of match - = regoff_t rm_eo; // end of match - = } regmatch_t; - */ -/* - * internals of regex_t - */ -#define MAGIC1 ((('r'^0200)<<8) | 'e') - -/* - * The internal representation is a *strip*, a sequence of - * operators ending with an endmarker. (Some terminology etc. is a - * historical relic of earlier versions which used multiple strips.) - * Certain oddities in the representation are there to permit running - * the machinery backwards; in particular, any deviation from sequential - * flow must be marked at both its source and its destination. Some - * fine points: - * - * - OPLUS_ and O_PLUS are *inside* the loop they create. - * - OQUEST_ and O_QUEST are *outside* the bypass they create. - * - OCH_ and O_CH are *outside* the multi-way branch they create, while - * OOR1 and OOR2 are respectively the end and the beginning of one of - * the branches. Note that there is an implicit OOR2 following OCH_ - * and an implicit OOR1 preceding O_CH. - * - * In state representations, an operator's bit is on to signify a state - * immediately *preceding* "execution" of that operator. - */ -typedef unsigned long sop; /* strip operator */ -typedef long sopno; -#define OPRMASK 0xf8000000 -#define OPDMASK 0x07ffffff -#define OPSHIFT ((unsigned)27) -#define OP(n) ((n)&OPRMASK) -#define OPND(n) ((n)&OPDMASK) -#define SOP(op, opnd) ((op)|(opnd)) -/* operators meaning operand */ -/* (back, fwd are offsets) */ -#define OEND (1< uch [csetsize] */ - uch mask; /* bit within array */ - uch hash; /* hash code */ - size_t smultis; - char *multis; /* -> char[smulti] ab\0cd\0ef\0\0 */ -} 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 += (c)) -#define CHsub(cs, c) ((cs)->ptr[(uch)(c)] &= ~(cs)->mask, (cs)->hash -= (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; - -/* - * main compiled-expression structure - */ -struct re_guts { - 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) */ - sopno laststate; /* the final OEND */ - int iflags; /* internal flags */ -# define USEBOL 01 /* used ^ */ -# define USEEOL 02 /* used $ */ -# 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 mlen; /* length of must */ - 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(c) || (c) == '_') diff --git a/regex.subproj/regexec.c b/regex.subproj/regexec.c deleted file mode 100644 index 928e272..0000000 --- a/regex.subproj/regexec.c +++ /dev/null @@ -1,195 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1992, 1993, 1994 - * 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. - */ - -/* - * the outer shell of regexec() - * - * This file includes engine.c *twice*, after muchos fiddling with the - * macros that code uses. This lets the same code operate on two different - * representations for state sets. - */ -#include -#include -#include -#include -#include -#include -#include - -#include "utils.h" -#include "regex2.h" - -static int nope = 0; /* for use in asserts; shuts lint up */ - -/* macros for manipulating states, small version */ -#define states long -#define states1 states /* for later use in regexec() decision */ -#define CLEAR(v) ((v) = 0) -#define SET0(v, n) ((v) &= ~(1 << (n))) -#define SET1(v, n) ((v) |= 1 << (n)) -#define ISSET(v, n) ((v) & (1 << (n))) -#define ASSIGN(d, s) ((d) = (s)) -#define EQ(a, b) ((a) == (b)) -#define STATEVARS int dummy /* dummy version */ -#define STATESETUP(m, n) /* nothing */ -#define STATETEARDOWN(m) /* nothing */ -#define SETUP(v) ((v) = 0) -#define onestate int -#define INIT(o, n) ((o) = (unsigned)1 << (n)) -#define INC(o) ((o) <<= 1) -#define ISSTATEIN(v, o) ((v) & (o)) -/* some abbreviations; note that some of these know variable names! */ -/* do "if I'm here, I can also be there" etc without branches */ -#define FWD(dst, src, n) ((dst) |= ((unsigned)(src)&(here)) << (n)) -#define BACK(dst, src, n) ((dst) |= ((unsigned)(src)&(here)) >> (n)) -#define ISSETBACK(v, n) ((v) & ((unsigned)here >> (n))) -/* function names */ -#define SNAMES /* engine.c looks after details */ - -#include "engine.c" - -/* now undo things */ -#undef states -#undef CLEAR -#undef SET0 -#undef SET1 -#undef ISSET -#undef ASSIGN -#undef EQ -#undef STATEVARS -#undef STATESETUP -#undef STATETEARDOWN -#undef SETUP -#undef onestate -#undef INIT -#undef INC -#undef ISSTATEIN -#undef FWD -#undef BACK -#undef ISSETBACK -#undef SNAMES - -/* macros for manipulating states, large version */ -#define states char * -#define CLEAR(v) memset(v, 0, m->g->nstates) -#define SET0(v, n) ((v)[n] = 0) -#define SET1(v, n) ((v)[n] = 1) -#define ISSET(v, n) ((v)[n]) -#define ASSIGN(d, s) memcpy(d, s, m->g->nstates) -#define EQ(a, b) (memcmp(a, b, m->g->nstates) == 0) -#define STATEVARS int vn; char *space -#define STATESETUP(m, nv) { (m)->space = malloc((nv)*(m)->g->nstates); \ - if ((m)->space == NULL) return(REG_ESPACE); \ - (m)->vn = 0; } -#define STATETEARDOWN(m) { free((m)->space); } -#define SETUP(v) ((v) = &m->space[m->vn++ * m->g->nstates]) -#define onestate int -#define INIT(o, n) ((o) = (n)) -#define INC(o) ((o)++) -#define ISSTATEIN(v, o) ((v)[o]) -/* some abbreviations; note that some of these know variable names! */ -/* do "if I'm here, I can also be there" etc without branches */ -#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)]) -/* function names */ -#define LNAMES /* flag */ - -#include "engine.c" - -/* - - regexec - interface for matching - = extern int regexec(const regex_t *, const char *, size_t, \ - = regmatch_t [], int); - = #define REG_NOTBOL 00001 - = #define REG_NOTEOL 00002 - = #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 - * - * We put this here so we can exploit knowledge of the state representation - * when choosing which matcher to call. Also, by this point the matchers - * have been prototyped. - */ -int /* 0 success, REG_NOMATCH failure */ -regexec(preg, string, nmatch, pmatch, eflags) -const regex_t *preg; -const char *string; -size_t nmatch; -regmatch_t pmatch[]; -int eflags; -{ - register struct re_guts *g = preg->re_g; -#ifdef REDEBUG -# define GOODFLAGS(f) (f) -#else -# define GOODFLAGS(f) ((f)&(REG_NOTBOL|REG_NOTEOL|REG_STARTEND)) -#endif - - if (preg->re_magic != MAGIC1 || g->magic != MAGIC2) - return(REG_BADPAT); - assert(!(g->iflags&BAD)); - if (g->iflags&BAD) /* backstop for no-debug case */ - return(REG_BADPAT); - eflags = GOODFLAGS(eflags); - - 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)); -} diff --git a/regex.subproj/regfree.c b/regex.subproj/regfree.c deleted file mode 100644 index 9d81d4c..0000000 --- a/regex.subproj/regfree.c +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1992, 1993, 1994 - * 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. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)regfree.c 8.3 (Berkeley) 3/20/94"; -#endif /* LIBC_SCCS and not lint */ - -#include -#include -#include -#include - -#include "utils.h" -#include "regex2.h" - -/* - - regfree - free everything - = extern void regfree(regex_t *); - */ -void -regfree(preg) -regex_t *preg; -{ - register struct re_guts *g; - - if (preg->re_magic != MAGIC1) /* oops */ - return; /* nice to complain, but hard */ - - g = preg->re_g; - if (g == NULL || g->magic != MAGIC2) /* oops again */ - return; - preg->re_magic = 0; /* mark it invalid */ - g->magic = 0; /* mark it invalid */ - - if (g->strip != NULL) - free((char *)g->strip); - if (g->sets != NULL) - free((char *)g->sets); - if (g->setbits != NULL) - free((char *)g->setbits); - if (g->must != NULL) - free(g->must); - free((char *)g); -} diff --git a/regex.subproj/utils.h b/regex.subproj/utils.h deleted file mode 100644 index f18607b..0000000 --- a/regex.subproj/utils.h +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1992, 1993, 1994 - * 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. - */ - -/* utility definitions */ -#define DUPMAX _POSIX2_RE_DUP_MAX /* xxx is this right? */ -#define INFINITY (DUPMAX + 1) -#define NC (CHAR_MAX - CHAR_MIN + 1) -typedef unsigned char uch; - -/* switch off assertions (if not already off) if no REDEBUG */ -#ifndef REDEBUG -#ifndef NDEBUG -#define NDEBUG /* no assertions please */ -#endif -#endif -#include - -/* for old systems with bcopy() but no memmove() */ -#ifdef USEBCOPY -#define memmove(d, s, c) bcopy(s, d, c) -#endif diff --git a/regex/Makefile.inc b/regex/Makefile.inc new file mode 100644 index 0000000..a71b092 --- /dev/null +++ b/regex/Makefile.inc @@ -0,0 +1,17 @@ +# from @(#)Makefile.inc 8.1 (Berkeley) 6/4/93 +# $FreeBSD: src/lib/libc/regex/Makefile.inc,v 1.6 2001/03/27 17:26:51 ru Exp $ + +# regex sources +.PATH: ${.CURDIR}/regex + +CFLAGS+=-DPOSIX_MISTAKE + +SRCS+= regcomp.c regerror.c regexec.c regfree.c + +.if ${LIB} == "c" +MAN3+= regex.3 +MAN7+= re_format.7 + +MLINKS+=regex.3 regcomp.3 regex.3 regexec.3 regex.3 regerror.3 +MLINKS+=regexec.3 regfree.3 +.endif diff --git a/regex/cclass.h b/regex/cclass.h new file mode 100644 index 0000000..028b6ed --- /dev/null +++ b/regex/cclass.h @@ -0,0 +1,88 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1992, 1993, 1994 + * 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. + */ + +/* character-class table */ +static struct cclass { + char *name; + char *chars; + char *multis; +} cclasses[] = { + "alnum", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\ +0123456789", "", + "alpha", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", + "", + "blank", " \t", "", + "cntrl", "\007\b\t\n\v\f\r\1\2\3\4\5\6\16\17\20\21\22\23\24\ +\25\26\27\30\31\32\33\34\35\36\37\177", "", + "digit", "0123456789", "", + "graph", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\ +0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~", + "", + "lower", "abcdefghijklmnopqrstuvwxyz", + "", + "print", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\ +0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ ", + "", + "punct", "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~", + "", + "space", "\t\n\v\f\r ", "", + "upper", "ABCDEFGHIJKLMNOPQRSTUVWXYZ", + "", + "xdigit", "0123456789ABCDEFabcdef", + "", + NULL, 0, "" +}; diff --git a/regex/cname.h b/regex/cname.h new file mode 100644 index 0000000..1abcd7c --- /dev/null +++ b/regex/cname.h @@ -0,0 +1,159 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1992, 1993, 1994 + * 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. + */ + +/* character-name table */ +static const struct cname { + char *name; + char code; +} cnames[] = { + "NUL", '\0', + "SOH", '\001', + "STX", '\002', + "ETX", '\003', + "EOT", '\004', + "ENQ", '\005', + "ACK", '\006', + "BEL", '\007', + "alert", '\007', + "BS", '\010', + "backspace", '\b', + "HT", '\011', + "tab", '\t', + "LF", '\012', + "newline", '\n', + "VT", '\013', + "vertical-tab", '\v', + "FF", '\014', + "form-feed", '\f', + "CR", '\015', + "carriage-return", '\r', + "SO", '\016', + "SI", '\017', + "DLE", '\020', + "DC1", '\021', + "DC2", '\022', + "DC3", '\023', + "DC4", '\024', + "NAK", '\025', + "SYN", '\026', + "ETB", '\027', + "CAN", '\030', + "EM", '\031', + "SUB", '\032', + "ESC", '\033', + "IS4", '\034', + "FS", '\034', + "IS3", '\035', + "GS", '\035', + "IS2", '\036', + "RS", '\036', + "IS1", '\037', + "US", '\037', + "space", ' ', + "exclamation-mark", '!', + "quotation-mark", '"', + "number-sign", '#', + "dollar-sign", '$', + "percent-sign", '%', + "ampersand", '&', + "apostrophe", '\'', + "left-parenthesis", '(', + "right-parenthesis", ')', + "asterisk", '*', + "plus-sign", '+', + "comma", ',', + "hyphen", '-', + "hyphen-minus", '-', + "period", '.', + "full-stop", '.', + "slash", '/', + "solidus", '/', + "zero", '0', + "one", '1', + "two", '2', + "three", '3', + "four", '4', + "five", '5', + "six", '6', + "seven", '7', + "eight", '8', + "nine", '9', + "colon", ':', + "semicolon", ';', + "less-than-sign", '<', + "equals-sign", '=', + "greater-than-sign", '>', + "question-mark", '?', + "commercial-at", '@', + "left-square-bracket", '[', + "backslash", '\\', + "reverse-solidus", '\\', + "right-square-bracket", ']', + "circumflex", '^', + "circumflex-accent", '^', + "underscore", '_', + "low-line", '_', + "grave-accent", '`', + "left-brace", '{', + "left-curly-bracket", '{', + "vertical-line", '|', + "right-brace", '}', + "right-curly-bracket", '}', + "tilde", '~', + "DEL", '\177', + NULL, 0, +}; diff --git a/regex/engine.c b/regex/engine.c new file mode 100644 index 0000000..3f7856a --- /dev/null +++ b/regex/engine.c @@ -0,0 +1,1109 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1992, 1993, 1994 + * 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. + */ + +/* + * The matching engine and friends. This file is #included by regexec.c + * after suitable #defines of a variety of macros used herein, so that + * different state representations can be used without duplicating masses + * of code. + */ + +#ifdef SNAMES +#define matcher smatcher +#define fast sfast +#define slow sslow +#define dissect sdissect +#define backref sbackref +#define step sstep +#define print sprint +#define at sat +#define match smat +#endif +#ifdef LNAMES +#define matcher lmatcher +#define fast lfast +#define slow lslow +#define dissect ldissect +#define backref lbackref +#define step lstep +#define print lprint +#define at lat +#define match lmat +#endif + +/* another structure passed up and down to avoid zillions of parameters */ +struct match { + struct re_guts *g; + int eflags; + regmatch_t *pmatch; /* [nsub+1] (0 element unused) */ + char *offp; /* offsets work from here */ + char *beginp; /* start of string -- virtual NUL precedes */ + char *endp; /* end of string -- virtual NUL here */ + char *coldp; /* can be no match starting before here */ + char **lastpos; /* [nplus+1] */ + STATEVARS; + states st; /* current states */ + states fresh; /* states for a fresh start */ + states tmp; /* temporary */ + states empty; /* empty set of states */ +}; + +/* ========= begin header generated by ./mkh ========= */ +#ifdef __cplusplus +extern "C" { +#endif + +/* === engine.c === */ +static int matcher __P((struct re_guts *g, char *string, size_t nmatch, regmatch_t pmatch[], int eflags)); +static char *dissect __P((struct match *m, char *start, char *stop, sopno startst, sopno stopst)); +static char *backref __P((struct match *m, char *start, char *stop, sopno startst, sopno stopst, sopno lev)); +static char *fast __P((struct match *m, char *start, char *stop, sopno startst, sopno stopst)); +static char *slow __P((struct match *m, char *start, char *stop, sopno startst, sopno stopst)); +static states step __P((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) +#ifdef REDEBUG +static void print __P((struct match *m, char *caption, states st, int ch, FILE *d)); +#endif +#ifdef REDEBUG +static void at __P((struct match *m, char *title, char *start, char *stop, sopno startst, sopno stopst)); +#endif +#ifdef REDEBUG +static char *pchar __P((int ch)); +#endif + +#ifdef __cplusplus +} +#endif +/* ========= end header generated by ./mkh ========= */ + +#ifdef REDEBUG +#define SP(t, s, c) print(m, t, s, c, stdout) +#define AT(t, p1, p2, s1, s2) at(m, t, p1, p2, s1, s2) +#define NOTE(str) { if (m->eflags®_TRACE) printf("=%s\n", (str)); } +#else +#define SP(t, s, c) /* nothing */ +#define AT(t, p1, p2, s1, s2) /* nothing */ +#define NOTE(s) /* nothing */ +#endif + +/* + - matcher - the actual matching engine + == static int matcher(register struct re_guts *g, char *string, \ + == size_t nmatch, regmatch_t pmatch[], int eflags); + */ +static int /* 0 success, REG_NOMATCH failure */ +matcher(g, string, nmatch, pmatch, eflags) +register struct re_guts *g; +char *string; +size_t nmatch; +regmatch_t pmatch[]; +int eflags; +{ + register char *endp; + register int i; + struct match mv; + register struct match *m = &mv; + register char *dp; + const register sopno gf = g->firststate+1; /* +1 for OEND */ + const register sopno gl = g->laststate; + char *start; + char *stop; + + /* simplify the situation where possible */ + if (g->cflags®_NOSUB) + nmatch = 0; + if (eflags®_STARTEND) { + start = string + pmatch[0].rm_so; + stop = string + pmatch[0].rm_eo; + } else { + start = string; + stop = start + strlen(start); + } + if (stop < start) + return(REG_INVARG); + + /* prescreening; this does wonders for this rather slow code */ + if (g->must != NULL) { + for (dp = start; dp < stop; dp++) + if (*dp == g->must[0] && stop - dp >= g->mlen && + memcmp(dp, g->must, (size_t)g->mlen) == 0) + break; + if (dp == stop) /* we didn't find g->must */ + return(REG_NOMATCH); + } + + /* match struct setup */ + m->g = g; + m->eflags = eflags; + m->pmatch = NULL; + m->lastpos = NULL; + m->offp = string; + m->beginp = start; + m->endp = stop; + STATESETUP(m, 4); + SETUP(m->st); + SETUP(m->fresh); + SETUP(m->tmp); + SETUP(m->empty); + CLEAR(m->empty); + + /* this loop does only one repetition except for backrefs */ + for (;;) { + endp = fast(m, start, stop, gf, gl); + if (endp == NULL) { /* a miss */ + STATETEARDOWN(m); + return(REG_NOMATCH); + } + if (nmatch == 0 && !g->backrefs) + break; /* no further info needed */ + + /* where? */ + assert(m->coldp != NULL); + for (;;) { + NOTE("finding start"); + endp = slow(m, m->coldp, stop, gf, gl); + if (endp != NULL) + break; + assert(m->coldp < m->endp); + m->coldp++; + } + if (nmatch == 1 && !g->backrefs) + break; /* no further info needed */ + + /* oh my, he wants the subexpressions... */ + if (m->pmatch == NULL) + m->pmatch = (regmatch_t *)malloc((m->g->nsub + 1) * + sizeof(regmatch_t)); + if (m->pmatch == NULL) { + STATETEARDOWN(m); + return(REG_ESPACE); + } + for (i = 1; i <= m->g->nsub; i++) + m->pmatch[i].rm_so = m->pmatch[i].rm_eo = -1; + if (!g->backrefs && !(m->eflags®_BACKR)) { + NOTE("dissecting"); + dp = dissect(m, m->coldp, endp, gf, gl); + } else { + if (g->nplus > 0 && m->lastpos == NULL) + m->lastpos = (char **)malloc((g->nplus+1) * + sizeof(char *)); + if (g->nplus > 0 && m->lastpos == NULL) { + free(m->pmatch); + STATETEARDOWN(m); + return(REG_ESPACE); + } + NOTE("backref dissect"); + dp = backref(m, m->coldp, endp, gf, gl, (sopno)0); + } + if (dp != NULL) + break; + + /* uh-oh... we couldn't find a subexpression-level match */ + assert(g->backrefs); /* must be back references doing it */ + assert(g->nplus == 0 || m->lastpos != NULL); + for (;;) { + if (dp != NULL || endp <= m->coldp) + break; /* defeat */ + NOTE("backoff"); + endp = slow(m, m->coldp, endp-1, gf, gl); + if (endp == NULL) + break; /* defeat */ + /* try it on a shorter possibility */ +#ifndef NDEBUG + for (i = 1; i <= m->g->nsub; i++) { + assert(m->pmatch[i].rm_so == -1); + assert(m->pmatch[i].rm_eo == -1); + } +#endif + NOTE("backoff dissect"); + dp = backref(m, m->coldp, endp, gf, gl, (sopno)0); + } + assert(dp == NULL || dp == endp); + if (dp != NULL) /* found a shorter one */ + break; + + /* despite initial appearances, there is no match here */ + NOTE("false alarm"); + start = m->coldp + 1; /* recycle starting later */ + assert(start <= stop); + } + + /* fill in the details if requested */ + if (nmatch > 0) { + pmatch[0].rm_so = m->coldp - m->offp; + pmatch[0].rm_eo = endp - m->offp; + } + if (nmatch > 1) { + assert(m->pmatch != NULL); + for (i = 1; i < nmatch; i++) + if (i <= m->g->nsub) + pmatch[i] = m->pmatch[i]; + else { + pmatch[i].rm_so = -1; + pmatch[i].rm_eo = -1; + } + } + + if (m->pmatch != NULL) + free((char *)m->pmatch); + if (m->lastpos != NULL) + free((char *)m->lastpos); + STATETEARDOWN(m); + return(0); +} + +/* + - dissect - figure out what matched what, no back references + == static char *dissect(register struct match *m, char *start, \ + == char *stop, sopno startst, sopno stopst); + */ +static char * /* == stop (success) always */ +dissect(m, start, stop, startst, stopst) +register struct match *m; +char *start; +char *stop; +sopno startst; +sopno stopst; +{ + register int i; + register sopno ss; /* start sop of current subRE */ + register sopno es; /* end sop of current subRE */ + register char *sp; /* start of string matched by it */ + register char *stp; /* string matched by it cannot pass here */ + register char *rest; /* start of rest of string */ + register char *tail; /* string unmatched by rest of RE */ + register sopno ssub; /* start sop of subsubRE */ + register sopno esub; /* end sop of subsubRE */ + register char *ssp; /* start of string matched by subsubRE */ + register char *sep; /* end of string matched by subsubRE */ + register char *oldssp; /* previous ssp */ + register char *dp; + + AT("diss", start, stop, startst, stopst); + sp = start; + for (ss = startst; ss < stopst; ss = es) { + /* identify end of subRE */ + es = ss; + switch (OP(m->g->strip[es])) { + case OPLUS_: + case OQUEST_: + es += OPND(m->g->strip[es]); + break; + case OCH_: + while (OP(m->g->strip[es]) != O_CH) + es += OPND(m->g->strip[es]); + break; + } + es++; + + /* figure out what it matched */ + switch (OP(m->g->strip[ss])) { + case OEND: + assert(nope); + break; + case OCHAR: + sp++; + break; + case OBOL: + case OEOL: + case OBOW: + case OEOW: + break; + case OANY: + case OANYOF: + sp++; + break; + case OBACK_: + case O_BACK: + assert(nope); + break; + /* cases where length of match is hard to find */ + case OQUEST_: + stp = stop; + for (;;) { + /* how long could this one be? */ + rest = slow(m, sp, stp, ss, es); + assert(rest != NULL); /* it did match */ + /* could the rest match the rest? */ + tail = slow(m, rest, stop, es, stopst); + if (tail == stop) + break; /* yes! */ + /* no -- try a shorter match for this one */ + stp = rest - 1; + assert(stp >= sp); /* it did work */ + } + ssub = ss + 1; + esub = es - 1; + /* did innards match? */ + if (slow(m, sp, rest, ssub, esub) != NULL) { + dp = dissect(m, sp, rest, ssub, esub); + assert(dp == rest); + } else /* no */ + assert(sp == rest); + sp = rest; + break; + case OPLUS_: + stp = stop; + for (;;) { + /* how long could this one be? */ + rest = slow(m, sp, stp, ss, es); + assert(rest != NULL); /* it did match */ + /* could the rest match the rest? */ + tail = slow(m, rest, stop, es, stopst); + if (tail == stop) + break; /* yes! */ + /* no -- try a shorter match for this one */ + stp = rest - 1; + assert(stp >= sp); /* it did work */ + } + ssub = ss + 1; + esub = es - 1; + ssp = sp; + oldssp = ssp; + for (;;) { /* find last match of innards */ + sep = slow(m, ssp, rest, ssub, esub); + if (sep == NULL || sep == ssp) + break; /* failed or matched null */ + oldssp = ssp; /* on to next try */ + ssp = sep; + } + if (sep == NULL) { + /* last successful match */ + sep = ssp; + ssp = oldssp; + } + assert(sep == rest); /* must exhaust substring */ + assert(slow(m, ssp, sep, ssub, esub) == rest); + dp = dissect(m, ssp, sep, ssub, esub); + assert(dp == sep); + sp = rest; + break; + case OCH_: + stp = stop; + for (;;) { + /* how long could this one be? */ + rest = slow(m, sp, stp, ss, es); + assert(rest != NULL); /* it did match */ + /* could the rest match the rest? */ + tail = slow(m, rest, stop, es, stopst); + if (tail == stop) + break; /* yes! */ + /* no -- try a shorter match for this one */ + stp = rest - 1; + assert(stp >= sp); /* it did work */ + } + ssub = ss + 1; + esub = ss + OPND(m->g->strip[ss]) - 1; + assert(OP(m->g->strip[esub]) == OOR1); + for (;;) { /* find first matching branch */ + if (slow(m, sp, rest, ssub, esub) == rest) + break; /* it matched all of it */ + /* that one missed, try next one */ + assert(OP(m->g->strip[esub]) == OOR1); + esub++; + assert(OP(m->g->strip[esub]) == OOR2); + ssub = esub + 1; + esub += OPND(m->g->strip[esub]); + if (OP(m->g->strip[esub]) == OOR2) + esub--; + else + assert(OP(m->g->strip[esub]) == O_CH); + } + dp = dissect(m, sp, rest, ssub, esub); + assert(dp == rest); + sp = rest; + break; + case O_PLUS: + case O_QUEST: + case OOR1: + case OOR2: + case O_CH: + assert(nope); + break; + case OLPAREN: + i = OPND(m->g->strip[ss]); + assert(0 < i && i <= m->g->nsub); + m->pmatch[i].rm_so = sp - m->offp; + break; + case ORPAREN: + i = OPND(m->g->strip[ss]); + assert(0 < i && i <= m->g->nsub); + m->pmatch[i].rm_eo = sp - m->offp; + break; + default: /* uh oh */ + assert(nope); + break; + } + } + + assert(sp == stop); + return(sp); +} + +/* + - backref - figure out what matched what, figuring in back references + == static char *backref(register struct match *m, char *start, \ + == char *stop, sopno startst, sopno stopst, sopno lev); + */ +static char * /* == stop (success) or NULL (failure) */ +backref(m, start, stop, startst, stopst, lev) +register struct match *m; +char *start; +char *stop; +sopno startst; +sopno stopst; +sopno lev; /* PLUS nesting level */ +{ + register int i; + register sopno ss; /* start sop of current subRE */ + register char *sp; /* start of string matched by it */ + register sopno ssub; /* start sop of subsubRE */ + register sopno esub; /* end sop of subsubRE */ + register char *ssp; /* start of string matched by subsubRE */ + register char *dp; + register size_t len; + register int hard; + register sop s; + register regoff_t offsave; + register cset *cs; + + AT("back", start, stop, startst, stopst); + sp = start; + + /* get as far as we can with easy stuff */ + hard = 0; + for (ss = startst; !hard && ss < stopst; ss++) + switch (OP(s = m->g->strip[ss])) { + case OCHAR: + if (sp == stop || *sp++ != (char)OPND(s)) + return(NULL); + break; + case OANY: + if (sp == stop) + return(NULL); + sp++; + break; + case OANYOF: + cs = &m->g->sets[OPND(s)]; + if (sp == stop || !CHIN(cs, *sp++)) + return(NULL); + break; + case OBOL: + if ( (sp == m->beginp && !(m->eflags®_NOTBOL)) || + (sp < m->endp && *(sp-1) == '\n' && + (m->g->cflags®_NEWLINE)) ) + { /* yes */ } + else + return(NULL); + break; + case OEOL: + if ( (sp == m->endp && !(m->eflags®_NOTEOL)) || + (sp < m->endp && *sp == '\n' && + (m->g->cflags®_NEWLINE)) ) + { /* yes */ } + else + return(NULL); + break; + case OBOW: + if (( (sp == m->beginp && !(m->eflags®_NOTBOL)) || + (sp < m->endp && *(sp-1) == '\n' && + (m->g->cflags®_NEWLINE)) || + (sp > m->beginp && + !ISWORD(*(sp-1))) ) && + (sp < m->endp && ISWORD(*sp)) ) + { /* yes */ } + else + return(NULL); + break; + case OEOW: + 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))) ) + { /* yes */ } + else + return(NULL); + break; + case O_QUEST: + break; + case OOR1: /* matches null but needs to skip */ + ss++; + s = m->g->strip[ss]; + do { + assert(OP(s) == OOR2); + ss += OPND(s); + } while (OP(s = m->g->strip[ss]) != O_CH); + /* note that the ss++ gets us past the O_CH */ + break; + default: /* have to make a choice */ + hard = 1; + break; + } + if (!hard) { /* that was it! */ + if (sp != stop) + return(NULL); + return(sp); + } + ss--; /* adjust for the for's final increment */ + + /* the hard stuff */ + AT("hard", sp, stop, ss, stopst); + s = m->g->strip[ss]; + switch (OP(s)) { + case OBACK_: /* the vilest depths */ + i = OPND(s); + assert(0 < i && i <= m->g->nsub); + if (m->pmatch[i].rm_eo == -1) + return(NULL); + assert(m->pmatch[i].rm_so != -1); + len = m->pmatch[i].rm_eo - m->pmatch[i].rm_so; + assert(stop - m->beginp >= len); + if (sp > stop - len) + return(NULL); /* not enough left to match */ + ssp = m->offp + m->pmatch[i].rm_so; + if (memcmp(sp, ssp, len) != 0) + return(NULL); + while (m->g->strip[ss] != SOP(O_BACK, i)) + ss++; + return(backref(m, sp+len, stop, ss+1, stopst, lev)); + break; + case OQUEST_: /* to null or not */ + dp = backref(m, sp, stop, ss+1, stopst, lev); + if (dp != NULL) + return(dp); /* not */ + return(backref(m, sp, stop, ss+OPND(s)+1, stopst, lev)); + break; + case OPLUS_: + assert(m->lastpos != NULL); + assert(lev+1 <= m->g->nplus); + m->lastpos[lev+1] = sp; + return(backref(m, sp, stop, ss+1, stopst, lev+1)); + break; + case O_PLUS: + if (sp == m->lastpos[lev]) /* last pass matched null */ + return(backref(m, sp, stop, ss+1, stopst, lev-1)); + /* try another pass */ + m->lastpos[lev] = sp; + dp = backref(m, sp, stop, ss-OPND(s)+1, stopst, lev); + if (dp == NULL) + return(backref(m, sp, stop, ss+1, stopst, lev-1)); + else + return(dp); + break; + case OCH_: /* find the right one, if any */ + ssub = ss + 1; + esub = ss + OPND(s) - 1; + assert(OP(m->g->strip[esub]) == OOR1); + for (;;) { /* find first matching branch */ + dp = backref(m, sp, stop, ssub, esub, lev); + if (dp != NULL) + return(dp); + /* that one missed, try next one */ + if (OP(m->g->strip[esub]) == O_CH) + return(NULL); /* there is none */ + esub++; + assert(OP(m->g->strip[esub]) == OOR2); + ssub = esub + 1; + esub += OPND(m->g->strip[esub]); + if (OP(m->g->strip[esub]) == OOR2) + esub--; + else + assert(OP(m->g->strip[esub]) == O_CH); + } + break; + case OLPAREN: /* must undo assignment if rest fails */ + i = OPND(s); + assert(0 < i && i <= m->g->nsub); + offsave = m->pmatch[i].rm_so; + m->pmatch[i].rm_so = sp - m->offp; + dp = backref(m, sp, stop, ss+1, stopst, lev); + if (dp != NULL) + return(dp); + m->pmatch[i].rm_so = offsave; + return(NULL); + break; + case ORPAREN: /* must undo assignment if rest fails */ + i = OPND(s); + assert(0 < i && i <= m->g->nsub); + offsave = m->pmatch[i].rm_eo; + m->pmatch[i].rm_eo = sp - m->offp; + dp = backref(m, sp, stop, ss+1, stopst, lev); + if (dp != NULL) + return(dp); + m->pmatch[i].rm_eo = offsave; + return(NULL); + break; + default: /* uh oh */ + assert(nope); + break; + } + + /* "can't happen" */ + assert(nope); + /* NOTREACHED */ +} + +/* + - fast - step through the string at top speed + == static char *fast(register struct match *m, char *start, \ + == char *stop, sopno startst, sopno stopst); + */ +static char * /* where tentative match ended, or NULL */ +fast(m, start, stop, startst, stopst) +register struct match *m; +char *start; +char *stop; +sopno startst; +sopno stopst; +{ + register states st = m->st; + register states fresh = m->fresh; + register states tmp = m->tmp; + register char *p = start; + register int c = (start == m->beginp) ? OUT : *(start-1); + register int lastc; /* previous c */ + register int flagch; + register int i; + register char *coldp; /* last p after which no match was underway */ + + CLEAR(st); + SET1(st, startst); + st = step(m->g, startst, stopst, st, NOTHING, st); + ASSIGN(fresh, st); + SP("start", st, *p); + coldp = NULL; + for (;;) { + /* next character */ + lastc = c; + c = (p == m->endp) ? OUT : *p; + if (EQ(st, fresh)) + coldp = p; + + /* is there an EOL and/or BOL between lastc and c? */ + flagch = '\0'; + i = 0; + if ( (lastc == '\n' && m->g->cflags®_NEWLINE) || + (lastc == OUT && !(m->eflags®_NOTBOL)) ) { + flagch = BOL; + i = m->g->nbol; + } + if ( (c == '\n' && m->g->cflags®_NEWLINE) || + (c == OUT && !(m->eflags®_NOTEOL)) ) { + flagch = (flagch == BOL) ? BOLEOL : EOL; + i += m->g->neol; + } + if (i != 0) { + for (; i > 0; i--) + st = step(m->g, startst, stopst, st, flagch, st); + SP("boleol", st, c); + } + + /* how about a word boundary? */ + if ( (flagch == BOL || (lastc != OUT && !ISWORD(lastc))) && + (c != OUT && ISWORD(c)) ) { + flagch = BOW; + } + if ( (lastc != OUT && ISWORD(lastc)) && + (flagch == EOL || (c != OUT && !ISWORD(c))) ) { + flagch = EOW; + } + if (flagch == BOW || flagch == EOW) { + st = step(m->g, startst, stopst, st, flagch, st); + SP("boweow", st, c); + } + + /* are we done? */ + if (ISSET(st, stopst) || p == stop) + break; /* NOTE BREAK OUT */ + + /* no, we must deal with this character */ + ASSIGN(tmp, st); + ASSIGN(st, fresh); + assert(c != OUT); + 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++; + } + + assert(coldp != NULL); + m->coldp = coldp; + if (ISSET(st, stopst)) + return(p+1); + else + return(NULL); +} + +/* + - slow - step through the string more deliberately + == static char *slow(register struct match *m, char *start, \ + == char *stop, sopno startst, sopno stopst); + */ +static char * /* where it ended */ +slow(m, start, stop, startst, stopst) +register struct match *m; +char *start; +char *stop; +sopno startst; +sopno stopst; +{ + register states st = m->st; + register states empty = m->empty; + register states tmp = m->tmp; + register char *p = start; + register int c = (start == m->beginp) ? OUT : *(start-1); + register int lastc; /* previous c */ + register int flagch; + register int i; + register char *matchp; /* last p at which a match ended */ + + AT("slow", start, stop, startst, stopst); + CLEAR(st); + SET1(st, startst); + SP("sstart", st, *p); + st = step(m->g, startst, stopst, st, NOTHING, st); + matchp = NULL; + for (;;) { + /* next character */ + lastc = c; + c = (p == m->endp) ? OUT : *p; + + /* is there an EOL and/or BOL between lastc and c? */ + flagch = '\0'; + i = 0; + if ( (lastc == '\n' && m->g->cflags®_NEWLINE) || + (lastc == OUT && !(m->eflags®_NOTBOL)) ) { + flagch = BOL; + i = m->g->nbol; + } + if ( (c == '\n' && m->g->cflags®_NEWLINE) || + (c == OUT && !(m->eflags®_NOTEOL)) ) { + flagch = (flagch == BOL) ? BOLEOL : EOL; + i += m->g->neol; + } + if (i != 0) { + for (; i > 0; i--) + st = step(m->g, startst, stopst, st, flagch, st); + SP("sboleol", st, c); + } + + /* how about a word boundary? */ + if ( (flagch == BOL || (lastc != OUT && !ISWORD(lastc))) && + (c != OUT && ISWORD(c)) ) { + flagch = BOW; + } + if ( (lastc != OUT && ISWORD(lastc)) && + (flagch == EOL || (c != OUT && !ISWORD(c))) ) { + flagch = EOW; + } + if (flagch == BOW || flagch == EOW) { + st = step(m->g, startst, stopst, st, flagch, st); + SP("sboweow", st, c); + } + + /* are we done? */ + if (ISSET(st, stopst)) + matchp = p; + if (EQ(st, empty) || p == stop) + break; /* NOTE BREAK OUT */ + + /* no, we must deal with this character */ + ASSIGN(tmp, st); + ASSIGN(st, empty); + assert(c != OUT); + 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++; + } + + return(matchp); +} + + +/* + - step - map set of states reachable before char to set reachable after + == static states step(register struct re_guts *g, sopno start, sopno stop, \ + == register states bef, int ch, register 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(g, start, stop, bef, ch, aft) +register struct re_guts *g; +sopno start; /* start state within strip */ +sopno stop; /* state after stop state within strip */ +register states bef; /* states reachable before */ +int ch; /* character or NONCHAR code */ +register states aft; /* states already known reachable after */ +{ + register cset *cs; + register sop s; + register sopno pc; + register onestate here; /* note, macros know this name */ + register sopno look; + register int i; + + for (pc = start, INIT(here, pc); pc != stop; pc++, INC(here)) { + s = g->strip[pc]; + switch (OP(s)) { + case OEND: + assert(pc == stop-1); + break; + case OCHAR: + /* only characters can match */ + assert(!NONCHAR(ch) || ch != (char)OPND(s)); + if (ch == (char)OPND(s)) + FWD(aft, bef, 1); + break; + case OBOL: + if (ch == BOL || ch == BOLEOL) + FWD(aft, bef, 1); + break; + case OEOL: + if (ch == EOL || ch == BOLEOL) + FWD(aft, bef, 1); + break; + case OBOW: + if (ch == BOW) + FWD(aft, bef, 1); + break; + case OEOW: + if (ch == EOW) + FWD(aft, bef, 1); + break; + case OANY: + if (!NONCHAR(ch)) + FWD(aft, bef, 1); + break; + case OANYOF: + cs = &g->sets[OPND(s)]; + if (!NONCHAR(ch) && CHIN(cs, ch)) + FWD(aft, bef, 1); + break; + case OBACK_: /* ignored here */ + case O_BACK: + FWD(aft, aft, 1); + break; + case OPLUS_: /* forward, this is just an empty */ + FWD(aft, aft, 1); + break; + case O_PLUS: /* both forward and back */ + FWD(aft, aft, 1); + i = ISSETBACK(aft, OPND(s)); + BACK(aft, aft, OPND(s)); + if (!i && ISSETBACK(aft, OPND(s))) { + /* oho, must reconsider loop body */ + pc -= OPND(s) + 1; + INIT(here, pc); + } + break; + case OQUEST_: /* two branches, both forward */ + FWD(aft, aft, 1); + FWD(aft, aft, OPND(s)); + break; + case O_QUEST: /* just an empty */ + FWD(aft, aft, 1); + break; + case OLPAREN: /* not significant here */ + case ORPAREN: + FWD(aft, aft, 1); + break; + case OCH_: /* mark the first two branches */ + FWD(aft, aft, 1); + assert(OP(g->strip[pc+OPND(s)]) == OOR2); + FWD(aft, aft, OPND(s)); + break; + case OOR1: /* done a branch, find the O_CH */ + if (ISSTATEIN(aft, here)) { + for (look = 1; + OP(s = g->strip[pc+look]) != O_CH; + look += OPND(s)) + assert(OP(s) == OOR2); + FWD(aft, aft, look); + } + break; + case OOR2: /* propagate OCH_'s marking */ + FWD(aft, aft, 1); + if (OP(g->strip[pc+OPND(s)]) != O_CH) { + assert(OP(g->strip[pc+OPND(s)]) == OOR2); + FWD(aft, aft, OPND(s)); + } + break; + case O_CH: /* just empty */ + FWD(aft, aft, 1); + break; + default: /* ooooops... */ + assert(nope); + break; + } + } + + return(aft); +} + +#ifdef REDEBUG +/* + - print - print a set of states + == #ifdef REDEBUG + == static void print(struct match *m, char *caption, states st, \ + == int ch, FILE *d); + == #endif + */ +static void +print(m, caption, st, ch, d) +struct match *m; +char *caption; +states st; +int ch; +FILE *d; +{ + register struct re_guts *g = m->g; + register int i; + register int first = 1; + + if (!(m->eflags®_TRACE)) + return; + + fprintf(d, "%s", caption); + if (ch != '\0') + fprintf(d, " %s", pchar(ch)); + for (i = 0; i < g->nstates; i++) + if (ISSET(st, i)) { + fprintf(d, "%s%d", (first) ? "\t" : ", ", i); + first = 0; + } + fprintf(d, "\n"); +} + +/* + - at - print current situation + == #ifdef REDEBUG + == static void at(struct match *m, char *title, char *start, char *stop, \ + == sopno startst, sopno stopst); + == #endif + */ +static void +at(m, title, start, stop, startst, stopst) +struct match *m; +char *title; +char *start; +char *stop; +sopno startst; +sopno stopst; +{ + if (!(m->eflags®_TRACE)) + return; + + printf("%s %s-", title, pchar(*start)); + printf("%s ", pchar(*stop)); + printf("%ld-%ld\n", (long)startst, (long)stopst); +} + +#ifndef PCHARDONE +#define PCHARDONE /* never again */ +/* + - pchar - make a character printable + == #ifdef REDEBUG + == static char *pchar(int ch); + == #endif + * + * Is this identical to regchar() over in debug.c? Well, yes. But a + * duplicate here avoids having a debugging-capable regexec.o tied to + * a matching debug.o, and this is convenient. It all disappears in + * the non-debug compilation anyway, so it doesn't matter much. + */ +static char * /* -> representation */ +pchar(ch) +int ch; +{ + static char pbuf[10]; + + if (isprint(ch) || ch == ' ') + sprintf(pbuf, "%c", ch); + else + sprintf(pbuf, "\\%o", ch); + return(pbuf); +} +#endif +#endif + +#undef matcher +#undef fast +#undef slow +#undef dissect +#undef backref +#undef step +#undef print +#undef at +#undef match diff --git a/regex/re_format.7 b/regex/re_format.7 new file mode 100644 index 0000000..32303f2 --- /dev/null +++ b/regex/re_format.7 @@ -0,0 +1,476 @@ +.\" Copyright (c) 1992, 1993, 1994 Henry Spencer. +.\" Copyright (c) 1992, 1993, 1994 +.\" 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. +.\" +.\" @(#)re_format.7 8.3 (Berkeley) 3/20/94 +.\" $FreeBSD: src/lib/libc/regex/re_format.7,v 1.9 2001/07/15 07:53:08 dd Exp $ +.\" +.Dd March 20, 1994 +.Dt RE_FORMAT 7 +.Os +.Sh NAME +.Nm re_format +.Nd POSIX 1003.2 regular expressions +.Sh DESCRIPTION +Regular expressions +.Pq Dq RE Ns s , +as defined in +.St -p1003.2 , +come in two forms: +modern REs (roughly those of +.Xr egrep 1 ; +1003.2 calls these +.Dq extended +REs) +and obsolete REs (roughly those of +.Xr ed 1 ; +1003.2 +.Dq basic +REs). +Obsolete REs mostly exist for backward compatibility in some old programs; +they will be discussed at the end. +.St -p1003.2 +leaves some aspects of RE syntax and semantics open; +`\(dd' marks decisions on these aspects that +may not be fully portable to other +.St -p1003.2 +implementations. +.Pp +A (modern) RE is one\(dd or more non-empty\(dd +.Em branches , +separated by +.Ql \&| . +It matches anything that matches one of the branches. +.Pp +A branch is one\(dd or more +.Em pieces , +concatenated. +It matches a match for the first, followed by a match for the second, etc. +.Pp +A piece is an +.Em atom +possibly followed +by a single\(dd +.Ql \&* , +.Ql \&+ , +.Ql \&? , +or +.Em bound . +An atom followed by +.Ql \&* +matches a sequence of 0 or more matches of the atom. +An atom followed by +.Ql \&+ +matches a sequence of 1 or more matches of the atom. +An atom followed by +.Ql ?\& +matches a sequence of 0 or 1 matches of the atom. +.Pp +A +.Em bound +is +.Ql \&{ +followed by an unsigned decimal integer, +possibly followed by +.Ql \&, +possibly followed by another unsigned decimal integer, +always followed by +.Ql \&} . +The integers must lie between 0 and +.Dv RE_DUP_MAX +(255\(dd) inclusive, +and if there are two of them, the first may not exceed the second. +An atom followed by a bound containing one integer +.Em i +and no comma matches +a sequence of exactly +.Em i +matches of the atom. +An atom followed by a bound +containing one integer +.Em i +and a comma matches +a sequence o +.Em i +or more matches of the atom. +An atom followed by a bound +containing two integers +.Em i +and +.Em j +matches +a sequence of +.Em i +through +.Em j +(inclusive) matches of the atom. +.Pp +An atom is a regular expression enclosed in +.Ql () +(matching a match for the +regular expression), +an empty set of +.Ql () +(matching the null string)\(dd, +a +.Em bracket expression +(see below), +.Ql .\& +(matching any single character), +.Ql \&^ +(matching the null string at the beginning of a line), +.Ql \&$ +(matching the null string at the end of a line), a +.Ql \e +followed by one of the characters +.Ql ^.[$()|*+?{\e +(matching that character taken as an ordinary character), +a +.Ql \e +followed by any other character\(dd +(matching that character taken as an ordinary character, +as if the +.Ql \e +had not been present\(dd), +or a single character with no other significance (matching that character). +A +.Ql \&{ +followed by a character other than a digit is an ordinary +character, not the beginning of a bound\(dd. +It is illegal to end an RE with +.Ql \e . +.Pp +A +.Em bracket expression +is a list of characters enclosed in +.Ql [] . +It normally matches any single character from the list (but see below). +If the list begins with +.Ql \&^ , +it matches any single character +(but see below) +.Em not +from the rest of the list. +If two characters in the list are separated by +.Ql \&- , +this is shorthand +for the full +.Em range +of characters between those two (inclusive) in the +collating sequence, +.No e.g. Ql [0-9] +in ASCII matches any decimal digit. +It is illegal\(dd for two ranges to share an +endpoint, +.No e.g. Ql a-c-e . +Ranges are very collating-sequence-dependent, +and portable programs should avoid relying on them. +.Pp +To include a literal +.Ql \&] +in the list, make it the first character +(following a possible +.Ql \&^ ) . +To include a literal +.Ql \&- , +make it the first or last character, +or the second endpoint of a range. +To use a literal +.Ql \&- +as the first endpoint of a range, +enclose it in +.Ql [.\& +and +.Ql .]\& +to make it a collating element (see below). +With the exception of these and some combinations using +.Ql \&[ +(see next paragraphs), all other special characters, including +.Ql \e , +lose their special significance within a bracket expression. +.Pp +Within a bracket expression, a collating element (a character, +a multi-character sequence that collates as if it were a single character, +or a collating-sequence name for either) +enclosed in +.Ql [.\& +and +.Ql .]\& +stands for the +sequence of characters of that collating element. +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 +.Ql ch +collating element, +then the RE +.Ql [[.ch.]]*c +matches the first five characters +of +.Ql chchcc . +.Pp +Within a bracket expression, a collating element enclosed in +.Ql [= +and +.Ql =] +is an equivalence class, standing for the sequences of characters +of all collating elements equivalent to that one, including itself. +(If there are no other equivalent collating elements, +the treatment is as if the enclosing delimiters were +.Ql [.\& +and +.Ql .] . ) +For example, if +.Ql x +and +.Ql y +are the members of an equivalence class, +then +.Ql [[=x=]] , +.Ql [[=y=]] , +and +.Ql [xy] +are all synonymous. +An equivalence class may not\(dd be an endpoint +of a range. +.Pp +Within a bracket expression, the name of a +.Em character class +enclosed in +.Ql [: +and +.Ql :] +stands for the list of all characters belonging to that +class. +Standard character class names are: +.Pp +.Bl -column "alnum" "digit" "xdigit" -offset indent +.It Em "alnum digit punct" +.It Em "alpha graph space" +.It Em "blank lower upper" +.It Em "cntrl print xdigit" +.El +.Pp +These stand for the character classes defined in +.Xr ctype 3 . +A locale may provide others. +A character class may not be used as an endpoint of a range. +.Pp +There are two special cases\(dd of bracket expressions: +the bracket expressions +.Ql [[:<:]] +and +.Ql [[:>:]] +match the null string at the beginning and end of a word respectively. +A word is defined as a sequence of word characters +which is neither preceded nor followed by +word characters. +A word character is an +.Em alnum +character (as defined by +.Xr ctype 3 ) +or an underscore. +This is an extension, +compatible with but not specified by +.St -p1003.2 , +and should be used with +caution in software intended to be portable to other systems. +.Pp +In the event that an RE could match more than one substring of a given +string, +the RE matches the one starting earliest in the string. +If the RE could match more than one substring starting at that point, +it matches the longest. +Subexpressions also match the longest possible substrings, subject to +the constraint that the whole match be as long as possible, +with subexpressions starting earlier in the RE taking priority over +ones starting later. +Note that higher-level subexpressions thus take priority over +their lower-level component subexpressions. +.Pp +Match lengths are measured in characters, not collating elements. +A null string is considered longer than no match at all. +For example, +.Ql bb* +matches the three middle characters of +.Ql abbbc , +.Ql (wee|week)(knights|nights) +matches all ten characters of +.Ql weeknights , +when +.Ql (.*).*\& +is matched against +.Ql abc +the parenthesized subexpression +matches all three characters, and +when +.Ql (a*)* +is matched against +.Ql bc +both the whole RE and the parenthesized +subexpression match the null string. +.Pp +If case-independent matching is specified, +the effect is much as if all case distinctions had vanished from the +alphabet. +When an alphabetic that exists in multiple cases appears as an +ordinary character outside a bracket expression, it is effectively +transformed into a bracket expression containing both cases, +.No e.g. Ql x +becomes +.Ql [xX] . +When it appears inside a bracket expression, all case counterparts +of it are added to the bracket expression, so that (e.g.) +.Ql [x] +becomes +.Ql [xX] +and +.Ql [^x] +becomes +.Ql [^xX] . +.Pp +No particular limit is imposed on the length of REs\(dd. +Programs intended to be portable should not employ REs longer +than 256 bytes, +as an implementation can refuse to accept such REs and remain +POSIX-compliant. +.Pp +Obsolete +.Pq Dq basic +regular expressions differ in several respects. +.Ql \&| +is an ordinary character and there is no equivalent +for its functionality. +.Ql \&+ +and +.Ql ?\& +are ordinary characters, and their functionality +can be expressed using bounds +.No ( Ql {1,} +or +.Ql {0,1} +respectively). +Also note that +.Ql x+ +in modern REs is equivalent to +.Ql xx* . +The delimiters for bounds are +.Ql \e{ +and +.Ql \e} , +with +.Ql \&{ +and +.Ql \&} +by themselves ordinary characters. +The parentheses for nested subexpressions are +.Ql \e( +and +.Ql \e) , +with +.Ql \&( +and +.Ql \&) +by themselves ordinary characters. +.Ql \&^ +is an ordinary character except at the beginning of the +RE or\(dd the beginning of a parenthesized subexpression, +.Ql \&$ +is an ordinary character except at the end of the +RE or\(dd the end of a parenthesized subexpression, +and +.Ql \&* +is an ordinary character if it appears at the beginning of the +RE or the beginning of a parenthesized subexpression +(after a possible leading +.Ql \&^ ) . +Finally, there is one new type of atom, a +.Em back reference : +.Ql \e +followed by a non-zero decimal digit +.Em d +matches the same sequence of characters +matched by the +.Em d Ns th +parenthesized subexpression +(numbering subexpressions by the positions of their opening parentheses, +left to right), +so that (e.g.) +.Ql \e([bc]\e)\e1 +matches +.Ql bb +or +.Ql cc +but not +.Ql bc . +.Sh SEE ALSO +.Xr regex 3 +.Rs +.%T Regular Expression Notation +.%R IEEE Std +.%N 1003.2 +.%P section 2.8 +.Re +.Sh BUGS +Having two kinds of REs is a botch. +.Pp +The current +.St -p1003.2 +spec says that +.Ql \&) +is an ordinary character in +the absence of an unmatched +.Ql \&( ; +this was an unintentional result of a wording error, +and change is likely. +Avoid relying on it. +.Pp +Back references are a dreadful botch, +posing major problems for efficient implementations. +They are also somewhat vaguely defined +(does +.Ql a\e(\e(b\e)*\e2\e)*d +match +.Ql abbbd ? ) . +Avoid using them. +.Pp +.St -p1003.2 +specification of case-independent matching is vague. +The +.Dq one case implies all cases +definition given above +is current consensus among implementors as to the right interpretation. +.Pp +The syntax for word boundaries is incredibly ugly. diff --git a/regex/regcomp.c b/regex/regcomp.c new file mode 100644 index 0000000..e2e0bf3 --- /dev/null +++ b/regex/regcomp.c @@ -0,0 +1,1712 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1992, 1993, 1994 + * 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. + */ + +#include +#include +#include +#include +#include +#include +#include + +#include "utils.h" +#include "regex2.h" + +#include "cclass.h" +#include "cname.h" + +/* + * parse structure, passed up and down to avoid global variables and + * other clumsinesses + */ +struct parse { + char *next; /* next character in RE */ + char *end; /* end of string (-> NUL normally) */ + int error; /* has an error been seen? */ + sop *strip; /* malloced strip */ + sopno ssize; /* malloced strip size (allocated) */ + sopno slen; /* malloced strip length (used) */ + int ncsalloc; /* number of csets allocated */ + struct re_guts *g; +# define NPAREN 10 /* we need to remember () 1-9 for back refs */ + sopno pbegin[NPAREN]; /* -> ( ([0] unused) */ + sopno pend[NPAREN]; /* -> ) ([0] unused) */ +}; + +/* ========= begin header generated by ./mkh ========= */ +#ifdef __cplusplus +extern "C" { +#endif + +/* === regcomp.c === */ +static void p_ere __P((struct parse *p, int stop)); +static void p_ere_exp __P((struct parse *p)); +static void p_str __P((struct parse *p)); +static void p_bre __P((struct parse *p, int end1, int end2)); +static int p_simp_re __P((struct parse *p, int starordinary)); +static int p_count __P((struct parse *p)); +static void p_bracket __P((struct parse *p)); +static void p_b_term __P((struct parse *p, cset *cs)); +static void p_b_cclass __P((struct parse *p, cset *cs)); +static void p_b_eclass __P((struct parse *p, cset *cs)); +static char p_b_symbol __P((struct parse *p)); +static char p_b_coll_elem __P((struct parse *p, int endc)); +static char othercase __P((int ch)); +static void bothcases __P((struct parse *p, int ch)); +static void ordinary __P((struct parse *p, int ch)); +static void nonnewline __P((struct parse *p)); +static void repeat __P((struct parse *p, sopno start, int from, int to)); +static int seterr __P((struct parse *p, int e)); +static cset *allocset __P((struct parse *p)); +static void freeset __P((struct parse *p, cset *cs)); +static int freezeset __P((struct parse *p, cset *cs)); +static int firstch __P((struct parse *p, cset *cs)); +static int nch __P((struct parse *p, cset *cs)); +static void mcadd __P((struct parse *p, cset *cs, char *cp)); +static void mcsub __P((cset *cs, char *cp)); +static int mcin __P((cset *cs, char *cp)); +static char *mcfind __P((cset *cs, char *cp)); +static void mcinvert __P((struct parse *p, cset *cs)); +static void mccase __P((struct parse *p, cset *cs)); +static int isinsets __P((struct re_guts *g, int c)); +static int samesets __P((struct re_guts *g, int c1, int c2)); +static void categorize __P((struct parse *p, struct re_guts *g)); +static sopno dupl __P((struct parse *p, sopno start, sopno finish)); +static void doemit __P((struct parse *p, sop op, size_t opnd)); +static void doinsert __P((struct parse *p, sop op, size_t opnd, sopno pos)); +static void dofwd __P((struct parse *p, sopno pos, sop value)); +static void enlarge __P((struct parse *p, sopno size)); +static void stripsnug __P((struct parse *p, struct re_guts *g)); +static void findmust __P((struct parse *p, struct re_guts *g)); +static sopno pluscount __P((struct parse *p, struct re_guts *g)); + +#ifdef __cplusplus +} +#endif +/* ========= end header generated by ./mkh ========= */ + +static char nuls[10]; /* place to point scanner in event of error */ + +/* + * macros for use with parse structure + * BEWARE: these know that the parse structure is named `p' !!! + */ +#define PEEK() (*p->next) +#define PEEK2() (*(p->next+1)) +#define MORE() (p->next < p->end) +#define MORE2() (p->next+1 < p->end) +#define SEE(c) (MORE() && PEEK() == (c)) +#define SEETWO(a, b) (MORE() && MORE2() && PEEK() == (a) && PEEK2() == (b)) +#define EAT(c) ((SEE(c)) ? (NEXT(), 1) : 0) +#define EATTWO(a, b) ((SEETWO(a, b)) ? (NEXT2(), 1) : 0) +#define NEXT() (p->next++) +#define NEXT2() (p->next += 2) +#define NEXTn(n) (p->next += (n)) +#define GETNEXT() (*p->next++) +#define SETERROR(e) seterr(p, (e)) +#define REQUIRE(co, e) ((co) || SETERROR(e)) +#define MUSTSEE(c, e) (REQUIRE(MORE() && PEEK() == (c), e)) +#define MUSTEAT(c, e) (REQUIRE(MORE() && GETNEXT() == (c), e)) +#define MUSTNOTSEE(c, e) (REQUIRE(!MORE() || PEEK() != (c), e)) +#define EMIT(op, sopnd) doemit(p, (sop)(op), (size_t)(sopnd)) +#define INSERT(op, pos) doinsert(p, (sop)(op), HERE()-(pos)+1, pos) +#define AHEAD(pos) dofwd(p, pos, HERE()-(pos)) +#define ASTERN(sop, pos) EMIT(sop, HERE()-pos) +#define HERE() (p->slen) +#define THERE() (p->slen - 1) +#define THERETHERE() (p->slen - 2) +#define DROP(n) (p->slen -= (n)) + +#ifndef NDEBUG +static int never = 0; /* for use in asserts; shuts lint up */ +#else +#define never 0 /* some s have bugs too */ +#endif + +/* + - regcomp - interface for parser and compilation + = extern int regcomp(regex_t *, const char *, int); + = #define REG_BASIC 0000 + = #define REG_EXTENDED 0001 + = #define REG_ICASE 0002 + = #define REG_NOSUB 0004 + = #define REG_NEWLINE 0010 + = #define REG_NOSPEC 0020 + = #define REG_PEND 0040 + = #define REG_DUMP 0200 + */ +int /* 0 success, otherwise REG_something */ +regcomp(preg, pattern, cflags) +regex_t *preg; +const char *pattern; +int cflags; +{ + struct parse pa; + register struct re_guts *g; + register struct parse *p = &pa; + register int i; + register size_t len; +#ifdef REDEBUG +# define GOODFLAGS(f) (f) +#else +# define GOODFLAGS(f) ((f)&~REG_DUMP) +#endif + + cflags = GOODFLAGS(cflags); + if ((cflags®_EXTENDED) && (cflags®_NOSPEC)) + return(REG_INVARG); + + if (cflags®_PEND) { + if (preg->re_endp < pattern) + return(REG_INVARG); + len = preg->re_endp - pattern; + } else + 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)); + if (g == NULL) + return(REG_ESPACE); + p->ssize = len/(size_t)2*(size_t)3 + (size_t)1; /* ugh */ + p->strip = (sop *)malloc(p->ssize * sizeof(sop)); + p->slen = 0; + if (p->strip == NULL) { + free((char *)g); + return(REG_ESPACE); + } + + /* set things up */ + p->g = g; + p->next = (char *)pattern; /* convenience; we do not modify it */ + p->end = p->next + len; + p->error = 0; + p->ncsalloc = 0; + for (i = 0; i < NPAREN; i++) { + 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->nbol = 0; + g->neol = 0; + g->must = 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 */ + EMIT(OEND, 0); + g->firststate = THERE(); + if (cflags®_EXTENDED) + p_ere(p, OUT); + else if (cflags®_NOSPEC) + p_str(p); + else + p_bre(p, OUT, OUT); + EMIT(OEND, 0); + g->laststate = THERE(); + + /* tidy up loose ends and fill things in */ + categorize(p, g); + stripsnug(p, g); + findmust(p, g); + g->nplus = pluscount(p, g); + g->magic = MAGIC2; + preg->re_nsub = g->nsub; + preg->re_g = g; + preg->re_magic = MAGIC1; +#ifndef REDEBUG + /* not debugging, so can't rely on the assert() in regexec() */ + if (g->iflags&BAD) + SETERROR(REG_ASSERT); +#endif + + /* win or lose, we're done */ + if (p->error != 0) /* lose */ + regfree(preg); + return(p->error); +} + +/* + - p_ere - ERE parser top level, concatenation and alternation + == static void p_ere(register struct parse *p, int stop); + */ +static void +p_ere(p, stop) +register struct parse *p; +int stop; /* character this ERE should end at */ +{ + register char c; + register sopno prevback; + register sopno prevfwd; + register sopno conc; + register int first = 1; /* is this the first alternative? */ + + for (;;) { + /* do a bunch of concatenated expressions */ + conc = HERE(); + while (MORE() && (c = PEEK()) != '|' && c != stop) + p_ere_exp(p); + REQUIRE(HERE() != conc, REG_EMPTY); /* require nonempty */ + + if (!EAT('|')) + break; /* NOTE BREAK OUT */ + + if (first) { + INSERT(OCH_, conc); /* offset is wrong */ + prevfwd = conc; + prevback = conc; + first = 0; + } + ASTERN(OOR1, prevback); + prevback = THERE(); + AHEAD(prevfwd); /* fix previous offset */ + prevfwd = HERE(); + EMIT(OOR2, 0); /* offset is very wrong */ + } + + if (!first) { /* tail-end fixups */ + AHEAD(prevfwd); + ASTERN(O_CH, prevback); + } + + assert(!MORE() || SEE(stop)); +} + +/* + - p_ere_exp - parse one subERE, an atom possibly followed by a repetition op + == static void p_ere_exp(register struct parse *p); + */ +static void +p_ere_exp(p) +register struct parse *p; +{ + register char c; + register sopno pos; + register int count; + register int count2; + register sopno subno; + int wascaret = 0; + + assert(MORE()); /* caller should have ensured this */ + c = GETNEXT(); + + pos = HERE(); + switch (c) { + case '(': + REQUIRE(MORE(), REG_EPAREN); + p->g->nsub++; + subno = p->g->nsub; + if (subno < NPAREN) + p->pbegin[subno] = HERE(); + EMIT(OLPAREN, subno); + if (!SEE(')')) + p_ere(p, ')'); + if (subno < NPAREN) { + p->pend[subno] = HERE(); + assert(p->pend[subno] != 0); + } + EMIT(ORPAREN, subno); + MUSTEAT(')', REG_EPAREN); + break; +#ifndef POSIX_MISTAKE + case ')': /* happens only if no current unmatched ( */ + /* + * You may ask, why the ifndef? Because I didn't notice + * this until slightly too late for 1003.2, and none of the + * other 1003.2 regular-expression reviewers noticed it at + * all. So an unmatched ) is legal POSIX, at least until + * we can get it fixed. + */ + SETERROR(REG_EPAREN); + break; +#endif + case '^': + EMIT(OBOL, 0); + p->g->iflags |= USEBOL; + p->g->nbol++; + wascaret = 1; + break; + case '$': + EMIT(OEOL, 0); + p->g->iflags |= USEEOL; + p->g->neol++; + break; + case '|': + SETERROR(REG_EMPTY); + break; + case '*': + case '+': + case '?': + SETERROR(REG_BADRPT); + break; + case '.': + if (p->g->cflags®_NEWLINE) + nonnewline(p); + else + EMIT(OANY, 0); + break; + case '[': + p_bracket(p); + break; + case '\\': + REQUIRE(MORE(), REG_EESCAPE); + c = GETNEXT(); + ordinary(p, c); + break; + case '{': /* okay as ordinary except if digit follows */ + REQUIRE(!MORE() || !isdigit(PEEK()), REG_BADRPT); + /* FALLTHROUGH */ + default: + ordinary(p, c); + break; + } + + if (!MORE()) + return; + c = PEEK(); + /* we call { a repetition if followed by a digit */ + if (!( c == '*' || c == '+' || c == '?' || + (c == '{' && MORE2() && isdigit(PEEK2())) )) + return; /* no repetition, we're done */ + NEXT(); + + REQUIRE(!wascaret, REG_BADRPT); + switch (c) { + case '*': /* implemented as +? */ + /* this case does not require the (y|) trick, noKLUDGE */ + INSERT(OPLUS_, pos); + ASTERN(O_PLUS, pos); + INSERT(OQUEST_, pos); + ASTERN(O_QUEST, pos); + break; + case '+': + INSERT(OPLUS_, pos); + ASTERN(O_PLUS, pos); + break; + case '?': + /* KLUDGE: emit y? as (y|) until subtle bug gets fixed */ + INSERT(OCH_, pos); /* offset slightly wrong */ + ASTERN(OOR1, pos); /* this one's right */ + AHEAD(pos); /* fix the OCH_ */ + EMIT(OOR2, 0); /* offset very wrong... */ + AHEAD(THERE()); /* ...so fix it */ + ASTERN(O_CH, THERETHERE()); + break; + case '{': + count = p_count(p); + if (EAT(',')) { + if (isdigit(PEEK())) { + count2 = p_count(p); + REQUIRE(count <= count2, REG_BADBR); + } else /* single number with comma */ + count2 = INFINITY; + } else /* just a single number */ + count2 = count; + repeat(p, pos, count, count2); + if (!EAT('}')) { /* error heuristics */ + while (MORE() && PEEK() != '}') + NEXT(); + REQUIRE(MORE(), REG_EBRACE); + SETERROR(REG_BADBR); + } + break; + } + + if (!MORE()) + return; + c = PEEK(); + if (!( c == '*' || c == '+' || c == '?' || + (c == '{' && MORE2() && isdigit(PEEK2())) ) ) + return; + SETERROR(REG_BADRPT); +} + +/* + - p_str - string (no metacharacters) "parser" + == static void p_str(register struct parse *p); + */ +static void +p_str(p) +register struct parse *p; +{ + REQUIRE(MORE(), REG_EMPTY); + while (MORE()) + ordinary(p, GETNEXT()); +} + +/* + - p_bre - BRE parser top level, anchoring and concatenation + == static void p_bre(register struct parse *p, register int end1, \ + == register int end2); + * 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. + * The amount of lookahead needed to avoid this kludge is excessive. + */ +static void +p_bre(p, end1, end2) +register struct parse *p; +register int end1; /* first terminating character */ +register int end2; /* second terminating character */ +{ + register sopno start = HERE(); + register int first = 1; /* first subexpression? */ + register int wasdollar = 0; + + if (EAT('^')) { + EMIT(OBOL, 0); + p->g->iflags |= USEBOL; + p->g->nbol++; + } + while (MORE() && !SEETWO(end1, end2)) { + wasdollar = p_simp_re(p, first); + first = 0; + } + if (wasdollar) { /* oops, that was a trailing anchor */ + DROP(1); + EMIT(OEOL, 0); + p->g->iflags |= USEEOL; + p->g->neol++; + } + + REQUIRE(HERE() != start, REG_EMPTY); /* require nonempty */ +} + +/* + - p_simp_re - parse a simple RE, an atom possibly followed by a repetition + == static int p_simp_re(register struct parse *p, int starordinary); + */ +static int /* was the simple RE an unbackslashed $? */ +p_simp_re(p, starordinary) +register struct parse *p; +int starordinary; /* is a leading * an ordinary character? */ +{ + register int c; + register int count; + register int count2; + register sopno pos; + register int i; + register sopno subno; +# define BACKSL (1<g->cflags®_NEWLINE) + nonnewline(p); + else + EMIT(OANY, 0); + break; + case '[': + p_bracket(p); + break; + case BACKSL|'{': + SETERROR(REG_BADRPT); + break; + case BACKSL|'(': + p->g->nsub++; + subno = p->g->nsub; + if (subno < NPAREN) + p->pbegin[subno] = HERE(); + EMIT(OLPAREN, subno); + /* the MORE here is an error heuristic */ + if (MORE() && !SEETWO('\\', ')')) + p_bre(p, '\\', ')'); + if (subno < NPAREN) { + p->pend[subno] = HERE(); + assert(p->pend[subno] != 0); + } + EMIT(ORPAREN, subno); + REQUIRE(EATTWO('\\', ')'), REG_EPAREN); + break; + case BACKSL|')': /* should not get here -- must be user */ + case BACKSL|'}': + SETERROR(REG_EPAREN); + break; + case BACKSL|'1': + case BACKSL|'2': + case BACKSL|'3': + case BACKSL|'4': + case BACKSL|'5': + case BACKSL|'6': + case BACKSL|'7': + case BACKSL|'8': + case BACKSL|'9': + i = (c&~BACKSL) - '0'; + assert(i < NPAREN); + if (p->pend[i] != 0) { + assert(i <= p->g->nsub); + EMIT(OBACK_, i); + assert(p->pbegin[i] != 0); + assert(OP(p->strip[p->pbegin[i]]) == OLPAREN); + assert(OP(p->strip[p->pend[i]]) == ORPAREN); + (void) dupl(p, p->pbegin[i]+1, p->pend[i]); + EMIT(O_BACK, i); + } else + SETERROR(REG_ESUBREG); + p->g->backrefs = 1; + break; + case '*': + REQUIRE(starordinary, REG_BADRPT); + /* FALLTHROUGH */ + default: + ordinary(p, c &~ BACKSL); + break; + } + + if (EAT('*')) { /* implemented as +? */ + /* this case does not require the (y|) trick, noKLUDGE */ + INSERT(OPLUS_, pos); + ASTERN(O_PLUS, pos); + INSERT(OQUEST_, pos); + ASTERN(O_QUEST, pos); + } else if (EATTWO('\\', '{')) { + count = p_count(p); + if (EAT(',')) { + if (MORE() && isdigit(PEEK())) { + count2 = p_count(p); + REQUIRE(count <= count2, REG_BADBR); + } else /* single number with comma */ + count2 = INFINITY; + } else /* just a single number */ + count2 = count; + repeat(p, pos, count, count2); + if (!EATTWO('\\', '}')) { /* error heuristics */ + while (MORE() && !SEETWO('\\', '}')) + NEXT(); + REQUIRE(MORE(), REG_EBRACE); + SETERROR(REG_BADBR); + } + } else if (c == (unsigned char)'$') /* $ (but not \$) ends it */ + return(1); + + return(0); +} + +/* + - p_count - parse a repetition count + == static int p_count(register struct parse *p); + */ +static int /* the value */ +p_count(p) +register struct parse *p; +{ + register int count = 0; + register int ndigits = 0; + + while (MORE() && isdigit(PEEK()) && count <= DUPMAX) { + count = count*10 + (GETNEXT() - '0'); + ndigits++; + } + + REQUIRE(ndigits > 0 && count <= DUPMAX, REG_BADBR); + return(count); +} + +/* + - p_bracket - parse a bracketed character list + == static void p_bracket(register 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) +register struct parse *p; +{ + register char c; + register cset *cs = allocset(p); + register int invert = 0; + + /* Dept of Truly Sickening Special-Case Kludges */ + if (p->next + 5 < p->end && strncmp(p->next, "[:<:]]", 6) == 0) { + EMIT(OBOW, 0); + NEXTn(6); + return; + } + if (p->next + 5 < p->end && strncmp(p->next, "[:>:]]", 6) == 0) { + EMIT(OEOW, 0); + NEXTn(6); + return; + } + + if (EAT('^')) + invert++; /* make note to invert set at end */ + if (EAT(']')) + CHadd(cs, ']'); + else if (EAT('-')) + CHadd(cs, '-'); + while (MORE() && PEEK() != ']' && !SEETWO('-', ']')) + p_b_term(p, cs); + if (EAT('-')) + CHadd(cs, '-'); + MUSTEAT(']', REG_EBRACK); + + if (p->error != 0) /* don't mess things up further */ + return; + + if (p->g->cflags®_ICASE) { + register int i; + register 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) { + register 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 (nch(p, cs) == 1) { /* optimize singleton sets */ + ordinary(p, firstch(p, cs)); + freeset(p, cs); + } else + EMIT(OANYOF, freezeset(p, cs)); +} + +/* + - p_b_term - parse one term of a bracketed character list + == static void p_b_term(register struct parse *p, register cset *cs); + */ +static void +p_b_term(p, cs) +register struct parse *p; +register cset *cs; +{ + register char c; + register char start, finish; + register int i; + + /* classify what we've got */ + switch ((MORE()) ? PEEK() : '\0') { + case '[': + c = (MORE2()) ? PEEK2() : '\0'; + break; + case '-': + SETERROR(REG_ERANGE); + return; /* NOTE RETURN */ + break; + default: + c = '\0'; + break; + } + + switch (c) { + case ':': /* character class */ + NEXT2(); + REQUIRE(MORE(), REG_EBRACK); + c = PEEK(); + REQUIRE(c != '-' && c != ']', REG_ECTYPE); + p_b_cclass(p, cs); + REQUIRE(MORE(), REG_EBRACK); + REQUIRE(EATTWO(':', ']'), REG_ECTYPE); + break; + case '=': /* equivalence class */ + NEXT2(); + REQUIRE(MORE(), REG_EBRACK); + c = PEEK(); + REQUIRE(c != '-' && c != ']', REG_ECOLLATE); + p_b_eclass(p, cs); + REQUIRE(MORE(), REG_EBRACK); + 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 */ + NEXT(); + if (EAT('-')) + finish = '-'; + else + finish = p_b_symbol(p); + } else + finish = start; +/* xxx what about signed chars here... */ + REQUIRE(start <= finish, REG_ERANGE); + for (i = start; i <= finish; i++) + CHadd(cs, i); + break; + } +} + +/* + - p_b_cclass - parse a character-class name and deal with it + == static void p_b_cclass(register struct parse *p, register cset *cs); + */ +static void +p_b_cclass(p, cs) +register struct parse *p; +register cset *cs; +{ + register char *sp = p->next; + register struct cclass *cp; + register size_t len; + register char *u; + register char c; + + while (MORE() && isalpha(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 */ + SETERROR(REG_ECTYPE); + return; + } + + u = cp->chars; + while ((c = *u++) != '\0') + CHadd(cs, c); + for (u = cp->multis; *u != '\0'; u += strlen(u) + 1) + MCadd(p, cs, u); +} + +/* + - p_b_eclass - parse an equivalence-class name and deal with it + == static void p_b_eclass(register struct parse *p, register cset *cs); + * + * This implementation is incomplete. xxx + */ +static void +p_b_eclass(p, cs) +register struct parse *p; +register cset *cs; +{ + register char c; + + c = p_b_coll_elem(p, '='); + CHadd(cs, c); +} + +/* + - p_b_symbol - parse a character or [..]ed multicharacter collating symbol + == static char p_b_symbol(register struct parse *p); + */ +static char /* value of symbol */ +p_b_symbol(p) +register struct parse *p; +{ + register char value; + + REQUIRE(MORE(), REG_EBRACK); + if (!EATTWO('[', '.')) + return(GETNEXT()); + + /* collating symbol */ + value = p_b_coll_elem(p, '.'); + REQUIRE(EATTWO('.', ']'), REG_ECOLLATE); + return(value); +} + +/* + - p_b_coll_elem - parse a collating-element name and look it up + == static char p_b_coll_elem(register struct parse *p, int endc); + */ +static char /* value of collating element */ +p_b_coll_elem(p, endc) +register struct parse *p; +int endc; /* name ended by endc,']' */ +{ + register char *sp = p->next; + register struct cname *cp; + register int len; + register char c; + + while (MORE() && !SEETWO(endc, ']')) + NEXT(); + if (!MORE()) { + SETERROR(REG_EBRACK); + return(0); + } + len = p->next - sp; + 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 */ + return(0); +} + +/* + - othercase - return the case counterpart of an alphabetic + == static char othercase(int ch); + */ +static char /* if no counterpart, return ch */ +othercase(ch) +int ch; +{ + assert(isalpha(ch)); + if (isupper(ch)) + return(tolower(ch)); + else if (islower(ch)) + return(toupper(ch)); + else /* peculiar, but could happen */ + return(ch); +} + +/* + - bothcases - emit a dualcase version of a two-case character + == static void bothcases(register struct parse *p, int ch); + * + * Boy, is this implementation ever a kludge... + */ +static void +bothcases(p, ch) +register struct parse *p; +int ch; +{ + register char *oldnext = p->next; + register char *oldend = p->end; + char bracket[3]; + + assert(othercase(ch) != ch); /* p_bracket() would recurse */ + p->next = bracket; + p->end = bracket+2; + bracket[0] = ch; + bracket[1] = ']'; + bracket[2] = '\0'; + p_bracket(p); + assert(p->next == bracket+2); + p->next = oldnext; + p->end = oldend; +} + +/* + - ordinary - emit an ordinary character + == static void ordinary(register struct parse *p, register int ch); + */ +static void +ordinary(p, ch) +register struct parse *p; +register int ch; +{ + register cat_t *cap = p->g->categories; + + if ((p->g->cflags®_ICASE) && isalpha(ch) && othercase(ch) != ch) + bothcases(p, ch); + else { + EMIT(OCHAR, (unsigned char)ch); + if (cap[ch] == 0) + cap[ch] = p->g->ncategories++; + } +} + +/* + - nonnewline - emit REG_NEWLINE version of OANY + == static void nonnewline(register struct parse *p); + * + * Boy, is this implementation ever a kludge... + */ +static void +nonnewline(p) +register struct parse *p; +{ + register char *oldnext = p->next; + register char *oldend = p->end; + char bracket[4]; + + p->next = bracket; + p->end = bracket+3; + bracket[0] = '^'; + bracket[1] = '\n'; + bracket[2] = ']'; + bracket[3] = '\0'; + p_bracket(p); + assert(p->next == bracket+3); + p->next = oldnext; + p->end = oldend; +} + +/* + - repeat - generate code for a bounded repetition, recursively if needed + == static void repeat(register struct parse *p, sopno start, int from, int to); + */ +static void +repeat(p, start, from, to) +register struct parse *p; +sopno start; /* operand from here to end of strip */ +int from; /* repeated from this number */ +int to; /* to this number of times (maybe INFINITY) */ +{ + register sopno finish = HERE(); +# define N 2 +# define INF 3 +# define REP(f, t) ((f)*8 + (t)) +# define MAP(n) (((n) <= 1) ? (n) : ((n) == INFINITY) ? INF : N) + register sopno copy; + + if (p->error != 0) /* head off possible runaway recursion */ + return; + + assert(from <= to); + + switch (REP(MAP(from), MAP(to))) { + case REP(0, 0): /* must be user doing this */ + DROP(finish-start); /* drop the operand */ + break; + case REP(0, 1): /* as x{1,1}? */ + case REP(0, N): /* as x{1,n}? */ + case REP(0, INF): /* as x{1,}? */ + /* KLUDGE: emit y? as (y|) until subtle bug gets fixed */ + INSERT(OCH_, start); /* offset is wrong... */ + repeat(p, start+1, 1, to); + ASTERN(OOR1, start); + AHEAD(start); /* ... fix it */ + EMIT(OOR2, 0); + AHEAD(THERE()); + ASTERN(O_CH, THERETHERE()); + break; + case REP(1, 1): /* trivial case */ + /* done */ + break; + case REP(1, N): /* as x?x{1,n-1} */ + /* KLUDGE: emit y? as (y|) until subtle bug gets fixed */ + INSERT(OCH_, start); + ASTERN(OOR1, start); + AHEAD(start); + EMIT(OOR2, 0); /* offset very wrong... */ + AHEAD(THERE()); /* ...so fix it */ + ASTERN(O_CH, THERETHERE()); + copy = dupl(p, start+1, finish+1); + assert(copy == finish+4); + repeat(p, copy, 1, to-1); + break; + case REP(1, INF): /* as x+ */ + INSERT(OPLUS_, start); + ASTERN(O_PLUS, start); + break; + case REP(N, N): /* as xx{m-1,n-1} */ + copy = dupl(p, start, finish); + repeat(p, copy, from-1, to-1); + break; + case REP(N, INF): /* as xx{n-1,INF} */ + copy = dupl(p, start, finish); + repeat(p, copy, from-1, to); + break; + default: /* "can't happen" */ + SETERROR(REG_ASSERT); /* just in case */ + break; + } +} + +/* + - seterr - set an error condition + == static int seterr(register struct parse *p, int e); + */ +static int /* useless but makes type checking happy */ +seterr(p, e) +register struct parse *p; +int e; +{ + if (p->error == 0) /* keep earliest error condition */ + p->error = e; + p->next = nuls; /* try to bring things to a halt */ + p->end = nuls; + return(0); /* make the return value well-defined */ +} + +/* + - allocset - allocate a set of characters for [] + == static cset *allocset(register struct parse *p); + */ +static cset * +allocset(p) +register struct parse *p; +{ + register int no = p->g->ncsets++; + register size_t nc; + register size_t nbytes; + register cset *cs; + register size_t css = (size_t)p->g->csetsize; + register int i; + + 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 *)realloc((char *)p->g->sets, + nc * sizeof(cset)); + if (p->g->setbits == NULL) + p->g->setbits = (uch *)malloc(nbytes); + else { + p->g->setbits = (uch *)realloc((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 */ + } + } + + 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; + + return(cs); +} + +/* + - freeset - free a now-unused set + == static void freeset(register struct parse *p, register cset *cs); + */ +static void +freeset(p, cs) +register struct parse *p; +register cset *cs; +{ + register int i; + register cset *top = &p->g->sets[p->g->ncsets]; + register size_t css = (size_t)p->g->csetsize; + + for (i = 0; i < css; i++) + CHsub(cs, i); + if (cs == top-1) /* recover only the easy case */ + p->g->ncsets--; +} + +/* + - freezeset - final processing on a set of characters + == static int freezeset(register struct parse *p, register 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) +register struct parse *p; +register cset *cs; +{ + register uch h = cs->hash; + register int i; + register cset *top = &p->g->sets[p->g->ncsets]; + register cset *cs2; + register 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(register struct parse *p, register cset *cs); + */ +static int /* character; there is no "none" value */ +firstch(p, cs) +register struct parse *p; +register cset *cs; +{ + register int i; + register 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 */ +} + +/* + - nch - number of characters in a set + == static int nch(register struct parse *p, register cset *cs); + */ +static int +nch(p, cs) +register struct parse *p; +register cset *cs; +{ + register int i; + register size_t css = (size_t)p->g->csetsize; + register int n = 0; + + for (i = 0; i < css; i++) + if (CHIN(cs, i)) + n++; + return(n); +} + +/* + - mcadd - add a collating element to a cset + == static void mcadd(register struct parse *p, register cset *cs, \ + == register char *cp); + */ +static void +mcadd(p, cs, cp) +register struct parse *p; +register cset *cs; +register char *cp; +{ + register size_t oldend = cs->smultis; + + cs->smultis += strlen(cp) + 1; + if (cs->multis == NULL) + cs->multis = malloc(cs->smultis); + else + cs->multis = realloc(cs->multis, cs->smultis); + if (cs->multis == NULL) { + SETERROR(REG_ESPACE); + return; + } + + (void) strcpy(cs->multis + oldend - 1, cp); + cs->multis[cs->smultis - 1] = '\0'; +} + +/* + - mcsub - subtract a collating element from a cset + == static void mcsub(register cset *cs, register char *cp); + */ +static void +mcsub(cs, cp) +register cset *cs; +register char *cp; +{ + register char *fp = mcfind(cs, cp); + register size_t len = strlen(fp); + + assert(fp != NULL); + (void) memmove(fp, fp + len + 1, + cs->smultis - (fp + len + 1 - cs->multis)); + cs->smultis -= len; + + if (cs->smultis == 0) { + free(cs->multis); + cs->multis = NULL; + return; + } + + cs->multis = realloc(cs->multis, cs->smultis); + assert(cs->multis != NULL); +} + +/* + - mcin - is a collating element in a cset? + == static int mcin(register cset *cs, register char *cp); + */ +static int +mcin(cs, cp) +register cset *cs; +register char *cp; +{ + return(mcfind(cs, cp) != NULL); +} + +/* + - mcfind - find a collating element in a cset + == static char *mcfind(register cset *cs, register char *cp); + */ +static char * +mcfind(cs, cp) +register cset *cs; +register char *cp; +{ + register 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); +} + +/* + - mcinvert - invert the list of collating elements in a cset + == static void mcinvert(register struct parse *p, register cset *cs); + * + * This would have to know the set of possibilities. Implementation + * is deferred. + */ +static void +mcinvert(p, cs) +register struct parse *p; +register cset *cs; +{ + assert(cs->multis == NULL); /* xxx */ +} + +/* + - mccase - add case counterparts of the list of collating elements in a cset + == static void mccase(register struct parse *p, register cset *cs); + * + * This would have to know the set of possibilities. Implementation + * is deferred. + */ +static void +mccase(p, cs) +register struct parse *p; +register cset *cs; +{ + assert(cs->multis == NULL); /* xxx */ +} + +/* + - isinsets - is this character in any sets? + == static int isinsets(register struct re_guts *g, int c); + */ +static int /* predicate */ +isinsets(g, c) +register struct re_guts *g; +int c; +{ + register uch *col; + register int i; + register int ncols = (g->ncsets+(CHAR_BIT-1)) / CHAR_BIT; + register unsigned uc = (unsigned char)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(register struct re_guts *g, int c1, int c2); + */ +static int /* predicate */ +samesets(g, c1, c2) +register struct re_guts *g; +int c1; +int c2; +{ + register uch *col; + register int i; + register int ncols = (g->ncsets+(CHAR_BIT-1)) / CHAR_BIT; + register unsigned uc1 = (unsigned char)c1; + register unsigned uc2 = (unsigned char)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, register struct re_guts *g); + */ +static void +categorize(p, g) +struct parse *p; +register struct re_guts *g; +{ + register cat_t *cats = g->categories; + register int c; + register int c2; + register cat_t cat; + + /* avoid making error situations worse */ + if (p->error != 0) + 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; + } +} + +/* + - dupl - emit a duplicate of a bunch of sops + == static sopno dupl(register struct parse *p, sopno start, sopno finish); + */ +static sopno /* start of duplicate */ +dupl(p, start, finish) +register struct parse *p; +sopno start; /* from here */ +sopno finish; /* to this less one */ +{ + register sopno ret = HERE(); + register sopno len = finish - start; + + assert(finish >= start); + if (len == 0) + return(ret); + enlarge(p, p->ssize + len); /* this many unexpected additions */ + assert(p->ssize >= p->slen + len); + (void) memcpy((char *)(p->strip + p->slen), + (char *)(p->strip + start), (size_t)len*sizeof(sop)); + p->slen += len; + return(ret); +} + +/* + - doemit - emit a strip operator + == static void doemit(register struct parse *p, sop op, size_t opnd); + * + * It might seem better to implement this as a macro with a function as + * hard-case backup, but it's just too big and messy unless there are + * some changes to the data structures. Maybe later. + */ +static void +doemit(p, op, opnd) +register struct parse *p; +sop op; +size_t opnd; +{ + /* avoid making error situations worse */ + if (p->error != 0) + return; + + /* deal with oversize operands ("can't happen", more or less) */ + assert(opnd < 1<slen >= p->ssize) + enlarge(p, (p->ssize+1) / 2 * 3); /* +50% */ + assert(p->slen < p->ssize); + + /* finally, it's all reduced to the easy case */ + p->strip[p->slen++] = SOP(op, opnd); +} + +/* + - doinsert - insert a sop into the strip + == static void doinsert(register struct parse *p, sop op, size_t opnd, sopno pos); + */ +static void +doinsert(p, op, opnd, pos) +register struct parse *p; +sop op; +size_t opnd; +sopno pos; +{ + register sopno sn; + register sop s; + register int i; + + /* avoid making error situations worse */ + if (p->error != 0) + return; + + sn = HERE(); + EMIT(op, opnd); /* do checks, ensure space */ + assert(HERE() == sn+1); + s = p->strip[sn]; + + /* adjust paren pointers */ + assert(pos > 0); + for (i = 1; i < NPAREN; i++) { + if (p->pbegin[i] >= pos) { + p->pbegin[i]++; + } + if (p->pend[i] >= pos) { + p->pend[i]++; + } + } + + memmove((char *)&p->strip[pos+1], (char *)&p->strip[pos], + (HERE()-pos-1)*sizeof(sop)); + p->strip[pos] = s; +} + +/* + - dofwd - complete a forward reference + == static void dofwd(register struct parse *p, sopno pos, sop value); + */ +static void +dofwd(p, pos, value) +register struct parse *p; +register sopno pos; +sop value; +{ + /* avoid making error situations worse */ + if (p->error != 0) + return; + + assert(value < 1<strip[pos] = OP(p->strip[pos]) | value; +} + +/* + - enlarge - enlarge the strip + == static void enlarge(register struct parse *p, sopno size); + */ +static void +enlarge(p, size) +register struct parse *p; +register sopno size; +{ + register sop *sp; + + if (p->ssize >= size) + return; + + sp = (sop *)realloc(p->strip, size*sizeof(sop)); + if (sp == NULL) { + SETERROR(REG_ESPACE); + return; + } + p->strip = sp; + p->ssize = size; +} + +/* + - stripsnug - compact the strip + == static void stripsnug(register struct parse *p, register struct re_guts *g); + */ +static void +stripsnug(p, g) +register struct parse *p; +register struct re_guts *g; +{ + g->nstates = p->slen; + g->strip = (sop *)realloc((char *)p->strip, p->slen * sizeof(sop)); + if (g->strip == NULL) { + SETERROR(REG_ESPACE); + g->strip = p->strip; + } +} + +/* + - findmust - fill in must and mlen with longest mandatory literal string + == static void findmust(register struct parse *p, register struct re_guts *g); + * + * This algorithm could do fancy things like analyzing the operands of | + * for common subsequences. Someday. This code is simple and finds most + * of the interesting cases. + * + * Note that must and mlen got initialized during setup. + */ +static void +findmust(p, g) +struct parse *p; +register struct re_guts *g; +{ + register sop *scan; + sop *start; + register sop *newstart; + register sopno newlen; + register sop s; + register char *cp; + register sopno i; + + /* avoid making error situations worse */ + if (p->error != 0) + return; + + /* find the longest OCHAR sequence in strip */ + newlen = 0; + scan = g->strip + 1; + do { + s = *scan++; + switch (OP(s)) { + case OCHAR: /* sequence member */ + if (newlen == 0) /* new sequence */ + newstart = scan - 1; + newlen++; + break; + case OPLUS_: /* things that don't break one */ + case OLPAREN: + case ORPAREN: + break; + case OQUEST_: /* things that must be skipped */ + case OCH_: + scan--; + do { + scan += OPND(s); + s = *scan; + /* assert() interferes w debug printouts */ + if (OP(s) != O_QUEST && OP(s) != O_CH && + OP(s) != OOR2) { + g->iflags |= BAD; + return; + } + } while (OP(s) != O_QUEST && OP(s) != O_CH); + /* fallthrough */ + default: /* things that break a sequence */ + if (newlen > g->mlen) { /* ends one */ + start = newstart; + g->mlen = newlen; + } + newlen = 0; + break; + } + } while (OP(s) != OEND); + + if (g->mlen == 0) /* there isn't one */ + return; + + /* turn it into a character string */ + g->must = malloc((size_t)g->mlen + 1); + if (g->must == NULL) { /* argh; just forget it */ + g->mlen = 0; + return; + } + cp = g->must; + scan = start; + for (i = g->mlen; i > 0; i--) { + while (OP(s = *scan++) != OCHAR) + continue; + assert(cp < g->must + g->mlen); + *cp++ = (char)OPND(s); + } + assert(cp == g->must + g->mlen); + *cp++ = '\0'; /* just on general principles */ +} + +/* + - pluscount - count + nesting + == static sopno pluscount(register struct parse *p, register struct re_guts *g); + */ +static sopno /* nesting depth */ +pluscount(p, g) +struct parse *p; +register struct re_guts *g; +{ + register sop *scan; + register sop s; + register sopno plusnest = 0; + register sopno maxnest = 0; + + if (p->error != 0) + return(0); /* there may not be an OEND */ + + scan = g->strip + 1; + do { + s = *scan++; + switch (OP(s)) { + case OPLUS_: + plusnest++; + break; + case O_PLUS: + if (plusnest > maxnest) + maxnest = plusnest; + plusnest--; + break; + } + } while (OP(s) != OEND); + if (plusnest != 0) + g->iflags |= BAD; + return(maxnest); +} diff --git a/regex/regerror.c b/regex/regerror.c new file mode 100644 index 0000000..6d7da99 --- /dev/null +++ b/regex/regerror.c @@ -0,0 +1,198 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1992, 1993, 1994 + * 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. + */ + +#if defined(LIBC_SCCS) && !defined(lint) +static char sccsid[] = "@(#)regerror.c 8.4 (Berkeley) 3/20/94"; +#endif /* LIBC_SCCS and not lint */ + +#include +#include +#include +#include +#include +#include +#include + +#include "utils.h" + +/* ========= begin header generated by ./mkh ========= */ +#ifdef __cplusplus +extern "C" { +#endif + +/* === regerror.c === */ +static char *regatoi __P((const regex_t *preg, char *localbuf)); + +#ifdef __cplusplus +} +#endif +/* ========= end header generated by ./mkh ========= */ +/* + = #define REG_NOMATCH 1 + = #define REG_BADPAT 2 + = #define REG_ECOLLATE 3 + = #define REG_ECTYPE 4 + = #define REG_EESCAPE 5 + = #define REG_ESUBREG 6 + = #define REG_EBRACK 7 + = #define REG_EPAREN 8 + = #define REG_EBRACE 9 + = #define REG_BADBR 10 + = #define REG_ERANGE 11 + = #define REG_ESPACE 12 + = #define REG_BADRPT 13 + = #define REG_EMPTY 14 + = #define REG_ASSERT 15 + = #define REG_INVARG 16 + = #define REG_ATOI 255 // convert name to number (!) + = #define REG_ITOA 0400 // convert number to name (!) + */ +static struct rerr { + int code; + char *name; + char *explain; +} rerrs[] = { + REG_NOMATCH, "REG_NOMATCH", "regexec() failed to match", + REG_BADPAT, "REG_BADPAT", "invalid regular expression", + REG_ECOLLATE, "REG_ECOLLATE", "invalid collating element", + REG_ECTYPE, "REG_ECTYPE", "invalid character class", + REG_EESCAPE, "REG_EESCAPE", "trailing backslash (\\)", + REG_ESUBREG, "REG_ESUBREG", "invalid backreference number", + REG_EBRACK, "REG_EBRACK", "brackets ([ ]) not balanced", + REG_EPAREN, "REG_EPAREN", "parentheses not balanced", + REG_EBRACE, "REG_EBRACE", "braces not balanced", + REG_BADBR, "REG_BADBR", "invalid repetition count(s)", + REG_ERANGE, "REG_ERANGE", "invalid character range", + REG_ESPACE, "REG_ESPACE", "out of memory", + REG_BADRPT, "REG_BADRPT", "repetition-operator operand invalid", + 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", + 0, "", "*** unknown regexp error code ***", +}; + +/* + - regerror - the interface to error numbers + = extern size_t regerror(int, const regex_t *, char *, size_t); + */ +/* ARGSUSED */ +size_t +regerror(errcode, preg, errbuf, errbuf_size) +int errcode; +const regex_t *preg; +char *errbuf; +size_t errbuf_size; +{ + register struct rerr *r; + register size_t len; + register int target = errcode &~ REG_ITOA; + register char *s; + char convbuf[50]; + + if (errcode == REG_ATOI) + s = regatoi(preg, convbuf); + else { + for (r = rerrs; r->code != 0; r++) + if (r->code == target) + break; + + if (errcode®_ITOA) { + if (r->code != 0) + (void) strcpy(convbuf, r->name); + else + sprintf(convbuf, "REG_0x%x", target); + assert(strlen(convbuf) < sizeof(convbuf)); + s = convbuf; + } else + s = r->explain; + } + + len = strlen(s) + 1; + if (errbuf_size > 0) { + if (errbuf_size > len) + (void) strcpy(errbuf, s); + else { + (void) strncpy(errbuf, s, errbuf_size-1); + errbuf[errbuf_size-1] = '\0'; + } + } + + return(len); +} + +/* + - regatoi - internal routine to implement REG_ATOI + == static char *regatoi(const regex_t *preg, char *localbuf); + */ +static char * +regatoi(preg, localbuf) +const regex_t *preg; +char *localbuf; +{ + register struct rerr *r; + register size_t siz; + register char *p; + + for (r = rerrs; r->code != 0; r++) + if (strcmp(r->name, preg->re_endp) == 0) + break; + if (r->code == 0) + return("0"); + + sprintf(localbuf, "%d", r->code); + return(localbuf); +} diff --git a/regex/regex.3 b/regex/regex.3 new file mode 100644 index 0000000..d871641 --- /dev/null +++ b/regex/regex.3 @@ -0,0 +1,701 @@ +.\" Copyright (c) 1992, 1993, 1994 Henry Spencer. +.\" Copyright (c) 1992, 1993, 1994 +.\" 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. +.\" +.\" @(#)regex.3 8.4 (Berkeley) 3/20/94 +.\" $FreeBSD: src/lib/libc/regex/regex.3,v 1.9 2001/10/01 16:08:58 ru Exp $ +.\" +.Dd March 20, 1994 +.Dt REGEX 3 +.Os +.Sh NAME +.Nm regcomp , +.Nm regexec , +.Nm regerror , +.Nm regfree +.Nd regular-expression library +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In sys/types.h +.In regex.h +.Ft int +.Fn regcomp "regex_t *preg" "const char *pattern" "int cflags" +.Ft int +.Fo regexec +.Fa "const regex_t *preg" "const char *string" +.Fa "size_t nmatch" "regmatch_t pmatch[]" "int eflags" +.Fc +.Ft size_t +.Fo regerror +.Fa "int errcode" "const regex_t *preg" +.Fa "char *errbuf" "size_t errbuf_size" +.Fc +.Ft void +.Fn regfree "regex_t *preg" +.Sh DESCRIPTION +These routines implement +.St -p1003.2 +regular expressions +.Pq Do RE Dc Ns s ; +see +.Xr re_format 7 . +.Fn Regcomp +compiles an RE written as a string into an internal form, +.Fn regexec +matches that internal form against a string and reports results, +.Fn regerror +transforms error codes from either into human-readable messages, +and +.Fn regfree +frees any dynamically-allocated storage used by the internal form +of an RE. +.Pp +The header +.Aq Pa regex.h +declares two structure types, +.Ft regex_t +and +.Ft regmatch_t , +the former for compiled internal forms and the latter for match reporting. +It also declares the four functions, +a type +.Ft regoff_t , +and a number of constants with names starting with +.Dq Dv REG_ . +.Pp +.Fn Regcomp +compiles the regular expression contained in the +.Fa pattern +string, +subject to the flags in +.Fa cflags , +and places the results in the +.Ft regex_t +structure pointed to by +.Fa preg . +.Fa Cflags +is the bitwise OR of zero or more of the following flags: +.Bl -tag -width REG_EXTENDED +.It Dv REG_EXTENDED +Compile modern +.Pq Dq extended +REs, +rather than the obsolete +.Pq Dq basic +REs that +are the default. +.It Dv REG_BASIC +This is a synonym for 0, +provided as a counterpart to +.Dv REG_EXTENDED +to improve readability. +.It Dv REG_NOSPEC +Compile with recognition of all special characters turned off. +All characters are thus considered ordinary, +so the +.Dq RE +is a literal string. +This is an extension, +compatible with but not specified by +.St -p1003.2 , +and should be used with +caution in software intended to be portable to other systems. +.Dv REG_EXTENDED +and +.Dv REG_NOSPEC +may not be used +in the same call to +.Fn regcomp . +.It Dv REG_ICASE +Compile for matching that ignores upper/lower case distinctions. +See +.Xr re_format 7 . +.It Dv REG_NOSUB +Compile for matching that need only report success or failure, +not what was matched. +.It Dv REG_NEWLINE +Compile for newline-sensitive matching. +By default, newline is a completely ordinary character with no special +meaning in either REs or strings. +With this flag, +.Ql [^ +bracket expressions and +.Ql .\& +never match newline, +a +.Ql ^\& +anchor matches the null string after any newline in the string +in addition to its normal function, +and the +.Ql $\& +anchor matches the null string before any newline in the +string in addition to its normal function. +.It Dv REG_PEND +The regular expression ends, +not at the first NUL, +but just before the character pointed to by the +.Va re_endp +member of the structure pointed to by +.Fa preg . +The +.Va re_endp +member is of type +.Ft "const char *" . +This flag permits inclusion of NULs in the RE; +they are considered ordinary characters. +This is an extension, +compatible with but not specified by +.St -p1003.2 , +and should be used with +caution in software intended to be portable to other systems. +.El +.Pp +When successful, +.Fn regcomp +returns 0 and fills in the structure pointed to by +.Fa preg . +One member of that structure +(other than +.Va re_endp ) +is publicized: +.Va re_nsub , +of type +.Ft size_t , +contains the number of parenthesized subexpressions within the RE +(except that the value of this member is undefined if the +.Dv REG_NOSUB +flag was used). +If +.Fn regcomp +fails, it returns a non-zero error code; +see +.Sx DIAGNOSTICS . +.Pp +.Fn Regexec +matches the compiled RE pointed to by +.Fa preg +against the +.Fa string , +subject to the flags in +.Fa eflags , +and reports results using +.Fa nmatch , +.Fa pmatch , +and the returned value. +The RE must have been compiled by a previous invocation of +.Fn regcomp . +The compiled form is not altered during execution of +.Fn regexec , +so a single compiled RE can be used simultaneously by multiple threads. +.Pp +By default, +the NUL-terminated string pointed to by +.Fa string +is considered to be the text of an entire line, minus any terminating +newline. +The +.Fa eflags +argument is the bitwise OR of zero or more of the following flags: +.Bl -tag -width REG_STARTEND +.It Dv REG_NOTBOL +The first character of +the string +is not the beginning of a line, so the +.Ql ^\& +anchor should not match before it. +This does not affect the behavior of newlines under +.Dv REG_NEWLINE . +.It Dv REG_NOTEOL +The NUL terminating +the string +does not end a line, so the +.Ql $\& +anchor should not match before it. +This does not affect the behavior of newlines under +.Dv REG_NEWLINE . +.It Dv REG_STARTEND +The string is considered to start at +.Fa string ++ +.Fa pmatch Ns [0]. Ns Va rm_so +and to have a terminating NUL located at +.Fa string ++ +.Fa pmatch Ns [0]. Ns Va rm_eo +(there need not actually be a NUL at that location), +regardless of the value of +.Fa nmatch . +See below for the definition of +.Fa pmatch +and +.Fa nmatch . +This is an extension, +compatible with but not specified by +.St -p1003.2 , +and should be used with +caution in software intended to be portable to other systems. +Note that a non-zero +.Va rm_so +does not imply +.Dv REG_NOTBOL ; +.Dv REG_STARTEND +affects only the location of the string, +not how it is matched. +.El +.Pp +See +.Xr re_format 7 +for a discussion of what is matched in situations where an RE or a +portion thereof could match any of several substrings of +.Fa string . +.Pp +Normally, +.Fn regexec +returns 0 for success and the non-zero code +.Dv REG_NOMATCH +for failure. +Other non-zero error codes may be returned in exceptional situations; +see +.Sx DIAGNOSTICS . +.Pp +If +.Dv REG_NOSUB +was specified in the compilation of the RE, +or if +.Fa nmatch +is 0, +.Fn regexec +ignores the +.Fa pmatch +argument (but see below for the case where +.Dv REG_STARTEND +is specified). +Otherwise, +.Fa pmatch +points to an array of +.Fa nmatch +structures of type +.Ft regmatch_t . +Such a structure has at least the members +.Va rm_so +and +.Va rm_eo , +both of type +.Ft regoff_t +(a signed arithmetic type at least as large as an +.Ft off_t +and a +.Ft ssize_t ) , +containing respectively the offset of the first character of a substring +and the offset of the first character after the end of the substring. +Offsets are measured from the beginning of the +.Fa string +argument given to +.Fn regexec . +An empty substring is denoted by equal offsets, +both indicating the character following the empty substring. +.Pp +The 0th member of the +.Fa pmatch +array is filled in to indicate what substring of +.Fa string +was matched by the entire RE. +Remaining members report what substring was matched by parenthesized +subexpressions within the RE; +member +.Va i +reports subexpression +.Va i , +with subexpressions counted (starting at 1) by the order of their opening +parentheses in the RE, left to right. +Unused entries in the array (corresponding either to subexpressions that +did not participate in the match at all, or to subexpressions that do not +exist in the RE (that is, +.Va i +> +.Fa preg Ns -> Ns Va re_nsub ) ) +have both +.Va rm_so +and +.Va rm_eo +set to -1. +If a subexpression participated in the match several times, +the reported substring is the last one it matched. +(Note, as an example in particular, that when the RE +.Ql "(b*)+" +matches +.Ql bbb , +the parenthesized subexpression matches each of the three +.So Li b Sc Ns s +and then +an infinite number of empty strings following the last +.Ql b , +so the reported substring is one of the empties.) +.Pp +If +.Dv REG_STARTEND +is specified, +.Fa pmatch +must point to at least one +.Ft regmatch_t +(even if +.Fa nmatch +is 0 or +.Dv REG_NOSUB +was specified), +to hold the input offsets for +.Dv REG_STARTEND . +Use for output is still entirely controlled by +.Fa nmatch ; +if +.Fa nmatch +is 0 or +.Dv REG_NOSUB +was specified, +the value of +.Fa pmatch Ns [0] +will not be changed by a successful +.Fn regexec . +.Pp +.Fn Regerror +maps a non-zero +.Fa errcode +from either +.Fn regcomp +or +.Fn regexec +to a human-readable, printable message. +If +.Fa preg +is +.No non\- Ns Dv NULL , +the error code should have arisen from use of +the +.Ft regex_t +pointed to by +.Fa preg , +and if the error code came from +.Fn regcomp , +it should have been the result from the most recent +.Fn regcomp +using that +.Ft regex_t . +.No ( Fn Regerror +may be able to supply a more detailed message using information +from the +.Ft regex_t . ) +.Fn Regerror +places the NUL-terminated message into the buffer pointed to by +.Fa errbuf , +limiting the length (including the NUL) to at most +.Fa errbuf_size +bytes. +If the whole message won't fit, +as much of it as will fit before the terminating NUL is supplied. +In any case, +the returned value is the size of buffer needed to hold the whole +message (including terminating NUL). +If +.Fa errbuf_size +is 0, +.Fa errbuf +is ignored but the return value is still correct. +.Pp +If the +.Fa errcode +given to +.Fn regerror +is first ORed with +.Dv REG_ITOA , +the +.Dq message +that results is the printable name of the error code, +e.g.\& +.Dq Dv REG_NOMATCH , +rather than an explanation thereof. +If +.Fa errcode +is +.Dv REG_ATOI , +then +.Fa preg +shall be +.No non\- Ns Dv NULL +and the +.Va re_endp +member of the structure it points to +must point to the printable name of an error code; +in this case, the result in +.Fa errbuf +is the decimal digits of +the numeric value of the error code +(0 if the name is not recognized). +.Dv REG_ITOA +and +.Dv REG_ATOI +are intended primarily as debugging facilities; +they are extensions, +compatible with but not specified by +.St -p1003.2 , +and should be used with +caution in software intended to be portable to other systems. +Be warned also that they are considered experimental and changes are possible. +.Pp +.Fn Regfree +frees any dynamically-allocated storage associated with the compiled RE +pointed to by +.Fa preg . +The remaining +.Ft regex_t +is no longer a valid compiled RE +and the effect of supplying it to +.Fn regexec +or +.Fn regerror +is undefined. +.Pp +None of these functions references global variables except for tables +of constants; +all are safe for use from multiple threads if the arguments are safe. +.Sh IMPLEMENTATION CHOICES +There are a number of decisions that +.St -p1003.2 +leaves up to the implementor, +either by explicitly saying +.Dq undefined +or by virtue of them being +forbidden by the RE grammar. +This implementation treats them as follows. +.Pp +See +.Xr re_format 7 +for a discussion of the definition of case-independent matching. +.Pp +There is no particular limit on the length of REs, +except insofar as memory is limited. +Memory usage is approximately linear in RE size, and largely insensitive +to RE complexity, except for bounded repetitions. +See +.Sx BUGS +for one short RE using them +that will run almost any system out of memory. +.Pp +A backslashed character other than one specifically given a magic meaning +by +.St -p1003.2 +(such magic meanings occur only in obsolete +.Bq Dq basic +REs) +is taken as an ordinary character. +.Pp +Any unmatched +.Ql [\& +is a +.Dv REG_EBRACK +error. +.Pp +Equivalence classes cannot begin or end bracket-expression ranges. +The endpoint of one range cannot begin another. +.Pp +.Dv RE_DUP_MAX , +the limit on repetition counts in bounded repetitions, is 255. +.Pp +A repetition operator +.Ql ( ?\& , +.Ql *\& , +.Ql +\& , +or bounds) +cannot follow another +repetition operator. +A repetition operator cannot begin an expression or subexpression +or follow +.Ql ^\& +or +.Ql |\& . +.Pp +.Ql |\& +cannot appear first or last in a (sub)expression or after another +.Ql |\& , +i.e. an operand of +.Ql |\& +cannot be an empty subexpression. +An empty parenthesized subexpression, +.Ql "()" , +is legal and matches an +empty (sub)string. +An empty string is not a legal RE. +.Pp +A +.Ql {\& +followed by a digit is considered the beginning of bounds for a +bounded repetition, which must then follow the syntax for bounds. +A +.Ql {\& +.Em not +followed by a digit is considered an ordinary character. +.Pp +.Ql ^\& +and +.Ql $\& +beginning and ending subexpressions in obsolete +.Pq Dq basic +REs are anchors, not ordinary characters. +.Sh SEE ALSO +.Xr grep 1 , +.Xr re_format 7 +.Pp +.St -p1003.2 , +sections 2.8 (Regular Expression Notation) +and +B.5 (C Binding for Regular Expression Matching). +.Sh DIAGNOSTICS +Non-zero error codes from +.Fn regcomp +and +.Fn regexec +include the following: +.Pp +.Bl -tag -width REG_ECOLLATE -compact +.It Dv REG_NOMATCH +.Fn regexec +failed to match +.It Dv REG_BADPAT +invalid regular expression +.It Dv REG_ECOLLATE +invalid collating element +.It Dv REG_ECTYPE +invalid character class +.It Dv REG_EESCAPE +.Ql \e +applied to unescapable character +.It Dv REG_ESUBREG +invalid backreference number +.It Dv REG_EBRACK +brackets +.Ql "[ ]" +not balanced +.It Dv REG_EPAREN +parentheses +.Ql "( )" +not balanced +.It Dv REG_EBRACE +braces +.Ql "{ }" +not balanced +.It Dv REG_BADBR +invalid repetition count(s) in +.Ql "{ }" +.It Dv REG_ERANGE +invalid character range in +.Ql "[ ]" +.It Dv REG_ESPACE +ran out of memory +.It Dv REG_BADRPT +.Ql ?\& , +.Ql *\& , +or +.Ql +\& +operand invalid +.It Dv REG_EMPTY +empty (sub)expression +.It Dv REG_ASSERT +can't happen - you found a bug +.It Dv REG_INVARG +invalid argument, e.g. negative-length string +.El +.Sh HISTORY +Originally written by +.An Henry Spencer . +Altered for inclusion in the +.Bx 4.4 +distribution. +.Sh BUGS +This is an alpha release with known defects. +Please report problems. +.Pp +The back-reference code is subtle and doubts linger about its correctness +in complex cases. +.Pp +.Fn Regexec +performance is poor. +This will improve with later releases. +.Fa Nmatch +exceeding 0 is expensive; +.Fa nmatch +exceeding 1 is worse. +.Fn Regexec +is largely insensitive to RE complexity +.Em except +that back +references are massively expensive. +RE length does matter; in particular, there is a strong speed bonus +for keeping RE length under about 30 characters, +with most special characters counting roughly double. +.Pp +.Fn Regcomp +implements bounded repetitions by macro expansion, +which is costly in time and space if counts are large +or bounded repetitions are nested. +An RE like, say, +.Ql "((((a{1,100}){1,100}){1,100}){1,100}){1,100}" +will (eventually) run almost any existing machine out of swap space. +.Pp +There are suspected problems with response to obscure error conditions. +Notably, +certain kinds of internal overflow, +produced only by truly enormous REs or by multiply nested bounded repetitions, +are probably not handled well. +.Pp +Due to a mistake in +.St -p1003.2 , +things like +.Ql "a)b" +are legal REs because +.Ql )\& +is +a special character only in the presence of a previous unmatched +.Ql (\& . +This can't be fixed until the spec is fixed. +.Pp +The standard's definition of back references is vague. +For example, does +.Ql "a\e(\e(b\e)*\e2\e)*d" +match +.Ql "abbbd" ? +Until the standard is clarified, +behavior in such cases should not be relied on. +.Pp +The implementation of word-boundary matching is a bit of a kludge, +and bugs may lurk in combinations of word-boundary matching and anchoring. diff --git a/regex/regex2.h b/regex/regex2.h new file mode 100644 index 0000000..d68f62b --- /dev/null +++ b/regex/regex2.h @@ -0,0 +1,191 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1992, 1993, 1994 + * 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. + */ + +/* + * First, the stuff that ends up in the outside-world include file + = typedef off_t regoff_t; + = typedef struct { + = int re_magic; + = size_t re_nsub; // number of parenthesized subexpressions + = const char *re_endp; // end pointer for REG_PEND + = struct re_guts *re_g; // none of your business :-) + = } regex_t; + = typedef struct { + = regoff_t rm_so; // start of match + = regoff_t rm_eo; // end of match + = } regmatch_t; + */ +/* + * internals of regex_t + */ +#define MAGIC1 ((('r'^0200)<<8) | 'e') + +/* + * The internal representation is a *strip*, a sequence of + * operators ending with an endmarker. (Some terminology etc. is a + * historical relic of earlier versions which used multiple strips.) + * Certain oddities in the representation are there to permit running + * the machinery backwards; in particular, any deviation from sequential + * flow must be marked at both its source and its destination. Some + * fine points: + * + * - OPLUS_ and O_PLUS are *inside* the loop they create. + * - OQUEST_ and O_QUEST are *outside* the bypass they create. + * - OCH_ and O_CH are *outside* the multi-way branch they create, while + * OOR1 and OOR2 are respectively the end and the beginning of one of + * the branches. Note that there is an implicit OOR2 following OCH_ + * and an implicit OOR1 preceding O_CH. + * + * In state representations, an operator's bit is on to signify a state + * immediately *preceding* "execution" of that operator. + */ +typedef unsigned long sop; /* strip operator */ +typedef long sopno; +#define OPRMASK 0xf8000000 +#define OPDMASK 0x07ffffff +#define OPSHIFT ((unsigned)27) +#define OP(n) ((n)&OPRMASK) +#define OPND(n) ((n)&OPDMASK) +#define SOP(op, opnd) ((op)|(opnd)) +/* operators meaning operand */ +/* (back, fwd are offsets) */ +#define OEND (1< uch [csetsize] */ + uch mask; /* bit within array */ + uch hash; /* hash code */ + size_t smultis; + char *multis; /* -> char[smulti] ab\0cd\0ef\0\0 */ +} 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 += (c)) +#define CHsub(cs, c) ((cs)->ptr[(uch)(c)] &= ~(cs)->mask, (cs)->hash -= (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; + +/* + * main compiled-expression structure + */ +struct re_guts { + 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) */ + sopno laststate; /* the final OEND */ + int iflags; /* internal flags */ +# define USEBOL 01 /* used ^ */ +# define USEEOL 02 /* used $ */ +# 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 mlen; /* length of must */ + 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(c) || (c) == '_') diff --git a/regex/regexec.c b/regex/regexec.c new file mode 100644 index 0000000..928e272 --- /dev/null +++ b/regex/regexec.c @@ -0,0 +1,195 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1992, 1993, 1994 + * 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. + */ + +/* + * the outer shell of regexec() + * + * This file includes engine.c *twice*, after muchos fiddling with the + * macros that code uses. This lets the same code operate on two different + * representations for state sets. + */ +#include +#include +#include +#include +#include +#include +#include + +#include "utils.h" +#include "regex2.h" + +static int nope = 0; /* for use in asserts; shuts lint up */ + +/* macros for manipulating states, small version */ +#define states long +#define states1 states /* for later use in regexec() decision */ +#define CLEAR(v) ((v) = 0) +#define SET0(v, n) ((v) &= ~(1 << (n))) +#define SET1(v, n) ((v) |= 1 << (n)) +#define ISSET(v, n) ((v) & (1 << (n))) +#define ASSIGN(d, s) ((d) = (s)) +#define EQ(a, b) ((a) == (b)) +#define STATEVARS int dummy /* dummy version */ +#define STATESETUP(m, n) /* nothing */ +#define STATETEARDOWN(m) /* nothing */ +#define SETUP(v) ((v) = 0) +#define onestate int +#define INIT(o, n) ((o) = (unsigned)1 << (n)) +#define INC(o) ((o) <<= 1) +#define ISSTATEIN(v, o) ((v) & (o)) +/* some abbreviations; note that some of these know variable names! */ +/* do "if I'm here, I can also be there" etc without branches */ +#define FWD(dst, src, n) ((dst) |= ((unsigned)(src)&(here)) << (n)) +#define BACK(dst, src, n) ((dst) |= ((unsigned)(src)&(here)) >> (n)) +#define ISSETBACK(v, n) ((v) & ((unsigned)here >> (n))) +/* function names */ +#define SNAMES /* engine.c looks after details */ + +#include "engine.c" + +/* now undo things */ +#undef states +#undef CLEAR +#undef SET0 +#undef SET1 +#undef ISSET +#undef ASSIGN +#undef EQ +#undef STATEVARS +#undef STATESETUP +#undef STATETEARDOWN +#undef SETUP +#undef onestate +#undef INIT +#undef INC +#undef ISSTATEIN +#undef FWD +#undef BACK +#undef ISSETBACK +#undef SNAMES + +/* macros for manipulating states, large version */ +#define states char * +#define CLEAR(v) memset(v, 0, m->g->nstates) +#define SET0(v, n) ((v)[n] = 0) +#define SET1(v, n) ((v)[n] = 1) +#define ISSET(v, n) ((v)[n]) +#define ASSIGN(d, s) memcpy(d, s, m->g->nstates) +#define EQ(a, b) (memcmp(a, b, m->g->nstates) == 0) +#define STATEVARS int vn; char *space +#define STATESETUP(m, nv) { (m)->space = malloc((nv)*(m)->g->nstates); \ + if ((m)->space == NULL) return(REG_ESPACE); \ + (m)->vn = 0; } +#define STATETEARDOWN(m) { free((m)->space); } +#define SETUP(v) ((v) = &m->space[m->vn++ * m->g->nstates]) +#define onestate int +#define INIT(o, n) ((o) = (n)) +#define INC(o) ((o)++) +#define ISSTATEIN(v, o) ((v)[o]) +/* some abbreviations; note that some of these know variable names! */ +/* do "if I'm here, I can also be there" etc without branches */ +#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)]) +/* function names */ +#define LNAMES /* flag */ + +#include "engine.c" + +/* + - regexec - interface for matching + = extern int regexec(const regex_t *, const char *, size_t, \ + = regmatch_t [], int); + = #define REG_NOTBOL 00001 + = #define REG_NOTEOL 00002 + = #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 + * + * We put this here so we can exploit knowledge of the state representation + * when choosing which matcher to call. Also, by this point the matchers + * have been prototyped. + */ +int /* 0 success, REG_NOMATCH failure */ +regexec(preg, string, nmatch, pmatch, eflags) +const regex_t *preg; +const char *string; +size_t nmatch; +regmatch_t pmatch[]; +int eflags; +{ + register struct re_guts *g = preg->re_g; +#ifdef REDEBUG +# define GOODFLAGS(f) (f) +#else +# define GOODFLAGS(f) ((f)&(REG_NOTBOL|REG_NOTEOL|REG_STARTEND)) +#endif + + if (preg->re_magic != MAGIC1 || g->magic != MAGIC2) + return(REG_BADPAT); + assert(!(g->iflags&BAD)); + if (g->iflags&BAD) /* backstop for no-debug case */ + return(REG_BADPAT); + eflags = GOODFLAGS(eflags); + + 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)); +} diff --git a/regex/regfree.c b/regex/regfree.c new file mode 100644 index 0000000..9d81d4c --- /dev/null +++ b/regex/regfree.c @@ -0,0 +1,98 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1992, 1993, 1994 + * 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. + */ + +#if defined(LIBC_SCCS) && !defined(lint) +static char sccsid[] = "@(#)regfree.c 8.3 (Berkeley) 3/20/94"; +#endif /* LIBC_SCCS and not lint */ + +#include +#include +#include +#include + +#include "utils.h" +#include "regex2.h" + +/* + - regfree - free everything + = extern void regfree(regex_t *); + */ +void +regfree(preg) +regex_t *preg; +{ + register struct re_guts *g; + + if (preg->re_magic != MAGIC1) /* oops */ + return; /* nice to complain, but hard */ + + g = preg->re_g; + if (g == NULL || g->magic != MAGIC2) /* oops again */ + return; + preg->re_magic = 0; /* mark it invalid */ + g->magic = 0; /* mark it invalid */ + + if (g->strip != NULL) + free((char *)g->strip); + if (g->sets != NULL) + free((char *)g->sets); + if (g->setbits != NULL) + free((char *)g->setbits); + if (g->must != NULL) + free(g->must); + free((char *)g); +} diff --git a/regex/utils.h b/regex/utils.h new file mode 100644 index 0000000..f18607b --- /dev/null +++ b/regex/utils.h @@ -0,0 +1,75 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1992, 1993, 1994 + * 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. + */ + +/* utility definitions */ +#define DUPMAX _POSIX2_RE_DUP_MAX /* xxx is this right? */ +#define INFINITY (DUPMAX + 1) +#define NC (CHAR_MAX - CHAR_MIN + 1) +typedef unsigned char uch; + +/* switch off assertions (if not already off) if no REDEBUG */ +#ifndef REDEBUG +#ifndef NDEBUG +#define NDEBUG /* no assertions please */ +#endif +#endif +#include + +/* for old systems with bcopy() but no memmove() */ +#ifdef USEBCOPY +#define memmove(d, s, c) bcopy(s, d, c) +#endif diff --git a/rpc/Makefile.inc b/rpc/Makefile.inc new file mode 100644 index 0000000..223003f --- /dev/null +++ b/rpc/Makefile.inc @@ -0,0 +1,159 @@ +# @(#)Makefile 5.11 (Berkeley) 9/6/90 +# $FreeBSD: src/lib/libc/rpc/Makefile.inc,v 1.21 2001/10/04 21:03:17 wpaul Exp $ + +.PATH: ${.CURDIR}/../libc/rpc ${.CURDIR}/. +SRCS+= auth_none.c auth_unix.c authunix_prot.c bindresvport.c clnt_bcast.c \ + clnt_dg.c clnt_generic.c clnt_perror.c clnt_raw.c clnt_simple.c \ + clnt_vc.c rpc_dtablesize.c getnetconfig.c getnetpath.c getrpcent.c \ + getrpcport.c mt_misc.c pmap_clnt.c pmap_getmaps.c pmap_getport.c \ + pmap_prot.c pmap_prot2.c pmap_rmt.c rpc_prot.c rpc_commondata.c \ + rpc_callmsg.c rpc_generic.c rpc_soc.c rpcb_clnt.c rpcb_prot.c \ + rpcb_st_xdr.c svc.c svc_auth.c svc_dg.c svc_auth_unix.c svc_generic.c \ + svc_raw.c svc_run.c svc_simple.c svc_vc.c + +# XDR +SRCS+= xdr.c xdr_array.c xdr_float.c xdr_mem.c xdr_rec.c xdr_reference.c \ + xdr_stdio.c + +# Secure-RPC +SRCS+= auth_time.c auth_des.c authdes_prot.c des_crypt.c des_soft.c \ + crypt_client.c key_call.c key_prot_xdr.c getpublickey.c \ + svc_auth_des.c + +# Resolver stuff +SRCS+= netname.c netnamer.c rpcdname.c + +# Misc Source +SRCS+= rtime.c + +# generated sources +SRCS+= crypt_clnt.c crypt_xdr.c crypt.h + +CFLAGS+= -DBROKEN_DES -DPORTMAP -DDES_BUILTIN + +CLEANFILES+= crypt_clnt.c crypt_xdr.c crypt.h + +RPCDIR= ${DESTDIR}/usr/include/rpcsvc +RPCGEN= rpcgen -C + +crypt_clnt.c: ${RPCDIR}/crypt.x crypt.h + ${RPCGEN} -l -o ${.TARGET} ${RPCDIR}/crypt.x + +crypt_xdr.c: ${RPCDIR}/crypt.x crypt.h + ${RPCGEN} -c -o ${.TARGET} ${RPCDIR}/crypt.x + +crypt.h: ${RPCDIR}/crypt.x + ${RPCGEN} -h -o ${.TARGET} ${RPCDIR}/crypt.x +MAN+= bindresvport.3 des_crypt.3 getnetconfig.3 getnetpath.3 getrpcent.3 \ + getrpcport.3 rpc.3 rpc_soc.3 rpc_clnt_auth.3 rpc_clnt_calls.3 \ + rpc_clnt_create.3 rpc_svc_calls.3 rpc_svc_create.3 rpc_svc_err.3 \ + rpc_svc_reg.3 rpc_xdr.3 rpcbind.3 xdr.3 publickey.3 rpc_secure.3 \ + rtime.3 +MAN+= publickey.5 rpc.5 netconfig.5 +MLINKS+= bindresvport.3 bindresvport_sa.3 \ + getnetconfig.3 setnetconfig.3 \ + getnetconfig.3 getnetconfigent.3 \ + getnetconfig.3 endnetconfig.3 \ + getnetconfig.3 nc_perror.3 \ + getnetconfig.3 nc_sperror.3 \ + getnetpath.3 setnetpath.3 \ + getnetpath.3 endnetpath.3 \ + getrpcent.3 getrpcbyname.3 \ + getrpcent.3 getrpcbynumber.3 \ + getrpcent.3 endrpcent.3 \ + getrpcent.3 setrpcent.3 \ + rpc_clnt_auth.3 auth_destroy.3 \ + rpc_clnt_auth.3 authnone_create.3 \ + rpc_clnt_auth.3 authsys_create.3 \ + rpc_clnt_auth.3 authsys_create_default.3 \ + rpc_clnt_calls.3 clnt_call.3 \ + rpc_clnt_calls.3 clnt_perrno.3 \ + rpc_clnt_calls.3 clnt_perror.3 \ + rpc_clnt_calls.3 clnt_sperrno.3 \ + rpc_clnt_calls.3 clnt_sperror.3 \ + rpc_clnt_calls.3 rpc_call.3 \ + rpc_clnt_calls.3 rpc_broadcast.3 \ + rpc_clnt_calls.3 rpc_broadcast_exp.3 \ + rpc_clnt_calls.3 clnt_freeres.3 \ + rpc_clnt_calls.3 clnt_geterr.3 \ + rpc_clnt_create.3 clnt_control.3 \ + rpc_clnt_create.3 clnt_create.3 \ + rpc_clnt_create.3 clnt_create_vers.3 \ + rpc_clnt_create.3 clnt_destroy.3 \ + rpc_clnt_create.3 clnt_pcreateerror.3 \ + rpc_clnt_create.3 clnt_spcreateerror.3 \ + rpc_clnt_create.3 clnt_dg_create.3 \ + rpc_clnt_create.3 clnt_raw_create.3 \ + rpc_clnt_create.3 clnt_tli_create.3 \ + rpc_clnt_create.3 clnt_tp_create.3 \ + rpc_clnt_create.3 clnt_vc_create.3 \ + rpc_svc_calls.3 svc_dg_enablecache.3 \ + rpc_svc_calls.3 svc_exit.3 \ + rpc_svc_calls.3 svc_freeargs.3 \ + rpc_svc_calls.3 svc_getargs.3 \ + rpc_svc_calls.3 svc_getreq_common.3 \ + rpc_svc_calls.3 svc_getreq_poll.3 \ + rpc_svc_calls.3 svc_getreqset.3 \ + rpc_svc_calls.3 svc_getrpccaller.3 \ + rpc_svc_calls.3 __svc_getcallercreds.3 \ + rpc_svc_calls.3 svc_pollset.3 \ + rpc_svc_calls.3 svc_run.3 \ + rpc_svc_calls.3 svc_sendreply.3 \ + rpc_svc_create.3 svc_control.3 \ + rpc_svc_create.3 svc_create.3 \ + rpc_svc_create.3 svc_dg_create.3 \ + rpc_svc_create.3 svc_destroy.3 \ + rpc_svc_create.3 svc_fd_create.3 \ + rpc_svc_create.3 svc_raw_create.3 \ + rpc_svc_create.3 svc_tli_create.3 \ + rpc_svc_create.3 svc_tp_create.3 \ + rpc_svc_create.3 svc_vc_create.3 \ + rpc_svc_err.3 svcerr_auth.3 \ + rpc_svc_err.3 svcerr_decode.3 \ + rpc_svc_err.3 svcerr_noproc.3 \ + rpc_svc_err.3 svcerr_noprog.3 \ + rpc_svc_err.3 svcerr_progvers.3 \ + rpc_svc_err.3 svcerr_systemerr.3 \ + rpc_svc_err.3 svcerr_weakauth.3 \ + rpc_svc_reg.3 rpc_reg.3 \ + rpc_svc_reg.3 svc_reg.3 \ + rpc_svc_reg.3 svc_unreg.3 \ + rpc_svc_reg.3 svc_auth_reg.3 \ + rpc_svc_reg.3 xprt_register.3 \ + rpc_svc_reg.3 xprt_unregister.3 \ + rpcbind.3 rpcb_getmaps.3 \ + rpcbind.3 rpcb_getaddr.3 \ + rpcbind.3 rpcb_gettime.3 \ + rpcbind.3 rpcb_rmtcall.3 \ + rpcbind.3 rpcb_set.3 \ + rpcbind.3 rpcb_unset.3 \ + rpc_soc.3 authunix_create.3 \ + rpc_soc.3 authunix_create_default.3 \ + rpc_soc.3 callrpc.3 \ + rpc_soc.3 clnt_broadcast.3 \ + rpc_soc.3 clntraw_create.3 \ + rpc_soc.3 clnttcp_create.3 \ + rpc_soc.3 clntunix_create.3 \ + rpc_soc.3 clntudp_bufcreate.3 \ + rpc_soc.3 clntudp_create.3 \ + rpc_soc.3 get_myaddress.3 \ + rpc_soc.3 pmap_getmaps.3 \ + rpc_soc.3 pmap_getport.3 \ + rpc_soc.3 pmap_rmtcall.3 \ + rpc_soc.3 pmap_set.3 \ + rpc_soc.3 pmap_unset.3 \ + rpc_soc.3 registerrpc.3 \ + rpc_soc.3 rpc_createerr.3 \ + rpc_soc.3 svc_fds.3 \ + rpc_soc.3 svc_fdset.3 \ + rpc_soc.3 svc_getcaller.3 \ + rpc_soc.3 svc_register.3 \ + rpc_soc.3 svc_unregister.3 \ + rpc_soc.3 svcfd_create.3 \ + rpc_soc.3 svcunixfd_create.3 \ + rpc_soc.3 svcraw_create.3 \ + rpc_soc.3 svctcp_create.3 \ + rpc_soc.3 svcudp_bufcreate.3 \ + rpc_soc.3 svcunix_create.3 \ + rpc_soc.3 xdr_pmap.3 \ + rpc_soc.3 xdr_pmaplist.3 diff --git a/stdio.subproj/Makefile b/stdio.subproj/Makefile deleted file mode 100644 index 4fc67ac..0000000 --- a/stdio.subproj/Makefile +++ /dev/null @@ -1,57 +0,0 @@ -# -# Generated by the NeXT Project Builder. -# -# NOTE: Do NOT change this file -- Project Builder maintains it. -# -# Put all of your customizations in files called Makefile.preamble -# and Makefile.postamble (both optional), and Makefile will include them. -# - -NAME = stdio - -PROJECTVERSION = 2.8 -PROJECT_TYPE = Component - -HFILES = floatio.h fvwrite.h glue.h local.h - -CFILES = clrerr.c fclose.c fdopen.c feof.c ferror.c fflush.c fgetc.c\ - fgetln.c fgetpos.c fgets.c fileno.c findfp.c flags.c\ - fopen.c fprintf.c fpurge.c fputc.c fputs.c fread.c\ - freopen.c fscanf.c fseek.c fsetpos.c ftell.c funopen.c\ - fvwrite.c fwalk.c fwrite.c getc.c getchar.c gets.c getw.c\ - makebuf.c mktemp.c perror.c printf.c putc.c putchar.c\ - puts.c putw.c refill.c remove.c rewind.c rget.c scanf.c\ - setbuf.c setbuffer.c setvbuf.c snprintf.c sprintf.c sscanf.c\ - stdio.c tempnam.c tmpfile.c tmpnam.c ungetc.c vfprintf.c\ - vfscanf.c vprintf.c vscanf.c vsnprintf.c vsprintf.c\ - vsscanf.c wbuf.c wsetup.c - -OTHERSRCS = Makefile.preamble Makefile Makefile.postamble - - -MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles -CODE_GEN_STYLE = DYNAMIC -MAKEFILE = subproj.make -LIBS = -DEBUG_LIBS = $(LIBS) -PROF_LIBS = $(LIBS) - - - - -NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc -WINDOWS_OBJCPLUS_COMPILER = $(DEVDIR)/gcc -PDO_UNIX_OBJCPLUS_COMPILER = $(NEXTDEV_BIN)/gcc -NEXTSTEP_JAVA_COMPILER = /usr/bin/javac -WINDOWS_JAVA_COMPILER = $(JDKBINDIR)/javac.exe -PDO_UNIX_JAVA_COMPILER = $(JDKBINDIR)/javac - -include $(MAKEFILEDIR)/platform.make - --include Makefile.preamble - -include $(MAKEFILEDIR)/$(MAKEFILE) - --include Makefile.postamble - --include Makefile.dependencies diff --git a/stdio.subproj/Makefile.postamble b/stdio.subproj/Makefile.postamble deleted file mode 100644 index 411cde6..0000000 --- a/stdio.subproj/Makefile.postamble +++ /dev/null @@ -1,100 +0,0 @@ -############################################################################### -# Makefile.postamble -# Copyright 1997, Apple Computer, Inc. -# -# Use this makefile, which is imported after all other makefiles, to -# override attributes for a project's Makefile environment. This allows you -# to take advantage of the environment set up by the other Makefiles. -# You can also define custom rules at the end of this file. -# -############################################################################### -# -# These variables are exported by the standard makefiles and can be -# used in any customizations you make. They are *outputs* of -# the Makefiles and should be used, not set. -# -# PRODUCTS: products to install. All of these products will be placed in -# the directory $(DSTROOT)$(INSTALLDIR) -# GLOBAL_RESOURCE_DIR: The directory to which resources are copied. -# LOCAL_RESOURCE_DIR: The directory to which localized resources are copied. -# OFILE_DIR: Directory into which .o object files are generated. -# DERIVED_SRC_DIR: Directory used for all other derived files -# -# ALL_CFLAGS: flags to pass when compiling .c files -# ALL_MFLAGS: flags to pass when compiling .m files -# ALL_CCFLAGS: flags to pass when compiling .cc, .cxx, and .C files -# ALL_MMFLAGS: flags to pass when compiling .mm, .mxx, and .M files -# ALL_PRECOMPFLAGS: flags to pass when precompiling .h files -# ALL_LDFLAGS: flags to pass when linking object files -# ALL_LIBTOOL_FLAGS: flags to pass when libtooling object files -# ALL_PSWFLAGS: flags to pass when processing .psw and .pswm (pswrap) files -# ALL_RPCFLAGS: flags to pass when processing .rpc (rpcgen) files -# ALL_YFLAGS: flags to pass when processing .y (yacc) files -# ALL_LFLAGS: flags to pass when processing .l (lex) files -# -# NAME: name of application, bundle, subproject, palette, etc. -# LANGUAGES: langages in which the project is written (default "English") -# English_RESOURCES: localized resources (e.g. nib's, images) of project -# GLOBAL_RESOURCES: non-localized resources of project -# -# SRCROOT: base directory in which to place the new source files -# SRCPATH: relative path from SRCROOT to present subdirectory -# -# INSTALLDIR: Directory the product will be installed into by 'install' target -# PUBLIC_HDR_INSTALLDIR: where to install public headers. Don't forget -# to prefix this with DSTROOT when you use it. -# PRIVATE_HDR_INSTALLDIR: where to install private headers. Don't forget -# to prefix this with DSTROOT when you use it. -# -# EXECUTABLE_EXT: Executable extension for the platform (i.e. .exe on Windows) -# -############################################################################### - -# Some compiler flags can be overridden here for certain build situations. -# -# WARNING_CFLAGS: flag used to set warning level (defaults to -Wmost) -# DEBUG_SYMBOLS_CFLAGS: debug-symbol flag passed to all builds (defaults -# to -g) -# DEBUG_BUILD_CFLAGS: flags passed during debug builds (defaults to -DDEBUG) -# OPTIMIZE_BUILD_CFLAGS: flags passed during optimized builds (defaults -# to -O) -# PROFILE_BUILD_CFLAGS: flags passed during profile builds (defaults -# to -pg -DPROFILE) -# LOCAL_DIR_INCLUDE_DIRECTIVE: flag used to add current directory to -# the include path (defaults to -I.) -# DEBUG_BUILD_LDFLAGS, OPTIMIZE_BUILD_LDFLAGS, PROFILE_BUILD_LDFLAGS: flags -# passed to ld/libtool (defaults to nothing) - - -# Library and Framework projects only: -# INSTALL_NAME_DIRECTIVE: This directive ensures that executables linked -# against the framework will run against the correct version even if -# the current version of the framework changes. You may override this -# to "" as an alternative to using the DYLD_LIBRARY_PATH during your -# development cycle, but be sure to restore it before installing. - - -# Ownership and permissions of files installed by 'install' target - -#INSTALL_AS_USER = root - # User/group ownership -#INSTALL_AS_GROUP = wheel - # (probably want to set both of these) -#INSTALL_PERMISSIONS = - # If set, 'install' chmod's executable to this - - -# Options to strip. Note: -S strips debugging symbols (executables can be stripped -# down further with -x or, if they load no bundles, with no options at all). - -#STRIPFLAGS = -S - - -######################################################################### -# Put rules to extend the behavior of the standard Makefiles here. Include them in -# the dependency tree via cvariables like AFTER_INSTALL in the Makefile.preamble. -# -# You should avoid redefining things like "install" or "app", as they are -# owned by the top-level Makefile API and no context has been set up for where -# derived files should go. -# diff --git a/stdio.subproj/Makefile.preamble b/stdio.subproj/Makefile.preamble deleted file mode 100644 index c1624b4..0000000 --- a/stdio.subproj/Makefile.preamble +++ /dev/null @@ -1,137 +0,0 @@ -############################################################################### -# Makefile.preamble -# Copyright 1997, Apple Computer, Inc. -# -# Use this makefile for configuring the standard application makefiles -# associated with ProjectBuilder. It is included before the main makefile. -# In Makefile.preamble you set attributes for a project, so they are available -# to the project's makefiles. In contrast, you typically write additional rules or -# override built-in behavior in the Makefile.postamble. -# -# Each directory in a project tree (main project plus subprojects) should -# have its own Makefile.preamble and Makefile.postamble. -############################################################################### -# -# Before the main makefile is included for this project, you may set: -# -# MAKEFILEDIR: Directory in which to find $(MAKEFILE) -# MAKEFILE: Top level mechanism Makefile (e.g., app.make, bundle.make) - -# Compiler/linker flags added to the defaults: The OTHER_* variables will be -# inherited by all nested sub-projects, but the LOCAL_ versions of the same -# variables will not. Put your -I, -D, -U, and -L flags in ProjectBuilder's -# Build Attributes inspector if at all possible. To override the default flags -# that get passed to ${CC} (e.g. change -O to -O2), see Makefile.postamble. The -# variables below are *inputs* to the build process and distinct from the override -# settings done (less often) in the Makefile.postamble. -# -# OTHER_CFLAGS, LOCAL_CFLAGS: additional flags to pass to the compiler -# Note that $(OTHER_CFLAGS) and $(LOCAL_CFLAGS) are used for .h, ...c, .m, -# .cc, .cxx, .C, and .M files. There is no need to respecify the -# flags in OTHER_MFLAGS, etc. -# OTHER_MFLAGS, LOCAL_MFLAGS: additional flags for .m files -# OTHER_CCFLAGS, LOCAL_CCFLAGS: additional flags for .cc, .cxx, and ...C files -# OTHER_MMFLAGS, LOCAL_MMFLAGS: additional flags for .mm and .M files -# OTHER_PRECOMPFLAGS, LOCAL_PRECOMPFLAGS: additional flags used when -# precompiling header files -# OTHER_LDFLAGS, LOCAL_LDFLAGS: additional flags passed to ld and libtool -# OTHER_PSWFLAGS, LOCAL_PSWFLAGS: additional flags passed to pswrap -# OTHER_RPCFLAGS, LOCAL_RPCFLAGS: additional flags passed to rpcgen -# OTHER_YFLAGS, LOCAL_YFLAGS: additional flags passed to yacc -# OTHER_LFLAGS, LOCAL_LFLAGS: additional flags passed to lex - -# These variables provide hooks enabling you to add behavior at almost every -# stage of the make: -# -# BEFORE_PREBUILD: targets to build before installing headers for a subproject -# AFTER_PREBUILD: targets to build after installing headers for a subproject -# BEFORE_BUILD_RECURSION: targets to make before building subprojects -# BEFORE_BUILD: targets to make before a build, but after subprojects -# AFTER_BUILD: targets to make after a build -# -# BEFORE_INSTALL: targets to build before installing the product -# AFTER_INSTALL: targets to build after installing the product -# BEFORE_POSTINSTALL: targets to build before postinstalling every subproject -# AFTER_POSTINSTALL: targts to build after postinstalling every subproject -# -# BEFORE_INSTALLHDRS: targets to build before installing headers for a -# subproject -# AFTER_INSTALLHDRS: targets to build after installing headers for a subproject -# BEFORE_INSTALLSRC: targets to build before installing source for a subproject -# AFTER_INSTALLSRC: targets to build after installing source for a subproject -# -# BEFORE_DEPEND: targets to build before building dependencies for a -# subproject -# AFTER_DEPEND: targets to build after building dependencies for a -# subproject -# -# AUTOMATIC_DEPENDENCY_INFO: if YES, then the dependency file is -# updated every time the project is built. If NO, the dependency -# file is only built when the depend target is invoked. - -# Framework-related variables: -# FRAMEWORK_DLL_INSTALLDIR: On Windows platforms, this variable indicates -# where to put the framework's DLL. This variable defaults to -# $(INSTALLDIR)/../Executables - -# Library-related variables: -# PUBLIC_HEADER_DIR: Determines where public exported header files -# should be installed. Do not include $(DSTROOT) in this value -- -# it is prefixed automatically. For library projects you should -# set this to something like /Developer/Headers/$(NAME). Do not set -# this variable for framework projects unless you do not want the -# header files included in the framework. -# PRIVATE_HEADER_DIR: Determines where private exported header files -# should be installed. Do not include $(DSTROOT) in this value -- -# it is prefixed automatically. -# LIBRARY_STYLE: This may be either STATIC or DYNAMIC, and determines -# whether the libraries produced are statically linked when they -# are used or if they are dynamically loadable. This defaults to -# DYNAMIC. -# LIBRARY_DLL_INSTALLDIR: On Windows platforms, this variable indicates -# where to put the library's DLL. This variable defaults to -# $(INSTALLDIR)/../Executables -# -# INSTALL_AS_USER: owner of the intalled products (default root) -# INSTALL_AS_GROUP: group of the installed products (default wheel) -# INSTALL_PERMISSIONS: permissions of the installed product (default o+rX) -# -# OTHER_RECURSIVE_VARIABLES: The names of variables which you want to be -# passed on the command line to recursive invocations of make. Note that -# the values in OTHER_*FLAGS are inherited by subprojects automatically -- -# you do not have to (and shouldn't) add OTHER_*FLAGS to -# OTHER_RECURSIVE_VARIABLES. - -# Additional headers to export beyond those in the PB.project: -# OTHER_PUBLIC_HEADERS -# OTHER_PROJECT_HEADERS -# OTHER_PRIVATE_HEADERS - -# Additional files for the project's product: <> -# OTHER_RESOURCES: (non-localized) resources for this project -# OTHER_OFILES: relocatables to be linked into this project -# OTHER_LIBS: more libraries to link against -# OTHER_PRODUCT_DEPENDS: other dependencies of this project -# OTHER_SOURCEFILES: other source files maintained by .pre/postamble -# OTHER_GARBAGE: additional files to be removed by `make clean' - -# Set this to YES if you don't want a final libtool call for a library/framework. -# BUILD_OFILES_LIST_ONLY - -# To include a version string, project source must exist in a directory named -# $(NAME).%d[.%d][.%d] and the following line must be uncommented. -# OTHER_GENERATED_OFILES = $(VERS_OFILE) - -# This definition will suppress stripping of debug symbols when an executable -# is installed. By default it is YES. -# STRIP_ON_INSTALL = NO - -# Uncomment to suppress generation of a KeyValueCoding index when installing -# frameworks (This index is used by WOB and IB to determine keys available -# for an object). Set to YES by default. -# PREINDEX_FRAMEWORK = NO - -# Change this definition to install projects somewhere other than the -# standard locations. NEXT_ROOT defaults to "C:/Apple" on Windows systems -# and "" on other systems. -DSTROOT = $(HOME) diff --git a/stdio.subproj/PB.project b/stdio.subproj/PB.project deleted file mode 100644 index 5d739da..0000000 --- a/stdio.subproj/PB.project +++ /dev/null @@ -1,89 +0,0 @@ -{ - DYNAMIC_CODE_GEN = YES; - FILESTABLE = { - H_FILES = (floatio.h, fvwrite.h, glue.h, local.h); - OTHER_LINKED = ( - clrerr.c, - fclose.c, - fdopen.c, - feof.c, - ferror.c, - fflush.c, - fgetc.c, - fgetln.c, - fgetpos.c, - fgets.c, - fileno.c, - findfp.c, - flags.c, - fopen.c, - fprintf.c, - fpurge.c, - fputc.c, - fputs.c, - fread.c, - freopen.c, - fscanf.c, - fseek.c, - fsetpos.c, - ftell.c, - funopen.c, - fvwrite.c, - fwalk.c, - fwrite.c, - getc.c, - getchar.c, - gets.c, - getw.c, - makebuf.c, - mktemp.c, - perror.c, - printf.c, - putc.c, - putchar.c, - puts.c, - putw.c, - refill.c, - remove.c, - rewind.c, - rget.c, - scanf.c, - setbuf.c, - setbuffer.c, - setvbuf.c, - snprintf.c, - sprintf.c, - sscanf.c, - stdio.c, - tempnam.c, - tmpfile.c, - tmpnam.c, - ungetc.c, - vfprintf.c, - vfscanf.c, - vprintf.c, - vscanf.c, - vsnprintf.c, - vsprintf.c, - vsscanf.c, - wbuf.c, - wsetup.c - ); - OTHER_SOURCES = (Makefile.preamble, Makefile, Makefile.postamble); - SUBPROJECTS = (); - }; - LANGUAGE = English; - MAKEFILEDIR = "$(MAKEFILEPATH)/pb_makefiles"; - NEXTSTEP_BUILDTOOL = /bin/gnumake; - NEXTSTEP_JAVA_COMPILER = /usr/bin/javac; - NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc; - PDO_UNIX_BUILDTOOL = $NEXT_ROOT/Developer/bin/make; - PDO_UNIX_JAVA_COMPILER = "$(JDKBINDIR)/javac"; - PDO_UNIX_OBJCPLUS_COMPILER = "$(NEXTDEV_BIN)/gcc"; - PROJECTNAME = stdio; - PROJECTTYPE = Component; - PROJECTVERSION = 2.8; - WINDOWS_BUILDTOOL = $NEXT_ROOT/Developer/Executables/make; - WINDOWS_JAVA_COMPILER = "$(JDKBINDIR)/javac.exe"; - WINDOWS_OBJCPLUS_COMPILER = "$(DEVDIR)/gcc"; -} diff --git a/stdio.subproj/clrerr.c b/stdio.subproj/clrerr.c deleted file mode 100644 index 610dae9..0000000 --- a/stdio.subproj/clrerr.c +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * 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 -#undef clearerr - -void -clearerr(fp) - FILE *fp; -{ - __sclearerr(fp); -} diff --git a/stdio.subproj/fclose.c b/stdio.subproj/fclose.c deleted file mode 100644 index e7b1c97..0000000 --- a/stdio.subproj/fclose.c +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * 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 -#include -#include -#include "local.h" - -int -fclose(fp) - register FILE *fp; -{ - register int r; - - if (fp->_flags == 0) { /* not open! */ - errno = EBADF; - return (EOF); - } - r = fp->_flags & __SWR ? __sflush(fp) : 0; - if (fp->_close != NULL && (*fp->_close)(fp->_cookie) < 0) - r = EOF; - if (fp->_flags & __SMBF) - free((char *)fp->_bf._base); - if (HASUB(fp)) - FREEUB(fp); - if (HASLB(fp)) - FREELB(fp); - fp->_flags = 0; /* Release this FILE for reuse. */ - fp->_r = fp->_w = 0; /* Mess up if reaccessed. */ - return (r); -} diff --git a/stdio.subproj/fdopen.c b/stdio.subproj/fdopen.c deleted file mode 100644 index 4bc1a94..0000000 --- a/stdio.subproj/fdopen.c +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * 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 -#include -#include -#include -#include -#include "local.h" - -FILE * -fdopen(fd, mode) - int fd; - const char *mode; -{ - register FILE *fp; - static int nofile; - int flags, oflags, fdflags, tmp; - - if (nofile == 0) - nofile = getdtablesize(); - - if ((flags = __sflags(mode, &oflags)) == 0) - return (NULL); - - /* Make sure the mode the user wants is a subset of the actual mode. */ - if ((fdflags = fcntl(fd, F_GETFL, 0)) < 0) - return (NULL); - tmp = fdflags & O_ACCMODE; - if (tmp != O_RDWR && (tmp != (oflags & O_ACCMODE))) { - errno = EINVAL; - return (NULL); - } - - if ((fp = __sfp()) == NULL) - return (NULL); - fp->_flags = flags; - /* - * If opened for appending, but underlying descriptor does not have - * O_APPEND bit set, assert __SAPP so that __swrite() will lseek to - * end before each write. - */ - if ((oflags & O_APPEND) && !(fdflags & O_APPEND)) - fp->_flags |= __SAPP; - fp->_file = fd; - fp->_cookie = fp; - fp->_read = __sread; - fp->_write = __swrite; - fp->_seek = __sseek; - fp->_close = __sclose; - return (fp); -} diff --git a/stdio.subproj/feof.c b/stdio.subproj/feof.c deleted file mode 100644 index 756ff08..0000000 --- a/stdio.subproj/feof.c +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * 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 - -/* - * A subroutine version of the macro feof. - */ -#undef feof - -int -feof(fp) - FILE *fp; -{ - return (__sfeof(fp)); -} diff --git a/stdio.subproj/ferror.c b/stdio.subproj/ferror.c deleted file mode 100644 index ef590e5..0000000 --- a/stdio.subproj/ferror.c +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * 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 - -/* - * A subroutine version of the macro ferror. - */ -#undef ferror - -int -ferror(fp) - FILE *fp; -{ - return (__sferror(fp)); -} diff --git a/stdio.subproj/fflush.c b/stdio.subproj/fflush.c deleted file mode 100644 index 33793d4..0000000 --- a/stdio.subproj/fflush.c +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * 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 -#include -#include "local.h" - -/* Flush a single file, or (if fp is NULL) all files. */ -int -fflush(fp) - register FILE *fp; -{ - - if (fp == NULL) - return (_fwalk(__sflush)); - if ((fp->_flags & (__SWR | __SRW)) == 0) { - errno = EBADF; - return (EOF); - } - return (__sflush(fp)); -} - -int -__sflush(fp) - register FILE *fp; -{ - register unsigned char *p; - register int n, t; - - t = fp->_flags; - if ((t & __SWR) == 0) - return (0); - - if ((p = fp->_bf._base) == NULL) - return (0); - - n = fp->_p - p; /* write this much */ - - /* - * Set these immediately to avoid problems with longjmp and to allow - * exchange buffering (via setvbuf) in user write function. - */ - fp->_p = p; - fp->_w = t & (__SLBF|__SNBF) ? 0 : fp->_bf._size; - - for (; n > 0; n -= t, p += t) { - t = (*fp->_write)(fp->_cookie, (char *)p, n); - if (t <= 0) { - fp->_flags |= __SERR; - return (EOF); - } - } - return (0); -} diff --git a/stdio.subproj/fgetc.c b/stdio.subproj/fgetc.c deleted file mode 100644 index 78a771b..0000000 --- a/stdio.subproj/fgetc.c +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * 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 - -int -fgetc(fp) - FILE *fp; -{ - return (__sgetc(fp)); -} diff --git a/stdio.subproj/fgetln.c b/stdio.subproj/fgetln.c deleted file mode 100644 index d1ce9d5..0000000 --- a/stdio.subproj/fgetln.c +++ /dev/null @@ -1,179 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * 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 -#include -#include -#include "local.h" - -/* - * Expand the line buffer. Return -1 on error. -#ifdef notdef - * The `new size' does not account for a terminating '\0', - * so we add 1 here. -#endif - */ -int -__slbexpand(fp, newsize) - FILE *fp; - size_t newsize; -{ - void *p; - -#ifdef notdef - ++newsize; -#endif - if (fp->_lb._size >= newsize) - return (0); - if ((p = realloc(fp->_lb._base, newsize)) == NULL) - return (-1); - fp->_lb._base = p; - fp->_lb._size = newsize; - return (0); -} - -/* - * Get an input line. The returned pointer often (but not always) - * points into a stdio buffer. Fgetln does not alter the text of - * the returned line (which is thus not a C string because it will - * not necessarily end with '\0'), but does allow callers to modify - * it if they wish. Thus, we set __SMOD in case the caller does. - */ -char * -fgetln(fp, lenp) - register FILE *fp; - size_t *lenp; -{ - register unsigned char *p; - register size_t len; - size_t off; - - /* make sure there is input */ - if (fp->_r <= 0 && __srefill(fp)) { - *lenp = 0; - return (NULL); - } - - /* look for a newline in the input */ - if ((p = memchr((void *)fp->_p, '\n', fp->_r)) != NULL) { - register char *ret; - - /* - * Found one. Flag buffer as modified to keep fseek from - * `optimising' a backward seek, in case the user stomps on - * the text. - */ - p++; /* advance over it */ - ret = (char *)fp->_p; - *lenp = len = p - fp->_p; - fp->_flags |= __SMOD; - fp->_r -= len; - fp->_p = p; - return (ret); - } - - /* - * We have to copy the current buffered data to the line buffer. - * As a bonus, though, we can leave off the __SMOD. - * - * OPTIMISTIC is length that we (optimistically) expect will - * accomodate the `rest' of the string, on each trip through the - * loop below. - */ -#define OPTIMISTIC 80 - - for (len = fp->_r, off = 0;; len += fp->_r) { - register size_t diff; - - /* - * Make sure there is room for more bytes. Copy data from - * 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)) - goto error; - (void)memcpy((void *)(fp->_lb._base + off), (void *)fp->_p, - len - off); - off = len; - if (__srefill(fp)) - break; /* EOF or error: return partial line */ - if ((p = memchr((void *)fp->_p, '\n', fp->_r)) == NULL) - continue; - - /* got it: finish up the line (like code above) */ - p++; - diff = p - fp->_p; - len += diff; - if (__slbexpand(fp, len)) - goto error; - (void)memcpy((void *)(fp->_lb._base + off), (void *)fp->_p, - diff); - fp->_r -= diff; - fp->_p = p; - break; - } - *lenp = len; -#ifdef notdef - fp->_lb._base[len] = 0; -#endif - return ((char *)fp->_lb._base); - -error: - *lenp = 0; /* ??? */ - return (NULL); /* ??? */ -} diff --git a/stdio.subproj/fgetpos.c b/stdio.subproj/fgetpos.c deleted file mode 100644 index 0dfafd6..0000000 --- a/stdio.subproj/fgetpos.c +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * 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 - -int -fgetpos(fp, pos) - FILE *fp; - fpos_t *pos; -{ - int retval; - /* FLOCKFILE(fp); */ - retval = (*pos = ftello(fp)) == (fpos_t)-1; - /* FUNLOCKFILE(fp); */ - return(retval); -} diff --git a/stdio.subproj/fgets.c b/stdio.subproj/fgets.c deleted file mode 100644 index 45da44e..0000000 --- a/stdio.subproj/fgets.c +++ /dev/null @@ -1,122 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * 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 -#include - -/* - * Read at most n-1 characters from the given file. - * Stop when a newline has been read, or the count runs out. - * Return first argument, or NULL if no characters were read. - */ -char * -fgets(buf, n, fp) - char *buf; - register size_t n; - register FILE *fp; -{ - register size_t len; - register char *s; - register unsigned char *p, *t; - - if (n == 0) /* sanity check */ - return (NULL); - - s = buf; - n--; /* leave space for NUL */ - while (n != 0) { - /* - * If the buffer is empty, refill it. - */ - if ((len = fp->_r) <= 0) { - if (__srefill(fp)) { - /* EOF/error: stop with partial or no line */ - if (s == buf) - return (NULL); - break; - } - len = fp->_r; - } - p = fp->_p; - - /* - * Scan through at most n bytes of the current buffer, - * looking for '\n'. If found, copy up to and including - * newline, and stop. Otherwise, copy entire chunk - * and loop. - */ - if (len > n) - len = n; - t = memchr((void *)p, '\n', len); - if (t != NULL) { - len = ++t - p; - fp->_r -= len; - fp->_p = t; - (void)memcpy((void *)s, (void *)p, len); - s[len] = 0; - return (buf); - } - fp->_r -= len; - fp->_p += len; - (void)memcpy((void *)s, (void *)p, len); - s += len; - n -= len; - } - *s = 0; - return (buf); -} diff --git a/stdio.subproj/fileno.c b/stdio.subproj/fileno.c deleted file mode 100644 index b5d106a..0000000 --- a/stdio.subproj/fileno.c +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * 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 - -/* - * A subroutine version of the macro fileno. - */ -#undef fileno - -int -fileno(fp) - FILE *fp; -{ - return (__sfileno(fp)); -} diff --git a/stdio.subproj/findfp.c b/stdio.subproj/findfp.c deleted file mode 100644 index 405a911..0000000 --- a/stdio.subproj/findfp.c +++ /dev/null @@ -1,184 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * 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 -#include -#include -#include -#include -#include -#include "local.h" -#include "glue.h" - -int __sdidinit = 0; - -#define NDYNAMIC 10 /* add ten more whenever necessary */ - -#define std(flags, file) \ - {0,0,0,flags,file,{0},0,__sF+file,__sclose,__sread,__sseek,__swrite} -/* p r w flags file _bf z cookie close read seek write */ - - /* the usual - (stdin + stdout + stderr) */ -static FILE usual[FOPEN_MAX - 3]; -static struct glue uglue = { 0, FOPEN_MAX - 3, usual }; - -FILE __sF[3] = { - std(__SRD, STDIN_FILENO), /* stdin */ - std(__SWR, STDOUT_FILENO), /* stdout */ - std(__SWR|__SNBF, STDERR_FILENO) /* stderr */ -}; -struct glue __sglue = { &uglue, 3, __sF }; - -static struct glue * -moreglue(n) - register int n; -{ - register struct glue *g; - register FILE *p; - static FILE empty; - - g = (struct glue *)malloc(sizeof(*g) + ALIGNBYTES + n * sizeof(FILE)); - if (g == NULL) - return (NULL); - p = (FILE *)ALIGN(g + 1); - g->next = NULL; - g->niobs = n; - g->iobs = p; - while (--n >= 0) - *p++ = empty; - return (g); -} - -/* - * Find a free FILE for fopen et al. - */ -FILE * -__sfp() -{ - register FILE *fp; - register int n; - register struct glue *g; - - if (!__sdidinit) - __sinit(); - for (g = &__sglue;; g = g->next) { - for (fp = g->iobs, n = g->niobs; --n >= 0; fp++) - if (fp->_flags == 0) - goto found; - if (g->next == NULL && (g->next = moreglue(NDYNAMIC)) == NULL) - break; - } - return (NULL); -found: - fp->_flags = 1; /* reserve this slot; caller sets real flags */ - fp->_p = NULL; /* no current pointer */ - fp->_w = 0; /* nothing to read or write */ - fp->_r = 0; - fp->_bf._base = NULL; /* no buffer */ - fp->_bf._size = 0; - fp->_lbfsize = 0; /* not line buffered */ - fp->_file = -1; /* no file */ -/* fp->_cookie = ; */ /* caller sets cookie, _read/_write etc */ - fp->_ub._base = NULL; /* no ungetc buffer */ - fp->_ub._size = 0; - fp->_lb._base = NULL; /* no line buffer */ - fp->_lb._size = 0; - return (fp); -} - -/* - * XXX. Force immediate allocation of internal memory. Not used by stdio, - * but documented historically for certain applications. Bad applications. - */ -void -f_prealloc() -{ - register struct glue *g; - int n; - - n = getdtablesize() - FOPEN_MAX + 20; /* 20 for slop. */ - for (g = &__sglue; (n -= g->niobs) > 0 && g->next; g = g->next) - /* void */; - if (n > 0) - g->next = moreglue(n); -} - -/* - * exit() calls _cleanup() through *__cleanup, set whenever we - * open or buffer a file. This chicanery is done so that programs - * that do not use stdio need not link it all in. - * - * The name `_cleanup' is, alas, fairly well known outside stdio. - */ -void -_cleanup() -{ - /* (void) _fwalk(fclose); */ - (void) _fwalk(__sflush); /* `cheating' */ -} - -/* - * __sinit() is called whenever stdio's internal variables must be set up. - */ -void -__sinit() -{ - /* make sure we clean up on exit */ - __cleanup = _cleanup; /* conservative */ - __sdidinit = 1; -} diff --git a/stdio.subproj/flags.c b/stdio.subproj/flags.c deleted file mode 100644 index 22cc1e9..0000000 --- a/stdio.subproj/flags.c +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * 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 -#include -#include -#include - -/* - * Return the (stdio) flags for a given mode. Store the flags - * to be passed to an open() syscall through *optr. - * Return 0 on error. - */ -int -__sflags(mode, optr) - register char *mode; - int *optr; -{ - register int ret, m, o; - - switch (*mode++) { - - case 'r': /* open for reading */ - ret = __SRD; - m = O_RDONLY; - o = 0; - break; - - case 'w': /* open for writing */ - ret = __SWR; - m = O_WRONLY; - o = O_CREAT | O_TRUNC; - break; - - case 'a': /* open for appending */ - ret = __SWR; - m = O_WRONLY; - o = O_CREAT | O_APPEND; - break; - - default: /* illegal mode */ - errno = EINVAL; - return (0); - } - - /* [rwa]\+ or [rwa]b\+ means read and write */ - if (*mode == '+' || (*mode == 'b' && mode[1] == '+')) { - ret = __SRW; - m = O_RDWR; - } - *optr = m | o; - return (ret); -} diff --git a/stdio.subproj/floatio.h b/stdio.subproj/floatio.h deleted file mode 100644 index 06be4a7..0000000 --- a/stdio.subproj/floatio.h +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * 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. - */ - -/* - * Floating point scanf/printf (input/output) definitions. - */ - -/* 11-bit exponent (VAX G floating point) is 308 decimal digits */ -#define MAXEXP 308 -/* 128 bit fraction takes up 39 decimal digits; max reasonable precision */ -#define MAXFRACT 39 diff --git a/stdio.subproj/fopen.c b/stdio.subproj/fopen.c deleted file mode 100644 index 4f10f39..0000000 --- a/stdio.subproj/fopen.c +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * 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 -#include -#include -#include -#include -#include "local.h" - -FILE * -fopen(file, mode) - const char *file; - const char *mode; -{ - register FILE *fp; - register int f; - int flags, oflags; - - if ((flags = __sflags(mode, &oflags)) == 0) - return (NULL); - if ((fp = __sfp()) == NULL) - return (NULL); - if ((f = open(file, oflags, DEFFILEMODE)) < 0) { - fp->_flags = 0; /* release */ - return (NULL); - } - fp->_file = f; - fp->_flags = flags; - fp->_cookie = fp; - fp->_read = __sread; - fp->_write = __swrite; - fp->_seek = __sseek; - fp->_close = __sclose; - - /* - * When opening in append mode, even though we use O_APPEND, - * we need to seek to the end so that ftell() gets the right - * answer. If the user then alters the seek pointer, or - * the file extends, this will fail, but there is not much - * we can do about this. (We could set __SAPP and check in - * fseek and ftell.) - */ - if (oflags & O_APPEND) - (void) __sseek((void *)fp, (fpos_t)0, SEEK_END); - return (fp); -} diff --git a/stdio.subproj/fprintf.c b/stdio.subproj/fprintf.c deleted file mode 100644 index 761156d..0000000 --- a/stdio.subproj/fprintf.c +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * 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 -#if __STDC__ -#include -#else -#include -#endif - -int -#if __STDC__ -fprintf(FILE *fp, const char *fmt, ...) -#else -fprintf(fp, fmt, va_alist) - FILE *fp; - char *fmt; - va_dcl -#endif -{ - int ret; - va_list ap; - -#if __STDC__ - va_start(ap, fmt); -#else - va_start(ap); -#endif - ret = vfprintf(fp, fmt, ap); - va_end(ap); - return (ret); -} diff --git a/stdio.subproj/fpurge.c b/stdio.subproj/fpurge.c deleted file mode 100644 index 65c0fad..0000000 --- a/stdio.subproj/fpurge.c +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * 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 -#include -#include -#include "local.h" - -/* - * fpurge: like fflush, but without writing anything: leave the - * given FILE's buffer empty. - */ -int -fpurge(fp) - register FILE *fp; -{ - if (!fp->_flags) { - errno = EBADF; - return(EOF); - } - - if (HASUB(fp)) - FREEUB(fp); - fp->_p = fp->_bf._base; - fp->_r = 0; - fp->_w = fp->_flags & (__SLBF|__SNBF) ? 0 : fp->_bf._size; - return (0); -} diff --git a/stdio.subproj/fputc.c b/stdio.subproj/fputc.c deleted file mode 100644 index 2e31e22..0000000 --- a/stdio.subproj/fputc.c +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * 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 - -int -fputc(c, fp) - int c; - register FILE *fp; -{ - return (putc(c, fp)); -} diff --git a/stdio.subproj/fputs.c b/stdio.subproj/fputs.c deleted file mode 100644 index 855db46..0000000 --- a/stdio.subproj/fputs.c +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * 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 -#include -#include "fvwrite.h" - -/* - * Write the given string to the given file. - */ -int -fputs(s, fp) - const char *s; - FILE *fp; -{ - struct __suio uio; - struct __siov iov; - - iov.iov_base = (void *)s; - iov.iov_len = uio.uio_resid = strlen(s); - uio.uio_iov = &iov; - uio.uio_iovcnt = 1; - return (__sfvwrite(fp, &uio)); -} diff --git a/stdio.subproj/fread.c b/stdio.subproj/fread.c deleted file mode 100644 index 5d622ea..0000000 --- a/stdio.subproj/fread.c +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * 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 -#include - -size_t -fread(buf, size, count, fp) - void *buf; - size_t size, count; - register FILE *fp; -{ - register size_t resid; - register char *p; - register int r; - size_t total; - - /* - * The ANSI standard requires a return value of 0 for a count - * or a size of 0. Peculiarily, it imposes no such requirements - * on fwrite; it only requires fread to be broken. - */ - if ((resid = count * size) == 0) - return (0); - if (fp->_r < 0) - fp->_r = 0; - total = resid; - p = buf; - while (resid > (r = fp->_r)) { - (void)memcpy((void *)p, (void *)fp->_p, (size_t)r); - fp->_p += r; - /* fp->_r = 0 ... done in __srefill */ - p += r; - resid -= r; - if (__srefill(fp)) { - /* no more input: return partial result */ - return ((total - resid) / size); - } - } - (void)memcpy((void *)p, (void *)fp->_p, resid); - fp->_r -= resid; - fp->_p += resid; - return (count); -} diff --git a/stdio.subproj/freopen.c b/stdio.subproj/freopen.c deleted file mode 100644 index 9e38851..0000000 --- a/stdio.subproj/freopen.c +++ /dev/null @@ -1,173 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * 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 -#include -#include -#include -#include -#include -#include -#include "local.h" - -/* - * Re-direct an existing, open (probably) file to some other file. - * ANSI is written such that the original file gets closed if at - * all possible, no matter what. - */ -FILE * -freopen(file, mode, fp) - const char *file, *mode; - register FILE *fp; -{ - register int f; - int flags, isopen, oflags, sverrno, wantfd; - - if ((flags = __sflags(mode, &oflags)) == 0) { - (void) fclose(fp); - return (NULL); - } - - if (!__sdidinit) - __sinit(); - - /* - * There are actually programs that depend on being able to "freopen" - * descriptors that weren't originally open. Keep this from breaking. - * Remember whether the stream was open to begin with, and which file - * 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. - */ - if (fp->_flags == 0) { - fp->_flags = __SEOF; /* hold on to it */ - isopen = 0; - wantfd = -1; - } else { - /* flush the stream; ANSI doesn't require this. */ - if (fp->_flags & __SWR) - (void) __sflush(fp); - /* if close is NULL, closing is a no-op, hence pointless */ - isopen = fp->_close != NULL; - if ((wantfd = fp->_file) < 0 && isopen) { - (void) (*fp->_close)(fp->_cookie); - isopen = 0; - } - } - - /* Get a new descriptor to refer to the new file. */ - f = open(file, oflags, DEFFILEMODE); - if (f < 0 && isopen) { - /* If out of fd's close the old one and try again. */ - if (errno == ENFILE || errno == EMFILE) { - (void) (*fp->_close)(fp->_cookie); - isopen = 0; - f = open(file, oflags, DEFFILEMODE); - } - } - sverrno = errno; - - /* - * Finish closing fp. Even if the open succeeded above, we cannot - * keep fp->_base: it may be the wrong size. This loses the effect - * of any setbuffer calls, but stdio has always done this before. - */ - if (isopen) - (void) (*fp->_close)(fp->_cookie); - if (fp->_flags & __SMBF) - free((char *)fp->_bf._base); - fp->_w = 0; - fp->_r = 0; - fp->_p = NULL; - fp->_bf._base = NULL; - fp->_bf._size = 0; - fp->_lbfsize = 0; - if (HASUB(fp)) - FREEUB(fp); - fp->_ub._size = 0; - if (HASLB(fp)) - FREELB(fp); - fp->_lb._size = 0; - - if (f < 0) { /* did not get it after all */ - fp->_flags = 0; /* set it free */ - errno = sverrno; /* restore in case _close clobbered */ - return (NULL); - } - - /* - * If reopening something that was open before on a real file, try - * to maintain the descriptor. Various C library routines (perror) - * assume stderr is always fd STDERR_FILENO, even if being freopen'd. - */ - if (wantfd >= 0 && f != wantfd) { - if (dup2(f, wantfd) >= 0) { - (void) close(f); - f = wantfd; - } - } - - fp->_flags = flags; - fp->_file = f; - fp->_cookie = fp; - fp->_read = __sread; - fp->_write = __swrite; - fp->_seek = __sseek; - fp->_close = __sclose; - return (fp); -} diff --git a/stdio.subproj/fscanf.c b/stdio.subproj/fscanf.c deleted file mode 100644 index 27a3028..0000000 --- a/stdio.subproj/fscanf.c +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * 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 -#if __STDC__ -#include -#else -#include -#endif - -int -#if __STDC__ -fscanf(FILE *fp, char const *fmt, ...) { - int ret; - va_list ap; - - va_start(ap, fmt); -#else -fscanf(fp, fmt, va_alist) - FILE *fp; - char *fmt; - va_dcl -{ - int ret; - va_list ap; - - va_start(ap); -#endif - ret = __svfscanf(fp, fmt, ap); - va_end(ap); - return (ret); -} diff --git a/stdio.subproj/fseek.c b/stdio.subproj/fseek.c deleted file mode 100644 index 802e3cc..0000000 --- a/stdio.subproj/fseek.c +++ /dev/null @@ -1,284 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * 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 -#include -#include -#include -#include -#include -#include -#include "local.h" - -#define POS_ERR (-(fpos_t)1) - -int -fseek(fp, offset, whence) - register FILE *fp; - long offset; - int whence; -{ - return (fseeko(fp, offset, whence)); -} - - -/* - * Seek the given file to the given offset. - * `Whence' must be one of the three SEEK_* macros. - */ -int -fseeko(fp, offset, whence) - register FILE *fp; - off_t offset; - int whence; -{ - register fpos_t (*seekfn) __P((void *, fpos_t, int)); - fpos_t target, curoff; - size_t n; - struct stat st; - int havepos; - - /* make sure stdio is set up */ - if (!__sdidinit) - __sinit(); - - /* FLOCKFILE(fp); */ - /* - * Have to be able to seek. - */ - if ((seekfn = fp->_seek) == NULL) { - errno = ESPIPE; /* historic practice */ - /* FUNLOCKFILE(fp); */ - return (EOF); - } - - /* - * Change any SEEK_CUR to SEEK_SET, and check `whence' argument. - * After this, whence is either SEEK_SET or SEEK_END. - */ - switch (whence) { - - case SEEK_CUR: - /* - * In order to seek relative to the current stream offset, - * we have to first find the current stream offset a la - * ftell (see ftell for details). - */ - if (fp->_flags & __SOFF) - curoff = fp->_offset; - else { - curoff = (*seekfn)(fp->_cookie, (fpos_t)0, SEEK_CUR); - if (curoff == -1) { - /* FUNLOCKFILE(fp); */ - return (EOF); - } - } - if (fp->_flags & __SRD) { - curoff -= fp->_r; - if (HASUB(fp)) - curoff -= fp->_ur; - } else if (fp->_flags & __SWR && fp->_p != NULL) - curoff += fp->_p - fp->_bf._base; - - offset += curoff; - whence = SEEK_SET; - havepos = 1; - break; - - case SEEK_SET: - case SEEK_END: - curoff = 0; /* XXX just to keep gcc quiet */ - havepos = 0; - break; - - default: - errno = EINVAL; - /* FUNLOCKFILE(fp); */ - return (EOF); - } - - /* - * Can only optimise if: - * reading (and not reading-and-writing); - * not unbuffered; and - * this is a `regular' Unix file (and hence seekfn==__sseek). - * We must check __NBF first, because it is possible to have __NBF - * and __SOPT both set. - */ - if (fp->_bf._base == NULL) - __smakebuf(fp); - if (fp->_flags & (__SWR | __SRW | __SNBF | __SNPT)) - goto dumb; - if ((fp->_flags & __SOPT) == 0) { - if (seekfn != __sseek || - fp->_file < 0 || fstat(fp->_file, &st) || - (st.st_mode & S_IFMT) != S_IFREG) { - fp->_flags |= __SNPT; - goto dumb; - } - fp->_blksize = st.st_blksize; - fp->_flags |= __SOPT; - } - - /* - * We are reading; we can try to optimise. - * Figure out where we are going and where we are now. - */ - if (whence == SEEK_SET) - target = offset; - else { - if (fstat(fp->_file, &st)) - goto dumb; - target = st.st_size + offset; - } - - if (!havepos) { - if (fp->_flags & __SOFF) - curoff = fp->_offset; - else { - curoff = (*seekfn)(fp->_cookie, (fpos_t)0, SEEK_CUR); - if (curoff == POS_ERR) - goto dumb; - } - curoff -= fp->_r; - if (HASUB(fp)) - curoff -= fp->_ur; - } - - /* - * Compute the number of bytes in the input buffer (pretending - * that any ungetc() input has been discarded). Adjust current - * offset backwards by this count so that it represents the - * file offset for the first byte in the current input buffer. - */ - if (HASUB(fp)) { - curoff += fp->_r; /* kill off ungetc */ - n = fp->_up - fp->_bf._base; - curoff -= n; - n += fp->_ur; - } else { - n = fp->_p - fp->_bf._base; - curoff -= n; - n += fp->_r; - } - - /* - * If the target offset is within the current buffer, - * simply adjust the pointers, clear EOF, undo ungetc(), - * and return. (If the buffer was modified, we have to - * skip this; see fgetln.c.) - */ - if ((fp->_flags & __SMOD) == 0 && - target >= curoff && target < curoff + n) { - register int o = target - curoff; - - fp->_p = fp->_bf._base + o; - fp->_r = n - o; - if (HASUB(fp)) - FREEUB(fp); - fp->_flags &= ~__SEOF; - /* FUNLOCKFILE(fp); */ - return (0); - } - - /* - * The place we want to get to is not within the current buffer, - * but we can still be kind to the kernel copyout mechanism. - * By aligning the file offset to a block boundary, we can let - * the kernel use the VM hardware to map pages instead of - * copying bytes laboriously. Using a block boundary also - * ensures that we only read one block, rather than two. - */ - curoff = target & ~(fp->_blksize - 1); - if ((*seekfn)(fp->_cookie, curoff, SEEK_SET) == POS_ERR) - goto dumb; - fp->_r = 0; - fp->_p = fp->_bf._base; - if (HASUB(fp)) - FREEUB(fp); - fp->_flags &= ~__SEOF; - n = target - curoff; - if (n) { - if (__srefill(fp) || fp->_r < n) - goto dumb; - fp->_p += n; - fp->_r -= n; - } - /* FUNLOCKFILE(fp); */ - return (0); - - /* - * We get here if we cannot optimise the seek ... just - * do it. Allow the seek function to change fp->_bf._base. - */ -dumb: - if (__sflush(fp) || - (*seekfn)(fp->_cookie, (fpos_t)offset, whence) == POS_ERR) { - /* FUNLOCKFILE(fp); */ - return (EOF); - } - /* success: clear EOF indicator and discard ungetc() data */ - if (HASUB(fp)) - FREEUB(fp); - fp->_p = fp->_bf._base; - fp->_r = 0; - /* fp->_w = 0; */ /* unnecessary (I think...) */ - fp->_flags &= ~__SEOF; - /* FUNLOCKFILE(fp); */ - return (0); -} diff --git a/stdio.subproj/fsetpos.c b/stdio.subproj/fsetpos.c deleted file mode 100644 index 7397bb9..0000000 --- a/stdio.subproj/fsetpos.c +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * 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 -#include - -/* - * fsetpos: like fseek. - */ -int -fsetpos(iop, pos) - FILE *iop; - const fpos_t *pos; -{ - return (fseeko(iop, (off_t)*pos, SEEK_SET)); -} diff --git a/stdio.subproj/ftell.c b/stdio.subproj/ftell.c deleted file mode 100644 index b899c66..0000000 --- a/stdio.subproj/ftell.c +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * 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 -#include -#include -#include "local.h" - -/* - * ftello: return current offset. - */ -off_t -ftello(fp) - register FILE *fp; -{ - register fpos_t pos; - - if (fp->_seek == NULL) { - errno = ESPIPE; /* historic practice */ - return (-1L); - } - - /* FLOCKFILE(fp); */ - /* - * Find offset of underlying I/O object, then - * adjust for buffered bytes. - */ - if (fp->_flags & __SOFF) - pos = fp->_offset; - else { - pos = (*fp->_seek)(fp->_cookie, (fpos_t)0, SEEK_CUR); - if (pos == -1) { - /* FUNLOCKFILE(fp); */ - return (pos); - } - } - if (fp->_flags & __SRD) { - /* - * Reading. Any unread characters (including - * those from ungetc) cause the position to be - * smaller than that in the underlying object. - */ - pos -= fp->_r; - if (HASUB(fp)) - pos -= fp->_ur; - } else if (fp->_flags & __SWR && fp->_p != NULL) { - /* - * Writing. Any buffered characters cause the - * position to be greater than that in the - * underlying object. - */ - pos += fp->_p - fp->_bf._base; - } - /* FUNLOCKFILE(fp); */ - return (pos); -} - -/* - * standard ftell function. - */ -long -ftell(fp) - register FILE *fp; -{ - register off_t rv; - rv = ftello(fp); - if ((long)rv != rv) { - errno = EOVERFLOW; - return (-1); - } - return (rv); -} diff --git a/stdio.subproj/funopen.c b/stdio.subproj/funopen.c deleted file mode 100644 index d96a23f..0000000 --- a/stdio.subproj/funopen.c +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * 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 -#include -#include "local.h" - -FILE * -funopen(cookie, readfn, writefn, seekfn, closefn) - const void *cookie; - int (*readfn)(), (*writefn)(); -#if __STDC__ - fpos_t (*seekfn)(void *cookie, fpos_t off, int whence); -#else - fpos_t (*seekfn)(); -#endif - int (*closefn)(); -{ - register FILE *fp; - int flags; - - if (readfn == NULL) { - if (writefn == NULL) { /* illegal */ - errno = EINVAL; - return (NULL); - } else - flags = __SWR; /* write only */ - } else { - if (writefn == NULL) - flags = __SRD; /* read only */ - else - flags = __SRW; /* read-write */ - } - if ((fp = __sfp()) == NULL) - return (NULL); - fp->_flags = flags; - fp->_file = -1; - fp->_cookie = (void *)cookie; - fp->_read = readfn; - fp->_write = writefn; - fp->_seek = seekfn; - fp->_close = closefn; - return (fp); -} diff --git a/stdio.subproj/fvwrite.c b/stdio.subproj/fvwrite.c deleted file mode 100644 index f7d2c86..0000000 --- a/stdio.subproj/fvwrite.c +++ /dev/null @@ -1,208 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * 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 -#include -#include "local.h" -#include "fvwrite.h" - -/* - * Write some memory regions. Return zero on success, EOF on error. - * - * This routine is large and unsightly, but most of the ugliness due - * to the three different kinds of output buffering is handled here. - */ -int -__sfvwrite(fp, uio) - register FILE *fp; - register struct __suio *uio; -{ - register size_t len; - register char *p; - register struct __siov *iov; - register int w, s; - char *nl; - int nlknown, nldist; - - if ((len = uio->uio_resid) == 0) - return (0); - /* make sure we can write */ - if (cantwrite(fp)) - return (EOF); - -#define MIN(a, b) ((a) < (b) ? (a) : (b)) -#define COPY(n) (void)memcpy((void *)fp->_p, (void *)p, (size_t)(n)) - - iov = uio->uio_iov; - p = iov->iov_base; - len = iov->iov_len; - iov++; -#define GETIOV(extra_work) \ - while (len == 0) { \ - extra_work; \ - p = iov->iov_base; \ - len = iov->iov_len; \ - iov++; \ - } - if (fp->_flags & __SNBF) { - /* - * Unbuffered: write up to BUFSIZ bytes at a time. - */ - do { - GETIOV(;); - w = (*fp->_write)(fp->_cookie, p, MIN(len, BUFSIZ)); - if (w <= 0) - goto err; - p += w; - len -= w; - } while ((uio->uio_resid -= w) != 0); - } else if ((fp->_flags & __SLBF) == 0) { - /* - * Fully buffered: fill partially full buffer, if any, - * and then flush. If there is no partial buffer, write - * one _bf._size byte chunk directly (without copying). - * - * String output is a special case: write as many bytes - * as fit, but pretend we wrote everything. This makes - * snprintf() return the number of bytes needed, rather - * than the number used, and avoids its write function - * (so that the write function can be invalid). - */ - do { - GETIOV(;); - w = fp->_w; - if (fp->_flags & __SSTR) { - if (len < w) - w = len; - COPY(w); /* copy MIN(fp->_w,len), */ - fp->_w -= w; - fp->_p += w; - w = len; /* but pretend copied all */ - } else if (fp->_p > fp->_bf._base && len > w) { - /* fill and flush */ - COPY(w); - /* fp->_w -= w; */ /* unneeded */ - fp->_p += w; - if (fflush(fp)) - goto err; - } else if (len >= (w = fp->_bf._size)) { - /* write directly */ - w = (*fp->_write)(fp->_cookie, p, w); - if (w <= 0) - goto err; - } else { - /* fill and done */ - w = len; - COPY(w); - fp->_w -= w; - fp->_p += w; - } - p += w; - len -= w; - } while ((uio->uio_resid -= w) != 0); - } else { - /* - * Line buffered: like fully buffered, but we - * must check for newlines. Compute the distance - * to the first newline (including the newline), - * or `infinity' if there is none, then pretend - * that the amount to write is MIN(len,nldist). - */ - nlknown = 0; - nldist = 0; /* XXX just to keep gcc happy */ - do { - GETIOV(nlknown = 0); - if (!nlknown) { - nl = memchr((void *)p, '\n', len); - nldist = nl ? nl + 1 - p : len + 1; - nlknown = 1; - } - s = MIN(len, nldist); - w = fp->_w + fp->_bf._size; - if (fp->_p > fp->_bf._base && s > w) { - COPY(w); - /* fp->_w -= w; */ - fp->_p += w; - if (fflush(fp)) - goto err; - } else if (s >= (w = fp->_bf._size)) { - w = (*fp->_write)(fp->_cookie, p, w); - if (w <= 0) - goto err; - } else { - w = s; - COPY(w); - fp->_w -= w; - fp->_p += w; - } - if ((nldist -= w) == 0) { - /* copied the newline: flush and forget */ - if (fflush(fp)) - goto err; - nlknown = 0; - } - p += w; - len -= w; - } while ((uio->uio_resid -= w) != 0); - } - return (0); - -err: - fp->_flags |= __SERR; - return (EOF); -} diff --git a/stdio.subproj/fvwrite.h b/stdio.subproj/fvwrite.h deleted file mode 100644 index 7b021ce..0000000 --- a/stdio.subproj/fvwrite.h +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * 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. - */ - -/* - * I/O descriptors for __sfvwrite(). - */ -struct __siov { - void *iov_base; - size_t iov_len; -}; -struct __suio { - struct __siov *uio_iov; - int uio_iovcnt; - int uio_resid; -}; - -#if __STDC__ || c_plusplus -extern int __sfvwrite(FILE *, struct __suio *); -#else -extern int __sfvwrite(); -#endif diff --git a/stdio.subproj/fwalk.c b/stdio.subproj/fwalk.c deleted file mode 100644 index ddbf641..0000000 --- a/stdio.subproj/fwalk.c +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * 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 -#include -#include "local.h" -#include "glue.h" - -int -_fwalk(function) - register int (*function)(); -{ - register FILE *fp; - register int n, ret; - register struct glue *g; - - ret = 0; - for (g = &__sglue; g != NULL; g = g->next) - for (fp = g->iobs, n = g->niobs; --n >= 0; fp++) - if (fp->_flags != 0) - ret |= (*function)(fp); - return (ret); -} diff --git a/stdio.subproj/fwrite.c b/stdio.subproj/fwrite.c deleted file mode 100644 index 7e4e82f..0000000 --- a/stdio.subproj/fwrite.c +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * 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 -#include "local.h" -#include "fvwrite.h" - -/* - * Write `count' objects (each size `size') from memory to the given file. - * Return the number of whole objects written. - */ -size_t -fwrite(buf, size, count, fp) - const void *buf; - size_t size, count; - FILE *fp; -{ - size_t n; - struct __suio uio; - struct __siov iov; - - iov.iov_base = (void *)buf; - uio.uio_resid = iov.iov_len = n = count * size; - uio.uio_iov = &iov; - uio.uio_iovcnt = 1; - - /* - * The usual case is success (__sfvwrite returns 0); - * skip the divide if this happens, since divides are - * generally slow and since this occurs whenever size==0. - */ - if (__sfvwrite(fp, &uio) == 0) - return (count); - return ((n - uio.uio_resid) / size); -} diff --git a/stdio.subproj/getc.c b/stdio.subproj/getc.c deleted file mode 100644 index b4af96a..0000000 --- a/stdio.subproj/getc.c +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * 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 - -/* - * A subroutine version of the macro getc. - */ -#undef getc - -int -getc(fp) - register FILE *fp; -{ - return (__sgetc(fp)); -} diff --git a/stdio.subproj/getchar.c b/stdio.subproj/getchar.c deleted file mode 100644 index e7d7e5a..0000000 --- a/stdio.subproj/getchar.c +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * 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. - */ - - -/* - * A subroutine version of the macro getchar. - */ -#include - -#undef getchar - -int -getchar() -{ - return (getc(stdin)); -} diff --git a/stdio.subproj/gets.c b/stdio.subproj/gets.c deleted file mode 100644 index ea8b1e5..0000000 --- a/stdio.subproj/gets.c +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * 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 -#include - -char * -gets(buf) - char *buf; -{ - register int c; - register char *s; - static int warned; - static char w[] = - "warning: this program uses gets(), which is unsafe.\r\n"; - - if (!warned) { - (void) write(STDERR_FILENO, w, sizeof(w) - 1); - warned = 1; - } - for (s = buf; (c = getchar()) != '\n';) - if (c == EOF) - if (s == buf) - return (NULL); - else - break; - else - *s++ = c; - *s = 0; - return (buf); -} diff --git a/stdio.subproj/getw.c b/stdio.subproj/getw.c deleted file mode 100644 index a2776b3..0000000 --- a/stdio.subproj/getw.c +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * 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 - -int -getw(fp) - FILE *fp; -{ - int x; - - return (fread((void *)&x, sizeof(x), 1, fp) == 1 ? x : EOF); -} diff --git a/stdio.subproj/glue.h b/stdio.subproj/glue.h deleted file mode 100644 index 4636067..0000000 --- a/stdio.subproj/glue.h +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * 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. - */ - -/* - * The first few FILEs are statically allocated; others are dynamically - * allocated and linked in via this glue structure. - */ -struct glue { - struct glue *next; - int niobs; - FILE *iobs; -}; - -extern struct glue __sglue; diff --git a/stdio.subproj/local.h b/stdio.subproj/local.h deleted file mode 100644 index ae80de0..0000000 --- a/stdio.subproj/local.h +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * 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. - */ - -/* - * Information local to this implementation of stdio, - * in particular, macros and private variables. - */ - -extern int __sflush __P((FILE *)); -extern FILE *__sfp __P((void)); -extern int __srefill __P((FILE *)); -extern int __sread __P((void *, char *, int)); -extern int __swrite __P((void *, char const *, int)); -extern fpos_t __sseek __P((void *, fpos_t, int)); -extern int __sclose __P((void *)); -extern void __sinit __P((void)); -extern void _cleanup __P((void)); -extern void (*__cleanup) __P((void)); -extern void __smakebuf __P((FILE *)); -extern int __swhatbuf __P((FILE *, size_t *, int *)); -extern int _fwalk __P((int (*)(FILE *))); -extern int __swsetup __P((FILE *)); -extern int __sflags __P((const char *, int *)); - -extern int __sdidinit; -extern void (*__cleanup) __P((void)); - -/* - * Return true iff the given FILE cannot be written now. - */ -#define cantwrite(fp) \ - ((((fp)->_flags & __SWR) == 0 || (fp)->_bf._base == NULL) && \ - __swsetup(fp)) - -/* - * Test whether the given stdio file has an active ungetc buffer; - * release such a buffer, without restoring ordinary unread data. - */ -#define HASUB(fp) ((fp)->_ub._base != NULL) -#define FREEUB(fp) { \ - if ((fp)->_ub._base != (fp)->_ubuf) \ - free((char *)(fp)->_ub._base); \ - (fp)->_ub._base = NULL; \ -} - -/* - * test for an fgetln() buffer. - */ -#define HASLB(fp) ((fp)->_lb._base != NULL) -#define FREELB(fp) { \ - free((char *)(fp)->_lb._base); \ - (fp)->_lb._base = NULL; \ -} diff --git a/stdio.subproj/makebuf.c b/stdio.subproj/makebuf.c deleted file mode 100644 index 89c3bbb..0000000 --- a/stdio.subproj/makebuf.c +++ /dev/null @@ -1,136 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * 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 -#include -#include -#include -#include -#include "local.h" - -/* - * Allocate a file buffer, or switch to unbuffered I/O. - * Per the ANSI C standard, ALL tty devices default to line buffered. - * - * As a side effect, we set __SOPT or __SNPT (en/dis-able fseek - * optimisation) right after the fstat() that finds the buffer size. - */ -void -__smakebuf(fp) - register FILE *fp; -{ - register void *p; - register int flags; - size_t size; - int couldbetty; - - if (fp->_flags & __SNBF) { - fp->_bf._base = fp->_p = fp->_nbuf; - fp->_bf._size = 1; - return; - } - flags = __swhatbuf(fp, &size, &couldbetty); - if ((p = malloc(size)) == NULL) { - fp->_flags |= __SNBF; - fp->_bf._base = fp->_p = fp->_nbuf; - fp->_bf._size = 1; - return; - } - __cleanup = _cleanup; - flags |= __SMBF; - fp->_bf._base = fp->_p = p; - fp->_bf._size = size; - if (couldbetty && isatty(fp->_file)) - flags |= __SLBF; - fp->_flags |= flags; -} - -/* - * Internal routine to determine `proper' buffering for a file. - */ -int -__swhatbuf(fp, bufsize, couldbetty) - register FILE *fp; - size_t *bufsize; - int *couldbetty; -{ - struct stat st; - - if (fp->_file < 0 || fstat(fp->_file, &st) < 0) { - *couldbetty = 0; - *bufsize = BUFSIZ; - return (__SNPT); - } - - /* could be a tty iff it is a character device */ - *couldbetty = (st.st_mode & S_IFMT) == S_IFCHR; - if (st.st_blksize <= 0) { - *bufsize = BUFSIZ; - return (__SNPT); - } - - /* - * Optimise fseek() only if it is a regular file. (The test for - * __sseek is mainly paranoia.) It is safe to set _blksize - * unconditionally; it will only be used if __SOPT is also set. - */ - *bufsize = st.st_blksize; - fp->_blksize = st.st_blksize; - return ((st.st_mode & S_IFMT) == S_IFREG && fp->_seek == __sseek ? - __SOPT : __SNPT); -} diff --git a/stdio.subproj/mktemp.c b/stdio.subproj/mktemp.c deleted file mode 100644 index e6e29eb..0000000 --- a/stdio.subproj/mktemp.c +++ /dev/null @@ -1,145 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1987, 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 -#include -#include -#include -#include -#include -#include - -static int _gettemp(); - -int -mkstemp(path) - char *path; -{ - int fd; - - return (_gettemp(path, &fd) ? fd : -1); -} - -char * -mktemp(path) - char *path; -{ - return(_gettemp(path, (int *)NULL) ? path : (char *)NULL); -} - -static int -_gettemp(path, doopen) - char *path; - register int *doopen; -{ - register char *start, *trv; - struct stat sbuf; - u_int pid; - - pid = getpid(); - for (trv = path; *trv; ++trv); /* extra X's get set to 0's */ - while (*--trv == 'X') { - *trv = (pid % 10) + '0'; - pid /= 10; - } - - /* - * check the target directory; if you have six X's and it - * doesn't exist this runs for a *very* long time. - */ - for (start = trv + 1;; --trv) { - if (trv <= path) - break; - if (*trv == '/') { - *trv = '\0'; - if (stat(path, &sbuf)) - return(0); - if (!S_ISDIR(sbuf.st_mode)) { - errno = ENOTDIR; - return(0); - } - *trv = '/'; - break; - } - } - - for (;;) { - if (doopen) { - if ((*doopen = - open(path, O_CREAT|O_EXCL|O_RDWR, 0600)) >= 0) - return(1); - if (errno != EEXIST) - return(0); - } - else if (stat(path, &sbuf)) - return(errno == ENOENT ? 1 : 0); - - /* tricky little algorithm for backward compatibility */ - for (trv = start;;) { - if (!*trv) - return(0); - if (*trv == 'z') - *trv++ = 'a'; - else { - if (isdigit(*trv)) - *trv = 'a'; - else - ++*trv; - break; - } - } - } - /*NOTREACHED*/ -} diff --git a/stdio.subproj/perror.c b/stdio.subproj/perror.c deleted file mode 100644 index 7a3c4f5..0000000 --- a/stdio.subproj/perror.c +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1988, 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 -#include -#include -#include -#include -#include - -void -perror(s) - const char *s; -{ - register struct iovec *v; - struct iovec iov[4]; - - v = iov; - if (s && *s) { - v->iov_base = (char *)s; - v->iov_len = strlen(s); - v++; - v->iov_base = ": "; - v->iov_len = 2; - v++; - } - v->iov_base = strerror(errno); - v->iov_len = strlen(v->iov_base); - v++; - v->iov_base = "\n"; - v->iov_len = 1; - (void)writev(STDERR_FILENO, iov, (v - iov) + 1); -} diff --git a/stdio.subproj/printf.c b/stdio.subproj/printf.c deleted file mode 100644 index a7e2385..0000000 --- a/stdio.subproj/printf.c +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * 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 -#if __STDC__ -#include -#else -#include -#endif - -int -#if __STDC__ -printf(char const *fmt, ...) -#else -printf(fmt, va_alist) - char *fmt; - va_dcl -#endif -{ - int ret; - va_list ap; - -#if __STDC__ - va_start(ap, fmt); -#else - va_start(ap); -#endif - ret = vfprintf(stdout, fmt, ap); - va_end(ap); - return (ret); -} diff --git a/stdio.subproj/putc.c b/stdio.subproj/putc.c deleted file mode 100644 index f4ca592..0000000 --- a/stdio.subproj/putc.c +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * 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 - -/* - * A subroutine version of the macro putc. - */ -#undef putc - -int -putc(c, fp) - int c; - register FILE *fp; -{ - return (__sputc(c, fp)); -} diff --git a/stdio.subproj/putchar.c b/stdio.subproj/putchar.c deleted file mode 100644 index b69fabe..0000000 --- a/stdio.subproj/putchar.c +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * 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 - -#undef putchar - -/* - * A subroutine version of the macro putchar - */ -int -putchar(c) - int c; -{ - register FILE *so = stdout; - - return (__sputc(c, so)); -} diff --git a/stdio.subproj/puts.c b/stdio.subproj/puts.c deleted file mode 100644 index 31ae510..0000000 --- a/stdio.subproj/puts.c +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * 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 -#include -#include "fvwrite.h" - -/* - * Write the given string to stdout, appending a newline. - */ -int -puts(s) - char const *s; -{ - size_t c = strlen(s); - struct __suio uio; - struct __siov iov[2]; - - iov[0].iov_base = (void *)s; - iov[0].iov_len = c; - iov[1].iov_base = "\n"; - iov[1].iov_len = 1; - uio.uio_resid = c + 1; - uio.uio_iov = &iov[0]; - uio.uio_iovcnt = 2; - return (__sfvwrite(stdout, &uio) ? EOF : '\n'); -} diff --git a/stdio.subproj/putw.c b/stdio.subproj/putw.c deleted file mode 100644 index 225f916..0000000 --- a/stdio.subproj/putw.c +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * 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 -#include "fvwrite.h" - -int -putw(w, fp) - int w; - FILE *fp; -{ - struct __suio uio; - struct __siov iov; - - iov.iov_base = &w; - iov.iov_len = uio.uio_resid = sizeof(w); - uio.uio_iov = &iov; - uio.uio_iovcnt = 1; - return (__sfvwrite(fp, &uio)); -} diff --git a/stdio.subproj/refill.c b/stdio.subproj/refill.c deleted file mode 100644 index 1af09b2..0000000 --- a/stdio.subproj/refill.c +++ /dev/null @@ -1,147 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * 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 -#include -#include -#include "local.h" - -static int -lflush(fp) - FILE *fp; -{ - - if ((fp->_flags & (__SLBF|__SWR)) == __SLBF|__SWR) - return (__sflush(fp)); - return (0); -} - -/* - * Refill a stdio buffer. - * Return EOF on eof or error, 0 otherwise. - */ -int -__srefill(fp) - register FILE *fp; -{ - - /* make sure stdio is set up */ - if (!__sdidinit) - __sinit(); - - fp->_r = 0; /* largely a convenience for callers */ - - /* SysV does not make this test; take it out for compatibility */ - if (fp->_flags & __SEOF) - return (EOF); - - /* if not already reading, have to be reading and writing */ - if ((fp->_flags & __SRD) == 0) { - if ((fp->_flags & __SRW) == 0) { - errno = EBADF; - return (EOF); - } - /* switch to reading */ - if (fp->_flags & __SWR) { - if (__sflush(fp)) - return (EOF); - fp->_flags &= ~__SWR; - fp->_w = 0; - fp->_lbfsize = 0; - } - fp->_flags |= __SRD; - } else { - /* - * We were reading. If there is an ungetc buffer, - * we must have been reading from that. Drop it, - * restoring the previous buffer (if any). If there - * is anything in that buffer, return. - */ - if (HASUB(fp)) { - FREEUB(fp); - if ((fp->_r = fp->_ur) != 0) { - fp->_p = fp->_up; - return (0); - } - } - } - - if (fp->_bf._base == NULL) - __smakebuf(fp); - - /* - * Before reading from a line buffered or unbuffered file, - * flush all line buffered output files, per the ANSI C - * standard. - */ - if (fp->_flags & (__SLBF|__SNBF)) - (void) _fwalk(lflush); - fp->_p = fp->_bf._base; - fp->_r = (*fp->_read)(fp->_cookie, (char *)fp->_p, fp->_bf._size); - fp->_flags &= ~__SMOD; /* buffer contents are again pristine */ - if (fp->_r <= 0) { - if (fp->_r == 0) - fp->_flags |= __SEOF; - else { - fp->_r = 0; - fp->_flags |= __SERR; - } - return (EOF); - } - return (0); -} diff --git a/stdio.subproj/remove.c b/stdio.subproj/remove.c deleted file mode 100644 index f20237e..0000000 --- a/stdio.subproj/remove.c +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * 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[] = "@(#)remove.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ - -#include -#include - -int -remove(file) - const char *file; -{ - return (unlink(file)); -} diff --git a/stdio.subproj/rewind.c b/stdio.subproj/rewind.c deleted file mode 100644 index f014fb6..0000000 --- a/stdio.subproj/rewind.c +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * 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 -#include - -void -rewind(fp) - register FILE *fp; -{ - (void) fseek(fp, 0L, SEEK_SET); - clearerr(fp); - errno = 0; /* not required, but seems reasonable */ -} diff --git a/stdio.subproj/rget.c b/stdio.subproj/rget.c deleted file mode 100644 index 7478d4f..0000000 --- a/stdio.subproj/rget.c +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * 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 - -/* - * Handle getc() when the buffer ran out: - * Refill, then return the first character - * in the newly-filled buffer. - */ -int -__srget(fp) - register FILE *fp; -{ - if (__srefill(fp) == 0) { - fp->_r--; - return (*fp->_p++); - } - return (EOF); -} diff --git a/stdio.subproj/scanf.c b/stdio.subproj/scanf.c deleted file mode 100644 index d2f6ce5..0000000 --- a/stdio.subproj/scanf.c +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * 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 -#if __STDC__ -#include -#else -#include -#endif - -int -#if __STDC__ -scanf(char const *fmt, ...) -#else -scanf(fmt, va_alist) - char *fmt; - va_dcl -#endif -{ - int ret; - va_list ap; - -#if __STDC__ - va_start(ap, fmt); -#else - va_start(ap); -#endif - ret = __svfscanf(stdin, fmt, ap); - va_end(ap); - return (ret); -} diff --git a/stdio.subproj/setbuf.c b/stdio.subproj/setbuf.c deleted file mode 100644 index 1180f10..0000000 --- a/stdio.subproj/setbuf.c +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * 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 -#include "local.h" - -void -setbuf(fp, buf) - FILE *fp; - char *buf; -{ - (void) setvbuf(fp, buf, buf ? _IOFBF : _IONBF, BUFSIZ); -} diff --git a/stdio.subproj/setbuffer.c b/stdio.subproj/setbuffer.c deleted file mode 100644 index 1aa3e62..0000000 --- a/stdio.subproj/setbuffer.c +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * 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 - -void -setbuffer(fp, buf, size) - register FILE *fp; - char *buf; - int size; -{ - - (void)setvbuf(fp, buf, buf ? _IOFBF : _IONBF, size); -} - -/* - * set line buffering - */ -int -setlinebuf(fp) - FILE *fp; -{ - - return (setvbuf(fp, (char *)NULL, _IOLBF, (size_t)0)); -} diff --git a/stdio.subproj/setvbuf.c b/stdio.subproj/setvbuf.c deleted file mode 100644 index 25a8d52..0000000 --- a/stdio.subproj/setvbuf.c +++ /dev/null @@ -1,179 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * 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 -#include -#include "local.h" - -/* - * Set one of the three kinds of buffering, optionally including - * a buffer. - */ -int -setvbuf(fp, buf, mode, size) - register FILE *fp; - char *buf; - register int mode; - register size_t size; -{ - register int ret, flags; - size_t iosize; - int ttyflag; - - /* - * Verify arguments. The `int' limit on `size' is due to this - * particular implementation. Note, buf and size are ignored - * when setting _IONBF. - */ - if (mode != _IONBF) - if ((mode != _IOFBF && mode != _IOLBF) || (int)size < 0) - return (EOF); - - /* - * Write current buffer, if any. Discard unread input (including - * ungetc data), cancel line buffering, and free old buffer if - * malloc()ed. We also clear any eof condition, as if this were - * a seek. - */ - ret = 0; - (void)__sflush(fp); - if (HASUB(fp)) - FREEUB(fp); - fp->_r = fp->_lbfsize = 0; - flags = fp->_flags; - if (flags & __SMBF) - free((void *)fp->_bf._base); - flags &= ~(__SLBF | __SNBF | __SMBF | __SOPT | __SNPT | __SEOF); - - /* If setting unbuffered mode, skip all the hard work. */ - if (mode == _IONBF) - goto nbf; - - /* - * Find optimal I/O size for seek optimization. This also returns - * a `tty flag' to suggest that we check isatty(fd), but we do not - * care since our caller told us how to buffer. - */ - flags |= __swhatbuf(fp, &iosize, &ttyflag); - if (size == 0) { - buf = NULL; /* force local allocation */ - size = iosize; - } - - /* Allocate buffer if needed. */ - if (buf == NULL) { - if ((buf = malloc(size)) == NULL) { - /* - * Unable to honor user's request. We will return - * failure, but try again with file system size. - */ - ret = EOF; - if (size != iosize) { - size = iosize; - buf = malloc(size); - } - } - if (buf == NULL) { - /* No luck; switch to unbuffered I/O. */ -nbf: - fp->_flags = flags | __SNBF; - fp->_w = 0; - fp->_bf._base = fp->_p = fp->_nbuf; - fp->_bf._size = 1; - return (ret); - } - flags |= __SMBF; - } - - /* - * Kill any seek optimization if the buffer is not the - * right size. - * - * SHOULD WE ALLOW MULTIPLES HERE (i.e., ok iff (size % iosize) == 0)? - */ - if (size != iosize) - flags |= __SNPT; - - /* - * Fix up the FILE fields, and set __cleanup for output flush on - * exit (since we are buffered in some way). - */ - if (mode == _IOLBF) - flags |= __SLBF; - fp->_flags = flags; - fp->_bf._base = fp->_p = (unsigned char *)buf; - fp->_bf._size = size; - /* fp->_lbfsize is still 0 */ - if (flags & __SWR) { - /* - * Begin or continue writing: see __swsetup(). Note - * that __SNBF is impossible (it was handled earlier). - */ - if (flags & __SLBF) { - fp->_w = 0; - fp->_lbfsize = -fp->_bf._size; - } else - fp->_w = size; - } else { - /* begin/continue reading, or stay in intermediate state */ - fp->_w = 0; - } - __cleanup = _cleanup; - - return (ret); -} diff --git a/stdio.subproj/snprintf.c b/stdio.subproj/snprintf.c deleted file mode 100644 index a9b6315..0000000 --- a/stdio.subproj/snprintf.c +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * 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 -#if __STDC__ -#include -#else -#include -#endif - -int -#if __STDC__ -snprintf(char *str, size_t n, char const *fmt, ...) -#else -snprintf(str, n, fmt, va_alist) - char *str; - size_t n; - char *fmt; - va_dcl -#endif -{ - int ret; - va_list ap; - FILE f; - - if ((int)n < 1) - return (EOF); -#if __STDC__ - va_start(ap, fmt); -#else - va_start(ap); -#endif - f._flags = __SWR | __SSTR; - f._bf._base = f._p = (unsigned char *)str; - f._bf._size = f._w = n - 1; - ret = vfprintf(&f, fmt, ap); - *f._p = 0; - va_end(ap); - return (ret); -} diff --git a/stdio.subproj/sprintf.c b/stdio.subproj/sprintf.c deleted file mode 100644 index 0cddde0..0000000 --- a/stdio.subproj/sprintf.c +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * 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 -#if __STDC__ -#include -#else -#include -#endif -#include -#include "local.h" - -int -#if __STDC__ -sprintf(char *str, char const *fmt, ...) -#else -sprintf(str, fmt, va_alist) - char *str; - char *fmt; - va_dcl -#endif -{ - int ret; - va_list ap; - FILE f; - - f._flags = __SWR | __SSTR; - f._bf._base = f._p = (unsigned char *)str; - f._bf._size = f._w = INT_MAX; -#if __STDC__ - va_start(ap, fmt); -#else - va_start(ap); -#endif - ret = vfprintf(&f, fmt, ap); - va_end(ap); - *f._p = 0; - return (ret); -} diff --git a/stdio.subproj/sscanf.c b/stdio.subproj/sscanf.c deleted file mode 100644 index 92ccf56..0000000 --- a/stdio.subproj/sscanf.c +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * 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 -#include -#if __STDC__ -#include -#else -#include -#endif -#include "local.h" - -/* ARGSUSED */ -static int -eofread(cookie, buf, len) - void *cookie; - char *buf; - int len; -{ - - return (0); -} - -int -#if __STDC__ -sscanf(const char *str, char const *fmt, ...) -#else -sscanf(str, fmt, va_alist) - char *str; - char *fmt; - va_dcl -#endif -{ - int ret; - va_list ap; - FILE f; - - 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; -#if __STDC__ - va_start(ap, fmt); -#else - va_start(ap); -#endif - ret = __svfscanf(&f, fmt, ap); - va_end(ap); - return (ret); -} diff --git a/stdio.subproj/stdio.c b/stdio.subproj/stdio.c deleted file mode 100644 index dc8a702..0000000 --- a/stdio.subproj/stdio.c +++ /dev/null @@ -1,125 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * 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 -#include -#include -#include "local.h" - -/* - * Small standard I/O/seek/close functions. - * These maintain the `known seek offset' for seek optimisation. - */ -int -__sread(cookie, buf, n) - void *cookie; - char *buf; - int n; -{ - register FILE *fp = cookie; - register int ret; - - ret = read(fp->_file, buf, n); - /* if the read succeeded, update the current offset */ - if (ret >= 0) - fp->_offset += ret; - else - fp->_flags &= ~__SOFF; /* paranoia */ - return (ret); -} - -int -__swrite(cookie, buf, n) - void *cookie; - char const *buf; - int n; -{ - register FILE *fp = cookie; - - if (fp->_flags & __SAPP) - (void) lseek(fp->_file, (off_t)0, SEEK_END); - fp->_flags &= ~__SOFF; /* in case FAPPEND mode is set */ - return (write(fp->_file, buf, n)); -} - -fpos_t -__sseek(cookie, offset, whence) - void *cookie; - fpos_t offset; - int whence; -{ - register FILE *fp = cookie; - register off_t ret; - - ret = lseek(fp->_file, (off_t)offset, whence); - if (ret == -1L) - fp->_flags &= ~__SOFF; - else { - fp->_flags |= __SOFF; - fp->_offset = ret; - } - return (ret); -} - -int -__sclose(cookie) - void *cookie; -{ - - return (close(((FILE *)cookie)->_file)); -} diff --git a/stdio.subproj/tempnam.c b/stdio.subproj/tempnam.c deleted file mode 100644 index ebbb84a..0000000 --- a/stdio.subproj/tempnam.c +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1988, 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 -#include -#include -#include -#include -#include - -char * -tempnam(dir, pfx) - const char *dir, *pfx; -{ - int sverrno; - char *f, *name; - - if (!(name = malloc(MAXPATHLEN))) - return(NULL); - - if (!pfx) - pfx = "tmp."; - - if (f = getenv("TMPDIR")) { - (void)snprintf(name, MAXPATHLEN, "%s%s%sXXXXXX", f, - *(f + strlen(f) - 1) == '/'? "": "/", pfx); - if (f = mktemp(name)) - return(f); - } - - if (f = (char *)dir) { - (void)snprintf(name, MAXPATHLEN, "%s%s%sXXXXXX", f, - *(f + strlen(f) - 1) == '/'? "": "/", pfx); - if (f = mktemp(name)) - return(f); - } - - f = P_tmpdir; - (void)snprintf(name, MAXPATHLEN, "%s%sXXXXXX", f, pfx); - if (f = mktemp(name)) - return(f); - - f = _PATH_TMP; - (void)snprintf(name, MAXPATHLEN, "%s%sXXXXXX", f, pfx); - if (f = mktemp(name)) - return(f); - - sverrno = errno; - free(name); - errno = sverrno; - return(NULL); -} diff --git a/stdio.subproj/tmpfile.c b/stdio.subproj/tmpfile.c deleted file mode 100644 index 2924a9e..0000000 --- a/stdio.subproj/tmpfile.c +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * 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 -#include -#include -#include -#include -#include - -FILE * -tmpfile() -{ - sigset_t set, oset; - FILE *fp; - int fd, sverrno; -#define TRAILER "tmp.XXXXXX" - char buf[sizeof(_PATH_TMP) + sizeof(TRAILER)]; - - (void)memcpy(buf, _PATH_TMP, sizeof(_PATH_TMP) - 1); - (void)memcpy(buf + sizeof(_PATH_TMP) - 1, TRAILER, sizeof(TRAILER)); - - sigfillset(&set); - (void)sigprocmask(SIG_BLOCK, &set, &oset); - - fd = mkstemp(buf); - if (fd != -1) - (void)unlink(buf); - - (void)sigprocmask(SIG_SETMASK, &oset, NULL); - - if (fd == -1) - return (NULL); - - if ((fp = fdopen(fd, "w+")) == NULL) { - sverrno = errno; - (void)close(fd); - errno = sverrno; - return (NULL); - } - return (fp); -} diff --git a/stdio.subproj/tmpnam.c b/stdio.subproj/tmpnam.c deleted file mode 100644 index 3ab71b1..0000000 --- a/stdio.subproj/tmpnam.c +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 1993, 1994 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * 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 - -#include -#include - -char * -tmpnam(s) - char *s; -{ - static u_long tmpcount; - static char buf[L_tmpnam]; - - if (s == NULL) - s = buf; - (void)snprintf(s, L_tmpnam, "%stmp.%lu.XXXXXX", P_tmpdir, tmpcount); - ++tmpcount; - return (mktemp(s)); -} diff --git a/stdio.subproj/ungetc.c b/stdio.subproj/ungetc.c deleted file mode 100644 index ab92783..0000000 --- a/stdio.subproj/ungetc.c +++ /dev/null @@ -1,167 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * 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 -#include -#include -#include "local.h" - -/* - * Expand the ungetc buffer `in place'. That is, adjust fp->_p when - * the buffer moves, so that it points the same distance from the end, - * and move the bytes in the buffer around as necessary so that they - * are all at the end (stack-style). - */ -static int -__submore(fp) - register FILE *fp; -{ - register int i; - register unsigned char *p; - - if (fp->_ub._base == fp->_ubuf) { - /* - * Get a new buffer (rather than expanding the old one). - */ - if ((p = malloc((size_t)BUFSIZ)) == NULL) - return (EOF); - fp->_ub._base = p; - fp->_ub._size = BUFSIZ; - p += BUFSIZ - sizeof(fp->_ubuf); - for (i = sizeof(fp->_ubuf); --i >= 0;) - p[i] = fp->_ubuf[i]; - fp->_p = p; - return (0); - } - i = fp->_ub._size; - p = realloc(fp->_ub._base, i << 1); - if (p == NULL) - return (EOF); - /* no overlap (hence can use memcpy) because we doubled the size */ - (void)memcpy((void *)(p + i), (void *)p, (size_t)i); - fp->_p = p + i; - fp->_ub._base = p; - fp->_ub._size = i << 1; - return (0); -} - -int -ungetc(c, fp) - int c; - register FILE *fp; -{ - if (c == EOF) - return (EOF); - if (!__sdidinit) - __sinit(); - if ((fp->_flags & __SRD) == 0) { - /* - * Not already reading: no good unless reading-and-writing. - * Otherwise, flush any current write stuff. - */ - if ((fp->_flags & __SRW) == 0) - return (EOF); - if (fp->_flags & __SWR) { - if (__sflush(fp)) - return (EOF); - fp->_flags &= ~__SWR; - fp->_w = 0; - fp->_lbfsize = 0; - } - fp->_flags |= __SRD; - } - c = (unsigned char)c; - - /* - * If we are in the middle of ungetc'ing, just continue. - * This may require expanding the current ungetc buffer. - */ - if (HASUB(fp)) { - if (fp->_r >= fp->_ub._size && __submore(fp)) - return (EOF); - *--fp->_p = c; - fp->_r++; - return (c); - } - fp->_flags &= ~__SEOF; - - /* - * If we can handle this by simply backing up, do so, - * but never replace the original character. - * (This makes sscanf() work when scanning `const' data.) - */ - if (fp->_bf._base != NULL && fp->_p > fp->_bf._base && - fp->_p[-1] == c) { - fp->_p--; - fp->_r++; - return (c); - } - - /* - * Create an ungetc buffer. - * Initially, we will use the `reserve' buffer. - */ - fp->_ur = fp->_r; - fp->_up = fp->_p; - fp->_ub._base = fp->_ubuf; - fp->_ub._size = sizeof(fp->_ubuf); - fp->_ubuf[sizeof(fp->_ubuf) - 1] = c; - fp->_p = &fp->_ubuf[sizeof(fp->_ubuf) - 1]; - fp->_r = 1; - return (c); -} diff --git a/stdio.subproj/vfprintf.c b/stdio.subproj/vfprintf.c deleted file mode 100644 index 2e49b6b..0000000 --- a/stdio.subproj/vfprintf.c +++ /dev/null @@ -1,1301 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * 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. - */ - -/* - * Actual printf innards. - * - * This code is large and complicated... - */ - -#include - -#include -#include -#include -#include - -#if __STDC__ -#include -#else -#include -#endif - -#include "local.h" -#include "fvwrite.h" - -/* Define FLOATING_POINT to get floating point. */ -#define FLOATING_POINT - -static int __sprint __P((FILE *, struct __suio *)); -static int __sbprintf __P((FILE *, const char *, va_list)); -static char * __ultoa __P((u_long, char *, int, int, char *)); -static char * __uqtoa __P((u_quad_t, char *, int, int, char *)); -static void __find_arguments __P((const char *, va_list, void ***)); -static void __grow_type_table __P((int, unsigned char **, int *)); - -/* - * Flush out all the vectors defined by the given uio, - * then reset it so that it can be reused. - */ -static int -__sprint(fp, uio) - FILE *fp; - register struct __suio *uio; -{ - register int err; - - if (uio->uio_resid == 0) { - uio->uio_iovcnt = 0; - return (0); - } - err = __sfvwrite(fp, uio); - uio->uio_resid = 0; - uio->uio_iovcnt = 0; - return (err); -} - -/* - * Helper function for `fprintf to unbuffered unix file': creates a - * temporary buffer. We only work on write-only files; this avoids - * worries about ungetc buffers and so forth. - */ -static int -__sbprintf(fp, fmt, ap) - register FILE *fp; - const char *fmt; - va_list ap; -{ - int ret; - FILE fake; - unsigned char buf[BUFSIZ]; - - /* copy the important variables */ - fake._flags = fp->_flags & ~__SNBF; - fake._file = fp->_file; - fake._cookie = fp->_cookie; - fake._write = fp->_write; - - /* set up the buffer */ - fake._bf._base = fake._p = buf; - fake._bf._size = fake._w = sizeof(buf); - fake._lbfsize = 0; /* not actually used, but Just In Case */ - - /* do the work, then copy any error status */ - ret = vfprintf(&fake, fmt, ap); - if (ret >= 0 && fflush(&fake)) - ret = EOF; - if (fake._flags & __SERR) - fp->_flags |= __SERR; - return (ret); -} - -/* - * Macros for converting digits to letters and vice versa - */ -#define to_digit(c) ((c) - '0') -#define is_digit(c) ((unsigned)to_digit(c) <= 9) -#define to_char(n) ((n) + '0') - -/* - * Convert an unsigned long to ASCII for printf purposes, returning - * a pointer to the first character of the string representation. - * Octal numbers can be forced to have a leading zero; hex numbers - * use the given digits. - */ -static char * -__ultoa(val, endp, base, octzero, xdigs) - register u_long val; - char *endp; - int base, octzero; - char *xdigs; -{ - register char *cp = endp; - register long sval; - - /* - * Handle the three cases separately, in the hope of getting - * better/faster code. - */ - switch (base) { - case 10: - if (val < 10) { /* many numbers are 1 digit */ - *--cp = to_char(val); - return (cp); - } - /* - * On many machines, unsigned arithmetic is harder than - * signed arithmetic, so we do at most one unsigned mod and - * divide; this is sufficient to reduce the range of - * the incoming value to where signed arithmetic works. - */ - if (val > LONG_MAX) { - *--cp = to_char(val % 10); - sval = val / 10; - } else - sval = val; - do { - *--cp = to_char(sval % 10); - sval /= 10; - } while (sval != 0); - break; - - case 8: - do { - *--cp = to_char(val & 7); - val >>= 3; - } while (val); - if (octzero && *cp != '0') - *--cp = '0'; - break; - - case 16: - do { - *--cp = xdigs[val & 15]; - val >>= 4; - } while (val); - break; - - default: /* oops */ - abort(); - } - return (cp); -} - -/* Identical to __ultoa, but for quads. */ -static char * -__uqtoa(val, endp, base, octzero, xdigs) - register u_quad_t val; - char *endp; - int base, octzero; - char *xdigs; -{ - register char *cp = endp; - register quad_t sval; - - /* quick test for small values; __ultoa is typically much faster */ - /* (perhaps instead we should run until small, then call __ultoa?) */ - if (val <= ULONG_MAX) - return (__ultoa((u_long)val, endp, base, octzero, xdigs)); - switch (base) { - case 10: - if (val < 10) { - *--cp = to_char(val % 10); - return (cp); - } - if (val > QUAD_MAX) { - *--cp = to_char(val % 10); - sval = val / 10; - } else - sval = val; - do { - *--cp = to_char(sval % 10); - sval /= 10; - } while (sval != 0); - break; - - case 8: - do { - *--cp = to_char(val & 7); - val >>= 3; - } while (val); - if (octzero && *cp != '0') - *--cp = '0'; - break; - - case 16: - do { - *--cp = xdigs[val & 15]; - val >>= 4; - } while (val); - break; - - default: - abort(); - } - return (cp); -} - -#ifdef FLOATING_POINT -#include -#include "floatio.h" - -#define BUF (MAXEXP+MAXFRACT+1) /* + decimal point */ -#define DEFPREC 6 - -static char *cvt __P((double, int, int, char *, int *, int, int *, char **)); -static int exponent __P((char *, int, int)); - -#else /* no FLOATING_POINT */ - -#define BUF 68 - -#endif /* FLOATING_POINT */ - -#define STATIC_ARG_TBL_SIZE 8 /* Size of static argument table. */ - -/* - * Flags used during conversion. - */ -#define ALT 0x001 /* alternate form */ -#define HEXPREFIX 0x002 /* add 0x or 0X prefix */ -#define LADJUST 0x004 /* left adjustment */ -#define LONGDBL 0x008 /* long double */ -#define LONGINT 0x010 /* long integer */ -#define QUADINT 0x020 /* quad integer */ -#define SHORTINT 0x040 /* short integer */ -#define ZEROPAD 0x080 /* zero (as opposed to blank) pad */ -#define FPT 0x100 /* Floating point number */ -int -vfprintf(fp, fmt0, ap) - FILE *fp; - const char *fmt0; - va_list ap; -{ - register char *fmt; /* format string */ - register int ch; /* character from fmt */ - register int n, n2; /* handy integer (short term usage) */ - register char *cp; /* handy char pointer (short term usage) */ - register struct __siov *iovp;/* for PRINT macro */ - register int flags; /* flags as above */ - int ret; /* return value accumulator */ - int width; /* width from format (%8d), or 0 */ - int prec; /* precision from format (%.3d), or -1 */ - char sign; /* sign prefix (' ', '+', '-', or \0) */ -#ifdef FLOATING_POINT - char softsign; /* temporary negative sign for floats */ - double _double = 0; /* double precision arguments %[eEfgG] */ - int expt; /* integer value of exponent */ - int expsize = 0; /* character count for expstr */ - int ndig; /* actual number of digits returned by cvt */ - char expstr[7]; /* buffer for exponent string */ - char *dtoaresult; /* buffer allocated by dtoa */ -#endif - u_long ulval = 0; /* integer arguments %[diouxX] */ - u_quad_t uqval = 0; /* %q integers */ - int base; /* base for [diouxX] conversion */ - int dprec; /* a copy of prec if [diouxX], 0 otherwise */ - int realsz; /* field size expanded by dprec, sign, etc */ - int size; /* size of converted field or string */ - int prsize; /* max size of printed field */ - char *xdigs = NULL; /* digits for [xX] conversion */ -#define NIOV 8 - struct __suio uio; /* output information: summary */ - struct __siov iov[NIOV];/* ... and individual io vectors */ - char buf[BUF]; /* space for %c, %[diouxX], %[eEfgG] */ - char ox[2]; /* space for 0x hex-prefix */ - void **argtable; /* args, built due to positional arg */ - void *statargtable [STATIC_ARG_TBL_SIZE]; - int nextarg; /* 1-based argument index */ - va_list orgap; /* original argument pointer */ - - /* - * Choose PADSIZE to trade efficiency vs. size. If larger printf - * fields occur frequently, increase PADSIZE and make the initialisers - * below longer. - */ -#define PADSIZE 16 /* pad chunk size */ - static char blanks[PADSIZE] = - {' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '}; - static char zeroes[PADSIZE] = - {'0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'}; - - /* - * BEWARE, these `goto error' on error, and PAD uses `n'. - */ -#define PRINT(ptr, len) { \ - iovp->iov_base = (ptr); \ - iovp->iov_len = (len); \ - uio.uio_resid += (len); \ - iovp++; \ - if (++uio.uio_iovcnt >= NIOV) { \ - if (__sprint(fp, &uio)) \ - goto error; \ - iovp = iov; \ - } \ -} -#define PAD(howmany, with) { \ - if ((n = (howmany)) > 0) { \ - while (n > PADSIZE) { \ - PRINT(with, PADSIZE); \ - n -= PADSIZE; \ - } \ - PRINT(with, n); \ - } \ -} -#define FLUSH() { \ - if (uio.uio_resid && __sprint(fp, &uio)) \ - goto error; \ - uio.uio_iovcnt = 0; \ - iovp = iov; \ -} - - /* - * Get the argument indexed by nextarg. If the argument table is - * built, use it to get the argument. If its not, get the next - * argument (and arguments must be gotten sequentially). - */ -#define GETARG(type) \ - ((argtable != NULL) ? *((type*)(argtable[nextarg++])) : \ - (nextarg++, va_arg(ap, type))) - - /* - * To extend shorts properly, we need both signed and unsigned - * argument extraction methods. - */ -#define SARG() \ - (flags&LONGINT ? GETARG(long) : \ - flags&SHORTINT ? (long)(short)GETARG(int) : \ - (long)GETARG(int)) -#define UARG() \ - (flags&LONGINT ? GETARG(u_long) : \ - flags&SHORTINT ? (u_long)(u_short)GETARG(int) : \ - (u_long)GETARG(u_int)) - - /* - * Get * arguments, including the form *nn$. Preserve the nextarg - * that the argument can be gotten once the type is determined. - */ -#define GETASTER(val) \ - n2 = 0; \ - cp = fmt; \ - while (is_digit(*cp)) { \ - n2 = 10 * n2 + to_digit(*cp); \ - cp++; \ - } \ - if (*cp == '$') { \ - int hold = nextarg; \ - if (argtable == NULL) { \ - argtable = statargtable; \ - __find_arguments (fmt0, orgap, &argtable); \ - } \ - nextarg = n2; \ - val = GETARG (int); \ - nextarg = hold; \ - fmt = ++cp; \ - } else { \ - val = GETARG (int); \ - } -#ifdef FLOATING_POINT - dtoaresult = NULL; -#endif - /* FLOCKFILE(fp); */ - /* sorry, fprintf(read_only_file, "") returns EOF, not 0 */ - if (cantwrite(fp)) { - /* FUNLOCKFILE(fp); */ - return (EOF); - } - - /* optimise fprintf(stderr) (and other unbuffered Unix files) */ - if ((fp->_flags & (__SNBF|__SWR|__SRW)) == (__SNBF|__SWR) && - fp->_file >= 0) { - /* FUNLOCKFILE(fp); */ - return (__sbprintf(fp, fmt0, ap)); - } - - fmt = (char *)fmt0; - argtable = NULL; - nextarg = 1; - orgap = ap; - uio.uio_iov = iovp = iov; - uio.uio_resid = 0; - uio.uio_iovcnt = 0; - ret = 0; - - /* - * Scan the format for conversions (`%' character). - */ - for (;;) { - for (cp = fmt; (ch = *fmt) != '\0' && ch != '%'; fmt++) - /* void */; - if ((n = fmt - cp) != 0) { - if ((unsigned)ret + n > INT_MAX) { - ret = EOF; - goto error; - } - PRINT(cp, n); - ret += n; - } - if (ch == '\0') - goto done; - fmt++; /* skip over '%' */ - - flags = 0; - dprec = 0; - width = 0; - prec = -1; - sign = '\0'; - -rflag: ch = *fmt++; -reswitch: switch (ch) { - case ' ': - /* - * ``If the space and + flags both appear, the space - * flag will be ignored.'' - * -- ANSI X3J11 - */ - if (!sign) - sign = ' '; - goto rflag; - case '#': - flags |= ALT; - goto rflag; - case '*': - /* - * ``A negative field width argument is taken as a - * - flag followed by a positive field width.'' - * -- ANSI X3J11 - * They don't exclude field widths read from args. - */ - GETASTER (width); - if (width >= 0) - goto rflag; - width = -width; - /* FALLTHROUGH */ - case '-': - flags |= LADJUST; - goto rflag; - case '+': - sign = '+'; - goto rflag; - case '.': - if ((ch = *fmt++) == '*') { - GETASTER (n); - prec = n < 0 ? -1 : n; - goto rflag; - } - n = 0; - while (is_digit(ch)) { - n = 10 * n + to_digit(ch); - ch = *fmt++; - } - prec = n < 0 ? -1 : n; - goto reswitch; - case '0': - /* - * ``Note that 0 is taken as a flag, not as the - * beginning of a field width.'' - * -- ANSI X3J11 - */ - flags |= ZEROPAD; - goto rflag; - case '1': case '2': case '3': case '4': - case '5': case '6': case '7': case '8': case '9': - n = 0; - do { - n = 10 * n + to_digit(ch); - ch = *fmt++; - } while (is_digit(ch)); - if (ch == '$') { - nextarg = n; - if (argtable == NULL) { - argtable = statargtable; - __find_arguments (fmt0, orgap, - &argtable); - } - goto rflag; - } - width = n; - goto reswitch; -#ifdef FLOATING_POINT - case 'L': - flags |= LONGDBL; - goto rflag; -#endif - case 'h': - flags |= SHORTINT; - goto rflag; - case 'l': - if (flags & LONGINT) - flags |= QUADINT; - else - flags |= LONGINT; - goto rflag; - case 'q': - flags |= QUADINT; - goto rflag; - case 'c': - *(cp = buf) = GETARG(int); - size = 1; - sign = '\0'; - break; - case 'D': - flags |= LONGINT; - /*FALLTHROUGH*/ - case 'd': - case 'i': - if (flags & QUADINT) { - uqval = GETARG(quad_t); - if ((quad_t)uqval < 0) { - uqval = -uqval; - sign = '-'; - } - } else { - ulval = SARG(); - if ((long)ulval < 0) { - ulval = -ulval; - sign = '-'; - } - } - base = 10; - goto number; -#ifdef FLOATING_POINT - case 'e': - case 'E': - case 'f': - goto fp_begin; - case 'g': - case 'G': - if (prec == 0) - prec = 1; -fp_begin: if (prec == -1) - prec = DEFPREC; - if (flags & LONGDBL) - /* XXX this loses precision. */ - _double = (double)GETARG(long double); - else - _double = GETARG(double); - /* do this before tricky precision changes */ - if (isinf(_double)) { - if (_double < 0) - sign = '-'; - cp = "Inf"; - size = 3; - break; - } - if (isnan(_double)) { - cp = "NaN"; - size = 3; - break; - } - flags |= FPT; - cp = cvt(_double, prec, flags, &softsign, - &expt, ch, &ndig, &dtoaresult); - if (ch == 'g' || ch == 'G') { - if (expt <= -4 || expt > prec) - ch = (ch == 'g') ? 'e' : 'E'; - else - ch = 'g'; - } - if (ch <= 'e') { /* 'e' or 'E' fmt */ - --expt; - expsize = exponent(expstr, expt, ch); - size = expsize + ndig; - if (ndig > 1 || flags & ALT) - ++size; - } else if (ch == 'f') { /* f fmt */ - if (expt > 0) { - size = expt; - if (prec || flags & ALT) - size += prec + 1; - } else /* "0.X" */ - size = prec + 2; - } else if (expt >= ndig) { /* fixed g fmt */ - size = expt; - if (flags & ALT) - ++size; - } else - size = ndig + (expt > 0 ? - 1 : 2 - expt); - - if (softsign) - sign = '-'; - break; -#endif /* FLOATING_POINT */ - case 'n': - if (flags & QUADINT) - *GETARG(quad_t *) = ret; - else if (flags & LONGINT) - *GETARG(long *) = ret; - else if (flags & SHORTINT) - *GETARG(short *) = ret; - else - *GETARG(int *) = ret; - continue; /* no output */ - case 'O': - flags |= LONGINT; - /*FALLTHROUGH*/ - case 'o': - if (flags & QUADINT) - uqval = GETARG(u_quad_t); - else - ulval = UARG(); - base = 8; - goto nosign; - case 'p': - /* - * ``The argument shall be a pointer to void. The - * value of the pointer is converted to a sequence - * of printable characters, in an implementation- - * defined manner.'' - * -- ANSI X3J11 - */ - ulval = (u_long)GETARG(void *); - base = 16; - xdigs = "0123456789abcdef"; - flags = (flags & ~QUADINT) | HEXPREFIX; - ch = 'x'; - goto nosign; - case 's': - if ((cp = GETARG(char *)) == NULL) - cp = "(null)"; - if (prec >= 0) { - /* - * can't use strlen; can only look for the - * NUL in the first `prec' characters, and - * strlen() will go further. - */ - char *p = memchr(cp, 0, (size_t)prec); - - if (p != NULL) { - size = p - cp; - if (size > prec) - size = prec; - } else - size = prec; - } else - size = strlen(cp); - sign = '\0'; - break; - case 'U': - flags |= LONGINT; - /*FALLTHROUGH*/ - case 'u': - if (flags & QUADINT) - uqval = GETARG(u_quad_t); - else - ulval = UARG(); - base = 10; - goto nosign; - case 'X': - xdigs = "0123456789ABCDEF"; - goto hex; - case 'x': - xdigs = "0123456789abcdef"; -hex: if (flags & QUADINT) - uqval = GETARG(u_quad_t); - else - ulval = UARG(); - base = 16; - /* leading 0x/X only if non-zero */ - if (flags & ALT && - (flags & QUADINT ? uqval != 0 : ulval != 0)) - flags |= HEXPREFIX; - - /* unsigned conversions */ -nosign: sign = '\0'; - /* - * ``... diouXx conversions ... if a precision is - * specified, the 0 flag will be ignored.'' - * -- ANSI X3J11 - */ -number: if ((dprec = prec) >= 0) - flags &= ~ZEROPAD; - - /* - * ``The result of converting a zero value with an - * explicit precision of zero is no characters.'' - * -- ANSI X3J11 - */ - cp = buf + BUF; - if (flags & QUADINT) { - if (uqval != 0 || prec != 0) - cp = __uqtoa(uqval, cp, base, - flags & ALT, xdigs); - } else { - if (ulval != 0 || prec != 0) - cp = __ultoa(ulval, cp, base, - flags & ALT, xdigs); - } - size = buf + BUF - cp; - break; - default: /* "%?" prints ?, unless ? is NUL */ - if (ch == '\0') - goto done; - /* pretend it was %c with argument ch */ - cp = buf; - *cp = ch; - size = 1; - sign = '\0'; - break; - } - - /* - * All reasonable formats wind up here. At this point, `cp' - * points to a string which (if not flags&LADJUST) should be - * padded out to `width' places. If flags&ZEROPAD, it should - * first be prefixed by any sign or other prefix; otherwise, - * it should be blank padded before the prefix is emitted. - * After any left-hand padding and prefixing, emit zeroes - * required by a decimal [diouxX] precision, then print the - * string proper, then emit zeroes required by any leftover - * floating precision; finally, if LADJUST, pad with blanks. - * - * Compute actual size, so we know how much to pad. - * size excludes decimal prec; realsz includes it. - */ - realsz = dprec > size ? dprec : size; - if (sign) - realsz++; - else if (flags & HEXPREFIX) - realsz += 2; - - prsize = width > realsz ? width : realsz; - if ((unsigned)ret + prsize > INT_MAX) { - ret = EOF; - goto error; - } - - /* right-adjusting blank padding */ - if ((flags & (LADJUST|ZEROPAD)) == 0) - PAD(width - realsz, blanks); - - /* prefix */ - if (sign) { - PRINT(&sign, 1); - } else if (flags & HEXPREFIX) { - ox[0] = '0'; - ox[1] = ch; - PRINT(ox, 2); - } - - /* right-adjusting zero padding */ - if ((flags & (LADJUST|ZEROPAD)) == ZEROPAD) - PAD(width - realsz, zeroes); - - /* leading zeroes from decimal precision */ - PAD(dprec - size, zeroes); - - /* the string or number proper */ -#ifdef FLOATING_POINT - if ((flags & FPT) == 0) { - PRINT(cp, size); - } else { /* glue together f_p fragments */ - if (ch >= 'f') { /* 'f' or 'g' */ - if (_double == 0) { - /* kludge for __dtoa irregularity */ - if (expt >= ndig && - (flags & ALT) == 0) { - PRINT("0", 1); - } else { - PRINT("0.", 2); - PAD(ndig - 1, zeroes); - } - } else if (expt <= 0) { - PRINT("0.", 2); - PAD(-expt, zeroes); - PRINT(cp, ndig); - } else if (expt >= ndig) { - PRINT(cp, ndig); - PAD(expt - ndig, zeroes); - if (flags & ALT) - PRINT(".", 1); - } else { - PRINT(cp, expt); - cp += expt; - PRINT(".", 1); - PRINT(cp, ndig-expt); - } - } else { /* 'e' or 'E' */ - if (ndig > 1 || flags & ALT) { - ox[0] = *cp++; - ox[1] = '.'; - PRINT(ox, 2); - if (_double) { - PRINT(cp, ndig-1); - } else /* 0.[0..] */ - /* __dtoa irregularity */ - PAD(ndig - 1, zeroes); - } else /* XeYYY */ - PRINT(cp, 1); - PRINT(expstr, expsize); - } - } -#else - PRINT(cp, size); -#endif - /* left-adjusting padding (always blank) */ - if (flags & LADJUST) - PAD(width - realsz, blanks); - - /* finally, adjust ret */ - ret += prsize; - - FLUSH(); /* copy out the I/O vectors */ - } -done: - FLUSH(); -error: -#ifdef FLOATING_POINT - if (dtoaresult != NULL) - free(dtoaresult); -#endif - if (__sferror(fp)) - ret = EOF; - /* FUNLOCKFILE(fp); */ - if ((argtable != NULL) && (argtable != statargtable)) - free (argtable); - return (ret); - /* NOTREACHED */ -} - -/* - * Type ids for argument type table. - */ -#define T_UNUSED 0 -#define T_SHORT 1 -#define T_U_SHORT 2 -#define TP_SHORT 3 -#define T_INT 4 -#define T_U_INT 5 -#define TP_INT 6 -#define T_LONG 7 -#define T_U_LONG 8 -#define TP_LONG 9 -#define T_QUAD 10 -#define T_U_QUAD 11 -#define TP_QUAD 12 -#define T_DOUBLE 13 -#define T_LONG_DOUBLE 14 -#define TP_CHAR 15 -#define TP_VOID 16 - -/* - * Find all arguments when a positional parameter is encountered. Returns a - * table, indexed by argument number, of pointers to each arguments. The - * initial argument table should be an array of STATIC_ARG_TBL_SIZE entries. - * It will be replaces with a malloc-ed one if it overflows. - */ -static void -__find_arguments (fmt0, ap, argtable) - const char *fmt0; - va_list ap; - void ***argtable; -{ - register char *fmt; /* format string */ - register int ch; /* character from fmt */ - register int n, n2; /* handy integer (short term usage) */ - register char *cp; /* handy char pointer (short term usage) */ - register int flags; /* flags as above */ - int width; /* width from format (%8d), or 0 */ - unsigned char *typetable; /* table of types */ - unsigned char stattypetable [STATIC_ARG_TBL_SIZE]; - int tablesize; /* current size of type table */ - int tablemax; /* largest used index in table */ - int nextarg; /* 1-based argument index */ - - /* - * Add an argument type to the table, expanding if necessary. - */ -#define ADDTYPE(type) \ - ((nextarg >= tablesize) ? \ - __grow_type_table(nextarg, &typetable, &tablesize) : 0, \ - (nextarg > tablemax) ? tablemax = nextarg : 0, \ - typetable[nextarg++] = type) - -#define ADDSARG() \ - ((flags&LONGINT) ? ADDTYPE(T_LONG) : \ - ((flags&SHORTINT) ? ADDTYPE(T_SHORT) : ADDTYPE(T_INT))) - -#define ADDUARG() \ - ((flags&LONGINT) ? ADDTYPE(T_U_LONG) : \ - ((flags&SHORTINT) ? ADDTYPE(T_U_SHORT) : ADDTYPE(T_U_INT))) - - /* - * Add * arguments to the type array. - */ -#define ADDASTER() \ - n2 = 0; \ - cp = fmt; \ - while (is_digit(*cp)) { \ - n2 = 10 * n2 + to_digit(*cp); \ - cp++; \ - } \ - if (*cp == '$') { \ - int hold = nextarg; \ - nextarg = n2; \ - ADDTYPE (T_INT); \ - nextarg = hold; \ - fmt = ++cp; \ - } else { \ - ADDTYPE (T_INT); \ - } - fmt = (char *)fmt0; - typetable = stattypetable; - tablesize = STATIC_ARG_TBL_SIZE; - tablemax = 0; - nextarg = 1; - memset (typetable, T_UNUSED, STATIC_ARG_TBL_SIZE); - - /* - * Scan the format for conversions (`%' character). - */ - for (;;) { - for (cp = fmt; (ch = *fmt) != '\0' && ch != '%'; fmt++) - /* void */; - if (ch == '\0') - goto done; - fmt++; /* skip over '%' */ - - flags = 0; - width = 0; - -rflag: ch = *fmt++; -reswitch: switch (ch) { - case ' ': - case '#': - goto rflag; - case '*': - ADDASTER (); - goto rflag; - case '-': - case '+': - goto rflag; - case '.': - if ((ch = *fmt++) == '*') { - ADDASTER (); - goto rflag; - } - while (is_digit(ch)) { - ch = *fmt++; - } - goto reswitch; - case '0': - goto rflag; - case '1': case '2': case '3': case '4': - case '5': case '6': case '7': case '8': case '9': - n = 0; - do { - n = 10 * n + to_digit(ch); - ch = *fmt++; - } while (is_digit(ch)); - if (ch == '$') { - nextarg = n; - goto rflag; - } - width = n; - goto reswitch; -#ifdef FLOATING_POINT - case 'L': - flags |= LONGDBL; - goto rflag; -#endif - case 'h': - flags |= SHORTINT; - goto rflag; - case 'l': - if (flags & LONGINT) - flags |= QUADINT; - else - flags |= LONGINT; - goto rflag; - case 'q': - flags |= QUADINT; - goto rflag; - case 'c': - ADDTYPE(T_INT); - break; - case 'D': - flags |= LONGINT; - /*FALLTHROUGH*/ - case 'd': - case 'i': - if (flags & QUADINT) { - ADDTYPE(T_QUAD); - } else { - ADDSARG(); - } - break; -#ifdef FLOATING_POINT - case 'e': - case 'E': - case 'f': - case 'g': - case 'G': - if (flags & LONGDBL) - ADDTYPE(T_LONG_DOUBLE); - else - ADDTYPE(T_DOUBLE); - break; -#endif /* FLOATING_POINT */ - case 'n': - if (flags & QUADINT) - ADDTYPE(TP_QUAD); - else if (flags & LONGINT) - ADDTYPE(TP_LONG); - else if (flags & SHORTINT) - ADDTYPE(TP_SHORT); - else - ADDTYPE(TP_INT); - continue; /* no output */ - case 'O': - flags |= LONGINT; - /*FALLTHROUGH*/ - case 'o': - if (flags & QUADINT) - ADDTYPE(T_U_QUAD); - else - ADDUARG(); - break; - case 'p': - ADDTYPE(TP_VOID); - break; - case 's': - ADDTYPE(TP_CHAR); - break; - case 'U': - flags |= LONGINT; - /*FALLTHROUGH*/ - case 'u': - if (flags & QUADINT) - ADDTYPE(T_U_QUAD); - else - ADDUARG(); - break; - case 'X': - case 'x': - if (flags & QUADINT) - ADDTYPE(T_U_QUAD); - else - ADDUARG(); - break; - default: /* "%?" prints ?, unless ? is NUL */ - if (ch == '\0') - goto done; - break; - } - } -done: - /* - * Build the argument table. - */ - if (tablemax >= STATIC_ARG_TBL_SIZE) { - *argtable = (void **) - malloc (sizeof (void *) * (tablemax + 1)); - } - - (*argtable) [0] = NULL; - for (n = 1; n <= tablemax; n++) { - switch (typetable [n]) { - case T_UNUSED: - (*argtable) [n] = (void *) &va_arg (ap, int); - break; - case T_SHORT: - (*argtable) [n] = (void *) &va_arg (ap, int); - break; - case T_U_SHORT: - (*argtable) [n] = (void *) &va_arg (ap, int); - break; - case TP_SHORT: - (*argtable) [n] = (void *) &va_arg (ap, short *); - break; - case T_INT: - (*argtable) [n] = (void *) &va_arg (ap, int); - break; - case T_U_INT: - (*argtable) [n] = (void *) &va_arg (ap, unsigned int); - break; - case TP_INT: - (*argtable) [n] = (void *) &va_arg (ap, int *); - break; - case T_LONG: - (*argtable) [n] = (void *) &va_arg (ap, long); - break; - case T_U_LONG: - (*argtable) [n] = (void *) &va_arg (ap, unsigned long); - break; - case TP_LONG: - (*argtable) [n] = (void *) &va_arg (ap, long *); - break; - case T_QUAD: - (*argtable) [n] = (void *) &va_arg (ap, quad_t); - break; - case T_U_QUAD: - (*argtable) [n] = (void *) &va_arg (ap, u_quad_t); - break; - case TP_QUAD: - (*argtable) [n] = (void *) &va_arg (ap, quad_t *); - break; - case T_DOUBLE: - (*argtable) [n] = (void *) &va_arg (ap, double); - break; - case T_LONG_DOUBLE: - (*argtable) [n] = (void *) &va_arg (ap, long double); - break; - case TP_CHAR: - (*argtable) [n] = (void *) &va_arg (ap, char *); - break; - case TP_VOID: - (*argtable) [n] = (void *) &va_arg (ap, void *); - break; - } - } - - if ((typetable != NULL) && (typetable != stattypetable)) - free (typetable); -} - -/* - * Increase the size of the type table. - */ -static void -__grow_type_table (nextarg, typetable, tablesize) - int nextarg; - unsigned char **typetable; - int *tablesize; -{ - unsigned char *const oldtable = *typetable; - const int oldsize = *tablesize; - unsigned char *newtable; - int newsize = oldsize * 2; - - if (newsize < nextarg + 1) - newsize = nextarg + 1; - if (oldsize == STATIC_ARG_TBL_SIZE) { - if ((newtable = malloc (newsize)) == NULL) - abort(); /* XXX handle better */ - bcopy (oldtable, newtable, oldsize); - } else { - if ((newtable = realloc (oldtable, newsize)) == NULL) - abort(); /* XXX handle better */ - } - memset (&newtable [oldsize], T_UNUSED, (newsize - oldsize)); - - *typetable = newtable; - *tablesize = newsize; -} - - -#ifdef FLOATING_POINT - -extern char *__dtoa __P((double, int, int, int *, int *, char **, char **)); - -static char * -cvt(value, ndigits, flags, sign, decpt, ch, length, dtoaresultp) - double value; - int ndigits, flags, *decpt, ch, *length; - char *sign; - char **dtoaresultp; -{ - int mode, dsgn; - char *digits, *bp, *rve; - - if (ch == 'f') - mode = 3; /* ndigits after the decimal point */ - else { - /* - * To obtain ndigits after the decimal point for the 'e' - * and 'E' formats, round to ndigits + 1 significant - * figures. - */ - if (ch == 'e' || ch == 'E') - ndigits++; - mode = 2; /* ndigits significant digits */ - } - if (value < 0) { - value = -value; - *sign = '-'; - } else - *sign = '\000'; - digits = __dtoa(value, mode, ndigits, decpt, &dsgn, &rve, dtoaresultp); - if ((ch != 'g' && ch != 'G') || flags & ALT) { - /* print trailing zeros */ - bp = digits + ndigits; - if (ch == 'f') { - if (*digits == '0' && value) - *decpt = -ndigits + 1; - bp += *decpt; - } - if (value == 0) /* kludge for __dtoa irregularity */ - rve = bp; - while (rve < bp) - *rve++ = '0'; - } - *length = rve - digits; - return (digits); -} - -static int -exponent(p0, exp, fmtch) - char *p0; - int exp, fmtch; -{ - register char *p, *t; - char expbuf[MAXEXP]; - - p = p0; - *p++ = fmtch; - if (exp < 0) { - exp = -exp; - *p++ = '-'; - } - else - *p++ = '+'; - t = expbuf + MAXEXP; - if (exp > 9) { - do { - *--t = to_char(exp % 10); - } while ((exp /= 10) > 9); - *--t = to_char(exp); - for (; t < expbuf + MAXEXP; *p++ = *t++); - } - else { - *p++ = '0'; - *p++ = to_char(exp); - } - return (p - p0); -} -#endif /* FLOATING_POINT */ diff --git a/stdio.subproj/vfscanf.c b/stdio.subproj/vfscanf.c deleted file mode 100644 index a12e167..0000000 --- a/stdio.subproj/vfscanf.c +++ /dev/null @@ -1,777 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * 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 -#include -#include -#if __STDC__ -#include -#else -#include -#endif -#include "local.h" - -#define FLOATING_POINT - -#include "floatio.h" -#define BUF 513 /* Maximum length of numeric string. */ - -/* - * Flags used during conversion. - */ -#define LONG 0x01 /* l: long or double */ -#define LONGDBL 0x02 /* L: long double; unimplemented */ -#define SHORT 0x04 /* h: short */ -#define SUPPRESS 0x08 /* suppress assignment */ -#define POINTER 0x10 /* weird %p pointer (`fake hex') */ -#define NOSKIP 0x20 /* do not skip blanks */ -#define QUAD 0x400 - -/* - * The following are used in numeric conversions only: - * SIGNOK, NDIGITS, DPTOK, and EXPOK are for floating point; - * SIGNOK, NDIGITS, PFXOK, and NZDIGITS are for integral. - */ -#define SIGNOK 0x40 /* +/- is (still) legal */ -#define NDIGITS 0x80 /* no digits detected */ - -#define DPTOK 0x100 /* (float) decimal point is still legal */ -#define EXPOK 0x200 /* (float) exponent (e+3, etc) still legal */ - -#define PFXOK 0x100 /* 0x prefix is (still) legal */ -#define NZDIGITS 0x200 /* no zero digits detected */ - -/* - * Conversion types. - */ -#define CT_CHAR 0 /* %c conversion */ -#define CT_CCL 1 /* %[...] conversion */ -#define CT_STRING 2 /* %s conversion */ -#define CT_INT 3 /* integer, i.e., strtoq or strtouq */ -#define CT_FLOAT 4 /* floating, i.e., strtod */ - -#define u_char unsigned char -#define u_long unsigned long - -static u_char *__sccl(char *, u_char *); - -/* - * vfscanf - */ -int -__svfscanf(fp, fmt0, ap) - register FILE *fp; - char const *fmt0; - va_list ap; -{ - register u_char *fmt = (u_char *)fmt0; - register int c; /* character from format, or conversion */ - register size_t width; /* field width, or 0 */ - register char *p; /* points into all kinds of strings */ - register int n; /* handy integer */ - register int flags; /* flags as defined above */ - register 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 strtoq/strtouq */ - u_quad_t (*ccfn)(); /* conversion function (strtoq/strtouq) */ - char ccltab[256]; /* character class table for %[...] */ - char buf[BUF]; /* buffer for numeric conversions */ - - /* `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; - nread = 0; - base = 0; /* XXX just to keep gcc happy */ - ccfn = NULL; /* XXX just to keep gcc happy */ - for (;;) { - c = *fmt++; - if (c == 0) - return (nassigned); - if (isspace(c)) { - for (;;) { - if (fp->_r <= 0 && __srefill(fp)) - return (nassigned); - if (!isspace(*fp->_p)) - break; - nread++, fp->_r--, fp->_p++; - } - continue; - } - if (c != '%') - goto literal; - width = 0; - flags = 0; - /* - * switch on the format. continue if done; - * break once format type is derived. - */ -again: c = *fmt++; - switch (c) { - case '%': -literal: - if (fp->_r <= 0 && __srefill(fp)) - goto input_failure; - if (*fp->_p != c) - goto match_failure; - fp->_r--, fp->_p++; - nread++; - continue; - - case '*': - flags |= SUPPRESS; - goto again; - case 'l': - flags |= LONG; - goto again; - case 'q': - flags |= QUAD; - goto again; - case 'L': - flags |= LONGDBL; - goto again; - case 'h': - flags |= SHORT; - goto again; - - case '0': case '1': case '2': case '3': case '4': - case '5': case '6': case '7': case '8': case '9': - width = width * 10 + c - '0'; - goto again; - - /* - * Conversions. - * Those marked `compat' are for 4.[123]BSD compatibility. - * - * (According to ANSI, E and X formats are supposed - * to the same as e and x. Sorry about that.) - */ - case 'D': /* compat */ - flags |= LONG; - /* FALLTHROUGH */ - case 'd': - c = CT_INT; - ccfn = (u_quad_t (*)())strtoq; - base = 10; - break; - - case 'i': - c = CT_INT; - ccfn = (u_quad_t (*)())strtoq; - base = 0; - break; - - case 'O': /* compat */ - flags |= LONG; - /* FALLTHROUGH */ - case 'o': - c = CT_INT; - ccfn = strtouq; - base = 8; - break; - - case 'u': - c = CT_INT; - ccfn = strtouq; - base = 10; - break; - - case 'X': /* compat XXX */ - flags |= LONG; - /* FALLTHROUGH */ - case 'x': - flags |= PFXOK; /* enable 0x prefixing */ - c = CT_INT; - ccfn = strtouq; - base = 16; - break; - -#ifdef FLOATING_POINT - case 'E': /* compat XXX */ - case 'F': /* compat */ - flags |= LONG; - /* FALLTHROUGH */ - case 'e': case 'f': case 'g': - c = CT_FLOAT; - break; -#endif - - case 's': - c = CT_STRING; - break; - - case '[': - fmt = __sccl(ccltab, fmt); - flags |= NOSKIP; - c = CT_CCL; - break; - - case 'c': - flags |= NOSKIP; - c = CT_CHAR; - break; - - case 'p': /* pointer format is like hex */ - flags |= POINTER | PFXOK; - c = CT_INT; - ccfn = strtouq; - base = 16; - break; - - case 'n': - if (flags & SUPPRESS) /* ??? */ - continue; - if (flags & SHORT) - *va_arg(ap, short *) = nread; - else if (flags & LONG) - *va_arg(ap, long *) = nread; - else if (flags & QUAD) - *va_arg(ap, quad_t *) = nread; - else - *va_arg(ap, int *) = nread; - continue; - - /* - * Disgusting backwards compatibility hacks. XXX - */ - case '\0': /* compat */ - return (EOF); - - default: /* compat */ - if (isupper(c)) - flags |= LONG; - c = CT_INT; - ccfn = (u_quad_t (*)())strtoq; - base = 10; - break; - } - - /* - * We have a conversion that requires input. - */ - if (fp->_r <= 0 && __srefill(fp)) - goto input_failure; - - /* - * Consume leading white space, except for formats - * that suppress this. - */ - if ((flags & NOSKIP) == 0) { - while (isspace(*fp->_p)) { - nread++; - if (--fp->_r > 0) - fp->_p++; - else if (__srefill(fp)) - goto input_failure; - } - /* - * Note that there is at least one character in - * the buffer, so conversions that do not set NOSKIP - * ca no longer result in an input failure. - */ - } - - /* - * Do the conversion. - */ - switch (c) { - - case CT_CHAR: - /* scan arbitrary characters (sets NOSKIP) */ - if (width == 0) - width = 1; - if (flags & SUPPRESS) { - size_t sum = 0; - for (;;) { - if ((n = fp->_r) < width) { - sum += n; - width -= n; - fp->_p += n; - if (__srefill(fp)) { - if (sum == 0) - goto input_failure; - break; - } - } else { - sum += width; - fp->_r -= width; - fp->_p += width; - break; - } - } - nread += sum; - } else { - size_t r = fread((void *)va_arg(ap, char *), 1, - width, fp); - - if (r == 0) - goto input_failure; - nread += r; - nassigned++; - } - break; - - case CT_CCL: - /* scan a (nonempty) character class (sets NOSKIP) */ - if (width == 0) - width = ~0; /* `infinity' */ - /* take only those things in the class */ - if (flags & SUPPRESS) { - n = 0; - while (ccltab[*fp->_p]) { - n++, fp->_r--, fp->_p++; - if (--width == 0) - break; - if (fp->_r <= 0 && __srefill(fp)) { - if (n == 0) - goto input_failure; - break; - } - } - if (n == 0) - goto match_failure; - } else { - p0 = p = va_arg(ap, char *); - while (ccltab[*fp->_p]) { - fp->_r--; - *p++ = *fp->_p++; - if (--width == 0) - break; - if (fp->_r <= 0 && __srefill(fp)) { - if (p == p0) - goto input_failure; - break; - } - } - n = p - p0; - if (n == 0) - goto match_failure; - *p = 0; - nassigned++; - } - nread += n; - break; - - case CT_STRING: - /* like CCL, but zero-length string OK, & no NOSKIP */ - if (width == 0) - width = ~0; - if (flags & SUPPRESS) { - n = 0; - while (!isspace(*fp->_p)) { - n++, fp->_r--, fp->_p++; - if (--width == 0) - break; - if (fp->_r <= 0 && __srefill(fp)) - break; - } - nread += n; - } else { - p0 = p = va_arg(ap, char *); - while (!isspace(*fp->_p)) { - fp->_r--; - *p++ = *fp->_p++; - if (--width == 0) - break; - if (fp->_r <= 0 && __srefill(fp)) - break; - } - *p = 0; - nread += p - p0; - nassigned++; - } - continue; - - case CT_INT: - /* scan an integer as if by strtoq/strtouq */ -#ifdef hardway - if (width == 0 || width > sizeof(buf) - 1) - width = sizeof(buf) - 1; -#else - /* size_t is unsigned, hence this optimisation */ - if (--width > sizeof(buf) - 2) - width = sizeof(buf) - 2; - width++; -#endif - flags |= SIGNOK | NDIGITS | NZDIGITS; - for (p = buf; width; width--) { - c = *fp->_p; - /* - * Switch on the character; `goto ok' - * if we accept it as a part of number. - */ - switch (c) { - - /* - * The digit 0 is always legal, but is - * special. For %i conversions, if no - * digits (zero or nonzero) have been - * scanned (only signs), we will have - * base==0. In that case, we should set - * it to 8 and enable 0x prefixing. - * Also, if we have not scanned zero digits - * before this, do not turn off prefixing - * (someone else will turn it off if we - * have scanned any nonzero digits). - */ - case '0': - if (base == 0) { - base = 8; - flags |= PFXOK; - } - if (flags & NZDIGITS) - flags &= ~(SIGNOK|NZDIGITS|NDIGITS); - else - flags &= ~(SIGNOK|PFXOK|NDIGITS); - goto ok; - - /* 1 through 7 always legal */ - case '1': case '2': case '3': - case '4': case '5': case '6': case '7': - base = basefix[base]; - flags &= ~(SIGNOK | PFXOK | NDIGITS); - goto ok; - - /* digits 8 and 9 ok iff decimal or hex */ - case '8': case '9': - base = basefix[base]; - if (base <= 8) - break; /* not legal here */ - flags &= ~(SIGNOK | PFXOK | NDIGITS); - goto ok; - - /* letters ok iff hex */ - case 'A': case 'B': case 'C': - case 'D': case 'E': case 'F': - case 'a': case 'b': case 'c': - case 'd': case 'e': case 'f': - /* no need to fix base here */ - if (base <= 10) - break; /* not legal here */ - flags &= ~(SIGNOK | PFXOK | NDIGITS); - goto ok; - - /* sign ok only as first character */ - case '+': case '-': - if (flags & SIGNOK) { - flags &= ~SIGNOK; - goto ok; - } - break; - - /* x ok iff flag still set & 2nd char */ - case 'x': case 'X': - if (flags & PFXOK && p == buf + 1) { - base = 16; /* if %i */ - flags &= ~PFXOK; - goto ok; - } - break; - } - - /* - * If we got here, c is not a legal character - * for a number. Stop accumulating digits. - */ - break; - ok: - /* - * c is legal: store it and look at the next. - */ - *p++ = c; - if (--fp->_r > 0) - fp->_p++; - else if (__srefill(fp)) - break; /* EOF */ - } - /* - * If we had only a sign, it is no good; push - * back the sign. If the number ends in `x', - * it was [sign] '0' 'x', so push back the x - * and treat it as [sign] '0'. - */ - if (flags & NDIGITS) { - if (p > buf) - (void) ungetc(*(u_char *)--p, fp); - goto match_failure; - } - c = ((u_char *)p)[-1]; - if (c == 'x' || c == 'X') { - --p; - (void) ungetc(c, fp); - } - if ((flags & SUPPRESS) == 0) { - u_quad_t res; - - *p = 0; - res = (*ccfn)(buf, (char **)NULL, base); - if (flags & POINTER) - *va_arg(ap, void **) = (void *)res; - else if (flags & SHORT) - *va_arg(ap, short *) = res; - else if (flags & LONG) - *va_arg(ap, long *) = res; - else if (flags & QUAD) - *va_arg(ap, quad_t *) = res; - else - *va_arg(ap, int *) = res; - nassigned++; - } - nread += p - buf; - break; - -#ifdef FLOATING_POINT - case CT_FLOAT: - /* scan a floating point number as if by strtod */ -#ifdef hardway - if (width == 0 || width > sizeof(buf) - 1) - width = sizeof(buf) - 1; -#else - /* size_t is unsigned, hence this optimisation */ - if (--width > sizeof(buf) - 2) - width = sizeof(buf) - 2; - width++; -#endif - flags |= SIGNOK | NDIGITS | DPTOK | EXPOK; - for (p = buf; width; width--) { - c = *fp->_p; - /* - * This code mimicks the integer conversion - * code, but is much simpler. - */ - switch (c) { - - case '0': case '1': case '2': case '3': - case '4': case '5': case '6': case '7': - case '8': case '9': - flags &= ~(SIGNOK | NDIGITS); - goto fok; - - case '+': case '-': - if (flags & SIGNOK) { - flags &= ~SIGNOK; - goto fok; - } - break; - case '.': - if (flags & DPTOK) { - flags &= ~(SIGNOK | DPTOK); - goto fok; - } - break; - case 'e': case 'E': - /* no exponent without some digits */ - if ((flags&(NDIGITS|EXPOK)) == EXPOK) { - flags = - (flags & ~(EXPOK|DPTOK)) | - SIGNOK | NDIGITS; - goto fok; - } - break; - } - break; - fok: - *p++ = c; - if (--fp->_r > 0) - fp->_p++; - else if (__srefill(fp)) - break; /* EOF */ - } - /* - * If no digits, might be missing exponent digits - * (just give back the exponent) or might be missing - * regular digits, but had sign and/or decimal point. - */ - if (flags & NDIGITS) { - if (flags & EXPOK) { - /* no digits at all */ - while (p > buf) - ungetc(*(u_char *)--p, fp); - goto match_failure; - } - /* just a bad exponent (e and maybe sign) */ - c = *(u_char *)--p; - if (c != 'e' && c != 'E') { - (void) ungetc(c, fp);/* sign */ - c = *(u_char *)--p; - } - (void) ungetc(c, fp); - } - if ((flags & SUPPRESS) == 0) { - double res; - - *p = 0; - res = strtod(buf,(char **) NULL); - if (flags & LONGDBL) - *va_arg(ap, long double *) = res; - else if (flags & LONG) - *va_arg(ap, double *) = res; - else - *va_arg(ap, float *) = res; - nassigned++; - } - nread += p - buf; - break; -#endif /* FLOATING_POINT */ - } - } -input_failure: - return (nassigned ? nassigned : -1); -match_failure: - return (nassigned); -} - -/* - * Fill in the given table from the scanset at the given format - * (just after `['). Return a pointer to the character past the - * closing `]'. The table has a 1 wherever characters should be - * considered part of the scanset. - */ -static u_char * -__sccl(tab, fmt) - register char *tab; - register u_char *fmt; -{ - register int c, n, v; - - /* first `clear' the whole table */ - c = *fmt++; /* first char hat => negated scanset */ - if (c == '^') { - v = 1; /* default => accept */ - c = *fmt++; /* get new first char */ - } else - v = 0; /* default => reject */ - /* should probably use memset here */ - for (n = 0; n < 256; n++) - tab[n] = v; - if (c == 0) - return (fmt - 1);/* format ended before closing ] */ - - /* - * Now set the entries corresponding to the actual scanset - * to the opposite of the above. - * - * The first character may be ']' (or '-') without being special; - * the last character may be '-'. - */ - v = 1 - v; - for (;;) { - tab[c] = v; /* take character c */ -doswitch: - n = *fmt++; /* and examine the next */ - switch (n) { - - case 0: /* format ended too soon */ - return (fmt - 1); - - case '-': - /* - * A scanset of the form - * [01+-] - * is defined as `the digit 0, the digit 1, - * the character +, the character -', but - * the effect of a scanset such as - * [a-zA-Z0-9] - * is implementation defined. The V7 Unix - * scanf treats `a-z' as `the letters a through - * z', but treats `a-a' as `the letter a, the - * character -, and the letter a'. - * - * For compatibility, the `-' is not considerd - * to define a range if the character following - * it is either a close bracket (required by ANSI) - * or is not numerically greater than the character - * we just stored in the table (c). - */ - n = *fmt; - if (n == ']' || n < c) { - c = '-'; - break; /* resume the for(;;) */ - } - fmt++; - do { /* fill in the range */ - tab[++c] = v; - } while (c < n); -#if 1 /* XXX another disgusting compatibility hack */ - /* - * Alas, the V7 Unix scanf also treats formats - * such as [a-c-e] as `the letters a through e'. - * This too is permitted by the standard.... - */ - goto doswitch; -#else - c = *fmt++; - if (c == 0) - return (fmt - 1); - if (c == ']') - return (fmt); -#endif - break; - - case ']': /* end of scanset */ - return (fmt); - - default: /* just another character */ - c = n; - break; - } - } - /* NOTREACHED */ -} diff --git a/stdio.subproj/vprintf.c b/stdio.subproj/vprintf.c deleted file mode 100644 index 686deaf..0000000 --- a/stdio.subproj/vprintf.c +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * 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 - -int -vprintf(fmt, ap) - char const *fmt; - _BSD_VA_LIST_ ap; -{ - return (vfprintf(stdout, fmt, ap)); -} diff --git a/stdio.subproj/vscanf.c b/stdio.subproj/vscanf.c deleted file mode 100644 index 3b92a1c..0000000 --- a/stdio.subproj/vscanf.c +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Donn Seeley at UUNET Technologies, 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. - */ - - -#include - -int -vscanf(fmt, ap) - const char *fmt; - _BSD_VA_LIST_ ap; -{ - - return (__svfscanf(stdin, fmt, ap)); -} diff --git a/stdio.subproj/vsnprintf.c b/stdio.subproj/vsnprintf.c deleted file mode 100644 index 3d2e6d1..0000000 --- a/stdio.subproj/vsnprintf.c +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * 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 - -int -vsnprintf(str, n, fmt, ap) - char *str; - size_t n; - const char *fmt; - _BSD_VA_LIST_ ap; -{ - int ret; - FILE f; - - if ((int)n < 1) - return (EOF); - f._flags = __SWR | __SSTR; - f._bf._base = f._p = (unsigned char *)str; - f._bf._size = f._w = n - 1; - ret = vfprintf(&f, fmt, ap); - *f._p = 0; - return (ret); -} diff --git a/stdio.subproj/vsprintf.c b/stdio.subproj/vsprintf.c deleted file mode 100644 index 2e8e0ad..0000000 --- a/stdio.subproj/vsprintf.c +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * 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 -#include - -int -vsprintf(str, fmt, ap) - char *str; - const char *fmt; - _BSD_VA_LIST_ ap; -{ - int ret; - FILE f; - - f._flags = __SWR | __SSTR; - f._bf._base = f._p = (unsigned char *)str; - f._bf._size = f._w = INT_MAX; - ret = vfprintf(&f, fmt, ap); - *f._p = 0; - return (ret); -} diff --git a/stdio.subproj/vsscanf.c b/stdio.subproj/vsscanf.c deleted file mode 100644 index 59bbabf..0000000 --- a/stdio.subproj/vsscanf.c +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Donn Seeley at UUNET Technologies, 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. - */ - - -#include -#include - -/* ARGSUSED */ -static int -eofread(cookie, buf, len) - void *cookie; - char *buf; - int len; -{ - - return (0); -} - -int -vsscanf(str, fmt, ap) - const char *str; - const char *fmt; - _BSD_VA_LIST_ ap; -{ - FILE f; - - 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; - return (__svfscanf(&f, fmt, ap)); -} diff --git a/stdio.subproj/wbuf.c b/stdio.subproj/wbuf.c deleted file mode 100644 index 78032d4..0000000 --- a/stdio.subproj/wbuf.c +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * 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 -#include "local.h" - -/* - * Write the given character into the (probably full) buffer for - * the given file. Flush the buffer out if it is or becomes full, - * or if c=='\n' and the file is line buffered. - */ -int -__swbuf(c, fp) - register int c; - register FILE *fp; -{ - register int n; - - /* - * In case we cannot write, or longjmp takes us out early, - * make sure _w is 0 (if fully- or un-buffered) or -_bf._size - * (if line buffered) so that we will get called again. - * If we did not do this, a sufficient number of putc() - * calls might wrap _w from negative to positive. - */ - fp->_w = fp->_lbfsize; - if (cantwrite(fp)) - return (EOF); - c = (unsigned char)c; - - /* - * If it is completely full, flush it out. Then, in any case, - * stuff c into the buffer. If this causes the buffer to fill - * completely, or if c is '\n' and the file is line buffered, - * flush it (perhaps a second time). The second flush will always - * happen on unbuffered streams, where _bf._size==1; fflush() - * guarantees that putc() will always call wbuf() by setting _w - * to 0, so we need not do anything else. - */ - n = fp->_p - fp->_bf._base; - if (n >= fp->_bf._size) { - if (fflush(fp)) - return (EOF); - n = 0; - } - fp->_w--; - *fp->_p++ = c; - if (++n == fp->_bf._size || (fp->_flags & __SLBF && c == '\n')) - if (fflush(fp)) - return (EOF); - return (c); -} diff --git a/stdio.subproj/wsetup.c b/stdio.subproj/wsetup.c deleted file mode 100644 index 758523d..0000000 --- a/stdio.subproj/wsetup.c +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * 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 -#include -#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. - */ -int -__swsetup(fp) - register FILE *fp; -{ - /* make sure stdio is set up */ - if (!__sdidinit) - __sinit(); - - /* - * If we are not writing, we had better be reading and writing. - */ - if ((fp->_flags & __SWR) == 0) { - if ((fp->_flags & __SRW) == 0) - return (EOF); - if (fp->_flags & __SRD) { - /* clobber any ungetc data */ - if (HASUB(fp)) - FREEUB(fp); - fp->_flags &= ~(__SRD|__SEOF); - fp->_r = 0; - fp->_p = fp->_bf._base; - } - fp->_flags |= __SWR; - } - - /* - * Make a buffer if necessary, then set _w. - */ - if (fp->_bf._base == NULL) - __smakebuf(fp); - if (fp->_flags & __SLBF) { - /* - * It is line buffered, so make _lbfsize be -_bufsize - * for the putc() macro. We will change _lbfsize back - * to 0 whenever we turn off __SWR. - */ - fp->_w = 0; - fp->_lbfsize = -fp->_bf._size; - } else - fp->_w = fp->_flags & __SNBF ? 0 : fp->_bf._size; - return (0); -} diff --git a/stdio/Makefile.inc b/stdio/Makefile.inc new file mode 100644 index 0000000..0054af3 --- /dev/null +++ b/stdio/Makefile.inc @@ -0,0 +1,47 @@ +# @(#)Makefile.inc 8.3 (Berkeley) 4/17/94 +# $FreeBSD: src/lib/libc/stdio/Makefile.inc,v 1.20 2001/03/27 17:26:52 ru Exp $ + +# stdio sources +.PATH: ${.CURDIR}/stdio + +SRCS+= clrerr.c findfp.c fsetpos.c mktemp.c scanf.c ungetc.c \ + fclose.c flags.c ftell.c perror.c setbuf.c vfprintf.c \ + fdopen.c fopen.c funopen.c printf.c setbuffer.c vfscanf.c \ + feof.c fprintf.c fvwrite.c putc.c setvbuf.c vprintf.c \ + ferror.c fpurge.c fwalk.c putchar.c snprintf.c vscanf.c \ + fflush.c fputc.c fwrite.c puts.c sprintf.c vsnprintf.c \ + fgetc.c fputs.c getc.c putw.c sscanf.c vsprintf.c \ + fgetln.c fread.c getchar.c refill.c stdio.c vsscanf.c \ + fgetpos.c freopen.c gets.c remove.c tempnam.c wbuf.c \ + fgets.c fscanf.c getw.c rewind.c tmpfile.c wsetup.c \ + fileno.c fseek.c makebuf.c rget.c tmpnam.c asprintf.c \ + vasprintf.c + + +.if ${LIB} == "c" +MAN3+= fclose.3 ferror.3 fflush.3 fgetln.3 fgets.3 fopen.3 fputs.3 \ + fread.3 fseek.3 funopen.3 getc.3 mktemp.3 printf.3 putc.3 remove.3 \ + scanf.3 setbuf.3 stdio.3 tmpnam.3 ungetc.3 + +MLINKS+=ferror.3 clearerr.3 ferror.3 feof.3 ferror.3 fileno.3 +MLINKS+=fflush.3 fpurge.3 +MLINKS+=fgets.3 gets.3 +MLINKS+=fopen.3 fdopen.3 fopen.3 freopen.3 +MLINKS+=fputs.3 puts.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+=funopen.3 fropen.3 funopen.3 fwopen.3 +MLINKS+=getc.3 fgetc.3 getc.3 getchar.3 getc.3 getw.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+=putc.3 fputc.3 putc.3 putchar.3 putc.3 putw.3 +MLINKS+=scanf.3 fscanf.3 scanf.3 sscanf.3 scanf.3 vfscanf.3 scanf.3 vscanf.3 \ + scanf.3 vsscanf.3 +MLINKS+=setbuf.3 setbuffer.3 setbuf.3 setlinebuf.3 setbuf.3 setvbuf.3 +MLINKS+=tmpnam.3 tempnam.3 tmpnam.3 tmpfile.3 +.endif diff --git a/stdio/asprintf.c b/stdio/asprintf.c new file mode 100644 index 0000000..e0da796 --- /dev/null +++ b/stdio/asprintf.c @@ -0,0 +1,81 @@ +/* $OpenBSD: asprintf.c,v 1.4 1998/06/21 22:13:46 millert Exp $ */ + +/* + * Copyright (c) 1997 Todd C. Miller + * 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. 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 ARE 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 + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#if defined(LIBC_RCS) && !defined(lint) +static char rcsid[] = "$FreeBSD: src/lib/libc/stdio/asprintf.c,v 1.6 1999/08/28 00:00:55 peter Exp $"; +#endif /* LIBC_RCS and not lint */ + +#include +#include +#include +#if __STDC__ +#include +#else +#include +#endif + +int +#if __STDC__ +asprintf(char **str, char const *fmt, ...) +#else +asprintf(str, fmt, va_alist) + char **str; + const char *fmt; + va_dcl +#endif +{ + int ret; + va_list ap; + FILE f; + +#if __STDC__ + va_start(ap, fmt); +#else + va_start(ap); +#endif + 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 NULL */ + ret = vfprintf(&f, fmt, ap); + *f._p = '\0'; + va_end(ap); + f._bf._base = reallocf(f._bf._base, f._bf._size + 1); + if (f._bf._base == NULL) { + errno = ENOMEM; + ret = -1; + } + *str = (char *)f._bf._base; + return (ret); +} diff --git a/stdio/clrerr.c b/stdio/clrerr.c new file mode 100644 index 0000000..610dae9 --- /dev/null +++ b/stdio/clrerr.c @@ -0,0 +1,67 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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 +#undef clearerr + +void +clearerr(fp) + FILE *fp; +{ + __sclearerr(fp); +} diff --git a/stdio/fclose.3 b/stdio/fclose.3 new file mode 100644 index 0000000..5dded81 --- /dev/null +++ b/stdio/fclose.3 @@ -0,0 +1,99 @@ +.\" 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. +.\" +.\" @(#)fclose.3 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD: src/lib/libc/stdio/fclose.3,v 1.11 2001/10/01 16:08:58 ru Exp $ +.\" +.Dd June 4, 1993 +.Dt FCLOSE 3 +.Os +.Sh NAME +.Nm fclose +.Nd close a stream +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In stdio.h +.Ft int +.Fn fclose "FILE *stream" +.Sh DESCRIPTION +The +.Fn fclose +function +dissociates the named +.Fa stream +from its underlying file or set of functions. +If the stream was being used for output, any buffered data is written +first, using +.Xr fflush 3 . +.Sh RETURN VALUES +Upon successful completion 0 is returned. +Otherwise, +.Dv EOF +is returned and the global variable +.Va errno +is set to indicate the error. +In either case no further access to the stream is possible. +.Sh ERRORS +The +.Fn fclose +function +may also fail and set +.Va errno +for any of the errors specified for the routines +.Xr close 2 +or +.Xr fflush 3 . +.Sh NOTES +.Fn fclose +does not handle NULL arguments; they will result in a segmentation +violation. +This is intentional - it makes it easier to make sure programs written +under +.Fx +are bug free. +This behaviour is an implementation detail, and programs should not +rely upon it. +.Sh SEE ALSO +.Xr close 2 , +.Xr fflush 3 , +.Xr fopen 3 , +.Xr setbuf 3 +.Sh STANDARDS +The +.Fn fclose +function +conforms to +.St -isoC . diff --git a/stdio/fclose.c b/stdio/fclose.c new file mode 100644 index 0000000..e7b1c97 --- /dev/null +++ b/stdio/fclose.c @@ -0,0 +1,86 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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 +#include +#include +#include "local.h" + +int +fclose(fp) + register FILE *fp; +{ + register int r; + + if (fp->_flags == 0) { /* not open! */ + errno = EBADF; + return (EOF); + } + r = fp->_flags & __SWR ? __sflush(fp) : 0; + if (fp->_close != NULL && (*fp->_close)(fp->_cookie) < 0) + r = EOF; + if (fp->_flags & __SMBF) + free((char *)fp->_bf._base); + if (HASUB(fp)) + FREEUB(fp); + if (HASLB(fp)) + FREELB(fp); + fp->_flags = 0; /* Release this FILE for reuse. */ + fp->_r = fp->_w = 0; /* Mess up if reaccessed. */ + return (r); +} diff --git a/stdio/fdopen.c b/stdio/fdopen.c new file mode 100644 index 0000000..4bc1a94 --- /dev/null +++ b/stdio/fdopen.c @@ -0,0 +1,107 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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 +#include +#include +#include +#include +#include "local.h" + +FILE * +fdopen(fd, mode) + int fd; + const char *mode; +{ + register FILE *fp; + static int nofile; + int flags, oflags, fdflags, tmp; + + if (nofile == 0) + nofile = getdtablesize(); + + if ((flags = __sflags(mode, &oflags)) == 0) + return (NULL); + + /* Make sure the mode the user wants is a subset of the actual mode. */ + if ((fdflags = fcntl(fd, F_GETFL, 0)) < 0) + return (NULL); + tmp = fdflags & O_ACCMODE; + if (tmp != O_RDWR && (tmp != (oflags & O_ACCMODE))) { + errno = EINVAL; + return (NULL); + } + + if ((fp = __sfp()) == NULL) + return (NULL); + fp->_flags = flags; + /* + * If opened for appending, but underlying descriptor does not have + * O_APPEND bit set, assert __SAPP so that __swrite() will lseek to + * end before each write. + */ + if ((oflags & O_APPEND) && !(fdflags & O_APPEND)) + fp->_flags |= __SAPP; + fp->_file = fd; + fp->_cookie = fp; + fp->_read = __sread; + fp->_write = __swrite; + fp->_seek = __sseek; + fp->_close = __sclose; + return (fp); +} diff --git a/stdio/feof.c b/stdio/feof.c new file mode 100644 index 0000000..756ff08 --- /dev/null +++ b/stdio/feof.c @@ -0,0 +1,71 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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 + +/* + * A subroutine version of the macro feof. + */ +#undef feof + +int +feof(fp) + FILE *fp; +{ + return (__sfeof(fp)); +} diff --git a/stdio/ferror.3 b/stdio/ferror.3 new file mode 100644 index 0000000..ff8b1f6 --- /dev/null +++ b/stdio/ferror.3 @@ -0,0 +1,103 @@ +.\" 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. +.\" +.\" @(#)ferror.3 8.2 (Berkeley) 4/19/94 +.\" $FreeBSD: src/lib/libc/stdio/ferror.3,v 1.6 2001/10/01 16:08:59 ru Exp $ +.\" +.Dd April 19, 1994 +.Dt FERROR 3 +.Os +.Sh NAME +.Nm clearerr , +.Nm feof , +.Nm ferror , +.Nm fileno +.Nd check and reset stream status +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In stdio.h +.Ft void +.Fn clearerr "FILE *stream" +.Ft int +.Fn feof "FILE *stream" +.Ft int +.Fn ferror "FILE *stream" +.Ft int +.Fn fileno "FILE *stream" +.Sh DESCRIPTION +The function +.Fn clearerr +clears the end-of-file and error indicators for the stream pointed +to by +.Fa stream . +.Pp +The function +.Fn feof +tests the end-of-file indicator for the stream pointed to by +.Fa stream , +returning non-zero if it is set. +The end-of-file indicator can only be cleared by the function +.Fn clearerr . +.Pp +The function +.Fn ferror +tests the error indicator for the stream pointed to by +.Fa stream , +returning non-zero if it is set. +The error indicator can only be reset by the +.Fn clearerr +function. +.Pp +The function +.Fn fileno +examines the argument +.Fa stream +and returns its integer descriptor. +.Sh ERRORS +These functions should not fail and do not set the external +variable +.Va errno . +.Sh SEE ALSO +.Xr open 2 , +.Xr stdio 3 +.Sh STANDARDS +The functions +.Fn clearerr , +.Fn feof , +and +.Fn ferror +conform to +.St -isoC . diff --git a/stdio/ferror.c b/stdio/ferror.c new file mode 100644 index 0000000..ef590e5 --- /dev/null +++ b/stdio/ferror.c @@ -0,0 +1,71 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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 + +/* + * A subroutine version of the macro ferror. + */ +#undef ferror + +int +ferror(fp) + FILE *fp; +{ + return (__sferror(fp)); +} diff --git a/stdio/fflush.3 b/stdio/fflush.3 new file mode 100644 index 0000000..37c7dcd --- /dev/null +++ b/stdio/fflush.3 @@ -0,0 +1,113 @@ +.\" 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. +.\" +.\" @(#)fflush.3 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD: src/lib/libc/stdio/fflush.3,v 1.8 2001/10/01 16:08:59 ru Exp $ +.\" +.Dd June 4, 1993 +.Dt FFLUSH 3 +.Os +.Sh NAME +.Nm fflush , +.Nm fpurge +.Nd flush a stream +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In stdio.h +.Ft int +.Fn fflush "FILE *stream" +.Ft int +.Fn fpurge "FILE *stream" +.Sh DESCRIPTION +The function +.Fn fflush +forces a write of all buffered data for the given output or update +.Fa stream +via the stream's underlying write function. +The open status of the stream is unaffected. +.Pp +If the +.Fa stream +argument is +.Dv NULL , +.Fn fflush +flushes +.Em all +open output streams. +.Pp +The function +.Fn fpurge +erases any input or output buffered in the given +.Fa stream . +For output streams this discards any unwritten output. +For input streams this discards any input read from the underlying object +but not yet obtained via +.Xr getc 3 ; +this includes any text pushed back via +.Xr ungetc . +.Sh RETURN VALUES +Upon successful completion 0 is returned. +Otherwise, +.Dv EOF +is returned and the global variable +.Va errno +is set to indicate the error. +.Sh ERRORS +.Bl -tag -width Er +.It Bq Er EBADF +.Fa Stream +is not an open stream, or, in the case of +.Fn fflush , +not a stream open for writing. +.El +.Pp +The function +.Fn fflush +may also fail and set +.Va errno +for any of the errors specified for the routine +.Xr write 2 . +.Sh SEE ALSO +.Xr write 2 , +.Xr fclose 3 , +.Xr fopen 3 , +.Xr setbuf 3 +.Sh STANDARDS +The +.Fn fflush +function +conforms to +.St -isoC . diff --git a/stdio/fflush.c b/stdio/fflush.c new file mode 100644 index 0000000..33793d4 --- /dev/null +++ b/stdio/fflush.c @@ -0,0 +1,109 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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 +#include +#include "local.h" + +/* Flush a single file, or (if fp is NULL) all files. */ +int +fflush(fp) + register FILE *fp; +{ + + if (fp == NULL) + return (_fwalk(__sflush)); + if ((fp->_flags & (__SWR | __SRW)) == 0) { + errno = EBADF; + return (EOF); + } + return (__sflush(fp)); +} + +int +__sflush(fp) + register FILE *fp; +{ + register unsigned char *p; + register int n, t; + + t = fp->_flags; + if ((t & __SWR) == 0) + return (0); + + if ((p = fp->_bf._base) == NULL) + return (0); + + n = fp->_p - p; /* write this much */ + + /* + * Set these immediately to avoid problems with longjmp and to allow + * exchange buffering (via setvbuf) in user write function. + */ + fp->_p = p; + fp->_w = t & (__SLBF|__SNBF) ? 0 : fp->_bf._size; + + for (; n > 0; n -= t, p += t) { + t = (*fp->_write)(fp->_cookie, (char *)p, n); + if (t <= 0) { + fp->_flags |= __SERR; + return (EOF); + } + } + return (0); +} diff --git a/stdio/fgetc.c b/stdio/fgetc.c new file mode 100644 index 0000000..78a771b --- /dev/null +++ b/stdio/fgetc.c @@ -0,0 +1,66 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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 + +int +fgetc(fp) + FILE *fp; +{ + return (__sgetc(fp)); +} diff --git a/stdio/fgetln.3 b/stdio/fgetln.3 new file mode 100644 index 0000000..e779aec --- /dev/null +++ b/stdio/fgetln.3 @@ -0,0 +1,127 @@ +.\" Copyright (c) 1990, 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. +.\" +.\" @(#)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 $ +.\" +.Dd April 19, 1994 +.Dt FGETLN 3 +.Os +.Sh NAME +.Nm fgetln +.Nd get a line from a stream +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In stdio.h +.Ft char * +.Fn fgetln "FILE *stream" "size_t *len" +.Sh DESCRIPTION +The +.Fn fgetln +function +returns a pointer to the next line from the stream referenced by +.Fa stream . +This line is +.Em not +a C string as it does not end with a terminating +.Dv NUL +character. +The length of the line, including the final newline, +is stored in the memory location to which +.Fa len +points. +(Note, however, that if the line is the last +in a file that does not end in a newline, +the returned text will not contain a newline.) +.Sh RETURN VALUES +Upon successful completion a pointer is returned; +this pointer becomes invalid after the next +.Tn I/O +operation on +.Fa stream +(whether successful or not) +or as soon as the stream is closed. +Otherwise, +.Dv NULL +is returned. +The +.Fn fgetln +function +does not distinguish between end-of-file and error; the routines +.Xr feof 3 +and +.Xr ferror 3 +must be used +to determine which occurred. +If an error occurs, the global variable +.Va errno +is set to indicate the error. +The end-of-file condition is remembered, even on a terminal, and all +subsequent attempts to read will return +.Dv NULL +until the condition is +cleared with +.Xr clearerr 3 . +.Pp +The text to which the returned pointer points may be modified, +provided that no changes are made beyond the returned size. +These changes are lost as soon as the pointer becomes invalid. +.Sh ERRORS +.Bl -tag -width Er +.It Bq Er EBADF +The argument +.Fa stream +is not a stream open for reading. +.El +.Pp +The +.Fn fgetln +function +may also fail and set +.Va errno +for any of the errors specified for the routines +.Xr fflush 3 , +.Xr malloc 3 , +.Xr read 2 , +.Xr stat 2 , +or +.Xr realloc 3 . +.Sh SEE ALSO +.Xr ferror 3 , +.Xr fgets 3 , +.Xr fopen 3 , +.Xr putc 3 +.Sh HISTORY +The +.Fn fgetln +function first appeared in +.Bx 4.4 . diff --git a/stdio/fgetln.c b/stdio/fgetln.c new file mode 100644 index 0000000..d1ce9d5 --- /dev/null +++ b/stdio/fgetln.c @@ -0,0 +1,179 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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 +#include +#include +#include "local.h" + +/* + * Expand the line buffer. Return -1 on error. +#ifdef notdef + * The `new size' does not account for a terminating '\0', + * so we add 1 here. +#endif + */ +int +__slbexpand(fp, newsize) + FILE *fp; + size_t newsize; +{ + void *p; + +#ifdef notdef + ++newsize; +#endif + if (fp->_lb._size >= newsize) + return (0); + if ((p = realloc(fp->_lb._base, newsize)) == NULL) + return (-1); + fp->_lb._base = p; + fp->_lb._size = newsize; + return (0); +} + +/* + * Get an input line. The returned pointer often (but not always) + * points into a stdio buffer. Fgetln does not alter the text of + * the returned line (which is thus not a C string because it will + * not necessarily end with '\0'), but does allow callers to modify + * it if they wish. Thus, we set __SMOD in case the caller does. + */ +char * +fgetln(fp, lenp) + register FILE *fp; + size_t *lenp; +{ + register unsigned char *p; + register size_t len; + size_t off; + + /* make sure there is input */ + if (fp->_r <= 0 && __srefill(fp)) { + *lenp = 0; + return (NULL); + } + + /* look for a newline in the input */ + if ((p = memchr((void *)fp->_p, '\n', fp->_r)) != NULL) { + register char *ret; + + /* + * Found one. Flag buffer as modified to keep fseek from + * `optimising' a backward seek, in case the user stomps on + * the text. + */ + p++; /* advance over it */ + ret = (char *)fp->_p; + *lenp = len = p - fp->_p; + fp->_flags |= __SMOD; + fp->_r -= len; + fp->_p = p; + return (ret); + } + + /* + * We have to copy the current buffered data to the line buffer. + * As a bonus, though, we can leave off the __SMOD. + * + * OPTIMISTIC is length that we (optimistically) expect will + * accomodate the `rest' of the string, on each trip through the + * loop below. + */ +#define OPTIMISTIC 80 + + for (len = fp->_r, off = 0;; len += fp->_r) { + register size_t diff; + + /* + * Make sure there is room for more bytes. Copy data from + * 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)) + goto error; + (void)memcpy((void *)(fp->_lb._base + off), (void *)fp->_p, + len - off); + off = len; + if (__srefill(fp)) + break; /* EOF or error: return partial line */ + if ((p = memchr((void *)fp->_p, '\n', fp->_r)) == NULL) + continue; + + /* got it: finish up the line (like code above) */ + p++; + diff = p - fp->_p; + len += diff; + if (__slbexpand(fp, len)) + goto error; + (void)memcpy((void *)(fp->_lb._base + off), (void *)fp->_p, + diff); + fp->_r -= diff; + fp->_p = p; + break; + } + *lenp = len; +#ifdef notdef + fp->_lb._base[len] = 0; +#endif + return ((char *)fp->_lb._base); + +error: + *lenp = 0; /* ??? */ + return (NULL); /* ??? */ +} diff --git a/stdio/fgetpos.c b/stdio/fgetpos.c new file mode 100644 index 0000000..0dfafd6 --- /dev/null +++ b/stdio/fgetpos.c @@ -0,0 +1,71 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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 + +int +fgetpos(fp, pos) + FILE *fp; + fpos_t *pos; +{ + int retval; + /* FLOCKFILE(fp); */ + retval = (*pos = ftello(fp)) == (fpos_t)-1; + /* FUNLOCKFILE(fp); */ + return(retval); +} diff --git a/stdio/fgets.3 b/stdio/fgets.3 new file mode 100644 index 0000000..cb808a0 --- /dev/null +++ b/stdio/fgets.3 @@ -0,0 +1,158 @@ +.\" 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. +.\" +.\" @(#)fgets.3 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD: src/lib/libc/stdio/fgets.3,v 1.12 2001/10/01 16:08:59 ru Exp $ +.\" +.Dd June 4, 1993 +.Dt FGETS 3 +.Os +.Sh NAME +.Nm fgets , +.Nm gets +.Nd get a line from a stream +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In stdio.h +.Ft char * +.Fn fgets "char *str" "int size" "FILE *stream" +.Ft char * +.Fn gets "char *str" +.Sh DESCRIPTION +The +.Fn fgets +function +reads at most one less than the number of characters specified by +.Fa size +from the given +.Fa stream +and stores them in the string +.Fa str . +Reading stops when a newline character is found, +at end-of-file or error. +The newline, if any, is retained. +If any characters are read and there is no error, a +.Ql \e0 +character is appended to end the string. +.Pp +The +.Fn gets +function +is equivalent to +.Fn fgets +with an infinite +.Fa size +and a +.Fa stream +of +.Em stdin , +except that the newline character (if any) is not stored in the string. +It is the caller's responsibility to ensure that the input line, +if any, is sufficiently short to fit in the string. +.Sh RETURN VALUES +Upon successful completion, +.Fn fgets +and +.Fn gets +return +a pointer to the string. +If end-of-file occurs before any characters are read, +they return +.Dv NULL +and the buffer contents is unchanged. +If an error occurs, +they return +.Dv NULL +and the buffer contents is indeterminate. +The +.Fn fgets +and +.Fn gets +functions +do not distinguish between end-of-file and error, and callers must use +.Xr feof 3 +and +.Xr ferror 3 +to determine which occurred. +.Sh ERRORS +.Bl -tag -width Er +.It Bq Er EBADF +The given +.Fa stream +is not a readable stream. +.El +.Pp +The function +.Fn fgets +may also fail and set +.Va errno +for any of the errors specified for the routines +.Xr fflush 3 , +.Xr fstat 2 , +.Xr read 2 , +or +.Xr malloc 3 . +.Pp +The function +.Fn gets +may also fail and set +.Va errno +for any of the errors specified for the routine +.Xr getchar 3 . +.Sh SEE ALSO +.Xr feof 3 , +.Xr ferror 3 , +.Xr fgetln 3 +.Sh STANDARDS +The functions +.Fn fgets +and +.Fn gets +conform to +.St -isoC . +.Sh BUGS +Since it is usually impossible to ensure that the next input line +is less than some arbitrary length, and because overflowing the +input buffer is almost invariably a security violation, programs +should +.Em NEVER +use +.Fn gets . +The +.Fn gets +function +exists purely to conform to +.St -isoC . diff --git a/stdio/fgets.c b/stdio/fgets.c new file mode 100644 index 0000000..554f485 --- /dev/null +++ b/stdio/fgets.c @@ -0,0 +1,122 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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 +#include + +/* + * Read at most n-1 characters from the given file. + * Stop when a newline has been read, or the count runs out. + * Return first argument, or NULL if no characters were read. + */ +char * +fgets(buf, n, fp) + char *buf; + register int n; + register FILE *fp; +{ + register size_t len; + register char *s; + register unsigned char *p, *t; + + if (n == 0) /* sanity check */ + return (NULL); + + s = buf; + n--; /* leave space for NUL */ + while (n != 0) { + /* + * If the buffer is empty, refill it. + */ + if ((len = fp->_r) <= 0) { + if (__srefill(fp)) { + /* EOF/error: stop with partial or no line */ + if (s == buf) + return (NULL); + break; + } + len = fp->_r; + } + p = fp->_p; + + /* + * Scan through at most n bytes of the current buffer, + * looking for '\n'. If found, copy up to and including + * newline, and stop. Otherwise, copy entire chunk + * and loop. + */ + if (len > n) + len = n; + t = memchr((void *)p, '\n', len); + if (t != NULL) { + len = ++t - p; + fp->_r -= len; + fp->_p = t; + (void)memcpy((void *)s, (void *)p, len); + s[len] = 0; + return (buf); + } + fp->_r -= len; + fp->_p += len; + (void)memcpy((void *)s, (void *)p, len); + s += len; + n -= len; + } + *s = 0; + return (buf); +} diff --git a/stdio/fileno.c b/stdio/fileno.c new file mode 100644 index 0000000..b5d106a --- /dev/null +++ b/stdio/fileno.c @@ -0,0 +1,71 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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 + +/* + * A subroutine version of the macro fileno. + */ +#undef fileno + +int +fileno(fp) + FILE *fp; +{ + return (__sfileno(fp)); +} diff --git a/stdio/findfp.c b/stdio/findfp.c new file mode 100644 index 0000000..405a911 --- /dev/null +++ b/stdio/findfp.c @@ -0,0 +1,184 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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 +#include +#include +#include +#include +#include +#include "local.h" +#include "glue.h" + +int __sdidinit = 0; + +#define NDYNAMIC 10 /* add ten more whenever necessary */ + +#define std(flags, file) \ + {0,0,0,flags,file,{0},0,__sF+file,__sclose,__sread,__sseek,__swrite} +/* p r w flags file _bf z cookie close read seek write */ + + /* the usual - (stdin + stdout + stderr) */ +static FILE usual[FOPEN_MAX - 3]; +static struct glue uglue = { 0, FOPEN_MAX - 3, usual }; + +FILE __sF[3] = { + std(__SRD, STDIN_FILENO), /* stdin */ + std(__SWR, STDOUT_FILENO), /* stdout */ + std(__SWR|__SNBF, STDERR_FILENO) /* stderr */ +}; +struct glue __sglue = { &uglue, 3, __sF }; + +static struct glue * +moreglue(n) + register int n; +{ + register struct glue *g; + register FILE *p; + static FILE empty; + + g = (struct glue *)malloc(sizeof(*g) + ALIGNBYTES + n * sizeof(FILE)); + if (g == NULL) + return (NULL); + p = (FILE *)ALIGN(g + 1); + g->next = NULL; + g->niobs = n; + g->iobs = p; + while (--n >= 0) + *p++ = empty; + return (g); +} + +/* + * Find a free FILE for fopen et al. + */ +FILE * +__sfp() +{ + register FILE *fp; + register int n; + register struct glue *g; + + if (!__sdidinit) + __sinit(); + for (g = &__sglue;; g = g->next) { + for (fp = g->iobs, n = g->niobs; --n >= 0; fp++) + if (fp->_flags == 0) + goto found; + if (g->next == NULL && (g->next = moreglue(NDYNAMIC)) == NULL) + break; + } + return (NULL); +found: + fp->_flags = 1; /* reserve this slot; caller sets real flags */ + fp->_p = NULL; /* no current pointer */ + fp->_w = 0; /* nothing to read or write */ + fp->_r = 0; + fp->_bf._base = NULL; /* no buffer */ + fp->_bf._size = 0; + fp->_lbfsize = 0; /* not line buffered */ + fp->_file = -1; /* no file */ +/* fp->_cookie = ; */ /* caller sets cookie, _read/_write etc */ + fp->_ub._base = NULL; /* no ungetc buffer */ + fp->_ub._size = 0; + fp->_lb._base = NULL; /* no line buffer */ + fp->_lb._size = 0; + return (fp); +} + +/* + * XXX. Force immediate allocation of internal memory. Not used by stdio, + * but documented historically for certain applications. Bad applications. + */ +void +f_prealloc() +{ + register struct glue *g; + int n; + + n = getdtablesize() - FOPEN_MAX + 20; /* 20 for slop. */ + for (g = &__sglue; (n -= g->niobs) > 0 && g->next; g = g->next) + /* void */; + if (n > 0) + g->next = moreglue(n); +} + +/* + * exit() calls _cleanup() through *__cleanup, set whenever we + * open or buffer a file. This chicanery is done so that programs + * that do not use stdio need not link it all in. + * + * The name `_cleanup' is, alas, fairly well known outside stdio. + */ +void +_cleanup() +{ + /* (void) _fwalk(fclose); */ + (void) _fwalk(__sflush); /* `cheating' */ +} + +/* + * __sinit() is called whenever stdio's internal variables must be set up. + */ +void +__sinit() +{ + /* make sure we clean up on exit */ + __cleanup = _cleanup; /* conservative */ + __sdidinit = 1; +} diff --git a/stdio/flags.c b/stdio/flags.c new file mode 100644 index 0000000..22cc1e9 --- /dev/null +++ b/stdio/flags.c @@ -0,0 +1,108 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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 +#include +#include +#include + +/* + * Return the (stdio) flags for a given mode. Store the flags + * to be passed to an open() syscall through *optr. + * Return 0 on error. + */ +int +__sflags(mode, optr) + register char *mode; + int *optr; +{ + register int ret, m, o; + + switch (*mode++) { + + case 'r': /* open for reading */ + ret = __SRD; + m = O_RDONLY; + o = 0; + break; + + case 'w': /* open for writing */ + ret = __SWR; + m = O_WRONLY; + o = O_CREAT | O_TRUNC; + break; + + case 'a': /* open for appending */ + ret = __SWR; + m = O_WRONLY; + o = O_CREAT | O_APPEND; + break; + + default: /* illegal mode */ + errno = EINVAL; + return (0); + } + + /* [rwa]\+ or [rwa]b\+ means read and write */ + if (*mode == '+' || (*mode == 'b' && mode[1] == '+')) { + ret = __SRW; + m = O_RDWR; + } + *optr = m | o; + return (ret); +} diff --git a/stdio/floatio.h b/stdio/floatio.h new file mode 100644 index 0000000..06be4a7 --- /dev/null +++ b/stdio/floatio.h @@ -0,0 +1,65 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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. + */ + +/* + * Floating point scanf/printf (input/output) definitions. + */ + +/* 11-bit exponent (VAX G floating point) is 308 decimal digits */ +#define MAXEXP 308 +/* 128 bit fraction takes up 39 decimal digits; max reasonable precision */ +#define MAXFRACT 39 diff --git a/stdio/fopen.3 b/stdio/fopen.3 new file mode 100644 index 0000000..cbf6234 --- /dev/null +++ b/stdio/fopen.3 @@ -0,0 +1,252 @@ +.\" 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. +.\" +.\" @(#)fopen.3 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD: src/lib/libc/stdio/fopen.3,v 1.12 2001/10/01 16:08:59 ru Exp $ +.\" +.Dd June 4, 1993 +.Dt FOPEN 3 +.Os +.Sh NAME +.Nm fopen , +.Nm fdopen , +.Nm freopen +.Nd stream open functions +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In stdio.h +.Ft FILE * +.Fn fopen "const char *path" "const char *mode" +.Ft FILE * +.Fn fdopen "int fildes" "const char *mode" +.Ft FILE * +.Fn freopen "const char *path" "const char *mode" "FILE *stream" +.Sh DESCRIPTION +The +.Fn fopen +function +opens the file whose name is the string pointed to by +.Fa path +and associates a stream with it. +.Pp +The argument +.Fa mode +points to a string beginning with one of the following +sequences (Additional characters may follow these sequences.): +.Bl -tag -width indent +.It Dq Li r +Open text file for reading. +The stream is positioned at the beginning of the file. +.It Dq Li r+ +Open for reading and writing. +The stream is positioned at the beginning of the file. +.It Dq Li w +Truncate file to zero length or create text file for writing. +The stream is positioned at the beginning of the file. +.It Dq Li w+ +Open for reading and writing. +The file is created if it does not exist, otherwise it is truncated. +The stream is positioned at the beginning of the file. +.It Dq Li a +Open for writing. +The file is created if it does not exist. +The stream is positioned at the end of the file. +Subsequent writes to the file will always end up at the then current +end of file, irrespective of any intervening +.Xr fseek 3 +or similar. +.It Dq Li a+ +Open for reading and writing. +The file is created if it does not exist. +The stream is positioned at the end of the file. +Subsequent writes to the file will always end up at the then current +end of file, irrespective of any intervening +.Xr fseek 3 +or similar. +.El +.Pp +The +.Fa mode +string can also include the letter ``b'' either as a third character or +as a character between the characters in any of the two-character strings +described above. +This is strictly for compatibility with +.St -isoC +and has no effect; the ``b'' is ignored. +.Pp +Any created files will have mode +.Pf \\*q Dv S_IRUSR +\&| +.Dv S_IWUSR +\&| +.Dv S_IRGRP +\&| +.Dv S_IWGRP +\&| +.Dv S_IROTH +\&| +.Dv S_IWOTH Ns \\*q +.Pq Li 0666 , +as modified by the process' +umask value (see +.Xr umask 2 ) . +.Pp +Reads and writes may be intermixed on read/write streams in any order, +and do not require an intermediate seek as in previous versions of +.Em stdio . +This is not portable to other systems, however; +.Tn ANSI C +requires that +a file positioning function intervene between output and input, unless +an input operation encounters end-of-file. +.Pp +The +.Fn fdopen +function associates a stream with the existing file descriptor, +.Fa fildes . +The +.Fa mode +of the stream must be compatible with the mode of the file descriptor. +When the stream is closed via +.Xr fclose 3 , +.Fa fildes +is closed also. +.Pp +The +.Fn freopen +function +opens the file whose name is the string pointed to by +.Fa path +and associates the stream pointed to by +.Fa stream +with it. +The original stream (if it exists) is closed. +The +.Fa mode +argument is used just as in the +.Fn fopen +function. +The primary use of the +.Fn freopen +function +is to change the file associated with a +standard text stream +.Pf ( Em stderr , +.Em stdin , +or +.Em stdout ) . +.Sh RETURN VALUES +Upon successful completion +.Fn fopen , +.Fn fdopen +and +.Fn freopen +return a +.Tn FILE +pointer. +Otherwise, +.Dv NULL +is returned and the global variable +.Va errno +is set to indicate the error. +.Sh ERRORS +.Bl -tag -width Er +.It Bq Er EINVAL +The +.Fa mode +provided to +.Fn fopen , +.Fn fdopen , +or +.Fn freopen +was invalid. +.El +.Pp +The +.Fn fopen , +.Fn fdopen +and +.Fn freopen +functions +may also fail and set +.Va errno +for any of the errors specified for the routine +.Xr malloc 3 . +.Pp +The +.Fn fopen +function +may also fail and set +.Va errno +for any of the errors specified for the routine +.Xr open 2 . +.Pp +The +.Fn fdopen +function +may also fail and set +.Va errno +for any of the errors specified for the routine +.Xr fcntl 2 . +.Pp +The +.Fn freopen +function +may also fail and set +.Va errno +for any of the errors specified for the routines +.Xr open 2 , +.Xr fclose 3 +and +.Xr fflush 3 . +.Sh SEE ALSO +.Xr open 2 , +.Xr fclose 3 , +.Xr fseek 3 , +.Xr funopen 3 +.Sh STANDARDS +The +.Fn fopen +and +.Fn freopen +functions +conform to +.St -isoC . +The +.Fn fdopen +function +conforms to +.St -p1003.1-88 . diff --git a/stdio/fopen.c b/stdio/fopen.c new file mode 100644 index 0000000..4f10f39 --- /dev/null +++ b/stdio/fopen.c @@ -0,0 +1,102 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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 +#include +#include +#include +#include +#include "local.h" + +FILE * +fopen(file, mode) + const char *file; + const char *mode; +{ + register FILE *fp; + register int f; + int flags, oflags; + + if ((flags = __sflags(mode, &oflags)) == 0) + return (NULL); + if ((fp = __sfp()) == NULL) + return (NULL); + if ((f = open(file, oflags, DEFFILEMODE)) < 0) { + fp->_flags = 0; /* release */ + return (NULL); + } + fp->_file = f; + fp->_flags = flags; + fp->_cookie = fp; + fp->_read = __sread; + fp->_write = __swrite; + fp->_seek = __sseek; + fp->_close = __sclose; + + /* + * When opening in append mode, even though we use O_APPEND, + * we need to seek to the end so that ftell() gets the right + * answer. If the user then alters the seek pointer, or + * the file extends, this will fail, but there is not much + * we can do about this. (We could set __SAPP and check in + * fseek and ftell.) + */ + if (oflags & O_APPEND) + (void) __sseek((void *)fp, (fpos_t)0, SEEK_END); + return (fp); +} diff --git a/stdio/fprintf.c b/stdio/fprintf.c new file mode 100644 index 0000000..761156d --- /dev/null +++ b/stdio/fprintf.c @@ -0,0 +1,87 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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 +#if __STDC__ +#include +#else +#include +#endif + +int +#if __STDC__ +fprintf(FILE *fp, const char *fmt, ...) +#else +fprintf(fp, fmt, va_alist) + FILE *fp; + char *fmt; + va_dcl +#endif +{ + int ret; + va_list ap; + +#if __STDC__ + va_start(ap, fmt); +#else + va_start(ap); +#endif + ret = vfprintf(fp, fmt, ap); + va_end(ap); + return (ret); +} diff --git a/stdio/fpurge.c b/stdio/fpurge.c new file mode 100644 index 0000000..65c0fad --- /dev/null +++ b/stdio/fpurge.c @@ -0,0 +1,83 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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 +#include +#include +#include "local.h" + +/* + * fpurge: like fflush, but without writing anything: leave the + * given FILE's buffer empty. + */ +int +fpurge(fp) + register FILE *fp; +{ + if (!fp->_flags) { + errno = EBADF; + return(EOF); + } + + if (HASUB(fp)) + FREEUB(fp); + fp->_p = fp->_bf._base; + fp->_r = 0; + fp->_w = fp->_flags & (__SLBF|__SNBF) ? 0 : fp->_bf._size; + return (0); +} diff --git a/stdio/fputc.c b/stdio/fputc.c new file mode 100644 index 0000000..2e31e22 --- /dev/null +++ b/stdio/fputc.c @@ -0,0 +1,67 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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 + +int +fputc(c, fp) + int c; + register FILE *fp; +{ + return (putc(c, fp)); +} diff --git a/stdio/fputs.3 b/stdio/fputs.3 new file mode 100644 index 0000000..4702017 --- /dev/null +++ b/stdio/fputs.3 @@ -0,0 +1,110 @@ +.\" 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. +.\" +.\" @(#)fputs.3 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD: src/lib/libc/stdio/fputs.3,v 1.8 2001/10/01 16:08:59 ru Exp $ +.\" +.Dd June 4, 1993 +.Dt FPUTS 3 +.Os +.Sh NAME +.Nm fputs , +.Nm puts +.Nd output a line to a stream +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In stdio.h +.Ft int +.Fn fputs "const char *str" "FILE *stream" +.Ft int +.Fn puts "const char *str" +.Sh DESCRIPTION +The function +.Fn fputs +writes the string pointed to by +.Fa str +to the stream pointed to by +.Fa stream . +.\" The terminating +.\" .Dv NUL +.\" character is not written. +.Pp +The function +.Fn puts +writes the string +.Fa str , +and a terminating newline character, +to the stream +.Em stdout . +.Sh RETURN VALUES +The +.Fn fputs +function +returns 0 on success and +.Dv EOF +on error; +.Fn puts +returns a nonnegative integer on success and +.Dv EOF +on error. +.Sh ERRORS +.Bl -tag -width Er +.It Bq Er EBADF +The +.Fa stream +supplied +is not a writable stream. +.El +.Pp +The functions +.Fn fputs +and +.Fn puts +may also fail and set +.Va errno +for any of the errors specified for the routines +.Xr write 2 . +.Sh SEE ALSO +.Xr ferror 3 , +.Xr putc 3 , +.Xr stdio 3 +.Sh STANDARDS +The functions +.Fn fputs +and +.Fn puts +conform to +.St -isoC . diff --git a/stdio/fputs.c b/stdio/fputs.c new file mode 100644 index 0000000..855db46 --- /dev/null +++ b/stdio/fputs.c @@ -0,0 +1,79 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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 +#include +#include "fvwrite.h" + +/* + * Write the given string to the given file. + */ +int +fputs(s, fp) + const char *s; + FILE *fp; +{ + struct __suio uio; + struct __siov iov; + + iov.iov_base = (void *)s; + iov.iov_len = uio.uio_resid = strlen(s); + uio.uio_iov = &iov; + uio.uio_iovcnt = 1; + return (__sfvwrite(fp, &uio)); +} diff --git a/stdio/fread.3 b/stdio/fread.3 new file mode 100644 index 0000000..16cebfc --- /dev/null +++ b/stdio/fread.3 @@ -0,0 +1,109 @@ +.\" 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. +.\" +.\" @(#)fread.3 8.2 (Berkeley) 3/8/94 +.\" $FreeBSD: src/lib/libc/stdio/fread.3,v 1.8 2001/10/01 16:08:59 ru Exp $ +.\" +.Dd March 8, 1994 +.Dt FREAD 3 +.Os +.Sh NAME +.Nm fread , +.Nm fwrite +.Nd binary stream input/output +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In stdio.h +.Ft size_t +.Fn fread "void *ptr" "size_t size" "size_t nmemb" "FILE *stream" +.Ft size_t +.Fn fwrite "const void *ptr" "size_t size" "size_t nmemb" "FILE *stream" +.Sh DESCRIPTION +The function +.Fn fread +reads +.Fa nmemb +objects, each +.Fa size +bytes long, from the stream pointed to by +.Fa stream , +storing them at the location given by +.Fa ptr . +.Pp +The function +.Fn fwrite +writes +.Fa nmemb +objects, each +.Fa size +bytes long, to the stream pointed to by +.Fa stream , +obtaining them from the location given by +.Fa ptr . +.Sh RETURN VALUES +The functions +.Fn fread +and +.Fn fwrite +advance the file position indicator for the stream +by the number of bytes read or written. +They return the number of objects read or written. +If an error occurs, or the end-of-file is reached, +the return value is a short object count (or zero). +.Pp +The function +.Fn fread +does not distinguish between end-of-file and error, and callers +must use +.Xr feof 3 +and +.Xr ferror 3 +to determine which occurred. +The function +.Fn fwrite +returns a value less than +.Fa nmemb +only if a write error has occurred. +.Sh SEE ALSO +.Xr read 2 , +.Xr write 2 +.Sh STANDARDS +The functions +.Fn fread +and +.Fn fwrite +conform to +.St -isoC . diff --git a/stdio/fread.c b/stdio/fread.c new file mode 100644 index 0000000..5d622ea --- /dev/null +++ b/stdio/fread.c @@ -0,0 +1,99 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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 +#include + +size_t +fread(buf, size, count, fp) + void *buf; + size_t size, count; + register FILE *fp; +{ + register size_t resid; + register char *p; + register int r; + size_t total; + + /* + * The ANSI standard requires a return value of 0 for a count + * or a size of 0. Peculiarily, it imposes no such requirements + * on fwrite; it only requires fread to be broken. + */ + if ((resid = count * size) == 0) + return (0); + if (fp->_r < 0) + fp->_r = 0; + total = resid; + p = buf; + while (resid > (r = fp->_r)) { + (void)memcpy((void *)p, (void *)fp->_p, (size_t)r); + fp->_p += r; + /* fp->_r = 0 ... done in __srefill */ + p += r; + resid -= r; + if (__srefill(fp)) { + /* no more input: return partial result */ + return ((total - resid) / size); + } + } + (void)memcpy((void *)p, (void *)fp->_p, resid); + fp->_r -= resid; + fp->_p += resid; + return (count); +} diff --git a/stdio/freopen.c b/stdio/freopen.c new file mode 100644 index 0000000..9e38851 --- /dev/null +++ b/stdio/freopen.c @@ -0,0 +1,173 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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 +#include +#include +#include +#include +#include +#include +#include "local.h" + +/* + * Re-direct an existing, open (probably) file to some other file. + * ANSI is written such that the original file gets closed if at + * all possible, no matter what. + */ +FILE * +freopen(file, mode, fp) + const char *file, *mode; + register FILE *fp; +{ + register int f; + int flags, isopen, oflags, sverrno, wantfd; + + if ((flags = __sflags(mode, &oflags)) == 0) { + (void) fclose(fp); + return (NULL); + } + + if (!__sdidinit) + __sinit(); + + /* + * There are actually programs that depend on being able to "freopen" + * descriptors that weren't originally open. Keep this from breaking. + * Remember whether the stream was open to begin with, and which file + * 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. + */ + if (fp->_flags == 0) { + fp->_flags = __SEOF; /* hold on to it */ + isopen = 0; + wantfd = -1; + } else { + /* flush the stream; ANSI doesn't require this. */ + if (fp->_flags & __SWR) + (void) __sflush(fp); + /* if close is NULL, closing is a no-op, hence pointless */ + isopen = fp->_close != NULL; + if ((wantfd = fp->_file) < 0 && isopen) { + (void) (*fp->_close)(fp->_cookie); + isopen = 0; + } + } + + /* Get a new descriptor to refer to the new file. */ + f = open(file, oflags, DEFFILEMODE); + if (f < 0 && isopen) { + /* If out of fd's close the old one and try again. */ + if (errno == ENFILE || errno == EMFILE) { + (void) (*fp->_close)(fp->_cookie); + isopen = 0; + f = open(file, oflags, DEFFILEMODE); + } + } + sverrno = errno; + + /* + * Finish closing fp. Even if the open succeeded above, we cannot + * keep fp->_base: it may be the wrong size. This loses the effect + * of any setbuffer calls, but stdio has always done this before. + */ + if (isopen) + (void) (*fp->_close)(fp->_cookie); + if (fp->_flags & __SMBF) + free((char *)fp->_bf._base); + fp->_w = 0; + fp->_r = 0; + fp->_p = NULL; + fp->_bf._base = NULL; + fp->_bf._size = 0; + fp->_lbfsize = 0; + if (HASUB(fp)) + FREEUB(fp); + fp->_ub._size = 0; + if (HASLB(fp)) + FREELB(fp); + fp->_lb._size = 0; + + if (f < 0) { /* did not get it after all */ + fp->_flags = 0; /* set it free */ + errno = sverrno; /* restore in case _close clobbered */ + return (NULL); + } + + /* + * If reopening something that was open before on a real file, try + * to maintain the descriptor. Various C library routines (perror) + * assume stderr is always fd STDERR_FILENO, even if being freopen'd. + */ + if (wantfd >= 0 && f != wantfd) { + if (dup2(f, wantfd) >= 0) { + (void) close(f); + f = wantfd; + } + } + + fp->_flags = flags; + fp->_file = f; + fp->_cookie = fp; + fp->_read = __sread; + fp->_write = __swrite; + fp->_seek = __sseek; + fp->_close = __sclose; + return (fp); +} diff --git a/stdio/fscanf.c b/stdio/fscanf.c new file mode 100644 index 0000000..27a3028 --- /dev/null +++ b/stdio/fscanf.c @@ -0,0 +1,87 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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 +#if __STDC__ +#include +#else +#include +#endif + +int +#if __STDC__ +fscanf(FILE *fp, char const *fmt, ...) { + int ret; + va_list ap; + + va_start(ap, fmt); +#else +fscanf(fp, fmt, va_alist) + FILE *fp; + char *fmt; + va_dcl +{ + int ret; + va_list ap; + + va_start(ap); +#endif + ret = __svfscanf(fp, fmt, ap); + va_end(ap); + return (ret); +} diff --git a/stdio/fseek.3 b/stdio/fseek.3 new file mode 100644 index 0000000..7343c96 --- /dev/null +++ b/stdio/fseek.3 @@ -0,0 +1,252 @@ +.\" 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. +.\" +.\" @(#)fseek.3 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD: src/lib/libc/stdio/fseek.3,v 1.19 2001/10/01 16:08:59 ru Exp $ +.\" +.Dd March 5, 1999 +.Dt FSEEK 3 +.Os +.Sh NAME +.Nm fgetpos , +.Nm fseek , +.Nm fseeko , +.Nm fsetpos , +.Nm ftell , +.Nm ftello , +.Nm rewind +.Nd reposition a stream +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In stdio.h +.Ft int +.Fn fseek "FILE *stream" "long offset" "int whence" +.Ft long +.Fn ftell "FILE *stream" +.Ft void +.Fn rewind "FILE *stream" +.Ft int +.Fn fgetpos "FILE *stream" "fpos_t *pos" +.Ft int +.Fn fsetpos "FILE *stream" "const fpos_t *pos" +.In sys/types.h +.Ft int +.Fn fseeko "FILE *stream" "off_t offset" "int whence" +.Ft off_t +.Fn ftello "FILE *stream" +.Sh DESCRIPTION +The +.Fn fseek +function sets the file position indicator for the stream pointed +to by +.Fa stream . +The new position, measured in bytes, is obtained by adding +.Fa offset +bytes to the position specified by +.Fa whence . +If +.Fa whence +is set to +.Dv SEEK_SET , +.Dv SEEK_CUR , +or +.Dv SEEK_END , +the offset is relative to the +start of the file, the current position indicator, or end-of-file, +respectively. +A successful call to the +.Fn fseek +function clears the end-of-file indicator for the stream and undoes +any effects of the +.Xr ungetc 3 +function on the same stream. +.Pp +The +.Fn ftell +function +obtains the current value of the file position indicator for the +stream pointed to by +.Fa stream . +.Pp +The +.Fn rewind +function sets the file position indicator for the stream pointed +to by +.Fa stream +to the beginning of the file. +It is equivalent to: +.Pp +.Dl (void)fseek(stream, 0L, SEEK_SET) +.Pp +except that the error indicator for the stream is also cleared +(see +.Xr clearerr 3 ) . +.Pp +Since +.Fn rewind +does not return a value, +an application wishing to detect errors should clear +.Va errno , +then call +.Fn rewind , +and if +.Va errno +is non-zero, assume an error has occurred. +.Pp +The +.Fn fseeko +function is identical to +.Fn fseek , +except it takes an +.Fa off_t +argument +instead of a +.Fa long . +Likewise, the +.Fn ftello +function is identical to +.Fn ftell , +except it returns an +.Fa off_t . +.Pp +The +.Fn fgetpos +and +.Fn fsetpos +functions +are alternate interfaces equivalent 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 +.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. +.Sh RETURN VALUES +The +.Fn rewind +function +returns no value. +.Pp +.Rv -std fgetpos fseek fseeko fsetpos +.Pp +Upon successful completion, +.Fn ftell +and +.Fn ftello +return the current offset. +Otherwise, \-1 is returned and the global variable +.Va errno +is set to indicate the error. +.Sh ERRORS +.Bl -tag -width Er +.It Bq Er EBADF +The +.Fa stream +specified +is not a seekable stream. +.It Bq Er EINVAL +The +.Fa whence +argument is invalid or +the resulting file-position +indicator would be set to a negative value. +.It Bq Er EOVERFLOW +The resulting file offset would be a value which +cannot be represented correctly in an object of type +.Fa off_t +for +.Fn fseeko +and +.Fn ftello +or +.Fa long +for +.Fn fseek +and +.Fn ftell . +.It Bq Er ESPIPE +The file descriptor underlying stream is associated with a pipe or FIFO +or file-position indicator value is unspecified +(see +.Xr ungetc 3 ) . +.El +.Pp +The functions +.Fn fgetpos , +.Fn fseek , +.Fn fseeko , +.Fn fsetpos , +.Fn ftell , +and +.Fn ftello +may also fail and set +.Va errno +for any of the errors specified for the routines +.Xr fflush 3 , +.Xr fstat 2 , +.Xr lseek 2 , +and +.Xr malloc 3 . +.Sh SEE ALSO +.Xr lseek 2 , +.Xr clearerr 3 , +.Xr ungetc 3 +.Sh STANDARDS +The +.Fn fgetpos , +.Fn fsetpos , +.Fn fseek , +.Fn ftell , +and +.Fn rewind +functions +conform to +.St -isoC . +.Pp +The +.Fn fseeko +and +.Fn ftello +functions conform to +.St -susv2 . diff --git a/stdio/fseek.c b/stdio/fseek.c new file mode 100644 index 0000000..802e3cc --- /dev/null +++ b/stdio/fseek.c @@ -0,0 +1,284 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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 +#include +#include +#include +#include +#include +#include +#include "local.h" + +#define POS_ERR (-(fpos_t)1) + +int +fseek(fp, offset, whence) + register FILE *fp; + long offset; + int whence; +{ + return (fseeko(fp, offset, whence)); +} + + +/* + * Seek the given file to the given offset. + * `Whence' must be one of the three SEEK_* macros. + */ +int +fseeko(fp, offset, whence) + register FILE *fp; + off_t offset; + int whence; +{ + register fpos_t (*seekfn) __P((void *, fpos_t, int)); + fpos_t target, curoff; + size_t n; + struct stat st; + int havepos; + + /* make sure stdio is set up */ + if (!__sdidinit) + __sinit(); + + /* FLOCKFILE(fp); */ + /* + * Have to be able to seek. + */ + if ((seekfn = fp->_seek) == NULL) { + errno = ESPIPE; /* historic practice */ + /* FUNLOCKFILE(fp); */ + return (EOF); + } + + /* + * Change any SEEK_CUR to SEEK_SET, and check `whence' argument. + * After this, whence is either SEEK_SET or SEEK_END. + */ + switch (whence) { + + case SEEK_CUR: + /* + * In order to seek relative to the current stream offset, + * we have to first find the current stream offset a la + * ftell (see ftell for details). + */ + if (fp->_flags & __SOFF) + curoff = fp->_offset; + else { + curoff = (*seekfn)(fp->_cookie, (fpos_t)0, SEEK_CUR); + if (curoff == -1) { + /* FUNLOCKFILE(fp); */ + return (EOF); + } + } + if (fp->_flags & __SRD) { + curoff -= fp->_r; + if (HASUB(fp)) + curoff -= fp->_ur; + } else if (fp->_flags & __SWR && fp->_p != NULL) + curoff += fp->_p - fp->_bf._base; + + offset += curoff; + whence = SEEK_SET; + havepos = 1; + break; + + case SEEK_SET: + case SEEK_END: + curoff = 0; /* XXX just to keep gcc quiet */ + havepos = 0; + break; + + default: + errno = EINVAL; + /* FUNLOCKFILE(fp); */ + return (EOF); + } + + /* + * Can only optimise if: + * reading (and not reading-and-writing); + * not unbuffered; and + * this is a `regular' Unix file (and hence seekfn==__sseek). + * We must check __NBF first, because it is possible to have __NBF + * and __SOPT both set. + */ + if (fp->_bf._base == NULL) + __smakebuf(fp); + if (fp->_flags & (__SWR | __SRW | __SNBF | __SNPT)) + goto dumb; + if ((fp->_flags & __SOPT) == 0) { + if (seekfn != __sseek || + fp->_file < 0 || fstat(fp->_file, &st) || + (st.st_mode & S_IFMT) != S_IFREG) { + fp->_flags |= __SNPT; + goto dumb; + } + fp->_blksize = st.st_blksize; + fp->_flags |= __SOPT; + } + + /* + * We are reading; we can try to optimise. + * Figure out where we are going and where we are now. + */ + if (whence == SEEK_SET) + target = offset; + else { + if (fstat(fp->_file, &st)) + goto dumb; + target = st.st_size + offset; + } + + if (!havepos) { + if (fp->_flags & __SOFF) + curoff = fp->_offset; + else { + curoff = (*seekfn)(fp->_cookie, (fpos_t)0, SEEK_CUR); + if (curoff == POS_ERR) + goto dumb; + } + curoff -= fp->_r; + if (HASUB(fp)) + curoff -= fp->_ur; + } + + /* + * Compute the number of bytes in the input buffer (pretending + * that any ungetc() input has been discarded). Adjust current + * offset backwards by this count so that it represents the + * file offset for the first byte in the current input buffer. + */ + if (HASUB(fp)) { + curoff += fp->_r; /* kill off ungetc */ + n = fp->_up - fp->_bf._base; + curoff -= n; + n += fp->_ur; + } else { + n = fp->_p - fp->_bf._base; + curoff -= n; + n += fp->_r; + } + + /* + * If the target offset is within the current buffer, + * simply adjust the pointers, clear EOF, undo ungetc(), + * and return. (If the buffer was modified, we have to + * skip this; see fgetln.c.) + */ + if ((fp->_flags & __SMOD) == 0 && + target >= curoff && target < curoff + n) { + register int o = target - curoff; + + fp->_p = fp->_bf._base + o; + fp->_r = n - o; + if (HASUB(fp)) + FREEUB(fp); + fp->_flags &= ~__SEOF; + /* FUNLOCKFILE(fp); */ + return (0); + } + + /* + * The place we want to get to is not within the current buffer, + * but we can still be kind to the kernel copyout mechanism. + * By aligning the file offset to a block boundary, we can let + * the kernel use the VM hardware to map pages instead of + * copying bytes laboriously. Using a block boundary also + * ensures that we only read one block, rather than two. + */ + curoff = target & ~(fp->_blksize - 1); + if ((*seekfn)(fp->_cookie, curoff, SEEK_SET) == POS_ERR) + goto dumb; + fp->_r = 0; + fp->_p = fp->_bf._base; + if (HASUB(fp)) + FREEUB(fp); + fp->_flags &= ~__SEOF; + n = target - curoff; + if (n) { + if (__srefill(fp) || fp->_r < n) + goto dumb; + fp->_p += n; + fp->_r -= n; + } + /* FUNLOCKFILE(fp); */ + return (0); + + /* + * We get here if we cannot optimise the seek ... just + * do it. Allow the seek function to change fp->_bf._base. + */ +dumb: + if (__sflush(fp) || + (*seekfn)(fp->_cookie, (fpos_t)offset, whence) == POS_ERR) { + /* FUNLOCKFILE(fp); */ + return (EOF); + } + /* success: clear EOF indicator and discard ungetc() data */ + if (HASUB(fp)) + FREEUB(fp); + fp->_p = fp->_bf._base; + fp->_r = 0; + /* fp->_w = 0; */ /* unnecessary (I think...) */ + fp->_flags &= ~__SEOF; + /* FUNLOCKFILE(fp); */ + return (0); +} diff --git a/stdio/fsetpos.c b/stdio/fsetpos.c new file mode 100644 index 0000000..7397bb9 --- /dev/null +++ b/stdio/fsetpos.c @@ -0,0 +1,70 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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 +#include + +/* + * fsetpos: like fseek. + */ +int +fsetpos(iop, pos) + FILE *iop; + const fpos_t *pos; +{ + return (fseeko(iop, (off_t)*pos, SEEK_SET)); +} diff --git a/stdio/ftell.c b/stdio/ftell.c new file mode 100644 index 0000000..b899c66 --- /dev/null +++ b/stdio/ftell.c @@ -0,0 +1,127 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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 +#include +#include +#include "local.h" + +/* + * ftello: return current offset. + */ +off_t +ftello(fp) + register FILE *fp; +{ + register fpos_t pos; + + if (fp->_seek == NULL) { + errno = ESPIPE; /* historic practice */ + return (-1L); + } + + /* FLOCKFILE(fp); */ + /* + * Find offset of underlying I/O object, then + * adjust for buffered bytes. + */ + if (fp->_flags & __SOFF) + pos = fp->_offset; + else { + pos = (*fp->_seek)(fp->_cookie, (fpos_t)0, SEEK_CUR); + if (pos == -1) { + /* FUNLOCKFILE(fp); */ + return (pos); + } + } + if (fp->_flags & __SRD) { + /* + * Reading. Any unread characters (including + * those from ungetc) cause the position to be + * smaller than that in the underlying object. + */ + pos -= fp->_r; + if (HASUB(fp)) + pos -= fp->_ur; + } else if (fp->_flags & __SWR && fp->_p != NULL) { + /* + * Writing. Any buffered characters cause the + * position to be greater than that in the + * underlying object. + */ + pos += fp->_p - fp->_bf._base; + } + /* FUNLOCKFILE(fp); */ + return (pos); +} + +/* + * standard ftell function. + */ +long +ftell(fp) + register FILE *fp; +{ + register off_t rv; + rv = ftello(fp); + if ((long)rv != rv) { + errno = EOVERFLOW; + return (-1); + } + return (rv); +} diff --git a/stdio/funopen.3 b/stdio/funopen.3 new file mode 100644 index 0000000..ad5603e --- /dev/null +++ b/stdio/funopen.3 @@ -0,0 +1,172 @@ +.\" 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. +.\" 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. +.\" +.\" @(#)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 $ +.\" +.Dd June 9, 1993 +.Dt FUNOPEN 3 +.Os +.Sh NAME +.Nm funopen , +.Nm fropen , +.Nm fwopen +.Nd open a stream +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In stdio.h +.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)" +.Ft FILE * +.Fn fwopen "void *cookie" "int (*writefn)(void *, const char *, int)" +.Sh DESCRIPTION +The +.Fn funopen +function +associates a stream with up to four +.Dq Tn I/O No functions . +Either +.Fa readfn +or +.Fa writefn +must be specified; +the others can be given as an appropriately-typed +.Dv NULL +pointer. +These +.Tn I/O +functions will be used to read, write, seek and +close the new stream. +.Pp +In general, omitting a function means that any attempt to perform the +associated operation on the resulting stream will fail. +If the close function is omitted, closing the stream will flush +any buffered output and then succeed. +.Pp +The calling conventions of +.Fa readfn , +.Fa writefn , +.Fa seekfn +and +.Fa closefn +must match those, respectively, of +.Xr read 2 , +.Xr write 2 , +.Xr lseek 2 , +and +.Xr close 2 +with the single exception that they are passed the +.Fa cookie +argument specified to +.Fn funopen +in place of the traditional file descriptor argument. +.Pp +Read and write +.Tn I/O +functions are allowed to change the underlying buffer +on fully buffered or line buffered streams by calling +.Xr setvbuf 3 . +They are also not required to completely fill or empty the buffer. +They are not, however, allowed to change streams from unbuffered to buffered +or to change the state of the line buffering flag. +They must also be prepared to have read or write calls occur on buffers other +than the one most recently specified. +.Pp +All user +.Tn I/O +functions can report an error by returning \-1. +Additionally, all of the functions should set the external variable +.Va errno +appropriately if an error occurs. +.Pp +An error on +.Fn closefn +does not keep the stream open. +.Pp +As a convenience, the include file +.Aq Pa stdio.h +defines the macros +.Fn fropen +and +.Fn fwopen +as calls to +.Fn funopen +with only a read or write function specified. +.Sh RETURN VALUES +Upon successful completion, +.Fn funopen +returns a +.Dv FILE +pointer. +Otherwise, +.Dv NULL +is returned and the global variable +.Va errno +is set to indicate the error. +.Sh ERRORS +.Bl -tag -width Er +.It Bq Er EINVAL +The +.Fn funopen +function +was called without either a read or write function. +The +.Fn funopen +function +may also fail and set +.Va errno +for any of the errors +specified for the routine +.Xr malloc 3 . +.El +.Sh SEE ALSO +.Xr fcntl 2 , +.Xr open 2 , +.Xr fclose 3 , +.Xr fopen 3 , +.Xr fseek 3 , +.Xr setbuf 3 +.Sh HISTORY +The +.Fn funopen +functions first appeared in +.Bx 4.4 . +.Sh BUGS +The +.Fn funopen +function +may not be portable to systems other than +.Bx . diff --git a/stdio/funopen.c b/stdio/funopen.c new file mode 100644 index 0000000..d96a23f --- /dev/null +++ b/stdio/funopen.c @@ -0,0 +1,99 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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 +#include +#include "local.h" + +FILE * +funopen(cookie, readfn, writefn, seekfn, closefn) + const void *cookie; + int (*readfn)(), (*writefn)(); +#if __STDC__ + fpos_t (*seekfn)(void *cookie, fpos_t off, int whence); +#else + fpos_t (*seekfn)(); +#endif + int (*closefn)(); +{ + register FILE *fp; + int flags; + + if (readfn == NULL) { + if (writefn == NULL) { /* illegal */ + errno = EINVAL; + return (NULL); + } else + flags = __SWR; /* write only */ + } else { + if (writefn == NULL) + flags = __SRD; /* read only */ + else + flags = __SRW; /* read-write */ + } + if ((fp = __sfp()) == NULL) + return (NULL); + fp->_flags = flags; + fp->_file = -1; + fp->_cookie = (void *)cookie; + fp->_read = readfn; + fp->_write = writefn; + fp->_seek = seekfn; + fp->_close = closefn; + return (fp); +} diff --git a/stdio/fvwrite.c b/stdio/fvwrite.c new file mode 100644 index 0000000..b316854 --- /dev/null +++ b/stdio/fvwrite.c @@ -0,0 +1,213 @@ +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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) +#if 0 +static char sccsid[] = "@(#)fvwrite.c 8.1 (Berkeley) 6/4/93"; +#endif +static const char rcsid[] = + "$FreeBSD: src/lib/libc/stdio/fvwrite.c,v 1.10 1999/08/28 00:01:06 peter Exp $"; +#endif /* LIBC_SCCS and not lint */ + +#include +#include +#include +#include "local.h" +#include "fvwrite.h" + +/* + * Write some memory regions. Return zero on success, EOF on error. + * + * This routine is large and unsightly, but most of the ugliness due + * to the three different kinds of output buffering is handled here. + */ +int +__sfvwrite(fp, uio) + register FILE *fp; + register struct __suio *uio; +{ + register size_t len; + register char *p; + register struct __siov *iov; + register int w, s; + char *nl; + int nlknown, nldist; + + if ((len = uio->uio_resid) == 0) + return (0); + /* make sure we can write */ + if (cantwrite(fp)) + return (EOF); + +#define MIN(a, b) ((a) < (b) ? (a) : (b)) +#define COPY(n) (void)memcpy((void *)fp->_p, (void *)p, (size_t)(n)) + + iov = uio->uio_iov; + p = iov->iov_base; + len = iov->iov_len; + iov++; +#define GETIOV(extra_work) \ + while (len == 0) { \ + extra_work; \ + p = iov->iov_base; \ + len = iov->iov_len; \ + iov++; \ + } + if (fp->_flags & __SNBF) { + /* + * Unbuffered: write up to BUFSIZ bytes at a time. + */ + do { + GETIOV(;); + w = (*fp->_write)(fp->_cookie, p, MIN(len, BUFSIZ)); + if (w <= 0) + goto err; + p += w; + len -= w; + } while ((uio->uio_resid -= w) != 0); + } else if ((fp->_flags & __SLBF) == 0) { + /* + * Fully buffered: fill partially full buffer, if any, + * and then flush. If there is no partial buffer, write + * one _bf._size byte chunk directly (without copying). + * + * String output is a special case: write as many bytes + * as fit, but pretend we wrote everything. This makes + * snprintf() return the number of bytes needed, rather + * than the number used, and avoids its write function + * (so that the write function can be invalid). + */ + do { + GETIOV(;); + if ((fp->_flags & (__SALC | __SSTR)) == + (__SALC | __SSTR) && fp->_w < len) { + size_t blen = fp->_p - fp->_bf._base; + + /* + * Alloc an extra 128 bytes (+ 1 for NULL) + * so we don't call realloc(3) so often. + */ + fp->_w = len + 128; + fp->_bf._size = blen + len + 128; + fp->_bf._base = + reallocf(fp->_bf._base, fp->_bf._size + 1); + if (fp->_bf._base == NULL) + goto err; + fp->_p = fp->_bf._base + blen; + } + w = fp->_w; + if (fp->_flags & __SSTR) { + if (len < w) + w = len; + if (w > 0) { + COPY(w); /* copy MIN(fp->_w,len), */ + fp->_w -= w; + fp->_p += w; + } + w = len; /* but pretend copied all */ + } else if (fp->_p > fp->_bf._base && len > w) { + /* fill and flush */ + COPY(w); + /* fp->_w -= w; */ /* unneeded */ + fp->_p += w; + if (fflush(fp)) + goto err; + } else if (len >= (w = fp->_bf._size)) { + /* write directly */ + w = (*fp->_write)(fp->_cookie, p, w); + if (w <= 0) + goto err; + } else { + /* fill and done */ + w = len; + COPY(w); + fp->_w -= w; + fp->_p += w; + } + p += w; + len -= w; + } while ((uio->uio_resid -= w) != 0); + } else { + /* + * Line buffered: like fully buffered, but we + * must check for newlines. Compute the distance + * to the first newline (including the newline), + * or `infinity' if there is none, then pretend + * that the amount to write is MIN(len,nldist). + */ + nlknown = 0; + nldist = 0; /* XXX just to keep gcc happy */ + do { + GETIOV(nlknown = 0); + if (!nlknown) { + nl = memchr((void *)p, '\n', len); + nldist = nl ? nl + 1 - p : len + 1; + nlknown = 1; + } + s = MIN(len, nldist); + w = fp->_w + fp->_bf._size; + if (fp->_p > fp->_bf._base && s > w) { + COPY(w); + /* fp->_w -= w; */ + fp->_p += w; + if (fflush(fp)) + goto err; + } else if (s >= (w = fp->_bf._size)) { + w = (*fp->_write)(fp->_cookie, p, w); + if (w <= 0) + goto err; + } else { + w = s; + COPY(w); + fp->_w -= w; + fp->_p += w; + } + if ((nldist -= w) == 0) { + /* copied the newline: flush and forget */ + if (fflush(fp)) + goto err; + nlknown = 0; + } + p += w; + len -= w; + } while ((uio->uio_resid -= w) != 0); + } + return (0); + +err: + fp->_flags |= __SERR; + return (EOF); +} diff --git a/stdio/fvwrite.h b/stdio/fvwrite.h new file mode 100644 index 0000000..ec6bc0b --- /dev/null +++ b/stdio/fvwrite.h @@ -0,0 +1,56 @@ +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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. + * + * @(#)fvwrite.h 8.1 (Berkeley) 6/4/93 + */ + +/* + * I/O descriptors for __sfvwrite(). + */ +struct __siov { + void *iov_base; + size_t iov_len; +}; +struct __suio { + struct __siov *uio_iov; + int uio_iovcnt; + int uio_resid; +}; + +#if __STDC__ || c_plusplus +extern int __sfvwrite(FILE *, struct __suio *); +#else +extern int __sfvwrite(); +#endif diff --git a/stdio/fwalk.c b/stdio/fwalk.c new file mode 100644 index 0000000..ddbf641 --- /dev/null +++ b/stdio/fwalk.c @@ -0,0 +1,78 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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 +#include +#include "local.h" +#include "glue.h" + +int +_fwalk(function) + register int (*function)(); +{ + register FILE *fp; + register int n, ret; + register struct glue *g; + + ret = 0; + for (g = &__sglue; g != NULL; g = g->next) + for (fp = g->iobs, n = g->niobs; --n >= 0; fp++) + if (fp->_flags != 0) + ret |= (*function)(fp); + return (ret); +} diff --git a/stdio/fwrite.c b/stdio/fwrite.c new file mode 100644 index 0000000..7e4e82f --- /dev/null +++ b/stdio/fwrite.c @@ -0,0 +1,90 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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 +#include "local.h" +#include "fvwrite.h" + +/* + * Write `count' objects (each size `size') from memory to the given file. + * Return the number of whole objects written. + */ +size_t +fwrite(buf, size, count, fp) + const void *buf; + size_t size, count; + FILE *fp; +{ + size_t n; + struct __suio uio; + struct __siov iov; + + iov.iov_base = (void *)buf; + uio.uio_resid = iov.iov_len = n = count * size; + uio.uio_iov = &iov; + uio.uio_iovcnt = 1; + + /* + * The usual case is success (__sfvwrite returns 0); + * skip the divide if this happens, since divides are + * generally slow and since this occurs whenever size==0. + */ + if (__sfvwrite(fp, &uio) == 0) + return (count); + return ((n - uio.uio_resid) / size); +} diff --git a/stdio/getc.3 b/stdio/getc.3 new file mode 100644 index 0000000..3db3eca --- /dev/null +++ b/stdio/getc.3 @@ -0,0 +1,139 @@ +.\" 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/getc.3,v 1.11 2001/10/01 16:08:59 ru Exp $ +.\" +.Dd June 4, 1993 +.Dt GETC 3 +.Os +.Sh NAME +.Nm fgetc , +.Nm getc , +.Nm getchar , +.Nm getw +.Nd get next character or word from input stream +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In stdio.h +.Ft int +.Fn fgetc "FILE *stream" +.Ft int +.Fn getc "FILE *stream" +.Ft int +.Fn getchar +.Ft int +.Fn getw "FILE *stream" +.Sh DESCRIPTION +The +.Fn fgetc +function +obtains the next input character (if present) from the stream pointed at by +.Fa stream , +or the next character pushed back on the stream via +.Xr ungetc 3 . +.Pp +The +.Fn getc +function +acts essentially identically to +.Fn fgetc , +but is a macro that expands in-line. +.Pp +The +.Fn getchar +function +is equivalent to +.Fn getc stdin . +.Pp +The +.Fn getw +function +obtains the next +.Em int +(if present) +from the stream pointed at by +.Fa stream . +.Sh RETURN VALUES +If successful, these routines return the next requested object +from the +.Fa stream . +If the stream is at end-of-file or a read error occurs, +the routines return +.Dv EOF . +The routines +.Xr feof 3 +and +.Xr ferror 3 +must be used to distinguish between end-of-file and error. +If an error occurs, the global variable +.Va errno +is set to indicate the error. +The end-of-file condition is remembered, even on a terminal, and all +subsequent attempts to read will return +.Dv EOF +until the condition is cleared with +.Xr clearerr 3 . +.Sh SEE ALSO +.Xr ferror 3 , +.Xr fopen 3 , +.Xr fread 3 , +.Xr putc 3 , +.Xr ungetc 3 +.Sh STANDARDS +The +.Fn fgetc , +.Fn getc +and +.Fn getchar +functions +conform to +.St -isoC . +.Sh BUGS +Since +.Dv EOF +is a valid integer value, +.Xr feof 3 +and +.Xr ferror 3 +must be used to check for failure after calling +.Fn getw . +The size and byte order of an +.Em int +varies from one machine to another, and +.Fn getw +is not recommended for portable applications. +.Pp diff --git a/stdio/getc.c b/stdio/getc.c new file mode 100644 index 0000000..b4af96a --- /dev/null +++ b/stdio/getc.c @@ -0,0 +1,71 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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 + +/* + * A subroutine version of the macro getc. + */ +#undef getc + +int +getc(fp) + register FILE *fp; +{ + return (__sgetc(fp)); +} diff --git a/stdio/getchar.c b/stdio/getchar.c new file mode 100644 index 0000000..e7d7e5a --- /dev/null +++ b/stdio/getchar.c @@ -0,0 +1,70 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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. + */ + + +/* + * A subroutine version of the macro getchar. + */ +#include + +#undef getchar + +int +getchar() +{ + return (getc(stdin)); +} diff --git a/stdio/gets.c b/stdio/gets.c new file mode 100644 index 0000000..ea8b1e5 --- /dev/null +++ b/stdio/gets.c @@ -0,0 +1,86 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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 +#include + +char * +gets(buf) + char *buf; +{ + register int c; + register char *s; + static int warned; + static char w[] = + "warning: this program uses gets(), which is unsafe.\r\n"; + + if (!warned) { + (void) write(STDERR_FILENO, w, sizeof(w) - 1); + warned = 1; + } + for (s = buf; (c = getchar()) != '\n';) + if (c == EOF) + if (s == buf) + return (NULL); + else + break; + else + *s++ = c; + *s = 0; + return (buf); +} diff --git a/stdio/getw.c b/stdio/getw.c new file mode 100644 index 0000000..a2776b3 --- /dev/null +++ b/stdio/getw.c @@ -0,0 +1,68 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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 + +int +getw(fp) + FILE *fp; +{ + int x; + + return (fread((void *)&x, sizeof(x), 1, fp) == 1 ? x : EOF); +} diff --git a/stdio/glue.h b/stdio/glue.h new file mode 100644 index 0000000..4636067 --- /dev/null +++ b/stdio/glue.h @@ -0,0 +1,68 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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. + */ + +/* + * The first few FILEs are statically allocated; others are dynamically + * allocated and linked in via this glue structure. + */ +struct glue { + struct glue *next; + int niobs; + FILE *iobs; +}; + +extern struct glue __sglue; diff --git a/stdio/local.h b/stdio/local.h new file mode 100644 index 0000000..ae80de0 --- /dev/null +++ b/stdio/local.h @@ -0,0 +1,107 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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. + */ + +/* + * Information local to this implementation of stdio, + * in particular, macros and private variables. + */ + +extern int __sflush __P((FILE *)); +extern FILE *__sfp __P((void)); +extern int __srefill __P((FILE *)); +extern int __sread __P((void *, char *, int)); +extern int __swrite __P((void *, char const *, int)); +extern fpos_t __sseek __P((void *, fpos_t, int)); +extern int __sclose __P((void *)); +extern void __sinit __P((void)); +extern void _cleanup __P((void)); +extern void (*__cleanup) __P((void)); +extern void __smakebuf __P((FILE *)); +extern int __swhatbuf __P((FILE *, size_t *, int *)); +extern int _fwalk __P((int (*)(FILE *))); +extern int __swsetup __P((FILE *)); +extern int __sflags __P((const char *, int *)); + +extern int __sdidinit; +extern void (*__cleanup) __P((void)); + +/* + * Return true iff the given FILE cannot be written now. + */ +#define cantwrite(fp) \ + ((((fp)->_flags & __SWR) == 0 || (fp)->_bf._base == NULL) && \ + __swsetup(fp)) + +/* + * Test whether the given stdio file has an active ungetc buffer; + * release such a buffer, without restoring ordinary unread data. + */ +#define HASUB(fp) ((fp)->_ub._base != NULL) +#define FREEUB(fp) { \ + if ((fp)->_ub._base != (fp)->_ubuf) \ + free((char *)(fp)->_ub._base); \ + (fp)->_ub._base = NULL; \ +} + +/* + * test for an fgetln() buffer. + */ +#define HASLB(fp) ((fp)->_lb._base != NULL) +#define FREELB(fp) { \ + free((char *)(fp)->_lb._base); \ + (fp)->_lb._base = NULL; \ +} diff --git a/stdio/makebuf.c b/stdio/makebuf.c new file mode 100644 index 0000000..89c3bbb --- /dev/null +++ b/stdio/makebuf.c @@ -0,0 +1,136 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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 +#include +#include +#include +#include +#include "local.h" + +/* + * Allocate a file buffer, or switch to unbuffered I/O. + * Per the ANSI C standard, ALL tty devices default to line buffered. + * + * As a side effect, we set __SOPT or __SNPT (en/dis-able fseek + * optimisation) right after the fstat() that finds the buffer size. + */ +void +__smakebuf(fp) + register FILE *fp; +{ + register void *p; + register int flags; + size_t size; + int couldbetty; + + if (fp->_flags & __SNBF) { + fp->_bf._base = fp->_p = fp->_nbuf; + fp->_bf._size = 1; + return; + } + flags = __swhatbuf(fp, &size, &couldbetty); + if ((p = malloc(size)) == NULL) { + fp->_flags |= __SNBF; + fp->_bf._base = fp->_p = fp->_nbuf; + fp->_bf._size = 1; + return; + } + __cleanup = _cleanup; + flags |= __SMBF; + fp->_bf._base = fp->_p = p; + fp->_bf._size = size; + if (couldbetty && isatty(fp->_file)) + flags |= __SLBF; + fp->_flags |= flags; +} + +/* + * Internal routine to determine `proper' buffering for a file. + */ +int +__swhatbuf(fp, bufsize, couldbetty) + register FILE *fp; + size_t *bufsize; + int *couldbetty; +{ + struct stat st; + + if (fp->_file < 0 || fstat(fp->_file, &st) < 0) { + *couldbetty = 0; + *bufsize = BUFSIZ; + return (__SNPT); + } + + /* could be a tty iff it is a character device */ + *couldbetty = (st.st_mode & S_IFMT) == S_IFCHR; + if (st.st_blksize <= 0) { + *bufsize = BUFSIZ; + return (__SNPT); + } + + /* + * Optimise fseek() only if it is a regular file. (The test for + * __sseek is mainly paranoia.) It is safe to set _blksize + * unconditionally; it will only be used if __SOPT is also set. + */ + *bufsize = st.st_blksize; + fp->_blksize = st.st_blksize; + return ((st.st_mode & S_IFMT) == S_IFREG && fp->_seek == __sseek ? + __SOPT : __SNPT); +} diff --git a/stdio/mktemp.3 b/stdio/mktemp.3 new file mode 100644 index 0000000..b19d61f --- /dev/null +++ b/stdio/mktemp.3 @@ -0,0 +1,246 @@ +.\" Copyright (c) 1989, 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. +.\" +.\" @(#)mktemp.3 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD: src/lib/libc/stdio/mktemp.3,v 1.17 2001/10/01 16:08:59 ru Exp $ +.\" +.Dd February 11, 1998 +.Dt MKTEMP 3 +.Os +.Sh NAME +.Nm mktemp +.Nd make temporary file name (unique) +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In unistd.h +.Ft char * +.Fn mktemp "char *template" +.Ft int +.Fn mkstemp "char *template" +.Ft int +.Fn mkstemps "char *template" "int suffixlen" +.Ft char * +.Fn mkdtemp "char *template" +.Sh DESCRIPTION +The +.Fn mktemp +function +takes the given file name template and overwrites a portion of it +to create a file name. +This file name is guaranteed not to exist at the time of function invocation +and is suitable for use +by the application. +The template may be any file name with some number of +.Ql X Ns s +appended +to it, for example +.Pa /tmp/temp.XXXXXX . +The trailing +.Ql X Ns s +are replaced with a +unique alphanumeric combination. +The number of unique file names +.Fn mktemp +can return depends on the number of +.Ql X Ns s +provided; six +.Ql X Ns s +will +result in +.Fn mktemp +selecting one of 56800235584 (62 ** 6) possible temporary file names. +.Pp +The +.Fn mkstemp +function +makes the same replacement to the template and creates the template file, +mode 0600, returning a file descriptor opened for reading and writing. +This avoids the race between testing for a file's existence and opening it +for use. +.Pp +The +.Fn mkstemps +function acts the same as +.Fn mkstemp , +except it permits a suffix to exist in the template. +The template should be of the form +.Pa /tmp/tmpXXXXXXsuffix . +.Fn mkstemps +is told the length of the suffix string. +.Pp +The +.Fn mkdtemp +function makes the same replacement to the template as in +.Xr mktemp 3 +and creates the template directory, mode 0700. +.Sh RETURN VALUES +The +.Fn mktemp +and +.Fn mkdtemp +functions return a pointer to the template on success and +.Dv NULL +on failure. +The +.Fn mkstemp +and +.Fn mkstemps +functions +return \-1 if no suitable file could be created. +If either call fails an error code is placed in the global variable +.Va errno . +.Sh ERRORS +The +.Fn mkstemp , +.Fn mkstemps +and +.Fn mkdtemp +functions +may set +.Va errno +to one of the following values: +.Bl -tag -width Er +.It Bq Er ENOTDIR +The pathname portion of the template is not an existing directory. +.El +.Pp +The +.Fn mkstemp , +.Fn mkstemps +and +.Fn mkdtemp +functions +may also set +.Va errno +to any value specified by the +.Xr stat 2 +function. +.Pp +The +.Fn mkstemp +and +.Fn mkstemps +functions +may also set +.Va errno +to any value specified by the +.Xr open 2 +function. +.Pp +The +.Fn mkdtemp +function +may also set +.Va errno +to any value specified by the +.Xr mkdir 2 +function. +.Sh NOTES +A common problem that results in a core dump is that the programmer +passes in a read-only string to +.Fn mktemp , +.Fn mkstemp , +.Fn mkstemps +or +.Fn mkdtemp . +This is common with programs that were developed before +.St -isoC +compilers were common. +For example, calling +.Fn mkstemp +with an argument of +.Qq /tmp/tempfile.XXXXXX +will result in a core dump due to +.Fn mkstemp +attempting to modify the string constant that was given. +If the program in question makes heavy use of that type +of function call, you do have the option of compiling the program +so that it will store string constants in a writable segment of memory. +See +.Xr gcc 1 +for more information. +.Sh BUGS +This family of functions produces filenames which can be guessed, +though the risk is minimized when large numbers of +.Ql X Ns s +are used to +increase the number of possible temporary filenames. +This makes the race in +.Fn mktemp , +between testing for a file's existence (in the +.Fn mktemp +function call) +and opening it for use +(later in the user application) +particularly dangerous from a security perspective. +Whenever it is possible, +.Fn mkstemp +should be used instead, since it does not have the race condition. +If +.Fn mkstemp +cannot be used, the filename created by +.Fn mktemp +should be created using the +.Dv O_EXCL +flag to +.Xr open 2 +and the return status of the call should be tested for failure. +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. +.Sh SEE ALSO +.Xr chmod 2 , +.Xr getpid 2 , +.Xr mkdir 2 , +.Xr open 2 , +.Xr stat 2 +.Sh HISTORY +A +.Fn mktemp +function appeared in +.At v7 . +The +.Fn mkstemp +function appeared in +.Bx 4.4 . +The +.Fn mkdtemp +function first appeared in +.Ox 2.2 , +and later in +.Fx 3.2 . +The +.Fn mkstemps +function first appeared in +.Ox 2.4 , +and later in +.Fx 3.4 . diff --git a/stdio/mktemp.c b/stdio/mktemp.c new file mode 100644 index 0000000..c044a67 --- /dev/null +++ b/stdio/mktemp.c @@ -0,0 +1,186 @@ +/* + * Copyright (c) 1987, 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) +#if 0 +static char sccsid[] = "@(#)mktemp.c 8.1 (Berkeley) 6/4/93"; +#endif +static const char rcsid[] = + "$FreeBSD: src/lib/libc/stdio/mktemp.c,v 1.19.2.1 2001/01/20 09:35:24 kris Exp $"; +#endif /* LIBC_SCCS and not lint */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +char *_mktemp __P((char *)); + +static int _gettemp __P((char *, int *, int, int)); + +static const unsigned char padchar[] = +"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; + +int +mkstemps(path, slen) + char *path; + int slen; +{ + int fd; + + return (_gettemp(path, &fd, 0, slen) ? fd : -1); +} + +int +mkstemp(path) + char *path; +{ + int fd; + + return (_gettemp(path, &fd, 0, 0) ? fd : -1); +} + +char * +mkdtemp(path) + char *path; +{ + return(_gettemp(path, (int *)NULL, 1, 0) ? path : (char *)NULL); +} + +char * +_mktemp(path) + char *path; +{ + return(_gettemp(path, (int *)NULL, 0, 0) ? path : (char *)NULL); +} + +char * +mktemp(path) + char *path; +{ + return(_mktemp(path)); +} + +static int +_gettemp(path, doopen, domkdir, slen) + char *path; + register int *doopen; + int domkdir; + int slen; +{ + register char *start, *trv, *suffp; + char *pad; + struct stat sbuf; + int rval; + uint32_t rand; + + if (doopen && domkdir) { + errno = EINVAL; + return(0); + } + + for (trv = path; *trv; ++trv) + ; + trv -= slen; + suffp = trv; + --trv; + if (trv < path) { + errno = EINVAL; + return (0); + } + + /* Fill space with random characters */ + while (trv >= path && *trv == 'X') { + rand = arc4random() % (sizeof(padchar) - 1); + *trv-- = padchar[rand]; + } + start = trv + 1; + + /* + * check the target directory. + */ + if (doopen || domkdir) { + for (;; --trv) { + if (trv <= path) + break; + if (*trv == '/') { + *trv = '\0'; + rval = stat(path, &sbuf); + *trv = '/'; + if (rval != 0) + return(0); + if (!S_ISDIR(sbuf.st_mode)) { + errno = ENOTDIR; + return(0); + } + break; + } + } + } + + for (;;) { + if (doopen) { + if ((*doopen = + open(path, O_CREAT|O_EXCL|O_RDWR, 0600)) >= 0) + return(1); + if (errno != EEXIST) + return(0); + } else if (domkdir) { + if (mkdir(path, 0700) == 0) + return(1); + if (errno != EEXIST) + return(0); + } else if (lstat(path, &sbuf)) + return(errno == ENOENT ? 1 : 0); + + /* If we have a collision, cycle through the space of filenames */ + for (trv = start;;) { + if (*trv == '\0' || trv == suffp) + return(0); + pad = strchr(padchar, *trv); + if (pad == NULL || !*++pad) + *trv++ = padchar[0]; + else { + *trv++ = *pad; + break; + } + } + } + /*NOTREACHED*/ +} diff --git a/stdio/perror.c b/stdio/perror.c new file mode 100644 index 0000000..7a3c4f5 --- /dev/null +++ b/stdio/perror.c @@ -0,0 +1,85 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1988, 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 +#include +#include +#include +#include +#include + +void +perror(s) + const char *s; +{ + register struct iovec *v; + struct iovec iov[4]; + + v = iov; + if (s && *s) { + v->iov_base = (char *)s; + v->iov_len = strlen(s); + v++; + v->iov_base = ": "; + v->iov_len = 2; + v++; + } + v->iov_base = strerror(errno); + v->iov_len = strlen(v->iov_base); + v++; + v->iov_base = "\n"; + v->iov_len = 1; + (void)writev(STDERR_FILENO, iov, (v - iov) + 1); +} diff --git a/stdio/printf.3 b/stdio/printf.3 new file mode 100644 index 0000000..dacf1d4 --- /dev/null +++ b/stdio/printf.3 @@ -0,0 +1,643 @@ +.\" 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.17.2.10 2001/12/14 18:33:57 ru Exp $ +.\" +.Dd June 4, 1993 +.Dt PRINTF 3 +.Os +.Sh NAME +.Nm printf , fprintf , sprintf , snprintf , asprintf , +.Nm vprintf , vfprintf, vsprintf , vsnprintf , vasprintf +.Nd formatted output conversion +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In stdio.h +.Ft int +.Fn printf "const char *format" ... +.Ft int +.Fn fprintf "FILE *stream" "const char *format" ... +.Ft int +.Fn sprintf "char *str" "const char *format" ... +.Ft int +.Fn snprintf "char *str" "size_t size" "const char *format" ... +.Ft int +.Fn asprintf "char **ret" "const char *format" ... +.In stdarg.h +.Ft int +.Fn vprintf "const char *format" "va_list ap" +.Ft int +.Fn vfprintf "FILE *stream" "const char *format" "va_list ap" +.Ft int +.Fn vsprintf "char *str" "const char *format" "va_list ap" +.Ft int +.Fn vsnprintf "char *str" "size_t size" "const char *format" "va_list ap" +.Ft int +.Fn vasprintf "char **ret" "const char *format" "va_list ap" +.Sh DESCRIPTION +The +.Fn printf +family of functions produces output according to a +.Fa format +as described below. +.Fn Printf +and +.Fn vprintf +write output to +.Pa stdout , +the standard output stream; +.Fn fprintf +and +.Fn vfprintf +write output to the given output +.Fa stream ; +.Fn sprintf , +.Fn snprintf , +.Fn vsprintf , +and +.Fn vsnprintf +write to the character string +.Fa str ; +and +.Fn asprintf +and +.Fn vasprintf +dynamically allocate a new string with +.Xr malloc 3 . +.Pp +These functions write the output under the control of a +.Fa format +string that specifies how subsequent arguments +(or arguments accessed via the variable-length argument facilities of +.Xr stdarg 3 ) +are converted for output. +.Pp +These functions return the number of characters printed +(not including the trailing +.Ql \e0 +used to end output to strings), +except for +.Fn snprintf +and +.Fn vsnprintf , +which return the number of characters that would have been printed if the +.Fa size +were unlimited +(again, not including the final +.Ql \e0 ) . +.Pp +.Fn Asprintf +and +.Fn vasprintf +set +.Fa *ret +to be a pointer to a buffer sufficiently large to hold the formatted string. +This pointer should be passed to +.Xr free 3 +to release the allocated storage when it is no longer needed. +If sufficient space cannot be allocated, +.Fn asprintf +and +.Fn vasprintf +will return -1 and set +.Fa ret +to be a +.Dv NULL +pointer. +.Pp +.Fn Snprintf +and +.Fn vsnprintf +will write at most +.Fa size Ns \-1 +of the characters printed into the output string +(the +.Fa size Ns 'th +character then gets the terminating +.Ql \e0 ) ; +if the return value is greater than or equal to the +.Fa size +argument, the string was too short +and some of the printed characters were discarded. +.Pp +.Fn Sprintf +and +.Fn vsprintf +effectively assume an infinite +.Fa size . +.Pp +The format string is composed of zero or more directives: +ordinary +.\" multibyte +characters (not +.Cm % ) , +which are copied unchanged to the output stream; +and conversion specifications, each of which results +in fetching zero or more subsequent arguments. +Each conversion specification is introduced by +the +.Cm % +character. +The arguments must correspond properly (after type promotion) +with the conversion specifier. +After the +.Cm % , +the following appear in sequence: +.Bl -bullet +.It +An optional field, consisting of a decimal digit string followed by a +.Cm $ , +specifying the next argument to access. +If this field is not provided, the argument following the last +argument accessed will be used. +Arguments are numbered starting at +.Cm 1 . +If unaccessed arguments in the format string are interspersed with ones that +are accessed the results will be indeterminate. +.It +Zero or more of the following flags: +.Bl -hyphen +.It +A +.Cm # +character +specifying that the value should be converted to an +.Dq alternate form . +For +.Cm c , d , i , n , p , s , +and +.Cm u +conversions, this option has no effect. +For +.Cm o +conversions, the precision of the number is increased to force the first +character of the output string to a zero (except if a zero value is printed +with an explicit precision of zero). +For +.Cm x +and +.Cm X +conversions, a non-zero result has the string +.Ql 0x +(or +.Ql 0X +for +.Cm X +conversions) prepended to it. +For +.Cm e , E , f , g , +and +.Cm G +conversions, the result will always contain a decimal point, even if no +digits follow it (normally, a decimal point appears in the results of +those conversions only if a digit follows). +For +.Cm g +and +.Cm G +conversions, trailing zeros are not removed from the result as they +would otherwise be. +.It +A +.Cm 0 +(zero) +character specifying zero padding. +For all conversions except +.Cm n , +the converted value is padded on the left with zeros rather than blanks. +If a precision is given with a numeric conversion +.Cm ( d , i , o , u , i , x , +and +.Cm X ) , +the +.Cm 0 +flag is ignored. +.It +A negative field width flag +.Cm \- +indicates the converted value is to be left adjusted on the field boundary. +Except for +.Cm n +conversions, the converted value is padded on the right with blanks, +rather than on the left with blanks or zeros. +A +.Cm \- +overrides a +.Cm 0 +if both are given. +.It +A space, specifying that a blank should be left before a positive number +produced by a signed conversion +.Cm ( d , e , E , f , g , G , +or +.Cm i ) . +.It +A +.Cm + +character specifying that a sign always be placed before a +number produced by a signed conversion. +A +.Cm + +overrides a space if both are used. +.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 +flag has been given) to fill out +the field width. +.It +An optional precision, in the form of a period +.Cm \&. +followed by an +optional digit string. +If the digit string is omitted, the precision is taken as zero. +This gives the minimum number of digits to appear for +.Cm d , i , o , u , x , +and +.Cm X +conversions, the number of digits to appear after the decimal-point for +.Cm e , E , +and +.Cm f +conversions, the maximum number of significant digits for +.Cm g +and +.Cm G +conversions, or the maximum number of characters to be printed from a +string for +.Cm s +conversions. +.It +The optional character +.Cm h , +specifying that a following +.Cm d , i , o , u , x , +or +.Cm X +conversion corresponds to a +.Vt short int +or +.Vt unsigned short int +argument, or that a following +.Cm n +conversion corresponds to a pointer to a +.Vt short int +argument. +.It +The optional character +.Cm l +(ell) specifying that a following +.Cm d , i , o , u , x , +or +.Cm X +conversion applies to a pointer to a +.Vt long int +or +.Vt unsigned long int +argument, or that a following +.Cm n +conversion corresponds to a pointer to a +.Vt long int +argument. +.It +The optional characters +.Cm ll +(ell ell) specifying that a following +.Cm d , i , o , u , x , +or +.Cm X +conversion applies to a pointer to a +.Vt long long int +or +.Vt unsigned long long int +argument, or that a following +.Cm n +conversion corresponds to a pointer to a +.Vt long long int +argument. +.It +The optional character +.Cm q , +specifying that a following +.Cm d , i , o , u , x , +or +.Cm X +conversion corresponds to a +.Vt quad int +or +.Vt unsigned quad int +argument, or that a following +.Cm n +conversion corresponds to a pointer to a +.Vt quad int +argument. +.It +The character +.Cm L +specifying that a following +.Cm e , E , f , g , +or +.Cm G +conversion corresponds to a +.Vt long double +argument. +.It +A character that specifies the type of conversion to be applied. +.El +.Pp +A field width or precision, or both, may be indicated by +an asterisk +.Ql * +or an asterisk followed by one or more decimal digits and a +.Ql $ +instead of a +digit string. +In this case, an +.Vt int +argument supplies the field width or precision. +A negative field width is treated as a left adjustment flag followed by a +positive field width; a negative precision is treated as though it were +missing. +If a single format directive mixes positional (nn$) +and non-positional arguments, the results are undefined. +.Pp +The conversion specifiers and their meanings are: +.Bl -tag -width "diouxX" +.It Cm diouxX +The +.Vt int +(or appropriate variant) argument is converted to signed decimal +.Cm ( d +and +.Cm i ) , +unsigned octal +.Pq Cm o , +unsigned decimal +.Pq Cm u , +or unsigned hexadecimal +.Cm ( x +and +.Cm X ) +notation. +The letters +.Cm abcdef +are used for +.Cm x +conversions; the letters +.Cm ABCDEF +are used for +.Cm X +conversions. +The precision, if any, gives the minimum number of digits that must +appear; if the converted value requires fewer digits, it is padded on +the left with zeros. +.It Cm DOU +The +.Vt long int +argument is converted to signed decimal, unsigned octal, or unsigned +decimal, as if the format had been +.Cm ld , lo , +or +.Cm lu +respectively. +These conversion characters are deprecated, and will eventually disappear. +.It Cm eE +The +.Vt double +argument is rounded and converted in the style +.Oo \- Oc Ns d Ns Cm \&. Ns ddd Ns Cm e Ns \\*[Pm]dd +where there is one digit before the +decimal-point character +and the number of digits after it is equal to the precision; +if the precision is missing, +it is taken as 6; if the precision is +zero, no decimal-point character appears. +An +.Cm E +conversion uses the letter +.Cm E +(rather than +.Cm e ) +to introduce the exponent. +The exponent always contains at least two digits; if the value is zero, +the exponent is 00. +.It Cm f +The +.Vt double +argument is rounded and converted to decimal notation in the style +.Oo \- Oc Ns ddd Ns Cm \&. Ns ddd , +where the number of digits after the decimal-point character +is equal to the precision specification. +If the precision is missing, it is taken as 6; if the precision is +explicitly zero, no decimal-point character appears. +If a decimal point appears, at least one digit appears before it. +.It Cm gG +The +.Vt double +argument is converted in style +.Cm f +or +.Cm e +(or +.Cm E +for +.Cm G +conversions). +The precision specifies the number of significant digits. +If the precision is missing, 6 digits are given; if the precision is zero, +it is treated as 1. +Style +.Cm e +is used if the exponent from its conversion is less than -4 or greater than +or equal to the precision. +Trailing zeros are removed from the fractional part of the result; a +decimal point appears only if it is followed by at least one digit. +.It Cm c +The +.Vt int +argument is converted to an +.Vt unsigned char , +and the resulting character is written. +.It Cm s +The +.Vt char * +argument is expected to be a pointer to an array of character type (pointer +to a string). +Characters from the array are written up to (but not including) +a terminating +.Dv NUL +character; +if a precision is specified, no more than the number specified are +written. +If a precision is given, no null character +need be present; if the precision is not specified, or is greater than +the size of the array, the array must contain a terminating +.Dv NUL +character. +.It Cm p +The +.Vt void * +pointer argument is printed in hexadecimal (as if by +.Ql %#x +or +.Ql %#lx ) . +.It Cm n +The number of characters written so far is stored into the +integer indicated by the +.Vt int * +(or variant) pointer argument. +No argument is converted. +.It Cm % +A +.Ql % +is written. +No argument is converted. +The complete conversion specification +is +.Ql %% . +.El +.Pp +In no case does a non-existent or small field width cause truncation of +a field; if the result of a conversion is wider than the field width, the +field is expanded to contain the conversion result. +.Sh EXAMPLES +To print a date and time in the form +.Dq Li "Sunday, July 3, 10:02" , +where +.Fa weekday +and +.Fa month +are pointers to strings: +.Bd -literal -offset indent +#include +fprintf(stdout, "%s, %s %d, %.2d:%.2d\en", + weekday, month, day, hour, min); +.Ed +.Pp +To print \*(Pi +to five decimal places: +.Bd -literal -offset indent +#include +#include +fprintf(stdout, "pi = %.5f\en", 4 * atan(1.0)); +.Ed +.Pp +To allocate a 128 byte string and print into it: +.Bd -literal -offset indent +#include +#include +#include +char *newfmt(const char *fmt, ...) +{ + char *p; + va_list ap; + if ((p = malloc(128)) == NULL) + return (NULL); + va_start(ap, fmt); + (void) vsnprintf(p, 128, fmt, ap); + va_end(ap); + return (p); +} +.Ed +.Sh SEE ALSO +.Xr printf 1 , +.Xr scanf 3 +.Sh STANDARDS +The +.Fn fprintf , +.Fn printf , +.Fn sprintf , +.Fn vprintf , +.Fn vfprintf , +and +.Fn vsprintf +functions +conform to +.St -isoC . +.Sh HISTORY +The functions +.Fn asprintf +and +.Fn vasprintf +first appeared in the +.Tn GNU C +library. +These were implemented by +.An Peter Wemm Aq peter@FreeBSD.org +in +.Fx 2.2 , +but were later replaced with a different implementation +from +.An Todd C. Miller Aq Todd.Miller@courtesan.com +for +.Ox 2.3 . +.Sh BUGS +The conversion formats +.Cm \&%D , \&%O , +and +.Cm %U +are not standard and +are provided only for backward compatibility. +The effect of padding the +.Cm %p +format with zeros (either by the +.Cm 0 +flag or by specifying a precision), and the benign effect (i.e., none) +of the +.Cm # +flag on +.Cm %n +and +.Cm %p +conversions, as well as other +nonsensical combinations such as +.Cm %Ld , +are not standard; such combinations +should be avoided. +.Pp +Because +.Fn sprintf +and +.Fn vsprintf +assume an infinitely long string, +callers must be careful not to overflow the actual space; +this is often hard to assure. +For safety, programmers should use the +.Fn snprintf +interface instead. +Unfortunately, this interface is not portable. diff --git a/stdio/printf.c b/stdio/printf.c new file mode 100644 index 0000000..a7e2385 --- /dev/null +++ b/stdio/printf.c @@ -0,0 +1,86 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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 +#if __STDC__ +#include +#else +#include +#endif + +int +#if __STDC__ +printf(char const *fmt, ...) +#else +printf(fmt, va_alist) + char *fmt; + va_dcl +#endif +{ + int ret; + va_list ap; + +#if __STDC__ + va_start(ap, fmt); +#else + va_start(ap); +#endif + ret = vfprintf(stdout, fmt, ap); + va_end(ap); + return (ret); +} diff --git a/stdio/putc.3 b/stdio/putc.3 new file mode 100644 index 0000000..551135f --- /dev/null +++ b/stdio/putc.3 @@ -0,0 +1,136 @@ +.\" 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/putc.3,v 1.8 2001/10/01 16:08:59 ru Exp $ +.\" +.Dd June 4, 1993 +.Dt PUTC 3 +.Os +.Sh NAME +.Nm fputc , +.Nm putc , +.Nm putchar , +.Nm putw +.Nd output a character or word to a stream +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In stdio.h +.Ft int +.Fn fputc "int c" "FILE *stream" +.Ft int +.Fn putc "int c" "FILE *stream" +.Ft int +.Fn putchar "int c" +.Ft int +.Fn putw "int w" "FILE *stream" +.Sh DESCRIPTION +The +.Fn fputc +function +writes the character +.Fa c +(converted to an ``unsigned char'') +to the output stream pointed to by +.Fa stream . +.Pp +The +.Fn putc +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 +macro +is identical to +.Fn putc +with an output stream of +.Em stdout . +.Pp +The +.Fn putw +function +writes the specified +.Em int +to the named output +.Fa stream . +.Sh RETURN VALUES +The functions, +.Fn fputc , +.Fn putc +and +.Fn putchar +return the character written. +If an error occurs, the value +.Dv EOF +is returned. +The +.Fn putw +function +returns 0 on success; +.Dv EOF +is returned if +a write error occurs, +or if an attempt is made to write a read-only stream. +.Sh SEE ALSO +.Xr ferror 3 , +.Xr fopen 3 , +.Xr getc 3 , +.Xr stdio 3 +.Sh STANDARDS +The functions +.Fn fputc , +.Fn putc , +and +.Fn putchar , +conform to +.St -isoC . +A function +.Fn putw +function appeared in +.At v6 . +.Sh BUGS +The size and byte order of an +.Em int +varies from one machine to another, and +.Fn putw +is not recommended for portable applications. diff --git a/stdio/putc.c b/stdio/putc.c new file mode 100644 index 0000000..f4ca592 --- /dev/null +++ b/stdio/putc.c @@ -0,0 +1,72 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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 + +/* + * A subroutine version of the macro putc. + */ +#undef putc + +int +putc(c, fp) + int c; + register FILE *fp; +{ + return (__sputc(c, fp)); +} diff --git a/stdio/putchar.c b/stdio/putchar.c new file mode 100644 index 0000000..b69fabe --- /dev/null +++ b/stdio/putchar.c @@ -0,0 +1,73 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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 + +#undef putchar + +/* + * A subroutine version of the macro putchar + */ +int +putchar(c) + int c; +{ + register FILE *so = stdout; + + return (__sputc(c, so)); +} diff --git a/stdio/puts.c b/stdio/puts.c new file mode 100644 index 0000000..31ae510 --- /dev/null +++ b/stdio/puts.c @@ -0,0 +1,82 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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 +#include +#include "fvwrite.h" + +/* + * Write the given string to stdout, appending a newline. + */ +int +puts(s) + char const *s; +{ + size_t c = strlen(s); + struct __suio uio; + struct __siov iov[2]; + + iov[0].iov_base = (void *)s; + iov[0].iov_len = c; + iov[1].iov_base = "\n"; + iov[1].iov_len = 1; + uio.uio_resid = c + 1; + uio.uio_iov = &iov[0]; + uio.uio_iovcnt = 2; + return (__sfvwrite(stdout, &uio) ? EOF : '\n'); +} diff --git a/stdio/putw.c b/stdio/putw.c new file mode 100644 index 0000000..225f916 --- /dev/null +++ b/stdio/putw.c @@ -0,0 +1,75 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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 +#include "fvwrite.h" + +int +putw(w, fp) + int w; + FILE *fp; +{ + struct __suio uio; + struct __siov iov; + + iov.iov_base = &w; + iov.iov_len = uio.uio_resid = sizeof(w); + uio.uio_iov = &iov; + uio.uio_iovcnt = 1; + return (__sfvwrite(fp, &uio)); +} diff --git a/stdio/refill.c b/stdio/refill.c new file mode 100644 index 0000000..1af09b2 --- /dev/null +++ b/stdio/refill.c @@ -0,0 +1,147 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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 +#include +#include +#include "local.h" + +static int +lflush(fp) + FILE *fp; +{ + + if ((fp->_flags & (__SLBF|__SWR)) == __SLBF|__SWR) + return (__sflush(fp)); + return (0); +} + +/* + * Refill a stdio buffer. + * Return EOF on eof or error, 0 otherwise. + */ +int +__srefill(fp) + register FILE *fp; +{ + + /* make sure stdio is set up */ + if (!__sdidinit) + __sinit(); + + fp->_r = 0; /* largely a convenience for callers */ + + /* SysV does not make this test; take it out for compatibility */ + if (fp->_flags & __SEOF) + return (EOF); + + /* if not already reading, have to be reading and writing */ + if ((fp->_flags & __SRD) == 0) { + if ((fp->_flags & __SRW) == 0) { + errno = EBADF; + return (EOF); + } + /* switch to reading */ + if (fp->_flags & __SWR) { + if (__sflush(fp)) + return (EOF); + fp->_flags &= ~__SWR; + fp->_w = 0; + fp->_lbfsize = 0; + } + fp->_flags |= __SRD; + } else { + /* + * We were reading. If there is an ungetc buffer, + * we must have been reading from that. Drop it, + * restoring the previous buffer (if any). If there + * is anything in that buffer, return. + */ + if (HASUB(fp)) { + FREEUB(fp); + if ((fp->_r = fp->_ur) != 0) { + fp->_p = fp->_up; + return (0); + } + } + } + + if (fp->_bf._base == NULL) + __smakebuf(fp); + + /* + * Before reading from a line buffered or unbuffered file, + * flush all line buffered output files, per the ANSI C + * standard. + */ + if (fp->_flags & (__SLBF|__SNBF)) + (void) _fwalk(lflush); + fp->_p = fp->_bf._base; + fp->_r = (*fp->_read)(fp->_cookie, (char *)fp->_p, fp->_bf._size); + fp->_flags &= ~__SMOD; /* buffer contents are again pristine */ + if (fp->_r <= 0) { + if (fp->_r == 0) + fp->_flags |= __SEOF; + else { + fp->_r = 0; + fp->_flags |= __SERR; + } + return (EOF); + } + return (0); +} diff --git a/stdio/remove.3 b/stdio/remove.3 new file mode 100644 index 0000000..8c9d65f --- /dev/null +++ b/stdio/remove.3 @@ -0,0 +1,87 @@ +.\" 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. +.\" +.\" @(#)remove.3 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD: src/lib/libc/stdio/remove.3,v 1.9 2001/10/01 16:08:59 ru Exp $ +.\" +.Dd June 4, 1993 +.Dt REMOVE 3 +.Os +.Sh NAME +.Nm remove +.Nd remove directory entry +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In stdio.h +.Ft int +.Fn remove "const char *path" +.Sh DESCRIPTION +The +.Fn remove +function removes the file or directory specified by +.Fa path . +.Pp +If +.Fa path +specifies a directory, +.Fn remove "path" +is the equivalent of +.Fn rmdir "path" . +Otherwise, it is the equivalent of +.Fn unlink "path" . +.Sh RETURN VALUES +.Rv -std remove +.Sh ERRORS +The +.Fn remove +function +may fail and set +.Va errno +for any of the errors specified for the routines +.Xr lstat 2 , +.Xr rmdir 2 +or +.Xr unlink 2 . +.Sh SEE ALSO +.Xr rmdir 2 , +.Xr unlink 2 +.Sh STANDARDS +The +.Fn remove +function conforms to +.St -isoC +and +.St -xpg4.2 . diff --git a/stdio/remove.c b/stdio/remove.c new file mode 100644 index 0000000..4e20f08 --- /dev/null +++ b/stdio/remove.c @@ -0,0 +1,61 @@ +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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) +#if 0 +static char sccsid[] = "@(#)remove.c 8.1 (Berkeley) 6/4/93"; +#endif +static const char rcsid[] = + "$FreeBSD: src/lib/libc/stdio/remove.c,v 1.6.2.1 2000/09/20 04:43:12 jkh Exp $"; +#endif /* LIBC_SCCS and not lint */ + +#include +#include +#include +#include + +int +remove(file) + const char *file; +{ + struct stat sb; + + if (lstat(file, &sb) < 0) + return (-1); + if (S_ISDIR(sb.st_mode)) + return (rmdir(file)); + return (unlink(file)); +} diff --git a/stdio/rewind.c b/stdio/rewind.c new file mode 100644 index 0000000..f014fb6 --- /dev/null +++ b/stdio/rewind.c @@ -0,0 +1,69 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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 +#include + +void +rewind(fp) + register FILE *fp; +{ + (void) fseek(fp, 0L, SEEK_SET); + clearerr(fp); + errno = 0; /* not required, but seems reasonable */ +} diff --git a/stdio/rget.c b/stdio/rget.c new file mode 100644 index 0000000..7478d4f --- /dev/null +++ b/stdio/rget.c @@ -0,0 +1,75 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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 + +/* + * Handle getc() when the buffer ran out: + * Refill, then return the first character + * in the newly-filled buffer. + */ +int +__srget(fp) + register FILE *fp; +{ + if (__srefill(fp) == 0) { + fp->_r--; + return (*fp->_p++); + } + return (EOF); +} diff --git a/stdio/scanf.3 b/stdio/scanf.3 new file mode 100644 index 0000000..776ab49 --- /dev/null +++ b/stdio/scanf.3 @@ -0,0 +1,446 @@ +.\" 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.13 2001/10/01 16:08:59 ru Exp $ +.\" +.Dd December 11, 1993 +.Dt SCANF 3 +.Os +.Sh NAME +.Nm scanf , +.Nm fscanf , +.Nm sscanf , +.Nm vscanf , +.Nm vsscanf , +.Nm vfscanf +.Nd input format conversion +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In stdio.h +.Ft int +.Fn scanf "const char *format" ... +.Ft int +.Fn fscanf "FILE *stream" "const char *format" ... +.Ft int +.Fn sscanf "const char *str" "const char *format" ... +.In stdarg.h +.Ft int +.Fn vscanf "const char *format" "va_list ap" +.Ft int +.Fn vsscanf "const char *str" "const char *format" "va_list ap" +.Ft int +.Fn vfscanf "FILE *stream" "const char *format" "va_list ap" +.Sh DESCRIPTION +The +.Fn scanf +family of functions scans input according to a +.Fa format +as described below. +This format may contain +.Em conversion specifiers ; +the results from such conversions, if any, +are stored through the +.Em pointer +arguments. +The +.Fn scanf +function +reads input from the standard input stream +.Em stdin , +.Fn fscanf +reads input from the stream pointer +.Fa stream , +and +.Fn sscanf +reads its input from the character string pointed to by +.Fa str . +The +.Fn vfscanf +function +is analogous to +.Xr vfprintf 3 +and reads input from the stream pointer +.Fa stream +using a variable argument list of pointers (see +.Xr stdarg 3 ) . +The +.Fn vscanf +function scans a variable argument list from the standard input and +the +.Fn vsscanf +function scans it from a string; +these are analogous to +the +.Fn vprintf +and +.Fn vsprintf +functions respectively. +Each successive +.Em pointer +argument must correspond properly with +each successive conversion specifier +(but see `suppression' below). +All conversions are introduced by the +.Cm % +(percent sign) character. +The +.Fa format +string +may also contain other characters. +White space (such as blanks, tabs, or newlines) in the +.Fa format +string match any amount of white space, including none, in the input. +Everything else +matches only itself. +Scanning stops +when an input character does not match such a format character. +Scanning also stops +when an input conversion cannot be made (see below). +.Sh CONVERSIONS +Following the +.Cm % +character introducing a conversion +there may be a number of +.Em flag +characters, as follows: +.Bl -tag -width indent +.It Cm * +Suppresses assignment. +The conversion that follows occurs as usual, but no pointer is used; +the result of the conversion is simply discarded. +.It Cm h +Indicates that the conversion will be one of +.Cm dioux +or +.Cm n +and the next pointer is a pointer to a +.Em short int +(rather than +.Em int ) . +.It Cm l +Indicates either that the conversion will be one of +.Cm dioux +or +.Cm n +and the next pointer is a pointer to a +.Em long int +(rather than +.Em int ) , +or that the conversion will be one of +.Cm efg +and the next pointer is a pointer to +.Em double +(rather than +.Em float ) . +.It Cm L +Indicates that the conversion will be +.Cm efg +and the next pointer is a pointer to +.Em long double . +(This type is not implemented; the +.Cm L +flag is currently ignored.) +.It Cm q +Indicates either that the conversion will be one of +.Cm dioux +or +.Cm n +and the next pointer is a pointer to a +.Em long long int +(rather than +.Em int ) , +.El +.Pp +In addition to these flags, +there may be an optional maximum field width, +expressed as a decimal integer, +between the +.Cm % +and the conversion. +If no width is given, +a default of `infinity' is used (with one exception, below); +otherwise at most this many characters are scanned +in processing the conversion. +Before conversion begins, +most conversions skip white space; +this white space is not counted against the field width. +.Pp +The following conversions are available: +.Bl -tag -width XXXX +.It Cm % +Matches a literal `%'. +That is, `%\&%' in the format string +matches a single input `%' character. +No conversion is done, and assignment does not occur. +.It Cm d +Matches an optionally signed decimal integer; +the next pointer must be a pointer to +.Em int . +.It Cm D +Equivalent to +.Cm ld ; +this exists only for backwards compatibility. +.It Cm i +Matches an optionally signed integer; +the next pointer must be a pointer to +.Em int . +The integer is read in base 16 if it begins +with +.Ql 0x +or +.Ql 0X , +in base 8 if it begins with +.Ql 0 , +and in base 10 otherwise. +Only characters that correspond to the base are used. +.It Cm o +Matches an octal integer; +the next pointer must be a pointer to +.Em unsigned int . +.It Cm O +Equivalent to +.Cm lo ; +this exists for backwards compatibility. +.It Cm u +Matches an optionally signed decimal integer; +the next pointer must be a pointer to +.Em unsigned int . +.It Cm x +Matches an optionally signed hexadecimal integer; +the next pointer must be a pointer to +.Em unsigned int . +.It Cm X +Equivalent to +.Cm lx ; +this violates the +.St -isoC , +but is backwards compatible with previous +.Ux +systems. +.It Cm f +Matches an optionally signed floating-point number; +the next pointer must be a pointer to +.Em float . +.It Cm e +Equivalent to +.Cm f . +.It Cm g +Equivalent to +.Cm f . +.It Cm E +Equivalent to +.Cm lf ; +this violates the +.St -isoC , +but is backwards compatible with previous +.Ux +systems. +.It Cm F +Equivalent to +.Cm lf ; +this exists only for backwards compatibility. +.It Cm s +Matches a sequence of non-white-space characters; +the next pointer must be a pointer to +.Em char , +and the array must be large enough to accept all the sequence and the +terminating +.Dv NUL +character. +The input string stops at white space +or at the maximum field width, whichever occurs first. +.It Cm c +Matches a sequence of +.Em width +count +characters (default 1); +the next pointer must be a pointer to +.Em char , +and there must be enough room for all the characters +(no terminating +.Dv NUL +is added). +The usual skip of leading white space is suppressed. +To skip white space first, use an explicit space in the format. +.It Cm \&[ +Matches a nonempty sequence of characters from the specified set +of accepted characters; +the next pointer must be a pointer to +.Em char , +and there must be enough room for all the characters in the string, +plus a terminating +.Dv NUL +character. +The usual skip of leading white space is suppressed. +The string is to be made up of characters in +(or not in) +a particular set; +the set is defined by the characters between the open bracket +.Cm [ +character +and a close bracket +.Cm ] +character. +The set +.Em excludes +those characters +if the first character after the open bracket is a circumflex +.Cm ^ . +To include a close bracket in the set, +make it the first character after the open bracket +or the circumflex; +any other position will end the set. +The hyphen character +.Cm - +is also special; +when placed between two other characters, +it adds all intervening characters to the set. +To include a hyphen, +make it the last character before the final close bracket. +For instance, +.Ql [^]0-9-] +means the set `everything except close bracket, zero through nine, +and hyphen'. +The string ends with the appearance of a character not in the +(or, with a circumflex, in) set +or when the field width runs out. +.It Cm p +Matches a pointer value (as printed by +.Ql %p +in +.Xr printf 3 ) ; +the next pointer must be a pointer to +.Em void . +.It Cm n +Nothing is expected; +instead, the number of characters consumed thus far from the input +is stored through the next pointer, +which must be a pointer to +.Em int . +This is +.Em not +a conversion, although it can be suppressed with the +.Cm * +flag. +.El +.Pp +The decimal point +character is defined in the program's locale (category +.Dv LC_NUMERIC ) . +.Pp +For backwards compatibility, +other conversion characters (except +.Ql \e0 ) +are taken as if they were +.Ql %d +or, if uppercase, +.Ql %ld , +and a `conversion' of +.Ql %\e0 +causes an immediate return of +.Dv EOF . +The +.Cm F +and +.Cm X +conversions will be changed in the future +to conform to the +.Tn ANSI +C standard, +after which they will act like +.Cm f +and +.Cm x +respectively. +.Sh RETURN VALUES +These +functions +return +the number of input items assigned, which can be fewer than provided +for, or even zero, in the event of a matching failure. +Zero +indicates that, while there was input available, +no conversions were assigned; +typically this is due to an invalid input character, +such as an alphabetic character for a +.Ql %d +conversion. +The value +.Dv EOF +is returned if an input failure occurs before any conversion such as an +end-of-file occurs. +If an error or end-of-file occurs after conversion +has begun, +the number of conversions which were successfully completed is returned. +.Sh SEE ALSO +.Xr getc 3 , +.Xr printf 3 , +.Xr strtod 3 , +.Xr strtol 3 , +.Xr strtoul 3 +.Sh STANDARDS +The functions +.Fn fscanf , +.Fn scanf , +and +.Fn sscanf +conform to +.St -isoC . +.Sh HISTORY +The functions +.Fn vscanf , +.Fn vsscanf +and +.Fn vfscanf +are new to this release. +.Sh BUGS +The current situation with +.Cm %F +and +.Cm %X +conversions is unfortunate. +.Pp +All of the backwards compatibility formats will be removed in the future. +.Pp +Numerical strings are truncated to 512 characters; for example, +.Cm %f +and +.Cm %d +are implicitly +.Cm %512f +and +.Cm %512d . diff --git a/stdio/scanf.c b/stdio/scanf.c new file mode 100644 index 0000000..d2f6ce5 --- /dev/null +++ b/stdio/scanf.c @@ -0,0 +1,86 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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 +#if __STDC__ +#include +#else +#include +#endif + +int +#if __STDC__ +scanf(char const *fmt, ...) +#else +scanf(fmt, va_alist) + char *fmt; + va_dcl +#endif +{ + int ret; + va_list ap; + +#if __STDC__ + va_start(ap, fmt); +#else + va_start(ap); +#endif + ret = __svfscanf(stdin, fmt, ap); + va_end(ap); + return (ret); +} diff --git a/stdio/setbuf.3 b/stdio/setbuf.3 new file mode 100644 index 0000000..bf88ada --- /dev/null +++ b/stdio/setbuf.3 @@ -0,0 +1,205 @@ +.\" Copyright (c) 1980, 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. +.\" +.\" @(#)setbuf.3 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD: src/lib/libc/stdio/setbuf.3,v 1.10 2001/10/01 16:08:59 ru Exp $ +.\" +.Dd June 4, 1993 +.Dt SETBUF 3 +.Os +.Sh NAME +.Nm setbuf , +.Nm setbuffer , +.Nm setlinebuf , +.Nm setvbuf +.Nd stream buffering operations +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In stdio.h +.Ft void +.Fn setbuf "FILE *stream" "char *buf" +.Ft void +.Fn setbuffer "FILE *stream" "char *buf" "int size" +.Ft int +.Fn setlinebuf "FILE *stream" +.Ft int +.Fn setvbuf "FILE *stream" "char *buf" "int mode" "size_t size" +.Sh DESCRIPTION +The three types of buffering available are unbuffered, block buffered, +and line buffered. +When an output stream is unbuffered, information appears on the +destination file or terminal as soon as written; +when it is block buffered many characters are saved up and written as a block; +when it is line buffered characters are saved up until a newline is +output or input is read from any stream attached to a terminal device +(typically stdin). +The function +.Xr fflush 3 +may be used to force the block out early. +(See +.Xr fclose 3 . ) +.Pp +Normally all files are block buffered. +When the first +.Tn I/O +operation occurs on a file, +.Xr malloc 3 +is called, +and an optimally-sized buffer is obtained. +If a stream refers to a terminal +(as +.Em stdout +normally does) it is line buffered. +The standard error stream +.Em stderr +is always unbuffered. +.Pp +The +.Fn setvbuf +function +may be used to alter the buffering behavior of a stream. +The +.Fa mode +parameter must be one of the following three macros: +.Bl -tag -width _IOFBF -offset indent +.It Dv _IONBF +unbuffered +.It Dv _IOLBF +line buffered +.It Dv _IOFBF +fully buffered +.El +.Pp +The +.Fa size +parameter may be given as zero +to obtain deferred optimal-size buffer allocation as usual. +If it is not zero, +then except for unbuffered files, the +.Fa buf +argument should point to a buffer at least +.Fa size +bytes long; +this buffer will be used instead of the current buffer. +(If the +.Fa size +argument +is not zero but +.Fa buf +is +.Dv NULL , +a buffer of the given size will be allocated immediately, +and released on close. +This is an extension to ANSI C; +portable code should use a size of 0 with any +.Dv NULL +buffer.) +.Pp +The +.Fn setvbuf +function may be used at any time, +but may have peculiar side effects +(such as discarding input or flushing output) +if the stream is ``active''. +Portable applications should call it only once on any given stream, +and before any +.Tn I/O +is performed. +.Pp +The other three calls are, in effect, simply aliases for calls to +.Fn setvbuf . +Except for the lack of a return value, the +.Fn setbuf +function is exactly equivalent to the call +.Pp +.Dl "setvbuf(stream, buf, buf ? _IOFBF : _IONBF, BUFSIZ);" +.Pp +The +.Fn setbuffer +function +is the same, except that the size of the buffer is up to the caller, +rather than being determined by the default +.Dv BUFSIZ . +The +.Fn setlinebuf +function +is exactly equivalent to the call: +.Pp +.Dl "setvbuf(stream, (char *)NULL, _IOLBF, 0);" +.Sh RETURN VALUES +The +.Fn setvbuf +function returns 0 on success, or +.Dv EOF +if the request cannot be honored +(note that the stream is still functional in this case). +.Pp +The +.Fn setlinebuf +function returns what the equivalent +.Fn setvbuf +would have returned. +.Sh SEE ALSO +.Xr fclose 3 , +.Xr fopen 3 , +.Xr fread 3 , +.Xr malloc 3 , +.Xr printf 3 , +.Xr puts 3 +.Sh STANDARDS +The +.Fn setbuf +and +.Fn setvbuf +functions +conform to +.St -isoC . +.Sh BUGS +The +.Fn setbuffer +and +.Fn setlinebuf +functions are not portable to versions of +.Bx +before +.Bx 4.2 . +On +.Bx 4.2 +and +.Bx 4.3 +systems, +.Fn setbuf +always uses a suboptimal buffer size and should be avoided. diff --git a/stdio/setbuf.c b/stdio/setbuf.c new file mode 100644 index 0000000..1180f10 --- /dev/null +++ b/stdio/setbuf.c @@ -0,0 +1,68 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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 +#include "local.h" + +void +setbuf(fp, buf) + FILE *fp; + char *buf; +{ + (void) setvbuf(fp, buf, buf ? _IOFBF : _IONBF, BUFSIZ); +} diff --git a/stdio/setbuffer.c b/stdio/setbuffer.c new file mode 100644 index 0000000..1aa3e62 --- /dev/null +++ b/stdio/setbuffer.c @@ -0,0 +1,80 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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 + +void +setbuffer(fp, buf, size) + register FILE *fp; + char *buf; + int size; +{ + + (void)setvbuf(fp, buf, buf ? _IOFBF : _IONBF, size); +} + +/* + * set line buffering + */ +int +setlinebuf(fp) + FILE *fp; +{ + + return (setvbuf(fp, (char *)NULL, _IOLBF, (size_t)0)); +} diff --git a/stdio/setvbuf.c b/stdio/setvbuf.c new file mode 100644 index 0000000..25a8d52 --- /dev/null +++ b/stdio/setvbuf.c @@ -0,0 +1,179 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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 +#include +#include "local.h" + +/* + * Set one of the three kinds of buffering, optionally including + * a buffer. + */ +int +setvbuf(fp, buf, mode, size) + register FILE *fp; + char *buf; + register int mode; + register size_t size; +{ + register int ret, flags; + size_t iosize; + int ttyflag; + + /* + * Verify arguments. The `int' limit on `size' is due to this + * particular implementation. Note, buf and size are ignored + * when setting _IONBF. + */ + if (mode != _IONBF) + if ((mode != _IOFBF && mode != _IOLBF) || (int)size < 0) + return (EOF); + + /* + * Write current buffer, if any. Discard unread input (including + * ungetc data), cancel line buffering, and free old buffer if + * malloc()ed. We also clear any eof condition, as if this were + * a seek. + */ + ret = 0; + (void)__sflush(fp); + if (HASUB(fp)) + FREEUB(fp); + fp->_r = fp->_lbfsize = 0; + flags = fp->_flags; + if (flags & __SMBF) + free((void *)fp->_bf._base); + flags &= ~(__SLBF | __SNBF | __SMBF | __SOPT | __SNPT | __SEOF); + + /* If setting unbuffered mode, skip all the hard work. */ + if (mode == _IONBF) + goto nbf; + + /* + * Find optimal I/O size for seek optimization. This also returns + * a `tty flag' to suggest that we check isatty(fd), but we do not + * care since our caller told us how to buffer. + */ + flags |= __swhatbuf(fp, &iosize, &ttyflag); + if (size == 0) { + buf = NULL; /* force local allocation */ + size = iosize; + } + + /* Allocate buffer if needed. */ + if (buf == NULL) { + if ((buf = malloc(size)) == NULL) { + /* + * Unable to honor user's request. We will return + * failure, but try again with file system size. + */ + ret = EOF; + if (size != iosize) { + size = iosize; + buf = malloc(size); + } + } + if (buf == NULL) { + /* No luck; switch to unbuffered I/O. */ +nbf: + fp->_flags = flags | __SNBF; + fp->_w = 0; + fp->_bf._base = fp->_p = fp->_nbuf; + fp->_bf._size = 1; + return (ret); + } + flags |= __SMBF; + } + + /* + * Kill any seek optimization if the buffer is not the + * right size. + * + * SHOULD WE ALLOW MULTIPLES HERE (i.e., ok iff (size % iosize) == 0)? + */ + if (size != iosize) + flags |= __SNPT; + + /* + * Fix up the FILE fields, and set __cleanup for output flush on + * exit (since we are buffered in some way). + */ + if (mode == _IOLBF) + flags |= __SLBF; + fp->_flags = flags; + fp->_bf._base = fp->_p = (unsigned char *)buf; + fp->_bf._size = size; + /* fp->_lbfsize is still 0 */ + if (flags & __SWR) { + /* + * Begin or continue writing: see __swsetup(). Note + * that __SNBF is impossible (it was handled earlier). + */ + if (flags & __SLBF) { + fp->_w = 0; + fp->_lbfsize = -fp->_bf._size; + } else + fp->_w = size; + } else { + /* begin/continue reading, or stay in intermediate state */ + fp->_w = 0; + } + __cleanup = _cleanup; + + return (ret); +} diff --git a/stdio/snprintf.c b/stdio/snprintf.c new file mode 100644 index 0000000..a9b6315 --- /dev/null +++ b/stdio/snprintf.c @@ -0,0 +1,95 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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 +#if __STDC__ +#include +#else +#include +#endif + +int +#if __STDC__ +snprintf(char *str, size_t n, char const *fmt, ...) +#else +snprintf(str, n, fmt, va_alist) + char *str; + size_t n; + char *fmt; + va_dcl +#endif +{ + int ret; + va_list ap; + FILE f; + + if ((int)n < 1) + return (EOF); +#if __STDC__ + va_start(ap, fmt); +#else + va_start(ap); +#endif + f._flags = __SWR | __SSTR; + f._bf._base = f._p = (unsigned char *)str; + f._bf._size = f._w = n - 1; + ret = vfprintf(&f, fmt, ap); + *f._p = 0; + va_end(ap); + return (ret); +} diff --git a/stdio/sprintf.c b/stdio/sprintf.c new file mode 100644 index 0000000..0cddde0 --- /dev/null +++ b/stdio/sprintf.c @@ -0,0 +1,94 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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 +#if __STDC__ +#include +#else +#include +#endif +#include +#include "local.h" + +int +#if __STDC__ +sprintf(char *str, char const *fmt, ...) +#else +sprintf(str, fmt, va_alist) + char *str; + char *fmt; + va_dcl +#endif +{ + int ret; + va_list ap; + FILE f; + + f._flags = __SWR | __SSTR; + f._bf._base = f._p = (unsigned char *)str; + f._bf._size = f._w = INT_MAX; +#if __STDC__ + va_start(ap, fmt); +#else + va_start(ap); +#endif + ret = vfprintf(&f, fmt, ap); + va_end(ap); + *f._p = 0; + return (ret); +} diff --git a/stdio/sscanf.c b/stdio/sscanf.c new file mode 100644 index 0000000..92ccf56 --- /dev/null +++ b/stdio/sscanf.c @@ -0,0 +1,107 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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 +#include +#if __STDC__ +#include +#else +#include +#endif +#include "local.h" + +/* ARGSUSED */ +static int +eofread(cookie, buf, len) + void *cookie; + char *buf; + int len; +{ + + return (0); +} + +int +#if __STDC__ +sscanf(const char *str, char const *fmt, ...) +#else +sscanf(str, fmt, va_alist) + char *str; + char *fmt; + va_dcl +#endif +{ + int ret; + va_list ap; + FILE f; + + 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; +#if __STDC__ + va_start(ap, fmt); +#else + va_start(ap); +#endif + ret = __svfscanf(&f, fmt, ap); + va_end(ap); + return (ret); +} diff --git a/stdio/stdio.3 b/stdio/stdio.3 new file mode 100644 index 0000000..59fd492 --- /dev/null +++ b/stdio/stdio.3 @@ -0,0 +1,297 @@ +.\" Copyright (c) 1990, 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. +.\" +.\" @(#)stdio.3 8.7 (Berkeley) 4/19/94 +.\" $FreeBSD: src/lib/libc/stdio/stdio.3,v 1.18 2001/10/01 16:08:59 ru Exp $ +.\" +.Dd April 19, 1994 +.Dt STDIO 3 +.Os +.Sh NAME +.Nm stdio +.Nd standard input/output library functions +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In stdio.h +.Vt FILE *stdin ; +.Vt FILE *stdout ; +.Vt FILE *stderr ; +.Sh DESCRIPTION +The standard +.Tn I/O +library provides a simple and efficient buffered stream +.Tn I/O +interface. +Input and output is mapped into logical data streams +and the physical +.Tn I/O +characteristics are concealed. +The functions and macros are listed +below; more information is available from the individual man pages. +.Pp +A stream is associated with an external file (which may be a physical +device) by +.Em opening +a file, which may involve creating a new file. +Creating an +existing file causes its former contents to be discarded. +If a file can support positioning requests (such as a disk file, as opposed +to a terminal) then a +.Em file position indicator +associated with the stream is positioned at the start of the file (byte +zero), unless the file is opened with append mode. +If append mode +is used, the position indicator will be placed at the end-of-file. +The position indicator is maintained by subsequent reads, writes +and positioning requests. +All input occurs as if the characters +were read by successive calls to the +.Xr fgetc 3 +function; all output takes place as if all characters were +written by successive calls to the +.Xr fputc 3 +function. +.Pp +A file is disassociated from a stream by +.Em closing +the file. +Output streams are flushed (any unwritten buffer contents are transferred +to the host environment) before the stream is disassociated from the file. +The value of a pointer to a +.Dv FILE +object is indeterminate (garbage) after a file is closed. +.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 +the +.Xr exit 3 +function is called, all open files are closed (hence all output +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, +.Xr _exit 2 +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. +.Pp +This implementation makes no distinction between +.Dq text +and +.Dq binary +streams. +In effect, all streams are binary. +No translation is performed and no extra padding appears on any stream. +.Pp +At program startup, three streams are predefined and need not be +opened explicitly: +.Bl -bullet -compact -offset indent +.It +.Em standard input +(for reading conventional input), +.It +.Em standard output +(for writing conventional output), and +.It +.Em standard error +(for writing diagnostic output). +.El +These streams are abbreviated +.Em stdin , stdout +and +.Em stderr . +Initially, the standard error stream +is unbuffered; the standard input and output streams are +fully buffered if and only if the streams do not refer to +an interactive or +.Dq terminal +device, as determined by the +.Xr isatty 3 +function. +In fact, +.Em all +freshly-opened streams that refer to terminal devices +default to line buffering, and +pending output to such streams is written automatically +whenever such an input stream is read. +Note that this applies only to +.Dq "true reads" ; +if the read request can be satisfied by existing buffered data, +no automatic flush will occur. +In these cases, +or when a large amount of computation is done after printing +part of a line on an output terminal, it is necessary to +.Xr fflush 3 +the standard output before going off and computing so that the output +will appear. +Alternatively, these defaults may be modified via the +.Xr setvbuf 3 +function. +.Pp +The +.Nm +library is a part of the library +.Nm libc +and routines are automatically loaded as needed by the C compiler. +The +.Tn SYNOPSIS +sections of the following manual pages indicate which include files +are to be used, what the compiler declaration for the function +looks like and which external variables are of interest. +.Pp +The following are defined as macros; +these names may not be re-used +without first removing their current definitions with +.Dv #undef : +.Dv BUFSIZ , +.Dv EOF , +.Dv FILENAME_MAX , +.Dv FOPEN_MAX , +.Dv L_cuserid , +.Dv L_ctermid , +.Dv L_tmpnam , +.Dv NULL , +.Dv P_tmpdir , +.Dv SEEK_CUR , +.Dv SEEK_END , +.Dv SEEK_SET , +.Dv TMP_MAX , +.Dv clearerr , +.Dv feof , +.Dv ferror , +.Dv fileno , +.Dv fropen , +.Dv fwopen , +.Dv getc , +.Dv getchar , +.Dv putc , +.Dv putchar , +.Dv stderr , +.Dv stdin , +.Dv stdout , +.Dv vfscanf . +Function versions of the macro functions +.Fn clearerr , +.Fn feof , +.Fn ferror , +.Fn fileno , +.Fn getc , +.Fn getchar , +.Fn putc , +and +.Fn putchar +exist and will be used if the macro +definitions are explicitly removed. +.Sh SEE ALSO +.Xr close 2 , +.Xr open 2 , +.Xr read 2 , +.Xr write 2 +.Sh BUGS +The standard buffered functions do not interact well with certain other +library and system functions, especially +.Xr vfork 2 . +.Sh STANDARDS +The +.Nm +library conforms to +.St -isoC . +.Sh LIST OF FUNCTIONS +.Bl -column "Description" +.It Sy "Function Description" +.It "asprintf formatted output conversion" +.It "clearerr check and reset stream status" +.It "fclose close a stream" +.It "fdopen stream open functions" +.It "feof check and reset stream status" +.It "ferror check and reset stream status" +.It "fflush flush a stream" +.It "fgetc get next character or word from input stream" +.It "fgetln get a line from a stream" +.It "fgetpos reposition a stream" +.It "fgets get a line from a stream" +.It "fileno check and reset stream status" +.It "fopen stream open functions" +.It "fprintf formatted output conversion" +.It "fpurge flush a stream" +.It "fputc output a character or word to a stream" +.It "fputs output a line to a stream" +.It "fread binary stream input/output" +.It "freopen stream open functions" +.It "fropen open a stream" +.It "fscanf input format conversion" +.It "fseek reposition a stream" +.It "fsetpos reposition a stream" +.It "ftell reposition a stream" +.It "funopen open a stream" +.It "fwopen open a stream" +.It "fwrite binary stream input/output" +.It "getc get next character or word from input stream" +.It "getchar get next character or word from input stream" +.It "gets get a line from a stream" +.It "getw get next character or word from input stream" +.It "mkdtemp create unique temporary file" +.It "mkstemp create unique temporary file" +.It "mktemp create unique temporary file" +.It "perror system error messages" +.It "printf formatted output conversion" +.It "putc output a character or word to a stream" +.It "putchar output a character or word to a stream" +.It "puts output a line to a stream" +.It "putw output a character or word to a stream" +.It "remove remove directory entry" +.It "rewind reposition a stream" +.It "scanf input format conversion" +.It "setbuf stream buffering operations" +.It "setbuffer stream buffering operations" +.It "setlinebuf stream buffering operations" +.It "setvbuf stream buffering operations" +.It "snprintf formatted output conversion" +.It "sprintf formatted output conversion" +.It "sscanf input format conversion" +.It "strerror system error messages" +.It "sys_errlist system error messages" +.It "sys_nerr system error messages" +.It "tempnam temporary file routines" +.It "tmpfile temporary file routines" +.It "tmpnam temporary file routines" +.It "ungetc un-get character from input stream" +.It "vasprintf formatted output conversion" +.It "vfprintf formatted output conversion" +.It "vfscanf input format conversion" +.It "vprintf formatted output conversion" +.It "vscanf input format conversion" +.It "vsnprintf formatted output conversion" +.It "vsprintf formatted output conversion" +.It "vsscanf input format conversion" +.El diff --git a/stdio/stdio.c b/stdio/stdio.c new file mode 100644 index 0000000..dc8a702 --- /dev/null +++ b/stdio/stdio.c @@ -0,0 +1,125 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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 +#include +#include +#include "local.h" + +/* + * Small standard I/O/seek/close functions. + * These maintain the `known seek offset' for seek optimisation. + */ +int +__sread(cookie, buf, n) + void *cookie; + char *buf; + int n; +{ + register FILE *fp = cookie; + register int ret; + + ret = read(fp->_file, buf, n); + /* if the read succeeded, update the current offset */ + if (ret >= 0) + fp->_offset += ret; + else + fp->_flags &= ~__SOFF; /* paranoia */ + return (ret); +} + +int +__swrite(cookie, buf, n) + void *cookie; + char const *buf; + int n; +{ + register FILE *fp = cookie; + + if (fp->_flags & __SAPP) + (void) lseek(fp->_file, (off_t)0, SEEK_END); + fp->_flags &= ~__SOFF; /* in case FAPPEND mode is set */ + return (write(fp->_file, buf, n)); +} + +fpos_t +__sseek(cookie, offset, whence) + void *cookie; + fpos_t offset; + int whence; +{ + register FILE *fp = cookie; + register off_t ret; + + ret = lseek(fp->_file, (off_t)offset, whence); + if (ret == -1L) + fp->_flags &= ~__SOFF; + else { + fp->_flags |= __SOFF; + fp->_offset = ret; + } + return (ret); +} + +int +__sclose(cookie) + void *cookie; +{ + + return (close(((FILE *)cookie)->_file)); +} diff --git a/stdio/tempnam.c b/stdio/tempnam.c new file mode 100644 index 0000000..ebbb84a --- /dev/null +++ b/stdio/tempnam.c @@ -0,0 +1,104 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1988, 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 +#include +#include +#include +#include +#include + +char * +tempnam(dir, pfx) + const char *dir, *pfx; +{ + int sverrno; + char *f, *name; + + if (!(name = malloc(MAXPATHLEN))) + return(NULL); + + if (!pfx) + pfx = "tmp."; + + if (f = getenv("TMPDIR")) { + (void)snprintf(name, MAXPATHLEN, "%s%s%sXXXXXX", f, + *(f + strlen(f) - 1) == '/'? "": "/", pfx); + if (f = mktemp(name)) + return(f); + } + + if (f = (char *)dir) { + (void)snprintf(name, MAXPATHLEN, "%s%s%sXXXXXX", f, + *(f + strlen(f) - 1) == '/'? "": "/", pfx); + if (f = mktemp(name)) + return(f); + } + + f = P_tmpdir; + (void)snprintf(name, MAXPATHLEN, "%s%sXXXXXX", f, pfx); + if (f = mktemp(name)) + return(f); + + f = _PATH_TMP; + (void)snprintf(name, MAXPATHLEN, "%s%sXXXXXX", f, pfx); + if (f = mktemp(name)) + return(f); + + sverrno = errno; + free(name); + errno = sverrno; + return(NULL); +} diff --git a/stdio/tmpfile.c b/stdio/tmpfile.c new file mode 100644 index 0000000..2924a9e --- /dev/null +++ b/stdio/tmpfile.c @@ -0,0 +1,97 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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 +#include +#include +#include +#include +#include + +FILE * +tmpfile() +{ + sigset_t set, oset; + FILE *fp; + int fd, sverrno; +#define TRAILER "tmp.XXXXXX" + char buf[sizeof(_PATH_TMP) + sizeof(TRAILER)]; + + (void)memcpy(buf, _PATH_TMP, sizeof(_PATH_TMP) - 1); + (void)memcpy(buf + sizeof(_PATH_TMP) - 1, TRAILER, sizeof(TRAILER)); + + sigfillset(&set); + (void)sigprocmask(SIG_BLOCK, &set, &oset); + + fd = mkstemp(buf); + if (fd != -1) + (void)unlink(buf); + + (void)sigprocmask(SIG_SETMASK, &oset, NULL); + + if (fd == -1) + return (NULL); + + if ((fp = fdopen(fd, "w+")) == NULL) { + sverrno = errno; + (void)close(fd); + errno = sverrno; + return (NULL); + } + return (fp); +} diff --git a/stdio/tmpnam.3 b/stdio/tmpnam.3 new file mode 100644 index 0000000..fa4c1e9 --- /dev/null +++ b/stdio/tmpnam.3 @@ -0,0 +1,229 @@ +.\" Copyright (c) 1988, 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. +.\" +.\" @(#)tmpnam.3 8.2 (Berkeley) 11/17/93 +.\" $FreeBSD: src/lib/libc/stdio/tmpnam.3,v 1.10 2001/10/01 16:08:59 ru Exp $ +.\" +.Dd November 17, 1993 +.Dt TMPFILE 3 +.Os +.Sh NAME +.Nm tempnam , +.Nm tmpfile , +.Nm tmpnam +.Nd temporary file routines +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In stdio.h +.Ft FILE * +.Fn tmpfile void +.Ft char * +.Fn tmpnam "char *str" +.Ft char * +.Fn tempnam "const char *tmpdir" "const char *prefix" +.Sh DESCRIPTION +The +.Fn tmpfile +function +returns a pointer to a stream associated with a file descriptor returned +by the routine +.Xr mkstemp 3 . +The created file is unlinked before +.Fn tmpfile +returns, causing the file to be automatically deleted when the last +reference to it is closed. +The file is opened with the access value +.Ql w+ . +The file is created in the directory determined by the environment variable +.Ev TMPDIR +if set. +The default location if +.Ev TMPDIR +is not set is +.Pa /tmp . +.Pp +The +.Fn tmpnam +function +returns a pointer to a file name, in the +.Dv P_tmpdir +directory, which +did not reference an existing file at some indeterminate point in the +past. +.Dv P_tmpdir +is defined in the include file +.Aq Pa stdio.h . +If the argument +.Fa str +is +.Pf non- Dv NULL , +the file name is copied to the buffer it references. +Otherwise, the file name is copied to a static buffer. +In either case, +.Fn tmpnam +returns a pointer to the file name. +.Pp +The buffer referenced by +.Fa str +is expected to be at least +.Dv L_tmpnam +bytes in length. +.Dv L_tmpnam +is defined in the include file +.Aq Pa stdio.h . +.Pp +The +.Fn tempnam +function +is similar to +.Fn tmpnam , +but provides the ability to specify the directory which will +contain the temporary file and the file name prefix. +.Pp +The environment variable +.Ev TMPDIR +(if set), the argument +.Fa tmpdir +(if +.Pf non- Dv NULL ) , +the directory +.Dv P_tmpdir , +and the directory +.Pa /tmp +are tried, in the listed order, as directories in which to store the +temporary file. +.Pp +The argument +.Fa prefix , +if +.Pf non- Dv NULL , +is used to specify a file name prefix, which will be the +first part of the created file name. +.Fn Tempnam +allocates memory in which to store the file name; the returned pointer +may be used as a subsequent argument to +.Xr free 3 . +.Sh RETURN VALUES +The +.Fn tmpfile +function +returns a pointer to an open file stream on success, and a +.Dv NULL +pointer +on error. +.Pp +The +.Fn tmpnam +and +.Fn tempfile +functions +return a pointer to a file name on success, and a +.Dv NULL +pointer +on error. +.Sh ERRORS +The +.Fn tmpfile +function +may fail and set the global variable +.Va errno +for any of the errors specified for the library functions +.Xr fdopen 3 +or +.Xr mkstemp 3 . +.Pp +The +.Fn tmpnam +function +may fail and set +.Va errno +for any of the errors specified for the library function +.Xr mktemp 3 . +.Pp +The +.Fn tempnam +function +may fail and set +.Va errno +for any of the errors specified for the library functions +.Xr malloc 3 +or +.Xr mktemp 3 . +.Sh SEE ALSO +.Xr mkstemp 3 , +.Xr mktemp 3 +.Sh STANDARDS +The +.Fn tmpfile +and +.Fn tmpnam +functions +conform to +.St -isoC . +.Sh BUGS +These interfaces are provided for System V and +.Tn ANSI +compatibility only. +The +.Xr mkstemp 3 +interface is strongly preferred. +.Pp +There are four important problems with these interfaces (as well as +with the historic +.Xr mktemp 3 +interface). +First, there is an obvious race between file name selection and file +creation and deletion. +Second, most historic implementations provide only a limited number +of possible temporary file names (usually 26) before file names will +start being recycled. +Third, the System V implementations of these functions (and of +.Xr mktemp 3 ) +use the +.Xr access 2 +function to determine whether or not the temporary file may be created. +This has obvious ramifications for setuid or setgid programs, complicating +the portable use of these interfaces in such programs. +Finally, there is no specification of the permissions with which the +temporary files are created. +.Pp +This implementation does not have these flaws, but portable software +cannot depend on that. +In particular, the +.Fn tmpfile +interface should not be used in software expected to be used on other systems +if there is any possibility that the user does not wish the temporary file to +be publicly readable and writable. diff --git a/stdio/tmpnam.c b/stdio/tmpnam.c new file mode 100644 index 0000000..ba8a60b --- /dev/null +++ b/stdio/tmpnam.c @@ -0,0 +1,83 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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 + +#include +#include +#include + +char * +tmpnam(s) + char *s; +{ + static u_long tmpcount; + static char *buf = NULL; + + if( buf == NULL ) { + buf = malloc(L_tmpnam); + if( buf == NULL ) + return NULL; + } + + if (s == NULL) + s = buf; + (void)snprintf(s, L_tmpnam, "%stmp.%lu.XXXXXX", P_tmpdir, tmpcount); + ++tmpcount; + return (mktemp(s)); +} diff --git a/stdio/ungetc.3 b/stdio/ungetc.3 new file mode 100644 index 0000000..adb91fa --- /dev/null +++ b/stdio/ungetc.3 @@ -0,0 +1,101 @@ +.\" 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. +.\" +.\" @(#)ungetc.3 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD: src/lib/libc/stdio/ungetc.3,v 1.12 2001/10/01 16:08:59 ru Exp $ +.\" +.Dd June 4, 1993 +.Dt UNGETC 3 +.Os +.Sh NAME +.Nm ungetc +.Nd un-get character from input stream +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In stdio.h +.Ft int +.Fn ungetc "int c" "FILE *stream" +.Sh DESCRIPTION +The +.Fn ungetc +function pushes the character +.Fa c +(converted to an unsigned char) +back onto the input stream pointed to by +.Fa stream . +The pushed-back 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 ( fseek 3 , +.Xr fsetpos 3 , +or +.Xr rewind 3 ) +will discard the pushed back characters. +.Pp +One character of push-back is guaranteed, +but as long as there is sufficient memory, +an effectively infinite amount of pushback is allowed. +.Pp +If a character is successfully pushed-back, +the end-of-file indicator for the stream is cleared. +The file-position indicator is decremented +by each successful call to +.Fn ungetc ; +if its value was 0 before a call, its value is unspecified after +the call. +.Sh RETURN VALUES +The +.Fn ungetc +function returns the character pushed-back after the conversion, +or +.Dv EOF +if the operation fails. +If the value of the argument +.Fa c +character equals +.Dv EOF , +the operation will fail and the stream will remain unchanged. +.Sh SEE ALSO +.Xr fseek 3 , +.Xr getc 3 , +.Xr setvbuf 3 +.Sh STANDARDS +The +.Fn ungetc +function conforms to +.St -isoC . diff --git a/stdio/ungetc.c b/stdio/ungetc.c new file mode 100644 index 0000000..ab92783 --- /dev/null +++ b/stdio/ungetc.c @@ -0,0 +1,167 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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 +#include +#include +#include "local.h" + +/* + * Expand the ungetc buffer `in place'. That is, adjust fp->_p when + * the buffer moves, so that it points the same distance from the end, + * and move the bytes in the buffer around as necessary so that they + * are all at the end (stack-style). + */ +static int +__submore(fp) + register FILE *fp; +{ + register int i; + register unsigned char *p; + + if (fp->_ub._base == fp->_ubuf) { + /* + * Get a new buffer (rather than expanding the old one). + */ + if ((p = malloc((size_t)BUFSIZ)) == NULL) + return (EOF); + fp->_ub._base = p; + fp->_ub._size = BUFSIZ; + p += BUFSIZ - sizeof(fp->_ubuf); + for (i = sizeof(fp->_ubuf); --i >= 0;) + p[i] = fp->_ubuf[i]; + fp->_p = p; + return (0); + } + i = fp->_ub._size; + p = realloc(fp->_ub._base, i << 1); + if (p == NULL) + return (EOF); + /* no overlap (hence can use memcpy) because we doubled the size */ + (void)memcpy((void *)(p + i), (void *)p, (size_t)i); + fp->_p = p + i; + fp->_ub._base = p; + fp->_ub._size = i << 1; + return (0); +} + +int +ungetc(c, fp) + int c; + register FILE *fp; +{ + if (c == EOF) + return (EOF); + if (!__sdidinit) + __sinit(); + if ((fp->_flags & __SRD) == 0) { + /* + * Not already reading: no good unless reading-and-writing. + * Otherwise, flush any current write stuff. + */ + if ((fp->_flags & __SRW) == 0) + return (EOF); + if (fp->_flags & __SWR) { + if (__sflush(fp)) + return (EOF); + fp->_flags &= ~__SWR; + fp->_w = 0; + fp->_lbfsize = 0; + } + fp->_flags |= __SRD; + } + c = (unsigned char)c; + + /* + * If we are in the middle of ungetc'ing, just continue. + * This may require expanding the current ungetc buffer. + */ + if (HASUB(fp)) { + if (fp->_r >= fp->_ub._size && __submore(fp)) + return (EOF); + *--fp->_p = c; + fp->_r++; + return (c); + } + fp->_flags &= ~__SEOF; + + /* + * If we can handle this by simply backing up, do so, + * but never replace the original character. + * (This makes sscanf() work when scanning `const' data.) + */ + if (fp->_bf._base != NULL && fp->_p > fp->_bf._base && + fp->_p[-1] == c) { + fp->_p--; + fp->_r++; + return (c); + } + + /* + * Create an ungetc buffer. + * Initially, we will use the `reserve' buffer. + */ + fp->_ur = fp->_r; + fp->_up = fp->_p; + fp->_ub._base = fp->_ubuf; + fp->_ub._size = sizeof(fp->_ubuf); + fp->_ubuf[sizeof(fp->_ubuf) - 1] = c; + fp->_p = &fp->_ubuf[sizeof(fp->_ubuf) - 1]; + fp->_r = 1; + return (c); +} diff --git a/stdio/vasprintf.c b/stdio/vasprintf.c new file mode 100644 index 0000000..0937701 --- /dev/null +++ b/stdio/vasprintf.c @@ -0,0 +1,65 @@ +/* $OpenBSD: vasprintf.c,v 1.4 1998/06/21 22:13:47 millert Exp $ */ + +/* + * Copyright (c) 1997 Todd C. Miller + * 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. 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 ARE 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 + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#if defined(LIBC_RCS) && !defined(lint) +static char rcsid[] = "$FreeBSD: src/lib/libc/stdio/vasprintf.c,v 1.11 1999/08/28 00:01:19 peter Exp $"; +#endif /* LIBC_RCS and not lint */ + +#include +#include +#include + +int +vasprintf(str, fmt, ap) + char **str; + const char *fmt; + _BSD_VA_LIST_ ap; +{ + int ret; + FILE f; + + 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 NULL */ + ret = vfprintf(&f, fmt, ap); + *f._p = '\0'; + f._bf._base = reallocf(f._bf._base, f._bf._size + 1); + if (f._bf._base == NULL) { + errno = ENOMEM; + ret = -1; + } + *str = (char *)f._bf._base; + return (ret); +} diff --git a/stdio/vfprintf.c b/stdio/vfprintf.c new file mode 100644 index 0000000..d1cf00b --- /dev/null +++ b/stdio/vfprintf.c @@ -0,0 +1,1663 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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. + */ + +/* + * Actual printf innards. + * + * This code is large and complicated... + */ + +#include + +#include +#include +#include +#include +#include + +#if __STDC__ +#include +#else +#include +#endif + +#include "local.h" +#include "fvwrite.h" + +/* Define FLOATING_POINT to get floating point. */ +#define FLOATING_POINT +union arg { + int intarg; + unsigned int uintarg; + long longarg; + unsigned long ulongarg; + quad_t quadarg; + u_quad_t uquadarg; + void *pvoidarg; + char *pchararg; + short *pshortarg; + int *pintarg; + long *plongarg; + quad_t *pquadarg; +#ifdef FLOATING_POINT + double doublearg; + long double longdoublearg; +#endif +#ifdef ALTIVEC + unsigned char vuchararg[16]; + signed char vchararg[16]; + unsigned short vushortarg[8]; + signed short vshortarg[8]; + unsigned int vuintarg[4]; + signed int vintarg[4]; + float vfloatarg[4]; +#endif +}; + +static int __sprint __P((FILE *, struct __suio *)); +static int __sbprintf __P((FILE *, const char *, va_list)); +static char * __ultoa __P((u_long, char *, int, int, char *)); +static char * __uqtoa __P((u_quad_t, char *, int, int, char *)); +static void __find_arguments __P((const char *, va_list, union arg **)); +static void __grow_type_table __P((int, unsigned char **, int *)); + + /* + * Get the argument indexed by nextarg. If the argument table is + * built, use it to get the argument. If its not, get the next + * argument (and arguments must be gotten sequentially). + */ +#define GETARG(type) \ + ((argtable != NULL) ? *((type*)(&argtable[nextarg++])) : \ + (nextarg++, va_arg(ap, type))) + +#ifdef ALTIVEC +static void getvec(union arg *dst, const union arg *argtable, int nextarg, va_list ap) +{ + vector unsigned char tmp; + + tmp = GETARG(vector unsigned char); + memcpy( dst, &tmp, 16 ); +} + +#endif + +/* + * Flush out all the vectors defined by the given uio, + * then reset it so that it can be reused. + */ +static int +__sprint(fp, uio) + FILE *fp; + register struct __suio *uio; +{ + register int err; + + if (uio->uio_resid == 0) { + uio->uio_iovcnt = 0; + return (0); + } + err = __sfvwrite(fp, uio); + uio->uio_resid = 0; + uio->uio_iovcnt = 0; + return (err); +} + +/* + * Helper function for `fprintf to unbuffered unix file': creates a + * temporary buffer. We only work on write-only files; this avoids + * worries about ungetc buffers and so forth. + */ +static int +__sbprintf(fp, fmt, ap) + register FILE *fp; + const char *fmt; + va_list ap; +{ + int ret; + FILE fake; + unsigned char buf[BUFSIZ]; + + /* copy the important variables */ + fake._flags = fp->_flags & ~__SNBF; + fake._file = fp->_file; + fake._cookie = fp->_cookie; + fake._write = fp->_write; + + /* set up the buffer */ + fake._bf._base = fake._p = buf; + fake._bf._size = fake._w = sizeof(buf); + fake._lbfsize = 0; /* not actually used, but Just In Case */ + + /* do the work, then copy any error status */ + ret = vfprintf(&fake, fmt, ap); + if (ret >= 0 && fflush(&fake)) + ret = EOF; + if (fake._flags & __SERR) + fp->_flags |= __SERR; + return (ret); +} + +/* + * Macros for converting digits to letters and vice versa + */ +#define to_digit(c) ((c) - '0') +#define is_digit(c) ((unsigned)to_digit(c) <= 9) +#define to_char(n) ((n) + '0') + +/* + * Convert an unsigned long to ASCII for printf purposes, returning + * a pointer to the first character of the string representation. + * Octal numbers can be forced to have a leading zero; hex numbers + * use the given digits. + */ +static char * +__ultoa(val, endp, base, octzero, xdigs) + register u_long val; + char *endp; + int base, octzero; + char *xdigs; +{ + register char *cp = endp; + register long sval; + + /* + * Handle the three cases separately, in the hope of getting + * better/faster code. + */ + switch (base) { + case 10: + if (val < 10) { /* many numbers are 1 digit */ + *--cp = to_char(val); + return (cp); + } + /* + * On many machines, unsigned arithmetic is harder than + * signed arithmetic, so we do at most one unsigned mod and + * divide; this is sufficient to reduce the range of + * the incoming value to where signed arithmetic works. + */ + if (val > LONG_MAX) { + *--cp = to_char(val % 10); + sval = val / 10; + } else + sval = val; + do { + *--cp = to_char(sval % 10); + sval /= 10; + } while (sval != 0); + break; + + case 8: + do { + *--cp = to_char(val & 7); + val >>= 3; + } while (val); + if (octzero && *cp != '0') + *--cp = '0'; + break; + + case 16: + do { + *--cp = xdigs[val & 15]; + val >>= 4; + } while (val); + break; + + default: /* oops */ + abort(); + } + return (cp); +} + +/* Identical to __ultoa, but for quads. */ +static char * +__uqtoa(val, endp, base, octzero, xdigs) + register u_quad_t val; + char *endp; + int base, octzero; + char *xdigs; +{ + register char *cp = endp; + register quad_t sval; + + /* quick test for small values; __ultoa is typically much faster */ + /* (perhaps instead we should run until small, then call __ultoa?) */ + if (val <= ULONG_MAX) + return (__ultoa((u_long)val, endp, base, octzero, xdigs)); + switch (base) { + case 10: + if (val < 10) { + *--cp = to_char(val % 10); + return (cp); + } + if (val > QUAD_MAX) { + *--cp = to_char(val % 10); + sval = val / 10; + } else + sval = val; + do { + *--cp = to_char(sval % 10); + sval /= 10; + } while (sval != 0); + break; + + case 8: + do { + *--cp = to_char(val & 7); + val >>= 3; + } while (val); + if (octzero && *cp != '0') + *--cp = '0'; + break; + + case 16: + do { + *--cp = xdigs[val & 15]; + val >>= 4; + } while (val); + break; + + default: + abort(); + } + return (cp); +} + +#ifdef FLOATING_POINT +#include +#include "floatio.h" + +#define BUF (MAXEXP+MAXFRACT+1) /* + decimal point */ +#define DEFPREC 6 + +static char *cvt __P((double, int, int, char *, int *, int, int *, char **)); +static int exponent __P((char *, int, int)); + +#if defined(__APPLE__) +/* + * We don't want to be dependent on any libm symbols so use the versions in Libc + */ + +#undef isinf +#undef isnan + +extern int isnan(double); +extern int isinf(double); + +#endif /* __APPLE __ */ + +#else /* no FLOATING_POINT */ + +#define BUF 68 + +#endif /* FLOATING_POINT */ + +#define STATIC_ARG_TBL_SIZE 8 /* Size of static argument table. */ + +/* + * Flags used during conversion. + */ +#define ALT 0x001 /* alternate form */ +#define HEXPREFIX 0x002 /* add 0x or 0X prefix */ +#define LADJUST 0x004 /* left adjustment */ +#define LONGDBL 0x008 /* long double */ +#define LONGINT 0x010 /* long integer */ +#define QUADINT 0x020 /* quad integer */ +#define SHORTINT 0x040 /* short integer */ +#define ZEROPAD 0x080 /* zero (as opposed to blank) pad */ +#define FPT 0x100 /* Floating point number */ +#define VECTOR 0x200 /* Altivec vector */ +int +vfprintf(fp, fmt0, ap) + FILE *fp; + const char *fmt0; + va_list ap; +{ + register char *fmt; /* format string */ + register int ch; /* character from fmt */ + register int n, n2; /* handy integer (short term usage) */ + register char *cp; /* handy char pointer (short term usage) */ + register struct __siov *iovp;/* for PRINT macro */ + register int flags; /* flags as above */ + int ret; /* return value accumulator */ + int width; /* width from format (%8d), or 0 */ + int prec; /* precision from format (%.3d), or -1 */ + char sign; /* sign prefix (' ', '+', '-', or \0) */ +#ifdef FLOATING_POINT + char softsign; /* temporary negative sign for floats */ + double _double = 0; /* double precision arguments %[eEfgG] */ + int expt; /* integer value of exponent */ + int expsize = 0; /* character count for expstr */ + int ndig; /* actual number of digits returned by cvt */ + char expstr[7]; /* buffer for exponent string */ + char *dtoaresult; /* buffer allocated by dtoa */ +#endif +#ifdef ALTIVEC + union arg vval; /* Vector argument. */ + char *pct; /* Pointer to '%' at beginning of specifier. */ + char vsep; /* Vector separator character. */ +#endif + u_long ulval = 0; /* integer arguments %[diouxX] */ + u_quad_t uqval = 0; /* %q integers */ + int base; /* base for [diouxX] conversion */ + int dprec; /* a copy of prec if [diouxX], 0 otherwise */ + int realsz; /* field size expanded by dprec, sign, etc */ + int size; /* size of converted field or string */ + int prsize; /* max size of printed field */ + char *xdigs = NULL; /* digits for [xX] conversion */ +#define NIOV 8 + struct __suio uio; /* output information: summary */ + struct __siov iov[NIOV];/* ... and individual io vectors */ + char buf[BUF]; /* space for %c, %[diouxX], %[eEfgG] */ + char ox[2]; /* space for 0x hex-prefix */ + union arg *argtable; /* args, built due to positional arg */ + union arg statargtable [STATIC_ARG_TBL_SIZE]; + int nextarg; /* 1-based argument index */ + va_list orgap; /* original argument pointer */ + + /* + * Choose PADSIZE to trade efficiency vs. size. If larger printf + * fields occur frequently, increase PADSIZE and make the initialisers + * below longer. + */ +#define PADSIZE 16 /* pad chunk size */ + static char blanks[PADSIZE] = + {' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '}; + static char zeroes[PADSIZE] = + {'0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'}; + + /* + * BEWARE, these `goto error' on error, and PAD uses `n'. + */ +#define PRINT(ptr, len) { \ + iovp->iov_base = (ptr); \ + iovp->iov_len = (len); \ + uio.uio_resid += (len); \ + iovp++; \ + if (++uio.uio_iovcnt >= NIOV) { \ + if (__sprint(fp, &uio)) \ + goto error; \ + iovp = iov; \ + } \ +} +#define PAD(howmany, with) { \ + if ((n = (howmany)) > 0) { \ + while (n > PADSIZE) { \ + PRINT(with, PADSIZE); \ + n -= PADSIZE; \ + } \ + PRINT(with, n); \ + } \ +} +#define FLUSH() { \ + if (uio.uio_resid && __sprint(fp, &uio)) \ + goto error; \ + uio.uio_iovcnt = 0; \ + iovp = iov; \ +} + + + /* + * To extend shorts properly, we need both signed and unsigned + * argument extraction methods. + */ +#define SARG() \ + (flags&LONGINT ? GETARG(long) : \ + flags&SHORTINT ? (long)(short)GETARG(int) : \ + (long)GETARG(int)) +#define UARG() \ + (flags&LONGINT ? GETARG(u_long) : \ + flags&SHORTINT ? (u_long)(u_short)GETARG(int) : \ + (u_long)GETARG(u_int)) + + /* + * Get * arguments, including the form *nn$. Preserve the nextarg + * that the argument can be gotten once the type is determined. + */ +#define GETASTER(val) \ + n2 = 0; \ + cp = fmt; \ + while (is_digit(*cp)) { \ + n2 = 10 * n2 + to_digit(*cp); \ + cp++; \ + } \ + if (*cp == '$') { \ + int hold = nextarg; \ + if (argtable == NULL) { \ + argtable = statargtable; \ + __find_arguments (fmt0, orgap, &argtable); \ + } \ + nextarg = n2; \ + val = GETARG (int); \ + nextarg = hold; \ + fmt = ++cp; \ + } else { \ + val = GETARG (int); \ + } +#ifdef FLOATING_POINT + dtoaresult = NULL; +#endif + /* FLOCKFILE(fp); */ + /* sorry, fprintf(read_only_file, "") returns EOF, not 0 */ + if (cantwrite(fp)) { + /* FUNLOCKFILE(fp); */ + return (EOF); + } + + /* optimise fprintf(stderr) (and other unbuffered Unix files) */ + if ((fp->_flags & (__SNBF|__SWR|__SRW)) == (__SNBF|__SWR) && + fp->_file >= 0) { + /* FUNLOCKFILE(fp); */ + return (__sbprintf(fp, fmt0, ap)); + } + + fmt = (char *)fmt0; + argtable = NULL; + nextarg = 1; + orgap = ap; + uio.uio_iov = iovp = iov; + uio.uio_resid = 0; + uio.uio_iovcnt = 0; + ret = 0; + + /* + * Scan the format for conversions (`%' character). + */ + for (;;) { + for (cp = fmt; (ch = *fmt) != '\0' && ch != '%'; fmt++) + /* void */; + if ((n = fmt - cp) != 0) { + if ((unsigned)ret + n > INT_MAX) { + ret = EOF; + goto error; + } + PRINT(cp, n); + ret += n; + } + if (ch == '\0') + goto done; +#ifdef ALTIVEC + pct = fmt; +#endif + fmt++; /* skip over '%' */ + + flags = 0; + dprec = 0; + width = 0; + prec = -1; + sign = '\0'; +#ifdef ALTIVEC + vsep = 'X'; /* Illegal value, changed to defaults later. */ +#endif + +rflag: ch = *fmt++; +reswitch: switch (ch) { + case ' ': + /* + * ``If the space and + flags both appear, the space + * flag will be ignored.'' + * -- ANSI X3J11 + */ + if (!sign) + sign = ' '; + goto rflag; + case '#': + flags |= ALT; + goto rflag; +#ifdef ALTIVEC + case ',': case ';': case ':': case '_': + vsep = ch; + goto rflag; +#endif + case '*': + /* + * ``A negative field width argument is taken as a + * - flag followed by a positive field width.'' + * -- ANSI X3J11 + * They don't exclude field widths read from args. + */ + GETASTER (width); + if (width >= 0) + goto rflag; + width = -width; + /* FALLTHROUGH */ + case '-': + flags |= LADJUST; + goto rflag; + case '+': + sign = '+'; + goto rflag; + case '.': + if ((ch = *fmt++) == '*') { + GETASTER (n); + prec = n < 0 ? -1 : n; + goto rflag; + } + n = 0; + while (is_digit(ch)) { + n = 10 * n + to_digit(ch); + ch = *fmt++; + } + prec = n < 0 ? -1 : n; + goto reswitch; + case '0': + /* + * ``Note that 0 is taken as a flag, not as the + * beginning of a field width.'' + * -- ANSI X3J11 + */ + flags |= ZEROPAD; + goto rflag; + case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + n = 0; + do { + n = 10 * n + to_digit(ch); + ch = *fmt++; + } while (is_digit(ch)); + if (ch == '$') { + nextarg = n; + if (argtable == NULL) { + argtable = statargtable; + __find_arguments (fmt0, orgap, + &argtable); + } + goto rflag; + } + width = n; + goto reswitch; +#ifdef FLOATING_POINT + case 'L': + flags |= LONGDBL; + goto rflag; +#endif +#ifdef ALTIVEC + case 'v': + flags |= VECTOR; + goto rflag; +#endif + case 'h': + flags |= SHORTINT; + goto rflag; + case 'l': + if (flags & LONGINT) + flags |= QUADINT; + else + flags |= LONGINT; + goto rflag; + case 'q': + flags |= QUADINT; + goto rflag; + case 'z': + if (sizeof(size_t) == sizeof(long)) + flags |= LONGINT; + if (sizeof(size_t) == sizeof(quad_t)) + flags |= QUADINT; + goto rflag; + case 'c': +#ifdef ALTIVEC + if (flags & VECTOR) { + getvec(&vval, argtable, nextarg, ap); + nextarg++; + break; + } +#endif + *(cp = buf) = GETARG(int); + size = 1; + sign = '\0'; + break; + case 'D': + flags |= LONGINT; + /*FALLTHROUGH*/ + case 'd': + case 'i': +#ifdef ALTIVEC + if (flags & VECTOR) { + getvec(&vval, argtable, nextarg, ap); + break; + } else +#endif + if (flags & QUADINT) { + uqval = GETARG(quad_t); + if ((quad_t)uqval < 0) { + uqval = -uqval; + sign = '-'; + } + } else { + ulval = SARG(); + if ((long)ulval < 0) { + ulval = -ulval; + sign = '-'; + } + } + base = 10; + goto number; +#ifdef FLOATING_POINT + case 'e': + case 'E': + case 'f': +#ifdef ALTIVEC + if (flags & VECTOR) { + flags |= FPT; + getvec(&vval, argtable, nextarg, ap); + nextarg++; + break; + } +#endif + goto fp_begin; + case 'g': + case 'G': +#ifdef ALTIVEC + if (flags & VECTOR) { + flags |= FPT; + getvec(&vval, argtable, nextarg, ap); + nextarg++; + break; + } +#endif + if (prec == 0) + prec = 1; +fp_begin: if (prec == -1) + prec = DEFPREC; + if (flags & LONGDBL) + /* XXX this loses precision. */ + _double = (double)GETARG(long double); + else + _double = GETARG(double); + /* do this before tricky precision changes */ + if (isinf(_double)) { + if (_double < 0) + sign = '-'; + cp = "Inf"; + size = 3; + break; + } + if (isnan(_double)) { + cp = "NaN"; + size = 3; + break; + } + flags |= FPT; + if (dtoaresult != NULL) { + free(dtoaresult); + dtoaresult = NULL; + } + cp = cvt(_double, prec, flags, &softsign, + &expt, ch, &ndig, &dtoaresult); + if (ch == 'g' || ch == 'G') { + if (expt <= -4 || expt > prec) + ch = (ch == 'g') ? 'e' : 'E'; + else + ch = 'g'; + } + if (ch <= 'e') { /* 'e' or 'E' fmt */ + --expt; + expsize = exponent(expstr, expt, ch); + size = expsize + ndig; + if (ndig > 1 || flags & ALT) + ++size; + } else if (ch == 'f') { /* f fmt */ + if (expt > 0) { + size = expt; + if (prec || flags & ALT) + size += prec + 1; + } else /* "0.X" */ + size = prec + 2; + } else if (expt >= ndig) { /* fixed g fmt */ + size = expt; + if (flags & ALT) + ++size; + } else + size = ndig + (expt > 0 ? + 1 : 2 - expt); + + if (softsign) + sign = '-'; + break; +#endif /* FLOATING_POINT */ + case 'n': + if (flags & QUADINT) + *GETARG(quad_t *) = ret; + else if (flags & LONGINT) + *GETARG(long *) = ret; + else if (flags & SHORTINT) + *GETARG(short *) = ret; + else + *GETARG(int *) = ret; + continue; /* no output */ + case 'O': + flags |= LONGINT; + /*FALLTHROUGH*/ + case 'o': +#ifdef ALTIVEC + if (flags & VECTOR) { + getvec(&vval, argtable, nextarg, ap); + nextarg++; + break; + } else +#endif + if (flags & QUADINT) + uqval = GETARG(u_quad_t); + else + ulval = UARG(); + base = 8; + goto nosign; + case 'p': + /* + * ``The argument shall be a pointer to void. The + * value of the pointer is converted to a sequence + * of printable characters, in an implementation- + * defined manner.'' + * -- ANSI X3J11 + */ +#ifdef ALTIVEC + if (flags & VECTOR) { + getvec(&vval, argtable, nextarg, ap); + nextarg++; + break; + } +#endif + ulval = (u_long)GETARG(void *); + base = 16; + xdigs = "0123456789abcdef"; + flags = (flags & ~QUADINT) | HEXPREFIX; + ch = 'x'; + goto nosign; + case 's': + if ((cp = GETARG(char *)) == NULL) + cp = "(null)"; + if (prec >= 0) { + /* + * can't use strlen; can only look for the + * NUL in the first `prec' characters, and + * strlen() will go further. + */ + char *p = memchr(cp, 0, (size_t)prec); + + if (p != NULL) { + size = p - cp; + if (size > prec) + size = prec; + } else + size = prec; + } else + size = strlen(cp); + sign = '\0'; + break; + case 'U': + flags |= LONGINT; + /*FALLTHROUGH*/ + case 'u': +#ifdef ALTIVEC + if (flags & VECTOR) { + getvec(&vval, argtable, nextarg, ap); + nextarg++; + break; + } else +#endif + if (flags & QUADINT) + uqval = GETARG(u_quad_t); + else + ulval = UARG(); + base = 10; + goto nosign; + case 'X': + xdigs = "0123456789ABCDEF"; + goto hex; + case 'x': + xdigs = "0123456789abcdef"; +hex: +#ifdef ALTIVEC + if (flags & VECTOR) { + getvec(&vval, argtable, nextarg, ap); + nextarg++; + break; + } else +#endif + if (flags & QUADINT) + uqval = GETARG(u_quad_t); + else + ulval = UARG(); + base = 16; + /* leading 0x/X only if non-zero */ + if (flags & ALT && + (flags & QUADINT ? uqval != 0 : ulval != 0)) + flags |= HEXPREFIX; + + /* unsigned conversions */ +nosign: sign = '\0'; + /* + * ``... diouXx conversions ... if a precision is + * specified, the 0 flag will be ignored.'' + * -- ANSI X3J11 + */ +number: if ((dprec = prec) >= 0) + flags &= ~ZEROPAD; + + /* + * ``The result of converting a zero value with an + * explicit precision of zero is no characters.'' + * -- ANSI X3J11 + */ + cp = buf + BUF; + if (flags & QUADINT) { + if (uqval != 0 || prec != 0) + cp = __uqtoa(uqval, cp, base, + flags & ALT, xdigs); + } else { + if (ulval != 0 || prec != 0) + cp = __ultoa(ulval, cp, base, + flags & ALT, xdigs); + } + size = buf + BUF - cp; + break; + default: /* "%?" prints ?, unless ? is NUL */ + if (ch == '\0') + goto done; + /* pretend it was %c with argument ch */ + cp = buf; + *cp = ch; + size = 1; + sign = '\0'; + break; + } + +#ifdef ALTIVEC + if (flags & VECTOR) { + /* + * Do the minimum amount of work necessary to construct + * a format specifier that can be used to recursively + * call vfprintf() for each element in the vector. + */ + int i, j; /* Counter. */ + int vcnt; /* Number of elements in vector. */ + char *vfmt; /* Pointer to format specifier. */ + char vfmt_buf[32]; /* Static buffer for format spec. */ + int vwidth = 0; /* Width specified via '*'. */ + int vprec = 0; /* Precision specified via '*'. */ + union { /* Element. */ + int i; + float f; + } velm; + char *vstr; /* Used for asprintf(). */ + int vlen; /* Length returned by asprintf(). */ + + /* + * Set vfmt. If vfmt_buf may not be big enough, + * malloc() space, taking care to free it later. + */ + if (&fmt[-1] - pct < sizeof(vfmt_buf)) + vfmt = vfmt_buf; + else + vfmt = (char *)malloc(&fmt[-1] - pct + 1); + + /* Set the separator character, if not specified. */ + if (vsep == 'X') { + if (ch == 'c') + vsep = '\0'; + else + vsep = ' '; + } + + /* Create the format specifier. */ + for (i = j = 0; i < &fmt[-1] - pct; i++) { + switch (pct[i]) { + case ',': case ';': case ':': case '_': + case 'v': case 'h': case 'l': + /* Ignore. */ + break; + case '*': + if (pct[i - 1] != '.') + vwidth = 1; + else + vprec = 1; + /* FALLTHROUGH */ + default: + vfmt[j++] = pct[i]; + } + } + + /* + * Determine the number of elements in the vector and + * finish up the format specifier. + */ + if (flags & SHORTINT) { + vfmt[j++] = 'h'; + vcnt = 8; + } else if (flags & LONGINT) { + vfmt[j++] = 'l'; + vcnt = 4; + } else { + switch (ch) { + case 'e': + case 'E': + case 'f': + case 'g': + case 'G': + vcnt = 4; + break; + default: + /* + * The default case should never + * happen. + */ + case 'c': + case 'd': + case 'i': + case 'u': + case 'o': + case 'p': + case 'x': + case 'X': + vcnt = 16; + } + } + vfmt[j++] = ch; + vfmt[j++] = '\0'; + +/* Get a vector element. */ +#define VPRINT(cnt, ind, args...) do { \ + if (flags & FPT) { \ + velm.f = vval.vfloatarg[ind]; \ + vlen = asprintf(&vstr, vfmt , ## args, velm.f); \ + } else { \ + switch (cnt) { \ + default: \ + /* The default case should never happen. */ \ + case 4: \ + velm.i = vval.vintarg[ind]; \ + break; \ + case 8: \ + velm.i = vval.vshortarg[ind]; \ + break; \ + case 16: \ + velm.i = vval.vchararg[ind]; \ + break; \ + } \ + vlen = asprintf(&vstr, vfmt , ## args, velm.i); \ + } \ + ret += vlen; \ + PRINT(vstr, vlen); \ + FLUSH(); \ + free(vstr); \ +} while (0) + + /* Actually print. */ + if (vwidth == 0) { + if (vprec == 0) { + /* First element. */ + VPRINT(vcnt, 0); + for (i = 1; i < vcnt; i++) { + /* Separator. */ + PRINT(&vsep, 1); + + /* Element. */ + VPRINT(vcnt, i); + } + } else { + /* First element. */ + VPRINT(vcnt, 0, prec); + for (i = 1; i < vcnt; i++) { + /* Separator. */ + PRINT(&vsep, 1); + + /* Element. */ + VPRINT(vcnt, i, prec); + } + } + } else { + if (vprec == 0) { + /* First element. */ + VPRINT(vcnt, 0, width); + for (i = 1; i < vcnt; i++) { + /* Separator. */ + PRINT(&vsep, 1); + + /* Element. */ + VPRINT(vcnt, i, width); + } + } else { + /* First element. */ + VPRINT(vcnt, 0, width, prec); + for (i = 1; i < vcnt; i++) { + /* Separator. */ + PRINT(&vsep, 1); + + /* Element. */ + VPRINT(vcnt, i, width, prec); + } + } + } +#undef VPRINT + + if (vfmt != vfmt_buf) + free(vfmt); + + continue; + } +#endif + /* + * All reasonable formats wind up here. At this point, `cp' + * points to a string which (if not flags&LADJUST) should be + * padded out to `width' places. If flags&ZEROPAD, it should + * first be prefixed by any sign or other prefix; otherwise, + * it should be blank padded before the prefix is emitted. + * After any left-hand padding and prefixing, emit zeroes + * required by a decimal [diouxX] precision, then print the + * string proper, then emit zeroes required by any leftover + * floating precision; finally, if LADJUST, pad with blanks. + * + * Compute actual size, so we know how much to pad. + * size excludes decimal prec; realsz includes it. + */ + realsz = dprec > size ? dprec : size; + if (sign) + realsz++; + else if (flags & HEXPREFIX) + realsz += 2; + + prsize = width > realsz ? width : realsz; + if ((unsigned)ret + prsize > INT_MAX) { + ret = EOF; + goto error; + } + + /* right-adjusting blank padding */ + if ((flags & (LADJUST|ZEROPAD)) == 0) + PAD(width - realsz, blanks); + + /* prefix */ + if (sign) { + PRINT(&sign, 1); + } else if (flags & HEXPREFIX) { + ox[0] = '0'; + ox[1] = ch; + PRINT(ox, 2); + } + + /* right-adjusting zero padding */ + if ((flags & (LADJUST|ZEROPAD)) == ZEROPAD) + PAD(width - realsz, zeroes); + + /* leading zeroes from decimal precision */ + PAD(dprec - size, zeroes); + + /* the string or number proper */ +#ifdef FLOATING_POINT + if ((flags & FPT) == 0) { + PRINT(cp, size); + } else { /* glue together f_p fragments */ + if (ch >= 'f') { /* 'f' or 'g' */ + if (_double == 0) { + /* kludge for __dtoa irregularity */ + if (expt >= ndig && + (flags & ALT) == 0) { + PRINT("0", 1); + } else { + PRINT("0.", 2); + PAD(ndig - 1, zeroes); + } + } else if (expt <= 0) { + PRINT("0.", 2); + PAD(-expt, zeroes); + PRINT(cp, ndig); + } else if (expt >= ndig) { + PRINT(cp, ndig); + PAD(expt - ndig, zeroes); + if (flags & ALT) + PRINT(".", 1); + } else { + PRINT(cp, expt); + cp += expt; + PRINT(".", 1); + PRINT(cp, ndig-expt); + } + } else { /* 'e' or 'E' */ + if (ndig > 1 || flags & ALT) { + ox[0] = *cp++; + ox[1] = '.'; + PRINT(ox, 2); + if (_double) { + PRINT(cp, ndig-1); + } else /* 0.[0..] */ + /* __dtoa irregularity */ + PAD(ndig - 1, zeroes); + } else /* XeYYY */ + PRINT(cp, 1); + PRINT(expstr, expsize); + } + } +#else + PRINT(cp, size); +#endif + + /* left-adjusting padding (always blank) */ + if (flags & LADJUST) + PAD(width - realsz, blanks); + + /* finally, adjust ret */ + ret += prsize; + + FLUSH(); /* copy out the I/O vectors */ + } +done: + FLUSH(); +error: +#ifdef FLOATING_POINT + if (dtoaresult != NULL) + free(dtoaresult); +#endif + if (__sferror(fp)) + ret = EOF; + /* FUNLOCKFILE(fp); */ + if ((argtable != NULL) && (argtable != statargtable)) + free (argtable); + return (ret); + /* NOTREACHED */ +} + +/* + * Type ids for argument type table. + */ +#define T_UNUSED 0 +#define T_SHORT 1 +#define T_U_SHORT 2 +#define TP_SHORT 3 +#define T_INT 4 +#define T_U_INT 5 +#define TP_INT 6 +#define T_LONG 7 +#define T_U_LONG 8 +#define TP_LONG 9 +#define T_QUAD 10 +#define T_U_QUAD 11 +#define TP_QUAD 12 +#define T_DOUBLE 13 +#define T_LONG_DOUBLE 14 +#define TP_CHAR 15 +#define TP_VOID 16 +#define T_VECTOR 17 + +/* + * Find all arguments when a positional parameter is encountered. Returns a + * table, indexed by argument number, of pointers to each arguments. The + * initial argument table should be an array of STATIC_ARG_TBL_SIZE entries. + * It will be replaces with a malloc-ed one if it overflows. + */ +static void +__find_arguments (fmt0, ap, argtable) + const char *fmt0; + va_list ap; + union arg **argtable; +{ + register char *fmt; /* format string */ + register int ch; /* character from fmt */ + register int n, n2; /* handy integer (short term usage) */ + register char *cp; /* handy char pointer (short term usage) */ + register int flags; /* flags as above */ + int width; /* width from format (%8d), or 0 */ + unsigned char *typetable; /* table of types */ + unsigned char stattypetable [STATIC_ARG_TBL_SIZE]; + int tablesize; /* current size of type table */ + int tablemax; /* largest used index in table */ + int nextarg; /* 1-based argument index */ + + /* + * Add an argument type to the table, expanding if necessary. + */ +#define ADDTYPE(type) \ + ((nextarg >= tablesize) ? \ + __grow_type_table(nextarg, &typetable, &tablesize) : 0, \ + (nextarg > tablemax) ? tablemax = nextarg : 0, \ + typetable[nextarg++] = type) + +#define ADDSARG() \ + ((flags&LONGINT) ? ADDTYPE(T_LONG) : \ + ((flags&SHORTINT) ? ADDTYPE(T_SHORT) : ADDTYPE(T_INT))) + +#define ADDUARG() \ + ((flags&LONGINT) ? ADDTYPE(T_U_LONG) : \ + ((flags&SHORTINT) ? ADDTYPE(T_U_SHORT) : ADDTYPE(T_U_INT))) + + /* + * Add * arguments to the type array. + */ +#define ADDASTER() \ + n2 = 0; \ + cp = fmt; \ + while (is_digit(*cp)) { \ + n2 = 10 * n2 + to_digit(*cp); \ + cp++; \ + } \ + if (*cp == '$') { \ + int hold = nextarg; \ + nextarg = n2; \ + ADDTYPE (T_INT); \ + nextarg = hold; \ + fmt = ++cp; \ + } else { \ + ADDTYPE (T_INT); \ + } + fmt = (char *)fmt0; + typetable = stattypetable; + tablesize = STATIC_ARG_TBL_SIZE; + tablemax = 0; + nextarg = 1; + memset (typetable, T_UNUSED, STATIC_ARG_TBL_SIZE); + + /* + * Scan the format for conversions (`%' character). + */ + for (;;) { + for (cp = fmt; (ch = *fmt) != '\0' && ch != '%'; fmt++) + /* void */; + if (ch == '\0') + goto done; + fmt++; /* skip over '%' */ + + flags = 0; + width = 0; + +rflag: ch = *fmt++; +reswitch: switch (ch) { + case ' ': + case '#': + goto rflag; + case '*': + ADDASTER (); + goto rflag; + case '-': + case '+': + goto rflag; + case '.': + if ((ch = *fmt++) == '*') { + ADDASTER (); + goto rflag; + } + while (is_digit(ch)) { + ch = *fmt++; + } + goto reswitch; + case '0': + goto rflag; + case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + n = 0; + do { + n = 10 * n + to_digit(ch); + ch = *fmt++; + } while (is_digit(ch)); + if (ch == '$') { + nextarg = n; + goto rflag; + } + width = n; + goto reswitch; +#ifdef FLOATING_POINT + case 'L': + flags |= LONGDBL; + goto rflag; +#endif + case 'h': + flags |= SHORTINT; + goto rflag; + case 'l': + if (flags & LONGINT) + flags |= QUADINT; + else + flags |= LONGINT; + goto rflag; + case 'q': + flags |= QUADINT; + goto rflag; + case 'c': +#ifdef ALTIVEC + if (flags & VECTOR) + ADDTYPE(T_VECTOR); + else +#endif + ADDTYPE(T_INT); + break; + case 'D': + flags |= LONGINT; + /*FALLTHROUGH*/ + case 'd': + case 'i': +#ifdef ALTIVEC + if (flags & VECTOR) + ADDTYPE(T_VECTOR); + else +#endif + if (flags & QUADINT) { + ADDTYPE(T_QUAD); + } else { + ADDSARG(); + } + break; +#ifdef FLOATING_POINT + case 'e': + case 'E': + case 'f': + case 'g': + case 'G': +#ifdef ALTIVEC + if (flags & VECTOR) + ADDTYPE(T_VECTOR); + else +#endif + if (flags & LONGDBL) + ADDTYPE(T_LONG_DOUBLE); + else + ADDTYPE(T_DOUBLE); + break; +#endif /* FLOATING_POINT */ + case 'n': + if (flags & QUADINT) + ADDTYPE(TP_QUAD); + else if (flags & LONGINT) + ADDTYPE(TP_LONG); + else if (flags & SHORTINT) + ADDTYPE(TP_SHORT); + else + ADDTYPE(TP_INT); + continue; /* no output */ + case 'O': + flags |= LONGINT; + /*FALLTHROUGH*/ + case 'o': +#ifdef ALTIVEC + if (flags & VECTOR) + ADDTYPE(T_VECTOR); + else +#endif + if (flags & QUADINT) + ADDTYPE(T_U_QUAD); + else + ADDUARG(); + break; + case 'p': +#ifdef ALTIVEC + if (flags & VECTOR) + ADDTYPE(T_VECTOR); + else +#endif + ADDTYPE(TP_VOID); + break; + case 's': + ADDTYPE(TP_CHAR); + break; + case 'U': + flags |= LONGINT; + /*FALLTHROUGH*/ + case 'u': +#ifdef ALTIVEC + if (flags & VECTOR) + ADDTYPE(T_VECTOR); + else +#endif + if (flags & QUADINT) + ADDTYPE(T_U_QUAD); + else + ADDUARG(); + break; + case 'X': + case 'x': +#ifdef ALTIVEC + if (flags & VECTOR) + ADDTYPE(T_VECTOR); + else +#endif + if (flags & QUADINT) + ADDTYPE(T_U_QUAD); + else + ADDUARG(); + break; + default: /* "%?" prints ?, unless ? is NUL */ + if (ch == '\0') + goto done; + break; + } + } +done: + /* + * Build the argument table. + */ + if (tablemax >= STATIC_ARG_TBL_SIZE) { + *argtable = (union arg *) + malloc (sizeof (union arg) * (tablemax + 1)); + } + + (*argtable) [0].intarg = NULL; + for (n = 1; n <= tablemax; n++) { + switch (typetable [n]) { + case T_UNUSED: + (*argtable) [n].intarg = va_arg (ap, int); + break; + case T_SHORT: + (*argtable) [n].intarg = va_arg (ap, int); + break; + case T_U_SHORT: + (*argtable) [n].intarg = va_arg (ap, int); + break; + case TP_SHORT: + (*argtable) [n].pshortarg = va_arg (ap, short *); + break; + case T_INT: + (*argtable) [n].intarg = va_arg (ap, int); + break; + case T_U_INT: + (*argtable) [n].uintarg = va_arg (ap, unsigned int); + break; + case TP_INT: + (*argtable) [n].pintarg = va_arg (ap, int *); + break; + case T_LONG: + (*argtable) [n].longarg = va_arg (ap, long); + break; + case T_U_LONG: + (*argtable) [n].ulongarg = va_arg (ap, unsigned long); + break; + case TP_LONG: + (*argtable) [n].plongarg = va_arg (ap, long *); + break; + case T_QUAD: + (*argtable) [n].quadarg = va_arg (ap, quad_t); + break; + case T_U_QUAD: + (*argtable) [n].uquadarg = va_arg (ap, u_quad_t); + break; + case TP_QUAD: + (*argtable) [n].pquadarg = va_arg (ap, quad_t *); + break; +#ifdef FLOATING_POINT + case T_DOUBLE: + (*argtable) [n].doublearg = va_arg (ap, double); + break; + case T_LONG_DOUBLE: + (*argtable) [n].longdoublearg = va_arg (ap, long double); + break; +#endif +#ifdef ALTIVEC + case T_VECTOR: + { int tmp = 0; + getvec( &((*argtable) [n]), NULL, tmp, ap ); + } +#endif + case TP_CHAR: + (*argtable) [n].pchararg = va_arg (ap, char *); + break; + case TP_VOID: + (*argtable) [n].pvoidarg = va_arg (ap, void *); + break; + } + } + + if ((typetable != NULL) && (typetable != stattypetable)) + free (typetable); +} + +/* + * Increase the size of the type table. + */ +static void +__grow_type_table (nextarg, typetable, tablesize) + int nextarg; + unsigned char **typetable; + int *tablesize; +{ + unsigned char *const oldtable = *typetable; + const int oldsize = *tablesize; + unsigned char *newtable; + int newsize = oldsize * 2; + + if (newsize < nextarg + 1) + newsize = nextarg + 1; + if (oldsize == STATIC_ARG_TBL_SIZE) { + if ((newtable = malloc (newsize)) == NULL) + abort(); /* XXX handle better */ + bcopy (oldtable, newtable, oldsize); + } else { + if ((newtable = realloc (oldtable, newsize)) == NULL) + abort(); /* XXX handle better */ + } + memset (&newtable [oldsize], T_UNUSED, (newsize - oldsize)); + + *typetable = newtable; + *tablesize = newsize; +} + + +#ifdef FLOATING_POINT + +extern char *__dtoa __P((double, int, int, int *, int *, char **, char **)); + +static char * +cvt(value, ndigits, flags, sign, decpt, ch, length, dtoaresultp) + double value; + int ndigits, flags, *decpt, ch, *length; + char *sign; + char **dtoaresultp; +{ + int mode, dsgn; + char *digits, *bp, *rve; + + if (ch == 'f') + mode = 3; /* ndigits after the decimal point */ + else { + /* + * To obtain ndigits after the decimal point for the 'e' + * and 'E' formats, round to ndigits + 1 significant + * figures. + */ + if (ch == 'e' || ch == 'E') + ndigits++; + mode = 2; /* ndigits significant digits */ + } + if (value < 0) { + value = -value; + *sign = '-'; + } else + *sign = '\000'; + digits = __dtoa(value, mode, ndigits, decpt, &dsgn, &rve, dtoaresultp); + if ((ch != 'g' && ch != 'G') || flags & ALT) { + /* print trailing zeros */ + bp = digits + ndigits; + if (ch == 'f') { + if (*digits == '0' && value) + *decpt = -ndigits + 1; + bp += *decpt; + } + if (value == 0) /* kludge for __dtoa irregularity */ + rve = bp; + while (rve < bp) + *rve++ = '0'; + } + *length = rve - digits; + return (digits); +} + +static int +exponent(p0, exp, fmtch) + char *p0; + int exp, fmtch; +{ + register char *p, *t; + char expbuf[MAXEXP]; + + p = p0; + *p++ = fmtch; + if (exp < 0) { + exp = -exp; + *p++ = '-'; + } + else + *p++ = '+'; + t = expbuf + MAXEXP; + if (exp > 9) { + do { + *--t = to_char(exp % 10); + } while ((exp /= 10) > 9); + *--t = to_char(exp); + for (; t < expbuf + MAXEXP; *p++ = *t++); + } + else { + *p++ = '0'; + *p++ = to_char(exp); + } + return (p - p0); +} +#endif /* FLOATING_POINT */ diff --git a/stdio/vfscanf.c b/stdio/vfscanf.c new file mode 100644 index 0000000..35bb094 --- /dev/null +++ b/stdio/vfscanf.c @@ -0,0 +1,786 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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 +#include +#include +#if __STDC__ +#include +#else +#include +#endif +#include "local.h" + +#define FLOATING_POINT + +#include "floatio.h" +#define BUF 513 /* Maximum length of numeric string. */ + +/* + * Flags used during conversion. + */ +#define LONG 0x01 /* l: long or double */ +#define LONGDBL 0x02 /* L: long double; unimplemented */ +#define SHORT 0x04 /* h: short */ +#define SUPPRESS 0x08 /* suppress assignment */ +#define POINTER 0x10 /* weird %p pointer (`fake hex') */ +#define NOSKIP 0x20 /* do not skip blanks */ +#define QUAD 0x400 + +/* + * The following are used in numeric conversions only: + * SIGNOK, NDIGITS, DPTOK, and EXPOK are for floating point; + * SIGNOK, NDIGITS, PFXOK, and NZDIGITS are for integral. + */ +#define SIGNOK 0x40 /* +/- is (still) legal */ +#define NDIGITS 0x80 /* no digits detected */ + +#define DPTOK 0x100 /* (float) decimal point is still legal */ +#define EXPOK 0x200 /* (float) exponent (e+3, etc) still legal */ + +#define PFXOK 0x100 /* 0x prefix is (still) legal */ +#define NZDIGITS 0x200 /* no zero digits detected */ + +/* + * Conversion types. + */ +#define CT_CHAR 0 /* %c conversion */ +#define CT_CCL 1 /* %[...] conversion */ +#define CT_STRING 2 /* %s conversion */ +#define CT_INT 3 /* integer, i.e., strtoq or strtouq */ +#define CT_FLOAT 4 /* floating, i.e., strtod */ + +#define u_char unsigned char +#define u_long unsigned long + +static u_char *__sccl(char *, u_char *); + +/* + * vfscanf + */ +int +__svfscanf(fp, fmt0, ap) + register FILE *fp; + char const *fmt0; + va_list ap; +{ + register u_char *fmt = (u_char *)fmt0; + register int c; /* character from format, or conversion */ + register size_t width; /* field width, or 0 */ + register char *p; /* points into all kinds of strings */ + register int n; /* handy integer */ + register int flags; /* flags as defined above */ + register 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 strtoq/strtouq */ + u_quad_t (*ccfn)(); /* conversion function (strtoq/strtouq) */ + char ccltab[256]; /* character class table for %[...] */ + char buf[BUF]; /* buffer for numeric conversions */ + + /* `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; + nread = 0; + base = 0; /* XXX just to keep gcc happy */ + ccfn = NULL; /* XXX just to keep gcc happy */ + for (;;) { + c = *fmt++; + if (c == 0) + return (nassigned); + if (isspace(c)) { + for (;;) { + if (fp->_r <= 0 && __srefill(fp)) + return (nassigned); + if (!isspace(*fp->_p)) + break; + nread++, fp->_r--, fp->_p++; + } + continue; + } + if (c != '%') + goto literal; + width = 0; + flags = 0; + /* + * switch on the format. continue if done; + * break once format type is derived. + */ +again: c = *fmt++; + switch (c) { + case '%': +literal: + if (fp->_r <= 0 && __srefill(fp)) + goto input_failure; + if (*fp->_p != c) + goto match_failure; + fp->_r--, fp->_p++; + nread++; + continue; + + case '*': + flags |= SUPPRESS; + goto again; + case 'l': + if( flags & LONG ) + flags |= QUAD; + else + flags |= LONG; + goto again; + case 'q': + flags |= QUAD; + goto again; + case 'z': + if( sizeof(size_t) == sizeof(long) ) + flags |= LONG; + if( sizeof(size_t) == sizeof(quad_t) ) + flags |= QUAD; + goto again; + case 'L': + flags |= LONGDBL; + goto again; + case 'h': + flags |= SHORT; + goto again; + + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + width = width * 10 + c - '0'; + goto again; + + /* + * Conversions. + * Those marked `compat' are for 4.[123]BSD compatibility. + * + * (According to ANSI, E and X formats are supposed + * to the same as e and x. Sorry about that.) + */ + case 'D': /* compat */ + flags |= LONG; + /* FALLTHROUGH */ + case 'd': + c = CT_INT; + ccfn = (u_quad_t (*)())strtoq; + base = 10; + break; + + case 'i': + c = CT_INT; + ccfn = (u_quad_t (*)())strtoq; + base = 0; + break; + + case 'O': /* compat */ + flags |= LONG; + /* FALLTHROUGH */ + case 'o': + c = CT_INT; + ccfn = strtouq; + base = 8; + break; + + case 'u': + c = CT_INT; + ccfn = strtouq; + base = 10; + break; + + case 'X': /* compat XXX */ + flags |= LONG; + /* FALLTHROUGH */ + case 'x': + flags |= PFXOK; /* enable 0x prefixing */ + c = CT_INT; + ccfn = strtouq; + base = 16; + break; + +#ifdef FLOATING_POINT + case 'E': /* compat XXX */ + case 'F': /* compat */ + flags |= LONG; + /* FALLTHROUGH */ + case 'e': case 'f': case 'g': + c = CT_FLOAT; + break; +#endif + + case 's': + c = CT_STRING; + break; + + case '[': + fmt = __sccl(ccltab, fmt); + flags |= NOSKIP; + c = CT_CCL; + break; + + case 'c': + flags |= NOSKIP; + c = CT_CHAR; + break; + + case 'p': /* pointer format is like hex */ + flags |= POINTER | PFXOK; + c = CT_INT; + ccfn = strtouq; + base = 16; + break; + + case 'n': + if (flags & SUPPRESS) /* ??? */ + continue; + if (flags & SHORT) + *va_arg(ap, short *) = nread; + else if (flags & LONG) + *va_arg(ap, long *) = nread; + else if (flags & QUAD) + *va_arg(ap, quad_t *) = nread; + else + *va_arg(ap, int *) = nread; + continue; + + /* + * Disgusting backwards compatibility hacks. XXX + */ + case '\0': /* compat */ + return (EOF); + + default: /* compat */ + if (isupper(c)) + flags |= LONG; + c = CT_INT; + ccfn = (u_quad_t (*)())strtoq; + base = 10; + break; + } + + /* + * We have a conversion that requires input. + */ + if (fp->_r <= 0 && __srefill(fp)) + goto input_failure; + + /* + * Consume leading white space, except for formats + * that suppress this. + */ + if ((flags & NOSKIP) == 0) { + while (isspace(*fp->_p)) { + nread++; + if (--fp->_r > 0) + fp->_p++; + else if (__srefill(fp)) + goto input_failure; + } + /* + * Note that there is at least one character in + * the buffer, so conversions that do not set NOSKIP + * ca no longer result in an input failure. + */ + } + + /* + * Do the conversion. + */ + switch (c) { + + case CT_CHAR: + /* scan arbitrary characters (sets NOSKIP) */ + if (width == 0) + width = 1; + if (flags & SUPPRESS) { + size_t sum = 0; + for (;;) { + if ((n = fp->_r) < width) { + sum += n; + width -= n; + fp->_p += n; + if (__srefill(fp)) { + if (sum == 0) + goto input_failure; + break; + } + } else { + sum += width; + fp->_r -= width; + fp->_p += width; + break; + } + } + nread += sum; + } else { + size_t r = fread((void *)va_arg(ap, char *), 1, + width, fp); + + if (r == 0) + goto input_failure; + nread += r; + nassigned++; + } + break; + + case CT_CCL: + /* scan a (nonempty) character class (sets NOSKIP) */ + if (width == 0) + width = ~0; /* `infinity' */ + /* take only those things in the class */ + if (flags & SUPPRESS) { + n = 0; + while (ccltab[*fp->_p]) { + n++, fp->_r--, fp->_p++; + if (--width == 0) + break; + if (fp->_r <= 0 && __srefill(fp)) { + if (n == 0) + goto input_failure; + break; + } + } + if (n == 0) + goto match_failure; + } else { + p0 = p = va_arg(ap, char *); + while (ccltab[*fp->_p]) { + fp->_r--; + *p++ = *fp->_p++; + if (--width == 0) + break; + if (fp->_r <= 0 && __srefill(fp)) { + if (p == p0) + goto input_failure; + break; + } + } + n = p - p0; + if (n == 0) + goto match_failure; + *p = 0; + nassigned++; + } + nread += n; + break; + + case CT_STRING: + /* like CCL, but zero-length string OK, & no NOSKIP */ + if (width == 0) + width = ~0; + if (flags & SUPPRESS) { + n = 0; + while (!isspace(*fp->_p)) { + n++, fp->_r--, fp->_p++; + if (--width == 0) + break; + if (fp->_r <= 0 && __srefill(fp)) + break; + } + nread += n; + } else { + p0 = p = va_arg(ap, char *); + while (!isspace(*fp->_p)) { + fp->_r--; + *p++ = *fp->_p++; + if (--width == 0) + break; + if (fp->_r <= 0 && __srefill(fp)) + break; + } + *p = 0; + nread += p - p0; + nassigned++; + } + continue; + + case CT_INT: + /* scan an integer as if by strtoq/strtouq */ +#ifdef hardway + if (width == 0 || width > sizeof(buf) - 1) + width = sizeof(buf) - 1; +#else + /* size_t is unsigned, hence this optimisation */ + if (--width > sizeof(buf) - 2) + width = sizeof(buf) - 2; + width++; +#endif + flags |= SIGNOK | NDIGITS | NZDIGITS; + for (p = buf; width; width--) { + c = *fp->_p; + /* + * Switch on the character; `goto ok' + * if we accept it as a part of number. + */ + switch (c) { + + /* + * The digit 0 is always legal, but is + * special. For %i conversions, if no + * digits (zero or nonzero) have been + * scanned (only signs), we will have + * base==0. In that case, we should set + * it to 8 and enable 0x prefixing. + * Also, if we have not scanned zero digits + * before this, do not turn off prefixing + * (someone else will turn it off if we + * have scanned any nonzero digits). + */ + case '0': + if (base == 0) { + base = 8; + flags |= PFXOK; + } + if (flags & NZDIGITS) + flags &= ~(SIGNOK|NZDIGITS|NDIGITS); + else + flags &= ~(SIGNOK|PFXOK|NDIGITS); + goto ok; + + /* 1 through 7 always legal */ + case '1': case '2': case '3': + case '4': case '5': case '6': case '7': + base = basefix[base]; + flags &= ~(SIGNOK | PFXOK | NDIGITS); + goto ok; + + /* digits 8 and 9 ok iff decimal or hex */ + case '8': case '9': + base = basefix[base]; + if (base <= 8) + break; /* not legal here */ + flags &= ~(SIGNOK | PFXOK | NDIGITS); + goto ok; + + /* letters ok iff hex */ + case 'A': case 'B': case 'C': + case 'D': case 'E': case 'F': + case 'a': case 'b': case 'c': + case 'd': case 'e': case 'f': + /* no need to fix base here */ + if (base <= 10) + break; /* not legal here */ + flags &= ~(SIGNOK | PFXOK | NDIGITS); + goto ok; + + /* sign ok only as first character */ + case '+': case '-': + if (flags & SIGNOK) { + flags &= ~SIGNOK; + goto ok; + } + break; + + /* x ok iff flag still set & 2nd char */ + case 'x': case 'X': + if (flags & PFXOK && p == buf + 1) { + base = 16; /* if %i */ + flags &= ~PFXOK; + goto ok; + } + break; + } + + /* + * If we got here, c is not a legal character + * for a number. Stop accumulating digits. + */ + break; + ok: + /* + * c is legal: store it and look at the next. + */ + *p++ = c; + if (--fp->_r > 0) + fp->_p++; + else if (__srefill(fp)) + break; /* EOF */ + } + /* + * If we had only a sign, it is no good; push + * back the sign. If the number ends in `x', + * it was [sign] '0' 'x', so push back the x + * and treat it as [sign] '0'. + */ + if (flags & NDIGITS) { + if (p > buf) + (void) ungetc(*(u_char *)--p, fp); + goto match_failure; + } + c = ((u_char *)p)[-1]; + if (c == 'x' || c == 'X') { + --p; + (void) ungetc(c, fp); + } + if ((flags & SUPPRESS) == 0) { + u_quad_t res; + + *p = 0; + res = (*ccfn)(buf, (char **)NULL, base); + if (flags & POINTER) + *va_arg(ap, void **) = (void *)res; + else if (flags & SHORT) + *va_arg(ap, short *) = res; + else if (flags & QUAD) + *va_arg(ap, quad_t *) = res; + else if (flags & LONG) + *va_arg(ap, long *) = res; + else + *va_arg(ap, int *) = res; + nassigned++; + } + nread += p - buf; + break; + +#ifdef FLOATING_POINT + case CT_FLOAT: + /* scan a floating point number as if by strtod */ +#ifdef hardway + if (width == 0 || width > sizeof(buf) - 1) + width = sizeof(buf) - 1; +#else + /* size_t is unsigned, hence this optimisation */ + if (--width > sizeof(buf) - 2) + width = sizeof(buf) - 2; + width++; +#endif + flags |= SIGNOK | NDIGITS | DPTOK | EXPOK; + for (p = buf; width; width--) { + c = *fp->_p; + /* + * This code mimicks the integer conversion + * code, but is much simpler. + */ + switch (c) { + + case '0': case '1': case '2': case '3': + case '4': case '5': case '6': case '7': + case '8': case '9': + flags &= ~(SIGNOK | NDIGITS); + goto fok; + + case '+': case '-': + if (flags & SIGNOK) { + flags &= ~SIGNOK; + goto fok; + } + break; + case '.': + if (flags & DPTOK) { + flags &= ~(SIGNOK | DPTOK); + goto fok; + } + break; + case 'e': case 'E': + /* no exponent without some digits */ + if ((flags&(NDIGITS|EXPOK)) == EXPOK) { + flags = + (flags & ~(EXPOK|DPTOK)) | + SIGNOK | NDIGITS; + goto fok; + } + break; + } + break; + fok: + *p++ = c; + if (--fp->_r > 0) + fp->_p++; + else if (__srefill(fp)) + break; /* EOF */ + } + /* + * If no digits, might be missing exponent digits + * (just give back the exponent) or might be missing + * regular digits, but had sign and/or decimal point. + */ + if (flags & NDIGITS) { + if (flags & EXPOK) { + /* no digits at all */ + while (p > buf) + ungetc(*(u_char *)--p, fp); + goto match_failure; + } + /* just a bad exponent (e and maybe sign) */ + c = *(u_char *)--p; + if (c != 'e' && c != 'E') { + (void) ungetc(c, fp);/* sign */ + c = *(u_char *)--p; + } + (void) ungetc(c, fp); + } + if ((flags & SUPPRESS) == 0) { + long double res; + + *p = 0; + res = strtod(buf,(char **) NULL); + if (flags & LONGDBL) + *va_arg(ap, long double *) = res; + else if (flags & LONG) + *va_arg(ap, double *) = res; + else + *va_arg(ap, float *) = res; + nassigned++; + } + nread += p - buf; + break; +#endif /* FLOATING_POINT */ + } + } +input_failure: + return (nassigned ? nassigned : -1); +match_failure: + return (nassigned); +} + +/* + * Fill in the given table from the scanset at the given format + * (just after `['). Return a pointer to the character past the + * closing `]'. The table has a 1 wherever characters should be + * considered part of the scanset. + */ +static u_char * +__sccl(tab, fmt) + register char *tab; + register u_char *fmt; +{ + register int c, n, v; + + /* first `clear' the whole table */ + c = *fmt++; /* first char hat => negated scanset */ + if (c == '^') { + v = 1; /* default => accept */ + c = *fmt++; /* get new first char */ + } else + v = 0; /* default => reject */ + /* should probably use memset here */ + for (n = 0; n < 256; n++) + tab[n] = v; + if (c == 0) + return (fmt - 1);/* format ended before closing ] */ + + /* + * Now set the entries corresponding to the actual scanset + * to the opposite of the above. + * + * The first character may be ']' (or '-') without being special; + * the last character may be '-'. + */ + v = 1 - v; + for (;;) { + tab[c] = v; /* take character c */ +doswitch: + n = *fmt++; /* and examine the next */ + switch (n) { + + case 0: /* format ended too soon */ + return (fmt - 1); + + case '-': + /* + * A scanset of the form + * [01+-] + * is defined as `the digit 0, the digit 1, + * the character +, the character -', but + * the effect of a scanset such as + * [a-zA-Z0-9] + * is implementation defined. The V7 Unix + * scanf treats `a-z' as `the letters a through + * z', but treats `a-a' as `the letter a, the + * character -, and the letter a'. + * + * For compatibility, the `-' is not considerd + * to define a range if the character following + * it is either a close bracket (required by ANSI) + * or is not numerically greater than the character + * we just stored in the table (c). + */ + n = *fmt; + if (n == ']' || n < c) { + c = '-'; + break; /* resume the for(;;) */ + } + fmt++; + do { /* fill in the range */ + tab[++c] = v; + } while (c < n); +#if 1 /* XXX another disgusting compatibility hack */ + /* + * Alas, the V7 Unix scanf also treats formats + * such as [a-c-e] as `the letters a through e'. + * This too is permitted by the standard.... + */ + goto doswitch; +#else + c = *fmt++; + if (c == 0) + return (fmt - 1); + if (c == ']') + return (fmt); +#endif + break; + + case ']': /* end of scanset */ + return (fmt); + + default: /* just another character */ + c = n; + break; + } + } + /* NOTREACHED */ +} diff --git a/stdio/vprintf.c b/stdio/vprintf.c new file mode 100644 index 0000000..686deaf --- /dev/null +++ b/stdio/vprintf.c @@ -0,0 +1,67 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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 + +int +vprintf(fmt, ap) + char const *fmt; + _BSD_VA_LIST_ ap; +{ + return (vfprintf(stdout, fmt, ap)); +} diff --git a/stdio/vscanf.c b/stdio/vscanf.c new file mode 100644 index 0000000..3b92a1c --- /dev/null +++ b/stdio/vscanf.c @@ -0,0 +1,68 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Donn Seeley at UUNET Technologies, 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. + */ + + +#include + +int +vscanf(fmt, ap) + const char *fmt; + _BSD_VA_LIST_ ap; +{ + + return (__svfscanf(stdin, fmt, ap)); +} diff --git a/stdio/vsnprintf.c b/stdio/vsnprintf.c new file mode 100644 index 0000000..3d2e6d1 --- /dev/null +++ b/stdio/vsnprintf.c @@ -0,0 +1,79 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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 + +int +vsnprintf(str, n, fmt, ap) + char *str; + size_t n; + const char *fmt; + _BSD_VA_LIST_ ap; +{ + int ret; + FILE f; + + if ((int)n < 1) + return (EOF); + f._flags = __SWR | __SSTR; + f._bf._base = f._p = (unsigned char *)str; + f._bf._size = f._w = n - 1; + ret = vfprintf(&f, fmt, ap); + *f._p = 0; + return (ret); +} diff --git a/stdio/vsprintf.c b/stdio/vsprintf.c new file mode 100644 index 0000000..2e8e0ad --- /dev/null +++ b/stdio/vsprintf.c @@ -0,0 +1,77 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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 +#include + +int +vsprintf(str, fmt, ap) + char *str; + const char *fmt; + _BSD_VA_LIST_ ap; +{ + int ret; + FILE f; + + f._flags = __SWR | __SSTR; + f._bf._base = f._p = (unsigned char *)str; + f._bf._size = f._w = INT_MAX; + ret = vfprintf(&f, fmt, ap); + *f._p = 0; + return (ret); +} diff --git a/stdio/vsscanf.c b/stdio/vsscanf.c new file mode 100644 index 0000000..59bbabf --- /dev/null +++ b/stdio/vsscanf.c @@ -0,0 +1,88 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Donn Seeley at UUNET Technologies, 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. + */ + + +#include +#include + +/* ARGSUSED */ +static int +eofread(cookie, buf, len) + void *cookie; + char *buf; + int len; +{ + + return (0); +} + +int +vsscanf(str, fmt, ap) + const char *str; + const char *fmt; + _BSD_VA_LIST_ ap; +{ + FILE f; + + 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; + return (__svfscanf(&f, fmt, ap)); +} diff --git a/stdio/wbuf.c b/stdio/wbuf.c new file mode 100644 index 0000000..78032d4 --- /dev/null +++ b/stdio/wbuf.c @@ -0,0 +1,107 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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 +#include "local.h" + +/* + * Write the given character into the (probably full) buffer for + * the given file. Flush the buffer out if it is or becomes full, + * or if c=='\n' and the file is line buffered. + */ +int +__swbuf(c, fp) + register int c; + register FILE *fp; +{ + register int n; + + /* + * In case we cannot write, or longjmp takes us out early, + * make sure _w is 0 (if fully- or un-buffered) or -_bf._size + * (if line buffered) so that we will get called again. + * If we did not do this, a sufficient number of putc() + * calls might wrap _w from negative to positive. + */ + fp->_w = fp->_lbfsize; + if (cantwrite(fp)) + return (EOF); + c = (unsigned char)c; + + /* + * If it is completely full, flush it out. Then, in any case, + * stuff c into the buffer. If this causes the buffer to fill + * completely, or if c is '\n' and the file is line buffered, + * flush it (perhaps a second time). The second flush will always + * happen on unbuffered streams, where _bf._size==1; fflush() + * guarantees that putc() will always call wbuf() by setting _w + * to 0, so we need not do anything else. + */ + n = fp->_p - fp->_bf._base; + if (n >= fp->_bf._size) { + if (fflush(fp)) + return (EOF); + n = 0; + } + fp->_w--; + *fp->_p++ = c; + if (++n == fp->_bf._size || (fp->_flags & __SLBF && c == '\n')) + if (fflush(fp)) + return (EOF); + return (c); +} diff --git a/stdio/wsetup.c b/stdio/wsetup.c new file mode 100644 index 0000000..758523d --- /dev/null +++ b/stdio/wsetup.c @@ -0,0 +1,109 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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 +#include +#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. + */ +int +__swsetup(fp) + register FILE *fp; +{ + /* make sure stdio is set up */ + if (!__sdidinit) + __sinit(); + + /* + * If we are not writing, we had better be reading and writing. + */ + if ((fp->_flags & __SWR) == 0) { + if ((fp->_flags & __SRW) == 0) + return (EOF); + if (fp->_flags & __SRD) { + /* clobber any ungetc data */ + if (HASUB(fp)) + FREEUB(fp); + fp->_flags &= ~(__SRD|__SEOF); + fp->_r = 0; + fp->_p = fp->_bf._base; + } + fp->_flags |= __SWR; + } + + /* + * Make a buffer if necessary, then set _w. + */ + if (fp->_bf._base == NULL) + __smakebuf(fp); + if (fp->_flags & __SLBF) { + /* + * It is line buffered, so make _lbfsize be -_bufsize + * for the putc() macro. We will change _lbfsize back + * to 0 whenever we turn off __SWR. + */ + fp->_w = 0; + fp->_lbfsize = -fp->_bf._size; + } else + fp->_w = fp->_flags & __SNBF ? 0 : fp->_bf._size; + return (0); +} diff --git a/stdlib.subproj/Makefile b/stdlib.subproj/Makefile deleted file mode 100644 index f952411..0000000 --- a/stdlib.subproj/Makefile +++ /dev/null @@ -1,51 +0,0 @@ -# -# Generated by the NeXT Project Builder. -# -# NOTE: Do NOT change this file -- Project Builder maintains it. -# -# Put all of your customizations in files called Makefile.preamble -# and Makefile.postamble (both optional), and Makefile will include them. -# - -NAME = stdlib - -PROJECTVERSION = 2.8 -PROJECT_TYPE = Component - -HFILES = atexit.h - -CFILES = abort.c atexit.c atof.c atoi.c atol.c bsearch.c div.c\ - exit.c getenv.c getopt.c getsubopt.c heapsort.c labs.c\ - ldiv.c merge.c putenv.c qsort.c radixsort.c rand.c random.c\ - setenv.c strtod.c strtol.c strtoq.c strtoul.c strtouq.c\ - system.c - -OTHERSRCS = Makefile.preamble Makefile Makefile.postamble - - -MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles -CODE_GEN_STYLE = DYNAMIC -MAKEFILE = subproj.make -LIBS = -DEBUG_LIBS = $(LIBS) -PROF_LIBS = $(LIBS) - - - - -NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc -WINDOWS_OBJCPLUS_COMPILER = $(DEVDIR)/gcc -PDO_UNIX_OBJCPLUS_COMPILER = $(NEXTDEV_BIN)/gcc -NEXTSTEP_JAVA_COMPILER = /usr/bin/javac -WINDOWS_JAVA_COMPILER = $(JDKBINDIR)/javac.exe -PDO_UNIX_JAVA_COMPILER = $(JDKBINDIR)/javac - -include $(MAKEFILEDIR)/platform.make - --include Makefile.preamble - -include $(MAKEFILEDIR)/$(MAKEFILE) - --include Makefile.postamble - --include Makefile.dependencies diff --git a/stdlib.subproj/Makefile.postamble b/stdlib.subproj/Makefile.postamble deleted file mode 100644 index 411cde6..0000000 --- a/stdlib.subproj/Makefile.postamble +++ /dev/null @@ -1,100 +0,0 @@ -############################################################################### -# Makefile.postamble -# Copyright 1997, Apple Computer, Inc. -# -# Use this makefile, which is imported after all other makefiles, to -# override attributes for a project's Makefile environment. This allows you -# to take advantage of the environment set up by the other Makefiles. -# You can also define custom rules at the end of this file. -# -############################################################################### -# -# These variables are exported by the standard makefiles and can be -# used in any customizations you make. They are *outputs* of -# the Makefiles and should be used, not set. -# -# PRODUCTS: products to install. All of these products will be placed in -# the directory $(DSTROOT)$(INSTALLDIR) -# GLOBAL_RESOURCE_DIR: The directory to which resources are copied. -# LOCAL_RESOURCE_DIR: The directory to which localized resources are copied. -# OFILE_DIR: Directory into which .o object files are generated. -# DERIVED_SRC_DIR: Directory used for all other derived files -# -# ALL_CFLAGS: flags to pass when compiling .c files -# ALL_MFLAGS: flags to pass when compiling .m files -# ALL_CCFLAGS: flags to pass when compiling .cc, .cxx, and .C files -# ALL_MMFLAGS: flags to pass when compiling .mm, .mxx, and .M files -# ALL_PRECOMPFLAGS: flags to pass when precompiling .h files -# ALL_LDFLAGS: flags to pass when linking object files -# ALL_LIBTOOL_FLAGS: flags to pass when libtooling object files -# ALL_PSWFLAGS: flags to pass when processing .psw and .pswm (pswrap) files -# ALL_RPCFLAGS: flags to pass when processing .rpc (rpcgen) files -# ALL_YFLAGS: flags to pass when processing .y (yacc) files -# ALL_LFLAGS: flags to pass when processing .l (lex) files -# -# NAME: name of application, bundle, subproject, palette, etc. -# LANGUAGES: langages in which the project is written (default "English") -# English_RESOURCES: localized resources (e.g. nib's, images) of project -# GLOBAL_RESOURCES: non-localized resources of project -# -# SRCROOT: base directory in which to place the new source files -# SRCPATH: relative path from SRCROOT to present subdirectory -# -# INSTALLDIR: Directory the product will be installed into by 'install' target -# PUBLIC_HDR_INSTALLDIR: where to install public headers. Don't forget -# to prefix this with DSTROOT when you use it. -# PRIVATE_HDR_INSTALLDIR: where to install private headers. Don't forget -# to prefix this with DSTROOT when you use it. -# -# EXECUTABLE_EXT: Executable extension for the platform (i.e. .exe on Windows) -# -############################################################################### - -# Some compiler flags can be overridden here for certain build situations. -# -# WARNING_CFLAGS: flag used to set warning level (defaults to -Wmost) -# DEBUG_SYMBOLS_CFLAGS: debug-symbol flag passed to all builds (defaults -# to -g) -# DEBUG_BUILD_CFLAGS: flags passed during debug builds (defaults to -DDEBUG) -# OPTIMIZE_BUILD_CFLAGS: flags passed during optimized builds (defaults -# to -O) -# PROFILE_BUILD_CFLAGS: flags passed during profile builds (defaults -# to -pg -DPROFILE) -# LOCAL_DIR_INCLUDE_DIRECTIVE: flag used to add current directory to -# the include path (defaults to -I.) -# DEBUG_BUILD_LDFLAGS, OPTIMIZE_BUILD_LDFLAGS, PROFILE_BUILD_LDFLAGS: flags -# passed to ld/libtool (defaults to nothing) - - -# Library and Framework projects only: -# INSTALL_NAME_DIRECTIVE: This directive ensures that executables linked -# against the framework will run against the correct version even if -# the current version of the framework changes. You may override this -# to "" as an alternative to using the DYLD_LIBRARY_PATH during your -# development cycle, but be sure to restore it before installing. - - -# Ownership and permissions of files installed by 'install' target - -#INSTALL_AS_USER = root - # User/group ownership -#INSTALL_AS_GROUP = wheel - # (probably want to set both of these) -#INSTALL_PERMISSIONS = - # If set, 'install' chmod's executable to this - - -# Options to strip. Note: -S strips debugging symbols (executables can be stripped -# down further with -x or, if they load no bundles, with no options at all). - -#STRIPFLAGS = -S - - -######################################################################### -# Put rules to extend the behavior of the standard Makefiles here. Include them in -# the dependency tree via cvariables like AFTER_INSTALL in the Makefile.preamble. -# -# You should avoid redefining things like "install" or "app", as they are -# owned by the top-level Makefile API and no context has been set up for where -# derived files should go. -# diff --git a/stdlib.subproj/Makefile.preamble b/stdlib.subproj/Makefile.preamble deleted file mode 100644 index c1624b4..0000000 --- a/stdlib.subproj/Makefile.preamble +++ /dev/null @@ -1,137 +0,0 @@ -############################################################################### -# Makefile.preamble -# Copyright 1997, Apple Computer, Inc. -# -# Use this makefile for configuring the standard application makefiles -# associated with ProjectBuilder. It is included before the main makefile. -# In Makefile.preamble you set attributes for a project, so they are available -# to the project's makefiles. In contrast, you typically write additional rules or -# override built-in behavior in the Makefile.postamble. -# -# Each directory in a project tree (main project plus subprojects) should -# have its own Makefile.preamble and Makefile.postamble. -############################################################################### -# -# Before the main makefile is included for this project, you may set: -# -# MAKEFILEDIR: Directory in which to find $(MAKEFILE) -# MAKEFILE: Top level mechanism Makefile (e.g., app.make, bundle.make) - -# Compiler/linker flags added to the defaults: The OTHER_* variables will be -# inherited by all nested sub-projects, but the LOCAL_ versions of the same -# variables will not. Put your -I, -D, -U, and -L flags in ProjectBuilder's -# Build Attributes inspector if at all possible. To override the default flags -# that get passed to ${CC} (e.g. change -O to -O2), see Makefile.postamble. The -# variables below are *inputs* to the build process and distinct from the override -# settings done (less often) in the Makefile.postamble. -# -# OTHER_CFLAGS, LOCAL_CFLAGS: additional flags to pass to the compiler -# Note that $(OTHER_CFLAGS) and $(LOCAL_CFLAGS) are used for .h, ...c, .m, -# .cc, .cxx, .C, and .M files. There is no need to respecify the -# flags in OTHER_MFLAGS, etc. -# OTHER_MFLAGS, LOCAL_MFLAGS: additional flags for .m files -# OTHER_CCFLAGS, LOCAL_CCFLAGS: additional flags for .cc, .cxx, and ...C files -# OTHER_MMFLAGS, LOCAL_MMFLAGS: additional flags for .mm and .M files -# OTHER_PRECOMPFLAGS, LOCAL_PRECOMPFLAGS: additional flags used when -# precompiling header files -# OTHER_LDFLAGS, LOCAL_LDFLAGS: additional flags passed to ld and libtool -# OTHER_PSWFLAGS, LOCAL_PSWFLAGS: additional flags passed to pswrap -# OTHER_RPCFLAGS, LOCAL_RPCFLAGS: additional flags passed to rpcgen -# OTHER_YFLAGS, LOCAL_YFLAGS: additional flags passed to yacc -# OTHER_LFLAGS, LOCAL_LFLAGS: additional flags passed to lex - -# These variables provide hooks enabling you to add behavior at almost every -# stage of the make: -# -# BEFORE_PREBUILD: targets to build before installing headers for a subproject -# AFTER_PREBUILD: targets to build after installing headers for a subproject -# BEFORE_BUILD_RECURSION: targets to make before building subprojects -# BEFORE_BUILD: targets to make before a build, but after subprojects -# AFTER_BUILD: targets to make after a build -# -# BEFORE_INSTALL: targets to build before installing the product -# AFTER_INSTALL: targets to build after installing the product -# BEFORE_POSTINSTALL: targets to build before postinstalling every subproject -# AFTER_POSTINSTALL: targts to build after postinstalling every subproject -# -# BEFORE_INSTALLHDRS: targets to build before installing headers for a -# subproject -# AFTER_INSTALLHDRS: targets to build after installing headers for a subproject -# BEFORE_INSTALLSRC: targets to build before installing source for a subproject -# AFTER_INSTALLSRC: targets to build after installing source for a subproject -# -# BEFORE_DEPEND: targets to build before building dependencies for a -# subproject -# AFTER_DEPEND: targets to build after building dependencies for a -# subproject -# -# AUTOMATIC_DEPENDENCY_INFO: if YES, then the dependency file is -# updated every time the project is built. If NO, the dependency -# file is only built when the depend target is invoked. - -# Framework-related variables: -# FRAMEWORK_DLL_INSTALLDIR: On Windows platforms, this variable indicates -# where to put the framework's DLL. This variable defaults to -# $(INSTALLDIR)/../Executables - -# Library-related variables: -# PUBLIC_HEADER_DIR: Determines where public exported header files -# should be installed. Do not include $(DSTROOT) in this value -- -# it is prefixed automatically. For library projects you should -# set this to something like /Developer/Headers/$(NAME). Do not set -# this variable for framework projects unless you do not want the -# header files included in the framework. -# PRIVATE_HEADER_DIR: Determines where private exported header files -# should be installed. Do not include $(DSTROOT) in this value -- -# it is prefixed automatically. -# LIBRARY_STYLE: This may be either STATIC or DYNAMIC, and determines -# whether the libraries produced are statically linked when they -# are used or if they are dynamically loadable. This defaults to -# DYNAMIC. -# LIBRARY_DLL_INSTALLDIR: On Windows platforms, this variable indicates -# where to put the library's DLL. This variable defaults to -# $(INSTALLDIR)/../Executables -# -# INSTALL_AS_USER: owner of the intalled products (default root) -# INSTALL_AS_GROUP: group of the installed products (default wheel) -# INSTALL_PERMISSIONS: permissions of the installed product (default o+rX) -# -# OTHER_RECURSIVE_VARIABLES: The names of variables which you want to be -# passed on the command line to recursive invocations of make. Note that -# the values in OTHER_*FLAGS are inherited by subprojects automatically -- -# you do not have to (and shouldn't) add OTHER_*FLAGS to -# OTHER_RECURSIVE_VARIABLES. - -# Additional headers to export beyond those in the PB.project: -# OTHER_PUBLIC_HEADERS -# OTHER_PROJECT_HEADERS -# OTHER_PRIVATE_HEADERS - -# Additional files for the project's product: <> -# OTHER_RESOURCES: (non-localized) resources for this project -# OTHER_OFILES: relocatables to be linked into this project -# OTHER_LIBS: more libraries to link against -# OTHER_PRODUCT_DEPENDS: other dependencies of this project -# OTHER_SOURCEFILES: other source files maintained by .pre/postamble -# OTHER_GARBAGE: additional files to be removed by `make clean' - -# Set this to YES if you don't want a final libtool call for a library/framework. -# BUILD_OFILES_LIST_ONLY - -# To include a version string, project source must exist in a directory named -# $(NAME).%d[.%d][.%d] and the following line must be uncommented. -# OTHER_GENERATED_OFILES = $(VERS_OFILE) - -# This definition will suppress stripping of debug symbols when an executable -# is installed. By default it is YES. -# STRIP_ON_INSTALL = NO - -# Uncomment to suppress generation of a KeyValueCoding index when installing -# frameworks (This index is used by WOB and IB to determine keys available -# for an object). Set to YES by default. -# PREINDEX_FRAMEWORK = NO - -# Change this definition to install projects somewhere other than the -# standard locations. NEXT_ROOT defaults to "C:/Apple" on Windows systems -# and "" on other systems. -DSTROOT = $(HOME) diff --git a/stdlib.subproj/PB.project b/stdlib.subproj/PB.project deleted file mode 100644 index 7480e6f..0000000 --- a/stdlib.subproj/PB.project +++ /dev/null @@ -1,51 +0,0 @@ -{ - DYNAMIC_CODE_GEN = YES; - FILESTABLE = { - H_FILES = (atexit.h); - OTHER_LINKED = ( - abort.c, - atexit.c, - atof.c, - atoi.c, - atol.c, - bsearch.c, - div.c, - exit.c, - getenv.c, - getopt.c, - getsubopt.c, - heapsort.c, - labs.c, - ldiv.c, - merge.c, - putenv.c, - qsort.c, - radixsort.c, - rand.c, - random.c, - setenv.c, - strtod.c, - strtol.c, - strtoq.c, - strtoul.c, - strtouq.c, - system.c - ); - OTHER_SOURCES = (Makefile.preamble, Makefile, Makefile.postamble); - SUBPROJECTS = (); - }; - LANGUAGE = English; - MAKEFILEDIR = "$(MAKEFILEPATH)/pb_makefiles"; - NEXTSTEP_BUILDTOOL = /bin/gnumake; - NEXTSTEP_JAVA_COMPILER = /usr/bin/javac; - NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc; - PDO_UNIX_BUILDTOOL = $NEXT_ROOT/Developer/bin/make; - PDO_UNIX_JAVA_COMPILER = "$(JDKBINDIR)/javac"; - PDO_UNIX_OBJCPLUS_COMPILER = "$(NEXTDEV_BIN)/gcc"; - PROJECTNAME = stdlib; - PROJECTTYPE = Component; - PROJECTVERSION = 2.8; - WINDOWS_BUILDTOOL = $NEXT_ROOT/Developer/Executables/make; - WINDOWS_JAVA_COMPILER = "$(JDKBINDIR)/javac.exe"; - WINDOWS_OBJCPLUS_COMPILER = "$(DEVDIR)/gcc"; -} diff --git a/stdlib.subproj/abort.c b/stdlib.subproj/abort.c deleted file mode 100644 index df2ae6e..0000000 --- a/stdlib.subproj/abort.c +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1985, 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 -#include -#include -#include - -void -abort() -{ - sigset_t mask; - - sigfillset(&mask); - /* - * don't block SIGABRT to give any handler a chance; we ignore - * any errors -- X311J doesn't allow abort to return anyway. - */ - sigdelset(&mask, SIGABRT); - (void)sigprocmask(SIG_SETMASK, &mask, (sigset_t *)NULL); - (void)kill(getpid(), SIGABRT); - - /* - * if SIGABRT ignored, or caught and the handler returns, do - * it again, only harder. - */ - (void)signal(SIGABRT, SIG_DFL); - (void)sigprocmask(SIG_SETMASK, &mask, (sigset_t *)NULL); - (void)kill(getpid(), SIGABRT); - exit(1); -} diff --git a/stdlib.subproj/atexit.c b/stdlib.subproj/atexit.c deleted file mode 100644 index 014fbce..0000000 --- a/stdlib.subproj/atexit.c +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * 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 -#include -#include "atexit.h" - -struct atexit *__atexit = NULL; /* points to head of LIFO stack */ - -/* - * Register a function to be performed at exit. - */ -int -atexit(fn) - void (*fn)(); -{ - static struct atexit __atexit0; /* one guaranteed table */ - register struct atexit *p; - - if ((p = __atexit) == NULL) - __atexit = p = &__atexit0; - else if (p->ind >= ATEXIT_SIZE) { - if ((p = malloc(sizeof(*p))) == NULL) - return (-1); - p->ind = 0; - p->next = __atexit; - __atexit = p; - } - p->fns[p->ind++] = fn; - return (0); -} diff --git a/stdlib.subproj/atexit.h b/stdlib.subproj/atexit.h deleted file mode 100644 index 27a7fa5..0000000 --- a/stdlib.subproj/atexit.h +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 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. - */ - -/* must be at least 32 to guarantee ANSI conformance */ -#define ATEXIT_SIZE 32 - -struct atexit { - struct atexit *next; /* next in list */ - int ind; /* next index in this table */ - void (*fns[ATEXIT_SIZE])(); /* the table itself */ -}; - -extern struct atexit *__atexit; /* points to head of LIFO stack */ - /* storage allocated in atexit.c */ diff --git a/stdlib.subproj/atof.c b/stdlib.subproj/atof.c deleted file mode 100644 index 49ad147..0000000 --- a/stdlib.subproj/atof.c +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1988, 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 - -double -atof(ascii) - const char *ascii; -{ - return (strtod(ascii, NULL)); -} - diff --git a/stdlib.subproj/atoi.c b/stdlib.subproj/atoi.c deleted file mode 100644 index c178b6a..0000000 --- a/stdlib.subproj/atoi.c +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1988, 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 -#include - -atoi(str) - const char *str; -{ - return((int)strtol(str, (char **)NULL, 10)); -} diff --git a/stdlib.subproj/atol.c b/stdlib.subproj/atol.c deleted file mode 100644 index 5aec484..0000000 --- a/stdlib.subproj/atol.c +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1988, 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 -#include - -long -atol(str) - const char *str; -{ - return(strtol(str, (char **)NULL, 10)); -} diff --git a/stdlib.subproj/bsearch.c b/stdlib.subproj/bsearch.c deleted file mode 100644 index bb40138..0000000 --- a/stdlib.subproj/bsearch.c +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 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 -#include - -/* - * Perform a binary search. - * - * The code below is a bit sneaky. After a comparison fails, we - * divide the work in half by moving either left or right. If lim - * is odd, moving left simply involves halving lim: e.g., when lim - * is 5 we look at item 2, so we change lim to 2 so that we will - * look at items 0 & 1. If lim is even, the same applies. If lim - * is odd, moving right again involes halving lim, this time moving - * the base up one item past p: e.g., when lim is 5 we change base - * to item 3 and make lim 2 so that we will look at items 3 and 4. - * If lim is even, however, we have to shrink it by one before - * halving: e.g., when lim is 4, we still looked at item 2, so we - * have to make lim 3, then halve, obtaining 1, so that we will only - * look at item 3. - */ -void * -bsearch(key, base0, nmemb, size, compar) - register const void *key; - const void *base0; - size_t nmemb; - register size_t size; - register int (*compar) __P((const void *, const void *)); -{ - register const char *base = base0; - register size_t lim; - register int cmp; - register const void *p; - - for (lim = nmemb; lim != 0; lim >>= 1) { - p = base + (lim >> 1) * size; - cmp = (*compar)(key, p); - if (cmp == 0) - return ((void *)p); - if (cmp > 0) { /* key > p: move right */ - base = (char *)p + size; - lim--; - } /* else move left */ - } - return (NULL); -} diff --git a/stdlib.subproj/div.c b/stdlib.subproj/div.c deleted file mode 100644 index c6594e6..0000000 --- a/stdlib.subproj/div.c +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * 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 /* div_t */ - -div_t -div(num, denom) - int num, denom; -{ - div_t r; - - r.quot = num / denom; - r.rem = num % denom; - /* - * The ANSI standard says that |r.quot| <= |n/d|, where - * n/d is to be computed in infinite precision. In other - * words, we should always truncate the quotient towards - * 0, never -infinity. - * - * Machine division and remainer may work either way when - * one or both of n or d is negative. If only one is - * negative and r.quot has been truncated towards -inf, - * r.rem will have the same sign as denom and the opposite - * sign of num; if both are negative and r.quot has been - * truncated towards -inf, r.rem will be positive (will - * have the opposite sign of num). These are considered - * `wrong'. - * - * If both are num and denom are positive, r will always - * be positive. - * - * This all boils down to: - * if num >= 0, but r.rem < 0, we got the wrong answer. - * In that case, to get the right answer, add 1 to r.quot and - * subtract denom from r.rem. - */ - if (num >= 0 && r.rem < 0) { - r.quot++; - r.rem -= denom; - } - return (r); -} diff --git a/stdlib.subproj/exit.c b/stdlib.subproj/exit.c deleted file mode 100644 index 133133d..0000000 --- a/stdlib.subproj/exit.c +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 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 -#include -#include "atexit.h" - -void (*__cleanup)() = NULL; - -/* - * Exit, flushing stdio buffers if necessary. - */ -void -exit(status) - int status; -{ - register struct atexit *p; - register int n; - - for (p = __atexit; p; p = p->next) - for (n = p->ind; --n >= 0;) - (*p->fns[n])(); - if (__cleanup) - (*__cleanup)(); - _exit(status); -} diff --git a/stdlib.subproj/getenv.c b/stdlib.subproj/getenv.c deleted file mode 100644 index 51d9073..0000000 --- a/stdlib.subproj/getenv.c +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1987, 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 -#include -#include - -#include - -char *__findenv __P((const char *, int *)); - -/* - * getenv -- - * Returns ptr to value associated with name, if any, else NULL. - */ -char * -getenv(name) - const char *name; -{ - int offset; - - return (__findenv(name, &offset)); -} - -/* - * __findenv -- - * Returns pointer to value associated with name, if any, else NULL. - * Sets offset to be the offset of the name/value combination in the - * environmental array, for use by setenv(3) and unsetenv(3). - * Explicitly removes '=' in argument name. - * - * This routine *should* be a static; don't use it. - */ -char * -__findenv(name, offset) - register const char *name; - int *offset; -{ - register int len; - register const char *np; - register char **p, *c; - - char **environ = *_NSGetEnviron(); - - if (name == NULL || environ == NULL) - return (NULL); - for (np = name; *np && *np != '='; ++np) - continue; - len = np - name; - for (p = environ; (c = *p) != NULL; ++p) - if (strncmp(c, name, len) == 0 && c[len] == '=') { - *offset = p - environ; - return (c + len + 1); - } - return (NULL); -} diff --git a/stdlib.subproj/getopt.c b/stdlib.subproj/getopt.c deleted file mode 100644 index d5075b7..0000000 --- a/stdlib.subproj/getopt.c +++ /dev/null @@ -1,137 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1987, 1993, 1994 - * 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 -#include -#include - -#include - -int opterr = 1, /* if error message should be printed */ - optind = 1, /* index into parent argv vector */ - optopt, /* character checked for validity */ - optreset; /* reset getopt */ -char *optarg; /* argument associated with option */ - -#define BADCH (int)'?' -#define BADARG (int)':' -#define EMSG "" - -/* - * getopt -- - * Parse argc/argv argument vector. - */ -int -getopt(nargc, nargv, ostr) - int nargc; - char * const *nargv; - const char *ostr; -{ - char *__progname = *(*_NSGetArgv()); - static char *place = EMSG; /* option letter processing */ - char *oli; /* option letter list index */ - - if (optreset || !*place) { /* update scanning pointer */ - optreset = 0; - if (optind >= nargc || *(place = nargv[optind]) != '-') { - place = EMSG; - return (EOF); - } - if (place[1] && *++place == '-') { /* found "--" */ - ++optind; - place = EMSG; - return (EOF); - } - } /* option letter okay? */ - if ((optopt = (int)*place++) == (int)':' || - !(oli = strchr(ostr, optopt))) { - /* - * if the user didn't specify '-' as an option, - * assume it means EOF. - */ - if (optopt == (int)'-') - return (EOF); - if (!*place) - ++optind; - if (opterr && *ostr != ':') - (void)fprintf(stderr, - "%s: illegal option -- %c\n", __progname, optopt); - return (BADCH); - } - if (*++oli != ':') { /* don't need argument */ - optarg = NULL; - if (!*place) - ++optind; - } - else { /* need an argument */ - if (*place) /* no white space */ - optarg = place; - else if (nargc <= ++optind) { /* no arg */ - place = EMSG; - if (*ostr == ':') - return (BADARG); - if (opterr) - (void)fprintf(stderr, - "%s: option requires an argument -- %c\n", - __progname, optopt); - return (BADCH); - } - else /* white space */ - optarg = nargv[optind]; - place = EMSG; - ++optind; - } - return (optopt); /* dump back option letter */ -} diff --git a/stdlib.subproj/getsubopt.c b/stdlib.subproj/getsubopt.c deleted file mode 100644 index d4d6813..0000000 --- a/stdlib.subproj/getsubopt.c +++ /dev/null @@ -1,116 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 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 -#include - -/* - * The SVID interface to getsubopt provides no way of figuring out which - * part of the suboptions list wasn't matched. This makes error messages - * tricky... The extern variable suboptarg is a pointer to the token - * which didn't match. - */ -char *suboptarg; - -getsubopt(optionp, tokens, valuep) - register char **optionp, **valuep; - register char * const *tokens; -{ - register int cnt; - register char *p; - - suboptarg = *valuep = NULL; - - if (!optionp || !*optionp) - return(-1); - - /* skip leading white-space, commas */ - for (p = *optionp; *p && (*p == ',' || *p == ' ' || *p == '\t'); ++p); - - if (!*p) { - *optionp = p; - return(-1); - } - - /* save the start of the token, and skip the rest of the token. */ - for (suboptarg = p; - *++p && *p != ',' && *p != '=' && *p != ' ' && *p != '\t';); - - if (*p) { - /* - * If there's an equals sign, set the value pointer, and - * skip over the value part of the token. Terminate the - * token. - */ - if (*p == '=') { - *p = '\0'; - for (*valuep = ++p; - *p && *p != ',' && *p != ' ' && *p != '\t'; ++p); - if (*p) - *p++ = '\0'; - } else - *p++ = '\0'; - /* Skip any whitespace or commas after this token. */ - for (; *p && (*p == ',' || *p == ' ' || *p == '\t'); ++p); - } - - /* set optionp for next round. */ - *optionp = p; - - for (cnt = 0; *tokens; ++tokens, ++cnt) - if (!strcmp(suboptarg, *tokens)) - return(cnt); - return(-1); -} diff --git a/stdlib.subproj/heapsort.c b/stdlib.subproj/heapsort.c deleted file mode 100644 index 0b8b1be..0000000 --- a/stdlib.subproj/heapsort.c +++ /dev/null @@ -1,202 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1991, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Ronnie Kon at Mindcraft Inc., Kevin Lew and Elmer Yglesias. - * - * 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 -#include -#include -#include - -/* - * Swap two areas of size number of bytes. Although qsort(3) permits random - * blocks of memory to be sorted, sorting pointers is almost certainly the - * common case (and, were it not, could easily be made so). Regardless, it - * isn't worth optimizing; the SWAP's get sped up by the cache, and pointer - * arithmetic gets lost in the time required for comparison function calls. - */ -#define SWAP(a, b, count, size, tmp) { \ - count = size; \ - do { \ - tmp = *a; \ - *a++ = *b; \ - *b++ = tmp; \ - } while (--count); \ -} - -/* Copy one block of size size to another. */ -#define COPY(a, b, count, size, tmp1, tmp2) { \ - count = size; \ - tmp1 = a; \ - tmp2 = b; \ - do { \ - *tmp1++ = *tmp2++; \ - } while (--count); \ -} - -/* - * Build the list into a heap, where a heap is defined such that for - * the records K1 ... KN, Kj/2 >= Kj for 1 <= j/2 <= j <= N. - * - * There two cases. If j == nmemb, select largest of Ki and Kj. If - * j < nmemb, select largest of Ki, Kj and Kj+1. - */ -#define CREATE(initval, nmemb, par_i, child_i, par, child, size, count, tmp) { \ - for (par_i = initval; (child_i = par_i * 2) <= nmemb; \ - par_i = child_i) { \ - child = base + child_i * size; \ - if (child_i < nmemb && compar(child, child + size) < 0) { \ - child += size; \ - ++child_i; \ - } \ - par = base + par_i * size; \ - if (compar(child, par) <= 0) \ - break; \ - SWAP(par, child, count, size, tmp); \ - } \ -} - -/* - * Select the top of the heap and 'heapify'. Since by far the most expensive - * action is the call to the compar function, a considerable optimization - * in the average case can be achieved due to the fact that k, the displaced - * elememt, is ususally quite small, so it would be preferable to first - * heapify, always maintaining the invariant that the larger child is copied - * over its parent's record. - * - * Then, starting from the *bottom* of the heap, finding k's correct place, - * again maintianing the invariant. As a result of the invariant no element - * is 'lost' when k is assigned its correct place in the heap. - * - * The time savings from this optimization are on the order of 15-20% for the - * average case. See Knuth, Vol. 3, page 158, problem 18. - * - * XXX Don't break the #define SELECT line, below. Reiser cpp gets upset. - */ -#define SELECT(par_i, child_i, nmemb, par, child, size, k, count, tmp1, tmp2) { \ - for (par_i = 1; (child_i = par_i * 2) <= nmemb; par_i = child_i) { \ - child = base + child_i * size; \ - if (child_i < nmemb && compar(child, child + size) < 0) { \ - child += size; \ - ++child_i; \ - } \ - par = base + par_i * size; \ - COPY(par, child, count, size, tmp1, tmp2); \ - } \ - for (;;) { \ - child_i = par_i; \ - par_i = child_i / 2; \ - child = base + child_i * size; \ - par = base + par_i * size; \ - if (child_i == 1 || compar(k, par) < 0) { \ - COPY(child, k, count, size, tmp1, tmp2); \ - break; \ - } \ - COPY(child, par, count, size, tmp1, tmp2); \ - } \ -} - -/* - * Heapsort -- Knuth, Vol. 3, page 145. Runs in O (N lg N), both average - * and worst. While heapsort is faster than the worst case of quicksort, - * the BSD quicksort does median selection so that the chance of finding - * a data set that will trigger the worst case is nonexistent. Heapsort's - * only advantage over quicksort is that it requires little additional memory. - */ -int -heapsort(vbase, nmemb, size, compar) - void *vbase; - size_t nmemb, size; - int (*compar) __P((const void *, const void *)); -{ - register int cnt, i, j, l; - register char tmp, *tmp1, *tmp2; - char *base, *k, *p, *t; - - if (nmemb <= 1) - return (0); - - if (!size) { - errno = EINVAL; - return (-1); - } - - if ((k = malloc(size)) == NULL) - return (-1); - - /* - * Items are numbered from 1 to nmemb, so offset from size bytes - * below the starting address. - */ - base = (char *)vbase - size; - - for (l = nmemb / 2 + 1; --l;) - CREATE(l, nmemb, i, j, t, p, size, cnt, tmp); - - /* - * For each element of the heap, save the largest element into its - * final slot, save the displaced element (k), then recreate the - * heap. - */ - while (nmemb > 1) { - COPY(k, base + nmemb * size, cnt, size, tmp1, tmp2); - COPY(base + nmemb * size, base + size, cnt, size, tmp1, tmp2); - --nmemb; - SELECT(i, j, nmemb, t, p, size, k, cnt, tmp1, tmp2); - } - free(k); - return (0); -} diff --git a/stdlib.subproj/labs.c b/stdlib.subproj/labs.c deleted file mode 100644 index 5267e5d..0000000 --- a/stdlib.subproj/labs.c +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 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[] = "@(#)labs.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ - -#include - -long -labs(j) - long j; -{ - return(j < 0 ? -j : j); -} diff --git a/stdlib.subproj/ldiv.c b/stdlib.subproj/ldiv.c deleted file mode 100644 index 83f63e4..0000000 --- a/stdlib.subproj/ldiv.c +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * 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 /* ldiv_t */ - -ldiv_t -ldiv(num, denom) - long num, denom; -{ - ldiv_t r; - - /* see div.c for comments */ - - r.quot = num / denom; - r.rem = num % denom; - if (num >= 0 && r.rem < 0) { - r.quot++; - r.rem -= denom; - } - return (r); -} diff --git a/stdlib.subproj/merge.c b/stdlib.subproj/merge.c deleted file mode 100644 index c71e767..0000000 --- a/stdlib.subproj/merge.c +++ /dev/null @@ -1,365 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1992, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Peter McIlroy. - * - * 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. - */ - - -/* - * Hybrid exponential search/linear search merge sort with hybrid - * natural/pairwise first pass. Requires about .3% more comparisons - * for random data than LSMS with pairwise first pass alone. - * It works for objects as small as two bytes. - */ - -#define NATURAL -#define THRESHOLD 16 /* Best choice for natural merge cut-off. */ - -/* #define NATURAL to get hybrid natural merge. - * (The default is pairwise merging.) - */ - -#include - -#include -#include -#include - -static void setup __P((u_char *, u_char *, size_t, size_t, int (*)())); -static void insertionsort __P((u_char *, size_t, size_t, int (*)())); - -#define ISIZE sizeof(int) -#define PSIZE sizeof(u_char *) -#define ICOPY_LIST(src, dst, last) \ - do \ - *(int*)dst = *(int*)src, src += ISIZE, dst += ISIZE; \ - while(src < last) -#define ICOPY_ELT(src, dst, i) \ - do \ - *(int*) dst = *(int*) src, src += ISIZE, dst += ISIZE; \ - while (i -= ISIZE) - -#define CCOPY_LIST(src, dst, last) \ - do \ - *dst++ = *src++; \ - while (src < last) -#define CCOPY_ELT(src, dst, i) \ - do \ - *dst++ = *src++; \ - while (i -= 1) - -/* - * Find the next possible pointer head. (Trickery for forcing an array - * to do double duty as a linked list when objects do not align with word - * boundaries. - */ -/* Assumption: PSIZE is a power of 2. */ -#define EVAL(p) (u_char **) \ - ((u_char *)0 + \ - (((u_char *)p + PSIZE - 1 - (u_char *) 0) & ~(PSIZE - 1))) - -/* - * Arguments are as for qsort. - */ -int -mergesort(base, nmemb, size, cmp) - void *base; - size_t nmemb; - register size_t size; - int (*cmp) __P((const void *, const void *)); -{ - register int i, sense; - int big, iflag; - register u_char *f1, *f2, *t, *b, *tp2, *q, *l1, *l2; - u_char *list2, *list1, *p2, *p, *last, **p1; - - if (size < PSIZE / 2) { /* Pointers must fit into 2 * size. */ - errno = EINVAL; - return (-1); - } - - /* - * XXX - * Stupid subtraction for the Cray. - */ - iflag = 0; - if (!(size % ISIZE) && !(((char *)base - (char *)0) % ISIZE)) - iflag = 1; - - if ((list2 = malloc(nmemb * size + PSIZE)) == NULL) - return (-1); - - list1 = base; - setup(list1, list2, nmemb, size, cmp); - last = list2 + nmemb * size; - i = big = 0; - while (*EVAL(list2) != last) { - l2 = list1; - p1 = EVAL(list1); - for (tp2 = p2 = list2; p2 != last; p1 = EVAL(l2)) { - p2 = *EVAL(p2); - f1 = l2; - f2 = l1 = list1 + (p2 - list2); - if (p2 != last) - p2 = *EVAL(p2); - l2 = list1 + (p2 - list2); - while (f1 < l1 && f2 < l2) { - if ((*cmp)(f1, f2) <= 0) { - q = f2; - b = f1, t = l1; - sense = -1; - } else { - q = f1; - b = f2, t = l2; - sense = 0; - } - if (!big) { /* here i = 0 */ -LINEAR: while ((b += size) < t && cmp(q, b) >sense) - if (++i == 6) { - big = 1; - goto EXPONENTIAL; - } - } else { -EXPONENTIAL: for (i = size; ; i <<= 1) - if ((p = (b + i)) >= t) { - if ((p = t - size) > b && - (*cmp)(q, p) <= sense) - t = p; - else - b = p; - break; - } else if ((*cmp)(q, p) <= sense) { - t = p; - if (i == size) - big = 0; - goto FASTCASE; - } else - b = p; -SLOWCASE: while (t > b+size) { - i = (((t - b) / size) >> 1) * size; - if ((*cmp)(q, p = b + i) <= sense) - t = p; - else - b = p; - } - goto COPY; -FASTCASE: while (i > size) - if ((*cmp)(q, - p = b + (i >>= 1)) <= sense) - t = p; - else - b = p; -COPY: b = t; - } - i = size; - if (q == f1) { - if (iflag) { - ICOPY_LIST(f2, tp2, b); - ICOPY_ELT(f1, tp2, i); - } else { - CCOPY_LIST(f2, tp2, b); - CCOPY_ELT(f1, tp2, i); - } - } else { - if (iflag) { - ICOPY_LIST(f1, tp2, b); - ICOPY_ELT(f2, tp2, i); - } else { - CCOPY_LIST(f1, tp2, b); - CCOPY_ELT(f2, tp2, i); - } - } - } - if (f2 < l2) { - if (iflag) - ICOPY_LIST(f2, tp2, l2); - else - CCOPY_LIST(f2, tp2, l2); - } else if (f1 < l1) { - if (iflag) - ICOPY_LIST(f1, tp2, l1); - else - CCOPY_LIST(f1, tp2, l1); - } - *p1 = l2; - } - tp2 = list1; /* swap list1, list2 */ - list1 = list2; - list2 = tp2; - last = list2 + nmemb*size; - } - if (base == list2) { - memmove(list2, list1, nmemb*size); - list2 = list1; - } - free(list2); - return (0); -} - -#define swap(a, b) { \ - s = b; \ - i = size; \ - do { \ - tmp = *a; *a++ = *s; *s++ = tmp; \ - } while (--i); \ - a -= size; \ - } -#define reverse(bot, top) { \ - s = top; \ - do { \ - i = size; \ - do { \ - tmp = *bot; *bot++ = *s; *s++ = tmp; \ - } while (--i); \ - s -= size2; \ - } while(bot < s); \ -} - -/* - * Optional hybrid natural/pairwise first pass. Eats up list1 in runs of - * increasing order, list2 in a corresponding linked list. Checks for runs - * when THRESHOLD/2 pairs compare with same sense. (Only used when NATURAL - * is defined. Otherwise simple pairwise merging is used.) - */ -void -setup(list1, list2, n, size, cmp) - size_t n, size; - int (*cmp) __P((const void *, const void *)); - u_char *list1, *list2; -{ - int i, length, size2, tmp, sense; - u_char *f1, *f2, *s, *l2, *last, *p2; - - size2 = size*2; - if (n <= 5) { - insertionsort(list1, n, size, cmp); - *EVAL(list2) = (u_char*) list2 + n*size; - return; - } - /* - * Avoid running pointers out of bounds; limit n to evens - * for simplicity. - */ - i = 4 + (n & 1); - insertionsort(list1 + (n - i) * size, i, size, cmp); - last = list1 + size * (n - i); - *EVAL(list2 + (last - list1)) = list2 + n * size; - -#ifdef NATURAL - p2 = list2; - f1 = list1; - sense = (cmp(f1, f1 + size) > 0); - for (; f1 < last; sense = !sense) { - length = 2; - /* Find pairs with same sense. */ - for (f2 = f1 + size2; f2 < last; f2 += size2) { - if ((cmp(f2, f2+ size) > 0) != sense) - break; - length += 2; - } - if (length < THRESHOLD) { /* Pairwise merge */ - do { - p2 = *EVAL(p2) = f1 + size2 - list1 + list2; - if (sense > 0) - swap (f1, f1 + size); - } while ((f1 += size2) < f2); - } else { /* Natural merge */ - l2 = f2; - for (f2 = f1 + size2; f2 < l2; f2 += size2) { - if ((cmp(f2-size, f2) > 0) != sense) { - p2 = *EVAL(p2) = f2 - list1 + list2; - if (sense > 0) - reverse(f1, f2-size); - f1 = f2; - } - } - if (sense > 0) - reverse (f1, f2-size); - f1 = f2; - if (f2 < last || cmp(f2 - size, f2) > 0) - p2 = *EVAL(p2) = f2 - list1 + list2; - else - p2 = *EVAL(p2) = list2 + n*size; - } - } -#else /* pairwise merge only. */ - for (f1 = list1, p2 = list2; f1 < last; f1 += size2) { - p2 = *EVAL(p2) = p2 + size2; - if (cmp (f1, f1 + size) > 0) - swap(f1, f1 + size); - } -#endif /* NATURAL */ -} - -/* - * This is to avoid out-of-bounds addresses in sorting the - * last 4 elements. - */ -static void -insertionsort(a, n, size, cmp) - u_char *a; - size_t n, size; - int (*cmp) __P((const void *, const void *)); -{ - u_char *ai, *s, *t, *u, tmp; - int i; - - for (ai = a+size; --n >= 1; ai += size) - for (t = ai; t > a; t -= size) { - u = t - size; - if (cmp(u, t) <= 0) - break; - swap(u, t); - } -} diff --git a/stdlib.subproj/putenv.c b/stdlib.subproj/putenv.c deleted file mode 100644 index 2fbe267..0000000 --- a/stdlib.subproj/putenv.c +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1988, 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 -#include - -int -putenv(str) - const char *str; -{ - char *p, *equal; - int rval; - - if ((p = strdup(str)) == NULL) - return (-1); - if ((equal = index(p, '=')) == NULL) { - (void)free(p); - return (-1); - } - *equal = '\0'; - rval = setenv(p, equal + 1, 1); - (void)free(p); - return (rval); -} diff --git a/stdlib.subproj/qsort.c b/stdlib.subproj/qsort.c deleted file mode 100644 index d0d2fc6..0000000 --- a/stdlib.subproj/qsort.c +++ /dev/null @@ -1,192 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * 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. - */ - - -#include -#include - -static inline char *med3 __P((char *, char *, char *, int (*)())); -static inline void swapfunc __P((char *, char *, int, int)); - -#define min(a, b) (a) < (b) ? a : b - -/* - * Qsort routine from Bentley & McIlroy's "Engineering a Sort Function". - */ -#define swapcode(TYPE, parmi, parmj, n) { \ - long i = (n) / sizeof (TYPE); \ - register TYPE *pi = (TYPE *) (parmi); \ - register TYPE *pj = (TYPE *) (parmj); \ - do { \ - register TYPE t = *pi; \ - *pi++ = *pj; \ - *pj++ = t; \ - } while (--i > 0); \ -} - -#define SWAPINIT(a, es) swaptype = ((char *)a - (char *)0) % sizeof(long) || \ - es % sizeof(long) ? 2 : es == sizeof(long)? 0 : 1; - -static inline void -swapfunc(a, b, n, swaptype) - char *a, *b; - int n, swaptype; -{ - if(swaptype <= 1) - swapcode(long, a, b, n) - else - swapcode(char, a, b, n) -} - -#define swap(a, b) \ - if (swaptype == 0) { \ - long t = *(long *)(a); \ - *(long *)(a) = *(long *)(b); \ - *(long *)(b) = t; \ - } else \ - swapfunc(a, b, es, swaptype) - -#define vecswap(a, b, n) if ((n) > 0) swapfunc(a, b, n, swaptype) - -static inline char * -med3(a, b, c, cmp) - char *a, *b, *c; - int (*cmp)(); -{ - return cmp(a, b) < 0 ? - (cmp(b, c) < 0 ? b : (cmp(a, c) < 0 ? c : a )) - :(cmp(b, c) > 0 ? b : (cmp(a, c) < 0 ? a : c )); -} - -void -qsort(a, n, es, cmp) - void *a; - size_t n, es; - int (*cmp)(); -{ - char *pa, *pb, *pc, *pd, *pl, *pm, *pn; - int d, r, swaptype, swap_cnt; - -loop: SWAPINIT(a, es); - swap_cnt = 0; - if (n < 7) { - for (pm = a + es; pm < (char *) a + n * es; pm += es) - for (pl = pm; pl > (char *) a && cmp(pl - es, pl) > 0; - pl -= es) - swap(pl, pl - es); - return; - } - pm = a + (n / 2) * es; - if (n > 7) { - pl = a; - pn = a + (n - 1) * es; - if (n > 40) { - d = (n / 8) * es; - pl = med3(pl, pl + d, pl + 2 * d, cmp); - pm = med3(pm - d, pm, pm + d, cmp); - pn = med3(pn - 2 * d, pn - d, pn, cmp); - } - pm = med3(pl, pm, pn, cmp); - } - swap(a, pm); - pa = pb = a + es; - - pc = pd = a + (n - 1) * es; - for (;;) { - while (pb <= pc && (r = cmp(pb, a)) <= 0) { - if (r == 0) { - swap_cnt = 1; - swap(pa, pb); - pa += es; - } - pb += es; - } - while (pb <= pc && (r = cmp(pc, a)) >= 0) { - if (r == 0) { - swap_cnt = 1; - swap(pc, pd); - pd -= es; - } - pc -= es; - } - if (pb > pc) - break; - swap(pb, pc); - swap_cnt = 1; - pb += es; - pc -= es; - } - if (swap_cnt == 0) { /* Switch to insertion sort */ - for (pm = a + es; pm < (char *) a + n * es; pm += es) - for (pl = pm; pl > (char *) a && cmp(pl - es, pl) > 0; - pl -= es) - swap(pl, pl - es); - return; - } - - pn = a + n * es; - r = min(pa - (char *)a, pb - pa); - vecswap(a, pb - r, r); - r = min(pd - pc, pn - pd - es); - vecswap(pb, pn - r, r); - if ((r = pb - pa) > es) - qsort(a, r / es, es, cmp); - if ((r = pd - pc) > es) { - /* Iterate rather than recurse to save stack space */ - a = pn - r; - n = r / es; - goto loop; - } -/* qsort(pn - r, r / es, es, cmp);*/ -} diff --git a/stdlib.subproj/radixsort.c b/stdlib.subproj/radixsort.c deleted file mode 100644 index 53a02b5..0000000 --- a/stdlib.subproj/radixsort.c +++ /dev/null @@ -1,336 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Peter McIlroy and by Dan Bernstein at New York University, - * - * 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. - */ - - -/* - * Radixsort routines. - * - * Program r_sort_a() is unstable but uses O(logN) extra memory for a stack. - * Use radixsort(a, n, trace, endchar) for this case. - * - * For stable sorting (using N extra pointers) use sradixsort(), which calls - * r_sort_b(). - * - * For a description of this code, see D. McIlroy, P. McIlroy, K. Bostic, - * "Engineering Radix Sort". - */ - -#include -#include -#include -#include - -typedef struct { - const u_char **sa; - int sn, si; -} stack; - -static inline void simplesort - __P((const u_char **, int, int, const u_char *, u_int)); -static void r_sort_a __P((const u_char **, int, int, const u_char *, u_int)); -static void r_sort_b __P((const u_char **, - const u_char **, int, int, const u_char *, u_int)); - -#define THRESHOLD 20 /* Divert to simplesort(). */ -#define SIZE 512 /* Default stack size. */ - -#define SETUP { \ - if (tab == NULL) { \ - tr = tr0; \ - for (c = 0; c < endch; c++) \ - tr0[c] = c + 1; \ - tr0[c] = 0; \ - for (c++; c < 256; c++) \ - tr0[c] = c; \ - endch = 0; \ - } else { \ - endch = tab[endch]; \ - tr = tab; \ - if (endch != 0 && endch != 255) { \ - errno = EINVAL; \ - return (-1); \ - } \ - } \ -} - -int -radixsort(a, n, tab, endch) - const u_char **a, *tab; - int n; - u_int endch; -{ - const u_char *tr; - int c; - u_char tr0[256]; - - SETUP; - r_sort_a(a, n, 0, tr, endch); - return (0); -} - -int -sradixsort(a, n, tab, endch) - const u_char **a, *tab; - int n; - u_int endch; -{ - const u_char *tr, **ta; - int c; - u_char tr0[256]; - - SETUP; - if (n < THRESHOLD) - simplesort(a, n, 0, tr, endch); - else { - if ((ta = malloc(n * sizeof(a))) == NULL) - return (-1); - r_sort_b(a, ta, n, 0, tr, endch); - free(ta); - } - return (0); -} - -#define empty(s) (s >= sp) -#define pop(a, n, i) a = (--sp)->sa, n = sp->sn, i = sp->si -#define push(a, n, i) sp->sa = a, sp->sn = n, (sp++)->si = i -#define swap(a, b, t) t = a, a = b, b = t - -/* Unstable, in-place sort. */ -static void -r_sort_a(a, n, i, tr, endch) - const u_char **a; - int n, i; - const u_char *tr; - u_int endch; -{ - static int count[256], nc, bmin; - register int c; - register const u_char **ak, *r; - stack s[SIZE], *sp, *sp0, *sp1, temp; - int *cp, bigc; - const u_char **an, *t, **aj, **top[256]; - - /* Set up stack. */ - sp = s; - push(a, n, i); - while (!empty(s)) { - pop(a, n, i); - if (n < THRESHOLD) { - simplesort(a, n, i, tr, endch); - continue; - } - an = a + n; - - /* Make character histogram. */ - if (nc == 0) { - bmin = 255; /* First occupied bin, excluding eos. */ - for (ak = a; ak < an;) { - c = tr[(*ak++)[i]]; - if (++count[c] == 1 && c != endch) { - if (c < bmin) - bmin = c; - nc++; - } - } - if (sp + nc > s + SIZE) { /* Get more stack. */ - r_sort_a(a, n, i, tr, endch); - continue; - } - } - - /* - * Set top[]; push incompletely sorted bins onto stack. - * top[] = pointers to last out-of-place element in bins. - * count[] = counts of elements in bins. - * Before permuting: top[c-1] + count[c] = top[c]; - * during deal: top[c] counts down to top[c-1]. - */ - sp0 = sp1 = sp; /* Stack position of biggest bin. */ - bigc = 2; /* Size of biggest bin. */ - if (endch == 0) /* Special case: set top[eos]. */ - top[0] = ak = a + count[0]; - else { - ak = a; - top[255] = an; - } - for (cp = count + bmin; nc > 0; cp++) { - while (*cp == 0) /* Find next non-empty pile. */ - cp++; - if (*cp > 1) { - if (*cp > bigc) { - bigc = *cp; - sp1 = sp; - } - push(ak, *cp, i+1); - } - top[cp-count] = ak += *cp; - nc--; - } - swap(*sp0, *sp1, temp); /* Play it safe -- biggest bin last. */ - - /* - * Permute misplacements home. Already home: everything - * before aj, and in bin[c], items from top[c] on. - * Inner loop: - * r = next element to put in place; - * ak = top[r[i]] = location to put the next element. - * aj = bottom of 1st disordered bin. - * Outer loop: - * Once the 1st disordered bin is done, ie. aj >= ak, - * aj<-aj + count[c] connects the bins in a linked list; - * reset count[c]. - */ - for (aj = a; aj < an; *aj = r, aj += count[c], count[c] = 0) - for (r = *aj; aj < (ak = --top[c = tr[r[i]]]);) - swap(*ak, r, t); - } -} - -/* Stable sort, requiring additional memory. */ -static void -r_sort_b(a, ta, n, i, tr, endch) - const u_char **a, **ta; - int n, i; - const u_char *tr; - u_int endch; -{ - static int count[256], nc, bmin; - register int c; - register const u_char **ak, **ai; - stack s[512], *sp, *sp0, *sp1, temp; - const u_char **top[256]; - int *cp, bigc; - - sp = s; - push(a, n, i); - while (!empty(s)) { - pop(a, n, i); - if (n < THRESHOLD) { - simplesort(a, n, i, tr, endch); - continue; - } - - if (nc == 0) { - bmin = 255; - for (ak = a + n; --ak >= a;) { - c = tr[(*ak)[i]]; - if (++count[c] == 1 && c != endch) { - if (c < bmin) - bmin = c; - nc++; - } - } - if (sp + nc > s + SIZE) { - r_sort_b(a, ta, n, i, tr, endch); - continue; - } - } - - sp0 = sp1 = sp; - bigc = 2; - if (endch == 0) { - top[0] = ak = a + count[0]; - count[0] = 0; - } else { - ak = a; - top[255] = a + n; - count[255] = 0; - } - for (cp = count + bmin; nc > 0; cp++) { - while (*cp == 0) - cp++; - if ((c = *cp) > 1) { - if (c > bigc) { - bigc = c; - sp1 = sp; - } - push(ak, c, i+1); - } - top[cp-count] = ak += c; - *cp = 0; /* Reset count[]. */ - nc--; - } - swap(*sp0, *sp1, temp); - - for (ak = ta + n, ai = a+n; ak > ta;) /* Copy to temp. */ - *--ak = *--ai; - for (ak = ta+n; --ak >= ta;) /* Deal to piles. */ - *--top[tr[(*ak)[i]]] = *ak; - } -} - -static inline void -simplesort(a, n, b, tr, endch) /* insertion sort */ - register const u_char **a; - int n, b; - register const u_char *tr; - u_int endch; -{ - register u_char ch; - const u_char **ak, **ai, *s, *t; - - for (ak = a+1; --n >= 1; ak++) - for (ai = ak; ai > a; ai--) { - for (s = ai[0] + b, t = ai[-1] + b; - (ch = tr[*s]) != endch; s++, t++) - if (ch != tr[*t]) - break; - if (ch >= tr[*t]) - break; - swap(ai[0], ai[-1], s); - } -} diff --git a/stdlib.subproj/rand.c b/stdlib.subproj/rand.c deleted file mode 100644 index 0379c8f..0000000 --- a/stdlib.subproj/rand.c +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 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 -#include - -static u_long next = 1; - -int -rand() -{ - return ((next = next * 1103515245 + 12345) % ((u_long)RAND_MAX + 1)); -} - -void -srand(seed) -u_int seed; -{ - next = seed; -} diff --git a/stdlib.subproj/random.c b/stdlib.subproj/random.c deleted file mode 100644 index 722e805..0000000 --- a/stdlib.subproj/random.c +++ /dev/null @@ -1,399 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1983, 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 -#include - -/* - * random.c: - * - * An improved random number generation package. In addition to the standard - * rand()/srand() like interface, this package also has a special state info - * interface. The initstate() routine is called with a seed, an array of - * bytes, and a count of how many bytes are being passed in; this array is - * then initialized to contain information for random number generation with - * that much state information. Good sizes for the amount of state - * information are 32, 64, 128, and 256 bytes. The state can be switched by - * calling the setstate() routine with the same array as was initiallized - * with initstate(). By default, the package runs with 128 bytes of state - * information and generates far better random numbers than a linear - * 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 - * 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 - * 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). - * - * The random number generation technique is a linear feedback shift register - * approach, employing trinomials (since there are fewer terms to sum up that - * way). In this approach, the least significant bit of all the numbers in - * the state table will act as a linear feedback shift register, and will - * have period 2^deg - 1 (where deg is the degree of the polynomial being - * used, assuming that the polynomial is irreducible and primitive). The - * higher order bits will have longer periods, since their values are also - * influenced by pseudo-random carries out of the lower bits. The total - * period of the generator is approximately deg*(2**deg - 1); thus doubling - * the amount of state information has a vast influence on the period of the - * generator. Note: the deg*(2**deg - 1) is an approximation only good for - * large deg, when the period of the shift register is the dominant factor. - * With deg equal to seven, the period is actually much longer than the - * 7*(2**7 - 1) predicted by this formula. - */ - -/* - * For each of the currently supported random number generators, we have a - * break value on the amount of state information (you need at least this - * many bytes of state info to support this random number generator), a degree - * for the polynomial (actually a trinomial) that the R.N.G. is based on, and - * the separation between the two lower order coefficients of the trinomial. - */ -#define TYPE_0 0 /* linear congruential */ -#define BREAK_0 8 -#define DEG_0 0 -#define SEP_0 0 - -#define TYPE_1 1 /* x**7 + x**3 + 1 */ -#define BREAK_1 32 -#define DEG_1 7 -#define SEP_1 3 - -#define TYPE_2 2 /* x**15 + x + 1 */ -#define BREAK_2 64 -#define DEG_2 15 -#define SEP_2 1 - -#define TYPE_3 3 /* x**31 + x**3 + 1 */ -#define BREAK_3 128 -#define DEG_3 31 -#define SEP_3 3 - -#define TYPE_4 4 /* x**63 + x + 1 */ -#define BREAK_4 256 -#define DEG_4 63 -#define SEP_4 1 - -/* - * Array versions of the above information to make code run faster -- - * relies on fact that TYPE_i == i. - */ -#define MAX_TYPES 5 /* max number of types above */ - -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 }; - -/* - * Initially, everything is set up as if from: - * - * initstate(1, &randtbl, 128); - * - * Note that this initialization takes advantage of the fact that srandom() - * advances the front and rear pointers 10*rand_deg times, and hence the - * rear pointer which starts at 0 will also end up at zero; thus the zeroeth - * element of the state information, which contains info about the current - * position of the rear pointer is just - * - * MAX_TYPES * (rptr - state) + TYPE_3 == TYPE_3. - */ - -static long randtbl[DEG_3 + 1] = { - TYPE_3, - 0x9a319039, 0x32d9c024, 0x9b663182, 0x5da1f342, 0xde3b81e0, 0xdf0a6fb5, - 0xf103bc02, 0x48f340fb, 0x7449e56b, 0xbeb1dbb0, 0xab5c5918, 0x946554fd, - 0x8c2e680f, 0xeb3d799f, 0xb11ee0b7, 0x2d436b86, 0xda672e2a, 0x1588ca88, - 0xe369735d, 0x904f35f7, 0xd7158fd6, 0x6fa6f051, 0x616e6b96, 0xac94efdc, - 0x36413f93, 0xc622c298, 0xf5a42ab8, 0x8a88d77b, 0xf5ad9d0e, 0x8999220b, - 0x27fb47b9, -}; - -/* - * fptr and rptr are two pointers into the state info, a front and a rear - * pointer. These two pointers are always rand_sep places aparts, as they - * cycle cyclically through the state information. (Yes, this does mean we - * could get away with just one pointer, but the code for random() is more - * efficient this way). The pointers are left positioned as they would be - * from the call - * - * initstate(1, randtbl, 128); - * - * (The position of the rear pointer, rptr, is really 0 (as explained above - * 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]; - -/* - * The following things are the pointer to the state information table, the - * type of the current generator, the degree of the current polynomial being - * used, and the separation between the two pointers. Note that for efficiency - * of random(), we remember the first location of the state information, not - * the zeroeth. Hence it is valid to access state[-1], which is used to - * store the type of the R.N.G. Also, we remember the last location, since - * 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]; - -/* - * srandom: - * - * Initialize the random number generator based on the given seed. If the - * type is the trivial no-state-information type, just remember the seed. - * Otherwise, initializes state[] based on the given "seed" via a linear - * congruential generator. Then, the pointers are set to known locations - * that are exactly rand_sep places apart. Lastly, it cycles the state - * information a given number of times to get rid of any initial dependencies - * introduced by the L.C.R.N.G. Note that the initialization of randtbl[] - * for default usage relies on values produced by this routine. - */ -void -srandom(x) - unsigned long x; -{ - register long i; - - if (rand_type == TYPE_0) - state[0] = x; - else { - state[0] = x; - for (i = 1; i < rand_deg; i++) - state[i] = 1103515245 * state[i - 1] + 12345; - fptr = &state[rand_sep]; - rptr = &state[0]; - for (i = 0; i < 10 * rand_deg; i++) - (void)random(); - } -} - -/* - * initstate: - * - * Initialize the state information in the given array of n bytes for future - * random number generation. Based on the number of bytes we are given, and - * the break values for the different R.N.G.'s, we choose the best (largest) - * one we can and set things up for it. srandom() is then called to - * initialize the state information. - * - * Note that on return from srandom(), we set state[-1] to be the type - * multiplexed with the current value of the rear pointer; this is so - * successive calls to initstate() won't lose this information and will be - * able to restart with setstate(). - * - * Note: the first thing we do is save the current state, if any, just like - * setstate() so that it doesn't matter when initstate is called. - * - * Returns a pointer to the old state. - * - * Note: The Sparc platform requires that arg_state begin on a long - * word boundary; otherwise a bus error will occur. Even so, lint will - * complain about mis-alignment, but you should disregard these messages. - */ -char * -initstate(seed, arg_state, n) - unsigned long seed; /* seed for R.N.G. */ - char *arg_state; /* pointer to state array */ - long n; /* # bytes of state info */ -{ - register char *ostate = (char *)(&state[-1]); - register long *long_arg_state = (long *) arg_state; - - if (rand_type == TYPE_0) - state[-1] = rand_type; - else - state[-1] = MAX_TYPES * (rptr - state) + rand_type; - if (n < BREAK_0) { - (void)fprintf(stderr, - "random: not enough state (%ld bytes); ignored.\n", n); - return(0); - } - if (n < BREAK_1) { - rand_type = TYPE_0; - rand_deg = DEG_0; - rand_sep = SEP_0; - } else if (n < BREAK_2) { - rand_type = TYPE_1; - rand_deg = DEG_1; - rand_sep = SEP_1; - } else if (n < BREAK_3) { - rand_type = TYPE_2; - rand_deg = DEG_2; - rand_sep = SEP_2; - } else if (n < BREAK_4) { - rand_type = TYPE_3; - rand_deg = DEG_3; - rand_sep = SEP_3; - } else { - rand_type = TYPE_4; - rand_deg = DEG_4; - rand_sep = SEP_4; - } - state = (long *) (long_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; - else - long_arg_state[0] = MAX_TYPES * (rptr - state) + rand_type; - return(ostate); -} - -/* - * setstate: - * - * Restore the state from the given state array. - * - * Note: it is important that we also remember the locations of the pointers - * in the current state information, and restore the locations of the pointers - * from the old state information. This is done by multiplexing the pointer - * location into the zeroeth word of the state information. - * - * Note that due to the order in which things are done, it is OK to call - * setstate() with the same state as the current state. - * - * Returns a pointer to the old state information. - * - * Note: The Sparc platform requires that arg_state begin on a long - * word boundary; otherwise a bus error will occur. Even so, lint will - * complain about mis-alignment, but you should disregard these messages. - */ -char * -setstate(arg_state) - char *arg_state; /* pointer to state array */ -{ - register long *new_state = (long *) arg_state; - register long type = new_state[0] % MAX_TYPES; - register long rear = new_state[0] / MAX_TYPES; - char *ostate = (char *)(&state[-1]); - - if (rand_type == TYPE_0) - state[-1] = rand_type; - else - state[-1] = MAX_TYPES * (rptr - state) + rand_type; - switch(type) { - case TYPE_0: - case TYPE_1: - case TYPE_2: - case TYPE_3: - case TYPE_4: - rand_type = type; - rand_deg = degrees[type]; - rand_sep = seps[type]; - break; - default: - (void)fprintf(stderr, - "random: state info corrupted; not changed.\n"); - } - state = (long *) (new_state + 1); - if (rand_type != TYPE_0) { - rptr = &state[rear]; - fptr = &state[(rear + rand_sep) % rand_deg]; - } - end_ptr = &state[rand_deg]; /* set end_ptr too */ - return(ostate); -} - -/* - * random: - * - * If we are using the trivial TYPE_0 R.N.G., just do the old linear - * congruential bit. Otherwise, we do our fancy trinomial stuff, which is - * the same in all the other cases due to all the global variables that have - * been set up. The basic operation is to add the number at the rear pointer - * into the one at the front pointer. Then both pointers are advanced to - * the next location cyclically in the table. The value returned is the sum - * generated, reduced to 31 bits by throwing away the "least random" low bit. - * - * Note: the code takes advantage of the fact that both the front and - * rear pointers can't wrap on the same call by not testing the rear - * pointer if the front one has wrapped. - * - * Returns a 31-bit random number. - */ -long -random() -{ - register long i; - register long *f, *r; - - if (rand_type == TYPE_0) { - i = state[0]; - state[0] = i = (i * 1103515245 + 12345) & 0x7fffffff; - } else { - /* - * Use local variables rather than static variables for speed. - */ - f = fptr; r = rptr; - *f += *r; - i = (*f >> 1) & 0x7fffffff; /* chucking least random bit */ - if (++f >= end_ptr) { - f = state; - ++r; - } - else if (++r >= end_ptr) { - r = state; - } - - fptr = f; rptr = r; - } - return(i); -} diff --git a/stdlib.subproj/setenv.c b/stdlib.subproj/setenv.c deleted file mode 100644 index e74a41f..0000000 --- a/stdlib.subproj/setenv.c +++ /dev/null @@ -1,137 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1987, 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 -#include -#include - -#include - -char *__findenv __P((const char *, int *)); - -/* - * 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) - register const char *name; - register const char *value; - int rewrite; -{ - static int alloced; /* if allocated space before */ - register char *c; - int l_value, offset; - char ***environp = _NSGetEnviron(); - - 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); - } - } else { /* create new slot */ - register int cnt; - register char **p; - - for (p = *environp, cnt = 0; *p; ++p, ++cnt); - if (alloced) { /* just increase size */ - *environp = (char **)realloc((char *)*environp, - (size_t)(sizeof(char *) * (cnt + 2))); - if (!*environp) - return (-1); - } - else { /* get new space */ - alloced = 1; /* copy old entries into it */ - p = malloc((size_t)(sizeof(char *) * (cnt + 2))); - if (!p) - return (-1); - bcopy(*environp, p, cnt * sizeof(char *)); - *environp = p; - } - (*environp)[cnt + 1] = NULL; - offset = cnt; - } - for (c = (char *)name; *c && *c != '='; ++c); /* no `=' in name */ - if (!((*environp)[offset] = /* name + `=' + value */ - malloc((size_t)((int)(c - name) + l_value + 2)))) - return (-1); - for (c = (*environp)[offset]; (*c = *name++) && *c != '='; ++c); - for (*c++ = '='; *c++ = *value++;); - return (0); -} - -/* - * unsetenv(name) -- - * Delete environmental variable "name". - */ -void -unsetenv(name) - const char *name; -{ - char **environ = *_NSGetEnviron(); - register char **p; - int offset; - - while (__findenv(name, &offset)) /* if set multiple times */ - for (p = &environ[offset];; ++p) - if (!(*p = *(p + 1))) - break; -} diff --git a/stdlib.subproj/strtod.c b/stdlib.subproj/strtod.c deleted file mode 100644 index 05c075e..0000000 --- a/stdlib.subproj/strtod.c +++ /dev/null @@ -1,2508 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/**************************************************************** - * - * The author of this software is David M. Gay. - * - * Copyright (c) 1991 by AT&T. - * - * Permission to use, copy, modify, and distribute this software for any - * purpose without fee is hereby granted, provided that this entire notice - * is included in all copies of any software which is or includes a copy - * or modification of this software and in all copies of the supporting - * documentation for such software. - * - * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED - * WARRANTY. IN PARTICULAR, NEITHER THE AUTHOR NOR AT&T MAKES ANY - * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY - * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. - * - ***************************************************************/ - -/* Please send bug reports to - David M. Gay - AT&T Bell Laboratories, Room 2C-463 - 600 Mountain Avenue - Murray Hill, NJ 07974-2070 - U.S.A. - dmg@research.att.com or research!dmg - */ - -/* strtod for IEEE-, VAX-, and IBM-arithmetic machines. - * - * This strtod returns a nearest machine number to the input decimal - * string (or sets errno to ERANGE). With IEEE arithmetic, ties are - * broken by the IEEE round-even rule. Otherwise ties are broken by - * 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]. - * - * Modifications: - * - * 1. We only require IEEE, IBM, or VAX double-precision - * arithmetic (not IEEE double-extended). - * 2. We get by with floating-point arithmetic in a case that - * Clinger missed -- when we're computing d * 10^n - * for a small integer d and the integer n is not too - * much larger than 22 (the maximum integer k for which - * we can represent 10^k exactly), we may be able to - * compute (d*10^k) * 10^(e-k) with just one roundoff. - * 3. Rather than a bit-at-a-time adjustment of the binary - * result in the hard case, we use floating-point - * arithmetic to determine the adjustment to within - * one bit; only in really hard cases do we need to - * compute a second residual. - * 4. Because of 3., we don't need a large table of powers of 10 - * for ten-to-e (just some small tables, e.g. of 10^k - * for 0 <= k <= 22). - */ - -/* - * #define IEEE_LITTLE_ENDIAN for IEEE-arithmetic machines where the least - * significant byte has the lowest address. - * #define IEEE_BIG_ENDIAN for IEEE-arithmetic machines where the most - * significant byte has the lowest address. - * #define Long int on machines with 32-bit ints and 64-bit longs. - * #define Sudden_Underflow for IEEE-format machines without gradual - * underflow (i.e., that flush to zero on underflow). - * #define IBM for IBM mainframe-style floating-point arithmetic. - * #define VAX for VAX-style floating-point arithmetic. - * #define Unsigned_Shifts if >> does treats its left operand as unsigned. - * #define No_leftright to omit left-right logic in fast floating-point - * computation of dtoa. - * #define Check_FLT_ROUNDS if FLT_ROUNDS can assume the values 2 or 3. - * #define RND_PRODQUOT to use rnd_prod and rnd_quot (assembly routines - * that use extended-precision instructions to compute rounded - * products and quotients) with IBM. - * #define ROUND_BIASED for IEEE-format with biased rounding. - * #define Inaccurate_Divide for IEEE-format with correctly rounded - * products but inaccurate quotients, e.g., for Intel i860. - * #define Just_16 to store 16 bits per 32-bit Long when doing high-precision - * integer arithmetic. Whether this speeds things up or slows things - * down depends on the machine and the number being converted. - * #define KR_headers for old-style C function headers. - * #define Bad_float_h if your system lacks a float.h or if it does not - * define some or all of DBL_DIG, DBL_MAX_10_EXP, DBL_MAX_EXP, - * FLT_RADIX, FLT_ROUNDS, and DBL_MAX. - * #define MALLOC your_malloc, where your_malloc(n) acts like malloc(n) - * if memory is available and otherwise does something you deem - * appropriate. If MALLOC is undefined, malloc will be invoked - * directly -- and assumed always to succeed. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char *rcsid = "$OpenBSD: strtod.c,v 1.9 1997/03/25 17:07:30 rahnds Exp $"; -#endif /* LIBC_SCCS and not lint */ - -#if defined(__m68k__) || defined(__sparc__) || defined(__i386__) || \ - defined(__mips__) || defined(__ns32k__) || defined(__alpha__) || \ - defined(__powerpc__) || defined(__m88k__) || defined(__ppc__) -#include -#if BYTE_ORDER == BIG_ENDIAN -#define IEEE_BIG_ENDIAN -#else -#define IEEE_LITTLE_ENDIAN -#endif -#endif - -#ifdef __arm32__ -/* - * Although the CPU is little endian the FP has different - * byte and word endianness. The byte order is still little endian - * but the word order is big endian. - */ -#define IEEE_BIG_ENDIAN -#endif - -#ifdef vax -#define VAX -#endif - -#define Long int32_t -#define ULong u_int32_t - -#ifdef DEBUG -#include "stdio.h" -#define Bug(x) {fprintf(stderr, "%s\n", x); exit(1);} -#endif - -#ifdef __cplusplus -#include "malloc.h" -#include "memory.h" -#else -#ifndef KR_headers -#include "stdlib.h" -#include "string.h" -#include "locale.h" -#else -#include "malloc.h" -#include "memory.h" -#endif -#endif - -#ifdef MALLOC -#ifdef KR_headers -extern char *MALLOC(); -#else -extern void *MALLOC(size_t); -#endif -#else -#define MALLOC malloc -#endif - -#include "ctype.h" -#include "errno.h" - -#ifdef Bad_float_h -#undef __STDC__ -#ifdef IEEE_BIG_ENDIAN -#define IEEE_ARITHMETIC -#endif -#ifdef IEEE_LITTLE_ENDIAN -#define IEEE_ARITHMETIC -#endif - -#ifdef IEEE_ARITHMETIC -#define DBL_DIG 15 -#define DBL_MAX_10_EXP 308 -#define DBL_MAX_EXP 1024 -#define FLT_RADIX 2 -#define FLT_ROUNDS 1 -#define DBL_MAX 1.7976931348623157e+308 -#endif - -#ifdef IBM -#define DBL_DIG 16 -#define DBL_MAX_10_EXP 75 -#define DBL_MAX_EXP 63 -#define FLT_RADIX 16 -#define FLT_ROUNDS 0 -#define DBL_MAX 7.2370055773322621e+75 -#endif - -#ifdef VAX -#define DBL_DIG 16 -#define DBL_MAX_10_EXP 38 -#define DBL_MAX_EXP 127 -#define FLT_RADIX 2 -#define FLT_ROUNDS 1 -#define DBL_MAX 1.7014118346046923e+38 -#endif - -#ifndef LONG_MAX -#define LONG_MAX 2147483647 -#endif -#else -#include "float.h" -#endif -#ifndef __MATH_H__ -#include "math.h" -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef CONST -#ifdef KR_headers -#define CONST /* blank */ -#else -#define CONST const -#endif -#endif - -#ifdef Unsigned_Shifts -#define Sign_Extend(a,b) if (b < 0) a |= 0xffff0000; -#else -#define Sign_Extend(a,b) /*no-op*/ -#endif - -#if defined(IEEE_LITTLE_ENDIAN) + defined(IEEE_BIG_ENDIAN) + defined(VAX) + \ - defined(IBM) != 1 -Exactly one of IEEE_LITTLE_ENDIAN IEEE_BIG_ENDIAN, VAX, or -IBM should be defined. -#endif - -#ifdef IEEE_LITTLE_ENDIAN -#define word0(x) ((ULong *)&x)[1] -#define word1(x) ((ULong *)&x)[0] -#else -#define word0(x) ((ULong *)&x)[0] -#define word1(x) ((ULong *)&x)[1] -#endif - -/* The following definition of Storeinc is appropriate for MIPS processors. - * An alternative that might be better on some machines is - * #define Storeinc(a,b,c) (*a++ = b << 16 | c & 0xffff) - */ -#if defined(IEEE_LITTLE_ENDIAN) + defined(VAX) + defined(__arm32__) -#define Storeinc(a,b,c) (((unsigned short *)a)[1] = (unsigned short)b, \ -((unsigned short *)a)[0] = (unsigned short)c, a++) -#else -#define Storeinc(a,b,c) (((unsigned short *)a)[0] = (unsigned short)b, \ -((unsigned short *)a)[1] = (unsigned short)c, a++) -#endif - -/* #define P DBL_MANT_DIG */ -/* Ten_pmax = floor(P*log(2)/log(5)) */ -/* Bletch = (highest power of 2 < DBL_MAX_10_EXP) / 16 */ -/* Quick_max = floor((P-1)*log(FLT_RADIX)/log(10) - 1) */ -/* Int_max = floor(P*log(FLT_RADIX)/log(10) - 1) */ - -#if defined(IEEE_LITTLE_ENDIAN) + defined(IEEE_BIG_ENDIAN) -#define Exp_shift 20 -#define Exp_shift1 20 -#define Exp_msk1 0x100000 -#define Exp_msk11 0x100000 -#define Exp_mask 0x7ff00000 -#define P 53 -#define Bias 1023 -#define IEEE_Arith -#define Emin (-1022) -#define Exp_1 0x3ff00000 -#define Exp_11 0x3ff00000 -#define Ebits 11 -#define Frac_mask 0xfffff -#define Frac_mask1 0xfffff -#define Ten_pmax 22 -#define Bletch 0x10 -#define Bndry_mask 0xfffff -#define Bndry_mask1 0xfffff -#define LSB 1 -#define Sign_bit 0x80000000 -#define Log2P 1 -#define Tiny0 0 -#define Tiny1 1 -#define Quick_max 14 -#define Int_max 14 -#define Infinite(x) (word0(x) == 0x7ff00000) /* sufficient test for here */ -#else -#undef Sudden_Underflow -#define Sudden_Underflow -#ifdef IBM -#define Exp_shift 24 -#define Exp_shift1 24 -#define Exp_msk1 0x1000000 -#define Exp_msk11 0x1000000 -#define Exp_mask 0x7f000000 -#define P 14 -#define Bias 65 -#define Exp_1 0x41000000 -#define Exp_11 0x41000000 -#define Ebits 8 /* exponent has 7 bits, but 8 is the right value in b2d */ -#define Frac_mask 0xffffff -#define Frac_mask1 0xffffff -#define Bletch 4 -#define Ten_pmax 22 -#define Bndry_mask 0xefffff -#define Bndry_mask1 0xffffff -#define LSB 1 -#define Sign_bit 0x80000000 -#define Log2P 4 -#define Tiny0 0x100000 -#define Tiny1 0 -#define Quick_max 14 -#define Int_max 15 -#else /* VAX */ -#define Exp_shift 23 -#define Exp_shift1 7 -#define Exp_msk1 0x80 -#define Exp_msk11 0x800000 -#define Exp_mask 0x7f80 -#define P 56 -#define Bias 129 -#define Exp_1 0x40800000 -#define Exp_11 0x4080 -#define Ebits 8 -#define Frac_mask 0x7fffff -#define Frac_mask1 0xffff007f -#define Ten_pmax 24 -#define Bletch 2 -#define Bndry_mask 0xffff007f -#define Bndry_mask1 0xffff007f -#define LSB 0x10000 -#define Sign_bit 0x8000 -#define Log2P 1 -#define Tiny0 0x80 -#define Tiny1 0 -#define Quick_max 15 -#define Int_max 15 -#endif -#endif - -#ifndef IEEE_Arith -#define ROUND_BIASED -#endif - -#ifdef RND_PRODQUOT -#define rounded_product(a,b) a = rnd_prod(a, b) -#define rounded_quotient(a,b) a = rnd_quot(a, b) -#ifdef KR_headers -extern double rnd_prod(), rnd_quot(); -#else -extern double rnd_prod(double, double), rnd_quot(double, double); -#endif -#else -#define rounded_product(a,b) a *= b -#define rounded_quotient(a,b) a /= b -#endif - -#define Big0 (Frac_mask1 | Exp_msk1*(DBL_MAX_EXP+Bias-1)) -#define Big1 0xffffffff - -#ifndef Just_16 -/* When Pack_32 is not defined, we store 16 bits per 32-bit Long. - * This makes some inner loops simpler and sometimes saves work - * during multiplications, but it often seems to make things slightly - * slower. Hence the default is now to store 32 bits per Long. - */ -#ifndef Pack_32 -#define Pack_32 -#endif -#endif - -#define Kmax 15 - -#ifdef __cplusplus -extern "C" double strtod(const char *s00, char **se); -extern "C" char *__dtoa(double d, int mode, int ndigits, - int *decpt, int *sign, char **rve, char **resultp); -#endif - - struct -Bigint { - struct Bigint *next; - int k, maxwds, sign, wds; - ULong x[1]; - }; - - typedef struct Bigint Bigint; - - static Bigint * -Balloc -#ifdef KR_headers - (k) int k; -#else - (int k) -#endif -{ - int x; - Bigint *rv; - - x = 1 << k; - rv = (Bigint *)malloc(sizeof(Bigint) + (x-1)*sizeof(Long)); - rv->k = k; - rv->maxwds = x; - rv->sign = rv->wds = 0; - return rv; -} - - static void -Bfree -#ifdef KR_headers - (v) Bigint *v; -#else - (Bigint *v) -#endif -{ - free(v); -} - -#define Bcopy(x,y) memcpy((char *)&x->sign, (char *)&y->sign, \ -y->wds*sizeof(Long) + 2*sizeof(int)) - - static Bigint * -multadd -#ifdef KR_headers - (b, m, a) Bigint *b; int m, a; -#else - (Bigint *b, int m, int a) /* multiply by m and add a */ -#endif -{ - int i, wds; - ULong *x, y; -#ifdef Pack_32 - ULong xi, z; -#endif - Bigint *b1; - - wds = b->wds; - x = b->x; - i = 0; - do { -#ifdef Pack_32 - xi = *x; - y = (xi & 0xffff) * m + a; - z = (xi >> 16) * m + (y >> 16); - a = (int)(z >> 16); - *x++ = (z << 16) + (y & 0xffff); -#else - y = *x * m + a; - a = (int)(y >> 16); - *x++ = y & 0xffff; -#endif - } - while(++i < wds); - if (a) { - if (wds >= b->maxwds) { - b1 = Balloc(b->k+1); - Bcopy(b1, b); - Bfree(b); - b = b1; - } - b->x[wds++] = a; - b->wds = wds; - } - return b; - } - - static Bigint * -s2b -#ifdef KR_headers - (s, nd0, nd, y9) CONST char *s; int nd0, nd; ULong y9; -#else - (CONST char *s, int nd0, int nd, ULong y9) -#endif -{ - Bigint *b; - int i, k; - Long x, y; - - x = (nd + 8) / 9; - for(k = 0, y = 1; x > y; y <<= 1, k++) ; -#ifdef Pack_32 - b = Balloc(k); - b->x[0] = y9; - b->wds = 1; -#else - b = Balloc(k+1); - b->x[0] = y9 & 0xffff; - b->wds = (b->x[1] = y9 >> 16) ? 2 : 1; -#endif - - i = 9; - if (9 < nd0) { - s += 9; - do b = multadd(b, 10, *s++ - '0'); - while(++i < nd0); - s++; - } - else - s += 10; - for(; i < nd; i++) - b = multadd(b, 10, *s++ - '0'); - return b; - } - - static int -hi0bits -#ifdef KR_headers - (x) register ULong x; -#else - (register ULong x) -#endif -{ - register int k = 0; - - if (!(x & 0xffff0000)) { - k = 16; - x <<= 16; - } - if (!(x & 0xff000000)) { - k += 8; - x <<= 8; - } - if (!(x & 0xf0000000)) { - k += 4; - x <<= 4; - } - if (!(x & 0xc0000000)) { - k += 2; - x <<= 2; - } - if (!(x & 0x80000000)) { - k++; - if (!(x & 0x40000000)) - return 32; - } - return k; - } - - static int -lo0bits -#ifdef KR_headers - (y) ULong *y; -#else - (ULong *y) -#endif -{ - register int k; - register ULong x = *y; - - if (x & 7) { - if (x & 1) - return 0; - if (x & 2) { - *y = x >> 1; - return 1; - } - *y = x >> 2; - return 2; - } - k = 0; - if (!(x & 0xffff)) { - k = 16; - x >>= 16; - } - if (!(x & 0xff)) { - k += 8; - x >>= 8; - } - if (!(x & 0xf)) { - k += 4; - x >>= 4; - } - if (!(x & 0x3)) { - k += 2; - x >>= 2; - } - if (!(x & 1)) { - k++; - x >>= 1; - if (!x & 1) - return 32; - } - *y = x; - return k; - } - - static Bigint * -i2b -#ifdef KR_headers - (i) int i; -#else - (int i) -#endif -{ - Bigint *b; - - b = Balloc(1); - b->x[0] = i; - b->wds = 1; - return b; - } - - static Bigint * -mult -#ifdef KR_headers - (a, b) Bigint *a, *b; -#else - (Bigint *a, Bigint *b) -#endif -{ - Bigint *c; - int k, wa, wb, wc; - ULong carry, y, z; - ULong *x, *xa, *xae, *xb, *xbe, *xc, *xc0; -#ifdef Pack_32 - ULong z2; -#endif - - if (a->wds < b->wds) { - c = a; - a = b; - b = c; - } - k = a->k; - wa = a->wds; - wb = b->wds; - wc = wa + wb; - if (wc > a->maxwds) - k++; - c = Balloc(k); - for(x = c->x, xa = x + wc; x < xa; x++) - *x = 0; - xa = a->x; - xae = xa + wa; - xb = b->x; - xbe = xb + wb; - xc0 = c->x; -#ifdef Pack_32 - for(; xb < xbe; xb++, xc0++) { - if (y = *xb & 0xffff) { - x = xa; - xc = xc0; - carry = 0; - do { - z = (*x & 0xffff) * y + (*xc & 0xffff) + carry; - carry = z >> 16; - z2 = (*x++ >> 16) * y + (*xc >> 16) + carry; - carry = z2 >> 16; - Storeinc(xc, z2, z); - } - while(x < xae); - *xc = carry; - } - if (y = *xb >> 16) { - x = xa; - xc = xc0; - carry = 0; - z2 = *xc; - do { - z = (*x & 0xffff) * y + (*xc >> 16) + carry; - carry = z >> 16; - Storeinc(xc, z, z2); - z2 = (*x++ >> 16) * y + (*xc & 0xffff) + carry; - carry = z2 >> 16; - } - while(x < xae); - *xc = z2; - } - } -#else - for(; xb < xbe; xc0++) { - if (y = *xb++) { - x = xa; - xc = xc0; - carry = 0; - do { - z = *x++ * y + *xc + carry; - carry = z >> 16; - *xc++ = z & 0xffff; - } - while(x < xae); - *xc = carry; - } - } -#endif - for(xc0 = c->x, xc = xc0 + wc; wc > 0 && !*--xc; --wc) ; - c->wds = wc; - return c; - } - - static Bigint *p5s; - - static Bigint * -pow5mult -#ifdef KR_headers - (b, k) Bigint *b; int k; -#else - (Bigint *b, int k) -#endif -{ - Bigint *b1, *p5, *p51; - int i; - static int p05[3] = { 5, 25, 125 }; - - if (i = k & 3) - b = multadd(b, p05[i-1], 0); - - if (!(k >>= 2)) - return b; - if (!(p5 = p5s)) { - /* first time */ - p5 = p5s = i2b(625); - p5->next = 0; - } - for(;;) { - if (k & 1) { - b1 = mult(b, p5); - Bfree(b); - b = b1; - } - if (!(k >>= 1)) - break; - if (!(p51 = p5->next)) { - p51 = p5->next = mult(p5,p5); - p51->next = 0; - } - p5 = p51; - } - return b; - } - - static Bigint * -lshift -#ifdef KR_headers - (b, k) Bigint *b; int k; -#else - (Bigint *b, int k) -#endif -{ - int i, k1, n, n1; - Bigint *b1; - ULong *x, *x1, *xe, z; - -#ifdef Pack_32 - n = k >> 5; -#else - n = k >> 4; -#endif - k1 = b->k; - n1 = n + b->wds + 1; - for(i = b->maxwds; n1 > i; i <<= 1) - k1++; - b1 = Balloc(k1); - x1 = b1->x; - for(i = 0; i < n; i++) - *x1++ = 0; - x = b->x; - xe = x + b->wds; -#ifdef Pack_32 - if (k &= 0x1f) { - k1 = 32 - k; - z = 0; - do { - *x1++ = *x << k | z; - z = *x++ >> k1; - } - while(x < xe); - if (*x1 = z) - ++n1; - } -#else - if (k &= 0xf) { - k1 = 16 - k; - z = 0; - do { - *x1++ = *x << k & 0xffff | z; - z = *x++ >> k1; - } - while(x < xe); - if (*x1 = z) - ++n1; - } -#endif - else do - *x1++ = *x++; - while(x < xe); - b1->wds = n1 - 1; - Bfree(b); - return b1; - } - - static int -cmp -#ifdef KR_headers - (a, b) Bigint *a, *b; -#else - (Bigint *a, Bigint *b) -#endif -{ - ULong *xa, *xa0, *xb, *xb0; - int i, j; - - i = a->wds; - j = b->wds; -#ifdef DEBUG - if (i > 1 && !a->x[i-1]) - Bug("cmp called with a->x[a->wds-1] == 0"); - if (j > 1 && !b->x[j-1]) - Bug("cmp called with b->x[b->wds-1] == 0"); -#endif - if (i -= j) - return i; - xa0 = a->x; - xa = xa0 + j; - xb0 = b->x; - xb = xb0 + j; - for(;;) { - if (*--xa != *--xb) - return *xa < *xb ? -1 : 1; - if (xa <= xa0) - break; - } - return 0; - } - - static Bigint * -diff -#ifdef KR_headers - (a, b) Bigint *a, *b; -#else - (Bigint *a, Bigint *b) -#endif -{ - Bigint *c; - int i, wa, wb; - Long borrow, y; /* We need signed shifts here. */ - ULong *xa, *xae, *xb, *xbe, *xc; -#ifdef Pack_32 - Long z; -#endif - - i = cmp(a,b); - if (!i) { - c = Balloc(0); - c->wds = 1; - c->x[0] = 0; - return c; - } - if (i < 0) { - c = a; - a = b; - b = c; - i = 1; - } - else - i = 0; - c = Balloc(a->k); - c->sign = i; - wa = a->wds; - xa = a->x; - xae = xa + wa; - wb = b->wds; - xb = b->x; - xbe = xb + wb; - xc = c->x; - borrow = 0; -#ifdef Pack_32 - do { - y = (*xa & 0xffff) - (*xb & 0xffff) + borrow; - borrow = y >> 16; - Sign_Extend(borrow, y); - z = (*xa++ >> 16) - (*xb++ >> 16) + borrow; - borrow = z >> 16; - Sign_Extend(borrow, z); - Storeinc(xc, z, y); - } - while(xb < xbe); - while(xa < xae) { - y = (*xa & 0xffff) + borrow; - borrow = y >> 16; - Sign_Extend(borrow, y); - z = (*xa++ >> 16) + borrow; - borrow = z >> 16; - Sign_Extend(borrow, z); - Storeinc(xc, z, y); - } -#else - do { - y = *xa++ - *xb++ + borrow; - borrow = y >> 16; - Sign_Extend(borrow, y); - *xc++ = y & 0xffff; - } - while(xb < xbe); - while(xa < xae) { - y = *xa++ + borrow; - borrow = y >> 16; - Sign_Extend(borrow, y); - *xc++ = y & 0xffff; - } -#endif - while(!*--xc) - wa--; - c->wds = wa; - return c; - } - - static double -ulp -#ifdef KR_headers - (x) double x; -#else - (double x) -#endif -{ - register Long L; - double a; - - L = (word0(x) & Exp_mask) - (P-1)*Exp_msk1; -#ifndef Sudden_Underflow - if (L > 0) { -#endif -#ifdef IBM - L |= Exp_msk1 >> 4; -#endif - word0(a) = L; - word1(a) = 0; -#ifndef Sudden_Underflow - } - else { - L = -L >> Exp_shift; - if (L < Exp_shift) { - word0(a) = 0x80000 >> L; - word1(a) = 0; - } - else { - word0(a) = 0; - L -= Exp_shift; - word1(a) = L >= 31 ? 1 : 1 << 31 - L; - } - } -#endif - return a; - } - - static double -b2d -#ifdef KR_headers - (a, e) Bigint *a; int *e; -#else - (Bigint *a, int *e) -#endif -{ - ULong *xa, *xa0, w, y, z; - int k; - double d; -#ifdef VAX - ULong d0, d1; -#else -#define d0 word0(d) -#define d1 word1(d) -#endif - - xa0 = a->x; - xa = xa0 + a->wds; - y = *--xa; -#ifdef DEBUG - if (!y) Bug("zero y in b2d"); -#endif - k = hi0bits(y); - *e = 32 - k; -#ifdef Pack_32 - if (k < Ebits) { - d0 = Exp_1 | y >> Ebits - k; - w = xa > xa0 ? *--xa : 0; - d1 = y << (32-Ebits) + k | w >> Ebits - k; - goto ret_d; - } - z = xa > xa0 ? *--xa : 0; - if (k -= Ebits) { - d0 = Exp_1 | y << k | z >> 32 - k; - y = xa > xa0 ? *--xa : 0; - d1 = z << k | y >> 32 - k; - } - else { - d0 = Exp_1 | y; - d1 = z; - } -#else - if (k < Ebits + 16) { - z = xa > xa0 ? *--xa : 0; - d0 = Exp_1 | y << k - Ebits | z >> Ebits + 16 - k; - w = xa > xa0 ? *--xa : 0; - y = xa > xa0 ? *--xa : 0; - d1 = z << k + 16 - Ebits | w << k - Ebits | y >> 16 + Ebits - k; - goto ret_d; - } - z = xa > xa0 ? *--xa : 0; - w = xa > xa0 ? *--xa : 0; - k -= Ebits + 16; - d0 = Exp_1 | y << k + 16 | z << k | w >> 16 - k; - y = xa > xa0 ? *--xa : 0; - d1 = w << k + 16 | y << k; -#endif - ret_d: -#ifdef VAX - word0(d) = d0 >> 16 | d0 << 16; - word1(d) = d1 >> 16 | d1 << 16; -#else -#undef d0 -#undef d1 -#endif - return d; - } - - static Bigint * -d2b -#ifdef KR_headers - (d, e, bits) double d; int *e, *bits; -#else - (double d, int *e, int *bits) -#endif -{ - Bigint *b; - int de, i, k; - ULong *x, y, z; -#ifdef VAX - ULong d0, d1; - d0 = word0(d) >> 16 | word0(d) << 16; - d1 = word1(d) >> 16 | word1(d) << 16; -#else -#define d0 word0(d) -#define d1 word1(d) -#endif - -#ifdef Pack_32 - b = Balloc(1); -#else - b = Balloc(2); -#endif - x = b->x; - - z = d0 & Frac_mask; - d0 &= 0x7fffffff; /* clear sign bit, which we ignore */ -#ifdef Sudden_Underflow - de = (int)(d0 >> Exp_shift); -#ifndef IBM - z |= Exp_msk11; -#endif -#else - if (de = (int)(d0 >> Exp_shift)) - z |= Exp_msk1; -#endif -#ifdef Pack_32 - if (y = d1) { - if (k = lo0bits(&y)) { - x[0] = y | z << 32 - k; - z >>= k; - } - else - x[0] = y; - i = b->wds = (x[1] = z) ? 2 : 1; - } - else { -#ifdef DEBUG - if (!z) - Bug("Zero passed to d2b"); -#endif - k = lo0bits(&z); - x[0] = z; - i = b->wds = 1; - k += 32; - } -#else - if (y = d1) { - if (k = lo0bits(&y)) - if (k >= 16) { - x[0] = y | z << 32 - k & 0xffff; - x[1] = z >> k - 16 & 0xffff; - x[2] = z >> k; - i = 2; - } - else { - x[0] = y & 0xffff; - x[1] = y >> 16 | z << 16 - k & 0xffff; - x[2] = z >> k & 0xffff; - x[3] = z >> k+16; - i = 3; - } - else { - x[0] = y & 0xffff; - x[1] = y >> 16; - x[2] = z & 0xffff; - x[3] = z >> 16; - i = 3; - } - } - else { -#ifdef DEBUG - if (!z) - Bug("Zero passed to d2b"); -#endif - k = lo0bits(&z); - if (k >= 16) { - x[0] = z; - i = 0; - } - else { - x[0] = z & 0xffff; - x[1] = z >> 16; - i = 1; - } - k += 32; - } - while(!x[i]) - --i; - b->wds = i + 1; -#endif -#ifndef Sudden_Underflow - if (de) { -#endif -#ifdef IBM - *e = (de - Bias - (P-1) << 2) + k; - *bits = 4*P + 8 - k - hi0bits(word0(d) & Frac_mask); -#else - *e = de - Bias - (P-1) + k; - *bits = P - k; -#endif -#ifndef Sudden_Underflow - } - else { - *e = de - Bias - (P-1) + 1 + k; -#ifdef Pack_32 - *bits = 32*i - hi0bits(x[i-1]); -#else - *bits = (i+2)*16 - hi0bits(x[i]); -#endif - } -#endif - return b; - } -#undef d0 -#undef d1 - - static double -ratio -#ifdef KR_headers - (a, b) Bigint *a, *b; -#else - (Bigint *a, Bigint *b) -#endif -{ - double da, db; - int k, ka, kb; - - da = b2d(a, &ka); - db = b2d(b, &kb); -#ifdef Pack_32 - k = ka - kb + 32*(a->wds - b->wds); -#else - k = ka - kb + 16*(a->wds - b->wds); -#endif -#ifdef IBM - if (k > 0) { - word0(da) += (k >> 2)*Exp_msk1; - if (k &= 3) - da *= 1 << k; - } - else { - k = -k; - word0(db) += (k >> 2)*Exp_msk1; - if (k &= 3) - db *= 1 << k; - } -#else - if (k > 0) - word0(da) += k*Exp_msk1; - else { - k = -k; - word0(db) += k*Exp_msk1; - } -#endif - return da / db; - } - -static CONST double -tens[] = { - 1e0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9, - 1e10, 1e11, 1e12, 1e13, 1e14, 1e15, 1e16, 1e17, 1e18, 1e19, - 1e20, 1e21, 1e22 -#ifdef VAX - , 1e23, 1e24 -#endif - }; - -#ifdef IEEE_Arith -static CONST double bigtens[] = { 1e16, 1e32, 1e64, 1e128, 1e256 }; -static CONST double tinytens[] = { 1e-16, 1e-32, 1e-64, 1e-128, 1e-256 }; -#define n_bigtens 5 -#else -#ifdef IBM -static CONST double bigtens[] = { 1e16, 1e32, 1e64 }; -static CONST double tinytens[] = { 1e-16, 1e-32, 1e-64 }; -#define n_bigtens 3 -#else -static CONST double bigtens[] = { 1e16, 1e32 }; -static CONST double tinytens[] = { 1e-16, 1e-32 }; -#define n_bigtens 2 -#endif -#endif - - double -strtod -#ifdef KR_headers - (s00, se) CONST char *s00; char **se; -#else - (CONST char *s00, char **se) -#endif -{ - int bb2, bb5, bbe, bd2, bd5, bbbits, bs2, c, dsign, - e, e1, esign, i, j, k, nd, nd0, nf, nz, nz0, sign; - CONST char *s, *s0, *s1; - double aadj, aadj1, adj, rv, rv0; - Long L; - ULong y, z; - Bigint *bb, *bb1, *bd, *bd0, *bs, *delta; - -#ifndef KR_headers - CONST char decimal_point = localeconv()->decimal_point[0]; -#else - CONST char decimal_point = '.'; -#endif - - sign = nz0 = nz = 0; - rv = 0.; - - - for(s = s00; isspace((unsigned char) *s); s++) - ; - - if (*s == '-') { - sign = 1; - s++; - } else if (*s == '+') { - s++; - } - - if (*s == '\0') { - s = s00; - goto ret; - } - - if (*s == '0') { - nz0 = 1; - while(*++s == '0') ; - if (!*s) - goto ret; - } - s0 = s; - y = z = 0; - for(nd = nf = 0; (c = *s) >= '0' && c <= '9'; nd++, s++) - if (nd < 9) - y = 10*y + c - '0'; - else if (nd < 16) - z = 10*z + c - '0'; - nd0 = nd; - if (c == decimal_point) { - c = *++s; - if (!nd) { - for(; c == '0'; c = *++s) - nz++; - if (c > '0' && c <= '9') { - s0 = s; - nf += nz; - nz = 0; - goto have_dig; - } - goto dig_done; - } - for(; c >= '0' && c <= '9'; c = *++s) { - have_dig: - nz++; - if (c -= '0') { - nf += nz; - for(i = 1; i < nz; i++) - if (nd++ < 9) - y *= 10; - else if (nd <= DBL_DIG + 1) - z *= 10; - if (nd++ < 9) - y = 10*y + c; - else if (nd <= DBL_DIG + 1) - z = 10*z + c; - nz = 0; - } - } - } - dig_done: - e = 0; - if (c == 'e' || c == 'E') { - if (!nd && !nz && !nz0) { - s = s00; - goto ret; - } - s00 = s; - esign = 0; - switch(c = *++s) { - case '-': - esign = 1; - case '+': - c = *++s; - } - if (c >= '0' && c <= '9') { - while(c == '0') - c = *++s; - if (c > '0' && c <= '9') { - L = c - '0'; - s1 = s; - while((c = *++s) >= '0' && c <= '9') - L = 10*L + c - '0'; - if (s - s1 > 8 || L > 19999) - /* Avoid confusion from exponents - * so large that e might overflow. - */ - e = 19999; /* safe for 16 bit ints */ - else - e = (int)L; - if (esign) - e = -e; - } - else - e = 0; - } - else - s = s00; - } - if (!nd) { - if (!nz && !nz0) - s = s00; - goto ret; - } - e1 = e -= nf; - - /* Now we have nd0 digits, starting at s0, followed by a - * decimal point, followed by nd-nd0 digits. The number we're - * after is the integer represented by those digits times - * 10**e */ - - if (!nd0) - nd0 = nd; - k = nd < DBL_DIG + 1 ? nd : DBL_DIG + 1; - rv = y; - if (k > 9) - rv = tens[k - 9] * rv + z; - bd0 = 0; - if (nd <= DBL_DIG -#ifndef RND_PRODQUOT - && FLT_ROUNDS == 1 -#endif - ) { - if (!e) - goto ret; - if (e > 0) { - if (e <= Ten_pmax) { -#ifdef VAX - goto vax_ovfl_check; -#else - /* rv = */ rounded_product(rv, tens[e]); - goto ret; -#endif - } - i = DBL_DIG - nd; - if (e <= Ten_pmax + i) { - /* A fancier test would sometimes let us do - * this for larger i values. - */ - e -= i; - rv *= tens[i]; -#ifdef VAX - /* VAX exponent range is so narrow we must - * worry about overflow here... - */ - vax_ovfl_check: - word0(rv) -= P*Exp_msk1; - /* rv = */ rounded_product(rv, tens[e]); - if ((word0(rv) & Exp_mask) - > Exp_msk1*(DBL_MAX_EXP+Bias-1-P)) - goto ovfl; - word0(rv) += P*Exp_msk1; -#else - /* rv = */ rounded_product(rv, tens[e]); -#endif - goto ret; - } - } -#ifndef Inaccurate_Divide - else if (e >= -Ten_pmax) { - /* rv = */ rounded_quotient(rv, tens[-e]); - goto ret; - } -#endif - } - e1 += nd - k; - - /* Get starting approximation = rv * 10**e1 */ - - if (e1 > 0) { - if (i = e1 & 15) - rv *= tens[i]; - if (e1 &= ~15) { - if (e1 > DBL_MAX_10_EXP) { - ovfl: - errno = ERANGE; -#ifdef __STDC__ - rv = HUGE_VAL; -#else - /* Can't trust HUGE_VAL */ -#ifdef IEEE_Arith - word0(rv) = Exp_mask; - word1(rv) = 0; -#else - word0(rv) = Big0; - word1(rv) = Big1; -#endif -#endif - if (bd0) - goto retfree; - goto ret; - } - if (e1 >>= 4) { - for(j = 0; e1 > 1; j++, e1 >>= 1) - if (e1 & 1) - rv *= bigtens[j]; - /* The last multiplication could overflow. */ - word0(rv) -= P*Exp_msk1; - rv *= bigtens[j]; - if ((z = word0(rv) & Exp_mask) - > Exp_msk1*(DBL_MAX_EXP+Bias-P)) - goto ovfl; - if (z > Exp_msk1*(DBL_MAX_EXP+Bias-1-P)) { - /* set to largest number */ - /* (Can't trust DBL_MAX) */ - word0(rv) = Big0; - word1(rv) = Big1; - } - else - word0(rv) += P*Exp_msk1; - } - - } - } - else if (e1 < 0) { - e1 = -e1; - if (i = e1 & 15) - rv /= tens[i]; - if (e1 &= ~15) { - e1 >>= 4; - if (e1 >= 1 << n_bigtens) - goto undfl; - for(j = 0; e1 > 1; j++, e1 >>= 1) - if (e1 & 1) - rv *= tinytens[j]; - /* The last multiplication could underflow. */ - rv0 = rv; - rv *= tinytens[j]; - if (!rv) { - rv = 2.*rv0; - rv *= tinytens[j]; - if (!rv) { - undfl: - rv = 0.; - errno = ERANGE; - if (bd0) - goto retfree; - goto ret; - } - word0(rv) = Tiny0; - word1(rv) = Tiny1; - /* The refinement below will clean - * this approximation up. - */ - } - } - } - - /* Now the hard part -- adjusting rv to the correct value.*/ - - /* Put digits into bd: true value = bd * 10^e */ - - bd0 = s2b(s0, nd0, nd, y); - - for(;;) { - bd = Balloc(bd0->k); - Bcopy(bd, bd0); - bb = d2b(rv, &bbe, &bbbits); /* rv = bb * 2^bbe */ - bs = i2b(1); - - if (e >= 0) { - bb2 = bb5 = 0; - bd2 = bd5 = e; - } - else { - bb2 = bb5 = -e; - bd2 = bd5 = 0; - } - if (bbe >= 0) - bb2 += bbe; - else - bd2 -= bbe; - bs2 = bb2; -#ifdef Sudden_Underflow -#ifdef IBM - j = 1 + 4*P - 3 - bbbits + ((bbe + bbbits - 1) & 3); -#else - j = P + 1 - bbbits; -#endif -#else - i = bbe + bbbits - 1; /* logb(rv) */ - if (i < Emin) /* denormal */ - j = bbe + (P-Emin); - else - j = P + 1 - bbbits; -#endif - bb2 += j; - bd2 += j; - i = bb2 < bd2 ? bb2 : bd2; - if (i > bs2) - i = bs2; - if (i > 0) { - bb2 -= i; - bd2 -= i; - bs2 -= i; - } - if (bb5 > 0) { - bs = pow5mult(bs, bb5); - bb1 = mult(bs, bb); - Bfree(bb); - bb = bb1; - } - if (bb2 > 0) - bb = lshift(bb, bb2); - if (bd5 > 0) - bd = pow5mult(bd, bd5); - if (bd2 > 0) - bd = lshift(bd, bd2); - if (bs2 > 0) - bs = lshift(bs, bs2); - delta = diff(bb, bd); - dsign = delta->sign; - delta->sign = 0; - i = cmp(delta, bs); - if (i < 0) { - /* Error is less than half an ulp -- check for - * special case of mantissa a power of two. - */ - if (dsign || word1(rv) || word0(rv) & Bndry_mask) - break; - delta = lshift(delta,Log2P); - if (cmp(delta, bs) > 0) - goto drop_down; - break; - } - if (i == 0) { - /* exactly half-way between */ - if (dsign) { - if ((word0(rv) & Bndry_mask1) == Bndry_mask1 - && word1(rv) == 0xffffffff) { - /*boundary case -- increment exponent*/ - word0(rv) = (word0(rv) & Exp_mask) - + Exp_msk1 -#ifdef IBM - | Exp_msk1 >> 4 -#endif - ; - word1(rv) = 0; - break; - } - } - else if (!(word0(rv) & Bndry_mask) && !word1(rv)) { - drop_down: - /* boundary case -- decrement exponent */ -#ifdef Sudden_Underflow - L = word0(rv) & Exp_mask; -#ifdef IBM - if (L < Exp_msk1) -#else - if (L <= Exp_msk1) -#endif - goto undfl; - L -= Exp_msk1; -#else - L = (word0(rv) & Exp_mask) - Exp_msk1; -#endif - word0(rv) = L | Bndry_mask1; - word1(rv) = 0xffffffff; -#ifdef IBM - goto cont; -#else - break; -#endif - } -#ifndef ROUND_BIASED - if (!(word1(rv) & LSB)) - break; -#endif - if (dsign) - rv += ulp(rv); -#ifndef ROUND_BIASED - else { - rv -= ulp(rv); -#ifndef Sudden_Underflow - if (!rv) - goto undfl; -#endif - } -#endif - break; - } - if ((aadj = ratio(delta, bs)) <= 2.) { - if (dsign) - aadj = aadj1 = 1.; - else if (word1(rv) || word0(rv) & Bndry_mask) { -#ifndef Sudden_Underflow - if (word1(rv) == Tiny1 && !word0(rv)) - goto undfl; -#endif - aadj = 1.; - aadj1 = -1.; - } - else { - /* special case -- power of FLT_RADIX to be */ - /* rounded down... */ - - if (aadj < 2./FLT_RADIX) - aadj = 1./FLT_RADIX; - else - aadj *= 0.5; - aadj1 = -aadj; - } - } - else { - aadj *= 0.5; - aadj1 = dsign ? aadj : -aadj; -#ifdef Check_FLT_ROUNDS - switch(FLT_ROUNDS) { - case 2: /* towards +infinity */ - aadj1 -= 0.5; - break; - case 0: /* towards 0 */ - case 3: /* towards -infinity */ - aadj1 += 0.5; - } -#else - if (FLT_ROUNDS == 0) - aadj1 += 0.5; -#endif - } - y = word0(rv) & Exp_mask; - - /* Check for overflow */ - - if (y == Exp_msk1*(DBL_MAX_EXP+Bias-1)) { - rv0 = rv; - word0(rv) -= P*Exp_msk1; - adj = aadj1 * ulp(rv); - rv += adj; - if ((word0(rv) & Exp_mask) >= - Exp_msk1*(DBL_MAX_EXP+Bias-P)) { - if (word0(rv0) == Big0 && word1(rv0) == Big1) - goto ovfl; - word0(rv) = Big0; - word1(rv) = Big1; - goto cont; - } - else - word0(rv) += P*Exp_msk1; - } - else { -#ifdef Sudden_Underflow - if ((word0(rv) & Exp_mask) <= P*Exp_msk1) { - rv0 = rv; - word0(rv) += P*Exp_msk1; - adj = aadj1 * ulp(rv); - rv += adj; -#ifdef IBM - if ((word0(rv) & Exp_mask) < P*Exp_msk1) -#else - if ((word0(rv) & Exp_mask) <= P*Exp_msk1) -#endif - { - if (word0(rv0) == Tiny0 - && word1(rv0) == Tiny1) - goto undfl; - word0(rv) = Tiny0; - word1(rv) = Tiny1; - goto cont; - } - else - word0(rv) -= P*Exp_msk1; - } - else { - adj = aadj1 * ulp(rv); - rv += adj; - } -#else - /* Compute adj so that the IEEE rounding rules will - * correctly round rv + adj in some half-way cases. - * If rv * ulp(rv) is denormalized (i.e., - * y <= (P-1)*Exp_msk1), we must adjust aadj to avoid - * trouble from bits lost to denormalization; - * example: 1.2e-307 . - */ - if (y <= (P-1)*Exp_msk1 && aadj >= 1.) { - aadj1 = (double)(int)(aadj + 0.5); - if (!dsign) - aadj1 = -aadj1; - } - adj = aadj1 * ulp(rv); - rv += adj; -#endif - } - z = word0(rv) & Exp_mask; - if (y == z) { - /* Can we stop now? */ - L = aadj; - aadj -= L; - /* The tolerances below are conservative. */ - if (dsign || word1(rv) || word0(rv) & Bndry_mask) { - if (aadj < .4999999 || aadj > .5000001) - break; - } - else if (aadj < .4999999/FLT_RADIX) - break; - } - cont: - Bfree(bb); - Bfree(bd); - Bfree(bs); - Bfree(delta); - } - retfree: - Bfree(bb); - Bfree(bd); - Bfree(bs); - Bfree(bd0); - Bfree(delta); - ret: - if (se) - *se = (char *)s; - return sign ? -rv : rv; - } - - static int -quorem -#ifdef KR_headers - (b, S) Bigint *b, *S; -#else - (Bigint *b, Bigint *S) -#endif -{ - int n; - Long borrow, y; - ULong carry, q, ys; - ULong *bx, *bxe, *sx, *sxe; -#ifdef Pack_32 - Long z; - ULong si, zs; -#endif - - n = S->wds; -#ifdef DEBUG - /*debug*/ if (b->wds > n) - /*debug*/ Bug("oversize b in quorem"); -#endif - if (b->wds < n) - return 0; - sx = S->x; - sxe = sx + --n; - bx = b->x; - bxe = bx + n; - q = *bxe / (*sxe + 1); /* ensure q <= true quotient */ -#ifdef DEBUG - /*debug*/ if (q > 9) - /*debug*/ Bug("oversized quotient in quorem"); -#endif - if (q) { - borrow = 0; - carry = 0; - do { -#ifdef Pack_32 - si = *sx++; - ys = (si & 0xffff) * q + carry; - zs = (si >> 16) * q + (ys >> 16); - carry = zs >> 16; - y = (*bx & 0xffff) - (ys & 0xffff) + borrow; - borrow = y >> 16; - Sign_Extend(borrow, y); - z = (*bx >> 16) - (zs & 0xffff) + borrow; - borrow = z >> 16; - Sign_Extend(borrow, z); - Storeinc(bx, z, y); -#else - ys = *sx++ * q + carry; - carry = ys >> 16; - y = *bx - (ys & 0xffff) + borrow; - borrow = y >> 16; - Sign_Extend(borrow, y); - *bx++ = y & 0xffff; -#endif - } - while(sx <= sxe); - if (!*bxe) { - bx = b->x; - while(--bxe > bx && !*bxe) - --n; - b->wds = n; - } - } - if (cmp(b, S) >= 0) { - q++; - borrow = 0; - carry = 0; - bx = b->x; - sx = S->x; - do { -#ifdef Pack_32 - si = *sx++; - ys = (si & 0xffff) + carry; - zs = (si >> 16) + (ys >> 16); - carry = zs >> 16; - y = (*bx & 0xffff) - (ys & 0xffff) + borrow; - borrow = y >> 16; - Sign_Extend(borrow, y); - z = (*bx >> 16) - (zs & 0xffff) + borrow; - borrow = z >> 16; - Sign_Extend(borrow, z); - Storeinc(bx, z, y); -#else - ys = *sx++ + carry; - carry = ys >> 16; - y = *bx - (ys & 0xffff) + borrow; - borrow = y >> 16; - Sign_Extend(borrow, y); - *bx++ = y & 0xffff; -#endif - } - while(sx <= sxe); - bx = b->x; - bxe = bx + n; - if (!*bxe) { - while(--bxe > bx && !*bxe) - --n; - b->wds = n; - } - } - return q; - } - -/* 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]. - * - * Modifications: - * 1. Rather than iterating, we use a simple numeric overestimate - * to determine k = floor(log10(d)). We scale relevant - * quantities using O(log2(k)) rather than O(k) multiplications. - * 2. For some modes > 2 (corresponding to ecvt and fcvt), we don't - * try to generate digits strictly left to right. Instead, we - * compute with fewer bits and propagate the carry if necessary - * when rounding the final digit up. This is often faster. - * 3. Under the assumption that input will be rounded nearest, - * mode 0 renders 1e23 as 1e23 rather than 9.999999999999999e22. - * That is, we allow equality in stopping tests when the - * round-nearest rule will give the same floating-point value - * as would satisfaction of the stopping test with strict - * inequality. - * 4. We remove common factors of powers of 2 from relevant - * quantities. - * 5. When converting floating-point integers less than 1e16, - * we use floating-point arithmetic rather than resorting - * to multiple-precision integers. - * 6. When asked to produce fewer than 15 digits, we first try - * to get by with floating-point arithmetic; we resort to - * multiple-precision integer arithmetic only if we cannot - * guarantee that the floating-point calculation has given - * the correctly rounded result. For k requested digits and - * "uniformly" distributed input, the probability is - * something like 10^(k-15) that we must resort to the Long - * calculation. - */ - - char * -__dtoa -#ifdef KR_headers - (d, mode, ndigits, decpt, sign, rve) - double d; int mode, ndigits, *decpt, *sign; char **rve, char **resultp; -#else - (double d, int mode, int ndigits, int *decpt, int *sign, char **rve, char **resultp) -#endif -{ - /* Arguments ndigits, decpt, sign are similar to those - of ecvt and fcvt; trailing zeros are suppressed from - the returned string. If not null, *rve is set to point - to the end of the return value. If d is +-Infinity or NaN, - then *decpt is set to 9999. - - mode: - 0 ==> shortest string that yields d when read in - and rounded to nearest. - 1 ==> like 0, but with Steele & White stopping rule; - e.g. with IEEE P754 arithmetic , mode 0 gives - 1e23 whereas mode 1 gives 9.999999999999999e22. - 2 ==> max(1,ndigits) significant digits. This gives a - return value similar to that of ecvt, except - that trailing zeros are suppressed. - 3 ==> through ndigits past the decimal point. This - gives a return value similar to that from fcvt, - except that trailing zeros are suppressed, and - ndigits can be negative. - 4-9 should give the same return values as 2-3, i.e., - 4 <= mode <= 9 ==> same return as mode - 2 + (mode & 1). These modes are mainly for - debugging; often they run slower but sometimes - faster than modes 2-3. - 4,5,8,9 ==> left-to-right digit generation. - 6-9 ==> don't try fast floating-point estimate - (if applicable). - - Values of mode other than 0-9 are treated as mode 0. - - Sufficient space is allocated to the return value - to hold the suppressed trailing zeros. - */ - - int bbits, b2, b5, be, dig, i, ieps, ilim, ilim0, ilim1, - j, j1, k, k0, k_check, leftright, m2, m5, s2, s5, - spec_case, try_quick; - Long L; -#ifndef Sudden_Underflow - int denorm; - ULong x; -#endif - Bigint *b, *b1, *delta, *mlo, *mhi, *S; - double d2, ds, eps; - char *s, *s0; - - if (word0(d) & Sign_bit) { - /* set sign for everything, including 0's and NaNs */ - *sign = 1; - word0(d) &= ~Sign_bit; /* clear sign bit */ - } - else - *sign = 0; - -#if defined(IEEE_Arith) + defined(VAX) -#ifdef IEEE_Arith - if ((word0(d) & Exp_mask) == Exp_mask) -#else - if (word0(d) == 0x8000) -#endif - { - /* Infinity or NaN */ - *decpt = 9999; - s = -#ifdef IEEE_Arith - !word1(d) && !(word0(d) & 0xfffff) ? "Infinity" : -#endif - "NaN"; - if (rve) - *rve = -#ifdef IEEE_Arith - s[3] ? s + 8 : -#endif - s + 3; - return s; - } -#endif -#ifdef IBM - d += 0; /* normalize */ -#endif - if (!d) { - *decpt = 1; - s = "0"; - if (rve) - *rve = s + 1; - return s; - } - - b = d2b(d, &be, &bbits); -#ifdef Sudden_Underflow - i = (int)(word0(d) >> Exp_shift1 & (Exp_mask>>Exp_shift1)); -#else - if (i = (int)(word0(d) >> Exp_shift1 & (Exp_mask>>Exp_shift1))) { -#endif - d2 = d; - word0(d2) &= Frac_mask1; - word0(d2) |= Exp_11; -#ifdef IBM - if (j = 11 - hi0bits(word0(d2) & Frac_mask)) - d2 /= 1 << j; -#endif - - /* log(x) ~=~ log(1.5) + (x-1.5)/1.5 - * log10(x) = log(x) / log(10) - * ~=~ log(1.5)/log(10) + (x-1.5)/(1.5*log(10)) - * log10(d) = (i-Bias)*log(2)/log(10) + log10(d2) - * - * This suggests computing an approximation k to log10(d) by - * - * k = (i - Bias)*0.301029995663981 - * + ( (d2-1.5)*0.289529654602168 + 0.176091259055681 ); - * - * We want k to be too large rather than too small. - * The error in the first-order Taylor series approximation - * is in our favor, so we just round up the constant enough - * to compensate for any error in the multiplication of - * (i - Bias) by 0.301029995663981; since |i - Bias| <= 1077, - * and 1077 * 0.30103 * 2^-52 ~=~ 7.2e-14, - * adding 1e-13 to the constant term more than suffices. - * Hence we adjust the constant term to 0.1760912590558. - * (We could get a more accurate k by invoking log10, - * but this is probably not worthwhile.) - */ - - i -= Bias; -#ifdef IBM - i <<= 2; - i += j; -#endif -#ifndef Sudden_Underflow - denorm = 0; - } - else { - /* d is denormalized */ - - i = bbits + be + (Bias + (P-1) - 1); - x = i > 32 ? word0(d) << 64 - i | word1(d) >> i - 32 - : word1(d) << 32 - i; - d2 = x; - word0(d2) -= 31*Exp_msk1; /* adjust exponent */ - i -= (Bias + (P-1) - 1) + 1; - denorm = 1; - } -#endif - ds = (d2-1.5)*0.289529654602168 + 0.1760912590558 + i*0.301029995663981; - k = (int)ds; - if (ds < 0. && ds != k) - k--; /* want k = floor(ds) */ - k_check = 1; - if (k >= 0 && k <= Ten_pmax) { - if (d < tens[k]) - k--; - k_check = 0; - } - j = bbits - i - 1; - if (j >= 0) { - b2 = 0; - s2 = j; - } - else { - b2 = -j; - s2 = 0; - } - if (k >= 0) { - b5 = 0; - s5 = k; - s2 += k; - } - else { - b2 -= k; - b5 = -k; - s5 = 0; - } - if (mode < 0 || mode > 9) - mode = 0; - try_quick = 1; - if (mode > 5) { - mode -= 4; - try_quick = 0; - } - leftright = 1; - switch(mode) { - case 0: - case 1: - ilim = ilim1 = -1; - i = 18; - ndigits = 0; - break; - case 2: - leftright = 0; - /* no break */ - case 4: - if (ndigits <= 0) - ndigits = 1; - ilim = ilim1 = i = ndigits; - break; - case 3: - leftright = 0; - /* no break */ - case 5: - i = ndigits + k + 1; - ilim = i; - ilim1 = i - 1; - if (i <= 0) - i = 1; - } - *resultp = (char *) malloc(i + 1); - s = s0 = *resultp; - - if (ilim >= 0 && ilim <= Quick_max && try_quick) { - - /* Try to get by with floating-point arithmetic. */ - - i = 0; - d2 = d; - k0 = k; - ilim0 = ilim; - ieps = 2; /* conservative */ - if (k > 0) { - ds = tens[k&0xf]; - j = k >> 4; - if (j & Bletch) { - /* prevent overflows */ - j &= Bletch - 1; - d /= bigtens[n_bigtens-1]; - ieps++; - } - for(; j; j >>= 1, i++) - if (j & 1) { - ieps++; - ds *= bigtens[i]; - } - d /= ds; - } - else if (j1 = -k) { - d *= tens[j1 & 0xf]; - for(j = j1 >> 4; j; j >>= 1, i++) - if (j & 1) { - ieps++; - d *= bigtens[i]; - } - } - if (k_check && d < 1. && ilim > 0) { - if (ilim1 <= 0) - goto fast_failed; - ilim = ilim1; - k--; - d *= 10.; - ieps++; - } - eps = ieps*d + 7.; - word0(eps) -= (P-1)*Exp_msk1; - if (ilim == 0) { - S = mhi = 0; - d -= 5.; - if (d > eps) - goto one_digit; - if (d < -eps) - goto no_digits; - goto fast_failed; - } -#ifndef No_leftright - if (leftright) { - /* Use Steele & White method of only - * generating digits needed. - */ - eps = 0.5/tens[ilim-1] - eps; - for(i = 0;;) { - L = d; - d -= L; - *s++ = '0' + (int)L; - if (d < eps) - goto ret1; - if (1. - d < eps) - goto bump_up; - if (++i >= ilim) - break; - eps *= 10.; - d *= 10.; - } - } - else { -#endif - /* Generate ilim digits, then fix them up. */ - eps *= tens[ilim-1]; - for(i = 1;; i++, d *= 10.) { - L = d; - d -= L; - *s++ = '0' + (int)L; - if (i == ilim) { - if (d > 0.5 + eps) - goto bump_up; - else if (d < 0.5 - eps) { - while(*--s == '0'); - s++; - goto ret1; - } - break; - } - } -#ifndef No_leftright - } -#endif - fast_failed: - s = s0; - d = d2; - k = k0; - ilim = ilim0; - } - - /* Do we have a "small" integer? */ - - if (be >= 0 && k <= Int_max) { - /* Yes. */ - ds = tens[k]; - if (ndigits < 0 && ilim <= 0) { - S = mhi = 0; - if (ilim < 0 || d <= 5*ds) - goto no_digits; - goto one_digit; - } - for(i = 1;; i++) { - L = d / ds; - d -= L*ds; -#ifdef Check_FLT_ROUNDS - /* If FLT_ROUNDS == 2, L will usually be high by 1 */ - if (d < 0) { - L--; - d += ds; - } -#endif - *s++ = '0' + (int)L; - if (i == ilim) { - d += d; - if (d > ds || d == ds && L & 1) { - bump_up: - while(*--s == '9') - if (s == s0) { - k++; - *s = '0'; - break; - } - ++*s++; - } - break; - } - if (!(d *= 10.)) - break; - } - goto ret1; - } - - m2 = b2; - m5 = b5; - mhi = mlo = 0; - if (leftright) { - if (mode < 2) { - i = -#ifndef Sudden_Underflow - denorm ? be + (Bias + (P-1) - 1 + 1) : -#endif -#ifdef IBM - 1 + 4*P - 3 - bbits + ((bbits + be - 1) & 3); -#else - 1 + P - bbits; -#endif - } - else { - j = ilim - 1; - if (m5 >= j) - m5 -= j; - else { - s5 += j -= m5; - b5 += j; - m5 = 0; - } - if ((i = ilim) < 0) { - m2 -= i; - i = 0; - } - } - b2 += i; - s2 += i; - mhi = i2b(1); - } - if (m2 > 0 && s2 > 0) { - i = m2 < s2 ? m2 : s2; - b2 -= i; - m2 -= i; - s2 -= i; - } - if (b5 > 0) { - if (leftright) { - if (m5 > 0) { - mhi = pow5mult(mhi, m5); - b1 = mult(mhi, b); - Bfree(b); - b = b1; - } - if (j = b5 - m5) - b = pow5mult(b, j); - } - else - b = pow5mult(b, b5); - } - S = i2b(1); - if (s5 > 0) - S = pow5mult(S, s5); - - /* Check for special case that d is a normalized power of 2. */ - - if (mode < 2) { - if (!word1(d) && !(word0(d) & Bndry_mask) -#ifndef Sudden_Underflow - && word0(d) & Exp_mask -#endif - ) { - /* The special case */ - b2 += Log2P; - s2 += Log2P; - spec_case = 1; - } - else - spec_case = 0; - } - - /* Arrange for convenient computation of quotients: - * shift left if necessary so divisor has 4 leading 0 bits. - * - * Perhaps we should just compute leading 28 bits of S once - * and for all and pass them and a shift to quorem, so it - * can do shifts and ors to compute the numerator for q. - */ -#ifdef Pack_32 - if (i = ((s5 ? 32 - hi0bits(S->x[S->wds-1]) : 1) + s2) & 0x1f) - i = 32 - i; -#else - if (i = ((s5 ? 32 - hi0bits(S->x[S->wds-1]) : 1) + s2) & 0xf) - i = 16 - i; -#endif - if (i > 4) { - i -= 4; - b2 += i; - m2 += i; - s2 += i; - } - else if (i < 4) { - i += 28; - b2 += i; - m2 += i; - s2 += i; - } - if (b2 > 0) - b = lshift(b, b2); - if (s2 > 0) - S = lshift(S, s2); - if (k_check) { - if (cmp(b,S) < 0) { - k--; - b = multadd(b, 10, 0); /* we botched the k estimate */ - if (leftright) - mhi = multadd(mhi, 10, 0); - ilim = ilim1; - } - } - if (ilim <= 0 && mode > 2) { - if (ilim < 0 || cmp(b,S = multadd(S,5,0)) <= 0) { - /* no digits, fcvt style */ - no_digits: - k = -1 - ndigits; - goto ret; - } - one_digit: - *s++ = '1'; - k++; - goto ret; - } - if (leftright) { - if (m2 > 0) - mhi = lshift(mhi, m2); - - /* Compute mlo -- check for special case - * that d is a normalized power of 2. - */ - - mlo = mhi; - if (spec_case) { - mhi = Balloc(mhi->k); - Bcopy(mhi, mlo); - mhi = lshift(mhi, Log2P); - } - - for(i = 1;;i++) { - dig = quorem(b,S) + '0'; - /* Do we yet have the shortest decimal string - * that will round to d? - */ - j = cmp(b, mlo); - delta = diff(S, mhi); - j1 = delta->sign ? 1 : cmp(b, delta); - Bfree(delta); -#ifndef ROUND_BIASED - if (j1 == 0 && !mode && !(word1(d) & 1)) { - if (dig == '9') - goto round_9_up; - if (j > 0) - dig++; - *s++ = dig; - goto ret; - } -#endif - if (j < 0 || j == 0 && !mode -#ifndef ROUND_BIASED - && !(word1(d) & 1) -#endif - ) { - if (j1 > 0) { - b = lshift(b, 1); - j1 = cmp(b, S); - if ((j1 > 0 || j1 == 0 && dig & 1) - && dig++ == '9') - goto round_9_up; - } - *s++ = dig; - goto ret; - } - if (j1 > 0) { - if (dig == '9') { /* possible if i == 1 */ - round_9_up: - *s++ = '9'; - goto roundoff; - } - *s++ = dig + 1; - goto ret; - } - *s++ = dig; - if (i == ilim) - break; - b = multadd(b, 10, 0); - if (mlo == mhi) - mlo = mhi = multadd(mhi, 10, 0); - else { - mlo = multadd(mlo, 10, 0); - mhi = multadd(mhi, 10, 0); - } - } - } - else - for(i = 1;; i++) { - *s++ = dig = quorem(b,S) + '0'; - if (i >= ilim) - break; - b = multadd(b, 10, 0); - } - - /* Round off last digit */ - - b = lshift(b, 1); - j = cmp(b, S); - if (j > 0 || j == 0 && dig & 1) { - roundoff: - while(*--s == '9') - if (s == s0) { - k++; - *s++ = '1'; - goto ret; - } - ++*s++; - } - else { - while(*--s == '0'); - s++; - } - ret: - Bfree(S); - if (mhi) { - if (mlo && mlo != mhi) - Bfree(mlo); - Bfree(mhi); - } - ret1: - Bfree(b); - if (s == s0) { /* don't return empty string */ - *s++ = '0'; - k = 0; - } - *s = 0; - *decpt = k + 1; - if (rve) - *rve = s; - return s0; - } -#ifdef __cplusplus -} -#endif diff --git a/stdlib.subproj/strtol.c b/stdlib.subproj/strtol.c deleted file mode 100644 index ad8302d..0000000 --- a/stdlib.subproj/strtol.c +++ /dev/null @@ -1,147 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 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 -#include -#include -#include - - -/* - * Convert a string to a long integer. - * - * Ignores `locale' stuff. Assumes that the upper and lower case - * alphabets and digits are each contiguous. - */ -long -strtol(nptr, endptr, base) - const char *nptr; - char **endptr; - register int base; -{ - register const char *s = nptr; - register unsigned long acc; - register int c; - register unsigned long cutoff; - register int neg = 0, any, cutlim; - - /* - * Skip white space and pick up leading +/- sign if any. - * If base is 0, allow 0x for hex and 0 for octal, else - * assume decimal; if base is already 16, allow 0x. - */ - do { - c = *s++; - } while (isspace(c)); - if (c == '-') { - neg = 1; - c = *s++; - } else if (c == '+') - c = *s++; - if ((base == 0 || base == 16) && - c == '0' && (*s == 'x' || *s == 'X')) { - c = s[1]; - s += 2; - base = 16; - } - if (base == 0) - base = c == '0' ? 8 : 10; - - /* - * Compute the cutoff value between legal numbers and illegal - * numbers. That is the largest legal value, divided by the - * base. An input number that is greater than this value, if - * followed by a legal input character, is too big. One that - * is equal to this value may be valid or not; the limit - * between valid and invalid numbers is then based on the last - * digit. For instance, if the range for longs is - * [-2147483648..2147483647] and the input base is 10, - * cutoff will be set to 214748364 and cutlim to either - * 7 (neg==0) or 8 (neg==1), meaning that if we have accumulated - * a value > 214748364, or equal but the next digit is > 7 (or 8), - * the number is too big, and we will return a range error. - * - * Set any if any `digits' consumed; make it negative to indicate - * overflow. - */ - cutoff = neg ? -(unsigned long)LONG_MIN : LONG_MAX; - cutlim = cutoff % (unsigned long)base; - cutoff /= (unsigned long)base; - for (acc = 0, any = 0;; c = *s++) { - if (isdigit(c)) - c -= '0'; - else if (isalpha(c)) - c -= isupper(c) ? 'A' - 10 : 'a' - 10; - else - break; - if (c >= base) - break; - if (any < 0 || acc > cutoff || acc == cutoff && c > cutlim) - any = -1; - else { - any = 1; - acc *= base; - acc += c; - } - } - if (any < 0) { - acc = neg ? LONG_MIN : LONG_MAX; - errno = ERANGE; - } else if (neg) - acc = -acc; - if (endptr != 0) - *endptr = (char *)(any ? s - 1 : nptr); - return (acc); -} diff --git a/stdlib.subproj/strtoq.c b/stdlib.subproj/strtoq.c deleted file mode 100644 index c099ba1..0000000 --- a/stdlib.subproj/strtoq.c +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * 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. - */ - - -#include - -#include -#include -#include -#include - -/* - * Convert a string to a quad integer. - * - * Ignores `locale' stuff. Assumes that the upper and lower case - * alphabets and digits are each contiguous. - */ -quad_t -strtoq(nptr, endptr, base) - const char *nptr; - char **endptr; - register int base; -{ - register const char *s; - register u_quad_t acc; - register int c; - register u_quad_t qbase, cutoff; - register int neg, any, cutlim; - - /* - * Skip white space and pick up leading +/- sign if any. - * If base is 0, allow 0x for hex and 0 for octal, else - * assume decimal; if base is already 16, allow 0x. - */ - s = nptr; - do { - c = *s++; - } while (isspace(c)); - if (c == '-') { - neg = 1; - c = *s++; - } else { - neg = 0; - if (c == '+') - c = *s++; - } - if ((base == 0 || base == 16) && - c == '0' && (*s == 'x' || *s == 'X')) { - c = s[1]; - s += 2; - base = 16; - } - if (base == 0) - base = c == '0' ? 8 : 10; - - /* - * Compute the cutoff value between legal numbers and illegal - * numbers. That is the largest legal value, divided by the - * base. An input number that is greater than this value, if - * followed by a legal input character, is too big. One that - * is equal to this value may be valid or not; the limit - * between valid and invalid numbers is then based on the last - * digit. For instance, if the range for quads is - * [-9223372036854775808..9223372036854775807] and the input base - * is 10, cutoff will be set to 922337203685477580 and cutlim to - * either 7 (neg==0) or 8 (neg==1), meaning that if we have - * accumulated a value > 922337203685477580, or equal but the - * next digit is > 7 (or 8), the number is too big, and we will - * return a range error. - * - * Set any if any `digits' consumed; make it negative to indicate - * overflow. - */ - qbase = (unsigned)base; - cutoff = neg ? -(u_quad_t)QUAD_MIN : QUAD_MAX; - cutlim = cutoff % qbase; - cutoff /= qbase; - for (acc = 0, any = 0;; c = *s++) { - if (isdigit(c)) - c -= '0'; - else if (isalpha(c)) - c -= isupper(c) ? 'A' - 10 : 'a' - 10; - else - break; - if (c >= base) - break; - if (any < 0 || acc > cutoff || acc == cutoff && c > cutlim) - any = -1; - else { - any = 1; - acc *= qbase; - acc += c; - } - } - if (any < 0) { - acc = neg ? QUAD_MIN : QUAD_MAX; - errno = ERANGE; - } else if (neg) - acc = -acc; - if (endptr != 0) - *endptr = (char *)(any ? s - 1 : nptr); - return (acc); -} diff --git a/stdlib.subproj/strtoul.c b/stdlib.subproj/strtoul.c deleted file mode 100644 index e0ccb4d..0000000 --- a/stdlib.subproj/strtoul.c +++ /dev/null @@ -1,125 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 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 -#include -#include -#include - -/* - * Convert a string to an unsigned long integer. - * - * Ignores `locale' stuff. Assumes that the upper and lower case - * alphabets and digits are each contiguous. - */ -unsigned long -strtoul(nptr, endptr, base) - const char *nptr; - char **endptr; - register int base; -{ - register const char *s = nptr; - register unsigned long acc; - register int c; - register unsigned long cutoff; - register int neg = 0, any, cutlim; - - /* - * See strtol for comments as to the logic used. - */ - do { - c = *s++; - } while (isspace(c)); - if (c == '-') { - neg = 1; - c = *s++; - } else if (c == '+') - c = *s++; - if ((base == 0 || base == 16) && - c == '0' && (*s == 'x' || *s == 'X')) { - c = s[1]; - s += 2; - base = 16; - } - if (base == 0) - base = c == '0' ? 8 : 10; - cutoff = (unsigned long)ULONG_MAX / (unsigned long)base; - cutlim = (unsigned long)ULONG_MAX % (unsigned long)base; - for (acc = 0, any = 0;; c = *s++) { - if (isdigit(c)) - c -= '0'; - else if (isalpha(c)) - c -= isupper(c) ? 'A' - 10 : 'a' - 10; - else - break; - if (c >= base) - break; - if (any < 0 || acc > cutoff || acc == cutoff && c > cutlim) - any = -1; - else { - any = 1; - acc *= base; - acc += c; - } - } - if (any < 0) { - acc = ULONG_MAX; - errno = ERANGE; - } else if (neg) - acc = -acc; - if (endptr != 0) - *endptr = (char *)(any ? s - 1 : nptr); - return (acc); -} diff --git a/stdlib.subproj/strtouq.c b/stdlib.subproj/strtouq.c deleted file mode 100644 index 1fefc54..0000000 --- a/stdlib.subproj/strtouq.c +++ /dev/null @@ -1,132 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * 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. - */ - - -#include - -#include -#include -#include -#include - -/* - * Convert a string to an unsigned quad integer. - * - * Ignores `locale' stuff. Assumes that the upper and lower case - * alphabets and digits are each contiguous. - */ -u_quad_t -strtouq(nptr, endptr, base) - const char *nptr; - char **endptr; - register int base; -{ - register const char *s = nptr; - register u_quad_t acc; - register int c; - register u_quad_t qbase, cutoff; - register int neg, any, cutlim; - - /* - * See strtoq for comments as to the logic used. - */ - s = nptr; - do { - c = *s++; - } while (isspace(c)); - if (c == '-') { - neg = 1; - c = *s++; - } else { - neg = 0; - if (c == '+') - c = *s++; - } - if ((base == 0 || base == 16) && - c == '0' && (*s == 'x' || *s == 'X')) { - c = s[1]; - s += 2; - base = 16; - } - if (base == 0) - base = c == '0' ? 8 : 10; - qbase = (unsigned)base; - cutoff = (u_quad_t)UQUAD_MAX / qbase; - cutlim = (u_quad_t)UQUAD_MAX % qbase; - for (acc = 0, any = 0;; c = *s++) { - if (isdigit(c)) - c -= '0'; - else if (isalpha(c)) - c -= isupper(c) ? 'A' - 10 : 'a' - 10; - else - break; - if (c >= base) - break; - if (any < 0 || acc > cutoff || acc == cutoff && c > cutlim) - any = -1; - else { - any = 1; - acc *= qbase; - acc += c; - } - } - if (any < 0) { - acc = UQUAD_MAX; - errno = ERANGE; - } else if (neg) - acc = -acc; - if (endptr != 0) - *endptr = (char *)(any ? s - 1 : nptr); - return (acc); -} diff --git a/stdlib.subproj/system.c b/stdlib.subproj/system.c deleted file mode 100644 index f31e4db..0000000 --- a/stdlib.subproj/system.c +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1988, 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 -#include -#include -#include -#include -#include -#include - -system(command) - const char *command; -{ - union wait pstat; - pid_t pid; - int omask; - sig_t intsave, quitsave; - - if (!command) /* just checking... */ - return(1); - - omask = sigblock(sigmask(SIGCHLD)); - switch(pid = vfork()) { - case -1: /* error */ - (void)sigsetmask(omask); - pstat.w_status = 0; - pstat.w_retcode = 127; - return(pstat.w_status); - case 0: /* child */ - (void)sigsetmask(omask); - execl(_PATH_BSHELL, "sh", "-c", command, (char *)NULL); - _exit(127); - } - intsave = signal(SIGINT, SIG_IGN); - quitsave = signal(SIGQUIT, SIG_IGN); - pid = waitpid(pid, (int *)&pstat, 0); - (void)sigsetmask(omask); - (void)signal(SIGINT, intsave); - (void)signal(SIGQUIT, quitsave); - return(pid == -1 ? -1 : pstat.w_status); -} diff --git a/stdlib/Makefile.inc b/stdlib/Makefile.inc new file mode 100644 index 0000000..2ed34f1 --- /dev/null +++ b/stdlib/Makefile.inc @@ -0,0 +1,45 @@ +# from @(#)Makefile.inc 8.3 (Berkeley) 2/4/95 +# $FreeBSD: src/lib/libc/stdlib/Makefile.inc,v 1.32 2001/09/07 13:03:16 phantom Exp $ + +# machine-independent stdlib sources +.PATH: ${.CURDIR}/${MACHINE_ARCH}/stdlib ${.CURDIR}/stdlib + +MISRCS+=abort.c bsearch.c getsubopt.c putenv.c setenv.c strtouq.c \ + atexit.c div.c heapsort.c qsort.c strtod.c system.c \ + atof.c exit.c labs.c radixsort.c strtol.c \ + atoi.c getenv.c ldiv.c rand.c strtoq.c \ + atol.c getopt.c merge.c random.c strtoul.c \ + reallocf.c a64l.c l64a.c strtoll.c strtoull.c + +.if ${MACHINE_ARCH} == "alpha" +# XXX Temporary until the assumption that a long is 32-bits is resolved +# XXX FreeBSD's code. NetBSD kludged this with Long = int32_t and +# XXX ULong = u_int32_t +SRCS+= netbsd_strtod.c +.else +SRCS+= strtod.c +.endif + +# machine-dependent stdlib sources +.if exists(${.CURDIR}/${MACHINE_ARCH}/stdlib/Makefile.inc) +.include "${.CURDIR}/${MACHINE_ARCH}/stdlib/Makefile.inc" +.endif + +.if ${LIB} == "c" +MAN3+= abort.3 abs.3 alloca.3 atexit.3 atof.3 atoi.3 atol.3 bsearch.3 \ + div.3 exit.3 getenv.3 getopt.3 getsubopt.3 hcreate.3 labs.3 \ + ldiv.3 malloc.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 \ + a64l.3 + +MLINKS+=getenv.3 putenv.3 getenv.3 setenv.3 getenv.3 unsetenv.3 +MLINKS+=hcreate.3 hdestroy.3 hcreate.3 hsearch.3 +MLINKS+=qsort.3 heapsort.3 qsort.3 mergesort.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+=strtol.3 strtoll.3 strtol.3 strtoq.3 +MLINKS+=strtoul.3 strtoull.3 strtoul.3 strtouq.3 +MLINKS+=malloc.3 calloc.3 malloc.3 free.3 malloc.3 realloc.3 malloc.3 reallocf.3 +MLINKS+=tsearch.3 tdelete.3 tsearch.3 tfind.3 tsearch.3 twalk.3 a64l.3 l64a.3 +.endif diff --git a/stdlib/a64l.3 b/stdlib/a64l.3 new file mode 100644 index 0000000..0c15487 --- /dev/null +++ b/stdlib/a64l.3 @@ -0,0 +1,145 @@ +.\" Copyright (c) 1997 Todd C. Miller +.\" 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. 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 ARE 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 +.\" ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +.\" +.\" $OpenBSD: a64l.3,v 1.5 2000/04/20 13:50:01 aaron Exp $ +.\" +.Dd August 17, 1997 +.Dt A64L 3 +.Os +.Sh NAME +.Nm a64l , +.Nm l64a +.Nd convert between 32-bit integer and radix-64 ASCII string +.Sh SYNOPSIS +.Fd #include +.Ft long +.Fn a64l "const char *s" +.Ft char * +.Fn l64a "long l" +.Sh DESCRIPTION +The +.Fn a64l +and +.Fn l64a +functions are used to maintain numbers stored in radix-64 +.Tn ASCII +characters. +This is a notation by which 32-bit integers +can be represented by up to six characters; each character represents a +.Dq digit +in a radix-64 notation. +.Pp +The characters used to represent digits are +.Ql \&. +for 0, +.Ql / +for 1, +.Ql 0 +through +.Ql 9 +for 2-11, +.Ql A +through +.Ql Z +for 12-37, and +.Ql a +through +.Ql z +for 38-63. +.Pp +The +.Fn a64l +function takes a pointer to a null-terminated radix-64 representation +and returns a corresponding 32-bit value. +If the string pointed to by +.Fa s +contains more than six characters, +.Fn a64l +will use the first six. +.Fn a64l +scans the character string from left to right, decoding +each character as a 6-bit radix-64 number. +If a long integer is +larger than 32 bits, the return value will be sign-extended. +.Pp +.Fn l64a +takes a long integer argument +.Fa l +and returns a pointer to the corresponding radix-64 representation. +.Sh RETURN VALUES +On success, +.Fn a64l +returns a 32-bit representation of +.Fa s . +If +.Fa s +is a null pointer or if it contains digits other than those described above. +.Fn a64l +returns \-1 and sets the global variable +.Va errno +to +.Er EINVAL . +.Pp +On success, +.Fn l64a +returns a pointer to a string containing the radix-64 representation of +.Fa l . +If +.Fa l +is 0, +.Fn l64a +returns a pointer to the empty string. +If +.Fa l +is negative, +.Fn l64a +returns a null pointer and sets the global variable +.Va errno +to +.Er EINVAL . +.Sh WARNINGS +The value returned by +.Fn l64a +is a pointer into a static buffer, the contents of which +will be overwritten by subsequent calls. +.Pp +The value returned by +.Fn a64l +may be incorrect if the value is too large; for that reason, only strings +that resulted from a call to +.Fn l64a +should be used to call +.Fn a64l . +.Pp +If a long integer is larger than 32 bits, only the low-order +32 bits are used. +.Sh STANDARDS +The +.Fn a64l +and +.Fn l64a +functions conform to +.St -xpg4.2 . + diff --git a/stdlib/a64l.c b/stdlib/a64l.c new file mode 100644 index 0000000..67415b4 --- /dev/null +++ b/stdlib/a64l.c @@ -0,0 +1,47 @@ +/* + * Written by J.T. Conklin . + * Public domain. + */ + +#if defined(LIBC_SCCS) && !defined(lint) +static char *rcsid = "$OpenBSD: a64l.c,v 1.3 1997/08/17 22:58:34 millert Exp $"; +#endif /* LIBC_SCCS and not lint */ + +#include +#include + +long +a64l(s) + const char *s; +{ + long value, digit, shift; + int i; + + if (s == NULL) { + errno = EINVAL; + return(-1L); + } + + value = 0; + shift = 0; + for (i = 0; *s && i < 6; i++, s++) { + if (*s >= '.' && *s <= '/') + digit = *s - '.'; + else if (*s >= '0' && *s <= '9') + digit = *s - '0' + 2; + else if (*s >= 'A' && *s <= 'Z') + digit = *s - 'A' + 12; + else if (*s >= 'a' && *s <= 'z') + digit = *s - 'a' + 38; + else { + errno = EINVAL; + return(-1L); + } + + value |= digit << shift; + shift += 6; + } + + return(value); +} + diff --git a/stdlib/abort.3 b/stdlib/abort.3 new file mode 100644 index 0000000..07ca798 --- /dev/null +++ b/stdlib/abort.3 @@ -0,0 +1,83 @@ +.\" 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. +.\" +.\" @(#)abort.3 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD: src/lib/libc/stdlib/abort.3,v 1.9 2001/09/09 18:52:00 asmodai Exp $ +.\" +.Dd June 4, 1993 +.Dt ABORT 3 +.Os +.Sh NAME +.Nm abort +.Nd cause abnormal program termination +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In stdlib.h +.Ft void +.Fn abort void +.Sh DESCRIPTION +The +.Fn abort +function causes abnormal program termination to occur, unless the +signal +.Dv SIGABRT +is being caught and the signal handler does not return. +.Pp +Any open streams are flushed and closed. +.Sh IMPLEMENTATION NOTES +The +.Fn abort +function is thread-safe. +It is unknown if it is async-cancel-safe. +.Sh RETURN VALUES +The +.Fn abort +function +never returns. +.Sh SEE ALSO +.Xr sigaction 2 , +.Xr exit 3 +.Sh STANDARDS +The +.Fn abort +function +conforms to +.St -p1003.1-90 . +The +.Fn abort +function also conforms to +.St -isoC-99 +with the implementation specific details as noted above. diff --git a/stdlib/abort.c b/stdlib/abort.c new file mode 100644 index 0000000..5616ad9 --- /dev/null +++ b/stdlib/abort.c @@ -0,0 +1,106 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1985, 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 +#include +#include +#include + +void +abort() +{ + int mypid = getpid(); + volatile long i; + volatile long *excp = 0; + sigset_t mask; + + sigfillset(&mask); + /* + * don't block SIGABRT to give any handler a chance; we ignore + * any errors -- X3J11 doesn't allow abort to return anyway. + */ + sigdelset(&mask, SIGABRT); + (void)sigprocmask(SIG_SETMASK, &mask, (sigset_t *)NULL); + (void)kill(mypid, SIGABRT); + + /* + * if SIGABRT ignored, or caught and the handler returns, do + * it again, only harder. + */ + (void)signal(SIGABRT, SIG_DFL); + (void)sigprocmask(SIG_SETMASK, &mask, (sigset_t *)NULL); + (void)kill(mypid, SIGABRT); + + i = *excp; /* still no joy; cause a processor trap */ + i = *++excp; /* maybe an unaligned address will do it */ + + /* okay, let's try to write text space */ + excp = (volatile long *)&abort; + *excp = ~*excp; + *excp = ~*excp; + + i /= 0; /* this time for sure! */ + + /* increasing desperation; try signals until one of them sticks */ + (void)kill(mypid, SIGILL); + (void)kill(mypid, SIGBUS); + + /* almost last resort */ + _exit(1); + + /* if _exit returns, do not return */ + for (;;) + sleep(600); +} diff --git a/stdlib/abs.3 b/stdlib/abs.3 new file mode 100644 index 0000000..e1d0337 --- /dev/null +++ b/stdlib/abs.3 @@ -0,0 +1,77 @@ +.\" 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. +.\" +.\" @(#)abs.3 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD: src/lib/libc/stdlib/abs.3,v 1.10 2001/09/07 14:46:35 asmodai Exp $ +.\" +.Dd June 4, 1993 +.Dt ABS 3 +.Os +.Sh NAME +.Nm abs +.Nd integer absolute value function +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In stdlib.h +.Ft int +.Fn abs "int j" +.Sh DESCRIPTION +The +.Fn abs +function +computes +the absolute value of the integer +.Ar j . +.Sh RETURN VALUES +The +.Fn abs +function +returns +the absolute value. +.Sh SEE ALSO +.Xr cabs 3 , +.Xr fabs 3 , +.Xr floor 3 , +.Xr hypot 3 , +.Xr labs 3 , +.Xr math 3 +.Sh STANDARDS +The +.Fn abs +function conforms to +.St -isoC . +.Sh BUGS +The absolute value of the most negative integer remains negative. diff --git a/stdlib/alloca.3 b/stdlib/alloca.3 new file mode 100644 index 0000000..9567ded --- /dev/null +++ b/stdlib/alloca.3 @@ -0,0 +1,81 @@ +.\" 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. +.\" +.\" @(#)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 $ +.\" +.Dd June 4, 1993 +.Dt ALLOCA 3 +.Os +.Sh NAME +.Nm alloca +.Nd memory allocator +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In stdlib.h +.Ft void * +.Fn alloca "size_t size" +.Sh DESCRIPTION +The +.Fn alloca +function +allocates +.Fa size +bytes of space in the stack frame of the caller. +This temporary space is automatically freed on +return. +.Sh RETURN VALUES +The +.Fn alloca +function returns a pointer to the beginning of the allocated space. +If the allocation failed, a +.Dv NULL +pointer is returned. +.Sh SEE ALSO +.Xr brk 2 , +.Xr calloc 3 , +.Xr getpagesize 3 , +.Xr malloc 3 , +.Xr realloc 3 +.Sh BUGS +The +.Fn alloca +function +is machine dependent; its use is discouraged. +.\" .Sh HISTORY +.\" The +.\" .Fn alloca +.\" function appeared in +.\" .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... diff --git a/stdlib/atexit.3 b/stdlib/atexit.3 new file mode 100644 index 0000000..f1b0acf --- /dev/null +++ b/stdlib/atexit.3 @@ -0,0 +1,80 @@ +.\" 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. +.\" +.\" @(#)atexit.3 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD: src/lib/libc/stdlib/atexit.3,v 1.7 2001/09/07 14:46:35 asmodai Exp $ +.\" +.Dd June 4, 1993 +.Dt ATEXIT 3 +.Os +.Sh NAME +.Nm atexit +.Nd register a function to be called on exit +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In stdlib.h +.Ft int +.Fn atexit "void (*function)(void)" +.Sh DESCRIPTION +The +.Fn atexit +function +registers the given +.Ar function +to be called at program exit, whether via +.Xr exit 3 +or via return from the program's +.Em main . +Functions so registered are called in reverse order; +no arguments are passed. +At least 32 functions can always be registered, +and more are allowed as long as sufficient memory can be allocated. +.Sh RETURN VALUES +.Rv -std atexit +.Sh ERRORS +.Bl -tag -width Er +.It Bq Er ENOMEM +No memory was available to add the function to the list. +The existing list of functions is unmodified. +.El +.Sh SEE ALSO +.Xr exit 3 +.Sh STANDARDS +The +.Fn atexit +function +conforms to +.St -isoC . diff --git a/stdlib/atexit.c b/stdlib/atexit.c new file mode 100644 index 0000000..014fbce --- /dev/null +++ b/stdlib/atexit.c @@ -0,0 +1,86 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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 +#include +#include "atexit.h" + +struct atexit *__atexit = NULL; /* points to head of LIFO stack */ + +/* + * Register a function to be performed at exit. + */ +int +atexit(fn) + void (*fn)(); +{ + static struct atexit __atexit0; /* one guaranteed table */ + register struct atexit *p; + + if ((p = __atexit) == NULL) + __atexit = p = &__atexit0; + else if (p->ind >= ATEXIT_SIZE) { + if ((p = malloc(sizeof(*p))) == NULL) + return (-1); + p->ind = 0; + p->next = __atexit; + __atexit = p; + } + p->fns[p->ind++] = fn; + return (0); +} diff --git a/stdlib/atexit.h b/stdlib/atexit.h new file mode 100644 index 0000000..27a7fa5 --- /dev/null +++ b/stdlib/atexit.h @@ -0,0 +1,65 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 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. + */ + +/* must be at least 32 to guarantee ANSI conformance */ +#define ATEXIT_SIZE 32 + +struct atexit { + struct atexit *next; /* next in list */ + int ind; /* next index in this table */ + void (*fns[ATEXIT_SIZE])(); /* the table itself */ +}; + +extern struct atexit *__atexit; /* points to head of LIFO stack */ + /* storage allocated in atexit.c */ diff --git a/stdlib/atof.3 b/stdlib/atof.3 new file mode 100644 index 0000000..1f5042d --- /dev/null +++ b/stdlib/atof.3 @@ -0,0 +1,97 @@ +.\" Copyright (c) 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. +.\" +.\" @(#)atof.3 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD: src/lib/libc/stdlib/atof.3,v 1.12 2001/09/26 20:10:10 asmodai Exp $ +.\" +.Dd June 4, 1993 +.Dt ATOF 3 +.Os +.Sh NAME +.Nm atof +.Nd convert +.Tn ASCII +string to double +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In stdlib.h +.Ft double +.Fn atof "const char *nptr" +.Sh DESCRIPTION +The +.Fn atof +function converts the initial portion of the string pointed to by +.Ar nptr +to +.Ar double +representation. +.Pp +It is equivalent to: +.Bd -literal -offset indent +strtod(nptr, (char **)NULL); +.Ed +.Pp +The decimal point +character is defined in the program's locale (category +.Dv LC_NUMERIC ) . +.Sh IMPLEMENTATION NOTES +The +.Fn atof +function is not thread-safe and also not async-cancel-safe. +.Pp +The +.Fn atof +function has been deprecated by +.Fn strtod +and should not be used in new code. +.Sh ERRORS +The +.Fn atof +function does not detect errors. +.Sh SEE ALSO +.Xr atoi 3 , +.Xr atol 3 , +.Xr strtod 3 , +.Xr strtol 3 , +.Xr strtoul 3 +.Sh STANDARDS +The +.Fn atof +function conforms to +.St -p1003.1-90 , +.St -isoC , +and +.St -isoC-99 . diff --git a/stdlib/atof.c b/stdlib/atof.c new file mode 100644 index 0000000..49ad147 --- /dev/null +++ b/stdlib/atof.c @@ -0,0 +1,64 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1988, 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 + +double +atof(ascii) + const char *ascii; +{ + return (strtod(ascii, NULL)); +} + diff --git a/stdlib/atoi.3 b/stdlib/atoi.3 new file mode 100644 index 0000000..40ac028 --- /dev/null +++ b/stdlib/atoi.3 @@ -0,0 +1,93 @@ +.\" 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. +.\" +.\" @(#)atoi.3 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD: src/lib/libc/stdlib/atoi.3,v 1.8 2001/10/01 12:44:24 ru Exp $ +.\" +.Dd June 4, 1993 +.Dt ATOI 3 +.Os +.Sh NAME +.Nm atoi +.Nd convert +.Tn ASCII +string to integer +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In stdlib.h +.Ft int +.Fn atoi "const char *nptr" +.Sh DESCRIPTION +The +.Fn atoi +function converts the initial portion of the string pointed to by +.Em nptr +to +.Em integer +representation. +.Pp +It is equivalent to: +.Bd -literal -offset indent +(int)strtol(nptr, (char **)NULL, 10); +.Ed +.Sh IMPLEMENTATION NOTES +The +.Fn atoi +function is not thread-safe and also not async-cancel safe. +.Pp +The +.Fn atoi +function has been deprecated by +.Fn strtol +and should not be used in new code. +.Sh ERRORS +The +.Fn atoi +function does not detect errors. +.Sh SEE ALSO +.Xr atof 3 , +.Xr atol 3 , +.Xr strtod 3 , +.Xr strtol 3 , +.Xr strtoul 3 +.Sh STANDARDS +The +.Fn atoi +function conforms to +.St -p1003.1-90 , +.St -isoC , +and +.St -isoC-99 . diff --git a/stdlib/atoi.c b/stdlib/atoi.c new file mode 100644 index 0000000..c178b6a --- /dev/null +++ b/stdlib/atoi.c @@ -0,0 +1,63 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1988, 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 +#include + +atoi(str) + const char *str; +{ + return((int)strtol(str, (char **)NULL, 10)); +} diff --git a/stdlib/atol.3 b/stdlib/atol.3 new file mode 100644 index 0000000..c18ced0 --- /dev/null +++ b/stdlib/atol.3 @@ -0,0 +1,77 @@ +.\" 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. +.\" +.\" @(#)atol.3 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD: src/lib/libc/stdlib/atol.3,v 1.6 2001/09/07 14:46:35 asmodai Exp $ +.\" +.Dd June 4, 1993 +.Dt ATOL 3 +.Os +.Sh NAME +.Nm atol +.Nd convert +.Tn ASCII +string to long integer +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In stdlib.h +.Ft long +.Fn atol "const char *nptr" +.Sh DESCRIPTION +The +.Fn atol +function converts the initial portion of the string pointed to by +.Ar nptr +to +.Em long integer +representation. +.Pp +It is equivalent to: +.Bd -literal -offset indent +strtol(nptr, (char **)NULL, 10); +.Ed +.Sh SEE ALSO +.Xr atof 3 , +.Xr atoi 3 , +.Xr strtod 3 , +.Xr strtol 3 , +.Xr strtoul 3 +.Sh STANDARDS +The +.Fn atol +function +conforms to +.St -isoC . diff --git a/stdlib/atol.c b/stdlib/atol.c new file mode 100644 index 0000000..5aec484 --- /dev/null +++ b/stdlib/atol.c @@ -0,0 +1,64 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1988, 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 +#include + +long +atol(str) + const char *str; +{ + return(strtol(str, (char **)NULL, 10)); +} diff --git a/stdlib/bsearch.3 b/stdlib/bsearch.3 new file mode 100644 index 0000000..25c608d --- /dev/null +++ b/stdlib/bsearch.3 @@ -0,0 +1,93 @@ +.\" Copyright (c) 1990, 1991, 1993, 1994 +.\" 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. +.\" +.\" @(#)bsearch.3 8.3 (Berkeley) 4/19/94 +.\" $FreeBSD: src/lib/libc/stdlib/bsearch.3,v 1.8 2001/09/07 14:46:35 asmodai Exp $ +.\" +.Dd April 19, 1994 +.Dt BSEARCH 3 +.Os +.Sh NAME +.Nm bsearch +.Nd binary search of a sorted table +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In stdlib.h +.Ft void * +.Fn bsearch "const void *key" "const void *base" "size_t nmemb" "size_t size" "int (*compar) (const void *, const void *)" +.Sh DESCRIPTION +The +.Fn bsearch +function searches an array of +.Fa nmemb +objects, the initial member of which is +pointed to by +.Fa base , +for a member that matches the object pointed to by +.Fa key . +The size of each member of the array is specified by +.Fa size . +.Pp +The contents of the array should be in ascending sorted order according +to the comparison function referenced by +.Fa compar . +The +.Fa compar +routine +is expected to have +two arguments which point to the +.Fa key +object and to an array member, in that order, and should return an integer +less than, equal to, or greater than zero if the +.Fa key +object is found, respectively, to be less than, to match, or be +greater than the array member. +.Sh RETURN VALUES +The +.Fn bsearch +function returns a pointer to a matching member of the array, or a null +pointer if no match is found. +If two members compare as equal, which member is matched is unspecified. +.Sh SEE ALSO +.Xr db 3 , +.Xr lsearch 3 , +.Xr qsort 3 +.\" .Xr tsearch 3 +.Sh STANDARDS +The +.Fn bsearch +function conforms to +.St -isoC . diff --git a/stdlib/bsearch.c b/stdlib/bsearch.c new file mode 100644 index 0000000..bb40138 --- /dev/null +++ b/stdlib/bsearch.c @@ -0,0 +1,99 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 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 +#include + +/* + * Perform a binary search. + * + * The code below is a bit sneaky. After a comparison fails, we + * divide the work in half by moving either left or right. If lim + * is odd, moving left simply involves halving lim: e.g., when lim + * is 5 we look at item 2, so we change lim to 2 so that we will + * look at items 0 & 1. If lim is even, the same applies. If lim + * is odd, moving right again involes halving lim, this time moving + * the base up one item past p: e.g., when lim is 5 we change base + * to item 3 and make lim 2 so that we will look at items 3 and 4. + * If lim is even, however, we have to shrink it by one before + * halving: e.g., when lim is 4, we still looked at item 2, so we + * have to make lim 3, then halve, obtaining 1, so that we will only + * look at item 3. + */ +void * +bsearch(key, base0, nmemb, size, compar) + register const void *key; + const void *base0; + size_t nmemb; + register size_t size; + register int (*compar) __P((const void *, const void *)); +{ + register const char *base = base0; + register size_t lim; + register int cmp; + register const void *p; + + for (lim = nmemb; lim != 0; lim >>= 1) { + p = base + (lim >> 1) * size; + cmp = (*compar)(key, p); + if (cmp == 0) + return ((void *)p); + if (cmp > 0) { /* key > p: move right */ + base = (char *)p + size; + lim--; + } /* else move left */ + } + return (NULL); +} diff --git a/stdlib/div.3 b/stdlib/div.3 new file mode 100644 index 0000000..b567fed --- /dev/null +++ b/stdlib/div.3 @@ -0,0 +1,70 @@ +.\" 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. +.\" 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. +.\" +.\" @(#)div.3 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD: src/lib/libc/stdlib/div.3,v 1.6 2001/09/07 14:46:35 asmodai Exp $ +.\" +.Dd June 4, 1993 +.Dt DIV 3 +.Os +.Sh NAME +.Nm div +.Nd return quotient and remainder from division +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In stdlib.h +.Ft div_t +.Fn div "int num" "int denom" +.Sh DESCRIPTION +The +.Fn div +function +computes the value +.Fa num/denom +and returns the quotient and remainder in a structure named +.Fa div_t +that contains two +.Em int +members named +.Fa quot +and +.Fa rem . +.Sh SEE ALSO +.Xr ldiv 3 +.Sh STANDARDS +The +.Fn div +function +conforms to +.St -isoC . diff --git a/stdlib/div.c b/stdlib/div.c new file mode 100644 index 0000000..c6594e6 --- /dev/null +++ b/stdlib/div.c @@ -0,0 +1,97 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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 /* div_t */ + +div_t +div(num, denom) + int num, denom; +{ + div_t r; + + r.quot = num / denom; + r.rem = num % denom; + /* + * The ANSI standard says that |r.quot| <= |n/d|, where + * n/d is to be computed in infinite precision. In other + * words, we should always truncate the quotient towards + * 0, never -infinity. + * + * Machine division and remainer may work either way when + * one or both of n or d is negative. If only one is + * negative and r.quot has been truncated towards -inf, + * r.rem will have the same sign as denom and the opposite + * sign of num; if both are negative and r.quot has been + * truncated towards -inf, r.rem will be positive (will + * have the opposite sign of num). These are considered + * `wrong'. + * + * If both are num and denom are positive, r will always + * be positive. + * + * This all boils down to: + * if num >= 0, but r.rem < 0, we got the wrong answer. + * In that case, to get the right answer, add 1 to r.quot and + * subtract denom from r.rem. + */ + if (num >= 0 && r.rem < 0) { + r.quot++; + r.rem -= denom; + } + return (r); +} diff --git a/stdlib/exit.3 b/stdlib/exit.3 new file mode 100644 index 0000000..e74285e --- /dev/null +++ b/stdlib/exit.3 @@ -0,0 +1,98 @@ +.\" 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. +.\" +.\" @(#)exit.3 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD: src/lib/libc/stdlib/exit.3,v 1.10 2001/09/07 14:46:35 asmodai Exp $ +.\" +.Dd June 4, 1993 +.Dt EXIT 3 +.Os +.Sh NAME +.Nm exit +.Nd perform normal program termination +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In stdlib.h +.Ft void +.Fn exit "int status" +.Sh DESCRIPTION +.Fn Exit +terminates a process. +.Pp +Before termination it performs the following functions in the +order listed: +.Bl -enum -offset indent +.It +Call the functions registered with the +.Xr atexit 3 +function, in the reverse order of their registration. +.It +Flush all open output streams. +.It +Close all open streams. +.It +Unlink all files created with the +.Xr tmpfile 3 +function. +.El +.Pp +Passing arbitrary values back to the environment as +.Ar status +is considered bad style; +you should use the values +.Dv EXIT_SUCCESS +and +.Dv EXIT_FAILURE . +If portability is not a concern, you may +use the values described in +.Xr sysexits 3 . +.Sh RETURN VALUES +The +.Fn exit +function +never returns. +.Sh SEE ALSO +.Xr _exit 2 , +.Xr atexit 3 , +.Xr intro 3 , +.Xr sysexits 3 , +.Xr tmpfile 3 +.Sh STANDARDS +The +.Fn exit +function +conforms to +.St -isoC . diff --git a/stdlib/exit.c b/stdlib/exit.c new file mode 100644 index 0000000..133133d --- /dev/null +++ b/stdlib/exit.c @@ -0,0 +1,78 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 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 +#include +#include "atexit.h" + +void (*__cleanup)() = NULL; + +/* + * Exit, flushing stdio buffers if necessary. + */ +void +exit(status) + int status; +{ + register struct atexit *p; + register int n; + + for (p = __atexit; p; p = p->next) + for (n = p->ind; --n >= 0;) + (*p->fns[n])(); + if (__cleanup) + (*__cleanup)(); + _exit(status); +} diff --git a/stdlib/getenv.3 b/stdlib/getenv.3 new file mode 100644 index 0000000..9a2d953 --- /dev/null +++ b/stdlib/getenv.3 @@ -0,0 +1,164 @@ +.\" Copyright (c) 1988, 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. +.\" +.\" @(#)getenv.3 8.2 (Berkeley) 12/11/93 +.\" $FreeBSD: src/lib/libc/stdlib/getenv.3,v 1.12 2001/09/07 14:46:35 asmodai Exp $ +.\" +.Dd December 11, 1993 +.Dt GETENV 3 +.Os +.Sh NAME +.Nm getenv , +.Nm putenv , +.Nm setenv , +.Nm unsetenv +.Nd environment variable functions +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In stdlib.h +.Ft char * +.Fn getenv "const char *name" +.Ft int +.Fn setenv "const char *name" "const char *value" "int overwrite" +.Ft int +.Fn putenv "const char *string" +.Ft void +.Fn unsetenv "const char *name" +.Sh DESCRIPTION +These functions set, unset and fetch environment variables from the +host +.Em environment list . +For compatibility with differing environment conventions, +the given arguments +.Ar name +and +.Ar value +may be appended and prepended, +respectively, +with an equal sign +.Dq Li \&= . +.Pp +The +.Fn getenv +function obtains the current value of the environment variable, +.Ar name . +If the variable +.Ar name +is not in the current environment, +a null pointer is returned. +.Pp +The +.Fn setenv +function inserts or resets the environment variable +.Ar name +in the current environment list. +If the variable +.Ar name +does not exist in the list, +it is inserted with the given +.Ar value . +If the variable does exist, the argument +.Ar overwrite +is tested; if +.Ar overwrite is +zero, the +variable is not reset, otherwise it is reset +to the given +.Ar value . +.Pp +The +.Fn putenv +function takes an argument of the form ``name=value'' and is +equivalent to: +.Bd -literal -offset indent +setenv(name, value, 1); +.Ed +.Pp +The +.Fn unsetenv +function +deletes all instances of the variable name pointed to by +.Fa name +from the list. +.Sh RETURN VALUES +.Rv -std setenv putenv +.Sh ERRORS +.Bl -tag -width Er +.It Bq Er ENOMEM +The function +.Fn setenv +or +.Fn putenv +failed because they were unable to allocate memory for the environment. +.El +.Sh SEE ALSO +.Xr csh 1 , +.Xr sh 1 , +.Xr execve 2 , +.Xr environ 7 +.Sh STANDARDS +The +.Fn getenv +function conforms to +.St -isoC . +.Sh BUGS +Successive calls to +.Fn setenv +or +.Fn putenv +assigning a differently sized +.Ar value +to the same +.Ar name +will result in a memory leak. The +.Fx +semantics for these functions +(namely, that the contents of +.Ar value +are copied and that old values remain accessible indefinitely) make this +bug unavoidable. Future versions may eliminate one or both of these +semantic guarantees in order to fix the bug. +.Sh HISTORY +The functions +.Fn setenv +and +.Fn unsetenv +appeared in +.At v7 . +The +.Fn putenv +function appeared in +.Bx 4.3 Reno . diff --git a/stdlib/getenv.c b/stdlib/getenv.c new file mode 100644 index 0000000..51d9073 --- /dev/null +++ b/stdlib/getenv.c @@ -0,0 +1,108 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1987, 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 +#include +#include + +#include + +char *__findenv __P((const char *, int *)); + +/* + * getenv -- + * Returns ptr to value associated with name, if any, else NULL. + */ +char * +getenv(name) + const char *name; +{ + int offset; + + return (__findenv(name, &offset)); +} + +/* + * __findenv -- + * Returns pointer to value associated with name, if any, else NULL. + * Sets offset to be the offset of the name/value combination in the + * environmental array, for use by setenv(3) and unsetenv(3). + * Explicitly removes '=' in argument name. + * + * This routine *should* be a static; don't use it. + */ +char * +__findenv(name, offset) + register const char *name; + int *offset; +{ + register int len; + register const char *np; + register char **p, *c; + + char **environ = *_NSGetEnviron(); + + if (name == NULL || environ == NULL) + return (NULL); + for (np = name; *np && *np != '='; ++np) + continue; + len = np - name; + for (p = environ; (c = *p) != NULL; ++p) + if (strncmp(c, name, len) == 0 && c[len] == '=') { + *offset = p - environ; + return (c + len + 1); + } + return (NULL); +} diff --git a/stdlib/getopt.3 b/stdlib/getopt.3 new file mode 100644 index 0000000..7b08faf --- /dev/null +++ b/stdlib/getopt.3 @@ -0,0 +1,266 @@ +.\" Copyright (c) 1988, 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. +.\" +.\" @(#)getopt.3 8.5 (Berkeley) 4/27/95 +.\" $FreeBSD: src/lib/libc/stdlib/getopt.3,v 1.20 2001/09/07 14:46:35 asmodai Exp $ +.\" +.Dd April 27, 1995 +.Dt GETOPT 3 +.Os +.Sh NAME +.Nm getopt +.Nd get option character from command line argument list +.Sh LIBRARY +.Lb libc +.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 ; +.Ft int +.Fn getopt "int argc" "char * const *argv" "const char *optstring" +.Sh DESCRIPTION +The +.Fn getopt +function incrementally parses a command line argument list +.Fa argv +and returns the next +.Em known +option character. +An option character is +.Em known +if it has been specified in the string of accepted option characters, +.Fa optstring . +.Pp +The option string +.Fa optstring +may contain the following elements: individual characters, and +characters followed by a colon to indicate an option argument +is to follow. +For example, an option string +.Li "\&""x"" +recognizes an option +.Dq Fl x , +and an option string +.Li "\&""x:"" +recognizes an option and argument +.Dq Fl x Ar argument . +It does not matter to +.Fn getopt +if a following argument has leading white space. +.Pp +On return from +.Fn getopt , +.Va optarg +points to an option argument, if it is anticipated, +and the variable +.Va optind +contains the index to the next +.Fa argv +argument for a subsequent call +to +.Fn getopt . +The variable +.Va optopt +saves the last +.Em known +option character returned by +.Fn getopt . +.Pp +The variable +.Va opterr +and +.Va optind +are both initialized to 1. +The +.Va optind +variable may be set to another value before a set of calls to +.Fn getopt +in order to skip over more or less argv entries. +.Pp +In order to use +.Fn getopt +to evaluate multiple sets of arguments, or to evaluate a single set of +arguments multiple times, +the variable +.Va optreset +must be set to 1 before the second and each additional set of calls to +.Fn getopt , +and the variable +.Va optind +must be reinitialized. +.Pp +The +.Fn getopt +function +returns \-1 +when the argument list is exhausted, or +.Ql ?\& +if a non-recognized +option is encountered. +The interpretation of options in the argument list may be cancelled +by the option +.Ql -- +(double dash) which causes +.Fn getopt +to signal the end of argument processing and return \-1. +When all options have been processed (i.e., up to the first non-option +argument), +.Fn getopt +returns \-1. +.Sh DIAGNOSTICS +If the +.Fn getopt +function encounters a character not found in the string +.Va optstring +or detects +a missing option argument it writes an error message to the +.Em stderr +and returns +.Ql ?\& . +Setting +.Va opterr +to a zero will disable these error messages. +If +.Va optstring +has a leading +.Ql \&: +then a missing option argument causes a +.Ql \&: +to be returned in addition to suppressing any error messages. +.Pp +Option arguments are allowed to begin with +.Dq Li \- ; +this is reasonable but +reduces the amount of error checking possible. +.Sh EXTENSIONS +The +.Va optreset +variable was added to make it possible to call the +.Fn getopt +function multiple times. +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 +function appeared in +.Bx 4.3 . +.Sh BUGS +The +.Fn getopt +function was once specified to return +.Dv EOF +instead of \-1. +This was changed by +.St -p1003.2-92 +to decouple +.Fn getopt +from +.Pa . +.Pp +A single dash +.Dq Li - +may be specified as a character in +.Fa optstring , +however it should +.Em never +have an argument associated with it. +This allows +.Fn getopt +to be used with programs that expect +.Dq Li - +as an option flag. +This practice is wrong, and should not be used in any current development. +It is provided for backward compatibility +.Em only . +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 +.Fn getopt +to be used with programs that expect a number +.Pq Dq Li \&-\&3 +as an option. +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. +.Bd -literal -offset indent +int length; +char *p, *ep; + +while ((ch = getopt(argc, argv, "0123456789")) != -1) + switch (ch) { + 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) { + length = strtol((p = argv[optind] + 1), + &ep, 10); + optind++; + optreset = 1; + } else + usage(); + if (*ep != '\0') + errx(EX_USAGE, "illegal number -- %s", p); + break; + } +.Ed diff --git a/stdlib/getopt.c b/stdlib/getopt.c new file mode 100644 index 0000000..d5075b7 --- /dev/null +++ b/stdlib/getopt.c @@ -0,0 +1,137 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1987, 1993, 1994 + * 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 +#include +#include + +#include + +int opterr = 1, /* if error message should be printed */ + optind = 1, /* index into parent argv vector */ + optopt, /* character checked for validity */ + optreset; /* reset getopt */ +char *optarg; /* argument associated with option */ + +#define BADCH (int)'?' +#define BADARG (int)':' +#define EMSG "" + +/* + * getopt -- + * Parse argc/argv argument vector. + */ +int +getopt(nargc, nargv, ostr) + int nargc; + char * const *nargv; + const char *ostr; +{ + char *__progname = *(*_NSGetArgv()); + static char *place = EMSG; /* option letter processing */ + char *oli; /* option letter list index */ + + if (optreset || !*place) { /* update scanning pointer */ + optreset = 0; + if (optind >= nargc || *(place = nargv[optind]) != '-') { + place = EMSG; + return (EOF); + } + if (place[1] && *++place == '-') { /* found "--" */ + ++optind; + place = EMSG; + return (EOF); + } + } /* option letter okay? */ + if ((optopt = (int)*place++) == (int)':' || + !(oli = strchr(ostr, optopt))) { + /* + * if the user didn't specify '-' as an option, + * assume it means EOF. + */ + if (optopt == (int)'-') + return (EOF); + if (!*place) + ++optind; + if (opterr && *ostr != ':') + (void)fprintf(stderr, + "%s: illegal option -- %c\n", __progname, optopt); + return (BADCH); + } + if (*++oli != ':') { /* don't need argument */ + optarg = NULL; + if (!*place) + ++optind; + } + else { /* need an argument */ + if (*place) /* no white space */ + optarg = place; + else if (nargc <= ++optind) { /* no arg */ + place = EMSG; + if (*ostr == ':') + return (BADARG); + if (opterr) + (void)fprintf(stderr, + "%s: option requires an argument -- %c\n", + __progname, optopt); + return (BADCH); + } + else /* white space */ + optarg = nargv[optind]; + place = EMSG; + ++optind; + } + return (optopt); /* dump back option letter */ +} diff --git a/stdlib/getsubopt.3 b/stdlib/getsubopt.3 new file mode 100644 index 0000000..83c5f7c --- /dev/null +++ b/stdlib/getsubopt.3 @@ -0,0 +1,149 @@ +.\" Copyright (c) 1990, 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. +.\" +.\" @(#)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 $ +.\" +.Dd June 9, 1993 +.Dt GETSUBOPT 3 +.Os +.Sh NAME +.Nm getsubopt +.Nd get sub options from an argument +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In unistd.h +.Vt extern char *suboptarg ; +.Ft int +.Fn getsubopt "char **optionp" "char * const *tokens" "char **valuep" +.Sh DESCRIPTION +The +.Fn getsubopt +function +parses a string containing tokens delimited by one or more tab, space or +comma +.Pq Ql \&, +characters. +It is intended for use in parsing groups of option arguments provided +as part of a utility command line. +.Pp +The argument +.Fa optionp +is a pointer to a pointer to the string. +The argument +.Fa tokens +is a pointer to a +.Dv NULL Ns -terminated +array of pointers to strings. +.Pp +The +.Fn getsubopt +function +returns the zero-based offset of the pointer in the +.Fa tokens +array referencing a string which matches the first token +in the string, or, \-1 if the string contains no tokens or +.Fa tokens +does not contain a matching string. +.Pp +If the token is of the form ``name=value'', the location referenced by +.Fa valuep +will be set to point to the start of the ``value'' portion of the token. +.Pp +On return from +.Fn getsubopt , +.Fa optionp +will be set to point to the start of the next token in the string, +or the null at the end of the string if no more tokens are present. +The external variable +.Fa suboptarg +will be set to point to the start of the current token, or +.Dv NULL +if no +tokens were present. +The argument +.Fa valuep +will be set to point to the ``value'' portion of the token, or +.Dv NULL +if no ``value'' portion was present. +.Sh EXAMPLES +.Bd -literal -compact +char *tokens[] = { + #define ONE 0 + "one", + #define TWO 1 + "two", + NULL +}; + +\&... + +extern char *optarg, *suboptarg; +char *options, *value; + +while ((ch = getopt(argc, argv, "ab:")) != \-1) { + switch(ch) { + case 'a': + /* process ``a'' option */ + break; + case 'b': + options = optarg; + while (*options) { + switch(getsubopt(&options, tokens, &value)) { + case ONE: + /* process ``one'' sub option */ + break; + case TWO: + /* process ``two'' sub option */ + if (!value) + error("no value for two"); + i = atoi(value); + break; + case \-1: + if (suboptarg) + error("illegal sub option %s", + suboptarg); + else + error("missing sub option"); + break; + } + break; + } +.Ed +.Sh SEE ALSO +.Xr getopt 3 , +.Xr strsep 3 +.Sh HISTORY +The +.Fn getsubopt +function first appeared in +.Bx 4.4 . diff --git a/stdlib/getsubopt.c b/stdlib/getsubopt.c new file mode 100644 index 0000000..d4d6813 --- /dev/null +++ b/stdlib/getsubopt.c @@ -0,0 +1,116 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 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 +#include + +/* + * The SVID interface to getsubopt provides no way of figuring out which + * part of the suboptions list wasn't matched. This makes error messages + * tricky... The extern variable suboptarg is a pointer to the token + * which didn't match. + */ +char *suboptarg; + +getsubopt(optionp, tokens, valuep) + register char **optionp, **valuep; + register char * const *tokens; +{ + register int cnt; + register char *p; + + suboptarg = *valuep = NULL; + + if (!optionp || !*optionp) + return(-1); + + /* skip leading white-space, commas */ + for (p = *optionp; *p && (*p == ',' || *p == ' ' || *p == '\t'); ++p); + + if (!*p) { + *optionp = p; + return(-1); + } + + /* save the start of the token, and skip the rest of the token. */ + for (suboptarg = p; + *++p && *p != ',' && *p != '=' && *p != ' ' && *p != '\t';); + + if (*p) { + /* + * If there's an equals sign, set the value pointer, and + * skip over the value part of the token. Terminate the + * token. + */ + if (*p == '=') { + *p = '\0'; + for (*valuep = ++p; + *p && *p != ',' && *p != ' ' && *p != '\t'; ++p); + if (*p) + *p++ = '\0'; + } else + *p++ = '\0'; + /* Skip any whitespace or commas after this token. */ + for (; *p && (*p == ',' || *p == ' ' || *p == '\t'); ++p); + } + + /* set optionp for next round. */ + *optionp = p; + + for (cnt = 0; *tokens; ++tokens, ++cnt) + if (!strcmp(suboptarg, *tokens)) + return(cnt); + return(-1); +} diff --git a/stdlib/hcreate.3 b/stdlib/hcreate.3 new file mode 100644 index 0000000..1619c98 --- /dev/null +++ b/stdlib/hcreate.3 @@ -0,0 +1,206 @@ +.\" $FreeBSD: src/lib/libc/stdlib/hcreate.3,v 1.2 2001/07/09 15:54:36 ru Exp $ +.\" +.Dd May 8, 2001 +.Os +.Dt HCREATE 3 +.Sh NAME +.Nm hcreate , hdestroy , hsearch +.Nd manage hash search table +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In search.h +.Ft int +.Fn hcreate "size_t nel" +.Ft void +.Fn hdestroy void +.Ft ENTRY * +.Fn hsearch "ENTRY item" "ACTION action" +.Sh DESCRIPTION +The +.Fn hcreate , +.Fn hdestroy , +and +.Fn hsearch +functions manage hash search tables. +.Pp +The +.Fn hcreate +function allocates sufficient space for the table, and the application should +ensure it is called before +.Fn hsearch +is used. +The +.Fa nel +argument is an estimate of the maximum +number of entries that the table should contain. +This number may be adjusted upward by the +algorithm in order to obtain certain mathematically favorable circumstances. +.Pp +The +.Fn hdestroy +function disposes of the search table, and may be followed by another call to +.Fn hcreate . +After the call to +.Fn hdestroy , +the data can no longer be considered accessible. +.Pp +The +.Fn hsearch +function is a hash-table search routine. +It returns a pointer into a hash table +indicating the location at which an entry can be found. +The +.Fa item +argument is a structure of type +.Vt ENTRY +(defined in the +.Aq Pa search.h +header) containing two pointers: +.Fa item.key +points to the comparison key (a +.Vt "char *" ) , +and +.Fa item.data +(a +.Vt "void *" ) +points to any other data to be associated with +that key. +The comparison function used by +.Fn hsearch +is +.Xr strcmp 3 . +The +.Fa action +argument is a +member of an enumeration type +.Vt ACTION +indicating the disposition of the entry if it cannot be +found in the table. +.Dv ENTER +indicates that the +.Fa item +should be inserted in the table at an +appropriate point. +.Dv FIND +indicates that no entry should be made. +Unsuccessful resolution is +indicated by the return of a +.Dv NULL +pointer. +.Sh RETURN VALUES +The +.Fn hcreate +function returns 0 if it cannot allocate sufficient space for the table; +otherwise, it returns non-zero. +.Pp +The +.Fn hdestroy +function does not return a value. +.Pp +The +.Fn hsearch +function returns a +.Dv NULL +pointer if either the +.Fa action +is +.Dv FIND +and the +.Fa item +could not be found or the +.Fa action +is +.Dv ENTER +and the table is full. +.Sh ERRORS +The +.Fn hcreate +and +.Fn hsearch +functions may fail if: +.Bl -tag -width Er +.It Bq Er ENOMEM +Insufficient storage space is available. +.El +.Sh EXAMPLES +The following example reads in strings followed by two numbers +and stores them in a hash table, discarding duplicates. +It then reads in strings and finds the matching entry in the hash +table and prints it out. +.Bd -literal +#include +#include +#include + +struct info { /* This is the info stored in the table */ + int age, room; /* other than the key. */ +}; + +#define NUM_EMPL 5000 /* # of elements in search table. */ + +int +main(void) +{ + char string_space[NUM_EMPL*20]; /* Space to store strings. */ + struct info info_space[NUM_EMPL]; /* Space to store employee info. */ + char *str_ptr = string_space; /* Next space in string_space. */ + struct info *info_ptr = info_space; /* Next space in info_space. */ + ENTRY item; + ENTRY *found_item; /* Name to look for in table. */ + char name_to_find[30]; + int i = 0; + + /* Create table; no error checking is performed. */ + (void) hcreate(NUM_EMPL); + + while (scanf("%s%d%d", str_ptr, &info_ptr->age, + &info_ptr->room) != EOF && i++ < NUM_EMPL) { + /* Put information in structure, and structure in item. */ + item.key = str_ptr; + item.data = info_ptr; + str_ptr += strlen(str_ptr) + 1; + info_ptr++; + /* Put item into table. */ + (void) hsearch(item, ENTER); + } + + /* Access table. */ + item.key = name_to_find; + while (scanf("%s", item.key) != EOF) { + if ((found_item = hsearch(item, FIND)) != NULL) { + /* If item is in the table. */ + (void)printf("found %s, age = %d, room = %d\en", + found_item->key, + ((struct info *)found_item->data)->age, + ((struct info *)found_item->data)->room); + } else + (void)printf("no such employee %s\en", name_to_find); + } + return 0; +} +.Ed +.Sh SEE ALSO +.Xr bsearch 3 , +.Xr lsearch 3 , +.Xr malloc 3 , +.Xr strcmp 3 , +.Xr tsearch 3 +.Sh STANDARDS +The +.Fn hcreate , +.Fn hdestroy , +and +.Fn hsearch +functions conform to +.St -xpg4.2 . +.Sh HISTORY +The +.Fn hcreate , +.Fn hdestroy , +and +.Fn hsearch +functions first appeared in +.At V . +.Sh BUGS +The interface permits the use of only one hash table at a time. diff --git a/stdlib/heapsort.c b/stdlib/heapsort.c new file mode 100644 index 0000000..0b8b1be --- /dev/null +++ b/stdlib/heapsort.c @@ -0,0 +1,202 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1991, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Ronnie Kon at Mindcraft Inc., Kevin Lew and Elmer Yglesias. + * + * 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 +#include +#include +#include + +/* + * Swap two areas of size number of bytes. Although qsort(3) permits random + * blocks of memory to be sorted, sorting pointers is almost certainly the + * common case (and, were it not, could easily be made so). Regardless, it + * isn't worth optimizing; the SWAP's get sped up by the cache, and pointer + * arithmetic gets lost in the time required for comparison function calls. + */ +#define SWAP(a, b, count, size, tmp) { \ + count = size; \ + do { \ + tmp = *a; \ + *a++ = *b; \ + *b++ = tmp; \ + } while (--count); \ +} + +/* Copy one block of size size to another. */ +#define COPY(a, b, count, size, tmp1, tmp2) { \ + count = size; \ + tmp1 = a; \ + tmp2 = b; \ + do { \ + *tmp1++ = *tmp2++; \ + } while (--count); \ +} + +/* + * Build the list into a heap, where a heap is defined such that for + * the records K1 ... KN, Kj/2 >= Kj for 1 <= j/2 <= j <= N. + * + * There two cases. If j == nmemb, select largest of Ki and Kj. If + * j < nmemb, select largest of Ki, Kj and Kj+1. + */ +#define CREATE(initval, nmemb, par_i, child_i, par, child, size, count, tmp) { \ + for (par_i = initval; (child_i = par_i * 2) <= nmemb; \ + par_i = child_i) { \ + child = base + child_i * size; \ + if (child_i < nmemb && compar(child, child + size) < 0) { \ + child += size; \ + ++child_i; \ + } \ + par = base + par_i * size; \ + if (compar(child, par) <= 0) \ + break; \ + SWAP(par, child, count, size, tmp); \ + } \ +} + +/* + * Select the top of the heap and 'heapify'. Since by far the most expensive + * action is the call to the compar function, a considerable optimization + * in the average case can be achieved due to the fact that k, the displaced + * elememt, is ususally quite small, so it would be preferable to first + * heapify, always maintaining the invariant that the larger child is copied + * over its parent's record. + * + * Then, starting from the *bottom* of the heap, finding k's correct place, + * again maintianing the invariant. As a result of the invariant no element + * is 'lost' when k is assigned its correct place in the heap. + * + * The time savings from this optimization are on the order of 15-20% for the + * average case. See Knuth, Vol. 3, page 158, problem 18. + * + * XXX Don't break the #define SELECT line, below. Reiser cpp gets upset. + */ +#define SELECT(par_i, child_i, nmemb, par, child, size, k, count, tmp1, tmp2) { \ + for (par_i = 1; (child_i = par_i * 2) <= nmemb; par_i = child_i) { \ + child = base + child_i * size; \ + if (child_i < nmemb && compar(child, child + size) < 0) { \ + child += size; \ + ++child_i; \ + } \ + par = base + par_i * size; \ + COPY(par, child, count, size, tmp1, tmp2); \ + } \ + for (;;) { \ + child_i = par_i; \ + par_i = child_i / 2; \ + child = base + child_i * size; \ + par = base + par_i * size; \ + if (child_i == 1 || compar(k, par) < 0) { \ + COPY(child, k, count, size, tmp1, tmp2); \ + break; \ + } \ + COPY(child, par, count, size, tmp1, tmp2); \ + } \ +} + +/* + * Heapsort -- Knuth, Vol. 3, page 145. Runs in O (N lg N), both average + * and worst. While heapsort is faster than the worst case of quicksort, + * the BSD quicksort does median selection so that the chance of finding + * a data set that will trigger the worst case is nonexistent. Heapsort's + * only advantage over quicksort is that it requires little additional memory. + */ +int +heapsort(vbase, nmemb, size, compar) + void *vbase; + size_t nmemb, size; + int (*compar) __P((const void *, const void *)); +{ + register int cnt, i, j, l; + register char tmp, *tmp1, *tmp2; + char *base, *k, *p, *t; + + if (nmemb <= 1) + return (0); + + if (!size) { + errno = EINVAL; + return (-1); + } + + if ((k = malloc(size)) == NULL) + return (-1); + + /* + * Items are numbered from 1 to nmemb, so offset from size bytes + * below the starting address. + */ + base = (char *)vbase - size; + + for (l = nmemb / 2 + 1; --l;) + CREATE(l, nmemb, i, j, t, p, size, cnt, tmp); + + /* + * For each element of the heap, save the largest element into its + * final slot, save the displaced element (k), then recreate the + * heap. + */ + while (nmemb > 1) { + COPY(k, base + nmemb * size, cnt, size, tmp1, tmp2); + COPY(base + nmemb * size, base + size, cnt, size, tmp1, tmp2); + --nmemb; + SELECT(i, j, nmemb, t, p, size, k, cnt, tmp1, tmp2); + } + free(k); + return (0); +} diff --git a/stdlib/l64a.c b/stdlib/l64a.c new file mode 100644 index 0000000..c666bc6 --- /dev/null +++ b/stdlib/l64a.c @@ -0,0 +1,47 @@ +/* + * Written by J.T. Conklin . + * Public domain. + */ + +#if defined(LIBC_SCCS) && !defined(lint) +static char *rcsid = "$OpenBSD: l64a.c,v 1.3 1997/08/17 22:58:34 millert Exp $"; +#endif /* LIBC_SCCS and not lint */ + +#include +#include + +char * +l64a(value) + long value; +{ + static char buf[8]; + char *s = buf; + int digit; + int i; + + if (value < 0) { + errno = EINVAL; + return(NULL); + } + + for (i = 0; value != 0 && i < 6; i++) { + digit = value & 0x3f; + + if (digit < 2) + *s = digit + '.'; + else if (digit < 12) + *s = digit + '0' - 2; + else if (digit < 38) + *s = digit + 'A' - 12; + else + *s = digit + 'a' - 38; + + value >>= 6; + s++; + } + + *s = '\0'; + + return(buf); +} + diff --git a/stdlib/labs.3 b/stdlib/labs.3 new file mode 100644 index 0000000..8cd757f --- /dev/null +++ b/stdlib/labs.3 @@ -0,0 +1,69 @@ +.\" 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. +.\" +.\" @(#)labs.3 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD: src/lib/libc/stdlib/labs.3,v 1.7 2001/09/07 14:46:35 asmodai Exp $ +.\" +.Dd June 4, 1993 +.Dt LABS 3 +.Os +.Sh NAME +.Nm labs +.Nd return the absolute value of a long integer +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In stdlib.h +.Ft long +.Fn labs "long j" +.Sh DESCRIPTION +The +.Fn labs +function +returns the absolute value of the long integer +.Ar j . +.Sh SEE ALSO +.Xr abs 3 , +.Xr cabs 3 , +.Xr floor 3 , +.Xr math 3 +.Sh STANDARDS +The +.Fn labs +function +conforms to +.St -isoC . +.Sh BUGS +The absolute value of the most negative integer remains negative. diff --git a/stdlib/labs.c b/stdlib/labs.c new file mode 100644 index 0000000..5267e5d --- /dev/null +++ b/stdlib/labs.c @@ -0,0 +1,66 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 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[] = "@(#)labs.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ + +#include + +long +labs(j) + long j; +{ + return(j < 0 ? -j : j); +} diff --git a/stdlib/ldiv.3 b/stdlib/ldiv.3 new file mode 100644 index 0000000..c9f168e --- /dev/null +++ b/stdlib/ldiv.3 @@ -0,0 +1,73 @@ +.\" 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. +.\" +.\" @(#)ldiv.3 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD: src/lib/libc/stdlib/ldiv.3,v 1.7 2001/09/07 14:46:35 asmodai Exp $ +.\" +.Dd June 4, 1993 +.Dt LDIV 3 +.Os +.Sh NAME +.Nm ldiv +.Nd return quotient and remainder from division +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In stdlib.h +.Ft ldiv_t +.Fn ldiv "long num" "long denom" +.Sh DESCRIPTION +The +.Fn ldiv +function +computes the value +.Ar num/denom +and returns the quotient and remainder in a structure named +.Ar ldiv_t +that contains two +.Em long integer +members named +.Ar quot +and +.Ar rem . +.Sh SEE ALSO +.Xr div 3 , +.Xr math 3 +.Sh STANDARDS +The +.Fn ldiv +function +conforms to +.St -isoC . diff --git a/stdlib/ldiv.c b/stdlib/ldiv.c new file mode 100644 index 0000000..83f63e4 --- /dev/null +++ b/stdlib/ldiv.c @@ -0,0 +1,76 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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 /* ldiv_t */ + +ldiv_t +ldiv(num, denom) + long num, denom; +{ + ldiv_t r; + + /* see div.c for comments */ + + r.quot = num / denom; + r.rem = num % denom; + if (num >= 0 && r.rem < 0) { + r.quot++; + r.rem -= denom; + } + return (r); +} diff --git a/stdlib/malloc.3 b/stdlib/malloc.3 new file mode 100644 index 0000000..76af046 --- /dev/null +++ b/stdlib/malloc.3 @@ -0,0 +1,483 @@ +.\" Copyright (c) 1980, 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. +.\" +.\" @(#)malloc.3 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD: src/lib/libc/stdlib/malloc.3,v 1.49 2001/11/05 00:39:27 dd Exp $ +.\" +.Dd August 27, 1996 +.Dt MALLOC 3 +.Os +.Sh NAME +.Nm malloc , calloc , realloc , free , reallocf +.Nd general purpose memory allocation functions +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In stdlib.h +.Ft void * +.Fn malloc "size_t size" +.Ft void * +.Fn calloc "size_t number" "size_t size" +.Ft void * +.Fn realloc "void *ptr" "size_t size" +.Ft void * +.Fn reallocf "void *ptr" "size_t size" +.Ft void +.Fn free "void *ptr" +.Ft char * +.Va _malloc_options +.Ft void +.Fn \*(lp*_malloc_message\*(rp "char *p1" "char *p2" "char *p3" "char *p4" +.Sh DESCRIPTION +The +.Fn malloc +function allocates +.Fa size +bytes of memory. +The allocated space is suitably aligned (after possible pointer coercion) +for storage of any type of object. +If the space is at least +.Em pagesize +bytes in length (see +.Xr getpagesize 3 ) , +the returned memory will be page boundary aligned as well. +If +.Fn malloc +fails, a +.Dv NULL +pointer is returned. +.Pp +Note that +.Fn malloc +does +.Em NOT +normally initialize the returned memory to zero bytes. +.Pp +The +.Fn calloc +function allocates space for +.Fa number +objects, +each +.Fa size +bytes in length. +The result is identical to calling +.Fn malloc +with an argument of +.Dq "number * size" , +with the exception that the allocated memory is explicitly initialized +to zero bytes. +.Pp +The +.Fn realloc +function changes the size of the previously allocated memory referenced by +.Fa ptr +to +.Fa size +bytes. +The contents of the memory are unchanged up to the lesser of the new and +old sizes. +If the new size is larger, +the value of the newly allocated portion of the memory is undefined. +If the requested memory cannot be allocated, +.Dv NULL +is returned and +the memory referenced by +.Fa ptr +is valid and unchanged. +If +.Fa ptr +is +.Dv NULL , +the +.Fn realloc +function behaves identically to +.Fn malloc +for the specified size. +.Pp +The +.Fn reallocf +function call is identical to the realloc function call, except that it +will free the passed pointer when the requested memory cannot be allocated. +This is a +.Fx +specific API designed to ease the problems with traditional coding styles +for realloc causing memory leaks in libraries. +.Pp +The +.Fn free +function causes the allocated memory referenced by +.Fa ptr +to be made available for future allocations. +If +.Fa ptr +is +.Dv NULL , +no action occurs. +.Sh TUNING +Once, when the first call is made to one of these memory allocation +routines, various flags will be set or reset, which affect the +workings of this allocation implementation. +.Pp +The ``name'' of the file referenced by the symbolic link named +.Pa /etc/malloc.conf , +the value of the environment variable +.Ev MALLOC_OPTIONS , +and the string pointed to by the global variable +.Va _malloc_options +will be interpreted, in that order, character by character as flags. +.Pp +Most flags are single letters, +where uppercase indicates that the behavior is set, or on, +and lowercase means that the behavior is not set, or off. +.Bl -tag -width indent +.It A +All warnings (except for the warning about unknown +flags being set) become fatal. +The process will call +.Xr abort 3 +in these cases. +.It J +Each byte of new memory allocated by +.Fn malloc , +.Fn realloc +or +.Fn reallocf +as well as all memory returned by +.Fn free , +.Fn realloc +or +.Fn reallocf +will be initialized to 0xd0. +This options also sets the +.Dq R +option. +This is intended for debugging and will impact performance negatively. +.It H +Pass a hint to the kernel about pages unused by the allocation functions. +This will help performance if the system is paging excessively. This +option is off by default. +.It R +Causes the +.Fn realloc +and +.Fn reallocf +functions to always reallocate memory even if the initial allocation was +sufficiently large. +This can substantially aid in compacting memory. +.It U +Generate +.Dq utrace +entries for +.Xr ktrace 1 , +for all operations. +Consult the source for details on this option. +.It V +Attempting to allocate zero bytes will return a +.Dv NULL +pointer instead of +a valid pointer. +(The default behavior is to make a minimal allocation and return a +pointer to it.) +This option is provided for System V compatibility. +This option is incompatible with the +.Dq X +option. +.It X +Rather than return failure for any allocation function, +display a diagnostic message on stderr and cause the program to drop +core (using +.Xr abort 3 ) . +This option should be set at compile time by including the following in +the source code: +.Bd -literal -offset indent +_malloc_options = "X"; +.Ed +.It Z +This option implicitly sets the +.Dq J +and +.Dq R +options, and then zeros out the bytes that were requested. +This is intended for debugging and will impact performance negatively. +.It < +Reduce the size of the cache by a factor of two. +The default cache size is 16 pages. +This option can be specified multiple times. +.It > +Double the size of the cache by a factor of two. +The default cache size is 16 pages. +This option can be specified multiple times. +.El +.Pp +The +.Dq J +and +.Dq Z +options are intended for testing and debugging. +An application which changes its behavior when these options are used +is flawed. +.Sh EXAMPLES +To set a systemwide reduction of cache size, and to dump core whenever +a problem occurs: +.Pp +.Bd -literal -offset indent +ln -s 'A<' /etc/malloc.conf +.Ed +.Pp +To specify in the source that a program does no return value checking +on calls to these functions: +.Bd -literal -offset indent +_malloc_options = "X"; +.Ed +.Sh ENVIRONMENT +The following environment variables affect the execution of the allocation +functions: +.Bl -tag -width ".Ev MALLOC_OPTIONS" +.It Ev MALLOC_OPTIONS +If the environment variable +.Ev MALLOC_OPTIONS +is set, the characters it contains will be interpreted as flags to the +allocation functions. +.El +.Sh RETURN VALUES +The +.Fn malloc +and +.Fn calloc +functions return a pointer to the allocated memory if successful; otherwise +a +.Dv NULL +pointer is returned and +.Va errno +is set to +.Er ENOMEM . +.Pp +The +.Fn realloc +and +.Fn reallocf +functions return a pointer, possibly identical to +.Fa ptr , +to the allocated memory +if successful; otherwise a +.Dv NULL +pointer is returned, in which case the +memory referenced by +.Fa ptr +is still available and intact. +In the case of memory allocation failure, +.Va errno +is set to +.Er ENOMEM . +.Pp +The +.Fn free +function returns no value. +.Sh DEBUGGING MALLOC PROBLEMS +The major difference between this implementation and other allocation +implementations is that the free pages are not accessed unless allocated, +and are aggressively returned to the kernel for reuse. +.Bd -ragged -offset indent +Most allocation implementations will store a data structure containing a +linked list in the free chunks of memory, +used to tie all the free memory together. +That can be suboptimal, +as every time the free-list is traversed, +the otherwise unused, and likely paged out, +pages are faulted into primary memory. +On systems which are paging, +this can result in a factor of five increase in the number of page-faults +done by a process. +.Ed +.Pp +A side effect of this architecture is that many minor transgressions on +the interface which would traditionally not be detected are in fact +detected. As a result, programs that have been running happily for +years may suddenly start to complain loudly, when linked with this +allocation implementation. +.Pp +The first and most important thing to do is to set the +.Dq A +option. +This option forces a coredump (if possible) at the first sign of trouble, +rather than the normal policy of trying to continue if at all possible. +.Pp +It is probably also a good idea to recompile the program with suitable +options and symbols for debugger support. +.Pp +If the program starts to give unusual results, coredump or generally behave +differently without emitting any of the messages listed in the next +section, it is likely because it depends on the storage being filled with +zero bytes. Try running it with +.Dq Z +option set; +if that improves the situation, this diagnosis has been confirmed. +If the program still misbehaves, +the likely problem is accessing memory outside the allocated area, +more likely after than before the allocated area. +.Pp +Alternatively, if the symptoms are not easy to reproduce, setting the +.Dq J +option may help provoke the problem. +.Pp +In truly difficult cases, the +.Dq U +option, if supported by the kernel, can provide a detailed trace of +all calls made to these functions. +.Pp +Unfortunately this implementation does not provide much detail about +the problems it detects, the performance impact for storing such information +would be prohibitive. +There are a number of allocation implementations available on the 'Net +which focus on detecting and pinpointing problems by trading performance +for extra sanity checks and detailed diagnostics. +.Sh DIAGNOSTIC MESSAGES +If +.Fn malloc , +.Fn calloc , +.Fn realloc +or +.Fn free +detect an error or warning condition, +a message will be printed to file descriptor STDERR_FILENO. +Errors will result in the process dumping core. +If the +.Dq A +option is set, all warnings are treated as errors. +.Pp +The +.Va _malloc_message +variable allows the programmer to override the function which emits +the text strings forming the errors and warnings if for some reason +the stderr filedescriptor is not suitable for this. +Please note that doing anything which tries to allocate memory in +this function will assure death of the process. +.Pp +The following is a brief description of possible error messages and +their meanings: +.Pp +.Bl -diag +.It "(ES): mumble mumble mumble" +The allocation functions were compiled with +.Dq EXTRA_SANITY +defined, and an error was found during the additional error checking. +Consult the source code for further information. +.It "mmap(2) failed, check limits" +This most likely means that the system is dangerously overloaded or that +the process' limits are incorrectly specified. +.It "freelist is destroyed" +The internal free-list has been corrupted. +.It "out of memory" +The +.Dq X +option was specified and an allocation of memory failed. +.El +.Pp +The following is a brief description of possible warning messages and +their meanings: +.Bl -diag +.It "chunk/page is already free" +The process attempted to +.Fn free +memory which had already been freed. +.It "junk pointer, ..." +A pointer specified to one of the allocation functions points outside the +bounds of the memory of which they are aware. +.It "malloc() has never been called" +No memory has been allocated, +yet something is being freed or +realloc'ed. +.It "modified (chunk-/page-) pointer" +The pointer passed to +.Fn free +or +.Fn realloc +has been modified. +.It "pointer to wrong page" +The pointer that +.Fn free , +.Fn realloc , +or +.Fn reallocf +is trying to free does not reference a possible page. +.It "recursive call" +A process has attempted to call an allocation function recursively. +This is not permitted. In particular, signal handlers should not +attempt to allocate memory. +.It "unknown char in MALLOC_OPTIONS" +An unknown option was specified. +Even with the +.Dq A +option set, this warning is still only a warning. +.El +.Sh SEE ALSO +.Xr brk 2 , +.Xr mmap 2 , +.Xr alloca 3 , +.Xr getpagesize 3 , +.Xr memory 3 +.Pa /usr/share/doc/papers/malloc.ascii.gz +.Sh STANDARDS +The +.Fn malloc , +.Fn calloc , +.Fn realloc +and +.Fn free +functions conform to +.St -isoC . +.Sh HISTORY +The present allocation implementation started out as a filesystem for a +drum attached to a 20bit binary challenged computer which was built +with discrete germanium transistors. It has since graduated to +handle primary storage rather than secondary. +It first appeared in its new shape and ability in +.Fx 2.2 . +.Pp +The +.Xr reallocf 3 +function first appeared in +.Fx 3.0 . +.Sh AUTHORS +.An Poul-Henning Kamp Aq phk@FreeBSD.org +.Sh BUGS +The messages printed in case of problems provide no detail about the +actual values. +.Pp +It can be argued that returning a +.Dv NULL +pointer when asked to +allocate zero bytes is a silly response to a silly question. diff --git a/stdlib/memory.3 b/stdlib/memory.3 new file mode 100644 index 0000000..25222d4 --- /dev/null +++ b/stdlib/memory.3 @@ -0,0 +1,81 @@ +.\" 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. +.\" +.\" @(#)memory.3 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD: src/lib/libc/stdlib/memory.3,v 1.11 2001/09/07 14:46:35 asmodai Exp $ +.\" +.Dd June 4, 1993 +.Dt MEMORY 3 +.Os +.Sh NAME +.Nm malloc , +.Nm free , +.Nm realloc , +.Nm calloc , +.Nm alloca , +.Nm mmap +.Nd general memory allocation operations +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In stdlib.h +.Ft void * +.Fn malloc "size_t size" +.Ft void +.Fn free "void *ptr" +.Ft void * +.Fn realloc "void *ptr" "size_t size" +.Ft void * +.Fn calloc "size_t nelem" "size_t elsize" +.Ft void * +.Fn alloca "size_t size" +.In sys/types.h +.In sys/mman.h +.Ft void * +.Fn mmap "void * addr" "size_t len" "int prot" "int flags" "int fd" "off_t offset" +.Sh DESCRIPTION +These functions allocate and free memory for the calling process. +They are described in the +individual manual pages. +.Sh SEE ALSO +.Xr mmap 2 , +.Xr alloca 3 , +.Xr calloc 3 , +.Xr free 3 , +.Xr malloc 3 , +.Xr realloc 3 +.Sh STANDARDS +These functions, with the exception of +.Fn alloca +and +.Fn mmap +conform to +.St -isoC . diff --git a/stdlib/merge.c b/stdlib/merge.c new file mode 100644 index 0000000..c71e767 --- /dev/null +++ b/stdlib/merge.c @@ -0,0 +1,365 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Peter McIlroy. + * + * 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. + */ + + +/* + * Hybrid exponential search/linear search merge sort with hybrid + * natural/pairwise first pass. Requires about .3% more comparisons + * for random data than LSMS with pairwise first pass alone. + * It works for objects as small as two bytes. + */ + +#define NATURAL +#define THRESHOLD 16 /* Best choice for natural merge cut-off. */ + +/* #define NATURAL to get hybrid natural merge. + * (The default is pairwise merging.) + */ + +#include + +#include +#include +#include + +static void setup __P((u_char *, u_char *, size_t, size_t, int (*)())); +static void insertionsort __P((u_char *, size_t, size_t, int (*)())); + +#define ISIZE sizeof(int) +#define PSIZE sizeof(u_char *) +#define ICOPY_LIST(src, dst, last) \ + do \ + *(int*)dst = *(int*)src, src += ISIZE, dst += ISIZE; \ + while(src < last) +#define ICOPY_ELT(src, dst, i) \ + do \ + *(int*) dst = *(int*) src, src += ISIZE, dst += ISIZE; \ + while (i -= ISIZE) + +#define CCOPY_LIST(src, dst, last) \ + do \ + *dst++ = *src++; \ + while (src < last) +#define CCOPY_ELT(src, dst, i) \ + do \ + *dst++ = *src++; \ + while (i -= 1) + +/* + * Find the next possible pointer head. (Trickery for forcing an array + * to do double duty as a linked list when objects do not align with word + * boundaries. + */ +/* Assumption: PSIZE is a power of 2. */ +#define EVAL(p) (u_char **) \ + ((u_char *)0 + \ + (((u_char *)p + PSIZE - 1 - (u_char *) 0) & ~(PSIZE - 1))) + +/* + * Arguments are as for qsort. + */ +int +mergesort(base, nmemb, size, cmp) + void *base; + size_t nmemb; + register size_t size; + int (*cmp) __P((const void *, const void *)); +{ + register int i, sense; + int big, iflag; + register u_char *f1, *f2, *t, *b, *tp2, *q, *l1, *l2; + u_char *list2, *list1, *p2, *p, *last, **p1; + + if (size < PSIZE / 2) { /* Pointers must fit into 2 * size. */ + errno = EINVAL; + return (-1); + } + + /* + * XXX + * Stupid subtraction for the Cray. + */ + iflag = 0; + if (!(size % ISIZE) && !(((char *)base - (char *)0) % ISIZE)) + iflag = 1; + + if ((list2 = malloc(nmemb * size + PSIZE)) == NULL) + return (-1); + + list1 = base; + setup(list1, list2, nmemb, size, cmp); + last = list2 + nmemb * size; + i = big = 0; + while (*EVAL(list2) != last) { + l2 = list1; + p1 = EVAL(list1); + for (tp2 = p2 = list2; p2 != last; p1 = EVAL(l2)) { + p2 = *EVAL(p2); + f1 = l2; + f2 = l1 = list1 + (p2 - list2); + if (p2 != last) + p2 = *EVAL(p2); + l2 = list1 + (p2 - list2); + while (f1 < l1 && f2 < l2) { + if ((*cmp)(f1, f2) <= 0) { + q = f2; + b = f1, t = l1; + sense = -1; + } else { + q = f1; + b = f2, t = l2; + sense = 0; + } + if (!big) { /* here i = 0 */ +LINEAR: while ((b += size) < t && cmp(q, b) >sense) + if (++i == 6) { + big = 1; + goto EXPONENTIAL; + } + } else { +EXPONENTIAL: for (i = size; ; i <<= 1) + if ((p = (b + i)) >= t) { + if ((p = t - size) > b && + (*cmp)(q, p) <= sense) + t = p; + else + b = p; + break; + } else if ((*cmp)(q, p) <= sense) { + t = p; + if (i == size) + big = 0; + goto FASTCASE; + } else + b = p; +SLOWCASE: while (t > b+size) { + i = (((t - b) / size) >> 1) * size; + if ((*cmp)(q, p = b + i) <= sense) + t = p; + else + b = p; + } + goto COPY; +FASTCASE: while (i > size) + if ((*cmp)(q, + p = b + (i >>= 1)) <= sense) + t = p; + else + b = p; +COPY: b = t; + } + i = size; + if (q == f1) { + if (iflag) { + ICOPY_LIST(f2, tp2, b); + ICOPY_ELT(f1, tp2, i); + } else { + CCOPY_LIST(f2, tp2, b); + CCOPY_ELT(f1, tp2, i); + } + } else { + if (iflag) { + ICOPY_LIST(f1, tp2, b); + ICOPY_ELT(f2, tp2, i); + } else { + CCOPY_LIST(f1, tp2, b); + CCOPY_ELT(f2, tp2, i); + } + } + } + if (f2 < l2) { + if (iflag) + ICOPY_LIST(f2, tp2, l2); + else + CCOPY_LIST(f2, tp2, l2); + } else if (f1 < l1) { + if (iflag) + ICOPY_LIST(f1, tp2, l1); + else + CCOPY_LIST(f1, tp2, l1); + } + *p1 = l2; + } + tp2 = list1; /* swap list1, list2 */ + list1 = list2; + list2 = tp2; + last = list2 + nmemb*size; + } + if (base == list2) { + memmove(list2, list1, nmemb*size); + list2 = list1; + } + free(list2); + return (0); +} + +#define swap(a, b) { \ + s = b; \ + i = size; \ + do { \ + tmp = *a; *a++ = *s; *s++ = tmp; \ + } while (--i); \ + a -= size; \ + } +#define reverse(bot, top) { \ + s = top; \ + do { \ + i = size; \ + do { \ + tmp = *bot; *bot++ = *s; *s++ = tmp; \ + } while (--i); \ + s -= size2; \ + } while(bot < s); \ +} + +/* + * Optional hybrid natural/pairwise first pass. Eats up list1 in runs of + * increasing order, list2 in a corresponding linked list. Checks for runs + * when THRESHOLD/2 pairs compare with same sense. (Only used when NATURAL + * is defined. Otherwise simple pairwise merging is used.) + */ +void +setup(list1, list2, n, size, cmp) + size_t n, size; + int (*cmp) __P((const void *, const void *)); + u_char *list1, *list2; +{ + int i, length, size2, tmp, sense; + u_char *f1, *f2, *s, *l2, *last, *p2; + + size2 = size*2; + if (n <= 5) { + insertionsort(list1, n, size, cmp); + *EVAL(list2) = (u_char*) list2 + n*size; + return; + } + /* + * Avoid running pointers out of bounds; limit n to evens + * for simplicity. + */ + i = 4 + (n & 1); + insertionsort(list1 + (n - i) * size, i, size, cmp); + last = list1 + size * (n - i); + *EVAL(list2 + (last - list1)) = list2 + n * size; + +#ifdef NATURAL + p2 = list2; + f1 = list1; + sense = (cmp(f1, f1 + size) > 0); + for (; f1 < last; sense = !sense) { + length = 2; + /* Find pairs with same sense. */ + for (f2 = f1 + size2; f2 < last; f2 += size2) { + if ((cmp(f2, f2+ size) > 0) != sense) + break; + length += 2; + } + if (length < THRESHOLD) { /* Pairwise merge */ + do { + p2 = *EVAL(p2) = f1 + size2 - list1 + list2; + if (sense > 0) + swap (f1, f1 + size); + } while ((f1 += size2) < f2); + } else { /* Natural merge */ + l2 = f2; + for (f2 = f1 + size2; f2 < l2; f2 += size2) { + if ((cmp(f2-size, f2) > 0) != sense) { + p2 = *EVAL(p2) = f2 - list1 + list2; + if (sense > 0) + reverse(f1, f2-size); + f1 = f2; + } + } + if (sense > 0) + reverse (f1, f2-size); + f1 = f2; + if (f2 < last || cmp(f2 - size, f2) > 0) + p2 = *EVAL(p2) = f2 - list1 + list2; + else + p2 = *EVAL(p2) = list2 + n*size; + } + } +#else /* pairwise merge only. */ + for (f1 = list1, p2 = list2; f1 < last; f1 += size2) { + p2 = *EVAL(p2) = p2 + size2; + if (cmp (f1, f1 + size) > 0) + swap(f1, f1 + size); + } +#endif /* NATURAL */ +} + +/* + * This is to avoid out-of-bounds addresses in sorting the + * last 4 elements. + */ +static void +insertionsort(a, n, size, cmp) + u_char *a; + size_t n, size; + int (*cmp) __P((const void *, const void *)); +{ + u_char *ai, *s, *t, *u, tmp; + int i; + + for (ai = a+size; --n >= 1; ai += size) + for (t = ai; t > a; t -= size) { + u = t - size; + if (cmp(u, t) <= 0) + break; + swap(u, t); + } +} diff --git a/stdlib/putenv.c b/stdlib/putenv.c new file mode 100644 index 0000000..2fbe267 --- /dev/null +++ b/stdlib/putenv.c @@ -0,0 +1,76 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1988, 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 +#include + +int +putenv(str) + const char *str; +{ + char *p, *equal; + int rval; + + if ((p = strdup(str)) == NULL) + return (-1); + if ((equal = index(p, '=')) == NULL) { + (void)free(p); + return (-1); + } + *equal = '\0'; + rval = setenv(p, equal + 1, 1); + (void)free(p); + return (rval); +} diff --git a/stdlib/qsort.3 b/stdlib/qsort.3 new file mode 100644 index 0000000..9f591b9 --- /dev/null +++ b/stdlib/qsort.3 @@ -0,0 +1,231 @@ +.\" 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. +.\" +.\" @(#)qsort.3 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD: src/lib/libc/stdlib/qsort.3,v 1.10 2001/09/07 14:46:35 asmodai Exp $ +.\" +.Dd June 4, 1993 +.Dt QSORT 3 +.Os +.Sh NAME +.Nm qsort , heapsort , mergesort +.Nd sort functions +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In stdlib.h +.Ft void +.Fn qsort "void *base" "size_t nmemb" "size_t size" "int (*compar)(const void *, const void *)" +.Ft int +.Fn heapsort "void *base" "size_t nmemb" "size_t size" "int (*compar)(const void *, const void *)" +.Ft int +.Fn mergesort "void *base" "size_t nmemb" "size_t size" "int (*compar)(const void *, const void *)" +.Sh DESCRIPTION +The +.Fn qsort +function is a modified partition-exchange sort, or quicksort. +The +.Fn heapsort +function is a modified selection sort. +The +.Fn mergesort +function is a modified merge sort with exponential search +intended for sorting data with pre-existing order. +.Pp +The +.Fn qsort +and +.Fn heapsort +functions sort an array of +.Fa nmemb +objects, the initial member of which is pointed to by +.Fa base . +The size of each object is specified by +.Fa size . +.Fn Mergesort +behaves similarly, but +.Em requires +that +.Fa size +be greater than +.Dq "sizeof(void *) / 2" . +.Pp +The contents of the array +.Fa base +are sorted in ascending order according to +a comparison function pointed to by +.Fa compar , +which requires two arguments pointing to the objects being +compared. +.Pp +The comparison function must return an integer less than, equal to, or +greater than zero if the first argument is considered to be respectively +less than, equal to, or greater than the second. +.Pp +The functions +.Fn qsort +and +.Fn heapsort +are +.Em not +stable, that is, if two members compare as equal, their order in +the sorted array is undefined. +The function +.Fn mergesort +is stable. +.Pp +The +.Fn qsort +function is an implementation of C.A.R. Hoare's ``quicksort'' algorithm, +a variant of partition-exchange sorting; in particular, see D.E. Knuth's +Algorithm Q. +.Fn Qsort +takes O N lg N average time. +This implementation uses median selection to avoid its +O N**2 worst-case behavior. +.Pp +The +.Fn heapsort +function is an implementation of J.W.J. William's ``heapsort'' algorithm, +a variant of selection sorting; in particular, see D.E. Knuth's Algorithm H. +.Fn Heapsort +takes O N lg N worst-case time. +Its +.Em only +advantage over +.Fn qsort +is that it uses almost no additional memory; while +.Fn qsort +does not allocate memory, it is implemented using recursion. +.Pp +The function +.Fn mergesort +requires additional memory of size +.Fa nmemb * +.Fa size +bytes; it should be used only when space is not at a premium. +.Fn Mergesort +is optimized for data with pre-existing order; its worst case +time is O N lg N; its best case is O N. +.Pp +Normally, +.Fn qsort +is faster than +.Fn mergesort +is faster than +.Fn heapsort . +Memory availability and pre-existing order in the data can make this +untrue. +.Sh RETURN VALUES +The +.Fn qsort +function +returns no value. +.Pp +.Rv -std heapsort mergesort +.Sh ERRORS +The +.Fn heapsort +and +.Fn mergesort +functions succeed unless: +.Bl -tag -width Er +.It Bq Er EINVAL +The +.Fa size +argument is zero, or, +the +.Fa size +argument to +.Fn mergesort +is less than +.Dq "sizeof(void *) / 2" . +.It Bq Er ENOMEM +.Fn Heapsort +or +.Fn mergesort +were unable to allocate memory. +.El +.Sh COMPATIBILITY +Previous versions of +.Fn qsort +did not permit the comparison routine itself to call +.Fn qsort 3 . +This is no longer true. +.Sh SEE ALSO +.Xr sort 1 , +.Xr radixsort 3 +.Rs +.%A Hoare, C.A.R. +.%D 1962 +.%T "Quicksort" +.%J "The Computer Journal" +.%V 5:1 +.%P pp. 10-15 +.Re +.Rs +.%A Williams, J.W.J +.%D 1964 +.%T "Heapsort" +.%J "Communications of the ACM" +.%V 7:1 +.%P pp. 347-348 +.Re +.Rs +.%A Knuth, D.E. +.%D 1968 +.%B "The Art of Computer Programming" +.%V Vol. 3 +.%T "Sorting and Searching" +.%P pp. 114-123, 145-149 +.Re +.Rs +.%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. +.%T "Engineering a Sort Function" +.%J "bentley@research.att.com" +.%V January 1992 +.Re +.Sh STANDARDS +The +.Fn qsort +function +conforms to +.St -isoC . diff --git a/stdlib/qsort.c b/stdlib/qsort.c new file mode 100644 index 0000000..d0d2fc6 --- /dev/null +++ b/stdlib/qsort.c @@ -0,0 +1,192 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * 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. + */ + + +#include +#include + +static inline char *med3 __P((char *, char *, char *, int (*)())); +static inline void swapfunc __P((char *, char *, int, int)); + +#define min(a, b) (a) < (b) ? a : b + +/* + * Qsort routine from Bentley & McIlroy's "Engineering a Sort Function". + */ +#define swapcode(TYPE, parmi, parmj, n) { \ + long i = (n) / sizeof (TYPE); \ + register TYPE *pi = (TYPE *) (parmi); \ + register TYPE *pj = (TYPE *) (parmj); \ + do { \ + register TYPE t = *pi; \ + *pi++ = *pj; \ + *pj++ = t; \ + } while (--i > 0); \ +} + +#define SWAPINIT(a, es) swaptype = ((char *)a - (char *)0) % sizeof(long) || \ + es % sizeof(long) ? 2 : es == sizeof(long)? 0 : 1; + +static inline void +swapfunc(a, b, n, swaptype) + char *a, *b; + int n, swaptype; +{ + if(swaptype <= 1) + swapcode(long, a, b, n) + else + swapcode(char, a, b, n) +} + +#define swap(a, b) \ + if (swaptype == 0) { \ + long t = *(long *)(a); \ + *(long *)(a) = *(long *)(b); \ + *(long *)(b) = t; \ + } else \ + swapfunc(a, b, es, swaptype) + +#define vecswap(a, b, n) if ((n) > 0) swapfunc(a, b, n, swaptype) + +static inline char * +med3(a, b, c, cmp) + char *a, *b, *c; + int (*cmp)(); +{ + return cmp(a, b) < 0 ? + (cmp(b, c) < 0 ? b : (cmp(a, c) < 0 ? c : a )) + :(cmp(b, c) > 0 ? b : (cmp(a, c) < 0 ? a : c )); +} + +void +qsort(a, n, es, cmp) + void *a; + size_t n, es; + int (*cmp)(); +{ + char *pa, *pb, *pc, *pd, *pl, *pm, *pn; + int d, r, swaptype, swap_cnt; + +loop: SWAPINIT(a, es); + swap_cnt = 0; + if (n < 7) { + for (pm = a + es; pm < (char *) a + n * es; pm += es) + for (pl = pm; pl > (char *) a && cmp(pl - es, pl) > 0; + pl -= es) + swap(pl, pl - es); + return; + } + pm = a + (n / 2) * es; + if (n > 7) { + pl = a; + pn = a + (n - 1) * es; + if (n > 40) { + d = (n / 8) * es; + pl = med3(pl, pl + d, pl + 2 * d, cmp); + pm = med3(pm - d, pm, pm + d, cmp); + pn = med3(pn - 2 * d, pn - d, pn, cmp); + } + pm = med3(pl, pm, pn, cmp); + } + swap(a, pm); + pa = pb = a + es; + + pc = pd = a + (n - 1) * es; + for (;;) { + while (pb <= pc && (r = cmp(pb, a)) <= 0) { + if (r == 0) { + swap_cnt = 1; + swap(pa, pb); + pa += es; + } + pb += es; + } + while (pb <= pc && (r = cmp(pc, a)) >= 0) { + if (r == 0) { + swap_cnt = 1; + swap(pc, pd); + pd -= es; + } + pc -= es; + } + if (pb > pc) + break; + swap(pb, pc); + swap_cnt = 1; + pb += es; + pc -= es; + } + if (swap_cnt == 0) { /* Switch to insertion sort */ + for (pm = a + es; pm < (char *) a + n * es; pm += es) + for (pl = pm; pl > (char *) a && cmp(pl - es, pl) > 0; + pl -= es) + swap(pl, pl - es); + return; + } + + pn = a + n * es; + r = min(pa - (char *)a, pb - pa); + vecswap(a, pb - r, r); + r = min(pd - pc, pn - pd - es); + vecswap(pb, pn - r, r); + if ((r = pb - pa) > es) + qsort(a, r / es, es, cmp); + if ((r = pd - pc) > es) { + /* Iterate rather than recurse to save stack space */ + a = pn - r; + n = r / es; + goto loop; + } +/* qsort(pn - r, r / es, es, cmp);*/ +} diff --git a/stdlib/radixsort.3 b/stdlib/radixsort.3 new file mode 100644 index 0000000..f4e6171 --- /dev/null +++ b/stdlib/radixsort.3 @@ -0,0 +1,161 @@ +.\" Copyright (c) 1990, 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. +.\" +.\" @(#)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 $ +.\" +.Dd January 27, 1994 +.Dt RADIXSORT 3 +.Os +.Sh NAME +.Nm radixsort +.Nd radix sort +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In limits.h +.In stdlib.h +.Ft int +.Fn radixsort "const unsigned char **base" "int nmemb" "const unsigned char *table" "unsigned endbyte" +.Ft int +.Fn sradixsort "const unsigned char **base" "int nmemb" "const unsigned char *table" "unsigned endbyte" +.Sh DESCRIPTION +The +.Fn radixsort +and +.Fn sradixsort +functions +are implementations of radix sort. +.Pp +These functions sort an array of pointers to byte strings, the initial +member of which is referenced by +.Fa base . +The byte strings may contain any values; the end of each string +is denoted by the user-specified value +.Fa endbyte . +.Pp +Applications may specify a sort order by providing the +.Fa table +argument. +If +.Pf non- Dv NULL , +.Fa table +must reference an array of +.Dv UCHAR_MAX ++ 1 bytes which contains the sort +weight of each possible byte value. +The end-of-string byte must have a sort weight of 0 or 255 +(for sorting in reverse order). +More than one byte may have the same sort weight. +The +.Fa table +argument +is useful for applications which wish to sort different characters +equally, for example, providing a table with the same weights +for A-Z as for a-z will result in a case-insensitive sort. +If +.Fa table +is NULL, the contents of the array are sorted in ascending order +according to the +.Tn ASCII +order of the byte strings they reference and +.Fa endbyte +has a sorting weight of 0. +.Pp +The +.Fn sradixsort +function is stable, that is, if two elements compare as equal, their +order in the sorted array is unchanged. +The +.Fn sradixsort +function uses additional memory sufficient to hold +.Fa nmemb +pointers. +.Pp +The +.Fn radixsort +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. +They take linear time relative to the number of bytes in the strings. +.Sh RETURN VALUES +.Rv -std radixsort +.Sh ERRORS +.Bl -tag -width Er +.It Bq Er EINVAL +The value of the +.Fa endbyte +element of +.Fa table +is not 0 or 255. +.El +.Pp +Additionally, the +.Fn sradixsort +function +may fail and set +.Va errno +for any of the errors specified for the library routine +.Xr malloc 3 . +.Sh SEE ALSO +.Xr sort 1 , +.Xr qsort 3 +.Pp +.Rs +.%A Knuth, D.E. +.%D 1968 +.%B "The Art of Computer Programming" +.%T "Sorting and Searching" +.%V Vol. 3 +.%P pp. 170-178 +.Re +.Rs +.%A Paige, R. +.%D 1987 +.%T "Three Partition Refinement Algorithms" +.%J "SIAM J. Comput." +.%V Vol. 16 +.%N No. 6 +.Re +.Rs +.%A McIlroy, P. +.%D 1993 +.%B "Engineering Radix Sort" +.%T "Computing Systems" +.%V Vol. 6:1 +.%P pp. 5-27 +.Re +.Sh HISTORY +The +.Fn radixsort +function first appeared in +.Bx 4.4 . diff --git a/stdlib/radixsort.c b/stdlib/radixsort.c new file mode 100644 index 0000000..44a39d0 --- /dev/null +++ b/stdlib/radixsort.c @@ -0,0 +1,348 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Peter McIlroy and by Dan Bernstein at New York University, + * + * 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. + */ + + +/* + * Radixsort routines. + * + * Program r_sort_a() is unstable but uses O(logN) extra memory for a stack. + * Use radixsort(a, n, trace, endchar) for this case. + * + * For stable sorting (using N extra pointers) use sradixsort(), which calls + * r_sort_b(). + * + * For a description of this code, see D. McIlroy, P. McIlroy, K. Bostic, + * "Engineering Radix Sort". + */ + +#include +#include +#include +#include + +typedef struct { + const u_char **sa; + int sn, si; +} stack; + +static inline void simplesort + __P((const u_char **, int, int, const u_char *, u_int)); +static void r_sort_a __P((const u_char **, int, int, const u_char *, u_int)); +static void r_sort_b __P((const u_char **, + const u_char **, int, int, const u_char *, u_int)); + +#define THRESHOLD 20 /* Divert to simplesort(). */ +#define SIZE 512 /* Default stack size. */ + +#define SETUP { \ + if (tab == NULL) { \ + tr = tr0; \ + for (c = 0; c < endch; c++) \ + tr0[c] = c + 1; \ + tr0[c] = 0; \ + for (c++; c < 256; c++) \ + tr0[c] = c; \ + endch = 0; \ + } else { \ + endch = tab[endch]; \ + tr = tab; \ + if (endch != 0 && endch != 255) { \ + errno = EINVAL; \ + return (-1); \ + } \ + } \ +} + +int +radixsort(a, n, tab, endch) + const u_char **a, *tab; + int n; + u_int endch; +{ + const u_char *tr; + int c; + u_char tr0[256]; + + SETUP; + r_sort_a(a, n, 0, tr, endch); + return (0); +} + +int +sradixsort(a, n, tab, endch) + const u_char **a, *tab; + int n; + u_int endch; +{ + const u_char *tr, **ta; + int c; + u_char tr0[256]; + + SETUP; + if (n < THRESHOLD) + simplesort(a, n, 0, tr, endch); + else { + if ((ta = malloc(n * sizeof(a))) == NULL) + return (-1); + r_sort_b(a, ta, n, 0, tr, endch); + free(ta); + } + return (0); +} + +#define empty(s) (s >= sp) +#define pop(a, n, i) a = (--sp)->sa, n = sp->sn, i = sp->si +#define push(a, n, i) sp->sa = a, sp->sn = n, (sp++)->si = i +#define swap(a, b, t) t = a, a = b, b = t + +/* Unstable, in-place sort. */ +static void +r_sort_a(a, n, i, tr, endch) + const u_char **a; + int n, i; + const u_char *tr; + u_int endch; +{ + static int *count = NULL, nc, bmin; + register int c; + register const u_char **ak, *r; + stack s[SIZE], *sp, *sp0, *sp1, temp; + int *cp, bigc; + const u_char **an, *t, **aj, **top[256]; + + if( count == NULL ) { + count = malloc(256*sizeof(int)); + if( count == NULL ) + return; + } + + /* Set up stack. */ + sp = s; + push(a, n, i); + while (!empty(s)) { + pop(a, n, i); + if (n < THRESHOLD) { + simplesort(a, n, i, tr, endch); + continue; + } + an = a + n; + + /* Make character histogram. */ + if (nc == 0) { + bmin = 255; /* First occupied bin, excluding eos. */ + for (ak = a; ak < an;) { + c = tr[(*ak++)[i]]; + if (++count[c] == 1 && c != endch) { + if (c < bmin) + bmin = c; + nc++; + } + } + if (sp + nc > s + SIZE) { /* Get more stack. */ + r_sort_a(a, n, i, tr, endch); + continue; + } + } + + /* + * Set top[]; push incompletely sorted bins onto stack. + * top[] = pointers to last out-of-place element in bins. + * count[] = counts of elements in bins. + * Before permuting: top[c-1] + count[c] = top[c]; + * during deal: top[c] counts down to top[c-1]. + */ + sp0 = sp1 = sp; /* Stack position of biggest bin. */ + bigc = 2; /* Size of biggest bin. */ + if (endch == 0) /* Special case: set top[eos]. */ + top[0] = ak = a + count[0]; + else { + ak = a; + top[255] = an; + } + for (cp = count + bmin; nc > 0; cp++) { + while (*cp == 0) /* Find next non-empty pile. */ + cp++; + if (*cp > 1) { + if (*cp > bigc) { + bigc = *cp; + sp1 = sp; + } + push(ak, *cp, i+1); + } + top[cp-count] = ak += *cp; + nc--; + } + swap(*sp0, *sp1, temp); /* Play it safe -- biggest bin last. */ + + /* + * Permute misplacements home. Already home: everything + * before aj, and in bin[c], items from top[c] on. + * Inner loop: + * r = next element to put in place; + * ak = top[r[i]] = location to put the next element. + * aj = bottom of 1st disordered bin. + * Outer loop: + * Once the 1st disordered bin is done, ie. aj >= ak, + * aj<-aj + count[c] connects the bins in a linked list; + * reset count[c]. + */ + for (aj = a; aj < an; *aj = r, aj += count[c], count[c] = 0) + for (r = *aj; aj < (ak = --top[c = tr[r[i]]]);) + swap(*ak, r, t); + } +} + +/* Stable sort, requiring additional memory. */ +static void +r_sort_b(a, ta, n, i, tr, endch) + const u_char **a, **ta; + int n, i; + const u_char *tr; + u_int endch; +{ + static int *count = NULL, nc, bmin; + register int c; + register const u_char **ak, **ai; + stack s[512], *sp, *sp0, *sp1, temp; + const u_char **top[256]; + int *cp, bigc; + + if( count == NULL ) { + count = malloc(256*sizeof(int)); + if( count == NULL ) + return; + } + + sp = s; + push(a, n, i); + while (!empty(s)) { + pop(a, n, i); + if (n < THRESHOLD) { + simplesort(a, n, i, tr, endch); + continue; + } + + if (nc == 0) { + bmin = 255; + for (ak = a + n; --ak >= a;) { + c = tr[(*ak)[i]]; + if (++count[c] == 1 && c != endch) { + if (c < bmin) + bmin = c; + nc++; + } + } + if (sp + nc > s + SIZE) { + r_sort_b(a, ta, n, i, tr, endch); + continue; + } + } + + sp0 = sp1 = sp; + bigc = 2; + if (endch == 0) { + top[0] = ak = a + count[0]; + count[0] = 0; + } else { + ak = a; + top[255] = a + n; + count[255] = 0; + } + for (cp = count + bmin; nc > 0; cp++) { + while (*cp == 0) + cp++; + if ((c = *cp) > 1) { + if (c > bigc) { + bigc = c; + sp1 = sp; + } + push(ak, c, i+1); + } + top[cp-count] = ak += c; + *cp = 0; /* Reset count[]. */ + nc--; + } + swap(*sp0, *sp1, temp); + + for (ak = ta + n, ai = a+n; ak > ta;) /* Copy to temp. */ + *--ak = *--ai; + for (ak = ta+n; --ak >= ta;) /* Deal to piles. */ + *--top[tr[(*ak)[i]]] = *ak; + } +} + +static inline void +simplesort(a, n, b, tr, endch) /* insertion sort */ + register const u_char **a; + int n, b; + register const u_char *tr; + u_int endch; +{ + register u_char ch; + const u_char **ak, **ai, *s, *t; + + for (ak = a+1; --n >= 1; ak++) + for (ai = ak; ai > a; ai--) { + for (s = ai[0] + b, t = ai[-1] + b; + (ch = tr[*s]) != endch; s++, t++) + if (ch != tr[*t]) + break; + if (ch >= tr[*t]) + break; + swap(ai[0], ai[-1], s); + } +} diff --git a/stdlib/rand.3 b/stdlib/rand.3 new file mode 100644 index 0000000..609c263 --- /dev/null +++ b/stdlib/rand.3 @@ -0,0 +1,117 @@ +.\" 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. +.\" +.\" @(#)rand.3 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD: src/lib/libc/stdlib/rand.3,v 1.12 2001/09/07 14:46:36 asmodai Exp $ +.\" +.Dd May 25, 1999 +.Dt RAND 3 +.Os +.Sh NAME +.Nm rand , +.Nm srand , +.Nm sranddev , +.Nm rand_r +.Nd bad random number generator +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In stdlib.h +.Ft void +.Fn srand "unsigned seed" +.Ft void +.Fn sranddev void +.Ft int +.Fn rand void +.Ft int +.Fn rand_r "unsigned *ctx" +.Sh DESCRIPTION +.Bf -symbolic +These interfaces are obsoleted by +.Xr random 3 . +.Ef +.Pp +The +.Fn rand +function computes a sequence of pseudo-random integers in the range +of 0 to +.Dv RAND_MAX +(as defined by the header file +.Aq Pa stdlib.h ) . +.Pp +The +.Fn srand +function sets its argument +.Fa seed +as the seed for a new sequence of +pseudo-random numbers to be returned by +.Fn rand . +These sequences are repeatable by calling +.Fn srand +with the same seed value. +.Pp +If no +.Fa seed +value is provided, the functions are automatically +seeded with a value of 1. +.Pp +The +.Fn sranddev +function initializes a seed using the +.Xr random 4 +random number device which returns good random numbers, +suitable for cryptographic use. +.Pp +.Fn rand_r +provides the same functionality as +.Fn rand . +A pointer to the context value +.Fa ctx +must be supplied by the caller. +.Sh SEE ALSO +.Xr random 3 , +.Xr random 4 +.Sh STANDARDS +The +.Fn rand +and +.Fn srand +functions +conform to +.St -isoC . +.Pp +The +.Fn rand_r +function is as proposed in the POSIX.4a Draft #6 document. diff --git a/stdlib/rand.c b/stdlib/rand.c new file mode 100644 index 0000000..42a5bd4 --- /dev/null +++ b/stdlib/rand.c @@ -0,0 +1,107 @@ +/*- + * Copyright (c) 1990, 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. + * + * Posix rand_r function added May 1999 by Wes Peters . + * + * $FreeBSD: src/lib/libc/stdlib/rand.c,v 1.2.2.1 2001/03/05 11:33:57 obrien Exp $ + */ + +#if defined(LIBC_SCCS) && !defined(lint) +static char sccsid[] = "@(#)rand.c 8.1 (Berkeley) 6/14/93"; +#endif /* LIBC_SCCS and not lint */ + +#include +#include + +#ifdef TEST +#include +#endif /* TEST */ + +static int +do_rand(unsigned long *ctx) +{ + return ((*ctx = *ctx * 1103515245 + 12345) % ((u_long)RAND_MAX + 1)); +} + + +int +rand_r(unsigned int *ctx) +{ + u_long val = (u_long) *ctx; + *ctx = do_rand(&val); + return (int) *ctx; +} + + +static u_long next = 1; + +int +rand() +{ + return do_rand(&next); +} + +void +srand(seed) +u_int seed; +{ + next = seed; +} + +#ifdef TEST + +main() +{ + int i; + unsigned myseed; + + printf("seeding rand with 0x19610910: \n"); + srand(0x19610910); + + printf("generating three pseudo-random numbers:\n"); + for (i = 0; i < 3; i++) + { + printf("next random number = %d\n", rand()); + } + + printf("generating the same sequence with rand_r:\n"); + myseed = 0x19610910; + for (i = 0; i < 3; i++) + { + printf("next random number = %d\n", rand_r(&myseed)); + } + + return 0; +} + +#endif /* TEST */ + diff --git a/stdlib/random.3 b/stdlib/random.3 new file mode 100644 index 0000000..172030d --- /dev/null +++ b/stdlib/random.3 @@ -0,0 +1,191 @@ +.\" Copyright (c) 1983, 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. +.\" +.\" @(#)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 $ +.\" +.Dd June 4, 1993 +.Dt RANDOM 3 +.Os +.Sh NAME +.Nm random , +.Nm srandom , +.Nm srandomdev , +.Nm initstate , +.Nm setstate +.Nd better random number generator; routines for changing generators +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In stdlib.h +.Ft long +.Fn random void +.Ft void +.Fn srandom "unsigned long seed" +.Ft void +.Fn srandomdev void +.Ft char * +.Fn initstate "unsigned long seed" "char *state" "long n" +.Ft char * +.Fn setstate "char *state" +.Sh DESCRIPTION +The +.Fn random +function +uses a non-linear additive feedback random number generator employing a +default table of size 31 long integers to return successive pseudo-random +numbers in the range from 0 to +.if t 2\u\s731\s10\d\(mi1. +.if n (2**31)\(mi1. +The period of this random number generator is very large, approximately +.if t 16\(mu(2\u\s731\s10\d\(mi1). +.if n 16*((2**31)\(mi1). +.Pp +The +.Fn random +and +.Fn srandom +functions have (almost) the same calling sequence and initialization properties as the +.Xr rand 3 +and +.Xr srand 3 +functions. +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 +.Fn random +are usable. For example, +.Sq Li random()&01 +will produce a random binary +value. +.Pp +Like +.Xr rand 3 , +.Fn random +will by default produce a sequence of numbers that can be duplicated +by calling +.Fn srandom +with +.Ql 1 +as the seed. +.Pp +The +.Fn srandomdev +routine initialize a state array using +.Xr random 4 +random number device which returns good random numbers, +suitable for cryptographic use. +Note that this particular seeding +procedure can generate states which are impossible to reproduce by +calling +.Fn srandom +with any value, since the succeeding terms in the +state buffer are no longer derived from the LC algorithm applied to +a fixed seed. +.Pp +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 +.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 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. +The +.Fn initstate +function +returns a pointer to the previous state information array. +.Pp +Once a state has been initialized, the +.Fn setstate +routine provides for rapid switching between states. +The +.Fn setstate +function +returns a pointer to the previous state array; its +argument state array is used for further random number generation +until the next call to +.Fn initstate +or +.Fn setstate . +.Pp +Once a state array has been initialized, it may be restarted at a +different point either by calling +.Fn initstate +(with the desired seed, the state array, and its size) or by calling +both +.Fn setstate +(with the state array) and +.Fn srandom +(with the desired seed). +The advantage of calling both +.Fn setstate +and +.Fn srandom +is that the size of the state array does not have to be remembered after +it is initialized. +.Pp +With 256 bytes of state information, the period of the random number +generator is greater than +.if t 2\u\s769\s10\d, +.if n 2**69 +which should be sufficient for most purposes. +.Sh AUTHORS +.An Earl T. Cohen +.Sh DIAGNOSTICS +If +.Fn initstate +is called with less than 8 bytes of state information, or if +.Fn setstate +detects that the state information has been garbled, error +messages are printed on the standard error output. +.Sh SEE ALSO +.Xr rand 3 , +.Xr srand 3 , +.Xr random 4 +.Sh HISTORY +These +functions appeared in +.Bx 4.2 . +.Sh BUGS +About 2/3 the speed of +.Xr rand 3 . +.Pp +The historical implementation used to have a very weak seeding; the +random sequence did not vary much with the seed. +The current implementation employs a better pseudo-random number +generator for the initial state calculation. diff --git a/stdlib/random.c b/stdlib/random.c new file mode 100644 index 0000000..722e805 --- /dev/null +++ b/stdlib/random.c @@ -0,0 +1,399 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1983, 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 +#include + +/* + * random.c: + * + * An improved random number generation package. In addition to the standard + * rand()/srand() like interface, this package also has a special state info + * interface. The initstate() routine is called with a seed, an array of + * bytes, and a count of how many bytes are being passed in; this array is + * then initialized to contain information for random number generation with + * that much state information. Good sizes for the amount of state + * information are 32, 64, 128, and 256 bytes. The state can be switched by + * calling the setstate() routine with the same array as was initiallized + * with initstate(). By default, the package runs with 128 bytes of state + * information and generates far better random numbers than a linear + * 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 + * 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 + * 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). + * + * The random number generation technique is a linear feedback shift register + * approach, employing trinomials (since there are fewer terms to sum up that + * way). In this approach, the least significant bit of all the numbers in + * the state table will act as a linear feedback shift register, and will + * have period 2^deg - 1 (where deg is the degree of the polynomial being + * used, assuming that the polynomial is irreducible and primitive). The + * higher order bits will have longer periods, since their values are also + * influenced by pseudo-random carries out of the lower bits. The total + * period of the generator is approximately deg*(2**deg - 1); thus doubling + * the amount of state information has a vast influence on the period of the + * generator. Note: the deg*(2**deg - 1) is an approximation only good for + * large deg, when the period of the shift register is the dominant factor. + * With deg equal to seven, the period is actually much longer than the + * 7*(2**7 - 1) predicted by this formula. + */ + +/* + * For each of the currently supported random number generators, we have a + * break value on the amount of state information (you need at least this + * many bytes of state info to support this random number generator), a degree + * for the polynomial (actually a trinomial) that the R.N.G. is based on, and + * the separation between the two lower order coefficients of the trinomial. + */ +#define TYPE_0 0 /* linear congruential */ +#define BREAK_0 8 +#define DEG_0 0 +#define SEP_0 0 + +#define TYPE_1 1 /* x**7 + x**3 + 1 */ +#define BREAK_1 32 +#define DEG_1 7 +#define SEP_1 3 + +#define TYPE_2 2 /* x**15 + x + 1 */ +#define BREAK_2 64 +#define DEG_2 15 +#define SEP_2 1 + +#define TYPE_3 3 /* x**31 + x**3 + 1 */ +#define BREAK_3 128 +#define DEG_3 31 +#define SEP_3 3 + +#define TYPE_4 4 /* x**63 + x + 1 */ +#define BREAK_4 256 +#define DEG_4 63 +#define SEP_4 1 + +/* + * Array versions of the above information to make code run faster -- + * relies on fact that TYPE_i == i. + */ +#define MAX_TYPES 5 /* max number of types above */ + +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 }; + +/* + * Initially, everything is set up as if from: + * + * initstate(1, &randtbl, 128); + * + * Note that this initialization takes advantage of the fact that srandom() + * advances the front and rear pointers 10*rand_deg times, and hence the + * rear pointer which starts at 0 will also end up at zero; thus the zeroeth + * element of the state information, which contains info about the current + * position of the rear pointer is just + * + * MAX_TYPES * (rptr - state) + TYPE_3 == TYPE_3. + */ + +static long randtbl[DEG_3 + 1] = { + TYPE_3, + 0x9a319039, 0x32d9c024, 0x9b663182, 0x5da1f342, 0xde3b81e0, 0xdf0a6fb5, + 0xf103bc02, 0x48f340fb, 0x7449e56b, 0xbeb1dbb0, 0xab5c5918, 0x946554fd, + 0x8c2e680f, 0xeb3d799f, 0xb11ee0b7, 0x2d436b86, 0xda672e2a, 0x1588ca88, + 0xe369735d, 0x904f35f7, 0xd7158fd6, 0x6fa6f051, 0x616e6b96, 0xac94efdc, + 0x36413f93, 0xc622c298, 0xf5a42ab8, 0x8a88d77b, 0xf5ad9d0e, 0x8999220b, + 0x27fb47b9, +}; + +/* + * fptr and rptr are two pointers into the state info, a front and a rear + * pointer. These two pointers are always rand_sep places aparts, as they + * cycle cyclically through the state information. (Yes, this does mean we + * could get away with just one pointer, but the code for random() is more + * efficient this way). The pointers are left positioned as they would be + * from the call + * + * initstate(1, randtbl, 128); + * + * (The position of the rear pointer, rptr, is really 0 (as explained above + * 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]; + +/* + * The following things are the pointer to the state information table, the + * type of the current generator, the degree of the current polynomial being + * used, and the separation between the two pointers. Note that for efficiency + * of random(), we remember the first location of the state information, not + * the zeroeth. Hence it is valid to access state[-1], which is used to + * store the type of the R.N.G. Also, we remember the last location, since + * 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]; + +/* + * srandom: + * + * Initialize the random number generator based on the given seed. If the + * type is the trivial no-state-information type, just remember the seed. + * Otherwise, initializes state[] based on the given "seed" via a linear + * congruential generator. Then, the pointers are set to known locations + * that are exactly rand_sep places apart. Lastly, it cycles the state + * information a given number of times to get rid of any initial dependencies + * introduced by the L.C.R.N.G. Note that the initialization of randtbl[] + * for default usage relies on values produced by this routine. + */ +void +srandom(x) + unsigned long x; +{ + register long i; + + if (rand_type == TYPE_0) + state[0] = x; + else { + state[0] = x; + for (i = 1; i < rand_deg; i++) + state[i] = 1103515245 * state[i - 1] + 12345; + fptr = &state[rand_sep]; + rptr = &state[0]; + for (i = 0; i < 10 * rand_deg; i++) + (void)random(); + } +} + +/* + * initstate: + * + * Initialize the state information in the given array of n bytes for future + * random number generation. Based on the number of bytes we are given, and + * the break values for the different R.N.G.'s, we choose the best (largest) + * one we can and set things up for it. srandom() is then called to + * initialize the state information. + * + * Note that on return from srandom(), we set state[-1] to be the type + * multiplexed with the current value of the rear pointer; this is so + * successive calls to initstate() won't lose this information and will be + * able to restart with setstate(). + * + * Note: the first thing we do is save the current state, if any, just like + * setstate() so that it doesn't matter when initstate is called. + * + * Returns a pointer to the old state. + * + * Note: The Sparc platform requires that arg_state begin on a long + * word boundary; otherwise a bus error will occur. Even so, lint will + * complain about mis-alignment, but you should disregard these messages. + */ +char * +initstate(seed, arg_state, n) + unsigned long seed; /* seed for R.N.G. */ + char *arg_state; /* pointer to state array */ + long n; /* # bytes of state info */ +{ + register char *ostate = (char *)(&state[-1]); + register long *long_arg_state = (long *) arg_state; + + if (rand_type == TYPE_0) + state[-1] = rand_type; + else + state[-1] = MAX_TYPES * (rptr - state) + rand_type; + if (n < BREAK_0) { + (void)fprintf(stderr, + "random: not enough state (%ld bytes); ignored.\n", n); + return(0); + } + if (n < BREAK_1) { + rand_type = TYPE_0; + rand_deg = DEG_0; + rand_sep = SEP_0; + } else if (n < BREAK_2) { + rand_type = TYPE_1; + rand_deg = DEG_1; + rand_sep = SEP_1; + } else if (n < BREAK_3) { + rand_type = TYPE_2; + rand_deg = DEG_2; + rand_sep = SEP_2; + } else if (n < BREAK_4) { + rand_type = TYPE_3; + rand_deg = DEG_3; + rand_sep = SEP_3; + } else { + rand_type = TYPE_4; + rand_deg = DEG_4; + rand_sep = SEP_4; + } + state = (long *) (long_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; + else + long_arg_state[0] = MAX_TYPES * (rptr - state) + rand_type; + return(ostate); +} + +/* + * setstate: + * + * Restore the state from the given state array. + * + * Note: it is important that we also remember the locations of the pointers + * in the current state information, and restore the locations of the pointers + * from the old state information. This is done by multiplexing the pointer + * location into the zeroeth word of the state information. + * + * Note that due to the order in which things are done, it is OK to call + * setstate() with the same state as the current state. + * + * Returns a pointer to the old state information. + * + * Note: The Sparc platform requires that arg_state begin on a long + * word boundary; otherwise a bus error will occur. Even so, lint will + * complain about mis-alignment, but you should disregard these messages. + */ +char * +setstate(arg_state) + char *arg_state; /* pointer to state array */ +{ + register long *new_state = (long *) arg_state; + register long type = new_state[0] % MAX_TYPES; + register long rear = new_state[0] / MAX_TYPES; + char *ostate = (char *)(&state[-1]); + + if (rand_type == TYPE_0) + state[-1] = rand_type; + else + state[-1] = MAX_TYPES * (rptr - state) + rand_type; + switch(type) { + case TYPE_0: + case TYPE_1: + case TYPE_2: + case TYPE_3: + case TYPE_4: + rand_type = type; + rand_deg = degrees[type]; + rand_sep = seps[type]; + break; + default: + (void)fprintf(stderr, + "random: state info corrupted; not changed.\n"); + } + state = (long *) (new_state + 1); + if (rand_type != TYPE_0) { + rptr = &state[rear]; + fptr = &state[(rear + rand_sep) % rand_deg]; + } + end_ptr = &state[rand_deg]; /* set end_ptr too */ + return(ostate); +} + +/* + * random: + * + * If we are using the trivial TYPE_0 R.N.G., just do the old linear + * congruential bit. Otherwise, we do our fancy trinomial stuff, which is + * the same in all the other cases due to all the global variables that have + * been set up. The basic operation is to add the number at the rear pointer + * into the one at the front pointer. Then both pointers are advanced to + * the next location cyclically in the table. The value returned is the sum + * generated, reduced to 31 bits by throwing away the "least random" low bit. + * + * Note: the code takes advantage of the fact that both the front and + * rear pointers can't wrap on the same call by not testing the rear + * pointer if the front one has wrapped. + * + * Returns a 31-bit random number. + */ +long +random() +{ + register long i; + register long *f, *r; + + if (rand_type == TYPE_0) { + i = state[0]; + state[0] = i = (i * 1103515245 + 12345) & 0x7fffffff; + } else { + /* + * Use local variables rather than static variables for speed. + */ + f = fptr; r = rptr; + *f += *r; + i = (*f >> 1) & 0x7fffffff; /* chucking least random bit */ + if (++f >= end_ptr) { + f = state; + ++r; + } + else if (++r >= end_ptr) { + r = state; + } + + fptr = f; rptr = r; + } + return(i); +} diff --git a/stdlib/reallocf.c b/stdlib/reallocf.c new file mode 100644 index 0000000..c4cd9d9 --- /dev/null +++ b/stdlib/reallocf.c @@ -0,0 +1,39 @@ +/*- + * Copyright (c) 1998, M. Warner Losh + * 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/stdlib/reallocf.c,v 1.3 1999/08/28 00:01:37 peter Exp $ + */ +#include + +void * +reallocf(void *ptr, size_t size) +{ + void *nptr; + + nptr = realloc(ptr, size); + if (!nptr && ptr) + free(ptr); + return (nptr); +} diff --git a/stdlib/realpath.3 b/stdlib/realpath.3 new file mode 100644 index 0000000..90dc5c0 --- /dev/null +++ b/stdlib/realpath.3 @@ -0,0 +1,128 @@ +.\" Copyright (c) 1994 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" This code is derived from software contributed to Berkeley by +.\" Jan-Simon Pendry. +.\" +.\" 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. +.\" +.\" @(#)realpath.3 8.2 (Berkeley) 2/16/94 +.\" $FreeBSD: src/lib/libc/stdlib/realpath.3,v 1.10 2001/09/07 14:46:36 asmodai Exp $ +.\" +.Dd February 16, 1994 +.Dt REALPATH 3 +.Os +.Sh NAME +.Nm realpath +.Nd returns the canonicalized absolute pathname +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In sys/param.h +.In stdlib.h +.Ft "char *" +.Fn realpath "const char *pathname" "char resolved_path[MAXPATHLEN]" +.Sh DESCRIPTION +The +.Fn realpath +function resolves all symbolic links, extra +.Dq / +characters and references to +.Pa /./ +and +.Pa /../ +in +.Fa pathname , +and copies the resulting absolute pathname into +the memory referenced by +.Fa resolved_path . +The +.Fa resolved_path +argument +.Em must +refer to a buffer capable of storing at least +.Dv MAXPATHLEN +characters. +.Pp +The +.Fn realpath +function will resolve both absolute and relative paths +and return the absolute pathname corresponding to +.Fa pathname . +All but the last component of +.Fa pathname +must exist when +.Fn realpath +is called. +.Sh "RETURN VALUES" +The +.Fn realpath +function returns +.Fa resolved_path +on success. +If an error occurs, +.Fn realpath +returns +.Dv NULL , +and +.Fa resolved_path +contains the pathname which caused the problem. +.Sh ERRORS +The function +.Fn realpath +may fail and set the external variable +.Va errno +for any of the errors specified for the library functions +.Xr chdir 2 , +.Xr close 2 , +.Xr fchdir 2 , +.Xr lstat 2 , +.Xr open 2 , +.Xr readlink 2 +and +.Xr getcwd 3 . +.Sh CAVEATS +This implementation of +.Fn realpath +differs slightly from the Solaris implementation. +The +.Bx 4.4 +version always returns absolute pathnames, +whereas the Solaris implementation will, +under certain circumstances, return a relative +.Fa resolved_path +when given a relative +.Fa pathname . +.Sh "SEE ALSO" +.Xr getcwd 3 +.Sh HISTORY +The +.Fn realpath +function call first appeared in +.Bx 4.4 . diff --git a/stdlib/setenv.c b/stdlib/setenv.c new file mode 100644 index 0000000..e74a41f --- /dev/null +++ b/stdlib/setenv.c @@ -0,0 +1,137 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1987, 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 +#include +#include + +#include + +char *__findenv __P((const char *, int *)); + +/* + * 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) + register const char *name; + register const char *value; + int rewrite; +{ + static int alloced; /* if allocated space before */ + register char *c; + int l_value, offset; + char ***environp = _NSGetEnviron(); + + 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); + } + } else { /* create new slot */ + register int cnt; + register char **p; + + for (p = *environp, cnt = 0; *p; ++p, ++cnt); + if (alloced) { /* just increase size */ + *environp = (char **)realloc((char *)*environp, + (size_t)(sizeof(char *) * (cnt + 2))); + if (!*environp) + return (-1); + } + else { /* get new space */ + alloced = 1; /* copy old entries into it */ + p = malloc((size_t)(sizeof(char *) * (cnt + 2))); + if (!p) + return (-1); + bcopy(*environp, p, cnt * sizeof(char *)); + *environp = p; + } + (*environp)[cnt + 1] = NULL; + offset = cnt; + } + for (c = (char *)name; *c && *c != '='; ++c); /* no `=' in name */ + if (!((*environp)[offset] = /* name + `=' + value */ + malloc((size_t)((int)(c - name) + l_value + 2)))) + return (-1); + for (c = (*environp)[offset]; (*c = *name++) && *c != '='; ++c); + for (*c++ = '='; *c++ = *value++;); + return (0); +} + +/* + * unsetenv(name) -- + * Delete environmental variable "name". + */ +void +unsetenv(name) + const char *name; +{ + char **environ = *_NSGetEnviron(); + register char **p; + int offset; + + while (__findenv(name, &offset)) /* if set multiple times */ + for (p = &environ[offset];; ++p) + if (!(*p = *(p + 1))) + break; +} diff --git a/stdlib/strfmon.3 b/stdlib/strfmon.3 new file mode 100644 index 0000000..a01bd42 --- /dev/null +++ b/stdlib/strfmon.3 @@ -0,0 +1,92 @@ +.\" Copyright (c) 2001 Jeroen Ruigrok van der Werven +.\" 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 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. +.\" +.\" $FreeBSD: src/lib/libc/stdlib/strfmon.3,v 1.3 2001/10/01 13:50:03 ru Exp $ +.\" +.Dd September 7, 2001 +.Dt STRFMON 3 +.Os +.Sh NAME +.Nm strfmon +.Nd convert monetary value to string +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In monetary.h +.Ft ssize_t +.Fn strfmon "char *s" "size_t maxsize" "const char *format" "..." +.Sh DESCRIPTION +The +.Fn strfmon +function places characters into the array pointed to by +.Fa s +as controlled by the string pointed to by +.Fa format . +No more than +.Fa maxsize +bytes are placed into the array. +.Sh RETURN VALUES +If the total number of resulting bytes including the terminating +.Dv NULL +byte is not more than +.Fa maxsize , +.Fn strfmon +returns the number of bytes placed into the array pointed to by +.Fa s , +not including the terminating +.Dv NULL +byte. +Otherwise, \-1 is returned, +the contents of the array are indeterminate, +and +.Va errno +is set to indicate the error. +.Sh ERRORS +The +.Fn strfmon +function will fail if: +.Bl -tag -width Er +.It Bq Er E2BIG +Conversion stopped due to lack of space in the buffer. +.El +.Sh SEE ALSO +.Xr localeconv 3 +.Sh STANDARDS +The +.Fn strfmon +function +conforms to +.St -xpg4 +and +.St -susv2 . +.Sh AUTHORS +.An -nosplit +The +.Fn strfmon +function was implemented by +.An Alexey Zelkin Aq phantom@FreeBSD.org . +.Pp +This manual page was written by +.An Jeroen Ruigrok van der Werven Aq asmodai@FreeBSD.org +based on the standards' text. diff --git a/stdlib/strtod.3 b/stdlib/strtod.3 new file mode 100644 index 0000000..2aaa34f --- /dev/null +++ b/stdlib/strtod.3 @@ -0,0 +1,140 @@ +.\" 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.13 2001/09/07 14:46:36 asmodai Exp $ +.\" +.Dd June 4, 1993 +.Dt STRTOD 3 +.Os +.Sh NAME +.Nm strtod +.Nd convert +.Tn ASCII +string to double +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In stdlib.h +.Ft double +.Fn strtod "const char *nptr" "char **endptr" +.Sh DESCRIPTION +The +.Fn strtod +function converts the initial portion of the string +pointed to by +.Fa nptr +to +.Em double +representation. +.Pp +The expected form of the string is an optional plus (``+'') or minus +sign (``\-'') followed by a sequence of digits optionally containing +a decimal-point character, optionally followed by an exponent. +An exponent consists of an ``E'' or ``e'', followed by an optional plus +or minus sign, followed by a sequence of digits. +.Pp +Leading white-space characters in the string (as defined by the +.Xr isspace 3 +function) are skipped. +The decimal point +character is defined in the program's locale (category +.Dv LC_NUMERIC ) . +.Sh RETURN VALUES +The +.Fn strtod +function returns the converted value, if any. +.Pp +If +.Fa endptr +is not +.Dv NULL , +a pointer to the character after the last character used +in the conversion is stored in the location referenced by +.Fa endptr . +.Pp +If no conversion is performed, zero is returned and the value of +.Fa nptr +is stored in the location referenced by +.Fa endptr . +.Pp +If the correct value would cause overflow, plus or minus +.Dv HUGE_VAL +is returned (according to the sign of the value), and +.Er ERANGE +is stored in +.Va errno . +If the correct value would cause underflow, zero is +returned and +.Er ERANGE +is stored in +.Va errno . +.Sh ERRORS +.Bl -tag -width Er +.It Bq Er ERANGE +Overflow or underflow occurred. +.El +.Sh SEE ALSO +.Xr atof 3 , +.Xr atoi 3 , +.Xr atol 3 , +.Xr strtol 3 , +.Xr strtoul 3 +.Sh STANDARDS +The +.Fn strtod +function +conforms to +.St -isoC . +.Sh AUTHORS +The author of this software is +.An David M. Gay . +.Pp +Copyright (c) 1991 by AT&T. +.Pp +Permission to use, copy, modify, and distribute this software for any +purpose without fee is hereby granted, provided that this entire notice +is included in all copies of any software which is or includes a copy +or modification of this software and in all copies of the supporting +documentation for such software. +.Pp +THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED +WARRANTY. IN PARTICULAR, NEITHER THE AUTHOR NOR AT&T MAKES ANY +REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY +OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. +.Pp +Contact your vendor for a free copy of the source code to +.Fn strtod +and accompanying functions. diff --git a/stdlib/strtod.c b/stdlib/strtod.c new file mode 100644 index 0000000..50a37a6 --- /dev/null +++ b/stdlib/strtod.c @@ -0,0 +1,2515 @@ +/* + * Copyright (c) 1999 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@ + */ +/**************************************************************** + * + * The author of this software is David M. Gay. + * + * Copyright (c) 1991 by AT&T. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose without fee is hereby granted, provided that this entire notice + * is included in all copies of any software which is or includes a copy + * or modification of this software and in all copies of the supporting + * documentation for such software. + * + * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED + * WARRANTY. IN PARTICULAR, NEITHER THE AUTHOR NOR AT&T MAKES ANY + * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY + * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. + * + ***************************************************************/ + +/* Please send bug reports to + David M. Gay + AT&T Bell Laboratories, Room 2C-463 + 600 Mountain Avenue + Murray Hill, NJ 07974-2070 + U.S.A. + dmg@research.att.com or research!dmg + */ + +/* strtod for IEEE-, VAX-, and IBM-arithmetic machines. + * + * This strtod returns a nearest machine number to the input decimal + * string (or sets errno to ERANGE). With IEEE arithmetic, ties are + * broken by the IEEE round-even rule. Otherwise ties are broken by + * 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]. + * + * Modifications: + * + * 1. We only require IEEE, IBM, or VAX double-precision + * arithmetic (not IEEE double-extended). + * 2. We get by with floating-point arithmetic in a case that + * Clinger missed -- when we're computing d * 10^n + * for a small integer d and the integer n is not too + * much larger than 22 (the maximum integer k for which + * we can represent 10^k exactly), we may be able to + * compute (d*10^k) * 10^(e-k) with just one roundoff. + * 3. Rather than a bit-at-a-time adjustment of the binary + * result in the hard case, we use floating-point + * arithmetic to determine the adjustment to within + * one bit; only in really hard cases do we need to + * compute a second residual. + * 4. Because of 3., we don't need a large table of powers of 10 + * for ten-to-e (just some small tables, e.g. of 10^k + * for 0 <= k <= 22). + */ + +/* + * #define IEEE_LITTLE_ENDIAN for IEEE-arithmetic machines where the least + * significant byte has the lowest address. + * #define IEEE_BIG_ENDIAN for IEEE-arithmetic machines where the most + * significant byte has the lowest address. + * #define Long int on machines with 32-bit ints and 64-bit longs. + * #define Sudden_Underflow for IEEE-format machines without gradual + * underflow (i.e., that flush to zero on underflow). + * #define IBM for IBM mainframe-style floating-point arithmetic. + * #define VAX for VAX-style floating-point arithmetic. + * #define Unsigned_Shifts if >> does treats its left operand as unsigned. + * #define No_leftright to omit left-right logic in fast floating-point + * computation of dtoa. + * #define Check_FLT_ROUNDS if FLT_ROUNDS can assume the values 2 or 3. + * #define RND_PRODQUOT to use rnd_prod and rnd_quot (assembly routines + * that use extended-precision instructions to compute rounded + * products and quotients) with IBM. + * #define ROUND_BIASED for IEEE-format with biased rounding. + * #define Inaccurate_Divide for IEEE-format with correctly rounded + * products but inaccurate quotients, e.g., for Intel i860. + * #define Just_16 to store 16 bits per 32-bit Long when doing high-precision + * integer arithmetic. Whether this speeds things up or slows things + * down depends on the machine and the number being converted. + * #define KR_headers for old-style C function headers. + * #define Bad_float_h if your system lacks a float.h or if it does not + * define some or all of DBL_DIG, DBL_MAX_10_EXP, DBL_MAX_EXP, + * FLT_RADIX, FLT_ROUNDS, and DBL_MAX. + * #define MALLOC your_malloc, where your_malloc(n) acts like malloc(n) + * if memory is available and otherwise does something you deem + * appropriate. If MALLOC is undefined, malloc will be invoked + * directly -- and assumed always to succeed. + */ + +#if defined(LIBC_SCCS) && !defined(lint) +static char *rcsid = "$OpenBSD: strtod.c,v 1.9 1997/03/25 17:07:30 rahnds Exp $"; +#endif /* LIBC_SCCS and not lint */ + +#if defined(__m68k__) || defined(__sparc__) || defined(__i386__) || \ + defined(__mips__) || defined(__ns32k__) || defined(__alpha__) || \ + defined(__powerpc__) || defined(__m88k__) || defined(__ppc__) +#include +#if BYTE_ORDER == BIG_ENDIAN +#define IEEE_BIG_ENDIAN +#else +#define IEEE_LITTLE_ENDIAN +#endif +#endif + +#ifdef __arm32__ +/* + * Although the CPU is little endian the FP has different + * byte and word endianness. The byte order is still little endian + * but the word order is big endian. + */ +#define IEEE_BIG_ENDIAN +#endif + +#ifdef vax +#define VAX +#endif + +#define Long int32_t +#define ULong u_int32_t + +#ifdef DEBUG +#include "stdio.h" +#define Bug(x) {fprintf(stderr, "%s\n", x); exit(1);} +#endif + +#ifdef __cplusplus +#include "malloc.h" +#include "memory.h" +#else +#ifndef KR_headers +#include "stdlib.h" +#include "string.h" +#include "locale.h" +#else +#include "malloc.h" +#include "memory.h" +#endif +#endif + +#ifdef MALLOC +#ifdef KR_headers +extern char *MALLOC(); +#else +extern void *MALLOC(size_t); +#endif +#else +#define MALLOC malloc +#endif + +#include "ctype.h" +#include "errno.h" + +#if defined(__APPLE__) +/* + * Temporarily define this, so we avoid pulling in symbols from libm + */ +#define Bad_float_h +#endif + +#ifdef Bad_float_h +#undef __STDC__ +#ifdef IEEE_BIG_ENDIAN +#define IEEE_ARITHMETIC +#endif +#ifdef IEEE_LITTLE_ENDIAN +#define IEEE_ARITHMETIC +#endif + +#ifdef IEEE_ARITHMETIC +#define DBL_DIG 15 +#define DBL_MAX_10_EXP 308 +#define DBL_MAX_EXP 1024 +#define FLT_RADIX 2 +#define FLT_ROUNDS 1 +#define DBL_MAX 1.7976931348623157e+308 +#endif + +#ifdef IBM +#define DBL_DIG 16 +#define DBL_MAX_10_EXP 75 +#define DBL_MAX_EXP 63 +#define FLT_RADIX 16 +#define FLT_ROUNDS 0 +#define DBL_MAX 7.2370055773322621e+75 +#endif + +#ifdef VAX +#define DBL_DIG 16 +#define DBL_MAX_10_EXP 38 +#define DBL_MAX_EXP 127 +#define FLT_RADIX 2 +#define FLT_ROUNDS 1 +#define DBL_MAX 1.7014118346046923e+38 +#endif + +#ifndef LONG_MAX +#define LONG_MAX 2147483647 +#endif +#else +#include "float.h" +#endif +#ifndef __MATH_H__ +#include "math.h" +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef CONST +#ifdef KR_headers +#define CONST /* blank */ +#else +#define CONST const +#endif +#endif + +#ifdef Unsigned_Shifts +#define Sign_Extend(a,b) if (b < 0) a |= 0xffff0000; +#else +#define Sign_Extend(a,b) /*no-op*/ +#endif + +#if defined(IEEE_LITTLE_ENDIAN) + defined(IEEE_BIG_ENDIAN) + defined(VAX) + \ + defined(IBM) != 1 +Exactly one of IEEE_LITTLE_ENDIAN IEEE_BIG_ENDIAN, VAX, or +IBM should be defined. +#endif + +#ifdef IEEE_LITTLE_ENDIAN +#define word0(x) ((ULong *)&x)[1] +#define word1(x) ((ULong *)&x)[0] +#else +#define word0(x) ((ULong *)&x)[0] +#define word1(x) ((ULong *)&x)[1] +#endif + +/* The following definition of Storeinc is appropriate for MIPS processors. + * An alternative that might be better on some machines is + * #define Storeinc(a,b,c) (*a++ = b << 16 | c & 0xffff) + */ +#if defined(IEEE_LITTLE_ENDIAN) + defined(VAX) + defined(__arm32__) +#define Storeinc(a,b,c) (((unsigned short *)a)[1] = (unsigned short)b, \ +((unsigned short *)a)[0] = (unsigned short)c, a++) +#else +#define Storeinc(a,b,c) (((unsigned short *)a)[0] = (unsigned short)b, \ +((unsigned short *)a)[1] = (unsigned short)c, a++) +#endif + +/* #define P DBL_MANT_DIG */ +/* Ten_pmax = floor(P*log(2)/log(5)) */ +/* Bletch = (highest power of 2 < DBL_MAX_10_EXP) / 16 */ +/* Quick_max = floor((P-1)*log(FLT_RADIX)/log(10) - 1) */ +/* Int_max = floor(P*log(FLT_RADIX)/log(10) - 1) */ + +#if defined(IEEE_LITTLE_ENDIAN) + defined(IEEE_BIG_ENDIAN) +#define Exp_shift 20 +#define Exp_shift1 20 +#define Exp_msk1 0x100000 +#define Exp_msk11 0x100000 +#define Exp_mask 0x7ff00000 +#define P 53 +#define Bias 1023 +#define IEEE_Arith +#define Emin (-1022) +#define Exp_1 0x3ff00000 +#define Exp_11 0x3ff00000 +#define Ebits 11 +#define Frac_mask 0xfffff +#define Frac_mask1 0xfffff +#define Ten_pmax 22 +#define Bletch 0x10 +#define Bndry_mask 0xfffff +#define Bndry_mask1 0xfffff +#define LSB 1 +#define Sign_bit 0x80000000 +#define Log2P 1 +#define Tiny0 0 +#define Tiny1 1 +#define Quick_max 14 +#define Int_max 14 +#define Infinite(x) (word0(x) == 0x7ff00000) /* sufficient test for here */ +#else +#undef Sudden_Underflow +#define Sudden_Underflow +#ifdef IBM +#define Exp_shift 24 +#define Exp_shift1 24 +#define Exp_msk1 0x1000000 +#define Exp_msk11 0x1000000 +#define Exp_mask 0x7f000000 +#define P 14 +#define Bias 65 +#define Exp_1 0x41000000 +#define Exp_11 0x41000000 +#define Ebits 8 /* exponent has 7 bits, but 8 is the right value in b2d */ +#define Frac_mask 0xffffff +#define Frac_mask1 0xffffff +#define Bletch 4 +#define Ten_pmax 22 +#define Bndry_mask 0xefffff +#define Bndry_mask1 0xffffff +#define LSB 1 +#define Sign_bit 0x80000000 +#define Log2P 4 +#define Tiny0 0x100000 +#define Tiny1 0 +#define Quick_max 14 +#define Int_max 15 +#else /* VAX */ +#define Exp_shift 23 +#define Exp_shift1 7 +#define Exp_msk1 0x80 +#define Exp_msk11 0x800000 +#define Exp_mask 0x7f80 +#define P 56 +#define Bias 129 +#define Exp_1 0x40800000 +#define Exp_11 0x4080 +#define Ebits 8 +#define Frac_mask 0x7fffff +#define Frac_mask1 0xffff007f +#define Ten_pmax 24 +#define Bletch 2 +#define Bndry_mask 0xffff007f +#define Bndry_mask1 0xffff007f +#define LSB 0x10000 +#define Sign_bit 0x8000 +#define Log2P 1 +#define Tiny0 0x80 +#define Tiny1 0 +#define Quick_max 15 +#define Int_max 15 +#endif +#endif + +#ifndef IEEE_Arith +#define ROUND_BIASED +#endif + +#ifdef RND_PRODQUOT +#define rounded_product(a,b) a = rnd_prod(a, b) +#define rounded_quotient(a,b) a = rnd_quot(a, b) +#ifdef KR_headers +extern double rnd_prod(), rnd_quot(); +#else +extern double rnd_prod(double, double), rnd_quot(double, double); +#endif +#else +#define rounded_product(a,b) a *= b +#define rounded_quotient(a,b) a /= b +#endif + +#define Big0 (Frac_mask1 | Exp_msk1*(DBL_MAX_EXP+Bias-1)) +#define Big1 0xffffffff + +#ifndef Just_16 +/* When Pack_32 is not defined, we store 16 bits per 32-bit Long. + * This makes some inner loops simpler and sometimes saves work + * during multiplications, but it often seems to make things slightly + * slower. Hence the default is now to store 32 bits per Long. + */ +#ifndef Pack_32 +#define Pack_32 +#endif +#endif + +#define Kmax 15 + +#ifdef __cplusplus +extern "C" double strtod(const char *s00, char **se); +extern "C" char *__dtoa(double d, int mode, int ndigits, + int *decpt, int *sign, char **rve, char **resultp); +#endif + + struct +Bigint { + struct Bigint *next; + int k, maxwds, sign, wds; + ULong x[1]; + }; + + typedef struct Bigint Bigint; + + static Bigint * +Balloc +#ifdef KR_headers + (k) int k; +#else + (int k) +#endif +{ + int x; + Bigint *rv; + + x = 1 << k; + rv = (Bigint *)malloc(sizeof(Bigint) + (x-1)*sizeof(Long)); + rv->k = k; + rv->maxwds = x; + rv->sign = rv->wds = 0; + return rv; +} + + static void +Bfree +#ifdef KR_headers + (v) Bigint *v; +#else + (Bigint *v) +#endif +{ + free(v); +} + +#define Bcopy(x,y) memcpy((char *)&x->sign, (char *)&y->sign, \ +y->wds*sizeof(Long) + 2*sizeof(int)) + + static Bigint * +multadd +#ifdef KR_headers + (b, m, a) Bigint *b; int m, a; +#else + (Bigint *b, int m, int a) /* multiply by m and add a */ +#endif +{ + int i, wds; + ULong *x, y; +#ifdef Pack_32 + ULong xi, z; +#endif + Bigint *b1; + + wds = b->wds; + x = b->x; + i = 0; + do { +#ifdef Pack_32 + xi = *x; + y = (xi & 0xffff) * m + a; + z = (xi >> 16) * m + (y >> 16); + a = (int)(z >> 16); + *x++ = (z << 16) + (y & 0xffff); +#else + y = *x * m + a; + a = (int)(y >> 16); + *x++ = y & 0xffff; +#endif + } + while(++i < wds); + if (a) { + if (wds >= b->maxwds) { + b1 = Balloc(b->k+1); + Bcopy(b1, b); + Bfree(b); + b = b1; + } + b->x[wds++] = a; + b->wds = wds; + } + return b; + } + + static Bigint * +s2b +#ifdef KR_headers + (s, nd0, nd, y9) CONST char *s; int nd0, nd; ULong y9; +#else + (CONST char *s, int nd0, int nd, ULong y9) +#endif +{ + Bigint *b; + int i, k; + Long x, y; + + x = (nd + 8) / 9; + for(k = 0, y = 1; x > y; y <<= 1, k++) ; +#ifdef Pack_32 + b = Balloc(k); + b->x[0] = y9; + b->wds = 1; +#else + b = Balloc(k+1); + b->x[0] = y9 & 0xffff; + b->wds = (b->x[1] = y9 >> 16) ? 2 : 1; +#endif + + i = 9; + if (9 < nd0) { + s += 9; + do b = multadd(b, 10, *s++ - '0'); + while(++i < nd0); + s++; + } + else + s += 10; + for(; i < nd; i++) + b = multadd(b, 10, *s++ - '0'); + return b; + } + + static int +hi0bits +#ifdef KR_headers + (x) register ULong x; +#else + (register ULong x) +#endif +{ + register int k = 0; + + if (!(x & 0xffff0000)) { + k = 16; + x <<= 16; + } + if (!(x & 0xff000000)) { + k += 8; + x <<= 8; + } + if (!(x & 0xf0000000)) { + k += 4; + x <<= 4; + } + if (!(x & 0xc0000000)) { + k += 2; + x <<= 2; + } + if (!(x & 0x80000000)) { + k++; + if (!(x & 0x40000000)) + return 32; + } + return k; + } + + static int +lo0bits +#ifdef KR_headers + (y) ULong *y; +#else + (ULong *y) +#endif +{ + register int k; + register ULong x = *y; + + if (x & 7) { + if (x & 1) + return 0; + if (x & 2) { + *y = x >> 1; + return 1; + } + *y = x >> 2; + return 2; + } + k = 0; + if (!(x & 0xffff)) { + k = 16; + x >>= 16; + } + if (!(x & 0xff)) { + k += 8; + x >>= 8; + } + if (!(x & 0xf)) { + k += 4; + x >>= 4; + } + if (!(x & 0x3)) { + k += 2; + x >>= 2; + } + if (!(x & 1)) { + k++; + x >>= 1; + if (!x & 1) + return 32; + } + *y = x; + return k; + } + + static Bigint * +i2b +#ifdef KR_headers + (i) int i; +#else + (int i) +#endif +{ + Bigint *b; + + b = Balloc(1); + b->x[0] = i; + b->wds = 1; + return b; + } + + static Bigint * +mult +#ifdef KR_headers + (a, b) Bigint *a, *b; +#else + (Bigint *a, Bigint *b) +#endif +{ + Bigint *c; + int k, wa, wb, wc; + ULong carry, y, z; + ULong *x, *xa, *xae, *xb, *xbe, *xc, *xc0; +#ifdef Pack_32 + ULong z2; +#endif + + if (a->wds < b->wds) { + c = a; + a = b; + b = c; + } + k = a->k; + wa = a->wds; + wb = b->wds; + wc = wa + wb; + if (wc > a->maxwds) + k++; + c = Balloc(k); + for(x = c->x, xa = x + wc; x < xa; x++) + *x = 0; + xa = a->x; + xae = xa + wa; + xb = b->x; + xbe = xb + wb; + xc0 = c->x; +#ifdef Pack_32 + for(; xb < xbe; xb++, xc0++) { + if (y = *xb & 0xffff) { + x = xa; + xc = xc0; + carry = 0; + do { + z = (*x & 0xffff) * y + (*xc & 0xffff) + carry; + carry = z >> 16; + z2 = (*x++ >> 16) * y + (*xc >> 16) + carry; + carry = z2 >> 16; + Storeinc(xc, z2, z); + } + while(x < xae); + *xc = carry; + } + if (y = *xb >> 16) { + x = xa; + xc = xc0; + carry = 0; + z2 = *xc; + do { + z = (*x & 0xffff) * y + (*xc >> 16) + carry; + carry = z >> 16; + Storeinc(xc, z, z2); + z2 = (*x++ >> 16) * y + (*xc & 0xffff) + carry; + carry = z2 >> 16; + } + while(x < xae); + *xc = z2; + } + } +#else + for(; xb < xbe; xc0++) { + if (y = *xb++) { + x = xa; + xc = xc0; + carry = 0; + do { + z = *x++ * y + *xc + carry; + carry = z >> 16; + *xc++ = z & 0xffff; + } + while(x < xae); + *xc = carry; + } + } +#endif + for(xc0 = c->x, xc = xc0 + wc; wc > 0 && !*--xc; --wc) ; + c->wds = wc; + return c; + } + + static Bigint *p5s; + + static Bigint * +pow5mult +#ifdef KR_headers + (b, k) Bigint *b; int k; +#else + (Bigint *b, int k) +#endif +{ + Bigint *b1, *p5, *p51; + int i; + static int p05[3] = { 5, 25, 125 }; + + if (i = k & 3) + b = multadd(b, p05[i-1], 0); + + if (!(k >>= 2)) + return b; + if (!(p5 = p5s)) { + /* first time */ + p5 = p5s = i2b(625); + p5->next = 0; + } + for(;;) { + if (k & 1) { + b1 = mult(b, p5); + Bfree(b); + b = b1; + } + if (!(k >>= 1)) + break; + if (!(p51 = p5->next)) { + p51 = p5->next = mult(p5,p5); + p51->next = 0; + } + p5 = p51; + } + return b; + } + + static Bigint * +lshift +#ifdef KR_headers + (b, k) Bigint *b; int k; +#else + (Bigint *b, int k) +#endif +{ + int i, k1, n, n1; + Bigint *b1; + ULong *x, *x1, *xe, z; + +#ifdef Pack_32 + n = k >> 5; +#else + n = k >> 4; +#endif + k1 = b->k; + n1 = n + b->wds + 1; + for(i = b->maxwds; n1 > i; i <<= 1) + k1++; + b1 = Balloc(k1); + x1 = b1->x; + for(i = 0; i < n; i++) + *x1++ = 0; + x = b->x; + xe = x + b->wds; +#ifdef Pack_32 + if (k &= 0x1f) { + k1 = 32 - k; + z = 0; + do { + *x1++ = *x << k | z; + z = *x++ >> k1; + } + while(x < xe); + if (*x1 = z) + ++n1; + } +#else + if (k &= 0xf) { + k1 = 16 - k; + z = 0; + do { + *x1++ = *x << k & 0xffff | z; + z = *x++ >> k1; + } + while(x < xe); + if (*x1 = z) + ++n1; + } +#endif + else do + *x1++ = *x++; + while(x < xe); + b1->wds = n1 - 1; + Bfree(b); + return b1; + } + + static int +cmp +#ifdef KR_headers + (a, b) Bigint *a, *b; +#else + (Bigint *a, Bigint *b) +#endif +{ + ULong *xa, *xa0, *xb, *xb0; + int i, j; + + i = a->wds; + j = b->wds; +#ifdef DEBUG + if (i > 1 && !a->x[i-1]) + Bug("cmp called with a->x[a->wds-1] == 0"); + if (j > 1 && !b->x[j-1]) + Bug("cmp called with b->x[b->wds-1] == 0"); +#endif + if (i -= j) + return i; + xa0 = a->x; + xa = xa0 + j; + xb0 = b->x; + xb = xb0 + j; + for(;;) { + if (*--xa != *--xb) + return *xa < *xb ? -1 : 1; + if (xa <= xa0) + break; + } + return 0; + } + + static Bigint * +diff +#ifdef KR_headers + (a, b) Bigint *a, *b; +#else + (Bigint *a, Bigint *b) +#endif +{ + Bigint *c; + int i, wa, wb; + Long borrow, y; /* We need signed shifts here. */ + ULong *xa, *xae, *xb, *xbe, *xc; +#ifdef Pack_32 + Long z; +#endif + + i = cmp(a,b); + if (!i) { + c = Balloc(0); + c->wds = 1; + c->x[0] = 0; + return c; + } + if (i < 0) { + c = a; + a = b; + b = c; + i = 1; + } + else + i = 0; + c = Balloc(a->k); + c->sign = i; + wa = a->wds; + xa = a->x; + xae = xa + wa; + wb = b->wds; + xb = b->x; + xbe = xb + wb; + xc = c->x; + borrow = 0; +#ifdef Pack_32 + do { + y = (*xa & 0xffff) - (*xb & 0xffff) + borrow; + borrow = y >> 16; + Sign_Extend(borrow, y); + z = (*xa++ >> 16) - (*xb++ >> 16) + borrow; + borrow = z >> 16; + Sign_Extend(borrow, z); + Storeinc(xc, z, y); + } + while(xb < xbe); + while(xa < xae) { + y = (*xa & 0xffff) + borrow; + borrow = y >> 16; + Sign_Extend(borrow, y); + z = (*xa++ >> 16) + borrow; + borrow = z >> 16; + Sign_Extend(borrow, z); + Storeinc(xc, z, y); + } +#else + do { + y = *xa++ - *xb++ + borrow; + borrow = y >> 16; + Sign_Extend(borrow, y); + *xc++ = y & 0xffff; + } + while(xb < xbe); + while(xa < xae) { + y = *xa++ + borrow; + borrow = y >> 16; + Sign_Extend(borrow, y); + *xc++ = y & 0xffff; + } +#endif + while(!*--xc) + wa--; + c->wds = wa; + return c; + } + + static double +ulp +#ifdef KR_headers + (x) double x; +#else + (double x) +#endif +{ + register Long L; + double a; + + L = (word0(x) & Exp_mask) - (P-1)*Exp_msk1; +#ifndef Sudden_Underflow + if (L > 0) { +#endif +#ifdef IBM + L |= Exp_msk1 >> 4; +#endif + word0(a) = L; + word1(a) = 0; +#ifndef Sudden_Underflow + } + else { + L = -L >> Exp_shift; + if (L < Exp_shift) { + word0(a) = 0x80000 >> L; + word1(a) = 0; + } + else { + word0(a) = 0; + L -= Exp_shift; + word1(a) = L >= 31 ? 1 : 1 << 31 - L; + } + } +#endif + return a; + } + + static double +b2d +#ifdef KR_headers + (a, e) Bigint *a; int *e; +#else + (Bigint *a, int *e) +#endif +{ + ULong *xa, *xa0, w, y, z; + int k; + double d; +#ifdef VAX + ULong d0, d1; +#else +#define d0 word0(d) +#define d1 word1(d) +#endif + + xa0 = a->x; + xa = xa0 + a->wds; + y = *--xa; +#ifdef DEBUG + if (!y) Bug("zero y in b2d"); +#endif + k = hi0bits(y); + *e = 32 - k; +#ifdef Pack_32 + if (k < Ebits) { + d0 = Exp_1 | y >> Ebits - k; + w = xa > xa0 ? *--xa : 0; + d1 = y << (32-Ebits) + k | w >> Ebits - k; + goto ret_d; + } + z = xa > xa0 ? *--xa : 0; + if (k -= Ebits) { + d0 = Exp_1 | y << k | z >> 32 - k; + y = xa > xa0 ? *--xa : 0; + d1 = z << k | y >> 32 - k; + } + else { + d0 = Exp_1 | y; + d1 = z; + } +#else + if (k < Ebits + 16) { + z = xa > xa0 ? *--xa : 0; + d0 = Exp_1 | y << k - Ebits | z >> Ebits + 16 - k; + w = xa > xa0 ? *--xa : 0; + y = xa > xa0 ? *--xa : 0; + d1 = z << k + 16 - Ebits | w << k - Ebits | y >> 16 + Ebits - k; + goto ret_d; + } + z = xa > xa0 ? *--xa : 0; + w = xa > xa0 ? *--xa : 0; + k -= Ebits + 16; + d0 = Exp_1 | y << k + 16 | z << k | w >> 16 - k; + y = xa > xa0 ? *--xa : 0; + d1 = w << k + 16 | y << k; +#endif + ret_d: +#ifdef VAX + word0(d) = d0 >> 16 | d0 << 16; + word1(d) = d1 >> 16 | d1 << 16; +#else +#undef d0 +#undef d1 +#endif + return d; + } + + static Bigint * +d2b +#ifdef KR_headers + (d, e, bits) double d; int *e, *bits; +#else + (double d, int *e, int *bits) +#endif +{ + Bigint *b; + int de, i, k; + ULong *x, y, z; +#ifdef VAX + ULong d0, d1; + d0 = word0(d) >> 16 | word0(d) << 16; + d1 = word1(d) >> 16 | word1(d) << 16; +#else +#define d0 word0(d) +#define d1 word1(d) +#endif + +#ifdef Pack_32 + b = Balloc(1); +#else + b = Balloc(2); +#endif + x = b->x; + + z = d0 & Frac_mask; + d0 &= 0x7fffffff; /* clear sign bit, which we ignore */ +#ifdef Sudden_Underflow + de = (int)(d0 >> Exp_shift); +#ifndef IBM + z |= Exp_msk11; +#endif +#else + if (de = (int)(d0 >> Exp_shift)) + z |= Exp_msk1; +#endif +#ifdef Pack_32 + if (y = d1) { + if (k = lo0bits(&y)) { + x[0] = y | z << 32 - k; + z >>= k; + } + else + x[0] = y; + i = b->wds = (x[1] = z) ? 2 : 1; + } + else { +#ifdef DEBUG + if (!z) + Bug("Zero passed to d2b"); +#endif + k = lo0bits(&z); + x[0] = z; + i = b->wds = 1; + k += 32; + } +#else + if (y = d1) { + if (k = lo0bits(&y)) + if (k >= 16) { + x[0] = y | z << 32 - k & 0xffff; + x[1] = z >> k - 16 & 0xffff; + x[2] = z >> k; + i = 2; + } + else { + x[0] = y & 0xffff; + x[1] = y >> 16 | z << 16 - k & 0xffff; + x[2] = z >> k & 0xffff; + x[3] = z >> k+16; + i = 3; + } + else { + x[0] = y & 0xffff; + x[1] = y >> 16; + x[2] = z & 0xffff; + x[3] = z >> 16; + i = 3; + } + } + else { +#ifdef DEBUG + if (!z) + Bug("Zero passed to d2b"); +#endif + k = lo0bits(&z); + if (k >= 16) { + x[0] = z; + i = 0; + } + else { + x[0] = z & 0xffff; + x[1] = z >> 16; + i = 1; + } + k += 32; + } + while(!x[i]) + --i; + b->wds = i + 1; +#endif +#ifndef Sudden_Underflow + if (de) { +#endif +#ifdef IBM + *e = (de - Bias - (P-1) << 2) + k; + *bits = 4*P + 8 - k - hi0bits(word0(d) & Frac_mask); +#else + *e = de - Bias - (P-1) + k; + *bits = P - k; +#endif +#ifndef Sudden_Underflow + } + else { + *e = de - Bias - (P-1) + 1 + k; +#ifdef Pack_32 + *bits = 32*i - hi0bits(x[i-1]); +#else + *bits = (i+2)*16 - hi0bits(x[i]); +#endif + } +#endif + return b; + } +#undef d0 +#undef d1 + + static double +ratio +#ifdef KR_headers + (a, b) Bigint *a, *b; +#else + (Bigint *a, Bigint *b) +#endif +{ + double da, db; + int k, ka, kb; + + da = b2d(a, &ka); + db = b2d(b, &kb); +#ifdef Pack_32 + k = ka - kb + 32*(a->wds - b->wds); +#else + k = ka - kb + 16*(a->wds - b->wds); +#endif +#ifdef IBM + if (k > 0) { + word0(da) += (k >> 2)*Exp_msk1; + if (k &= 3) + da *= 1 << k; + } + else { + k = -k; + word0(db) += (k >> 2)*Exp_msk1; + if (k &= 3) + db *= 1 << k; + } +#else + if (k > 0) + word0(da) += k*Exp_msk1; + else { + k = -k; + word0(db) += k*Exp_msk1; + } +#endif + return da / db; + } + +static CONST double +tens[] = { + 1e0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9, + 1e10, 1e11, 1e12, 1e13, 1e14, 1e15, 1e16, 1e17, 1e18, 1e19, + 1e20, 1e21, 1e22 +#ifdef VAX + , 1e23, 1e24 +#endif + }; + +#ifdef IEEE_Arith +static CONST double bigtens[] = { 1e16, 1e32, 1e64, 1e128, 1e256 }; +static CONST double tinytens[] = { 1e-16, 1e-32, 1e-64, 1e-128, 1e-256 }; +#define n_bigtens 5 +#else +#ifdef IBM +static CONST double bigtens[] = { 1e16, 1e32, 1e64 }; +static CONST double tinytens[] = { 1e-16, 1e-32, 1e-64 }; +#define n_bigtens 3 +#else +static CONST double bigtens[] = { 1e16, 1e32 }; +static CONST double tinytens[] = { 1e-16, 1e-32 }; +#define n_bigtens 2 +#endif +#endif + + double +strtod +#ifdef KR_headers + (s00, se) CONST char *s00; char **se; +#else + (CONST char *s00, char **se) +#endif +{ + int bb2, bb5, bbe, bd2, bd5, bbbits, bs2, c, dsign, + e, e1, esign, i, j, k, nd, nd0, nf, nz, nz0, sign; + CONST char *s, *s0, *s1; + double aadj, aadj1, adj, rv, rv0; + Long L; + ULong y, z; + Bigint *bb, *bb1, *bd, *bd0, *bs, *delta; + +#ifndef KR_headers + CONST char decimal_point = localeconv()->decimal_point[0]; +#else + CONST char decimal_point = '.'; +#endif + + sign = nz0 = nz = 0; + rv = 0.; + + + for(s = s00; isspace((unsigned char) *s); s++) + ; + + if (*s == '-') { + sign = 1; + s++; + } else if (*s == '+') { + s++; + } + + if (*s == '\0') { + s = s00; + goto ret; + } + + if (*s == '0') { + nz0 = 1; + while(*++s == '0') ; + if (!*s) + goto ret; + } + s0 = s; + y = z = 0; + for(nd = nf = 0; (c = *s) >= '0' && c <= '9'; nd++, s++) + if (nd < 9) + y = 10*y + c - '0'; + else if (nd < 16) + z = 10*z + c - '0'; + nd0 = nd; + if (c == decimal_point) { + c = *++s; + if (!nd) { + for(; c == '0'; c = *++s) + nz++; + if (c > '0' && c <= '9') { + s0 = s; + nf += nz; + nz = 0; + goto have_dig; + } + goto dig_done; + } + for(; c >= '0' && c <= '9'; c = *++s) { + have_dig: + nz++; + if (c -= '0') { + nf += nz; + for(i = 1; i < nz; i++) + if (nd++ < 9) + y *= 10; + else if (nd <= DBL_DIG + 1) + z *= 10; + if (nd++ < 9) + y = 10*y + c; + else if (nd <= DBL_DIG + 1) + z = 10*z + c; + nz = 0; + } + } + } + dig_done: + e = 0; + if (c == 'e' || c == 'E') { + if (!nd && !nz && !nz0) { + s = s00; + goto ret; + } + s00 = s; + esign = 0; + switch(c = *++s) { + case '-': + esign = 1; + case '+': + c = *++s; + } + if (c >= '0' && c <= '9') { + while(c == '0') + c = *++s; + if (c > '0' && c <= '9') { + L = c - '0'; + s1 = s; + while((c = *++s) >= '0' && c <= '9') + L = 10*L + c - '0'; + if (s - s1 > 8 || L > 19999) + /* Avoid confusion from exponents + * so large that e might overflow. + */ + e = 19999; /* safe for 16 bit ints */ + else + e = (int)L; + if (esign) + e = -e; + } + else + e = 0; + } + else + s = s00; + } + if (!nd) { + if (!nz && !nz0) + s = s00; + goto ret; + } + e1 = e -= nf; + + /* Now we have nd0 digits, starting at s0, followed by a + * decimal point, followed by nd-nd0 digits. The number we're + * after is the integer represented by those digits times + * 10**e */ + + if (!nd0) + nd0 = nd; + k = nd < DBL_DIG + 1 ? nd : DBL_DIG + 1; + rv = y; + if (k > 9) + rv = tens[k - 9] * rv + z; + bd0 = 0; + if (nd <= DBL_DIG +#ifndef RND_PRODQUOT + && FLT_ROUNDS == 1 +#endif + ) { + if (!e) + goto ret; + if (e > 0) { + if (e <= Ten_pmax) { +#ifdef VAX + goto vax_ovfl_check; +#else + /* rv = */ rounded_product(rv, tens[e]); + goto ret; +#endif + } + i = DBL_DIG - nd; + if (e <= Ten_pmax + i) { + /* A fancier test would sometimes let us do + * this for larger i values. + */ + e -= i; + rv *= tens[i]; +#ifdef VAX + /* VAX exponent range is so narrow we must + * worry about overflow here... + */ + vax_ovfl_check: + word0(rv) -= P*Exp_msk1; + /* rv = */ rounded_product(rv, tens[e]); + if ((word0(rv) & Exp_mask) + > Exp_msk1*(DBL_MAX_EXP+Bias-1-P)) + goto ovfl; + word0(rv) += P*Exp_msk1; +#else + /* rv = */ rounded_product(rv, tens[e]); +#endif + goto ret; + } + } +#ifndef Inaccurate_Divide + else if (e >= -Ten_pmax) { + /* rv = */ rounded_quotient(rv, tens[-e]); + goto ret; + } +#endif + } + e1 += nd - k; + + /* Get starting approximation = rv * 10**e1 */ + + if (e1 > 0) { + if (i = e1 & 15) + rv *= tens[i]; + if (e1 &= ~15) { + if (e1 > DBL_MAX_10_EXP) { + ovfl: + errno = ERANGE; +#ifdef __STDC__ + rv = HUGE_VAL; +#else + /* Can't trust HUGE_VAL */ +#ifdef IEEE_Arith + word0(rv) = Exp_mask; + word1(rv) = 0; +#else + word0(rv) = Big0; + word1(rv) = Big1; +#endif +#endif + if (bd0) + goto retfree; + goto ret; + } + if (e1 >>= 4) { + for(j = 0; e1 > 1; j++, e1 >>= 1) + if (e1 & 1) + rv *= bigtens[j]; + /* The last multiplication could overflow. */ + word0(rv) -= P*Exp_msk1; + rv *= bigtens[j]; + if ((z = word0(rv) & Exp_mask) + > Exp_msk1*(DBL_MAX_EXP+Bias-P)) + goto ovfl; + if (z > Exp_msk1*(DBL_MAX_EXP+Bias-1-P)) { + /* set to largest number */ + /* (Can't trust DBL_MAX) */ + word0(rv) = Big0; + word1(rv) = Big1; + } + else + word0(rv) += P*Exp_msk1; + } + + } + } + else if (e1 < 0) { + e1 = -e1; + if (i = e1 & 15) + rv /= tens[i]; + if (e1 &= ~15) { + e1 >>= 4; + if (e1 >= 1 << n_bigtens) + goto undfl; + for(j = 0; e1 > 1; j++, e1 >>= 1) + if (e1 & 1) + rv *= tinytens[j]; + /* The last multiplication could underflow. */ + rv0 = rv; + rv *= tinytens[j]; + if (!rv) { + rv = 2.*rv0; + rv *= tinytens[j]; + if (!rv) { + undfl: + rv = 0.; + errno = ERANGE; + if (bd0) + goto retfree; + goto ret; + } + word0(rv) = Tiny0; + word1(rv) = Tiny1; + /* The refinement below will clean + * this approximation up. + */ + } + } + } + + /* Now the hard part -- adjusting rv to the correct value.*/ + + /* Put digits into bd: true value = bd * 10^e */ + + bd0 = s2b(s0, nd0, nd, y); + + for(;;) { + bd = Balloc(bd0->k); + Bcopy(bd, bd0); + bb = d2b(rv, &bbe, &bbbits); /* rv = bb * 2^bbe */ + bs = i2b(1); + + if (e >= 0) { + bb2 = bb5 = 0; + bd2 = bd5 = e; + } + else { + bb2 = bb5 = -e; + bd2 = bd5 = 0; + } + if (bbe >= 0) + bb2 += bbe; + else + bd2 -= bbe; + bs2 = bb2; +#ifdef Sudden_Underflow +#ifdef IBM + j = 1 + 4*P - 3 - bbbits + ((bbe + bbbits - 1) & 3); +#else + j = P + 1 - bbbits; +#endif +#else + i = bbe + bbbits - 1; /* logb(rv) */ + if (i < Emin) /* denormal */ + j = bbe + (P-Emin); + else + j = P + 1 - bbbits; +#endif + bb2 += j; + bd2 += j; + i = bb2 < bd2 ? bb2 : bd2; + if (i > bs2) + i = bs2; + if (i > 0) { + bb2 -= i; + bd2 -= i; + bs2 -= i; + } + if (bb5 > 0) { + bs = pow5mult(bs, bb5); + bb1 = mult(bs, bb); + Bfree(bb); + bb = bb1; + } + if (bb2 > 0) + bb = lshift(bb, bb2); + if (bd5 > 0) + bd = pow5mult(bd, bd5); + if (bd2 > 0) + bd = lshift(bd, bd2); + if (bs2 > 0) + bs = lshift(bs, bs2); + delta = diff(bb, bd); + dsign = delta->sign; + delta->sign = 0; + i = cmp(delta, bs); + if (i < 0) { + /* Error is less than half an ulp -- check for + * special case of mantissa a power of two. + */ + if (dsign || word1(rv) || word0(rv) & Bndry_mask) + break; + delta = lshift(delta,Log2P); + if (cmp(delta, bs) > 0) + goto drop_down; + break; + } + if (i == 0) { + /* exactly half-way between */ + if (dsign) { + if ((word0(rv) & Bndry_mask1) == Bndry_mask1 + && word1(rv) == 0xffffffff) { + /*boundary case -- increment exponent*/ + word0(rv) = (word0(rv) & Exp_mask) + + Exp_msk1 +#ifdef IBM + | Exp_msk1 >> 4 +#endif + ; + word1(rv) = 0; + break; + } + } + else if (!(word0(rv) & Bndry_mask) && !word1(rv)) { + drop_down: + /* boundary case -- decrement exponent */ +#ifdef Sudden_Underflow + L = word0(rv) & Exp_mask; +#ifdef IBM + if (L < Exp_msk1) +#else + if (L <= Exp_msk1) +#endif + goto undfl; + L -= Exp_msk1; +#else + L = (word0(rv) & Exp_mask) - Exp_msk1; +#endif + word0(rv) = L | Bndry_mask1; + word1(rv) = 0xffffffff; +#ifdef IBM + goto cont; +#else + break; +#endif + } +#ifndef ROUND_BIASED + if (!(word1(rv) & LSB)) + break; +#endif + if (dsign) + rv += ulp(rv); +#ifndef ROUND_BIASED + else { + rv -= ulp(rv); +#ifndef Sudden_Underflow + if (!rv) + goto undfl; +#endif + } +#endif + break; + } + if ((aadj = ratio(delta, bs)) <= 2.) { + if (dsign) + aadj = aadj1 = 1.; + else if (word1(rv) || word0(rv) & Bndry_mask) { +#ifndef Sudden_Underflow + if (word1(rv) == Tiny1 && !word0(rv)) + goto undfl; +#endif + aadj = 1.; + aadj1 = -1.; + } + else { + /* special case -- power of FLT_RADIX to be */ + /* rounded down... */ + + if (aadj < 2./FLT_RADIX) + aadj = 1./FLT_RADIX; + else + aadj *= 0.5; + aadj1 = -aadj; + } + } + else { + aadj *= 0.5; + aadj1 = dsign ? aadj : -aadj; +#ifdef Check_FLT_ROUNDS + switch(FLT_ROUNDS) { + case 2: /* towards +infinity */ + aadj1 -= 0.5; + break; + case 0: /* towards 0 */ + case 3: /* towards -infinity */ + aadj1 += 0.5; + } +#else + if (FLT_ROUNDS == 0) + aadj1 += 0.5; +#endif + } + y = word0(rv) & Exp_mask; + + /* Check for overflow */ + + if (y == Exp_msk1*(DBL_MAX_EXP+Bias-1)) { + rv0 = rv; + word0(rv) -= P*Exp_msk1; + adj = aadj1 * ulp(rv); + rv += adj; + if ((word0(rv) & Exp_mask) >= + Exp_msk1*(DBL_MAX_EXP+Bias-P)) { + if (word0(rv0) == Big0 && word1(rv0) == Big1) + goto ovfl; + word0(rv) = Big0; + word1(rv) = Big1; + goto cont; + } + else + word0(rv) += P*Exp_msk1; + } + else { +#ifdef Sudden_Underflow + if ((word0(rv) & Exp_mask) <= P*Exp_msk1) { + rv0 = rv; + word0(rv) += P*Exp_msk1; + adj = aadj1 * ulp(rv); + rv += adj; +#ifdef IBM + if ((word0(rv) & Exp_mask) < P*Exp_msk1) +#else + if ((word0(rv) & Exp_mask) <= P*Exp_msk1) +#endif + { + if (word0(rv0) == Tiny0 + && word1(rv0) == Tiny1) + goto undfl; + word0(rv) = Tiny0; + word1(rv) = Tiny1; + goto cont; + } + else + word0(rv) -= P*Exp_msk1; + } + else { + adj = aadj1 * ulp(rv); + rv += adj; + } +#else + /* Compute adj so that the IEEE rounding rules will + * correctly round rv + adj in some half-way cases. + * If rv * ulp(rv) is denormalized (i.e., + * y <= (P-1)*Exp_msk1), we must adjust aadj to avoid + * trouble from bits lost to denormalization; + * example: 1.2e-307 . + */ + if (y <= (P-1)*Exp_msk1 && aadj >= 1.) { + aadj1 = (double)(int)(aadj + 0.5); + if (!dsign) + aadj1 = -aadj1; + } + adj = aadj1 * ulp(rv); + rv += adj; +#endif + } + z = word0(rv) & Exp_mask; + if (y == z) { + /* Can we stop now? */ + L = aadj; + aadj -= L; + /* The tolerances below are conservative. */ + if (dsign || word1(rv) || word0(rv) & Bndry_mask) { + if (aadj < .4999999 || aadj > .5000001) + break; + } + else if (aadj < .4999999/FLT_RADIX) + break; + } + cont: + Bfree(bb); + Bfree(bd); + Bfree(bs); + Bfree(delta); + } + retfree: + Bfree(bb); + Bfree(bd); + Bfree(bs); + Bfree(bd0); + Bfree(delta); + ret: + if (se) + *se = (char *)s; + return sign ? -rv : rv; + } + + static int +quorem +#ifdef KR_headers + (b, S) Bigint *b, *S; +#else + (Bigint *b, Bigint *S) +#endif +{ + int n; + Long borrow, y; + ULong carry, q, ys; + ULong *bx, *bxe, *sx, *sxe; +#ifdef Pack_32 + Long z; + ULong si, zs; +#endif + + n = S->wds; +#ifdef DEBUG + /*debug*/ if (b->wds > n) + /*debug*/ Bug("oversize b in quorem"); +#endif + if (b->wds < n) + return 0; + sx = S->x; + sxe = sx + --n; + bx = b->x; + bxe = bx + n; + q = *bxe / (*sxe + 1); /* ensure q <= true quotient */ +#ifdef DEBUG + /*debug*/ if (q > 9) + /*debug*/ Bug("oversized quotient in quorem"); +#endif + if (q) { + borrow = 0; + carry = 0; + do { +#ifdef Pack_32 + si = *sx++; + ys = (si & 0xffff) * q + carry; + zs = (si >> 16) * q + (ys >> 16); + carry = zs >> 16; + y = (*bx & 0xffff) - (ys & 0xffff) + borrow; + borrow = y >> 16; + Sign_Extend(borrow, y); + z = (*bx >> 16) - (zs & 0xffff) + borrow; + borrow = z >> 16; + Sign_Extend(borrow, z); + Storeinc(bx, z, y); +#else + ys = *sx++ * q + carry; + carry = ys >> 16; + y = *bx - (ys & 0xffff) + borrow; + borrow = y >> 16; + Sign_Extend(borrow, y); + *bx++ = y & 0xffff; +#endif + } + while(sx <= sxe); + if (!*bxe) { + bx = b->x; + while(--bxe > bx && !*bxe) + --n; + b->wds = n; + } + } + if (cmp(b, S) >= 0) { + q++; + borrow = 0; + carry = 0; + bx = b->x; + sx = S->x; + do { +#ifdef Pack_32 + si = *sx++; + ys = (si & 0xffff) + carry; + zs = (si >> 16) + (ys >> 16); + carry = zs >> 16; + y = (*bx & 0xffff) - (ys & 0xffff) + borrow; + borrow = y >> 16; + Sign_Extend(borrow, y); + z = (*bx >> 16) - (zs & 0xffff) + borrow; + borrow = z >> 16; + Sign_Extend(borrow, z); + Storeinc(bx, z, y); +#else + ys = *sx++ + carry; + carry = ys >> 16; + y = *bx - (ys & 0xffff) + borrow; + borrow = y >> 16; + Sign_Extend(borrow, y); + *bx++ = y & 0xffff; +#endif + } + while(sx <= sxe); + bx = b->x; + bxe = bx + n; + if (!*bxe) { + while(--bxe > bx && !*bxe) + --n; + b->wds = n; + } + } + return q; + } + +/* 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]. + * + * Modifications: + * 1. Rather than iterating, we use a simple numeric overestimate + * to determine k = floor(log10(d)). We scale relevant + * quantities using O(log2(k)) rather than O(k) multiplications. + * 2. For some modes > 2 (corresponding to ecvt and fcvt), we don't + * try to generate digits strictly left to right. Instead, we + * compute with fewer bits and propagate the carry if necessary + * when rounding the final digit up. This is often faster. + * 3. Under the assumption that input will be rounded nearest, + * mode 0 renders 1e23 as 1e23 rather than 9.999999999999999e22. + * That is, we allow equality in stopping tests when the + * round-nearest rule will give the same floating-point value + * as would satisfaction of the stopping test with strict + * inequality. + * 4. We remove common factors of powers of 2 from relevant + * quantities. + * 5. When converting floating-point integers less than 1e16, + * we use floating-point arithmetic rather than resorting + * to multiple-precision integers. + * 6. When asked to produce fewer than 15 digits, we first try + * to get by with floating-point arithmetic; we resort to + * multiple-precision integer arithmetic only if we cannot + * guarantee that the floating-point calculation has given + * the correctly rounded result. For k requested digits and + * "uniformly" distributed input, the probability is + * something like 10^(k-15) that we must resort to the Long + * calculation. + */ + + char * +__dtoa +#ifdef KR_headers + (d, mode, ndigits, decpt, sign, rve) + double d; int mode, ndigits, *decpt, *sign; char **rve, char **resultp; +#else + (double d, int mode, int ndigits, int *decpt, int *sign, char **rve, char **resultp) +#endif +{ + /* Arguments ndigits, decpt, sign are similar to those + of ecvt and fcvt; trailing zeros are suppressed from + the returned string. If not null, *rve is set to point + to the end of the return value. If d is +-Infinity or NaN, + then *decpt is set to 9999. + + mode: + 0 ==> shortest string that yields d when read in + and rounded to nearest. + 1 ==> like 0, but with Steele & White stopping rule; + e.g. with IEEE P754 arithmetic , mode 0 gives + 1e23 whereas mode 1 gives 9.999999999999999e22. + 2 ==> max(1,ndigits) significant digits. This gives a + return value similar to that of ecvt, except + that trailing zeros are suppressed. + 3 ==> through ndigits past the decimal point. This + gives a return value similar to that from fcvt, + except that trailing zeros are suppressed, and + ndigits can be negative. + 4-9 should give the same return values as 2-3, i.e., + 4 <= mode <= 9 ==> same return as mode + 2 + (mode & 1). These modes are mainly for + debugging; often they run slower but sometimes + faster than modes 2-3. + 4,5,8,9 ==> left-to-right digit generation. + 6-9 ==> don't try fast floating-point estimate + (if applicable). + + Values of mode other than 0-9 are treated as mode 0. + + Sufficient space is allocated to the return value + to hold the suppressed trailing zeros. + */ + + int bbits, b2, b5, be, dig, i, ieps, ilim, ilim0, ilim1, + j, j1, k, k0, k_check, leftright, m2, m5, s2, s5, + spec_case, try_quick; + Long L; +#ifndef Sudden_Underflow + int denorm; + ULong x; +#endif + Bigint *b, *b1, *delta, *mlo, *mhi, *S; + double d2, ds, eps; + char *s, *s0; + + if (word0(d) & Sign_bit) { + /* set sign for everything, including 0's and NaNs */ + *sign = 1; + word0(d) &= ~Sign_bit; /* clear sign bit */ + } + else + *sign = 0; + +#if defined(IEEE_Arith) + defined(VAX) +#ifdef IEEE_Arith + if ((word0(d) & Exp_mask) == Exp_mask) +#else + if (word0(d) == 0x8000) +#endif + { + /* Infinity or NaN */ + *decpt = 9999; + s = +#ifdef IEEE_Arith + !word1(d) && !(word0(d) & 0xfffff) ? "Infinity" : +#endif + "NaN"; + if (rve) + *rve = +#ifdef IEEE_Arith + s[3] ? s + 8 : +#endif + s + 3; + return s; + } +#endif +#ifdef IBM + d += 0; /* normalize */ +#endif + if (!d) { + *decpt = 1; + s = "0"; + if (rve) + *rve = s + 1; + return s; + } + + b = d2b(d, &be, &bbits); +#ifdef Sudden_Underflow + i = (int)(word0(d) >> Exp_shift1 & (Exp_mask>>Exp_shift1)); +#else + if (i = (int)(word0(d) >> Exp_shift1 & (Exp_mask>>Exp_shift1))) { +#endif + d2 = d; + word0(d2) &= Frac_mask1; + word0(d2) |= Exp_11; +#ifdef IBM + if (j = 11 - hi0bits(word0(d2) & Frac_mask)) + d2 /= 1 << j; +#endif + + /* log(x) ~=~ log(1.5) + (x-1.5)/1.5 + * log10(x) = log(x) / log(10) + * ~=~ log(1.5)/log(10) + (x-1.5)/(1.5*log(10)) + * log10(d) = (i-Bias)*log(2)/log(10) + log10(d2) + * + * This suggests computing an approximation k to log10(d) by + * + * k = (i - Bias)*0.301029995663981 + * + ( (d2-1.5)*0.289529654602168 + 0.176091259055681 ); + * + * We want k to be too large rather than too small. + * The error in the first-order Taylor series approximation + * is in our favor, so we just round up the constant enough + * to compensate for any error in the multiplication of + * (i - Bias) by 0.301029995663981; since |i - Bias| <= 1077, + * and 1077 * 0.30103 * 2^-52 ~=~ 7.2e-14, + * adding 1e-13 to the constant term more than suffices. + * Hence we adjust the constant term to 0.1760912590558. + * (We could get a more accurate k by invoking log10, + * but this is probably not worthwhile.) + */ + + i -= Bias; +#ifdef IBM + i <<= 2; + i += j; +#endif +#ifndef Sudden_Underflow + denorm = 0; + } + else { + /* d is denormalized */ + + i = bbits + be + (Bias + (P-1) - 1); + x = i > 32 ? word0(d) << 64 - i | word1(d) >> i - 32 + : word1(d) << 32 - i; + d2 = x; + word0(d2) -= 31*Exp_msk1; /* adjust exponent */ + i -= (Bias + (P-1) - 1) + 1; + denorm = 1; + } +#endif + ds = (d2-1.5)*0.289529654602168 + 0.1760912590558 + i*0.301029995663981; + k = (int)ds; + if (ds < 0. && ds != k) + k--; /* want k = floor(ds) */ + k_check = 1; + if (k >= 0 && k <= Ten_pmax) { + if (d < tens[k]) + k--; + k_check = 0; + } + j = bbits - i - 1; + if (j >= 0) { + b2 = 0; + s2 = j; + } + else { + b2 = -j; + s2 = 0; + } + if (k >= 0) { + b5 = 0; + s5 = k; + s2 += k; + } + else { + b2 -= k; + b5 = -k; + s5 = 0; + } + if (mode < 0 || mode > 9) + mode = 0; + try_quick = 1; + if (mode > 5) { + mode -= 4; + try_quick = 0; + } + leftright = 1; + switch(mode) { + case 0: + case 1: + ilim = ilim1 = -1; + i = 18; + ndigits = 0; + break; + case 2: + leftright = 0; + /* no break */ + case 4: + if (ndigits <= 0) + ndigits = 1; + ilim = ilim1 = i = ndigits; + break; + case 3: + leftright = 0; + /* no break */ + case 5: + i = ndigits + k + 1; + ilim = i; + ilim1 = i - 1; + if (i <= 0) + i = 1; + } + *resultp = (char *) malloc(i + 1); + s = s0 = *resultp; + + if (ilim >= 0 && ilim <= Quick_max && try_quick) { + + /* Try to get by with floating-point arithmetic. */ + + i = 0; + d2 = d; + k0 = k; + ilim0 = ilim; + ieps = 2; /* conservative */ + if (k > 0) { + ds = tens[k&0xf]; + j = k >> 4; + if (j & Bletch) { + /* prevent overflows */ + j &= Bletch - 1; + d /= bigtens[n_bigtens-1]; + ieps++; + } + for(; j; j >>= 1, i++) + if (j & 1) { + ieps++; + ds *= bigtens[i]; + } + d /= ds; + } + else if (j1 = -k) { + d *= tens[j1 & 0xf]; + for(j = j1 >> 4; j; j >>= 1, i++) + if (j & 1) { + ieps++; + d *= bigtens[i]; + } + } + if (k_check && d < 1. && ilim > 0) { + if (ilim1 <= 0) + goto fast_failed; + ilim = ilim1; + k--; + d *= 10.; + ieps++; + } + eps = ieps*d + 7.; + word0(eps) -= (P-1)*Exp_msk1; + if (ilim == 0) { + S = mhi = 0; + d -= 5.; + if (d > eps) + goto one_digit; + if (d < -eps) + goto no_digits; + goto fast_failed; + } +#ifndef No_leftright + if (leftright) { + /* Use Steele & White method of only + * generating digits needed. + */ + eps = 0.5/tens[ilim-1] - eps; + for(i = 0;;) { + L = d; + d -= L; + *s++ = '0' + (int)L; + if (d < eps) + goto ret1; + if (1. - d < eps) + goto bump_up; + if (++i >= ilim) + break; + eps *= 10.; + d *= 10.; + } + } + else { +#endif + /* Generate ilim digits, then fix them up. */ + eps *= tens[ilim-1]; + for(i = 1;; i++, d *= 10.) { + L = d; + d -= L; + *s++ = '0' + (int)L; + if (i == ilim) { + if (d > 0.5 + eps) + goto bump_up; + else if (d < 0.5 - eps) { + while(*--s == '0'); + s++; + goto ret1; + } + break; + } + } +#ifndef No_leftright + } +#endif + fast_failed: + s = s0; + d = d2; + k = k0; + ilim = ilim0; + } + + /* Do we have a "small" integer? */ + + if (be >= 0 && k <= Int_max) { + /* Yes. */ + ds = tens[k]; + if (ndigits < 0 && ilim <= 0) { + S = mhi = 0; + if (ilim < 0 || d <= 5*ds) + goto no_digits; + goto one_digit; + } + for(i = 1;; i++) { + L = d / ds; + d -= L*ds; +#ifdef Check_FLT_ROUNDS + /* If FLT_ROUNDS == 2, L will usually be high by 1 */ + if (d < 0) { + L--; + d += ds; + } +#endif + *s++ = '0' + (int)L; + if (i == ilim) { + d += d; + if (d > ds || d == ds && L & 1) { + bump_up: + while(*--s == '9') + if (s == s0) { + k++; + *s = '0'; + break; + } + ++*s++; + } + break; + } + if (!(d *= 10.)) + break; + } + goto ret1; + } + + m2 = b2; + m5 = b5; + mhi = mlo = 0; + if (leftright) { + if (mode < 2) { + i = +#ifndef Sudden_Underflow + denorm ? be + (Bias + (P-1) - 1 + 1) : +#endif +#ifdef IBM + 1 + 4*P - 3 - bbits + ((bbits + be - 1) & 3); +#else + 1 + P - bbits; +#endif + } + else { + j = ilim - 1; + if (m5 >= j) + m5 -= j; + else { + s5 += j -= m5; + b5 += j; + m5 = 0; + } + if ((i = ilim) < 0) { + m2 -= i; + i = 0; + } + } + b2 += i; + s2 += i; + mhi = i2b(1); + } + if (m2 > 0 && s2 > 0) { + i = m2 < s2 ? m2 : s2; + b2 -= i; + m2 -= i; + s2 -= i; + } + if (b5 > 0) { + if (leftright) { + if (m5 > 0) { + mhi = pow5mult(mhi, m5); + b1 = mult(mhi, b); + Bfree(b); + b = b1; + } + if (j = b5 - m5) + b = pow5mult(b, j); + } + else + b = pow5mult(b, b5); + } + S = i2b(1); + if (s5 > 0) + S = pow5mult(S, s5); + + /* Check for special case that d is a normalized power of 2. */ + + if (mode < 2) { + if (!word1(d) && !(word0(d) & Bndry_mask) +#ifndef Sudden_Underflow + && word0(d) & Exp_mask +#endif + ) { + /* The special case */ + b2 += Log2P; + s2 += Log2P; + spec_case = 1; + } + else + spec_case = 0; + } + + /* Arrange for convenient computation of quotients: + * shift left if necessary so divisor has 4 leading 0 bits. + * + * Perhaps we should just compute leading 28 bits of S once + * and for all and pass them and a shift to quorem, so it + * can do shifts and ors to compute the numerator for q. + */ +#ifdef Pack_32 + if (i = ((s5 ? 32 - hi0bits(S->x[S->wds-1]) : 1) + s2) & 0x1f) + i = 32 - i; +#else + if (i = ((s5 ? 32 - hi0bits(S->x[S->wds-1]) : 1) + s2) & 0xf) + i = 16 - i; +#endif + if (i > 4) { + i -= 4; + b2 += i; + m2 += i; + s2 += i; + } + else if (i < 4) { + i += 28; + b2 += i; + m2 += i; + s2 += i; + } + if (b2 > 0) + b = lshift(b, b2); + if (s2 > 0) + S = lshift(S, s2); + if (k_check) { + if (cmp(b,S) < 0) { + k--; + b = multadd(b, 10, 0); /* we botched the k estimate */ + if (leftright) + mhi = multadd(mhi, 10, 0); + ilim = ilim1; + } + } + if (ilim <= 0 && mode > 2) { + if (ilim < 0 || cmp(b,S = multadd(S,5,0)) <= 0) { + /* no digits, fcvt style */ + no_digits: + k = -1 - ndigits; + goto ret; + } + one_digit: + *s++ = '1'; + k++; + goto ret; + } + if (leftright) { + if (m2 > 0) + mhi = lshift(mhi, m2); + + /* Compute mlo -- check for special case + * that d is a normalized power of 2. + */ + + mlo = mhi; + if (spec_case) { + mhi = Balloc(mhi->k); + Bcopy(mhi, mlo); + mhi = lshift(mhi, Log2P); + } + + for(i = 1;;i++) { + dig = quorem(b,S) + '0'; + /* Do we yet have the shortest decimal string + * that will round to d? + */ + j = cmp(b, mlo); + delta = diff(S, mhi); + j1 = delta->sign ? 1 : cmp(b, delta); + Bfree(delta); +#ifndef ROUND_BIASED + if (j1 == 0 && !mode && !(word1(d) & 1)) { + if (dig == '9') + goto round_9_up; + if (j > 0) + dig++; + *s++ = dig; + goto ret; + } +#endif + if (j < 0 || j == 0 && !mode +#ifndef ROUND_BIASED + && !(word1(d) & 1) +#endif + ) { + if (j1 > 0) { + b = lshift(b, 1); + j1 = cmp(b, S); + if ((j1 > 0 || j1 == 0 && dig & 1) + && dig++ == '9') + goto round_9_up; + } + *s++ = dig; + goto ret; + } + if (j1 > 0) { + if (dig == '9') { /* possible if i == 1 */ + round_9_up: + *s++ = '9'; + goto roundoff; + } + *s++ = dig + 1; + goto ret; + } + *s++ = dig; + if (i == ilim) + break; + b = multadd(b, 10, 0); + if (mlo == mhi) + mlo = mhi = multadd(mhi, 10, 0); + else { + mlo = multadd(mlo, 10, 0); + mhi = multadd(mhi, 10, 0); + } + } + } + else + for(i = 1;; i++) { + *s++ = dig = quorem(b,S) + '0'; + if (i >= ilim) + break; + b = multadd(b, 10, 0); + } + + /* Round off last digit */ + + b = lshift(b, 1); + j = cmp(b, S); + if (j > 0 || j == 0 && dig & 1) { + roundoff: + while(*--s == '9') + if (s == s0) { + k++; + *s++ = '1'; + goto ret; + } + ++*s++; + } + else { + while(*--s == '0'); + s++; + } + ret: + Bfree(S); + if (mhi) { + if (mlo && mlo != mhi) + Bfree(mlo); + Bfree(mhi); + } + ret1: + Bfree(b); + if (s == s0) { /* don't return empty string */ + *s++ = '0'; + k = 0; + } + *s = 0; + *decpt = k + 1; + if (rve) + *rve = s; + return s0; + } +#ifdef __cplusplus +} +#endif diff --git a/stdlib/strtol.3 b/stdlib/strtol.3 new file mode 100644 index 0000000..0033f4e --- /dev/null +++ b/stdlib/strtol.3 @@ -0,0 +1,207 @@ +.\" 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.14 2001/09/11 09:39:23 ru Exp $ +.\" +.Dd June 4, 1993 +.Dt STRTOL 3 +.Os +.Sh NAME +.Nm strtol , strtoll , strtoq +.Nd "convert a string value to a long, long long, or quad_t integer" +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In stdlib.h +.In limits.h +.Ft long +.Fn strtol "const char *nptr" "char **endptr" "int base" +.Ft long long +.Fn strtoll "const char *nptr" "char **endptr" "int base" +.In sys/types.h +.In stdlib.h +.In limits.h +.Ft quad_t +.Fn strtoq "const char *nptr" "char **endptr" "int base" +.Sh DESCRIPTION +The +.Fn strtol +function +converts the string in +.Fa nptr +to a +.Em long +value. +The +.Fn strtoll +function +converts the string in +.Fa nptr +to a +.Em long long +value. +The +.Fn strtoq +function +converts the string in +.Fa nptr +to a +.Em quad_t +value. +The conversion is done according to the given +.Fa base , +which must be between 2 and 36 inclusive, +or be the special value 0. +.Pp +The string may begin with an arbitrary amount of white space +(as determined by +.Xr isspace 3 ) +followed by a single optional +.Ql + +or +.Ql - +sign. +If +.Fa base +is zero or 16, +the string may then include a +.Ql 0x +prefix, +and the number will be read in base 16; otherwise, a zero +.Fa base +is taken as 10 (decimal) unless the next character is +.Ql 0 , +in which case it is taken as 8 (octal). +.Pp +The remainder of the string is converted to a +.Em long +value in the obvious manner, +stopping at the first character which is not a valid digit +in the given base. +(In bases above 10, the letter +.Ql A +in either upper or lower case +represents 10, +.Ql B +represents 11, and so forth, with +.Ql Z +representing 35.) +.Pp +If +.Fa endptr +is non nil, +.Fn strtol +stores the address of the first invalid character in +.Fa *endptr . +If there were no digits at all, however, +.Fn strtol +stores the original value of +.Fa nptr +in +.Fa *endptr . +(Thus, if +.Fa *nptr +is not +.Ql \e0 +but +.Fa **endptr +is +.Ql \e0 +on return, the entire string was valid.) +.Sh RETURN VALUES +The +.Fn strtol +or +.Fn strtoll +function +returns the result of the conversion, +unless the value would underflow or overflow. +If no conversion could be performed, 0 is returned and +the global variable +.Va errno +is set to +.Er EINVAL . +If an underflow occurs, +.Fn strtol +returns +.Dv LONG_MIN . +If an overflow occurs, +.Fn strtol +returns +.Dv LONG_MAX . +If an underflow occurs, +.Fn strtoll +returns +.Dv LLONG_MIN . +If an overflow occurs, +.Fn strtoll +returns +.Dv LLONG_MAX . +In all cases, +.Va errno +is set to +.Er ERANGE . +.Sh ERRORS +.Bl -tag -width Er +.It Bq Er EINVAL +The value of +.Fa base +is not supported or +no conversion could be performed. +.It Bq Er ERANGE +The given string was out of range; the value converted has been clamped. +.El +.Sh SEE ALSO +.Xr atof 3 , +.Xr atoi 3 , +.Xr atol 3 , +.Xr strtod 3 , +.Xr strtoul 3 +.Sh STANDARDS +The +.Fn strtol +function +conforms to +.St -isoC . +The +.Fn strtoll +function +conforms to +.St -isoC-99 . +The +.Bx +.Fn strtoq +function is deprecated. diff --git a/stdlib/strtol.c b/stdlib/strtol.c new file mode 100644 index 0000000..ad8302d --- /dev/null +++ b/stdlib/strtol.c @@ -0,0 +1,147 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 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 +#include +#include +#include + + +/* + * Convert a string to a long integer. + * + * Ignores `locale' stuff. Assumes that the upper and lower case + * alphabets and digits are each contiguous. + */ +long +strtol(nptr, endptr, base) + const char *nptr; + char **endptr; + register int base; +{ + register const char *s = nptr; + register unsigned long acc; + register int c; + register unsigned long cutoff; + register int neg = 0, any, cutlim; + + /* + * Skip white space and pick up leading +/- sign if any. + * If base is 0, allow 0x for hex and 0 for octal, else + * assume decimal; if base is already 16, allow 0x. + */ + do { + c = *s++; + } while (isspace(c)); + if (c == '-') { + neg = 1; + c = *s++; + } else if (c == '+') + c = *s++; + if ((base == 0 || base == 16) && + c == '0' && (*s == 'x' || *s == 'X')) { + c = s[1]; + s += 2; + base = 16; + } + if (base == 0) + base = c == '0' ? 8 : 10; + + /* + * Compute the cutoff value between legal numbers and illegal + * numbers. That is the largest legal value, divided by the + * base. An input number that is greater than this value, if + * followed by a legal input character, is too big. One that + * is equal to this value may be valid or not; the limit + * between valid and invalid numbers is then based on the last + * digit. For instance, if the range for longs is + * [-2147483648..2147483647] and the input base is 10, + * cutoff will be set to 214748364 and cutlim to either + * 7 (neg==0) or 8 (neg==1), meaning that if we have accumulated + * a value > 214748364, or equal but the next digit is > 7 (or 8), + * the number is too big, and we will return a range error. + * + * Set any if any `digits' consumed; make it negative to indicate + * overflow. + */ + cutoff = neg ? -(unsigned long)LONG_MIN : LONG_MAX; + cutlim = cutoff % (unsigned long)base; + cutoff /= (unsigned long)base; + for (acc = 0, any = 0;; c = *s++) { + if (isdigit(c)) + c -= '0'; + else if (isalpha(c)) + c -= isupper(c) ? 'A' - 10 : 'a' - 10; + else + break; + if (c >= base) + break; + if (any < 0 || acc > cutoff || acc == cutoff && c > cutlim) + any = -1; + else { + any = 1; + acc *= base; + acc += c; + } + } + if (any < 0) { + acc = neg ? LONG_MIN : LONG_MAX; + errno = ERANGE; + } else if (neg) + acc = -acc; + if (endptr != 0) + *endptr = (char *)(any ? s - 1 : nptr); + return (acc); +} diff --git a/stdlib/strtoll.c b/stdlib/strtoll.c new file mode 100644 index 0000000..41a16c6 --- /dev/null +++ b/stdlib/strtoll.c @@ -0,0 +1,144 @@ +/*- + * 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[] = "@(#)strtoq.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ + +#if defined(LIBC_SCCS) && !defined(lint) +static const char rcsid[] = + "$FreeBSD: src/lib/libc/stdlib/strtoll.c,v 1.5.2.1 2001/03/02 09:45:20 obrien Exp $"; +#endif + +#include + +#include +#include +#include +#include + +/* + * Convert a string to a long long integer. + * + * Ignores `locale' stuff. Assumes that the upper and lower case + * alphabets and digits are each contiguous. + */ +long long +strtoll(nptr, endptr, base) + const char *nptr; + char **endptr; + register int base; +{ + register const char *s; + register unsigned long long acc; + register unsigned char c; + register unsigned long long qbase, cutoff; + register int neg, any, cutlim; + + /* + * Skip white space and pick up leading +/- sign if any. + * If base is 0, allow 0x for hex and 0 for octal, else + * assume decimal; if base is already 16, allow 0x. + */ + s = nptr; + do { + c = *s++; + } while (isspace(c)); + if (c == '-') { + neg = 1; + c = *s++; + } else { + neg = 0; + if (c == '+') + c = *s++; + } + if ((base == 0 || base == 16) && + c == '0' && (*s == 'x' || *s == 'X')) { + c = s[1]; + s += 2; + base = 16; + } + if (base == 0) + base = c == '0' ? 8 : 10; + + /* + * Compute the cutoff value between legal numbers and illegal + * numbers. That is the largest legal value, divided by the + * base. An input number that is greater than this value, if + * followed by a legal input character, is too big. One that + * is equal to this value may be valid or not; the limit + * between valid and invalid numbers is then based on the last + * digit. For instance, if the range for quads is + * [-9223372036854775808..9223372036854775807] and the input base + * is 10, cutoff will be set to 922337203685477580 and cutlim to + * either 7 (neg==0) or 8 (neg==1), meaning that if we have + * accumulated a value > 922337203685477580, or equal but the + * next digit is > 7 (or 8), the number is too big, and we will + * return a range error. + * + * Set any if any `digits' consumed; make it negative to indicate + * overflow. + */ + qbase = (unsigned)base; + cutoff = neg ? (unsigned long long)-(LLONG_MIN + LLONG_MAX) + LLONG_MAX + : LLONG_MAX; + cutlim = cutoff % qbase; + cutoff /= qbase; + for (acc = 0, any = 0;; c = *s++) { + if (!isascii(c)) + break; + if (isdigit(c)) + c -= '0'; + else if (isalpha(c)) + c -= isupper(c) ? 'A' - 10 : 'a' - 10; + else + break; + if (c >= base) + break; + if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim)) + any = -1; + else { + any = 1; + acc *= qbase; + acc += c; + } + } + if (any < 0) { + acc = neg ? LLONG_MIN : LLONG_MAX; + errno = ERANGE; + } else if (neg) + acc = -acc; + if (endptr != 0) + *endptr = (char *)(any ? s - 1 : nptr); + return (acc); +} diff --git a/stdlib/strtoq.c b/stdlib/strtoq.c new file mode 100644 index 0000000..dcda96a --- /dev/null +++ b/stdlib/strtoq.c @@ -0,0 +1,61 @@ +/*- + * 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[] = "@(#)strtoq.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ + +#if defined(LIBC_SCCS) && !defined(lint) +static const char rcsid[] = + "$FreeBSD: src/lib/libc/stdlib/strtoq.c,v 1.4.6.1 2001/03/02 09:45:20 obrien Exp $"; +#endif + +#include + +#include + +/* + * Convert a string to a quad integer. + * + * Ignores `locale' stuff. Assumes that the upper and lower case + * alphabets and digits are each contiguous. + */ +quad_t +strtoq(nptr, endptr, base) + const char *nptr; + char **endptr; + int base; +{ + + return strtoll(nptr, endptr, base); +} diff --git a/stdlib/strtoul.3 b/stdlib/strtoul.3 new file mode 100644 index 0000000..2bc473e --- /dev/null +++ b/stdlib/strtoul.3 @@ -0,0 +1,198 @@ +.\" 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. +.\" +.\" @(#)strtoul.3 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD: src/lib/libc/stdlib/strtoul.3,v 1.14 2001/09/11 09:39:23 ru Exp $ +.\" +.Dd June 4, 1993 +.Dt STRTOUL 3 +.Os +.Sh NAME +.Nm strtoul , strtoull , strtouq +.Nd "convert a string to an unsigned long, unsigned long long, or uquad_t integer" +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In stdlib.h +.In limits.h +.Ft unsigned long +.Fn strtoul "const char *nptr" "char **endptr" "int base" +.Ft unsigned long long +.Fn strtoull "const char *nptr" "char **endptr" "int base" +.In sys/types.h +.In stdlib.h +.In limits.h +.Ft u_quad_t +.Fn strtouq "const char *nptr" "char **endptr" "int base" +.Sh DESCRIPTION +The +.Fn strtoul +function +converts the string in +.Fa nptr +to an +.Em unsigned long +value. +The +.Fn strtoull +function +converts the string in +.Fa nptr +to an +.Em unsigned long long +value. +The +.Fn strtouq +function +converts the string in +.Fa nptr +to a +.Em u_quad_t +value. +The conversion is done according to the given +.Fa base , +which must be between 2 and 36 inclusive, +or be the special value 0. +.Pp +The string may begin with an arbitrary amount of white space +(as determined by +.Xr isspace 3 ) +followed by a single optional +.Ql + +or +.Ql - +sign. +If +.Fa base +is zero or 16, +the string may then include a +.Ql 0x +prefix, +and the number will be read in base 16; otherwise, a zero +.Fa base +is taken as 10 (decimal) unless the next character is +.Ql 0 , +in which case it is taken as 8 (octal). +.Pp +The remainder of the string is converted to an +.Em unsigned long +value in the obvious manner, +stopping at the end of the string +or at the first character that does not produce a valid digit +in the given base. +(In bases above 10, the letter +.Ql A +in either upper or lower case +represents 10, +.Ql B +represents 11, and so forth, with +.Ql Z +representing 35.) +.Pp +If +.Fa endptr +is non nil, +.Fn strtoul +stores the address of the first invalid character in +.Fa *endptr . +If there were no digits at all, however, +.Fn strtoul +stores the original value of +.Fa nptr +in +.Fa *endptr . +(Thus, if +.Fa *nptr +is not +.Ql \e0 +but +.Fa **endptr +is +.Ql \e0 +on return, the entire string was valid.) +.Sh RETURN VALUES +The +.Fn strtoul +or +.Fn strtoull +function +returns either the result of the conversion +or, if there was a leading minus sign, +the negation of the result of the conversion, +unless the original (non-negated) value would overflow; +in the latter case, +.Fn strtoul +returns +.Dv ULONG_MAX +and +.Fn strtoull +returns +.Dv ULLONG_MAX . +In all cases, +.Va errno +is set to +.Er ERANGE . +If no conversion could be performed, 0 is returned and +the global variable +.Va errno +is set to +.Er EINVAL . +.Sh ERRORS +.Bl -tag -width Er +.It Bq Er EINVAL +The value of +.Fa base +is not supported or +no conversion could be performed. +.It Bq Er ERANGE +The given string was out of range; the value converted has been clamped. +.El +.Sh SEE ALSO +.Xr strtol 3 +.Sh STANDARDS +The +.Fn strtoul +function +conforms to +.St -isoC . +The +.Fn strtoull +function +conforms to +.St -isoC-99 . +The +.Bx +.Fn strtoq +function is deprecated. diff --git a/stdlib/strtoul.c b/stdlib/strtoul.c new file mode 100644 index 0000000..e0ccb4d --- /dev/null +++ b/stdlib/strtoul.c @@ -0,0 +1,125 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 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 +#include +#include +#include + +/* + * Convert a string to an unsigned long integer. + * + * Ignores `locale' stuff. Assumes that the upper and lower case + * alphabets and digits are each contiguous. + */ +unsigned long +strtoul(nptr, endptr, base) + const char *nptr; + char **endptr; + register int base; +{ + register const char *s = nptr; + register unsigned long acc; + register int c; + register unsigned long cutoff; + register int neg = 0, any, cutlim; + + /* + * See strtol for comments as to the logic used. + */ + do { + c = *s++; + } while (isspace(c)); + if (c == '-') { + neg = 1; + c = *s++; + } else if (c == '+') + c = *s++; + if ((base == 0 || base == 16) && + c == '0' && (*s == 'x' || *s == 'X')) { + c = s[1]; + s += 2; + base = 16; + } + if (base == 0) + base = c == '0' ? 8 : 10; + cutoff = (unsigned long)ULONG_MAX / (unsigned long)base; + cutlim = (unsigned long)ULONG_MAX % (unsigned long)base; + for (acc = 0, any = 0;; c = *s++) { + if (isdigit(c)) + c -= '0'; + else if (isalpha(c)) + c -= isupper(c) ? 'A' - 10 : 'a' - 10; + else + break; + if (c >= base) + break; + if (any < 0 || acc > cutoff || acc == cutoff && c > cutlim) + any = -1; + else { + any = 1; + acc *= base; + acc += c; + } + } + if (any < 0) { + acc = ULONG_MAX; + errno = ERANGE; + } else if (neg) + acc = -acc; + if (endptr != 0) + *endptr = (char *)(any ? s - 1 : nptr); + return (acc); +} diff --git a/stdlib/strtoull.c b/stdlib/strtoull.c new file mode 100644 index 0000000..f80850e --- /dev/null +++ b/stdlib/strtoull.c @@ -0,0 +1,121 @@ +/*- + * 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[] = "@(#)strtouq.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ + +#if defined(LIBC_SCCS) && !defined(lint) +static const char rcsid[] = + "$FreeBSD: src/lib/libc/stdlib/strtoull.c,v 1.5.2.1 2001/03/02 09:45:20 obrien Exp $"; +#endif + +#include + +#include +#include +#include +#include + +/* + * Convert a string to an unsigned long long integer. + * + * Ignores `locale' stuff. Assumes that the upper and lower case + * alphabets and digits are each contiguous. + */ +unsigned long long +strtoull(nptr, endptr, base) + const char *nptr; + char **endptr; + register int base; +{ + register const char *s = nptr; + register unsigned long long acc; + register unsigned char c; + register unsigned long long qbase, cutoff; + register int neg, any, cutlim; + + /* + * See strtoq for comments as to the logic used. + */ + s = nptr; + do { + c = *s++; + } while (isspace(c)); + if (c == '-') { + neg = 1; + c = *s++; + } else { + neg = 0; + if (c == '+') + c = *s++; + } + if ((base == 0 || base == 16) && + c == '0' && (*s == 'x' || *s == 'X')) { + c = s[1]; + s += 2; + base = 16; + } + if (base == 0) + base = c == '0' ? 8 : 10; + qbase = (unsigned)base; + cutoff = (unsigned long long)ULLONG_MAX / qbase; + cutlim = (unsigned long long)ULLONG_MAX % qbase; + for (acc = 0, any = 0;; c = *s++) { + if (!isascii(c)) + break; + if (isdigit(c)) + c -= '0'; + else if (isalpha(c)) + c -= isupper(c) ? 'A' - 10 : 'a' - 10; + else + break; + if (c >= base) + break; + if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim)) + any = -1; + else { + any = 1; + acc *= qbase; + acc += c; + } + } + if (any < 0) { + acc = ULLONG_MAX; + errno = ERANGE; + } else if (neg) + acc = -acc; + if (endptr != 0) + *endptr = (char *)(any ? s - 1 : nptr); + return (acc); +} diff --git a/stdlib/strtouq.c b/stdlib/strtouq.c new file mode 100644 index 0000000..89f26d8 --- /dev/null +++ b/stdlib/strtouq.c @@ -0,0 +1,61 @@ +/*- + * 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[] = "@(#)strtouq.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ + +#if defined(LIBC_SCCS) && !defined(lint) +static const char rcsid[] = + "$FreeBSD: src/lib/libc/stdlib/strtouq.c,v 1.4.8.1 2001/03/02 09:45:20 obrien Exp $"; +#endif + +#include + +#include + +/* + * Convert a string to an unsigned quad integer. + * + * Ignores `locale' stuff. Assumes that the upper and lower case + * alphabets and digits are each contiguous. + */ +u_quad_t +strtouq(nptr, endptr, base) + const char *nptr; + char **endptr; + int base; +{ + + return strtoull(nptr, endptr, base); +} diff --git a/stdlib/system.3 b/stdlib/system.3 new file mode 100644 index 0000000..a6aa661 --- /dev/null +++ b/stdlib/system.3 @@ -0,0 +1,103 @@ +.\" 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. +.\" +.\" @(#)system.3 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD: src/lib/libc/stdlib/system.3,v 1.10 2001/09/07 14:46:36 asmodai Exp $ +.\" +.Dd June 4, 1993 +.Dt SYSTEM 3 +.Os +.Sh NAME +.Nm system +.Nd pass a command to the shell +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In stdlib.h +.Ft int +.Fn system "const char *string" +.Sh DESCRIPTION +The +.Fn system +function +hands the argument +.Fa string +to the command interpreter +.Xr sh 1 . +The calling process waits for the shell +to finish executing the command, +ignoring +.Dv SIGINT +and +.Dv SIGQUIT , +and blocking +.Dv SIGCHLD . +.Pp +If +.Fa string +is a +.Dv NULL +pointer, +.Fn system +will return non-zero if the command interpreter +.Xr sh 1 +is available, and zero if it is not. +.Pp +The +.Fn system +function +returns the exit status of the shell as returned by +.Xr waitpid 2 , +or \-1 if an error occurred when invoking +.Xr fork 2 +or +.Xr waitpid 2 . +A return value of 127 means the execution of the shell +failed. +.Sh SEE ALSO +.Xr sh 1 , +.Xr execve 2 , +.Xr fork 2 , +.Xr waitpid 2 , +.Xr popen 3 +.Sh STANDARDS +The +.Fn system +function +conforms to +.St -isoC . +and is expected to be +.St -p1003.2 +compatible. diff --git a/stdlib/system.c b/stdlib/system.c new file mode 100644 index 0000000..19d7c76 --- /dev/null +++ b/stdlib/system.c @@ -0,0 +1,97 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1988, 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 +#include +#include +#include +#include +#include +#include +#include + +system(command) + const char *command; +{ + union wait pstat; + pid_t kid, pid; + int omask; + sig_t intsave, quitsave; + + if (!command) /* just checking... */ + return(1); + + omask = sigblock(sigmask(SIGCHLD)); + switch(kid = vfork()) { + case -1: /* error */ + (void)sigsetmask(omask); + pstat.w_status = 0; + pstat.w_retcode = 127; + return(pstat.w_status); + case 0: /* child */ + (void)sigsetmask(omask); + execl(_PATH_BSHELL, "sh", "-c", command, (char *)NULL); + _exit(127); + } + intsave = signal(SIGINT, SIG_IGN); + quitsave = signal(SIGQUIT, SIG_IGN); + do { + pid = waitpid(kid, (int *)&pstat, 0); + } while (pid < 0 && errno == EINTR); + (void)sigsetmask(omask); + (void)signal(SIGINT, intsave); + (void)signal(SIGQUIT, quitsave); + return(pid == -1 ? -1 : pstat.w_status); +} diff --git a/stdlib/tsearch.3 b/stdlib/tsearch.3 new file mode 100644 index 0000000..a36fe89 --- /dev/null +++ b/stdlib/tsearch.3 @@ -0,0 +1,118 @@ +.\" $NetBSD$ +.\" Copyright (c) 1997 Todd C. Miller +.\" 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. 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 ARE 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 +.\" 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.7 2001/09/07 14:46:36 asmodai Exp $ +.\" +.Dd June 15, 1997 +.Dt TSEARCH 3 +.Os +.Sh NAME +.Nm tsearch , tfind , tdelete , twalk +.Nd manipulate binary search trees +.Sh SYNOPSIS +.In search.h +.Ft void * +.Fn tdelete "const void *key" "void **rootp" "int (*compar) (const void *, const void *)" +.Ft void * +.Fn tfind "const void *key" "void **rootp" "int (*compar) (const void *, const void *)" +.Ft void * +.Fn tsearch "const void *key" "void **rootp" "int (*compar) (const void *, const void *)" +.Ft void +.Fn twalk "const void *root" "void (*compar) (const void *, VISIT, int)" +.Sh DESCRIPTION +The +.Fn tdelete , +.Fn tfind , +.Fn tsearch , +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 +the user has the same style of return values as +.Xr strcmp 3 . +.Pp +.Fn Tfind +searches for the datum matched by the argument +.Fa key +in the binary tree rooted at +.Fa rootp , +returning a pointer to the datum if it is found and NULL +if it is not. +.Pp +.Fn Tsearch +is identical to +.Fn tfind +except that if no match is found, +.Fa key +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 +.Fn Tdelete +deletes a node from the specified binary search tree and returns +a pointer to the parent of the node to be deleted. +It takes the same arguments as +.Fn tfind +and +.Fn tsearch . +If the node to be deleted is the root of the binary search tree, +.Fa rootp +will be adjusted. +.Pp +.Fn Twalk +walks the binary search tree rooted in +.Fa root +and calls the function +.Fa action +on each node. +.Fa Action +is called with three arguments: a pointer to the current node, +a value from the enum +.Sy "typedef enum { preorder, postorder, endorder, leaf } VISIT;" +specifying the traversal type, and a node level (where level +zero is the root of the tree). +.Sh SEE ALSO +.Xr bsearch 3 , +.Xr hsearch 3 , +.Xr lsearch 3 +.Sh RETURN VALUES +The +.Fn tsearch +function returns NULL if allocation of a new node fails (usually +due to a lack of free memory). +.Pp +.Fn Tfind , +.Fn tsearch , +and +.Fn tdelete +return NULL if +.Fa rootp +is NULL or the datum cannot be found. +.Pp +The +.Fn twalk +function returns no value. diff --git a/stdtime/Makefile.inc b/stdtime/Makefile.inc new file mode 100644 index 0000000..12c4b0c --- /dev/null +++ b/stdtime/Makefile.inc @@ -0,0 +1,17 @@ +# Makefile.inc,v 1.2 1994/09/13 21:26:01 wollman Exp +# $FreeBSD: src/lib/libc/stdtime/Makefile.inc,v 1.13 2001/10/28 19:54:49 dillon Exp $ + +.PATH: ${.CURDIR}/stdtime ${.CURDIR}/locale + +SRCS+= timelocal.c asctime.c difftime.c localtime.c strftime.c strptime.c + +.if ${LIB} == "c" +MAN3+= ctime.3 strftime.3 strptime.3 time2posix.3 +MAN5+= tzfile.5 + +MLINKS+=ctime.3 asctime.3 ctime.3 difftime.3 ctime.3 gmtime.3 \ + ctime.3 localtime.3 ctime.3 mktime.3 ctime.3 timegm.3 \ + 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 +.endif diff --git a/stdtime/asctime.c b/stdtime/asctime.c new file mode 100644 index 0000000..c669b54 --- /dev/null +++ b/stdtime/asctime.c @@ -0,0 +1,78 @@ +/* +** This file is in the public domain, so clarified as of +** June 5, 1996 by Arthur David Olson (arthur_david_olson@nih.gov). +** +** $FreeBSD: src/lib/libc/stdtime/asctime.c,v 1.7.6.1 2001/03/05 11:37:20 obrien Exp $ +*/ + +#ifndef lint +#ifndef NOID +static char elsieid[] = "@(#)asctime.c 7.7"; +#endif /* !defined NOID */ +#endif /* !defined lint */ + +/*LINTLIBRARY*/ + +#include "private.h" +#include "tzfile.h" + +/* +** A la X3J11, with core dump avoidance. +*/ + + +char * +asctime(timeptr) +const struct tm * timeptr; +{ + static char *result = NULL; + + if( result == NULL ) { + result = (char *)malloc(3 * 2 + 5 * INT_STRLEN_MAXIMUM(int) + + 3 + 2 + 1 + 1); + if( result == NULL ) + return NULL; + } + return(asctime_r(timeptr, result)); +} + +char * +asctime_r(timeptr, result) +const struct tm * timeptr; +char *result; +{ + static const char wday_name[][3] = { + "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" + }; + static const char mon_name[][3] = { + "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). + */ + register const char * wn; + register const char * mn; + + if (timeptr->tm_wday < 0 || timeptr->tm_wday >= DAYSPERWEEK) + wn = "???"; + else wn = wday_name[timeptr->tm_wday]; + if (timeptr->tm_mon < 0 || timeptr->tm_mon >= MONSPERYEAR) + mn = "???"; + else mn = mon_name[timeptr->tm_mon]; + /* + ** The X3J11-suggested format is + ** "%.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", + wn, mn, + timeptr->tm_mday, timeptr->tm_hour, + timeptr->tm_min, timeptr->tm_sec, + TM_YEAR_BASE + timeptr->tm_year); + return result; +} diff --git a/stdtime/ctime.3 b/stdtime/ctime.3 new file mode 100644 index 0000000..fa2895d --- /dev/null +++ b/stdtime/ctime.3 @@ -0,0 +1,363 @@ +.\" Copyright (c) 1989, 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" This code is derived from software contributed to Berkeley by +.\" Arthur Olson. +.\" 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: @(#)ctime.3 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD: src/lib/libc/stdtime/ctime.3,v 1.11.2.6 2001/10/02 11:36:10 ru Exp $ +.\" +.Dd January 2, 1999 +.Dt CTIME 3 +.Os +.Sh NAME +.Nm asctime , +.Nm asctime_r , +.Nm ctime , +.Nm ctime_r , +.Nm difftime , +.Nm gmtime , +.Nm gmtime_r , +.Nm localtime , +.Nm localtime_r , +.Nm mktime , +.Nm timegm +.Nd transform binary date and time values +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In time.h +.Vt extern char *tzname[2] ; +.Ft char * +.Fn ctime "const time_t *clock" +.Ft double +.Fn difftime "time_t time1" "time_t time0" +.Ft char * +.Fn asctime "const struct tm *tm" +.Ft struct tm * +.Fn localtime "const time_t *clock" +.Ft struct tm * +.Fn gmtime "const time_t *clock" +.Ft time_t +.Fn mktime "struct tm *tm" +.Ft time_t +.Fn timegm "struct tm *tm" +.Ft char * +.Fn ctime_r "const time_t *clock" "char *buf" +.Ft struct tm * +.Fn localtime_r "const time_t *clock" "struct tm *result" +.Ft struct tm * +.Fn gmtime_r "const time_t *clock" "struct tm *result" +.Ft char * +.Fn asctime_r "const struct tm *tm" "char *buf" +.Sh DESCRIPTION +The functions +.Fn ctime , +.Fn gmtime +and +.Fn localtime +all take as an argument a time value representing the time in seconds since +the Epoch (00:00:00 +.Tn UTC , +January 1, 1970; see +.Xr time 3 ) . +.Pp +The function +.Fn localtime +converts the time value pointed at by +.Fa clock , +and returns a pointer to a +.Dq Fa struct tm +(described below) which contains +the broken-out time information for the value after adjusting for the current +time zone (and any other factors such as Daylight Saving Time). +Time zone adjustments are performed as specified by the +.Ev TZ +environment variable (see +.Xr tzset 3 ) . +The function +.Fn localtime +uses +.Xr tzset 3 +to initialize time conversion information if +.Xr tzset 3 +has not already been called by the process. +.Pp +After filling in the tm structure, +.Fn localtime +sets the +.Fa tm_isdst Ns 'th +element of +.Fa tzname +to a pointer to an +.Tn ASCII +string that's the time zone abbreviation to be +used with +.Fn localtime Ns 's +return value. +.Pp +The function +.Fn gmtime +similarly converts the time value, but without any time zone adjustment, +and returns a pointer to a tm structure (described below). +.Pp +The +.Fn ctime +function +adjusts the time value for the current time zone in the same manner as +.Fn localtime , +and returns a pointer to a 26-character string of the form: +.Bd -literal -offset indent +Thu Nov 24 18:22:48 1986\en\e0 +.Ed +.Pp +All the fields have constant width. +.Pp +.Fn ctime_r +provides the same functionality as +.Fn ctime +except the caller must provide the output buffer +.Fa buf +to store the result, which must be at least 26 characters long. +.Fn localtime_r +and +.Fn gmtime_r +provide the same functionality as +.Fn localtime +and +.Fn gmtime +respectively, except the caller must provide the output buffer +.Fa result . +.Pp +The +.Fn asctime +function +converts the broken down time in the structure +.Fa tm +pointed at by +.Fa *tm +to the form +shown in the example above. +.Pp +.Fn asctime_r +provides the same functionality as +.Fn asctime +except the caller provide the output buffer +.Fa buf +to store the result, which must be at least 26 characters long. +.Pp +The functions +.Fn mktime +and +.Fn timegm +convert the broken-down time in the structure +pointed to by tm into a time value with the same encoding as that of the +values returned by the +.Xr time 3 +function (that is, seconds from the Epoch, +.Tn UTC ) . +.Fn mktime +interprets the input structure according to the current timezone setting +(see +.Xr tzset 3 ) . +.Fn timegm +interprets the input structure as representing Universal Coordinated Time +.Pq Tn UTC . +.Pp +The original values of the +.Fa tm_wday +and +.Fa tm_yday +components of the structure are ignored, and the original values of the +other components are not restricted to their normal ranges, and will be +normalized if needed. +For example, +October 40 is changed into November 9, +a +.Fa tm_hour +of \-1 means 1 hour before midnight, +.Fa tm_mday +of 0 means the day preceding the current month, and +.Fa tm_mon +of \-2 means 2 months before January of +.Fa tm_year . +(A positive or zero value for +.Fa tm_isdst +causes +.Fn mktime +to presume initially that summer time (for example, Daylight Saving Time) +is or is not in effect for the specified time, respectively. +A negative value for +.Fa tm_isdst +causes the +.Fn mktime +function to attempt to divine whether summer time is in effect for the +specified time. +The +.Fa tm_isdst +and +.Fa tm_gmtoff +members are forced to zero by +.Fn timegm . ) +.Pp +On successful completion, the values of the +.Fa tm_wday +and +.Fa tm_yday +components of the structure are set appropriately, and the other components +are set to represent the specified calendar time, but with their values +forced to their normal ranges; the final value of +.Fa tm_mday +is not set until +.Fa tm_mon +and +.Fa tm_year +are determined. +.Fn Mktime +returns the specified calendar time; if the calendar time cannot be +represented, it returns \-1; +.Pp +The +.Fn difftime +function +returns the difference between two calendar times, +.Pf ( Fa time1 +- +.Fa time0 ) , +expressed in seconds. +.Pp +External declarations as well as the tm structure definition are in the +.Aq Pa time.h +include file. +The tm structure includes at least the following fields: +.Bd -literal -offset indent +int tm_sec; /\(** seconds (0 - 60) \(**/ +int tm_min; /\(** minutes (0 - 59) \(**/ +int tm_hour; /\(** hours (0 - 23) \(**/ +int tm_mday; /\(** day of month (1 - 31) \(**/ +int tm_mon; /\(** month of year (0 - 11) \(**/ +int tm_year; /\(** year \- 1900 \(**/ +int tm_wday; /\(** day of week (Sunday = 0) \(**/ +int tm_yday; /\(** day of year (0 - 365) \(**/ +int tm_isdst; /\(** is summer time in effect? \(**/ +char \(**tm_zone; /\(** abbreviation of timezone name \(**/ +long tm_gmtoff; /\(** offset from UTC in seconds \(**/ +.Ed +.Pp +The +field +.Fa tm_isdst +is non-zero if summer time is in effect. +.Pp +The field +.Fa tm_gmtoff +is the offset (in seconds) of the time represented from +.Tn UTC , +with positive +values indicating east of the Prime Meridian. +.Sh SEE ALSO +.Xr date 1 , +.Xr gettimeofday 2 , +.Xr getenv 3 , +.Xr time 3 , +.Xr tzset 3 , +.Xr tzfile 5 +.Sh STANDARDS +The +.Fn asctime , +.Fn ctime , +.Fn difftime , +.Fn gmtime , +.Fn localtime , +and +.Fn mktime +functions conform to +.St -isoC , +and conform to +.St -p1003.1-96 +provided the selected local timezone does not contain a leap-second table +(see +.Xr zic 8 ) . +.Pp +The +.Fn asctime_r , +.Fn ctime_r , +.Fn gmtime_r , +and +.Fn localtime_r +functions are expected to conform to +.St -p1003.1-96 +(again provided the selected local timezone does not contain a leap-second +table). +.Pp +The +.Fn timegm +function is not specified by any standard; its function cannot be +completely emulated using the standard functions described above. +.Sh HISTORY +This manual page is derived from +the time package contributed to Berkeley by +.An Arthur Olson +and which appeared in +.Bx 4.3 . +.Sh BUGS +Except for +.Fn difftime , +.Fn mktime , +and the +.Fn \&_r +variants of the other functions, +these functions leaves their result in an internal static object and return +a pointer to that object. +Subsequent calls to these +function will modify the same object. +.Pp +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 +in the +.Tn POSIX +threaded environment.) +.Pp +The +.Fa tm_zone +field of a returned tm structure points to a static array of characters, +which will also be overwritten by any subsequent calls (as well as by +subsequent calls to +.Xr tzset 3 +and +.Xr tzsetwall 3 ) . +.Pp +Use of the external variable +.Fa tzname +is discouraged; the +.Fa tm_zone +entry in the tm structure is preferred. diff --git a/stdtime/difftime.c b/stdtime/difftime.c new file mode 100644 index 0000000..5a6c5c6 --- /dev/null +++ b/stdtime/difftime.c @@ -0,0 +1,79 @@ +/* +** This file is in the public domain, so clarified as of +** June 5, 1996 by Arthur David Olson (arthur_david_olson@nih.gov). +** +** $FreeBSD: src/lib/libc/stdtime/difftime.c,v 1.4.8.1 2001/03/05 11:37:21 obrien Exp $ +*/ + +#ifndef lint +#ifndef NOID +static char elsieid[] = "@(#)difftime.c 7.7"; +#endif /* !defined NOID */ +#endif /* !defined lint */ + +/*LINTLIBRARY*/ + +#include "private.h" + +/* +** Algorithm courtesy Paul Eggert (eggert@twinsun.com). +*/ + +#ifdef HAVE_LONG_DOUBLE +#define long_double long double +#endif /* defined HAVE_LONG_DOUBLE */ +#ifndef HAVE_LONG_DOUBLE +#define long_double double +#endif /* !defined HAVE_LONG_DOUBLE */ + +double +difftime(time1, time0) +const time_t time1; +const time_t time0; +{ + 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; + if (time1 < time0) + return -difftime(time0, time1); + /* + ** As much as possible, avoid loss of precision + ** by computing the difference before converting to double. + */ + delta = time1 - time0; + if (delta >= 0) + return delta; + /* + ** Repair delta overflow. + */ + hibit = (~ (time_t) 0) << (TYPE_BIT(time_t) - 1); + /* + ** The following expression rounds twice, which means + ** the result may not be the closest to the true answer. + ** For example, suppose time_t is 64-bit signed int, + ** long_double is IEEE 754 double with default rounding, + ** time1 = 9223372036854775807 and time0 = -1536. + ** Then the true difference is 9223372036854777343, + ** which rounds to 9223372036854777856 + ** with a total error of 513. + ** But delta overflows to -9223372036854774273, + ** which rounds to -9223372036854774784, and correcting + ** this by subtracting 2 * (long_double) hibit + ** (i.e. by adding 2**64 = 18446744073709551616) + ** yields 9223372036854776832, which + ** rounds to 9223372036854775808 + ** with a total error of 1535 instead. + ** This problem occurs only with very large differences. + ** It's too painful to fix this portably. + ** We are not alone in this problem; + ** some C compilers round twice when converting + ** large unsigned types to small floating types, + ** so if time_t is unsigned the "return delta" above + ** has the same double-rounding problem with those compilers. + */ + return delta - 2 * (long_double) hibit; +} diff --git a/stdtime/localtime.c b/stdtime/localtime.c new file mode 100644 index 0000000..680d750 --- /dev/null +++ b/stdtime/localtime.c @@ -0,0 +1,1770 @@ +/* +** This file is in the public domain, so clarified as of +** June 5, 1996 by Arthur David Olson (arthur_david_olson@nih.gov). +** +** $FreeBSD: src/lib/libc/stdtime/localtime.c,v 1.25.2.1 2001/03/05 11:37:21 obrien Exp $ +*/ + +#ifndef lint +#ifndef NOID +static char elsieid[] = "@(#)localtime.c 7.57"; +#endif /* !defined NOID */ +#endif /* !defined lint */ + +/* +** Leap second handling from Bradley White (bww@k.gp.cs.cmu.edu). +** POSIX-style TZ environment variable handling from Guy Harris +** (guy@auspex.com). +*/ + +/*LINTLIBRARY*/ + +#include +#include +#include "private.h" +#include "tzfile.h" +#include "fcntl.h" +#ifdef _THREAD_SAFE +#include +#include "pthread_private.h" +#endif + +/* +** SunOS 4.1.1 headers lack O_BINARY. +*/ + +#ifdef O_BINARY +#define OPEN_MODE (O_RDONLY | O_BINARY) +#endif /* defined O_BINARY */ +#ifndef O_BINARY +#define OPEN_MODE O_RDONLY +#endif /* !defined O_BINARY */ + +#ifndef WILDABBR +/* +** Someone might make incorrect use of a time zone abbreviation: +** 1. They might reference tzname[0] before calling tzset (explicitly +** or implicitly). +** 2. They might reference tzname[1] before calling tzset (explicitly +** or implicitly). +** 3. They might reference tzname[1] after setting to a time zone +** in which Daylight Saving Time is never observed. +** 4. They might reference tzname[0] after setting to a time zone +** in which Standard Time is never observed. +** 5. They might reference tm.TM_ZONE after calling offtime. +** What's best to do in the above cases is open to debate; +** for now, we just set things up so that in any of the five cases +** WILDABBR is used. Another possibility: initialize tzname[0] to the +** string "tzname[0] used before set", and similarly for the other cases. +** And another: initialize tzname[0] to "ERA", with an explanation in the +** manual page of what this "time zone abbreviation" means (doing this so +** that tzname[0] has the "normal" length of three characters). +*/ +#define WILDABBR " " +#endif /* !defined WILDABBR */ + +static char wildabbr[] = "WILDABBR"; + +static const char gmt[] = "GMT"; + +struct ttinfo { /* time type information */ + long tt_gmtoff; /* GMT 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 */ +}; + +struct lsinfo { /* leap second information */ + time_t ls_trans; /* transition time */ + long ls_corr; /* correction to apply */ +}; + +#define BIGGEST(a, b) (((a) > (b)) ? (a) : (b)) + +#ifdef TZNAME_MAX +#define MY_TZNAME_MAX TZNAME_MAX +#endif /* defined TZNAME_MAX */ +#ifndef TZNAME_MAX +#define MY_TZNAME_MAX 255 +#endif /* !defined TZNAME_MAX */ + +struct state { + int leapcnt; + int timecnt; + int typecnt; + int charcnt; + time_t ats[TZ_MAX_TIMES]; + unsigned char types[TZ_MAX_TIMES]; + struct ttinfo ttis[TZ_MAX_TYPES]; + char chars[BIGGEST(BIGGEST(TZ_MAX_CHARS + 1, sizeof gmt), + (2 * (MY_TZNAME_MAX + 1)))]; + struct lsinfo lsis[TZ_MAX_LEAPS]; +}; + +struct rule { + int r_type; /* type of rule--see below */ + int r_day; /* day number of rule */ + int r_week; /* week number of rule */ + int r_mon; /* month number of rule */ + long r_time; /* transition time of rule */ +}; + +#define JULIAN_DAY 0 /* Jn - Julian day */ +#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. +*/ + +static long detzcode P((const char * codep)); +static const char * getzname P((const char * strp)); +static const char * getnum P((const char * strp, int * nump, int min, + int max)); +static const char * getsecs P((const char * strp, long * secsp)); +static const char * getoffset P((const char * strp, long * offsetp)); +static const char * getrule P((const char * strp, struct rule * rulep)); +static void gmtload P((struct state * sp)); +static void gmtsub P((const time_t * timep, long offset, + struct tm * tmp)); +static void localsub P((const time_t * timep, long offset, + struct tm * tmp)); +static int increment_overflow P((int * number, int delta)); +static int normalize_overflow P((int * tensptr, int * unitsptr, + int base)); +static void settzname P((void)); +static time_t time1 P((struct tm * tmp, + void(*funcp) P((const time_t *, + long, struct tm *)), + long offset)); +static time_t time2 P((struct tm *tmp, + void(*funcp) P((const time_t *, + long, struct tm*)), + long offset, int * okayp)); +static void timesub P((const time_t * timep, long offset, + const struct state * sp, struct tm * tmp)); +static int tmcomp P((const struct tm * atmp, + const struct tm * btmp)); +static time_t transtime P((time_t janfirst, int year, + const struct rule * rulep, long offset)); +static int tzload P((const char * name, struct state * sp)); +static int tzparse P((const char * name, struct state * sp, + int lastditch)); + +#ifdef ALL_STATE +static struct state * lclptr; +static struct state * gmtptr; +#endif /* defined ALL_STATE */ + +#ifndef ALL_STATE +static struct state lclmem; +static struct state gmtmem; +#define lclptr (&lclmem) +#define gmtptr (&gmtmem) +#endif /* State Farm */ + +#ifndef TZ_STRLEN_MAX +#define TZ_STRLEN_MAX 255 +#endif /* !defined TZ_STRLEN_MAX */ + +static char lcl_TZname[TZ_STRLEN_MAX + 1]; +#ifdef _THREAD_SAFE +static struct pthread_mutex _lcl_mutexd = PTHREAD_MUTEX_STATIC_INITIALIZER; +static struct pthread_mutex _gmt_mutexd = PTHREAD_MUTEX_STATIC_INITIALIZER; +static pthread_mutex_t lcl_mutex = &_lcl_mutexd; +static pthread_mutex_t gmt_mutex = &_gmt_mutexd; +#endif + +char * tzname[2] = { + wildabbr, + wildabbr +}; + +/* +** Section 4.12.3 of X3.159-1989 requires that +** Except for the strftime function, these functions [asctime, +** ctime, gmtime, localtime] return values in one of two static +** objects: a broken-down time structure and an array of char. +** Thanks to Paul Eggert (eggert@twinsun.com) for noting this. +*/ + +static struct tm tm; + +#ifdef USG_COMPAT +time_t timezone = 0; +int daylight = 0; +#endif /* defined USG_COMPAT */ + +#ifdef ALTZONE +time_t altzone = 0; +#endif /* defined ALTZONE */ + +static long +detzcode(codep) +const char * const codep; +{ + register long result; + register int i; + + result = (codep[0] & 0x80) ? ~0L : 0L; + for (i = 0; i < 4; ++i) + result = (result << 8) | (codep[i] & 0xff); + return result; +} + +static void +settzname P((void)) +{ + register struct state * sp = lclptr; + register int i; + + tzname[0] = wildabbr; + tzname[1] = wildabbr; +#ifdef USG_COMPAT + daylight = 0; + timezone = 0; +#endif /* defined USG_COMPAT */ +#ifdef ALTZONE + altzone = 0; +#endif /* defined ALTZONE */ +#ifdef ALL_STATE + if (sp == NULL) { + tzname[0] = tzname[1] = gmt; + return; + } +#endif /* defined ALL_STATE */ + for (i = 0; i < sp->typecnt; ++i) { + register const struct ttinfo * const ttisp = &sp->ttis[i]; + + tzname[ttisp->tt_isdst] = + &sp->chars[ttisp->tt_abbrind]; +#ifdef USG_COMPAT + if (ttisp->tt_isdst) + daylight = 1; + if (i == 0 || !ttisp->tt_isdst) + timezone = -(ttisp->tt_gmtoff); +#endif /* defined USG_COMPAT */ +#ifdef ALTZONE + if (i == 0 || ttisp->tt_isdst) + altzone = -(ttisp->tt_gmtoff); +#endif /* defined ALTZONE */ + } + /* + ** And to get the latest zone names into tzname. . . + */ + for (i = 0; i < sp->timecnt; ++i) { + register const struct ttinfo * const ttisp = + &sp->ttis[ + sp->types[i]]; + + tzname[ttisp->tt_isdst] = + &sp->chars[ttisp->tt_abbrind]; + } +} + +static int +tzload(name, sp) +register const char * name; +register struct state * const sp; +{ + register const char * p; + register int i; + register int fid; + static struct stat sb; + struct stat newsb; + + /* XXX The following is from OpenBSD, and I'm not sure it is correct */ + if (name != NULL && issetugid() != 0) + if ((name[0] == ':' && name[1] == '/') || + name[0] == '/' || strchr(name, '.')) + name = NULL; + if (name == NULL && (name = TZDEFAULT) == NULL) + return -1; + { + register int doaccess; + struct stat stab; + /* + ** Section 4.9.1 of the C standard says that + ** "FILENAME_MAX expands to an integral constant expression + ** that is the size needed for an array of char large enough + ** to hold the longest file name string that the implementation + ** guarantees can be opened." + */ + char fullname[FILENAME_MAX + 1]; + + if (name[0] == ':') + ++name; + doaccess = name[0] == '/'; + if (!doaccess) { + if ((p = TZDIR) == NULL) + return -1; + if ((strlen(p) + 1 + strlen(name) + 1) >= sizeof fullname) + return -1; + (void) strcpy(fullname, p); + (void) strcat(fullname, "/"); + (void) strcat(fullname, name); + /* + ** Set doaccess if '.' (as in "../") shows up in name. + */ + if (strchr(name, '.') != NULL) + doaccess = TRUE; + name = fullname; + } + if (lstat(name, &newsb) == -1) + return -1; + if( (sb.st_dev == newsb.st_dev) && (sb.st_ino == newsb.st_ino) && + (sb.st_gen == newsb.st_gen) && + (memcmp(&sb.st_ctimespec, &newsb.st_ctimespec, + sizeof(struct timespec)) == 0) ) { + return 0; + } + memcpy(&sb, &newsb, sizeof(sb)); + if ((fid = open(name, OPEN_MODE)) == -1) + return -1; + if ((fstat(fid, &stab) < 0) || !S_ISREG(stab.st_mode)) + return -1; + } + { + struct tzhead * tzhp; + char buf[sizeof *sp + sizeof *tzhp]; + int ttisstdcnt; + int ttisgmtcnt; + + i = read(fid, buf, sizeof 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; + 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 || + sp->charcnt < 0 || sp->charcnt > TZ_MAX_CHARS || + (ttisstdcnt != sp->typecnt && ttisstdcnt != 0) || + (ttisgmtcnt != sp->typecnt && ttisgmtcnt != 0)) + return -1; + if (i - (p - buf) < sp->timecnt * 4 + /* ats */ + sp->timecnt + /* types */ + sp->typecnt * (4 + 2) + /* ttinfos */ + sp->charcnt + /* chars */ + sp->leapcnt * (4 + 4) + /* lsinfos */ + ttisstdcnt + /* ttisstds */ + ttisgmtcnt) /* ttisgmts */ + return -1; + for (i = 0; i < sp->timecnt; ++i) { + sp->ats[i] = detzcode(p); + p += 4; + } + for (i = 0; i < sp->timecnt; ++i) { + sp->types[i] = (unsigned char) *p++; + if (sp->types[i] >= sp->typecnt) + return -1; + } + for (i = 0; i < sp->typecnt; ++i) { + register struct ttinfo * ttisp; + + ttisp = &sp->ttis[i]; + ttisp->tt_gmtoff = detzcode(p); + p += 4; + ttisp->tt_isdst = (unsigned char) *p++; + if (ttisp->tt_isdst != 0 && ttisp->tt_isdst != 1) + return -1; + ttisp->tt_abbrind = (unsigned char) *p++; + if (ttisp->tt_abbrind < 0 || + ttisp->tt_abbrind > sp->charcnt) + return -1; + } + for (i = 0; i < sp->charcnt; ++i) + sp->chars[i] = *p++; + sp->chars[i] = '\0'; /* ensure '\0' at end */ + for (i = 0; i < sp->leapcnt; ++i) { + register struct lsinfo * lsisp; + + lsisp = &sp->lsis[i]; + lsisp->ls_trans = detzcode(p); + p += 4; + lsisp->ls_corr = detzcode(p); + p += 4; + } + for (i = 0; i < sp->typecnt; ++i) { + register struct ttinfo * ttisp; + + ttisp = &sp->ttis[i]; + if (ttisstdcnt == 0) + ttisp->tt_ttisstd = FALSE; + else { + ttisp->tt_ttisstd = *p++; + if (ttisp->tt_ttisstd != TRUE && + ttisp->tt_ttisstd != FALSE) + return -1; + } + } + for (i = 0; i < sp->typecnt; ++i) { + register struct ttinfo * ttisp; + + ttisp = &sp->ttis[i]; + if (ttisgmtcnt == 0) + ttisp->tt_ttisgmt = FALSE; + else { + ttisp->tt_ttisgmt = *p++; + if (ttisp->tt_ttisgmt != TRUE && + ttisp->tt_ttisgmt != FALSE) + return -1; + } + } + } + return 0; +} + +static const int mon_lengths[2][MONSPERYEAR] = { + { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }, + { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 } +}; + +static const int year_lengths[2] = { + DAYSPERNYEAR, DAYSPERLYEAR +}; + +/* +** Given a pointer into a time zone string, scan until a character that is not +** a valid character in a zone name is found. Return a pointer to that +** character. +*/ + +static const char * +getzname(strp) +register const char * strp; +{ + register char c; + + while ((c = *strp) != '\0' && !is_digit(c) && c != ',' && c != '-' && + c != '+') + ++strp; + return strp; +} + +/* +** Given a pointer into a time zone string, extract a number from that string. +** Check that the number is within a specified range; if it is not, return +** NULL. +** Otherwise, return a pointer to the first character not part of the number. +*/ + +static const char * +getnum(strp, nump, min, max) +register const char * strp; +int * const nump; +const int min; +const int max; +{ + register char c; + register int num; + + if (strp == NULL || !is_digit(c = *strp)) + return NULL; + num = 0; + do { + num = num * 10 + (c - '0'); + if (num > max) + return NULL; /* illegal value */ + c = *++strp; + } while (is_digit(c)); + if (num < min) + return NULL; /* illegal value */ + *nump = num; + return strp; +} + +/* +** Given a pointer into a time zone string, extract a number of seconds, +** in hh[:mm[:ss]] form, from the string. +** If any error occurs, return NULL. +** Otherwise, return a pointer to the first character not part of the number +** of seconds. +*/ + +static const char * +getsecs(strp, secsp) +register const char * strp; +long * const secsp; +{ + int num; + + /* + ** `HOURSPERDAY * DAYSPERWEEK - 1' allows quasi-Posix rules like + ** "M10.4.6/26", which does not conform to Posix, + ** but which specifies the equivalent of + ** ``02:00 on the first Sunday on or after 23 Oct''. + */ + strp = getnum(strp, &num, 0, HOURSPERDAY * DAYSPERWEEK - 1); + if (strp == NULL) + return NULL; + *secsp = num * (long) SECSPERHOUR; + if (*strp == ':') { + ++strp; + strp = getnum(strp, &num, 0, MINSPERHOUR - 1); + if (strp == NULL) + return NULL; + *secsp += num * SECSPERMIN; + if (*strp == ':') { + ++strp; + /* `SECSPERMIN' allows for leap seconds. */ + strp = getnum(strp, &num, 0, SECSPERMIN); + if (strp == NULL) + return NULL; + *secsp += num; + } + } + return strp; +} + +/* +** Given a pointer into a time zone string, extract an offset, in +** [+-]hh[:mm[:ss]] form, from the string. +** If any error occurs, return NULL. +** Otherwise, return a pointer to the first character not part of the time. +*/ + +static const char * +getoffset(strp, offsetp) +register const char * strp; +long * const offsetp; +{ + register int neg = 0; + + if (*strp == '-') { + neg = 1; + ++strp; + } else if (*strp == '+') + ++strp; + strp = getsecs(strp, offsetp); + if (strp == NULL) + return NULL; /* illegal time */ + if (neg) + *offsetp = -*offsetp; + return strp; +} + +/* +** Given a pointer into a time zone string, extract a rule in the form +** date[/time]. See POSIX section 8 for the format of "date" and "time". +** If a valid rule is not found, return NULL. +** Otherwise, return a pointer to the first character not part of the rule. +*/ + +static const char * +getrule(strp, rulep) +const char * strp; +register struct rule * const rulep; +{ + if (*strp == 'J') { + /* + ** Julian day. + */ + rulep->r_type = JULIAN_DAY; + ++strp; + strp = getnum(strp, &rulep->r_day, 1, DAYSPERNYEAR); + } else if (*strp == 'M') { + /* + ** Month, week, day. + */ + rulep->r_type = MONTH_NTH_DAY_OF_WEEK; + ++strp; + strp = getnum(strp, &rulep->r_mon, 1, MONSPERYEAR); + if (strp == NULL) + return NULL; + if (*strp++ != '.') + return NULL; + strp = getnum(strp, &rulep->r_week, 1, 5); + if (strp == NULL) + return NULL; + if (*strp++ != '.') + return NULL; + strp = getnum(strp, &rulep->r_day, 0, DAYSPERWEEK - 1); + } else if (is_digit(*strp)) { + /* + ** Day of year. + */ + rulep->r_type = DAY_OF_YEAR; + strp = getnum(strp, &rulep->r_day, 0, DAYSPERLYEAR - 1); + } else return NULL; /* invalid format */ + if (strp == NULL) + return NULL; + if (*strp == '/') { + /* + ** Time specified. + */ + ++strp; + strp = getsecs(strp, &rulep->r_time); + } else rulep->r_time = 2 * SECSPERHOUR; /* default = 2:00:00 */ + return strp; +} + +/* +** 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, +** calculate the Epoch-relative time that rule takes effect. +*/ + +static time_t +transtime(janfirst, year, rulep, offset) +const time_t janfirst; +const int year; +register const struct rule * const rulep; +const long offset; +{ + register int leapyear; + register time_t value; + register int i; + int d, m1, yy0, yy1, yy2, dow; + + INITIALIZE(value); + leapyear = isleap(year); + switch (rulep->r_type) { + + case JULIAN_DAY: + /* + ** Jn - Julian day, 1 == January 1, 60 == March 1 even in leap + ** years. + ** In non-leap years, or if the day number is 59 or less, just + ** add SECSPERDAY times the day number-1 to the time of + ** January 1, midnight, to get the day. + */ + value = janfirst + (rulep->r_day - 1) * SECSPERDAY; + if (leapyear && rulep->r_day >= 60) + value += SECSPERDAY; + break; + + case DAY_OF_YEAR: + /* + ** n - day of year. + ** Just add SECSPERDAY times the day number to the time of + ** January 1, midnight, to get the day. + */ + value = janfirst + rulep->r_day * SECSPERDAY; + break; + + case MONTH_NTH_DAY_OF_WEEK: + /* + ** Mm.n.d - nth "dth day" of month m. + */ + value = janfirst; + for (i = 0; i < rulep->r_mon - 1; ++i) + value += mon_lengths[leapyear][i] * SECSPERDAY; + + /* + ** Use Zeller's Congruence to get day-of-week of first day of + ** month. + */ + m1 = (rulep->r_mon + 9) % 12 + 1; + yy0 = (rulep->r_mon <= 2) ? (year - 1) : year; + yy1 = yy0 / 100; + yy2 = yy0 % 100; + dow = ((26 * m1 - 2) / 10 + + 1 + yy2 + yy2 / 4 + yy1 / 4 - 2 * yy1) % 7; + if (dow < 0) + dow += DAYSPERWEEK; + + /* + ** "dow" is the day-of-week of the first day of the month. Get + ** the day-of-month (zero-origin) of the first "dow" day of the + ** month. + */ + d = rulep->r_day - dow; + if (d < 0) + d += DAYSPERWEEK; + for (i = 1; i < rulep->r_week; ++i) { + if (d + DAYSPERWEEK >= + mon_lengths[leapyear][rulep->r_mon - 1]) + break; + d += DAYSPERWEEK; + } + + /* + ** "d" is the day-of-month (zero-origin) of the day we want. + */ + value += d * SECSPERDAY; + break; + } + + /* + ** "value" is the Epoch-relative time of 00:00:00 GMT 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. + */ + return value + rulep->r_time + offset; +} + +/* +** Given a POSIX section 8-style TZ string, fill in the rule tables as +** appropriate. +*/ + +static int +tzparse(name, sp, lastditch) +const char * name; +register struct state * const sp; +const int lastditch; +{ + const char * stdname; + const char * dstname; + size_t stdlen; + size_t dstlen; + long stdoffset; + long dstoffset; + register time_t * atp; + register unsigned char * typep; + register char * cp; + register int load_result; + + INITIALIZE(dstname); + stdname = name; + if (lastditch) { + stdlen = strlen(name); /* length of standard zone name */ + name += stdlen; + if (stdlen >= sizeof sp->chars) + stdlen = (sizeof sp->chars) - 1; + stdoffset = 0; + } else { + name = getzname(name); + stdlen = name - stdname; + if (stdlen < 3) + return -1; + if (*name == '\0') + return -1; /* was "stdoffset = 0;" */ + else { + name = getoffset(name, &stdoffset); + if (name == NULL) + return -1; + } + } + load_result = tzload(TZDEFRULES, sp); + if (load_result != 0) + sp->leapcnt = 0; /* so, we're off a little */ + if (*name != '\0') { + dstname = name; + name = getzname(name); + dstlen = name - dstname; /* length of DST zone name */ + if (dstlen < 3) + return -1; + if (*name != '\0' && *name != ',' && *name != ';') { + name = getoffset(name, &dstoffset); + if (name == NULL) + return -1; + } else dstoffset = stdoffset - SECSPERHOUR; + if (*name == ',' || *name == ';') { + struct rule start; + struct rule end; + register int year; + register time_t janfirst; + time_t starttime; + time_t endtime; + + ++name; + if ((name = getrule(name, &start)) == NULL) + return -1; + if (*name++ != ',') + return -1; + if ((name = getrule(name, &end)) == NULL) + return -1; + if (*name != '\0') + return -1; + sp->typecnt = 2; /* standard time and DST */ + /* + ** Two transitions per year, from EPOCH_YEAR to 2037. + */ + sp->timecnt = 2 * (2037 - EPOCH_YEAR + 1); + if (sp->timecnt > TZ_MAX_TIMES) + return -1; + sp->ttis[0].tt_gmtoff = -dstoffset; + sp->ttis[0].tt_isdst = 1; + sp->ttis[0].tt_abbrind = stdlen + 1; + sp->ttis[1].tt_gmtoff = -stdoffset; + sp->ttis[1].tt_isdst = 0; + sp->ttis[1].tt_abbrind = 0; + atp = sp->ats; + typep = sp->types; + janfirst = 0; + for (year = EPOCH_YEAR; year <= 2037; ++year) { + starttime = transtime(janfirst, year, &start, + stdoffset); + endtime = transtime(janfirst, year, &end, + dstoffset); + if (starttime > endtime) { + *atp++ = endtime; + *typep++ = 1; /* DST ends */ + *atp++ = starttime; + *typep++ = 0; /* DST begins */ + } else { + *atp++ = starttime; + *typep++ = 0; /* DST begins */ + *atp++ = endtime; + *typep++ = 1; /* DST ends */ + } + janfirst += year_lengths[isleap(year)] * + SECSPERDAY; + } + } else { + register long theirstdoffset; + register long theirdstoffset; + register long theiroffset; + register int isdst; + register int i; + register int j; + + if (*name != '\0') + return -1; + if (load_result != 0) + return -1; + /* + ** Initial values of theirstdoffset and theirdstoffset. + */ + theirstdoffset = 0; + for (i = 0; i < sp->timecnt; ++i) { + j = sp->types[i]; + if (!sp->ttis[j].tt_isdst) { + theirstdoffset = + -sp->ttis[j].tt_gmtoff; + break; + } + } + theirdstoffset = 0; + for (i = 0; i < sp->timecnt; ++i) { + j = sp->types[i]; + if (sp->ttis[j].tt_isdst) { + theirdstoffset = + -sp->ttis[j].tt_gmtoff; + break; + } + } + /* + ** Initially we're assumed to be in standard time. + */ + isdst = FALSE; + theiroffset = theirstdoffset; + /* + ** Now juggle transition times and types + ** tracking offsets as you do. + */ + for (i = 0; i < sp->timecnt; ++i) { + j = sp->types[i]; + sp->types[i] = sp->ttis[j].tt_isdst; + if (sp->ttis[j].tt_ttisgmt) { + /* No adjustment to transition time */ + } else { + /* + ** If summer time is in effect, and the + ** transition time was not specified as + ** standard time, add the summer time + ** offset to the transition time; + ** otherwise, add the standard time + ** offset to the transition time. + */ + /* + ** Transitions from DST to DDST + ** will effectively disappear since + ** POSIX provides for only one DST + ** offset. + */ + if (isdst && !sp->ttis[j].tt_ttisstd) { + sp->ats[i] += dstoffset - + theirdstoffset; + } else { + sp->ats[i] += stdoffset - + theirstdoffset; + } + } + theiroffset = -sp->ttis[j].tt_gmtoff; + if (sp->ttis[j].tt_isdst) + theirdstoffset = theiroffset; + else theirstdoffset = theiroffset; + } + /* + ** Finally, fill in ttis. + ** ttisstd and ttisgmt need not be handled. + */ + sp->ttis[0].tt_gmtoff = -stdoffset; + sp->ttis[0].tt_isdst = FALSE; + sp->ttis[0].tt_abbrind = 0; + sp->ttis[1].tt_gmtoff = -dstoffset; + sp->ttis[1].tt_isdst = TRUE; + sp->ttis[1].tt_abbrind = stdlen + 1; + } + } else { + dstlen = 0; + sp->typecnt = 1; /* only standard time */ + sp->timecnt = 0; + sp->ttis[0].tt_gmtoff = -stdoffset; + sp->ttis[0].tt_isdst = 0; + sp->ttis[0].tt_abbrind = 0; + } + sp->charcnt = stdlen + 1; + if (dstlen != 0) + sp->charcnt += dstlen + 1; + if (sp->charcnt > sizeof sp->chars) + return -1; + cp = sp->chars; + (void) strncpy(cp, stdname, stdlen); + cp += stdlen; + *cp++ = '\0'; + if (dstlen != 0) { + (void) strncpy(cp, dstname, dstlen); + *(cp + dstlen) = '\0'; + } + return 0; +} + +static void +gmtload(sp) +struct state * const sp; +{ + if (tzload(gmt, sp) != 0) + (void) tzparse(gmt, sp, TRUE); +} + +#ifndef STD_INSPIRED +/* +** A non-static declaration of tzsetwall in a system header file +** may cause a warning about this upcoming static declaration... +*/ +static +#endif /* !defined STD_INSPIRED */ +#ifdef _THREAD_SAFE +void +tzsetwall_basic P((void)) +#else +void +tzsetwall P((void)) +#endif +{ + +#ifdef ALL_STATE + if (lclptr == NULL) { + lclptr = (struct state *) malloc(sizeof *lclptr); + if (lclptr == NULL) { + settzname(); /* all we can do */ + return; + } + } +#endif /* defined ALL_STATE */ + if (tzload((char *) NULL, lclptr) != 0) + gmtload(lclptr); + settzname(); +} + +#ifdef _THREAD_SAFE +void +tzsetwall P((void)) +{ + pthread_mutex_lock(&lcl_mutex); + tzsetwall_basic(); + pthread_mutex_unlock(&lcl_mutex); +} +#endif + +#ifdef _THREAD_SAFE +static void +tzset_basic P((void)) +#else +void +tzset P((void)) +#endif +{ + register const char * name; + + name = getenv("TZ"); + if (name == NULL) { + tzsetwall(); + return; + } + + if (strlen(name) < sizeof(lcl_TZname)) + (void) strcpy(lcl_TZname, name); + +#ifdef ALL_STATE + if (lclptr == NULL) { + lclptr = (struct state *) malloc(sizeof *lclptr); + if (lclptr == NULL) { + settzname(); /* all we can do */ + return; + } + } +#endif /* defined ALL_STATE */ + if (*name == '\0') { + /* + ** User wants it fast rather than right. + */ + lclptr->leapcnt = 0; /* so, we're off a little */ + lclptr->timecnt = 0; + lclptr->ttis[0].tt_gmtoff = 0; + lclptr->ttis[0].tt_abbrind = 0; + (void) strcpy(lclptr->chars, gmt); + } else if (tzload(name, lclptr) != 0) + if (name[0] == ':' || tzparse(name, lclptr, FALSE) != 0) + (void) gmtload(lclptr); + settzname(); +} + +#ifdef _THREAD_SAFE +void +tzset P((void)) +{ + pthread_mutex_lock(&lcl_mutex); + tzset_basic(); + pthread_mutex_unlock(&lcl_mutex); +} +#endif + +/* +** The easy way to behave "as if no library function calls" localtime +** is to not call it--so we drop its guts into "localsub", which can be +** freely called. (And no, the PANS doesn't require the above behavior-- +** but it *is* desirable.) +** +** The unused offset argument is for the benefit of mktime variants. +*/ + +/*ARGSUSED*/ +static void +localsub(timep, offset, tmp) +const time_t * const timep; +const long offset; +struct tm * const tmp; +{ + register struct state * sp; + register const struct ttinfo * ttisp; + register int i; + const time_t t = *timep; + + sp = lclptr; +#ifdef ALL_STATE + if (sp == NULL) { + gmtsub(timep, offset, tmp); + return; + } +#endif /* defined ALL_STATE */ + if (sp->timecnt == 0 || t < sp->ats[0]) { + i = 0; + while (sp->ttis[i].tt_isdst) + if (++i >= sp->typecnt) { + i = 0; + break; + } + } else { + for (i = 1; i < sp->timecnt; ++i) + if (t < sp->ats[i]) + break; + i = sp->types[i - 1]; + } + ttisp = &sp->ttis[i]; + /* + ** To get (wrong) behavior that's compatible with System V Release 2.0 + ** you'd replace the statement below with + ** t += ttisp->tt_gmtoff; + ** timesub(&t, 0L, sp, tmp); + */ + timesub(&t, ttisp->tt_gmtoff, sp, tmp); + tmp->tm_isdst = ttisp->tt_isdst; + tzname[tmp->tm_isdst] = &sp->chars[ttisp->tt_abbrind]; +#ifdef TM_ZONE + tmp->TM_ZONE = &sp->chars[ttisp->tt_abbrind]; +#endif /* defined TM_ZONE */ +} + +struct tm * +localtime_r(timep, p_tm) +const time_t * const timep; +struct tm *p_tm; +{ +#ifdef _THREAD_SAFE + pthread_mutex_lock(&lcl_mutex); +#endif + tzset(); + localsub(timep, 0L, p_tm); +#ifdef _THREAD_SAFE + pthread_mutex_unlock(&lcl_mutex); +#endif + return(p_tm); +} + +struct tm * +localtime(timep) +const time_t * const timep; +{ +#ifdef _THREAD_SAFE + static struct pthread_mutex _localtime_mutex = PTHREAD_MUTEX_STATIC_INITIALIZER; + static pthread_mutex_t localtime_mutex = &_localtime_mutex; + static pthread_key_t localtime_key = -1; + struct tm *p_tm; + + pthread_mutex_lock(&localtime_mutex); + if (localtime_key < 0) { + if (pthread_key_create(&localtime_key, free) < 0) { + pthread_mutex_unlock(&localtime_mutex); + return(NULL); + } + } + pthread_mutex_unlock(&localtime_mutex); + p_tm = pthread_getspecific(localtime_key); + if (p_tm == NULL) { + if ((p_tm = (struct tm *)malloc(sizeof(struct tm))) == NULL) + return(NULL); + pthread_setspecific(localtime_key, p_tm); + } + pthread_mutex_lock(&lcl_mutex); + tzset(); + localsub(timep, 0L, p_tm); + pthread_mutex_unlock(&lcl_mutex); + return p_tm; +#else + tzset(); + localsub(timep, 0L, &tm); + return &tm; +#endif +} + +/* +** gmtsub is to gmtime as localsub is to localtime. +*/ + +static void +gmtsub(timep, offset, tmp) +const time_t * const timep; +const long offset; +struct tm * const tmp; +{ +#ifdef _THREAD_SAFE + pthread_mutex_lock(&gmt_mutex); +#endif +#ifdef ALL_STATE + if( gmtptr == NULL ) + gmtptr = (struct state *) malloc(sizeof *gmtptr); + if (gmtptr != NULL) +#endif /* defined ALL_STATE */ + gmtload(gmtptr); +#ifdef _THREAD_SAFE + pthread_mutex_unlock(&gmt_mutex); +#endif + timesub(timep, offset, gmtptr, tmp); +#ifdef TM_ZONE + /* + ** Could get fancy here and deliver something such as + ** "GMT+xxxx" or "GMT-xxxx" if offset is non-zero, + ** but this is no time for a treasure hunt. + */ + if (offset != 0) + tmp->TM_ZONE = wildabbr; + else { +#ifdef ALL_STATE + if (gmtptr == NULL) + tmp->TM_ZONE = gmt; + else tmp->TM_ZONE = gmtptr->chars; +#endif /* defined ALL_STATE */ +#ifndef ALL_STATE + tmp->TM_ZONE = gmtptr->chars; +#endif /* State Farm */ + } +#endif /* defined TM_ZONE */ +} + +struct tm * +gmtime(timep) +const time_t * const timep; +{ +#ifdef _THREAD_SAFE + static struct pthread_mutex _gmtime_mutex = PTHREAD_MUTEX_STATIC_INITIALIZER; + static pthread_mutex_t gmtime_mutex = &_gmtime_mutex; + static pthread_key_t gmtime_key = -1; + struct tm *p_tm; + + pthread_mutex_lock(&gmtime_mutex); + if (gmtime_key < 0) { + if (pthread_key_create(&gmtime_key, free) < 0) { + pthread_mutex_unlock(&gmtime_mutex); + return(NULL); + } + } + pthread_mutex_unlock(&gmtime_mutex); + /* + * Changed to follow draft 4 pthreads standard, which + * is what BSD currently has. + */ + if ((p_tm = pthread_getspecific(gmtime_key)) == NULL) { + if ((p_tm = (struct tm *)malloc(sizeof(struct tm))) == NULL) { + return(NULL); + } + pthread_setspecific(gmtime_key, p_tm); + } + gmtsub(timep, 0L, p_tm); + return(p_tm); +#else + gmtsub(timep, 0L, &tm); + return &tm; +#endif +} + +struct tm * +gmtime_r(const time_t * timep, struct tm * tm) +{ + gmtsub(timep, 0L, tm); + return(tm); +} + +#ifdef STD_INSPIRED + +struct tm * +offtime(timep, offset) +const time_t * const timep; +const long offset; +{ + gmtsub(timep, offset, &tm); + return &tm; +} + +#endif /* defined STD_INSPIRED */ + +static void +timesub(timep, offset, sp, tmp) +const time_t * const timep; +const long offset; +register const struct state * const sp; +register struct tm * const tmp; +{ + register const struct lsinfo * lp; + register long days; + register long rem; + register int y; + register int yleap; + register const int * ip; + register long corr; + register int hit; + register int i; + + corr = 0; + hit = 0; +#ifdef ALL_STATE + i = (sp == NULL) ? 0 : sp->leapcnt; +#endif /* defined ALL_STATE */ +#ifndef ALL_STATE + i = sp->leapcnt; +#endif /* State Farm */ + while (--i >= 0) { + lp = &sp->lsis[i]; + if (*timep >= lp->ls_trans) { + if (*timep == lp->ls_trans) { + hit = ((i == 0 && lp->ls_corr > 0) || + lp->ls_corr > sp->lsis[i - 1].ls_corr); + if (hit) + while (i > 0 && + sp->lsis[i].ls_trans == + sp->lsis[i - 1].ls_trans + 1 && + sp->lsis[i].ls_corr == + sp->lsis[i - 1].ls_corr + 1) { + ++hit; + --i; + } + } + corr = lp->ls_corr; + break; + } + } + days = *timep / SECSPERDAY; + rem = *timep % SECSPERDAY; +#ifdef mc68k + if (*timep == 0x80000000) { + /* + ** A 3B1 muffs the division on the most negative number. + */ + days = -24855; + rem = -11648; + } +#endif /* defined mc68k */ + rem += (offset - corr); + while (rem < 0) { + rem += SECSPERDAY; + --days; + } + while (rem >= SECSPERDAY) { + rem -= SECSPERDAY; + ++days; + } + tmp->tm_hour = (int) (rem / SECSPERHOUR); + rem = rem % SECSPERHOUR; + tmp->tm_min = (int) (rem / SECSPERMIN); + /* + ** A positive leap second requires a special + ** representation. This uses "... ??:59:60" et seq. + */ + tmp->tm_sec = (int) (rem % SECSPERMIN) + hit; + tmp->tm_wday = (int) ((EPOCH_WDAY + days) % DAYSPERWEEK); + if (tmp->tm_wday < 0) + tmp->tm_wday += DAYSPERWEEK; + y = EPOCH_YEAR; +#define LEAPS_THRU_END_OF(y) ((y) / 4 - (y) / 100 + (y) / 400) + while (days < 0 || days >= (long) year_lengths[yleap = isleap(y)]) { + register int newy; + + newy = y + days / DAYSPERNYEAR; + if (days < 0) + --newy; + days -= (newy - y) * DAYSPERNYEAR + + LEAPS_THRU_END_OF(newy - 1) - + LEAPS_THRU_END_OF(y - 1); + y = newy; + } + tmp->tm_year = y - TM_YEAR_BASE; + tmp->tm_yday = (int) days; + ip = mon_lengths[yleap]; + for (tmp->tm_mon = 0; days >= (long) ip[tmp->tm_mon]; ++(tmp->tm_mon)) + days = days - (long) ip[tmp->tm_mon]; + tmp->tm_mday = (int) (days + 1); + tmp->tm_isdst = 0; +#ifdef TM_GMTOFF + tmp->TM_GMTOFF = offset; +#endif /* defined TM_GMTOFF */ +} + +char * +ctime(timep) +const time_t * const timep; +{ +/* +** Section 4.12.3.2 of X3.159-1989 requires that +** The ctime funciton converts the calendar time pointed to by timer +** to local time in the form of a string. It is equivalent to +** asctime(localtime(timer)) +*/ + return asctime(localtime(timep)); +} + +char * +ctime_r(timep, buf) +const time_t * const timep; +char *buf; +{ + struct tm tm; + return asctime_r(localtime_r(timep, &tm), buf); +} + +/* +** Adapted from code provided by Robert Elz, who writes: +** The "best" way to do mktime I think is based on an idea of Bob +** Kridle's (so its said...) from a long time ago. +** [kridle@xinet.com as of 1996-01-16.] +** It does a binary search of the time_t space. Since time_t's are +** just 32 bits, its a max of 32 iterations (even at 64 bits it +** would still be very reasonable). +*/ + +#ifndef WRONG +#define WRONG (-1) +#endif /* !defined WRONG */ + +/* +** Simplified normalize logic courtesy Paul Eggert (eggert@twinsun.com). +*/ + +static int +increment_overflow(number, delta) +int * number; +int delta; +{ + int number0; + + number0 = *number; + *number += delta; + return (*number < number0) != (delta < 0); +} + +static int +normalize_overflow(tensptr, unitsptr, base) +int * const tensptr; +int * const unitsptr; +const int base; +{ + register int tensdelta; + + tensdelta = (*unitsptr >= 0) ? + (*unitsptr / base) : + (-1 - (-1 - *unitsptr) / base); + *unitsptr -= tensdelta * base; + return increment_overflow(tensptr, tensdelta); +} + +static int +tmcomp(atmp, btmp) +register const struct tm * const atmp; +register const struct tm * const btmp; +{ + register int result; + + if ((result = (atmp->tm_year - btmp->tm_year)) == 0 && + (result = (atmp->tm_mon - btmp->tm_mon)) == 0 && + (result = (atmp->tm_mday - btmp->tm_mday)) == 0 && + (result = (atmp->tm_hour - btmp->tm_hour)) == 0 && + (result = (atmp->tm_min - btmp->tm_min)) == 0) + result = atmp->tm_sec - btmp->tm_sec; + return result; +} + +static time_t +time2(tmp, funcp, offset, okayp) +struct tm * const tmp; +void (* const funcp) P((const time_t*, long, struct tm*)); +const long offset; +int * const okayp; +{ + register const struct state * sp; + register int dir; + register int bits; + register int i, j ; + register int saved_seconds; + time_t newt; + time_t t; + struct tm yourtm, mytm; + + *okayp = FALSE; + yourtm = *tmp; + if (normalize_overflow(&yourtm.tm_hour, &yourtm.tm_min, MINSPERHOUR)) + return WRONG; + if (normalize_overflow(&yourtm.tm_mday, &yourtm.tm_hour, HOURSPERDAY)) + return WRONG; + if (normalize_overflow(&yourtm.tm_year, &yourtm.tm_mon, MONSPERYEAR)) + return WRONG; + /* + ** Turn yourtm.tm_year into an actual year number for now. + ** It is converted back to an offset from TM_YEAR_BASE later. + */ + if (increment_overflow(&yourtm.tm_year, TM_YEAR_BASE)) + return WRONG; + while (yourtm.tm_mday <= 0) { + if (increment_overflow(&yourtm.tm_year, -1)) + return WRONG; + i = yourtm.tm_year + (1 < yourtm.tm_mon); + yourtm.tm_mday += year_lengths[isleap(i)]; + } + while (yourtm.tm_mday > DAYSPERLYEAR) { + i = yourtm.tm_year + (1 < yourtm.tm_mon); + yourtm.tm_mday -= year_lengths[isleap(i)]; + if (increment_overflow(&yourtm.tm_year, 1)) + return WRONG; + } + for ( ; ; ) { + i = mon_lengths[isleap(yourtm.tm_year)][yourtm.tm_mon]; + if (yourtm.tm_mday <= i) + break; + yourtm.tm_mday -= i; + if (++yourtm.tm_mon >= MONSPERYEAR) { + yourtm.tm_mon = 0; + if (increment_overflow(&yourtm.tm_year, 1)) + return WRONG; + } + } + if (increment_overflow(&yourtm.tm_year, -TM_YEAR_BASE)) + return WRONG; + if (yourtm.tm_year + TM_YEAR_BASE < EPOCH_YEAR) { + /* + ** We can't set tm_sec to 0, because that might push the + ** time below the minimum representable time. + ** Set tm_sec to 59 instead. + ** This assumes that the minimum representable time is + ** not in the same minute that a leap second was deleted from, + ** which is a safer assumption than using 58 would be. + */ + if (increment_overflow(&yourtm.tm_sec, 1 - SECSPERMIN)) + return WRONG; + saved_seconds = yourtm.tm_sec; + yourtm.tm_sec = SECSPERMIN - 1; + } else { + saved_seconds = yourtm.tm_sec; + yourtm.tm_sec = 0; + } + /* + ** Divide the search space in half + ** (this works whether time_t is signed or unsigned). + */ + bits = TYPE_BIT(time_t) - 1; + /* + ** If time_t is signed, then 0 is just above the median, + ** assuming two's complement arithmetic. + ** If time_t is unsigned, then (1 << bits) is just above the median. + */ + t = TYPE_SIGNED(time_t) ? 0 : (((time_t) 1) << bits); + for ( ; ; ) { + (*funcp)(&t, offset, &mytm); + dir = tmcomp(&mytm, &yourtm); + if (dir != 0) { + if (bits-- < 0) + return WRONG; + if (bits < 0) + --t; /* may be needed if new t is minimal */ + else if (dir > 0) + t -= ((time_t) 1) << bits; + else t += ((time_t) 1) << bits; + continue; + } + if (yourtm.tm_isdst < 0 || mytm.tm_isdst == yourtm.tm_isdst) + break; + /* + ** Right time, wrong type. + ** Hunt for right time, right type. + ** 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); +#ifdef ALL_STATE + if (sp == NULL) + return WRONG; +#endif /* defined ALL_STATE */ + for (i = sp->typecnt - 1; i >= 0; --i) { + if (sp->ttis[i].tt_isdst != yourtm.tm_isdst) + continue; + for (j = sp->typecnt - 1; j >= 0; --j) { + if (sp->ttis[j].tt_isdst == yourtm.tm_isdst) + continue; + newt = t + sp->ttis[j].tt_gmtoff - + sp->ttis[i].tt_gmtoff; + (*funcp)(&newt, offset, &mytm); + if (tmcomp(&mytm, &yourtm) != 0) + continue; + if (mytm.tm_isdst != yourtm.tm_isdst) + continue; + /* + ** We have a match. + */ + t = newt; + goto label; + } + } + return WRONG; + } +label: + newt = t + saved_seconds; + if ((newt < t) != (saved_seconds < 0)) + return WRONG; + t = newt; + (*funcp)(&t, offset, tmp); + *okayp = TRUE; + return t; +} + +static time_t +time1(tmp, funcp, offset) +struct tm * const tmp; +void (* const funcp) P((const time_t *, long, struct tm *)); +const long offset; +{ + register time_t t; + register const struct state * sp; + register int samei, otheri; + int okay; + + if (tmp->tm_isdst > 1) + tmp->tm_isdst = 1; + t = time2(tmp, funcp, offset, &okay); +#ifdef PCTS + /* + ** PCTS code courtesy Grant Sullivan (grant@osf.org). + */ + if (okay) + return t; + if (tmp->tm_isdst < 0) + tmp->tm_isdst = 0; /* reset to std and try again */ +#endif /* defined PCTS */ +#ifndef PCTS + if (okay || tmp->tm_isdst < 0) + return t; +#endif /* !defined PCTS */ + /* + ** We're supposed to assume that somebody took a time of one type + ** and did some math on it that yielded a "struct tm" that's bad. + ** 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); +#ifdef ALL_STATE + if (sp == NULL) + return WRONG; +#endif /* defined ALL_STATE */ + for (samei = sp->typecnt - 1; samei >= 0; --samei) { + if (sp->ttis[samei].tt_isdst != tmp->tm_isdst) + continue; + for (otheri = sp->typecnt - 1; otheri >= 0; --otheri) { + if (sp->ttis[otheri].tt_isdst == tmp->tm_isdst) + continue; + tmp->tm_sec += sp->ttis[otheri].tt_gmtoff - + sp->ttis[samei].tt_gmtoff; + tmp->tm_isdst = !tmp->tm_isdst; + t = time2(tmp, funcp, offset, &okay); + if (okay) + return t; + tmp->tm_sec -= sp->ttis[otheri].tt_gmtoff - + sp->ttis[samei].tt_gmtoff; + tmp->tm_isdst = !tmp->tm_isdst; + } + } + return WRONG; +} + +time_t +mktime(tmp) +struct tm * const tmp; +{ + time_t mktime_return_value; +#ifdef _THREAD_SAFE + pthread_mutex_lock(&lcl_mutex); +#endif + tzset(); + mktime_return_value = time1(tmp, localsub, 0L); +#ifdef _THREAD_SAFE + pthread_mutex_unlock(&lcl_mutex); +#endif + return(mktime_return_value); +} + +#ifdef STD_INSPIRED + +time_t +timelocal(tmp) +struct tm * const tmp; +{ + tmp->tm_isdst = -1; /* in case it wasn't initialized */ + return mktime(tmp); +} + +time_t +timegm(tmp) +struct tm * const tmp; +{ + tmp->tm_isdst = 0; + return time1(tmp, gmtsub, 0L); +} + +time_t +timeoff(tmp, offset) +struct tm * const tmp; +const long offset; +{ + tmp->tm_isdst = 0; + return time1(tmp, gmtsub, offset); +} + +#endif /* defined STD_INSPIRED */ + +#ifdef CMUCS + +/* +** The following is supplied for compatibility with +** previous versions of the CMUCS runtime library. +*/ + +long +gtime(tmp) +struct tm * const tmp; +{ + const time_t t = mktime(tmp); + + if (t == WRONG) + return -1; + return t; +} + +#endif /* defined CMUCS */ + +/* +** XXX--is the below the right way to conditionalize?? +*/ + +#ifdef STD_INSPIRED + +/* +** IEEE Std 1003.1-1988 (POSIX) legislates that 536457599 +** shall correspond to "Wed Dec 31 23:59:59 GMT 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. +*/ + +static long +leapcorr(timep) +time_t * timep; +{ + register struct state * sp; + register struct lsinfo * lp; + register int i; + + sp = lclptr; + i = sp->leapcnt; + while (--i >= 0) { + lp = &sp->lsis[i]; + if (*timep >= lp->ls_trans) + return lp->ls_corr; + } + return 0; +} + +time_t +time2posix(t) +time_t t; +{ + tzset(); + return t - leapcorr(&t); +} + +time_t +posix2time(t) +time_t t; +{ + time_t x; + time_t y; + + tzset(); + /* + ** For a positive leap second hit, the result + ** is not unique. For a negative leap second + ** hit, the corresponding time doesn't exist, + ** so we return an adjacent second. + */ + x = t + leapcorr(&t); + y = x - leapcorr(&x); + if (y < t) { + do { + x++; + y = x - leapcorr(&x); + } while (y < t); + if (t != y) + return x - 1; + } else if (y > t) { + do { + --x; + y = x - leapcorr(&x); + } while (y > t); + if (t != y) + return x + 1; + } + return x; +} + +#endif /* defined STD_INSPIRED */ diff --git a/stdtime/private.h b/stdtime/private.h new file mode 100644 index 0000000..90329d3 --- /dev/null +++ b/stdtime/private.h @@ -0,0 +1,220 @@ +/* $FreeBSD: src/lib/libc/stdtime/private.h,v 1.6.8.1 2000/08/23 00:19:15 jhb Exp $ */ + +#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). +*/ + +/* Stuff moved from Makefile.inc to reduce clutter */ +#ifndef TM_GMTOFF +#define TM_GMTOFF tm_gmtoff +#define TM_ZONE tm_zone +#define STD_INSPIRED 1 +#define PCTS 1 +#define HAVE_LONG_DOUBLE 1 +#define HAVE_STRERROR 1 +#define HAVE_UNISTD_H 1 +#define LOCALE_HOME _PATH_LOCALE +#define TZDIR "/usr/share/zoneinfo" +#endif /* ndef TM_GMTOFF */ + +/* +** This header is for use ONLY with the time conversion code. +** There is no guarantee that it will remain unchanged, +** or that it will remain at all. +** Do NOT copy it to any system include directory. +** Thank you! +*/ + +/* +** ID +*/ + +#ifndef lint +#ifndef NOID +/* +static char privatehid[] = "@(#)private.h 7.43"; +*/ +#endif /* !defined NOID */ +#endif /* !defined lint */ + +/* +** Defaults for preprocessor symbols. +** You can override these in your C compiler options, e.g. `-DHAVE_ADJTIME=0'. +*/ + +#ifndef HAVE_ADJTIME +#define HAVE_ADJTIME 1 +#endif /* !defined HAVE_ADJTIME */ + +#ifndef HAVE_GETTEXT +#define HAVE_GETTEXT 0 +#endif /* !defined HAVE_GETTEXT */ + +#ifndef HAVE_SETTIMEOFDAY +#define HAVE_SETTIMEOFDAY 3 +#endif /* !defined HAVE_SETTIMEOFDAY */ + +#ifndef HAVE_STRERROR +#define HAVE_STRERROR 0 +#endif /* !defined HAVE_STRERROR */ + +#ifndef HAVE_UNISTD_H +#define HAVE_UNISTD_H 1 +#endif /* !defined HAVE_UNISTD_H */ + +#ifndef HAVE_UTMPX_H +#define HAVE_UTMPX_H 0 +#endif /* !defined HAVE_UTMPX_H */ + +#ifndef LOCALE_HOME +#define LOCALE_HOME "/usr/lib/locale" +#endif /* !defined LOCALE_HOME */ + +/* +** Nested includes +*/ + +#include "sys/types.h" /* for time_t */ +#include "stdio.h" +#include "errno.h" +#include "string.h" +#include "limits.h" /* for CHAR_BIT */ +#include "time.h" +#include "stdlib.h" + +#if HAVE_GETTEXT - 0 +#include "libintl.h" +#endif /* HAVE_GETTEXT - 0 */ + +#if HAVE_UNISTD_H - 0 +#include "unistd.h" /* for F_OK and R_OK */ +#endif /* HAVE_UNISTD_H - 0 */ + +#if !(HAVE_UNISTD_H - 0) +#ifndef F_OK +#define F_OK 0 +#endif /* !defined F_OK */ +#ifndef R_OK +#define R_OK 4 +#endif /* !defined R_OK */ +#endif /* !(HAVE_UNISTD_H - 0) */ + +/* Unlike 's isdigit, this also works if c < 0 | c > UCHAR_MAX. */ +#define is_digit(c) ((unsigned)(c) - '0' <= 9) + +/* +** Workarounds for compilers/systems. +*/ + +#ifndef P +#ifdef __STDC__ +#define P(x) x +#endif /* defined __STDC__ */ +#ifndef __STDC__ +#define P(x) () +#endif /* !defined __STDC__ */ +#endif /* !defined P */ + +/* +** SunOS 4.1.1 headers lack FILENAME_MAX. +*/ + +#ifndef FILENAME_MAX + +#ifndef MAXPATHLEN +#ifdef unix +#include "sys/param.h" +#endif /* defined unix */ +#endif /* !defined MAXPATHLEN */ + +#ifdef MAXPATHLEN +#define FILENAME_MAX MAXPATHLEN +#endif /* defined MAXPATHLEN */ +#ifndef MAXPATHLEN +#define FILENAME_MAX 1024 /* Pure guesswork */ +#endif /* !defined MAXPATHLEN */ + +#endif /* !defined FILENAME_MAX */ + +/* +** Finally, some convenience items. +*/ + +#ifndef TRUE +#define TRUE 1 +#endif /* !defined TRUE */ + +#ifndef FALSE +#define FALSE 0 +#endif /* !defined FALSE */ + +#ifndef TYPE_BIT +#define TYPE_BIT(type) (sizeof (type) * CHAR_BIT) +#endif /* !defined TYPE_BIT */ + +#ifndef TYPE_SIGNED +#define TYPE_SIGNED(type) (((type) -1) < 0) +#endif /* !defined TYPE_SIGNED */ + +#ifndef INT_STRLEN_MAXIMUM +/* +** 302 / 1000 is log10(2.0) rounded up. +** Subtract one for the sign bit if the type is signed; +** add one for integer division truncation; +** add one more for a minus sign if the type is signed. +*/ +#define INT_STRLEN_MAXIMUM(type) \ + ((TYPE_BIT(type) - TYPE_SIGNED(type)) * 302 / 1000 + 1 + TYPE_SIGNED(type)) +#endif /* !defined INT_STRLEN_MAXIMUM */ + +/* +** INITIALIZE(x) +*/ + +#ifndef GNUC_or_lint +#ifdef lint +#define GNUC_or_lint +#endif /* defined lint */ +#ifndef lint +#ifdef __GNUC__ +#define GNUC_or_lint +#endif /* defined __GNUC__ */ +#endif /* !defined lint */ +#endif /* !defined GNUC_or_lint */ + +#ifndef INITIALIZE +#ifdef GNUC_or_lint +#define INITIALIZE(x) ((x) = 0) +#endif /* defined GNUC_or_lint */ +#ifndef GNUC_or_lint +#define INITIALIZE(x) +#endif /* !defined GNUC_or_lint */ +#endif /* !defined INITIALIZE */ + +/* +** For the benefit of GNU folk... +** `_(MSGID)' uses the current locale's message library string for MSGID. +** The default is to use gettext if available, and use MSGID otherwise. +*/ + +#ifndef _ +#if HAVE_GETTEXT - 0 +#define _(msgid) gettext(msgid) +#else /* !(HAVE_GETTEXT - 0) */ +#define _(msgid) msgid +#endif /* !(HAVE_GETTEXT - 0) */ +#endif /* !defined _ */ + +#ifndef TZ_DOMAIN +#define TZ_DOMAIN "tz" +#endif /* !defined TZ_DOMAIN */ + +/* +** UNIX was a registered trademark of UNIX System Laboratories in 1993. +*/ + +#endif /* !defined PRIVATE_H */ diff --git a/stdtime/strftime.3 b/stdtime/strftime.3 new file mode 100644 index 0000000..1a6f074 --- /dev/null +++ b/stdtime/strftime.3 @@ -0,0 +1,265 @@ +.\" Copyright (c) 1989, 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. +.\" +.\" @(#)strftime.3 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD: src/lib/libc/stdtime/strftime.3,v 1.18.2.7 2001/12/14 18:33:59 ru Exp $ +.\" +.Dd October 4, 1997 +.Dt STRFTIME 3 +.Os +.Sh NAME +.Nm strftime +.Nd format date and time +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In time.h +.Ft size_t +.Fn strftime "char *buf" "size_t maxsize" "const char *format" "const struct tm *timeptr" +.Sh DESCRIPTION +The +.Fn strftime +function formats the information from +.Fa timeptr +into the buffer +.Fa buf +according to the string pointed to by +.Fa format . +.Pp +The +.Fa format +string consists of zero or more conversion specifications and +ordinary characters. +All ordinary characters are copied directly into the buffer. +A conversion specification consists of a percent sign +.Dq Ql % +and one other character. +.Pp +No more than +.Fa maxsize +characters will be placed into the array. +If the total number of resulting characters, including the terminating +NUL character, is not more than +.Fa maxsize , +.Fn strftime +returns the number of characters in the array, not counting the +terminating NUL. +Otherwise, zero is returned and the buffer contents is indeterminate. +.Pp +The conversion specifications are copied to the buffer after expansion +as follows:- +.Bl -tag -width "xxxx" +.It Cm \&%A +is replaced by national representation of the full weekday name. +.It Cm %a +is replaced by national representation of +the abbreviated weekday name, where the abbreviation +is the first three characters. +.It Cm \&%B +is replaced by national representation of the full month name. +.It Cm %b +is replaced by national representation of +the abbreviated month name, where the abbreviation is +the first three characters. +.It Cm \&%C +is replaced by (year / 100) as decimal number; single +digits are preceded by a zero. +.It Cm %c +is replaced by national representation of time and date. +The format is similar to that produced by +.Xr ctime 3 +and is +equivalent to "%a %Ef %T %Y". +It also implies the +"3+1+6+1+8+1+4" format of output. +.It Cm \&%D +is equivalent to +.Dq Li %m/%d/%y . +.It Cm %d +is replaced by the day of the month as a decimal number (01-31). +.It Cm \&%E* Cm \&%O* +POSIX locale extensions. +The sequences +%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. +.Pp +Additionly %Ef implemented to represent short month name / day +order of the date, %EF to represent long month name / day +order +and %OB to represent alternative months names +(used standalone, without day mentioned). +.It Cm %e +is replaced by the day of month as a decimal number (1-31); single +digits are preceded by a blank. +.It Cm \&%G +is replaced by a year as a decimal number with century. +This year is the one that contains the greater part of +the week (Monday as the first day of the week). +.It Cm %g +is replaced by the same year as in +.Dq Li %G , +but as a decimal number without century (00-99). +.It Cm \&%H +is replaced by the hour (24-hour clock) as a decimal number (00-23). +.It Cm %h +the same as %b. +.It Cm \&%I +is replaced by the hour (12-hour clock) as a decimal number (01-12). +.It Cm %j +is replaced by the day of the year as a decimal number (001-366). +.It Cm %k +is replaced by the hour (24-hour clock) as a decimal number (0-23); +single digits are preceded by a blank. +.It Cm %l +is replaced by the hour (12-hour clock) as a decimal number (1-12); +single digits are preceded by a blank. +.It Cm \&%M +is replaced by the minute as a decimal number (00-59). +.It Cm %m +is replaced by the month as a decimal number (01-12). +.It Cm %n +is replaced by a newline. +.It Cm \&%O* +the same as %E*. +.It Cm %p +is replaced by national representation of either +"ante meridiem" +or +"post meridiem" +as appropriate. +.It Cm \&%R +is equivalent to +.Dq Li %H:%M . +.It Cm %r +is equivalent to +.Dq Li %I:%M:%S %p . +.It Cm \&%S +is replaced by the second as a decimal number (00-60). +.It Cm %s +is replaced by the number of seconds since the Epoch, UTC (see +.Xr mktime 3 ) . +.It Cm \&%T +is equivalent to +.Dq Li %H:%M:%S . +.It Cm %t +is replaced by a tab. +.It Cm \&%U +is replaced by the week number of the year (Sunday as the first day of +the week) as a decimal number (00-53). +.It Cm %u +is replaced by the weekday (Monday as the first day of the week) +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 +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 +is equivalent to +.Dq Li %e-%b-%Y . +.It Cm \&%W +is replaced by the week number of the year (Monday as the first day of +the week) as a decimal number (00-53). +.It Cm %w +is replaced by the weekday (Sunday as the first day of the week) +as a decimal number (0-6). +.It Cm \&%X +is replaced by national representation of the time. +.It Cm %x +is replaced by national representation of the date. +.It Cm \&%Y +is replaced by the year with century as a decimal number. +.It Cm %y +is replaced by the year without century as a decimal number (00-99). +.It Cm \&%Z +is replaced by the time zone name. +.It Cm \&%z +is replaced by the time zone offset from UTC; a leading plus sign stands for +east of UTC, a minus sign for west of UTC, hours and minutes follow +with two digits each and no delimiter between them (common form for +RFC 822 date headers). +.It Cm %+ +is replaced by national representation of the date and time +(the format is similar to that produced by +.Xr date 1 ) . +.It Cm %% +is replaced by +.Ql % . +.El +.Sh SEE ALSO +.Xr date 1 , +.Xr printf 1 , +.Xr ctime 3 , +.Xr printf 3 , +.Xr strptime 3 +.Sh STANDARDS +The +.Fn strftime +function +conforms to +.St -isoC +with a lot of extensions including +.Ql %C , +.Ql \&%D , +.Ql %E* , +.Ql %e , +.Ql %G , +.Ql %g , +.Ql %h , +.Ql %k , +.Ql %l , +.Ql %n , +.Ql %O* , +.Ql \&%R , +.Ql %r , +.Ql %s , +.Ql \&%T , +.Ql %t , +.Ql %u , +.Ql \&%V , +.Ql %z , +.Ql %+ . +.Pp +The peculiar week number and year in the replacements of +.Ql %G , +.Ql %g +and +.Ql \&%V +are defined in ISO 8601: 1988. +.Sh BUGS +There is no conversion specification for the phase of the moon. diff --git a/stdtime/strftime.c b/stdtime/strftime.c new file mode 100644 index 0000000..21625c7 --- /dev/null +++ b/stdtime/strftime.c @@ -0,0 +1,459 @@ +/* + * Copyright (c) 1989 The Regents of the University of California. + * All rights reserved. + * + * Redistribution and use in source and binary forms are permitted + * provided that the above copyright notice and this paragraph are + * duplicated in all such forms and that any documentation, + * advertising materials, and other materials related to such + * distribution and use acknowledge that the software was developed + * by the University of California, Berkeley. The name of the + * University may not be used to endorse or promote products derived + * from this software without specific prior written permission. + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. + */ + +#ifdef LIBC_RCS +static const char rcsid[] = + "$FreeBSD: src/lib/libc/stdtime/strftime.c,v 1.25.2.3 2001/02/18 04:06:49 kris Exp $"; +#endif + +#ifndef lint +#ifndef NOID +static const char elsieid[] = "@(#)strftime.c 7.38"; +/* +** Based on the UCB version with the ID appearing below. +** This is ANSIish only when "multibyte character == plain character". +*/ +#endif /* !defined NOID */ +#endif /* !defined lint */ + +#include "private.h" + +#ifndef LIBC_SCCS +#ifndef lint +static const char sccsid[] = "@(#)strftime.c 5.4 (Berkeley) 3/14/89"; +#endif /* !defined lint */ +#endif /* !defined LIBC_SCCS */ + +#include "tzfile.h" +#include +#include +#include "timelocal.h" + +static char * _add P((const char *, char *, const char *)); +static char * _conv P((int, const char *, char *, const char *)); +static char * _fmt P((const char *, const struct tm *, char *, const char *)); + +size_t strftime P((char *, size_t, const char *, const struct tm *)); + +extern char * tzname[]; + +size_t +strftime(s, maxsize, format, t) + char *const s; + const size_t maxsize; + const char *const format; + const struct tm *const t; +{ + char *p; + + tzset(); + p = _fmt(((format == NULL) ? "%c" : format), t, s, s + maxsize); + if (p == s + maxsize) + return 0; + *p = '\0'; + return p - s; +} + +static char * +_fmt(format, t, pt, ptlim) + const char *format; + const struct tm *const t; + char *pt; + const char *const ptlim; +{ + int Ealternative, Oalternative; + + for ( ; *format; ++format) { + if (*format == '%') { + Ealternative = 0; + Oalternative = 0; +label: + switch (*++format) { + case '\0': + --format; + break; + case 'A': + pt = _add((t->tm_wday < 0 || t->tm_wday > 6) ? + "?" : Locale->weekday[t->tm_wday], + pt, ptlim); + continue; + case 'a': + pt = _add((t->tm_wday < 0 || t->tm_wday > 6) ? + "?" : Locale->wday[t->tm_wday], + pt, ptlim); + continue; + case 'B': + pt = _add((t->tm_mon < 0 || t->tm_mon > 11) ? + "?" : (Oalternative ? Locale->alt_month : + Locale->month)[t->tm_mon], + pt, ptlim); + continue; + case 'b': + case 'h': + pt = _add((t->tm_mon < 0 || t->tm_mon > 11) ? + "?" : Locale->mon[t->tm_mon], + pt, ptlim); + continue; + case 'C': + /* + ** %C used to do a... + ** _fmt("%a %b %e %X %Y", t); + ** ...whereas now POSIX 1003.2 calls for + ** something completely different. + ** (ado, 5/24/93) + */ + pt = _conv((t->tm_year + TM_YEAR_BASE) / 100, + "%02d", pt, ptlim); + continue; + case 'c': + /* NOTE: c_fmt is intentionally ignored */ + pt = _fmt("%a %Ef %T %Y", t, pt, ptlim); + continue; + case 'D': + pt = _fmt("%m/%d/%y", t, pt, ptlim); + continue; + case 'd': + pt = _conv(t->tm_mday, "%02d", pt, ptlim); + continue; + case 'E': + if (Ealternative || Oalternative) + break; + Ealternative++; + goto label; + case 'O': + /* + ** POSIX locale extensions, a la + ** Arnold Robbins' strftime version 3.0. + ** The sequences + ** %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 + */ + if (Ealternative || Oalternative) + break; + Oalternative++; + goto label; + case 'e': + pt = _conv(t->tm_mday, "%2d", pt, ptlim); + continue; + case 'f': + if (!Ealternative) + break; + pt = _fmt(Locale->Ef_fmt, t, pt, ptlim); + continue; + case 'F': + if (!Ealternative) + break; + pt = _fmt(Locale->EF_fmt, t, pt, ptlim); + continue; + case 'H': + pt = _conv(t->tm_hour, "%02d", pt, ptlim); + continue; + case 'I': + pt = _conv((t->tm_hour % 12) ? + (t->tm_hour % 12) : 12, + "%02d", pt, ptlim); + continue; + case 'j': + pt = _conv(t->tm_yday + 1, "%03d", pt, ptlim); + continue; + case 'k': + /* + ** This used to be... + ** _conv(t->tm_hour % 12 ? + ** t->tm_hour % 12 : 12, 2, ' '); + ** ...and has been changed to the below to + ** match SunOS 4.1.1 and Arnold Robbins' + ** strftime version 3.0. That is, "%k" and + ** "%l" have been swapped. + ** (ado, 5/24/93) + */ + pt = _conv(t->tm_hour, "%2d", pt, ptlim); + continue; +#ifdef KITCHEN_SINK + case 'K': + /* + ** After all this time, still unclaimed! + */ + pt = _add("kitchen sink", pt, ptlim); + continue; +#endif /* defined KITCHEN_SINK */ + case 'l': + /* + ** This used to be... + ** _conv(t->tm_hour, 2, ' '); + ** ...and has been changed to the below to + ** 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) + */ + pt = _conv((t->tm_hour % 12) ? + (t->tm_hour % 12) : 12, + "%2d", pt, ptlim); + continue; + case 'M': + pt = _conv(t->tm_min, "%02d", pt, ptlim); + continue; + case 'm': + pt = _conv(t->tm_mon + 1, "%02d", pt, ptlim); + continue; + case 'n': + pt = _add("\n", pt, ptlim); + continue; + case 'p': + pt = _add((t->tm_hour >= 12) ? + Locale->pm : + Locale->am, + pt, ptlim); + continue; + case 'R': + pt = _fmt("%H:%M", t, pt, ptlim); + continue; + case 'r': + pt = _fmt("%I:%M:%S %p", t, pt, ptlim); + continue; + case 'S': + pt = _conv(t->tm_sec, "%02d", pt, ptlim); + continue; + case 's': + { + struct tm tm; + char buf[INT_STRLEN_MAXIMUM( + time_t) + 1]; + time_t mkt; + + tm = *t; + mkt = mktime(&tm); + if (TYPE_SIGNED(time_t)) + (void) sprintf(buf, "%ld", + (long) mkt); + else (void) sprintf(buf, "%lu", + (unsigned long) mkt); + pt = _add(buf, pt, ptlim); + } + continue; + case 'T': + pt = _fmt("%H:%M:%S", t, pt, ptlim); + continue; + case 't': + pt = _add("\t", pt, ptlim); + continue; + case 'U': + pt = _conv((t->tm_yday + 7 - t->tm_wday) / 7, + "%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) + */ + pt = _conv((t->tm_wday == 0) ? 7 : t->tm_wday, + "%d", pt, ptlim); + continue; + case 'V': /* ISO 8601 week number */ + case 'G': /* ISO 8601 year (four digits) */ + case 'g': /* ISO 8601 year (two digits) */ +/* +** From Arnold Robbins' strftime version 3.0: "the week number of the +** year (the first Monday as the first day of week 1) as a decimal number +** (01-53)." +** (ado, 1993-05-24) +** +** From "http://www.ft.uni-erlangen.de/~mskuhn/iso-time.html" by Markus Kuhn: +** "Week 01 of a year is per definition the first week which has the +** Thursday in this year, which is equivalent to the week which contains +** the fourth day of January. In other words, the first week of a new year +** is the week which has the majority of its days in the new year. Week 01 +** might also contain days from the previous year and the week before week +** 01 of a year is the last week (52 or 53) of the previous year even if +** it contains days from the new year. A week starts with Monday (day 1) +** and ends with Sunday (day 7). For example, the first week of the year +** 1997 lasts from 1996-12-30 to 1997-01-05..." +** (ado, 1996-01-02) +*/ + { + int year; + int yday; + int wday; + int w; + + year = t->tm_year + TM_YEAR_BASE; + yday = t->tm_yday; + wday = t->tm_wday; + for ( ; ; ) { + int len; + int bot; + int top; + + len = isleap(year) ? + DAYSPERLYEAR : + DAYSPERNYEAR; + /* + ** What yday (-3 ... 3) does + ** the ISO year begin on? + */ + bot = ((yday + 11 - wday) % + DAYSPERWEEK) - 3; + /* + ** What yday does the NEXT + ** ISO year begin on? + */ + top = bot - + (len % DAYSPERWEEK); + if (top < -3) + top += DAYSPERWEEK; + top += len; + if (yday >= top) { + ++year; + w = 1; + break; + } + if (yday >= bot) { + w = 1 + ((yday - bot) / + DAYSPERWEEK); + break; + } + --year; + yday += isleap(year) ? + DAYSPERLYEAR : + DAYSPERNYEAR; + } +#ifdef XPG4_1994_04_09 + if ((w == 52 + && t->tm_mon == TM_JANUARY) + || (w == 1 + && t->tm_mon == TM_DECEMBER)) + w = 53; +#endif /* defined XPG4_1994_04_09 */ + if (*format == 'V') + pt = _conv(w, "%02d", + pt, ptlim); + else if (*format == 'g') { + pt = _conv(year % 100, "%02d", + pt, ptlim); + } else pt = _conv(year, "%04d", + pt, ptlim); + } + continue; + case 'v': + /* + ** From Arnold Robbins' strftime version 3.0: + ** "date as dd-bbb-YYYY" + ** (ado, 5/24/93) + */ + pt = _fmt("%e-%b-%Y", t, pt, ptlim); + continue; + case 'W': + pt = _conv((t->tm_yday + 7 - + (t->tm_wday ? + (t->tm_wday - 1) : 6)) / 7, + "%02d", pt, ptlim); + continue; + case 'w': + pt = _conv(t->tm_wday, "%d", pt, ptlim); + continue; + case 'X': + pt = _fmt(Locale->X_fmt, t, pt, ptlim); + continue; + case 'x': + pt = _fmt(Locale->x_fmt, t, pt, ptlim); + continue; + case 'y': + pt = _conv((t->tm_year + TM_YEAR_BASE) % 100, + "%02d", pt, ptlim); + continue; + case 'Y': + pt = _conv(t->tm_year + TM_YEAR_BASE, "%04d", + pt, ptlim); + continue; + case 'Z': + 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], + pt, ptlim); + } else pt = _add("?", pt, ptlim); + 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); + }; + continue; + case '+': + pt = _fmt(Locale->date_fmt, t, pt, ptlim); + 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. + */ + default: + break; + } + } + if (pt == ptlim) + break; + *pt++ = *format; + } + return pt; +} + +static char * +_conv(n, format, pt, ptlim) + const int n; + const char *const format; + char *const pt; + const char *const ptlim; +{ + char buf[INT_STRLEN_MAXIMUM(int) + 1]; + + (void) sprintf(buf, format, n); + return _add(buf, pt, ptlim); +} + +static char * +_add(str, pt, ptlim) + const char *str; + char *pt; + const char *const ptlim; +{ + while (pt < ptlim && (*pt = *str++) != '\0') + ++pt; + return pt; +} diff --git a/stdtime/strptime.3 b/stdtime/strptime.3 new file mode 100644 index 0000000..eedf7d1 --- /dev/null +++ b/stdtime/strptime.3 @@ -0,0 +1,139 @@ +.\" +.\" Copyright (c) 1997 Joerg Wunsch +.\" +.\" 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 DEVELOPERS ``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 DEVELOPERS 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/stdtime/strptime.3,v 1.9.2.7 2001/12/14 18:33:59 ru Exp $ +.\" " +.Dd May 8, 1997 +.Dt STRPTIME 3 +.Os +.Sh NAME +.Nm strptime +.Nd parse date and time string +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In time.h +.Ft char * +.Fn strptime "const char *buf" "const char *format" "struct tm *timeptr" +.Sh DESCRIPTION +The +.Fn strptime +function parses the string in the buffer +.Fa buf +according to the string pointed to by +.Fa format , +and fills in the elements of the structure pointed to by +.Fa timeptr . +The resulting values will be relative to the local time zone. +Thus, it can be considered the reverse operation of +.Xr strftime 3 . +.Pp +The +.Fa format +string consists of zero or more conversion specifications and +ordinary characters. +All ordinary characters are matched exactly with the buffer, where +white space in the format string will match any amount of white space +in the buffer. +All conversion specifications are identical to those described in +.Xr strftime 3 . +.Pp +Two-digit year values, including formats +.Fa %y +and +.Fa \&%D , +are now interpreted as beginning at 1969 per POSIX requirements. +Years 69-00 are interpreted in the 20th century (1969-2000), years +01-68 in the 21st century (2001-2068). +.Sh RETURN VALUES +Upon successful completion, +.Fn strptime +returns the pointer to the first character in +.Fa buf +that has not been required to satisfy the specified conversions in +.Fa format . +It returns +.Dv NULL +if one of the conversions failed. +.Sh SEE ALSO +.Xr date 1 , +.Xr scanf 3 , +.Xr strftime 3 +.Sh AUTHORS +The +.Fn strptime +function has been contributed by Powerdog Industries. +.Pp +This man page was written by +.An J\(:org Wunsch . +.Sh HISTORY +The +.Fn strptime +function appeared in +.Fx 3.0 . +.Sh BUGS +Both the +.Fa %e +and +.Fa %l +format specifiers may incorrectly scan one too many digits +if the intended values comprise only a single digit +and that digit is followed immediately by another digit. +Both specifiers accept zero-padded values, +even though they are both defined as taking unpadded values. +.Pp +The +.Fa %p +format specifier has no effect unless it is parsed +.Em after +hour-related specifiers. +Specifying +.Fa %l +without +.Fa %p +will produce undefined results. +Note that 12AM +(ante meridiem) +is taken as midnight +and 12PM +(post meridiem) +is taken as noon. +.Pp +The +.Fa %U +and +.Fa %W +format specifiers accept any value within the range 00 to 53 +without validating against other values supplied (like month +or day of the year, for example). +.Pp +The +.Fa %Z +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 +.Fa EST +which is both Eastern Standard Time and Eastern Australia Summer Time. diff --git a/stdtime/strptime.c b/stdtime/strptime.c new file mode 100644 index 0000000..7b6c7f7 --- /dev/null +++ b/stdtime/strptime.c @@ -0,0 +1,560 @@ +/* + * Powerdog Industries kindly requests feedback from anyone modifying + * this function: + * + * Date: Thu, 05 Jun 1997 23:17:17 -0400 + * From: Kevin Ruddy + * To: James FitzGibbon + * Subject: Re: Use of your strptime(3) code (fwd) + * + * The reason for the "no mod" clause was so that modifications would + * come back and we could integrate them and reissue so that a wider + * audience could use it (thereby spreading the wealth). This has + * made it possible to get strptime to work on many operating systems. + * I'm not sure why that's "plain unacceptable" to the FreeBSD team. + * + * Anyway, you can change it to "with or without modification" as + * you see fit. Enjoy. + * + * Kevin Ruddy + * Powerdog Industries, Inc. + */ +/* + * Copyright (c) 1994 Powerdog Industries. 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 Powerdog Industries. + * 4. The name of Powerdog Industries may not be used to endorse or + * promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY POWERDOG INDUSTRIES ``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 POWERDOG INDUSTRIES 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. + */ + +#ifdef LIBC_RCS +static const char rcsid[] = + "$FreeBSD: src/lib/libc/stdtime/strptime.c,v 1.17.2.2 2001/07/31 00:06:24 dd Exp $"; +#endif + +#ifndef lint +#ifndef NOID +static char copyright[] = +"@(#) Copyright (c) 1994 Powerdog Industries. All rights reserved."; +static char sccsid[] = "@(#)strptime.c 0.1 (Powerdog) 94/03/27"; +#endif /* !defined NOID */ +#endif /* not lint */ + +#include +#include +#include +#include +#include +#ifdef _THREAD_SAFE +#include +#include "pthread_private.h" +#endif +#include "timelocal.h" + +static char * _strptime(const char *, const char *, struct tm *); + +#ifdef _THREAD_SAFE +static struct pthread_mutex _gotgmt_mutexd = PTHREAD_MUTEX_STATIC_INITIALIZER; +static pthread_mutex_t gotgmt_mutex = &_gotgmt_mutexd; +#endif +static int got_GMT; + +#define asizeof(a) (sizeof (a) / sizeof ((a)[0])) + +static char * +_strptime(const char *buf, const char *fmt, struct tm *tm) +{ + char c; + const char *ptr; + int i, + len; + int Ealternative, Oalternative; + + ptr = fmt; + while (*ptr != 0) { + if (*buf == 0) + break; + + c = *ptr++; + + if (c != '%') { + if (isspace((unsigned char)c)) + while (*buf != 0 && isspace((unsigned char)*buf)) + buf++; + else if (c != *buf++) + return 0; + continue; + } + + Ealternative = 0; + Oalternative = 0; +label: + c = *ptr++; + switch (c) { + case 0: + case '%': + if (*buf++ != '%') + return 0; + break; + + case '+': + buf = _strptime(buf, Locale->date_fmt, tm); + if (buf == 0) + return 0; + break; + + case 'C': + if (!isdigit((unsigned char)*buf)) + return 0; + + /* XXX This will break for 3-digit centuries. */ + len = 2; + for (i = 0; len && *buf != 0 && isdigit((unsigned char)*buf); buf++) { + i *= 10; + i += *buf - '0'; + len--; + } + if (i < 19) + return 0; + + tm->tm_year = i * 100 - 1900; + break; + + case 'c': + /* NOTE: c_fmt is intentionally ignored */ + buf = _strptime(buf, "%a %Ef %T %Y", tm); + if (buf == 0) + return 0; + break; + + case 'D': + buf = _strptime(buf, "%m/%d/%y", tm); + if (buf == 0) + return 0; + break; + + case 'E': + if (Ealternative || Oalternative) + break; + Ealternative++; + goto label; + + case 'O': + if (Ealternative || Oalternative) + break; + Oalternative++; + goto label; + + case 'F': + case 'f': + if (!Ealternative) + break; + buf = _strptime(buf, (c == 'f') ? Locale->Ef_fmt : Locale->EF_fmt, tm); + if (buf == 0) + return 0; + break; + + case 'R': + buf = _strptime(buf, "%H:%M", tm); + if (buf == 0) + return 0; + break; + + case 'r': + buf = _strptime(buf, "%I:%M:%S %p", tm); + if (buf == 0) + return 0; + break; + + case 'T': + buf = _strptime(buf, "%H:%M:%S", tm); + if (buf == 0) + return 0; + break; + + case 'X': + buf = _strptime(buf, Locale->X_fmt, tm); + if (buf == 0) + return 0; + break; + + case 'x': + buf = _strptime(buf, Locale->x_fmt, tm); + if (buf == 0) + return 0; + break; + + case 'j': + if (!isdigit((unsigned char)*buf)) + return 0; + + len = 3; + for (i = 0; len && *buf != 0 && isdigit((unsigned char)*buf); buf++) { + i *= 10; + i += *buf - '0'; + len--; + } + if (i < 1 || i > 366) + return 0; + + tm->tm_yday = i - 1; + break; + + case 'M': + case 'S': + if (*buf == 0 || isspace((unsigned char)*buf)) + break; + + if (!isdigit((unsigned char)*buf)) + return 0; + + len = 2; + for (i = 0; len && *buf != 0 && isdigit((unsigned char)*buf); buf++) { + i *= 10; + i += *buf - '0'; + len--; + } + + if (c == 'M') { + if (i > 59) + return 0; + tm->tm_min = i; + } else { + if (i > 60) + return 0; + tm->tm_sec = i; + } + + if (*buf != 0 && isspace((unsigned char)*buf)) + while (*ptr != 0 && !isspace((unsigned char)*ptr)) + ptr++; + break; + + case 'H': + case 'I': + case 'k': + case 'l': + /* + * Of these, %l is the only specifier explicitly + * documented as not being zero-padded. However, + * there is no harm in allowing zero-padding. + * + * XXX The %l specifier may gobble one too many + * digits if used incorrectly. + */ + if (!isdigit((unsigned char)*buf)) + return 0; + + len = 2; + for (i = 0; len && *buf != 0 && isdigit((unsigned char)*buf); buf++) { + i *= 10; + i += *buf - '0'; + len--; + } + if (c == 'H' || c == 'k') { + if (i > 23) + return 0; + } else if (i > 12) + return 0; + + tm->tm_hour = i; + + if (*buf != 0 && isspace((unsigned char)*buf)) + while (*ptr != 0 && !isspace((unsigned char)*ptr)) + ptr++; + break; + + case 'p': + /* + * XXX This is bogus if parsed before hour-related + * specifiers. + */ + len = strlen(Locale->am); + if (strncasecmp(buf, Locale->am, len) == 0) { + if (tm->tm_hour > 12) + return 0; + if (tm->tm_hour == 12) + tm->tm_hour = 0; + buf += len; + break; + } + + len = strlen(Locale->pm); + if (strncasecmp(buf, Locale->pm, len) == 0) { + if (tm->tm_hour > 12) + return 0; + if (tm->tm_hour != 12) + tm->tm_hour += 12; + buf += len; + break; + } + + return 0; + + case 'A': + case 'a': + for (i = 0; i < asizeof(Locale->weekday); i++) { + if (c == 'A') { + len = strlen(Locale->weekday[i]); + if (strncasecmp(buf, + Locale->weekday[i], + len) == 0) + break; + } else { + len = strlen(Locale->wday[i]); + if (strncasecmp(buf, + Locale->wday[i], + len) == 0) + break; + } + } + if (i == asizeof(Locale->weekday)) + return 0; + + tm->tm_wday = i; + buf += len; + break; + + case 'U': + case 'W': + /* + * XXX This is bogus, as we can not assume any valid + * information present in the tm structure at this + * point to calculate a real value, so just check the + * range for now. + */ + if (!isdigit((unsigned char)*buf)) + return 0; + + len = 2; + for (i = 0; len && *buf != 0 && isdigit((unsigned char)*buf); buf++) { + i *= 10; + i += *buf - '0'; + len--; + } + if (i > 53) + return 0; + + if (*buf != 0 && isspace((unsigned char)*buf)) + while (*ptr != 0 && !isspace((unsigned char)*ptr)) + ptr++; + break; + + case 'w': + if (!isdigit((unsigned char)*buf)) + return 0; + + i = *buf - '0'; + if (i > 6) + return 0; + + tm->tm_wday = i; + + if (*buf != 0 && isspace((unsigned char)*buf)) + while (*ptr != 0 && !isspace((unsigned char)*ptr)) + ptr++; + break; + + case 'd': + case 'e': + /* + * The %e specifier is explicitly documented as not + * being zero-padded but there is no harm in allowing + * such padding. + * + * XXX The %e specifier may gobble one too many + * digits if used incorrectly. + */ + if (!isdigit((unsigned char)*buf)) + return 0; + + len = 2; + for (i = 0; len && *buf != 0 && isdigit((unsigned char)*buf); buf++) { + i *= 10; + i += *buf - '0'; + len--; + } + if (i > 31) + return 0; + + tm->tm_mday = i; + + if (*buf != 0 && isspace((unsigned char)*buf)) + while (*ptr != 0 && !isspace((unsigned char)*ptr)) + ptr++; + break; + + case 'B': + case 'b': + case 'h': + for (i = 0; i < asizeof(Locale->month); i++) { + if (Oalternative) { + if (c == 'B') { + len = strlen(Locale->alt_month[i]); + if (strncasecmp(buf, + Locale->alt_month[i], + len) == 0) + break; + } + } else { + if (c == 'B') { + len = strlen(Locale->month[i]); + if (strncasecmp(buf, + Locale->month[i], + len) == 0) + break; + } else { + len = strlen(Locale->mon[i]); + if (strncasecmp(buf, + Locale->mon[i], + len) == 0) + break; + } + } + } + if (i == asizeof(Locale->month)) + return 0; + + tm->tm_mon = i; + buf += len; + break; + + case 'm': + if (!isdigit((unsigned char)*buf)) + return 0; + + len = 2; + for (i = 0; len && *buf != 0 && isdigit((unsigned char)*buf); buf++) { + i *= 10; + i += *buf - '0'; + len--; + } + if (i < 1 || i > 12) + return 0; + + tm->tm_mon = i - 1; + + if (*buf != 0 && isspace((unsigned char)*buf)) + while (*ptr != 0 && !isspace((unsigned char)*ptr)) + ptr++; + break; + + case 's': + { + char *cp; + time_t t; + + t = strtol(buf, &cp, 10); + if (t == LONG_MAX) + return 0; + buf = cp; + gmtime_r(&t, tm); + got_GMT = 1; + } + break; + + case 'Y': + case 'y': + if (*buf == 0 || isspace((unsigned char)*buf)) + break; + + if (!isdigit((unsigned char)*buf)) + return 0; + + len = (c == 'Y') ? 4 : 2; + for (i = 0; len && *buf != 0 && isdigit((unsigned char)*buf); buf++) { + i *= 10; + i += *buf - '0'; + len--; + } + if (c == 'Y') + i -= 1900; + if (c == 'y' && i < 69) + i += 100; + if (i < 0) + return 0; + + tm->tm_year = i; + + if (*buf != 0 && isspace((unsigned char)*buf)) + while (*ptr != 0 && !isspace((unsigned char)*ptr)) + ptr++; + break; + + case 'Z': + { + const char *cp; + char *zonestr; + + for (cp = buf; *cp && isupper((unsigned char)*cp); ++cp) {/*empty*/} + if (cp - buf) { + zonestr = alloca(cp - buf + 1); + strncpy(zonestr, buf, cp - buf); + zonestr[cp - buf] = '\0'; + tzset(); + if (0 == strcmp(zonestr, "GMT")) { + got_GMT = 1; + } else if (0 == strcmp(zonestr, tzname[0])) { + tm->tm_isdst = 0; + } else if (0 == strcmp(zonestr, tzname[1])) { + tm->tm_isdst = 1; + } else { + return 0; + } + buf += cp - buf; + } + } + break; + } + } + return (char *)buf; +} + + +char * +strptime(const char *buf, const char *fmt, struct tm *tm) +{ + char *ret; + +#ifdef _THREAD_SAFE + pthread_mutex_lock(&gotgmt_mutex); +#endif + + got_GMT = 0; + ret = _strptime(buf, fmt, tm); + if (ret && got_GMT) { + time_t t = timegm(tm); + localtime_r(&t, tm); + got_GMT = 0; + } + +#ifdef _THREAD_SAFE + pthread_mutex_unlock(&gotgmt_mutex); +#endif + + return ret; +} diff --git a/stdtime/time2posix.3 b/stdtime/time2posix.3 new file mode 100644 index 0000000..cc6bd49 --- /dev/null +++ b/stdtime/time2posix.3 @@ -0,0 +1,120 @@ +.\" $FreeBSD: src/lib/libc/stdtime/time2posix.3,v 1.9.2.4 2001/12/14 18:33:59 ru Exp $ +.\" +.Dd May 1, 1996 +.Dt TIME2POSIX 3 +.Os +.Sh NAME +.Nm time2posix , +.Nm posix2time +.Nd convert seconds since the Epoch +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In time.h +.Ft time_t +.Fn time2posix "const time_t *t" +.Ft time_t +.Fn posix2time "const time_t *t" +.Sh DESCRIPTION +.St -p1003.1-88 +legislates that a time_t value of +536457599 shall correspond to "Wed Dec 31 23:59:59 GMT 1986." +This effectively implies that POSIX time_t's cannot include leap +seconds and, +therefore, +that the system time must be adjusted as each leap occurs. +.Pp +If the time package is configured with leap-second support +enabled, +however, +no such adjustment is needed and +time_t values continue to increase over leap events +(as a true `seconds since...' value). +This means that these values will differ from those required by POSIX +by the net number of leap seconds inserted since the Epoch. +.Pp +Typically this is not a problem as the type time_t is intended +to be +(mostly) +opaque\(emtime_t values should only be obtained-from and +passed-to functions such as +.Xr time 3 , +.Xr localtime 3 , +.Xr mktime 3 +and +.Xr difftime 3 . +However, +.St -p1003.1-88 +gives an arithmetic +expression for directly computing a time_t value from a given date/time, +and the same relationship is assumed by some +(usually older) +applications. +Any programs creating/dissecting time_t's +using such a relationship will typically not handle intervals +over leap seconds correctly. +.Pp +The +.Fn time2posix +and +.Fn posix2time +functions are provided to address this time_t mismatch by converting +between local time_t values and their POSIX equivalents. +This is done by accounting for the number of time-base changes that +would have taken place on a POSIX system as leap seconds were inserted +or deleted. +These converted values can then be used in lieu of correcting the older +applications, +or when communicating with POSIX-compliant systems. +.Pp +The +.Fn time2posix +function is single-valued. +That is, +every local time_t +corresponds to a single POSIX time_t. +The +.Fn posix2time +function is less well-behaved: +for a positive leap second hit the result is not unique, +and for a negative leap second hit the corresponding +POSIX time_t doesn't exist so an adjacent value is returned. +Both of these are good indicators of the inferiority of the +POSIX representation. +.Pp +The following table summarizes the relationship between time_t +and its conversion to, +and back from, +the POSIX representation over the leap second inserted at the end of June, +1993. +.Bl -column "93/06/30" "23:59:59" "A+0" "X=time2posix(T)" +.It Sy "DATE TIME T X=time2posix(T) posix2time(X)" +.It "93/06/30 23:59:59 A+0 B+0 A+0" +.It "93/06/30 23:59:60 A+1 B+1 A+1 or A+2" +.It "93/07/01 00:00:00 A+2 B+1 A+1 or A+2" +.It "93/07/01 00:00:01 A+3 B+2 A+3" +.El +.Pp +A leap second deletion would look like... +.Bl -column "??/06/30" "23:59:58" "A+0" "X=time2posix(T)" +.It Sy "DATE TIME T X=time2posix(T) posix2time(X)" +.It "??/06/30 23:59:58 A+0 B+0 A+0" +.It "??/07/01 00:00:00 A+1 B+2 A+1" +.It "??/07/01 00:00:01 A+2 B+3 A+2" +.El +.Pp +.D1 No "[Note: posix2time(B+1) => A+0 or A+1]" +.Pp +If leap-second support is not enabled, +local time_t's and +POSIX time_t's are equivalent, +and both +.Fn time2posix +and +.Fn posix2time +degenerate to the identity function. +.Sh "SEE ALSO" +.Xr difftime 3 , +.Xr localtime 3 , +.Xr mktime 3 , +.Xr time 3 diff --git a/stdtime/timelocal.c b/stdtime/timelocal.c new file mode 100644 index 0000000..514d3f1 --- /dev/null +++ b/stdtime/timelocal.c @@ -0,0 +1,244 @@ +/*- + * Copyright (c) 1997 FreeBSD Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD: src/lib/libc/stdtime/timelocal.c,v 1.8.2.2 2000/10/26 16:21:35 ache Exp $ + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "setlocale.h" +#include "timelocal.h" + +static int split_lines(char *, const char *); +static void set_from_buf(const char *, int); + +struct lc_time_T _time_localebuf; +int _time_using_locale; + +#define LCTIME_SIZE_FULL (sizeof(struct lc_time_T) / sizeof(char *)) +#define LCTIME_SIZE_1 \ + (offsetof(struct lc_time_T, alt_month[0]) / sizeof(char *)) +#define LCTIME_SIZE_2 \ + (offsetof(struct lc_time_T, Ef_fmt) / sizeof(char *)) + +const struct lc_time_T _C_time_locale = { + { + "Jan", "Feb", "Mar", "Apr", "May", "Jun", + "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" + }, { + "January", "February", "March", "April", "May", "June", + "July", "August", "September", "October", "November", "December" + }, { + "Sun", "Mon", "Tue", "Wed", + "Thu", "Fri", "Sat" + }, { + "Sunday", "Monday", "Tuesday", "Wednesday", + "Thursday", "Friday", "Saturday" + }, + + /* X_fmt */ + "%H:%M:%S", + + /* + ** x_fmt + ** Since the C language standard calls for + ** "date, using locale's date format," anything goes. + ** Using just numbers (as here) makes Quakers happier; + ** it's also compatible with SVR4. + */ + "%m/%d/%y", + + /* + ** c_fmt (ctime-compatible) + ** Not used, just compatibility placeholder. + */ + NULL, + + /* am */ + "AM", + + /* pm */ + "PM", + + /* date_fmt */ + "%a %Ef %X %Z %Y", + + { + "January", "February", "March", "April", "May", "June", + "July", "August", "September", "October", "November", "December" + }, + + /* Ef_fmt + ** To determine short months / day order + */ + "%b %e", + + /* EF_fmt + ** To determine long months / day order + */ + "%B %e" +}; + + +int +__time_load_locale(const char *name) +{ + static char * locale_buf; + static char locale_buf_C[] = "C"; + static int num_lines; + + int fd; + char * lbuf; + char * p; + const char * plim; + char filename[PATH_MAX]; + struct stat st; + size_t namesize; + size_t bufsize; + int save_using_locale; + + save_using_locale = _time_using_locale; + _time_using_locale = 0; + + if (name == NULL) + goto no_locale; + + if (!strcmp(name, "C") || !strcmp(name, "POSIX")) + return 0; + + /* + ** If the locale name is the same as our cache, use the cache. + */ + lbuf = locale_buf; + if (lbuf != NULL && strcmp(name, lbuf) == 0) { + set_from_buf(lbuf, num_lines); + _time_using_locale = 1; + return 0; + } + /* + ** Slurp the locale file into the cache. + */ + namesize = strlen(name) + 1; + + if (!_PathLocale) + goto no_locale; + /* Range checking not needed, 'name' size is limited */ + strcpy(filename, _PathLocale); + strcat(filename, "/"); + strcat(filename, name); + strcat(filename, "/LC_TIME"); + fd = open(filename, O_RDONLY); + if (fd < 0) + goto no_locale; + if (fstat(fd, &st) != 0) + goto bad_locale; + if (st.st_size <= 0) + goto bad_locale; + bufsize = namesize + st.st_size; + locale_buf = NULL; + lbuf = (lbuf == NULL || lbuf == locale_buf_C) ? + malloc(bufsize) : reallocf(lbuf, bufsize); + if (lbuf == NULL) + goto bad_locale; + (void) strcpy(lbuf, name); + p = lbuf + namesize; + plim = p + st.st_size; + if (read(fd, p, (size_t) st.st_size) != st.st_size) + goto bad_lbuf; + if (close(fd) != 0) + goto bad_lbuf; + /* + ** Parse the locale file into localebuf. + */ + if (plim[-1] != '\n') + goto bad_lbuf; + num_lines = split_lines(p, plim); + if (num_lines >= LCTIME_SIZE_FULL) + num_lines = LCTIME_SIZE_FULL; + else if (num_lines >= LCTIME_SIZE_2) + num_lines = LCTIME_SIZE_2; + else if (num_lines >= LCTIME_SIZE_1) + num_lines = LCTIME_SIZE_1; + else + goto reset_locale; + set_from_buf(lbuf, num_lines); + /* + ** Record the successful parse in the cache. + */ + locale_buf = lbuf; + + _time_using_locale = 1; + return 0; + +reset_locale: + /* + * XXX - This may not be the correct thing to do in this case. + * setlocale() assumes that we left the old locale alone. + */ + locale_buf = locale_buf_C; + _time_localebuf = _C_time_locale; + save_using_locale = 0; +bad_lbuf: + free(lbuf); +bad_locale: + (void)close(fd); +no_locale: + _time_using_locale = save_using_locale; + return -1; +} + +static int +split_lines(char *p, const char *plim) +{ + int i; + + for (i = 0; p < plim; i++) { + p = strchr(p, '\n'); + *p++ = '\0'; + } + return i; +} + +static void +set_from_buf(const char *p, int num_lines) +{ + const char **ap; + int i; + + for (ap = (const char **) &_time_localebuf, i = 0; + i < num_lines; ++ap, ++i) + *ap = p += strlen(p) + 1; + if (num_lines >= LCTIME_SIZE_2) + return; + for (i = 0; i < 12; i++) + _time_localebuf.alt_month[i] = _time_localebuf.month[i]; +} diff --git a/stdtime/timelocal.h b/stdtime/timelocal.h new file mode 100644 index 0000000..e1f9694 --- /dev/null +++ b/stdtime/timelocal.h @@ -0,0 +1,54 @@ +/*- + * Copyright (c) 1997 FreeBSD Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD: src/lib/libc/stdtime/timelocal.h,v 1.5.2.1 2000/10/26 16:21:35 ache Exp $ + */ + +/* + * Private header file for the strftime and strptime localization + * stuff. + */ +struct lc_time_T { + const char * mon[12]; + const char * month[12]; + const char * wday[7]; + const char * weekday[7]; + const char * X_fmt; + const char * x_fmt; + const char * c_fmt; /* not used, just compatibility placeholder */ + const char * am; + const char * pm; + const char * date_fmt; + const char * alt_month[12]; + const char * Ef_fmt; + const char * EF_fmt; +}; + +extern struct lc_time_T _time_localebuf; +extern int _time_using_locale; +extern const struct lc_time_T _C_time_locale; + +#define Locale (_time_using_locale ? &_time_localebuf : &_C_time_locale) + diff --git a/stdtime/tzfile.5 b/stdtime/tzfile.5 new file mode 100644 index 0000000..25ad3e6 --- /dev/null +++ b/stdtime/tzfile.5 @@ -0,0 +1,138 @@ +.\" $FreeBSD: src/lib/libc/stdtime/tzfile.5,v 1.8.2.2 2001/08/17 15:42:43 ru Exp $ +.Dd September 13, 1994 +.Dt TZFILE 5 +.Os +.Sh NAME +.Nm tzfile +.Nd timezone information +.Sh SYNOPSIS +.Fd #include \&"/usr/src/lib/libc/stdtime/tzfile.h\&" +.Sh DESCRIPTION +The time zone information files used by +.Xr tzset 3 +begin with the magic characters +.Dq Li TZif +to identify them as +time zone information files, +followed by sixteen bytes reserved for future use, +followed by four four-byte values +written in a ``standard'' byte order +(the high-order byte of the value is written first). +These values are, +in order: +.Pp +.Bl -tag -compact -width tzh_ttisstdcnt +.It Va tzh_ttisgmtcnt +The number of UTC/local indicators stored in the file. +.It Va tzh_ttisstdcnt +The number of standard/wall indicators stored in the file. +.It Va tzh_leapcnt +The number of leap seconds for which data is stored in the file. +.It Va tzh_timecnt +The number of ``transition times'' for which data is stored +in the file. +.It Va tzh_typecnt +The number of ``local time types'' for which data is stored +in the file (must not be zero). +.It Va tzh_charcnt +The number of characters of ``time zone abbreviation strings'' +stored in the file. +.El +.Pp +The above header is followed by +.Va tzh_timecnt +four-byte values of type +.Fa long , +sorted in ascending order. +These values are written in ``standard'' byte order. +Each is used as a transition time (as returned by +.Xr time 3 ) +at which the rules for computing local time change. +Next come +.Va tzh_timecnt +one-byte values of type +.Fa "unsigned char" ; +each one tells which of the different types of ``local time'' types +described in the file is associated with the same-indexed transition time. +These values serve as indices into an array of +.Fa ttinfo +structures that appears next in the file; +these structures are defined as follows: +.Pp +.Bd -literal -offset indent +struct ttinfo { + long tt_gmtoff; + int tt_isdst; + unsigned int tt_abbrind; +}; +.Ed +.Pp +Each structure is written as a four-byte value for +.Va tt_gmtoff +of type +.Fa long , +in a standard byte order, followed by a one-byte value for +.Va tt_isdst +and a one-byte value for +.Va tt_abbrind . +In each structure, +.Va tt_gmtoff +gives the number of seconds to be added to UTC, +.Li tt_isdst +tells whether +.Li tm_isdst +should be set by +.Xr localtime 3 +and +.Va tt_abbrind +serves as an index into the array of time zone abbreviation characters +that follow the +.Li ttinfo +structure(s) in the file. +.Pp +Then there are +.Va tzh_leapcnt +pairs of four-byte values, written in standard byte order; +the first value of each pair gives the time +(as returned by +.Xr time 3 ) +at which a leap second occurs; +the second gives the +.Em total +number of leap seconds to be applied after the given time. +The pairs of values are sorted in ascending order by time. +.Pp +Then there are +.Va tzh_ttisstdcnt +standard/wall indicators, each stored as a one-byte value; +they tell whether the transition times associated with local time types +were specified as standard time or wall clock time, +and are used when a time zone file is used in handling POSIX-style +time zone environment variables. +.Pp +Finally there are +.Va tzh_ttisgmtcnt +UTC/local indicators, each stored as a one-byte value; +they tell whether the transition times associated with local time types +were specified as UTC or local time, +and are used when a time zone file is used in handling POSIX-style +time zone environment variables. +.Pp +.Nm localtime +uses the first standard-time +.Li ttinfo +structure in the file +(or simply the first +.Li ttinfo +structure in the absence of a standard-time structure) +if either +.Li tzh_timecnt +is zero or the time argument is less than the first transition time recorded +in the file. +.Sh SEE ALSO +.Xr ctime 3 , +.Xr time2posix 3 , +.Xr zic 8 +.\" @(#)tzfile.5 7.2 +.\" This file is in the public domain, so clarified as of +.\" 1996-06-05 by Arthur David Olson (arthur_david_olson@nih.gov). diff --git a/stdtime/tzfile.h b/stdtime/tzfile.h new file mode 100644 index 0000000..c1b27ea --- /dev/null +++ b/stdtime/tzfile.h @@ -0,0 +1,190 @@ +#ifndef TZFILE_H + +#define TZFILE_H + +/* +** This file is in the public domain, so clarified as of +** 1996-06-05 by Arthur David Olson (arthur_david_olson@nih.gov). +*/ + +/* +** This header is for use ONLY with the time conversion code. +** There is no guarantee that it will remain unchanged, +** or that it will remain at all. +** Do NOT copy it to any system include directory. +** Thank you! +*/ + +/* +** ID +*/ + +#ifndef lint +#ifndef NOID +/* +static char tzfilehid[] = "@(#)tzfile.h 7.14"; +*/ +#endif /* !defined NOID */ +#endif /* !defined lint */ + +/* +** Information about time zone files. +*/ + +#ifndef TZDIR +#define TZDIR "/usr/share/zoneinfo" /* Time zone object file directory */ +#endif /* !defined TZDIR */ + +#ifndef TZDEFAULT +#define TZDEFAULT "/etc/localtime" +#endif /* !defined TZDEFAULT */ + +#ifndef TZDEFRULES +#define TZDEFRULES "posixrules" +#endif /* !defined TZDEFRULES */ + +/* +** Each file begins with. . . +*/ + +#define TZ_MAGIC "TZif" + +struct tzhead { + char tzh_magic[4]; /* TZ_MAGIC */ + char tzh_reserved[16]; /* reserved for future use */ + char tzh_ttisgmtcnt[4]; /* coded number of trans. time flags */ + 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 UTC 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 +** tzh_ttisgmtcnt (char)s indexed by type; if TRUE, transition +** time is UTC, if FALSE, +** transition time is local time +** if absent, transition times are +** assumed to be local time +*/ + +/* +** In the current implementation, "tzset()" refuses to deal with files that +** exceed any of the limits below. +*/ + +#ifndef TZ_MAX_TIMES +/* +** 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 +#endif /* !defined TZ_MAX_TIMES */ + +#ifndef TZ_MAX_TYPES +#ifndef NOSOLAR +#define TZ_MAX_TYPES 256 /* Limited by what (unsigned char)'s can hold */ +#endif /* !defined NOSOLAR */ +#ifdef NOSOLAR +/* +** Must be at least 14 for Europe/Riga as of Jan 12 1995, +** as noted by Earl Chew . +*/ +#define TZ_MAX_TYPES 20 /* Maximum number of local time types */ +#endif /* !defined NOSOLAR */ +#endif /* !defined TZ_MAX_TYPES */ + +#ifndef TZ_MAX_CHARS +#define TZ_MAX_CHARS 50 /* Maximum number of abbreviation characters */ + /* (limited by what unsigned chars can hold) */ +#endif /* !defined TZ_MAX_CHARS */ + +#ifndef TZ_MAX_LEAPS +#define TZ_MAX_LEAPS 50 /* Maximum number of leap second corrections */ +#endif /* !defined TZ_MAX_LEAPS */ + +#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)) + +#ifndef USG + +/* +** Use of the underscored variants may cause problems if you move your code to +** certain System-V-based systems; for maximum portability, use the +** underscore-free variants. The underscored variants are provided for +** backward compatibility only; they may disappear from future versions of +** this file. +*/ + +#define SECS_PER_MIN SECSPERMIN +#define MINS_PER_HOUR MINSPERHOUR +#define HOURS_PER_DAY HOURSPERDAY +#define DAYS_PER_WEEK DAYSPERWEEK +#define DAYS_PER_NYEAR DAYSPERNYEAR +#define DAYS_PER_LYEAR DAYSPERLYEAR +#define SECS_PER_HOUR SECSPERHOUR +#define SECS_PER_DAY SECSPERDAY +#define MONS_PER_YEAR MONSPERYEAR + +#endif /* !defined USG */ + +#endif /* !defined TZFILE_H */ diff --git a/string.subproj/Makefile b/string.subproj/Makefile deleted file mode 100644 index 85018cc..0000000 --- a/string.subproj/Makefile +++ /dev/null @@ -1,51 +0,0 @@ -# -# Generated by the NeXT Project Builder. -# -# NOTE: Do NOT change this file -- Project Builder maintains it. -# -# Put all of your customizations in files called Makefile.preamble -# and Makefile.postamble (both optional), and Makefile will include them. -# - -NAME = string - -PROJECTVERSION = 2.8 -PROJECT_TYPE = Component - -OTHERLINKED = strcmp.s - -CFILES = index.c memccpy.c memchr.c memcmp.c memset.c rindex.c\ - rindix.c strcasecmp.c strchr.c strcoll.c strcspn.c strdup.c\ - strerror.c strftime.c strmode.c strpbrk.c strsep.c strspn.c\ - strstr.c strtok.c strxfrm.c swab.c - -OTHERSRCS = Makefile.preamble Makefile Makefile.postamble - -OTHERLINKEDOFILES = strcmp.o - -MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles -CODE_GEN_STYLE = DYNAMIC -MAKEFILE = subproj.make -LIBS = -DEBUG_LIBS = $(LIBS) -PROF_LIBS = $(LIBS) - - - - -NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc -WINDOWS_OBJCPLUS_COMPILER = $(DEVDIR)/gcc -PDO_UNIX_OBJCPLUS_COMPILER = $(NEXTDEV_BIN)/gcc -NEXTSTEP_JAVA_COMPILER = /usr/bin/javac -WINDOWS_JAVA_COMPILER = $(JDKBINDIR)/javac.exe -PDO_UNIX_JAVA_COMPILER = $(JDKBINDIR)/javac - -include $(MAKEFILEDIR)/platform.make - --include Makefile.preamble - -include $(MAKEFILEDIR)/$(MAKEFILE) - --include Makefile.postamble - --include Makefile.dependencies diff --git a/string.subproj/Makefile.postamble b/string.subproj/Makefile.postamble deleted file mode 100644 index 411cde6..0000000 --- a/string.subproj/Makefile.postamble +++ /dev/null @@ -1,100 +0,0 @@ -############################################################################### -# Makefile.postamble -# Copyright 1997, Apple Computer, Inc. -# -# Use this makefile, which is imported after all other makefiles, to -# override attributes for a project's Makefile environment. This allows you -# to take advantage of the environment set up by the other Makefiles. -# You can also define custom rules at the end of this file. -# -############################################################################### -# -# These variables are exported by the standard makefiles and can be -# used in any customizations you make. They are *outputs* of -# the Makefiles and should be used, not set. -# -# PRODUCTS: products to install. All of these products will be placed in -# the directory $(DSTROOT)$(INSTALLDIR) -# GLOBAL_RESOURCE_DIR: The directory to which resources are copied. -# LOCAL_RESOURCE_DIR: The directory to which localized resources are copied. -# OFILE_DIR: Directory into which .o object files are generated. -# DERIVED_SRC_DIR: Directory used for all other derived files -# -# ALL_CFLAGS: flags to pass when compiling .c files -# ALL_MFLAGS: flags to pass when compiling .m files -# ALL_CCFLAGS: flags to pass when compiling .cc, .cxx, and .C files -# ALL_MMFLAGS: flags to pass when compiling .mm, .mxx, and .M files -# ALL_PRECOMPFLAGS: flags to pass when precompiling .h files -# ALL_LDFLAGS: flags to pass when linking object files -# ALL_LIBTOOL_FLAGS: flags to pass when libtooling object files -# ALL_PSWFLAGS: flags to pass when processing .psw and .pswm (pswrap) files -# ALL_RPCFLAGS: flags to pass when processing .rpc (rpcgen) files -# ALL_YFLAGS: flags to pass when processing .y (yacc) files -# ALL_LFLAGS: flags to pass when processing .l (lex) files -# -# NAME: name of application, bundle, subproject, palette, etc. -# LANGUAGES: langages in which the project is written (default "English") -# English_RESOURCES: localized resources (e.g. nib's, images) of project -# GLOBAL_RESOURCES: non-localized resources of project -# -# SRCROOT: base directory in which to place the new source files -# SRCPATH: relative path from SRCROOT to present subdirectory -# -# INSTALLDIR: Directory the product will be installed into by 'install' target -# PUBLIC_HDR_INSTALLDIR: where to install public headers. Don't forget -# to prefix this with DSTROOT when you use it. -# PRIVATE_HDR_INSTALLDIR: where to install private headers. Don't forget -# to prefix this with DSTROOT when you use it. -# -# EXECUTABLE_EXT: Executable extension for the platform (i.e. .exe on Windows) -# -############################################################################### - -# Some compiler flags can be overridden here for certain build situations. -# -# WARNING_CFLAGS: flag used to set warning level (defaults to -Wmost) -# DEBUG_SYMBOLS_CFLAGS: debug-symbol flag passed to all builds (defaults -# to -g) -# DEBUG_BUILD_CFLAGS: flags passed during debug builds (defaults to -DDEBUG) -# OPTIMIZE_BUILD_CFLAGS: flags passed during optimized builds (defaults -# to -O) -# PROFILE_BUILD_CFLAGS: flags passed during profile builds (defaults -# to -pg -DPROFILE) -# LOCAL_DIR_INCLUDE_DIRECTIVE: flag used to add current directory to -# the include path (defaults to -I.) -# DEBUG_BUILD_LDFLAGS, OPTIMIZE_BUILD_LDFLAGS, PROFILE_BUILD_LDFLAGS: flags -# passed to ld/libtool (defaults to nothing) - - -# Library and Framework projects only: -# INSTALL_NAME_DIRECTIVE: This directive ensures that executables linked -# against the framework will run against the correct version even if -# the current version of the framework changes. You may override this -# to "" as an alternative to using the DYLD_LIBRARY_PATH during your -# development cycle, but be sure to restore it before installing. - - -# Ownership and permissions of files installed by 'install' target - -#INSTALL_AS_USER = root - # User/group ownership -#INSTALL_AS_GROUP = wheel - # (probably want to set both of these) -#INSTALL_PERMISSIONS = - # If set, 'install' chmod's executable to this - - -# Options to strip. Note: -S strips debugging symbols (executables can be stripped -# down further with -x or, if they load no bundles, with no options at all). - -#STRIPFLAGS = -S - - -######################################################################### -# Put rules to extend the behavior of the standard Makefiles here. Include them in -# the dependency tree via cvariables like AFTER_INSTALL in the Makefile.preamble. -# -# You should avoid redefining things like "install" or "app", as they are -# owned by the top-level Makefile API and no context has been set up for where -# derived files should go. -# diff --git a/string.subproj/Makefile.preamble b/string.subproj/Makefile.preamble deleted file mode 100644 index c1624b4..0000000 --- a/string.subproj/Makefile.preamble +++ /dev/null @@ -1,137 +0,0 @@ -############################################################################### -# Makefile.preamble -# Copyright 1997, Apple Computer, Inc. -# -# Use this makefile for configuring the standard application makefiles -# associated with ProjectBuilder. It is included before the main makefile. -# In Makefile.preamble you set attributes for a project, so they are available -# to the project's makefiles. In contrast, you typically write additional rules or -# override built-in behavior in the Makefile.postamble. -# -# Each directory in a project tree (main project plus subprojects) should -# have its own Makefile.preamble and Makefile.postamble. -############################################################################### -# -# Before the main makefile is included for this project, you may set: -# -# MAKEFILEDIR: Directory in which to find $(MAKEFILE) -# MAKEFILE: Top level mechanism Makefile (e.g., app.make, bundle.make) - -# Compiler/linker flags added to the defaults: The OTHER_* variables will be -# inherited by all nested sub-projects, but the LOCAL_ versions of the same -# variables will not. Put your -I, -D, -U, and -L flags in ProjectBuilder's -# Build Attributes inspector if at all possible. To override the default flags -# that get passed to ${CC} (e.g. change -O to -O2), see Makefile.postamble. The -# variables below are *inputs* to the build process and distinct from the override -# settings done (less often) in the Makefile.postamble. -# -# OTHER_CFLAGS, LOCAL_CFLAGS: additional flags to pass to the compiler -# Note that $(OTHER_CFLAGS) and $(LOCAL_CFLAGS) are used for .h, ...c, .m, -# .cc, .cxx, .C, and .M files. There is no need to respecify the -# flags in OTHER_MFLAGS, etc. -# OTHER_MFLAGS, LOCAL_MFLAGS: additional flags for .m files -# OTHER_CCFLAGS, LOCAL_CCFLAGS: additional flags for .cc, .cxx, and ...C files -# OTHER_MMFLAGS, LOCAL_MMFLAGS: additional flags for .mm and .M files -# OTHER_PRECOMPFLAGS, LOCAL_PRECOMPFLAGS: additional flags used when -# precompiling header files -# OTHER_LDFLAGS, LOCAL_LDFLAGS: additional flags passed to ld and libtool -# OTHER_PSWFLAGS, LOCAL_PSWFLAGS: additional flags passed to pswrap -# OTHER_RPCFLAGS, LOCAL_RPCFLAGS: additional flags passed to rpcgen -# OTHER_YFLAGS, LOCAL_YFLAGS: additional flags passed to yacc -# OTHER_LFLAGS, LOCAL_LFLAGS: additional flags passed to lex - -# These variables provide hooks enabling you to add behavior at almost every -# stage of the make: -# -# BEFORE_PREBUILD: targets to build before installing headers for a subproject -# AFTER_PREBUILD: targets to build after installing headers for a subproject -# BEFORE_BUILD_RECURSION: targets to make before building subprojects -# BEFORE_BUILD: targets to make before a build, but after subprojects -# AFTER_BUILD: targets to make after a build -# -# BEFORE_INSTALL: targets to build before installing the product -# AFTER_INSTALL: targets to build after installing the product -# BEFORE_POSTINSTALL: targets to build before postinstalling every subproject -# AFTER_POSTINSTALL: targts to build after postinstalling every subproject -# -# BEFORE_INSTALLHDRS: targets to build before installing headers for a -# subproject -# AFTER_INSTALLHDRS: targets to build after installing headers for a subproject -# BEFORE_INSTALLSRC: targets to build before installing source for a subproject -# AFTER_INSTALLSRC: targets to build after installing source for a subproject -# -# BEFORE_DEPEND: targets to build before building dependencies for a -# subproject -# AFTER_DEPEND: targets to build after building dependencies for a -# subproject -# -# AUTOMATIC_DEPENDENCY_INFO: if YES, then the dependency file is -# updated every time the project is built. If NO, the dependency -# file is only built when the depend target is invoked. - -# Framework-related variables: -# FRAMEWORK_DLL_INSTALLDIR: On Windows platforms, this variable indicates -# where to put the framework's DLL. This variable defaults to -# $(INSTALLDIR)/../Executables - -# Library-related variables: -# PUBLIC_HEADER_DIR: Determines where public exported header files -# should be installed. Do not include $(DSTROOT) in this value -- -# it is prefixed automatically. For library projects you should -# set this to something like /Developer/Headers/$(NAME). Do not set -# this variable for framework projects unless you do not want the -# header files included in the framework. -# PRIVATE_HEADER_DIR: Determines where private exported header files -# should be installed. Do not include $(DSTROOT) in this value -- -# it is prefixed automatically. -# LIBRARY_STYLE: This may be either STATIC or DYNAMIC, and determines -# whether the libraries produced are statically linked when they -# are used or if they are dynamically loadable. This defaults to -# DYNAMIC. -# LIBRARY_DLL_INSTALLDIR: On Windows platforms, this variable indicates -# where to put the library's DLL. This variable defaults to -# $(INSTALLDIR)/../Executables -# -# INSTALL_AS_USER: owner of the intalled products (default root) -# INSTALL_AS_GROUP: group of the installed products (default wheel) -# INSTALL_PERMISSIONS: permissions of the installed product (default o+rX) -# -# OTHER_RECURSIVE_VARIABLES: The names of variables which you want to be -# passed on the command line to recursive invocations of make. Note that -# the values in OTHER_*FLAGS are inherited by subprojects automatically -- -# you do not have to (and shouldn't) add OTHER_*FLAGS to -# OTHER_RECURSIVE_VARIABLES. - -# Additional headers to export beyond those in the PB.project: -# OTHER_PUBLIC_HEADERS -# OTHER_PROJECT_HEADERS -# OTHER_PRIVATE_HEADERS - -# Additional files for the project's product: <> -# OTHER_RESOURCES: (non-localized) resources for this project -# OTHER_OFILES: relocatables to be linked into this project -# OTHER_LIBS: more libraries to link against -# OTHER_PRODUCT_DEPENDS: other dependencies of this project -# OTHER_SOURCEFILES: other source files maintained by .pre/postamble -# OTHER_GARBAGE: additional files to be removed by `make clean' - -# Set this to YES if you don't want a final libtool call for a library/framework. -# BUILD_OFILES_LIST_ONLY - -# To include a version string, project source must exist in a directory named -# $(NAME).%d[.%d][.%d] and the following line must be uncommented. -# OTHER_GENERATED_OFILES = $(VERS_OFILE) - -# This definition will suppress stripping of debug symbols when an executable -# is installed. By default it is YES. -# STRIP_ON_INSTALL = NO - -# Uncomment to suppress generation of a KeyValueCoding index when installing -# frameworks (This index is used by WOB and IB to determine keys available -# for an object). Set to YES by default. -# PREINDEX_FRAMEWORK = NO - -# Change this definition to install projects somewhere other than the -# standard locations. NEXT_ROOT defaults to "C:/Apple" on Windows systems -# and "" on other systems. -DSTROOT = $(HOME) diff --git a/string.subproj/PB.project b/string.subproj/PB.project deleted file mode 100644 index 78cb76d..0000000 --- a/string.subproj/PB.project +++ /dev/null @@ -1,47 +0,0 @@ -{ - DYNAMIC_CODE_GEN = YES; - FILESTABLE = { - H_FILES = (); - OTHER_LINKED = ( - index.c, - memccpy.c, - memchr.c, - memcmp.c, - memset.c, - rindex.c, - rindix.c, - strcasecmp.c, - strchr.c, - strcmp.s, - strcoll.c, - strcspn.c, - strdup.c, - strerror.c, - strftime.c, - strmode.c, - strpbrk.c, - strsep.c, - strspn.c, - strstr.c, - strtok.c, - strxfrm.c, - swab.c - ); - OTHER_SOURCES = (Makefile.preamble, Makefile, Makefile.postamble); - SUBPROJECTS = (); - }; - LANGUAGE = English; - MAKEFILEDIR = "$(MAKEFILEPATH)/pb_makefiles"; - NEXTSTEP_BUILDTOOL = /bin/gnumake; - NEXTSTEP_JAVA_COMPILER = /usr/bin/javac; - NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc; - PDO_UNIX_BUILDTOOL = $NEXT_ROOT/Developer/bin/make; - PDO_UNIX_JAVA_COMPILER = "$(JDKBINDIR)/javac"; - PDO_UNIX_OBJCPLUS_COMPILER = "$(NEXTDEV_BIN)/gcc"; - PROJECTNAME = string; - PROJECTTYPE = Component; - PROJECTVERSION = 2.8; - WINDOWS_BUILDTOOL = $NEXT_ROOT/Developer/Executables/make; - WINDOWS_JAVA_COMPILER = "$(JDKBINDIR)/javac.exe"; - WINDOWS_OBJCPLUS_COMPILER = "$(DEVDIR)/gcc"; -} diff --git a/string.subproj/index.c b/string.subproj/index.c deleted file mode 100644 index 673fa55..0000000 --- a/string.subproj/index.c +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 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 -#include -#include - -char * -#ifdef STRCHR -strchr(p, ch) -#else -index(p, ch) -#endif - register const char *p, ch; -{ - for (;; ++p) { - if (*p == ch) - return((char *)p); - if (!*p) - return((char *)NULL); - } - /* NOTREACHED */ -} diff --git a/string.subproj/memccpy.c b/string.subproj/memccpy.c deleted file mode 100644 index 657b4f9..0000000 --- a/string.subproj/memccpy.c +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 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 -#include - -void * -memccpy(t, f, c, n) - void *t; - const void *f; - int c; - register size_t n; -{ - - if (n) { - register unsigned char *tp = t; - register const unsigned char *fp = f; - register unsigned char uc = c; - do { - if ((*tp++ = *fp++) == uc) - return (tp); - } while (--n != 0); - } - return (0); -} diff --git a/string.subproj/memchr.c b/string.subproj/memchr.c deleted file mode 100644 index 000bf02..0000000 --- a/string.subproj/memchr.c +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * 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[] = "@(#)memchr.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ - -#include -#include - -void * -memchr(s, c, n) - const void *s; - register unsigned char c; - register size_t n; -{ - if (n != 0) { - register const unsigned char *p = s; - - do { - if (*p++ == c) - return ((void *)(p - 1)); - } while (--n != 0); - } - return (NULL); -} diff --git a/string.subproj/memcmp.c b/string.subproj/memcmp.c deleted file mode 100644 index a54399d..0000000 --- a/string.subproj/memcmp.c +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1988, 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 -#include - -/* - * Compare memory regions. - */ -int -memcmp(s1, s2, n) - const void *s1, *s2; - size_t n; -{ - if (n != 0) { - register const unsigned char *p1 = s1, *p2 = s2; - - do { - if (*p1++ != *p2++) - return (*--p1 - *--p2); - } while (--n != 0); - } - return (0); -} diff --git a/string.subproj/memset.c b/string.subproj/memset.c deleted file mode 100644 index 6b0b3d8..0000000 --- a/string.subproj/memset.c +++ /dev/null @@ -1,151 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Mike Hibler and Chris Torek. - * - * 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[] = "@(#)memset.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ - -#include - -#include -#include - -#define wsize sizeof(u_int) -#define wmask (wsize - 1) - -#ifdef BZERO -#define RETURN return -#define VAL 0 -#define WIDEVAL 0 - -void -bzero(dst0, length) - void *dst0; - register size_t length; -#else -#define RETURN return (dst0) -#define VAL c0 -#define WIDEVAL c - -void * -memset(dst0, c0, length) - void *dst0; - register int c0; - register size_t length; -#endif -{ - register size_t t; - register u_int c; - register u_char *dst; - - dst = dst0; - /* - * If not enough words, just fill bytes. A length >= 2 words - * guarantees that at least one of them is `complete' after - * any necessary alignment. For instance: - * - * |-----------|-----------|-----------| - * |00|01|02|03|04|05|06|07|08|09|0A|00| - * ^---------------------^ - * dst dst+length-1 - * - * but we use a minimum of 3 here since the overhead of the code - * to do word writes is substantial. - */ - if (length < 3 * wsize) { - while (length != 0) { - *dst++ = VAL; - --length; - } - RETURN; - } - -#ifndef BZERO - if ((c = (u_char)c0) != 0) { /* Fill the word. */ - c = (c << 8) | c; /* u_int is 16 bits. */ -#if UINT_MAX > 0xffff - c = (c << 16) | c; /* u_int is 32 bits. */ -#endif -#if UINT_MAX > 0xffffffff - c = (c << 32) | c; /* u_int is 64 bits. */ -#endif - } -#endif - /* Align destination by filling in bytes. */ - if ((t = (int)dst & wmask) != 0) { - t = wsize - t; - length -= t; - do { - *dst++ = VAL; - } while (--t != 0); - } - - /* Fill words. Length was >= 2*words so we know t >= 1 here. */ - t = length / wsize; - do { - *(u_int *)dst = WIDEVAL; - dst += wsize; - } while (--t != 0); - - /* Mop up trailing bytes, if any. */ - t = length & wmask; - if (t != 0) - do { - *dst++ = VAL; - } while (--t != 0); - RETURN; -} diff --git a/string.subproj/rindex.c b/string.subproj/rindex.c deleted file mode 100644 index c5eb97a..0000000 --- a/string.subproj/rindex.c +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1988, 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 -#include - -/* consider #define rindex strrchr */ - -char *strrchr(p, ch) - register const char *p; - register int ch; -{ - register char *save; - - for (save = NULL;; ++p) { - if (*p == ch) - save = (char *)p; - if (!*p) - return(save); - } - /* NOTREACHED */ -} - diff --git a/string.subproj/rindix.c b/string.subproj/rindix.c deleted file mode 100644 index ae1ae04..0000000 --- a/string.subproj/rindix.c +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* Copyright (c) 1992 NeXT Computer, Inc. All rights reserved. - * - * File: libc/string/rindex.c - */ - -#import - -#undef rindex - -char *rindex(const char *s, int c) -{ - return strrchr(s, c); -} - - - diff --git a/string.subproj/strcasecmp.c b/string.subproj/strcasecmp.c deleted file mode 100644 index ab1b078..0000000 --- a/string.subproj/strcasecmp.c +++ /dev/null @@ -1,136 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1987, 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 -#include - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)strcasecmp.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ - -typedef unsigned char u_char; - -/* - * This array is designed for mapping upper and lower case letter - * together for a case independent comparison. The mappings are - * based upon ascii character sequences. - */ -static const u_char charmap[] = { - '\000', '\001', '\002', '\003', '\004', '\005', '\006', '\007', - '\010', '\011', '\012', '\013', '\014', '\015', '\016', '\017', - '\020', '\021', '\022', '\023', '\024', '\025', '\026', '\027', - '\030', '\031', '\032', '\033', '\034', '\035', '\036', '\037', - '\040', '\041', '\042', '\043', '\044', '\045', '\046', '\047', - '\050', '\051', '\052', '\053', '\054', '\055', '\056', '\057', - '\060', '\061', '\062', '\063', '\064', '\065', '\066', '\067', - '\070', '\071', '\072', '\073', '\074', '\075', '\076', '\077', - '\100', '\141', '\142', '\143', '\144', '\145', '\146', '\147', - '\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157', - '\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167', - '\170', '\171', '\172', '\133', '\134', '\135', '\136', '\137', - '\140', '\141', '\142', '\143', '\144', '\145', '\146', '\147', - '\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157', - '\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167', - '\170', '\171', '\172', '\173', '\174', '\175', '\176', '\177', - '\200', '\201', '\202', '\203', '\204', '\205', '\206', '\207', - '\210', '\211', '\212', '\213', '\214', '\215', '\216', '\217', - '\220', '\221', '\222', '\223', '\224', '\225', '\226', '\227', - '\230', '\231', '\232', '\233', '\234', '\235', '\236', '\237', - '\240', '\241', '\242', '\243', '\244', '\245', '\246', '\247', - '\250', '\251', '\252', '\253', '\254', '\255', '\256', '\257', - '\260', '\261', '\262', '\263', '\264', '\265', '\266', '\267', - '\270', '\271', '\272', '\273', '\274', '\275', '\276', '\277', - '\300', '\301', '\302', '\303', '\304', '\305', '\306', '\307', - '\310', '\311', '\312', '\313', '\314', '\315', '\316', '\317', - '\320', '\321', '\322', '\323', '\324', '\325', '\326', '\327', - '\330', '\331', '\332', '\333', '\334', '\335', '\336', '\337', - '\340', '\341', '\342', '\343', '\344', '\345', '\346', '\347', - '\350', '\351', '\352', '\353', '\354', '\355', '\356', '\357', - '\360', '\361', '\362', '\363', '\364', '\365', '\366', '\367', - '\370', '\371', '\372', '\373', '\374', '\375', '\376', '\377', -}; - -int -strcasecmp(s1, s2) - const char *s1, *s2; -{ - register const u_char *cm = charmap, - *us1 = (const u_char *)s1, - *us2 = (const u_char *)s2; - - while (cm[*us1] == cm[*us2++]) - if (*us1++ == '\0') - return (0); - return (cm[*us1] - cm[*--us2]); -} - -int -strncasecmp(s1, s2, n) - const char *s1, *s2; - register size_t n; -{ - if (n != 0) { - register const u_char *cm = charmap, - *us1 = (const u_char *)s1, - *us2 = (const u_char *)s2; - - do { - if (cm[*us1] != cm[*us2++]) - return (cm[*us1] - cm[*--us2]); - if (*us1++ == '\0') - break; - } while (--n != 0); - } - return (0); -} diff --git a/string.subproj/strchr.c b/string.subproj/strchr.c deleted file mode 100644 index b99e5c9..0000000 --- a/string.subproj/strchr.c +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* Copyright (c) 1992 NeXT Computer, Inc. All rights reserved. - * - * File: libc/string/strchr.c - * - * This file contains machine independent code for string index - * - * HISTORY - * 24-Nov-92 Derek B Clegg (dclegg@next.com) - * Created. - */ -#import - -/* This routine needs to be optimized. */ - -char *strchr(const char *s, int c) -{ - const char ch = c; - - for ( ; *s != ch; s++) - if (*s == '\0') - return 0; - return (char *)s; -} diff --git a/string.subproj/strcmp.s b/string.subproj/strcmp.s deleted file mode 100644 index 556ec2d..0000000 --- a/string.subproj/strcmp.s +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -.text -.globl _strcmp -_strcmp: -#if defined(__i386__) - movl 0x04(%esp),%eax - movl 0x08(%esp),%edx - jmp L2 /* Jump into the loop! */ - - .align 2,0x90 -L1: incl %eax - incl %edx -L2: movb (%eax),%cl - testb %cl,%cl /* null terminator??? */ - jz L3 - cmpb %cl,(%edx) /* chars match??? */ - jne L3 - incl %eax - incl %edx - movb (%eax),%cl - testb %cl,%cl - jz L3 - cmpb %cl,(%edx) - jne L3 - incl %eax - incl %edx - movb (%eax),%cl - testb %cl,%cl - jz L3 - cmpb %cl,(%edx) - jne L3 - incl %eax - incl %edx - movb (%eax),%cl - testb %cl,%cl - jz L3 - cmpb %cl,(%edx) - jne L3 - incl %eax - incl %edx - movb (%eax),%cl - testb %cl,%cl - jz L3 - cmpb %cl,(%edx) - jne L3 - incl %eax - incl %edx - movb (%eax),%cl - testb %cl,%cl - jz L3 - cmpb %cl,(%edx) - jne L3 - incl %eax - incl %edx - movb (%eax),%cl - testb %cl,%cl - jz L3 - cmpb %cl,(%edx) - jne L3 - incl %eax - incl %edx - movb (%eax),%cl - testb %cl,%cl - jz L3 - cmpb %cl,(%edx) - je L1 - .align 2, 0x90 -L3: movzbl (%eax),%eax /* unsigned comparison */ - movzbl (%edx),%edx - subl %edx,%eax - ret -#elif defined(__ppc__) - mr r5,r3 -1: lbz r3,0(r5) - addi r5,r5,1 - cmpwi cr1,r3,0 - lbz r0,0(r4) - addi r4,r4,1 - subf. r3,r0,r3 - beqlr+ cr1 - beq- 1b - blr -#else -#error strcmp is not defined for this architecture -#endif diff --git a/string.subproj/strcoll.c b/string.subproj/strcoll.c deleted file mode 100644 index e0d1ef1..0000000 --- a/string.subproj/strcoll.c +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * 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 -#include - -/* - * Compare strings according to LC_COLLATE category of current locale. - */ -int -strcoll(s1, s2) - const char *s1, *s2; -{ - /* LC_COLLATE is unimplemented, hence always "C" */ - return (strcmp(s1, s2)); -} diff --git a/string.subproj/strcspn.c b/string.subproj/strcspn.c deleted file mode 100644 index 61f7f9b..0000000 --- a/string.subproj/strcspn.c +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * 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 -#include - -/* - * Span the complement of string s2. - */ -size_t -strcspn(s1, s2) - const char *s1; - register const char *s2; -{ - register const char *p, *spanp; - register char c, sc; - - /* - * Stop as soon as we find any character from s2. Note that there - * must be a NUL in s2; it suffices to stop when we find that, too. - */ - for (p = s1;;) { - c = *p++; - spanp = s2; - do { - if ((sc = *spanp++) == c) - return (p - 1 - s1); - } while (sc != 0); - } - /* NOTREACHED */ -} diff --git a/string.subproj/strdup.c b/string.subproj/strdup.c deleted file mode 100644 index a238f53..0000000 --- a/string.subproj/strdup.c +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1988, 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 - -#include -#include -#include - -char * -strdup(str) - const char *str; -{ - size_t len; - char *copy; - - len = strlen(str) + 1; - if (!(copy = malloc((u_int)len))) - return (NULL); - bcopy(str, copy, len); - return (copy); -} diff --git a/string.subproj/strerror.c b/string.subproj/strerror.c deleted file mode 100644 index d0b5693..0000000 --- a/string.subproj/strerror.c +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1988, 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 - -#define UPREFIX "Unknown error: " -static char ebuf[40] = UPREFIX; /* 64-bit number + slop */ - -char * -strerror(num) - int num; -{ - extern const int sys_nerr; - extern const char *const sys_errlist[]; - register unsigned int errnum; - register char *p, *t; - char tmp[40]; - - errnum = num; /* convert to unsigned */ - if (errnum < sys_nerr) - return((char*)sys_errlist[errnum]); - - /* Do this by hand, so we don't include stdio(3). */ - t = tmp; - do { - *t++ = "0123456789"[errnum % 10]; - } while (errnum /= 10); - for (p = ebuf + sizeof(UPREFIX) - 1;;) { - *p++ = *--t; - if (t <= tmp) - break; - } - return(ebuf); -} diff --git a/string.subproj/strftime.c b/string.subproj/strftime.c deleted file mode 100644 index beff35e..0000000 --- a/string.subproj/strftime.c +++ /dev/null @@ -1,310 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1989, 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 -#include -#include -#include - -static char *afmt[] = { - "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", -}; -static char *Afmt[] = { - "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", - "Saturday", -}; -static char *bfmt[] = { - "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", - "Oct", "Nov", "Dec", -}; -static char *Bfmt[] = { - "January", "February", "March", "April", "May", "June", "July", - "August", "September", "October", "November", "December", -}; - -static size_t gsize; -static char *pt; -static int _add __P((char *)); -static int _conv __P((int, int, int)); -static int _secs __P((const struct tm *)); -static size_t _fmt __P((const char *, const struct tm *)); - -size_t -strftime(s, maxsize, format, t) - char *s; - size_t maxsize; - const char *format; - const struct tm *t; -{ - - pt = s; - if ((gsize = maxsize) < 1) - return(0); - if (_fmt(format, t)) { - *pt = '\0'; - return(maxsize - gsize); - } - return(0); -} - -static size_t -_fmt(format, t) - register const char *format; - const struct tm *t; -{ - for (; *format; ++format) { - if (*format == '%') - switch(*++format) { - case '\0': - --format; - break; - case 'A': - if (t->tm_wday < 0 || t->tm_wday > 6) - return(0); - if (!_add(Afmt[t->tm_wday])) - return(0); - continue; - case 'a': - if (t->tm_wday < 0 || t->tm_wday > 6) - return(0); - if (!_add(afmt[t->tm_wday])) - return(0); - continue; - case 'B': - if (t->tm_mon < 0 || t->tm_mon > 11) - return(0); - if (!_add(Bfmt[t->tm_mon])) - return(0); - continue; - case 'b': - case 'h': - if (t->tm_mon < 0 || t->tm_mon > 11) - return(0); - if (!_add(bfmt[t->tm_mon])) - return(0); - continue; - case 'C': - if (!_fmt("%a %b %e %H:%M:%S %Y", t)) - return(0); - continue; - case 'c': - if (!_fmt("%m/%d/%y %H:%M:%S", t)) - return(0); - continue; - case 'D': - if (!_fmt("%m/%d/%y", t)) - return(0); - continue; - case 'd': - if (!_conv(t->tm_mday, 2, '0')) - return(0); - continue; - case 'e': - if (!_conv(t->tm_mday, 2, ' ')) - return(0); - continue; - case 'H': - if (!_conv(t->tm_hour, 2, '0')) - return(0); - continue; - case 'I': - if (!_conv(t->tm_hour % 12 ? - t->tm_hour % 12 : 12, 2, '0')) - return(0); - continue; - case 'j': - if (!_conv(t->tm_yday + 1, 3, '0')) - return(0); - continue; - case 'k': - if (!_conv(t->tm_hour, 2, ' ')) - return(0); - continue; - case 'l': - if (!_conv(t->tm_hour % 12 ? - t->tm_hour % 12 : 12, 2, ' ')) - return(0); - continue; - case 'M': - if (!_conv(t->tm_min, 2, '0')) - return(0); - continue; - case 'm': - if (!_conv(t->tm_mon + 1, 2, '0')) - return(0); - continue; - case 'n': - if (!_add("\n")) - return(0); - continue; - case 'p': - if (!_add(t->tm_hour >= 12 ? "PM" : "AM")) - return(0); - continue; - case 'R': - if (!_fmt("%H:%M", t)) - return(0); - continue; - case 'r': - if (!_fmt("%I:%M:%S %p", t)) - return(0); - continue; - case 'S': - if (!_conv(t->tm_sec, 2, '0')) - return(0); - continue; - case 's': - if (!_secs(t)) - return(0); - continue; - case 'T': - case 'X': - if (!_fmt("%H:%M:%S", t)) - return(0); - continue; - case 't': - if (!_add("\t")) - return(0); - continue; - case 'U': - if (!_conv((t->tm_yday + 7 - t->tm_wday) / 7, - 2, '0')) - return(0); - continue; - case 'W': - if (!_conv((t->tm_yday + 7 - - (t->tm_wday ? (t->tm_wday - 1) : 6)) - / 7, 2, '0')) - return(0); - continue; - case 'w': - if (!_conv(t->tm_wday, 1, '0')) - return(0); - continue; - case 'x': - if (!_fmt("%m/%d/%y", t)) - return(0); - continue; - case 'y': - if (!_conv((t->tm_year + TM_YEAR_BASE) - % 100, 2, '0')) - return(0); - continue; - case 'Y': - if (!_conv(t->tm_year + TM_YEAR_BASE, 4, '0')) - return(0); - continue; - case 'Z': - if (!t->tm_zone || !_add(t->tm_zone)) - return(0); - 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) does. - */ - default: - break; - } - if (!gsize--) - return(0); - *pt++ = *format; - } - return(gsize); -} - -static int -_secs(t) - const struct tm *t; -{ - static char buf[15]; - register time_t s; - register char *p; - struct tm tmp; - - /* Make a copy, mktime(3) modifies the tm struct. */ - tmp = *t; - s = mktime(&tmp); - for (p = buf + sizeof(buf) - 2; s > 0 && p > buf; s /= 10) - *p-- = s % 10 + '0'; - return(_add(++p)); -} - -static int -_conv(n, digits, pad) - int n, digits, pad; -{ - static char buf[10]; - register char *p; - - for (p = buf + sizeof(buf) - 2; n > 0 && p > buf; n /= 10, --digits) - *p-- = n % 10 + '0'; - while (p > buf && digits-- > 0) - *p-- = pad; - return(_add(++p)); -} - -static int -_add(str) - register char *str; -{ - for (;; ++pt, --gsize) { - if (!gsize) - return(0); - if (!(*pt = *str++)) - return(1); - } -} diff --git a/string.subproj/strmode.c b/string.subproj/strmode.c deleted file mode 100644 index 462b945..0000000 --- a/string.subproj/strmode.c +++ /dev/null @@ -1,170 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 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 -#include -#include - -void -strmode(mode, p) - register mode_t mode; - register char *p; -{ - /* print type */ - switch (mode & S_IFMT) { - case S_IFDIR: /* directory */ - *p++ = 'd'; - break; - case S_IFCHR: /* character special */ - *p++ = 'c'; - break; - case S_IFBLK: /* block special */ - *p++ = 'b'; - break; - case S_IFREG: /* regular */ - *p++ = '-'; - break; - case S_IFLNK: /* symbolic link */ - *p++ = 'l'; - break; - case S_IFSOCK: /* socket */ - *p++ = 's'; - break; -#ifdef S_IFIFO - case S_IFIFO: /* fifo */ - *p++ = 'p'; - break; -#endif -#ifdef S_IFWHT - case S_IFWHT: /* whiteout */ - *p++ = 'w'; - break; -#endif - default: /* unknown */ - *p++ = '?'; - break; - } - /* usr */ - if (mode & S_IRUSR) - *p++ = 'r'; - else - *p++ = '-'; - if (mode & S_IWUSR) - *p++ = 'w'; - else - *p++ = '-'; - switch (mode & (S_IXUSR | S_ISUID)) { - case 0: - *p++ = '-'; - break; - case S_IXUSR: - *p++ = 'x'; - break; - case S_ISUID: - *p++ = 'S'; - break; - case S_IXUSR | S_ISUID: - *p++ = 's'; - break; - } - /* group */ - if (mode & S_IRGRP) - *p++ = 'r'; - else - *p++ = '-'; - if (mode & S_IWGRP) - *p++ = 'w'; - else - *p++ = '-'; - switch (mode & (S_IXGRP | S_ISGID)) { - case 0: - *p++ = '-'; - break; - case S_IXGRP: - *p++ = 'x'; - break; - case S_ISGID: - *p++ = 'S'; - break; - case S_IXGRP | S_ISGID: - *p++ = 's'; - break; - } - /* other */ - if (mode & S_IROTH) - *p++ = 'r'; - else - *p++ = '-'; - if (mode & S_IWOTH) - *p++ = 'w'; - else - *p++ = '-'; - switch (mode & (S_IXOTH | S_ISVTX)) { - case 0: - *p++ = '-'; - break; - case S_IXOTH: - *p++ = 'x'; - break; - case S_ISVTX: - *p++ = 'T'; - break; - case S_IXOTH | S_ISVTX: - *p++ = 't'; - break; - } - *p++ = ' '; /* will be a '+' if ACL's implemented */ - *p = '\0'; -} diff --git a/string.subproj/strpbrk.c b/string.subproj/strpbrk.c deleted file mode 100644 index 7a68733..0000000 --- a/string.subproj/strpbrk.c +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1985, 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 -#include - -/* - * Find the first occurrence in s1 of a character in s2 (excluding NUL). - */ -char * -strpbrk(s1, s2) - register const char *s1, *s2; -{ - register const char *scanp; - register int c, sc; - - while ((c = *s1++) != 0) { - for (scanp = s2; (sc = *scanp++) != 0;) - if (sc == c) - return ((char *)(s1 - 1)); - } - return (NULL); -} diff --git a/string.subproj/strsep.c b/string.subproj/strsep.c deleted file mode 100644 index 8b43f33..0000000 --- a/string.subproj/strsep.c +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 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 -#include -#include - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)strsep.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ - -/* - * Get next token from string *stringp, where tokens are possibly-empty - * strings separated by characters from delim. - * - * Writes NULs into the string at *stringp to end tokens. - * delim need not remain constant from call to call. - * On return, *stringp points past the last NUL written (if there might - * be further tokens), or is NULL (if there are definitely no more tokens). - * - * If *stringp is NULL, strsep returns NULL. - */ -char * -strsep(stringp, delim) - register char **stringp; - register const char *delim; -{ - register char *s; - register const char *spanp; - register int c, sc; - char *tok; - - if ((s = *stringp) == NULL) - return (NULL); - for (tok = s;;) { - c = *s++; - spanp = delim; - do { - if ((sc = *spanp++) == c) { - if (c == 0) - s = NULL; - else - s[-1] = 0; - *stringp = s; - return (tok); - } - } while (sc != 0); - } - /* NOTREACHED */ -} diff --git a/string.subproj/strspn.c b/string.subproj/strspn.c deleted file mode 100644 index 5e496f2..0000000 --- a/string.subproj/strspn.c +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1989, 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 -#include - -/* - * Span the string s2 (skip characters that are in s2). - */ -size_t -strspn(s1, s2) - const char *s1; - register const char *s2; -{ - register const char *p = s1, *spanp; - register char c, sc; - - /* - * Skip any characters in s2, excluding the terminating \0. - */ -cont: - c = *p++; - for (spanp = s2; (sc = *spanp++) != 0;) - if (sc == c) - goto cont; - return (p - 1 - s1); -} diff --git a/string.subproj/strstr.c b/string.subproj/strstr.c deleted file mode 100644 index 6ec3d6d..0000000 --- a/string.subproj/strstr.c +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * 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 -#include - -/* - * Find the first occurrence of find in s. - */ -char * -strstr(s, find) - register const char *s, *find; -{ - register char c, sc; - register size_t len; - - if ((c = *find++) != 0) { - len = strlen(find); - do { - do { - if ((sc = *s++) == 0) - return (NULL); - } while (sc != c); - } while (strncmp(s, find, len) != 0); - s--; - } - return ((char *)s); -} diff --git a/string.subproj/strtok.c b/string.subproj/strtok.c deleted file mode 100644 index 16521c3..0000000 --- a/string.subproj/strtok.c +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1988, 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 -#include - -char * -strtok(s, delim) - register char *s; - register const char *delim; -{ - register char *spanp; - register int c, sc; - char *tok; - static char *last; - - - if (s == NULL && (s = last) == NULL) - return (NULL); - - /* - * Skip (span) leading delimiters (s += strspn(s, delim), sort of). - */ -cont: - c = *s++; - for (spanp = (char *)delim; (sc = *spanp++) != 0;) { - if (c == sc) - goto cont; - } - - if (c == 0) { /* no non-delimiter characters */ - last = NULL; - return (NULL); - } - tok = s - 1; - - /* - * Scan token (scan for delimiters: s += strcspn(s, delim), sort of). - * Note that delim must have one NUL; we stop if we see that, too. - */ - for (;;) { - c = *s++; - spanp = (char *)delim; - do { - if ((sc = *spanp++) == c) { - if (c == 0) - s = NULL; - else - s[-1] = 0; - last = s; - return (tok); - } - } while (sc != 0); - } - /* NOTREACHED */ -} diff --git a/string.subproj/strxfrm.c b/string.subproj/strxfrm.c deleted file mode 100644 index 0153076..0000000 --- a/string.subproj/strxfrm.c +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * 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 -#include - -/* - * Transform src, storing the result in dst, such that - * strcmp() on transformed strings returns what strcoll() - * on the original untransformed strings would return. - */ -size_t -strxfrm(dst, src, n) - register char *dst; - const char *src; - size_t n; -{ - register size_t srclen, copysize; - - /* - * Since locales are unimplemented, this is just a copy. - */ - srclen = strlen(src); - if (n != 0) { - copysize = srclen < n ? srclen : n - 1; - (void)memcpy(dst, src, copysize); - dst[copysize] = 0; - } - return (srclen); -} diff --git a/string.subproj/swab.c b/string.subproj/swab.c deleted file mode 100644 index e229855..0000000 --- a/string.subproj/swab.c +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1988, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Jeffrey Mogul. - * - * 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 - -void -swab(from, to, len) - const void *from; - void *to; - size_t len; -{ - register unsigned long temp; - register int n; - register char *fp, *tp; - - n = (len >> 1) + 1; - fp = (char *)from; - tp = (char *)to; -#define STEP temp = *fp++,*tp++ = *fp++,*tp++ = temp - /* round to multiple of 8 */ - while ((--n) & 07) - STEP; - n >>= 3; - while (--n >= 0) { - STEP; STEP; STEP; STEP; - STEP; STEP; STEP; STEP; - } -} diff --git a/string/Makefile.inc b/string/Makefile.inc new file mode 100644 index 0000000..0ac7762 --- /dev/null +++ b/string/Makefile.inc @@ -0,0 +1,47 @@ +# @(#)Makefile.inc 8.1 (Berkeley) 6/4/93 +# $FreeBSD: src/lib/libc/string/Makefile.inc,v 1.25 2001/10/10 02:17:35 ache Exp $ + +.PATH: ${.CURDIR}/${MACHINE_ARCH}/string ${.CURDIR}/string + +CFLAGS+= -I${.CURDIR}/locale + +# machine-independent string sources +MISRCS+=index.c rindex.c strcspn.c strpbrk.c strxfrm.c \ + memccpy.c rindix.c strdup.c strsep.c swab.c \ + memchr.c strcasecmp.c strerror.c strspn.c \ + memcmp.c strchr.c strftime.c strstr.c \ + memset.c strcoll.c strmode.c strtok.c \ + strlcat.c strlcpy.c + +# machine-dependent string sources +.if exists(${.CURDIR}/${MACHINE_ARCH}/string/Makefile.inc) +.include "${.CURDIR}/${MACHINE_ARCH}/string/Makefile.inc" +.endif + +.if ${LIB} == "c" +MAN3+= bcmp.3 bcopy.3 bstring.3 bzero.3 ffs.3 index.3 memccpy.3 memchr.3 \ + memcmp.3 memcpy.3 memmove.3 memset.3 rindex.3 strcasecmp.3 strcat.3 \ + strchr.3 strcmp.3 strcoll.3 strcpy.3 strcspn.3 strdup.3 strerror.3 \ + string.3 strlcpy.3 strlen.3 strmode.3 strpbrk.3 strrchr.3 strsep.3 \ + strspn.3 strstr.3 strtok.3 strxfrm.3 swab.3 wmemchr.3 + +MLINKS+=strcasecmp.3 strncasecmp.3 +MLINKS+=strcat.3 strncat.3 +MLINKS+=strcmp.3 strncmp.3 +MLINKS+=strcpy.3 strncpy.3 +MLINKS+=strerror.3 perror.3 strerror.3 sys_errlist.3 strerror.3 sys_nerr.3 +MLINKS+=strlcpy.3 strlcat.3 +MLINKS+=strtok.3 strtok_r.3 +MLINKS+=strstr.3 strcasestr.3 +MLINKS+=strstr.3 strnstr.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 \ + wmemchr.3 wcscmp.3 wmemchr.3 wcscpy.3 \ + wmemchr.3 wcscspn.3 wmemchr.3 wcslcat.3 \ + wmemchr.3 wcslcpy.3 wmemchr.3 wcslen.3 \ + wmemchr.3 wcsncat.3 wmemchr.3 wcsncmp.3 \ + wmemchr.3 wcsncpy.3 wmemchr.3 wcspbrk.3 \ + wmemchr.3 wcsrchr.3 wmemchr.3 wcsspn.3 \ + wmemchr.3 wcsstr.3 +.endif diff --git a/string/bcmp.3 b/string/bcmp.3 new file mode 100644 index 0000000..60bd887 --- /dev/null +++ b/string/bcmp.3 @@ -0,0 +1,74 @@ +.\" 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. +.\" 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. +.\" +.\" @(#)bcmp.3 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD: src/lib/libc/string/bcmp.3,v 1.8 2001/10/01 16:09:00 ru Exp $ +.\" +.Dd June 4, 1993 +.Dt BCMP 3 +.Os +.Sh NAME +.Nm bcmp +.Nd compare byte string +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In string.h +.Ft int +.Fn bcmp "const void *b1" "const void *b2" "size_t len" +.Sh DESCRIPTION +The +.Fn bcmp +function +compares byte string +.Fa b1 +against byte string +.Fa b2 , +returning zero if they are identical, non-zero otherwise. +Both strings are assumed to be +.Fa len +bytes long. +Zero-length strings are always identical. +.Pp +The strings may overlap. +.Sh SEE ALSO +.Xr memcmp 3 , +.Xr strcasecmp 3 , +.Xr strcmp 3 , +.Xr strcoll 3 , +.Xr strxfrm 3 +.Sh HISTORY +A +.Fn bcmp +function first appeared in +.Bx 4.2 . diff --git a/string/bcopy.3 b/string/bcopy.3 new file mode 100644 index 0000000..a239409 --- /dev/null +++ b/string/bcopy.3 @@ -0,0 +1,74 @@ +.\" 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. +.\" +.\" 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. +.\" +.\" @(#)bcopy.3 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD: src/lib/libc/string/bcopy.3,v 1.7 2001/10/01 16:09:00 ru Exp $ +.\" +.Dd June 4, 1993 +.Dt BCOPY 3 +.Os +.Sh NAME +.Nm bcopy +.Nd copy byte string +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In string.h +.Ft void +.Fn bcopy "const void *src" "void *dst" "size_t len" +.Sh DESCRIPTION +The +.Fn bcopy +function +copies +.Fa len +bytes from string +.Fa src +to string +.Fa dst . +The two strings may overlap. +If +.Fa len +is zero, no bytes are copied. +.Sh SEE ALSO +.Xr memccpy 3 , +.Xr memcpy 3 , +.Xr memmove 3 , +.Xr strcpy 3 , +.Xr strncpy 3 +.Sh HISTORY +A +.Fn bcopy +function appeared in +.Bx 4.2 . diff --git a/string/bstring.3 b/string/bstring.3 new file mode 100644 index 0000000..3629a3e --- /dev/null +++ b/string/bstring.3 @@ -0,0 +1,112 @@ +.\" 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. +.\" 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. +.\" +.\" @(#)bstring.3 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD: src/lib/libc/string/bstring.3,v 1.7 2001/10/01 16:09:00 ru Exp $ +.\" +.Dd June 4, 1993 +.Dt BSTRING 3 +.Os +.Sh NAME +.Nm bcmp , +.Nm bcopy , +.Nm bzero , +.Nm memccpy , +.Nm memchr , +.Nm memcmp , +.Nm memcpy , +.Nm memmove , +.Nm memset +.Nd byte string operations +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In string.h +.Ft int +.Fn bcmp "const void *b1" "const void *b2" "size_t len" +.Ft void +.Fn bcopy "const void *src" "void *dst" "size_t len" +.Ft void +.Fn bzero "void *b" "size_t len" +.Ft void * +.Fn memchr "const void *b" "int c" "size_t len" +.Ft int +.Fn memcmp "const void *b1" "const void *b2" "size_t len" +.Ft void * +.Fn memccpy "void *dst" "const void *src" "int c" "size_t len" +.Ft void * +.Fn memcpy "void *dst" "const void *src" "size_t len" +.Ft void * +.Fn memmove "void *dst" "const void *src" "size_t len" +.Ft void * +.Fn memset "void *b" "int c" "size_t len" +.Sh DESCRIPTION +These functions operate on variable length strings of bytes. +They do not check for terminating null bytes as the routines +listed in +.Xr string 3 +do. +.Pp +See the specific manual pages for more information. +.Sh SEE ALSO +.Xr bcmp 3 , +.Xr bcopy 3 , +.Xr bzero 3 , +.Xr memccpy 3 , +.Xr memchr 3 , +.Xr memcmp 3 , +.Xr memcpy 3 , +.Xr memmove 3 , +.Xr memset 3 +.Sh STANDARDS +The functions +.Fn memchr , +.Fn memcmp , +.Fn memcpy , +.Fn memmove , +and +.Fn memset +conform to +.St -isoC . +.Sh HISTORY +The functions +.Fn bzero +and +.Fn memccpy +appeared in +.Bx 4.3 ; +the functions +.Fn bcmp , +.Fn bcopy , +appeared in +.Bx 4.2 . diff --git a/string/bzero.3 b/string/bzero.3 new file mode 100644 index 0000000..faa16fe --- /dev/null +++ b/string/bzero.3 @@ -0,0 +1,71 @@ +.\" 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. +.\" +.\" 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. +.\" +.\" @(#)bzero.3 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD: src/lib/libc/string/bzero.3,v 1.7 2001/10/01 16:09:00 ru Exp $ +.\" +.Dd June 4, 1993 +.Dt BZERO 3 +.Os +.Sh NAME +.Nm bzero +.Nd write zeroes to a byte string +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In string.h +.Ft void +.Fn bzero "void *b" "size_t len" +.Sh DESCRIPTION +The +.Fn bzero +function +writes +.Fa len +zero bytes to the string +.Fa b . +If +.Fa len +is zero, +.Fn bzero +does nothing. +.Sh SEE ALSO +.Xr memset 3 , +.Xr swab 3 +.Sh HISTORY +A +.Fn bzero +function +appeared in +.Bx 4.3 . diff --git a/string/ffs.3 b/string/ffs.3 new file mode 100644 index 0000000..665d9da --- /dev/null +++ b/string/ffs.3 @@ -0,0 +1,64 @@ +.\" 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. +.\" 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. +.\" +.\" @(#)ffs.3 8.2 (Berkeley) 4/19/94 +.\" $FreeBSD: src/lib/libc/string/ffs.3,v 1.5 2001/10/01 16:09:00 ru Exp $ +.\" +.Dd April 19, 1994 +.Dt FFS 3 +.Os +.Sh NAME +.Nm ffs +.Nd find first bit set in a bit string +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In string.h +.Ft int +.Fn ffs "int value" +.Sh DESCRIPTION +The +.Fn ffs +function finds the first bit set in +.Fa value +and returns the index of that bit. +Bits are numbered starting from 1, starting at the right-most +bit. +A return value of 0 means that the argument was zero. +.Sh SEE ALSO +.Xr bitstring 3 +.Sh HISTORY +The +.Fn ffs +function appeared in +.Bx 4.3 . diff --git a/string/index.3 b/string/index.3 new file mode 100644 index 0000000..309a39c --- /dev/null +++ b/string/index.3 @@ -0,0 +1,83 @@ +.\" 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. +.\" 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. +.\" +.\" @(#)index.3 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD: src/lib/libc/string/index.3,v 1.6 2001/10/01 16:09:00 ru Exp $ +.\" +.Dd June 4, 1993 +.Dt INDEX 3 +.Os +.Sh NAME +.Nm index +.Nd locate character in string +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In string.h +.Ft char * +.Fn index "const char *s" "int c" +.Sh DESCRIPTION +The +.Fn index +function +locates the first character matching +.Fa c +(converted to a +.Em char ) +in the null-terminated string +.Fa s . +.Sh RETURN VALUES +A pointer to the character is returned if it is found; otherwise +.Dv NULL +is returned. +If +.Fa c +is '\e0', +.Fn index +locates the terminating '\e0'. +.Sh SEE ALSO +.Xr memchr 3 , +.Xr rindex 3 , +.Xr strchr 3 , +.Xr strcspn 3 , +.Xr strpbrk 3 , +.Xr strrchr 3 , +.Xr strsep 3 , +.Xr strspn 3 , +.Xr strstr 3 , +.Xr strtok 3 +.Sh HISTORY +A +.Fn index +function appeared in +.At v6 . diff --git a/string/index.c b/string/index.c new file mode 100644 index 0000000..673fa55 --- /dev/null +++ b/string/index.c @@ -0,0 +1,74 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 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 +#include +#include + +char * +#ifdef STRCHR +strchr(p, ch) +#else +index(p, ch) +#endif + register const char *p, ch; +{ + for (;; ++p) { + if (*p == ch) + return((char *)p); + if (!*p) + return((char *)NULL); + } + /* NOTREACHED */ +} diff --git a/string/memccpy.3 b/string/memccpy.3 new file mode 100644 index 0000000..44a457f --- /dev/null +++ b/string/memccpy.3 @@ -0,0 +1,76 @@ +.\" Copyright (c) 1990, 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. +.\" +.\" @(#)memccpy.3 8.1 (Berkeley) 6/9/93 +.\" $FreeBSD: src/lib/libc/string/memccpy.3,v 1.6 2001/10/01 16:09:00 ru Exp $ +.\" +.Dd June 9, 1993 +.Dt MEMCCPY 3 +.Os +.Sh NAME +.Nm memccpy +.Nd copy string until character found +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In string.h +.Ft void * +.Fn memccpy "void *dst" "const void *src" "int c" "size_t len" +.Sh DESCRIPTION +The +.Fn memccpy +function +copies bytes from string +.Fa src +to string +.Fa dst . +If the character +.Fa c +(as converted to an unsigned char) occurs in the string +.Fa src , +the copy stops and a pointer to the byte after the copy of +.Fa c +in the string +.Fa dst +is returned. +Otherwise, +.Fa len +bytes are copied, and a NULL pointer is returned. +.Sh SEE ALSO +.Xr bcopy 3 , +.Xr memcpy 3 , +.Xr memmove 3 , +.Xr strcpy 3 +.Sh HISTORY +The +.Fn memccpy +function first appeared in +.Bx 4.4 . diff --git a/string/memccpy.c b/string/memccpy.c new file mode 100644 index 0000000..657b4f9 --- /dev/null +++ b/string/memccpy.c @@ -0,0 +1,77 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 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 +#include + +void * +memccpy(t, f, c, n) + void *t; + const void *f; + int c; + register size_t n; +{ + + if (n) { + register unsigned char *tp = t; + register const unsigned char *fp = f; + register unsigned char uc = c; + do { + if ((*tp++ = *fp++) == uc) + return (tp); + } while (--n != 0); + } + return (0); +} diff --git a/string/memchr.3 b/string/memchr.3 new file mode 100644 index 0000000..b363185 --- /dev/null +++ b/string/memchr.3 @@ -0,0 +1,82 @@ +.\" 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. +.\" +.\" @(#)memchr.3 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD: src/lib/libc/string/memchr.3,v 1.7 2001/10/01 16:09:00 ru Exp $ +.\" +.Dd June 4, 1993 +.Dt MEMCHR 3 +.Os +.Sh NAME +.Nm memchr +.Nd locate byte in byte string +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In string.h +.Ft void * +.Fn memchr "const void *b" "int c" "size_t len" +.Sh DESCRIPTION +The +.Fn memchr +function +locates the first occurrence of +.Fa c +(converted to an unsigned char) +in string +.Fa b . +.Sh RETURN VALUES +The +.Fn memchr +function +returns a pointer to the byte located, +or NULL if no such byte exists within +.Fa len +bytes. +.Sh SEE ALSO +.Xr strchr 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 +.Fn memchr +function +conforms to +.St -isoC . diff --git a/string/memchr.c b/string/memchr.c new file mode 100644 index 0000000..000bf02 --- /dev/null +++ b/string/memchr.c @@ -0,0 +1,80 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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[] = "@(#)memchr.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ + +#include +#include + +void * +memchr(s, c, n) + const void *s; + register unsigned char c; + register size_t n; +{ + if (n != 0) { + register const unsigned char *p = s; + + do { + if (*p++ == c) + return ((void *)(p - 1)); + } while (--n != 0); + } + return (NULL); +} diff --git a/string/memcmp.3 b/string/memcmp.3 new file mode 100644 index 0000000..980af28 --- /dev/null +++ b/string/memcmp.3 @@ -0,0 +1,85 @@ +.\" 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. +.\" +.\" @(#)memcmp.3 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD: src/lib/libc/string/memcmp.3,v 1.8 2001/10/01 16:09:00 ru Exp $ +.\" +.Dd June 4, 1993 +.Dt MEMCMP 3 +.Os +.Sh NAME +.Nm memcmp +.Nd compare byte string +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In string.h +.Ft int +.Fn memcmp "const void *b1" "const void *b2" "size_t len" +.Sh DESCRIPTION +The +.Fn memcmp +function +compares byte string +.Fa b1 +against byte string +.Fa b2 . +Both strings are assumed to be +.Fa len +bytes long. +.Sh RETURN VALUES +The +.Fn memcmp +function +returns zero if the two strings are identical, +otherwise returns the difference between the first two differing bytes +(treated as unsigned char values, so that +.Sq Li \e200 +is greater than +.Sq Li \&\e0 , +for example). +Zero-length strings are always identical. +.Sh SEE ALSO +.Xr bcmp 3 , +.Xr strcasecmp 3 , +.Xr strcmp 3 , +.Xr strcoll 3 , +.Xr strxfrm 3 +.Sh STANDARDS +The +.Fn memcmp +function +conforms to +.St -isoC . diff --git a/string/memcmp.c b/string/memcmp.c new file mode 100644 index 0000000..a54399d --- /dev/null +++ b/string/memcmp.c @@ -0,0 +1,75 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1988, 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 +#include + +/* + * Compare memory regions. + */ +int +memcmp(s1, s2, n) + const void *s1, *s2; + size_t n; +{ + if (n != 0) { + register const unsigned char *p1 = s1, *p2 = s2; + + do { + if (*p1++ != *p2++) + return (*--p1 - *--p2); + } while (--n != 0); + } + return (0); +} diff --git a/string/memcpy.3 b/string/memcpy.3 new file mode 100644 index 0000000..311fbec --- /dev/null +++ b/string/memcpy.3 @@ -0,0 +1,86 @@ +.\" 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. +.\" +.\" @(#)memcpy.3 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD: src/lib/libc/string/memcpy.3,v 1.6 2001/10/01 16:09:00 ru Exp $ +.\" +.Dd June 4, 1993 +.Dt MEMCPY 3 +.Os +.Sh NAME +.Nm memcpy +.Nd copy byte string +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In string.h +.Ft void * +.Fn memcpy "void *dst" "const void *src" "size_t len" +.Sh DESCRIPTION +The +.Fn memcpy +function +copies +.Fa len +bytes from string +.Fa src +to string +.Fa dst . +.Sh RETURN VALUES +The +.Fn memcpy +function +returns the original value of +.Fa dst . +.Sh SEE ALSO +.Xr bcopy 3 , +.Xr memccpy 3 , +.Xr memmove 3 , +.Xr strcpy 3 +.Sh STANDARDS +The +.Fn memcpy +function +conforms to +.St -isoC . +.Sh BUGS +In this implementation +.Fn memcpy +is implemented using +.Xr bcopy 3 , +and therefore the strings may overlap. +On other systems, copying overlapping strings may produce surprises. +A simpler solution is to not use +.Fn memcpy . diff --git a/string/memmove.3 b/string/memmove.3 new file mode 100644 index 0000000..8f4f2cc --- /dev/null +++ b/string/memmove.3 @@ -0,0 +1,78 @@ +.\" 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. +.\" +.\" @(#)memmove.3 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD: src/lib/libc/string/memmove.3,v 1.6 2001/10/01 16:09:00 ru Exp $ +.\" +.Dd June 4, 1993 +.Dt MEMMOVE 3 +.Os +.Sh NAME +.Nm memmove +.Nd copy byte string +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In string.h +.Ft void * +.Fn memmove "void *dst" "const void *src" "size_t len" +.Sh DESCRIPTION +The +.Fn memmove +function +copies +.Fa len +bytes from string +.Fa src +to string +.Fa dst . +The two strings may overlap; +the copy is always done in a non-destructive manner. +.Sh RETURN VALUES +The +.Fn memmove +function returns the original value of +.Fa dst . +.Sh SEE ALSO +.Xr bcopy 3 , +.Xr memccpy 3 , +.Xr memcpy 3 , +.Xr strcpy 3 +.Sh STANDARDS +The +.Fn memmove +function +conforms to +.St -isoC . diff --git a/string/memset.3 b/string/memset.3 new file mode 100644 index 0000000..3f1ba5e --- /dev/null +++ b/string/memset.3 @@ -0,0 +1,73 @@ +.\" 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. +.\" +.\" @(#)memset.3 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD: src/lib/libc/string/memset.3,v 1.7 2001/10/01 16:09:00 ru Exp $ +.\" +.Dd June 4, 1993 +.Dt MEMSET 3 +.Os +.Sh NAME +.Nm memset +.Nd write a byte to byte string +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In string.h +.Ft void * +.Fn memset "void *b" "int c" "size_t len" +.Sh DESCRIPTION +The +.Fn memset +function +writes +.Fa len +bytes of value +.Fa c +(converted to an unsigned char) to the string +.Fa b . +.Sh RETURN VALUES +The +.Fn memset +function returns its first argument. +.Sh SEE ALSO +.Xr bzero 3 , +.Xr swab 3 +.Sh STANDARDS +The +.Fn memset +function +conforms to +.St -isoC . diff --git a/string/memset.c b/string/memset.c new file mode 100644 index 0000000..1343d88 --- /dev/null +++ b/string/memset.c @@ -0,0 +1,154 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Mike Hibler and Chris Torek. + * + * 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[] = "@(#)memset.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ + +#include + +#include +#include + +#define wsize sizeof(u_int) +#define wmask (wsize - 1) + +#ifndef __ppc__ + +#ifdef BZERO +#define RETURN return +#define VAL 0 +#define WIDEVAL 0 + +void +bzero(dst0, length) + void *dst0; + register size_t length; +#else +#define RETURN return (dst0) +#define VAL c0 +#define WIDEVAL c + +void * +memset(dst0, c0, length) + void *dst0; + register int c0; + register size_t length; +#endif +{ + register size_t t; + register u_int c; + register u_char *dst; + + dst = dst0; + /* + * If not enough words, just fill bytes. A length >= 2 words + * guarantees that at least one of them is `complete' after + * any necessary alignment. For instance: + * + * |-----------|-----------|-----------| + * |00|01|02|03|04|05|06|07|08|09|0A|00| + * ^---------------------^ + * dst dst+length-1 + * + * but we use a minimum of 3 here since the overhead of the code + * to do word writes is substantial. + */ + if (length < 3 * wsize) { + while (length != 0) { + *dst++ = VAL; + --length; + } + RETURN; + } + +#ifndef BZERO + if ((c = (u_char)c0) != 0) { /* Fill the word. */ + c = (c << 8) | c; /* u_int is 16 bits. */ +#if UINT_MAX > 0xffff + c = (c << 16) | c; /* u_int is 32 bits. */ +#endif +#if UINT_MAX > 0xffffffff + c = (c << 32) | c; /* u_int is 64 bits. */ +#endif + } +#endif + /* Align destination by filling in bytes. */ + if ((t = (int)dst & wmask) != 0) { + t = wsize - t; + length -= t; + do { + *dst++ = VAL; + } while (--t != 0); + } + + /* Fill words. Length was >= 2*words so we know t >= 1 here. */ + t = length / wsize; + do { + *(u_int *)dst = WIDEVAL; + dst += wsize; + } while (--t != 0); + + /* Mop up trailing bytes, if any. */ + t = length & wmask; + if (t != 0) + do { + *dst++ = VAL; + } while (--t != 0); + RETURN; +} +#endif /* __ppc__ */ diff --git a/string/rindex.3 b/string/rindex.3 new file mode 100644 index 0000000..d7e5d89 --- /dev/null +++ b/string/rindex.3 @@ -0,0 +1,85 @@ +.\" 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. +.\" 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. +.\" +.\" @(#)rindex.3 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD: src/lib/libc/string/rindex.3,v 1.6 2001/10/01 16:09:00 ru Exp $ +.\" +.Dd June 4, 1993 +.Dt RINDEX 3 +.Os +.Sh NAME +.Nm rindex +.Nd locate character in string +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In string.h +.Ft char * +.Fn rindex "const char *s" "int c" +.Sh DESCRIPTION +The +.Fn rindex +function +locates the last character +matching +.Fa c +(converted to a +.Em char ) +in the null-terminated string +.Fa s . +.Sh RETURN VALUES +A pointer to the character is returned if it is found; otherwise +NULL is returned. +If +.Fa c +is +.Ql \e0 , +.Fn rindex +locates the terminating +.Ql \e0 . +.Sh SEE ALSO +.Xr index 3 , +.Xr memchr 3 , +.Xr strchr 3 , +.Xr strcspn 3 , +.Xr strpbrk 3 , +.Xr strrchr 3 , +.Xr strsep 3 , +.Xr strspn 3 , +.Xr strstr 3 , +.Xr strtok 3 +.Sh HISTORY +A +.Fn rindex +function appeared in +.At v6 . diff --git a/string/rindex.c b/string/rindex.c new file mode 100644 index 0000000..c5eb97a --- /dev/null +++ b/string/rindex.c @@ -0,0 +1,74 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1988, 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 +#include + +/* consider #define rindex strrchr */ + +char *strrchr(p, ch) + register const char *p; + register int ch; +{ + register char *save; + + for (save = NULL;; ++p) { + if (*p == ch) + save = (char *)p; + if (!*p) + return(save); + } + /* NOTREACHED */ +} + diff --git a/string/rindix.c b/string/rindix.c new file mode 100644 index 0000000..ae1ae04 --- /dev/null +++ b/string/rindix.c @@ -0,0 +1,37 @@ +/* + * Copyright (c) 1999 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@ + */ +/* Copyright (c) 1992 NeXT Computer, Inc. All rights reserved. + * + * File: libc/string/rindex.c + */ + +#import + +#undef rindex + +char *rindex(const char *s, int c) +{ + return strrchr(s, c); +} + + + diff --git a/string/strcasecmp.3 b/string/strcasecmp.3 new file mode 100644 index 0000000..f50cd5c --- /dev/null +++ b/string/strcasecmp.3 @@ -0,0 +1,97 @@ +.\" 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. +.\" 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. +.\" +.\" @(#)strcasecmp.3 8.1 (Berkeley) 6/9/93 +.\" $FreeBSD: src/lib/libc/string/strcasecmp.3,v 1.9 2001/10/01 16:09:00 ru Exp $ +.\" +.Dd June 9, 1993 +.Dt STRCASECMP 3 +.Os +.Sh NAME +.Nm strcasecmp , +.Nm strncasecmp +.Nd compare strings, ignoring case +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In string.h +.Ft int +.Fn strcasecmp "const char *s1" "const char *s2" +.Ft int +.Fn strncasecmp "const char *s1" "const char *s2" "size_t len" +.Sh DESCRIPTION +The +.Fn strcasecmp +and +.Fn strncasecmp +functions +compare the null-terminated strings +.Fa s1 +and +.Fa s2 . +.Pp +The +.Fn strncasecmp +compares at most +.Fa len +characters. +.Sh RETURN VALUES +The +.Fn strcasecmp +and +.Fn strncasecmp +return an integer greater than, equal to, or less than 0, +according as +.Fa s1 +is lexicographically greater than, equal to, or less than +.Fa s2 +after translation of each corresponding character to lower-case. +The strings themselves are not modified. +The comparison is done using unsigned characters, so that +.Sq Li \e200 +is greater than +.Ql \e0 . +.Sh SEE ALSO +.Xr bcmp 3 , +.Xr memcmp 3 , +.Xr strcmp 3 , +.Xr strcoll 3 , +.Xr strxfrm 3 , +.Xr tolower 3 +.Sh HISTORY +The +.Fn strcasecmp +and +.Fn strncasecmp +functions first appeared in +.Bx 4.4 . diff --git a/string/strcasecmp.c b/string/strcasecmp.c new file mode 100644 index 0000000..ab1b078 --- /dev/null +++ b/string/strcasecmp.c @@ -0,0 +1,136 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1987, 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 +#include + +#if defined(LIBC_SCCS) && !defined(lint) +static char sccsid[] = "@(#)strcasecmp.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ + +typedef unsigned char u_char; + +/* + * This array is designed for mapping upper and lower case letter + * together for a case independent comparison. The mappings are + * based upon ascii character sequences. + */ +static const u_char charmap[] = { + '\000', '\001', '\002', '\003', '\004', '\005', '\006', '\007', + '\010', '\011', '\012', '\013', '\014', '\015', '\016', '\017', + '\020', '\021', '\022', '\023', '\024', '\025', '\026', '\027', + '\030', '\031', '\032', '\033', '\034', '\035', '\036', '\037', + '\040', '\041', '\042', '\043', '\044', '\045', '\046', '\047', + '\050', '\051', '\052', '\053', '\054', '\055', '\056', '\057', + '\060', '\061', '\062', '\063', '\064', '\065', '\066', '\067', + '\070', '\071', '\072', '\073', '\074', '\075', '\076', '\077', + '\100', '\141', '\142', '\143', '\144', '\145', '\146', '\147', + '\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157', + '\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167', + '\170', '\171', '\172', '\133', '\134', '\135', '\136', '\137', + '\140', '\141', '\142', '\143', '\144', '\145', '\146', '\147', + '\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157', + '\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167', + '\170', '\171', '\172', '\173', '\174', '\175', '\176', '\177', + '\200', '\201', '\202', '\203', '\204', '\205', '\206', '\207', + '\210', '\211', '\212', '\213', '\214', '\215', '\216', '\217', + '\220', '\221', '\222', '\223', '\224', '\225', '\226', '\227', + '\230', '\231', '\232', '\233', '\234', '\235', '\236', '\237', + '\240', '\241', '\242', '\243', '\244', '\245', '\246', '\247', + '\250', '\251', '\252', '\253', '\254', '\255', '\256', '\257', + '\260', '\261', '\262', '\263', '\264', '\265', '\266', '\267', + '\270', '\271', '\272', '\273', '\274', '\275', '\276', '\277', + '\300', '\301', '\302', '\303', '\304', '\305', '\306', '\307', + '\310', '\311', '\312', '\313', '\314', '\315', '\316', '\317', + '\320', '\321', '\322', '\323', '\324', '\325', '\326', '\327', + '\330', '\331', '\332', '\333', '\334', '\335', '\336', '\337', + '\340', '\341', '\342', '\343', '\344', '\345', '\346', '\347', + '\350', '\351', '\352', '\353', '\354', '\355', '\356', '\357', + '\360', '\361', '\362', '\363', '\364', '\365', '\366', '\367', + '\370', '\371', '\372', '\373', '\374', '\375', '\376', '\377', +}; + +int +strcasecmp(s1, s2) + const char *s1, *s2; +{ + register const u_char *cm = charmap, + *us1 = (const u_char *)s1, + *us2 = (const u_char *)s2; + + while (cm[*us1] == cm[*us2++]) + if (*us1++ == '\0') + return (0); + return (cm[*us1] - cm[*--us2]); +} + +int +strncasecmp(s1, s2, n) + const char *s1, *s2; + register size_t n; +{ + if (n != 0) { + register const u_char *cm = charmap, + *us1 = (const u_char *)s1, + *us2 = (const u_char *)s2; + + do { + if (cm[*us1] != cm[*us2++]) + return (cm[*us1] - cm[*--us2]); + if (*us1++ == '\0') + break; + } while (--n != 0); + } + return (0); +} diff --git a/string/strcat.3 b/string/strcat.3 new file mode 100644 index 0000000..e6e9b51 --- /dev/null +++ b/string/strcat.3 @@ -0,0 +1,101 @@ +.\" 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. +.\" +.\" @(#)strcat.3 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD: src/lib/libc/string/strcat.3,v 1.9 2001/10/01 16:09:00 ru Exp $ +.\" +.Dd June 4, 1993 +.Dt STRCAT 3 +.Os +.Sh NAME +.Nm strcat +.Nd concatenate strings +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In string.h +.Ft char * +.Fn strcat "char *s" "const char *append" +.Ft char * +.Fn strncat "char *s" "const char *append" "size_t count" +.Sh DESCRIPTION +The +.Fn strcat +and +.Fn strncat +functions +append a copy of the null-terminated string +.Fa append +to the end of the null-terminated string +.Fa s , +then add a terminating +.Ql \e0 . +The string +.Fa s +must have sufficient space to hold the result. +.Pp +The +.Fn strncat +function +appends not more than +.Fa count +characters from +.Fa append , +and then adds a terminating +.Ql \e0 . +.Sh RETURN VALUES +The +.Fn strcat +and +.Fn strncat +functions +return the pointer +.Fa s . +.Sh SEE ALSO +.Xr bcopy 3 , +.Xr memccpy 3 , +.Xr memcpy 3 , +.Xr memmove 3 , +.Xr strcpy 3 , +.Xr strlcat 3 , +.Xr strlcpy 3 +.Sh STANDARDS +The +.Fn strcat +and +.Fn strncat +functions +conform to +.St -isoC . diff --git a/string/strchr.3 b/string/strchr.3 new file mode 100644 index 0000000..97be859 --- /dev/null +++ b/string/strchr.3 @@ -0,0 +1,88 @@ +.\" 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. +.\" +.\" @(#)strchr.3 8.2 (Berkeley) 4/19/94 +.\" $FreeBSD: src/lib/libc/string/strchr.3,v 1.8 2001/10/01 16:09:00 ru Exp $ +.\" +.Dd April 19, 1994 +.Dt STRCHR 3 +.Os +.Sh NAME +.Nm strchr +.Nd locate character in string +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In string.h +.Ft char * +.Fn strchr "const char *s" "int c" +.Sh DESCRIPTION +The +.Fn strchr +function locates the first occurrence of +.Ar c +in the string pointed to by +.Ar s . +The terminating +.Dv NUL +character is considered part of the string. +If +.Fa c +is +.Ql \e0 , +.Fn strchr +locates the terminating +.Ql \e0 . +.Sh RETURN VALUES +The function +.Fn strchr +returns 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 +.Fn strchr +function +conforms to +.St -isoC . diff --git a/string/strchr.c b/string/strchr.c new file mode 100644 index 0000000..b99e5c9 --- /dev/null +++ b/string/strchr.c @@ -0,0 +1,44 @@ +/* + * Copyright (c) 1999 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@ + */ +/* Copyright (c) 1992 NeXT Computer, Inc. All rights reserved. + * + * File: libc/string/strchr.c + * + * This file contains machine independent code for string index + * + * HISTORY + * 24-Nov-92 Derek B Clegg (dclegg@next.com) + * Created. + */ +#import + +/* This routine needs to be optimized. */ + +char *strchr(const char *s, int c) +{ + const char ch = c; + + for ( ; *s != ch; s++) + if (*s == '\0') + return 0; + return (char *)s; +} diff --git a/string/strcmp.3 b/string/strcmp.3 new file mode 100644 index 0000000..101d71b --- /dev/null +++ b/string/strcmp.3 @@ -0,0 +1,104 @@ +.\" 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. +.\" +.\" @(#)strcmp.3 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD: src/lib/libc/string/strcmp.3,v 1.10 2001/10/11 17:02:44 mike Exp $ +.\" +.Dd October 11, 2001 +.Dt STRCMP 3 +.Os +.Sh NAME +.Nm strcmp , +.Nm strncmp +.Nd compare strings +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In string.h +.Ft int +.Fn strcmp "const char *s1" "const char *s2" +.Ft int +.Fn strncmp "const char *s1" "const char *s2" "size_t len" +.Sh DESCRIPTION +The +.Fn strcmp +and +.Fn strncmp +functions +lexicographically compare the null-terminated strings +.Fa s1 +and +.Fa s2 . +.Pp +The +.Fn strncmp +function +compares not more than +.Fa len +characters. +Because +.Fn strncmp +is designed for comparing strings rather than binary data, +characters that appear after a +.Ql \e0 +character are not compared. +.Sh RETURN VALUES +The +.Fn strcmp +and +.Fn strncmp +return an integer greater than, equal to, or less than 0, according +as the string +.Fa s1 +is greater than, equal to, or less than the string +.Fa s2 . +The comparison is done using unsigned characters, so that +.Ql \e200 +is greater than +.Ql \e0 . +.Sh SEE ALSO +.Xr bcmp 3 , +.Xr memcmp 3 , +.Xr strcasecmp 3 , +.Xr strcoll 3 , +.Xr strxfrm 3 +.Sh STANDARDS +The +.Fn strcmp +and +.Fn strncmp +functions +conform to +.St -isoC . diff --git a/string/strcmp.s b/string/strcmp.s new file mode 100644 index 0000000..556ec2d --- /dev/null +++ b/string/strcmp.s @@ -0,0 +1,105 @@ +/* + * Copyright (c) 1999 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@ + */ +.text +.globl _strcmp +_strcmp: +#if defined(__i386__) + movl 0x04(%esp),%eax + movl 0x08(%esp),%edx + jmp L2 /* Jump into the loop! */ + + .align 2,0x90 +L1: incl %eax + incl %edx +L2: movb (%eax),%cl + testb %cl,%cl /* null terminator??? */ + jz L3 + cmpb %cl,(%edx) /* chars match??? */ + jne L3 + incl %eax + incl %edx + movb (%eax),%cl + testb %cl,%cl + jz L3 + cmpb %cl,(%edx) + jne L3 + incl %eax + incl %edx + movb (%eax),%cl + testb %cl,%cl + jz L3 + cmpb %cl,(%edx) + jne L3 + incl %eax + incl %edx + movb (%eax),%cl + testb %cl,%cl + jz L3 + cmpb %cl,(%edx) + jne L3 + incl %eax + incl %edx + movb (%eax),%cl + testb %cl,%cl + jz L3 + cmpb %cl,(%edx) + jne L3 + incl %eax + incl %edx + movb (%eax),%cl + testb %cl,%cl + jz L3 + cmpb %cl,(%edx) + jne L3 + incl %eax + incl %edx + movb (%eax),%cl + testb %cl,%cl + jz L3 + cmpb %cl,(%edx) + jne L3 + incl %eax + incl %edx + movb (%eax),%cl + testb %cl,%cl + jz L3 + cmpb %cl,(%edx) + je L1 + .align 2, 0x90 +L3: movzbl (%eax),%eax /* unsigned comparison */ + movzbl (%edx),%edx + subl %edx,%eax + ret +#elif defined(__ppc__) + mr r5,r3 +1: lbz r3,0(r5) + addi r5,r5,1 + cmpwi cr1,r3,0 + lbz r0,0(r4) + addi r4,r4,1 + subf. r3,r0,r3 + beqlr+ cr1 + beq- 1b + blr +#else +#error strcmp is not defined for this architecture +#endif diff --git a/string/strcoll.3 b/string/strcoll.3 new file mode 100644 index 0000000..7617184 --- /dev/null +++ b/string/strcoll.3 @@ -0,0 +1,75 @@ +.\" 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. +.\" +.\" @(#)strcoll.3 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD: src/lib/libc/string/strcoll.3,v 1.11 2001/10/01 16:09:00 ru Exp $ +.\" +.Dd June 4, 1993 +.Dt STRCOLL 3 +.Os +.Sh NAME +.Nm strcoll +.Nd compare strings according to current collation +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In string.h +.Ft int +.Fn strcoll "const char *s1" "const char *s2" +.Sh DESCRIPTION +The +.Fn strcoll +function +lexicographically compares the null-terminated strings +.Fa s1 +and +.Fa s2 +according to the current locale collation if any, otherwise call +.Fa strcmp , +and returns an integer greater than, equal to, or less than 0, +according as +.Fa s1 +is greater than, equal to, or less than +.Fa s2 . +.Sh SEE ALSO +.Xr setlocale 3 , +.Xr strcmp 3 , +.Xr strxfrm 3 +.Sh STANDARDS +The +.Fn strcoll +function +conforms to +.St -isoC . diff --git a/string/strcoll.c b/string/strcoll.c new file mode 100644 index 0000000..e0d1ef1 --- /dev/null +++ b/string/strcoll.c @@ -0,0 +1,71 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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 +#include + +/* + * Compare strings according to LC_COLLATE category of current locale. + */ +int +strcoll(s1, s2) + const char *s1, *s2; +{ + /* LC_COLLATE is unimplemented, hence always "C" */ + return (strcmp(s1, s2)); +} diff --git a/string/strcpy.3 b/string/strcpy.3 new file mode 100644 index 0000000..2a06447 --- /dev/null +++ b/string/strcpy.3 @@ -0,0 +1,165 @@ +.\" 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. +.\" +.\" @(#)strcpy.3 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD: src/lib/libc/string/strcpy.3,v 1.11 2001/10/01 16:09:00 ru Exp $ +.\" +.Dd August 9, 2001 +.Dt STRCPY 3 +.Os +.Sh NAME +.Nm strcpy , strncpy +.Nd copy strings +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In string.h +.Ft char * +.Fn strcpy "char *dst" "const char *src" +.Ft char * +.Fn strncpy "char *dst" "const char *src" "size_t len" +.Sh DESCRIPTION +The +.Fn strcpy +function +copies the string +.Fa src +to +.Fa dst +(including the terminating +.Ql \e0 +character). +.Pp +The +.Fn strncpy +function copies not more than +.Fa len +characters from +.Fa src +into +.Fa dst , +appending +.Ql \e0 +characters if +.Fa src +is less than +.Fa len +characters long, and +.Em not +terminating +.Fa dst +otherwise. +.Sh RETURN VALUES +The +.Fn strcpy +and +.Fn strncpy +functions +return +.Fa dst . +.Sh EXAMPLES +The following sets +.Va chararray +to +.Dq Li abc\e0\e0\e0 : +.Bd -literal -offset indent +char chararray[6]; + +(void)strncpy(chararray, "abc", sizeof(chararray)); +.Ed +.Pp +The following sets +.Va chararray +to +.Dq Li abcdef : +.Bd -literal -offset indent +char chararray[6]; + +(void)strncpy(chararray, "abcdefgh", sizeof(chararray)); +.Ed +.Pp +Note that it does +.Em not +.Tn NUL +terminate +.Va chararray +because the length of the source string is greater than or equal +to the length parameter. +.Pp +The following copies as many characters from +.Va input +to +.Va buf +as will fit and +.Tn NUL +terminates the result. +Because +.Fn strncpy +does +.Em not +guarantee to +.Tn NUL +terminate the string itself, this must be done explicitly. +.Bd -literal -offset indent +char buf[1024]; + +(void)strncpy(buf, input, sizeof(buf) - 1); +buf[sizeof(buf) - 1] = '\e0'; +.Ed +.Pp +This could be better achieved using +.Xr strlcpy 3 , +as shown in the following example: +.Pp +.Dl "(void)strlcpy(buf, input, sizeof(buf));" +.Pp +Note that because +.Xr strlcpy 3 +is not defined in any standards, it should +only be used when portability is not a concern. +.Sh SEE ALSO +.Xr bcopy 3 , +.Xr memccpy 3 , +.Xr memcpy 3 , +.Xr memmove 3 , +.Xr strlcpy 3 +.Sh STANDARDS +The +.Fn strcpy +and +.Fn strncpy +functions +conform to +.St -isoC . diff --git a/string/strcspn.3 b/string/strcspn.3 new file mode 100644 index 0000000..c105c12 --- /dev/null +++ b/string/strcspn.3 @@ -0,0 +1,85 @@ +.\" 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. +.\" +.\" @(#)strcspn.3 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD: src/lib/libc/string/strcspn.3,v 1.7 2001/10/01 16:09:00 ru Exp $ +.\" +.Dd June 4, 1993 +.Dt STRCSPN 3 +.Os +.Sh NAME +.Nm strcspn +.Nd span the complement of a string +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In string.h +.Ft size_t +.Fn strcspn "const char *s" "const char *charset" +.Sh DESCRIPTION +The +.Fn strcspn +function +spans the initial part of the null-terminated string +.Fa s +as long as the characters from +.Fa s +do not occur in string +.Fa charset +(it +spans the +.Em complement +of +.Fa charset ) . +.Sh RETURN VALUES +The +.Fn strcspn +function +returns the number of characters spanned. +.Sh SEE ALSO +.Xr memchr 3 , +.Xr strchr 3 , +.Xr strpbrk 3 , +.Xr strrchr 3 , +.Xr strsep 3 , +.Xr strspn 3 , +.Xr strstr 3 , +.Xr strtok 3 +.Sh STANDARDS +The +.Fn strcspn +function +conforms to +.St -isoC . diff --git a/string/strcspn.c b/string/strcspn.c new file mode 100644 index 0000000..61f7f9b --- /dev/null +++ b/string/strcspn.c @@ -0,0 +1,86 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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 +#include + +/* + * Span the complement of string s2. + */ +size_t +strcspn(s1, s2) + const char *s1; + register const char *s2; +{ + register const char *p, *spanp; + register char c, sc; + + /* + * Stop as soon as we find any character from s2. Note that there + * must be a NUL in s2; it suffices to stop when we find that, too. + */ + for (p = s1;;) { + c = *p++; + spanp = s2; + do { + if ((sc = *spanp++) == c) + return (p - 1 - s1); + } while (sc != 0); + } + /* NOTREACHED */ +} diff --git a/string/strdup.3 b/string/strdup.3 new file mode 100644 index 0000000..3bb2516 --- /dev/null +++ b/string/strdup.3 @@ -0,0 +1,70 @@ +.\" Copyright (c) 1990, 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. +.\" +.\" @(#)strdup.3 8.1 (Berkeley) 6/9/93 +.\" $FreeBSD: src/lib/libc/string/strdup.3,v 1.10 2001/10/01 16:09:00 ru Exp $ +.\" +.Dd June 9, 1993 +.Dt STRDUP 3 +.Os +.Sh NAME +.Nm strdup +.Nd save a copy of a string +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In string.h +.Ft char * +.Fn strdup "const char *str" +.Sh DESCRIPTION +The +.Fn strdup +function +allocates sufficient memory for a copy +of the string +.Fa str , +does the copy, and returns a pointer to it. +The pointer may subsequently be used as an +argument to the function +.Xr free 3 . +.Pp +If insufficient memory is available, NULL is returned and +.Va errno +is set to +.Er ENOMEM . +.Sh SEE ALSO +.Xr free 3 , +.Xr malloc 3 +.Sh HISTORY +The +.Fn strdup +function first appeared in +.Bx 4.4 . diff --git a/string/strdup.c b/string/strdup.c new file mode 100644 index 0000000..a238f53 --- /dev/null +++ b/string/strdup.c @@ -0,0 +1,74 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1988, 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 + +#include +#include +#include + +char * +strdup(str) + const char *str; +{ + size_t len; + char *copy; + + len = strlen(str) + 1; + if (!(copy = malloc((u_int)len))) + return (NULL); + bcopy(str, copy, len); + return (copy); +} diff --git a/string/strerror.3 b/string/strerror.3 new file mode 100644 index 0000000..c82aebf --- /dev/null +++ b/string/strerror.3 @@ -0,0 +1,130 @@ +.\" Copyright (c) 1980, 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. +.\" +.\" @(#)strerror.3 8.1 (Berkeley) 6/9/93 +.\" $FreeBSD: src/lib/libc/string/strerror.3,v 1.12 2001/10/01 16:09:00 ru Exp $ +.\" +.Dd June 9, 1993 +.Dt STRERROR 3 +.Os +.Sh NAME +.Nm perror , +.Nm strerror , +.Nm sys_errlist , +.Nm sys_nerr +.Nd system error messages +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In stdio.h +.Ft void +.Fn perror "const char *string" +.Vt extern const char * const sys_errlist[] ; +.Vt extern const int sys_nerr ; +.In string.h +.Ft char * +.Fn strerror "int errnum" +.Sh DESCRIPTION +The +.Fn strerror +and +.Fn perror +functions look up the error message string corresponding to an +error number. +.Pp +The +.Fn strerror +function accepts an error number argument +.Fa errnum +and +returns a pointer to the corresponding +message string. +.Pp +The +.Fn perror +function finds the error message corresponding to the current +value of the global variable +.Va errno +.Pq Xr intro 2 +and writes it, followed by a newline, to the +standard error file descriptor. +If the argument +.Fa string +is +.Pf non- Dv NULL +and does not point to the null character, +this string is prepended to the message +string and separated from it by +a colon and space +.Pq Ql \&:\ \& ; +otherwise, only the error message string is printed. +.Pp +If +.Fa errnum +is not a recognized error number, +the error message string will contain +.Dq Li "Unknown error:\ " +followed by the error number in decimal. +.Pp +The message strings can be accessed directly using the external +array +.Va sys_errlist . +The external value +.Va sys_nerr +contains a count of the messages in +.Va sys_errlist . +The use of these variables is deprecated; +.Fn strerror +should be used instead. +.Sh SEE ALSO +.Xr intro 2 , +.Xr psignal 3 +.Sh HISTORY +The +.Fn strerror +and +.Fn perror +functions first appeared in +.Bx 4.4 . +.Sh BUGS +For unknown error numbers, the +.Fn strerror +function will return its result in a static buffer which +may be overwritten by subsequent calls. +.Pp +Programs that use the deprecated +.Va sys_errlist +variable often fail to compile because they declare it +inconsistently. diff --git a/string/strerror.c b/string/strerror.c new file mode 100644 index 0000000..d0b5693 --- /dev/null +++ b/string/strerror.c @@ -0,0 +1,86 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1988, 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 + +#define UPREFIX "Unknown error: " +static char ebuf[40] = UPREFIX; /* 64-bit number + slop */ + +char * +strerror(num) + int num; +{ + extern const int sys_nerr; + extern const char *const sys_errlist[]; + register unsigned int errnum; + register char *p, *t; + char tmp[40]; + + errnum = num; /* convert to unsigned */ + if (errnum < sys_nerr) + return((char*)sys_errlist[errnum]); + + /* Do this by hand, so we don't include stdio(3). */ + t = tmp; + do { + *t++ = "0123456789"[errnum % 10]; + } while (errnum /= 10); + for (p = ebuf + sizeof(UPREFIX) - 1;;) { + *p++ = *--t; + if (t <= tmp) + break; + } + return(ebuf); +} diff --git a/string/strftime.c b/string/strftime.c new file mode 100644 index 0000000..beff35e --- /dev/null +++ b/string/strftime.c @@ -0,0 +1,310 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1989, 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 +#include +#include +#include + +static char *afmt[] = { + "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", +}; +static char *Afmt[] = { + "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", + "Saturday", +}; +static char *bfmt[] = { + "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", + "Oct", "Nov", "Dec", +}; +static char *Bfmt[] = { + "January", "February", "March", "April", "May", "June", "July", + "August", "September", "October", "November", "December", +}; + +static size_t gsize; +static char *pt; +static int _add __P((char *)); +static int _conv __P((int, int, int)); +static int _secs __P((const struct tm *)); +static size_t _fmt __P((const char *, const struct tm *)); + +size_t +strftime(s, maxsize, format, t) + char *s; + size_t maxsize; + const char *format; + const struct tm *t; +{ + + pt = s; + if ((gsize = maxsize) < 1) + return(0); + if (_fmt(format, t)) { + *pt = '\0'; + return(maxsize - gsize); + } + return(0); +} + +static size_t +_fmt(format, t) + register const char *format; + const struct tm *t; +{ + for (; *format; ++format) { + if (*format == '%') + switch(*++format) { + case '\0': + --format; + break; + case 'A': + if (t->tm_wday < 0 || t->tm_wday > 6) + return(0); + if (!_add(Afmt[t->tm_wday])) + return(0); + continue; + case 'a': + if (t->tm_wday < 0 || t->tm_wday > 6) + return(0); + if (!_add(afmt[t->tm_wday])) + return(0); + continue; + case 'B': + if (t->tm_mon < 0 || t->tm_mon > 11) + return(0); + if (!_add(Bfmt[t->tm_mon])) + return(0); + continue; + case 'b': + case 'h': + if (t->tm_mon < 0 || t->tm_mon > 11) + return(0); + if (!_add(bfmt[t->tm_mon])) + return(0); + continue; + case 'C': + if (!_fmt("%a %b %e %H:%M:%S %Y", t)) + return(0); + continue; + case 'c': + if (!_fmt("%m/%d/%y %H:%M:%S", t)) + return(0); + continue; + case 'D': + if (!_fmt("%m/%d/%y", t)) + return(0); + continue; + case 'd': + if (!_conv(t->tm_mday, 2, '0')) + return(0); + continue; + case 'e': + if (!_conv(t->tm_mday, 2, ' ')) + return(0); + continue; + case 'H': + if (!_conv(t->tm_hour, 2, '0')) + return(0); + continue; + case 'I': + if (!_conv(t->tm_hour % 12 ? + t->tm_hour % 12 : 12, 2, '0')) + return(0); + continue; + case 'j': + if (!_conv(t->tm_yday + 1, 3, '0')) + return(0); + continue; + case 'k': + if (!_conv(t->tm_hour, 2, ' ')) + return(0); + continue; + case 'l': + if (!_conv(t->tm_hour % 12 ? + t->tm_hour % 12 : 12, 2, ' ')) + return(0); + continue; + case 'M': + if (!_conv(t->tm_min, 2, '0')) + return(0); + continue; + case 'm': + if (!_conv(t->tm_mon + 1, 2, '0')) + return(0); + continue; + case 'n': + if (!_add("\n")) + return(0); + continue; + case 'p': + if (!_add(t->tm_hour >= 12 ? "PM" : "AM")) + return(0); + continue; + case 'R': + if (!_fmt("%H:%M", t)) + return(0); + continue; + case 'r': + if (!_fmt("%I:%M:%S %p", t)) + return(0); + continue; + case 'S': + if (!_conv(t->tm_sec, 2, '0')) + return(0); + continue; + case 's': + if (!_secs(t)) + return(0); + continue; + case 'T': + case 'X': + if (!_fmt("%H:%M:%S", t)) + return(0); + continue; + case 't': + if (!_add("\t")) + return(0); + continue; + case 'U': + if (!_conv((t->tm_yday + 7 - t->tm_wday) / 7, + 2, '0')) + return(0); + continue; + case 'W': + if (!_conv((t->tm_yday + 7 - + (t->tm_wday ? (t->tm_wday - 1) : 6)) + / 7, 2, '0')) + return(0); + continue; + case 'w': + if (!_conv(t->tm_wday, 1, '0')) + return(0); + continue; + case 'x': + if (!_fmt("%m/%d/%y", t)) + return(0); + continue; + case 'y': + if (!_conv((t->tm_year + TM_YEAR_BASE) + % 100, 2, '0')) + return(0); + continue; + case 'Y': + if (!_conv(t->tm_year + TM_YEAR_BASE, 4, '0')) + return(0); + continue; + case 'Z': + if (!t->tm_zone || !_add(t->tm_zone)) + return(0); + 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) does. + */ + default: + break; + } + if (!gsize--) + return(0); + *pt++ = *format; + } + return(gsize); +} + +static int +_secs(t) + const struct tm *t; +{ + static char buf[15]; + register time_t s; + register char *p; + struct tm tmp; + + /* Make a copy, mktime(3) modifies the tm struct. */ + tmp = *t; + s = mktime(&tmp); + for (p = buf + sizeof(buf) - 2; s > 0 && p > buf; s /= 10) + *p-- = s % 10 + '0'; + return(_add(++p)); +} + +static int +_conv(n, digits, pad) + int n, digits, pad; +{ + static char buf[10]; + register char *p; + + for (p = buf + sizeof(buf) - 2; n > 0 && p > buf; n /= 10, --digits) + *p-- = n % 10 + '0'; + while (p > buf && digits-- > 0) + *p-- = pad; + return(_add(++p)); +} + +static int +_add(str) + register char *str; +{ + for (;; ++pt, --gsize) { + if (!gsize) + return(0); + if (!(*pt = *str++)) + return(1); + } +} diff --git a/string/string.3 b/string/string.3 new file mode 100644 index 0000000..04e84bb --- /dev/null +++ b/string/string.3 @@ -0,0 +1,158 @@ +.\" 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. +.\" 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. +.\" +.\" @(#)string.3 8.2 (Berkeley) 12/11/93 +.\" $FreeBSD: src/lib/libc/string/string.3,v 1.11 2001/10/01 16:09:00 ru Exp $ +.\" +.Dd December 11, 1993 +.Dt STRING 3 +.Os +.Sh NAME +.Nm strcat , +.Nm strncat , +.Nm strchr , +.Nm strrchr , +.Nm strcmp , +.Nm strncmp , +.Nm strcasecmp , +.Nm strncasecmp , +.Nm strcpy , +.Nm strncpy , +.Nm strerror , +.Nm strlen , +.Nm strpbrk , +.Nm strsep , +.Nm strspn , +.Nm strcspn , +.Nm strstr , +.Nm strtok , +.Nm index , +.Nm rindex +.Nd string specific functions +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In string.h +.Ft char * +.Fn strcat "char *s" "const char * append" +.Ft char * +.Fn strncat "char *s" "const char *append" "size_t count" +.Ft char * +.Fn strchr "const char *s" "int c" +.Ft char * +.Fn strrchr "const char *s" "int c" +.Ft int +.Fn strcmp "const char *s1" "const char *s2" +.Ft int +.Fn strncmp "const char *s1" "const char *s2" "size_t count" +.Ft int +.Fn strcasecmp "const char *s1" "const char *s2" +.Ft int +.Fn strncasecmp "const char *s1" "const char *s2" "size_t count" +.Ft char * +.Fn strcpy "char *dst" "const char *src" +.Ft char * +.Fn strncpy "char *dst" "const char *src" "size_t count" +.Ft char * +.Fn strerror "int errno" +.Ft size_t +.Fn strlen "const char *s" +.Ft char * +.Fn strpbrk "const char *s" "const char *charset" +.Ft char * +.Fn strsep "char **stringp" "const char *delim" +.Ft size_t +.Fn strspn "const char *s" "const char *charset" +.Ft size_t +.Fn strcspn "const char *s" "const char *charset" +.Ft char * +.Fn strstr "const char *big" "const char *little" +.Ft char * +.Fn strtok "char *s" "const char *delim" +.Ft char * +.Fn index "const char *s" "int c" +.Ft char * +.Fn rindex "const char *s" "int c" +.Sh DESCRIPTION +The string +functions manipulate strings terminated by a +null byte. +.Pp +See the specific manual pages for more information. +For manipulating variable length generic objects as byte +strings (without the null byte check), see +.Xr bstring 3 . +.Pp +Except as noted in their specific manual pages, +the string functions do not test the destination +for size limitations. +.Sh SEE ALSO +.Xr bstring 3 , +.Xr index 3 , +.Xr rindex 3 , +.Xr strcasecmp 3 , +.Xr strcat 3 , +.Xr strchr 3 , +.Xr strcmp 3 , +.Xr strcpy 3 , +.Xr strcspn 3 , +.Xr strerror 3 , +.Xr strlen 3 , +.Xr strpbrk 3 , +.Xr strrchr 3 , +.Xr strsep 3 , +.Xr strspn 3 , +.Xr strstr 3 , +.Xr strtok 3 +.Sh STANDARDS +The +.Fn strcat , +.Fn strncat , +.Fn strchr , +.Fn strrchr , +.Fn strcmp , +.Fn strncmp , +.Fn strcpy , +.Fn strncpy , +.Fn strerror , +.Fn strlen , +.Fn strpbrk , +.Fn strsep , +.Fn strspn , +.Fn strcspn , +.Fn strstr , +and +.Fn strtok +functions +conform to +.St -isoC . diff --git a/string/strlcat.c b/string/strlcat.c new file mode 100644 index 0000000..7ec53b1 --- /dev/null +++ b/string/strlcat.c @@ -0,0 +1,74 @@ +/* + * Copyright (c) 1998 Todd C. Miller + * 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. 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 ARE 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 + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#if defined(LIBC_SCCS) && !defined(lint) +static char *rcsid = "$OpenBSD: strlcat.c,v 1.2 1999/06/17 16:28:58 millert Exp $"; +#endif /* LIBC_SCCS and not lint */ +#ifndef lint +static const char rcsid[] = + "$FreeBSD: src/lib/libc/string/strlcat.c,v 1.2.4.2 2001/07/09 23:30:06 obrien Exp $"; +#endif + +#include +#include + +/* + * Appends src to string dst of size siz (unlike strncat, siz is the + * full size of dst, not space left). At most siz-1 characters + * will be copied. Always NUL terminates (unless siz <= strlen(dst)). + * Returns strlen(initial dst) + strlen(src); if retval >= siz, + * truncation occurred. + */ +size_t strlcat(dst, src, siz) + char *dst; + const char *src; + size_t siz; +{ + register char *d = dst; + register const char *s = src; + register size_t n = siz; + size_t dlen; + + /* Find the end of dst and adjust bytes left but don't go past end */ + while (n-- != 0 && *d != '\0') + d++; + dlen = d - dst; + n = siz - dlen; + + if (n == 0) + return(dlen + strlen(s)); + while (*s != '\0') { + if (n != 1) { + *d++ = *s; + n--; + } + s++; + } + *d = '\0'; + + return(dlen + (s - src)); /* count does not include NUL */ +} diff --git a/string/strlcpy.3 b/string/strlcpy.3 new file mode 100644 index 0000000..60bb36b --- /dev/null +++ b/string/strlcpy.3 @@ -0,0 +1,201 @@ +.\" $OpenBSD: strlcpy.3,v 1.5 1999/06/06 15:17:32 aaron Exp $ +.\" +.\" Copyright (c) 1998 Todd C. Miller +.\" 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. 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 ARE 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 +.\" ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +.\" +.\" $FreeBSD: src/lib/libc/string/strlcpy.3,v 1.11 2001/10/01 16:09:00 ru Exp $ +.\" +.Dd June 22, 1998 +.Dt STRLCPY 3 +.Os +.Sh NAME +.Nm strlcpy , +.Nm strlcat +.Nd size-bounded string copying and concatenation +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In string.h +.Ft size_t +.Fn strlcpy "char *dst" "const char *src" "size_t size" +.Ft size_t +.Fn strlcat "char *dst" "const char *src" "size_t size" +.Sh DESCRIPTION +The +.Fn strlcpy +and +.Fn strlcat +functions copy and concatenate strings respectively. They are designed +to be safer, more consistent, and less error prone replacements for +.Xr strncpy 3 +and +.Xr strncat 3 . +Unlike those functions, +.Fn strlcpy +and +.Fn strlcat +take the full size of the buffer (not just the length) and guarantee to +NUL-terminate the result (as long as +.Fa size +is larger than 0 or, in the case of +.Fn strlcat , +as long as there is at least one byte free in +.Fa dst ) . +Note that you should include a byte for the NUL in +.Fa size . +Also note that +.Fn strlcpy +and +.Fn strlcat +only operate on true +.Dq C +strings. +This means that for +.Fn strlcpy +.Fa src +must be NUL-terminated and for +.Fn strlcat +both +.Fa src +and +.Fa dst +must be NUL-terminated. +.Pp +The +.Fn strlcpy +function copies up to +.Fa size +- 1 characters from the NUL-terminated string +.Fa src +to +.Fa dst , +NUL-terminating the result. +.Pp +The +.Fn strlcat +function appends the NUL-terminated string +.Fa src +to the end of +.Fa dst . +It will append at most +.Fa size +- strlen(dst) - 1 bytes, NUL-terminating the result. +.Sh RETURN VALUES +The +.Fn strlcpy +and +.Fn strlcat +functions return the total length of the string they tried to +create. For +.Fn strlcpy +that means the length of +.Fa src . +For +.Fn strlcat +that means the initial length of +.Fa dst +plus +the length of +.Fa src . +While this may seem somewhat confusing it was done to make +truncation detection simple. +.Pp +Note however, that if +.Fn strlcat +traverses +.Fa size +characters without finding a NUL, the length of the string is considered +to be +.Fa size +and the destination string will not be NUL-terminated (since there was +no space for the NUL). +This keeps +.Fn strlcat +from running off the end of a string. +In practice this should not happen (as it means that either +.Fa size +is incorrect or that +.Fa dst +is not a proper +.Dq C +string). +The check exists to prevent potential security problems in incorrect code. +.Sh EXAMPLES +The following code fragment illustrates the simple case: +.Bd -literal -offset indent +char *s, *p, buf[BUFSIZ]; + +\&... + +(void)strlcpy(buf, s, sizeof(buf)); +(void)strlcat(buf, p, sizeof(buf)); +.Ed +.Pp +To detect truncation, perhaps while building a pathname, something +like the following might be used: +.Bd -literal -offset indent +char *dir, *file, pname[MAXPATHLEN]; + +\&... + +if (strlcpy(pname, dir, sizeof(pname)) >= sizeof(pname)) + goto toolong; +if (strlcat(pname, file, sizeof(pname)) >= sizeof(pname)) + goto toolong; +.Ed +.Pp +Since we know how many characters we copied the first time, we can +speed things up a bit by using a copy instead of an append: +.Bd -literal -offset indent +char *dir, *file, pname[MAXPATHLEN]; +size_t n; + +\&... + +n = strlcpy(pname, dir, sizeof(pname)); +if (n >= sizeof(pname)) + goto toolong; +if (strlcpy(pname + n, file, sizeof(pname) - n) >= sizeof(pname) - n) + goto toolong; +.Ed +.Pp +However, one may question the validity of such optimizations, as they +defeat the whole purpose of +.Fn strlcpy +and +.Fn strlcat . +As a matter of fact, the first version of this manual page got it wrong. +.Sh SEE ALSO +.Xr snprintf 3 , +.Xr strncat 3 , +.Xr strncpy 3 +.Sh HISTORY +.Fn strlcpy +and +.Fn strlcat +functions first appeared in +.Ox 2.4 , +and made their appearance in +.Fx 3.3 . diff --git a/string/strlcpy.c b/string/strlcpy.c new file mode 100644 index 0000000..9de9d32 --- /dev/null +++ b/string/strlcpy.c @@ -0,0 +1,74 @@ +/* $OpenBSD: strlcpy.c,v 1.4 1999/05/01 18:56:41 millert Exp $ */ + +/* + * Copyright (c) 1998 Todd C. Miller + * 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. 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 ARE 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 + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#if defined(LIBC_SCCS) && !defined(lint) +#if 0 +static char *rcsid = "$OpenBSD: strlcpy.c,v 1.4 1999/05/01 18:56:41 millert Exp $"; +#endif +#endif /* LIBC_SCCS and not lint */ +#ifndef lint +static const char rcsid[] = + "$FreeBSD: src/lib/libc/string/strlcpy.c,v 1.2.4.1 2001/07/09 23:30:06 obrien Exp $"; +#endif + +#include +#include + +/* + * Copy src to string dst of size siz. At most siz-1 characters + * will be copied. Always NUL terminates (unless siz == 0). + * Returns strlen(src); if retval >= siz, truncation occurred. + */ +size_t strlcpy(dst, src, siz) + char *dst; + const char *src; + size_t siz; +{ + register char *d = dst; + register const char *s = src; + register size_t n = siz; + + /* Copy as many bytes as will fit */ + if (n != 0 && --n != 0) { + do { + if ((*d++ = *s++) == 0) + break; + } while (--n != 0); + } + + /* Not enough room in dst, add NUL and traverse rest of src */ + if (n == 0) { + if (siz != 0) + *d = '\0'; /* NUL-terminate dst */ + while (*s++) + ; + } + + return(s - src - 1); /* count does not include NUL */ +} diff --git a/string/strlen.3 b/string/strlen.3 new file mode 100644 index 0000000..b490ced --- /dev/null +++ b/string/strlen.3 @@ -0,0 +1,73 @@ +.\" 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. +.\" +.\" @(#)strlen.3 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD: src/lib/libc/string/strlen.3,v 1.6 2001/10/01 16:09:00 ru Exp $ +.\" +.Dd June 4, 1993 +.Dt STRLEN 3 +.Os +.Sh NAME +.Nm strlen +.Nd find length of string +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In string.h +.Ft size_t +.Fn strlen "const char *s" +.Sh DESCRIPTION +The +.Fn strlen +function +computes the length of the string +.Fa s . +.Sh RETURN VALUES +The +.Fn strlen +function +returns +the number of characters that precede the +terminating +.Dv NUL +character. +.Sh SEE ALSO +.Xr string 3 +.Sh STANDARDS +The +.Fn strlen +function +conforms to +.St -isoC . diff --git a/string/strmode.3 b/string/strmode.3 new file mode 100644 index 0000000..b72171b --- /dev/null +++ b/string/strmode.3 @@ -0,0 +1,153 @@ +.\" Copyright (c) 1990, 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. +.\" +.\" @(#)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 $ +.\" +.Dd July 28, 1994 +.Dt STRMODE 3 +.Os +.Sh NAME +.Nm strmode +.Nd convert inode status information into a symbolic string +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In string.h +.Ft void +.Fn strmode "mode_t mode" "char *bp" +.Sh DESCRIPTION +The +.Fn strmode +function +converts a file +.Fa mode +(the type and permission information associated with an inode, see +.Xr stat 2 ) +into a symbolic string which is stored in the location referenced by +.Fa bp . +This stored string is eleven characters in length plus a trailing +.Dv NUL . +.Pp +The first character is the inode type, and will be one of the following: +.Pp +.Bl -tag -width flag -offset indent -compact +.It \- +regular file +.It b +block special +.It c +character special +.It d +directory +.It l +symbolic link +.It p +fifo +.It s +socket +.It w +whiteout +.It ? +unknown inode type +.El +.Pp +The next nine characters encode three sets of permissions, in three +characters each. +The first three characters are the permissions for the owner of the +file, the second three for the group the file belongs to, and the +third for the ``other'', or default, set of users. +.Pp +Permission checking is done as specifically as possible. +If read permission is denied to the owner of a file in the first set +of permissions, the owner of the file will not be able to read the file. +This is true even if the owner is in the file's group and the group +permissions allow reading or the ``other'' permissions allow reading. +.Pp +If the first character of the three character set is an ``r'', the file is +readable for that set of users; if a dash ``\-'', it is not readable. +.Pp +If the second character of the three character set is a ``w'', the file is +writable for that set of users; if a dash ``\-'', it is not writable. +.Pp +The third character is the first of the following characters that apply: +.Bl -tag -width xxxx +.It S +If the character is part of the owner permissions and the file is not +executable or the directory is not searchable by the owner, and the +set-user-id bit is set. +.It S +If the character is part of the group permissions and the file is not +executable or the directory is not searchable by the group, and the +set-group-id bit is set. +.It T +If the character is part of the other permissions and the file is not +executable or the directory is not searchable by others, and the ``sticky'' +.Pq Dv S_ISVTX +bit is set. +.It s +If the character is part of the owner permissions and the file is +executable or the directory searchable by the owner, and the set-user-id +bit is set. +.It s +If the character is part of the group permissions and the file is +executable or the directory searchable by the group, and the set-group-id +bit is set. +.It t +If the character is part of the other permissions and the file is +executable or the directory searchable by others, and the ``sticky'' +.Pq Dv S_ISVTX +bit is set. +.It x +The file is executable or the directory is searchable. +.It \- +None of the above apply. +.El +.Pp +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 , +.Xr stat 2 , +.Xr getmode 3 , +.Xr setmode 3 +.Sh HISTORY +The +.Fn strmode +function first appeared in +.Bx 4.4 . diff --git a/string/strmode.c b/string/strmode.c new file mode 100644 index 0000000..462b945 --- /dev/null +++ b/string/strmode.c @@ -0,0 +1,170 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 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 +#include +#include + +void +strmode(mode, p) + register mode_t mode; + register char *p; +{ + /* print type */ + switch (mode & S_IFMT) { + case S_IFDIR: /* directory */ + *p++ = 'd'; + break; + case S_IFCHR: /* character special */ + *p++ = 'c'; + break; + case S_IFBLK: /* block special */ + *p++ = 'b'; + break; + case S_IFREG: /* regular */ + *p++ = '-'; + break; + case S_IFLNK: /* symbolic link */ + *p++ = 'l'; + break; + case S_IFSOCK: /* socket */ + *p++ = 's'; + break; +#ifdef S_IFIFO + case S_IFIFO: /* fifo */ + *p++ = 'p'; + break; +#endif +#ifdef S_IFWHT + case S_IFWHT: /* whiteout */ + *p++ = 'w'; + break; +#endif + default: /* unknown */ + *p++ = '?'; + break; + } + /* usr */ + if (mode & S_IRUSR) + *p++ = 'r'; + else + *p++ = '-'; + if (mode & S_IWUSR) + *p++ = 'w'; + else + *p++ = '-'; + switch (mode & (S_IXUSR | S_ISUID)) { + case 0: + *p++ = '-'; + break; + case S_IXUSR: + *p++ = 'x'; + break; + case S_ISUID: + *p++ = 'S'; + break; + case S_IXUSR | S_ISUID: + *p++ = 's'; + break; + } + /* group */ + if (mode & S_IRGRP) + *p++ = 'r'; + else + *p++ = '-'; + if (mode & S_IWGRP) + *p++ = 'w'; + else + *p++ = '-'; + switch (mode & (S_IXGRP | S_ISGID)) { + case 0: + *p++ = '-'; + break; + case S_IXGRP: + *p++ = 'x'; + break; + case S_ISGID: + *p++ = 'S'; + break; + case S_IXGRP | S_ISGID: + *p++ = 's'; + break; + } + /* other */ + if (mode & S_IROTH) + *p++ = 'r'; + else + *p++ = '-'; + if (mode & S_IWOTH) + *p++ = 'w'; + else + *p++ = '-'; + switch (mode & (S_IXOTH | S_ISVTX)) { + case 0: + *p++ = '-'; + break; + case S_IXOTH: + *p++ = 'x'; + break; + case S_ISVTX: + *p++ = 'T'; + break; + case S_IXOTH | S_ISVTX: + *p++ = 't'; + break; + } + *p++ = ' '; /* will be a '+' if ACL's implemented */ + *p = '\0'; +} diff --git a/string/strpbrk.3 b/string/strpbrk.3 new file mode 100644 index 0000000..715bb71 --- /dev/null +++ b/string/strpbrk.3 @@ -0,0 +1,80 @@ +.\" 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. +.\" +.\" @(#)strpbrk.3 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD: src/lib/libc/string/strpbrk.3,v 1.7 2001/10/01 16:09:00 ru Exp $ +.\" +.Dd June 4, 1993 +.Dt STRPBRK 3 +.Os +.Sh NAME +.Nm strpbrk +.Nd locate multiple characters in string +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In string.h +.Ft char * +.Fn strpbrk "const char *s" "const char *charset" +.Sh DESCRIPTION +The +.Fn strpbrk +function +locates in the null-terminated string +.Fa s +the first occurrence of any character in the string +.Fa charset +and returns a pointer to this character. +If no characters from +.Fa charset +occur anywhere in +.Fa s +.Fn strpbrk +returns NULL. +.Sh SEE ALSO +.Xr memchr 3 , +.Xr strchr 3 , +.Xr strcspn 3 , +.Xr strrchr 3 , +.Xr strsep 3 , +.Xr strspn 3 , +.Xr strstr 3 , +.Xr strtok 3 +.Sh STANDARDS +The +.Fn strpbrk +function +conforms to +.St -isoC . diff --git a/string/strpbrk.c b/string/strpbrk.c new file mode 100644 index 0000000..7a68733 --- /dev/null +++ b/string/strpbrk.c @@ -0,0 +1,75 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1985, 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 +#include + +/* + * Find the first occurrence in s1 of a character in s2 (excluding NUL). + */ +char * +strpbrk(s1, s2) + register const char *s1, *s2; +{ + register const char *scanp; + register int c, sc; + + while ((c = *s1++) != 0) { + for (scanp = s2; (sc = *scanp++) != 0;) + if (sc == c) + return ((char *)(s1 - 1)); + } + return (NULL); +} diff --git a/string/strrchr.3 b/string/strrchr.3 new file mode 100644 index 0000000..785cbbf --- /dev/null +++ b/string/strrchr.3 @@ -0,0 +1,91 @@ +.\" 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. +.\" +.\" @(#)strrchr.3 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD: src/lib/libc/string/strrchr.3,v 1.9 2001/10/01 16:09:00 ru Exp $ +.\" +.Dd June 4, 1993 +.Dt STRRCHR 3 +.Os +.Sh NAME +.Nm strrchr +.Nd locate character in string +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In string.h +.Ft char * +.Fn strrchr "const char *s" "int c" +.Sh DESCRIPTION +The +.Fn strrchr +function +locates the last occurrence of +.Fa c +(converted to a char) +in the string +.Fa s . +If +.Fa c +is +.Ql \e0 , +.Fn strrchr +locates the terminating +.Ql \e0 . +.Sh RETURN VALUES +The +.Fn strrchr +function +returns a pointer to the character, +or a null +pointer if +.Fa c +does not occur anywhere in +.Fa s . +.Sh SEE ALSO +.Xr memchr 3 , +.Xr strchr 3 , +.Xr strcspn 3 , +.Xr strpbrk 3 , +.Xr strsep 3 , +.Xr strspn 3 , +.Xr strstr 3 , +.Xr strtok 3 +.Sh STANDARDS +The +.Fn strrchr +function +conforms to +.St -isoC . diff --git a/string/strsep.3 b/string/strsep.3 new file mode 100644 index 0000000..3b5e3bc --- /dev/null +++ b/string/strsep.3 @@ -0,0 +1,121 @@ +.\" 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. +.\" +.\" 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. +.\" +.\" @(#)strsep.3 8.1 (Berkeley) 6/9/93 +.\" $FreeBSD: src/lib/libc/string/strsep.3,v 1.11 2001/10/01 16:09:00 ru Exp $ +.\" +.Dd June 9, 1993 +.Dt STRSEP 3 +.Os +.Sh NAME +.Nm strsep +.Nd separate strings +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In string.h +.Ft char * +.Fn strsep "char **stringp" "const char *delim" +.Sh DESCRIPTION +The +.Fn strsep +function locates, in the string referenced by +.Fa *stringp , +the first occurrence of any character in the string +.Fa delim +(or the terminating +.Ql \e0 +character) and replaces it with a +.Ql \e0 . +The location of the next character after the delimiter character +(or NULL, if the end of the string was reached) is stored in +.Fa *stringp . +The original value of +.Fa *stringp +is returned. +.Pp +An ``empty'' field, i.e. one caused by two adjacent delimiter characters, +can be detected by comparing the location referenced by the pointer returned +in +.Fa *stringp +to +.Ql \e0 . +.Pp +If +.Fa *stringp +is initially +.Dv NULL , +.Fn strsep +returns +.Dv NULL . +.Sh EXAMPLES +The following uses +.Fn strsep +to parse a string, containing tokens delimited by white space, into an +argument vector: +.Bd -literal -offset indent +char **ap, *argv[10], *inputstring; + +for (ap = argv; (*ap = strsep(&inputstring, " \et")) != NULL;) + if (**ap != '\e0') + if (++ap >= &argv[10]) + break; +.Ed +.Sh SEE ALSO +.Xr memchr 3 , +.Xr strchr 3 , +.Xr strcspn 3 , +.Xr strpbrk 3 , +.Xr strrchr 3 , +.Xr strspn 3 , +.Xr strstr 3 , +.Xr strtok 3 +.Sh HISTORY +The +.Fn strsep +function +is intended as a replacement for the +.Fn strtok +function. +While the +.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 +two adjacent delimiter characters, or to be used for more than a single +string at a time. +The +.Fn strsep +function first appeared in +.Bx 4.4 . diff --git a/string/strsep.c b/string/strsep.c new file mode 100644 index 0000000..8b43f33 --- /dev/null +++ b/string/strsep.c @@ -0,0 +1,101 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 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 +#include +#include + +#if defined(LIBC_SCCS) && !defined(lint) +static char sccsid[] = "@(#)strsep.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ + +/* + * Get next token from string *stringp, where tokens are possibly-empty + * strings separated by characters from delim. + * + * Writes NULs into the string at *stringp to end tokens. + * delim need not remain constant from call to call. + * On return, *stringp points past the last NUL written (if there might + * be further tokens), or is NULL (if there are definitely no more tokens). + * + * If *stringp is NULL, strsep returns NULL. + */ +char * +strsep(stringp, delim) + register char **stringp; + register const char *delim; +{ + register char *s; + register const char *spanp; + register int c, sc; + char *tok; + + if ((s = *stringp) == NULL) + return (NULL); + for (tok = s;;) { + c = *s++; + spanp = delim; + do { + if ((sc = *spanp++) == c) { + if (c == 0) + s = NULL; + else + s[-1] = 0; + *stringp = s; + return (tok); + } + } while (sc != 0); + } + /* NOTREACHED */ +} diff --git a/string/strspn.3 b/string/strspn.3 new file mode 100644 index 0000000..b55b12c --- /dev/null +++ b/string/strspn.3 @@ -0,0 +1,80 @@ +.\" 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. +.\" +.\" @(#)strspn.3 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD: src/lib/libc/string/strspn.3,v 1.8 2001/10/01 16:09:00 ru Exp $ +.\" +.Dd June 4, 1993 +.Dt STRSPN 3 +.Os +.Sh NAME +.Nm strspn +.Nd span a string +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In string.h +.Ft size_t +.Fn strspn "const char *s" "const char *charset" +.Sh DESCRIPTION +The +.Fn strspn +function +spans the initial part of the null-terminated string +.Fa s +as long as the characters from +.Fa s +occur in string +.Fa charset . +.Sh RETURN VALUES +The +.Fn strspn +function +returns the number of characters spanned. +.Sh SEE ALSO +.Xr memchr 3 , +.Xr strchr 3 , +.Xr strcspn 3 , +.Xr strpbrk 3 , +.Xr strrchr 3 , +.Xr strsep 3 , +.Xr strstr 3 , +.Xr strtok 3 +.Sh STANDARDS +The +.Fn strspn +function +conforms to +.St -isoC . diff --git a/string/strspn.c b/string/strspn.c new file mode 100644 index 0000000..5e496f2 --- /dev/null +++ b/string/strspn.c @@ -0,0 +1,79 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1989, 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 +#include + +/* + * Span the string s2 (skip characters that are in s2). + */ +size_t +strspn(s1, s2) + const char *s1; + register const char *s2; +{ + register const char *p = s1, *spanp; + register char c, sc; + + /* + * Skip any characters in s2, excluding the terminating \0. + */ +cont: + c = *p++; + for (spanp = s2; (sc = *spanp++) != 0;) + if (sc == c) + goto cont; + return (p - 1 - s1); +} diff --git a/string/strstr.3 b/string/strstr.3 new file mode 100644 index 0000000..433f26c --- /dev/null +++ b/string/strstr.3 @@ -0,0 +1,144 @@ +.\" Copyright (c) 2001 Mike Barcroft +.\" 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. +.\" +.\" @(#)strstr.3 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD: src/lib/libc/string/strstr.3,v 1.11 2001/10/11 15:49:06 mike Exp $ +.\" +.Dd October 11, 2001 +.Dt STRSTR 3 +.Os +.Sh NAME +.Nm strstr , strcasestr , strnstr +.Nd locate a substring in a string +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In string.h +.Ft char * +.Fn strstr "const char *big" "const char *little" +.Ft char * +.Fn strcasestr "const char *big" "const char *little" +.Ft char * +.Fn strnstr "const char *big" "const char *little" "size_t len" +.Sh DESCRIPTION +The +.Fn strstr +function +locates the first occurrence of the null-terminated string +.Fa little +in the null-terminated string +.Fa big . +.Pp +The +.Fn strcasestr +function is similar to +.Fn strstr , +but ignores the case of both strings. +.Pp +The +.Fn strnstr +function +locates the first occurrence of the null-terminated string +.Fa little +in the string +.Fa big , +where not more than +.Fa len +characters are searched. +Characters that appear after a +.Ql \e0 +character are not searched. +Since the +.Fn strnstr +function is a +.Fx +specific API, it should only be used when portablility is not a concern. +.Sh RETURN VALUES +If +.Fa little +is an empty string, +.Fa big +is returned; +if +.Fa little +occurs nowhere in +.Fa big , +NULL is returned; +otherwise a pointer to the first character of the first occurrence of +.Fa little +is returned. +.Sh EXAMPLES +The following sets the pointer +.Va ptr +to the +.Dq Li Bar Baz +portion of +.Va largestring : +.Bd -literal -offset indent +const char *largestring = "Foo Bar Baz"; +const char *smallstring = "Bar"; +char *ptr; + +ptr = strstr(largestring, smallstring); +.Ed +.Pp +The following sets the pointer +.Va ptr +to NULL, because only the first 4 characters of +.Va largestring +are searched: +.Bd -literal -offset indent +const char *largestring = "Foo Bar Baz"; +const char *smallstring = "Bar"; +char *ptr; + +ptr = strnstr(largestring, smallstring, 4); +.Ed +.Sh SEE ALSO +.Xr memchr 3 , +.Xr strchr 3 , +.Xr strcspn 3 , +.Xr strpbrk 3 , +.Xr strrchr 3 , +.Xr strsep 3 , +.Xr strspn 3 , +.Xr strtok 3 +.Sh STANDARDS +The +.Fn strstr +function +conforms to +.St -isoC . diff --git a/string/strstr.c b/string/strstr.c new file mode 100644 index 0000000..6ec3d6d --- /dev/null +++ b/string/strstr.c @@ -0,0 +1,83 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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 +#include + +/* + * Find the first occurrence of find in s. + */ +char * +strstr(s, find) + register const char *s, *find; +{ + register char c, sc; + register size_t len; + + if ((c = *find++) != 0) { + len = strlen(find); + do { + do { + if ((sc = *s++) == 0) + return (NULL); + } while (sc != c); + } while (strncmp(s, find, len) != 0); + s--; + } + return ((char *)s); +} diff --git a/string/strtok.3 b/string/strtok.3 new file mode 100644 index 0000000..bc90987 --- /dev/null +++ b/string/strtok.3 @@ -0,0 +1,175 @@ +.\" Copyright (c) 1998 Softweyr LLC. All rights reserved. +.\" +.\" strtok_r, from Berkeley strtok +.\" Oct 13, 1998 by Wes Peters +.\" +.\" Copyright (c) 1988, 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 +.\" notices, this list of conditions and the following disclaimer. +.\" +.\" 2. Redistributions in binary form must reproduce the above +.\" copyright notices, 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 Softweyr LLC, the +.\" University of California, Berkeley, and its contributors. +.\" +.\" 4. Neither the name of Softweyr LLC, 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 SOFTWEYR LLC, 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 SOFTWEYR LLC, 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. +.\" +.\" @(#)strtok.3 8.2 (Berkeley) 2/3/94 +.\" $FreeBSD: src/lib/libc/string/strtok.3,v 1.22 2001/10/01 16:09:00 ru Exp $ +.\" +.Dd November 27, 1998 +.Dt STRTOK 3 +.Os +.Sh NAME +.Nm strtok , strtok_r +.Nd string tokens +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In string.h +.Ft char * +.Fn strtok "char *str" "const char *sep" +.Ft char * +.Fn strtok_r "char *str" "const char *sep" "char **last" +.Sh DESCRIPTION +.Bf -symbolic +This interface is obsoleted by +.Xr strsep 3 . +.Ef +.Pp +The +.Fn strtok +function +is used to isolate sequential tokens in a null-terminated string, +.Fa str . +These tokens are separated in the string by at least one of the +characters in +.Fa sep . +The first time that +.Fn strtok +is called, +.Fa str +should be specified; subsequent calls, wishing to obtain further tokens +from the same string, should pass a null pointer instead. +The separator string, +.Fa sep , +must be supplied each time, and may change between calls. +.Pp +The implementation will behave as if no library function calls +.Fn strtok . +.Pp +The +.Fn strtok_r +function is a reentrant version of +.Fn strtok . +The context pointer +.Fa last +must be provided on each call. +.Fn strtok_r +may also be used to nest two parsing loops within one another, as +long as separate context pointers are used. +.Pp +The +.Fn strtok +and +.Fn strtok_r +functions +return a pointer to the beginning of each subsequent token in the string, +after replacing the token itself with a +.Dv NUL +character. +When no more tokens remain, a null pointer is returned. +.Sh EXAMPLES +The following uses +.Fn strtok_r +to parse two strings using separate contexts: +.Bd -literal +char test[80], blah[80]; +char *sep = "\e\e/:;=-"; +char *word, *phrase, *brkt, *brkb; + +strcpy(test, "This;is.a:test:of=the/string\e\etokenizer-function."); + +for (word = strtok_r(test, sep, &brkt); + word; + word = strtok_r(NULL, sep, &brkt)) +{ + strcpy(blah, "blah:blat:blab:blag"); + + for (phrase = strtok_r(blah, sep, &brkb); + phrase; + phrase = strtok_r(NULL, sep, &brkb)) + { + printf("So far we're at %s:%s\en", word, phrase); + } +} +.Ed +.Sh SEE ALSO +.Xr memchr 3 , +.Xr strchr 3 , +.Xr strcspn 3 , +.Xr strpbrk 3 , +.Xr strrchr 3 , +.Xr strsep 3 , +.Xr strspn 3 , +.Xr strstr 3 +.Sh STANDARDS +The +.Fn strtok +function +conforms to +.St -isoC . +.Sh BUGS +The System V +.Fn strtok , +if handed a string containing only delimiter characters, +will not alter the next starting point, so that a call to +.Fn strtok +with a different (or empty) delimiter string +may return a +.Pf non- Dv NULL +value. +Since this implementation always alters the next starting point, +such a sequence of calls would always return +.Dv NULL . +.Sh AUTHORS +.An Wes Peters , +Softweyr LLC: +.Aq wes@softweyr.com +.Pp +Based on the +.Fx 3.0 +implementation. diff --git a/string/strtok.c b/string/strtok.c new file mode 100644 index 0000000..1dfa6ad --- /dev/null +++ b/string/strtok.c @@ -0,0 +1,168 @@ +/* + * Copyright (c) 1998 Softweyr LLC. All rights reserved. + * + * strtok_r, from Berkeley strtok + * Oct 13, 1998 by Wes Peters + * + * Copyright (c) 1988, 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 + * notices, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notices, 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 Softweyr LLC, 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 SOFTWEYR LLC, 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 SOFTWEYR LLC, 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. + */ + +#ifndef lint +static const char rcsid[] = + "$FreeBSD: src/lib/libc/string/strtok.c,v 1.2.6.1 2001/07/09 23:30:07 obrien Exp $"; +#endif + +#include +#include + +char * +strtok_r(char *s, const char *delim, char **last) +{ + char *spanp; + int c, sc; + char *tok; + + if (s == NULL && (s = *last) == NULL) + { + return NULL; + } + + /* + * Skip (span) leading delimiters (s += strspn(s, delim), sort of). + */ +cont: + c = *s++; + for (spanp = (char *)delim; (sc = *spanp++) != 0; ) + { + if (c == sc) + { + goto cont; + } + } + + if (c == 0) /* no non-delimiter characters */ + { + *last = NULL; + return NULL; + } + tok = s - 1; + + /* + * Scan token (scan for delimiters: s += strcspn(s, delim), sort of). + * Note that delim must have one NUL; we stop if we see that, too. + */ + for (;;) + { + c = *s++; + spanp = (char *)delim; + do + { + if ((sc = *spanp++) == c) + { + if (c == 0) + { + s = NULL; + } + else + { + char *w = s - 1; + *w = '\0'; + } + *last = s; + return tok; + } + } + while (sc != 0); + } + /* NOTREACHED */ +} + + +char * +strtok(char *s, const char *delim) +{ + static char *last; + + return strtok_r(s, delim, &last); +} + + +#if defined(DEBUG_STRTOK) + +/* + * Test the tokenizer. + */ +int +main() +{ + char test[80], blah[80]; + char *sep = "\\/:;=-"; + char *word, *phrase, *brkt, *brkb; + + printf("String tokenizer test:\n"); + + strcpy(test, "This;is.a:test:of=the/string\\tokenizer-function."); + + for (word = strtok(test, sep); + word; + word = strtok(NULL, sep)) + { + printf("Next word is \"%s\".\n", word); + } + + phrase = "foo"; + + strcpy(test, "This;is.a:test:of=the/string\\tokenizer-function."); + + for (word = strtok_r(test, sep, &brkt); + word; + word = strtok_r(NULL, sep, &brkt)) + { + strcpy(blah, "blah:blat:blab:blag"); + + for (phrase = strtok_r(blah, sep, &brkb); + phrase; + phrase = strtok_r(NULL, sep, &brkb)) + { + printf("So far we're at %s:%s\n", word, phrase); + } + } + + return 0; +} + +#endif /* DEBUG_STRTOK */ diff --git a/string/strxfrm.3 b/string/strxfrm.3 new file mode 100644 index 0000000..f291222 --- /dev/null +++ b/string/strxfrm.3 @@ -0,0 +1,99 @@ +.\" 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. +.\" +.\" @(#)strxfrm.3 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD: src/lib/libc/string/strxfrm.3,v 1.14 2001/10/01 16:09:00 ru Exp $ +.\" +.Dd June 4, 1993 +.Dt STRXFRM 3 +.Os +.Sh NAME +.Nm strxfrm +.Nd transform a string under locale +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In string.h +.Ft size_t +.Fn strxfrm "char *dst" "const char *src" "size_t n" +.Sh DESCRIPTION +The +.Fn strxfrm +function transforms a null-terminated string pointed to by +.Fa src +according to the current locale collation if any, +then copies the transformed string +into +.Fa dst . +Not more than +.Fa n +characters are copied into +.Fa dst , +including the terminating null character added. +If +.Fa n +is set to 0 +(it helps to determine an actual size needed +for transformation), +.Fa dst +is permitted to be a NULL pointer. +.Pp +Comparing two strings using +.Fn strcmp +after +.Fn strxfrm +is equal to comparing +two original strings with +.Fn strcoll . +.Sh RETURN VALUES +Upon successful completion, +.Fn strxfrm +returns the length of the transformed string not including +the terminating null character. +If this value is +.Fa n +or more, the contents of +.Fa dst +are indeterminate. +.Sh SEE ALSO +.Xr setlocale 3 , +.Xr strcmp 3 , +.Xr strcoll 3 +.Sh STANDARDS +The +.Fn strxfrm +function +conforms to +.St -isoC . diff --git a/string/strxfrm.c b/string/strxfrm.c new file mode 100644 index 0000000..0153076 --- /dev/null +++ b/string/strxfrm.c @@ -0,0 +1,85 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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 +#include + +/* + * Transform src, storing the result in dst, such that + * strcmp() on transformed strings returns what strcoll() + * on the original untransformed strings would return. + */ +size_t +strxfrm(dst, src, n) + register char *dst; + const char *src; + size_t n; +{ + register size_t srclen, copysize; + + /* + * Since locales are unimplemented, this is just a copy. + */ + srclen = strlen(src); + if (n != 0) { + copysize = srclen < n ? srclen : n - 1; + (void)memcpy(dst, src, copysize); + dst[copysize] = 0; + } + return (srclen); +} diff --git a/string/swab.3 b/string/swab.3 new file mode 100644 index 0000000..fffd7cd --- /dev/null +++ b/string/swab.3 @@ -0,0 +1,68 @@ +.\" Copyright (c) 1990, 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. +.\" +.\" @(#)swab.3 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD: src/lib/libc/string/swab.3,v 1.6 2001/10/01 16:09:00 ru Exp $ +.\" +.Dd June 4, 1993 +.Dt SWAB 3 +.Os +.Sh NAME +.Nm swab +.Nd swap adjacent bytes +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In string.h +.Ft void +.Fn swab "const void *src" "void *dst" "size_t len" +.Sh DESCRIPTION +The function +.Fn swab +copies +.Fa len +bytes from the location referenced by +.Fa src +to the location referenced by +.Fa dst , +swapping adjacent bytes. +.Pp +The argument +.Fa len +must be an even number. +.Sh SEE ALSO +.Xr bzero 3 , +.Xr memset 3 +.Sh HISTORY +A +.Fn swab +function appeared in +.At v7 . diff --git a/string/swab.c b/string/swab.c new file mode 100644 index 0000000..e229855 --- /dev/null +++ b/string/swab.c @@ -0,0 +1,83 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1988, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Jeffrey Mogul. + * + * 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 + +void +swab(from, to, len) + const void *from; + void *to; + size_t len; +{ + register unsigned long temp; + register int n; + register char *fp, *tp; + + n = (len >> 1) + 1; + fp = (char *)from; + tp = (char *)to; +#define STEP temp = *fp++,*tp++ = *fp++,*tp++ = temp + /* round to multiple of 8 */ + while ((--n) & 07) + STEP; + n >>= 3; + while (--n >= 0) { + STEP; STEP; STEP; STEP; + STEP; STEP; STEP; STEP; + } +} diff --git a/string/wmemchr.3 b/string/wmemchr.3 new file mode 100644 index 0000000..cb41fc2 --- /dev/null +++ b/string/wmemchr.3 @@ -0,0 +1,145 @@ +.\" $NetBSD: wmemchr.3,v 1.4 2001/01/02 11:26:23 itojun 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. +.\" +.\" from: @(#)strcpy.3 8.1 (Berkeley) 6/4/93 +.\" +.\" $FreeBSD: src/lib/libc/string/wmemchr.3,v 1.5 2001/10/03 05:19:47 bde Exp $ +.\" +.Dd December 22, 2000 +.Dt WMEMCHR 3 +.Os +.Sh NAME +.Nm wmemchr , +.Nm wmemcmp , +.Nm wmemcpy , +.Nm wmemmove , +.Nm wmemset , +.Nm wcscat , +.Nm wcschr , +.Nm wcscmp , +.Nm wcscpy , +.Nm wcscspn , +.Nm wcslcat , +.Nm wcslcpy , +.Nm wcslen , +.Nm wcsncat , +.Nm wcsncmp , +.Nm wcsncpy , +.Nm wcspbrk , +.Nm wcsrchr , +.Nm wcsspn , +.Nm wcsstr +.Nd wide character string manipulation operations +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In wchar.h +.Ft wchar_t * +.Fn wmemchr "const wchar_t *s" "wchar_t c" "size_t n" +.Ft int +.Fn wmemcmp "const wchar_t *s1" "const wchar_t *s2" "size_t n" +.Ft wchar_t * +.Fn wmemcpy "wchar_t *s1" "const wchar_t *s2" "size_t n" +.Ft wchar_t * +.Fn wmemmove "wchar_t *s1" "const wchar_t *s2" "size_t n" +.Ft wchar_t * +.Fn wmemset "wchar_t *s" "wchar_t c" "size_t n" +.Ft wchar_t * +.Fn wcscat "wchar_t *s1" "const wchar_t *s2" +.Ft wchar_t * +.Fn wcschr "const wchar_t *s" "wchar_t c" +.Ft int +.Fn wcscmp "const wchar_t *s1" "const wchar_t *s2" +.Ft wchar_t * +.Fn wcscpy "wchar_t *s1" "const wchar_t *s2" +.Ft size_t +.Fn wcscspn "const wchar_t *s1" "const wchar_t *s2" +.Ft size_t +.Fn wcslcat "wchar_t *s1" "const wchar_t *s2" "size_t n" +.Ft size_t +.Fn wcslcpy "wchar_t *s1" "const wchar_t *s2" "size_t n" +.Ft size_t +.Fn wcslen "const wchar_t *s" +.Ft wchar_t * +.Fn wcsncat "wchar_t *s1" "const wchar_t *s2" "size_t n" +.Ft int +.Fn wcsncmp "const wchar_t *s1" "const wchar_t * s2" "size_t n" +.Ft wchar_t * +.Fn wcsncpy "wchar_t *s1" "const wchar_t *s2" "size_t n" +.Ft wchar_t * +.Fn wcspbrk "const wchar_t *s1" "const wchar_t *s2" +.Ft wchar_t * +.Fn wcsrchr "const wchar_t *s" "wchar_t c" +.Ft size_t +.Fn wcsspn "const wchar_t *s1" "const wchar_t *s2" +.Ft wchar_t * +.Fn wcsstr "const wchar_t *s1" "const wchar_t *s2" +.Sh DESCRIPTION +The functions implement string manipulation operations over wide character +strings. +For a detailed description, refer to documents for the respective single-byte +counterpart, such as +.Xr memchr 3 . +.Sh SEE ALSO +.Xr memchr 3 , +.Xr memcmp 3 , +.Xr memcpy 3 , +.Xr memmove 3 , +.Xr memset 3 , +.Xr strcat 3 , +.Xr strchr 3 , +.Xr strcmp 3 , +.Xr strcpy 3 , +.Xr strcspn 3 , +.Xr strlcat 3 , +.Xr strlcpy 3 , +.Xr strlen 3 , +.Xr strncat 3 , +.Xr strncmp 3 , +.Xr strncpy 3 , +.Xr strpbrk 3 , +.Xr strrchr 3 , +.Xr strspn 3 , +.Xr strstr 3 +.Sh STANDARDS +These functions conform to +.St -isoC-99 , +with the exception of +.Fn wcslcat +and +.Fn wcslcpy , +which are extensions. diff --git a/sys.subproj/Makefile b/sys.subproj/Makefile deleted file mode 100644 index 705fdfa..0000000 --- a/sys.subproj/Makefile +++ /dev/null @@ -1,52 +0,0 @@ -# -# Generated by the Apple Project Builder. -# -# NOTE: Do NOT change this file -- Project Builder maintains it. -# -# Put all of your customizations in files called Makefile.preamble -# and Makefile.postamble (both optional), and Makefile will include them. -# - -NAME = sys - -PROJECTVERSION = 2.8 -PROJECT_TYPE = Component - -HFILES = sigcatch.h - -CFILES = errno.c getdtablesize.c gettimeofday.c sigaction.c sigcatch.c\ - sigprocmask.c sigsuspend.c sigtramp.c - -SUBPROJECTS = i386.subproj ppc.subproj - -OTHERSRCS = Makefile.preamble Makefile Makefile.postamble msync.2\ - sem_close.2 sem_open.2 sem_post.2 sem_trywait.2\ - sem_unlink.2 sem_wait.2 shm_open.2 shm_unlink.2 - - -MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles -CODE_GEN_STYLE = DYNAMIC -MAKEFILE = subproj.make -LIBS = -DEBUG_LIBS = $(LIBS) -PROF_LIBS = $(LIBS) - - - - -NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc -WINDOWS_OBJCPLUS_COMPILER = $(DEVDIR)/gcc -PDO_UNIX_OBJCPLUS_COMPILER = $(NEXTDEV_BIN)/gcc -NEXTSTEP_JAVA_COMPILER = /usr/bin/javac -WINDOWS_JAVA_COMPILER = $(JDKBINDIR)/javac.exe -PDO_UNIX_JAVA_COMPILER = $(JDKBINDIR)/javac - -include $(MAKEFILEDIR)/platform.make - --include Makefile.preamble - -include $(MAKEFILEDIR)/$(MAKEFILE) - --include Makefile.postamble - --include Makefile.dependencies diff --git a/sys.subproj/Makefile.postamble b/sys.subproj/Makefile.postamble deleted file mode 100644 index 6b33f70..0000000 --- a/sys.subproj/Makefile.postamble +++ /dev/null @@ -1,106 +0,0 @@ -############################################################################### -# Makefile.postamble -# Copyright 1997, Apple Computer, Inc. -# -# Use this makefile, which is imported after all other makefiles, to -# override attributes for a project's Makefile environment. This allows you -# to take advantage of the environment set up by the other Makefiles. -# You can also define custom rules at the end of this file. -# -############################################################################### -# -# These variables are exported by the standard makefiles and can be -# used in any customizations you make. They are *outputs* of -# the Makefiles and should be used, not set. -# -# PRODUCTS: products to install. All of these products will be placed in -# the directory $(DSTROOT)$(INSTALLDIR) -# GLOBAL_RESOURCE_DIR: The directory to which resources are copied. -# LOCAL_RESOURCE_DIR: The directory to which localized resources are copied. -# OFILE_DIR: Directory into which .o object files are generated. -# DERIVED_SRC_DIR: Directory used for all other derived files -# -# ALL_CFLAGS: flags to pass when compiling .c files -# ALL_MFLAGS: flags to pass when compiling .m files -# ALL_CCFLAGS: flags to pass when compiling .cc, .cxx, and .C files -# ALL_MMFLAGS: flags to pass when compiling .mm, .mxx, and .M files -# ALL_PRECOMPFLAGS: flags to pass when precompiling .h files -# ALL_LDFLAGS: flags to pass when linking object files -# ALL_LIBTOOL_FLAGS: flags to pass when libtooling object files -# ALL_PSWFLAGS: flags to pass when processing .psw and .pswm (pswrap) files -# ALL_RPCFLAGS: flags to pass when processing .rpc (rpcgen) files -# ALL_YFLAGS: flags to pass when processing .y (yacc) files -# ALL_LFLAGS: flags to pass when processing .l (lex) files -# -# NAME: name of application, bundle, subproject, palette, etc. -# LANGUAGES: langages in which the project is written (default "English") -# English_RESOURCES: localized resources (e.g. nib's, images) of project -# GLOBAL_RESOURCES: non-localized resources of project -# -# SRCROOT: base directory in which to place the new source files -# SRCPATH: relative path from SRCROOT to present subdirectory -# -# INSTALLDIR: Directory the product will be installed into by 'install' target -# PUBLIC_HDR_INSTALLDIR: where to install public headers. Don't forget -# to prefix this with DSTROOT when you use it. -# PRIVATE_HDR_INSTALLDIR: where to install private headers. Don't forget -# to prefix this with DSTROOT when you use it. -# -# EXECUTABLE_EXT: Executable extension for the platform (i.e. .exe on Windows) -# -############################################################################### - -# Some compiler flags can be overridden here for certain build situations. -# -# WARNING_CFLAGS: flag used to set warning level (defaults to -Wmost) -# DEBUG_SYMBOLS_CFLAGS: debug-symbol flag passed to all builds (defaults -# to -g) -# DEBUG_BUILD_CFLAGS: flags passed during debug builds (defaults to -DDEBUG) -# OPTIMIZE_BUILD_CFLAGS: flags passed during optimized builds (defaults -# to -O) -# PROFILE_BUILD_CFLAGS: flags passed during profile builds (defaults -# to -pg -DPROFILE) -# LOCAL_DIR_INCLUDE_DIRECTIVE: flag used to add current directory to -# the include path (defaults to -I.) -# DEBUG_BUILD_LDFLAGS, OPTIMIZE_BUILD_LDFLAGS, PROFILE_BUILD_LDFLAGS: flags -# passed to ld/libtool (defaults to nothing) - - -# Library and Framework projects only: -# INSTALL_NAME_DIRECTIVE: This directive ensures that executables linked -# against the framework will run against the correct version even if -# the current version of the framework changes. You may override this -# to "" as an alternative to using the DYLD_LIBRARY_PATH during your -# development cycle, but be sure to restore it before installing. - - -# Ownership and permissions of files installed by 'install' target - -#INSTALL_AS_USER = root - # User/group ownership -#INSTALL_AS_GROUP = wheel - # (probably want to set both of these) -#INSTALL_PERMISSIONS = - # If set, 'install' chmod's executable to this - - -# Options to strip. Note: -S strips debugging symbols (executables can be stripped -# down further with -x or, if they load no bundles, with no options at all). - -#STRIPFLAGS = -S - - -######################################################################### -# Put rules to extend the behavior of the standard Makefiles here. Include them in -# the dependency tree via cvariables like AFTER_INSTALL in the Makefile.preamble. -# -# You should avoid redefining things like "install" or "app", as they are -# owned by the top-level Makefile API and no context has been set up for where -# derived files should go. -# - -MAN2DIR=/usr/share/man/man2 - -install-man: - install -m 755 -d $(DSTROOT)$(MAN2DIR) - install -m 444 -c *.2 $(DSTROOT)$(MAN2DIR) diff --git a/sys.subproj/Makefile.preamble b/sys.subproj/Makefile.preamble deleted file mode 100644 index eda7efc..0000000 --- a/sys.subproj/Makefile.preamble +++ /dev/null @@ -1,139 +0,0 @@ -############################################################################### -# Makefile.preamble -# Copyright 1997, Apple Computer, Inc. -# -# Use this makefile for configuring the standard application makefiles -# associated with ProjectBuilder. It is included before the main makefile. -# In Makefile.preamble you set attributes for a project, so they are available -# to the project's makefiles. In contrast, you typically write additional rules or -# override built-in behavior in the Makefile.postamble. -# -# Each directory in a project tree (main project plus subprojects) should -# have its own Makefile.preamble and Makefile.postamble. -############################################################################### -# -# Before the main makefile is included for this project, you may set: -# -# MAKEFILEDIR: Directory in which to find $(MAKEFILE) -# MAKEFILE: Top level mechanism Makefile (e.g., app.make, bundle.make) - -# Compiler/linker flags added to the defaults: The OTHER_* variables will be -# inherited by all nested sub-projects, but the LOCAL_ versions of the same -# variables will not. Put your -I, -D, -U, and -L flags in ProjectBuilder's -# Build Attributes inspector if at all possible. To override the default flags -# that get passed to ${CC} (e.g. change -O to -O2), see Makefile.postamble. The -# variables below are *inputs* to the build process and distinct from the override -# settings done (less often) in the Makefile.postamble. -# -# OTHER_CFLAGS, LOCAL_CFLAGS: additional flags to pass to the compiler -# Note that $(OTHER_CFLAGS) and $(LOCAL_CFLAGS) are used for .h, ...c, .m, -# .cc, .cxx, .C, and .M files. There is no need to respecify the -# flags in OTHER_MFLAGS, etc. -# OTHER_MFLAGS, LOCAL_MFLAGS: additional flags for .m files -# OTHER_CCFLAGS, LOCAL_CCFLAGS: additional flags for .cc, .cxx, and ...C files -# OTHER_MMFLAGS, LOCAL_MMFLAGS: additional flags for .mm and .M files -# OTHER_PRECOMPFLAGS, LOCAL_PRECOMPFLAGS: additional flags used when -# precompiling header files -# OTHER_LDFLAGS, LOCAL_LDFLAGS: additional flags passed to ld and libtool -# OTHER_PSWFLAGS, LOCAL_PSWFLAGS: additional flags passed to pswrap -# OTHER_RPCFLAGS, LOCAL_RPCFLAGS: additional flags passed to rpcgen -# OTHER_YFLAGS, LOCAL_YFLAGS: additional flags passed to yacc -# OTHER_LFLAGS, LOCAL_LFLAGS: additional flags passed to lex - -# These variables provide hooks enabling you to add behavior at almost every -# stage of the make: -# -# BEFORE_PREBUILD: targets to build before installing headers for a subproject -# AFTER_PREBUILD: targets to build after installing headers for a subproject -# BEFORE_BUILD_RECURSION: targets to make before building subprojects -# BEFORE_BUILD: targets to make before a build, but after subprojects -# AFTER_BUILD: targets to make after a build -# -# BEFORE_INSTALL: targets to build before installing the product -# AFTER_INSTALL: targets to build after installing the product -# BEFORE_POSTINSTALL: targets to build before postinstalling every subproject -# AFTER_POSTINSTALL: targts to build after postinstalling every subproject -# -# BEFORE_INSTALLHDRS: targets to build before installing headers for a -# subproject -# AFTER_INSTALLHDRS: targets to build after installing headers for a subproject -# BEFORE_INSTALLSRC: targets to build before installing source for a subproject -# AFTER_INSTALLSRC: targets to build after installing source for a subproject -# -# BEFORE_DEPEND: targets to build before building dependencies for a -# subproject -# AFTER_DEPEND: targets to build after building dependencies for a -# subproject -# -# AUTOMATIC_DEPENDENCY_INFO: if YES, then the dependency file is -# updated every time the project is built. If NO, the dependency -# file is only built when the depend target is invoked. - -AFTER_POSTINSTALL = install-man - -# Framework-related variables: -# FRAMEWORK_DLL_INSTALLDIR: On Windows platforms, this variable indicates -# where to put the framework's DLL. This variable defaults to -# $(INSTALLDIR)/../Executables - -# Library-related variables: -# PUBLIC_HEADER_DIR: Determines where public exported header files -# should be installed. Do not include $(DSTROOT) in this value -- -# it is prefixed automatically. For library projects you should -# set this to something like /Developer/Headers/$(NAME). Do not set -# this variable for framework projects unless you do not want the -# header files included in the framework. -# PRIVATE_HEADER_DIR: Determines where private exported header files -# should be installed. Do not include $(DSTROOT) in this value -- -# it is prefixed automatically. -# LIBRARY_STYLE: This may be either STATIC or DYNAMIC, and determines -# whether the libraries produced are statically linked when they -# are used or if they are dynamically loadable. This defaults to -# DYNAMIC. -# LIBRARY_DLL_INSTALLDIR: On Windows platforms, this variable indicates -# where to put the library's DLL. This variable defaults to -# $(INSTALLDIR)/../Executables -# -# INSTALL_AS_USER: owner of the intalled products (default root) -# INSTALL_AS_GROUP: group of the installed products (default wheel) -# INSTALL_PERMISSIONS: permissions of the installed product (default o+rX) -# -# OTHER_RECURSIVE_VARIABLES: The names of variables which you want to be -# passed on the command line to recursive invocations of make. Note that -# the values in OTHER_*FLAGS are inherited by subprojects automatically -- -# you do not have to (and shouldn't) add OTHER_*FLAGS to -# OTHER_RECURSIVE_VARIABLES. - -# Additional headers to export beyond those in the PB.project: -# OTHER_PUBLIC_HEADERS -# OTHER_PROJECT_HEADERS -# OTHER_PRIVATE_HEADERS - -# Additional files for the project's product: <> -# OTHER_RESOURCES: (non-localized) resources for this project -# OTHER_OFILES: relocatables to be linked into this project -# OTHER_LIBS: more libraries to link against -# OTHER_PRODUCT_DEPENDS: other dependencies of this project -# OTHER_SOURCEFILES: other source files maintained by .pre/postamble -# OTHER_GARBAGE: additional files to be removed by `make clean' - -# Set this to YES if you don't want a final libtool call for a library/framework. -# BUILD_OFILES_LIST_ONLY - -# To include a version string, project source must exist in a directory named -# $(NAME).%d[.%d][.%d] and the following line must be uncommented. -# OTHER_GENERATED_OFILES = $(VERS_OFILE) - -# This definition will suppress stripping of debug symbols when an executable -# is installed. By default it is YES. -# STRIP_ON_INSTALL = NO - -# Uncomment to suppress generation of a KeyValueCoding index when installing -# frameworks (This index is used by WOB and IB to determine keys available -# for an object). Set to YES by default. -# PREINDEX_FRAMEWORK = NO - -# Change this definition to install projects somewhere other than the -# standard locations. NEXT_ROOT defaults to "C:/Apple" on Windows systems -# and "" on other systems. -DSTROOT = $(HOME) diff --git a/sys.subproj/PB.project b/sys.subproj/PB.project deleted file mode 100644 index d57c398..0000000 --- a/sys.subproj/PB.project +++ /dev/null @@ -1,45 +0,0 @@ -{ - DYNAMIC_CODE_GEN = YES; - FILESTABLE = { - H_FILES = (sigcatch.h); - OTHER_LINKED = ( - errno.c, - getdtablesize.c, - gettimeofday.c, - sigaction.c, - sigcatch.c, - sigprocmask.c, - sigsuspend.c, - sigtramp.c - ); - OTHER_SOURCES = ( - Makefile.preamble, - Makefile, - Makefile.postamble, - msync.2, - sem_close.2, - sem_open.2, - sem_post.2, - sem_trywait.2, - sem_unlink.2, - sem_wait.2, - shm_open.2, - shm_unlink.2 - ); - SUBPROJECTS = (i386.subproj, ppc.subproj); - }; - LANGUAGE = English; - MAKEFILEDIR = "$(MAKEFILEPATH)/pb_makefiles"; - NEXTSTEP_BUILDTOOL = /bin/gnumake; - NEXTSTEP_JAVA_COMPILER = /usr/bin/javac; - NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc; - PDO_UNIX_BUILDTOOL = $NEXT_ROOT/Developer/bin/make; - PDO_UNIX_JAVA_COMPILER = "$(JDKBINDIR)/javac"; - PDO_UNIX_OBJCPLUS_COMPILER = "$(NEXTDEV_BIN)/gcc"; - PROJECTNAME = sys; - PROJECTTYPE = Component; - PROJECTVERSION = 2.8; - WINDOWS_BUILDTOOL = $NEXT_ROOT/Developer/Executables/make; - WINDOWS_JAVA_COMPILER = "$(JDKBINDIR)/javac.exe"; - WINDOWS_OBJCPLUS_COMPILER = "$(DEVDIR)/gcc"; -} diff --git a/sys.subproj/errno.c b/sys.subproj/errno.c deleted file mode 100644 index 9539d89..0000000 --- a/sys.subproj/errno.c +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * Portions Copyright (c) 1999 Apple Computer, Inc. All Rights - * Reserved. This 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.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. - * - * 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -/* - * The world-renowned global variable - */ -#include - -#undef errno -extern int errno; -int *__error(void) { - pthread_t self = pthread_self(); - /* If we're not a detached pthread, just return the global errno */ - if ((self == (pthread_t)0) || (self->sig != _PTHREAD_SIG) || (self->detached == _PTHREAD_CREATE_PARENT)) { - return &errno; - } - return &self->err_no; -} - -int cthread_errno(void) { - return *__error(); -} - diff --git a/sys.subproj/getdtablesize.c b/sys.subproj/getdtablesize.c deleted file mode 100644 index c25bf90..0000000 --- a/sys.subproj/getdtablesize.c +++ /dev/null @@ -1,5 +0,0 @@ -#include - -int getdtablesize() { - return sysconf(_SC_OPEN_MAX); -} diff --git a/sys.subproj/gettimeofday.c b/sys.subproj/gettimeofday.c deleted file mode 100644 index 8aa14ac..0000000 --- a/sys.subproj/gettimeofday.c +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - * - * File: libc/sys/gettimeofday.c - */ - -#include -#include -#include -#include -#include -#include - -int gettimeofday (struct timeval *tp, struct timezone *tzp) -{ - static int validtz = 0; - static struct timezone cached_tz = {0}; - struct timeval localtv; - - if (tzp && (tp == NULL) && (validtz == 0)) { - tp = &localtv; - } - - if (syscall (SYS_gettimeofday, tp, tzp) < 0) { - return (-1); - } - if (tzp) { - if (validtz == 0) { - struct tm *localtm = localtime ((time_t *)&tp->tv_sec); - cached_tz.tz_dsttime = localtm->tm_isdst; - cached_tz.tz_minuteswest = - (-localtm->tm_gmtoff / SECSPERMIN) + - (localtm->tm_isdst * MINSPERHOUR); - validtz = 1; - } - tzp->tz_dsttime = cached_tz.tz_dsttime; - tzp->tz_minuteswest = cached_tz.tz_minuteswest; - } - return (0); -} diff --git a/sys.subproj/i386.subproj/ATPgetreq.s b/sys.subproj/i386.subproj/ATPgetreq.s deleted file mode 100644 index 3e47b64..0000000 --- a/sys.subproj/i386.subproj/ATPgetreq.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(ATPgetreq, 3) - ret diff --git a/sys.subproj/i386.subproj/ATPgetrsp.s b/sys.subproj/i386.subproj/ATPgetrsp.s deleted file mode 100644 index 4f995b5..0000000 --- a/sys.subproj/i386.subproj/ATPgetrsp.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(ATPgetrsp, 3) - ret diff --git a/sys.subproj/i386.subproj/ATPsndreq.s b/sys.subproj/i386.subproj/ATPsndreq.s deleted file mode 100644 index 7f35022..0000000 --- a/sys.subproj/i386.subproj/ATPsndreq.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(ATPsndreq, 3) - ret diff --git a/sys.subproj/i386.subproj/ATPsndrsp.s b/sys.subproj/i386.subproj/ATPsndrsp.s deleted file mode 100644 index 1207b67..0000000 --- a/sys.subproj/i386.subproj/ATPsndrsp.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(ATPsndrsp, 3) - ret diff --git a/sys.subproj/i386.subproj/ATgetmsg.s b/sys.subproj/i386.subproj/ATgetmsg.s deleted file mode 100644 index 9bc673a..0000000 --- a/sys.subproj/i386.subproj/ATgetmsg.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(ATgetmsg, 3) - ret diff --git a/sys.subproj/i386.subproj/ATputmsg.s b/sys.subproj/i386.subproj/ATputmsg.s deleted file mode 100644 index 648d0a7..0000000 --- a/sys.subproj/i386.subproj/ATputmsg.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(ATputmsg, 3) - ret diff --git a/sys.subproj/i386.subproj/ATsocket.s b/sys.subproj/i386.subproj/ATsocket.s deleted file mode 100644 index 682c64c..0000000 --- a/sys.subproj/i386.subproj/ATsocket.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(ATsocket, 3) - ret diff --git a/sys.subproj/i386.subproj/Makefile b/sys.subproj/i386.subproj/Makefile deleted file mode 100644 index fd962c5..0000000 --- a/sys.subproj/i386.subproj/Makefile +++ /dev/null @@ -1,127 +0,0 @@ -# -# Generated by the Apple Project Builder. -# -# NOTE: Do NOT change this file -- Project Builder maintains it. -# -# Put all of your customizations in files called Makefile.preamble -# and Makefile.postamble (both optional), and Makefile will include them. -# - -NAME = i386 - -PROJECTVERSION = 2.8 -PROJECT_TYPE = Component - -HFILES = SYS.h - -OTHERLINKED = ATsocket.s ATgetmsg.s ATputmsg.s ATPsndreq.s ATPsndrsp.s\ - ATPgetreq.s ATPgetrsp.s accept.s access.s acct.s\ - add_profil.s adjtime.s bind.s cerror.s chdir.s\ - checkuseraccess.s chflags.s chmod.s chown.s chroot.s\ - close.s connect.s dup.s dup2.s exchangedata.s execve.s\ - _exit.s fchdir.s fchflags.s fchmod.s fchown.s fcntl.s\ - flock.s fork.s fpathconf.s fstat.s fstatfs.s fstatv.s\ - fsync.s ftruncate.s getattrlist.s getdirentries.s\ - getdirentriesattr.s getegid.s geteuid.s getfh.s\ - getfsstat.s getgid.s getgroups.s getitimer.s _getlogin.s\ - getpeername.s getpgrp.s getpid.s getppid.s getpriority.s\ - getrlimit.s getrusage.s getsockname.s getsockopt.s\ - getuid.s ioctl.s kill.s ktrace.s lfs_bmapv.s\ - lfs_markv.s lfs_segclean.s lfs_segwait.s link.s listen.s\ - lseek.s lstat.s lstatv.s madvise.s mincore.s minherit.s\ - mkcomplex.s mkdir.s mkfifo.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 nfssvc.s open.s pathconf.s pipe.s profil.s\ - ptrace.s quota.s quotactl.s read.s readlink.s readv.s\ - reboot.s recvfrom.s recvmsg.s rename.s revoke.s rmdir.s\ - searchfs.s select.s semconfig.s semctl.s semget.s\ - semop.s semsys.s sendmsg.s sendto.s setattrlist.s\ - setegid.s seteuid.s setgid.s setgroups.s setitimer.s\ - setjmp.s _setjmp.s _setlogin.s setpgid.s setpriority.s\ - setprivexec.s setquota.s setrlimit.s setsid.s\ - setsockopt.s settimeofday.s setuid.s shmat.s shmctl.s\ - shmdt.s shmget.s shmsys.s shm_open.s shm_unlink.s\ - shutdown.s sigaltstack.s sigpending.s sigreturn.s\ - socket.s socketpair.s stat.s statfs.s statv.s swapon.s\ - symlink.s sync.s syscall.s _sysctl.s table.s truncate.s\ - umask.s undelete.s unlink.s unmount.s utimes.s vfork.s\ - wait4.s write.s writev.s sem_close.s sem_destroy.s\ - sem_getvalue.s sem_init.s sem_open.s sem_post.s\ - sem_trywait.s sem_unlink.s sem_wait.s load_shared_file.s\ - reset_shared_file.s - -OTHERSRCS = Makefile.preamble Makefile Makefile.postamble - -OTHERLINKEDOFILES = ATsocket.o ATgetmsg.o ATputmsg.o ATPsndreq.o\ - ATPsndrsp.o ATPgetreq.o ATPgetrsp.o accept.o\ - access.o acct.o add_profil.o adjtime.o bind.o\ - cerror.o chdir.o checkuseraccess.o chflags.o\ - chmod.o chown.o chroot.o close.o connect.o dup.o\ - dup2.o exchangedata.o execve.o _exit.o fchdir.o\ - fchflags.o fchmod.o fchown.o fcntl.o flock.o\ - fork.o fpathconf.o fstat.o fstatfs.o fstatv.o\ - fsync.o ftruncate.o getattrlist.o getdirentries.o\ - getdirentriesattr.o getegid.o geteuid.o getfh.o\ - getfsstat.o getgid.o getgroups.o getitimer.o\ - _getlogin.o getpeername.o getpgrp.o getpid.o\ - getppid.o getpriority.o getrlimit.o getrusage.o\ - getsockname.o getsockopt.o getuid.o ioctl.o kill.o\ - ktrace.o lfs_bmapv.o lfs_markv.o lfs_segclean.o\ - lfs_segwait.o link.o listen.o lseek.o lstat.o\ - lstatv.o madvise.o mincore.o minherit.o\ - mkcomplex.o mkdir.o mkfifo.o mknod.o mlock.o\ - mlockall.o mmap.o mount.o mprotect.o msgctl.o\ - msgget.o msgrcv.o msgsnd.o msgsys.o msync.o\ - munlock.o munlockall.o munmap.o nfssvc.o open.o\ - pathconf.o pipe.o profil.o ptrace.o quota.o\ - quotactl.o read.o readlink.o readv.o reboot.o\ - recvfrom.o recvmsg.o rename.o revoke.o rmdir.o\ - searchfs.o select.o semconfig.o semctl.o semget.o\ - semop.o semsys.o sendmsg.o sendto.o setattrlist.o\ - setegid.o seteuid.o setgid.o setgroups.o\ - setitimer.o setjmp.o _setjmp.o _setlogin.o\ - setpgid.o setpriority.o setprivexec.o setquota.o\ - setrlimit.o setsid.o setsockopt.o settimeofday.o\ - setuid.o shmat.o shmctl.o shmdt.o shmget.o\ - shmsys.o shm_open.o shm_unlink.o shutdown.o\ - sigaltstack.o sigpending.o sigreturn.o socket.o\ - socketpair.o stat.o statfs.o statv.o swapon.o\ - symlink.o sync.o syscall.o _sysctl.o table.o\ - truncate.o umask.o undelete.o unlink.o unmount.o\ - utimes.o vfork.o wait4.o write.o writev.o\ - sem_close.o sem_destroy.o sem_getvalue.o sem_init.o\ - sem_open.o sem_post.o sem_trywait.o sem_unlink.o\ - sem_wait.o load_shared_file.o reset_shared_file.o - -MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles -CODE_GEN_STYLE = DYNAMIC -MAKEFILE = subproj.make -NEXTSTEP_INSTALLDIR = /Local/Developer/System -LIBS = -DEBUG_LIBS = $(LIBS) -PROF_LIBS = $(LIBS) - - - - -NEXTSTEP_BUILD_OUTPUT_DIR = /Local/Public/SandBox/$(USER)/BUILD/$(NAME) - -NEXTSTEP_PUBLIC_HEADERS_DIR = /usr/include - -NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc -WINDOWS_OBJCPLUS_COMPILER = $(DEVDIR)/gcc -PDO_UNIX_OBJCPLUS_COMPILER = $(NEXTDEV_BIN)/gcc -NEXTSTEP_JAVA_COMPILER = /usr/bin/javac -WINDOWS_JAVA_COMPILER = $(JDKBINDIR)/javac.exe -PDO_UNIX_JAVA_COMPILER = $(JDKBINDIR)/javac - -include $(MAKEFILEDIR)/platform.make - --include Makefile.preamble - -include $(MAKEFILEDIR)/$(MAKEFILE) - --include Makefile.postamble - --include Makefile.dependencies diff --git a/sys.subproj/i386.subproj/Makefile.postamble b/sys.subproj/i386.subproj/Makefile.postamble deleted file mode 100644 index 411cde6..0000000 --- a/sys.subproj/i386.subproj/Makefile.postamble +++ /dev/null @@ -1,100 +0,0 @@ -############################################################################### -# Makefile.postamble -# Copyright 1997, Apple Computer, Inc. -# -# Use this makefile, which is imported after all other makefiles, to -# override attributes for a project's Makefile environment. This allows you -# to take advantage of the environment set up by the other Makefiles. -# You can also define custom rules at the end of this file. -# -############################################################################### -# -# These variables are exported by the standard makefiles and can be -# used in any customizations you make. They are *outputs* of -# the Makefiles and should be used, not set. -# -# PRODUCTS: products to install. All of these products will be placed in -# the directory $(DSTROOT)$(INSTALLDIR) -# GLOBAL_RESOURCE_DIR: The directory to which resources are copied. -# LOCAL_RESOURCE_DIR: The directory to which localized resources are copied. -# OFILE_DIR: Directory into which .o object files are generated. -# DERIVED_SRC_DIR: Directory used for all other derived files -# -# ALL_CFLAGS: flags to pass when compiling .c files -# ALL_MFLAGS: flags to pass when compiling .m files -# ALL_CCFLAGS: flags to pass when compiling .cc, .cxx, and .C files -# ALL_MMFLAGS: flags to pass when compiling .mm, .mxx, and .M files -# ALL_PRECOMPFLAGS: flags to pass when precompiling .h files -# ALL_LDFLAGS: flags to pass when linking object files -# ALL_LIBTOOL_FLAGS: flags to pass when libtooling object files -# ALL_PSWFLAGS: flags to pass when processing .psw and .pswm (pswrap) files -# ALL_RPCFLAGS: flags to pass when processing .rpc (rpcgen) files -# ALL_YFLAGS: flags to pass when processing .y (yacc) files -# ALL_LFLAGS: flags to pass when processing .l (lex) files -# -# NAME: name of application, bundle, subproject, palette, etc. -# LANGUAGES: langages in which the project is written (default "English") -# English_RESOURCES: localized resources (e.g. nib's, images) of project -# GLOBAL_RESOURCES: non-localized resources of project -# -# SRCROOT: base directory in which to place the new source files -# SRCPATH: relative path from SRCROOT to present subdirectory -# -# INSTALLDIR: Directory the product will be installed into by 'install' target -# PUBLIC_HDR_INSTALLDIR: where to install public headers. Don't forget -# to prefix this with DSTROOT when you use it. -# PRIVATE_HDR_INSTALLDIR: where to install private headers. Don't forget -# to prefix this with DSTROOT when you use it. -# -# EXECUTABLE_EXT: Executable extension for the platform (i.e. .exe on Windows) -# -############################################################################### - -# Some compiler flags can be overridden here for certain build situations. -# -# WARNING_CFLAGS: flag used to set warning level (defaults to -Wmost) -# DEBUG_SYMBOLS_CFLAGS: debug-symbol flag passed to all builds (defaults -# to -g) -# DEBUG_BUILD_CFLAGS: flags passed during debug builds (defaults to -DDEBUG) -# OPTIMIZE_BUILD_CFLAGS: flags passed during optimized builds (defaults -# to -O) -# PROFILE_BUILD_CFLAGS: flags passed during profile builds (defaults -# to -pg -DPROFILE) -# LOCAL_DIR_INCLUDE_DIRECTIVE: flag used to add current directory to -# the include path (defaults to -I.) -# DEBUG_BUILD_LDFLAGS, OPTIMIZE_BUILD_LDFLAGS, PROFILE_BUILD_LDFLAGS: flags -# passed to ld/libtool (defaults to nothing) - - -# Library and Framework projects only: -# INSTALL_NAME_DIRECTIVE: This directive ensures that executables linked -# against the framework will run against the correct version even if -# the current version of the framework changes. You may override this -# to "" as an alternative to using the DYLD_LIBRARY_PATH during your -# development cycle, but be sure to restore it before installing. - - -# Ownership and permissions of files installed by 'install' target - -#INSTALL_AS_USER = root - # User/group ownership -#INSTALL_AS_GROUP = wheel - # (probably want to set both of these) -#INSTALL_PERMISSIONS = - # If set, 'install' chmod's executable to this - - -# Options to strip. Note: -S strips debugging symbols (executables can be stripped -# down further with -x or, if they load no bundles, with no options at all). - -#STRIPFLAGS = -S - - -######################################################################### -# Put rules to extend the behavior of the standard Makefiles here. Include them in -# the dependency tree via cvariables like AFTER_INSTALL in the Makefile.preamble. -# -# You should avoid redefining things like "install" or "app", as they are -# owned by the top-level Makefile API and no context has been set up for where -# derived files should go. -# diff --git a/sys.subproj/i386.subproj/Makefile.preamble b/sys.subproj/i386.subproj/Makefile.preamble deleted file mode 100644 index 6544e5f..0000000 --- a/sys.subproj/i386.subproj/Makefile.preamble +++ /dev/null @@ -1,137 +0,0 @@ -############################################################################### -# Makefile.preamble -# Copyright 1997, Apple Computer, Inc. -# -# Use this makefile for configuring the standard application makefiles -# associated with ProjectBuilder. It is included before the main makefile. -# In Makefile.preamble you set attributes for a project, so they are available -# to the project's makefiles. In contrast, you typically write additional rules or -# override built-in behavior in the Makefile.postamble. -# -# Each directory in a project tree (main project plus subprojects) should -# have its own Makefile.preamble and Makefile.postamble. -############################################################################### -# -# Before the main makefile is included for this project, you may set: -# -# MAKEFILEDIR: Directory in which to find $(MAKEFILE) -# MAKEFILE: Top level mechanism Makefile (e.g., app.make, bundle.make) - -# Compiler/linker flags added to the defaults: The OTHER_* variables will be -# inherited by all nested sub-projects, but the LOCAL_ versions of the same -# variables will not. Put your -I, -D, -U, and -L flags in ProjectBuilder's -# Build Attributes inspector if at all possible. To override the default flags -# that get passed to ${CC} (e.g. change -O to -O2), see Makefile.postamble. The -# variables below are *inputs* to the build process and distinct from the override -# settings done (less often) in the Makefile.postamble. -# -# OTHER_CFLAGS, LOCAL_CFLAGS: additional flags to pass to the compiler -# Note that $(OTHER_CFLAGS) and $(LOCAL_CFLAGS) are used for .h, ...c, .m, -# .cc, .cxx, .C, and .M files. There is no need to respecify the -# flags in OTHER_MFLAGS, etc. -# OTHER_MFLAGS, LOCAL_MFLAGS: additional flags for .m files -# OTHER_CCFLAGS, LOCAL_CCFLAGS: additional flags for .cc, .cxx, and ...C files -# OTHER_MMFLAGS, LOCAL_MMFLAGS: additional flags for .mm and .M files -# OTHER_PRECOMPFLAGS, LOCAL_PRECOMPFLAGS: additional flags used when -# precompiling header files -# OTHER_LDFLAGS, LOCAL_LDFLAGS: additional flags passed to ld and libtool -# OTHER_PSWFLAGS, LOCAL_PSWFLAGS: additional flags passed to pswrap -# OTHER_RPCFLAGS, LOCAL_RPCFLAGS: additional flags passed to rpcgen -# OTHER_YFLAGS, LOCAL_YFLAGS: additional flags passed to yacc -# OTHER_LFLAGS, LOCAL_LFLAGS: additional flags passed to lex - -# These variables provide hooks enabling you to add behavior at almost every -# stage of the make: -# -# BEFORE_PREBUILD: targets to build before installing headers for a subproject -# AFTER_PREBUILD: targets to build after installing headers for a subproject -# BEFORE_BUILD_RECURSION: targets to make before building subprojects -# BEFORE_BUILD: targets to make before a build, but after subprojects -# AFTER_BUILD: targets to make after a build -# -# BEFORE_INSTALL: targets to build before installing the product -# AFTER_INSTALL: targets to build after installing the product -# BEFORE_POSTINSTALL: targets to build before postinstalling every subproject -# AFTER_POSTINSTALL: targts to build after postinstalling every subproject -# -# BEFORE_INSTALLHDRS: targets to build before installing headers for a -# subproject -# AFTER_INSTALLHDRS: targets to build after installing headers for a subproject -# BEFORE_INSTALLSRC: targets to build before installing source for a subproject -# AFTER_INSTALLSRC: targets to build after installing source for a subproject -# -# BEFORE_DEPEND: targets to build before building dependencies for a -# subproject -# AFTER_DEPEND: targets to build after building dependencies for a -# subproject -# -# AUTOMATIC_DEPENDENCY_INFO: if YES, then the dependency file is -# updated every time the project is built. If NO, the dependency -# file is only built when the depend target is invoked. - -# Framework-related variables: -# FRAMEWORK_DLL_INSTALLDIR: On Windows platforms, this variable indicates -# where to put the framework's DLL. This variable defaults to -# $(INSTALLDIR)/../Executables - -# Library-related variables: -# PUBLIC_HEADER_DIR: Determines where public exported header files -# should be installed. Do not include $(DSTROOT) in this value -- -# it is prefixed automatically. For library projects you should -# set this to something like /Developer/Headers/$(NAME). Do not set -# this variable for framework projects unless you do not want the -# header files included in the framework. -# PRIVATE_HEADER_DIR: Determines where private exported header files -# should be installed. Do not include $(DSTROOT) in this value -- -# it is prefixed automatically. -# LIBRARY_STYLE: This may be either STATIC or DYNAMIC, and determines -# whether the libraries produced are statically linked when they -# are used or if they are dynamically loadable. This defaults to -# DYNAMIC. -# LIBRARY_DLL_INSTALLDIR: On Windows platforms, this variable indicates -# where to put the library's DLL. This variable defaults to -# $(INSTALLDIR)/../Executables -# -# INSTALL_AS_USER: owner of the intalled products (default root) -# INSTALL_AS_GROUP: group of the installed products (default wheel) -# INSTALL_PERMISSIONS: permissions of the installed product (default o+rX) -# -# OTHER_RECURSIVE_VARIABLES: The names of variables which you want to be -# passed on the command line to recursive invocations of make. Note that -# the values in OTHER_*FLAGS are inherited by subprojects automatically -- -# you do not have to (and shouldn't) add OTHER_*FLAGS to -# OTHER_RECURSIVE_VARIABLES. - -# Additional headers to export beyond those in the PB.project: -# OTHER_PUBLIC_HEADERS -# OTHER_PROJECT_HEADERS -# OTHER_PRIVATE_HEADERS - -# Additional files for the project's product: <> -# OTHER_RESOURCES: (non-localized) resources for this project -# OTHER_OFILES: relocatables to be linked into this project -# OTHER_LIBS: more libraries to link against -# OTHER_PRODUCT_DEPENDS: other dependencies of this project -# OTHER_SOURCEFILES: other source files maintained by .pre/postamble -# OTHER_GARBAGE: additional files to be removed by `make clean' - -# Set this to YES if you don't want a final libtool call for a library/framework. -# BUILD_OFILES_LIST_ONLY - -# To include a version string, project source must exist in a directory named -# $(NAME).%d[.%d][.%d] and the following line must be uncommented. -# OTHER_GENERATED_OFILES = $(VERS_OFILE) - -# This definition will suppress stripping of debug symbols when an executable -# is installed. By default it is YES. -# STRIP_ON_INSTALL = NO - -# Uncomment to suppress generation of a KeyValueCoding index when installing -# frameworks (This index is used by WOB and IB to determine keys available -# for an object). Set to YES by default. -# PREINDEX_FRAMEWORK = NO - -# Change this definition to install projects somewhere other than the -# standard locations. NEXT_ROOT defaults to "C:/Apple" on Windows systems -# and "" on other systems. -INCLUDED_ARCHS = i386 diff --git a/sys.subproj/i386.subproj/PB.project b/sys.subproj/i386.subproj/PB.project deleted file mode 100644 index 2e0da04..0000000 --- a/sys.subproj/i386.subproj/PB.project +++ /dev/null @@ -1,211 +0,0 @@ -{ - DYNAMIC_CODE_GEN = YES; - FILESTABLE = { - H_FILES = (SYS.h); - OTHER_LINKED = ( - ATsocket.s, - ATgetmsg.s, - ATputmsg.s, - ATPsndreq.s, - ATPsndrsp.s, - ATPgetreq.s, - ATPgetrsp.s, - accept.s, - access.s, - acct.s, - add_profil.s, - adjtime.s, - bind.s, - cerror.s, - chdir.s, - checkuseraccess.s, - chflags.s, - chmod.s, - chown.s, - chroot.s, - close.s, - connect.s, - dup.s, - dup2.s, - exchangedata.s, - execve.s, - _exit.s, - fchdir.s, - fchflags.s, - fchmod.s, - fchown.s, - fcntl.s, - flock.s, - fork.s, - fpathconf.s, - fstat.s, - fstatfs.s, - fstatv.s, - fsync.s, - ftruncate.s, - getattrlist.s, - getdirentries.s, - getdirentriesattr.s, - getegid.s, - geteuid.s, - getfh.s, - getfsstat.s, - getgid.s, - getgroups.s, - getitimer.s, - _getlogin.s, - getpeername.s, - getpgrp.s, - getpid.s, - getppid.s, - getpriority.s, - getrlimit.s, - getrusage.s, - getsockname.s, - getsockopt.s, - getuid.s, - ioctl.s, - kill.s, - ktrace.s, - lfs_bmapv.s, - lfs_markv.s, - lfs_segclean.s, - lfs_segwait.s, - link.s, - listen.s, - lseek.s, - lstat.s, - lstatv.s, - madvise.s, - mincore.s, - minherit.s, - mkcomplex.s, - mkdir.s, - mkfifo.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, - nfssvc.s, - open.s, - pathconf.s, - pipe.s, - profil.s, - ptrace.s, - quota.s, - quotactl.s, - read.s, - readlink.s, - readv.s, - reboot.s, - recvfrom.s, - recvmsg.s, - rename.s, - revoke.s, - rmdir.s, - searchfs.s, - select.s, - semconfig.s, - semctl.s, - semget.s, - semop.s, - semsys.s, - sendmsg.s, - sendto.s, - setattrlist.s, - setegid.s, - seteuid.s, - setgid.s, - setgroups.s, - setitimer.s, - setjmp.s, - _setjmp.s, - _setlogin.s, - setpgid.s, - setpriority.s, - setprivexec.s, - setquota.s, - setrlimit.s, - setsid.s, - setsockopt.s, - settimeofday.s, - setuid.s, - shmat.s, - shmctl.s, - shmdt.s, - shmget.s, - shmsys.s, - shm_open.s, - shm_unlink.s, - shutdown.s, - sigaltstack.s, - sigpending.s, - sigreturn.s, - socket.s, - socketpair.s, - stat.s, - statfs.s, - statv.s, - swapon.s, - symlink.s, - sync.s, - syscall.s, - _sysctl.s, - table.s, - truncate.s, - umask.s, - undelete.s, - unlink.s, - unmount.s, - utimes.s, - vfork.s, - wait4.s, - write.s, - writev.s, - sem_close.s, - sem_destroy.s, - sem_getvalue.s, - sem_init.s, - sem_open.s, - sem_post.s, - sem_trywait.s, - sem_unlink.s, - sem_wait.s, - load_shared_file.s, - reset_shared_file.s - ); - OTHER_SOURCES = (Makefile.preamble, Makefile, Makefile.postamble); - PRECOMPILED_HEADERS = (); - PROJECT_HEADERS = (); - PUBLIC_HEADERS = (); - SUBPROJECTS = (); - }; - LANGUAGE = English; - MAKEFILEDIR = "$(MAKEFILEPATH)/pb_makefiles"; - NEXTSTEP_BUILDDIR = "/Local/Public/SandBox/$(USER)/BUILD/$(NAME)"; - NEXTSTEP_BUILDTOOL = /bin/gnumake; - NEXTSTEP_INSTALLDIR = /Local/Developer/System; - NEXTSTEP_JAVA_COMPILER = /usr/bin/javac; - NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc; - NEXTSTEP_PUBLICHEADERSDIR = /usr/include; - PDO_UNIX_BUILDTOOL = $NEXT_ROOT/Developer/bin/make; - PDO_UNIX_JAVA_COMPILER = "$(JDKBINDIR)/javac"; - PDO_UNIX_OBJCPLUS_COMPILER = "$(NEXTDEV_BIN)/gcc"; - PROJECTNAME = i386; - PROJECTTYPE = Component; - PROJECTVERSION = 2.8; - WINDOWS_BUILDTOOL = $NEXT_ROOT/Developer/Executables/make; - WINDOWS_JAVA_COMPILER = "$(JDKBINDIR)/javac.exe"; - WINDOWS_OBJCPLUS_COMPILER = "$(DEVDIR)/gcc"; -} diff --git a/sys.subproj/i386.subproj/SYS.h b/sys.subproj/i386.subproj/SYS.h deleted file mode 100644 index c35bf0c..0000000 --- a/sys.subproj/i386.subproj/SYS.h +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - * - * File: SYS.h - * - * Definition of the user side of the UNIX system call interface - * for i386. - * - * HISTORY - * 12-3-92 Bruce Martin (Bruce_Martin@next.com) - * Created. - */ - -#define KERNEL_PRIVATE 1 -/* - * Headers - */ -#include -#include -#include - - -#define UNIX_SYSCALL_TRAP lcall $0x2b, $0 -#define MACHDEP_SYSCALL_TRAP lcall $0x7, $0 - - -#define UNIX_SYSCALL(name, nargs) \ - .globl cerror ;\ -LEAF(_##name, 0) ;\ - movl $SYS_##name, %eax ;\ - UNIX_SYSCALL_TRAP ;\ - jnb 2f ;\ - BRANCH_EXTERN(cerror) ;\ -2: - -#define UNIX_SYSCALL_NONAME(name, nargs) \ - .globl cerror ;\ - movl $SYS_##name, %eax ;\ - UNIX_SYSCALL_TRAP ;\ - jnb 2f ;\ - BRANCH_EXTERN(cerror) ;\ -2: - -#define PSEUDO(pseudo, name, nargs) \ -LEAF(_##pseudo, 0) ;\ - UNIX_SYSCALL_NONAME(name, nargs) - -#if !defined(SYS_getdirentriesattr) -#define SYS_getdirentriesattr 222 -#endif - -#if !defined(SYS_semsys) -#define SYS_semsys 251 -#define SYS_msgsys 252 -#define SYS_shmsys 253 -#define SYS_semctl 254 -#define SYS_semget 255 -#define SYS_semop 256 -#define SYS_semconfig 257 -#define SYS_msgctl 258 -#define SYS_msgget 259 -#define SYS_msgsnd 260 -#define SYS_msgrcv 261 -#define SYS_shmat 262 -#define SYS_shmctl 263 -#define SYS_shmdt 264 -#define SYS_shmget 265 -#endif - diff --git a/sys.subproj/i386.subproj/_exit.s b/sys.subproj/i386.subproj/_exit.s deleted file mode 100644 index f8c2d1e..0000000 --- a/sys.subproj/i386.subproj/_exit.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -PSEUDO(_exit, exit, 1) - ret diff --git a/sys.subproj/i386.subproj/_getlogin.s b/sys.subproj/i386.subproj/_getlogin.s deleted file mode 100644 index 1d2a47a..0000000 --- a/sys.subproj/i386.subproj/_getlogin.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -PSEUDO(_getlogin, getlogin, 0) - ret diff --git a/sys.subproj/i386.subproj/_setjmp.s b/sys.subproj/i386.subproj/_setjmp.s deleted file mode 100644 index bbec3f8..0000000 --- a/sys.subproj/i386.subproj/_setjmp.s +++ /dev/null @@ -1,135 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - * - * HISTORY - * 20-Apr-92 Bruce Martin (bmartin@next.com) - * Created from M68K sources. - */ - -/* - * C library -- _setjmp, _longjmp - * - * _longjmp(a,v) - * will generate a "return(v)" from - * the last call to - * _setjmp(a) - * by restoring registers from the stack, - * The previous signal state is NOT restored. - * - */ - -#include - -#define JB_ONSTACK 0 -#define JB_MASK 4 -#define JB_EAX 8 -#define JB_EBX 12 -#define JB_ECX 16 -#define JB_EDX 20 -#define JB_EDI 24 -#define JB_ESI 28 -#define JB_EBP 32 -#define JB_ESP 36 -#define JB_SS 40 -#define JB_EFLAGS 44 -#define JB_EIP 48 -#define JB_CS 52 -#define JB_DS 56 -#define JB_ES 60 -#define JB_FS 64 -#define JB_GS 68 - - -LEAF(__setjmp, 0) - movl 4(%esp), %ecx // jmp_buf (struct sigcontext *) - - // now build sigcontext - movl %ebx, JB_EBX(%ecx) - movl %edi, JB_EDI(%ecx) - movl %esi, JB_ESI(%ecx) - movl %ebp, JB_EBP(%ecx) - - // EIP is set to the frame return address value - movl (%esp), %eax - movl %eax, JB_EIP(%ecx) - // ESP is set to the frame return address plus 4 - movl %esp, %eax - addl $4, %eax - movl %eax, JB_ESP(%ecx) - -#if SAVE_SEG_REGS - // segment registers - mov %ss, JB_SS(%ecx) - mov %cs, JB_CS(%ecx) - mov %ds, JB_DS(%ecx) - mov %es, JB_ES(%ecx) - mov %fs, JB_FS(%ecx) - mov %gs, JB_GS(%ecx) -#endif - - // save eflags - you can't use movl - pushf - popl %eax - movl %eax, JB_EFLAGS(%ecx) - - // return 0 - xorl %eax, %eax - ret - - -LEAF(__longjmp, 0) - subl $2,%esp - fnstcw (%esp) // save FP control word - fninit // reset FP coprocessor - fldcw (%esp) // restore FP control word - addl $2,%esp - - movl 4(%esp), %ecx // jmp_buf (struct sigcontext *) - movl 8(%esp), %eax // return value - testl %eax, %eax - jnz 1f - incl %eax - - // general registers -1: movl JB_EBX(%ecx), %ebx - movl JB_ESI(%ecx), %esi - movl JB_EDI(%ecx), %edi - movl JB_EBP(%ecx), %ebp - movl JB_ESP(%ecx), %esp - -#if SAVE_SEG_REGS - // segment registers - mov JB_SS(%ecx), %ss - mov JB_CS(%ecx), %cs - mov JB_DS(%ecx), %ds - mov JB_ES(%ecx), %es - mov JB_FS(%ecx), %fs - mov JB_GS(%ecx), %gs -#endif - - // eflags - pushl JB_EFLAGS(%ecx) - popf - - jmp *JB_EIP(%ecx) diff --git a/sys.subproj/i386.subproj/_setlogin.s b/sys.subproj/i386.subproj/_setlogin.s deleted file mode 100644 index d8d2359..0000000 --- a/sys.subproj/i386.subproj/_setlogin.s +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -PSEUDO(_setlogin, setlogin, 0) - ret - diff --git a/sys.subproj/i386.subproj/_sysctl.s b/sys.subproj/i386.subproj/_sysctl.s deleted file mode 100644 index 1d174f8..0000000 --- a/sys.subproj/i386.subproj/_sysctl.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(__sysctl, 6) - ret diff --git a/sys.subproj/i386.subproj/accept.s b/sys.subproj/i386.subproj/accept.s deleted file mode 100644 index 6e0dc76..0000000 --- a/sys.subproj/i386.subproj/accept.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(accept, 3) - ret diff --git a/sys.subproj/i386.subproj/access.s b/sys.subproj/i386.subproj/access.s deleted file mode 100644 index 4d031b1..0000000 --- a/sys.subproj/i386.subproj/access.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(access, 2) - ret diff --git a/sys.subproj/i386.subproj/acct.s b/sys.subproj/i386.subproj/acct.s deleted file mode 100644 index 83074c5..0000000 --- a/sys.subproj/i386.subproj/acct.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(acct, 1) - ret diff --git a/sys.subproj/i386.subproj/add_profil.s b/sys.subproj/i386.subproj/add_profil.s deleted file mode 100644 index 02e610f..0000000 --- a/sys.subproj/i386.subproj/add_profil.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(add_profil, 4) - ret diff --git a/sys.subproj/i386.subproj/adjtime.s b/sys.subproj/i386.subproj/adjtime.s deleted file mode 100644 index 4496a62..0000000 --- a/sys.subproj/i386.subproj/adjtime.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(adjtime, 2) - ret diff --git a/sys.subproj/i386.subproj/bind.s b/sys.subproj/i386.subproj/bind.s deleted file mode 100644 index cbe58e1..0000000 --- a/sys.subproj/i386.subproj/bind.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(bind, 3) - ret diff --git a/sys.subproj/i386.subproj/cerror.s b/sys.subproj/i386.subproj/cerror.s deleted file mode 100644 index e1ab9cc..0000000 --- a/sys.subproj/i386.subproj/cerror.s +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - - .globl _errno - -LABEL(cerror) - REG_TO_EXTERN(%eax, _errno) - pushl %eax - CALL_EXTERN(_cthread_set_errno_self) - addl $4,%esp - movl $-1,%eax - movl $-1,%edx /* in case a 64-bit value is returned */ - ret diff --git a/sys.subproj/i386.subproj/chdir.s b/sys.subproj/i386.subproj/chdir.s deleted file mode 100644 index b862cb4..0000000 --- a/sys.subproj/i386.subproj/chdir.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(chdir, 1) - ret diff --git a/sys.subproj/i386.subproj/checkuseraccess.s b/sys.subproj/i386.subproj/checkuseraccess.s deleted file mode 100644 index a49371b..0000000 --- a/sys.subproj/i386.subproj/checkuseraccess.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1998 Apple Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(checkuseraccess, 0) - ret diff --git a/sys.subproj/i386.subproj/chflags.s b/sys.subproj/i386.subproj/chflags.s deleted file mode 100644 index 2436f67..0000000 --- a/sys.subproj/i386.subproj/chflags.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(chflags, 2) - ret diff --git a/sys.subproj/i386.subproj/chmod.s b/sys.subproj/i386.subproj/chmod.s deleted file mode 100644 index 6bc417a..0000000 --- a/sys.subproj/i386.subproj/chmod.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(chmod, 2) - ret diff --git a/sys.subproj/i386.subproj/chown.s b/sys.subproj/i386.subproj/chown.s deleted file mode 100644 index 05686ec..0000000 --- a/sys.subproj/i386.subproj/chown.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(chown, 3) - ret diff --git a/sys.subproj/i386.subproj/chroot.s b/sys.subproj/i386.subproj/chroot.s deleted file mode 100644 index 79c27c7..0000000 --- a/sys.subproj/i386.subproj/chroot.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(chroot, 1) - ret diff --git a/sys.subproj/i386.subproj/close.s b/sys.subproj/i386.subproj/close.s deleted file mode 100644 index 33d4a42..0000000 --- a/sys.subproj/i386.subproj/close.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(close, 1) - ret diff --git a/sys.subproj/i386.subproj/connect.s b/sys.subproj/i386.subproj/connect.s deleted file mode 100644 index 96719ab..0000000 --- a/sys.subproj/i386.subproj/connect.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(connect, 3) - ret diff --git a/sys.subproj/i386.subproj/dup.s b/sys.subproj/i386.subproj/dup.s deleted file mode 100644 index 9116c62..0000000 --- a/sys.subproj/i386.subproj/dup.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(dup, 2) - ret diff --git a/sys.subproj/i386.subproj/dup2.s b/sys.subproj/i386.subproj/dup2.s deleted file mode 100644 index 6f0fb01..0000000 --- a/sys.subproj/i386.subproj/dup2.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(dup2, 2) - ret diff --git a/sys.subproj/i386.subproj/exchangedata.s b/sys.subproj/i386.subproj/exchangedata.s deleted file mode 100644 index dcd757f..0000000 --- a/sys.subproj/i386.subproj/exchangedata.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1998 Apple Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(exchangedata, 0) - ret diff --git a/sys.subproj/i386.subproj/execve.s b/sys.subproj/i386.subproj/execve.s deleted file mode 100644 index 44e4ecb..0000000 --- a/sys.subproj/i386.subproj/execve.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(execve, 3) - ret // execve(file, argv, arge) diff --git a/sys.subproj/i386.subproj/fchdir.s b/sys.subproj/i386.subproj/fchdir.s deleted file mode 100644 index 8040919..0000000 --- a/sys.subproj/i386.subproj/fchdir.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(fchdir, 1) - ret diff --git a/sys.subproj/i386.subproj/fchflags.s b/sys.subproj/i386.subproj/fchflags.s deleted file mode 100644 index 7189e7e..0000000 --- a/sys.subproj/i386.subproj/fchflags.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(fchflags, 2) - ret diff --git a/sys.subproj/i386.subproj/fchmod.s b/sys.subproj/i386.subproj/fchmod.s deleted file mode 100644 index a48a89a..0000000 --- a/sys.subproj/i386.subproj/fchmod.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(fchmod, 2) - ret diff --git a/sys.subproj/i386.subproj/fchown.s b/sys.subproj/i386.subproj/fchown.s deleted file mode 100644 index d410dca..0000000 --- a/sys.subproj/i386.subproj/fchown.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(fchown, 3) - ret diff --git a/sys.subproj/i386.subproj/fcntl.s b/sys.subproj/i386.subproj/fcntl.s deleted file mode 100644 index f788e03..0000000 --- a/sys.subproj/i386.subproj/fcntl.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(fcntl, 3) - ret diff --git a/sys.subproj/i386.subproj/flock.s b/sys.subproj/i386.subproj/flock.s deleted file mode 100644 index f490a4a..0000000 --- a/sys.subproj/i386.subproj/flock.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(flock, 2) - ret diff --git a/sys.subproj/i386.subproj/fork.s b/sys.subproj/i386.subproj/fork.s deleted file mode 100644 index 74b278d..0000000 --- a/sys.subproj/i386.subproj/fork.s +++ /dev/null @@ -1,164 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -LEAF(_fork, 0) - CALL_EXTERN(__cthread_fork_prepare) -#if defined(__DYNAMIC__) -// Just like __cthread_fork_prepare we need to prevent threads on the child's -// side from doing a mach call in the dynamic linker until __dyld_fork_child -// is run (see below). So we call __dyld_fork_prepare which takes out the dyld -// lock to prevent all other threads but this one from entering dyld. -.cstring -LC1: - .ascii "__dyld_fork_prepare\0" -.text - subl $4,%esp // allocate space for the address parameter - leal 0(%esp),%eax // get the address of the allocated space - pushl %eax // push the address of the allocated space - call 1f -1: popl %eax - leal LC1-1b(%eax),%eax - pushl %eax // push the name of the function to look up - call __dyld_func_lookup - addl $8,%esp // remove parameters to __dyld_func_lookup - movl 0(%esp),%eax // move the value returned in address parameter - addl $4,%esp // deallocate the space for the address param - call *%eax // call __dyld_fork_prepare indirectly -#endif - - movl $SYS_fork,%eax; // code for fork -> eax - UNIX_SYSCALL_TRAP; // do the system call - jnc L1 // jump if CF==0 - -#if defined(__DYNAMIC__) -// __dyld_fork_parent() is called by the parent process after a fork syscall. -// This releases the dyld lock acquired by __dyld_fork_prepare(). In this case -// we just use it to clean up after a fork error so the parent process can -// dyld after fork() errors without deadlocking. -.cstring -LC2: - .ascii "__dyld_fork_parent\0" -.text - pushl %eax // save the return value (errno) - subl $4,%esp // allocate space for the address parameter - leal 0(%esp),%eax // get the address of the allocated space - pushl %eax // push the address of the allocated space - call 1f -1: popl %eax - leal LC2-1b(%eax),%eax - pushl %eax // push the name of the function to look up - call __dyld_func_lookup - addl $8,%esp // remove parameters to __dyld_func_lookup - movl 0(%esp),%eax // move the value returned in address parameter - addl $4,%esp // deallocate the space for the address param - call *%eax // call __dyld_fork_parent indirectly - popl %eax // restore the return value (errno) -#endif - CALL_EXTERN(cerror) - CALL_EXTERN(__cthread_fork_parent) - movl $-1,%eax - ret - -L1: - orl %edx,%edx // CF=OF=0, ZF set if zero result - jz L2 // parent, since r1 == 0 in parent, 1 in child - - //child here... -#if defined(__DYNAMIC__) -// Here on the child side of the fork we need to tell the dynamic linker that -// we have forked. To do this we call __dyld_fork_child in the dyanmic -// linker. But since we can't dynamicly bind anything until this is done we -// do this by using the private extern __dyld_func_lookup() function to get the -// address of __dyld_fork_child (the 'C' code equivlent): -// -// _dyld_func_lookup("__dyld_fork_child", &address); -// address(); -// -.cstring -LC0: - .ascii "__dyld_fork_child\0" - -.text - subl $4,%esp // allocate space for the address parameter - leal 0(%esp),%eax // get the address of the allocated space - pushl %eax // push the address of the allocated space - call 1f -1: popl %eax - leal LC0-1b(%eax),%eax - pushl %eax // push the name of the function to look up - call __dyld_func_lookup - addl $8,%esp // remove parameters to __dyld_func_lookup - movl 0(%esp),%eax // move the value returned in address parameter - addl $4,%esp // deallocate the space for the address param - call *%eax // call __dyld_fork_child indirectly -#endif - CALL_EXTERN(_fork_mach_init) - CALL_EXTERN(__cthread_fork_child) -#if defined(__DYNAMIC__) -.cstring -LC10: - .ascii "__dyld_fork_child_final\0" - -.text - subl $4,%esp // allocate space for the address parameter - leal 0(%esp),%eax // get the address of the allocated space - pushl %eax // push the address of the allocated space - call 1f -1: popl %eax - leal LC10-1b(%eax),%eax - pushl %eax // push the name of the function to look up - call __dyld_func_lookup - addl $8,%esp // remove parameters to __dyld_func_lookup - movl 0(%esp),%eax // move the value returned in address parameter - addl $4,%esp // deallocate the space for the address param - call *%eax // call __dyld_fork_child_final indirectly -#endif - xorl %eax,%eax // zero eax - ret - - //parent here... -L2: - push %eax // save pid -#if defined(__DYNAMIC__) -// __dyld_fork_parent() is called by the parent process after a fork syscall. -// This releases the dyld lock acquired by __dyld_fork_prepare(). - subl $4,%esp // allocate space for the address parameter - leal 0(%esp),%eax // get the address of the allocated space - pushl %eax // push the address of the allocated space - call 1f -1: popl %eax - leal LC2-1b(%eax),%eax - pushl %eax // push the name of the function to look up - call __dyld_func_lookup - addl $8,%esp // remove parameters to __dyld_func_lookup - movl 0(%esp),%eax // move the value returned in address parameter - addl $4,%esp // deallocate the space for the address param - call *%eax // call __dyld_fork_parent indirectly -#endif - CALL_EXTERN_AGAIN(__cthread_fork_parent) - pop %eax - ret - diff --git a/sys.subproj/i386.subproj/fpathconf.s b/sys.subproj/i386.subproj/fpathconf.s deleted file mode 100644 index 12f71ee..0000000 --- a/sys.subproj/i386.subproj/fpathconf.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(fpathconf, 2) - ret diff --git a/sys.subproj/i386.subproj/fstat.s b/sys.subproj/i386.subproj/fstat.s deleted file mode 100644 index 1a72abb..0000000 --- a/sys.subproj/i386.subproj/fstat.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(fstat, 2) - ret diff --git a/sys.subproj/i386.subproj/fstatfs.s b/sys.subproj/i386.subproj/fstatfs.s deleted file mode 100644 index b9a8cdf..0000000 --- a/sys.subproj/i386.subproj/fstatfs.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(fstatfs, 2) - ret diff --git a/sys.subproj/i386.subproj/fstatv.s b/sys.subproj/i386.subproj/fstatv.s deleted file mode 100644 index 69ee4c9..0000000 --- a/sys.subproj/i386.subproj/fstatv.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1998 Apple Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(fstatv, 0) - ret diff --git a/sys.subproj/i386.subproj/fsync.s b/sys.subproj/i386.subproj/fsync.s deleted file mode 100644 index 38d8f62..0000000 --- a/sys.subproj/i386.subproj/fsync.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(fsync, 1) - ret diff --git a/sys.subproj/i386.subproj/ftruncate.s b/sys.subproj/i386.subproj/ftruncate.s deleted file mode 100644 index 1522750..0000000 --- a/sys.subproj/i386.subproj/ftruncate.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(ftruncate, 2) - ret diff --git a/sys.subproj/i386.subproj/getattrlist.s b/sys.subproj/i386.subproj/getattrlist.s deleted file mode 100644 index 4e051b4..0000000 --- a/sys.subproj/i386.subproj/getattrlist.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1998 Apple Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(getattrlist, 0) - ret diff --git a/sys.subproj/i386.subproj/getdirentries.s b/sys.subproj/i386.subproj/getdirentries.s deleted file mode 100644 index 3592e4a..0000000 --- a/sys.subproj/i386.subproj/getdirentries.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(getdirentries, 4) - ret diff --git a/sys.subproj/i386.subproj/getdirentriesattr.s b/sys.subproj/i386.subproj/getdirentriesattr.s deleted file mode 100644 index 4840434..0000000 --- a/sys.subproj/i386.subproj/getdirentriesattr.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1998 Apple Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(getdirentriesattr, 0) - ret diff --git a/sys.subproj/i386.subproj/getegid.s b/sys.subproj/i386.subproj/getegid.s deleted file mode 100644 index 5be6771..0000000 --- a/sys.subproj/i386.subproj/getegid.s +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -PSEUDO(getegid, getgid, 0) - movl %edx, %eax - ret // egid = getegid(); diff --git a/sys.subproj/i386.subproj/geteuid.s b/sys.subproj/i386.subproj/geteuid.s deleted file mode 100644 index 132c7a2..0000000 --- a/sys.subproj/i386.subproj/geteuid.s +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -PSEUDO(geteuid, getuid, 0) - movl %edx, %eax - ret // euid = geteuid(); diff --git a/sys.subproj/i386.subproj/getfh.s b/sys.subproj/i386.subproj/getfh.s deleted file mode 100644 index a81c0e3..0000000 --- a/sys.subproj/i386.subproj/getfh.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(getfh, 2) - ret diff --git a/sys.subproj/i386.subproj/getfsstat.s b/sys.subproj/i386.subproj/getfsstat.s deleted file mode 100644 index 665b3a3..0000000 --- a/sys.subproj/i386.subproj/getfsstat.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(getfsstat, 3) - ret diff --git a/sys.subproj/i386.subproj/getgid.s b/sys.subproj/i386.subproj/getgid.s deleted file mode 100644 index ba2aac4..0000000 --- a/sys.subproj/i386.subproj/getgid.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(getgid, 0) - ret // gid = getgid(); diff --git a/sys.subproj/i386.subproj/getgroups.s b/sys.subproj/i386.subproj/getgroups.s deleted file mode 100644 index 8d255a5..0000000 --- a/sys.subproj/i386.subproj/getgroups.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(getgroups, 2) - ret // ngroups = getgroups(gidsetsize, gidset) diff --git a/sys.subproj/i386.subproj/getitimer.s b/sys.subproj/i386.subproj/getitimer.s deleted file mode 100644 index 3e24bbf..0000000 --- a/sys.subproj/i386.subproj/getitimer.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(getitimer, 2) - ret diff --git a/sys.subproj/i386.subproj/getpeername.s b/sys.subproj/i386.subproj/getpeername.s deleted file mode 100644 index 8a30166..0000000 --- a/sys.subproj/i386.subproj/getpeername.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(getpeername, 3) - ret diff --git a/sys.subproj/i386.subproj/getpgrp.s b/sys.subproj/i386.subproj/getpgrp.s deleted file mode 100644 index e1c3858..0000000 --- a/sys.subproj/i386.subproj/getpgrp.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(getpgrp, 1) - ret // pgrp = getpgrp(pid); diff --git a/sys.subproj/i386.subproj/getpid.s b/sys.subproj/i386.subproj/getpid.s deleted file mode 100644 index beab7f7..0000000 --- a/sys.subproj/i386.subproj/getpid.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(getpid, 0) - ret // pid = getpid(); diff --git a/sys.subproj/i386.subproj/getppid.s b/sys.subproj/i386.subproj/getppid.s deleted file mode 100644 index 87cc8b7..0000000 --- a/sys.subproj/i386.subproj/getppid.s +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -PSEUDO(getppid, getpid, 0) - movl %edx, %eax - ret // ppid = getppid(); diff --git a/sys.subproj/i386.subproj/getpriority.s b/sys.subproj/i386.subproj/getpriority.s deleted file mode 100644 index ca03e09..0000000 --- a/sys.subproj/i386.subproj/getpriority.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(getpriority, 2) - ret diff --git a/sys.subproj/i386.subproj/getrlimit.s b/sys.subproj/i386.subproj/getrlimit.s deleted file mode 100644 index e8c7669..0000000 --- a/sys.subproj/i386.subproj/getrlimit.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(getrlimit, 2) - ret diff --git a/sys.subproj/i386.subproj/getrusage.s b/sys.subproj/i386.subproj/getrusage.s deleted file mode 100644 index b3835d1..0000000 --- a/sys.subproj/i386.subproj/getrusage.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(getrusage, 2) - ret diff --git a/sys.subproj/i386.subproj/getsockname.s b/sys.subproj/i386.subproj/getsockname.s deleted file mode 100644 index cdddd3f..0000000 --- a/sys.subproj/i386.subproj/getsockname.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(getsockname, 3) - ret diff --git a/sys.subproj/i386.subproj/getsockopt.s b/sys.subproj/i386.subproj/getsockopt.s deleted file mode 100644 index 11fbb2c..0000000 --- a/sys.subproj/i386.subproj/getsockopt.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(getsockopt, 5) - ret diff --git a/sys.subproj/i386.subproj/getuid.s b/sys.subproj/i386.subproj/getuid.s deleted file mode 100644 index 534a7ed..0000000 --- a/sys.subproj/i386.subproj/getuid.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(getuid, 0) - ret // uid = getuid(); diff --git a/sys.subproj/i386.subproj/ioctl.s b/sys.subproj/i386.subproj/ioctl.s deleted file mode 100644 index 87d2668..0000000 --- a/sys.subproj/i386.subproj/ioctl.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(ioctl, 3) - ret diff --git a/sys.subproj/i386.subproj/kill.s b/sys.subproj/i386.subproj/kill.s deleted file mode 100644 index fbcde10..0000000 --- a/sys.subproj/i386.subproj/kill.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(kill, 2) - ret diff --git a/sys.subproj/i386.subproj/ktrace.s b/sys.subproj/i386.subproj/ktrace.s deleted file mode 100644 index 2cedba9..0000000 --- a/sys.subproj/i386.subproj/ktrace.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(ktrace, 4) - ret diff --git a/sys.subproj/i386.subproj/lfs_bmapv.s b/sys.subproj/i386.subproj/lfs_bmapv.s deleted file mode 100644 index 5bfe288..0000000 --- a/sys.subproj/i386.subproj/lfs_bmapv.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(lfs_bmapv, 2) - ret diff --git a/sys.subproj/i386.subproj/lfs_markv.s b/sys.subproj/i386.subproj/lfs_markv.s deleted file mode 100644 index b43267c..0000000 --- a/sys.subproj/i386.subproj/lfs_markv.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(lfs_markv, 2) - ret diff --git a/sys.subproj/i386.subproj/lfs_segclean.s b/sys.subproj/i386.subproj/lfs_segclean.s deleted file mode 100644 index 3463892..0000000 --- a/sys.subproj/i386.subproj/lfs_segclean.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(lfs_segclean, 2) - ret diff --git a/sys.subproj/i386.subproj/lfs_segwait.s b/sys.subproj/i386.subproj/lfs_segwait.s deleted file mode 100644 index 96c60f6..0000000 --- a/sys.subproj/i386.subproj/lfs_segwait.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(lfs_segwait, 2) - ret diff --git a/sys.subproj/i386.subproj/link.s b/sys.subproj/i386.subproj/link.s deleted file mode 100644 index aaf945a..0000000 --- a/sys.subproj/i386.subproj/link.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(link, 2) - ret diff --git a/sys.subproj/i386.subproj/listen.s b/sys.subproj/i386.subproj/listen.s deleted file mode 100644 index ff4e5ee..0000000 --- a/sys.subproj/i386.subproj/listen.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(listen, 2) - ret diff --git a/sys.subproj/i386.subproj/load_shared_file.s b/sys.subproj/i386.subproj/load_shared_file.s deleted file mode 100644 index bdfebfd..0000000 --- a/sys.subproj/i386.subproj/load_shared_file.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(load_shared_file, 7) - ret diff --git a/sys.subproj/i386.subproj/lseek.s b/sys.subproj/i386.subproj/lseek.s deleted file mode 100644 index 1d7ce24..0000000 --- a/sys.subproj/i386.subproj/lseek.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(lseek, 3) - ret diff --git a/sys.subproj/i386.subproj/lstat.s b/sys.subproj/i386.subproj/lstat.s deleted file mode 100644 index fbf7e02..0000000 --- a/sys.subproj/i386.subproj/lstat.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(lstat, 2) - ret diff --git a/sys.subproj/i386.subproj/lstatv.s b/sys.subproj/i386.subproj/lstatv.s deleted file mode 100644 index 40d7f4f..0000000 --- a/sys.subproj/i386.subproj/lstatv.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1998 Apple Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(lstatv, 0) - ret diff --git a/sys.subproj/i386.subproj/madvise.s b/sys.subproj/i386.subproj/madvise.s deleted file mode 100644 index 96a5603..0000000 --- a/sys.subproj/i386.subproj/madvise.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(madvise, 3) - ret diff --git a/sys.subproj/i386.subproj/mincore.s b/sys.subproj/i386.subproj/mincore.s deleted file mode 100644 index 1002afd..0000000 --- a/sys.subproj/i386.subproj/mincore.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(mincore, 3) - ret diff --git a/sys.subproj/i386.subproj/minherit.s b/sys.subproj/i386.subproj/minherit.s deleted file mode 100644 index 3901af9..0000000 --- a/sys.subproj/i386.subproj/minherit.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(minherit, 3) - ret diff --git a/sys.subproj/i386.subproj/mkcomplex.s b/sys.subproj/i386.subproj/mkcomplex.s deleted file mode 100644 index 0b54a3b..0000000 --- a/sys.subproj/i386.subproj/mkcomplex.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1998 Apple Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(mkcomplex, 0) - ret diff --git a/sys.subproj/i386.subproj/mkdir.s b/sys.subproj/i386.subproj/mkdir.s deleted file mode 100644 index fd001b9..0000000 --- a/sys.subproj/i386.subproj/mkdir.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(mkdir, 2) - ret diff --git a/sys.subproj/i386.subproj/mkfifo.s b/sys.subproj/i386.subproj/mkfifo.s deleted file mode 100644 index 1469906..0000000 --- a/sys.subproj/i386.subproj/mkfifo.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(mkfifo, 2) - ret diff --git a/sys.subproj/i386.subproj/mknod.s b/sys.subproj/i386.subproj/mknod.s deleted file mode 100644 index ab8c6fb..0000000 --- a/sys.subproj/i386.subproj/mknod.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(mknod, 3) - ret diff --git a/sys.subproj/i386.subproj/mlock.s b/sys.subproj/i386.subproj/mlock.s deleted file mode 100644 index 0051c53..0000000 --- a/sys.subproj/i386.subproj/mlock.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(mlock, 3) - ret diff --git a/sys.subproj/i386.subproj/mlockall.s b/sys.subproj/i386.subproj/mlockall.s deleted file mode 100644 index 0a0dad4..0000000 --- a/sys.subproj/i386.subproj/mlockall.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(mlockall, 3) - ret diff --git a/sys.subproj/i386.subproj/mmap.s b/sys.subproj/i386.subproj/mmap.s deleted file mode 100644 index 57fa9a1..0000000 --- a/sys.subproj/i386.subproj/mmap.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(mmap, 6) - ret diff --git a/sys.subproj/i386.subproj/mount.s b/sys.subproj/i386.subproj/mount.s deleted file mode 100644 index df208d0..0000000 --- a/sys.subproj/i386.subproj/mount.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(mount, 4) - ret diff --git a/sys.subproj/i386.subproj/mprotect.s b/sys.subproj/i386.subproj/mprotect.s deleted file mode 100644 index 368c648..0000000 --- a/sys.subproj/i386.subproj/mprotect.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(mprotect, 3) - ret diff --git a/sys.subproj/i386.subproj/msgctl.s b/sys.subproj/i386.subproj/msgctl.s deleted file mode 100644 index 9028ca2..0000000 --- a/sys.subproj/i386.subproj/msgctl.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(msgctl, 3) - ret diff --git a/sys.subproj/i386.subproj/msgget.s b/sys.subproj/i386.subproj/msgget.s deleted file mode 100644 index 9a9c46c..0000000 --- a/sys.subproj/i386.subproj/msgget.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(msgget, 3) - ret diff --git a/sys.subproj/i386.subproj/msgrcv.s b/sys.subproj/i386.subproj/msgrcv.s deleted file mode 100644 index 627c8c5..0000000 --- a/sys.subproj/i386.subproj/msgrcv.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(msgrcv, 3) - ret diff --git a/sys.subproj/i386.subproj/msgsnd.s b/sys.subproj/i386.subproj/msgsnd.s deleted file mode 100644 index 0cf6dc2..0000000 --- a/sys.subproj/i386.subproj/msgsnd.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(msgsnd, 3) - ret diff --git a/sys.subproj/i386.subproj/msgsys.s b/sys.subproj/i386.subproj/msgsys.s deleted file mode 100644 index bad4612..0000000 --- a/sys.subproj/i386.subproj/msgsys.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(msgsys, 3) - ret diff --git a/sys.subproj/i386.subproj/msync.s b/sys.subproj/i386.subproj/msync.s deleted file mode 100644 index 26924bc..0000000 --- a/sys.subproj/i386.subproj/msync.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(msync, 2) - ret diff --git a/sys.subproj/i386.subproj/munlock.s b/sys.subproj/i386.subproj/munlock.s deleted file mode 100644 index b7341af..0000000 --- a/sys.subproj/i386.subproj/munlock.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(munlock, 3) - ret diff --git a/sys.subproj/i386.subproj/munlockall.s b/sys.subproj/i386.subproj/munlockall.s deleted file mode 100644 index 098b0b4..0000000 --- a/sys.subproj/i386.subproj/munlockall.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(munlockall, 3) - ret diff --git a/sys.subproj/i386.subproj/munmap.s b/sys.subproj/i386.subproj/munmap.s deleted file mode 100644 index 7e2e28c..0000000 --- a/sys.subproj/i386.subproj/munmap.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(munmap, 2) - ret diff --git a/sys.subproj/i386.subproj/nfssvc.s b/sys.subproj/i386.subproj/nfssvc.s deleted file mode 100644 index 70a8e2d..0000000 --- a/sys.subproj/i386.subproj/nfssvc.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(nfssvc, 1) - ret diff --git a/sys.subproj/i386.subproj/open.s b/sys.subproj/i386.subproj/open.s deleted file mode 100644 index c505660..0000000 --- a/sys.subproj/i386.subproj/open.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(open, 3) - ret diff --git a/sys.subproj/i386.subproj/pathconf.s b/sys.subproj/i386.subproj/pathconf.s deleted file mode 100644 index ae6eab4..0000000 --- a/sys.subproj/i386.subproj/pathconf.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(pathconf, 2) - ret diff --git a/sys.subproj/i386.subproj/pipe.s b/sys.subproj/i386.subproj/pipe.s deleted file mode 100644 index 8fefcdd..0000000 --- a/sys.subproj/i386.subproj/pipe.s +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(pipe, 0) - movl 4(%esp),%ecx - movl %eax,(%ecx) - movl %edx,4(%ecx) - xorl %eax,%eax - ret diff --git a/sys.subproj/i386.subproj/profil.s b/sys.subproj/i386.subproj/profil.s deleted file mode 100644 index e9af89f..0000000 --- a/sys.subproj/i386.subproj/profil.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(profil, 4) - ret diff --git a/sys.subproj/i386.subproj/ptrace.s b/sys.subproj/i386.subproj/ptrace.s deleted file mode 100644 index 28ab2ad..0000000 --- a/sys.subproj/i386.subproj/ptrace.s +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - - .globl _errno - -LEAF(_ptrace, 0) - xorl %eax,%eax - REG_TO_EXTERN(%eax,_errno) -UNIX_SYSCALL_NONAME(ptrace, 4) - ret diff --git a/sys.subproj/i386.subproj/quota.s b/sys.subproj/i386.subproj/quota.s deleted file mode 100644 index f3788d7..0000000 --- a/sys.subproj/i386.subproj/quota.s +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -#define SYS_quota 149 - -UNIX_SYSCALL(quota, 4) - ret diff --git a/sys.subproj/i386.subproj/quotactl.s b/sys.subproj/i386.subproj/quotactl.s deleted file mode 100644 index cc89a5a..0000000 --- a/sys.subproj/i386.subproj/quotactl.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(quotactl, 3) - ret diff --git a/sys.subproj/i386.subproj/read.s b/sys.subproj/i386.subproj/read.s deleted file mode 100644 index 1429fa2..0000000 --- a/sys.subproj/i386.subproj/read.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(read, 3) - ret diff --git a/sys.subproj/i386.subproj/readlink.s b/sys.subproj/i386.subproj/readlink.s deleted file mode 100644 index 958d7b7..0000000 --- a/sys.subproj/i386.subproj/readlink.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(readlink, 3) - ret diff --git a/sys.subproj/i386.subproj/readv.s b/sys.subproj/i386.subproj/readv.s deleted file mode 100644 index fe11a86..0000000 --- a/sys.subproj/i386.subproj/readv.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(readv, 3) - ret diff --git a/sys.subproj/i386.subproj/reboot.s b/sys.subproj/i386.subproj/reboot.s deleted file mode 100644 index b6841b4..0000000 --- a/sys.subproj/i386.subproj/reboot.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(reboot, 2) - hlt diff --git a/sys.subproj/i386.subproj/recvfrom.s b/sys.subproj/i386.subproj/recvfrom.s deleted file mode 100644 index a9ab56e..0000000 --- a/sys.subproj/i386.subproj/recvfrom.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(recvfrom, 6) - ret diff --git a/sys.subproj/i386.subproj/recvmsg.s b/sys.subproj/i386.subproj/recvmsg.s deleted file mode 100644 index d61786f..0000000 --- a/sys.subproj/i386.subproj/recvmsg.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(recvmsg, 3) - ret diff --git a/sys.subproj/i386.subproj/rename.s b/sys.subproj/i386.subproj/rename.s deleted file mode 100644 index a3efcfb..0000000 --- a/sys.subproj/i386.subproj/rename.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(rename, 2) - ret diff --git a/sys.subproj/i386.subproj/reset_shared_file.s b/sys.subproj/i386.subproj/reset_shared_file.s deleted file mode 100644 index 49e7424..0000000 --- a/sys.subproj/i386.subproj/reset_shared_file.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(reset_shared_file, 3) - ret diff --git a/sys.subproj/i386.subproj/revoke.s b/sys.subproj/i386.subproj/revoke.s deleted file mode 100644 index 438ad16..0000000 --- a/sys.subproj/i386.subproj/revoke.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(revoke, 1) - ret diff --git a/sys.subproj/i386.subproj/rmdir.s b/sys.subproj/i386.subproj/rmdir.s deleted file mode 100644 index d5c2e6b..0000000 --- a/sys.subproj/i386.subproj/rmdir.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(rmdir, 1) - ret diff --git a/sys.subproj/i386.subproj/searchfs.s b/sys.subproj/i386.subproj/searchfs.s deleted file mode 100644 index 4ee3b8b..0000000 --- a/sys.subproj/i386.subproj/searchfs.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1998 Apple Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(searchfs, 0) - ret diff --git a/sys.subproj/i386.subproj/select.s b/sys.subproj/i386.subproj/select.s deleted file mode 100644 index 2aa2880..0000000 --- a/sys.subproj/i386.subproj/select.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(select, 5) - ret diff --git a/sys.subproj/i386.subproj/sem_close.s b/sys.subproj/i386.subproj/sem_close.s deleted file mode 100644 index c3ed857..0000000 --- a/sys.subproj/i386.subproj/sem_close.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -UNIX_SYSCALL(sem_close, 1) - ret - diff --git a/sys.subproj/i386.subproj/sem_destroy.s b/sys.subproj/i386.subproj/sem_destroy.s deleted file mode 100644 index 2b7fdc5..0000000 --- a/sys.subproj/i386.subproj/sem_destroy.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -UNIX_SYSCALL(sem_destroy, 1) - ret - diff --git a/sys.subproj/i386.subproj/sem_getvalue.s b/sys.subproj/i386.subproj/sem_getvalue.s deleted file mode 100644 index d169e21..0000000 --- a/sys.subproj/i386.subproj/sem_getvalue.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -UNIX_SYSCALL(sem_getvalue, 2) - ret - diff --git a/sys.subproj/i386.subproj/sem_init.s b/sys.subproj/i386.subproj/sem_init.s deleted file mode 100644 index daf0ba9..0000000 --- a/sys.subproj/i386.subproj/sem_init.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -UNIX_SYSCALL(sem_init, 3) - ret - diff --git a/sys.subproj/i386.subproj/sem_open.s b/sys.subproj/i386.subproj/sem_open.s deleted file mode 100644 index 2c68a7c..0000000 --- a/sys.subproj/i386.subproj/sem_open.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -UNIX_SYSCALL(sem_open, 4) - ret - diff --git a/sys.subproj/i386.subproj/sem_post.s b/sys.subproj/i386.subproj/sem_post.s deleted file mode 100644 index f6b24af..0000000 --- a/sys.subproj/i386.subproj/sem_post.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -UNIX_SYSCALL(sem_post, 1) - ret - diff --git a/sys.subproj/i386.subproj/sem_trywait.s b/sys.subproj/i386.subproj/sem_trywait.s deleted file mode 100644 index 9c0f725..0000000 --- a/sys.subproj/i386.subproj/sem_trywait.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -UNIX_SYSCALL(sem_trywait, 1) - ret - diff --git a/sys.subproj/i386.subproj/sem_unlink.s b/sys.subproj/i386.subproj/sem_unlink.s deleted file mode 100644 index 0449cbf..0000000 --- a/sys.subproj/i386.subproj/sem_unlink.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -UNIX_SYSCALL(sem_unlink, 1) - ret - diff --git a/sys.subproj/i386.subproj/sem_wait.s b/sys.subproj/i386.subproj/sem_wait.s deleted file mode 100644 index 405b047..0000000 --- a/sys.subproj/i386.subproj/sem_wait.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -UNIX_SYSCALL(sem_wait, 1) - ret - diff --git a/sys.subproj/i386.subproj/semconfig.s b/sys.subproj/i386.subproj/semconfig.s deleted file mode 100644 index 5c07385..0000000 --- a/sys.subproj/i386.subproj/semconfig.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(semconfig, 3) - ret diff --git a/sys.subproj/i386.subproj/semctl.s b/sys.subproj/i386.subproj/semctl.s deleted file mode 100644 index b53bebe..0000000 --- a/sys.subproj/i386.subproj/semctl.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(semctl, 3) - ret diff --git a/sys.subproj/i386.subproj/semget.s b/sys.subproj/i386.subproj/semget.s deleted file mode 100644 index 1889c4d..0000000 --- a/sys.subproj/i386.subproj/semget.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(semget, 3) - ret diff --git a/sys.subproj/i386.subproj/semop.s b/sys.subproj/i386.subproj/semop.s deleted file mode 100644 index 7c0c902..0000000 --- a/sys.subproj/i386.subproj/semop.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(semop, 3) - ret diff --git a/sys.subproj/i386.subproj/semsys.s b/sys.subproj/i386.subproj/semsys.s deleted file mode 100644 index e775bf6..0000000 --- a/sys.subproj/i386.subproj/semsys.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(semsys, 3) - ret diff --git a/sys.subproj/i386.subproj/sendmsg.s b/sys.subproj/i386.subproj/sendmsg.s deleted file mode 100644 index c6acb08..0000000 --- a/sys.subproj/i386.subproj/sendmsg.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(sendmsg, 3) - ret diff --git a/sys.subproj/i386.subproj/sendto.s b/sys.subproj/i386.subproj/sendto.s deleted file mode 100644 index 990f1f1..0000000 --- a/sys.subproj/i386.subproj/sendto.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(sendto, 6) - ret diff --git a/sys.subproj/i386.subproj/setattrlist.s b/sys.subproj/i386.subproj/setattrlist.s deleted file mode 100644 index 907e057..0000000 --- a/sys.subproj/i386.subproj/setattrlist.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1998 Apple Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(setattrlist, 0) - ret diff --git a/sys.subproj/i386.subproj/setegid.s b/sys.subproj/i386.subproj/setegid.s deleted file mode 100644 index a4db7f8..0000000 --- a/sys.subproj/i386.subproj/setegid.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(setegid, 1) - ret diff --git a/sys.subproj/i386.subproj/seteuid.s b/sys.subproj/i386.subproj/seteuid.s deleted file mode 100644 index 497ea22..0000000 --- a/sys.subproj/i386.subproj/seteuid.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(seteuid, 1) - ret diff --git a/sys.subproj/i386.subproj/setgid.s b/sys.subproj/i386.subproj/setgid.s deleted file mode 100644 index 4767c4c..0000000 --- a/sys.subproj/i386.subproj/setgid.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(setgid, 1) - ret diff --git a/sys.subproj/i386.subproj/setgroups.s b/sys.subproj/i386.subproj/setgroups.s deleted file mode 100644 index 66add53..0000000 --- a/sys.subproj/i386.subproj/setgroups.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(setgroups, 2) - ret // setgroups(gidsetsize, gidset) diff --git a/sys.subproj/i386.subproj/setitimer.s b/sys.subproj/i386.subproj/setitimer.s deleted file mode 100644 index 8806cd9..0000000 --- a/sys.subproj/i386.subproj/setitimer.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(setitimer, 3) - ret diff --git a/sys.subproj/i386.subproj/setjmp.s b/sys.subproj/i386.subproj/setjmp.s deleted file mode 100644 index bc5108d..0000000 --- a/sys.subproj/i386.subproj/setjmp.s +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -/* - * NeXT 386 setjmp/longjmp - * - * Written by Bruce Martin, NeXT Inc. 4/9/92 - */ - -/* - * C library -- setjmp, longjmp - * - * longjmp(a,v) - * will generate a "return(v)" from - * the last call to - * setjmp(a) - * by restoring registers from the stack, - * The previous value of the signal mask is - * restored. - * - */ - -#include -#include "SYS.h" - -#define JB_ONSTACK 0 -#define JB_MASK 4 -#define JB_EAX 8 -#define JB_EBX 12 -#define JB_ECX 16 -#define JB_EDX 20 -#define JB_EDI 24 -#define JB_ESI 28 -#define JB_EBP 32 -#define JB_ESP 36 -#define JB_SS 40 -#define JB_EFLAGS 44 -#define JB_EIP 48 -#define JB_CS 52 -#define JB_DS 56 -#define JB_ES 60 -#define JB_FS 64 -#define JB_GS 68 -#define JB_SAVEMASK 72 // sigsetjmp/siglongjmp only - -LEAF(_sigsetjmp, 0) - movl 4(%esp), %eax // sigjmp_buf * jmpbuf; - movl 8(%esp), %ecx // int savemask; - movl %ecx, JB_SAVEMASK(%eax) // jmpbuf[_JBLEN] = savemask; - cmpl $0, %ecx // if savemask != 0 - jne _setjmp // setjmp(jmpbuf); - BRANCH_EXTERN(__setjmp) // else - // _setjmp(jmpbuf); - -LEAF(_setjmp, 0) - movl 4(%esp), %ecx // jmp_buf (struct sigcontext *) - pushl %ecx // save ecx - - // call sigstack to get the current signal stack - subl $12, %esp // space for return structure - pushl %esp - pushl $0 - CALL_EXTERN(_sigaltstack) - movl 12(%esp), %eax // save stack pointer - movl %eax, JB_ONSTACK(%ecx) - addl $20, %esp - - // call sigblock to get signal mask - pushl $0 - CALL_EXTERN(_sigblock) - addl $4, %esp - popl %ecx // restore ecx - movl %eax, JB_MASK(%ecx) - - // now build sigcontext - movl %ebx, JB_EBX(%ecx) - movl %edi, JB_EDI(%ecx) - movl %esi, JB_ESI(%ecx) - movl %ebp, JB_EBP(%ecx) - - // EIP is set to the frame return address value - movl (%esp), %eax - movl %eax, JB_EIP(%ecx) - // ESP is set to the frame return address plus 4 - movl %esp, %eax - addl $4, %eax - movl %eax, JB_ESP(%ecx) - - // segment registers - movl $0, JB_SS(%ecx) - mov %ss, JB_SS(%ecx) - movl $0, JB_CS(%ecx) - mov %cs, JB_CS(%ecx) - movl $0, JB_DS(%ecx) - mov %ds, JB_DS(%ecx) - movl $0, JB_ES(%ecx) - mov %es, JB_ES(%ecx) - movl $0, JB_FS(%ecx) - mov %fs, JB_FS(%ecx) - movl $0, JB_GS(%ecx) - mov %gs, JB_GS(%ecx) - - // save eflags - you can't use movl - pushf - popl %eax - movl %eax, JB_EFLAGS(%ecx) - - // return 0 - xorl %eax, %eax - ret - -LEAF(_siglongjmp, 0) - movl 4(%esp), %eax // sigjmp_buf * jmpbuf; - cmpl $0, JB_SAVEMASK(%eax) // if jmpbuf[_JBLEN] != 0 - jne _longjmp // longjmp(jmpbuf, var); - BRANCH_EXTERN(__longjmp) // else - // _longjmp(jmpbuf, var); - -LEAF(_longjmp, 0) - subl $2,%esp - fnstcw (%esp) // save FP control word - fninit // reset FP coprocessor - fldcw (%esp) // restore FP control word - addl $2,%esp - movl 4(%esp), %eax // address of jmp_buf (saved context) - movl 8(%esp), %edx // return value - movl %edx, JB_EAX(%eax) // return value into saved context - movl $SYS_sigreturn, %eax // sigreturn system call - UNIX_SYSCALL_TRAP - addl $8, %esp - CALL_EXTERN(_longjmperror) - CALL_EXTERN(_abort) -END(_longjmp) diff --git a/sys.subproj/i386.subproj/setpgid.s b/sys.subproj/i386.subproj/setpgid.s deleted file mode 100644 index d0627ef..0000000 --- a/sys.subproj/i386.subproj/setpgid.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(setpgid, 2) - ret diff --git a/sys.subproj/i386.subproj/setpriority.s b/sys.subproj/i386.subproj/setpriority.s deleted file mode 100644 index 315ec64..0000000 --- a/sys.subproj/i386.subproj/setpriority.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(setpriority, 3) - ret diff --git a/sys.subproj/i386.subproj/setprivexec.s b/sys.subproj/i386.subproj/setprivexec.s deleted file mode 100644 index 9569b59..0000000 --- a/sys.subproj/i386.subproj/setprivexec.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(setprivexec, 3) - ret diff --git a/sys.subproj/i386.subproj/setquota.s b/sys.subproj/i386.subproj/setquota.s deleted file mode 100644 index 0919c02..0000000 --- a/sys.subproj/i386.subproj/setquota.s +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -#define SYS_setquota 148 - -UNIX_SYSCALL(setquota, 2) - ret diff --git a/sys.subproj/i386.subproj/setrlimit.s b/sys.subproj/i386.subproj/setrlimit.s deleted file mode 100644 index 06ffe21..0000000 --- a/sys.subproj/i386.subproj/setrlimit.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(setrlimit, 2) - ret diff --git a/sys.subproj/i386.subproj/setsid.s b/sys.subproj/i386.subproj/setsid.s deleted file mode 100644 index 5f6905e..0000000 --- a/sys.subproj/i386.subproj/setsid.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(setsid, 0) - ret diff --git a/sys.subproj/i386.subproj/setsockopt.s b/sys.subproj/i386.subproj/setsockopt.s deleted file mode 100644 index 48d60af..0000000 --- a/sys.subproj/i386.subproj/setsockopt.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(setsockopt, 5) - ret diff --git a/sys.subproj/i386.subproj/settimeofday.s b/sys.subproj/i386.subproj/settimeofday.s deleted file mode 100644 index 529c5f9..0000000 --- a/sys.subproj/i386.subproj/settimeofday.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(settimeofday, 2) - ret diff --git a/sys.subproj/i386.subproj/setuid.s b/sys.subproj/i386.subproj/setuid.s deleted file mode 100644 index dbebb62..0000000 --- a/sys.subproj/i386.subproj/setuid.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(setuid, 1) - ret diff --git a/sys.subproj/i386.subproj/shm_open.s b/sys.subproj/i386.subproj/shm_open.s deleted file mode 100644 index 3629959..0000000 --- a/sys.subproj/i386.subproj/shm_open.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(shm_open, 3) - ret diff --git a/sys.subproj/i386.subproj/shm_unlink.s b/sys.subproj/i386.subproj/shm_unlink.s deleted file mode 100644 index cbbc420..0000000 --- a/sys.subproj/i386.subproj/shm_unlink.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(shm_unlink, 3) - ret diff --git a/sys.subproj/i386.subproj/shmat.s b/sys.subproj/i386.subproj/shmat.s deleted file mode 100644 index c8fdc2c..0000000 --- a/sys.subproj/i386.subproj/shmat.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(shmat, 3) - ret diff --git a/sys.subproj/i386.subproj/shmctl.s b/sys.subproj/i386.subproj/shmctl.s deleted file mode 100644 index 4ae81b7..0000000 --- a/sys.subproj/i386.subproj/shmctl.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(shmctl, 3) - ret diff --git a/sys.subproj/i386.subproj/shmdt.s b/sys.subproj/i386.subproj/shmdt.s deleted file mode 100644 index bfc59ab..0000000 --- a/sys.subproj/i386.subproj/shmdt.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(shmdt, 3) - ret diff --git a/sys.subproj/i386.subproj/shmget.s b/sys.subproj/i386.subproj/shmget.s deleted file mode 100644 index 592ff0e..0000000 --- a/sys.subproj/i386.subproj/shmget.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(shmget, 3) - ret diff --git a/sys.subproj/i386.subproj/shmsys.s b/sys.subproj/i386.subproj/shmsys.s deleted file mode 100644 index 48f49c6..0000000 --- a/sys.subproj/i386.subproj/shmsys.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(shmsys, 3) - ret diff --git a/sys.subproj/i386.subproj/shutdown.s b/sys.subproj/i386.subproj/shutdown.s deleted file mode 100644 index 8e201ac..0000000 --- a/sys.subproj/i386.subproj/shutdown.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(shutdown, 2) - ret diff --git a/sys.subproj/i386.subproj/sigaltstack.s b/sys.subproj/i386.subproj/sigaltstack.s deleted file mode 100644 index b4ca3e5..0000000 --- a/sys.subproj/i386.subproj/sigaltstack.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(sigaltstack, 3) - ret diff --git a/sys.subproj/i386.subproj/sigpending.s b/sys.subproj/i386.subproj/sigpending.s deleted file mode 100644 index 6e99e21..0000000 --- a/sys.subproj/i386.subproj/sigpending.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(sigpending, 1) - ret diff --git a/sys.subproj/i386.subproj/sigreturn.s b/sys.subproj/i386.subproj/sigreturn.s deleted file mode 100644 index b048bb4..0000000 --- a/sys.subproj/i386.subproj/sigreturn.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(sigreturn, 1) - ret diff --git a/sys.subproj/i386.subproj/socket.s b/sys.subproj/i386.subproj/socket.s deleted file mode 100644 index 905c645..0000000 --- a/sys.subproj/i386.subproj/socket.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(socket, 3) - ret diff --git a/sys.subproj/i386.subproj/socketpair.s b/sys.subproj/i386.subproj/socketpair.s deleted file mode 100644 index 2e7c00a..0000000 --- a/sys.subproj/i386.subproj/socketpair.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(socketpair, 5) - ret diff --git a/sys.subproj/i386.subproj/stat.s b/sys.subproj/i386.subproj/stat.s deleted file mode 100644 index cb041e5..0000000 --- a/sys.subproj/i386.subproj/stat.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(stat, 2) - ret diff --git a/sys.subproj/i386.subproj/statfs.s b/sys.subproj/i386.subproj/statfs.s deleted file mode 100644 index 386a41b..0000000 --- a/sys.subproj/i386.subproj/statfs.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(statfs, 2); - ret diff --git a/sys.subproj/i386.subproj/statv.s b/sys.subproj/i386.subproj/statv.s deleted file mode 100644 index db5ce1c..0000000 --- a/sys.subproj/i386.subproj/statv.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1998 Apple Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(statv, 0) - ret diff --git a/sys.subproj/i386.subproj/swapon.s b/sys.subproj/i386.subproj/swapon.s deleted file mode 100644 index fe34af2..0000000 --- a/sys.subproj/i386.subproj/swapon.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(swapon, 1) - ret diff --git a/sys.subproj/i386.subproj/symlink.s b/sys.subproj/i386.subproj/symlink.s deleted file mode 100644 index 44edc06..0000000 --- a/sys.subproj/i386.subproj/symlink.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(symlink, 2) - ret diff --git a/sys.subproj/i386.subproj/sync.s b/sys.subproj/i386.subproj/sync.s deleted file mode 100644 index 03f711f..0000000 --- a/sys.subproj/i386.subproj/sync.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(sync, 0) - ret diff --git a/sys.subproj/i386.subproj/syscall.s b/sys.subproj/i386.subproj/syscall.s deleted file mode 100644 index 2e21b2d..0000000 --- a/sys.subproj/i386.subproj/syscall.s +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -LEAF(_syscall, 0) - popl %ecx // ret addr - popl %eax // syscall number - pushl %ecx - UNIX_SYSCALL_TRAP - movl (%esp),%edx // add one element to stack so - pushl %ecx // caller "pop" will work - jnb 2f - BRANCH_EXTERN(cerror) -2: -END(_syscall) diff --git a/sys.subproj/i386.subproj/table.s b/sys.subproj/i386.subproj/table.s deleted file mode 100644 index 4dec901..0000000 --- a/sys.subproj/i386.subproj/table.s +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -UNIX_SYSCALL(table, 5) - ret diff --git a/sys.subproj/i386.subproj/truncate.s b/sys.subproj/i386.subproj/truncate.s deleted file mode 100644 index a29542d..0000000 --- a/sys.subproj/i386.subproj/truncate.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(truncate, 2) - ret diff --git a/sys.subproj/i386.subproj/umask.s b/sys.subproj/i386.subproj/umask.s deleted file mode 100644 index 82d5619..0000000 --- a/sys.subproj/i386.subproj/umask.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(umask, 1) - ret diff --git a/sys.subproj/i386.subproj/undelete.s b/sys.subproj/i386.subproj/undelete.s deleted file mode 100644 index 1e1c804..0000000 --- a/sys.subproj/i386.subproj/undelete.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(undelete, 1) - ret diff --git a/sys.subproj/i386.subproj/unlink.s b/sys.subproj/i386.subproj/unlink.s deleted file mode 100644 index d3b7191..0000000 --- a/sys.subproj/i386.subproj/unlink.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(unlink, 1) - ret diff --git a/sys.subproj/i386.subproj/unmount.s b/sys.subproj/i386.subproj/unmount.s deleted file mode 100644 index 283b03c..0000000 --- a/sys.subproj/i386.subproj/unmount.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(unmount, 1) - ret diff --git a/sys.subproj/i386.subproj/utimes.s b/sys.subproj/i386.subproj/utimes.s deleted file mode 100644 index d9d7b8b..0000000 --- a/sys.subproj/i386.subproj/utimes.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(utimes, 1) - ret diff --git a/sys.subproj/i386.subproj/vfork.s b/sys.subproj/i386.subproj/vfork.s deleted file mode 100644 index edd5f4f..0000000 --- a/sys.subproj/i386.subproj/vfork.s +++ /dev/null @@ -1,185 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -#if 0 -LEAF(_vfork, 0) - CALL_EXTERN(__cthread_fork_prepare) -#if defined(__DYNAMIC__) -// Just like __cthread_fork_prepare we need to prevent threads on the child's -// side from doing a mach call in the dynamic linker until __dyld_fork_child -// is run (see below). So we call __dyld_fork_prepare which takes out the dyld -// lock to prevent all other threads but this one from entering dyld. -.cstring -LC1: - .ascii "__dyld_fork_prepare\0" -.text - subl $4,%esp // allocate space for the address parameter - leal 0(%esp),%eax // get the address of the allocated space - pushl %eax // push the address of the allocated space - call 1f -1: popl %eax - leal LC1-1b(%eax),%eax - pushl %eax // push the name of the function to look up - call __dyld_func_lookup - addl $8,%esp // remove parameters to __dyld_func_lookup - movl 0(%esp),%eax // move the value returned in address parameter - addl $4,%esp // deallocate the space for the address param - call *%eax // call __dyld_fork_prepare indirectly -#endif - - movl $SYS_vfork,%eax; // code for vfork -> eax - UNIX_SYSCALL_TRAP; // do the system call - jnc L1 // jump if CF==0 - -#if defined(__DYNAMIC__) -// __dyld_fork_parent() is called by the parent process after a vfork syscall. -// This releases the dyld lock acquired by __dyld_fork_prepare(). In this case -// we just use it to clean up after a vfork error so the parent process can -// dyld after vfork() errors without deadlocking. -.cstring -LC2: - .ascii "__dyld_fork_parent\0" -.text - pushl %eax // save the return value (errno) - subl $4,%esp // allocate space for the address parameter - leal 0(%esp),%eax // get the address of the allocated space - pushl %eax // push the address of the allocated space - call 1f -1: popl %eax - leal LC2-1b(%eax),%eax - pushl %eax // push the name of the function to look up - call __dyld_func_lookup - addl $8,%esp // remove parameters to __dyld_func_lookup - movl 0(%esp),%eax // move the value returned in address parameter - addl $4,%esp // deallocate the space for the address param - call *%eax // call __dyld_fork_parent indirectly - popl %eax // restore the return value (errno) -#endif - CALL_EXTERN(cerror) - CALL_EXTERN(__cthread_fork_parent) - movl $-1,%eax - ret - -L1: - orl %edx,%edx // CF=OF=0, ZF set if zero result - jz L2 // parent, since r1 == 0 in parent, 1 in child - - //child here... -#if defined(__DYNAMIC__) -// Here on the child side of the vfork we need to tell the dynamic linker that -// we have vforked. To do this we call __dyld_fork_child in the dyanmic -// linker. But since we can't dynamicly bind anything until this is done we -// do this by using the private extern __dyld_func_lookup() function to get the -// address of __dyld_fork_child (the 'C' code equivlent): -// -// _dyld_func_lookup("__dyld_fork_child", &address); -// address(); -// -.cstring -LC0: - .ascii "__dyld_fork_child\0" - -.text - subl $4,%esp // allocate space for the address parameter - leal 0(%esp),%eax // get the address of the allocated space - pushl %eax // push the address of the allocated space - call 1f -1: popl %eax - leal LC0-1b(%eax),%eax - pushl %eax // push the name of the function to look up - call __dyld_func_lookup - addl $8,%esp // remove parameters to __dyld_func_lookup - movl 0(%esp),%eax // move the value returned in address parameter - addl $4,%esp // deallocate the space for the address param - call *%eax // call __dyld_fork_child indirectly -#endif - CALL_EXTERN(_fork_mach_init) - CALL_EXTERN(__cthread_fork_child) -#if defined(__DYNAMIC__) -.cstring -LC10: - .ascii "__dyld_fork_child_final\0" - -.text - subl $4,%esp // allocate space for the address parameter - leal 0(%esp),%eax // get the address of the allocated space - pushl %eax // push the address of the allocated space - call 1f -1: popl %eax - leal LC10-1b(%eax),%eax - pushl %eax // push the name of the function to look up - call __dyld_func_lookup - addl $8,%esp // remove parameters to __dyld_func_lookup - movl 0(%esp),%eax // move the value returned in address parameter - addl $4,%esp // deallocate the space for the address param - call *%eax // call __dyld_fork_child_final indirectly -#endif - xorl %eax,%eax // zero eax - ret - - //parent here... -L2: - push %eax // save pid -#if defined(__DYNAMIC__) -// __dyld_fork_parent() is called by the parent process after a vfork syscall. -// This releases the dyld lock acquired by __dyld_fork_prepare(). - subl $4,%esp // allocate space for the address parameter - leal 0(%esp),%eax // get the address of the allocated space - pushl %eax // push the address of the allocated space - call 1f -1: popl %eax - leal LC2-1b(%eax),%eax - pushl %eax // push the name of the function to look up - call __dyld_func_lookup - addl $8,%esp // remove parameters to __dyld_func_lookup - movl 0(%esp),%eax // move the value returned in address parameter - addl $4,%esp // deallocate the space for the address param - call *%eax // call __dyld_fork_parent indirectly -#endif - CALL_EXTERN_AGAIN(__cthread_fork_parent) - pop %eax - ret -#else - -LEAF(_vfork, 0) - popl %ecx - movl $SYS_vfork,%eax; // code for vfork -> eax - UNIX_SYSCALL_TRAP; // do the system call - jnb L1 // jump if CF==0 - pushl %ecx - BRANCH_EXTERN(cerror) - -L1: - orl %edx,%edx // CF=OF=0, ZF set if zero result - jz L2 // parent, since r1 == 0 in parent, 1 in child - xorl %eax,%eax // zero eax - jmp *%ecx - -L2: - jmp *%ecx - -#endif - diff --git a/sys.subproj/i386.subproj/wait4.s b/sys.subproj/i386.subproj/wait4.s deleted file mode 100644 index 889c6c0..0000000 --- a/sys.subproj/i386.subproj/wait4.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(wait4, 4) - ret diff --git a/sys.subproj/i386.subproj/write.s b/sys.subproj/i386.subproj/write.s deleted file mode 100644 index e8e98f9..0000000 --- a/sys.subproj/i386.subproj/write.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(write, 3) - ret diff --git a/sys.subproj/i386.subproj/writev.s b/sys.subproj/i386.subproj/writev.s deleted file mode 100644 index 10fc07d..0000000 --- a/sys.subproj/i386.subproj/writev.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#include "SYS.h" - -UNIX_SYSCALL(writev, 3) - ret diff --git a/sys.subproj/msync.2 b/sys.subproj/msync.2 deleted file mode 100644 index 94de3b6..0000000 --- a/sys.subproj/msync.2 +++ /dev/null @@ -1,103 +0,0 @@ -.\" 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. -.\" -.\" @(#)msync.2 8.2 (Berkeley) 6/21/94 -.\" $FreeBSD: src/lib/libc/sys/msync.2,v 1.17 2000/04/21 09:41:53 phantom Exp $ -.\" -.Dd June 21, 1994 -.Dt MSYNC 2 -.Os -.Sh NAME -.Nm msync -.Nd synchronize a mapped region -.Sh LIBRARY -.Lb libc -.Sh SYNOPSIS -.Fd #include -.Fd #include -.Ft int -.Fn msync "void *addr" "size_t len" "int flags" -.Sh DESCRIPTION -The -.Fn msync -system call -writes any modified pages back to the filesystem and updates -the file modification time. -If -.Fa len -is 0, all modified pages within the region containing -.Fa addr -will be flushed; -if -.Fa len -is non-zero, only those pages containing -.Fa addr -and -.Fa len-1 -succeeding locations will be examined. -The -.Fa flags -argument may be specified as follows: -.Bd -literal -MS_ASYNC Return immediately -MS_SYNC Perform synchronous writes -MS_INVALIDATE Invalidate all cached data -.Ed -.Sh RETURN VALUES -If any errors occur, -1 is returned and errno is set to indicate the -error. -Otherwise, a 0 value is returned. -.Sh ERRORS -.Fn msync -will fail if: -.Bl -tag -width Er -.It Bq Er EINVAL -.Fa addr -is not a multiple of the hardware page size. -.It Bq Er EINVAL -.Fa len -is too large or negative. -.It Bq Er EINVAL -.Fa flags -was both MS_ASYNC and MS_INVALIDATE. -Only one of these flags is allowed. -.It Bq Er EIO -An I/O error occurred while writing to the file system. -.Sh SEE ALSO -.Xr madvise 2 , -.Xr mincore 2 , -.Xr mprotect 2 , -.Xr munmap 2 -.Sh HISTORY -The -.Fn msync -function first appeared in -.Bx 4.4 . diff --git a/sys.subproj/ppc.subproj/ATPgetreq.s b/sys.subproj/ppc.subproj/ATPgetreq.s deleted file mode 100644 index 3033717..0000000 --- a/sys.subproj/ppc.subproj/ATPgetreq.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(ATPgetreq, 3) - blr - diff --git a/sys.subproj/ppc.subproj/ATPgetrsp.s b/sys.subproj/ppc.subproj/ATPgetrsp.s deleted file mode 100644 index f5f25ab..0000000 --- a/sys.subproj/ppc.subproj/ATPgetrsp.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(ATPgetrsp, 3) - blr - diff --git a/sys.subproj/ppc.subproj/ATPsndreq.s b/sys.subproj/ppc.subproj/ATPsndreq.s deleted file mode 100644 index 076c33f..0000000 --- a/sys.subproj/ppc.subproj/ATPsndreq.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(ATPsndreq, 3) - blr - diff --git a/sys.subproj/ppc.subproj/ATPsndrsp.s b/sys.subproj/ppc.subproj/ATPsndrsp.s deleted file mode 100644 index 00cca6d..0000000 --- a/sys.subproj/ppc.subproj/ATPsndrsp.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(ATPsndrsp, 3) - blr - diff --git a/sys.subproj/ppc.subproj/ATgetmsg.s b/sys.subproj/ppc.subproj/ATgetmsg.s deleted file mode 100644 index 529a298..0000000 --- a/sys.subproj/ppc.subproj/ATgetmsg.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(ATgetmsg, 3) - blr - diff --git a/sys.subproj/ppc.subproj/ATputmsg.s b/sys.subproj/ppc.subproj/ATputmsg.s deleted file mode 100644 index 61e085f..0000000 --- a/sys.subproj/ppc.subproj/ATputmsg.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(ATputmsg, 3) - blr - diff --git a/sys.subproj/ppc.subproj/ATsocket.s b/sys.subproj/ppc.subproj/ATsocket.s deleted file mode 100644 index f53d7d0..0000000 --- a/sys.subproj/ppc.subproj/ATsocket.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(ATsocket, 3) - blr - diff --git a/sys.subproj/ppc.subproj/Makefile b/sys.subproj/ppc.subproj/Makefile deleted file mode 100644 index 633178e..0000000 --- a/sys.subproj/ppc.subproj/Makefile +++ /dev/null @@ -1,132 +0,0 @@ -# -# Generated by the Apple Project Builder. -# -# NOTE: Do NOT change this file -- Project Builder maintains it. -# -# Put all of your customizations in files called Makefile.preamble -# and Makefile.postamble (both optional), and Makefile will include them. -# - -NAME = ppc - -PROJECTVERSION = 2.8 -PROJECT_TYPE = Component - -HFILES = assym.h genassym.h _setjmp.h SYS.h processor_facilities.h - -OTHERLINKED = ATsocket.s ATgetmsg.s ATputmsg.s ATPsndreq.s ATPsndrsp.s\ - ATPgetreq.s ATPgetrsp.s accept.s access.s acct.s\ - add_profil.s adjtime.s bind.s cerror.s chdir.s\ - checkuseraccess.s chflags.s chmod.s chown.s chroot.s\ - close.s connect.s cthread.s dup.s dup2.s exchangedata.s\ - execve.s _exit.s fchdir.s fchflags.s fchmod.s fchown.s\ - fcntl.s flock.s fork.s fpathconf.s fstat.s fstatfs.s\ - fstatv.s fsync.s ftruncate.s getattrlist.s\ - getdirentries.s getdirentriesattr.s getegid.s geteuid.s\ - getfh.s getfsstat.s getgid.s getgroups.s getitimer.s\ - _getlogin.s getpeername.s getpgrp.s getpid.s getppid.s\ - getpriority.s getrlimit.s getrusage.s getsockname.s\ - getsockopt.s getuid.s ioctl.s kill.s ktrace.s\ - lfs_bmapv.s lfs_markv.s lfs_segclean.s lfs_segwait.s\ - link.s listen.s longjmp.s _longjmp.s lseek.s lstat.s\ - lstatv.s madvise.s mincore.s minherit.s mkcomplex.s\ - mkdir.s mkfifo.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\ - nfssvc.s open.s pathconf.s pipe.s profil.s ptrace.s\ - quota.s quotactl.s read.s readlink.s readv.s reboot.s\ - recvfrom.s recvmsg.s rename.s revoke.s rmdir.s\ - searchfs.s select.s semconfig.s semctl.s semget.s\ - semop.s semsys.s sendmsg.s sendto.s setattrlist.s\ - setegid.s seteuid.s setgid.s setgroups.s setitimer.s\ - setjmp.s _setjmp.s _setlogin.s setpgid.s setpriority.s\ - setprivexec.s setquota.s setrlimit.s setsid.s\ - setsockopt.s settimeofday.s setuid.s shmat.s shmctl.s\ - shmdt.s shmget.s shmsys.s shm_open.s shm_unlink.s\ - shutdown.s sigaltstack.s sigpending.s sigreturn.s\ - socket.s socketpair.s stat.s statfs.s statv.s swapon.s\ - symlink.s sync.s syscall.s _sysctl.s table.s truncate.s\ - umask.s undelete.s unlink.s unmount.s ur_cthread.s\ - utimes.s vfork.s wait4.s write.s writev.s sem_close.s\ - sem_destroy.s sem_getvalue.s sem_init.s sem_open.s\ - sem_post.s sem_trywait.s sem_unlink.s sem_wait.s\ - processor_facilities.s load_shared_file.s reset_shared_file.s - -OTHERSRCS = Makefile.preamble Makefile Makefile.postamble - -OTHERLINKEDOFILES = ATsocket.o ATgetmsg.o ATputmsg.o ATPsndreq.o\ - ATPsndrsp.o ATPgetreq.o ATPgetrsp.o accept.o\ - access.o acct.o add_profil.o adjtime.o bind.o\ - cerror.o chdir.o checkuseraccess.o chflags.o\ - chmod.o chown.o chroot.o close.o connect.o\ - cthread.o dup.o dup2.o exchangedata.o execve.o\ - _exit.o fchdir.o fchflags.o fchmod.o fchown.o\ - fcntl.o flock.o fork.o fpathconf.o fstat.o\ - fstatfs.o fstatv.o fsync.o ftruncate.o\ - getattrlist.o getdirentries.o getdirentriesattr.o\ - getegid.o geteuid.o getfh.o getfsstat.o getgid.o\ - getgroups.o getitimer.o _getlogin.o getpeername.o\ - getpgrp.o getpid.o getppid.o getpriority.o\ - getrlimit.o getrusage.o getsockname.o getsockopt.o\ - getuid.o ioctl.o kill.o ktrace.o lfs_bmapv.o\ - lfs_markv.o lfs_segclean.o lfs_segwait.o link.o\ - listen.o longjmp.o _longjmp.o lseek.o lstat.o\ - lstatv.o madvise.o mincore.o minherit.o\ - mkcomplex.o mkdir.o mkfifo.o mknod.o mlock.o\ - mlockall.o mmap.o mount.o mprotect.o msgctl.o\ - msgget.o msgrcv.o msgsnd.o msgsys.o msync.o\ - munlock.o munlockall.o munmap.o nfssvc.o open.o\ - pathconf.o pipe.o profil.o ptrace.o quota.o\ - quotactl.o read.o readlink.o readv.o reboot.o\ - recvfrom.o recvmsg.o rename.o revoke.o rmdir.o\ - searchfs.o select.o semconfig.o semctl.o semget.o\ - semop.o semsys.o sendmsg.o sendto.o setattrlist.o\ - setegid.o seteuid.o setgid.o setgroups.o\ - setitimer.o setjmp.o _setjmp.o _setlogin.o\ - setpgid.o setpriority.o setprivexec.o setquota.o\ - setrlimit.o setsid.o setsockopt.o settimeofday.o\ - setuid.o shmat.o shmctl.o shmdt.o shmget.o\ - shmsys.o shm_open.o shm_unlink.o shutdown.o\ - sigaltstack.o sigpending.o sigreturn.o socket.o\ - socketpair.o stat.o statfs.o statv.o swapon.o\ - symlink.o sync.o syscall.o _sysctl.o table.o\ - truncate.o umask.o undelete.o unlink.o unmount.o\ - ur_cthread.o utimes.o vfork.o wait4.o write.o\ - writev.o sem_close.o sem_destroy.o sem_getvalue.o\ - sem_init.o sem_open.o sem_post.o sem_trywait.o\ - sem_unlink.o sem_wait.o processor_facilities.o\ - load_shared_file.o reset_shared_file.o - -MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles -CODE_GEN_STYLE = DYNAMIC -MAKEFILE = subproj.make -NEXTSTEP_INSTALLDIR = /AppleInternal/Developer/System -LIBS = -DEBUG_LIBS = $(LIBS) -PROF_LIBS = $(LIBS) - - -PUBLIC_HEADERS = processor_facilities.h - - - -NEXTSTEP_BUILD_OUTPUT_DIR = /Local/Public/SandBox/$(USER)/BUILD/$(NAME) - -NEXTSTEP_PUBLIC_HEADERS_DIR = /usr/include - -NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc -WINDOWS_OBJCPLUS_COMPILER = $(DEVDIR)/gcc -PDO_UNIX_OBJCPLUS_COMPILER = $(NEXTDEV_BIN)/gcc -NEXTSTEP_JAVA_COMPILER = /usr/bin/javac -WINDOWS_JAVA_COMPILER = $(JDKBINDIR)/javac.exe -PDO_UNIX_JAVA_COMPILER = $(JDKBINDIR)/javac - -include $(MAKEFILEDIR)/platform.make - --include Makefile.preamble - -include $(MAKEFILEDIR)/$(MAKEFILE) - --include Makefile.postamble - --include Makefile.dependencies diff --git a/sys.subproj/ppc.subproj/Makefile.postamble b/sys.subproj/ppc.subproj/Makefile.postamble deleted file mode 100644 index 411cde6..0000000 --- a/sys.subproj/ppc.subproj/Makefile.postamble +++ /dev/null @@ -1,100 +0,0 @@ -############################################################################### -# Makefile.postamble -# Copyright 1997, Apple Computer, Inc. -# -# Use this makefile, which is imported after all other makefiles, to -# override attributes for a project's Makefile environment. This allows you -# to take advantage of the environment set up by the other Makefiles. -# You can also define custom rules at the end of this file. -# -############################################################################### -# -# These variables are exported by the standard makefiles and can be -# used in any customizations you make. They are *outputs* of -# the Makefiles and should be used, not set. -# -# PRODUCTS: products to install. All of these products will be placed in -# the directory $(DSTROOT)$(INSTALLDIR) -# GLOBAL_RESOURCE_DIR: The directory to which resources are copied. -# LOCAL_RESOURCE_DIR: The directory to which localized resources are copied. -# OFILE_DIR: Directory into which .o object files are generated. -# DERIVED_SRC_DIR: Directory used for all other derived files -# -# ALL_CFLAGS: flags to pass when compiling .c files -# ALL_MFLAGS: flags to pass when compiling .m files -# ALL_CCFLAGS: flags to pass when compiling .cc, .cxx, and .C files -# ALL_MMFLAGS: flags to pass when compiling .mm, .mxx, and .M files -# ALL_PRECOMPFLAGS: flags to pass when precompiling .h files -# ALL_LDFLAGS: flags to pass when linking object files -# ALL_LIBTOOL_FLAGS: flags to pass when libtooling object files -# ALL_PSWFLAGS: flags to pass when processing .psw and .pswm (pswrap) files -# ALL_RPCFLAGS: flags to pass when processing .rpc (rpcgen) files -# ALL_YFLAGS: flags to pass when processing .y (yacc) files -# ALL_LFLAGS: flags to pass when processing .l (lex) files -# -# NAME: name of application, bundle, subproject, palette, etc. -# LANGUAGES: langages in which the project is written (default "English") -# English_RESOURCES: localized resources (e.g. nib's, images) of project -# GLOBAL_RESOURCES: non-localized resources of project -# -# SRCROOT: base directory in which to place the new source files -# SRCPATH: relative path from SRCROOT to present subdirectory -# -# INSTALLDIR: Directory the product will be installed into by 'install' target -# PUBLIC_HDR_INSTALLDIR: where to install public headers. Don't forget -# to prefix this with DSTROOT when you use it. -# PRIVATE_HDR_INSTALLDIR: where to install private headers. Don't forget -# to prefix this with DSTROOT when you use it. -# -# EXECUTABLE_EXT: Executable extension for the platform (i.e. .exe on Windows) -# -############################################################################### - -# Some compiler flags can be overridden here for certain build situations. -# -# WARNING_CFLAGS: flag used to set warning level (defaults to -Wmost) -# DEBUG_SYMBOLS_CFLAGS: debug-symbol flag passed to all builds (defaults -# to -g) -# DEBUG_BUILD_CFLAGS: flags passed during debug builds (defaults to -DDEBUG) -# OPTIMIZE_BUILD_CFLAGS: flags passed during optimized builds (defaults -# to -O) -# PROFILE_BUILD_CFLAGS: flags passed during profile builds (defaults -# to -pg -DPROFILE) -# LOCAL_DIR_INCLUDE_DIRECTIVE: flag used to add current directory to -# the include path (defaults to -I.) -# DEBUG_BUILD_LDFLAGS, OPTIMIZE_BUILD_LDFLAGS, PROFILE_BUILD_LDFLAGS: flags -# passed to ld/libtool (defaults to nothing) - - -# Library and Framework projects only: -# INSTALL_NAME_DIRECTIVE: This directive ensures that executables linked -# against the framework will run against the correct version even if -# the current version of the framework changes. You may override this -# to "" as an alternative to using the DYLD_LIBRARY_PATH during your -# development cycle, but be sure to restore it before installing. - - -# Ownership and permissions of files installed by 'install' target - -#INSTALL_AS_USER = root - # User/group ownership -#INSTALL_AS_GROUP = wheel - # (probably want to set both of these) -#INSTALL_PERMISSIONS = - # If set, 'install' chmod's executable to this - - -# Options to strip. Note: -S strips debugging symbols (executables can be stripped -# down further with -x or, if they load no bundles, with no options at all). - -#STRIPFLAGS = -S - - -######################################################################### -# Put rules to extend the behavior of the standard Makefiles here. Include them in -# the dependency tree via cvariables like AFTER_INSTALL in the Makefile.preamble. -# -# You should avoid redefining things like "install" or "app", as they are -# owned by the top-level Makefile API and no context has been set up for where -# derived files should go. -# diff --git a/sys.subproj/ppc.subproj/Makefile.preamble b/sys.subproj/ppc.subproj/Makefile.preamble deleted file mode 100644 index e7c0be7..0000000 --- a/sys.subproj/ppc.subproj/Makefile.preamble +++ /dev/null @@ -1,138 +0,0 @@ -############################################################################### -# Makefile.preamble -# Copyright 1997, Apple Computer, Inc. -# -# Use this makefile for configuring the standard application makefiles -# associated with ProjectBuilder. It is included before the main makefile. -# In Makefile.preamble you set attributes for a project, so they are available -# to the project's makefiles. In contrast, you typically write additional rules or -# override built-in behavior in the Makefile.postamble. -# -# Each directory in a project tree (main project plus subprojects) should -# have its own Makefile.preamble and Makefile.postamble. -############################################################################### -# -# Before the main makefile is included for this project, you may set: -# -# MAKEFILEDIR: Directory in which to find $(MAKEFILE) -# MAKEFILE: Top level mechanism Makefile (e.g., app.make, bundle.make) - -# Compiler/linker flags added to the defaults: The OTHER_* variables will be -# inherited by all nested sub-projects, but the LOCAL_ versions of the same -# variables will not. Put your -I, -D, -U, and -L flags in ProjectBuilder's -# Build Attributes inspector if at all possible. To override the default flags -# that get passed to ${CC} (e.g. change -O to -O2), see Makefile.postamble. The -# variables below are *inputs* to the build process and distinct from the override -# settings done (less often) in the Makefile.postamble. -# -# OTHER_CFLAGS, LOCAL_CFLAGS: additional flags to pass to the compiler -# Note that $(OTHER_CFLAGS) and $(LOCAL_CFLAGS) are used for .h, ...c, .m, -# .cc, .cxx, .C, and .M files. There is no need to respecify the -# flags in OTHER_MFLAGS, etc. -# OTHER_MFLAGS, LOCAL_MFLAGS: additional flags for .m files -# OTHER_CCFLAGS, LOCAL_CCFLAGS: additional flags for .cc, .cxx, and ...C files -# OTHER_MMFLAGS, LOCAL_MMFLAGS: additional flags for .mm and .M files -# OTHER_PRECOMPFLAGS, LOCAL_PRECOMPFLAGS: additional flags used when -# precompiling header files -# OTHER_LDFLAGS, LOCAL_LDFLAGS: additional flags passed to ld and libtool -# OTHER_PSWFLAGS, LOCAL_PSWFLAGS: additional flags passed to pswrap -# OTHER_RPCFLAGS, LOCAL_RPCFLAGS: additional flags passed to rpcgen -# OTHER_YFLAGS, LOCAL_YFLAGS: additional flags passed to yacc -# OTHER_LFLAGS, LOCAL_LFLAGS: additional flags passed to lex - -# These variables provide hooks enabling you to add behavior at almost every -# stage of the make: -# -# BEFORE_PREBUILD: targets to build before installing headers for a subproject -# AFTER_PREBUILD: targets to build after installing headers for a subproject -# BEFORE_BUILD_RECURSION: targets to make before building subprojects -# BEFORE_BUILD: targets to make before a build, but after subprojects -# AFTER_BUILD: targets to make after a build -# -# BEFORE_INSTALL: targets to build before installing the product -# AFTER_INSTALL: targets to build after installing the product -# BEFORE_POSTINSTALL: targets to build before postinstalling every subproject -# AFTER_POSTINSTALL: targts to build after postinstalling every subproject -# -# BEFORE_INSTALLHDRS: targets to build before installing headers for a -# subproject -# AFTER_INSTALLHDRS: targets to build after installing headers for a subproject -# BEFORE_INSTALLSRC: targets to build before installing source for a subproject -# AFTER_INSTALLSRC: targets to build after installing source for a subproject -# -# BEFORE_DEPEND: targets to build before building dependencies for a -# subproject -# AFTER_DEPEND: targets to build after building dependencies for a -# subproject -# -# AUTOMATIC_DEPENDENCY_INFO: if YES, then the dependency file is -# updated every time the project is built. If NO, the dependency -# file is only built when the depend target is invoked. - -# Framework-related variables: -# FRAMEWORK_DLL_INSTALLDIR: On Windows platforms, this variable indicates -# where to put the framework's DLL. This variable defaults to -# $(INSTALLDIR)/../Executables - -# Library-related variables: -# PUBLIC_HEADER_DIR: Determines where public exported header files -# should be installed. Do not include $(DSTROOT) in this value -- -# it is prefixed automatically. For library projects you should -# set this to something like /Developer/Headers/$(NAME). Do not set -# this variable for framework projects unless you do not want the -# header files included in the framework. -PUBLIC_HEADER_DIR := $(SYSTEM_LIBRARY_DIR)/Frameworks/System.framework/Versions/B/PrivateHeaders/architecture/ppc -# PRIVATE_HEADER_DIR: Determines where private exported header files -# should be installed. Do not include $(DSTROOT) in this value -- -# it is prefixed automatically. -# LIBRARY_STYLE: This may be either STATIC or DYNAMIC, and determines -# whether the libraries produced are statically linked when they -# are used or if they are dynamically loadable. This defaults to -# DYNAMIC. -# LIBRARY_DLL_INSTALLDIR: On Windows platforms, this variable indicates -# where to put the library's DLL. This variable defaults to -# $(INSTALLDIR)/../Executables -# -# INSTALL_AS_USER: owner of the intalled products (default root) -# INSTALL_AS_GROUP: group of the installed products (default wheel) -# INSTALL_PERMISSIONS: permissions of the installed product (default o+rX) -# -# OTHER_RECURSIVE_VARIABLES: The names of variables which you want to be -# passed on the command line to recursive invocations of make. Note that -# the values in OTHER_*FLAGS are inherited by subprojects automatically -- -# you do not have to (and shouldn't) add OTHER_*FLAGS to -# OTHER_RECURSIVE_VARIABLES. - -# Additional headers to export beyond those in the PB.project: -# OTHER_PUBLIC_HEADERS -# OTHER_PROJECT_HEADERS -# OTHER_PRIVATE_HEADERS - -# Additional files for the project's product: <> -# OTHER_RESOURCES: (non-localized) resources for this project -# OTHER_OFILES: relocatables to be linked into this project -# OTHER_LIBS: more libraries to link against -# OTHER_PRODUCT_DEPENDS: other dependencies of this project -# OTHER_SOURCEFILES: other source files maintained by .pre/postamble -# OTHER_GARBAGE: additional files to be removed by `make clean' - -# Set this to YES if you don't want a final libtool call for a library/framework. -# BUILD_OFILES_LIST_ONLY - -# To include a version string, project source must exist in a directory named -# $(NAME).%d[.%d][.%d] and the following line must be uncommented. -# OTHER_GENERATED_OFILES = $(VERS_OFILE) - -# This definition will suppress stripping of debug symbols when an executable -# is installed. By default it is YES. -# STRIP_ON_INSTALL = NO - -# Uncomment to suppress generation of a KeyValueCoding index when installing -# frameworks (This index is used by WOB and IB to determine keys available -# for an object). Set to YES by default. -# PREINDEX_FRAMEWORK = NO - -# Change this definition to install projects somewhere other than the -# standard locations. NEXT_ROOT defaults to "C:/Apple" on Windows systems -# and "" on other systems. -INCLUDED_ARCHS = ppc diff --git a/sys.subproj/ppc.subproj/PB.project b/sys.subproj/ppc.subproj/PB.project deleted file mode 100644 index 2359ad6..0000000 --- a/sys.subproj/ppc.subproj/PB.project +++ /dev/null @@ -1,216 +0,0 @@ -{ - DYNAMIC_CODE_GEN = YES; - FILESTABLE = { - H_FILES = (assym.h, genassym.h, _setjmp.h, SYS.h, processor_facilities.h); - OTHER_LINKED = ( - ATsocket.s, - ATgetmsg.s, - ATputmsg.s, - ATPsndreq.s, - ATPsndrsp.s, - ATPgetreq.s, - ATPgetrsp.s, - accept.s, - access.s, - acct.s, - add_profil.s, - adjtime.s, - bind.s, - cerror.s, - chdir.s, - checkuseraccess.s, - chflags.s, - chmod.s, - chown.s, - chroot.s, - close.s, - connect.s, - cthread.s, - dup.s, - dup2.s, - exchangedata.s, - execve.s, - _exit.s, - fchdir.s, - fchflags.s, - fchmod.s, - fchown.s, - fcntl.s, - flock.s, - fork.s, - fpathconf.s, - fstat.s, - fstatfs.s, - fstatv.s, - fsync.s, - ftruncate.s, - getattrlist.s, - getdirentries.s, - getdirentriesattr.s, - getegid.s, - geteuid.s, - getfh.s, - getfsstat.s, - getgid.s, - getgroups.s, - getitimer.s, - _getlogin.s, - getpeername.s, - getpgrp.s, - getpid.s, - getppid.s, - getpriority.s, - getrlimit.s, - getrusage.s, - getsockname.s, - getsockopt.s, - getuid.s, - ioctl.s, - kill.s, - ktrace.s, - lfs_bmapv.s, - lfs_markv.s, - lfs_segclean.s, - lfs_segwait.s, - link.s, - listen.s, - longjmp.s, - _longjmp.s, - lseek.s, - lstat.s, - lstatv.s, - madvise.s, - mincore.s, - minherit.s, - mkcomplex.s, - mkdir.s, - mkfifo.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, - nfssvc.s, - open.s, - pathconf.s, - pipe.s, - profil.s, - ptrace.s, - quota.s, - quotactl.s, - read.s, - readlink.s, - readv.s, - reboot.s, - recvfrom.s, - recvmsg.s, - rename.s, - revoke.s, - rmdir.s, - searchfs.s, - select.s, - semconfig.s, - semctl.s, - semget.s, - semop.s, - semsys.s, - sendmsg.s, - sendto.s, - setattrlist.s, - setegid.s, - seteuid.s, - setgid.s, - setgroups.s, - setitimer.s, - setjmp.s, - _setjmp.s, - _setlogin.s, - setpgid.s, - setpriority.s, - setprivexec.s, - setquota.s, - setrlimit.s, - setsid.s, - setsockopt.s, - settimeofday.s, - setuid.s, - shmat.s, - shmctl.s, - shmdt.s, - shmget.s, - shmsys.s, - shm_open.s, - shm_unlink.s, - shutdown.s, - sigaltstack.s, - sigpending.s, - sigreturn.s, - socket.s, - socketpair.s, - stat.s, - statfs.s, - statv.s, - swapon.s, - symlink.s, - sync.s, - syscall.s, - _sysctl.s, - table.s, - truncate.s, - umask.s, - undelete.s, - unlink.s, - unmount.s, - ur_cthread.s, - utimes.s, - vfork.s, - wait4.s, - write.s, - writev.s, - sem_close.s, - sem_destroy.s, - sem_getvalue.s, - sem_init.s, - sem_open.s, - sem_post.s, - sem_trywait.s, - sem_unlink.s, - sem_wait.s, - processor_facilities.s, - load_shared_file.s, - reset_shared_file.s - ); - OTHER_SOURCES = (Makefile.preamble, Makefile, Makefile.postamble); - PRECOMPILED_HEADERS = (); - PROJECT_HEADERS = (); - PUBLIC_HEADERS = (processor_facilities.h); - SUBPROJECTS = (); - }; - LANGUAGE = English; - MAKEFILEDIR = "$(MAKEFILEPATH)/pb_makefiles"; - NEXTSTEP_BUILDDIR = "/Local/Public/SandBox/$(USER)/BUILD/$(NAME)"; - NEXTSTEP_BUILDTOOL = /bin/gnumake; - NEXTSTEP_INSTALLDIR = /AppleInternal/Developer/System; - NEXTSTEP_JAVA_COMPILER = /usr/bin/javac; - NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc; - NEXTSTEP_PUBLICHEADERSDIR = /usr/include; - PDO_UNIX_BUILDTOOL = $NEXT_ROOT/Developer/bin/make; - PDO_UNIX_JAVA_COMPILER = "$(JDKBINDIR)/javac"; - PDO_UNIX_OBJCPLUS_COMPILER = "$(NEXTDEV_BIN)/gcc"; - PROJECTNAME = ppc; - PROJECTTYPE = Component; - PROJECTVERSION = 2.8; - WINDOWS_BUILDTOOL = $NEXT_ROOT/Developer/Executables/make; - WINDOWS_JAVA_COMPILER = "$(JDKBINDIR)/javac.exe"; - WINDOWS_OBJCPLUS_COMPILER = "$(DEVDIR)/gcc"; -} diff --git a/sys.subproj/ppc.subproj/SYS.h b/sys.subproj/ppc.subproj/SYS.h deleted file mode 100644 index 7a56a8e..0000000 --- a/sys.subproj/ppc.subproj/SYS.h +++ /dev/null @@ -1,163 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* Copyright (c) 1992 NeXT Computer, Inc. All rights reserved. - * - * File: SYS.h - * - * Definition of the user side of the UNIX system call interface - * for M98K. - * - * Errors are flagged by the location of the trap return (ie., which - * instruction is executed upon rfi): - * - * SC PC + 4: Error (typically branch to cerror()) - * SC PC + 8: Success - * - * HISTORY - * 18-Nov-92 Ben Fathi (benf@next.com) - * Ported to m98k. - * - * 9-Jan-92 Peter King (king@next.com) - * Created. - */ - -#define KERNEL_PRIVATE 1 -/* - * Header files. - */ -#import -#import -#import -#import - -/* From rhapsody kernel mach/ppc/syscall_sw.h */ -#define kernel_trap_args_0 -#define kernel_trap_args_1 -#define kernel_trap_args_2 -#define kernel_trap_args_3 -#define kernel_trap_args_4 -#define kernel_trap_args_5 -#define kernel_trap_args_6 -#define kernel_trap_args_7 - -/* - * simple_kernel_trap -- Mach system calls with 8 or less args - * Args are passed in a0 - a7, system call number in r0. - * Do a "sc" instruction to enter kernel. - */ -#define simple_kernel_trap(trap_name, trap_number) \ - .globl _##trap_name @\ -_##trap_name: @\ - li r0,trap_number @\ - sc @\ - blr @\ - END(trap_name) - -#define kernel_trap_0(trap_name,trap_number) \ - simple_kernel_trap(trap_name,trap_number) - -#define kernel_trap_1(trap_name,trap_number) \ - simple_kernel_trap(trap_name,trap_number) - -#define kernel_trap_2(trap_name,trap_number) \ - simple_kernel_trap(trap_name,trap_number) - -#define kernel_trap_3(trap_name,trap_number) \ - simple_kernel_trap(trap_name,trap_number) - -#define kernel_trap_4(trap_name,trap_number) \ - simple_kernel_trap(trap_name,trap_number) - -#define kernel_trap_5(trap_name,trap_number) \ - simple_kernel_trap(trap_name,trap_number) - -#define kernel_trap_6(trap_name,trap_number) \ - simple_kernel_trap(trap_name,trap_number) - -#define kernel_trap_7(trap_name,trap_number) \ - simple_kernel_trap(trap_name,trap_number) - -#define kernel_trap_8(trap_name,trap_number) \ - simple_kernel_trap(trap_name,trap_number) - -#define kernel_trap_9(trap_name,trap_number) \ - simple_kernel_trap(trap_name,trap_number) - -/* End of rhapsody kernel mach/ppc/syscall_sw.h */ - -/* - * Macros. - */ - -#define SYSCALL(name, nargs) \ - .globl cerror @\ -LEAF(_##name) @\ - kernel_trap_args_##nargs @\ - li r0,SYS_##name @\ - sc @\ - b 1f @\ - b 2f @\ -1: BRANCH_EXTERN(cerror) @\ -.text \ -2: nop - -#define SYSCALL_NONAME(name, nargs) \ - .globl cerror @\ - kernel_trap_args_##nargs @\ - li r0,SYS_##name @\ - sc @\ - b 1f @\ - b 2f @\ -1: BRANCH_EXTERN(cerror) @\ -.text \ -2: nop - -#define PSEUDO(pseudo, name, nargs) \ -LEAF(_##pseudo) @\ - SYSCALL_NONAME(name, nargs) - - -#undef END -#import - -#if !defined(SYS_getdirentriesattr) -#define SYS_getdirentriesattr 222 -#endif - -#if !defined(SYS_semsys) -#define SYS_semsys 251 -#define SYS_msgsys 252 -#define SYS_shmsys 253 -#define SYS_semctl 254 -#define SYS_semget 255 -#define SYS_semop 256 -#define SYS_semconfig 257 -#define SYS_msgctl 258 -#define SYS_msgget 259 -#define SYS_msgsnd 260 -#define SYS_msgrcv 261 -#define SYS_shmat 262 -#define SYS_shmctl 263 -#define SYS_shmdt 264 -#define SYS_shmget 265 -#endif - diff --git a/sys.subproj/ppc.subproj/_exit.s b/sys.subproj/ppc.subproj/_exit.s deleted file mode 100644 index fd3a59e..0000000 --- a/sys.subproj/ppc.subproj/_exit.s +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -PSEUDO(_exit, exit, 1) - blr diff --git a/sys.subproj/ppc.subproj/_getlogin.s b/sys.subproj/ppc.subproj/_getlogin.s deleted file mode 100644 index e0eb958..0000000 --- a/sys.subproj/ppc.subproj/_getlogin.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -PSEUDO(_getlogin, getlogin, 0) - blr - diff --git a/sys.subproj/ppc.subproj/_longjmp.s b/sys.subproj/ppc.subproj/_longjmp.s deleted file mode 100644 index 6bdeb02..0000000 --- a/sys.subproj/ppc.subproj/_longjmp.s +++ /dev/null @@ -1,224 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ - -/* void _longjmp(jmp_buf env, int val); */ - -/* int _longjmp(jmp_buf env); */ -/* - * Copyright (c) 1998 Apple Computer, Inc. All rights reserved. - * - * File: sys/ppc/_longjmp.s - * - * Implements _longjmp() - * - * History: - * 8 September 1998 Matt Watson (mwatson@apple.com) - * Created. Derived from longjmp.s - */ - -#include -#include "_setjmp.h" - -#define VRSave 256 - -/* special flag bit definitions copied from /osfmk/ppc/thread_act.h */ - -#define floatUsedbit 1 -#define vectorUsedbit 2 - - -#if defined(__DYNAMIC__) - .data - .non_lazy_symbol_pointer - .align 2 -L_memmove$non_lazy_ptr: - .indirect_symbol _memmove - .long 0 - .non_lazy_symbol_pointer - .align 2 -L__cpu_has_altivec$non_lazy_ptr: - .indirect_symbol __cpu_has_altivec - .long 0 - .text -#endif - -LEAF(__longjmp) - - ; need to restore FPRs or VRs? - - lwz r5,JMP_flags(r3) - lwz r6,JMP_addr_at_setjmp(r3) - rlwinm r7,r5,0,vectorUsedbit,vectorUsedbit - rlwinm r8,r5,0,floatUsedbit,floatUsedbit - cmpw cr1,r3,r6 ; jmp_buf still at same address? - cmpwi cr3,r7,0 ; set cr3 iff VRs in use (non-volatile CR) - cmpwi cr4,r8,0 ; set cr4 iff FPRs in use (non-volatile CR) - beq+ cr1,LRestoreVRs - - ; jmp_buf was moved since setjmp (or is uninitialized.) - ; We must move VRs and FPRs to be quadword aligned at present address. - - stw r3,JMP_addr_at_setjmp(r3) ; update, in case we longjmp to this again - mr r31,r4 ; save "val" arg across memmove - mr r30,r3 ; and jmp_buf ptr - addi r3,r3,JMP_vr_base_addr - addi r4,r6,JMP_vr_base_addr - rlwinm r3,r3,0,0,27 ; r3 <- QW aligned addr where they should be - rlwinm r4,r4,0,0,27 ; r4 <- QW aligned addr where they originally were - sub r7,r4,r6 ; r7 <- offset of VRs/FPRs within jmp_buf - add r4,r30,r7 ; r4 <- where they are now - li r5,(JMP_buf_end - JMP_vr_base_addr) -#if defined(__DYNAMIC__) - bcl 20,31,1f ; Get pic-base -1: mflr r12 - addis r12, r12, ha16(L_memmove$non_lazy_ptr - 1b) - lwz r12, lo16(L_memmove$non_lazy_ptr - 1b)(r12) - mtctr r12 ; Get address left by dyld - bctrl -#else - bl _memmove -#endif - mr r3,r30 - mr r4,r31 - - ; Restore VRs iff any - ; cr3 - bne if VRs - ; cr4 - bne if FPRs - -LRestoreVRs: - beq+ cr3,LZeroVRSave ; no VRs - lwz r0,JMP_vrsave(r3) - addi r6,r3,JMP_vr_base_addr - cmpwi r0,0 ; any live VRs? - mtspr VRSave,r0 - beq+ LRestoreFPRs - lvx v20,0,r6 - li r7,16*1 - lvx v21,r7,r6 - li r7,16*2 - lvx v22,r7,r6 - li r7,16*3 - lvx v23,r7,r6 - li r7,16*4 - lvx v24,r7,r6 - li r7,16*5 - lvx v25,r7,r6 - li r7,16*6 - lvx v26,r7,r6 - li r7,16*7 - lvx v27,r7,r6 - li r7,16*8 - lvx v28,r7,r6 - li r7,16*9 - lvx v29,r7,r6 - li r7,16*10 - lvx v30,r7,r6 - li r7,16*11 - lvx v31,r7,r6 - b LRestoreFPRs ; skip zeroing VRSave - - ; Zero VRSave iff Altivec is supported, but VRs were not in use - ; at setjmp time. This covers the case where VRs are first used after - ; the setjmp but before the longjmp, and where VRSave is nonzero at - ; the longjmp. We need to zero it now, or it will always remain - ; nonzero since they are sticky bits. - -LZeroVRSave: -#if defined(__DYNAMIC__) - bcl 20,31,1f -1: mflr r9 ; get our address - addis r6,r9,ha16(L__cpu_has_altivec$non_lazy_ptr - 1b) - lwz r7,lo16(L__cpu_has_altivec$non_lazy_ptr - 1b)(r6) - lwz r7,0(r7) ; load the flag -#else - lis r7, ha16(__cpu_has_altivec) - lwz r7, lo16(__cpu_has_altivec)(r7) -#endif - cmpwi r7,0 - li r8,0 - beq LRestoreFPRs ; no Altivec, so skip - mtspr VRSave,r8 - - ; Restore FPRs if any - ; cr4 - bne iff FPRs - -LRestoreFPRs: - beq cr4,LRestoreGPRs ; FPRs not in use at setjmp - addi r6,r3,JMP_fp_base_addr - rlwinm r6,r6,0,0,27 ; mask off low 4 bits to qw align - lfd f14,0*8(r6) - lfd f15,1*8(r6) - lfd f16,2*8(r6) - lfd f17,3*8(r6) - lfd f18,4*8(r6) - lfd f19,5*8(r6) - lfd f20,6*8(r6) - lfd f21,7*8(r6) - lfd f22,8*8(r6) - lfd f23,9*8(r6) - lfd f24,10*8(r6) - lfd f25,11*8(r6) - lfd f26,12*8(r6) - lfd f27,13*8(r6) - lfd f28,14*8(r6) - lfd f29,15*8(r6) - lfd f30,16*8(r6) - lfd f31,17*8(r6) - - ; Restore GPRs - -LRestoreGPRs: - lwz r31, JMP_r31(r3) - /* r1, r14-r30 */ - lwz r1, JMP_r1 (r3) - lwz r2, JMP_r2 (r3) - lwz r13, JMP_r13(r3) - lwz r14, JMP_r14(r3) - lwz r15, JMP_r15(r3) - lwz r16, JMP_r16(r3) - lwz r17, JMP_r17(r3) - lwz r18, JMP_r18(r3) - lwz r19, JMP_r19(r3) - lwz r20, JMP_r20(r3) - lwz r21, JMP_r21(r3) - lwz r22, JMP_r22(r3) - lwz r23, JMP_r23(r3) - lwz r24, JMP_r24(r3) - lwz r25, JMP_r25(r3) - lwz r26, JMP_r26(r3) - lwz r27, JMP_r27(r3) - lwz r28, JMP_r28(r3) - lwz r29, JMP_r29(r3) - lwz r30, JMP_r30(r3) - lwz r0, JMP_cr(r3) - mtcrf 0xff,r0 - lwz r0, JMP_lr(r3) - mtlr r0 - lwz r0, JMP_ctr(r3) ; XXX ctr is volatile - mtctr r0 - lwz r0, JMP_xer(r3) ; XXX xer is volatile - mtxer r0 - mr. r3, r4 - bnelr - li r3, 1 - blr - diff --git a/sys.subproj/ppc.subproj/_setjmp.h b/sys.subproj/ppc.subproj/_setjmp.h deleted file mode 100644 index 8a78817..0000000 --- a/sys.subproj/ppc.subproj/_setjmp.h +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1998, Apple Computer Inc. All rights reserved. - * - * File: _setjmp.h - * - * Defines for register offsets in the save area. - * - */ - -/* NOTE: jmp_bufs are only 4-byte aligned. This means we - * need to pad before the VR and FPR save areas, so that they - * can be naturally aligned in the buffer. In case a jmp_buf - * is bcopy'd to a different alignment between the setjmp - * and longjmp, we need to save the jmp_buf address in the - * jmp_buf at setjmp time, so we can realign before reloading. - */ - -#define JMP_r1 0x00 -#define JMP_r2 0x04 -#define JMP_r13 0x08 -#define JMP_r14 0x0c -#define JMP_r15 0x10 -#define JMP_r16 0x14 -#define JMP_r17 0x18 -#define JMP_r18 0x1c -#define JMP_r19 0x20 -#define JMP_r20 0x24 -#define JMP_r21 0x28 -#define JMP_r22 0x2c -#define JMP_r23 0x30 -#define JMP_r24 0x34 -#define JMP_r25 0x38 -#define JMP_r26 0x3c -#define JMP_r27 0x40 -#define JMP_r28 0x44 -#define JMP_r29 0x48 -#define JMP_r30 0x4c -#define JMP_r31 0x50 -#define JMP_lr 0x54 -#define JMP_cr 0x58 -#define JMP_ctr 0x5c -#define JMP_xer 0x60 -#define JMP_sig 0x64 -#define JMP_SIGFLAG 0x68 -#define JMP_flags 0x6c -#define JMP_vrsave 0x70 -#define JMP_addr_at_setjmp 0x74 -/* 12 bytes padding here */ -#define JMP_vr_base_addr 0x84 -/* save room for 12 VRs (v20-v31), or 0xC0 bytes */ -#define JMP_fp_base_addr 0x144 -/* save room for 18 FPRs (f14-f31), or 0x90 bytes */ -#define JMP_buf_end 0x1d4 - diff --git a/sys.subproj/ppc.subproj/_setjmp.s b/sys.subproj/ppc.subproj/_setjmp.s deleted file mode 100644 index c69f9ad..0000000 --- a/sys.subproj/ppc.subproj/_setjmp.s +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ - -/* int _setjmp(jmp_buf env); */ -/* - * Copyright (c) 1998 Apple Computer, Inc. All rights reserved. - * - * File: sys/ppc/_setjmp.s - * - * Implements _setjmp() - * - * History: - * 8 September 1998 Matt Watson (mwatson@apple.com) - * Created. Derived from setjmp.s - */ - - -#include -#include "_setjmp.h" - -#define VRSave 256 - -/* special flag bit definitions copied from /osfmk/ppc/thread_act.h */ - -#define floatUsedbit 1 -#define vectorUsedbit 2 - -#define FlagsFastTrap 0x7FF3 - - -LEAF(__setjmp) - stw r31, JMP_r31(r3) - /* r1, r2, r13-r30 */ - stw r1, JMP_r1(r3) - stw r2, JMP_r2(r3) - stw r13, JMP_r13(r3) - stw r14, JMP_r14(r3) - stw r15, JMP_r15(r3) - stw r16, JMP_r16(r3) - stw r17, JMP_r17(r3) - stw r18, JMP_r18(r3) - stw r19, JMP_r19(r3) - stw r20, JMP_r20(r3) - stw r21, JMP_r21(r3) - stw r22, JMP_r22(r3) - mfcr r0 - stw r23, JMP_r23(r3) - stw r24, JMP_r24(r3) - mflr r5 - stw r25, JMP_r25(r3) - stw r26, JMP_r26(r3) - mfctr r6 ; XXX ctr is volatile - stw r27, JMP_r27(r3) - stw r28, JMP_r28(r3) - mfxer r7 ; XXX xer is volatile - stw r29, JMP_r29(r3) - stw r30, JMP_r30(r3) - stw r0, JMP_cr(r3) - stw r5, JMP_lr(r3) - stw r6, JMP_ctr(r3) - stw r7, JMP_xer(r3) - - mr r31,r3 ; save jmp_buf ptr - li r0,FlagsFastTrap - sc ; get FPR-inuse and VR-inuse flags from kernel - rlwinm r4,r3,0,floatUsedbit,floatUsedbit - rlwinm. r5,r3,0,vectorUsedbit,vectorUsedbit - cmpwi cr1,r4,0 ; set CR1 bne iff FPRs in use - stw r3,JMP_flags(r31) - stw r31,JMP_addr_at_setjmp(r31) - mr r3,r31 ; restore jmp_buf ptr - lwz r31,JMP_r31(r31) - beq LSaveFPRsIfNecessary ; skip if vectorUsedbit was 0 - - ; must save VRs and VRSAVE - - mfspr r4,VRSave - andi. r0,r4,0xFFF ; we only care about v20-v31 - stw r0,JMP_vrsave(r3) ; set up effective VRSAVE - beq LSaveFPRsIfNecessary ; no live non-volatile VRs - addi r6,r3,JMP_vr_base_addr - stvx v20,0,r6 - li r4,16*1 - stvx v21,r4,r6 - li r4,16*2 - stvx v22,r4,r6 - li r4,16*3 - stvx v23,r4,r6 - li r4,16*4 - stvx v24,r4,r6 - li r4,16*5 - stvx v25,r4,r6 - li r4,16*6 - stvx v26,r4,r6 - li r4,16*7 - stvx v27,r4,r6 - li r4,16*8 - stvx v28,r4,r6 - li r4,16*9 - stvx v29,r4,r6 - li r4,16*10 - stvx v30,r4,r6 - li r4,16*11 - stvx v31,r4,r6 - - ; must save FPRs if they are live in this thread - ; CR1 = bne iff FPRs are in use - -LSaveFPRsIfNecessary: - beq cr1,LExit ; FPRs not in use - addi r6,r3,JMP_fp_base_addr - rlwinm r6,r6,0,0,27 ; mask off low 4 bits to qw align - stfd f14,0*8(r6) - stfd f15,1*8(r6) - stfd f16,2*8(r6) - stfd f17,3*8(r6) - stfd f18,4*8(r6) - stfd f19,5*8(r6) - stfd f20,6*8(r6) - stfd f21,7*8(r6) - stfd f22,8*8(r6) - stfd f23,9*8(r6) - stfd f24,10*8(r6) - stfd f25,11*8(r6) - stfd f26,12*8(r6) - stfd f27,13*8(r6) - stfd f28,14*8(r6) - stfd f29,15*8(r6) - stfd f30,16*8(r6) - stfd f31,17*8(r6) - -LExit: - li r3, 0 - blr - diff --git a/sys.subproj/ppc.subproj/_setlogin.s b/sys.subproj/ppc.subproj/_setlogin.s deleted file mode 100644 index 997db69..0000000 --- a/sys.subproj/ppc.subproj/_setlogin.s +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -PSEUDO(_setlogin, setlogin, 0) - blr diff --git a/sys.subproj/ppc.subproj/_sysctl.s b/sys.subproj/ppc.subproj/_sysctl.s deleted file mode 100644 index 8e29463..0000000 --- a/sys.subproj/ppc.subproj/_sysctl.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(__sysctl, 6) - blr - diff --git a/sys.subproj/ppc.subproj/accept.s b/sys.subproj/ppc.subproj/accept.s deleted file mode 100644 index 672331c..0000000 --- a/sys.subproj/ppc.subproj/accept.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(accept, 3) - blr - diff --git a/sys.subproj/ppc.subproj/access.s b/sys.subproj/ppc.subproj/access.s deleted file mode 100644 index 5cd4fb9..0000000 --- a/sys.subproj/ppc.subproj/access.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(access, 2) - blr - diff --git a/sys.subproj/ppc.subproj/acct.s b/sys.subproj/ppc.subproj/acct.s deleted file mode 100644 index 387d35d..0000000 --- a/sys.subproj/ppc.subproj/acct.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(acct, 1) - blr - diff --git a/sys.subproj/ppc.subproj/add_profil.s b/sys.subproj/ppc.subproj/add_profil.s deleted file mode 100644 index d30b6dd..0000000 --- a/sys.subproj/ppc.subproj/add_profil.s +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(add_profil, 4) - blr diff --git a/sys.subproj/ppc.subproj/adjtime.s b/sys.subproj/ppc.subproj/adjtime.s deleted file mode 100644 index 11f80da..0000000 --- a/sys.subproj/ppc.subproj/adjtime.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(adjtime, 2) - blr - diff --git a/sys.subproj/ppc.subproj/assym.h b/sys.subproj/ppc.subproj/assym.h deleted file mode 100644 index 49d8a8f..0000000 --- a/sys.subproj/ppc.subproj/assym.h +++ /dev/null @@ -1,155 +0,0 @@ -/* - * Copyright (c) 1999 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 _ASSYM_H_ -#define _ASSYM_H_ -#define PCB_FLOAT_STATE 208 -#define PCB_FS_F0 208 -#define PCB_FS_F1 216 -#define PCB_FS_F2 224 -#define PCB_FS_F3 232 -#define PCB_FS_F4 240 -#define PCB_FS_F5 248 -#define PCB_FS_F6 256 -#define PCB_FS_F7 264 -#define PCB_FS_F8 272 -#define PCB_FS_F9 280 -#define PCB_FS_F10 288 -#define PCB_FS_F11 296 -#define PCB_FS_F12 304 -#define PCB_FS_F13 312 -#define PCB_FS_F14 320 -#define PCB_FS_F15 328 -#define PCB_FS_F16 336 -#define PCB_FS_F17 344 -#define PCB_FS_F18 352 -#define PCB_FS_F19 360 -#define PCB_FS_F20 368 -#define PCB_FS_F21 376 -#define PCB_FS_F22 384 -#define PCB_FS_F23 392 -#define PCB_FS_F24 400 -#define PCB_FS_F25 408 -#define PCB_FS_F26 416 -#define PCB_FS_F27 424 -#define PCB_FS_F28 432 -#define PCB_FS_F29 440 -#define PCB_FS_F30 448 -#define PCB_FS_F31 456 -#define PCB_FS_FPSCR 464 -#define PCB_SAVED_STATE 0 -#define PCB_KSP 472 -#define PCB_SR0 476 -#define PCB_SIZE 480 -#define SS_R0 8 -#define SS_R1 12 -#define SS_R2 16 -#define SS_R3 20 -#define SS_R4 24 -#define SS_R5 28 -#define SS_R6 32 -#define SS_R7 36 -#define SS_R8 40 -#define SS_R9 44 -#define SS_R10 48 -#define SS_R11 52 -#define SS_R12 56 -#define SS_R13 60 -#define SS_R14 64 -#define SS_R15 68 -#define SS_R16 72 -#define SS_R17 76 -#define SS_R18 80 -#define SS_R19 84 -#define SS_R20 88 -#define SS_R21 92 -#define SS_R22 96 -#define SS_R23 100 -#define SS_R24 104 -#define SS_R25 108 -#define SS_R26 112 -#define SS_R27 116 -#define SS_R28 120 -#define SS_R29 124 -#define SS_R30 128 -#define SS_R31 132 -#define SS_CR 136 -#define SS_XER 140 -#define SS_LR 144 -#define SS_CTR 148 -#define SS_SRR0 0 -#define SS_SRR1 4 -#define SS_MQ 152 -#define SS_SR_COPYIN 160 -#define SS_SIZE 176 -#define PP_SAVE_CR 0 -#define PP_SAVE_SRR0 4 -#define PP_SAVE_SRR1 8 -#define PP_SAVE_DAR 12 -#define PP_SAVE_DSISR 16 -#define PP_SAVE_SPRG0 20 -#define PP_SAVE_SPRG1 24 -#define PP_SAVE_SPRG2 28 -#define PP_SAVE_SPRG3 32 -#define PP_SAVE_EXCEPTION_TYPE 36 -#define PP_CPU_DATA 52 -#define PP_PHYS_EXCEPTION_HANDLERS 40 -#define PP_VIRT_PER_PROC 44 -#define PP_ACTIVE_STACKS 56 -#define PP_NEED_AST 60 -#define PP_FPU_PCB 64 -#define KS_PCB 16276 -#define KS_R1 16280 -#define KS_R2 16284 -#define KS_R13 16288 -#define KS_LR 16364 -#define KS_CR 16368 -#define KS_SIZE 96 -#define KSTK_SIZE 16372 -#define THREAD_PCB 36 -#define THREAD_KERNEL_STACK 40 -#define THREAD_SWAPFUNC 48 -#define THREAD_RECOVER 116 -#define THREAD_TASK 12 -#define TASK_VMMAP 8 -#define TASK_MACH_EXC_PORT 96 -#define VMMAP_PMAP 32 -#define PMAP_SPACE 4 -#define MACH_TRAP_OFFSET_POW2 4 -#define MACH_TRAP_ARGC 0 -#define MACH_TRAP_FUNCTION 4 -#define HOST_SELF 0 -#define CPU_ACTIVE_THREAD 0 -#define FM_SIZE 56 -#define ARG_SIZE 16 -#define LA_SIZE 24 -#define FM_BACKPTR 0 -#define FM_LR_SAVE 8 -#define FM_TOC_SAVE 20 -#define RPA_SIZE 32 -#define SPA_SIZE 16 -#define FM_ARG0 56 -#define FM_REDZONE 0 - -#define SIZEOF_SIGCATCH 4 -#define SIGCATCH_HANDLER 0x00000000 - -#endif /* _ASSYM_H_ */ diff --git a/sys.subproj/ppc.subproj/bind.s b/sys.subproj/ppc.subproj/bind.s deleted file mode 100644 index e694ae0..0000000 --- a/sys.subproj/ppc.subproj/bind.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(bind, 3) - blr - diff --git a/sys.subproj/ppc.subproj/cerror.s b/sys.subproj/ppc.subproj/cerror.s deleted file mode 100644 index 5753534..0000000 --- a/sys.subproj/ppc.subproj/cerror.s +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* Copyright (c) 1992 NeXT Computer, Inc. All rights reserved. - */ - -#import -#import - - .globl _errno - -NESTED(cerror, 0, 1, 0, 0) - REG_TO_EXTERN(r3,_errno) - CALL_EXTERN(_cthread_set_errno_self) - li32 r3,-1 - li32 r4,-1 /* in case a 64-bit value is returned */ - RETURN -END(cerror) diff --git a/sys.subproj/ppc.subproj/chdir.s b/sys.subproj/ppc.subproj/chdir.s deleted file mode 100644 index bec9ec4..0000000 --- a/sys.subproj/ppc.subproj/chdir.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(chdir, 1) - blr - diff --git a/sys.subproj/ppc.subproj/checkuseraccess.s b/sys.subproj/ppc.subproj/checkuseraccess.s deleted file mode 100644 index a3df1da..0000000 --- a/sys.subproj/ppc.subproj/checkuseraccess.s +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* Copyright 1998 Apple Computer, Inc. */ - -#include "SYS.h" - -SYSCALL(checkuseraccess, 0) - blr diff --git a/sys.subproj/ppc.subproj/chflags.s b/sys.subproj/ppc.subproj/chflags.s deleted file mode 100644 index 8969b30..0000000 --- a/sys.subproj/ppc.subproj/chflags.s +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(chflags, 2) - blr diff --git a/sys.subproj/ppc.subproj/chmod.s b/sys.subproj/ppc.subproj/chmod.s deleted file mode 100644 index d3b242a..0000000 --- a/sys.subproj/ppc.subproj/chmod.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(chmod, 2) - blr - diff --git a/sys.subproj/ppc.subproj/chown.s b/sys.subproj/ppc.subproj/chown.s deleted file mode 100644 index d05ce9a..0000000 --- a/sys.subproj/ppc.subproj/chown.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(chown, 3) - blr - diff --git a/sys.subproj/ppc.subproj/chroot.s b/sys.subproj/ppc.subproj/chroot.s deleted file mode 100644 index c2a061e..0000000 --- a/sys.subproj/ppc.subproj/chroot.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(chroot, 1) - blr - diff --git a/sys.subproj/ppc.subproj/close.s b/sys.subproj/ppc.subproj/close.s deleted file mode 100644 index fc1d293..0000000 --- a/sys.subproj/ppc.subproj/close.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(close, 1) - blr - diff --git a/sys.subproj/ppc.subproj/connect.s b/sys.subproj/ppc.subproj/connect.s deleted file mode 100644 index 5e7d6d3..0000000 --- a/sys.subproj/ppc.subproj/connect.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(connect, 3) - blr - diff --git a/sys.subproj/ppc.subproj/cthread.s b/sys.subproj/ppc.subproj/cthread.s deleted file mode 100644 index c456ba7..0000000 --- a/sys.subproj/ppc.subproj/cthread.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ - .text - .align 2 - .globl __pthread_set_self -__pthread_set_self: - li r0, 0x7FF1 - sc - blr diff --git a/sys.subproj/ppc.subproj/dup.s b/sys.subproj/ppc.subproj/dup.s deleted file mode 100644 index fe70d58..0000000 --- a/sys.subproj/ppc.subproj/dup.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(dup, 2) - blr - diff --git a/sys.subproj/ppc.subproj/dup2.s b/sys.subproj/ppc.subproj/dup2.s deleted file mode 100644 index ef1e13d..0000000 --- a/sys.subproj/ppc.subproj/dup2.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(dup2, 2) - blr - diff --git a/sys.subproj/ppc.subproj/exchangedata.s b/sys.subproj/ppc.subproj/exchangedata.s deleted file mode 100644 index 7a990fc..0000000 --- a/sys.subproj/ppc.subproj/exchangedata.s +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* Copyright 1998 Apple Computer, Inc. */ - -#include "SYS.h" - -SYSCALL(exchangedata, 0) - blr diff --git a/sys.subproj/ppc.subproj/execve.s b/sys.subproj/ppc.subproj/execve.s deleted file mode 100644 index 0c0172b..0000000 --- a/sys.subproj/ppc.subproj/execve.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(execve, 3) - blr - diff --git a/sys.subproj/ppc.subproj/fchdir.s b/sys.subproj/ppc.subproj/fchdir.s deleted file mode 100644 index 19aa46e..0000000 --- a/sys.subproj/ppc.subproj/fchdir.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(fchdir, 1) - blr - diff --git a/sys.subproj/ppc.subproj/fchflags.s b/sys.subproj/ppc.subproj/fchflags.s deleted file mode 100644 index 9e0749d..0000000 --- a/sys.subproj/ppc.subproj/fchflags.s +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(fchflags, 2) - blr diff --git a/sys.subproj/ppc.subproj/fchmod.s b/sys.subproj/ppc.subproj/fchmod.s deleted file mode 100644 index e4a0eb8..0000000 --- a/sys.subproj/ppc.subproj/fchmod.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(fchmod, 2) - blr - diff --git a/sys.subproj/ppc.subproj/fchown.s b/sys.subproj/ppc.subproj/fchown.s deleted file mode 100644 index 48b477b..0000000 --- a/sys.subproj/ppc.subproj/fchown.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(fchown, 3) - blr - diff --git a/sys.subproj/ppc.subproj/fcntl.s b/sys.subproj/ppc.subproj/fcntl.s deleted file mode 100644 index 83a060c..0000000 --- a/sys.subproj/ppc.subproj/fcntl.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(fcntl, 3) - blr - diff --git a/sys.subproj/ppc.subproj/flock.s b/sys.subproj/ppc.subproj/flock.s deleted file mode 100644 index c422536..0000000 --- a/sys.subproj/ppc.subproj/flock.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(flock, 2) - blr - diff --git a/sys.subproj/ppc.subproj/fork.s b/sys.subproj/ppc.subproj/fork.s deleted file mode 100644 index 6df807e..0000000 --- a/sys.subproj/ppc.subproj/fork.s +++ /dev/null @@ -1,163 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* Copyright (c) 1992 NeXT Computer, Inc. All rights reserved. - * - * File: libc/ppc/sys/fork.s - * - * HISTORY - * 18-Nov-92 Ben Fathi (benf@next.com) - * Created from M88K sources - * - * 11-Jan-92 Peter King (king@next.com) - * Created from M68K sources - */ - -#import -#import -#import -#import - -/* We use 8 bytes for LOCAL_VAR(1) and LOCAL_VAR(2) */ -NESTED(_fork, 8, 0, 0, 0) - CALL_EXTERN(__cthread_fork_prepare) -#if defined(__DYNAMIC__) -.cstring -LC1: - .ascii "__dyld_fork_prepare\0" -.text - .align 2 - mflr r0 - bl 1f -1: mflr r3 - mtlr r0 - addis r3,r3,ha16(LC1-1b) - addi r3,r3,lo16(LC1-1b) - addi r4,r1,LOCAL_VAR(1) - bl __dyld_func_lookup - lwz r3,LOCAL_VAR(1)(r1) - mtspr ctr,r3 - bctrl -#endif - li r0,SYS_fork - sc - b Lbotch // error return - - cmpwi r4,0 - beq Lparent // parent, since a1 == 0 in parent, - // 1 in child -#if defined(__DYNAMIC__) -.cstring -LC3: - .ascii "__dyld_fork_child\0" -.text - .align 2 - mflr r0 - bl 1f -1: mflr r3 - mtlr r0 - addis r3,r3,ha16(LC3-1b) - addi r3,r3,lo16(LC3-1b) - addi r4,r1,LOCAL_VAR(1) - bl __dyld_func_lookup - lwz r3,LOCAL_VAR(1)(r1) - mtspr ctr,r3 - bctrl -#endif - CALL_EXTERN(_fork_mach_init) - CALL_EXTERN(__cthread_fork_child) -#if defined(__DYNAMIC__) -.cstring -LC4: - .ascii "__dyld_fork_child_final\0" -.text - .align 2 - mflr r0 - bl 1f -1: mflr r3 - mtlr r0 - addis r3,r3,ha16(LC4-1b) - addi r3,r3,lo16(LC4-1b) - addi r4,r1,LOCAL_VAR(1) - bl __dyld_func_lookup - lwz r3,LOCAL_VAR(1)(r1) - mtspr ctr,r3 - bctrl -#endif - - li r3,0 - b Lreturn - -Lparent: -#if defined(__DYNAMIC__) - stw r3,LOCAL_VAR(2)(r1) // save child pid - mflr r0 - bl 1f -1: mflr r3 - mtlr r0 - addis r3,r3,ha16(LC2-1b) - addi r3,r3,lo16(LC2-1b) - addi r4,r1,LOCAL_VAR(1) - bl __dyld_func_lookup - lwz r3,LOCAL_VAR(1)(r1) - mtspr ctr,r3 - bctrl -#endif - CALL_EXTERN(__cthread_fork_parent) -#if defined(__DYNAMIC__) - lwz r3,LOCAL_VAR(2)(r1) -#endif - b Lreturn - -Lbotch: -#if defined(__DYNAMIC__) -.cstring -LC2: - .ascii "__dyld_fork_parent\0" -.text - .align 2 - stw r3,LOCAL_VAR(2)(r1) // save error value - mflr r0 - bl 1f -1: mflr r3 - mtlr r0 - addis r3,r3,ha16(LC2-1b) - addi r3,r3,lo16(LC2-1b) - addi r4,r1,LOCAL_VAR(1) - bl __dyld_func_lookup - lwz r3,LOCAL_VAR(1)(r1) - mtspr ctr,r3 - bctrl - lwz r3,LOCAL_VAR(2)(r1) // restore error value for cerror - -#endif - CALL_EXTERN(cerror) - /* - * We use cthread_fork_parent() to clean up after a fork error - * (unlock cthreads and mailloc packages) so the parent - * process can Malloc() after fork() errors without - * deadlocking. - */ - CALL_EXTERN_AGAIN(__cthread_fork_parent) - li32 r3,-1 // error return -Lreturn: RETURN -END(_fork) - diff --git a/sys.subproj/ppc.subproj/fpathconf.s b/sys.subproj/ppc.subproj/fpathconf.s deleted file mode 100644 index a4666fc..0000000 --- a/sys.subproj/ppc.subproj/fpathconf.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(fpathconf, 2) - blr - diff --git a/sys.subproj/ppc.subproj/fstat.s b/sys.subproj/ppc.subproj/fstat.s deleted file mode 100644 index dcc424a..0000000 --- a/sys.subproj/ppc.subproj/fstat.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(fstat, 2) - blr - diff --git a/sys.subproj/ppc.subproj/fstatfs.s b/sys.subproj/ppc.subproj/fstatfs.s deleted file mode 100644 index 27b0ad3..0000000 --- a/sys.subproj/ppc.subproj/fstatfs.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(fstatfs, 2) - blr - diff --git a/sys.subproj/ppc.subproj/fstatv.s b/sys.subproj/ppc.subproj/fstatv.s deleted file mode 100644 index 57cded8..0000000 --- a/sys.subproj/ppc.subproj/fstatv.s +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* Copyright 1998 Apple Computer, Inc. */ - -#include "SYS.h" - -SYSCALL(fstatv, 0) - blr diff --git a/sys.subproj/ppc.subproj/fsync.s b/sys.subproj/ppc.subproj/fsync.s deleted file mode 100644 index 5ff3afa..0000000 --- a/sys.subproj/ppc.subproj/fsync.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(fsync, 1) - blr - diff --git a/sys.subproj/ppc.subproj/ftruncate.s b/sys.subproj/ppc.subproj/ftruncate.s deleted file mode 100644 index 30eb15c..0000000 --- a/sys.subproj/ppc.subproj/ftruncate.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(ftruncate, 2) - blr - diff --git a/sys.subproj/ppc.subproj/genassym.h b/sys.subproj/ppc.subproj/genassym.h deleted file mode 100644 index 729dfa9..0000000 --- a/sys.subproj/ppc.subproj/genassym.h +++ /dev/null @@ -1,126 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * genassym.h -- macros of use with genassym.c and assymdefs.c - */ - -#import -#import - -#define PRINT_OFFSET(ptr_type, field) \ -MACRO_BEGIN \ - print_define("", #ptr_type, #field); \ - print_hex((unsigned) &(((ptr_type)0)->field)); \ -MACRO_END - -#define PRINT_BIT_FIELD(reg_type, field) \ -MACRO_BEGIN \ - reg_type __reg; \ - CONTENTS(__reg) = 0; \ - __reg.field = (typeof (__reg.field)) -1; \ - print_define("", #reg_type, #field); \ - print_hex(CONTENTS(__reg)); \ -MACRO_END - -#define PRINT_ENUM(item) \ -MACRO_BEGIN \ - print_define("", "", #item); \ - print_hex((unsigned)item); \ -MACRO_END - -#define PRINT_DEFINE(macro) \ -MACRO_BEGIN \ - print_define("", "", #macro); \ - print_str(STRINGIFY(macro)); \ -MACRO_END - -#define PRINT_CONSTANT(macro) \ -MACRO_BEGIN \ - print_define("", "", #macro); \ - print_hex((unsigned)macro); \ -MACRO_END - -#define PRINT_REGADDR(macro) \ -MACRO_BEGIN \ - print_define("", "", #macro); \ - print_hex((unsigned) ¯o); \ -MACRO_END - -#define PRINT_REG_PAIR(struct_ptr, name0, name1) \ -MACRO_BEGIN \ - print_define("", #struct_ptr, #name0 "_" #name1); \ - print_hex((unsigned) &(((struct_ptr)0)->U_##name0##_##name1)); \ -MACRO_END - -#define PRINT_BIT_POS(reg_type, field) \ -MACRO_BEGIN \ - reg_type __reg; \ - CONTENTS(__reg) = 0; \ - __reg.field = 1; \ - print_define("", #reg_type, #field "_BIT"); \ - print_dec((int) bit_num(#reg_type, #field, CONTENTS(__reg))); \ -MACRO_END - -#define PRINT_FIELD_INFO(reg_type, field) \ -MACRO_BEGIN \ - reg_type __reg; \ - CONTENTS(__reg) = 0; \ - __reg.field = -1; \ - print_define("", #reg_type, #field "_OFF"); \ - print_dec((int) bit_num(#reg_type, #field, CONTENTS(__reg))); \ - print_define("", #reg_type, #field "_WIDTH"); \ - print_dec((int) field_width(#reg_type, #field, CONTENTS(__reg)));\ -MACRO_END - -#define PRINT_L2_SIZE(type) \ -MACRO_BEGIN \ - print_define("L2_SIZEOF", #type, ""); \ - print_dec((int) log2(sizeof(type), #type)); \ -MACRO_END - -#define PRINT_SIZEOF(type) \ -MACRO_BEGIN \ - print_define("SIZEOF", #type, ""); \ - print_dec((int) sizeof(type)); \ -MACRO_END - -#define PRINT_L2_CONSTANT(macro) \ -MACRO_BEGIN \ - print_define("L2", "", #macro); \ - print_dec((int) log2(macro, #macro)); \ -MACRO_END - -typedef enum { - MAJOR, MINOR -} cmt_level_t; - -extern void comment(cmt_level_t level, const char *cmt); -extern void print_define(const char *prefix, const char *type_name, - const char *field); -extern void print_dec(int val); -extern void print_hex(unsigned val); -extern void print_str(const char *str); -extern unsigned bit_num(char *reg_type, char *field, unsigned bits); -extern unsigned field_width(char *reg_type, char *field, unsigned bits); -extern unsigned log2(unsigned val, char *type); -extern void assymdefs(void); - diff --git a/sys.subproj/ppc.subproj/getattrlist.s b/sys.subproj/ppc.subproj/getattrlist.s deleted file mode 100644 index b2b9a72..0000000 --- a/sys.subproj/ppc.subproj/getattrlist.s +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* Copyright 1998 Apple Computer, Inc. */ - -#include "SYS.h" - -SYSCALL(getattrlist, 0) - blr diff --git a/sys.subproj/ppc.subproj/getdirentries.s b/sys.subproj/ppc.subproj/getdirentries.s deleted file mode 100644 index 51e308b..0000000 --- a/sys.subproj/ppc.subproj/getdirentries.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(getdirentries, 4) - blr - diff --git a/sys.subproj/ppc.subproj/getdirentriesattr.s b/sys.subproj/ppc.subproj/getdirentriesattr.s deleted file mode 100644 index 989b481..0000000 --- a/sys.subproj/ppc.subproj/getdirentriesattr.s +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* Copyright 1998 Apple Computer, Inc. */ - -#include "SYS.h" - -SYSCALL(getdirentriesattr, 0) - blr diff --git a/sys.subproj/ppc.subproj/getegid.s b/sys.subproj/ppc.subproj/getegid.s deleted file mode 100644 index 1d5959c..0000000 --- a/sys.subproj/ppc.subproj/getegid.s +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* Copyright (c) 1992 NeXT Computer, Inc. All rights reserved. */ - -#import - -#import "SYS.h" - -PSEUDO(getegid,getgid,0) - mr a0,a1 - blr - diff --git a/sys.subproj/ppc.subproj/geteuid.s b/sys.subproj/ppc.subproj/geteuid.s deleted file mode 100644 index fc71756..0000000 --- a/sys.subproj/ppc.subproj/geteuid.s +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* Copyright (c) 1992 NeXT Computer, Inc. All rights reserved. */ - -#import - -#import "SYS.h" - -PSEUDO(geteuid,getuid,0) - mr a0,a1 - blr - diff --git a/sys.subproj/ppc.subproj/getfh.s b/sys.subproj/ppc.subproj/getfh.s deleted file mode 100644 index fb377fd..0000000 --- a/sys.subproj/ppc.subproj/getfh.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(getfh, 2) - blr - diff --git a/sys.subproj/ppc.subproj/getfsstat.s b/sys.subproj/ppc.subproj/getfsstat.s deleted file mode 100644 index 0e013f8..0000000 --- a/sys.subproj/ppc.subproj/getfsstat.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(getfsstat, 3) - blr - diff --git a/sys.subproj/ppc.subproj/getgid.s b/sys.subproj/ppc.subproj/getgid.s deleted file mode 100644 index 79c52fe..0000000 --- a/sys.subproj/ppc.subproj/getgid.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(getgid, 0) - blr - diff --git a/sys.subproj/ppc.subproj/getgroups.s b/sys.subproj/ppc.subproj/getgroups.s deleted file mode 100644 index 2284f9b..0000000 --- a/sys.subproj/ppc.subproj/getgroups.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(getgroups, 2) - blr - diff --git a/sys.subproj/ppc.subproj/getitimer.s b/sys.subproj/ppc.subproj/getitimer.s deleted file mode 100644 index 35075cf..0000000 --- a/sys.subproj/ppc.subproj/getitimer.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(getitimer, 2) - blr - diff --git a/sys.subproj/ppc.subproj/getpeername.s b/sys.subproj/ppc.subproj/getpeername.s deleted file mode 100644 index ca29d16..0000000 --- a/sys.subproj/ppc.subproj/getpeername.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(getpeername, 3) - blr - diff --git a/sys.subproj/ppc.subproj/getpgrp.s b/sys.subproj/ppc.subproj/getpgrp.s deleted file mode 100644 index ba45913..0000000 --- a/sys.subproj/ppc.subproj/getpgrp.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(getpgrp, 1) - blr - diff --git a/sys.subproj/ppc.subproj/getpid.s b/sys.subproj/ppc.subproj/getpid.s deleted file mode 100644 index 0445d37..0000000 --- a/sys.subproj/ppc.subproj/getpid.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(getpid, 0) - blr - diff --git a/sys.subproj/ppc.subproj/getppid.s b/sys.subproj/ppc.subproj/getppid.s deleted file mode 100644 index 209b0b3..0000000 --- a/sys.subproj/ppc.subproj/getppid.s +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* Copyright (c) 1992 NeXT Computer, Inc. All rights reserved. */ - -#import - -#import "SYS.h" - -PSEUDO(getppid,getpid,0) - mr a0,a1 - blr - diff --git a/sys.subproj/ppc.subproj/getpriority.s b/sys.subproj/ppc.subproj/getpriority.s deleted file mode 100644 index 8235428..0000000 --- a/sys.subproj/ppc.subproj/getpriority.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(getpriority, 2) - blr - diff --git a/sys.subproj/ppc.subproj/getrlimit.s b/sys.subproj/ppc.subproj/getrlimit.s deleted file mode 100644 index 0f02bea..0000000 --- a/sys.subproj/ppc.subproj/getrlimit.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(getrlimit, 2) - blr - diff --git a/sys.subproj/ppc.subproj/getrusage.s b/sys.subproj/ppc.subproj/getrusage.s deleted file mode 100644 index c01f157..0000000 --- a/sys.subproj/ppc.subproj/getrusage.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(getrusage, 2) - blr - diff --git a/sys.subproj/ppc.subproj/getsockname.s b/sys.subproj/ppc.subproj/getsockname.s deleted file mode 100644 index df3ed97..0000000 --- a/sys.subproj/ppc.subproj/getsockname.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(getsockname, 3) - blr - diff --git a/sys.subproj/ppc.subproj/getsockopt.s b/sys.subproj/ppc.subproj/getsockopt.s deleted file mode 100644 index 6b90c2f..0000000 --- a/sys.subproj/ppc.subproj/getsockopt.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(getsockopt, 5) - blr - diff --git a/sys.subproj/ppc.subproj/getuid.s b/sys.subproj/ppc.subproj/getuid.s deleted file mode 100644 index 45610de..0000000 --- a/sys.subproj/ppc.subproj/getuid.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(getuid, 0) - blr - diff --git a/sys.subproj/ppc.subproj/ioctl.s b/sys.subproj/ppc.subproj/ioctl.s deleted file mode 100644 index 79347cf..0000000 --- a/sys.subproj/ppc.subproj/ioctl.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(ioctl, 3) - blr - diff --git a/sys.subproj/ppc.subproj/kill.s b/sys.subproj/ppc.subproj/kill.s deleted file mode 100644 index 244276e..0000000 --- a/sys.subproj/ppc.subproj/kill.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(kill, 2) - blr - diff --git a/sys.subproj/ppc.subproj/ktrace.s b/sys.subproj/ppc.subproj/ktrace.s deleted file mode 100644 index b396926..0000000 --- a/sys.subproj/ppc.subproj/ktrace.s +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(ktrace, 4) - blr diff --git a/sys.subproj/ppc.subproj/lfs_bmapv.s b/sys.subproj/ppc.subproj/lfs_bmapv.s deleted file mode 100644 index 24c4507..0000000 --- a/sys.subproj/ppc.subproj/lfs_bmapv.s +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(lfs_bmapv, 2) - blr diff --git a/sys.subproj/ppc.subproj/lfs_markv.s b/sys.subproj/ppc.subproj/lfs_markv.s deleted file mode 100644 index dbb69c9..0000000 --- a/sys.subproj/ppc.subproj/lfs_markv.s +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(lfs_markv, 2) - blr diff --git a/sys.subproj/ppc.subproj/lfs_segclean.s b/sys.subproj/ppc.subproj/lfs_segclean.s deleted file mode 100644 index 8a36388..0000000 --- a/sys.subproj/ppc.subproj/lfs_segclean.s +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(lfs_segclean, 2) - blr diff --git a/sys.subproj/ppc.subproj/lfs_segwait.s b/sys.subproj/ppc.subproj/lfs_segwait.s deleted file mode 100644 index 2dc8335..0000000 --- a/sys.subproj/ppc.subproj/lfs_segwait.s +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(lfs_segwait, 2) - blr diff --git a/sys.subproj/ppc.subproj/link.s b/sys.subproj/ppc.subproj/link.s deleted file mode 100644 index 741d98a..0000000 --- a/sys.subproj/ppc.subproj/link.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(link, 2) - blr - diff --git a/sys.subproj/ppc.subproj/listen.s b/sys.subproj/ppc.subproj/listen.s deleted file mode 100644 index 3c01971..0000000 --- a/sys.subproj/ppc.subproj/listen.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(listen, 2) - blr - diff --git a/sys.subproj/ppc.subproj/load_shared_file.s b/sys.subproj/ppc.subproj/load_shared_file.s deleted file mode 100644 index 53b7c62..0000000 --- a/sys.subproj/ppc.subproj/load_shared_file.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(load_shared_file, 7) - blr - diff --git a/sys.subproj/ppc.subproj/longjmp.s b/sys.subproj/ppc.subproj/longjmp.s deleted file mode 100644 index 63d6806..0000000 --- a/sys.subproj/ppc.subproj/longjmp.s +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1998 Apple Computer, Inc. All rights reserved. - * - * File: sys/ppc/longjmp.s - * - * Implements siglongjmp(), longjmp(), _longjmp() - * - * NOTE: Scatterloading this file will BREAK the functions. - * - * History: - * 30-Aug-1998 Umesh Vaishampayan (umeshv@apple.com) - * Created. Derived from _setjmp.s, setjmp.c and setjmp.s - */ - -#include "SYS.h" -#include -#include "_setjmp.h" - -/* - * longjmp routines - */ - -/* void siglongjmp(sigjmp_buf env, int val); */ - -LEAF(_siglongjmp) - lwz r0, JMP_SIGFLAG(r3) ; load sigflag saved by siglongjmp() - cmpwi cr1,r0,0 ; this changes cr1[EQ] which is volatile - beq- cr1, L__longjmp ; if r0 == 0 do _longjmp() - ; else *** fall through *** to longjmp() - -/* void longjmp(jmp_buf env, int val); */ - -LEAF(_longjmp) -L_longjmp: - mr r30, r3 - mr r31, r4 - lwz r3, JMP_sig(r3) ; restore the signal mask - CALL_EXTERN(_sigsetmask) - mr r4, r31 - mr r3, r30 -L__longjmp: - BRANCH_EXTERN(__longjmp) diff --git a/sys.subproj/ppc.subproj/lseek.s b/sys.subproj/ppc.subproj/lseek.s deleted file mode 100644 index 0cce603..0000000 --- a/sys.subproj/ppc.subproj/lseek.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(lseek, 3) - blr - diff --git a/sys.subproj/ppc.subproj/lstat.s b/sys.subproj/ppc.subproj/lstat.s deleted file mode 100644 index 9454192..0000000 --- a/sys.subproj/ppc.subproj/lstat.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(lstat, 2) - blr - diff --git a/sys.subproj/ppc.subproj/lstatv.s b/sys.subproj/ppc.subproj/lstatv.s deleted file mode 100644 index 3c09ab4..0000000 --- a/sys.subproj/ppc.subproj/lstatv.s +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* Copyright 1998 Apple Computer, Inc. */ - -#include "SYS.h" - -SYSCALL(lstatv, 0) - blr diff --git a/sys.subproj/ppc.subproj/madvise.s b/sys.subproj/ppc.subproj/madvise.s deleted file mode 100644 index a656a59..0000000 --- a/sys.subproj/ppc.subproj/madvise.s +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* Copyright 1998 Apple Computer, Inc. */ - -#include "SYS.h" - -SYSCALL(madvise, 3) - blr diff --git a/sys.subproj/ppc.subproj/mincore.s b/sys.subproj/ppc.subproj/mincore.s deleted file mode 100644 index 0c794cf..0000000 --- a/sys.subproj/ppc.subproj/mincore.s +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* Copyright 1998 Apple Computer, Inc. */ - -#include "SYS.h" - -SYSCALL(mincore, 3) - blr diff --git a/sys.subproj/ppc.subproj/minherit.s b/sys.subproj/ppc.subproj/minherit.s deleted file mode 100644 index a17397b..0000000 --- a/sys.subproj/ppc.subproj/minherit.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(minherit, 3) - blr - diff --git a/sys.subproj/ppc.subproj/mkcomplex.s b/sys.subproj/ppc.subproj/mkcomplex.s deleted file mode 100644 index 011508b..0000000 --- a/sys.subproj/ppc.subproj/mkcomplex.s +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* Copyright 1998 Apple Computer, Inc. */ - -#include "SYS.h" - -SYSCALL(mkcomplex, 0) - blr diff --git a/sys.subproj/ppc.subproj/mkdir.s b/sys.subproj/ppc.subproj/mkdir.s deleted file mode 100644 index b9816c1..0000000 --- a/sys.subproj/ppc.subproj/mkdir.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(mkdir, 2) - blr - diff --git a/sys.subproj/ppc.subproj/mkfifo.s b/sys.subproj/ppc.subproj/mkfifo.s deleted file mode 100644 index d8483c9..0000000 --- a/sys.subproj/ppc.subproj/mkfifo.s +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(mkfifo, 2) - blr diff --git a/sys.subproj/ppc.subproj/mknod.s b/sys.subproj/ppc.subproj/mknod.s deleted file mode 100644 index 9017fee..0000000 --- a/sys.subproj/ppc.subproj/mknod.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(mknod, 3) - blr - diff --git a/sys.subproj/ppc.subproj/mlock.s b/sys.subproj/ppc.subproj/mlock.s deleted file mode 100644 index 3297c9e..0000000 --- a/sys.subproj/ppc.subproj/mlock.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(mlock, 3) - blr - diff --git a/sys.subproj/ppc.subproj/mlockall.s b/sys.subproj/ppc.subproj/mlockall.s deleted file mode 100644 index de14a8a..0000000 --- a/sys.subproj/ppc.subproj/mlockall.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(mlockall, 3) - blr - diff --git a/sys.subproj/ppc.subproj/mmap.s b/sys.subproj/ppc.subproj/mmap.s deleted file mode 100644 index b8dcac9..0000000 --- a/sys.subproj/ppc.subproj/mmap.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(mmap, 6) - blr - diff --git a/sys.subproj/ppc.subproj/mount.s b/sys.subproj/ppc.subproj/mount.s deleted file mode 100644 index cf61211..0000000 --- a/sys.subproj/ppc.subproj/mount.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* Copyright (c) 1992 NeXT Computer, Inc. All rights reserved. */ - -#import -#import "SYS.h" - -SYSCALL(mount, 4) - blr diff --git a/sys.subproj/ppc.subproj/mprotect.s b/sys.subproj/ppc.subproj/mprotect.s deleted file mode 100644 index a266bb5..0000000 --- a/sys.subproj/ppc.subproj/mprotect.s +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* Copyright 1998 Apple Computer, Inc. */ - -#include "SYS.h" - -SYSCALL(mprotect, 3) - blr diff --git a/sys.subproj/ppc.subproj/msgctl.s b/sys.subproj/ppc.subproj/msgctl.s deleted file mode 100644 index a56f61d..0000000 --- a/sys.subproj/ppc.subproj/msgctl.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(msgctl, 3) - blr - diff --git a/sys.subproj/ppc.subproj/msgget.s b/sys.subproj/ppc.subproj/msgget.s deleted file mode 100644 index 45aa533..0000000 --- a/sys.subproj/ppc.subproj/msgget.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(msgget, 3) - blr - diff --git a/sys.subproj/ppc.subproj/msgrcv.s b/sys.subproj/ppc.subproj/msgrcv.s deleted file mode 100644 index 9afa905..0000000 --- a/sys.subproj/ppc.subproj/msgrcv.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(msgrcv, 3) - blr - diff --git a/sys.subproj/ppc.subproj/msgsnd.s b/sys.subproj/ppc.subproj/msgsnd.s deleted file mode 100644 index 71d1954..0000000 --- a/sys.subproj/ppc.subproj/msgsnd.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(msgsnd, 3) - blr - diff --git a/sys.subproj/ppc.subproj/msgsys.s b/sys.subproj/ppc.subproj/msgsys.s deleted file mode 100644 index 7e0036f..0000000 --- a/sys.subproj/ppc.subproj/msgsys.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(msgsys, 3) - blr - diff --git a/sys.subproj/ppc.subproj/msync.s b/sys.subproj/ppc.subproj/msync.s deleted file mode 100644 index eb6fb6e..0000000 --- a/sys.subproj/ppc.subproj/msync.s +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* Copyright 1998 Apple Computer, Inc. */ - -#include "SYS.h" - -SYSCALL(msync, 2) - blr diff --git a/sys.subproj/ppc.subproj/munlock.s b/sys.subproj/ppc.subproj/munlock.s deleted file mode 100644 index 1306a1f..0000000 --- a/sys.subproj/ppc.subproj/munlock.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(munlock, 3) - blr - diff --git a/sys.subproj/ppc.subproj/munlockall.s b/sys.subproj/ppc.subproj/munlockall.s deleted file mode 100644 index 49f3585..0000000 --- a/sys.subproj/ppc.subproj/munlockall.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(munlockall, 3) - blr - diff --git a/sys.subproj/ppc.subproj/munmap.s b/sys.subproj/ppc.subproj/munmap.s deleted file mode 100644 index 7ea41da..0000000 --- a/sys.subproj/ppc.subproj/munmap.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(munmap, 2) - blr - diff --git a/sys.subproj/ppc.subproj/nfssvc.s b/sys.subproj/ppc.subproj/nfssvc.s deleted file mode 100644 index bf152ce..0000000 --- a/sys.subproj/ppc.subproj/nfssvc.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(nfssvc, 1) - blr - diff --git a/sys.subproj/ppc.subproj/open.s b/sys.subproj/ppc.subproj/open.s deleted file mode 100644 index 31e98c7..0000000 --- a/sys.subproj/ppc.subproj/open.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(open, 3) - blr - diff --git a/sys.subproj/ppc.subproj/pathconf.s b/sys.subproj/ppc.subproj/pathconf.s deleted file mode 100644 index 443bdd7..0000000 --- a/sys.subproj/ppc.subproj/pathconf.s +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(pathconf, 2) - blr diff --git a/sys.subproj/ppc.subproj/pipe.s b/sys.subproj/ppc.subproj/pipe.s deleted file mode 100644 index a26568d..0000000 --- a/sys.subproj/ppc.subproj/pipe.s +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* Copyright (c) 1992 NeXT Computer, Inc. All rights reserved. */ - -#import "SYS.h" - -LEAF(_pipe) - stw r3,ARG(1)(r1) // preserve fildes on stack - SYSCALL_NONAME(pipe, 0) - lwz r11,ARG(1)(r1) // restore fildes - stw r3,0(r11) - stw r4,4(r11) - li r3,0 - blr diff --git a/sys.subproj/ppc.subproj/processor_facilities.h b/sys.subproj/ppc.subproj/processor_facilities.h deleted file mode 100644 index f82e7a5..0000000 --- a/sys.subproj/ppc.subproj/processor_facilities.h +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (c) 2000 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@ - */ - -/* Does the current CPU have Altivec support? */ -extern int _cpu_has_altivec; - -/* What processor facilities is the current thread using? */ -#define floatUsed 0x40000000 -#define vectorUsed 0x20000000 - -extern int processor_facilities_used(void); diff --git a/sys.subproj/ppc.subproj/processor_facilities.s b/sys.subproj/ppc.subproj/processor_facilities.s deleted file mode 100644 index 87ebeb6..0000000 --- a/sys.subproj/ppc.subproj/processor_facilities.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 2000 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@ - */ -.globl _processor_facilities_used -_processor_facilities_used: - li r0,0x7FF3 - sc - blr diff --git a/sys.subproj/ppc.subproj/profil.s b/sys.subproj/ppc.subproj/profil.s deleted file mode 100644 index 150565f..0000000 --- a/sys.subproj/ppc.subproj/profil.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(profil, 4) - blr - diff --git a/sys.subproj/ppc.subproj/ptrace.s b/sys.subproj/ppc.subproj/ptrace.s deleted file mode 100644 index 2bb6255..0000000 --- a/sys.subproj/ppc.subproj/ptrace.s +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* Copyright (c) 1992 NeXT Computer, Inc. All rights reserved. */ - -#import "SYS.h" - -LEAF(_ptrace) - li r7,0 - REG_TO_EXTERN(r7,_errno) -SYSCALL_NONAME(ptrace, 4) - blr diff --git a/sys.subproj/ppc.subproj/quota.s b/sys.subproj/ppc.subproj/quota.s deleted file mode 100644 index d299496..0000000 --- a/sys.subproj/ppc.subproj/quota.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -#define SYS_quota 149 - -SYSCALL(quota, 4) - blr - diff --git a/sys.subproj/ppc.subproj/quotactl.s b/sys.subproj/ppc.subproj/quotactl.s deleted file mode 100644 index 78e71bc..0000000 --- a/sys.subproj/ppc.subproj/quotactl.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(quotactl, 3) - blr - diff --git a/sys.subproj/ppc.subproj/read.s b/sys.subproj/ppc.subproj/read.s deleted file mode 100644 index 11ef4b7..0000000 --- a/sys.subproj/ppc.subproj/read.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(read, 3) - blr - diff --git a/sys.subproj/ppc.subproj/readlink.s b/sys.subproj/ppc.subproj/readlink.s deleted file mode 100644 index 48e113e..0000000 --- a/sys.subproj/ppc.subproj/readlink.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(readlink, 3) - blr - diff --git a/sys.subproj/ppc.subproj/readv.s b/sys.subproj/ppc.subproj/readv.s deleted file mode 100644 index b002966..0000000 --- a/sys.subproj/ppc.subproj/readv.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(readv, 3) - blr - diff --git a/sys.subproj/ppc.subproj/reboot.s b/sys.subproj/ppc.subproj/reboot.s deleted file mode 100644 index 90bc47b..0000000 --- a/sys.subproj/ppc.subproj/reboot.s +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* Copyright (c) 1992 NeXT Computer, Inc. All rights reserved */ - -#import "SYS.h" - -SYSCALL(reboot, 2) - BRANCH_EXTERN(_abort) diff --git a/sys.subproj/ppc.subproj/recvfrom.s b/sys.subproj/ppc.subproj/recvfrom.s deleted file mode 100644 index 567b3e8..0000000 --- a/sys.subproj/ppc.subproj/recvfrom.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(recvfrom, 6) - blr - diff --git a/sys.subproj/ppc.subproj/recvmsg.s b/sys.subproj/ppc.subproj/recvmsg.s deleted file mode 100644 index aeb5106..0000000 --- a/sys.subproj/ppc.subproj/recvmsg.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(recvmsg, 3) - blr - diff --git a/sys.subproj/ppc.subproj/rename.s b/sys.subproj/ppc.subproj/rename.s deleted file mode 100644 index a2adfd0..0000000 --- a/sys.subproj/ppc.subproj/rename.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(rename, 2) - blr - diff --git a/sys.subproj/ppc.subproj/reset_shared_file.s b/sys.subproj/ppc.subproj/reset_shared_file.s deleted file mode 100644 index a43aba6..0000000 --- a/sys.subproj/ppc.subproj/reset_shared_file.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(reset_shared_file, 3) - blr - diff --git a/sys.subproj/ppc.subproj/revoke.s b/sys.subproj/ppc.subproj/revoke.s deleted file mode 100644 index 3e2ae5a..0000000 --- a/sys.subproj/ppc.subproj/revoke.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(revoke, 1) - blr - diff --git a/sys.subproj/ppc.subproj/rmdir.s b/sys.subproj/ppc.subproj/rmdir.s deleted file mode 100644 index 245e79d..0000000 --- a/sys.subproj/ppc.subproj/rmdir.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(rmdir, 1) - blr - diff --git a/sys.subproj/ppc.subproj/searchfs.s b/sys.subproj/ppc.subproj/searchfs.s deleted file mode 100644 index 6d04cda..0000000 --- a/sys.subproj/ppc.subproj/searchfs.s +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* Copyright 1998 Apple Computer, Inc. */ - -#include "SYS.h" - -SYSCALL(searchfs, 0) - blr diff --git a/sys.subproj/ppc.subproj/select.s b/sys.subproj/ppc.subproj/select.s deleted file mode 100644 index f23d513..0000000 --- a/sys.subproj/ppc.subproj/select.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(select, 5) - blr - diff --git a/sys.subproj/ppc.subproj/sem_close.s b/sys.subproj/ppc.subproj/sem_close.s deleted file mode 100644 index cee016c..0000000 --- a/sys.subproj/ppc.subproj/sem_close.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(sem_close, 1) - blr - diff --git a/sys.subproj/ppc.subproj/sem_destroy.s b/sys.subproj/ppc.subproj/sem_destroy.s deleted file mode 100644 index b9339c0..0000000 --- a/sys.subproj/ppc.subproj/sem_destroy.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(sem_destroy, 1) - blr - diff --git a/sys.subproj/ppc.subproj/sem_getvalue.s b/sys.subproj/ppc.subproj/sem_getvalue.s deleted file mode 100644 index 72317b5..0000000 --- a/sys.subproj/ppc.subproj/sem_getvalue.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(sem_getvalue, 2) - blr - diff --git a/sys.subproj/ppc.subproj/sem_init.s b/sys.subproj/ppc.subproj/sem_init.s deleted file mode 100644 index 06fd281..0000000 --- a/sys.subproj/ppc.subproj/sem_init.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(sem_init, 3) - blr - diff --git a/sys.subproj/ppc.subproj/sem_open.s b/sys.subproj/ppc.subproj/sem_open.s deleted file mode 100644 index c997c38..0000000 --- a/sys.subproj/ppc.subproj/sem_open.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(sem_open, 4) - blr - diff --git a/sys.subproj/ppc.subproj/sem_post.s b/sys.subproj/ppc.subproj/sem_post.s deleted file mode 100644 index 4c58ce4..0000000 --- a/sys.subproj/ppc.subproj/sem_post.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(sem_post, 1) - blr - diff --git a/sys.subproj/ppc.subproj/sem_trywait.s b/sys.subproj/ppc.subproj/sem_trywait.s deleted file mode 100644 index 7c0d846..0000000 --- a/sys.subproj/ppc.subproj/sem_trywait.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(sem_trywait, 1) - blr - diff --git a/sys.subproj/ppc.subproj/sem_unlink.s b/sys.subproj/ppc.subproj/sem_unlink.s deleted file mode 100644 index 9ddb3d8..0000000 --- a/sys.subproj/ppc.subproj/sem_unlink.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(sem_unlink, 1) - blr - diff --git a/sys.subproj/ppc.subproj/sem_wait.s b/sys.subproj/ppc.subproj/sem_wait.s deleted file mode 100644 index c5d166d..0000000 --- a/sys.subproj/ppc.subproj/sem_wait.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(sem_wait, 1) - blr - diff --git a/sys.subproj/ppc.subproj/semconfig.s b/sys.subproj/ppc.subproj/semconfig.s deleted file mode 100644 index ac9fc2f..0000000 --- a/sys.subproj/ppc.subproj/semconfig.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(semconfig, 3) - blr - diff --git a/sys.subproj/ppc.subproj/semctl.s b/sys.subproj/ppc.subproj/semctl.s deleted file mode 100644 index 847bd99..0000000 --- a/sys.subproj/ppc.subproj/semctl.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(semctl, 3) - blr - diff --git a/sys.subproj/ppc.subproj/semget.s b/sys.subproj/ppc.subproj/semget.s deleted file mode 100644 index a5339bd..0000000 --- a/sys.subproj/ppc.subproj/semget.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(semget, 3) - blr - diff --git a/sys.subproj/ppc.subproj/semop.s b/sys.subproj/ppc.subproj/semop.s deleted file mode 100644 index bb743b3..0000000 --- a/sys.subproj/ppc.subproj/semop.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(semop, 3) - blr - diff --git a/sys.subproj/ppc.subproj/semsys.s b/sys.subproj/ppc.subproj/semsys.s deleted file mode 100644 index a6c38d6..0000000 --- a/sys.subproj/ppc.subproj/semsys.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(semsys, 3) - blr - diff --git a/sys.subproj/ppc.subproj/sendmsg.s b/sys.subproj/ppc.subproj/sendmsg.s deleted file mode 100644 index d5843d4..0000000 --- a/sys.subproj/ppc.subproj/sendmsg.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(sendmsg, 3) - blr - diff --git a/sys.subproj/ppc.subproj/sendto.s b/sys.subproj/ppc.subproj/sendto.s deleted file mode 100644 index 3ba2164..0000000 --- a/sys.subproj/ppc.subproj/sendto.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(sendto, 6) - blr - diff --git a/sys.subproj/ppc.subproj/setattrlist.s b/sys.subproj/ppc.subproj/setattrlist.s deleted file mode 100644 index 136332b..0000000 --- a/sys.subproj/ppc.subproj/setattrlist.s +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* Copyright 1998 Apple Computer, Inc. */ - -#include "SYS.h" - -SYSCALL(setattrlist, 0) - blr diff --git a/sys.subproj/ppc.subproj/setegid.s b/sys.subproj/ppc.subproj/setegid.s deleted file mode 100644 index c0c16f2..0000000 --- a/sys.subproj/ppc.subproj/setegid.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(setegid, 1) - blr - diff --git a/sys.subproj/ppc.subproj/seteuid.s b/sys.subproj/ppc.subproj/seteuid.s deleted file mode 100644 index 9ecfa30..0000000 --- a/sys.subproj/ppc.subproj/seteuid.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(seteuid, 1) - blr - diff --git a/sys.subproj/ppc.subproj/setgid.s b/sys.subproj/ppc.subproj/setgid.s deleted file mode 100644 index eefae95..0000000 --- a/sys.subproj/ppc.subproj/setgid.s +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(setgid, 1) - blr diff --git a/sys.subproj/ppc.subproj/setgroups.s b/sys.subproj/ppc.subproj/setgroups.s deleted file mode 100644 index ee55f69..0000000 --- a/sys.subproj/ppc.subproj/setgroups.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(setgroups, 2) - blr - diff --git a/sys.subproj/ppc.subproj/setitimer.s b/sys.subproj/ppc.subproj/setitimer.s deleted file mode 100644 index 26ba852..0000000 --- a/sys.subproj/ppc.subproj/setitimer.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(setitimer, 3) - blr - diff --git a/sys.subproj/ppc.subproj/setjmp.s b/sys.subproj/ppc.subproj/setjmp.s deleted file mode 100644 index 78fbc76..0000000 --- a/sys.subproj/ppc.subproj/setjmp.s +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1998 Apple Computer, Inc. All rights reserved. - * - * File: sys/ppc/setjmp.s - * - * Implements sigsetjmp(), setjmp(), _setjmp() - * - * NOTE: Scatterloading this file will BREAK the functions. - * - * History: - * 30-Aug-1998 Umesh Vaishampayan (umeshv@apple.com) - * Created. Derived from _setjmp.s, setjmp.c and setjmp.s - */ - -#include "SYS.h" -#include -#include "_setjmp.h" - -/* - * setjmp routines - */ - -/* int sigsetjmp(sigjmp_buf env, int savemask); */ - -LEAF(_sigsetjmp) - cmpwi cr1,r4,0 ; this changes cr1[EQ] which is volatile - stw r4, JMP_SIGFLAG(r3) ; save the sigflag for use by siglongjmp() - beq- cr1, L__setjmp ; if r4 == 0 do _setjmp() - ; else *** fall through *** to setjmp() - -/* int setjmp(jmp_buf env); */ - -LEAF(_setjmp) -L_setjmp: - mflr r0 - stw r31, JMP_r31(r3) - stw r0, JMP_lr(r3) - mr r31, r3 - li r3, 0 ; get the previous signal mask - CALL_EXTERN(_sigblock) - stw r3, JMP_sig(r31) ; save the previous mask - mr r3, r31 - lwz r0, JMP_lr(r3) - mtlr r0 - lwz r31, JMP_r31(r3) -L__setjmp: - BRANCH_EXTERN(__setjmp) diff --git a/sys.subproj/ppc.subproj/setpgid.s b/sys.subproj/ppc.subproj/setpgid.s deleted file mode 100644 index 55dea92..0000000 --- a/sys.subproj/ppc.subproj/setpgid.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(setpgid, 2) - blr - diff --git a/sys.subproj/ppc.subproj/setpriority.s b/sys.subproj/ppc.subproj/setpriority.s deleted file mode 100644 index f550c21..0000000 --- a/sys.subproj/ppc.subproj/setpriority.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(setpriority, 3) - blr - diff --git a/sys.subproj/ppc.subproj/setprivexec.s b/sys.subproj/ppc.subproj/setprivexec.s deleted file mode 100644 index dfcb10e..0000000 --- a/sys.subproj/ppc.subproj/setprivexec.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(setprivexec, 3) - blr - diff --git a/sys.subproj/ppc.subproj/setquota.s b/sys.subproj/ppc.subproj/setquota.s deleted file mode 100644 index edc8f40..0000000 --- a/sys.subproj/ppc.subproj/setquota.s +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -#define SYS_setquota 148 - -SYSCALL(setquota, 2) - blr diff --git a/sys.subproj/ppc.subproj/setrlimit.s b/sys.subproj/ppc.subproj/setrlimit.s deleted file mode 100644 index 36796f0..0000000 --- a/sys.subproj/ppc.subproj/setrlimit.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(setrlimit, 2) - blr - diff --git a/sys.subproj/ppc.subproj/setsid.s b/sys.subproj/ppc.subproj/setsid.s deleted file mode 100644 index 793019c..0000000 --- a/sys.subproj/ppc.subproj/setsid.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(setsid, 0) - blr - diff --git a/sys.subproj/ppc.subproj/setsockopt.s b/sys.subproj/ppc.subproj/setsockopt.s deleted file mode 100644 index a5eb732..0000000 --- a/sys.subproj/ppc.subproj/setsockopt.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(setsockopt, 5) - blr - diff --git a/sys.subproj/ppc.subproj/settimeofday.s b/sys.subproj/ppc.subproj/settimeofday.s deleted file mode 100644 index 322876f..0000000 --- a/sys.subproj/ppc.subproj/settimeofday.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(settimeofday, 2) - blr - diff --git a/sys.subproj/ppc.subproj/setuid.s b/sys.subproj/ppc.subproj/setuid.s deleted file mode 100644 index d9d5dff..0000000 --- a/sys.subproj/ppc.subproj/setuid.s +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(setuid, 1) - blr diff --git a/sys.subproj/ppc.subproj/shm_open.s b/sys.subproj/ppc.subproj/shm_open.s deleted file mode 100644 index 28c8418..0000000 --- a/sys.subproj/ppc.subproj/shm_open.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(shm_open, 3) - blr - diff --git a/sys.subproj/ppc.subproj/shm_unlink.s b/sys.subproj/ppc.subproj/shm_unlink.s deleted file mode 100644 index 514dbf9..0000000 --- a/sys.subproj/ppc.subproj/shm_unlink.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(shm_unlink, 3) - blr - diff --git a/sys.subproj/ppc.subproj/shmat.s b/sys.subproj/ppc.subproj/shmat.s deleted file mode 100644 index f0752cc..0000000 --- a/sys.subproj/ppc.subproj/shmat.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(shmat, 3) - blr - diff --git a/sys.subproj/ppc.subproj/shmctl.s b/sys.subproj/ppc.subproj/shmctl.s deleted file mode 100644 index ef50a7f..0000000 --- a/sys.subproj/ppc.subproj/shmctl.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(shmctl, 3) - blr - diff --git a/sys.subproj/ppc.subproj/shmdt.s b/sys.subproj/ppc.subproj/shmdt.s deleted file mode 100644 index ca48fc6..0000000 --- a/sys.subproj/ppc.subproj/shmdt.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(shmdt, 3) - blr - diff --git a/sys.subproj/ppc.subproj/shmget.s b/sys.subproj/ppc.subproj/shmget.s deleted file mode 100644 index c9237ed..0000000 --- a/sys.subproj/ppc.subproj/shmget.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(shmget, 3) - blr - diff --git a/sys.subproj/ppc.subproj/shmsys.s b/sys.subproj/ppc.subproj/shmsys.s deleted file mode 100644 index 846b113..0000000 --- a/sys.subproj/ppc.subproj/shmsys.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(shmsys, 3) - blr - diff --git a/sys.subproj/ppc.subproj/shutdown.s b/sys.subproj/ppc.subproj/shutdown.s deleted file mode 100644 index 65970a1..0000000 --- a/sys.subproj/ppc.subproj/shutdown.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(shutdown, 2) - blr - diff --git a/sys.subproj/ppc.subproj/sigaltstack.s b/sys.subproj/ppc.subproj/sigaltstack.s deleted file mode 100644 index 1e28861..0000000 --- a/sys.subproj/ppc.subproj/sigaltstack.s +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(sigaltstack, 3) - blr diff --git a/sys.subproj/ppc.subproj/sigpending.s b/sys.subproj/ppc.subproj/sigpending.s deleted file mode 100644 index 8da6e14..0000000 --- a/sys.subproj/ppc.subproj/sigpending.s +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(sigpending, 1) - blr diff --git a/sys.subproj/ppc.subproj/sigreturn.s b/sys.subproj/ppc.subproj/sigreturn.s deleted file mode 100644 index 2f7f0f3..0000000 --- a/sys.subproj/ppc.subproj/sigreturn.s +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* Copyright (c) 1992 NeXT Computer, Inc. All rights reserved. - * - * File: libc/m98k/sys/sigreturn.s - * - * The sigreturn() system call. - * - * The M98K sigcontext structure is more robust than older cousins. - * This routine is responsible for restoring register state - * based on the setting of sc_regs_saved before trapping into the - * kernel. See - * - * HISTORY - * 18-Nov-92 Ben Fathi (benf@next.com) - * Ported to m98k. - * - * 13-Jan-92 Peter King (king@next.com) - * Created. - */ - -#import "assym.h" -#import "SYS.h" - -/* - * r3 = sigcontext pointer - */ - -LEAF(_sigreturn) - - /* Now call the kernel routine to restore the rest */ - - SYSCALL_NONAME(sigreturn, 1) - blr -END(_sigreturn) diff --git a/sys.subproj/ppc.subproj/socket.s b/sys.subproj/ppc.subproj/socket.s deleted file mode 100644 index db1141a..0000000 --- a/sys.subproj/ppc.subproj/socket.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(socket, 3) - blr - diff --git a/sys.subproj/ppc.subproj/socketpair.s b/sys.subproj/ppc.subproj/socketpair.s deleted file mode 100644 index 55e96dc..0000000 --- a/sys.subproj/ppc.subproj/socketpair.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(socketpair, 5) - blr - diff --git a/sys.subproj/ppc.subproj/stat.s b/sys.subproj/ppc.subproj/stat.s deleted file mode 100644 index 4b731d4..0000000 --- a/sys.subproj/ppc.subproj/stat.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(stat, 2) - blr - diff --git a/sys.subproj/ppc.subproj/statfs.s b/sys.subproj/ppc.subproj/statfs.s deleted file mode 100644 index e2833c3..0000000 --- a/sys.subproj/ppc.subproj/statfs.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(statfs, 2) - blr - diff --git a/sys.subproj/ppc.subproj/statv.s b/sys.subproj/ppc.subproj/statv.s deleted file mode 100644 index 1979fea..0000000 --- a/sys.subproj/ppc.subproj/statv.s +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* Copyright 1998 Apple Computer, Inc. */ - -#include "SYS.h" - -SYSCALL(statv, 0) - blr diff --git a/sys.subproj/ppc.subproj/swapon.s b/sys.subproj/ppc.subproj/swapon.s deleted file mode 100644 index b6af343..0000000 --- a/sys.subproj/ppc.subproj/swapon.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(swapon, 1) - blr - diff --git a/sys.subproj/ppc.subproj/symlink.s b/sys.subproj/ppc.subproj/symlink.s deleted file mode 100644 index 9c8bb6e..0000000 --- a/sys.subproj/ppc.subproj/symlink.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(symlink, 2) - blr - diff --git a/sys.subproj/ppc.subproj/sync.s b/sys.subproj/ppc.subproj/sync.s deleted file mode 100644 index 308892e..0000000 --- a/sys.subproj/ppc.subproj/sync.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(sync, 0) - blr - diff --git a/sys.subproj/ppc.subproj/syscall.s b/sys.subproj/ppc.subproj/syscall.s deleted file mode 100644 index fec2d28..0000000 --- a/sys.subproj/ppc.subproj/syscall.s +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* Copyright (c) 1992 NeXT Computer, Inc. All rights reserved. */ - -#include "SYS.h" - -PSEUDO(syscall, syscall, 7) - blr diff --git a/sys.subproj/ppc.subproj/table.s b/sys.subproj/ppc.subproj/table.s deleted file mode 100644 index 6c24f1c..0000000 --- a/sys.subproj/ppc.subproj/table.s +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(table, 5) - blr diff --git a/sys.subproj/ppc.subproj/truncate.s b/sys.subproj/ppc.subproj/truncate.s deleted file mode 100644 index 0b43058..0000000 --- a/sys.subproj/ppc.subproj/truncate.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(truncate, 2) - blr - diff --git a/sys.subproj/ppc.subproj/umask.s b/sys.subproj/ppc.subproj/umask.s deleted file mode 100644 index b5b594b..0000000 --- a/sys.subproj/ppc.subproj/umask.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(umask, 1) - blr - diff --git a/sys.subproj/ppc.subproj/undelete.s b/sys.subproj/ppc.subproj/undelete.s deleted file mode 100644 index d26927f..0000000 --- a/sys.subproj/ppc.subproj/undelete.s +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(undelete, 1) - blr diff --git a/sys.subproj/ppc.subproj/unlink.s b/sys.subproj/ppc.subproj/unlink.s deleted file mode 100644 index ef6071a..0000000 --- a/sys.subproj/ppc.subproj/unlink.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(unlink, 1) - blr - diff --git a/sys.subproj/ppc.subproj/unmount.s b/sys.subproj/ppc.subproj/unmount.s deleted file mode 100644 index 20e114b..0000000 --- a/sys.subproj/ppc.subproj/unmount.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(unmount, 1) - blr - diff --git a/sys.subproj/ppc.subproj/ur_cthread.s b/sys.subproj/ppc.subproj/ur_cthread.s deleted file mode 100644 index 50ff2be..0000000 --- a/sys.subproj/ppc.subproj/ur_cthread.s +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ - .text - .align 2 - .globl _pthread_self -_pthread_self: - li r0, 0x7FF2 - sc - blr diff --git a/sys.subproj/ppc.subproj/utimes.s b/sys.subproj/ppc.subproj/utimes.s deleted file mode 100644 index abb5f14..0000000 --- a/sys.subproj/ppc.subproj/utimes.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(utimes, 2) - blr - diff --git a/sys.subproj/ppc.subproj/vfork.s b/sys.subproj/ppc.subproj/vfork.s deleted file mode 100644 index 14bc4f3..0000000 --- a/sys.subproj/ppc.subproj/vfork.s +++ /dev/null @@ -1,180 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* Copyright (c) 1998 Apple Computer, Inc. All rights reserved. - * - * File: libc/ppc/sys/vfork.s - * - * HISTORY - * 23-Jun-1998 Umesh Vaishampayan (umeshv@apple.com) - * Created from fork.s - * - */ - -#if 0 -#import -#import -#import -#import - -/* We use 8 bytes for LOCAL_VAR(1) and LOCAL_VAR(2) */ -NESTED(_vfork, 8, 0, 0, 0) - CALL_EXTERN(__cthread_fork_prepare) -#if defined(__DYNAMIC__) -.cstring -LC1: - .ascii "__dyld_fork_prepare\0" -.text - .align 2 - mflr r0 - bl 1f -1: mflr r3 - mtlr r0 - addis r3,r3,ha16(LC1-1b) - addi r3,r3,lo16(LC1-1b) - addi r4,r1,LOCAL_VAR(1) - bl __dyld_func_lookup - lwz r3,LOCAL_VAR(1)(r1) - mtspr ctr,r3 - bctrl -#endif - li r0,SYS_vfork - sc - b Lbotch // error return - - cmpwi r4,0 - beq Lparent // parent, since a1 == 0 in parent, - // 1 in child -#if defined(__DYNAMIC__) -.cstring -LC3: - .ascii "__dyld_fork_child\0" -.text - .align 2 - mflr r0 - bl 1f -1: mflr r3 - mtlr r0 - addis r3,r3,ha16(LC3-1b) - addi r3,r3,lo16(LC3-1b) - addi r4,r1,LOCAL_VAR(1) - bl __dyld_func_lookup - lwz r3,LOCAL_VAR(1)(r1) - mtspr ctr,r3 - bctrl -#endif - CALL_EXTERN(_fork_mach_init) - CALL_EXTERN(__cthread_fork_child) -#if defined(__DYNAMIC__) -.cstring -LC4: - .ascii "__dyld_fork_child_final\0" -.text - .align 2 - mflr r0 - bl 1f -1: mflr r3 - mtlr r0 - addis r3,r3,ha16(LC4-1b) - addi r3,r3,lo16(LC4-1b) - addi r4,r1,LOCAL_VAR(1) - bl __dyld_func_lookup - lwz r3,LOCAL_VAR(1)(r1) - mtspr ctr,r3 - bctrl -#endif - - li r3,0 - b Lreturn - -Lparent: -#if defined(__DYNAMIC__) - stw r3,LOCAL_VAR(2)(r1) // save child pid - mflr r0 - bl 1f -1: mflr r3 - mtlr r0 - addis r3,r3,ha16(LC2-1b) - addi r3,r3,lo16(LC2-1b) - addi r4,r1,LOCAL_VAR(1) - bl __dyld_func_lookup - lwz r3,LOCAL_VAR(1)(r1) - mtspr ctr,r3 - bctrl -#endif - CALL_EXTERN(__cthread_fork_parent) -#if defined(__DYNAMIC__) - lwz r3,LOCAL_VAR(2)(r1) -#endif - b Lreturn - -Lbotch: -#if defined(__DYNAMIC__) -.cstring -LC2: - .ascii "__dyld_fork_parent\0" -.text - .align 2 - stw r3,LOCAL_VAR(2)(r1) // save error value - mflr r0 - bl 1f -1: mflr r3 - mtlr r0 - addis r3,r3,ha16(LC2-1b) - addi r3,r3,lo16(LC2-1b) - addi r4,r1,LOCAL_VAR(1) - bl __dyld_func_lookup - lwz r3,LOCAL_VAR(1)(r1) - mtspr ctr,r3 - bctrl - lwz r3,LOCAL_VAR(2)(r1) // restore error value for cerror - -#endif - CALL_EXTERN(cerror) - /* - * We use cthread_fork_parent() to clean up after a fork error - * (unlock cthreads and mailloc packages) so the parent - * process can Malloc() after fork() errors without - * deadlocking. - */ - CALL_EXTERN_AGAIN(__cthread_fork_parent) - li32 r3,-1 // error return -Lreturn: RETURN -END(_vfork) -#else -#include "SYS.h" - -.text -.align 2 -.globl _vfork -_vfork: - li r0,SYS_vfork - sc - b Lbotch // error return - - cmpwi r4,0 - beqlr // parent, since a1 == 0 in parent, - li r3,0 - blr -Lbotch: - BRANCH_EXTERN(cerror) -#endif - diff --git a/sys.subproj/ppc.subproj/wait4.s b/sys.subproj/ppc.subproj/wait4.s deleted file mode 100644 index 56c6921..0000000 --- a/sys.subproj/ppc.subproj/wait4.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(wait4, 4) - blr - diff --git a/sys.subproj/ppc.subproj/write.s b/sys.subproj/ppc.subproj/write.s deleted file mode 100644 index ef0833d..0000000 --- a/sys.subproj/ppc.subproj/write.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(write, 3) - blr - diff --git a/sys.subproj/ppc.subproj/writev.s b/sys.subproj/ppc.subproj/writev.s deleted file mode 100644 index 499ce7f..0000000 --- a/sys.subproj/ppc.subproj/writev.s +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -#include "SYS.h" - -SYSCALL(writev, 3) - blr - diff --git a/sys.subproj/sem_close.2 b/sys.subproj/sem_close.2 deleted file mode 100644 index 9d09d20..0000000 --- a/sys.subproj/sem_close.2 +++ /dev/null @@ -1,61 +0,0 @@ -.\" $Darwin$ -.\" -.\" Wilfredo Sanchez, wsanchez@apple.com -.\" Copyright (c) 2000 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@ -.\" -.Dd June 8, 2000 -.Dt SEM_CLOSE 2 -.Os Darwin -.Sh NAME -.Nm sem_close -.Nd close a named semaphore -.Sh SYNOPSIS -.Fd #include -.Ft int -.Fn sem_close "sem_t *sem" -.Sh DESCRIPTION -The system resources associated with the named semaphore referenced by -.Fa sem -are deallocated and the descriptor is invalidated. -.Pp -If successful, -.Fn sem_close -will return 0. Otherwise, -1 is returned and -.Va errno -is set. -.Sh ERRORS -.Fn sem_close -succeeds unless: -.Bl -tag -width Er -.It Bq Er EINVAL -.Fa sem -is not a valid semaphore descriptor. -.El -.Sh SEE ALSO -.Xr semctl 2 , -.Xr semget 2 , -.Xr semop 2 , -.Xr sem_init 2 , -.Xr sem_open 2 , -.Xr sem_unlink 2 -.Sh HISTORY -.Fn sem_close -is specified in the POSIX Realtime Extension (1003.1b-1993/1003.1i-1995). diff --git a/sys.subproj/sem_open.2 b/sys.subproj/sem_open.2 deleted file mode 100644 index 582bb25..0000000 --- a/sys.subproj/sem_open.2 +++ /dev/null @@ -1,163 +0,0 @@ -.\" $Darwin$ -.\" -.\" Wilfredo Sanchez, wsanchez@apple.com -.\" Copyright (c) 2000 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@ -.\" -.Dd June 8, 2000 -.Dt SEM_OPEN 2 -.Os Darwin -.Sh NAME -.Nm sem_open -.Nd initialize and open a named semaphore -.Sh SYNOPSIS -.Fd #include -.Ft sem_t * -.Fn sem_open "const char *name" "int flags" -.Ft sem_t * -.Fn sem_open "const char *name" "int flags" "mode_t mode" "unsigned int value" -.Sh DESCRIPTION -The named semaphore named -.Fa name -is initialized and opened as specified by the argument -.Fa flags -and a semaphore descriptor is returned to the calling process. -.Pp -The flags specified are formed by -.Em or Ns 'ing -the following values: -.Pp -.Bd -literal -offset indent -compact -O_CREAT create the semaphore if it does not exist -O_EXCL error if create and semaphore exists -.Ed -.Pp -If -.Dv O_CREATE -if specified, -.Fn sem_open -requires an additional two arguments. -.Fa mode -specifies the permissions for the semaphore as described in -.Xr chmod 2 -and modified by the process' umask value (see -.Xr umask 2 ) . -The semaphore is created with an initial -.Fa value , -which must be less than or equal to -.Dv SEM_VALUE_MAX . -.Pp -If -.Dv O_EXCL -is specified and the semaphore exists, -.Fn sem_open -fails. The check for the existence of the semaphore and the creation -of the semaphore are atomic with respect to all processes calling -.Fn sem_open -with -.Dv O_CREAT -and -.Dv O_EXCL -set. -.Pp -When a new semaphore is created, it is given the user ID and group ID -which coorespond to the effective user and group IDs of the calling -process. There is no visible entry in the file system for the created -object in this implementation. -.Pp -The returned semaphore descriptor is available to the calling process -until it is closed with -.Fn sem_close , -or until the caller exits or execs. -.Pp -If a process makes repeated calls to -.Fn sem_open , -with the same -.Fa name -argument, the same descriptor is returned for each successful call, -unless -.Fn sem_unlink -has been called on the semaphore in the interim. -.Pp -If -.Fn sem_open -fails for any reason, it will return a value of -.Dv SEM_FAILED -and sets -.Va errno . -On success, it returns a semaphore descriptor. -.Sh ERRORS -The named semaphore is opened unless: -.Bl -tag -width Er -.It Bq Er EACCES -The required permissions (for reading and/or writing) -are denied for the given flags; or -.Dv O_CREAT -is specified, the object does not exist, and permission to -create the semaphore is denied. -.It Bq Er EEXIST -.Dv O_CREAT -and -.Dv O_EXCL -were specified and the semaphore exists. -.It Bq Er EINTR -The -.Fn sem_open -operation was interrupted by a signal. -.It Bq Er EINVAL -The -.Fn shm_open -operation is not supported; or -.Dv O_CREAT -is specified and -.Fa value -exceeds -.Dv SEM_VALUE_MAX . -.It Bq Er EMFILE -The process has already reached its limit for semaphores or file -descriptors in use. -.It Bq Er ENAMETOOLONG -.Fa name -exceeded -.Dv SEM_NAME_LEN -characters. -.It Bq Er ENFILE -Too many semaphores or file descriptors are open on the system. -.It Bq Er ENOENT -.Dv O_CREAT -is not set and the named semaphore does not exist. -.It Bq Er ENOSPC -.Dv O_CREAT -is specified, the file does not exist, and there is insufficient -space available to create the semaphore. -.El -.Sh SEE ALSO -.Xr semctl 2 , -.Xr semget 2 , -.Xr semop 2 , -.Xr sem_close 2 , -.Xr sem_post 2 , -.Xr sem_trywait 2 , -.Xr sem_unlink 2 , -.Xr sem_wait 2 , -.Xr umask 2 -.Sh HISTORY -.Fn sem_open -is specified in the POSIX Realtime Extension (1003.1b-1993/1003.1i-1995). diff --git a/sys.subproj/sem_post.2 b/sys.subproj/sem_post.2 deleted file mode 100644 index 8f2b285..0000000 --- a/sys.subproj/sem_post.2 +++ /dev/null @@ -1,66 +0,0 @@ -.\" $Darwin$ -.\" -.\" Wilfredo Sanchez, wsanchez@apple.com -.\" Copyright (c) 2000 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@ -.\" -.Dd June 8, 2000 -.Dt SEM_POST 2 -.Os Darwin -.Sh NAME -.Nm sem_post -.Nd unlock a semaphore -.Sh SYNOPSIS -.Fd #include -.Ft int -.Fn sem_post "sem_t *sem" -.Sh DESCRIPTION -The the semaphore referenced by -.Fa sem -is unlocked, the value of the semaphore is incremented, and all -threads which are waiting on the semaphore are awakened. -.Pp -.Fn sem_post -is reentrant with respect to signals and may be called from within a -signal hanlder. -.Pp -If successful, -.Fn sem_post -will return 0. Otherwise, -1 is returned and -.Va errno -is set. -.Sh ERRORS -.Fn sem_post -succeeds unless: -.Bl -tag -width Er -.It Bq Er EINVAL -.Fa sem -is not a valid semaphore descriptor. -.El -.Sh SEE ALSO -.Xr semctl 2 , -.Xr semget 2 , -.Xr semop 2 , -.Xr sem_open 2 , -.Xr sem_trywait 2 , -.Xr sem_wait 2 -.Sh HISTORY -.Fn sem_post -is specified in the POSIX Realtime Extension (1003.1b-1993/1003.1i-1995). diff --git a/sys.subproj/sem_trywait.2 b/sys.subproj/sem_trywait.2 deleted file mode 100644 index c0db675..0000000 --- a/sys.subproj/sem_trywait.2 +++ /dev/null @@ -1 +0,0 @@ -.so man2/sem_wait.2 diff --git a/sys.subproj/sem_unlink.2 b/sys.subproj/sem_unlink.2 deleted file mode 100644 index 785862d..0000000 --- a/sys.subproj/sem_unlink.2 +++ /dev/null @@ -1,75 +0,0 @@ -.\" $Darwin$ -.\" -.\" Wilfredo Sanchez, wsanchez@apple.com -.\" Copyright (c) 2000 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@ -.\" -.Dd June 8, 2000 -.Dt SEM_UNLINK 2 -.Os Darwin -.Sh NAME -.Nm sem_unlink -.Nd remove a named semaphore -.Sh SYNOPSIS -.Fd #include -.Ft int -.Fn sem_unlink "const char *name" -.Sh DESCRIPTION -The named semaphore named -.Fa name -is removed. If the semaphore is in use my other processes, then -.Fa name -is immeditately dissasociated with the semaphore, but the semaphore -itself will not be removed until all references to it have been -closed. Subsequent calls to -.Fn sem_open -using -.Fa name -will refer to or create a new semaphore named -.Fa name . -.Pp -If successful, -.Fn sem_close -will return 0. Otherwise, -1 is returned and -.Va errno -is set, and the state of the semaphore is unchanged. -.Sh ERRORS -.Fn sem_unlink -succeeds unless: -.Bl -tag -width Er -.It Bq Er EACCES -Permission is denied to be remove the semaphore. -.It Bq Er ENAMETOOLONG -.Fa name -exceeded -.Dv SEM_NAME_LEN -characters. -.It Bq Er ENOENT -The named semaphore does not exist. -.El -.Sh SEE ALSO -.Xr semctl 2 , -.Xr semget 2 , -.Xr semop 2 , -.Xr sem_close 2 , -.Xr sem_open 2 -.Sh HISTORY -.Fn sem_unlink -is specified in the POSIX Realtime Extension (1003.1b-1993/1003.1i-1995). diff --git a/sys.subproj/sem_wait.2 b/sys.subproj/sem_wait.2 deleted file mode 100644 index db5a1b8..0000000 --- a/sys.subproj/sem_wait.2 +++ /dev/null @@ -1,89 +0,0 @@ -.\" $Darwin$ -.\" -.\" Wilfredo Sanchez, wsanchez@apple.com -.\" Copyright (c) 2000 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@ -.\" -.Dd June 8, 2000 -.Dt SEM_WAIT 2 -.Os Darwin -.Sh NAME -.Nm sem_wait, sem_trywait -.Nd lock a semaphore -.Sh SYNOPSIS -.Fd #include -.Ft int -.Fn sem_wait "sem_t *sem" -.Ft int -.Fn sem_trywait "sem_t *sem" -.Sh DESCRIPTION -The semaphore referenced by -.Fa sem -is locked. When calling -.Fn sem_wait , -if the semaphore's value is zero, the calling thread will block until -the lock is aquired or until the call is interrupted by a -signal. Alternatively, the -.Fn sem_trywait -function will fail if the semaphore is already locked, rather than -blocking on the semaphore. -.Pp -If successful (the lock was aquired), -.Fn sem_wait -and -.Fn sem_trywait -will return 0. Otherwise, -1 is returned and -.Va errno -is set, and the state of the semaphore is unchanged. -.Sh ERRORS -.Fn sem_wait -and -.Fn sem_trywait -succeed unless: -.Bl -tag -width Er -.It Bq Er EAGAIN -The semaphore is already locked. -.It Bq Er EINVAL -.Fa sem -is not a valid semaphore descriptor. -.It Bq Er EDEADLK -A deadlock was detected. -.It Bq Er EINTR -The call was interrupted by a signal. -.El -.Sh NOTES -Applications may encounter a priority inversion while using -semaphores. When a thread is waiting on a semaphore which is about to -be posted by a lower-priority thread and the lower-priority thread is -preempted by another thread (of medium priority), a priority inversion -has occured, and the higher-priority thread will be blocked for an -unlimited time period. Programmers using the realtime functionality -of the system should take care to avoid priority inversions. -.Sh SEE ALSO -.Xr semctl 2 , -.Xr semget 2 , -.Xr semop 2 , -.Xr sem_open 2 , -.Xr sem_post 2 -.Sh HISTORY -.Fn sem_wait -and -.Fn sem_trywait -are specified in the POSIX Realtime Extension (1003.1b-1993/1003.1i-1995). diff --git a/sys.subproj/shm_open.2 b/sys.subproj/shm_open.2 deleted file mode 100644 index 24dac52..0000000 --- a/sys.subproj/shm_open.2 +++ /dev/null @@ -1,176 +0,0 @@ -.\" $Darwin$ -.\" -.\" Wilfredo Sanchez, wsanchez@apple.com -.\" Copyright (c) 1999 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@ -.\" -.Dd September 20, 1999 -.Dt SHM_OPEN 2 -.Os Darwin -.Sh NAME -.Nm shm_open -.Nd open a shared memory object -.Sh SYNOPSIS -.Fd #include -.Ft int -.Fn shm_open "const char *name" "int flags" "mode_t mode" -.Sh DESCRIPTION -The shared memory object referenced by -.Fa name -is opened for reading and/or writing as specified by the argument -.Fa flags -and the file descriptor returned to the calling process. -The returned file descriptor will be the lowest non-open file -descriptor for the calling process, and is not shared with any -other processes, as it is a new file descriptor. The new file -descriptor will have the -.Dv FD_CLOEXEC -flag set. -Repeated calls -to -.Nm shm_open -with the same string value for -.Fn name -will return a file descriptor referring to the same shared memory -object, provided that the object has not been unlinked by a call to -.Fn shm_unlink . -The -.Fa flags -argument may indicate the file is to be -created if it does not exist (by specifying the -.Dv O_CREAT -flag), in which case the file is created with mode -.Fa mode -as described in -.Xr chmod 2 -and modified by the process' umask value (see -.Xr umask 2 ) . -.Pp -The flags specified are formed by -.Em or Ns 'ing -the following values: -.Pp -.Bd -literal -offset indent -compact -O_RDONLY open for reading only -O_RDWR open for reading and writing -O_CREAT create object if it does not exist -O_EXCL error if create and object exists -O_TRUNC truncate size to 0 -.Ed -.Pp -Exactly one of -.Dv O_RDONLY -or -.Dv O_RDWR -must be specified. -.Pp -If -.Dv O_TRUNC -is specified and the -file exists, the file is truncated to zero length. -If -.Dv O_EXCL -is set with -.Dv O_CREAT -and the file already -exists, -.Fn shm_open -returns an error. This may be used to -implement a simple exclusive access locking mechanism. -.Pp -If successful, -.Fn shm_open -returns a non-negative integer, termed a file descriptor. -It returns -1 and sets -.Va errno -on failure. -The file pointer used to mark the current position within the -memory object is set to the beginning of the object. -.Pp -When a new shared memory object is created it is given the -owner and group corresponding to the effective user and -group of the calling process. There is no visible entry in the -file system for the created object in this implementation. -.Pp -When a shared memory object is created, it persists until it -it unlinked and all other references are gone. Objects do -not persist across a system reboot. -.Pp -The new descriptor is set to remain open across -.Xr execve -system calls; see -.Xr close 2 -and -.Xr fcntl 2 . -.Pp -The system imposes a limit on the number of file descriptors -open simultaneously by one process. -.Xr Getdtablesize 2 -returns the current system limit. -.Sh ERRORS -The named object is opened unless: -.Bl -tag -width Er -.It Bq Er EACCES -The required permissions (for reading and/or writing) -are denied for the given flags. -.It Bq Er EACCES -.Dv O_CREAT -is specified, the object does not exist, and permission to -create the object is denied. -.It Bq Er EEXIST -.Dv O_CREAT -and -.Dv O_EXCL -were specified and the object exists. -.It Bq Er EINTR -The -.Fn shm_open -operation was interrupted by a signal. -.It Bq Er EINVAL -The -.Fn shm_open -operation is not supported. -.It Bq Er EMFILE -The process has already reached its limit for open file descriptors. -.It Bq Er ENAMETOOLONG -.Fa name -exceeded -.Dv SHM_NAME_MAX -characters. -.It Bq Er ENFILE -The system file table is full. -.It Bq Er ENOENT -.Dv O_CREAT -is not set and the named object does not exist. -.It Bq Er ENOSPC -.Dv O_CREAT -is specified, the file does not exist, and there is insufficient -space available to create the object. -.El -.Sh SEE ALSO -.Xr chmod 2 , -.Xr close 2 , -.Xr getdtablesize 2 , -.Xr mmap 2 , -.Xr shm_unlink 2 , -.Xr umask 2 -.Sh HISTORY -.Fn shm_open -is specified in the POSIX Realtime Extension (1003.1b-1993/1003.1i-1995). diff --git a/sys.subproj/shm_unlink.2 b/sys.subproj/shm_unlink.2 deleted file mode 100644 index a2a2191..0000000 --- a/sys.subproj/shm_unlink.2 +++ /dev/null @@ -1,74 +0,0 @@ -.\" $Darwin$ -.\" -.\" Wilfredo Sanchez, wsanchez@apple.com -.\" Copyright (c) 1999 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@ -.\" -.Dd September 20, 1999 -.Dt SHM_UNLINK 2 -.Os Darwin -.Sh NAME -.Nm shm_unlink -.Nd remove shared memory object -.Sh SYNOPSIS -.Fd #include -.Ft int -.Fn shm_unlink "const char *name" -.Sh DESCRIPTION -The -.Fn shm_unlink -function removes the shared memory object named by -.Fa name . -If no process has the file open, then all resources associated -with the object are reclaimed. -If one or more process have the object open, the name removed, -but the removal of the memory object is delayed until all -references to it have been closed. -.Sh RETURN VALUES -Upon successful completion, a value of 0 is returned. -Otherwise, a value of -1 is returned and -.Va errno -is set to indicate the error, and the named shared memory object -will remain unchanged. -.Sh ERRORS -The -.Fn shm_unlink -succeeds unless: -.Bl -tag -width Er -.It Bq Er EACCES -Permission is denied to be remove the object. -.It Bq Er ENAMETOOLONG -.Fa name -exceeded -.Dv SHM_NAME_MAX -characters. -.It Bq Er ENOENT -The named object does not exist. -.El -.Sh SEE ALSO -.Xr close 2 , -.Xr mmap 2 , -.Xr munmap 2 , -.Xr shmat 2 , -.Xr shmctl 2 , -.Xr shm_open 2 -.Sh HISTORY -.Fn shm_open -is specified in the POSIX Realtime Extension (1003.1b-1993/1003.1i-1995). diff --git a/sys.subproj/sigaction.c b/sys.subproj/sigaction.c deleted file mode 100644 index 5f57366..0000000 --- a/sys.subproj/sigaction.c +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - * - * @(#)sigaction.c 1.0 - */ - -#include -#include -#include -#include - -/* - * Intercept the sigaction syscall and use our signal trampoline - * as the signal handler instead. The code here is derived - * from sigvec in sys/kern_sig.c. - */ - -extern void (*sigcatch[NSIG])(); -#if defined(__DYNAMIC__) -extern int __in_sigtramp; -#endif - -static int -sigaction__ (sig, nsv, osv, bind) - int sig; - register struct sigaction *nsv, *osv; - int bind; -{ - struct sigaction vec; - void (*prevsig)(); - extern void _sigtramp(); - - if (sig <= 0 || sig >= NSIG || sig == SIGKILL || sig == SIGSTOP) { - errno = EINVAL; - return (-1); - } - prevsig = sigcatch[sig]; - if (nsv) { - sigcatch[sig] = nsv->sa_handler; - vec = *nsv; nsv = &vec; - if (nsv->sa_handler != (void (*)())SIG_DFL && nsv->sa_handler != (void (*)())SIG_IGN) { - nsv->sa_handler = _sigtramp; -#ifdef __DYNAMIC__ - if (bind && (__in_sigtramp == 0)) // XXX - _dyld_bind_fully_image_containing_address(sigcatch[sig]); -#endif - } - } - if (syscall (SYS_sigaction, sig, nsv, osv) < 0) { - sigcatch[sig] = prevsig; - return (-1); - } - if (osv && prevsig) - osv->sa_handler = prevsig; - 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__ - -int -_sigaction_nobind (sig, nsv, osv) - int sig; - register const struct sigaction *nsv; - register struct sigaction *osv; -{ - return sigaction__(sig, nsv, osv, 0); -} -#endif - diff --git a/sys.subproj/sigcatch.c b/sys.subproj/sigcatch.c deleted file mode 100644 index 2e19f89..0000000 --- a/sys.subproj/sigcatch.c +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* Copyright (c) 1992 NeXT Computer, Inc. All rights reserved. - * - * This file contains global data and the size of the global data can NOT - * change or otherwise it would make the shared library incompatable. This - * data has been padded so new signals can be added. Also see gen/siglist.c - */ - -#include "sigcatch.h" - -/* - * Actually declare the global data. - */ -sigcatch_t sigcatch[PADDING] = { (void (*)(int, int, struct sigcontext *))0 }; - - diff --git a/sys.subproj/sigcatch.h b/sys.subproj/sigcatch.h deleted file mode 100644 index cf7ef81..0000000 --- a/sys.subproj/sigcatch.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* Copyright (c) 1992 NeXT Computer, Inc. All rights reserved. - * - * File: libc/m98k/sigcatch.h - * - * Header file for sigtramp data structures. - */ - -#include - -/* - * Constants - */ -#define PADDING 50 - -/* - * Type definitions. - */ -typedef void (*sigcatch_t)(int, int, struct sigcontext *); - -/* - * Global data. - */ -extern sigcatch_t sigcatch[PADDING]; diff --git a/sys.subproj/sigprocmask.c b/sys.subproj/sigprocmask.c deleted file mode 100644 index 2407eb6..0000000 --- a/sys.subproj/sigprocmask.c +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* @(#)sigprocmask.c 1.0 9/26/95 (c) 1995 NeXT */ - -#include -#include -#include -#include - -/* - * Translate sigprocmask call to system call interface. - */ - -int sigprocmask ( - int how, - const sigset_t *nsm, - sigset_t *osm) -{ - sigset_t mask; - - if (nsm == 0) { - how = SIG_BLOCK; - sigemptyset(&mask); - } else { - mask = *nsm; - } - mask = (sigset_t) syscall(SYS_sigprocmask, how, mask); - /* syscall will call cerror if there is an error */ - if (osm) - *osm = mask; - return 0; -} diff --git a/sys.subproj/sigsuspend.c b/sys.subproj/sigsuspend.c deleted file mode 100644 index dcc65be..0000000 --- a/sys.subproj/sigsuspend.c +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* @(#)sigsuspend.c 1.0 9/22/95 (c) 1995 NeXT */ - -#include -#include -#include - -int -sigsuspend ( - const sigset_t *sigmask_p -) -{ - sigset_t mask; - - if (sigmask_p) - mask = *sigmask_p; - else - sigemptyset(&mask); - return syscall (SYS_sigsuspend, mask); -} - diff --git a/sys.subproj/sigtramp.c b/sys.subproj/sigtramp.c deleted file mode 100644 index 407add5..0000000 --- a/sys.subproj/sigtramp.c +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved - */ -#import "sigcatch.h" -#import -#import - -/* - * sigvec registers _sigtramp as the handler for any signal requiring - * user-mode intervention. All _sigtramp does is find the real handler, - * calls it, then sigreturn's. - * - * Note that the kernel saves/restores all of our register state. - */ -#if defined(__DYNAMIC__) -int __in_sigtramp = 0; -#endif - -void -_sigtramp( - int code, - int subcode, - struct sigcontext *scp -) { - sigcatch_t catcher; - - catcher = sigcatch[code]; -#if defined(__DYNAMIC__) - __in_sigtramp++; -#endif - catcher(code, subcode, scp); -#if defined(__DYNAMIC__) - __in_sigtramp--; -#endif - sigreturn(scp); -} diff --git a/sys/CLIB-LIST b/sys/CLIB-LIST new file mode 100644 index 0000000..7b30a40 --- /dev/null +++ b/sys/CLIB-LIST @@ -0,0 +1,679 @@ +CIRCLEQ_ENTRY M +CIRCLEQ_HEAD M +CIRCLEQ_INIT M +CIRCLEQ_INSERT_AFTER M +CIRCLEQ_INSERT_BEFORE M +CIRCLEQ_INSERT_HEAD M +CIRCLEQ_INSERT_TAIL M +CIRCLEQ_REMOVE M +LIST_ENTRY M +LIST_HEAD M +LIST_INIT M +LIST_INSERT_AFTER M +LIST_REMOVE M +TAILQ_ENTRY M +TAILQ_HEAD M +TAILQ_INIT M +TAILQ_INSERT_AFTER M +TAILQ_INSERT_HEAD M +TAILQ_INSERT_TAIL M +TAILQ_REMOVE M +_longjmp +_setjmp +abort +abs +acl_add +acl_canocicalize_principal +acl_check +acl_delete +acl_exact_match +acl_initialize +acos +acosh +addch +addstr +alarm +alloca +alphasort +arc +asctime +asin +asinh +assert +atan +atan2 +atanh +atexit +atof +atoi +atol +bcmp +bcopy +bit_alloc M +bit_clear M +bit_decl M +bit_ffc M +bit_ffs M +bit_nclear M +bit_nset M +bit_test M +bitstr_size M +box +bsearch +bypot +bzero +cabs +calloc +cbreak +cbrt +ceil +cfgetispeed +cfgetospeed +cfmakeraw +cfsetispeed +cfsetospeed +cfsetspeed +cgetcap +cgetclose +cgetent +cgetfirst +cgetmatch +cgetnext +cgetnum +cgetset +cgetstr +cgetustr +circle +clear +clearerr +clearok +clock +closedir +closelog +closepl +clrtobot +clrtoeol +confstr +cont +copysign +cos +cosh +crypt +ctermid +ctime +daemon +dbopen +delch +delwin +des_cbc_cksum +des_cbc_encrypt +des_cipher +des_ecb_encrypt +des_pcbc_encrypt +des_quad_cksum +des_random_key +des_read_password +des_set_key +des_setkey +des_string_to_key +devanme +diffti8me +dirfd +div +dleteln +dn_comp +dn_expand +drem +echo +ectv +edata +encrypt +end +endfsent +endgrent +endhostent +endnetent +endnetgrent +endprotoent +endpwent +endservent +endttyent +endusershell +endwin +er +erase +erf +erfc +err +errx +etext +etfc +execl +execle +execlp +exect +execv +execvp +exit +exp +expm1 +fabs +fclose +fctv +fdopen +feof +ferror +fflush +ffs +fgetc +fgetline +fgetln +fgetpos +fgets +fileno +finite +floor +flusok +fmin MP +fmod +fmount MP +fnmatch +fopen +fprintf +fpurge +fputc +fputs +fread +free +freopen +frexp +fropen +fscanf +fseek +fsetpos +ftell +ftime +fts_children +fts_close +fts_open +fts_read +fts_set +funopen +fwopen +fwrite +gamma +gcd MP +gctv +getbsize +getc +getcap +getch +getchar +getcwd +getdiskbyname +getenv +getfsent +getfsfile +getfsspec +getgrent +getgrgid +getgrnam +getgrouplist +gethostbyaddr +gethostbyname +gethostent +gethostid +gethostname +getloadavg +getmntinfo +getmntopts +getmode +getnetbyaddr +getnetbyname +getnetent +getnetgrent +getopt +getpagesize +getpass +getprotobyname +getprotobynumber +getprotoent +getpw +getpwent +getpwnam +getpwuid +gets +getservbyname +getservbyport +getservent +getstr +getsubopt +gettmode +getttyent +getttynam +getusershell +getw +getwd +getyx +glob +globfree +gmtime +group_from_gid +gtty +heapsort +herror +htonl +htons +hypot +inch +index +inet_addr +inet_aton +inet_lnaof +inet_makeaddr +inet_netof +inet_network +inet_ntoa +infnan +initgroups +initscr +initstate +innetgr +insch +insetln +insque +invert MP +isalnum +isalpha +isascii +isatty +isblank +iscntrl +isdigit +isgraph +isinf +islower +isnan +iso_addr +iso_ntoa +isprint +ispunct +isspace +isupper +isxdigit +itom MP +j0 +j1 +jn +krb_err_txt +krb_get_admhst +krb_get_cred +krb_get_krbhst +krb_get_lrealm +krb_get_phost +krb_kntoln +krb_mk_err +krb_mk_priv +krb_mk_req +krb_mk_safe +krb_net_read +krb_net_write +krb_rd_err +krb_rd_priv +krb_rd_req +krb_rd_safe +krb_realmofhost +krb_recvauth +krb_sendauth +krb_set_key +krb_set_tkt_string +kuserok +kvm_close +kvm_getargv +kvm_getenvv +kvm_geterr +kvm_getfiles +kvm_getloadavg +kvm_getprocs +kvm_nlist +kvm_open +kvm_openfiles +kvm_read +kvm_write +label +labs +ldexp +ldiv +leaveok +lfind +lgamma +line +linemod +link_addr +link_ntoa +localeconv +localtime +log +log10 +log1p +logb +longjmp +longjmperror +longname +lsearch +m_in MP +m_out MP +madd MP +malloc +mamcpy +mblen +mbmb +mbrrune +mbrune +mbstowcs +mbtowc +mcmp MP +mdiv MP +memccpy +memchr +memcmp +memcpy +memmove +memset +mergesort +min MP +mkstemp +mktemp +mktime +modf +moncontrol +monstartup +mount MP +move +move MP +mpool_close +mpool_filter +mpool_get +mpool_new +mpool_open +mpool_put +mpool_sync +msqrt MP +msub MP +mult MP +mvcur +newein +nice +nl +nlist +nocbreak +noecho +nonl +noraw +ns_addr +ns_ntoa +ntohl +ntohs +omin MP +omount MP +opendir +openlog +openpl +optarg +opterr +optind +optopt +optreset +overlay +overwrite +pause +pclose +perror +point +popen +pow +pow MP +printf +printw +psignal +putc +putchar +putenv +puts +putw +qsort +radixsort +raise +rand +random +raw +rcmd +re_comp +re_exec +readdir +realloc +realpath +refresh +regcomp +regerror +regexec +regfree +regsub +remove +remque +res_init +res_mkquery +res_query +res_send +res_serach +resetty +rewind +rewinddir +rexec +rindex +rint +rpow MP +rresvport +ruserok +savetty +scalb +scandir +scanf +scanw +scroll +scrollok +sdiv MP +seekdir +setbuf +setbuffer +setenv +setfsent +setgrent +setgroupent +sethostent +sethostid +sethostname +setinvalidrunt +setjmp +setkey +setlinebuf +setlocale +setlogmask +setmode +setnetent +setnetgrent +setpassent +setprotoent +setpwent +setrgid +setruid +setrunelocale +setservent +setstate +setterm +setttyent +setusershell +setvbuf +sgetrune +sigaddset +sigdelset +sigemptyset +sigfillset +siginterrupt +sigismember +siglongjmp +signal +signgam +sigsetjmp +sin +sinh +sleep +snprintf +space +sprintf +sputrune +sqrt +sradixsort +srand +sreandom +sscanf +standend +standout +stderr +stdin +stdout +strcasecmp +strcat +strchr +strcmp +strcoll +strcpy +strcspn +strdup +strerror +strftime +strlen +strmode +strncasecmp +strncat +strncmp +strncpy +strpbrk +strrchr +strsep +strspc +strspn +strstr +strtod +strtok +strtol +strtoq +strtoul +strtouq +strunvis +strvis +strvisx +strxfrm +stty +subwin +swab +sys_errlist +sys_nerr +sys_siglist +sys_signame +sysconf +sysctl +syslog +system +tan +tanh +tcdrain +tcflow +tcflush +tcgetattr +tcgetpgrp +tcsendbreak +tcsetattr +tcsetpgrp +telldir +tempnam +tf_close +tf_get_cred +tf_get_pinst +tf_get_pname +tf_init +tgetent +tgetflag +tgetnum +tgetstr +tgoto +time +times +timezone +tmpfile +tmpnam +toascii +tolower +touchline +touchoverlap +touchwin +toupper +tputs +ttynam +ttyslot +tzset +tzsetwall +ualarm +uname +unctrl +ungetc +unsetenv +unvis +user_from_uid +usleep +utime +va_arg M +va_end M +va_start M +valloc +verr +verrx +vfprintf +vfscanf +vis +vlimit +vprintf +vscanf +vsnprintf +vsprintf +vsscanf +vsyslog +vtimes +vwarn +vwarnx +waddch +waddstr +warn +warnx +wclear +wclreol +wclrtobot +wcstombs +wctomb +wdelch +wdeleteln +werase +wgetch +wgetstr +winch +winsch +winsertln +wmove +wprintw +wrefreash +wscanw +wstandend +wstandout +y0 +y1 +yn diff --git a/sys/MISSING-MANPAGE b/sys/MISSING-MANPAGE new file mode 100644 index 0000000..6aa16bd --- /dev/null +++ b/sys/MISSING-MANPAGE @@ -0,0 +1,9 @@ +creat (obsoleted by open) +killpg +ptarce +setregid +setreuid +sigblock (obsoleted by sigprocmask) +sigpause (obsoleted by sigsuspend) +sigsetmask (obsoleted by sigprocmask) +sigvec (obsoleted by sigaction) diff --git a/sys/MISSING_SYSCALLS b/sys/MISSING_SYSCALLS new file mode 100644 index 0000000..2cb3246 --- /dev/null +++ b/sys/MISSING_SYSCALLS @@ -0,0 +1,8 @@ +madvise UNIX +mincore UNIX +mlock UNIX +mprotect UNIX +msync UNIX +munlock UNIX +sigpending POSIX +sigstack compat[sigaltstack] diff --git a/sys/Makefile.inc b/sys/Makefile.inc new file mode 100644 index 0000000..bafd300 --- /dev/null +++ b/sys/Makefile.inc @@ -0,0 +1,150 @@ +# @(#)Makefile.inc 8.3 (Berkeley) 10/24/94 +# $FreeBSD: src/lsys/Makefile.inc,v 1.91 2001/09/21 21:35:22 rwatson Exp $ + +# sys sources +.PATH: ${.CURDIR}/${MACHINE_ARCH}/sys ${.CURDIR}/sys + +# Include the generated makefile containing the *complete* list +# of syscall names in MIASM. +#.include "${.CURDIR}/../../sys/sys/syscall.mk" + +# Include machine dependent definitions. +# +# MDASM names override the default syscall names in MIASM. +# NOASM will prevent the default syscall code from being generated. +# +.if exists(${.CURDIR}/${MACHINE_ARCH}/sys/Makefile.inc) +.include "${.CURDIR}/${MACHINE_ARCH}/sys/Makefile.inc" +.endif + +# Sources common to both syscall interfaces: +SRCS+= errno.c gettimeofday.c sigcatch.c sigsuspend.c getdtablesize.c \ + sigaction.c sigtramp.c crt_externs.c + + +# Add machine dependent asm sources: +SRCS+=${MDASM} + +# Look though the complete list of syscalls (MIASM) for names that are +# not defined with machine dependent implementations (MDASM) and are +# not declared for no generation of default code (NOASM). Add each +# syscall that satisfies these conditions to the ASM list. +.for _asm in ${MIASM} +.if (${MDASM:R:M${_asm:R}} == "") +.if (${NOASM:R:M${_asm:R}} == "") +ASM+=$(_asm) +.endif +.endif +.endfor + +OBJS+= ${ASM} ${PSEUDO} + +SASM= ${ASM:S/.o/.S/} + +SPSEUDO= ${PSEUDO:S/.o/.S/} + +SRCS+= ${SASM} ${SPSEUDO} + +# Generated files +CLEANFILES+= ${SASM} ${SPSEUDO} + +${SASM}: + printf '#include "SYS.h"\nRSYSCALL(${.PREFIX})\n' > ${.TARGET} + +${SPSEUDO}: + printf '#include "SYS.h"\nPSEUDO(${.PREFIX:S/_//})\n' \ + > ${.TARGET} + +.if ${LIB} == "c" +MAN2+= pthread_kill.2 pthread_sigmask.2 \ + sem_close.2 sem_open.2 sem_post.2 sem_trywait.2 \ + sem_unlink.2 sem_wait.2 shm_open.2 shm_unlink.2 \ + sigwait.2 getdtablesize.2 setreuid.2 setregid.2 \ + nanosleep.2 +#MAN+= _exit.2 accept.2 access.2 acct.2 adjtime.2 \ +# aio_cancel.2 aio_error.2 aio_read.2 aio_return.2 \ +# aio_suspend.2 aio_waitcomplete.2 aio_write.2 \ +# bind.2 brk.2 chdir.2 chflags.2 \ +# chmod.2 chown.2 chroot.2 clock_gettime.2 close.2 \ +# connect.2 dup.2 execve.2 extattr_get_file.2 \ +# fcntl.2 fhopen.2 flock.2 fork.2 fsync.2 \ +# getdirentries.2 getdtablesize.2 \ +# getfh.2 getfsstat.2 getgid.2 getgroups.2 getitimer.2 getlogin.2 \ +# getpeername.2 getpgrp.2 getpid.2 getpriority.2 getrlimit.2 \ +# getrusage.2 getsid.2 getsockname.2 \ +# getsockopt.2 gettimeofday.2 getuid.2 \ +# intro.2 ioctl.2 issetugid.2 jail.2 kill.2 \ +# kldfind.2 kldfirstmod.2 kldload.2 kldnext.2 kldstat.2 kldsym.2 \ +# kldunload.2 ktrace.2 kqueue.2 link.2 listen.2 lseek.2 \ +# madvise.2 mincore.2 minherit.2 mkdir.2 mkfifo.2 mknod.2 mlock.2 mmap.2 \ +# modfind.2 modnext.2 modstat.2 \ +# mount.2 mprotect.2 msync.2 munmap.2 nanosleep.2 \ +# nfssvc.2 open.2 pathconf.2 pipe.2 poll.2 profil.2 ptrace.2 quotactl.2 \ +# read.2 readlink.2 reboot.2 recv.2 rename.2 revoke.2 rfork.2 rmdir.2 \ +# rtprio.2 select.2 semctl.2 semget.2 semop.2 send.2 sendfile.2 \ +# setgroups.2 setpgid.2 setregid.2 setresuid.2 setreuid.2 setsid.2 \ +# setuid.2 shmat.2 shmctl.2 shmget.2 shutdown.2 \ +# sigaction.2 sigaltstack.2 sigpending.2 sigprocmask.2 sigreturn.2 \ +# sigstack.2 sigsuspend.2 socket.2 socketpair.2 stat.2 statfs.2 \ +# swapon.2 symlink.2 sync.2 sysarch.2 syscall.2 \ +# truncate.2 umask.2 undelete.2 \ +# unlink.2 utimes.2 vfork.2 wait.2 write.2 +#.if !defined(NO_P1003_1B) +#MAN+= sched_get_priority_max.2 sched_setparam.2 \ +# sched_setscheduler.2 sched_yield.2 +#.endif + +#MLINKS+=access.2 eaccess.2 +#MLINKS+=brk.2 sbrk.2 +#MLINKS+=chdir.2 fchdir.2 +#MLINKS+=chflags.2 fchflags.2 +#MLINKS+=chmod.2 fchmod.2 chmod.2 lchmod.2 +#MLINKS+=chown.2 fchown.2 chown.2 lchown.2 +#MLINKS+=clock_gettime.2 clock_getres.2 clock_gettime.2 clock_settime.2 +#MLINKS+=dup.2 dup2.2 +#MLINKS+=extattr_get_file.2 extattr_set_file.2 \ +# extattr_get_file.2 extattr_delete_file.2 \ +# extattr_get_file.2 extattr_get_fd.2 \ +# extattr_get_file.2 extattr_set_fd.2 \ +# extattr_get_file.2 extattr_delete_fd.2 \ +# extattr_get_file.2 extattr.2 +#MLINKS+=fhopen.2 fhstat.2 fhopen.2 fhstatfs.2 +#MLINKS+=getdirentries.2 getdents.2 +#MLINKS+=getgid.2 getegid.2 +#MLINKS+=getitimer.2 setitimer.2 +#MLINKS+=getlogin.2 getlogin_r.3 +#MLINKS+=getlogin.2 setlogin.2 +#MLINKS+=getpgrp.2 getpgid.2 +#MLINKS+=getpid.2 getppid.2 +#MLINKS+=getpriority.2 setpriority.2 +#MLINKS+=getrlimit.2 setrlimit.2 +#MLINKS+=getsockopt.2 setsockopt.2 +#MLINKS+=gettimeofday.2 settimeofday.2 +#MLINKS+=getuid.2 geteuid.2 +#MLINKS+=intro.2 errno.2 +#MLINKS+=kqueue.2 kevent.2 +#MLINKS+=mlock.2 munlock.2 +#MLINKS+=modnext.2 modfnext.2 +#MLINKS+=mount.2 unmount.2 +#MLINKS+=pathconf.2 fpathconf.2 +#MLINKS+=read.2 pread.2 read.2 readv.2 +#MLINKS+=recv.2 recvfrom.2 recv.2 recvmsg.2 +#MLINKS+=send.2 sendmsg.2 send.2 sendto.2 +#MLINKS+=setpgid.2 setpgrp.2 +#MLINKS+=setresuid.2 setresgid.2 setresuid.2 getresuid.2 setresuid.2 getresgid.2 +#MLINKS+=setuid.2 setegid.2 setuid.2 seteuid.2 setuid.2 setgid.2 +#MLINKS+=shmat.2 shmdt.2 +#MLINKS+=stat.2 fstat.2 stat.2 lstat.2 +#MLINKS+=statfs.2 fstatfs.2 +#MLINKS+=syscall.2 __syscall.2 +#MLINKS+=truncate.2 ftruncate.2 +#MLINKS+=utimes.2 futimes.2 utimes.2 lutimes.2 +#MLINKS+=wait.2 wait3.2 wait.2 wait4.2 wait.2 waitpid.2 +#MLINKS+=write.2 pwrite.2 write.2 writev.2 +#.if !defined(NO_P1003_1B) +#MLINKS+=sched_get_priority_max.2 sched_get_priority_min.2 \ +# sched_get_priority_max.2 sched_rr_get_interval.2 +#MLINKS+=sched_setparam.2 sched_getparam.2 +#MLINKS+=sched_setscheduler.2 sched_getscheduler.2 +#.endif +.endif diff --git a/sys/REQUIRED-MACROS b/sys/REQUIRED-MACROS new file mode 100644 index 0000000..4482b7a --- /dev/null +++ b/sys/REQUIRED-MACROS @@ -0,0 +1,3 @@ +sigmask +WCOREDUMP + diff --git a/sys/SYSCALL-LIST b/sys/SYSCALL-LIST new file mode 100644 index 0000000..e49e492 --- /dev/null +++ b/sys/SYSCALL-LIST @@ -0,0 +1,145 @@ +accept +access +acct +adjtime +bind +brk +sbrk +chdir +fchdir +chflags +creat +fchflags +chmod +fchmod +chown +fchown +chroot +close +connect +dup +dup2 +execve +_exit +fcntl +flock +fork +fsync +getdirentries +getdtablesize +getfh +getfsstat +getgid +getegid +getgroups +getitimer +setitimer +getlogin +setlogin +getpeername +getpgrp +getpid +getppid +getpriority +setpriority +getrlimit +setrlimit +getrusage +getsockname +getsockopt +setsockopt +gettimeofday +settimeofday +getuid +geteuid +ioctl +kill +killpg +ktrace +link +listen +lseek +madvise +mincore +mkdir +mkfifo +mknod +mlock +munlock +mmap +mount +unmount +mprotect +msync +munmap +nfssvc +open +pathconf +fpathconf +pipe +profil +pthread_kill +pthread_sigmask +ptrace +quotactl +read +readv +readlink +reboot +recv +recvfrom +recvmsg +rename +revoke +rmdir +select +send +sendto +sendmsg +setgroups +setpgid +setpgrp +setregid +setreuid +setsid +setuid +seteuid +setgid +setegid +shutdown +sigaction +sigaltstack +sigblock +sigpause +sigpending +sigprocmask +sigreturn +sigsetmask +sigstack +sigsuspend +sigvec +sigwait +socket +socketpair +stat +lstat +fstat +statfs +fstatfs +swapon +symlink +sync +syscall +__syscall +truncate +ftruncate +umask +unlink +utimes +vfork +wait +waitpid +wait3 +wait4 +write +writev diff --git a/sys/crt_externs.c b/sys/crt_externs.c new file mode 100644 index 0000000..41c6c3c --- /dev/null +++ b/sys/crt_externs.c @@ -0,0 +1,106 @@ +/* + * Copyright (c) 1999 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@ + */ +/* +** This file contains interfaces to the symbols defined int the crt modules. +** 3 April 1995 +** Matt Watson (mwatson@next.com) +** +*/ + +#if defined(__DYNAMIC__) +#include "mach-o/dyld.h" /* defines _dyld_lookup_and_bind() */ +#define STRINGIFY(a) # a +#define DECLARE_VAR(var, type) \ + static type * var ## _pointer = 0 +#define SETUP_VAR(var) \ + if ( var ## _pointer == 0) { \ + _dyld_lookup_and_bind( STRINGIFY(_ ## var), \ + (unsigned long *) & var ## _pointer, 0); \ + } +#define USE_VAR(var) (var ## _pointer) +#else +#define DECLARE_VAR(var, type) extern type var +#define SETUP_VAR(var) +#define USE_VAR(var) (& var) +#endif + +char ***_NSGetArgv(void) { + DECLARE_VAR(NXArgv, char **); + SETUP_VAR(NXArgv); + return(USE_VAR(NXArgv)); +} + +int *_NSGetArgc(void) { + DECLARE_VAR(NXArgc, int); + SETUP_VAR(NXArgc); + return(USE_VAR(NXArgc)); +} + +char ***_NSGetEnviron(void) { + DECLARE_VAR(environ, char **); + SETUP_VAR(environ); + return(USE_VAR(environ)); +} + +char **_NSGetProgname(void) { + DECLARE_VAR(__progname, char *); + SETUP_VAR(__progname); + return(USE_VAR(__progname)); +} + +struct mach_header *_NSGetMachExecuteHeader(void) { + DECLARE_VAR(_mh_execute_header, struct mach_header); + SETUP_VAR(_mh_execute_header); + return(USE_VAR(_mh_execute_header)); +} + +/* + * Fix for Radar bug 2200596 -- + * EH symbol definitions for gcc 2.7.2.x implementation of + * C++ exception handling. The problem: the EH implementation + * has "throw" store stuff into these pointers, and then as the + * stack is unwound, the code generated into each function (for + * checking whether this function contains a relevant "catch" + * clause and for calling destructors for local variables) looks + * at these globals to find the type and value thrown. + * + * The problem was that the compiler generated the symbols as + * "common" symbols, and common symbols cannot be placed in + * dynamic shared libraries. So we must put these guys as + * "data" symbols into crt0.o or the System Framework (library), + * and the compiler must generate code that defines the symbols + * as external references instead of common. + * + * I changed the symbol names (added the "_272") to be utterly + * paranoid about any possible future use of similar names by + * any future versions of gcc. + * -- D. Landauer, Jan. 1998 + */ + +void *__eh_pc_gcc_272 = (void *)0; +void *__eh_type_gcc_272 = (void *)0; +void *__eh_value_gcc_272 = (void *)0; + +/* This is what egcs uses for its global data pointer */ +void *__eh_global_dataptr = (void *)0; + +void *__keymgr_global[3] = { (void *)0 }; diff --git a/sys/errno.c b/sys/errno.c new file mode 100644 index 0000000..87b8da6 --- /dev/null +++ b/sys/errno.c @@ -0,0 +1,46 @@ +/* + * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This 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.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. + * + * 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +/* + * The world-renowned global variable + */ +#include + +#undef errno +extern int errno; +int *__error(void) { + pthread_t self = pthread_self(); + /* If we're not a detached pthread, just return the global errno */ + if ((self == (pthread_t)0) || (self->sig != _PTHREAD_SIG) || (self->detached & _PTHREAD_CREATE_PARENT)) { + return &errno; + } + return &self->err_no; +} + +int cthread_errno(void) { + return *__error(); +} + diff --git a/sys/getdtablesize.2 b/sys/getdtablesize.2 new file mode 100644 index 0000000..7465f9a --- /dev/null +++ b/sys/getdtablesize.2 @@ -0,0 +1,63 @@ +.\" Copyright (c) 1983, 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. +.\" +.\" @(#)getdtablesize.2 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD: src/lib/libc/sys/getdtablesize.2,v 1.4.2.3 2001/12/14 18:34:00 ru Exp $ +.\" +.Dd June 4, 1993 +.Dt GETDTABLESIZE 2 +.Os +.Sh NAME +.Nm getdtablesize +.Nd get descriptor table size +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In unistd.h +.Ft int +.Fn getdtablesize void +.Sh DESCRIPTION +Each process has a fixed size descriptor table, +which is guaranteed to have at least 20 slots. The entries in +the descriptor table are numbered with small integers starting at 0. +The call +.Fn getdtablesize +returns the size of this table. +.Sh SEE ALSO +.Xr close 2 , +.Xr dup 2 , +.Xr open 2 , +.Xr select 2 +.Sh HISTORY +The +.Fn getdtablesize +function call appeared in +.Bx 4.2 . diff --git a/sys/getdtablesize.c b/sys/getdtablesize.c new file mode 100644 index 0000000..c25bf90 --- /dev/null +++ b/sys/getdtablesize.c @@ -0,0 +1,5 @@ +#include + +int getdtablesize() { + return sysconf(_SC_OPEN_MAX); +} diff --git a/sys/gettimeofday.c b/sys/gettimeofday.c new file mode 100644 index 0000000..07ad5f0 --- /dev/null +++ b/sys/gettimeofday.c @@ -0,0 +1,69 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + * + * File: libc/sys/gettimeofday.c + */ + +#include +#include +#include +#include +#include +#include + +int gettimeofday (struct timeval *tp, struct timezone *tzp) +{ + static int validtz = 0; + static struct timezone cached_tz = {0}; + struct timeval localtv; +#ifdef __ppc__ + extern __ppc_gettimeofday(struct timeval *, struct timezone *); +#endif + + if (tzp && (tp == NULL) && (validtz == 0)) { + tp = &localtv; + } + +#ifdef __ppc__ + if(__ppc_gettimeofday(tp, tzp)) + return(-1); +#else + if (syscall (SYS_gettimeofday, tp, tzp) < 0) { + return (-1); + } +#endif + if (tzp) { + if (validtz == 0) { + struct tm *localtm = localtime ((time_t *)&tp->tv_sec); + cached_tz.tz_dsttime = localtm->tm_isdst; + cached_tz.tz_minuteswest = + (-localtm->tm_gmtoff / SECSPERMIN) + + (localtm->tm_isdst * MINSPERHOUR); + validtz = 1; + } + tzp->tz_dsttime = cached_tz.tz_dsttime; + tzp->tz_minuteswest = cached_tz.tz_minuteswest; + } + return (0); +} diff --git a/sys/msync.2 b/sys/msync.2 new file mode 100644 index 0000000..94de3b6 --- /dev/null +++ b/sys/msync.2 @@ -0,0 +1,103 @@ +.\" 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. +.\" +.\" @(#)msync.2 8.2 (Berkeley) 6/21/94 +.\" $FreeBSD: src/lib/libc/sys/msync.2,v 1.17 2000/04/21 09:41:53 phantom Exp $ +.\" +.Dd June 21, 1994 +.Dt MSYNC 2 +.Os +.Sh NAME +.Nm msync +.Nd synchronize a mapped region +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.Fd #include +.Fd #include +.Ft int +.Fn msync "void *addr" "size_t len" "int flags" +.Sh DESCRIPTION +The +.Fn msync +system call +writes any modified pages back to the filesystem and updates +the file modification time. +If +.Fa len +is 0, all modified pages within the region containing +.Fa addr +will be flushed; +if +.Fa len +is non-zero, only those pages containing +.Fa addr +and +.Fa len-1 +succeeding locations will be examined. +The +.Fa flags +argument may be specified as follows: +.Bd -literal +MS_ASYNC Return immediately +MS_SYNC Perform synchronous writes +MS_INVALIDATE Invalidate all cached data +.Ed +.Sh RETURN VALUES +If any errors occur, -1 is returned and errno is set to indicate the +error. +Otherwise, a 0 value is returned. +.Sh ERRORS +.Fn msync +will fail if: +.Bl -tag -width Er +.It Bq Er EINVAL +.Fa addr +is not a multiple of the hardware page size. +.It Bq Er EINVAL +.Fa len +is too large or negative. +.It Bq Er EINVAL +.Fa flags +was both MS_ASYNC and MS_INVALIDATE. +Only one of these flags is allowed. +.It Bq Er EIO +An I/O error occurred while writing to the file system. +.Sh SEE ALSO +.Xr madvise 2 , +.Xr mincore 2 , +.Xr mprotect 2 , +.Xr munmap 2 +.Sh HISTORY +The +.Fn msync +function first appeared in +.Bx 4.4 . diff --git a/sys/nanosleep.2 b/sys/nanosleep.2 new file mode 100644 index 0000000..a0db6d6 --- /dev/null +++ b/sys/nanosleep.2 @@ -0,0 +1,104 @@ +.\" $FreeBSD: src/lib/libc/sys/nanosleep.2,v 1.8.2.4 2001/12/14 18:34:01 ru Exp $ +.\" $OpenBSD: nanosleep.2,v 1.1 1997/04/20 20:56:20 tholo Exp $ +.\" $NetBSD: nanosleep.2,v 1.1 1997/04/17 18:12:02 jtc Exp $ +.\" +.\" Copyright (c) 1986, 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. +.\" +.\" @(#)sleep.3 8.1 (Berkeley) 6/4/93 +.\" +.Dd April 17, 1997 +.Dt NANOSLEEP 2 +.Os +.Sh NAME +.Nm nanosleep +.Nd suspend process execution for an interval measured in nanoseconds +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In time.h +.Ft int +.Fn nanosleep "const struct timespec *rqtp" "struct timespec *rmtp" +.Sh DESCRIPTION +.Fn Nanosleep +causes the process to sleep for the specified time. An unmasked signal will +cause it to terminate the sleep early, regardless of the +.Dv SA_RESTART +value on the interrupting signal. +.Sh RETURN VALUES +If the +.Fn nanosleep +function returns because the requested time has elapsed, the value +returned will be zero. +.Pp +If the +.Fn nanosleep +function returns due to the delivery of a signal, the value returned +will be the -1, and the global variable +.Va errno +will be set to indicate the interruption. +If +.Fa rmtp +is +.Pf non- Dv NULL , +the timespec structure it references is updated to contain the +unslept amount (the request time minus the time actually slept). +.Sh ERRORS +The +.Fn nanosleep +call fails if: +.Bl -tag -width Er +.It Bq Er EFAULT +Either +.Fa rqtp +or +.Fa rmtp +points to memory that is not a valid part of the process +address space. +.It Bq Er EINTR +.Fn nanosleep +was interrupted by the delivery of a signal. +.It Bq Er EINVAL +.Fa rqtp +specified a nanosecond value less than zero +or greater than or equal to 1000 million. +.It Bq Er ENOSYS +.Fn nanosleep +is not supported by this implementation. +.El +.Sh SEE ALSO +.Xr sigsuspend 2 , +.Xr sleep 3 +.Sh STANDARDS +The +.Fn nanosleep +function conforms to +.St -p1003.1b-93 . diff --git a/sys/pthread_kill.2 b/sys/pthread_kill.2 new file mode 100644 index 0000000..068b23e --- /dev/null +++ b/sys/pthread_kill.2 @@ -0,0 +1,75 @@ +.\" Darwin +.\" +.\" Copyright (C) 2000 Jason Evans . +.\" 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(s), this list of conditions and the following disclaimer as +.\" the first lines of this file unmodified other than the possible +.\" addition of one or more copyright notices. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice(s), 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 COPYRIGHT HOLDER(S) ``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 COPYRIGHT HOLDER(S) 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_r/man/pthread_kill.3,v 1.8 2001/10/01 16:09:09 ru Exp $ +.Dd Feb 05, 2002 +.Dt PTHREAD_KILL 2 +.Os +.Sh NAME +.Nm pthread_kill +.Nd send a signal to a specified thread +.Sh SYNOPSIS +.In pthread.h +.In signal.h +.Ft int +.Fn pthread_kill "pthread_t thread" "int sig" +.Sh DESCRIPTION +The +.Fn pthread_kill +function sends a signal, specified by +.Fa sig , +to a thread, specified by +.Fa thread . +If +.Fa sig +is 0, error checking is performed, but no signal is actually sent. +.Sh RETURN VALUES +If successful, +.Fn pthread_kill +returns 0. +Otherwise, an error number is returned. +.Sh ERRORS +.Fn pthread_kill +will fail if: +.Bl -tag -width Er +.It Bq Er ESRCH +.Fa thread +is an invalid thread ID. +.It Bq Er EINVAL +.Fa sig +is an invalid or unsupported signal number. +.El +.Sh SEE ALSO +.Xr kill 2 , +.Xr pthread_self 3 , +.Xr raise 3 +.Sh STANDARDS +.Fn pthread_kill +conforms to ISO/IEC 9945-1:1996 (``POSIX.1'') + diff --git a/sys/pthread_sigmask.2 b/sys/pthread_sigmask.2 new file mode 100644 index 0000000..f961512 --- /dev/null +++ b/sys/pthread_sigmask.2 @@ -0,0 +1,94 @@ +.\" Copyright (C) 2000 Jason Evans . +.\" 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(s), this list of conditions and the following disclaimer as +.\" the first lines of this file unmodified other than the possible +.\" addition of one or more copyright notices. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice(s), 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 COPYRIGHT HOLDER(S) ``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 COPYRIGHT HOLDER(S) 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_r/man/pthread_sigmask.3,v 1.9 2001/10/01 16:09:09 ru Exp $ +.Dd April 27, 2000 +.Dt PTHREAD_SIGMASK 2 +.Os +.Sh NAME +.Nm pthread_sigmask +.Nd examine and/or change a thread's signal mask +.Sh SYNOPSIS +.In pthread.h +.In signal.h +.Ft int +.Fn pthread_sigmask "int how" "const sigset_t *set" "sigset_t *oset" +.Sh DESCRIPTION +The +.Fn pthread_sigmask +function examines and/or changes the calling thread's signal mask. +.Pp +If +.Fa set +is not +.Dv NULL , +it specifies a set of signals to be modified, and +.Fa how +specifies what to set the signal mask to: +.Bl -tag -width SIG_UNBLOCK +.It Dv SIG_BLOCK +Union of the current mask and +.Fa set . +.It Dv SIG_UNBLOCK +Intersection of the current mask and the complement of +.Fa set . +.It Dv SIG_SETMASK +.Fa set . +.El +.Pp +If +.Fa oset +is not NULL, the previous signal mask is stored in the location pointed to by +.Fa oset . +.Pp +.Dv SIGKILL +and +.Dv SIGSTOP +cannot be blocked, and will be silently ignored if included in the signal mask. +.Sh RETURN VALUES +If successful, +.Fn pthread_sigmask +returns 0. +Otherwise, an error is returned. +.Sh ERRORS +.Fn pthread_sigmask +will fail if: +.Bl -tag -width Er +.It Bq Er EINVAL +.Fa how +is not one of the defined values. +.El +.Sh SEE ALSO +.Xr sigaction 2 , +.Xr sigpending 2 , +.Xr sigprocmask 2 , +.Xr sigsuspend 2 , +.Xr sigsetops 3 +.Sh STANDARDS +.Fn pthread_sigmask +conforms to ISO/IEC 9945-1:1996 (``POSIX.1'') + diff --git a/sys/sem_close.2 b/sys/sem_close.2 new file mode 100644 index 0000000..60fc5b6 --- /dev/null +++ b/sys/sem_close.2 @@ -0,0 +1,60 @@ +.\" $Darwin$ +.\" +.\" Copyright (c) 2000-2002 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@ +.\" +.Dd June 8, 2000 +.Dt SEM_CLOSE 2 +.Os Darwin +.Sh NAME +.Nm sem_close +.Nd close a named semaphore +.Sh SYNOPSIS +.Fd #include +.Ft int +.Fn sem_close "sem_t *sem" +.Sh DESCRIPTION +The system resources associated with the named semaphore referenced by +.Fa sem +are deallocated and the descriptor is invalidated. +.Pp +If successful, +.Fn sem_close +will return 0. Otherwise, -1 is returned and +.Va errno +is set. +.Sh ERRORS +.Fn sem_close +succeeds unless: +.Bl -tag -width Er +.It Bq Er EINVAL +.Fa sem +is not a valid semaphore descriptor. +.El +.Sh SEE ALSO +.Xr semctl 2 , +.Xr semget 2 , +.Xr semop 2 , +.Xr sem_init 2 , +.Xr sem_open 2 , +.Xr sem_unlink 2 +.Sh HISTORY +.Fn sem_close +is specified in the POSIX Realtime Extension (1003.1b-1993/1003.1i-1995). diff --git a/sys/sem_open.2 b/sys/sem_open.2 new file mode 100644 index 0000000..5f4d923 --- /dev/null +++ b/sys/sem_open.2 @@ -0,0 +1,162 @@ +.\" $Darwin$ +.\" +.\" Copyright (c) 2000-2002 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@ +.\" +.Dd June 8, 2000 +.Dt SEM_OPEN 2 +.Os Darwin +.Sh NAME +.Nm sem_open +.Nd initialize and open a named semaphore +.Sh SYNOPSIS +.Fd #include +.Ft sem_t * +.Fn sem_open "const char *name" "int flags" +.Ft sem_t * +.Fn sem_open "const char *name" "int flags" "mode_t mode" "unsigned int value" +.Sh DESCRIPTION +The named semaphore named +.Fa name +is initialized and opened as specified by the argument +.Fa flags +and a semaphore descriptor is returned to the calling process. +.Pp +The flags specified are formed by +.Em or Ns 'ing +the following values: +.Pp +.Bd -literal -offset indent -compact +O_CREAT create the semaphore if it does not exist +O_EXCL error if create and semaphore exists +.Ed +.Pp +If +.Dv O_CREATE +if specified, +.Fn sem_open +requires an additional two arguments. +.Fa mode +specifies the permissions for the semaphore as described in +.Xr chmod 2 +and modified by the process' umask value (see +.Xr umask 2 ) . +The semaphore is created with an initial +.Fa value , +which must be less than or equal to +.Dv SEM_VALUE_MAX . +.Pp +If +.Dv O_EXCL +is specified and the semaphore exists, +.Fn sem_open +fails. The check for the existence of the semaphore and the creation +of the semaphore are atomic with respect to all processes calling +.Fn sem_open +with +.Dv O_CREAT +and +.Dv O_EXCL +set. +.Pp +When a new semaphore is created, it is given the user ID and group ID +which coorespond to the effective user and group IDs of the calling +process. There is no visible entry in the file system for the created +object in this implementation. +.Pp +The returned semaphore descriptor is available to the calling process +until it is closed with +.Fn sem_close , +or until the caller exits or execs. +.Pp +If a process makes repeated calls to +.Fn sem_open , +with the same +.Fa name +argument, the same descriptor is returned for each successful call, +unless +.Fn sem_unlink +has been called on the semaphore in the interim. +.Pp +If +.Fn sem_open +fails for any reason, it will return a value of +.Dv SEM_FAILED +and sets +.Va errno . +On success, it returns a semaphore descriptor. +.Sh ERRORS +The named semaphore is opened unless: +.Bl -tag -width Er +.It Bq Er EACCES +The required permissions (for reading and/or writing) +are denied for the given flags; or +.Dv O_CREAT +is specified, the object does not exist, and permission to +create the semaphore is denied. +.It Bq Er EEXIST +.Dv O_CREAT +and +.Dv O_EXCL +were specified and the semaphore exists. +.It Bq Er EINTR +The +.Fn sem_open +operation was interrupted by a signal. +.It Bq Er EINVAL +The +.Fn shm_open +operation is not supported; or +.Dv O_CREAT +is specified and +.Fa value +exceeds +.Dv SEM_VALUE_MAX . +.It Bq Er EMFILE +The process has already reached its limit for semaphores or file +descriptors in use. +.It Bq Er ENAMETOOLONG +.Fa name +exceeded +.Dv SEM_NAME_LEN +characters. +.It Bq Er ENFILE +Too many semaphores or file descriptors are open on the system. +.It Bq Er ENOENT +.Dv O_CREAT +is not set and the named semaphore does not exist. +.It Bq Er ENOSPC +.Dv O_CREAT +is specified, the file does not exist, and there is insufficient +space available to create the semaphore. +.El +.Sh SEE ALSO +.Xr semctl 2 , +.Xr semget 2 , +.Xr semop 2 , +.Xr sem_close 2 , +.Xr sem_post 2 , +.Xr sem_trywait 2 , +.Xr sem_unlink 2 , +.Xr sem_wait 2 , +.Xr umask 2 +.Sh HISTORY +.Fn sem_open +is specified in the POSIX Realtime Extension (1003.1b-1993/1003.1i-1995). diff --git a/sys/sem_post.2 b/sys/sem_post.2 new file mode 100644 index 0000000..d5afd23 --- /dev/null +++ b/sys/sem_post.2 @@ -0,0 +1,65 @@ +.\" $Darwin$ +.\" +.\" Copyright (c) 2000-2002 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@ +.\" +.Dd June 8, 2000 +.Dt SEM_POST 2 +.Os Darwin +.Sh NAME +.Nm sem_post +.Nd unlock a semaphore +.Sh SYNOPSIS +.Fd #include +.Ft int +.Fn sem_post "sem_t *sem" +.Sh DESCRIPTION +The the semaphore referenced by +.Fa sem +is unlocked, the value of the semaphore is incremented, and all +threads which are waiting on the semaphore are awakened. +.Pp +.Fn sem_post +is reentrant with respect to signals and may be called from within a +signal hanlder. +.Pp +If successful, +.Fn sem_post +will return 0. Otherwise, -1 is returned and +.Va errno +is set. +.Sh ERRORS +.Fn sem_post +succeeds unless: +.Bl -tag -width Er +.It Bq Er EINVAL +.Fa sem +is not a valid semaphore descriptor. +.El +.Sh SEE ALSO +.Xr semctl 2 , +.Xr semget 2 , +.Xr semop 2 , +.Xr sem_open 2 , +.Xr sem_trywait 2 , +.Xr sem_wait 2 +.Sh HISTORY +.Fn sem_post +is specified in the POSIX Realtime Extension (1003.1b-1993/1003.1i-1995). diff --git a/sys/sem_trywait.2 b/sys/sem_trywait.2 new file mode 100644 index 0000000..c0db675 --- /dev/null +++ b/sys/sem_trywait.2 @@ -0,0 +1 @@ +.so man2/sem_wait.2 diff --git a/sys/sem_unlink.2 b/sys/sem_unlink.2 new file mode 100644 index 0000000..213628a --- /dev/null +++ b/sys/sem_unlink.2 @@ -0,0 +1,74 @@ +.\" $Darwin$ +.\" +.\" Copyright (c) 2000-2002 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@ +.\" +.Dd June 8, 2000 +.Dt SEM_UNLINK 2 +.Os Darwin +.Sh NAME +.Nm sem_unlink +.Nd remove a named semaphore +.Sh SYNOPSIS +.Fd #include +.Ft int +.Fn sem_unlink "const char *name" +.Sh DESCRIPTION +The named semaphore named +.Fa name +is removed. If the semaphore is in use my other processes, then +.Fa name +is immeditately dissasociated with the semaphore, but the semaphore +itself will not be removed until all references to it have been +closed. Subsequent calls to +.Fn sem_open +using +.Fa name +will refer to or create a new semaphore named +.Fa name . +.Pp +If successful, +.Fn sem_close +will return 0. Otherwise, -1 is returned and +.Va errno +is set, and the state of the semaphore is unchanged. +.Sh ERRORS +.Fn sem_unlink +succeeds unless: +.Bl -tag -width Er +.It Bq Er EACCES +Permission is denied to be remove the semaphore. +.It Bq Er ENAMETOOLONG +.Fa name +exceeded +.Dv SEM_NAME_LEN +characters. +.It Bq Er ENOENT +The named semaphore does not exist. +.El +.Sh SEE ALSO +.Xr semctl 2 , +.Xr semget 2 , +.Xr semop 2 , +.Xr sem_close 2 , +.Xr sem_open 2 +.Sh HISTORY +.Fn sem_unlink +is specified in the POSIX Realtime Extension (1003.1b-1993/1003.1i-1995). diff --git a/sys/sem_wait.2 b/sys/sem_wait.2 new file mode 100644 index 0000000..feeff3b --- /dev/null +++ b/sys/sem_wait.2 @@ -0,0 +1,88 @@ +.\" $Darwin$ +.\" +.\" Copyright (c) 2000-2002 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@ +.\" +.Dd June 8, 2000 +.Dt SEM_WAIT 2 +.Os Darwin +.Sh NAME +.Nm sem_wait, sem_trywait +.Nd lock a semaphore +.Sh SYNOPSIS +.Fd #include +.Ft int +.Fn sem_wait "sem_t *sem" +.Ft int +.Fn sem_trywait "sem_t *sem" +.Sh DESCRIPTION +The semaphore referenced by +.Fa sem +is locked. When calling +.Fn sem_wait , +if the semaphore's value is zero, the calling thread will block until +the lock is aquired or until the call is interrupted by a +signal. Alternatively, the +.Fn sem_trywait +function will fail if the semaphore is already locked, rather than +blocking on the semaphore. +.Pp +If successful (the lock was aquired), +.Fn sem_wait +and +.Fn sem_trywait +will return 0. Otherwise, -1 is returned and +.Va errno +is set, and the state of the semaphore is unchanged. +.Sh ERRORS +.Fn sem_wait +and +.Fn sem_trywait +succeed unless: +.Bl -tag -width Er +.It Bq Er EAGAIN +The semaphore is already locked. +.It Bq Er EINVAL +.Fa sem +is not a valid semaphore descriptor. +.It Bq Er EDEADLK +A deadlock was detected. +.It Bq Er EINTR +The call was interrupted by a signal. +.El +.Sh NOTES +Applications may encounter a priority inversion while using +semaphores. When a thread is waiting on a semaphore which is about to +be posted by a lower-priority thread and the lower-priority thread is +preempted by another thread (of medium priority), a priority inversion +has occured, and the higher-priority thread will be blocked for an +unlimited time period. Programmers using the realtime functionality +of the system should take care to avoid priority inversions. +.Sh SEE ALSO +.Xr semctl 2 , +.Xr semget 2 , +.Xr semop 2 , +.Xr sem_open 2 , +.Xr sem_post 2 +.Sh HISTORY +.Fn sem_wait +and +.Fn sem_trywait +are specified in the POSIX Realtime Extension (1003.1b-1993/1003.1i-1995). diff --git a/sys/setregid.2 b/sys/setregid.2 new file mode 100644 index 0000000..39f95d8 --- /dev/null +++ b/sys/setregid.2 @@ -0,0 +1,92 @@ +.\" Copyright (c) 1980, 1991, 1993, 1994 +.\" 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. +.\" +.\" @(#)setregid.2 8.2 (Berkeley) 4/16/94 +.\" $FreeBSD: src/lib/libc/sys/setregid.2,v 1.6.2.4 2001/12/14 18:34:01 ru Exp $ +.\" +.Dd April 16, 1994 +.Dt SETREGID 2 +.Os +.Sh NAME +.Nm setregid +.Nd set real and effective group ID +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In unistd.h +.Ft int +.Fn setregid "gid_t rgid" "gid_t egid" +.Sh DESCRIPTION +The real and effective group ID's of the current process +are set to the arguments. +Unprivileged users may change the real group +ID to the effective group ID and vice-versa; only the super-user may +make other changes. +.Pp +Supplying a value of -1 for either the real or effective +group ID forces the system to substitute the current +ID in place of the -1 parameter. +.Pp +The +.Fn setregid +function was intended to allow swapping +the real and effective group IDs +in set-group-ID programs to temporarily relinquish the set-group-ID value. +This function did not work correctly, +and its purpose is now better served by the use of the +.Fn setegid +function (see +.Xr setuid 2 ) . +.Pp +When setting the real and effective group IDs to the same value, +the standard +.Fn setgid +function is preferred. +.Sh RETURN VALUES +.Rv -std setregid +.Sh ERRORS +.Bl -tag -width Er +.It Bq Er EPERM +The current process is not the super-user and a change +other than changing the effective group-id to the real group-id +was specified. +.El +.Sh SEE ALSO +.Xr getgid 2 , +.Xr issetugid 2 , +.Xr setegid 2 , +.Xr setgid 2 , +.Xr setuid 2 +.Sh HISTORY +The +.Fn setregid +system call appeared in +.Bx 4.2 . diff --git a/sys/setreuid.2 b/sys/setreuid.2 new file mode 100644 index 0000000..1215a59 --- /dev/null +++ b/sys/setreuid.2 @@ -0,0 +1,90 @@ +.\" Copyright (c) 1980, 1991, 1993, 1994 +.\" 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. +.\" +.\" @(#)setreuid.2 8.2 (Berkeley) 4/16/94 +.\" $FreeBSD: src/lib/libc/sys/setreuid.2,v 1.6.2.6 2001/12/14 18:34:01 ru Exp $ +.\" +.Dd February 8, 2001 +.Dt SETREUID 2 +.Os +.Sh NAME +.Nm setreuid +.Nd set real and effective user ID's +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In unistd.h +.Ft int +.Fn setreuid "uid_t ruid" "uid_t euid" +.Sh DESCRIPTION +The real and effective user IDs of the +current process are set according to the arguments. +If +.Fa ruid +or +.Fa euid +is -1, the current uid is filled in by the system. +Unprivileged users may change the real user +ID to the effective user ID and vice-versa; only the super-user may +make other changes. +.Pp +The +.Fn setreuid +function has been used to swap the real and effective user IDs +in set-user-ID programs to temporarily relinquish the set-user-ID value. +This purpose is now better served by the use of the +.Fn seteuid +function (see +.Xr setuid 2 ) . +.Pp +When setting the real and effective user IDs to the same value, +the standard +.Fn setuid +function is preferred. +.Sh RETURN VALUES +.Rv -std setreuid +.Sh ERRORS +.Bl -tag -width Er +.It Bq Er EPERM +The current process is not the super-user and a change +other than changing the effective user-id to the real user-id +was specified. +.El +.Sh SEE ALSO +.Xr getuid 2 , +.Xr issetugid 2 , +.Xr seteuid 2 , +.Xr setuid 2 +.Sh HISTORY +The +.Fn setreuid +system call appeared in +.Bx 4.2 . diff --git a/sys/shm_open.2 b/sys/shm_open.2 new file mode 100644 index 0000000..ebf2fd3 --- /dev/null +++ b/sys/shm_open.2 @@ -0,0 +1,175 @@ +.\" $Darwin$ +.\" +.\" Copyright (c) 1999-2002 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@ +.\" +.Dd September 20, 1999 +.Dt SHM_OPEN 2 +.Os Darwin +.Sh NAME +.Nm shm_open +.Nd open a shared memory object +.Sh SYNOPSIS +.Fd #include +.Ft int +.Fn shm_open "const char *name" "int flags" "mode_t mode" +.Sh DESCRIPTION +The shared memory object referenced by +.Fa name +is opened for reading and/or writing as specified by the argument +.Fa flags +and the file descriptor returned to the calling process. +The returned file descriptor will be the lowest non-open file +descriptor for the calling process, and is not shared with any +other processes, as it is a new file descriptor. The new file +descriptor will have the +.Dv FD_CLOEXEC +flag set. +Repeated calls +to +.Nm shm_open +with the same string value for +.Fn name +will return a file descriptor referring to the same shared memory +object, provided that the object has not been unlinked by a call to +.Fn shm_unlink . +The +.Fa flags +argument may indicate the file is to be +created if it does not exist (by specifying the +.Dv O_CREAT +flag), in which case the file is created with mode +.Fa mode +as described in +.Xr chmod 2 +and modified by the process' umask value (see +.Xr umask 2 ) . +.Pp +The flags specified are formed by +.Em or Ns 'ing +the following values: +.Pp +.Bd -literal -offset indent -compact +O_RDONLY open for reading only +O_RDWR open for reading and writing +O_CREAT create object if it does not exist +O_EXCL error if create and object exists +O_TRUNC truncate size to 0 +.Ed +.Pp +Exactly one of +.Dv O_RDONLY +or +.Dv O_RDWR +must be specified. +.Pp +If +.Dv O_TRUNC +is specified and the +file exists, the file is truncated to zero length. +If +.Dv O_EXCL +is set with +.Dv O_CREAT +and the file already +exists, +.Fn shm_open +returns an error. This may be used to +implement a simple exclusive access locking mechanism. +.Pp +If successful, +.Fn shm_open +returns a non-negative integer, termed a file descriptor. +It returns -1 and sets +.Va errno +on failure. +The file pointer used to mark the current position within the +memory object is set to the beginning of the object. +.Pp +When a new shared memory object is created it is given the +owner and group corresponding to the effective user and +group of the calling process. There is no visible entry in the +file system for the created object in this implementation. +.Pp +When a shared memory object is created, it persists until it +it unlinked and all other references are gone. Objects do +not persist across a system reboot. +.Pp +The new descriptor is set to remain open across +.Xr execve +system calls; see +.Xr close 2 +and +.Xr fcntl 2 . +.Pp +The system imposes a limit on the number of file descriptors +open simultaneously by one process. +.Xr Getdtablesize 2 +returns the current system limit. +.Sh ERRORS +The named object is opened unless: +.Bl -tag -width Er +.It Bq Er EACCES +The required permissions (for reading and/or writing) +are denied for the given flags. +.It Bq Er EACCES +.Dv O_CREAT +is specified, the object does not exist, and permission to +create the object is denied. +.It Bq Er EEXIST +.Dv O_CREAT +and +.Dv O_EXCL +were specified and the object exists. +.It Bq Er EINTR +The +.Fn shm_open +operation was interrupted by a signal. +.It Bq Er EINVAL +The +.Fn shm_open +operation is not supported. +.It Bq Er EMFILE +The process has already reached its limit for open file descriptors. +.It Bq Er ENAMETOOLONG +.Fa name +exceeded +.Dv SHM_NAME_MAX +characters. +.It Bq Er ENFILE +The system file table is full. +.It Bq Er ENOENT +.Dv O_CREAT +is not set and the named object does not exist. +.It Bq Er ENOSPC +.Dv O_CREAT +is specified, the file does not exist, and there is insufficient +space available to create the object. +.El +.Sh SEE ALSO +.Xr chmod 2 , +.Xr close 2 , +.Xr getdtablesize 2 , +.Xr mmap 2 , +.Xr shm_unlink 2 , +.Xr umask 2 +.Sh HISTORY +.Fn shm_open +is specified in the POSIX Realtime Extension (1003.1b-1993/1003.1i-1995). diff --git a/sys/shm_unlink.2 b/sys/shm_unlink.2 new file mode 100644 index 0000000..0d85afd --- /dev/null +++ b/sys/shm_unlink.2 @@ -0,0 +1,73 @@ +.\" $Darwin$ +.\" +.\" Copyright (c) 1999-2002 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@ +.\" +.Dd September 20, 1999 +.Dt SHM_UNLINK 2 +.Os Darwin +.Sh NAME +.Nm shm_unlink +.Nd remove shared memory object +.Sh SYNOPSIS +.Fd #include +.Ft int +.Fn shm_unlink "const char *name" +.Sh DESCRIPTION +The +.Fn shm_unlink +function removes the shared memory object named by +.Fa name . +If no process has the file open, then all resources associated +with the object are reclaimed. +If one or more process have the object open, the name removed, +but the removal of the memory object is delayed until all +references to it have been closed. +.Sh RETURN VALUES +Upon successful completion, a value of 0 is returned. +Otherwise, a value of -1 is returned and +.Va errno +is set to indicate the error, and the named shared memory object +will remain unchanged. +.Sh ERRORS +The +.Fn shm_unlink +succeeds unless: +.Bl -tag -width Er +.It Bq Er EACCES +Permission is denied to be remove the object. +.It Bq Er ENAMETOOLONG +.Fa name +exceeded +.Dv SHM_NAME_MAX +characters. +.It Bq Er ENOENT +The named object does not exist. +.El +.Sh SEE ALSO +.Xr close 2 , +.Xr mmap 2 , +.Xr munmap 2 , +.Xr shmat 2 , +.Xr shmctl 2 , +.Xr shm_open 2 +.Sh HISTORY +.Fn shm_open +is specified in the POSIX Realtime Extension (1003.1b-1993/1003.1i-1995). diff --git a/sys/sigaction.c b/sys/sigaction.c new file mode 100644 index 0000000..1c3709e --- /dev/null +++ b/sys/sigaction.c @@ -0,0 +1,101 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + * + * @(#)sigaction.c 1.0 + */ + +#include +#include +#include +#include + +/* + * Intercept the sigaction syscall and use our signal trampoline + * as the signal handler instead. The code here is derived + * 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; +{ + struct sigaction vec; + void (*prevsig)(); + extern void _sigtramp(); + struct __sigaction sa; + struct __sigaction *sap; + + if (sig <= 0 || sig >= NSIG || sig == SIGKILL || sig == SIGSTOP) { + errno = EINVAL; + return (-1); + } + sap = (struct __sigaction *)0; + if (nsv) { + sa.sa_handler = nsv->sa_handler; + sa.sa_tramp = _sigtramp; + 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__ + +int +_sigaction_nobind (sig, nsv, osv) + int sig; + register const struct sigaction *nsv; + register struct sigaction *osv; +{ + return sigaction__(sig, nsv, osv, 0); +} +#endif + diff --git a/sys/sigcatch.c b/sys/sigcatch.c new file mode 100644 index 0000000..2e19f89 --- /dev/null +++ b/sys/sigcatch.c @@ -0,0 +1,36 @@ +/* + * Copyright (c) 1999 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@ + */ +/* Copyright (c) 1992 NeXT Computer, Inc. All rights reserved. + * + * This file contains global data and the size of the global data can NOT + * change or otherwise it would make the shared library incompatable. This + * data has been padded so new signals can be added. Also see gen/siglist.c + */ + +#include "sigcatch.h" + +/* + * Actually declare the global data. + */ +sigcatch_t sigcatch[PADDING] = { (void (*)(int, int, struct sigcontext *))0 }; + + diff --git a/sys/sigcatch.h b/sys/sigcatch.h new file mode 100644 index 0000000..cf7ef81 --- /dev/null +++ b/sys/sigcatch.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 1999 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@ + */ +/* Copyright (c) 1992 NeXT Computer, Inc. All rights reserved. + * + * File: libc/m98k/sigcatch.h + * + * Header file for sigtramp data structures. + */ + +#include + +/* + * Constants + */ +#define PADDING 50 + +/* + * Type definitions. + */ +typedef void (*sigcatch_t)(int, int, struct sigcontext *); + +/* + * Global data. + */ +extern sigcatch_t sigcatch[PADDING]; diff --git a/sys/sigsuspend.c b/sys/sigsuspend.c new file mode 100644 index 0000000..dcc65be --- /dev/null +++ b/sys/sigsuspend.c @@ -0,0 +1,41 @@ +/* + * Copyright (c) 1999 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@ + */ +/* @(#)sigsuspend.c 1.0 9/22/95 (c) 1995 NeXT */ + +#include +#include +#include + +int +sigsuspend ( + const sigset_t *sigmask_p +) +{ + sigset_t mask; + + if (sigmask_p) + mask = *sigmask_p; + else + sigemptyset(&mask); + return syscall (SYS_sigsuspend, mask); +} + diff --git a/sys/sigtramp.c b/sys/sigtramp.c new file mode 100644 index 0000000..0ab0ece --- /dev/null +++ b/sys/sigtramp.c @@ -0,0 +1,64 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#import "sigcatch.h" +#import +#import +#import + +/* + * sigvec registers _sigtramp as the handler for any signal requiring + * user-mode intervention. All _sigtramp does is find the real handler, + * calls it, then sigreturn's. + * + * Note that the kernel saves/restores all of our register state. + */ +#if defined(__DYNAMIC__) +int __in_sigtramp = 0; +#endif + +void +_sigtramp( + union __sigaction_u __sigaction_u, + int sigstyle, + int sig, + siginfo_t *sinfo, + struct ucontext *uctx +) { + +#if defined(__DYNAMIC__) + __in_sigtramp++; +#endif + if (sigstyle == 1) + sa_handler(sig); +#ifdef __ppc__ + else + sa_sigaction(sig, sinfo, uctx); +#endif /* __ppc__ */ + +#if defined(__DYNAMIC__) + __in_sigtramp--; +#endif + sigreturn(uctx); +} diff --git a/sys/sigwait.2 b/sys/sigwait.2 new file mode 100644 index 0000000..5309a79 --- /dev/null +++ b/sys/sigwait.2 @@ -0,0 +1,82 @@ +.\" Copyright (C) 2000 Jason Evans . +.\" 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(s), this list of conditions and the following disclaimer as +.\" the first lines of this file unmodified other than the possible +.\" addition of one or more copyright notices. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice(s), 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 COPYRIGHT HOLDER(S) ``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 COPYRIGHT HOLDER(S) 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_r/man/sigwait.3,v 1.7 2001/10/01 16:09:09 ru Exp $ +.Dd April 27, 2000 +.Dt SIGWAIT 2 +.Os +.Sh NAME +.Nm sigwait +.Nd select a set of signals +.Sh SYNOPSIS +.In signal.h +.Ft int +.Fn sigwait "const sigset_t *set" "int *sig" +.Sh DESCRIPTION +The +.Fn sigwait +function selects a set of signals, specified by +.Fa set . +If none of the selected signals are pending, +.Fn sigwait +waits until one or more of the selected signals has been generated. +Then +.Fn sigwait +atomically clears one of the selected signals from the set of pending signals +for the process and sets the location pointed to by +.Fa sig +to the signal number that was cleared. +.Pp +The signals specified by +.Fa set +should be blocked at the time of the call to +.Fn sigwait . +.Sh RETURN VALUES +If successful, +.Fn sigwait +returns 0 and sets the location pointed to by +.Fa sig +to the cleared signal number. +Otherwise, an error number is returned. +.Sh ERRORS +.Fn sigwait +will fail if: +.Bl -tag -width Er +.It Bq Er EINVAL +.Fa set +specifies one or more invalid signal numbers. +.El +.Sh SEE ALSO +.Xr sigaction 2 , +.Xr sigpending 2 , +.Xr sigsuspend 2 , +.Xr pause 3 , +.Xr pthread_sigmask 2 +.Sh STANDARDS +.Fn sigwait +conforms to ISO/IEC 9945-1:1996 (``POSIX.1'') + diff --git a/threads.subproj/Makefile b/threads.subproj/Makefile deleted file mode 100644 index a61e757..0000000 --- a/threads.subproj/Makefile +++ /dev/null @@ -1,57 +0,0 @@ -# -# Generated by the NeXT Project Builder. -# -# NOTE: Do NOT change this file -- Project Builder maintains it. -# -# Put all of your customizations in files called Makefile.preamble -# and Makefile.postamble (both optional), and Makefile will include them. -# - -NAME = threads - -PROJECTVERSION = 2.8 -PROJECT_TYPE = Component - -HFILES = cthread_internals.h cthreads.h - -CFILES = cprocs.c cthreads.c lu_utils.c mig_support.c - -SUBPROJECTS = i386.subproj ppc.subproj - -OTHERSRCS = Makefile.preamble Makefile Makefile.postamble - - -MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles -CODE_GEN_STYLE = DYNAMIC -MAKEFILE = subproj.make -NEXTSTEP_INSTALLDIR = /Local/Developer/System -LIBS = -DEBUG_LIBS = $(LIBS) -PROF_LIBS = $(LIBS) - - -NEXTSTEP_PB_CFLAGS = -D__POSIX_LIB__ -PROJECT_HEADERS = cthread_internals.h cthreads.h - - - -NEXTSTEP_BUILD_OUTPUT_DIR = /Local/Public/Sandbox/$(USER)/BUILD/$(NAME) - -NEXTSTEP_PUBLIC_HEADERS_DIR = /usr/include - -NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc -WINDOWS_OBJCPLUS_COMPILER = $(DEVDIR)/gcc -PDO_UNIX_OBJCPLUS_COMPILER = $(NEXTDEV_BIN)/gcc -NEXTSTEP_JAVA_COMPILER = /usr/bin/javac -WINDOWS_JAVA_COMPILER = $(JDKBINDIR)/javac.exe -PDO_UNIX_JAVA_COMPILER = $(JDKBINDIR)/javac - -include $(MAKEFILEDIR)/platform.make - --include Makefile.preamble - -include $(MAKEFILEDIR)/$(MAKEFILE) - --include Makefile.postamble - --include Makefile.dependencies diff --git a/threads.subproj/Makefile.postamble b/threads.subproj/Makefile.postamble deleted file mode 100644 index 411cde6..0000000 --- a/threads.subproj/Makefile.postamble +++ /dev/null @@ -1,100 +0,0 @@ -############################################################################### -# Makefile.postamble -# Copyright 1997, Apple Computer, Inc. -# -# Use this makefile, which is imported after all other makefiles, to -# override attributes for a project's Makefile environment. This allows you -# to take advantage of the environment set up by the other Makefiles. -# You can also define custom rules at the end of this file. -# -############################################################################### -# -# These variables are exported by the standard makefiles and can be -# used in any customizations you make. They are *outputs* of -# the Makefiles and should be used, not set. -# -# PRODUCTS: products to install. All of these products will be placed in -# the directory $(DSTROOT)$(INSTALLDIR) -# GLOBAL_RESOURCE_DIR: The directory to which resources are copied. -# LOCAL_RESOURCE_DIR: The directory to which localized resources are copied. -# OFILE_DIR: Directory into which .o object files are generated. -# DERIVED_SRC_DIR: Directory used for all other derived files -# -# ALL_CFLAGS: flags to pass when compiling .c files -# ALL_MFLAGS: flags to pass when compiling .m files -# ALL_CCFLAGS: flags to pass when compiling .cc, .cxx, and .C files -# ALL_MMFLAGS: flags to pass when compiling .mm, .mxx, and .M files -# ALL_PRECOMPFLAGS: flags to pass when precompiling .h files -# ALL_LDFLAGS: flags to pass when linking object files -# ALL_LIBTOOL_FLAGS: flags to pass when libtooling object files -# ALL_PSWFLAGS: flags to pass when processing .psw and .pswm (pswrap) files -# ALL_RPCFLAGS: flags to pass when processing .rpc (rpcgen) files -# ALL_YFLAGS: flags to pass when processing .y (yacc) files -# ALL_LFLAGS: flags to pass when processing .l (lex) files -# -# NAME: name of application, bundle, subproject, palette, etc. -# LANGUAGES: langages in which the project is written (default "English") -# English_RESOURCES: localized resources (e.g. nib's, images) of project -# GLOBAL_RESOURCES: non-localized resources of project -# -# SRCROOT: base directory in which to place the new source files -# SRCPATH: relative path from SRCROOT to present subdirectory -# -# INSTALLDIR: Directory the product will be installed into by 'install' target -# PUBLIC_HDR_INSTALLDIR: where to install public headers. Don't forget -# to prefix this with DSTROOT when you use it. -# PRIVATE_HDR_INSTALLDIR: where to install private headers. Don't forget -# to prefix this with DSTROOT when you use it. -# -# EXECUTABLE_EXT: Executable extension for the platform (i.e. .exe on Windows) -# -############################################################################### - -# Some compiler flags can be overridden here for certain build situations. -# -# WARNING_CFLAGS: flag used to set warning level (defaults to -Wmost) -# DEBUG_SYMBOLS_CFLAGS: debug-symbol flag passed to all builds (defaults -# to -g) -# DEBUG_BUILD_CFLAGS: flags passed during debug builds (defaults to -DDEBUG) -# OPTIMIZE_BUILD_CFLAGS: flags passed during optimized builds (defaults -# to -O) -# PROFILE_BUILD_CFLAGS: flags passed during profile builds (defaults -# to -pg -DPROFILE) -# LOCAL_DIR_INCLUDE_DIRECTIVE: flag used to add current directory to -# the include path (defaults to -I.) -# DEBUG_BUILD_LDFLAGS, OPTIMIZE_BUILD_LDFLAGS, PROFILE_BUILD_LDFLAGS: flags -# passed to ld/libtool (defaults to nothing) - - -# Library and Framework projects only: -# INSTALL_NAME_DIRECTIVE: This directive ensures that executables linked -# against the framework will run against the correct version even if -# the current version of the framework changes. You may override this -# to "" as an alternative to using the DYLD_LIBRARY_PATH during your -# development cycle, but be sure to restore it before installing. - - -# Ownership and permissions of files installed by 'install' target - -#INSTALL_AS_USER = root - # User/group ownership -#INSTALL_AS_GROUP = wheel - # (probably want to set both of these) -#INSTALL_PERMISSIONS = - # If set, 'install' chmod's executable to this - - -# Options to strip. Note: -S strips debugging symbols (executables can be stripped -# down further with -x or, if they load no bundles, with no options at all). - -#STRIPFLAGS = -S - - -######################################################################### -# Put rules to extend the behavior of the standard Makefiles here. Include them in -# the dependency tree via cvariables like AFTER_INSTALL in the Makefile.preamble. -# -# You should avoid redefining things like "install" or "app", as they are -# owned by the top-level Makefile API and no context has been set up for where -# derived files should go. -# diff --git a/threads.subproj/Makefile.preamble b/threads.subproj/Makefile.preamble deleted file mode 100644 index c1624b4..0000000 --- a/threads.subproj/Makefile.preamble +++ /dev/null @@ -1,137 +0,0 @@ -############################################################################### -# Makefile.preamble -# Copyright 1997, Apple Computer, Inc. -# -# Use this makefile for configuring the standard application makefiles -# associated with ProjectBuilder. It is included before the main makefile. -# In Makefile.preamble you set attributes for a project, so they are available -# to the project's makefiles. In contrast, you typically write additional rules or -# override built-in behavior in the Makefile.postamble. -# -# Each directory in a project tree (main project plus subprojects) should -# have its own Makefile.preamble and Makefile.postamble. -############################################################################### -# -# Before the main makefile is included for this project, you may set: -# -# MAKEFILEDIR: Directory in which to find $(MAKEFILE) -# MAKEFILE: Top level mechanism Makefile (e.g., app.make, bundle.make) - -# Compiler/linker flags added to the defaults: The OTHER_* variables will be -# inherited by all nested sub-projects, but the LOCAL_ versions of the same -# variables will not. Put your -I, -D, -U, and -L flags in ProjectBuilder's -# Build Attributes inspector if at all possible. To override the default flags -# that get passed to ${CC} (e.g. change -O to -O2), see Makefile.postamble. The -# variables below are *inputs* to the build process and distinct from the override -# settings done (less often) in the Makefile.postamble. -# -# OTHER_CFLAGS, LOCAL_CFLAGS: additional flags to pass to the compiler -# Note that $(OTHER_CFLAGS) and $(LOCAL_CFLAGS) are used for .h, ...c, .m, -# .cc, .cxx, .C, and .M files. There is no need to respecify the -# flags in OTHER_MFLAGS, etc. -# OTHER_MFLAGS, LOCAL_MFLAGS: additional flags for .m files -# OTHER_CCFLAGS, LOCAL_CCFLAGS: additional flags for .cc, .cxx, and ...C files -# OTHER_MMFLAGS, LOCAL_MMFLAGS: additional flags for .mm and .M files -# OTHER_PRECOMPFLAGS, LOCAL_PRECOMPFLAGS: additional flags used when -# precompiling header files -# OTHER_LDFLAGS, LOCAL_LDFLAGS: additional flags passed to ld and libtool -# OTHER_PSWFLAGS, LOCAL_PSWFLAGS: additional flags passed to pswrap -# OTHER_RPCFLAGS, LOCAL_RPCFLAGS: additional flags passed to rpcgen -# OTHER_YFLAGS, LOCAL_YFLAGS: additional flags passed to yacc -# OTHER_LFLAGS, LOCAL_LFLAGS: additional flags passed to lex - -# These variables provide hooks enabling you to add behavior at almost every -# stage of the make: -# -# BEFORE_PREBUILD: targets to build before installing headers for a subproject -# AFTER_PREBUILD: targets to build after installing headers for a subproject -# BEFORE_BUILD_RECURSION: targets to make before building subprojects -# BEFORE_BUILD: targets to make before a build, but after subprojects -# AFTER_BUILD: targets to make after a build -# -# BEFORE_INSTALL: targets to build before installing the product -# AFTER_INSTALL: targets to build after installing the product -# BEFORE_POSTINSTALL: targets to build before postinstalling every subproject -# AFTER_POSTINSTALL: targts to build after postinstalling every subproject -# -# BEFORE_INSTALLHDRS: targets to build before installing headers for a -# subproject -# AFTER_INSTALLHDRS: targets to build after installing headers for a subproject -# BEFORE_INSTALLSRC: targets to build before installing source for a subproject -# AFTER_INSTALLSRC: targets to build after installing source for a subproject -# -# BEFORE_DEPEND: targets to build before building dependencies for a -# subproject -# AFTER_DEPEND: targets to build after building dependencies for a -# subproject -# -# AUTOMATIC_DEPENDENCY_INFO: if YES, then the dependency file is -# updated every time the project is built. If NO, the dependency -# file is only built when the depend target is invoked. - -# Framework-related variables: -# FRAMEWORK_DLL_INSTALLDIR: On Windows platforms, this variable indicates -# where to put the framework's DLL. This variable defaults to -# $(INSTALLDIR)/../Executables - -# Library-related variables: -# PUBLIC_HEADER_DIR: Determines where public exported header files -# should be installed. Do not include $(DSTROOT) in this value -- -# it is prefixed automatically. For library projects you should -# set this to something like /Developer/Headers/$(NAME). Do not set -# this variable for framework projects unless you do not want the -# header files included in the framework. -# PRIVATE_HEADER_DIR: Determines where private exported header files -# should be installed. Do not include $(DSTROOT) in this value -- -# it is prefixed automatically. -# LIBRARY_STYLE: This may be either STATIC or DYNAMIC, and determines -# whether the libraries produced are statically linked when they -# are used or if they are dynamically loadable. This defaults to -# DYNAMIC. -# LIBRARY_DLL_INSTALLDIR: On Windows platforms, this variable indicates -# where to put the library's DLL. This variable defaults to -# $(INSTALLDIR)/../Executables -# -# INSTALL_AS_USER: owner of the intalled products (default root) -# INSTALL_AS_GROUP: group of the installed products (default wheel) -# INSTALL_PERMISSIONS: permissions of the installed product (default o+rX) -# -# OTHER_RECURSIVE_VARIABLES: The names of variables which you want to be -# passed on the command line to recursive invocations of make. Note that -# the values in OTHER_*FLAGS are inherited by subprojects automatically -- -# you do not have to (and shouldn't) add OTHER_*FLAGS to -# OTHER_RECURSIVE_VARIABLES. - -# Additional headers to export beyond those in the PB.project: -# OTHER_PUBLIC_HEADERS -# OTHER_PROJECT_HEADERS -# OTHER_PRIVATE_HEADERS - -# Additional files for the project's product: <> -# OTHER_RESOURCES: (non-localized) resources for this project -# OTHER_OFILES: relocatables to be linked into this project -# OTHER_LIBS: more libraries to link against -# OTHER_PRODUCT_DEPENDS: other dependencies of this project -# OTHER_SOURCEFILES: other source files maintained by .pre/postamble -# OTHER_GARBAGE: additional files to be removed by `make clean' - -# Set this to YES if you don't want a final libtool call for a library/framework. -# BUILD_OFILES_LIST_ONLY - -# To include a version string, project source must exist in a directory named -# $(NAME).%d[.%d][.%d] and the following line must be uncommented. -# OTHER_GENERATED_OFILES = $(VERS_OFILE) - -# This definition will suppress stripping of debug symbols when an executable -# is installed. By default it is YES. -# STRIP_ON_INSTALL = NO - -# Uncomment to suppress generation of a KeyValueCoding index when installing -# frameworks (This index is used by WOB and IB to determine keys available -# for an object). Set to YES by default. -# PREINDEX_FRAMEWORK = NO - -# Change this definition to install projects somewhere other than the -# standard locations. NEXT_ROOT defaults to "C:/Apple" on Windows systems -# and "" on other systems. -DSTROOT = $(HOME) diff --git a/threads.subproj/PB.project b/threads.subproj/PB.project deleted file mode 100644 index e63fd07..0000000 --- a/threads.subproj/PB.project +++ /dev/null @@ -1,28 +0,0 @@ -{ - DYNAMIC_CODE_GEN = YES; - FILESTABLE = { - H_FILES = (cthread_internals.h, cthreads.h); - OTHER_LINKED = (cprocs.c, cthreads.c, lu_utils.c, mig_support.c); - OTHER_SOURCES = (Makefile.preamble, Makefile, Makefile.postamble); - PROJECT_HEADERS = (cthread_internals.h, cthreads.h); - SUBPROJECTS = (i386.subproj, ppc.subproj); - }; - LANGUAGE = English; - MAKEFILEDIR = "$(MAKEFILEPATH)/pb_makefiles"; - NEXTSTEP_BUILDDIR = "/Local/Public/Sandbox/$(USER)/BUILD/$(NAME)"; - NEXTSTEP_BUILDTOOL = /bin/gnumake; - NEXTSTEP_COMPILEROPTIONS = "-D__POSIX_LIB__"; - NEXTSTEP_INSTALLDIR = /Local/Developer/System; - NEXTSTEP_JAVA_COMPILER = /usr/bin/javac; - NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc; - NEXTSTEP_PUBLICHEADERSDIR = /usr/include; - PDO_UNIX_BUILDTOOL = $NEXT_ROOT/Developer/bin/make; - PDO_UNIX_JAVA_COMPILER = "$(JDKBINDIR)/javac"; - PDO_UNIX_OBJCPLUS_COMPILER = "$(NEXTDEV_BIN)/gcc"; - PROJECTNAME = threads; - PROJECTTYPE = Component; - PROJECTVERSION = 2.8; - WINDOWS_BUILDTOOL = $NEXT_ROOT/Developer/Executables/make; - WINDOWS_JAVA_COMPILER = "$(JDKBINDIR)/javac.exe"; - WINDOWS_OBJCPLUS_COMPILER = "$(DEVDIR)/gcc"; -} diff --git a/threads.subproj/cprocs.c b/threads.subproj/cprocs.c deleted file mode 100644 index dfa18a8..0000000 --- a/threads.subproj/cprocs.c +++ /dev/null @@ -1,151 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Mach Operating System - * Copyright (c) 1989 Carnegie-Mellon University - * All rights reserved. The CMU software License Agreement specifies - * the terms and conditions for use and redistribution. - */ - -/* - * HISTORY - * 22-July-93 Blaine Garst - * fixed kernel cache set up of cproc info - * - * 05-April-90 Morris Meyer (mmeyer) at NeXT - * Fixed bug in cproc_fork_child() where the first cproc would - * try doing a msg_rpc() with an invalid reply port. - * - */ - -/* - * cprocs.c - by Eric Cooper - * - * Implementation of cprocs (lightweight processes) - * and primitive synchronization operations. - */ -#include -#include "pthread_internals.h" -#include "cthreads.h" -#include "cthread_internals.h" -#include - -/* - * C Threads imports: - */ -extern void stack_init(); -extern void alloc_stack(), _dealloc_stack(); - -/* - * Mach imports: - */ -extern mach_port_t mach_thread_self(); -extern boolean_t swtch_pri(); - -private int cprocs_started = FALSE; - -#ifdef CTHREADS_DEBUG -private void -print_cproc(p) - cproc_t p; -{ - char *s; - - switch (p->state) { - case CPROC_RUNNING: - s = ""; - break; - case CPROC_SPINNING: - s = "+"; - break; - case CPROC_BLOCKED: - s = "*"; - break; - default: - ASSERT(SHOULDNT_HAPPEN); - } - printf(" %x(%s)%s", - p->id, - cthread_name(p->incarnation), s); -} - -private void -print_cproc_queue(name, queue) - const char * name; - cthread_queue_t queue; -{ - printf("[%s] %s:", cthread_name(cthread_self()), name); - cthread_queue_map(queue, cproc_t, print_cproc); - printf("\n"); -} -#endif CTHREADS_DEBUG - -private int cproc_lock = 0; /* unlocked */ -private cproc_t cprocs = NO_CPROC; /* linked list of cprocs */ - -#ifdef CTHREADS_DEBUG -private void -print_all_cprocs() -{ - cproc_t p; - - printf("[%s] cprocs:", cthread_name(cthread_self())); - for (p = cprocs; p != NO_CPROC; p = p->link) - print_cproc(p); - printf("\n"); -} -#endif CTHREADS_DEBUG - -/* - * Routines for supporting fork() of multi-threaded programs. - */ - -void _cproc_fork_child() -/* - * Called in the child after a fork(). Resets cproc data structures to - * coincide with the reality that we now have a single cproc and cthread. - */ -{ - pthread_t pself; - - pself = pthread_self(); - pself->reply_port = MACH_PORT_NULL; -} - -/* - * Support for a per-thread UNIX errno. - */ - -#undef errno -extern int errno; -void cthread_set_errno_self(error) - int error; -{ - pthread_t t; - - t = pthread_self(); - if (t && (t->sig == _PTHREAD_SIG)) { - t->err_no = error; - } - errno = error; -} - diff --git a/threads.subproj/cthread_internals.h b/threads.subproj/cthread_internals.h deleted file mode 100644 index 901a438..0000000 --- a/threads.subproj/cthread_internals.h +++ /dev/null @@ -1,143 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Mach Operating System - * Copyright (c) 1989 Carnegie-Mellon University - * All rights reserved. The CMU software License Agreement specifies - * the terms and conditions for use and redistribution. - */ - -/* - * HISTORY - * 08-Mar-90 Avadis Tevanian, Jr. (avie) at NeXT - * Added errno field to cproc structure. - * - */ - -/* - * cthread_internals.h - by Eric Cooper - * - * Private definitions for the C Threads implementation. - * - * The cproc structure is used for different implementations - * of the basic schedulable units that execute cthreads. - * - * MTHREAD MACH threads; single address space, - * kernel-mode preemptive scheduling - */ -#include -#include -#include - -/* - * Low-level thread implementation. - * This structure must agree with struct ur_cthread in cthreads.h - */ -typedef struct cproc { - struct cproc *next; /* for lock, condition, and ready queues */ - struct cproc *incarnation; /* for cthread_self() */ - int state; - mach_port_t reply_port; /* for mig_get_reply_port() */ - - mach_port_t wait_port; - - int id; - struct cproc *link; /* so all cprocs can be found - after a fork() */ - int flags; - - unsigned int stack_base; - unsigned int stack_size; - int error; - -} *cproc_t; - -#define NO_CPROC ((cproc_t) 0) -#define cproc_self() ((cproc_t) ur_cthread_self()) -extern void cthread_set_self(cproc_t p); - -/* - * Possible cproc states. - */ -#define CPROC_RUNNING 0 -#define CPROC_SPINNING 1 -#define CPROC_BLOCKED 2 - -/* - * The cproc flag bits. - */ -#define CPROC_INITIAL_STACK 0x1 -#define CPROC_NOCACHE_THREAD /* Don't try to cache this cthread on exit */ - -/* - * C Threads imports: - */ -#ifdef __STRICT_BSD__ -extern char *malloc(); -#endif /* __STRICT_BSD__ */ - -/* - * Mach imports: - */ -extern void mach_error(); - -/* - * C library imports: - */ -#ifdef __STRICT_BSD__ -extern exit(); -#else -#include -#endif /* __STRICT_BSD__ */ - -/* - * Macro for MACH kernel calls. - */ -#ifndef MACH_CALL -#define MACH_CALL(expr, ret) { \ - if (((ret) = (expr)) != KERN_SUCCESS) { \ - mach_error(#expr, (ret)); \ - assert(0); \ - } \ -} -#endif - -/* - * Debugging support. - */ -#ifdef CTHREADS_DEBUG - -#define private -#define TRACE(x) if (cthread_debug) x ; else -extern int cthread_debug; - -/* - * C library imports: - */ -#include -#include -#else /* CTHREADS_DEBUG */ - -#define private static -#define TRACE(x) - -#endif /* DEBUG */ diff --git a/threads.subproj/cthreads.c b/threads.subproj/cthreads.c deleted file mode 100644 index 5bd7035..0000000 --- a/threads.subproj/cthreads.c +++ /dev/null @@ -1,141 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * cthreads.c - by Eric Cooper - * - * Implementation of cthread_fork, cthread_join, cthread_exit, etc. - * HISTORY - * 22-July-93 Blaine Garst - * fixed association of read_thread info - * fixed kernel cache set up of cproc info - * - */ -#include -#include "cthreads.h" -#include "cthread_internals.h" -#include "pthread_internals.h" -/* - * C Threads imports: - */ -extern void cproc_init(); -extern thread_port_t cproc_create(); -extern void mig_init(); -extern void _pthread_set_self(pthread_t); - -/* - * Mach imports: - */ -extern void mig_fork_child(); - -/* - * C library imports: - */ -extern int _setjmp(jmp_buf env); -extern void _longjmp(jmp_buf env, int val); - -/* - * Thread status bits. - */ -#define T_MAIN 0x1 -#define T_RETURNED 0x2 -#define T_DETACHED 0x4 - -#ifdef CTHREADS_DEBUG -int cthread_debug = FALSE; -#endif CTHREADS_DEBUG - -/* - * Routines for supporting fork() of multi-threaded programs. - */ - - -extern void _malloc_fork_prepare(), _malloc_fork_parent(); -extern void _malloc_fork_child(); -extern void _cproc_fork_child(), _stack_fork_child(); -extern void _lu_fork_child(void); -extern void _pthread_fork_child(void); - -static pthread_t psaved_self = 0; -static pthread_lock_t psaved_self_global_lock = LOCK_INITIALIZER; - -void _cthread_fork_prepare() -/* - * Prepare cthreads library to fork() a multi-threaded program. All cthread - * library critical section locks are acquired before a fork() and released - * afterwards to insure no cthread data structure is left in an inconsistent - * 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); - _malloc_fork_prepare(); -} - -void _cthread_fork_parent() -/* - * Called in the parent process after a fork syscall. - * Releases locks acquired by cthread_fork_prepare(). - */ -{ - _malloc_fork_parent(); - _spin_unlock(&psaved_self->lock); - _spin_unlock(&psaved_self_global_lock); - -} - -void _cthread_fork_child() -/* - * Called in the child process after a fork syscall. Releases locks acquired - * by cthread_fork_prepare(). Deallocates cthread data structures which - * described other threads in our parent. Makes this thread the main thread. - * - * The mach_init() routine must be called in the child before this routine. - */ -{ - pthread_t p = psaved_self; - - _pthread_set_self(p); - _spin_unlock(&psaved_self_global_lock); - mig_fork_child(); - _malloc_fork_child(); - p->kernel_thread = mach_thread_self(); - p->reply_port = MACH_PORT_NULL; - p->mutexes = NULL; - p->cleanup_stack = NULL; - p->death = MACH_PORT_NULL; - p->joiners = MACH_PORT_NULL; - p->num_joiners = 0; - p->detached = _PTHREAD_CREATE_PARENT; - _spin_unlock(&p->lock); - - _cproc_fork_child(); - - _lu_fork_child(); - - _pthread_fork_child(); - - __is_threaded = 0; - mig_init(1); /* enable multi-threaded mig interfaces */ - -} - diff --git a/threads.subproj/cthreads.h b/threads.subproj/cthreads.h deleted file mode 100644 index 6c97927..0000000 --- a/threads.subproj/cthreads.h +++ /dev/null @@ -1,307 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Cthreads. - */ - -#ifndef _CTHREADS_ -#define _CTHREADS_ 1 - -#if defined(__cplusplus) -#define __DECLBEGIN extern "C" { -#define __DECLEND } -#else -#define __DECLBEGIN -#define __DECLEND -#endif - -typedef void *any_t; - -/* - * Spin locks. - */ -__DECLBEGIN -extern void spin_unlock(int *p); -extern void spin_lock(int *p); -__DECLEND - -#include -#include - -#ifndef MACRO_BEGIN - -#define NEVER FALSE - -#define MACRO_BEGIN do { -#define MACRO_END } while (NEVER) - -#endif /* MACRO_BEGIN */ - -/* - * C Threads package initialization. - */ -__DECLBEGIN -extern void cthread_init(); -__DECLEND - -#include - -/* - * Queues. - */ -typedef struct cthread_queue { - struct cthread_queue_item *head; - struct cthread_queue_item *tail; -} *cthread_queue_t; - -typedef struct cthread_queue_item { - struct cthread_queue_item *next; -} *cthread_queue_item_t; - -#define NO_QUEUE_ITEM ((cthread_queue_item_t) 0) - -#define QUEUE_INITIALIZER { NO_QUEUE_ITEM, NO_QUEUE_ITEM } - -#define cthread_queue_alloc() ((cthread_queue_t) calloc(1, sizeof(struct cthread_queue))) -#define cthread_queue_init(q) ((q)->head = (q)->tail = 0) -#define cthread_queue_free(q) free((any_t) (q)) - -#define cthread_queue_enq(q, x) \ - MACRO_BEGIN \ - (x)->next = 0; \ - if ((q)->tail == 0) \ - (q)->head = (cthread_queue_item_t) (x); \ - else \ - (q)->tail->next = (cthread_queue_item_t) (x); \ - (q)->tail = (cthread_queue_item_t) (x); \ - MACRO_END - -#define cthread_queue_preq(q, x) \ - MACRO_BEGIN \ - if ((q)->tail == 0) \ - (q)->tail = (cthread_queue_item_t) (x); \ - ((cthread_queue_item_t) (x))->next = (q)->head; \ - (q)->head = (cthread_queue_item_t) (x); \ - MACRO_END - -#define cthread_queue_head(q, t) ((t) ((q)->head)) - -#define cthread_queue_deq(q, t, x) \ - MACRO_BEGIN \ - if (((x) = (t) ((q)->head)) != 0 && \ - ((q)->head = (cthread_queue_item_t) ((x)->next)) == 0) \ - (q)->tail = 0; \ - MACRO_END - -#define cthread_queue_map(q, t, f) \ - MACRO_BEGIN \ - register cthread_queue_item_t x, next; \ - for (x = (cthread_queue_item_t) ((q)->head); x != 0; x = next) { \ - next = x->next; \ - (*(f))((t) x); \ - } \ - MACRO_END - - -/* - * Mutex objects. - */ -typedef struct mutex { - int lock; - char *name; -} *mutex_t; - -#define MUTEX_INITIALIZER { 0, 0 } - -#define mutex_alloc() ((mutex_t) calloc(1, sizeof(struct mutex))) -#define mutex_init(m) ((m)->lock = 0) -#define mutex_set_name(m, x) ((m)->name = (x)) -#define mutex_name(m) ((m)->name != 0 ? (m)->name : "?") -#define mutex_clear(m) /* nop */ -#define mutex_free(m) free((any_t) (m)) - -#define mutex_lock(m) \ - MACRO_BEGIN \ - if (! mutex_try_lock(m)) mutex_wait_lock(m); \ - MACRO_END - -__DECLBEGIN -extern int mutex_try_lock(mutex_t m); /* nonblocking */ -extern void mutex_wait_lock(mutex_t m); /* blocking */ -extern void mutex_unlock(mutex_t m); -__DECLEND - -/* - * Condition variables. - */ -typedef struct condition { - int lock; - struct cthread_queue queue; - char *name; -} *condition_t; - -#define CONDITION_INITIALIZER { 0, QUEUE_INITIALIZER, 0 } - -#define condition_alloc() ((condition_t) calloc(1, sizeof(struct condition))) -#define condition_init(c) MACRO_BEGIN (c)->lock = 0; cthread_queue_init(&(c)->queue); MACRO_END -#define condition_set_name(c, x) ((c)->name = (x)) -#define condition_name(c) ((c)->name != 0 ? (c)->name : "?") -#define condition_clear(c) MACRO_BEGIN condition_broadcast(c); spin_lock(&(c)->lock); MACRO_END -#define condition_free(c) MACRO_BEGIN condition_clear(c); free((any_t) (c)); MACRO_END - -#define condition_signal(c) \ - MACRO_BEGIN \ - if ((c)->queue.head) cond_signal(c); \ - MACRO_END - -#define condition_broadcast(c) \ - MACRO_BEGIN \ - if ((c)->queue.head) cond_broadcast(c); \ - MACRO_END - -__DECLBEGIN -extern void cond_signal(condition_t c); -extern void cond_broadcast(condition_t c); -extern void condition_wait(condition_t c, mutex_t m); -__DECLEND - -/* - * Threads. - */ - -typedef any_t (*cthread_fn_t)(any_t arg); - -#import - -typedef struct cthread { - struct cthread *next; - thread_port_t real_thread; - struct mutex lock; - struct condition done; - int state; -#if defined(__cplusplus) - jmp_buf catchBuf; -#else - jmp_buf catch; -#endif - cthread_fn_t func; - any_t arg; - any_t result; - const char *name; - any_t data; -} *cthread_t; - -#define NO_CTHREAD ((cthread_t) 0) - -__DECLBEGIN -extern cthread_t cthread_fork(cthread_fn_t func, any_t arg); -extern void cthread_detach(cthread_t t); -extern any_t cthread_join(cthread_t t); -extern void cthread_yield(void); -extern void cthread_exit(any_t result); -extern kern_return_t cthread_priority( - cthread_t t, - int priority, - boolean_t set_max); -extern kern_return_t cthread_max_priority( - cthread_t t, - mach_port_t pset, - int max_priority); -extern kern_return_t cthread_abort(cthread_t t); -__DECLEND - -/* - * This structure must agree with struct cproc in cthread_internals.h - */ -typedef struct ur_cthread { - struct ur_cthread *next; - cthread_t incarnation; -} *ur_cthread_t; - -__DECLBEGIN -extern int cthread_sp(void); - -extern int cthread_stack_mask; - -extern ur_cthread_t ur_cthread_self(void); -#define cthread_thread(c) (c->real_thread) -extern void cthread_set_errno_self(int e); -extern int cthread_errno(void); -#define cthread_assoc(id, t) (((ur_cthread_t) (id))->incarnation = (t)) -#define cthread_self() (ur_cthread_self()->incarnation) - -extern void cthread_set_name(cthread_t t, const char *name); -extern const char *cthread_name(cthread_t t); -extern int cthread_count(void); -extern void cthread_set_limit(int n); -extern int cthread_limit(void); -__DECLEND - -#define cthread_set_data(t, x) ((t)->data = (x)) -#define cthread_data(t) ((t)->data) - -/* - * Spin locks. - */ -#define spin_unlock(p) (*(p) = 0) - -/* - * Mutex locks. - */ -#define mutex_unlock(m) ((m)->lock = 0) - - -/* - * Debugging support. - */ -#ifdef CTHREADS_DEBUG - -#ifndef ASSERT -/* - * Assertion macro, similar to - */ -#import -#define ASSERT(p) \ - MACRO_BEGIN \ - if (!(p)) { \ - fprintf(stderr, \ - "File %s, line %d: assertion p failed.\n", \ - __FILE__, __LINE__); \ - abort(); \ - } \ - MACRO_END - -#endif /* ASSERT */ - -#define SHOULDNT_HAPPEN 0 - -extern int cthread_debug; - -#else /* CTHREADS_DEBUG */ - -#ifndef ASSERT -#define ASSERT(p) -#endif /* ASSERT */ - -#endif /* CTHREADS_DEBUG */ - -#endif /* _CTHREADS_ */ diff --git a/threads.subproj/i386.subproj/Makefile b/threads.subproj/i386.subproj/Makefile deleted file mode 100644 index 9a10ba3..0000000 --- a/threads.subproj/i386.subproj/Makefile +++ /dev/null @@ -1,45 +0,0 @@ -# -# Generated by the NeXT Project Builder. -# -# NOTE: Do NOT change this file -- Project Builder maintains it. -# -# Put all of your customizations in files called Makefile.preamble -# and Makefile.postamble (both optional), and Makefile will include them. -# - -NAME = i386 - -PROJECTVERSION = 2.8 -PROJECT_TYPE = Component - -CFILES = thread.c - -OTHERSRCS = Makefile.preamble Makefile Makefile.postamble - - -MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles -CODE_GEN_STYLE = DYNAMIC -MAKEFILE = subproj.make -LIBS = -DEBUG_LIBS = $(LIBS) -PROF_LIBS = $(LIBS) - - - - -NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc -WINDOWS_OBJCPLUS_COMPILER = $(DEVDIR)/gcc -PDO_UNIX_OBJCPLUS_COMPILER = $(NEXTDEV_BIN)/gcc -NEXTSTEP_JAVA_COMPILER = /usr/bin/javac -WINDOWS_JAVA_COMPILER = $(JDKBINDIR)/javac.exe -PDO_UNIX_JAVA_COMPILER = $(JDKBINDIR)/javac - -include $(MAKEFILEDIR)/platform.make - --include Makefile.preamble - -include $(MAKEFILEDIR)/$(MAKEFILE) - --include Makefile.postamble - --include Makefile.dependencies diff --git a/threads.subproj/i386.subproj/Makefile.postamble b/threads.subproj/i386.subproj/Makefile.postamble deleted file mode 100644 index 411cde6..0000000 --- a/threads.subproj/i386.subproj/Makefile.postamble +++ /dev/null @@ -1,100 +0,0 @@ -############################################################################### -# Makefile.postamble -# Copyright 1997, Apple Computer, Inc. -# -# Use this makefile, which is imported after all other makefiles, to -# override attributes for a project's Makefile environment. This allows you -# to take advantage of the environment set up by the other Makefiles. -# You can also define custom rules at the end of this file. -# -############################################################################### -# -# These variables are exported by the standard makefiles and can be -# used in any customizations you make. They are *outputs* of -# the Makefiles and should be used, not set. -# -# PRODUCTS: products to install. All of these products will be placed in -# the directory $(DSTROOT)$(INSTALLDIR) -# GLOBAL_RESOURCE_DIR: The directory to which resources are copied. -# LOCAL_RESOURCE_DIR: The directory to which localized resources are copied. -# OFILE_DIR: Directory into which .o object files are generated. -# DERIVED_SRC_DIR: Directory used for all other derived files -# -# ALL_CFLAGS: flags to pass when compiling .c files -# ALL_MFLAGS: flags to pass when compiling .m files -# ALL_CCFLAGS: flags to pass when compiling .cc, .cxx, and .C files -# ALL_MMFLAGS: flags to pass when compiling .mm, .mxx, and .M files -# ALL_PRECOMPFLAGS: flags to pass when precompiling .h files -# ALL_LDFLAGS: flags to pass when linking object files -# ALL_LIBTOOL_FLAGS: flags to pass when libtooling object files -# ALL_PSWFLAGS: flags to pass when processing .psw and .pswm (pswrap) files -# ALL_RPCFLAGS: flags to pass when processing .rpc (rpcgen) files -# ALL_YFLAGS: flags to pass when processing .y (yacc) files -# ALL_LFLAGS: flags to pass when processing .l (lex) files -# -# NAME: name of application, bundle, subproject, palette, etc. -# LANGUAGES: langages in which the project is written (default "English") -# English_RESOURCES: localized resources (e.g. nib's, images) of project -# GLOBAL_RESOURCES: non-localized resources of project -# -# SRCROOT: base directory in which to place the new source files -# SRCPATH: relative path from SRCROOT to present subdirectory -# -# INSTALLDIR: Directory the product will be installed into by 'install' target -# PUBLIC_HDR_INSTALLDIR: where to install public headers. Don't forget -# to prefix this with DSTROOT when you use it. -# PRIVATE_HDR_INSTALLDIR: where to install private headers. Don't forget -# to prefix this with DSTROOT when you use it. -# -# EXECUTABLE_EXT: Executable extension for the platform (i.e. .exe on Windows) -# -############################################################################### - -# Some compiler flags can be overridden here for certain build situations. -# -# WARNING_CFLAGS: flag used to set warning level (defaults to -Wmost) -# DEBUG_SYMBOLS_CFLAGS: debug-symbol flag passed to all builds (defaults -# to -g) -# DEBUG_BUILD_CFLAGS: flags passed during debug builds (defaults to -DDEBUG) -# OPTIMIZE_BUILD_CFLAGS: flags passed during optimized builds (defaults -# to -O) -# PROFILE_BUILD_CFLAGS: flags passed during profile builds (defaults -# to -pg -DPROFILE) -# LOCAL_DIR_INCLUDE_DIRECTIVE: flag used to add current directory to -# the include path (defaults to -I.) -# DEBUG_BUILD_LDFLAGS, OPTIMIZE_BUILD_LDFLAGS, PROFILE_BUILD_LDFLAGS: flags -# passed to ld/libtool (defaults to nothing) - - -# Library and Framework projects only: -# INSTALL_NAME_DIRECTIVE: This directive ensures that executables linked -# against the framework will run against the correct version even if -# the current version of the framework changes. You may override this -# to "" as an alternative to using the DYLD_LIBRARY_PATH during your -# development cycle, but be sure to restore it before installing. - - -# Ownership and permissions of files installed by 'install' target - -#INSTALL_AS_USER = root - # User/group ownership -#INSTALL_AS_GROUP = wheel - # (probably want to set both of these) -#INSTALL_PERMISSIONS = - # If set, 'install' chmod's executable to this - - -# Options to strip. Note: -S strips debugging symbols (executables can be stripped -# down further with -x or, if they load no bundles, with no options at all). - -#STRIPFLAGS = -S - - -######################################################################### -# Put rules to extend the behavior of the standard Makefiles here. Include them in -# the dependency tree via cvariables like AFTER_INSTALL in the Makefile.preamble. -# -# You should avoid redefining things like "install" or "app", as they are -# owned by the top-level Makefile API and no context has been set up for where -# derived files should go. -# diff --git a/threads.subproj/i386.subproj/Makefile.preamble b/threads.subproj/i386.subproj/Makefile.preamble deleted file mode 100644 index 6544e5f..0000000 --- a/threads.subproj/i386.subproj/Makefile.preamble +++ /dev/null @@ -1,137 +0,0 @@ -############################################################################### -# Makefile.preamble -# Copyright 1997, Apple Computer, Inc. -# -# Use this makefile for configuring the standard application makefiles -# associated with ProjectBuilder. It is included before the main makefile. -# In Makefile.preamble you set attributes for a project, so they are available -# to the project's makefiles. In contrast, you typically write additional rules or -# override built-in behavior in the Makefile.postamble. -# -# Each directory in a project tree (main project plus subprojects) should -# have its own Makefile.preamble and Makefile.postamble. -############################################################################### -# -# Before the main makefile is included for this project, you may set: -# -# MAKEFILEDIR: Directory in which to find $(MAKEFILE) -# MAKEFILE: Top level mechanism Makefile (e.g., app.make, bundle.make) - -# Compiler/linker flags added to the defaults: The OTHER_* variables will be -# inherited by all nested sub-projects, but the LOCAL_ versions of the same -# variables will not. Put your -I, -D, -U, and -L flags in ProjectBuilder's -# Build Attributes inspector if at all possible. To override the default flags -# that get passed to ${CC} (e.g. change -O to -O2), see Makefile.postamble. The -# variables below are *inputs* to the build process and distinct from the override -# settings done (less often) in the Makefile.postamble. -# -# OTHER_CFLAGS, LOCAL_CFLAGS: additional flags to pass to the compiler -# Note that $(OTHER_CFLAGS) and $(LOCAL_CFLAGS) are used for .h, ...c, .m, -# .cc, .cxx, .C, and .M files. There is no need to respecify the -# flags in OTHER_MFLAGS, etc. -# OTHER_MFLAGS, LOCAL_MFLAGS: additional flags for .m files -# OTHER_CCFLAGS, LOCAL_CCFLAGS: additional flags for .cc, .cxx, and ...C files -# OTHER_MMFLAGS, LOCAL_MMFLAGS: additional flags for .mm and .M files -# OTHER_PRECOMPFLAGS, LOCAL_PRECOMPFLAGS: additional flags used when -# precompiling header files -# OTHER_LDFLAGS, LOCAL_LDFLAGS: additional flags passed to ld and libtool -# OTHER_PSWFLAGS, LOCAL_PSWFLAGS: additional flags passed to pswrap -# OTHER_RPCFLAGS, LOCAL_RPCFLAGS: additional flags passed to rpcgen -# OTHER_YFLAGS, LOCAL_YFLAGS: additional flags passed to yacc -# OTHER_LFLAGS, LOCAL_LFLAGS: additional flags passed to lex - -# These variables provide hooks enabling you to add behavior at almost every -# stage of the make: -# -# BEFORE_PREBUILD: targets to build before installing headers for a subproject -# AFTER_PREBUILD: targets to build after installing headers for a subproject -# BEFORE_BUILD_RECURSION: targets to make before building subprojects -# BEFORE_BUILD: targets to make before a build, but after subprojects -# AFTER_BUILD: targets to make after a build -# -# BEFORE_INSTALL: targets to build before installing the product -# AFTER_INSTALL: targets to build after installing the product -# BEFORE_POSTINSTALL: targets to build before postinstalling every subproject -# AFTER_POSTINSTALL: targts to build after postinstalling every subproject -# -# BEFORE_INSTALLHDRS: targets to build before installing headers for a -# subproject -# AFTER_INSTALLHDRS: targets to build after installing headers for a subproject -# BEFORE_INSTALLSRC: targets to build before installing source for a subproject -# AFTER_INSTALLSRC: targets to build after installing source for a subproject -# -# BEFORE_DEPEND: targets to build before building dependencies for a -# subproject -# AFTER_DEPEND: targets to build after building dependencies for a -# subproject -# -# AUTOMATIC_DEPENDENCY_INFO: if YES, then the dependency file is -# updated every time the project is built. If NO, the dependency -# file is only built when the depend target is invoked. - -# Framework-related variables: -# FRAMEWORK_DLL_INSTALLDIR: On Windows platforms, this variable indicates -# where to put the framework's DLL. This variable defaults to -# $(INSTALLDIR)/../Executables - -# Library-related variables: -# PUBLIC_HEADER_DIR: Determines where public exported header files -# should be installed. Do not include $(DSTROOT) in this value -- -# it is prefixed automatically. For library projects you should -# set this to something like /Developer/Headers/$(NAME). Do not set -# this variable for framework projects unless you do not want the -# header files included in the framework. -# PRIVATE_HEADER_DIR: Determines where private exported header files -# should be installed. Do not include $(DSTROOT) in this value -- -# it is prefixed automatically. -# LIBRARY_STYLE: This may be either STATIC or DYNAMIC, and determines -# whether the libraries produced are statically linked when they -# are used or if they are dynamically loadable. This defaults to -# DYNAMIC. -# LIBRARY_DLL_INSTALLDIR: On Windows platforms, this variable indicates -# where to put the library's DLL. This variable defaults to -# $(INSTALLDIR)/../Executables -# -# INSTALL_AS_USER: owner of the intalled products (default root) -# INSTALL_AS_GROUP: group of the installed products (default wheel) -# INSTALL_PERMISSIONS: permissions of the installed product (default o+rX) -# -# OTHER_RECURSIVE_VARIABLES: The names of variables which you want to be -# passed on the command line to recursive invocations of make. Note that -# the values in OTHER_*FLAGS are inherited by subprojects automatically -- -# you do not have to (and shouldn't) add OTHER_*FLAGS to -# OTHER_RECURSIVE_VARIABLES. - -# Additional headers to export beyond those in the PB.project: -# OTHER_PUBLIC_HEADERS -# OTHER_PROJECT_HEADERS -# OTHER_PRIVATE_HEADERS - -# Additional files for the project's product: <> -# OTHER_RESOURCES: (non-localized) resources for this project -# OTHER_OFILES: relocatables to be linked into this project -# OTHER_LIBS: more libraries to link against -# OTHER_PRODUCT_DEPENDS: other dependencies of this project -# OTHER_SOURCEFILES: other source files maintained by .pre/postamble -# OTHER_GARBAGE: additional files to be removed by `make clean' - -# Set this to YES if you don't want a final libtool call for a library/framework. -# BUILD_OFILES_LIST_ONLY - -# To include a version string, project source must exist in a directory named -# $(NAME).%d[.%d][.%d] and the following line must be uncommented. -# OTHER_GENERATED_OFILES = $(VERS_OFILE) - -# This definition will suppress stripping of debug symbols when an executable -# is installed. By default it is YES. -# STRIP_ON_INSTALL = NO - -# Uncomment to suppress generation of a KeyValueCoding index when installing -# frameworks (This index is used by WOB and IB to determine keys available -# for an object). Set to YES by default. -# PREINDEX_FRAMEWORK = NO - -# Change this definition to install projects somewhere other than the -# standard locations. NEXT_ROOT defaults to "C:/Apple" on Windows systems -# and "" on other systems. -INCLUDED_ARCHS = i386 diff --git a/threads.subproj/i386.subproj/PB.project b/threads.subproj/i386.subproj/PB.project deleted file mode 100644 index a77b649..0000000 --- a/threads.subproj/i386.subproj/PB.project +++ /dev/null @@ -1,23 +0,0 @@ -{ - DYNAMIC_CODE_GEN = YES; - FILESTABLE = { - H_FILES = (); - OTHER_LINKED = (thread.c); - OTHER_SOURCES = (Makefile.preamble, Makefile, Makefile.postamble); - SUBPROJECTS = (); - }; - LANGUAGE = English; - MAKEFILEDIR = "$(MAKEFILEPATH)/pb_makefiles"; - NEXTSTEP_BUILDTOOL = /bin/gnumake; - NEXTSTEP_JAVA_COMPILER = /usr/bin/javac; - NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc; - PDO_UNIX_BUILDTOOL = $NEXT_ROOT/Developer/bin/make; - PDO_UNIX_JAVA_COMPILER = "$(JDKBINDIR)/javac"; - PDO_UNIX_OBJCPLUS_COMPILER = "$(NEXTDEV_BIN)/gcc"; - PROJECTNAME = i386; - PROJECTTYPE = Component; - PROJECTVERSION = 2.8; - WINDOWS_BUILDTOOL = $NEXT_ROOT/Developer/Executables/make; - WINDOWS_JAVA_COMPILER = "$(JDKBINDIR)/javac.exe"; - WINDOWS_OBJCPLUS_COMPILER = "$(DEVDIR)/gcc"; -} diff --git a/threads.subproj/i386.subproj/thread.c b/threads.subproj/i386.subproj/thread.c deleted file mode 100644 index 64595c3..0000000 --- a/threads.subproj/i386.subproj/thread.c +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Mach Operating System - * Copyright (c) 1989 Carnegie-Mellon University - * All rights reserved. The CMU software License Agreement specifies - * the terms and conditions for use and redistribution. - */ - -/* - * 386/thread.c - * - * Cproc startup for 386 MTHREAD implementation. - */ - -#include -#include -#include -#include "cthread_internals.h" - -void -_pthread_set_self(p) - cproc_t p; -{ - asm("pushl %0" : : "m" (p)); - asm("pushl $0"); // fake the kernel out - asm("movl $1, %%eax" : : : "ax"); - asm("lcall $0x3b, $0"); -} - -void * -pthread_self() -{ - asm("movl $0, %eax"); - asm("lcall $0x3b, $0"); -} diff --git a/threads.subproj/lu_utils.c b/threads.subproj/lu_utils.c deleted file mode 100644 index 65a60a4..0000000 --- a/threads.subproj/lu_utils.c +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Port and memory management for doing lookups to the lookup server - * Copyright (C) 1989 by NeXT, Inc. - */ -/* - * HISTORY - * 27-Mar-90 Gregg Kellogg (gk) at NeXT - * Changed to use bootstrap port instead of service port. - * - */ -#include -#include -#include - -mach_port_t _lu_port = MACH_PORT_NULL; -static name_t LOOKUP_NAME = "lookup daemon"; - -mach_port_t _lookupd_port(mach_port_t port) { - 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); - if (ret != BOOTSTRAP_SUCCESS) { - mach_error("bootstrap_register() failed", ret); - abort(); - } - return port; - } - return _lu_port; -} - -/* called as child starts up. mach ports aren't inherited: trash cache */ -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_setport(mach_port_t desired) -{ - if (_lu_port != MACH_PORT_NULL) { - mach_port_deallocate(mach_task_self(), _lu_port); - } - _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; -} - diff --git a/threads.subproj/mig_support.c b/threads.subproj/mig_support.c deleted file mode 100644 index 1cf0f63..0000000 --- a/threads.subproj/mig_support.c +++ /dev/null @@ -1,171 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Mach Operating System - * Copyright (c) 1989 Carnegie-Mellon University - * All rights reserved. The CMU software License Agreement specifies - * the terms and conditions for use and redistribution. - */ -/* - * mig_support.c - by Mary Thompson - * - * Routines to set and deallocate the mig reply port for the current thread. - * Called from mig-generated interfaces. - */ -#include -#include -#include - -#include "cthreads.h" -#include "cthread_internals.h" - -pthread_lock_t reply_port_lock; -extern mach_port_t _pthread_reply_port(pthread_t); -static mach_port_t _task_reply_port = MACH_PORT_NULL; - -/* - * called in new child... - * clear lock to cover case where the parent had - * a thread holding this lock while another thread - * did the fork() - */ -void mig_fork_child() -{ - UNLOCK(reply_port_lock); -} - -/* - * Called by mach_init with 0 before cthread_init is - * called and again with 1 at the end of cthread_init. - */ -void -mig_init(init_done) - int init_done; -{ - if (init_done == 0) { - LOCK_INIT(reply_port_lock); - _task_reply_port = mach_reply_port(); - } -} - -/* - * Called by mig interface code whenever a reply port is needed. - * Tracing is masked during this call; otherwise, a call to printf() - * can result in a call to malloc() which eventually reenters - * mig_get_reply_port() and deadlocks. - */ -mach_port_t -mig_get_reply_port() -{ - register cproc_t self; - pthread_t pself; -#ifdef CTHREADS_DEBUG - int d = cthread_debug; -#endif CTHREADS_DEBUG - -#ifdef CTHREADS_DEBUG - cthread_debug = FALSE; -#endif CTHREADS_DEBUG - pself = pthread_self(); - if ((pself != (pthread_t)NULL) && (pself->sig == _PTHREAD_SIG)) { - if (pself->reply_port == MACH_PORT_NULL) { - pself->reply_port = mach_reply_port(); - } - return pself->reply_port; - } - self = cproc_self(); - if (self == NO_CPROC) { -#ifdef CTHREADS_DEBUG - cthread_debug = d; -#endif CTHREADS_DEBUG - return(_task_reply_port); - } - if (self->reply_port == MACH_PORT_NULL) { - self->reply_port = mach_reply_port(); - } -#ifdef CTHREADS_DEBUG - cthread_debug = d; -#endif CTHREADS_DEBUG - return self->reply_port; -} - -/* - * Called by mig interface code after a timeout on the reply port. - * May also be called by user. The new mig calls with port passed in - * We are ignoring this , so is osfmk cthreads code - */ -void -mig_dealloc_reply_port(mach_port_t migport) -{ - register cproc_t self; - pthread_t pself; - register mach_port_t port; -#ifdef CTHREADS_DEBUG - int d = cthread_debug; -#endif CTHREADS_DEBUG - -#ifdef CTHREADS_DEBUG - cthread_debug = FALSE; -#endif CTHREADS_DEBUG - pself = pthread_self(); - if ((pself != (pthread_t)NULL) && (pself->sig == _PTHREAD_SIG)) { - port = pself->reply_port; - if (port != MACH_PORT_NULL && port != _task_reply_port) { - LOCK(reply_port_lock); - pself->reply_port = _task_reply_port; - (void) mach_port_destroy(mach_task_self(), port); - pself->reply_port = MACH_PORT_NULL; - UNLOCK(reply_port_lock); - } - return; - } - self = cproc_self(); - if (self == NO_CPROC) { -#ifdef CTHREADS_DEBUG - cthread_debug = d; -#endif CTHREADS_DEBUG - return; - } - ASSERT(self != NO_CPROC); - port = self->reply_port; - if (port != MACH_PORT_NULL && port != _task_reply_port) { - LOCK(reply_port_lock); - self->reply_port = _task_reply_port; - (void) mach_port_destroy(mach_task_self(), port); - self->reply_port = MACH_PORT_NULL; - UNLOCK(reply_port_lock); - } -#ifdef CTHREADS_DEBUG - cthread_debug = d; -#endif CTHREADS_DEBUG -} - -/************************************************************* - * Called by mig interfaces after each RPC. - * Could be called by user. - ***********************************************************/ - -void -mig_put_reply_port( - mach_port_t reply_port) -{ -} diff --git a/threads.subproj/ppc.subproj/Makefile b/threads.subproj/ppc.subproj/Makefile deleted file mode 100644 index 62e6941..0000000 --- a/threads.subproj/ppc.subproj/Makefile +++ /dev/null @@ -1,43 +0,0 @@ -# -# Generated by the NeXT Project Builder. -# -# NOTE: Do NOT change this file -- Project Builder maintains it. -# -# Put all of your customizations in files called Makefile.preamble -# and Makefile.postamble (both optional), and Makefile will include them. -# - -NAME = ppc - -PROJECTVERSION = 2.8 -PROJECT_TYPE = Component - -OTHERSRCS = Makefile.preamble Makefile Makefile.postamble - - -MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles -CODE_GEN_STYLE = DYNAMIC -MAKEFILE = subproj.make -LIBS = -DEBUG_LIBS = $(LIBS) -PROF_LIBS = $(LIBS) - - - - -NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc -WINDOWS_OBJCPLUS_COMPILER = $(DEVDIR)/gcc -PDO_UNIX_OBJCPLUS_COMPILER = $(NEXTDEV_BIN)/gcc -NEXTSTEP_JAVA_COMPILER = /usr/bin/javac -WINDOWS_JAVA_COMPILER = $(JDKBINDIR)/javac.exe -PDO_UNIX_JAVA_COMPILER = $(JDKBINDIR)/javac - -include $(MAKEFILEDIR)/platform.make - --include Makefile.preamble - -include $(MAKEFILEDIR)/$(MAKEFILE) - --include Makefile.postamble - --include Makefile.dependencies diff --git a/threads.subproj/ppc.subproj/Makefile.postamble b/threads.subproj/ppc.subproj/Makefile.postamble deleted file mode 100644 index 411cde6..0000000 --- a/threads.subproj/ppc.subproj/Makefile.postamble +++ /dev/null @@ -1,100 +0,0 @@ -############################################################################### -# Makefile.postamble -# Copyright 1997, Apple Computer, Inc. -# -# Use this makefile, which is imported after all other makefiles, to -# override attributes for a project's Makefile environment. This allows you -# to take advantage of the environment set up by the other Makefiles. -# You can also define custom rules at the end of this file. -# -############################################################################### -# -# These variables are exported by the standard makefiles and can be -# used in any customizations you make. They are *outputs* of -# the Makefiles and should be used, not set. -# -# PRODUCTS: products to install. All of these products will be placed in -# the directory $(DSTROOT)$(INSTALLDIR) -# GLOBAL_RESOURCE_DIR: The directory to which resources are copied. -# LOCAL_RESOURCE_DIR: The directory to which localized resources are copied. -# OFILE_DIR: Directory into which .o object files are generated. -# DERIVED_SRC_DIR: Directory used for all other derived files -# -# ALL_CFLAGS: flags to pass when compiling .c files -# ALL_MFLAGS: flags to pass when compiling .m files -# ALL_CCFLAGS: flags to pass when compiling .cc, .cxx, and .C files -# ALL_MMFLAGS: flags to pass when compiling .mm, .mxx, and .M files -# ALL_PRECOMPFLAGS: flags to pass when precompiling .h files -# ALL_LDFLAGS: flags to pass when linking object files -# ALL_LIBTOOL_FLAGS: flags to pass when libtooling object files -# ALL_PSWFLAGS: flags to pass when processing .psw and .pswm (pswrap) files -# ALL_RPCFLAGS: flags to pass when processing .rpc (rpcgen) files -# ALL_YFLAGS: flags to pass when processing .y (yacc) files -# ALL_LFLAGS: flags to pass when processing .l (lex) files -# -# NAME: name of application, bundle, subproject, palette, etc. -# LANGUAGES: langages in which the project is written (default "English") -# English_RESOURCES: localized resources (e.g. nib's, images) of project -# GLOBAL_RESOURCES: non-localized resources of project -# -# SRCROOT: base directory in which to place the new source files -# SRCPATH: relative path from SRCROOT to present subdirectory -# -# INSTALLDIR: Directory the product will be installed into by 'install' target -# PUBLIC_HDR_INSTALLDIR: where to install public headers. Don't forget -# to prefix this with DSTROOT when you use it. -# PRIVATE_HDR_INSTALLDIR: where to install private headers. Don't forget -# to prefix this with DSTROOT when you use it. -# -# EXECUTABLE_EXT: Executable extension for the platform (i.e. .exe on Windows) -# -############################################################################### - -# Some compiler flags can be overridden here for certain build situations. -# -# WARNING_CFLAGS: flag used to set warning level (defaults to -Wmost) -# DEBUG_SYMBOLS_CFLAGS: debug-symbol flag passed to all builds (defaults -# to -g) -# DEBUG_BUILD_CFLAGS: flags passed during debug builds (defaults to -DDEBUG) -# OPTIMIZE_BUILD_CFLAGS: flags passed during optimized builds (defaults -# to -O) -# PROFILE_BUILD_CFLAGS: flags passed during profile builds (defaults -# to -pg -DPROFILE) -# LOCAL_DIR_INCLUDE_DIRECTIVE: flag used to add current directory to -# the include path (defaults to -I.) -# DEBUG_BUILD_LDFLAGS, OPTIMIZE_BUILD_LDFLAGS, PROFILE_BUILD_LDFLAGS: flags -# passed to ld/libtool (defaults to nothing) - - -# Library and Framework projects only: -# INSTALL_NAME_DIRECTIVE: This directive ensures that executables linked -# against the framework will run against the correct version even if -# the current version of the framework changes. You may override this -# to "" as an alternative to using the DYLD_LIBRARY_PATH during your -# development cycle, but be sure to restore it before installing. - - -# Ownership and permissions of files installed by 'install' target - -#INSTALL_AS_USER = root - # User/group ownership -#INSTALL_AS_GROUP = wheel - # (probably want to set both of these) -#INSTALL_PERMISSIONS = - # If set, 'install' chmod's executable to this - - -# Options to strip. Note: -S strips debugging symbols (executables can be stripped -# down further with -x or, if they load no bundles, with no options at all). - -#STRIPFLAGS = -S - - -######################################################################### -# Put rules to extend the behavior of the standard Makefiles here. Include them in -# the dependency tree via cvariables like AFTER_INSTALL in the Makefile.preamble. -# -# You should avoid redefining things like "install" or "app", as they are -# owned by the top-level Makefile API and no context has been set up for where -# derived files should go. -# diff --git a/threads.subproj/ppc.subproj/Makefile.preamble b/threads.subproj/ppc.subproj/Makefile.preamble deleted file mode 100644 index 7211b2b..0000000 --- a/threads.subproj/ppc.subproj/Makefile.preamble +++ /dev/null @@ -1,137 +0,0 @@ -############################################################################### -# Makefile.preamble -# Copyright 1997, Apple Computer, Inc. -# -# Use this makefile for configuring the standard application makefiles -# associated with ProjectBuilder. It is included before the main makefile. -# In Makefile.preamble you set attributes for a project, so they are available -# to the project's makefiles. In contrast, you typically write additional rules or -# override built-in behavior in the Makefile.postamble. -# -# Each directory in a project tree (main project plus subprojects) should -# have its own Makefile.preamble and Makefile.postamble. -############################################################################### -# -# Before the main makefile is included for this project, you may set: -# -# MAKEFILEDIR: Directory in which to find $(MAKEFILE) -# MAKEFILE: Top level mechanism Makefile (e.g., app.make, bundle.make) - -# Compiler/linker flags added to the defaults: The OTHER_* variables will be -# inherited by all nested sub-projects, but the LOCAL_ versions of the same -# variables will not. Put your -I, -D, -U, and -L flags in ProjectBuilder's -# Build Attributes inspector if at all possible. To override the default flags -# that get passed to ${CC} (e.g. change -O to -O2), see Makefile.postamble. The -# variables below are *inputs* to the build process and distinct from the override -# settings done (less often) in the Makefile.postamble. -# -# OTHER_CFLAGS, LOCAL_CFLAGS: additional flags to pass to the compiler -# Note that $(OTHER_CFLAGS) and $(LOCAL_CFLAGS) are used for .h, ...c, .m, -# .cc, .cxx, .C, and .M files. There is no need to respecify the -# flags in OTHER_MFLAGS, etc. -# OTHER_MFLAGS, LOCAL_MFLAGS: additional flags for .m files -# OTHER_CCFLAGS, LOCAL_CCFLAGS: additional flags for .cc, .cxx, and ...C files -# OTHER_MMFLAGS, LOCAL_MMFLAGS: additional flags for .mm and .M files -# OTHER_PRECOMPFLAGS, LOCAL_PRECOMPFLAGS: additional flags used when -# precompiling header files -# OTHER_LDFLAGS, LOCAL_LDFLAGS: additional flags passed to ld and libtool -# OTHER_PSWFLAGS, LOCAL_PSWFLAGS: additional flags passed to pswrap -# OTHER_RPCFLAGS, LOCAL_RPCFLAGS: additional flags passed to rpcgen -# OTHER_YFLAGS, LOCAL_YFLAGS: additional flags passed to yacc -# OTHER_LFLAGS, LOCAL_LFLAGS: additional flags passed to lex - -# These variables provide hooks enabling you to add behavior at almost every -# stage of the make: -# -# BEFORE_PREBUILD: targets to build before installing headers for a subproject -# AFTER_PREBUILD: targets to build after installing headers for a subproject -# BEFORE_BUILD_RECURSION: targets to make before building subprojects -# BEFORE_BUILD: targets to make before a build, but after subprojects -# AFTER_BUILD: targets to make after a build -# -# BEFORE_INSTALL: targets to build before installing the product -# AFTER_INSTALL: targets to build after installing the product -# BEFORE_POSTINSTALL: targets to build before postinstalling every subproject -# AFTER_POSTINSTALL: targts to build after postinstalling every subproject -# -# BEFORE_INSTALLHDRS: targets to build before installing headers for a -# subproject -# AFTER_INSTALLHDRS: targets to build after installing headers for a subproject -# BEFORE_INSTALLSRC: targets to build before installing source for a subproject -# AFTER_INSTALLSRC: targets to build after installing source for a subproject -# -# BEFORE_DEPEND: targets to build before building dependencies for a -# subproject -# AFTER_DEPEND: targets to build after building dependencies for a -# subproject -# -# AUTOMATIC_DEPENDENCY_INFO: if YES, then the dependency file is -# updated every time the project is built. If NO, the dependency -# file is only built when the depend target is invoked. - -# Framework-related variables: -# FRAMEWORK_DLL_INSTALLDIR: On Windows platforms, this variable indicates -# where to put the framework's DLL. This variable defaults to -# $(INSTALLDIR)/../Executables - -# Library-related variables: -# PUBLIC_HEADER_DIR: Determines where public exported header files -# should be installed. Do not include $(DSTROOT) in this value -- -# it is prefixed automatically. For library projects you should -# set this to something like /Developer/Headers/$(NAME). Do not set -# this variable for framework projects unless you do not want the -# header files included in the framework. -# PRIVATE_HEADER_DIR: Determines where private exported header files -# should be installed. Do not include $(DSTROOT) in this value -- -# it is prefixed automatically. -# LIBRARY_STYLE: This may be either STATIC or DYNAMIC, and determines -# whether the libraries produced are statically linked when they -# are used or if they are dynamically loadable. This defaults to -# DYNAMIC. -# LIBRARY_DLL_INSTALLDIR: On Windows platforms, this variable indicates -# where to put the library's DLL. This variable defaults to -# $(INSTALLDIR)/../Executables -# -# INSTALL_AS_USER: owner of the intalled products (default root) -# INSTALL_AS_GROUP: group of the installed products (default wheel) -# INSTALL_PERMISSIONS: permissions of the installed product (default o+rX) -# -# OTHER_RECURSIVE_VARIABLES: The names of variables which you want to be -# passed on the command line to recursive invocations of make. Note that -# the values in OTHER_*FLAGS are inherited by subprojects automatically -- -# you do not have to (and shouldn't) add OTHER_*FLAGS to -# OTHER_RECURSIVE_VARIABLES. - -# Additional headers to export beyond those in the PB.project: -# OTHER_PUBLIC_HEADERS -# OTHER_PROJECT_HEADERS -# OTHER_PRIVATE_HEADERS - -# Additional files for the project's product: <> -# OTHER_RESOURCES: (non-localized) resources for this project -# OTHER_OFILES: relocatables to be linked into this project -# OTHER_LIBS: more libraries to link against -# OTHER_PRODUCT_DEPENDS: other dependencies of this project -# OTHER_SOURCEFILES: other source files maintained by .pre/postamble -# OTHER_GARBAGE: additional files to be removed by `make clean' - -# Set this to YES if you don't want a final libtool call for a library/framework. -# BUILD_OFILES_LIST_ONLY - -# To include a version string, project source must exist in a directory named -# $(NAME).%d[.%d][.%d] and the following line must be uncommented. -# OTHER_GENERATED_OFILES = $(VERS_OFILE) - -# This definition will suppress stripping of debug symbols when an executable -# is installed. By default it is YES. -# STRIP_ON_INSTALL = NO - -# Uncomment to suppress generation of a KeyValueCoding index when installing -# frameworks (This index is used by WOB and IB to determine keys available -# for an object). Set to YES by default. -# PREINDEX_FRAMEWORK = NO - -# Change this definition to install projects somewhere other than the -# standard locations. NEXT_ROOT defaults to "C:/Apple" on Windows systems -# and "" on other systems. -INCLUDED_ARCHS = ppc diff --git a/threads.subproj/ppc.subproj/PB.project b/threads.subproj/ppc.subproj/PB.project deleted file mode 100644 index 49e45ce..0000000 --- a/threads.subproj/ppc.subproj/PB.project +++ /dev/null @@ -1,23 +0,0 @@ -{ - DYNAMIC_CODE_GEN = YES; - FILESTABLE = { - H_FILES = (); - OTHER_LINKED = (); - OTHER_SOURCES = (Makefile.preamble, Makefile, Makefile.postamble); - SUBPROJECTS = (); - }; - LANGUAGE = English; - MAKEFILEDIR = "$(MAKEFILEPATH)/pb_makefiles"; - NEXTSTEP_BUILDTOOL = /bin/gnumake; - NEXTSTEP_JAVA_COMPILER = /usr/bin/javac; - NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc; - PDO_UNIX_BUILDTOOL = $NEXT_ROOT/Developer/bin/make; - PDO_UNIX_JAVA_COMPILER = "$(JDKBINDIR)/javac"; - PDO_UNIX_OBJCPLUS_COMPILER = "$(NEXTDEV_BIN)/gcc"; - PROJECTNAME = ppc; - PROJECTTYPE = Component; - PROJECTVERSION = 2.8; - WINDOWS_BUILDTOOL = $NEXT_ROOT/Developer/Executables/make; - WINDOWS_JAVA_COMPILER = "$(JDKBINDIR)/javac.exe"; - WINDOWS_OBJCPLUS_COMPILER = "$(DEVDIR)/gcc"; -} diff --git a/threads/Makefile.inc b/threads/Makefile.inc new file mode 100644 index 0000000..0f81896 --- /dev/null +++ b/threads/Makefile.inc @@ -0,0 +1,7 @@ +.PATH: ${.CURDIR}/${MACHINE_ARCH}/threads ${.CURDIR}/threads + +.if exists(${.CURDIR}/${MACHINE_ARCH}/threads/Makefile.inc) +.include "${.CURDIR}/${MACHINE_ARCH}/threads/Makefile.inc" +.endif + +SRCS += cprocs.c cthreads.c lu_utils.c mig_support.c diff --git a/threads/cprocs.c b/threads/cprocs.c new file mode 100644 index 0000000..dfa18a8 --- /dev/null +++ b/threads/cprocs.c @@ -0,0 +1,151 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Mach Operating System + * Copyright (c) 1989 Carnegie-Mellon University + * All rights reserved. The CMU software License Agreement specifies + * the terms and conditions for use and redistribution. + */ + +/* + * HISTORY + * 22-July-93 Blaine Garst + * fixed kernel cache set up of cproc info + * + * 05-April-90 Morris Meyer (mmeyer) at NeXT + * Fixed bug in cproc_fork_child() where the first cproc would + * try doing a msg_rpc() with an invalid reply port. + * + */ + +/* + * cprocs.c - by Eric Cooper + * + * Implementation of cprocs (lightweight processes) + * and primitive synchronization operations. + */ +#include +#include "pthread_internals.h" +#include "cthreads.h" +#include "cthread_internals.h" +#include + +/* + * C Threads imports: + */ +extern void stack_init(); +extern void alloc_stack(), _dealloc_stack(); + +/* + * Mach imports: + */ +extern mach_port_t mach_thread_self(); +extern boolean_t swtch_pri(); + +private int cprocs_started = FALSE; + +#ifdef CTHREADS_DEBUG +private void +print_cproc(p) + cproc_t p; +{ + char *s; + + switch (p->state) { + case CPROC_RUNNING: + s = ""; + break; + case CPROC_SPINNING: + s = "+"; + break; + case CPROC_BLOCKED: + s = "*"; + break; + default: + ASSERT(SHOULDNT_HAPPEN); + } + printf(" %x(%s)%s", + p->id, + cthread_name(p->incarnation), s); +} + +private void +print_cproc_queue(name, queue) + const char * name; + cthread_queue_t queue; +{ + printf("[%s] %s:", cthread_name(cthread_self()), name); + cthread_queue_map(queue, cproc_t, print_cproc); + printf("\n"); +} +#endif CTHREADS_DEBUG + +private int cproc_lock = 0; /* unlocked */ +private cproc_t cprocs = NO_CPROC; /* linked list of cprocs */ + +#ifdef CTHREADS_DEBUG +private void +print_all_cprocs() +{ + cproc_t p; + + printf("[%s] cprocs:", cthread_name(cthread_self())); + for (p = cprocs; p != NO_CPROC; p = p->link) + print_cproc(p); + printf("\n"); +} +#endif CTHREADS_DEBUG + +/* + * Routines for supporting fork() of multi-threaded programs. + */ + +void _cproc_fork_child() +/* + * Called in the child after a fork(). Resets cproc data structures to + * coincide with the reality that we now have a single cproc and cthread. + */ +{ + pthread_t pself; + + pself = pthread_self(); + pself->reply_port = MACH_PORT_NULL; +} + +/* + * Support for a per-thread UNIX errno. + */ + +#undef errno +extern int errno; +void cthread_set_errno_self(error) + int error; +{ + pthread_t t; + + t = pthread_self(); + if (t && (t->sig == _PTHREAD_SIG)) { + t->err_no = error; + } + errno = error; +} + diff --git a/threads/cthread_internals.h b/threads/cthread_internals.h new file mode 100644 index 0000000..901a438 --- /dev/null +++ b/threads/cthread_internals.h @@ -0,0 +1,143 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Mach Operating System + * Copyright (c) 1989 Carnegie-Mellon University + * All rights reserved. The CMU software License Agreement specifies + * the terms and conditions for use and redistribution. + */ + +/* + * HISTORY + * 08-Mar-90 Avadis Tevanian, Jr. (avie) at NeXT + * Added errno field to cproc structure. + * + */ + +/* + * cthread_internals.h - by Eric Cooper + * + * Private definitions for the C Threads implementation. + * + * The cproc structure is used for different implementations + * of the basic schedulable units that execute cthreads. + * + * MTHREAD MACH threads; single address space, + * kernel-mode preemptive scheduling + */ +#include +#include +#include + +/* + * Low-level thread implementation. + * This structure must agree with struct ur_cthread in cthreads.h + */ +typedef struct cproc { + struct cproc *next; /* for lock, condition, and ready queues */ + struct cproc *incarnation; /* for cthread_self() */ + int state; + mach_port_t reply_port; /* for mig_get_reply_port() */ + + mach_port_t wait_port; + + int id; + struct cproc *link; /* so all cprocs can be found + after a fork() */ + int flags; + + unsigned int stack_base; + unsigned int stack_size; + int error; + +} *cproc_t; + +#define NO_CPROC ((cproc_t) 0) +#define cproc_self() ((cproc_t) ur_cthread_self()) +extern void cthread_set_self(cproc_t p); + +/* + * Possible cproc states. + */ +#define CPROC_RUNNING 0 +#define CPROC_SPINNING 1 +#define CPROC_BLOCKED 2 + +/* + * The cproc flag bits. + */ +#define CPROC_INITIAL_STACK 0x1 +#define CPROC_NOCACHE_THREAD /* Don't try to cache this cthread on exit */ + +/* + * C Threads imports: + */ +#ifdef __STRICT_BSD__ +extern char *malloc(); +#endif /* __STRICT_BSD__ */ + +/* + * Mach imports: + */ +extern void mach_error(); + +/* + * C library imports: + */ +#ifdef __STRICT_BSD__ +extern exit(); +#else +#include +#endif /* __STRICT_BSD__ */ + +/* + * Macro for MACH kernel calls. + */ +#ifndef MACH_CALL +#define MACH_CALL(expr, ret) { \ + if (((ret) = (expr)) != KERN_SUCCESS) { \ + mach_error(#expr, (ret)); \ + assert(0); \ + } \ +} +#endif + +/* + * Debugging support. + */ +#ifdef CTHREADS_DEBUG + +#define private +#define TRACE(x) if (cthread_debug) x ; else +extern int cthread_debug; + +/* + * C library imports: + */ +#include +#include +#else /* CTHREADS_DEBUG */ + +#define private static +#define TRACE(x) + +#endif /* DEBUG */ diff --git a/threads/cthreads.c b/threads/cthreads.c new file mode 100644 index 0000000..bad453f --- /dev/null +++ b/threads/cthreads.c @@ -0,0 +1,141 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * cthreads.c - by Eric Cooper + * + * Implementation of cthread_fork, cthread_join, cthread_exit, etc. + * HISTORY + * 22-July-93 Blaine Garst + * fixed association of read_thread info + * fixed kernel cache set up of cproc info + * + */ +#include +#include "cthreads.h" +#include "cthread_internals.h" +#include "pthread_internals.h" +/* + * C Threads imports: + */ +extern void cproc_init(); +extern thread_port_t cproc_create(); +extern void mig_init(); +extern void _pthread_set_self(pthread_t); + +/* + * Mach imports: + */ +extern void mig_fork_child(); + +/* + * C library imports: + */ +extern int _setjmp(jmp_buf env); +extern void _longjmp(jmp_buf env, int val); + +/* + * Thread status bits. + */ +#define T_MAIN 0x1 +#define T_RETURNED 0x2 +#define T_DETACHED 0x4 + +#ifdef CTHREADS_DEBUG +int cthread_debug = FALSE; +#endif CTHREADS_DEBUG + +/* + * Routines for supporting fork() of multi-threaded programs. + */ + + +extern void _malloc_fork_prepare(), _malloc_fork_parent(); +extern void _malloc_fork_child(); +extern void _cproc_fork_child(), _stack_fork_child(); +extern void _lu_fork_child(void); +extern void _pthread_fork_child(void); + +static pthread_t psaved_self = 0; +static pthread_lock_t psaved_self_global_lock = LOCK_INITIALIZER; + +void _cthread_fork_prepare() +/* + * Prepare cthreads library to fork() a multi-threaded program. All cthread + * library critical section locks are acquired before a fork() and released + * afterwards to insure no cthread data structure is left in an inconsistent + * 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); + _malloc_fork_prepare(); +} + +void _cthread_fork_parent() +/* + * Called in the parent process after a fork syscall. + * Releases locks acquired by cthread_fork_prepare(). + */ +{ + _malloc_fork_parent(); + _spin_unlock(&psaved_self->lock); + _spin_unlock(&psaved_self_global_lock); + +} + +void _cthread_fork_child() +/* + * Called in the child process after a fork syscall. Releases locks acquired + * by cthread_fork_prepare(). Deallocates cthread data structures which + * described other threads in our parent. Makes this thread the main thread. + * + * The mach_init() routine must be called in the child before this routine. + */ +{ + pthread_t p = psaved_self; + + _pthread_set_self(p); + _spin_unlock(&psaved_self_global_lock); + mig_fork_child(); + _malloc_fork_child(); + p->kernel_thread = mach_thread_self(); + p->reply_port = MACH_PORT_NULL; + p->mutexes = NULL; + p->cleanup_stack = NULL; + p->death = MACH_PORT_NULL; + p->joiner = NULL; + p->detached |= _PTHREAD_CREATE_PARENT; + _spin_unlock(&p->lock); + + _cproc_fork_child(); + + _lu_fork_child(); + + _pthread_fork_child(); + + __is_threaded = 0; + + mig_init(1); /* enable multi-threaded mig interfaces */ + +} + diff --git a/threads/cthreads.h b/threads/cthreads.h new file mode 100644 index 0000000..6c97927 --- /dev/null +++ b/threads/cthreads.h @@ -0,0 +1,307 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Cthreads. + */ + +#ifndef _CTHREADS_ +#define _CTHREADS_ 1 + +#if defined(__cplusplus) +#define __DECLBEGIN extern "C" { +#define __DECLEND } +#else +#define __DECLBEGIN +#define __DECLEND +#endif + +typedef void *any_t; + +/* + * Spin locks. + */ +__DECLBEGIN +extern void spin_unlock(int *p); +extern void spin_lock(int *p); +__DECLEND + +#include +#include + +#ifndef MACRO_BEGIN + +#define NEVER FALSE + +#define MACRO_BEGIN do { +#define MACRO_END } while (NEVER) + +#endif /* MACRO_BEGIN */ + +/* + * C Threads package initialization. + */ +__DECLBEGIN +extern void cthread_init(); +__DECLEND + +#include + +/* + * Queues. + */ +typedef struct cthread_queue { + struct cthread_queue_item *head; + struct cthread_queue_item *tail; +} *cthread_queue_t; + +typedef struct cthread_queue_item { + struct cthread_queue_item *next; +} *cthread_queue_item_t; + +#define NO_QUEUE_ITEM ((cthread_queue_item_t) 0) + +#define QUEUE_INITIALIZER { NO_QUEUE_ITEM, NO_QUEUE_ITEM } + +#define cthread_queue_alloc() ((cthread_queue_t) calloc(1, sizeof(struct cthread_queue))) +#define cthread_queue_init(q) ((q)->head = (q)->tail = 0) +#define cthread_queue_free(q) free((any_t) (q)) + +#define cthread_queue_enq(q, x) \ + MACRO_BEGIN \ + (x)->next = 0; \ + if ((q)->tail == 0) \ + (q)->head = (cthread_queue_item_t) (x); \ + else \ + (q)->tail->next = (cthread_queue_item_t) (x); \ + (q)->tail = (cthread_queue_item_t) (x); \ + MACRO_END + +#define cthread_queue_preq(q, x) \ + MACRO_BEGIN \ + if ((q)->tail == 0) \ + (q)->tail = (cthread_queue_item_t) (x); \ + ((cthread_queue_item_t) (x))->next = (q)->head; \ + (q)->head = (cthread_queue_item_t) (x); \ + MACRO_END + +#define cthread_queue_head(q, t) ((t) ((q)->head)) + +#define cthread_queue_deq(q, t, x) \ + MACRO_BEGIN \ + if (((x) = (t) ((q)->head)) != 0 && \ + ((q)->head = (cthread_queue_item_t) ((x)->next)) == 0) \ + (q)->tail = 0; \ + MACRO_END + +#define cthread_queue_map(q, t, f) \ + MACRO_BEGIN \ + register cthread_queue_item_t x, next; \ + for (x = (cthread_queue_item_t) ((q)->head); x != 0; x = next) { \ + next = x->next; \ + (*(f))((t) x); \ + } \ + MACRO_END + + +/* + * Mutex objects. + */ +typedef struct mutex { + int lock; + char *name; +} *mutex_t; + +#define MUTEX_INITIALIZER { 0, 0 } + +#define mutex_alloc() ((mutex_t) calloc(1, sizeof(struct mutex))) +#define mutex_init(m) ((m)->lock = 0) +#define mutex_set_name(m, x) ((m)->name = (x)) +#define mutex_name(m) ((m)->name != 0 ? (m)->name : "?") +#define mutex_clear(m) /* nop */ +#define mutex_free(m) free((any_t) (m)) + +#define mutex_lock(m) \ + MACRO_BEGIN \ + if (! mutex_try_lock(m)) mutex_wait_lock(m); \ + MACRO_END + +__DECLBEGIN +extern int mutex_try_lock(mutex_t m); /* nonblocking */ +extern void mutex_wait_lock(mutex_t m); /* blocking */ +extern void mutex_unlock(mutex_t m); +__DECLEND + +/* + * Condition variables. + */ +typedef struct condition { + int lock; + struct cthread_queue queue; + char *name; +} *condition_t; + +#define CONDITION_INITIALIZER { 0, QUEUE_INITIALIZER, 0 } + +#define condition_alloc() ((condition_t) calloc(1, sizeof(struct condition))) +#define condition_init(c) MACRO_BEGIN (c)->lock = 0; cthread_queue_init(&(c)->queue); MACRO_END +#define condition_set_name(c, x) ((c)->name = (x)) +#define condition_name(c) ((c)->name != 0 ? (c)->name : "?") +#define condition_clear(c) MACRO_BEGIN condition_broadcast(c); spin_lock(&(c)->lock); MACRO_END +#define condition_free(c) MACRO_BEGIN condition_clear(c); free((any_t) (c)); MACRO_END + +#define condition_signal(c) \ + MACRO_BEGIN \ + if ((c)->queue.head) cond_signal(c); \ + MACRO_END + +#define condition_broadcast(c) \ + MACRO_BEGIN \ + if ((c)->queue.head) cond_broadcast(c); \ + MACRO_END + +__DECLBEGIN +extern void cond_signal(condition_t c); +extern void cond_broadcast(condition_t c); +extern void condition_wait(condition_t c, mutex_t m); +__DECLEND + +/* + * Threads. + */ + +typedef any_t (*cthread_fn_t)(any_t arg); + +#import + +typedef struct cthread { + struct cthread *next; + thread_port_t real_thread; + struct mutex lock; + struct condition done; + int state; +#if defined(__cplusplus) + jmp_buf catchBuf; +#else + jmp_buf catch; +#endif + cthread_fn_t func; + any_t arg; + any_t result; + const char *name; + any_t data; +} *cthread_t; + +#define NO_CTHREAD ((cthread_t) 0) + +__DECLBEGIN +extern cthread_t cthread_fork(cthread_fn_t func, any_t arg); +extern void cthread_detach(cthread_t t); +extern any_t cthread_join(cthread_t t); +extern void cthread_yield(void); +extern void cthread_exit(any_t result); +extern kern_return_t cthread_priority( + cthread_t t, + int priority, + boolean_t set_max); +extern kern_return_t cthread_max_priority( + cthread_t t, + mach_port_t pset, + int max_priority); +extern kern_return_t cthread_abort(cthread_t t); +__DECLEND + +/* + * This structure must agree with struct cproc in cthread_internals.h + */ +typedef struct ur_cthread { + struct ur_cthread *next; + cthread_t incarnation; +} *ur_cthread_t; + +__DECLBEGIN +extern int cthread_sp(void); + +extern int cthread_stack_mask; + +extern ur_cthread_t ur_cthread_self(void); +#define cthread_thread(c) (c->real_thread) +extern void cthread_set_errno_self(int e); +extern int cthread_errno(void); +#define cthread_assoc(id, t) (((ur_cthread_t) (id))->incarnation = (t)) +#define cthread_self() (ur_cthread_self()->incarnation) + +extern void cthread_set_name(cthread_t t, const char *name); +extern const char *cthread_name(cthread_t t); +extern int cthread_count(void); +extern void cthread_set_limit(int n); +extern int cthread_limit(void); +__DECLEND + +#define cthread_set_data(t, x) ((t)->data = (x)) +#define cthread_data(t) ((t)->data) + +/* + * Spin locks. + */ +#define spin_unlock(p) (*(p) = 0) + +/* + * Mutex locks. + */ +#define mutex_unlock(m) ((m)->lock = 0) + + +/* + * Debugging support. + */ +#ifdef CTHREADS_DEBUG + +#ifndef ASSERT +/* + * Assertion macro, similar to + */ +#import +#define ASSERT(p) \ + MACRO_BEGIN \ + if (!(p)) { \ + fprintf(stderr, \ + "File %s, line %d: assertion p failed.\n", \ + __FILE__, __LINE__); \ + abort(); \ + } \ + MACRO_END + +#endif /* ASSERT */ + +#define SHOULDNT_HAPPEN 0 + +extern int cthread_debug; + +#else /* CTHREADS_DEBUG */ + +#ifndef ASSERT +#define ASSERT(p) +#endif /* ASSERT */ + +#endif /* CTHREADS_DEBUG */ + +#endif /* _CTHREADS_ */ diff --git a/threads/lu_utils.c b/threads/lu_utils.c new file mode 100644 index 0000000..090f2e9 --- /dev/null +++ b/threads/lu_utils.c @@ -0,0 +1,108 @@ +/* + * Port and memory management for doing lookups to the lookup server + * Copyright (C) 1989 by NeXT, Inc. + */ +/* + * HISTORY + * 27-Mar-90 Gregg Kellogg (gk) at NeXT + * Changed to use bootstrap port instead of service port. + * + */ +#include +#include +#include + +mach_port_t _lu_port = MACH_PORT_NULL; +static name_t LOOKUP_NAME = "lookup daemon v2"; + +mach_port_t _lookupd_port(mach_port_t port) { + 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); + if (ret != BOOTSTRAP_SUCCESS) { + mach_error("bootstrap_register() failed", ret); + abort(); + } + return port; + } + return _lu_port; +} + +/* called as child starts up. mach ports aren't inherited: trash cache */ +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_setport(mach_port_t desired) +{ + if (_lu_port != MACH_PORT_NULL) { + mach_port_deallocate(mach_task_self(), _lu_port); + } + _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; +} + diff --git a/threads/mig_support.c b/threads/mig_support.c new file mode 100644 index 0000000..1cf0f63 --- /dev/null +++ b/threads/mig_support.c @@ -0,0 +1,171 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Mach Operating System + * Copyright (c) 1989 Carnegie-Mellon University + * All rights reserved. The CMU software License Agreement specifies + * the terms and conditions for use and redistribution. + */ +/* + * mig_support.c - by Mary Thompson + * + * Routines to set and deallocate the mig reply port for the current thread. + * Called from mig-generated interfaces. + */ +#include +#include +#include + +#include "cthreads.h" +#include "cthread_internals.h" + +pthread_lock_t reply_port_lock; +extern mach_port_t _pthread_reply_port(pthread_t); +static mach_port_t _task_reply_port = MACH_PORT_NULL; + +/* + * called in new child... + * clear lock to cover case where the parent had + * a thread holding this lock while another thread + * did the fork() + */ +void mig_fork_child() +{ + UNLOCK(reply_port_lock); +} + +/* + * Called by mach_init with 0 before cthread_init is + * called and again with 1 at the end of cthread_init. + */ +void +mig_init(init_done) + int init_done; +{ + if (init_done == 0) { + LOCK_INIT(reply_port_lock); + _task_reply_port = mach_reply_port(); + } +} + +/* + * Called by mig interface code whenever a reply port is needed. + * Tracing is masked during this call; otherwise, a call to printf() + * can result in a call to malloc() which eventually reenters + * mig_get_reply_port() and deadlocks. + */ +mach_port_t +mig_get_reply_port() +{ + register cproc_t self; + pthread_t pself; +#ifdef CTHREADS_DEBUG + int d = cthread_debug; +#endif CTHREADS_DEBUG + +#ifdef CTHREADS_DEBUG + cthread_debug = FALSE; +#endif CTHREADS_DEBUG + pself = pthread_self(); + if ((pself != (pthread_t)NULL) && (pself->sig == _PTHREAD_SIG)) { + if (pself->reply_port == MACH_PORT_NULL) { + pself->reply_port = mach_reply_port(); + } + return pself->reply_port; + } + self = cproc_self(); + if (self == NO_CPROC) { +#ifdef CTHREADS_DEBUG + cthread_debug = d; +#endif CTHREADS_DEBUG + return(_task_reply_port); + } + if (self->reply_port == MACH_PORT_NULL) { + self->reply_port = mach_reply_port(); + } +#ifdef CTHREADS_DEBUG + cthread_debug = d; +#endif CTHREADS_DEBUG + return self->reply_port; +} + +/* + * Called by mig interface code after a timeout on the reply port. + * May also be called by user. The new mig calls with port passed in + * We are ignoring this , so is osfmk cthreads code + */ +void +mig_dealloc_reply_port(mach_port_t migport) +{ + register cproc_t self; + pthread_t pself; + register mach_port_t port; +#ifdef CTHREADS_DEBUG + int d = cthread_debug; +#endif CTHREADS_DEBUG + +#ifdef CTHREADS_DEBUG + cthread_debug = FALSE; +#endif CTHREADS_DEBUG + pself = pthread_self(); + if ((pself != (pthread_t)NULL) && (pself->sig == _PTHREAD_SIG)) { + port = pself->reply_port; + if (port != MACH_PORT_NULL && port != _task_reply_port) { + LOCK(reply_port_lock); + pself->reply_port = _task_reply_port; + (void) mach_port_destroy(mach_task_self(), port); + pself->reply_port = MACH_PORT_NULL; + UNLOCK(reply_port_lock); + } + return; + } + self = cproc_self(); + if (self == NO_CPROC) { +#ifdef CTHREADS_DEBUG + cthread_debug = d; +#endif CTHREADS_DEBUG + return; + } + ASSERT(self != NO_CPROC); + port = self->reply_port; + if (port != MACH_PORT_NULL && port != _task_reply_port) { + LOCK(reply_port_lock); + self->reply_port = _task_reply_port; + (void) mach_port_destroy(mach_task_self(), port); + self->reply_port = MACH_PORT_NULL; + UNLOCK(reply_port_lock); + } +#ifdef CTHREADS_DEBUG + cthread_debug = d; +#endif CTHREADS_DEBUG +} + +/************************************************************* + * Called by mig interfaces after each RPC. + * Could be called by user. + ***********************************************************/ + +void +mig_put_reply_port( + mach_port_t reply_port) +{ +} diff --git a/util.subproj/Makefile b/util.subproj/Makefile deleted file mode 100644 index f9b0874..0000000 --- a/util.subproj/Makefile +++ /dev/null @@ -1,45 +0,0 @@ -# -# Generated by the NeXT Project Builder. -# -# NOTE: Do NOT change this file -- Project Builder maintains it. -# -# Put all of your customizations in files called Makefile.preamble -# and Makefile.postamble (both optional), and Makefile will include them. -# - -NAME = util - -PROJECTVERSION = 2.8 -PROJECT_TYPE = Component - -CFILES = login.c login_tty.c logout.c logwtmp.c pty.c - -OTHERSRCS = Makefile.preamble Makefile Makefile.postamble - - -MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles -CODE_GEN_STYLE = DYNAMIC -MAKEFILE = subproj.make -LIBS = -DEBUG_LIBS = $(LIBS) -PROF_LIBS = $(LIBS) - - - - -NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc -WINDOWS_OBJCPLUS_COMPILER = $(DEVDIR)/gcc -PDO_UNIX_OBJCPLUS_COMPILER = $(NEXTDEV_BIN)/gcc -NEXTSTEP_JAVA_COMPILER = /usr/bin/javac -WINDOWS_JAVA_COMPILER = $(JDKBINDIR)/javac.exe -PDO_UNIX_JAVA_COMPILER = $(JDKBINDIR)/javac - -include $(MAKEFILEDIR)/platform.make - --include Makefile.preamble - -include $(MAKEFILEDIR)/$(MAKEFILE) - --include Makefile.postamble - --include Makefile.dependencies diff --git a/util.subproj/Makefile.postamble b/util.subproj/Makefile.postamble deleted file mode 100644 index 411cde6..0000000 --- a/util.subproj/Makefile.postamble +++ /dev/null @@ -1,100 +0,0 @@ -############################################################################### -# Makefile.postamble -# Copyright 1997, Apple Computer, Inc. -# -# Use this makefile, which is imported after all other makefiles, to -# override attributes for a project's Makefile environment. This allows you -# to take advantage of the environment set up by the other Makefiles. -# You can also define custom rules at the end of this file. -# -############################################################################### -# -# These variables are exported by the standard makefiles and can be -# used in any customizations you make. They are *outputs* of -# the Makefiles and should be used, not set. -# -# PRODUCTS: products to install. All of these products will be placed in -# the directory $(DSTROOT)$(INSTALLDIR) -# GLOBAL_RESOURCE_DIR: The directory to which resources are copied. -# LOCAL_RESOURCE_DIR: The directory to which localized resources are copied. -# OFILE_DIR: Directory into which .o object files are generated. -# DERIVED_SRC_DIR: Directory used for all other derived files -# -# ALL_CFLAGS: flags to pass when compiling .c files -# ALL_MFLAGS: flags to pass when compiling .m files -# ALL_CCFLAGS: flags to pass when compiling .cc, .cxx, and .C files -# ALL_MMFLAGS: flags to pass when compiling .mm, .mxx, and .M files -# ALL_PRECOMPFLAGS: flags to pass when precompiling .h files -# ALL_LDFLAGS: flags to pass when linking object files -# ALL_LIBTOOL_FLAGS: flags to pass when libtooling object files -# ALL_PSWFLAGS: flags to pass when processing .psw and .pswm (pswrap) files -# ALL_RPCFLAGS: flags to pass when processing .rpc (rpcgen) files -# ALL_YFLAGS: flags to pass when processing .y (yacc) files -# ALL_LFLAGS: flags to pass when processing .l (lex) files -# -# NAME: name of application, bundle, subproject, palette, etc. -# LANGUAGES: langages in which the project is written (default "English") -# English_RESOURCES: localized resources (e.g. nib's, images) of project -# GLOBAL_RESOURCES: non-localized resources of project -# -# SRCROOT: base directory in which to place the new source files -# SRCPATH: relative path from SRCROOT to present subdirectory -# -# INSTALLDIR: Directory the product will be installed into by 'install' target -# PUBLIC_HDR_INSTALLDIR: where to install public headers. Don't forget -# to prefix this with DSTROOT when you use it. -# PRIVATE_HDR_INSTALLDIR: where to install private headers. Don't forget -# to prefix this with DSTROOT when you use it. -# -# EXECUTABLE_EXT: Executable extension for the platform (i.e. .exe on Windows) -# -############################################################################### - -# Some compiler flags can be overridden here for certain build situations. -# -# WARNING_CFLAGS: flag used to set warning level (defaults to -Wmost) -# DEBUG_SYMBOLS_CFLAGS: debug-symbol flag passed to all builds (defaults -# to -g) -# DEBUG_BUILD_CFLAGS: flags passed during debug builds (defaults to -DDEBUG) -# OPTIMIZE_BUILD_CFLAGS: flags passed during optimized builds (defaults -# to -O) -# PROFILE_BUILD_CFLAGS: flags passed during profile builds (defaults -# to -pg -DPROFILE) -# LOCAL_DIR_INCLUDE_DIRECTIVE: flag used to add current directory to -# the include path (defaults to -I.) -# DEBUG_BUILD_LDFLAGS, OPTIMIZE_BUILD_LDFLAGS, PROFILE_BUILD_LDFLAGS: flags -# passed to ld/libtool (defaults to nothing) - - -# Library and Framework projects only: -# INSTALL_NAME_DIRECTIVE: This directive ensures that executables linked -# against the framework will run against the correct version even if -# the current version of the framework changes. You may override this -# to "" as an alternative to using the DYLD_LIBRARY_PATH during your -# development cycle, but be sure to restore it before installing. - - -# Ownership and permissions of files installed by 'install' target - -#INSTALL_AS_USER = root - # User/group ownership -#INSTALL_AS_GROUP = wheel - # (probably want to set both of these) -#INSTALL_PERMISSIONS = - # If set, 'install' chmod's executable to this - - -# Options to strip. Note: -S strips debugging symbols (executables can be stripped -# down further with -x or, if they load no bundles, with no options at all). - -#STRIPFLAGS = -S - - -######################################################################### -# Put rules to extend the behavior of the standard Makefiles here. Include them in -# the dependency tree via cvariables like AFTER_INSTALL in the Makefile.preamble. -# -# You should avoid redefining things like "install" or "app", as they are -# owned by the top-level Makefile API and no context has been set up for where -# derived files should go. -# diff --git a/util.subproj/Makefile.preamble b/util.subproj/Makefile.preamble deleted file mode 100644 index c1624b4..0000000 --- a/util.subproj/Makefile.preamble +++ /dev/null @@ -1,137 +0,0 @@ -############################################################################### -# Makefile.preamble -# Copyright 1997, Apple Computer, Inc. -# -# Use this makefile for configuring the standard application makefiles -# associated with ProjectBuilder. It is included before the main makefile. -# In Makefile.preamble you set attributes for a project, so they are available -# to the project's makefiles. In contrast, you typically write additional rules or -# override built-in behavior in the Makefile.postamble. -# -# Each directory in a project tree (main project plus subprojects) should -# have its own Makefile.preamble and Makefile.postamble. -############################################################################### -# -# Before the main makefile is included for this project, you may set: -# -# MAKEFILEDIR: Directory in which to find $(MAKEFILE) -# MAKEFILE: Top level mechanism Makefile (e.g., app.make, bundle.make) - -# Compiler/linker flags added to the defaults: The OTHER_* variables will be -# inherited by all nested sub-projects, but the LOCAL_ versions of the same -# variables will not. Put your -I, -D, -U, and -L flags in ProjectBuilder's -# Build Attributes inspector if at all possible. To override the default flags -# that get passed to ${CC} (e.g. change -O to -O2), see Makefile.postamble. The -# variables below are *inputs* to the build process and distinct from the override -# settings done (less often) in the Makefile.postamble. -# -# OTHER_CFLAGS, LOCAL_CFLAGS: additional flags to pass to the compiler -# Note that $(OTHER_CFLAGS) and $(LOCAL_CFLAGS) are used for .h, ...c, .m, -# .cc, .cxx, .C, and .M files. There is no need to respecify the -# flags in OTHER_MFLAGS, etc. -# OTHER_MFLAGS, LOCAL_MFLAGS: additional flags for .m files -# OTHER_CCFLAGS, LOCAL_CCFLAGS: additional flags for .cc, .cxx, and ...C files -# OTHER_MMFLAGS, LOCAL_MMFLAGS: additional flags for .mm and .M files -# OTHER_PRECOMPFLAGS, LOCAL_PRECOMPFLAGS: additional flags used when -# precompiling header files -# OTHER_LDFLAGS, LOCAL_LDFLAGS: additional flags passed to ld and libtool -# OTHER_PSWFLAGS, LOCAL_PSWFLAGS: additional flags passed to pswrap -# OTHER_RPCFLAGS, LOCAL_RPCFLAGS: additional flags passed to rpcgen -# OTHER_YFLAGS, LOCAL_YFLAGS: additional flags passed to yacc -# OTHER_LFLAGS, LOCAL_LFLAGS: additional flags passed to lex - -# These variables provide hooks enabling you to add behavior at almost every -# stage of the make: -# -# BEFORE_PREBUILD: targets to build before installing headers for a subproject -# AFTER_PREBUILD: targets to build after installing headers for a subproject -# BEFORE_BUILD_RECURSION: targets to make before building subprojects -# BEFORE_BUILD: targets to make before a build, but after subprojects -# AFTER_BUILD: targets to make after a build -# -# BEFORE_INSTALL: targets to build before installing the product -# AFTER_INSTALL: targets to build after installing the product -# BEFORE_POSTINSTALL: targets to build before postinstalling every subproject -# AFTER_POSTINSTALL: targts to build after postinstalling every subproject -# -# BEFORE_INSTALLHDRS: targets to build before installing headers for a -# subproject -# AFTER_INSTALLHDRS: targets to build after installing headers for a subproject -# BEFORE_INSTALLSRC: targets to build before installing source for a subproject -# AFTER_INSTALLSRC: targets to build after installing source for a subproject -# -# BEFORE_DEPEND: targets to build before building dependencies for a -# subproject -# AFTER_DEPEND: targets to build after building dependencies for a -# subproject -# -# AUTOMATIC_DEPENDENCY_INFO: if YES, then the dependency file is -# updated every time the project is built. If NO, the dependency -# file is only built when the depend target is invoked. - -# Framework-related variables: -# FRAMEWORK_DLL_INSTALLDIR: On Windows platforms, this variable indicates -# where to put the framework's DLL. This variable defaults to -# $(INSTALLDIR)/../Executables - -# Library-related variables: -# PUBLIC_HEADER_DIR: Determines where public exported header files -# should be installed. Do not include $(DSTROOT) in this value -- -# it is prefixed automatically. For library projects you should -# set this to something like /Developer/Headers/$(NAME). Do not set -# this variable for framework projects unless you do not want the -# header files included in the framework. -# PRIVATE_HEADER_DIR: Determines where private exported header files -# should be installed. Do not include $(DSTROOT) in this value -- -# it is prefixed automatically. -# LIBRARY_STYLE: This may be either STATIC or DYNAMIC, and determines -# whether the libraries produced are statically linked when they -# are used or if they are dynamically loadable. This defaults to -# DYNAMIC. -# LIBRARY_DLL_INSTALLDIR: On Windows platforms, this variable indicates -# where to put the library's DLL. This variable defaults to -# $(INSTALLDIR)/../Executables -# -# INSTALL_AS_USER: owner of the intalled products (default root) -# INSTALL_AS_GROUP: group of the installed products (default wheel) -# INSTALL_PERMISSIONS: permissions of the installed product (default o+rX) -# -# OTHER_RECURSIVE_VARIABLES: The names of variables which you want to be -# passed on the command line to recursive invocations of make. Note that -# the values in OTHER_*FLAGS are inherited by subprojects automatically -- -# you do not have to (and shouldn't) add OTHER_*FLAGS to -# OTHER_RECURSIVE_VARIABLES. - -# Additional headers to export beyond those in the PB.project: -# OTHER_PUBLIC_HEADERS -# OTHER_PROJECT_HEADERS -# OTHER_PRIVATE_HEADERS - -# Additional files for the project's product: <> -# OTHER_RESOURCES: (non-localized) resources for this project -# OTHER_OFILES: relocatables to be linked into this project -# OTHER_LIBS: more libraries to link against -# OTHER_PRODUCT_DEPENDS: other dependencies of this project -# OTHER_SOURCEFILES: other source files maintained by .pre/postamble -# OTHER_GARBAGE: additional files to be removed by `make clean' - -# Set this to YES if you don't want a final libtool call for a library/framework. -# BUILD_OFILES_LIST_ONLY - -# To include a version string, project source must exist in a directory named -# $(NAME).%d[.%d][.%d] and the following line must be uncommented. -# OTHER_GENERATED_OFILES = $(VERS_OFILE) - -# This definition will suppress stripping of debug symbols when an executable -# is installed. By default it is YES. -# STRIP_ON_INSTALL = NO - -# Uncomment to suppress generation of a KeyValueCoding index when installing -# frameworks (This index is used by WOB and IB to determine keys available -# for an object). Set to YES by default. -# PREINDEX_FRAMEWORK = NO - -# Change this definition to install projects somewhere other than the -# standard locations. NEXT_ROOT defaults to "C:/Apple" on Windows systems -# and "" on other systems. -DSTROOT = $(HOME) diff --git a/util.subproj/PB.project b/util.subproj/PB.project deleted file mode 100644 index 87e4046..0000000 --- a/util.subproj/PB.project +++ /dev/null @@ -1,23 +0,0 @@ -{ - DYNAMIC_CODE_GEN = YES; - FILESTABLE = { - H_FILES = (); - OTHER_LINKED = (login.c, login_tty.c, logout.c, logwtmp.c, pty.c); - OTHER_SOURCES = (Makefile.preamble, Makefile, Makefile.postamble); - SUBPROJECTS = (); - }; - LANGUAGE = English; - MAKEFILEDIR = "$(MAKEFILEPATH)/pb_makefiles"; - NEXTSTEP_BUILDTOOL = /bin/gnumake; - NEXTSTEP_JAVA_COMPILER = /usr/bin/javac; - NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc; - PDO_UNIX_BUILDTOOL = $NEXT_ROOT/Developer/bin/make; - PDO_UNIX_JAVA_COMPILER = "$(JDKBINDIR)/javac"; - PDO_UNIX_OBJCPLUS_COMPILER = "$(NEXTDEV_BIN)/gcc"; - PROJECTNAME = util; - PROJECTTYPE = Component; - PROJECTVERSION = 2.8; - WINDOWS_BUILDTOOL = $NEXT_ROOT/Developer/Executables/make; - WINDOWS_JAVA_COMPILER = "$(JDKBINDIR)/javac.exe"; - WINDOWS_OBJCPLUS_COMPILER = "$(DEVDIR)/gcc"; -} diff --git a/util.subproj/login.c b/util.subproj/login.c deleted file mode 100644 index 8720a25..0000000 --- a/util.subproj/login.c +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1988, 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 - -#include -#include -#include -#include -#include - -void -login(ut) - struct utmp *ut; -{ - register int fd; - int tty; - - tty = ttyslot(); - if (tty > 0 && (fd = open(_PATH_UTMP, O_WRONLY|O_CREAT, 0644)) >= 0) { - (void)lseek(fd, (off_t)(tty * sizeof(struct utmp)), L_SET); - (void)write(fd, ut, sizeof(struct utmp)); - (void)close(fd); - } - if ((fd = open(_PATH_WTMP, O_WRONLY|O_APPEND, 0)) >= 0) { - (void)write(fd, ut, sizeof(struct utmp)); - (void)close(fd); - } -} diff --git a/util.subproj/login_tty.c b/util.subproj/login_tty.c deleted file mode 100644 index e172a2b..0000000 --- a/util.subproj/login_tty.c +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 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 -#include -#include - -int login_tty(fd) - int fd; -{ - (void) setsid(); - if (ioctl(fd, TIOCSCTTY, (char *)NULL) == -1) - return (-1); - (void) dup2(fd, 0); - (void) dup2(fd, 1); - (void) dup2(fd, 2); - if (fd > 2) - (void) close(fd); - return (0); -} diff --git a/util.subproj/logout.c b/util.subproj/logout.c deleted file mode 100644 index 6c7be20..0000000 --- a/util.subproj/logout.c +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1988, 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 -#include - -#include -#include -#include -#include -#include - -typedef struct utmp UTMP; - -int -logout(line) - register char *line; -{ - register int fd; - UTMP ut; - int rval; - - if ((fd = open(_PATH_UTMP, O_RDWR, 0)) < 0) - return(0); - rval = 0; - while (read(fd, &ut, sizeof(UTMP)) == sizeof(UTMP)) { - if (!ut.ut_name[0] || strncmp(ut.ut_line, line, UT_LINESIZE)) - continue; - bzero(ut.ut_name, UT_NAMESIZE); - bzero(ut.ut_host, UT_HOSTSIZE); - (void)time(&ut.ut_time); - (void)lseek(fd, -(off_t)sizeof(UTMP), L_INCR); - (void)write(fd, &ut, sizeof(UTMP)); - rval = 1; - } - (void)close(fd); - return(rval); -} diff --git a/util.subproj/logwtmp.c b/util.subproj/logwtmp.c deleted file mode 100644 index 4e573a6..0000000 --- a/util.subproj/logwtmp.c +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1988, 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 -#include -#include -#include - -#include -#include - -void logwtmp(line, name, host) - char *line, *name, *host; -{ - struct utmp ut; - struct stat buf; - int fd; - time_t time(); - char *strncpy(); - - if ((fd = open(_PATH_WTMP, O_WRONLY|O_APPEND, 0)) < 0) - return; - if (fstat(fd, &buf) == 0) { - (void) strncpy(ut.ut_line, line, sizeof(ut.ut_line)); - (void) strncpy(ut.ut_name, name, sizeof(ut.ut_name)); - (void) strncpy(ut.ut_host, host, sizeof(ut.ut_host)); - (void) time(&ut.ut_time); - if (write(fd, (char *)&ut, sizeof(struct utmp)) != - sizeof(struct utmp)) - (void) ftruncate(fd, buf.st_size); - } - (void) close(fd); -} diff --git a/util.subproj/pty.c b/util.subproj/pty.c deleted file mode 100644 index aa0b2ad..0000000 --- a/util.subproj/pty.c +++ /dev/null @@ -1,146 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/* - * Copyright (c) 1990, 1993, 1994 - * 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 -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -int openpty(amaster, aslave, name, termp, winp) - int *amaster, *aslave; - char *name; - struct termios *termp; - struct winsize *winp; -{ - static char line[] = "/dev/ptyXX"; - register const char *cp1, *cp2; - register int master, slave, ttygid; - struct group *gr; - - if ((gr = getgrnam("tty")) != NULL) - ttygid = gr->gr_gid; - else - ttygid = -1; - - for (cp1 = "pqrstuvwxy"; *cp1; cp1++) { - line[8] = *cp1; - for (cp2 = "0123456789abcdef"; *cp2; cp2++) { - line[5] = 'p'; - line[9] = *cp2; - if ((master = open(line, O_RDWR, 0)) == -1) { - if (errno == ENOENT) - return (-1); /* out of ptys */ - } else { - line[5] = 't'; - (void) chown(line, getuid(), ttygid); - (void) chmod(line, S_IRUSR|S_IWUSR|S_IWGRP); - (void) revoke(line); - if ((slave = open(line, O_RDWR, 0)) != -1) { - *amaster = master; - *aslave = slave; - if (name) - strcpy(name, line); - if (termp) - (void) tcsetattr(slave, - TCSAFLUSH, termp); - if (winp) - (void) ioctl(slave, TIOCSWINSZ, - (char *)winp); - return (0); - } - (void) close(master); - } - } - } - errno = ENOENT; /* out of ptys */ - return (-1); -} - -forkpty(amaster, name, termp, winp) - int *amaster; - char *name; - struct termios *termp; - struct winsize *winp; -{ - int master, slave, pid; - - if (openpty(&master, &slave, name, termp, winp) == -1) - return (-1); - switch (pid = fork()) { - case -1: - return (-1); - case 0: - /* - * child - */ - (void) close(master); - login_tty(slave); - return (0); - } - /* - * parent - */ - *amaster = master; - (void) close(slave); - return (pid); -} diff --git a/util/Makefile.inc b/util/Makefile.inc new file mode 100644 index 0000000..8151c6b --- /dev/null +++ b/util/Makefile.inc @@ -0,0 +1,3 @@ +.PATH: ${.CURDIR}/${MACHINE_ARCH}/util ${.CURDIR}/util + +SRCS += login.c login_tty.c logout.c logwtmp.c pty.c diff --git a/util/login.c b/util/login.c new file mode 100644 index 0000000..8720a25 --- /dev/null +++ b/util/login.c @@ -0,0 +1,81 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1988, 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 + +#include +#include +#include +#include +#include + +void +login(ut) + struct utmp *ut; +{ + register int fd; + int tty; + + tty = ttyslot(); + if (tty > 0 && (fd = open(_PATH_UTMP, O_WRONLY|O_CREAT, 0644)) >= 0) { + (void)lseek(fd, (off_t)(tty * sizeof(struct utmp)), L_SET); + (void)write(fd, ut, sizeof(struct utmp)); + (void)close(fd); + } + if ((fd = open(_PATH_WTMP, O_WRONLY|O_APPEND, 0)) >= 0) { + (void)write(fd, ut, sizeof(struct utmp)); + (void)close(fd); + } +} diff --git a/util/login_tty.c b/util/login_tty.c new file mode 100644 index 0000000..e172a2b --- /dev/null +++ b/util/login_tty.c @@ -0,0 +1,71 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 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 +#include +#include + +int login_tty(fd) + int fd; +{ + (void) setsid(); + if (ioctl(fd, TIOCSCTTY, (char *)NULL) == -1) + return (-1); + (void) dup2(fd, 0); + (void) dup2(fd, 1); + (void) dup2(fd, 2); + if (fd > 2) + (void) close(fd); + return (0); +} diff --git a/util/logout.c b/util/logout.c new file mode 100644 index 0000000..6c7be20 --- /dev/null +++ b/util/logout.c @@ -0,0 +1,90 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1988, 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 +#include + +#include +#include +#include +#include +#include + +typedef struct utmp UTMP; + +int +logout(line) + register char *line; +{ + register int fd; + UTMP ut; + int rval; + + if ((fd = open(_PATH_UTMP, O_RDWR, 0)) < 0) + return(0); + rval = 0; + while (read(fd, &ut, sizeof(UTMP)) == sizeof(UTMP)) { + if (!ut.ut_name[0] || strncmp(ut.ut_line, line, UT_LINESIZE)) + continue; + bzero(ut.ut_name, UT_NAMESIZE); + bzero(ut.ut_host, UT_HOSTSIZE); + (void)time(&ut.ut_time); + (void)lseek(fd, -(off_t)sizeof(UTMP), L_INCR); + (void)write(fd, &ut, sizeof(UTMP)); + rval = 1; + } + (void)close(fd); + return(rval); +} diff --git a/util/logwtmp.c b/util/logwtmp.c new file mode 100644 index 0000000..4e573a6 --- /dev/null +++ b/util/logwtmp.c @@ -0,0 +1,85 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1988, 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 +#include +#include +#include + +#include +#include + +void logwtmp(line, name, host) + char *line, *name, *host; +{ + struct utmp ut; + struct stat buf; + int fd; + time_t time(); + char *strncpy(); + + if ((fd = open(_PATH_WTMP, O_WRONLY|O_APPEND, 0)) < 0) + return; + if (fstat(fd, &buf) == 0) { + (void) strncpy(ut.ut_line, line, sizeof(ut.ut_line)); + (void) strncpy(ut.ut_name, name, sizeof(ut.ut_name)); + (void) strncpy(ut.ut_host, host, sizeof(ut.ut_host)); + (void) time(&ut.ut_time); + if (write(fd, (char *)&ut, sizeof(struct utmp)) != + sizeof(struct utmp)) + (void) ftruncate(fd, buf.st_size); + } + (void) close(fd); +} diff --git a/util/pty.c b/util/pty.c new file mode 100644 index 0000000..aa0b2ad --- /dev/null +++ b/util/pty.c @@ -0,0 +1,146 @@ +/* + * Copyright (c) 1999 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@ + */ +/* + * Copyright (c) 1990, 1993, 1994 + * 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 +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +int openpty(amaster, aslave, name, termp, winp) + int *amaster, *aslave; + char *name; + struct termios *termp; + struct winsize *winp; +{ + static char line[] = "/dev/ptyXX"; + register const char *cp1, *cp2; + register int master, slave, ttygid; + struct group *gr; + + if ((gr = getgrnam("tty")) != NULL) + ttygid = gr->gr_gid; + else + ttygid = -1; + + for (cp1 = "pqrstuvwxy"; *cp1; cp1++) { + line[8] = *cp1; + for (cp2 = "0123456789abcdef"; *cp2; cp2++) { + line[5] = 'p'; + line[9] = *cp2; + if ((master = open(line, O_RDWR, 0)) == -1) { + if (errno == ENOENT) + return (-1); /* out of ptys */ + } else { + line[5] = 't'; + (void) chown(line, getuid(), ttygid); + (void) chmod(line, S_IRUSR|S_IWUSR|S_IWGRP); + (void) revoke(line); + if ((slave = open(line, O_RDWR, 0)) != -1) { + *amaster = master; + *aslave = slave; + if (name) + strcpy(name, line); + if (termp) + (void) tcsetattr(slave, + TCSAFLUSH, termp); + if (winp) + (void) ioctl(slave, TIOCSWINSZ, + (char *)winp); + return (0); + } + (void) close(master); + } + } + } + errno = ENOENT; /* out of ptys */ + return (-1); +} + +forkpty(amaster, name, termp, winp) + int *amaster; + char *name; + struct termios *termp; + struct winsize *winp; +{ + int master, slave, pid; + + if (openpty(&master, &slave, name, termp, winp) == -1) + return (-1); + switch (pid = fork()) { + case -1: + return (-1); + case 0: + /* + * child + */ + (void) close(master); + login_tty(slave); + return (0); + } + /* + * parent + */ + *amaster = master; + (void) close(slave); + return (pid); +} diff --git a/xdr/Makefile.inc b/xdr/Makefile.inc new file mode 100644 index 0000000..6ca6859 --- /dev/null +++ b/xdr/Makefile.inc @@ -0,0 +1,52 @@ +# @(#)Makefile 5.11 (Berkeley) 9/6/90 +# $FreeBSD: src/lib/libc/xdr/Makefile.inc,v 1.12 2001/03/27 17:26:57 ru Exp $ + +.PATH: ${.CURDIR}/../libc/xdr ${.CURDIR}/. +SRCS+= xdr.c xdr_array.c xdr_float.c xdr_mem.c \ + xdr_rec.c xdr_reference.c xdr_stdio.c + +.if ${LIB} == "c" +MAN+= xdr.3 + +MLINKS+= rpc_xdr.3 xdr_accepted_reply.3 \ + rpc_xdr.3 xdr_authsys_parms.3 \ + rpc_xdr.3 xdr_callhdr.3 \ + rpc_xdr.3 xdr_callmsg.3 \ + rpc_xdr.3 xdr_opaque_auth.3 \ + rpc_xdr.3 xdr_rejected_reply.3 \ + rpc_xdr.3 xdr_replymsg.3 \ + xdr.3 xdr_array.3 \ + xdr.3 xdr_bool.3 \ + xdr.3 xdr_bytes.3 \ + xdr.3 xdr_char.3 \ + xdr.3 xdr_destroy.3 \ + xdr.3 xdr_double.3 \ + xdr.3 xdr_enum.3 \ + xdr.3 xdr_float.3 \ + xdr.3 xdr_free.3 \ + xdr.3 xdr_getpos.3 \ + xdr.3 xdr_inline.3 \ + xdr.3 xdr_int.3 \ + xdr.3 xdr_long.3 \ + xdr.3 xdrmem_create.3 \ + xdr.3 xdr_opaque.3 \ + xdr.3 xdr_pointer.3 \ + xdr.3 xdrrec_create.3 \ + xdr.3 xdrrec_endofrecord.3 \ + xdr.3 xdrrec_eof.3 \ + xdr.3 xdrrec_skiprecord.3 \ + xdr.3 xdr_reference.3 \ + xdr.3 xdr_setpos.3 \ + xdr.3 xdr_short.3 \ + xdr.3 xdrstdio_create.3 \ + xdr.3 xdr_short.3 \ + xdr.3 xdrstdio_create.3 \ + xdr.3 xdr_string.3 \ + xdr.3 xdr_u_char.3 \ + xdr.3 xdr_u_long.3 \ + xdr.3 xdr_u_short.3 \ + xdr.3 xdr_union.3 \ + xdr.3 xdr_vector.3 \ + xdr.3 xdr_void.3 \ + xdr.3 xdr_wrapstring.3 +.endif diff --git a/yp/Makefile.inc b/yp/Makefile.inc new file mode 100644 index 0000000..1f0668c --- /dev/null +++ b/yp/Makefile.inc @@ -0,0 +1,17 @@ +# from: @(#)Makefile.inc 5.3 (Berkeley) 2/20/91 +# $FreeBSD: src/lib/libc/yp/Makefile.inc,v 1.8 1999/08/28 00:02:58 peter Exp $ + +# yp sources +.PATH: ${.CURDIR}/../libc/yp + +SRCS+= xdryp.c yp.h yp_xdr.c yplib.c +CLEANFILES+= yp.h yp_xdr.c + +RPCSRC= ${DESTDIR}/usr/include/rpcsvc/yp.x +RPCGEN= rpcgen -C + +yp_xdr.c: ${RPCSRC} + ${RPCGEN} -c -o ${.TARGET} ${RPCSRC} + +yp.h: ${RPCSRC} + ${RPCGEN} -h -o ${.TARGET} ${RPCSRC}