Browse Source

initial import

root 12 years ago
commit
0c41ace0b3
100 changed files with 5600 additions and 0 deletions
  1. 18 0
      CONTRIBUTORS
  2. 261 0
      LICENSE
  3. 258 0
      LICENSE.afpl
  4. 290 0
      LICENSE.gpl
  5. 2 0
      NOTICE
  6. 0 0
      amd64/bin/.shutuphg
  7. 2 0
      amd64/bin/ape/psh
  8. 0 0
      amd64/bin/auth/.shutuphg
  9. 0 0
      amd64/bin/aux/.shutuphg
  10. 0 0
      amd64/bin/bitsy/bitsyload/.shutuphg
  11. 0 0
      amd64/bin/dial/.shutuphg
  12. 0 0
      amd64/bin/disk/.shutuphg
  13. 0 0
      amd64/bin/fossil/.shutuphg
  14. 0 0
      amd64/bin/fs/.shutuphg
  15. 0 0
      amd64/bin/games/.shutuphg
  16. 0 0
      amd64/bin/ip/.shutuphg
  17. 0 0
      amd64/bin/ip/httpd/.shutuphg
  18. 0 0
      amd64/bin/ndb/.shutuphg
  19. 0 0
      amd64/bin/replica/.shutuphg
  20. 0 0
      amd64/bin/upas/.shutuphg
  21. 0 0
      amd64/bin/usb/.shutuphg
  22. 0 0
      amd64/bin/venti/.shutuphg
  23. 80 0
      amd64/include/ape/float.h
  24. 74 0
      amd64/include/ape/math.h
  25. 18 0
      amd64/include/ape/stdarg.h
  26. 38 0
      amd64/include/ape/ureg.h
  27. 72 0
      amd64/include/u.h
  28. 30 0
      amd64/include/ureg.h
  29. 0 0
      amd64/lib/.shutuphg
  30. 0 0
      amd64/lib/ape/.shutuphg
  31. 7 0
      amd64/mkfile
  32. 254 0
      sys/include/9p.h
  33. 45 0
      sys/include/String.h
  34. 46 0
      sys/include/a.out.h
  35. 20 0
      sys/include/ape/Plan9libnet.h
  36. 24 0
      sys/include/ape/ar.h
  37. 146 0
      sys/include/ape/arpa/inet.h
  38. 17 0
      sys/include/ape/assert.h
  39. 56 0
      sys/include/ape/bsd.h
  40. 55 0
      sys/include/ape/ctype.h
  41. 10 0
      sys/include/ape/cursor.h
  42. 40 0
      sys/include/ape/dirent.h
  43. 539 0
      sys/include/ape/draw.h
  44. 83 0
      sys/include/ape/errno.h
  45. 19 0
      sys/include/ape/error.h
  46. 10 0
      sys/include/ape/event.h
  47. 59 0
      sys/include/ape/fcntl.h
  48. 114 0
      sys/include/ape/fmt.h
  49. 26 0
      sys/include/ape/grp.h
  50. 23 0
      sys/include/ape/inttypes.h
  51. 6 0
      sys/include/ape/keyboard.h
  52. 78 0
      sys/include/ape/lib9.h
  53. 15 0
      sys/include/ape/libl.h
  54. 20 0
      sys/include/ape/libnet.h
  55. 39 0
      sys/include/ape/libv.h
  56. 85 0
      sys/include/ape/limits.h
  57. 46 0
      sys/include/ape/locale.h
  58. 29 0
      sys/include/ape/lock.h
  59. 6 0
      sys/include/ape/mouse.h
  60. 121 0
      sys/include/ape/netdb.h
  61. 147 0
      sys/include/ape/netinet/in.h
  62. 0 0
      sys/include/ape/netinet/tcp.h
  63. 28 0
      sys/include/ape/pwd.h
  64. 41 0
      sys/include/ape/qlock.h
  65. 77 0
      sys/include/ape/regexp.h
  66. 34 0
      sys/include/ape/select.h
  67. 26 0
      sys/include/ape/setjmp.h
  68. 95 0
      sys/include/ape/signal.h
  69. 23 0
      sys/include/ape/stddef.h
  70. 157 0
      sys/include/ape/stdio.h
  71. 55 0
      sys/include/ape/stdlib.h
  72. 47 0
      sys/include/ape/string.h
  73. 22 0
      sys/include/ape/sys/ioctl.h
  74. 28 0
      sys/include/ape/sys/limits.h
  75. 18 0
      sys/include/ape/sys/param.h
  76. 18 0
      sys/include/ape/sys/pty.h
  77. 29 0
      sys/include/ape/sys/resource.h
  78. 34 0
      sys/include/ape/sys/select.h
  79. 196 0
      sys/include/ape/sys/socket.h
  80. 84 0
      sys/include/ape/sys/stat.h
  81. 22 0
      sys/include/ape/sys/time.h
  82. 27 0
      sys/include/ape/sys/times.h
  83. 46 0
      sys/include/ape/sys/types.h
  84. 34 0
      sys/include/ape/sys/uio.h
  85. 26 0
      sys/include/ape/sys/un.h
  86. 23 0
      sys/include/ape/sys/utsname.h
  87. 35 0
      sys/include/ape/sys/wait.h
  88. 132 0
      sys/include/ape/termios.h
  89. 65 0
      sys/include/ape/time.h
  90. 19 0
      sys/include/ape/u.h
  91. 168 0
      sys/include/ape/unistd.h
  92. 61 0
      sys/include/ape/utf.h
  93. 22 0
      sys/include/ape/utime.h
  94. 17 0
      sys/include/ar.h
  95. 143 0
      sys/include/auth.h
  96. 173 0
      sys/include/authsrv.h
  97. 26 0
      sys/include/avl.h
  98. 10 0
      sys/include/bin.h
  99. 74 0
      sys/include/bio.h
  100. 137 0
      sys/include/bootexec.h

+ 18 - 0
CONTRIBUTORS

@@ -0,0 +1,18 @@
+#The following people have contributed source code to nix.
+
+Noah Evans <noah.evans@gmail.com>
+Ron Minnich <rminnich@gmail.com>
+John Floren <john@jfloren.net>
+Francisco J Ballesteros <nemo.mbox@gmail.com>
+Charles Forsyth <charles.forsyth@gmail.com>
+Enrique Soriano <enrique.soriano@gmail.com>
+Gorka Guardiola <paurea@gmail.com>
+James Mckie <jmk@plan9.bell-labs.com>
+Christian Neukirchen <chneukirchen@gmail.com>
+Erik Quanstrom <quanstro@quanstro.net>
+Erik Quanstrom <quanstro@gmail.com>
+Bakul Shah <bakul@bitblocks.com>
+David du Colombier <0intro@gmail.com>
+Akshat Kumar <akumar@mail.nanosouffle.net>
+Akshat Kumar <seed@mail.nanosouffle.net>
+Anthony Martin <ality@pbrane.org>

+ 261 - 0
LICENSE

@@ -0,0 +1,261 @@
+The Plan 9 software is provided under the terms of the
+Lucent Public License, Version 1.02, reproduced below,
+with the following notable exceptions:
+
+1. No right is granted to create derivative works of or
+   to redistribute (other than with the Plan 9 Operating System)
+   the screen imprinter fonts identified in subdirectory
+   /lib/font/bit/lucida and printer fonts (Lucida Sans Unicode, Lucida
+   Sans Italic, Lucida Sans Demibold, Lucida Typewriter, Lucida Sans
+   Typewriter83), identified in subdirectory /sys/lib/postscript/font.
+   These directories contain material copyrights by B&H Inc. and Y&Y Inc.
+
+2. The printer fonts identified in subdirectory /sys/lib/ghostscript/font
+   are subject to the GNU GPL, reproduced in the file /LICENSE.gpl.
+
+3. The ghostscript program in the subdirectory /sys/src/cmd/gs is
+   covered by the Aladdin Free Public License, reproduced in the file
+   /LICENSE.afpl.
+
+Other, less notable exceptions are marked in the file tree with
+COPYING, COPYRIGHT, or LICENSE files.
+
+===================================================================
+
+Lucent Public License Version 1.02
+
+THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS PUBLIC
+LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THE
+PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT.
+
+1. DEFINITIONS
+
+"Contribution" means:
+
+  a. in the case of Lucent Technologies Inc. ("LUCENT"), the Original
+     Program, and
+  b. in the case of each Contributor,
+
+     i. changes to the Program, and
+    ii. additions to the Program;
+
+    where such changes and/or additions to the Program were added to the
+    Program by such Contributor itself or anyone acting on such
+    Contributor's behalf, and the Contributor explicitly consents, in
+    accordance with Section 3C, to characterization of the changes and/or
+    additions as Contributions.
+
+"Contributor" means LUCENT and any other entity that has Contributed a
+Contribution to the Program.
+
+"Distributor" means a Recipient that distributes the Program,
+modifications to the Program, or any part thereof.
+
+"Licensed Patents" mean patent claims licensable by a Contributor
+which are necessarily infringed by the use or sale of its Contribution
+alone or when combined with the Program.
+
+"Original Program" means the original version of the software
+accompanying this Agreement as released by LUCENT, including source
+code, object code and documentation, if any.
+
+"Program" means the Original Program and Contributions or any part
+thereof
+
+"Recipient" means anyone who receives the Program under this
+Agreement, including all Contributors.
+
+2. GRANT OF RIGHTS
+
+ a. Subject to the terms of this Agreement, each Contributor hereby
+    grants Recipient a non-exclusive, worldwide, royalty-free copyright
+    license to reproduce, prepare derivative works of, publicly display,
+    publicly perform, distribute and sublicense the Contribution of such
+    Contributor, if any, and such derivative works, in source code and
+    object code form.
+    
+ b. Subject to the terms of this Agreement, each Contributor hereby
+    grants Recipient a non-exclusive, worldwide, royalty-free patent
+    license under Licensed Patents to make, use, sell, offer to sell,
+    import and otherwise transfer the Contribution of such Contributor, if
+    any, in source code and object code form. The patent license granted
+    by a Contributor shall also apply to the combination of the
+    Contribution of that Contributor and the Program if, at the time the
+    Contribution is added by the Contributor, such addition of the
+    Contribution causes such combination to be covered by the Licensed
+    Patents. The patent license granted by a Contributor shall not apply
+    to (i) any other combinations which include the Contribution, nor to
+    (ii) Contributions of other Contributors. No hardware per se is
+    licensed hereunder.
+    
+ c. Recipient understands that although each Contributor grants the
+    licenses to its Contributions set forth herein, no assurances are
+    provided by any Contributor that the Program does not infringe the
+    patent or other intellectual property rights of any other entity. Each
+    Contributor disclaims any liability to Recipient for claims brought by
+    any other entity based on infringement of intellectual property rights
+    or otherwise. As a condition to exercising the rights and licenses
+    granted hereunder, each Recipient hereby assumes sole responsibility
+    to secure any other intellectual property rights needed, if any. For
+    example, if a third party patent license is required to allow
+    Recipient to distribute the Program, it is Recipient's responsibility
+    to acquire that license before distributing the Program.
+
+ d. Each Contributor represents that to its knowledge it has sufficient
+    copyright rights in its Contribution, if any, to grant the copyright
+    license set forth in this Agreement.
+
+3. REQUIREMENTS
+
+A. Distributor may choose to distribute the Program in any form under
+this Agreement or under its own license agreement, provided that:
+
+ a. it complies with the terms and conditions of this Agreement;
+
+ b. if the Program is distributed in source code or other tangible
+    form, a copy of this Agreement or Distributor's own license agreement
+    is included with each copy of the Program; and
+
+ c. if distributed under Distributor's own license agreement, such
+    license agreement:
+
+      i. effectively disclaims on behalf of all Contributors all warranties
+         and conditions, express and implied, including warranties or
+         conditions of title and non-infringement, and implied warranties or
+         conditions of merchantability and fitness for a particular purpose;
+     ii. effectively excludes on behalf of all Contributors all liability
+         for damages, including direct, indirect, special, incidental and
+         consequential damages, such as lost profits; and
+    iii. states that any provisions which differ from this Agreement are
+         offered by that Contributor alone and not by any other party.
+
+B. Each Distributor must include the following in a conspicuous
+   location in the Program:
+
+   Copyright (C) 2003, Lucent Technologies Inc. and others. All Rights
+   Reserved.
+
+C. In addition, each Contributor must identify itself as the
+originator of its Contribution in a manner that reasonably allows
+subsequent Recipients to identify the originator of the Contribution.
+Also, each Contributor must agree that the additions and/or changes
+are intended to be a Contribution. Once a Contribution is contributed,
+it may not thereafter be revoked.
+
+4. COMMERCIAL DISTRIBUTION
+
+Commercial distributors of software may accept certain
+responsibilities with respect to end users, business partners and the
+like. While this license is intended to facilitate the commercial use
+of the Program, the Distributor who includes the Program in a
+commercial product offering should do so in a manner which does not
+create potential liability for Contributors. Therefore, if a
+Distributor includes the Program in a commercial product offering,
+such Distributor ("Commercial Distributor") hereby agrees to defend
+and indemnify every Contributor ("Indemnified Contributor") against
+any losses, damages and costs (collectively"Losses") arising from
+claims, lawsuits and other legal actions brought by a third party
+against the Indemnified Contributor to the extent caused by the acts
+or omissions of such Commercial Distributor in connection with its
+distribution of the Program in a commercial product offering. The
+obligations in this section do not apply to any claims or Losses
+relating to any actual or alleged intellectual property infringement.
+In order to qualify, an Indemnified Contributor must: a) promptly
+notify the Commercial Distributor in writing of such claim, and b)
+allow the Commercial Distributor to control, and cooperate with the
+Commercial Distributor in, the defense and any related settlement
+negotiations. The Indemnified Contributor may participate in any such
+claim at its own expense.
+
+For example, a Distributor might include the Program in a commercial
+product offering, Product X. That Distributor is then a Commercial
+Distributor. If that Commercial Distributor then makes performance
+claims, or offers warranties related to Product X, those performance
+claims and warranties are such Commercial Distributor's responsibility
+alone. Under this section, the Commercial Distributor would have to
+defend claims against the Contributors related to those performance
+claims and warranties, and if a court requires any Contributor to pay
+any damages as a result, the Commercial Distributor must pay those
+damages.
+
+5. NO WARRANTY
+
+EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS
+PROVIDED ON AN"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY
+WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY
+OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is solely
+responsible for determining the appropriateness of using and
+distributing the Program and assumes all risks associated with its
+exercise of rights under this Agreement, including but not limited to
+the risks and costs of program errors, compliance with applicable
+laws, damage to or loss of data, programs or equipment, and
+unavailability or interruption of operations.
+
+6. DISCLAIMER OF LIABILITY
+
+EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT NOR
+ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT,
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING
+WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF
+LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OR
+DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
+HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+
+7. EXPORT CONTROL
+
+Recipient agrees that Recipient alone is responsible for compliance
+with the United States export administration regulations (and the
+export control laws and regulation of any other countries).
+
+8. GENERAL
+
+If any provision of this Agreement is invalid or unenforceable under
+applicable law, it shall not affect the validity or enforceability of
+the remainder of the terms of this Agreement, and without further
+action by the parties hereto, such provision shall be reformed to the
+minimum extent necessary to make such provision valid and enforceable.
+
+If Recipient institutes patent litigation against a Contributor with
+respect to a patent applicable to software (including a cross-claim or
+counterclaim in a lawsuit), then any patent licenses granted by that
+Contributor to such Recipient under this Agreement shall terminate as
+of the date such litigation is filed. In addition, if Recipient
+institutes patent litigation against any entity (including a
+cross-claim or counterclaim in a lawsuit) alleging that the Program
+itself (excluding combinations of the Program with other software or
+hardware) infringes such Recipient's patent(s), then such Recipient's
+rights granted under Section 2(b) shall terminate as of the date such
+litigation is filed.
+
+All Recipient's rights under this Agreement shall terminate if it
+fails to comply with any of the material terms or conditions of this
+Agreement and does not cure such failure in a reasonable period of
+time after becoming aware of such noncompliance. If all Recipient's
+rights under this Agreement terminate, Recipient agrees to cease use
+and distribution of the Program as soon as reasonably practicable.
+However, Recipient's obligations under this Agreement and any licenses
+granted by Recipient relating to the Program shall continue and
+survive.
+
+LUCENT may publish new versions (including revisions) of this
+Agreement from time to time. Each new version of the Agreement will be
+given a distinguishing version number. The Program (including
+Contributions) may always be distributed subject to the version of the
+Agreement under which it was received. In addition, after a new
+version of the Agreement is published, Contributor may elect to
+distribute the Program (including its Contributions) under the new
+version. No one other than LUCENT has the right to modify this
+Agreement. Except as expressly stated in Sections 2(a) and 2(b) above,
+Recipient receives no rights or licenses to the intellectual property
+of any Contributor under this Agreement, whether expressly, by
+implication, estoppel or otherwise. All rights in the Program not
+expressly granted under this Agreement are reserved.
+
+This Agreement is governed by the laws of the State of New York and
+the intellectual property laws of the United States of America. No
+party to this Agreement will bring a legal action under this Agreement
+more than one year after the cause of action arose. Each party waives
+its rights to a jury trial in any resulting litigation.
+

+ 258 - 0
LICENSE.afpl

@@ -0,0 +1,258 @@
+
+                          Aladdin Free Public License
+                        (Version 9, September 18, 2000)
+
+   Copyright (C) 1994, 1995, 1997, 1998, 1999, 2000 Aladdin Enterprises,
+            Menlo Park, California, U.S.A. All rights reserved.
+
+     NOTE: This License is not the same as any of the GNU Licenses
+     published by the Free Software Foundation. Its terms are
+     substantially different from those of the GNU Licenses. If you are
+     familiar with the GNU Licenses, please read this license with extra
+     care.
+
+   Aladdin Enterprises hereby grants to anyone the permission to apply
+   this License to their own work, as long as the entire License
+   (including the above notices and this paragraph) is copied with no
+   changes, additions, or deletions except for changing the first
+   paragraph of Section 0 to include a suitable description of the work
+   to which the license is being applied and of the person or entity that
+   holds the copyright in the work, and, if the License is being applied
+   to a work created in a country other than the United States, replacing
+   the first paragraph of Section 6 with an appropriate reference to the
+   laws of the appropriate country.
+
+   This License is not an Open Source license: among other things, it
+   places restrictions on distribution of the Program, specifically
+   including sale of the Program. While Aladdin Enterprises respects and
+   supports the philosophy of the Open Source Definition, and shares the
+   desire of the GNU project to keep licensed software freely
+   redistributable in both source and object form, we feel that Open
+   Source licenses unfairly prevent developers of useful software from
+   being compensated proportionately when others profit financially from
+   their work. This License attempts to ensure that those who receive,
+   redistribute, and contribute to the licensed Program according to the
+   Open Source and Free Software philosophies have the right to do so,
+   while retaining for the developer(s) of the Program the power to make
+   those who use the Program to enhance the value of commercial products
+   pay for the privilege of doing so.
+
+0. Subject Matter
+
+   This License applies to the computer program known as "AFPL
+   Ghostscript." The "Program", below, refers to such program. The
+   Program is a copyrighted work whose copyright is held by artofcode
+   LLC, located in Benicia, California (the "Licensor"). Please note that
+   AFPL Ghostscript is neither the program known as "GNU Ghostscript" nor
+   the version of Ghostscript available for commercial licensing from
+   Artifex Software Inc.
+
+   A "work based on the Program" means either the Program or any
+   derivative work of the Program, as defined in the United States
+   Copyright Act of 1976, such as a translation or a modification.
+
+   BY MODIFYING OR DISTRIBUTING THE PROGRAM (OR ANY WORK BASED ON THE
+   PROGRAM), YOU INDICATE YOUR ACCEPTANCE OF THIS LICENSE TO DO SO, AND
+   ALL ITS TERMS AND CONDITIONS FOR COPYING, DISTRIBUTING OR MODIFYING
+   THE PROGRAM OR WORKS BASED ON IT. NOTHING OTHER THAN THIS LICENSE
+   GRANTS YOU PERMISSION TO MODIFY OR DISTRIBUTE THE PROGRAM OR ITS
+   DERIVATIVE WORKS. THESE ACTIONS ARE PROHIBITED BY LAW. IF YOU DO NOT
+   ACCEPT THESE TERMS AND CONDITIONS, DO NOT MODIFY OR DISTRIBUTE THE
+   PROGRAM. 
+
+1. Licenses.
+
+   Licensor hereby grants you the following rights, provided that you
+   comply with all of the restrictions set forth in this License and
+   provided, further, that you distribute an unmodified copy of this
+   License with the Program:
+   (a)
+          You may copy and distribute literal (i.e., verbatim) copies of
+          the Program's source code as you receive it throughout the
+          world, in any medium.
+   (b)
+          You may modify the Program, create works based on the Program
+          and distribute copies of such throughout the world, in any
+          medium.
+
+2. Restrictions.
+
+   This license is subject to the following restrictions:
+   (a)
+          Distribution of the Program or any work based on the Program by
+          a commercial organization to any third party is prohibited if
+          any payment is made in connection with such distribution,
+          whether directly (as in payment for a copy of the Program) or
+          indirectly (as in payment for some service related to the
+          Program, or payment for some product or service that includes a
+          copy of the Program "without charge"; these are only examples,
+          and not an exhaustive enumeration of prohibited activities).
+          The following methods of distribution involving payment shall
+          not in and of themselves be a violation of this restriction:
+        (i)
+               Posting the Program on a public access information storage
+               and retrieval service for which a fee is received for
+               retrieving information (such as an on-line service),
+               provided that the fee is not content-dependent (i.e., the
+               fee would be the same for retrieving the same volume of
+               information consisting of random data) and that access to
+               the service and to the Program is available independent of
+               any other product or service. An example of a service that
+               does not fall under this section is an on-line service
+               that is operated by a company and that is only available
+               to customers of that company. (This is not an exhaustive
+               enumeration.)
+        (ii)
+               Distributing the Program on removable computer-readable
+               media, provided that the files containing the Program are
+               reproduced entirely and verbatim on such media, that all
+               information on such media be redistributable for
+               non-commercial purposes without charge, and that such
+               media are distributed by themselves (except for
+               accompanying documentation) independent of any other
+               product or service. Examples of such media include CD-ROM,
+               magnetic tape, and optical storage media. (This is not
+               intended to be an exhaustive list.) An example of a
+               distribution that does not fall under this section is a
+               CD-ROM included in a book or magazine. (This is not an
+               exhaustive enumeration.)
+   (b)
+          Activities other than copying, distribution and modification of
+          the Program are not subject to this License and they are
+          outside its scope. Functional use (running) of the Program is
+          not restricted, and any output produced through the use of the
+          Program is subject to this license only if its contents
+          constitute a work based on the Program (independent of having
+          been made by running the Program).
+   (c)
+          You must meet all of the following conditions with respect to
+          any work that you distribute or publish that in whole or in
+          part contains or is derived from the Program or any part
+          thereof ("the Work"):
+        (i)
+               If you have modified the Program, you must cause the Work
+               to carry prominent notices stating that you have modified
+               the Program's files and the date of any change. In each
+               source file that you have modified, you must include a
+               prominent notice that you have modified the file,
+               including your name, your e-mail address (if any), and the
+               date and purpose of the change;
+        (ii)
+               You must cause the Work to be licensed as a whole and at
+               no charge to all third parties under the terms of this
+               License;
+        (iii)
+               If the Work normally reads commands interactively when
+               run, you must cause it, at each time the Work commences
+               operation, to print or display an announcement including
+               an appropriate copyright notice and a notice that there is
+               no warranty (or else, saying that you provide a warranty).
+               Such notice must also state that users may redistribute
+               the Work only under the conditions of this License and
+               tell the user how to view the copy of this License
+               included with the Work. (Exceptions: if the Program is
+               interactive but normally prints or displays such an
+               announcement only at the request of a user, such as in an
+               "About box", the Work is required to print or display the
+               notice only under the same circumstances; if the Program
+               itself is interactive but does not normally print such an
+               announcement, the Work is not required to print an
+               announcement.);
+        (iv)
+               You must accompany the Work with the complete
+               corresponding machine-readable source code, delivered on a
+               medium customarily used for software interchange. The
+               source code for a work means the preferred form of the
+               work for making modifications to it. For an executable
+               work, complete source code means all the source code for
+               all modules it contains, plus any associated interface
+               definition files, plus the scripts used to control
+               compilation and installation of the executable code. If
+               you distribute with the Work any component that is
+               normally distributed (in either source or binary form)
+               with the major components (compiler, kernel, and so on) of
+               the operating system on which the executable runs, you
+               must also distribute the source code of that component if
+               you have it and are allowed to do so;
+        (v)
+               If you distribute any written or printed material at all
+               with the Work, such material must include either a written
+               copy of this License, or a prominent written indication
+               that the Work is covered by this License and written
+               instructions for printing and/or displaying the copy of
+               the License on the distribution medium;
+        (vi)
+               You may not impose any further restrictions on the
+               recipient's exercise of the rights granted herein.
+
+   If distribution of executable or object code is made by offering the
+   equivalent ability to copy from a designated place, then offering
+   equivalent ability to copy the source code from the same place counts
+   as distribution of the source code, even though third parties are not
+   compelled to copy the source code along with the object code.
+
+  3. Reservation of Rights.
+
+   No rights are granted to the Program except as expressly set forth
+   herein. You may not copy, modify, sublicense, or distribute the
+   Program except as expressly provided under this License. Any attempt
+   otherwise to copy, modify, sublicense or distribute the Program is
+   void, and will automatically terminate your rights under this License.
+   However, parties who have received copies, or rights, from you under
+   this License will not have their licenses terminated so long as such
+   parties remain in full compliance.
+
+  4. Other Restrictions.
+
+   If the distribution and/or use of the Program is restricted in certain
+   countries for any reason, Licensor may add an explicit geographical
+   distribution limitation excluding those countries, so that
+   distribution is permitted only in or among countries not thus
+   excluded. In such case, this License incorporates the limitation as if
+   written in the body of this License.
+
+  5. Limitations.
+
+   THE PROGRAM IS PROVIDED TO YOU "AS IS," WITHOUT WARRANTY. THERE IS NO
+   WARRANTY FOR THE PROGRAM, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT
+   NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+   FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.
+   THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS
+   WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
+   ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 
+
+   IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+   WILL LICENSOR, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE
+   THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
+   INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES
+   ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT
+   NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR
+   LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM
+   TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER
+   PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 
+
+  6. General.
+
+   This License is governed by the laws of the State of California,
+   U.S.A., excluding choice of law rules.
+
+   If any part of this License is found to be in conflict with the law,
+   that part shall be interpreted in its broadest meaning consistent with
+   the law, and no other parts of the License shall be affected.
+
+   For United States Government users, the Program is provided with
+   RESTRICTED RIGHTS. If you are a unit or agency of the United States
+   Government or are acquiring the Program for any such unit or agency,
+   the following apply:
+
+     If the unit or agency is the Department of Defense ("DOD"), the
+     Program and its documentation are classified as "commercial
+     computer software" and "commercial computer software documentation"
+     respectively and, pursuant to DFAR Section 227.7202, the Government
+     is acquiring the Program and its documentation in accordance with
+     the terms of this License. If the unit or agency is other than DOD,
+     the Program and its documentation are classified as "commercial
+     computer software" and "commercial computer software documentation"
+     respectively and, pursuant to FAR Section 12.212, the Government is
+     acquiring the Program and its documentation in accordance with the
+     terms of this License.

+ 290 - 0
LICENSE.gpl

@@ -0,0 +1,290 @@
+!! This license applies only to the printer fonts identified in
+!! subdirectory /sys/lib/ghostscript/font.
+
+===================================================================
+GNU GENERAL PUBLIC LICENSE
+
+Version 2, June 1991
+
+Copyright (C) 1989, 1991 Free Software Foundation, Inc. 675 Mass Ave,
+Cambridge, MA 02139, USA. Everyone is permitted to copy and distribute
+verbatim copies of this license document, but changing it is not
+allowed.
+
+Preamble
+
+The licenses for most software are designed to take away your freedom
+to share and change it.  By contrast, the GNU General Public License
+is intended to guarantee your freedom to share and change free
+software--to make sure the software is free for all its users.  This
+General Public License applies to most of the Free Software
+Foundation's software and to any other program whose authors commit to
+using it.  (Some other Free Software Foundation software is covered by
+the GNU Library General Public License instead.)  You can apply it to
+your programs, too.
+
+When we speak of free software, we are referring to freedom, not
+price.  Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+this service if you wish), that you receive source code or can get it
+if you want it, that you can change the software or use pieces of it
+in new free programs; and that you know you can do these things.
+
+To protect your rights, we need to make restrictions that forbid
+anyone to deny you these rights or to ask you to surrender the rights.
+These restrictions translate to certain responsibilities for you if
+you distribute copies of the software, or if you modify it.
+
+For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must give the recipients all the rights that
+you have.  You must make sure that they, too, receive or can get the
+source code.  And you must show them these terms so they know their
+rights.
+
+We protect your rights with two steps: (1) copyright the software, and
+(2) offer you this license which gives you legal permission to copy,
+distribute and/or modify the software.
+
+Also, for each author's protection and ours, we want to make certain
+that everyone understands that there is no warranty for this free
+software.  If the software is modified by someone else and passed on,
+we want its recipients to know that what they have is not the
+original, so that any problems introduced by others will not reflect
+on the original authors' reputations.
+
+Finally, any free program is threatened constantly by software
+patents.  We wish to avoid the danger that redistributors of a free
+program will individually obtain patent licenses, in effect making the
+program proprietary.  To prevent this, we have made it clear that any
+patent must be licensed for everyone's free use or not licensed at
+all.
+
+The precise terms and conditions for copying, distribution and
+modification follow.
+
+GNU GENERAL PUBLIC LICENSE
+TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+0.  This License applies to any program or other work which contains a
+notice placed by the copyright holder saying it may be distributed
+under the terms of this General Public License.  The "Program", below,
+refers to any such program or work, and a "work based on the Program"
+means either the Program or any derivative work under copyright law:
+that is to say, a work containing the Program or a portion of it,
+either verbatim or with modifications and/or translated into another
+language.  (Hereinafter, translation is included without limitation in
+the term "modification".)  Each licensee is addressed as "you".
+
+Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope.  The act of
+running the Program is not restricted, and the output from the Program
+is covered only if its contents constitute a work based on the Program
+(independent of having been made by running the Program).  Whether
+that is true depends on what the Program does.
+
+1.  You may copy and distribute verbatim copies of the Program's
+source code as you receive it, in any medium, provided that you
+conspicuously and appropriately publish on each copy an appropriate
+copyright notice and disclaimer of warranty; keep intact all the
+notices that refer to this License and to the absence of any warranty;
+and give any other recipients of the Program a copy of this License
+along with the Program.
+
+You may charge a fee for the physical act of transferring a copy, and
+you may at your option offer warranty protection in exchange for a
+fee.
+
+2.  You may modify your copy or copies of the Program or any portion
+of it, thus forming a work based on the Program, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+a) You must cause the modified files to carry prominent notices
+stating that you changed the files and the date of any change.
+
+b) You must cause any work that you distribute or publish, that in
+whole or in part contains or is derived from the Program or any part
+thereof, to be licensed as a whole at no charge to all third parties
+under the terms of this License.
+
+c) If the modified program normally reads commands interactively when
+run, you must cause it, when started running for such interactive use
+in the most ordinary way, to print or display an announcement
+including an appropriate copyright notice and a notice that there is
+no warranty (or else, saying that you provide a warranty) and that
+users may redistribute the program under these conditions, and telling
+the user how to view a copy of this License.  (Exception: if the
+Program itself is interactive but does not normally print such an
+announcement, your work based on the Program is not required to print
+an announcement.)
+
+These requirements apply to the modified work as a whole.  If
+identifiable sections of that work are not derived from the Program,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works.  But when you
+distribute the same sections as part of a whole which is a work based
+on the Program, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote
+it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Program.
+
+In addition, mere aggregation of another work not based on the Program
+with the Program (or with a work based on the Program) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+3.  You may copy and distribute the Program (or a work based on it,
+under Section 2) in object code or executable form under the terms of
+Sections 1 and 2 above provided that you also do one of the following:
+
+a) Accompany it with the complete corresponding machine-readable
+source code, which must be distributed under the terms of Sections 1
+and 2 above on a medium customarily used for software interchange; or,
+
+b) Accompany it with a written offer, valid for at least three years,
+to give any third party, for a charge no more than your cost of
+physically performing source distribution, a complete machine-readable
+copy of the corresponding source code, to be distributed under the
+terms of Sections 1 and 2 above on a medium customarily used for
+software interchange; or,
+
+c) Accompany it with the information you received as to the offer to
+distribute corresponding source code.  (This alternative is allowed
+only for noncommercial distribution and only if you received the
+program in object code or executable form with such an offer, in
+accord with Subsection b above.)
+
+The source code for a work means the preferred form of the work for
+making modifications to it.  For an executable work, complete source
+code means all the source code for all modules it contains, plus any
+associated interface definition files, plus the scripts used to
+control compilation and installation of the executable.  However, as a
+special exception, the source code distributed need not include
+anything that is normally distributed (in either source or binary
+form) with the major components (compiler, kernel, and so on) of the
+operating system on which the executable runs, unless that component
+itself accompanies the executable.
+
+If distribution of executable or object code is made by offering
+access to copy from a designated place, then offering equivalent
+access to copy the source code from the same place counts as
+distribution of the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+4.  You may not copy, modify, sublicense, or distribute the Program
+except as expressly provided under this License.  Any attempt
+otherwise to copy, modify, sublicense or distribute the Program is
+void, and will automatically terminate your rights under this License.
+However, parties who have received copies, or rights, from you under
+this License will not have their licenses terminated so long as such
+parties remain in full compliance.
+
+5.  You are not required to accept this License, since you have not
+signed it.  However, nothing else grants you permission to modify or
+distribute the Program or its derivative works.  These actions are
+prohibited by law if you do not accept this License.  Therefore, by
+modifying or distributing the Program (or any work based on the
+Program), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Program or works based on it.
+
+6.  Each time you redistribute the Program (or any work based on the
+Program), the recipient automatically receives a license from the
+original licensor to copy, distribute or modify the Program subject to
+these terms and conditions.  You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties to
+this License.
+
+7.  If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License.  If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Program at all.  For example, if a patent
+license would not permit royalty-free redistribution of the Program by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Program.
+
+If any portion of this section is held invalid or unenforceable under
+any particular circumstance, the balance of the section is intended to
+apply and the section as a whole is intended to apply in other
+circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system, which is
+implemented by public license practices.  Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+8.  If the distribution and/or use of the Program is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Program under this License
+may add an explicit geographical distribution limitation excluding
+those countries, so that distribution is permitted only in or among
+countries not thus excluded.  In such case, this License incorporates
+the limitation as if written in the body of this License.
+
+9.  The Free Software Foundation may publish revised and/or new
+versions of the General Public License from time to time.  Such new
+versions will be similar in spirit to the present version, but may
+differ in detail to address new problems or concerns.
+
+Each version is given a distinguishing version number.  If the Program
+specifies a version number of this License which applies to it and
+"any later version", you have the option of following the terms and
+conditions either of that version or of any later version published by
+the Free Software Foundation.  If the Program does not specify a
+version number of this License, you may choose any version ever
+published by the Free Software Foundation.
+
+10.  If you wish to incorporate parts of the Program into other free
+programs whose distribution conditions are different, write to the
+author to ask for permission.  For software which is copyrighted by
+the Free Software Foundation, write to the Free Software Foundation;
+we sometimes make exceptions for this.  Our decision will be guided by
+the two goals of preserving the free status of all derivatives of our
+free software and of promoting the sharing and reuse of software
+generally.
+
+NO WARRANTY
+
+11.  BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO
+WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
+EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
+OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY
+KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
+PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME
+THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+12.  IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
+WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
+AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU
+FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
+CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
+PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
+RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
+FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF
+SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
+DAMAGES.
+
+END OF TERMS AND CONDITIONS

+ 2 - 0
NOTICE

@@ -0,0 +1,2 @@
+Copyright © 2002 Lucent Technologies Inc.
+All Rights Reserved

+ 0 - 0
amd64/bin/.shutuphg


+ 2 - 0
amd64/bin/ape/psh

@@ -0,0 +1,2 @@
+#!/bin/rc
+exec /rc/bin/ape/psh $*

+ 0 - 0
amd64/bin/auth/.shutuphg


+ 0 - 0
amd64/bin/aux/.shutuphg


+ 0 - 0
amd64/bin/bitsy/bitsyload/.shutuphg


+ 0 - 0
amd64/bin/dial/.shutuphg


+ 0 - 0
amd64/bin/disk/.shutuphg


+ 0 - 0
amd64/bin/fossil/.shutuphg


+ 0 - 0
amd64/bin/fs/.shutuphg


+ 0 - 0
amd64/bin/games/.shutuphg


+ 0 - 0
amd64/bin/ip/.shutuphg


+ 0 - 0
amd64/bin/ip/httpd/.shutuphg


+ 0 - 0
amd64/bin/ndb/.shutuphg


+ 0 - 0
amd64/bin/replica/.shutuphg


+ 0 - 0
amd64/bin/upas/.shutuphg


+ 0 - 0
amd64/bin/usb/.shutuphg


+ 0 - 0
amd64/bin/venti/.shutuphg


+ 80 - 0
amd64/include/ape/float.h

@@ -0,0 +1,80 @@
+#ifndef __FLOAT
+#define __FLOAT
+/* IEEE, default rounding */
+
+#define FLT_ROUNDS	1
+#define FLT_RADIX	2
+
+#define FLT_DIG		6
+#define FLT_EPSILON	1.19209290e-07
+#define FLT_MANT_DIG	24
+#define FLT_MAX		3.40282347e+38
+#define FLT_MAX_10_EXP	38
+#define FLT_MAX_EXP	128
+#define FLT_MIN		1.17549435e-38
+#define FLT_MIN_10_EXP	-37
+#define FLT_MIN_EXP	-125
+
+#define DBL_DIG		15
+#define DBL_EPSILON	2.2204460492503131e-16
+#define DBL_MANT_DIG	53
+#define DBL_MAX		1.797693134862315708145e+308
+#define DBL_MAX_10_EXP	308
+#define DBL_MAX_EXP	1024
+#define DBL_MIN		2.225073858507201383090233e-308
+#define DBL_MIN_10_EXP	-307
+#define DBL_MIN_EXP	-1021
+#define LDBL_MANT_DIG	DBL_MANT_DIG
+#define LDBL_EPSILON	DBL_EPSILON
+#define LDBL_DIG	DBL_DIG
+#define LDBL_MIN_EXP	DBL_MIN_EXP
+#define LDBL_MIN	DBL_MIN
+#define LDBL_MIN_10_EXP	DBL_MIN_10_EXP
+#define LDBL_MAX_EXP	DBL_MAX_EXP
+#define LDBL_MAX	DBL_MAX
+#define LDBL_MAX_10_EXP	DBL_MAX_10_EXP
+
+typedef 	union FPdbleword FPdbleword;
+union FPdbleword
+{
+	double	x;
+	struct {	/* little endian */
+		long lo;
+		long hi;
+	};
+};
+
+#ifdef _RESEARCH_SOURCE
+/* define stuff needed for floating conversion */
+#define IEEE_8087	1
+#define Sudden_Underflow 1
+#endif
+#ifdef _PLAN9_SOURCE
+/* MXCSR */
+/* fcr */
+#define	FPFTZ	(1<<15)	/* amd64 */
+#define	FPINEX	(1<<12)
+#define	FPUNFL	(1<<11)
+#define	FPOVFL	(1<<10)
+#define	FPZDIV	(1<<9)
+#define	FPDNRM	(1<<8)	/* amd64 */
+#define	FPINVAL	(1<<7)
+#define	FPDAZ	(1<<6)	/* amd64 */
+#define	FPRNR	(0<<13)
+#define	FPRZ	(3<<13)
+#define	FPRPINF	(2<<13)
+#define	FPRNINF	(1<<13)
+#define	FPRMASK	(3<<13)
+#define	FPPEXT	0
+#define	FPPSGL	0
+#define	FPPDBL	0
+#define	FPPMASK	0
+/* fsr */
+#define	FPAINEX	(1<<5)
+#define	FPAUNFL	(1<<4)
+#define	FPAOVFL	(1<<3)
+#define	FPAZDIV	(1<<2)
+#define	FPADNRM	(1<<1)	/* not in plan 9 */
+#define	FPAINVAL	(1<<0)
+#endif
+#endif /* __FLOAT */

+ 74 - 0
amd64/include/ape/math.h

@@ -0,0 +1,74 @@
+#ifndef __MATH
+#define __MATH
+#pragma lib "/$M/lib/ape/libap.a"
+
+/* a HUGE_VAL appropriate for IEEE double-precision */
+/* the correct value, 1.797693134862316e+308, causes a ken overflow */
+#define HUGE_VAL 1.79769313486231e+308
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern double acos(double);
+extern double asin(double);
+extern double atan(double);
+extern double atan2(double, double);
+extern double cos(double);
+extern double sin(double);
+extern double tan(double);
+extern double cosh(double);
+extern double sinh(double);
+extern double tanh(double);
+extern double exp(double);
+extern double frexp(double, int *);
+extern double ldexp(double, int);
+extern double log(double);
+extern double log10(double);
+extern double modf(double, double *);
+extern double pow(double, double);
+extern double sqrt(double);
+extern double ceil(double);
+extern double fabs(double);
+extern double floor(double);
+extern double fmod(double, double);
+extern double NaN(void);
+extern int isNaN(double);
+extern double Inf(int);
+extern int isInf(double, int);
+
+#ifdef _RESEARCH_SOURCE
+/* does >> treat left operand as unsigned ? */
+#define Unsigned_Shifts 1
+#define	M_E		2.7182818284590452354	/* e */
+#define	M_LOG2E		1.4426950408889634074	/* log 2e */
+#define	M_LOG10E	0.43429448190325182765	/* log 10e */
+#define	M_LN2		0.69314718055994530942	/* log e2 */
+#define	M_LN10		2.30258509299404568402	/* log e10 */
+#define	M_PI		3.14159265358979323846	/* pi */
+#define	M_PI_2		1.57079632679489661923	/* pi/2 */
+#define	M_PI_4		0.78539816339744830962	/* pi/4 */
+#define	M_1_PI		0.31830988618379067154	/* 1/pi */
+#define	M_2_PI		0.63661977236758134308	/* 2/pi */
+#define	M_2_SQRTPI	1.12837916709551257390	/* 2/sqrt(pi) */
+#define	M_SQRT2		1.41421356237309504880	/* sqrt(2) */
+#define	M_SQRT1_2	0.70710678118654752440	/* 1/sqrt(2) */
+
+extern double hypot(double, double);
+extern double erf(double);
+extern double erfc(double);
+extern double j0(double);
+extern double y0(double);
+extern double j1(double);
+extern double y1(double);
+extern double jn(int, double);
+extern double yn(int, double);
+
+#endif
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __MATH */

+ 18 - 0
amd64/include/ape/stdarg.h

@@ -0,0 +1,18 @@
+#ifndef __STDARG
+#define __STDARG
+
+typedef char *va_list;
+
+#define va_start(list, start) list = (sizeof(start)<8 ? (char *)((long long *)&(start)+1) : \
+(char *)(&(start)+1))
+#define va_end(list)
+#define va_arg(list, mode)\
+	((sizeof(mode) == 1)?\
+		((mode*)(list += 8))[-8]:\
+	(sizeof(mode) == 2)?\
+		((mode*)(list += 8))[-4]:\
+	(sizeof(mode) == 4)?\
+		((mode*)(list += 8))[-2]:\
+		((mode*)(list += sizeof(mode)))[-1])
+
+#endif /* __STDARG */

+ 38 - 0
amd64/include/ape/ureg.h

@@ -0,0 +1,38 @@
+#ifndef __UREG_H
+#define __UREG_H
+#if !defined(_PLAN9_SOURCE)
+    This header file is an extension to ANSI/POSIX
+#endif
+
+struct Ureg {
+	unsigned long long	ax;
+	unsigned long long	bx;
+	unsigned long long	cx;
+	unsigned long long	dx;
+	unsigned long long	si;
+	unsigned long long	di;
+	unsigned long long	bp;
+	unsigned long long	r8;
+	unsigned long long	r9;
+	unsigned long long	r10;
+	unsigned long long	r11;
+	unsigned long long	r12;
+	unsigned long long	r13;
+	unsigned long long	r14;
+	unsigned long long	r15;
+
+	unsigned short		ds;
+	unsigned short		es;
+	unsigned short		fs;
+	unsigned short		gs;
+
+	unsigned long long	type;
+	unsigned long long	error;		/* error code (or zero) */
+	unsigned long long	ip;		/* pc */
+	unsigned long long	cs;		/* old context */
+	unsigned long long	flags;		/* old flags */
+	unsigned long long	sp;		/* sp */
+	unsigned long long	ss;		/* old stack segment */
+};
+
+#endif

+ 72 - 0
amd64/include/u.h

@@ -0,0 +1,72 @@
+#define nil		((void*)0)
+typedef	unsigned short	ushort;
+typedef	unsigned char	uchar;
+typedef unsigned long	ulong;
+typedef unsigned int	uint;
+typedef   signed char	schar;
+typedef	long long	vlong;
+typedef	unsigned long long uvlong;
+typedef unsigned long long uintptr;
+typedef unsigned long	usize;
+typedef	ushort		Rune;
+typedef union FPdbleword FPdbleword;
+typedef uvlong		jmp_buf[2];
+#define	JMPBUFSP	0
+#define	JMPBUFPC	1
+#define	JMPBUFDPC	0
+typedef unsigned int	mpdigit;	/* for /sys/include/mp.h */
+typedef unsigned char	u8int;
+typedef unsigned short	u16int;
+typedef unsigned int	u32int;
+typedef unsigned long long u64int;
+
+/* MXCSR */
+/* fcr */
+#define	FPFTZ	(1<<15)	/* amd64 */
+#define	FPINEX	(1<<12)
+#define	FPUNFL	(1<<11)
+#define	FPOVFL	(1<<10)
+#define	FPZDIV	(1<<9)
+#define	FPDNRM	(1<<8)	/* amd64 */
+#define	FPINVAL	(1<<7)
+#define	FPDAZ	(1<<6)	/* amd64 */
+#define	FPRNR	(0<<13)
+#define	FPRZ	(3<<13)
+#define	FPRPINF	(2<<13)
+#define	FPRNINF	(1<<13)
+#define	FPRMASK	(3<<13)
+#define	FPPEXT	0
+#define	FPPSGL	0
+#define	FPPDBL	0
+#define	FPPMASK	0
+/* fsr */
+#define	FPAINEX	(1<<5)
+#define	FPAUNFL	(1<<4)
+#define	FPAOVFL	(1<<3)
+#define	FPAZDIV	(1<<2)
+#define	FPADNRM	(1<<1)	/* not in plan 9 */
+#define	FPAINVAL	(1<<0)
+union FPdbleword
+{
+	double	x;
+	struct {	/* little endian */
+		uint lo;
+		uint hi;
+	};
+};
+
+typedef	char*	va_list;
+#define va_start(list, start) list =\
+	(sizeof(start) < 8?\
+		(char*)((vlong*)&(start)+1):\
+		(char*)(&(start)+1))
+#define va_end(list)\
+	USED(list)
+#define va_arg(list, mode)\
+	((sizeof(mode) == 1)?\
+		((list += 8), (mode*)list)[-8]:\
+	(sizeof(mode) == 2)?\
+		((list += 8), (mode*)list)[-4]:\
+	(sizeof(mode) == 4)?\
+		((list += 8), (mode*)list)[-2]:\
+		((list += sizeof(mode)), (mode*)list)[-1])

+ 30 - 0
amd64/include/ureg.h

@@ -0,0 +1,30 @@
+struct Ureg {
+	u64int	ax;
+	u64int	bx;
+	u64int	cx;
+	u64int	dx;
+	u64int	si;
+	u64int	di;
+	u64int	bp;
+	u64int	r8;
+	u64int	r9;
+	u64int	r10;
+	u64int	r11;
+	u64int	r12;
+	u64int	r13;
+	u64int	r14;
+	u64int	r15;
+
+	u16int	ds;
+	u16int	es;
+	u16int	fs;
+	u16int	gs;
+
+	u64int	type;
+	u64int	error;				/* error code (or zero) */
+	u64int	ip;				/* pc */
+	u64int	cs;				/* old context */
+	u64int	flags;				/* old flags */
+	u64int	sp;				/* sp */
+	u64int	ss;				/* old stack segment */
+};

+ 0 - 0
amd64/lib/.shutuphg


+ 0 - 0
amd64/lib/ape/.shutuphg


+ 7 - 0
amd64/mkfile

@@ -0,0 +1,7 @@
+</sys/src/mkfile.proto
+
+CC=6c
+GC=6g
+LD=6l
+O=6
+AS=6a

+ 254 - 0
sys/include/9p.h

@@ -0,0 +1,254 @@
+#pragma src "/sys/src/lib9p"
+#pragma lib "lib9p.a"
+
+/*
+ * Maps from ulongs to void*s.
+ */
+typedef struct Intmap	Intmap;
+
+#pragma incomplete Intmap
+
+Intmap*	allocmap(void (*inc)(void*));
+void		freemap(Intmap*, void (*destroy)(void*));
+void*	lookupkey(Intmap*, ulong);
+void*	insertkey(Intmap*, ulong, void*);
+int		caninsertkey(Intmap*, ulong, void*);
+void*	deletekey(Intmap*, ulong);
+
+/*
+ * Fid and Request structures.
+ */
+typedef struct Fid		Fid;
+typedef struct Req		Req;
+typedef struct Fidpool	Fidpool;
+typedef struct Reqpool	Reqpool;
+typedef struct File		File;
+typedef struct Filelist	Filelist;
+typedef struct Tree		Tree;
+typedef struct Readdir	Readdir;
+typedef struct Srv Srv;
+
+#pragma incomplete Filelist
+#pragma incomplete Readdir
+
+struct Fid
+{
+	ulong	fid;
+	char		omode;	/* -1 = not open */
+	File*		file;
+	char*	uid;
+	Qid		qid;
+	void*	aux;
+
+/* below is implementation-specific; don't use */
+	Readdir*	rdir;
+	Ref		ref;
+	Fidpool*	pool;
+	vlong	diroffset;
+	long		dirindex;
+};
+
+struct Req
+{
+	ulong	tag;
+	void*	aux;
+	Fcall		ifcall;
+	Fcall		ofcall;
+	Dir		d;
+	Req*		oldreq;
+	Fid*		fid;
+	Fid*		afid;
+	Fid*		newfid;
+	Srv*		srv;
+
+/* below is implementation-specific; don't use */
+	QLock	lk;
+	Ref		ref;
+	Reqpool*	pool;
+	uchar*	buf;
+	uchar	type;
+	uchar	responded;
+	char*	error;
+	void*	rbuf;
+	Req**	flush;
+	int		nflush;
+};
+
+/*
+ * Pools to maintain Fid <-> fid and Req <-> tag maps.
+ */
+
+struct Fidpool {
+	Intmap	*map;
+	void		(*destroy)(Fid*);
+	Srv		*srv;
+};
+
+struct Reqpool {
+	Intmap	*map;
+	void		(*destroy)(Req*);
+	Srv		*srv;
+};
+
+Fidpool*	allocfidpool(void (*destroy)(Fid*));
+void		freefidpool(Fidpool*);
+Fid*		allocfid(Fidpool*, ulong);
+Fid*		lookupfid(Fidpool*, ulong);
+void		closefid(Fid*);
+Fid*		removefid(Fidpool*, ulong);
+
+Reqpool*	allocreqpool(void (*destroy)(Req*));
+void		freereqpool(Reqpool*);
+Req*		allocreq(Reqpool*, ulong);
+Req*		lookupreq(Reqpool*, ulong);
+void		closereq(Req*);
+Req*		removereq(Reqpool*, ulong);
+
+typedef	int	Dirgen(int, Dir*, void*);
+void		dirread9p(Req*, Dirgen*, void*);
+
+/*
+ * File trees.
+ */
+struct File {
+	Ref;
+	Dir;
+	File *parent;
+	void *aux;
+
+/* below is implementation-specific; don't use */
+	RWLock;
+	Filelist *filelist;
+	Tree *tree;
+	int nchild;
+	int allocd;
+	int nxchild;
+	Ref readers;
+};
+
+struct Tree {
+	File *root;
+	void	(*destroy)(File *file);
+
+/* below is implementation-specific; don't use */
+	Lock genlock;
+	ulong qidgen;
+	ulong dirqidgen;
+};
+
+Tree*	alloctree(char*, char*, ulong, void(*destroy)(File*));
+void		freetree(Tree*);
+File*		createfile(File*, char*, char*, ulong, void*);
+int		removefile(File*);
+void		closefile(File*);
+File*		walkfile(File*, char*);
+Readdir*	opendirfile(File*);
+long		readdirfile(Readdir*, uchar*, long);
+void		closedirfile(Readdir*);
+
+/*
+ * Kernel-style command parser
+ */
+typedef struct Cmdbuf Cmdbuf;
+typedef struct Cmdtab Cmdtab;
+Cmdbuf*		parsecmd(char *a, int n);
+void		respondcmderror(Req*, Cmdbuf*, char*, ...);
+Cmdtab*	lookupcmd(Cmdbuf*, Cmdtab*, int);
+#pragma varargck argpos respondcmderr 3
+struct Cmdbuf
+{
+	char	*buf;
+	char	**f;
+	int	nf;
+};
+
+struct Cmdtab
+{
+	int	index;	/* used by client to switch on result */
+	char	*cmd;	/* command name */
+	int	narg;	/* expected #args; 0 ==> variadic */
+};
+
+/*
+ * File service loop.
+ */
+struct Srv {
+	Tree*	tree;
+	void		(*destroyfid)(Fid*);
+	void		(*destroyreq)(Req*);
+	void		(*start)(Srv*);
+	void		(*end)(Srv*);
+	void*	aux;
+
+	void		(*attach)(Req*);
+	void		(*auth)(Req*);
+	void		(*open)(Req*);
+	void		(*create)(Req*);
+	void		(*read)(Req*);
+	void		(*write)(Req*);
+	void		(*remove)(Req*);
+	void		(*flush)(Req*);
+	void		(*stat)(Req*);
+	void		(*wstat)(Req*);
+	void		(*walk)(Req*);
+	char*	(*clone)(Fid*, Fid*);
+	char*	(*walk1)(Fid*, char*, Qid*);
+
+	int		infd;
+	int		outfd;
+	int		nopipe;
+	int		srvfd;
+	int		leavefdsopen;	/* magic for acme win */
+	char*	keyspec;
+
+/* below is implementation-specific; don't use */
+	Fidpool*	fpool;
+	Reqpool*	rpool;
+	uint		msize;
+
+	uchar*	rbuf;
+	QLock	rlock;
+	uchar*	wbuf;
+	QLock	wlock;
+	
+	char*	addr;
+};
+
+void		srv(Srv*);
+void		postmountsrv(Srv*, char*, char*, int);
+void		_postmountsrv(Srv*, char*, char*, int);
+void		listensrv(Srv*, char*);
+void		_listensrv(Srv*, char*);
+int 		postfd(char*, int);
+int		chatty9p;
+void		respond(Req*, char*);
+void		responderror(Req*);
+void		threadpostmountsrv(Srv*, char*, char*, int);
+void		threadlistensrv(Srv *s, char *addr);
+
+/*
+ * Helper.  Assumes user is same as group.
+ */
+int		hasperm(File*, char*, int);
+
+void*	emalloc9p(ulong);
+void*	erealloc9p(void*, ulong);
+char*	estrdup9p(char*);
+
+enum {
+	OMASK = 3
+};
+
+void		readstr(Req*, char*);
+void		readbuf(Req*, void*, long);
+void		walkandclone(Req*, char*(*walk1)(Fid*,char*,void*), 
+			char*(*clone)(Fid*,Fid*,void*), void*);
+
+void		auth9p(Req*);
+void		authread(Req*);
+void		authwrite(Req*);
+void		authdestroy(Fid*);
+int		authattach(Req*);
+
+extern void (*_forker)(void (*)(void*), void*, int);
+

+ 45 - 0
sys/include/String.h

@@ -0,0 +1,45 @@
+#pragma	src	"/sys/src/libString"
+#pragma	lib	"libString.a"
+
+/* extensible Strings */
+typedef struct String {
+	Lock;
+	char	*base;	/* base of String */
+	char	*end;	/* end of allocated space+1 */
+	char	*ptr;	/* ptr into String */
+	short	ref;
+	uchar	fixed;
+} String;
+
+#define s_clone(s) s_copy((s)->base)
+#define s_to_c(s) ((s)->base)
+#define s_len(s) ((s)->ptr-(s)->base)
+
+extern String*	s_append(String*, char*);
+extern String*	s_array(char*, int);
+extern String*	s_copy(char*);
+extern void	s_free(String*);
+extern String*	s_incref(String*);	
+extern String*	s_memappend(String*, char*, int);
+extern String*	s_nappend(String*, char*, int);
+extern String*	s_new(void);
+extern String*	s_newalloc(int);
+extern String*	s_parse(String*, String*);
+extern String*	s_reset(String*);
+extern String*	s_restart(String*);
+extern void	s_terminate(String*);
+extern void	s_tolower(String*);
+extern void	s_putc(String*, int);
+extern String*	s_unique(String*);
+extern String*	s_grow(String*, int);
+
+#ifdef BGETC
+extern int	s_read(Biobuf*, String*, int);
+extern char	*s_read_line(Biobuf*, String*);
+extern char	*s_getline(Biobuf*, String*);
+typedef struct Sinstack Sinstack;
+#pragma incomplete Sinstack
+extern char	*s_rdinstack(Sinstack*, String*);
+extern Sinstack	*s_allocinstack(char*);
+extern void	s_freeinstack(Sinstack*);
+#endif /* BGETC */

+ 46 - 0
sys/include/a.out.h

@@ -0,0 +1,46 @@
+typedef	struct	Exec	Exec;
+struct	Exec
+{
+	long	magic;		/* magic number */
+	long	text;	 	/* size of text segment */
+	long	data;	 	/* size of initialized data */
+	long	bss;	  	/* size of uninitialized data */
+	long	syms;	 	/* size of symbol table */
+	long	entry;	 	/* entry point */
+	long	spsz;		/* size of pc/sp offset table */
+	long	pcsz;		/* size of pc/line number table */
+};
+
+#define HDR_MAGIC	0x00008000		/* header expansion */
+
+#define	_MAGIC(f, b)	((f)|((((4*(b))+0)*(b))+7))
+#define	A_MAGIC		_MAGIC(0, 8)		/* 68020 */
+#define	I_MAGIC		_MAGIC(0, 11)		/* intel 386 */
+#define	J_MAGIC		_MAGIC(0, 12)		/* intel 960 (retired) */
+#define	K_MAGIC		_MAGIC(0, 13)		/* sparc */
+#define	V_MAGIC		_MAGIC(0, 16)		/* mips 3000 BE */
+#define	X_MAGIC		_MAGIC(0, 17)		/* att dsp 3210 (retired) */
+#define	M_MAGIC		_MAGIC(0, 18)		/* mips 4000 BE */
+#define	D_MAGIC		_MAGIC(0, 19)		/* amd 29000 (retired) */
+#define	E_MAGIC		_MAGIC(0, 20)		/* arm */
+#define	Q_MAGIC		_MAGIC(0, 21)		/* powerpc */
+#define	N_MAGIC		_MAGIC(0, 22)		/* mips 4000 LE */
+#define	L_MAGIC		_MAGIC(0, 23)		/* dec alpha */
+#define	P_MAGIC		_MAGIC(0, 24)		/* mips 3000 LE */
+#define	U_MAGIC		_MAGIC(0, 25)		/* sparc64 */
+#define	S_MAGIC		_MAGIC(HDR_MAGIC, 26)	/* amd64 */
+#define	T_MAGIC		_MAGIC(HDR_MAGIC, 27)	/* powerpc64 */
+
+#define	MIN_MAGIC	8
+#define	MAX_MAGIC	27			/* <= 90 */
+
+#define	DYN_MAGIC	0x80000000		/* dlm */
+
+typedef	struct	Sym	Sym;
+struct	Sym
+{
+	vlong	value;
+	uint	sig;
+	char	type;
+	char	*name;
+};

+ 20 - 0
sys/include/ape/Plan9libnet.h

@@ -0,0 +1,20 @@
+#ifndef __LIBNET_H
+#define __LIBNET_H
+#ifndef _NET_EXTENSION
+   This header file is not defined in ANSI or POSIX
+#endif
+#pragma lib "/$M/lib/ape/libnet.a"
+
+#define NETPATHLEN 40
+
+extern	int	accept(int, char*);
+extern	int	announce(char*, char*);
+extern	int	dial(char*, char*, char*, int*);
+extern	int	hangup(int);
+extern	int	listen(char*, char*);
+extern	char*	netmkaddr(char*, char*, char*);
+extern	int	reject(int, char*, char *);
+
+extern char    dialerrstr[64];
+
+#endif /* __LIBNET_H */

+ 24 - 0
sys/include/ape/ar.h

@@ -0,0 +1,24 @@
+#ifndef __AR_H
+#define __AR_H
+#ifndef _RESEARCH_SOURCE
+   This header file is not defined in ANSI or POSIX
+#endif
+
+#define	ARMAG	"!<arch>\n"
+#define	SARMAG	8
+
+#define	ARFMAG	"`\n"
+
+struct	ar_hdr
+{
+	char	ar_name[16];
+	char	ar_date[12];
+	char	ar_uid[6];
+	char	ar_gid[6];
+	char	ar_mode[8];
+	char	ar_size[10];
+	char	ar_fmag[2];
+};
+#define	SAR_HDR	60
+
+#endif

+ 146 - 0
sys/include/ape/arpa/inet.h

@@ -0,0 +1,146 @@
+#ifndef __netinet_in__
+#define __netinet_in__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * Copyright (c) 1982, 1986, 1990 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution is only permitted until one year after the first shipment
+ * of 4.4BSD by the Regents.  Otherwise, redistribution and use in source and
+ * binary forms are permitted provided that: (1) source distributions retain
+ * this entire copyright notice and comment, and (2) distributions including
+ * binaries display the following acknowledgement:  This product includes
+ * software developed by the University of California, Berkeley and its
+ * contributors'' in the documentation or other materials provided with the
+ * distribution and in all advertising materials mentioning features or use
+ * of this software.  Neither the name of the University nor the names of
+ * its contributors may 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.
+ *
+ *	@(#)in.h	7.10 (Berkeley) 6/28/90 plus MULTICAST 1.1
+ */
+
+/*
+ * Constants and structures defined by the internet system,
+ * Per RFC 790, September 1981.
+ */
+
+/*
+ * Protocols
+ */
+#define	IPPROTO_IP		0		/* dummy for IP */
+#define	IPPROTO_ICMP		1		/* control message protocol */
+#define	IPPROTO_GGP		3		/* gateway^2 (deprecated) */
+#define	IPPROTO_TCP		6		/* tcp */
+#define	IPPROTO_EGP		8		/* exterior gateway protocol */
+#define	IPPROTO_PUP		12		/* pup */
+#define	IPPROTO_UDP		17		/* user datagram protocol */
+#define	IPPROTO_IDP		22		/* xns idp */
+#define	IPPROTO_TP		29 		/* tp-4 w/ class negotiation */
+#define	IPPROTO_EON		80		/* ISO cnlp */
+
+#define	IPPROTO_RAW		255		/* raw IP packet */
+#define	IPPROTO_MAX		256
+
+
+/*
+ * Local port number conventions:
+ * Ports < IPPORT_RESERVED are reserved for
+ * privileged processes (e.g. root).
+ * Ports > IPPORT_USERRESERVED are reserved
+ * for servers, not necessarily privileged.
+ */
+#define	IPPORT_RESERVED		1024
+#define	IPPORT_USERRESERVED	5000
+
+/*
+ * Internet address (a structure for historical reasons)
+ */
+struct in_addr {
+	unsigned long s_addr;
+};
+
+/*
+ * Definitions of bits in internet address integers.
+ * On subnets, the decomposition of addresses to host and net parts
+ * is done according to subnet mask, not the masks here.
+ */
+#define	IN_CLASSA(i)		(((long)(i) & 0x80000000) == 0)
+#define	IN_CLASSA_NET		0xff000000
+#define	IN_CLASSA_NSHIFT	24
+#define	IN_CLASSA_HOST		0x00ffffff
+#define	IN_CLASSA_MAX		128
+
+#define	IN_CLASSB(i)		(((long)(i) & 0xc0000000) == 0x80000000)
+#define	IN_CLASSB_NET		0xffff0000
+#define	IN_CLASSB_NSHIFT	16
+#define	IN_CLASSB_HOST		0x0000ffff
+#define	IN_CLASSB_MAX		65536
+
+#define	IN_CLASSC(i)		(((long)(i) & 0xe0000000) == 0xc0000000)
+#define	IN_CLASSC_NET		0xffffff00
+#define	IN_CLASSC_NSHIFT	8
+#define	IN_CLASSC_HOST		0x000000ff
+
+#define	IN_CLASSD(i)		(((long)(i) & 0xf0000000) == 0xe0000000)
+#define	IN_MULTICAST(i)		IN_CLASSD(i)
+
+#define	IN_EXPERIMENTAL(i)	(((long)(i) & 0xe0000000) == 0xe0000000)
+#define	IN_BADCLASS(i)		(((long)(i) & 0xf0000000) == 0xf0000000)
+
+#define	INADDR_ANY		(unsigned long)0x00000000
+#define	INADDR_BROADCAST	(unsigned long)0xffffffff	/* must be masked */
+
+#define	IN_LOOPBACKNET		127			/* official! */
+
+/*
+ * Socket address, internet style.
+ */
+struct sockaddr_in {
+	short	sin_family;
+	unsigned short	sin_port;
+	struct	in_addr sin_addr;
+	char	sin_zero[8];
+};
+
+/*
+ * Structure used to describe IP options.
+ * Used to store options internally, to pass them to a process,
+ * or to restore options retrieved earlier.
+ * The ip_dst is used for the first-hop gateway when using a source route
+ * (this gets put into the header proper).
+ */
+struct ip_opts {
+	struct	in_addr ip_dst;		/* first hop, 0 w/o src rt */
+	char	ip_opts[40];		/* actually variable in size */
+};
+
+/*
+ * Options for use with [gs]etsockopt at the IP level.
+ * First word of comment is data type; bool is stored in int.
+ */
+#define	IP_OPTIONS	1	/* buf/ip_opts; set/get IP per-packet options */
+#define	IP_HDRINCL	7	/* int; header is included with data (raw) */
+#define	IP_TOS		8	/* int; IP type of service and precedence */
+#define	IP_TTL		9	/* int; IP time to live */
+
+extern unsigned long	ntohl(unsigned long x);
+extern unsigned short	ntohs(unsigned short x);
+extern unsigned long	htonl(unsigned long x);
+extern unsigned short	htons(unsigned short x);
+extern unsigned long	inet_addr(char*);
+extern char*		inet_ntoa(struct in_addr);
+extern unsigned long	nptohl(void*);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __netinet_in__ */

+ 17 - 0
sys/include/ape/assert.h

@@ -0,0 +1,17 @@
+#pragma lib "/$M/lib/ape/libap.a"
+
+#undef assert
+#ifdef NDEBUG
+#define assert(ignore) ((void)0)
+#else
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern void _assert(char *, unsigned);
+
+#ifdef __cplusplus
+}
+#endif
+#define assert(e) {if(!(e))_assert(__FILE__, __LINE__);}
+#endif /* NDEBUG */

+ 56 - 0
sys/include/ape/bsd.h

@@ -0,0 +1,56 @@
+#ifndef _BSD_EXTENSION
+    This header file is an extension to ANSI/POSIX
+#endif
+
+#ifndef __BSD_H_
+#define __BSD_H_
+#pragma src "/sys/src/ape/lib/bsd"
+#pragma lib "/$M/lib/ape/libbsd.a"
+
+#ifndef __TYPES_H
+#include <sys/types.h>
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifndef _SIZE_T
+#define _SIZE_T
+typedef unsigned long size_t;
+#endif
+
+/* ifndefs because X11 stuff (ugh) */
+#ifndef bcopy
+extern void	bcopy(void*, void*, size_t);
+#endif
+#ifndef bcmp
+extern int	bcmp(void*, void*, size_t);
+#endif
+#ifndef bzero
+extern void	bzero(void*, size_t);
+#endif
+extern int	ffs(unsigned int);
+extern void	bhappy(void*);
+extern int	rresvport(int*);
+extern int	rcmd(char**, int, char*, char*, char*, int*);
+extern char*	strdup(char*);
+extern int	strcasecmp(char*, char*);
+extern int 	putenv(char*);
+extern int	strncasecmp(char*, char*,int);
+extern void* memccpy(void*, void*, int, size_t);
+
+extern int	getopt(int, char**, char*);
+extern int	opterr;
+extern int	optind;
+extern int	optopt;
+extern char	*optarg;
+extern char	*mktemp(char *);
+extern char	*sys_errlist[];
+extern int		sys_nerr;
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif

+ 55 - 0
sys/include/ape/ctype.h

@@ -0,0 +1,55 @@
+#ifndef __CTYPE
+#define __CTYPE
+#pragma lib "/$M/lib/ape/libap.a"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern int isalnum(int);
+extern int isalpha(int);
+extern int iscntrl(int);
+extern int isdigit(int);
+extern int isgraph(int);
+extern int islower(int);
+extern int isprint(int);
+extern int ispunct(int);
+extern int isspace(int);
+extern int isupper(int);
+extern int isxdigit(int);
+extern int tolower(int);
+extern int toupper(int);
+
+#ifdef __cplusplus
+}
+#endif
+enum
+{
+  _ISupper = 01,	/* UPPERCASE.  */
+  _ISlower = 02,	/* lowercase.  */
+  _ISdigit = 04,	/* Numeric.  */
+  _ISspace = 010,	/* Whitespace.  */
+  _ISpunct = 020,	/* Punctuation.  */
+  _IScntrl = 040,	/* Control character.  */
+  _ISblank = 0100,	/* Blank (usually SPC and TAB).  */
+  _ISxdigit = 0200,	/* Hexadecimal numeric.  */
+};
+
+extern unsigned char _ctype[];
+#define	isalnum(c)	(_ctype[(unsigned char)(c)]&(_ISupper|_ISlower|_ISdigit))
+#define	isalpha(c)	(_ctype[(unsigned char)(c)]&(_ISupper|_ISlower))
+#define	iscntrl(c)	(_ctype[(unsigned char)(c)]&_IScntrl)
+#define	isdigit(c)	(_ctype[(unsigned char)(c)]&_ISdigit)
+#define	isgraph(c)	(_ctype[(unsigned char)(c)]&(_ISpunct|_ISupper|_ISlower|_ISdigit))
+#define	islower(c)	(_ctype[(unsigned char)(c)]&_ISlower)
+#define	isprint(c)	(_ctype[(unsigned char)(c)]&(_ISpunct|_ISupper|_ISlower|_ISdigit|_ISblank))
+#define	ispunct(c)	(_ctype[(unsigned char)(c)]&_ISpunct)
+#define	isspace(c)	(_ctype[(unsigned char)(c)]&_ISspace)
+#define	isupper(c)	(_ctype[(unsigned char)(c)]&_ISupper)
+#define	isxdigit(c)	(_ctype[(unsigned char)(c)]&_ISxdigit)
+
+#ifdef _BSD_EXTENSION
+#define	isascii(c) (((unsigned int)(c))<0x80)
+#endif
+
+#endif /* __CTYPE */

+ 10 - 0
sys/include/ape/cursor.h

@@ -0,0 +1,10 @@
+#ifndef _PLAN9_SOURCE
+  This header file is an extension to ANSI/POSIX
+#endif
+
+#ifndef	__CURSOR_H_
+#define	__CURSOR_H_
+#include "/sys/include/cursor.h"
+
+#endif
+

+ 40 - 0
sys/include/ape/dirent.h

@@ -0,0 +1,40 @@
+#ifndef	__DIRENT_H
+#define	__DIRENT_H
+#pragma lib "/$M/lib/ape/libap.a"
+/*
+ * this must be a power of 2 and a multiple of all the ones in the system
+ */
+#define MAXNAMLEN 255
+
+struct	dirent {
+	char	d_name[MAXNAMLEN + 1];
+};
+
+typedef struct _dirdesc {
+	int	dd_fd;		/* file descriptor */
+	long	dd_loc;		/* buf offset of entry from last readdir() */
+	long	dd_size;	/* amount of valid data in buffer */
+	char	*dd_buf;	/* directory data buffer */
+	void *dirs;
+	int	dirsize;
+	int	dirloc;
+} DIR;
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * functions defined on directories
+ */
+DIR		*opendir(const char *);
+struct dirent	*readdir(DIR *);
+void		rewinddir(DIR *);
+int		closedir(DIR *);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif

+ 539 - 0
sys/include/ape/draw.h

@@ -0,0 +1,539 @@
+#ifndef _PLAN9_SOURCE
+  This header file is an extension to ANSI/POSIX
+#endif
+
+#ifndef	__DRAW_H_
+#define	__DRAW_H_
+#pragma src "/sys/src/ape/lib/draw"
+#pragma lib "/$M/lib/ape/libdraw.a"
+
+#include <u.h>
+#include <fmt.h>
+#include <qlock.h>
+
+typedef struct	Cachefont Cachefont;
+typedef struct	Cacheinfo Cacheinfo;
+typedef struct	Cachesubf Cachesubf;
+typedef struct	Display Display;
+typedef struct	Font Font;
+typedef struct	Fontchar Fontchar;
+typedef struct	Image Image;
+typedef struct	Mouse Mouse;
+typedef struct	Point Point;
+typedef struct	Rectangle Rectangle;
+typedef struct	RGB RGB;
+typedef struct	Screen Screen;
+typedef struct	Subfont Subfont;
+
+#pragma varargck	type	"R"	Rectangle
+#pragma varargck	type	"P"	Point
+extern	int	Rfmt(Fmt*);
+extern	int	Pfmt(Fmt*);
+
+enum
+{
+	DOpaque		= 0xFFFFFFFF,
+	DTransparent	= 0x00000000,		/* only useful for allocimage, memfillcolor */
+	DBlack		= 0x000000FF,
+	DWhite		= 0xFFFFFFFF,
+	DRed		= 0xFF0000FF,
+	DGreen		= 0x00FF00FF,
+	DBlue		= 0x0000FFFF,
+	DCyan		= 0x00FFFFFF,
+	DMagenta		= 0xFF00FFFF,
+	DYellow		= 0xFFFF00FF,
+	DPaleyellow	= 0xFFFFAAFF,
+	DDarkyellow	= 0xEEEE9EFF,
+	DDarkgreen	= 0x448844FF,
+	DPalegreen	= 0xAAFFAAFF,
+	DMedgreen	= 0x88CC88FF,
+	DDarkblue	= 0x000055FF,
+	DPalebluegreen= 0xAAFFFFFF,
+	DPaleblue		= 0x0000BBFF,
+	DBluegreen	= 0x008888FF,
+	DGreygreen	= 0x55AAAAFF,
+	DPalegreygreen	= 0x9EEEEEFF,
+	DYellowgreen	= 0x99994CFF,
+	DMedblue		= 0x000099FF,
+	DGreyblue	= 0x005DBBFF,
+	DPalegreyblue	= 0x4993DDFF,
+	DPurpleblue	= 0x8888CCFF,
+
+	DNotacolor	= 0xFFFFFF00,
+	DNofill		= DNotacolor,
+	
+};
+
+enum
+{
+	Displaybufsize	= 8000,
+	ICOSSCALE	= 1024,
+	Borderwidth =	4,
+};
+
+enum
+{
+	/* refresh methods */
+	Refbackup	= 0,
+	Refnone		= 1,
+	Refmesg		= 2
+};
+#define	NOREFRESH	((void*)-1)
+
+enum
+{
+	/* line ends */
+	Endsquare	= 0,
+	Enddisc		= 1,
+	Endarrow	= 2,
+	Endmask		= 0x1F
+};
+
+#define	ARROW(a, b, c)	(Endarrow|((a)<<5)|((b)<<14)|((c)<<23))
+
+typedef enum
+{
+	/* Porter-Duff compositing operators */
+	Clear	= 0,
+
+	SinD	= 8,
+	DinS	= 4,
+	SoutD	= 2,
+	DoutS	= 1,
+
+	S		= SinD|SoutD,
+	SoverD	= SinD|SoutD|DoutS,
+	SatopD	= SinD|DoutS,
+	SxorD	= SoutD|DoutS,
+
+	D		= DinS|DoutS,
+	DoverS	= DinS|DoutS|SoutD,
+	DatopS	= DinS|SoutD,
+	DxorS	= DoutS|SoutD,	/* == SxorD */
+
+	Ncomp = 12,
+} Drawop;
+
+/*
+ * image channel descriptors 
+ */
+enum {
+	CRed = 0,
+	CGreen,
+	CBlue,
+	CGrey,
+	CAlpha,
+	CMap,
+	CIgnore,
+	NChan,
+};
+
+#define __DC(type, nbits)	((((type)&15)<<4)|((nbits)&15))
+#define CHAN1(a,b)	__DC(a,b)
+#define CHAN2(a,b,c,d)	(CHAN1((a),(b))<<8|__DC((c),(d)))
+#define CHAN3(a,b,c,d,e,f)	(CHAN2((a),(b),(c),(d))<<8|__DC((e),(f)))
+#define CHAN4(a,b,c,d,e,f,g,h)	(CHAN3((a),(b),(c),(d),(e),(f))<<8|__DC((g),(h)))
+
+#define NBITS(c) ((c)&15)
+#define TYPE(c) (((c)>>4)&15)
+
+enum {
+	GREY1	= CHAN1(CGrey, 1),
+	GREY2	= CHAN1(CGrey, 2),
+	GREY4	= CHAN1(CGrey, 4),
+	GREY8	= CHAN1(CGrey, 8),
+	CMAP8	= CHAN1(CMap, 8),
+	RGB15	= CHAN4(CIgnore, 1, CRed, 5, CGreen, 5, CBlue, 5),
+	RGB16	= CHAN3(CRed, 5, CGreen, 6, CBlue, 5),
+	RGB24	= CHAN3(CRed, 8, CGreen, 8, CBlue, 8),
+	RGBA32	= CHAN4(CRed, 8, CGreen, 8, CBlue, 8, CAlpha, 8),
+	ARGB32	= CHAN4(CAlpha, 8, CRed, 8, CGreen, 8, CBlue, 8),	/* stupid VGAs */
+	XRGB32	= CHAN4(CIgnore, 8, CRed, 8, CGreen, 8, CBlue, 8),
+	BGR24	= CHAN3(CBlue, 8, CGreen, 8, CRed, 8),
+	ABGR32	= CHAN4(CAlpha, 8, CBlue, 8, CGreen, 8, CRed, 8),
+	XBGR32	= CHAN4(CIgnore, 8, CBlue, 8, CGreen, 8, CRed, 8),
+};
+
+extern	char*	chantostr(char*, ulong);
+extern	ulong	strtochan(char*);
+extern	int		chantodepth(ulong);
+
+struct	Point
+{
+	int	x;
+	int	y;
+};
+
+struct Rectangle
+{
+	Point	min;
+	Point	max;
+};
+
+typedef void	(*Reffn)(Image*, Rectangle, void*);
+
+struct Screen
+{
+	Display	*display;	/* display holding data */
+	int	id;		/* id of system-held Screen */
+	Image	*image;		/* unused; for reference only */
+	Image	*fill;		/* color to paint behind windows */
+};
+
+struct Display
+{
+	QLock	qlock;
+	int		locking;	/*program is using lockdisplay */
+	int		dirno;
+	int		fd;
+	int		reffd;
+	int		ctlfd;
+	int		imageid;
+	int		local;
+	void		(*error)(Display*, char*);
+	char		*devdir;
+	char		*windir;
+	char		oldlabel[64];
+	ulong		dataqid;
+	Image		*white;
+	Image		*black;
+	Image		*opaque;
+	Image		*transparent;
+	Image		*image;
+	uchar		*buf;
+	int			bufsize;
+	uchar		*bufp;
+	Font		*defaultfont;
+	Subfont		*defaultsubfont;
+	Image		*windows;
+	Image		*screenimage;
+	int			_isnewdisplay;
+};
+
+struct Image
+{
+	Display		*display;	/* display holding data */
+	int		id;		/* id of system-held Image */
+	Rectangle	r;		/* rectangle in data area, local coords */
+	Rectangle 	clipr;		/* clipping region */
+	int		depth;		/* number of bits per pixel */
+	ulong	chan;
+	int		repl;		/* flag: data replicates to tile clipr */
+	Screen		*screen;	/* 0 if not a window */
+	Image		*next;	/* next in list of windows */
+};
+
+struct RGB
+{
+	ulong	red;
+	ulong	green;
+	ulong	blue;
+};
+
+/*
+ * Subfonts
+ *
+ * given char c, Subfont *f, Fontchar *i, and Point p, one says
+ *	i = f->info+c;
+ *	draw(b, Rect(p.x+i->left, p.y+i->top,
+ *		p.x+i->left+((i+1)->x-i->x), p.y+i->bottom),
+ *		color, f->bits, Pt(i->x, i->top));
+ *	p.x += i->width;
+ * to draw characters in the specified color (itself an Image) in Image b.
+ */
+
+struct	Fontchar
+{
+	int		x;		/* left edge of bits */
+	uchar		top;		/* first non-zero scan-line */
+	uchar		bottom;		/* last non-zero scan-line + 1 */
+	char		left;		/* offset of baseline */
+	uchar		width;		/* width of baseline */
+};
+
+struct	Subfont
+{
+	char		*name;
+	short		n;		/* number of chars in font */
+	uchar		height;		/* height of image */
+	char		ascent;		/* top of image to baseline */
+	Fontchar 	*info;		/* n+1 character descriptors */
+	Image		*bits;		/* of font */
+	int		ref;
+};
+
+enum
+{
+	/* starting values */
+	LOG2NFCACHE =	6,
+	NFCACHE =	(1<<LOG2NFCACHE),	/* #chars cached */
+	NFLOOK =	5,			/* #chars to scan in cache */
+	NFSUBF =	2,			/* #subfonts to cache */
+	/* max value */
+	MAXFCACHE =	1024+NFLOOK,		/* upper limit */
+	MAXSUBF =	50,			/* generous upper limit */
+	/* deltas */
+	DSUBF = 	4,
+	/* expiry ages */
+	SUBFAGE	=	10000,
+	CACHEAGE =	10000
+};
+
+struct Cachefont
+{
+	Rune		min;	/* lowest rune value to be taken from subfont */
+	Rune		max;	/* highest rune value+1 to be taken from subfont */
+	int		offset;	/* position in subfont of character at min */
+	char		*name;			/* stored in font */
+	char		*subfontname;		/* to access subfont */
+};
+
+struct Cacheinfo
+{
+	ushort		x;		/* left edge of bits */
+	uchar		width;		/* width of baseline */
+	schar		left;		/* offset of baseline */
+	Rune		value;	/* value of character at this slot in cache */
+	ushort		age;
+};
+
+struct Cachesubf
+{
+	ulong		age;	/* for replacement */
+	Cachefont	*cf;	/* font info that owns us */
+	Subfont		*f;	/* attached subfont */
+};
+
+struct Font
+{
+	char		*name;
+	Display		*display;
+	short		height;	/* max height of image, interline spacing */
+	short		ascent;	/* top of image to baseline */
+	short		width;	/* widest so far; used in caching only */	
+	short		nsub;	/* number of subfonts */
+	ulong		age;	/* increasing counter; used for LRU */
+	int		maxdepth;	/* maximum depth of all loaded subfonts */
+	int		ncache;	/* size of cache */
+	int		nsubf;	/* size of subfont list */
+	Cacheinfo	*cache;
+	Cachesubf	*subf;
+	Cachefont	**sub;	/* as read from file */
+	Image		*cacheimage;
+};
+
+#define	Dx(r)	((r).max.x-(r).min.x)
+#define	Dy(r)	((r).max.y-(r).min.y)
+
+#ifdef	__cplusplus
+extern "C" { 
+#endif
+
+/*
+ * Image management
+ */
+extern Image*	_allocimage(Image*, Display*, Rectangle, ulong, int, ulong, int, int);
+extern Image*	allocimage(Display*, Rectangle, ulong, int, ulong);
+extern uchar*	bufimage(Display*, int);
+extern int	bytesperline(Rectangle, int);
+extern void	closedisplay(Display*);
+extern void	drawerror(Display*, char*);
+extern int	flushimage(Display*, int);
+extern int	freeimage(Image*);
+extern int	_freeimage1(Image*);
+extern int	geninitdraw(char*, void(*)(Display*, char*), char*, char*, char*, int);
+extern int	initdraw(void(*)(Display*, char*), char*, char*);
+extern int	newwindow(char*);
+extern Display*	initdisplay(char*, char*, void(*)(Display*, char*));
+extern int	loadimage(Image*, Rectangle, uchar*, int);
+extern int	cloadimage(Image*, Rectangle, uchar*, int);
+extern int	getwindow(Display*, int);
+extern int	gengetwindow(Display*, char*, Image**, Screen**, int);
+extern Image* readimage(Display*, int, int);
+extern Image* creadimage(Display*, int, int);
+extern int	unloadimage(Image*, Rectangle, uchar*, int);
+extern int	wordsperline(Rectangle, int);
+extern int	writeimage(int, Image*, int);
+extern Image*	namedimage(Display*, char*);
+extern int	nameimage(Image*, char*, int);
+extern Image* allocimagemix(Display*, ulong, ulong);
+
+/*
+ * Colors
+ */
+extern	void	readcolmap(Display*, RGB*);
+extern	void	writecolmap(Display*, RGB*);
+extern	ulong	setalpha(ulong, uchar);
+
+/*
+ * Windows
+ */
+extern Screen*	allocscreen(Image*, Image*, int);
+extern Image*	_allocwindow(Image*, Screen*, Rectangle, int, ulong);
+extern Image*	allocwindow(Screen*, Rectangle, int, ulong);
+extern void	bottomnwindows(Image**, int);
+extern void	bottomwindow(Image*);
+extern int	freescreen(Screen*);
+extern Screen*	publicscreen(Display*, int, ulong);
+extern void	topnwindows(Image**, int);
+extern void	topwindow(Image*);
+extern int	originwindow(Image*, Point, Point);
+
+/*
+ * Geometry
+ */
+extern Point		Pt(int, int);
+extern Rectangle	Rect(int, int, int, int);
+extern Rectangle	Rpt(Point, Point);
+extern Point		addpt(Point, Point);
+extern Point		subpt(Point, Point);
+extern Point		divpt(Point, int);
+extern Point		mulpt(Point, int);
+extern int		eqpt(Point, Point);
+extern int		eqrect(Rectangle, Rectangle);
+extern Rectangle	insetrect(Rectangle, int);
+extern Rectangle	rectaddpt(Rectangle, Point);
+extern Rectangle	rectsubpt(Rectangle, Point);
+extern Rectangle	canonrect(Rectangle);
+extern int		rectXrect(Rectangle, Rectangle);
+extern int		rectinrect(Rectangle, Rectangle);
+extern void		combinerect(Rectangle*, Rectangle);
+extern int		rectclip(Rectangle*, Rectangle);
+extern int		ptinrect(Point, Rectangle);
+extern void		replclipr(Image*, int, Rectangle);
+extern int		drawreplxy(int, int, int);	/* used to be drawsetxy */
+extern Point	drawrepl(Rectangle, Point);
+extern int		rgb2cmap(int, int, int);
+extern int		cmap2rgb(int);
+extern int		cmap2rgba(int);
+extern void		icossin(int, int*, int*);
+extern void		icossin2(int, int, int*, int*);
+
+/*
+ * Graphics
+ */
+extern void	draw(Image*, Rectangle, Image*, Image*, Point);
+extern void	drawop(Image*, Rectangle, Image*, Image*, Point, Drawop);
+extern void	gendraw(Image*, Rectangle, Image*, Point, Image*, Point);
+extern void	gendrawop(Image*, Rectangle, Image*, Point, Image*, Point, Drawop);
+extern void	line(Image*, Point, Point, int, int, int, Image*, Point);
+extern void	lineop(Image*, Point, Point, int, int, int, Image*, Point, Drawop);
+extern void	poly(Image*, Point*, int, int, int, int, Image*, Point);
+extern void	polyop(Image*, Point*, int, int, int, int, Image*, Point, Drawop);
+extern void	fillpoly(Image*, Point*, int, int, Image*, Point);
+extern void	fillpolyop(Image*, Point*, int, int, Image*, Point, Drawop);
+extern Point	string(Image*, Point, Image*, Point, Font*, char*);
+extern Point	stringop(Image*, Point, Image*, Point, Font*, char*, Drawop);
+extern Point	stringn(Image*, Point, Image*, Point, Font*, char*, int);
+extern Point	stringnop(Image*, Point, Image*, Point, Font*, char*, int, Drawop);
+extern Point	runestring(Image*, Point, Image*, Point, Font*, Rune*);
+extern Point	runestringop(Image*, Point, Image*, Point, Font*, Rune*, Drawop);
+extern Point	runestringn(Image*, Point, Image*, Point, Font*, Rune*, int);
+extern Point	runestringnop(Image*, Point, Image*, Point, Font*, Rune*, int, Drawop);
+extern Point	stringbg(Image*, Point, Image*, Point, Font*, char*, Image*, Point);
+extern Point	stringbgop(Image*, Point, Image*, Point, Font*, char*, Image*, Point, Drawop);
+extern Point	stringnbg(Image*, Point, Image*, Point, Font*, char*, int, Image*, Point);
+extern Point	stringnbgop(Image*, Point, Image*, Point, Font*, char*, int, Image*, Point, Drawop);
+extern Point	runestringbg(Image*, Point, Image*, Point, Font*, Rune*, Image*, Point);
+extern Point	runestringbgop(Image*, Point, Image*, Point, Font*, Rune*, Image*, Point, Drawop);
+extern Point	runestringnbg(Image*, Point, Image*, Point, Font*, Rune*, int, Image*, Point);
+extern Point	runestringnbgop(Image*, Point, Image*, Point, Font*, Rune*, int, Image*, Point, Drawop);
+extern Point	_string(Image*, Point, Image*, Point, Font*, char*, Rune*, int, Rectangle, Image*, Point, Drawop);
+extern Point	stringsubfont(Image*, Point, Image*, Subfont*, char*);
+extern int		bezier(Image*, Point, Point, Point, Point, int, int, int, Image*, Point);
+extern int		bezierop(Image*, Point, Point, Point, Point, int, int, int, Image*, Point, Drawop);
+extern int		bezspline(Image*, Point*, int, int, int, int, Image*, Point);
+extern int		bezsplineop(Image*, Point*, int, int, int, int, Image*, Point, Drawop);
+extern int		bezsplinepts(Point*, int, Point**);
+extern int		fillbezier(Image*, Point, Point, Point, Point, int, Image*, Point);
+extern int		fillbezierop(Image*, Point, Point, Point, Point, int, Image*, Point, Drawop);
+extern int		fillbezspline(Image*, Point*, int, int, Image*, Point);
+extern int		fillbezsplineop(Image*, Point*, int, int, Image*, Point, Drawop);
+extern void	ellipse(Image*, Point, int, int, int, Image*, Point);
+extern void	ellipseop(Image*, Point, int, int, int, Image*, Point, Drawop);
+extern void	fillellipse(Image*, Point, int, int, Image*, Point);
+extern void	fillellipseop(Image*, Point, int, int, Image*, Point, Drawop);
+extern void	arc(Image*, Point, int, int, int, Image*, Point, int, int);
+extern void	arcop(Image*, Point, int, int, int, Image*, Point, int, int, Drawop);
+extern void	fillarc(Image*, Point, int, int, Image*, Point, int, int);
+extern void	fillarcop(Image*, Point, int, int, Image*, Point, int, int, Drawop);
+extern void	border(Image*, Rectangle, int, Image*, Point);
+extern void	borderop(Image*, Rectangle, int, Image*, Point, Drawop);
+
+/*
+ * Font management
+ */
+extern Font*	openfont(Display*, char*);
+extern Font*	buildfont(Display*, char*, char*);
+extern void	freefont(Font*);
+extern Font*	mkfont(Subfont*, Rune);
+extern int	cachechars(Font*, char**, Rune**, ushort*, int, int*, char**);
+extern void	agefont(Font*);
+extern Subfont*	allocsubfont(char*, int, int, int, Fontchar*, Image*);
+extern Subfont*	lookupsubfont(Display*, char*);
+extern void	installsubfont(char*, Subfont*);
+extern void	uninstallsubfont(Subfont*);
+extern void	freesubfont(Subfont*);
+extern Subfont*	readsubfont(Display*, char*, int, int);
+extern Subfont*	readsubfonti(Display*, char*, int, Image*, int);
+extern int	writesubfont(int, Subfont*);
+extern void	_unpackinfo(Fontchar*, uchar*, int);
+extern Point	stringsize(Font*, char*);
+extern int	stringwidth(Font*, char*);
+extern int	stringnwidth(Font*, char*, int);
+extern Point	runestringsize(Font*, Rune*);
+extern int	runestringwidth(Font*, Rune*);
+extern int	runestringnwidth(Font*, Rune*, int);
+extern Point	strsubfontwidth(Subfont*, char*);
+extern int	loadchar(Font*, Rune, Cacheinfo*, int, int, char**);
+extern char*	subfontname(char*, char*, int);
+extern Subfont*	_getsubfont(Display*, char*);
+extern Subfont*	getdefont(Display*);
+extern void		lockdisplay(Display*);
+extern void	unlockdisplay(Display*);
+extern int		drawlsetrefresh(ulong, int, void*, void*);
+
+/*
+ * Predefined 
+ */
+extern	uchar	defontdata[];
+extern	int		sizeofdefont;
+extern	Point		ZP;
+extern	Rectangle	ZR;
+
+/*
+ * Set up by initdraw()
+ */
+extern	Display	*display;
+extern	Font		*font;
+extern	Image	*screen;
+extern	Screen	*_screen;
+extern	int	_cursorfd;
+extern	int	_drawdebug;	/* set to 1 to see errors from flushimage */
+extern	void	_setdrawop(Display*, Drawop);
+
+#define	BGSHORT(p)		(((p)[0]<<0) | ((p)[1]<<8))
+#define	BGLONG(p)		((BGSHORT(p)<<0) | (BGSHORT(p+2)<<16))
+#define	BPSHORT(p, v)		((p)[0]=(v), (p)[1]=((v)>>8))
+#define	BPLONG(p, v)		(BPSHORT(p, (v)), BPSHORT(p+2, (v)>>16))
+
+/*
+ * Compressed image file parameters and helper routines
+ */
+#define	NMATCH	3		/* shortest match possible */
+#define	NRUN	(NMATCH+31)	/* longest match possible */
+#define	NMEM	1024		/* window size */
+#define	NDUMP	128		/* maximum length of dump */
+#define	NCBLOCK	6000		/* size of compressed blocks */
+extern	void	_twiddlecompressed(uchar*, int);
+extern	int	_compblocksize(Rectangle, int);
+
+/* XXX backwards helps; should go */
+extern	ulong	drawld2chan[];
+extern	void		drawsetdebug(int);
+
+#ifdef	__cplusplus
+}
+#endif
+
+#endif

+ 83 - 0
sys/include/ape/errno.h

@@ -0,0 +1,83 @@
+#ifndef __ERRNO
+#define __ERRNO
+#pragma lib "/$M/lib/ape/libap.a"
+
+extern int errno;
+
+#define EDOM	1000
+#define ERANGE	1001
+#define EPLAN9	1002
+
+#ifdef _POSIX_SOURCE
+
+#define E2BIG	1
+#define EACCES	2
+#define	EAGAIN	3
+#define EBADF	4
+#define EBUSY	5
+#define ECHILD	6
+#define EDEADLK	7
+#define EEXIST	8
+#define EFAULT	9
+#define EFBIG	10
+#define EINTR	11
+#define EINVAL	12
+#define EIO	13
+#define EISDIR	14
+#define EMFILE	15
+#define EMLINK	16
+#define ENAMETOOLONG	17
+#define ENFILE	18
+#define ENODEV	19
+#define ENOENT	20
+#define ENOEXEC	21
+#define ENOLCK	22
+#define ENOMEM	23
+#define ENOSPC	24
+#define ENOSYS	25
+#define ENOTDIR	26
+#define ENOTEMPTY	27
+#define ENOTTY	28
+#define ENXIO	29
+#define EPERM	30
+#define EPIPE	31
+#define EROFS	32
+#define ESPIPE	33
+#define ESRCH	34
+#define EXDEV	35
+
+/* bsd networking software */
+#define ENOTSOCK	36
+#define EPROTONOSUPPORT	37
+#define EPROTOTYPE	37	/* two names for 37 */
+#define ECONNREFUSED	38
+#define EAFNOSUPPORT	39
+#define ENOBUFS		40
+#define EOPNOTSUPP	41
+#define EADDRINUSE	42
+#define EDESTADDRREQ	43
+#define EMSGSIZE	44
+#define ENOPROTOOPT	45
+#define ESOCKTNOSUPPORT	46
+#define EPFNOSUPPORT	47
+#define EADDRNOTAVAIL	48
+#define ENETDOWN	49
+#define ENETUNREACH	50
+#define ENETRESET	51
+#define ECONNABORTED	52
+#define EISCON	53
+#define ENOTCONN	54
+#define ESHUTDOWN	55
+#define ETOOMANYREFS	56
+#define ETIMEDOUT	57
+#define EHOSTDOWN	58
+#define EHOSTUNREACH	59
+#define EGREG		60
+
+/* These added in 1003.1b-1993 */
+#define ECANCELED	61
+#define EINPROGRESS	62
+
+#endif /* _POSIX_SOURCE */
+
+#endif /* __ERRNO */

+ 19 - 0
sys/include/ape/error.h

@@ -0,0 +1,19 @@
+#ifndef __ERROR_H
+#define __ERROR_H
+#ifndef _RESEARCH_SOURCE
+   This header file is not defined in pure ANSI or POSIX
+#endif
+#pragma lib "/$M/lib/ape/libv.a"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern char *_progname;		/* program name */
+extern void _perror(char *);	/* perror but with _progname */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _ERROR_H */

+ 10 - 0
sys/include/ape/event.h

@@ -0,0 +1,10 @@
+#ifndef _PLAN9_SOURCE
+  This header file is an extension to ANSI/POSIX
+#endif
+
+#ifndef	__EVENT_H_
+#define	__EVENT_H_
+#include "/sys/include/event.h"
+
+#endif
+

+ 59 - 0
sys/include/ape/fcntl.h

@@ -0,0 +1,59 @@
+#ifndef __FCNTL_H
+#define __FCNTL_H
+#ifndef _POSIX_SOURCE
+   This header file is not defined in pure ANSI
+#endif
+#pragma lib "/$M/lib/ape/libap.a"
+
+#include	<sys/types.h>
+
+#define	O_RDONLY 0
+#define	O_WRONLY 1
+#define	O_RDWR	 2
+#define O_ACCMODE	0x003
+#define O_NONBLOCK	0x004
+#define O_APPEND	0x008
+#define O_CREAT		0x100
+#define O_TRUNC		0x200
+#define O_EXCL		0x400
+#define O_NOCTTY	0x800
+#define O_DSYNC		0x1000
+#define	O_RSYNC		0x2000
+#define O_SYNC		0x4000
+
+#define	F_DUPFD		0	/* Duplicate fildes */
+#define	F_GETFD		1	/* Get fildes flags */
+#define	F_SETFD		2	/* Set fildes flags */
+#define	F_GETFL		3	/* Get file flags */
+#define	F_SETFL		4	/* Set file flags */
+#define	F_GETLK		5	/* Get file lock */
+#define	F_SETLK		6	/* Set file lock */
+#define	F_SETLKW	7	/* Set file lock and wait */
+
+#define FD_CLOEXEC	1
+
+struct flock {
+	short	l_type;
+	short	l_whence;
+	off_t	l_start;
+	off_t	l_len;
+	pid_t	l_pid;
+};
+
+#define F_RDLCK		1	/* shared or read lock */
+#define F_UNLCK		2	/* unlock */
+#define F_WRLCK		3	/* exclusive or write lock */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern int fcntl(int, int, ...);
+extern int open(const char *, int, ...);
+extern int creat(const char *, mode_t);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif

+ 114 - 0
sys/include/ape/fmt.h

@@ -0,0 +1,114 @@
+#ifndef _PLAN9_SOURCE
+  This header file is an extension to ANSI/POSIX
+#endif
+
+#ifndef __FMT_H_
+#define __FMT_H_
+#pragma src "/sys/src/ape/lib/fmt"
+#pragma lib "/$M/lib/ape/libfmt.a"
+
+#include <u.h>
+
+/*
+ * The authors of this software are Rob Pike and Ken Thompson.
+ *              Copyright (c) 2002 by Lucent Technologies.
+ * 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 AUTHORS NOR LUCENT TECHNOLOGIES MAKE ANY
+ * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY
+ * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE.
+ */
+
+#include <stdarg.h>
+#include <utf.h>
+
+typedef struct Fmt	Fmt;
+struct Fmt{
+	unsigned char	runes;		/* output buffer is runes or chars? */
+	void	*start;			/* of buffer */
+	void	*to;			/* current place in the buffer */
+	void	*stop;			/* end of the buffer; overwritten if flush fails */
+	int	(*flush)(Fmt *);	/* called when to == stop */
+	void	*farg;			/* to make flush a closure */
+	int	nfmt;			/* num chars formatted so far */
+	va_list	args;			/* args passed to dofmt */
+	int	r;			/* % format Rune */
+	int	width;
+	int	prec;
+	unsigned long	flags;
+};
+
+enum{
+	FmtWidth	= 1,
+	FmtLeft		= FmtWidth << 1,
+	FmtPrec		= FmtLeft << 1,
+	FmtSharp	= FmtPrec << 1,
+	FmtSpace	= FmtSharp << 1,
+	FmtSign		= FmtSpace << 1,
+	FmtZero		= FmtSign << 1,
+	FmtUnsigned	= FmtZero << 1,
+	FmtShort	= FmtUnsigned << 1,
+	FmtLong		= FmtShort << 1,
+	FmtVLong	= FmtLong << 1,
+	FmtComma	= FmtVLong << 1,
+	FmtByte		= FmtComma << 1,
+	FmtLDouble	= FmtByte << 1,
+
+	FmtFlag		= FmtLDouble << 1
+};
+
+#ifdef	__cplusplus
+extern "C" { 
+#endif
+
+extern	int	print(char*, ...);
+extern	char*	seprint(char*, char*, char*, ...);
+extern	char*	vseprint(char*, char*, char*, va_list);
+extern	int	snprint(char*, int, char*, ...);
+extern	int	vsnprint(char*, int, char*, va_list);
+extern	char*	smprint(char*, ...);
+extern	char*	vsmprint(char*, va_list);
+extern	int	sprint(char*, char*, ...);
+extern	int	fprint(int, char*, ...);
+extern	int	vfprint(int, char*, va_list);
+
+extern	int	runesprint(Rune*, char*, ...);
+extern	int	runesnprint(Rune*, int, char*, ...);
+extern	int	runevsnprint(Rune*, int, char*, va_list);
+extern	Rune*	runeseprint(Rune*, Rune*, char*, ...);
+extern	Rune*	runevseprint(Rune*, Rune*, char*, va_list);
+extern	Rune*	runesmprint(char*, ...);
+extern	Rune*	runevsmprint(char*, va_list);
+
+extern	int	fmtfdinit(Fmt*, int, char*, int);
+extern	int	fmtfdflush(Fmt*);
+extern	int	fmtstrinit(Fmt*);
+extern	char*	fmtstrflush(Fmt*);
+extern	int	runefmtstrinit(Fmt*);
+
+extern	int	quotestrfmt(Fmt *f);
+extern	void	quotefmtinstall(void);
+extern	int	(*fmtdoquote)(int);
+
+
+extern	int	fmtinstall(int, int (*)(Fmt*));
+extern	int	dofmt(Fmt*, char*);
+extern	int	fmtprint(Fmt*, char*, ...);
+extern	int	fmtvprint(Fmt*, char*, va_list);
+extern	int	fmtrune(Fmt*, int);
+extern	int	fmtstrcpy(Fmt*, char*);
+
+extern	double	fmtstrtod(const char *, char **);
+extern	double	fmtcharstod(int(*)(void*), void*);
+
+extern	void	werrstr(const char*, ...);
+
+#ifdef	__cplusplus
+}
+#endif
+
+#endif

+ 26 - 0
sys/include/ape/grp.h

@@ -0,0 +1,26 @@
+#ifndef __GRP
+#define __GRP
+#ifndef _POSIX_SOURCE
+   This header file is not defined in pure ANSI
+#endif
+#pragma lib "/$M/lib/ape/libap.a"
+#include <sys/types.h>
+
+struct	group {
+	char	*gr_name;
+	gid_t	gr_gid;
+	char	**gr_mem;
+};
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern struct group *getgrgid(gid_t);
+extern struct group *getgrnam(const char *);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif

+ 23 - 0
sys/include/ape/inttypes.h

@@ -0,0 +1,23 @@
+#ifndef _SUSV2_SOURCE
+#error "inttypes.h is SUSV2"
+#endif
+
+#ifndef _INTTYPES_H_
+#define _INTTYPES_H_ 1
+
+typedef int _intptr_t;
+typedef unsigned int _uintptr_t;
+
+
+typedef char int8_t;
+typedef short int16_t;
+typedef int int32_t;
+typedef long long int64_t;
+typedef unsigned char uint8_t;
+typedef unsigned short uint16_t;
+typedef unsigned int uint32_t;
+typedef unsigned long long uint64_t;
+typedef _intptr_t intptr_t;
+typedef _uintptr_t uintptr_t;
+
+#endif

+ 6 - 0
sys/include/ape/keyboard.h

@@ -0,0 +1,6 @@
+#ifndef _PLAN9_SOURCE
+  This header file is an extension to ANSI/POSIX
+#endif
+
+#include "/sys/include/keyboard.h"
+

+ 78 - 0
sys/include/ape/lib9.h

@@ -0,0 +1,78 @@
+#ifndef __LIB9_H
+#define __LIB9_H
+#if !defined(_RESEARCH_SOURCE) && !defined(_PLAN9_SOURCE)
+    This header file is an extension to ANSI/POSIX
+#endif
+#pragma lib "/$M/lib/ape/lib9.a"
+
+#include <u.h>		/* ick; need Rune defined below */
+
+#define	MORDER	0x0003	/* mask for bits defining order of mounting */
+#define	MREPL	0x0000	/* mount replaces object */
+#define	MBEFORE	0x0001	/* mount goes before others in union directory */
+#define	MAFTER	0x0002	/* mount goes after others in union directory */
+#define	MCREATE	0x0004	/* permit creation in mounted directory */
+#define MRECOV	0x0008	/* perform recovery if mount channel is lost */
+#define MCACHE	0x0010	/* cache some data */
+#define	MMASK	0x0007	/* all bits on */
+
+#define	FORKPG		1
+#define	FORKEG		2
+#define	FORKFD		4
+
+#define	SG_RONLY	0040	/* read only */
+#define	SG_CEXEC	0100	/* detach on exec */
+
+enum
+{
+	RFNAMEG		= (1<<0),
+	RFENVG		= (1<<1),
+	RFFDG		= (1<<2),
+	RFNOTEG		= (1<<3),
+	RFPROC		= (1<<4),
+	RFMEM		= (1<<5),
+	RFNOWAIT	= (1<<6),
+	RFCNAMEG	= (1<<10),
+	RFCENVG		= (1<<11),
+	RFCFDG		= (1<<12),
+	RFREND		= (1<<13)
+};
+
+extern char *argv0;
+#define	ARGBEGIN	for((argv0||(argv0=*argv)),argv++,argc--;\
+			    argv[0] && argv[0][0]=='-' && argv[0][1];\
+			    argc--, argv++) {\
+				char *_args, *_argt;\
+				Rune _argc;\
+				_args = &argv[0][1];\
+				if(_args[0]=='-' && _args[1]==0){\
+					argc--; argv++; break;\
+				}\
+				_argc = 0;\
+				while(*_args && (_args += chartorune(&_argc, _args)))\
+				switch(_argc)
+#define	ARGEND		SET(_argt);USED(_argt,_argc,_args);}USED(argv, argc);
+#define	ARGF()		(_argt=_args, _args="",\
+				(*_argt? _argt: argv[1]? (argc--, *++argv): 0))
+#define	EARGF(x)	(_argt=_args, _args="",\
+				(*_argt? _argt: argv[1]? (argc--, *++argv): ((x), abort(), (char*)0)))
+
+#define	ARGC()		_argc
+
+extern	int	errstr(char*, unsigned int);
+extern	int	bind(char*, char*, int);
+extern	int	mount(int, int, char*, int, char*);
+extern	int	unmount(char*, char*);
+extern	int	rfork(int);
+extern	int	segattach(int, char*, void*, unsigned long);
+extern	int	segbrk(void*, void*);
+extern	int	segdetach(void*);
+extern	int	segflush(void*, unsigned long);
+extern	int	segfree(void*, unsigned long);
+extern	unsigned long	rendezvous(unsigned long, unsigned long);
+extern	unsigned long	getfcr(void);
+extern	unsigned long	getfsr(void);
+extern	void		setfcr(unsigned long);
+extern	void		setfsr(unsigned long);
+
+#endif

+ 15 - 0
sys/include/ape/libl.h

@@ -0,0 +1,15 @@
+#ifndef __LIBL_H
+#define __LIBL_H
+#ifndef _RESEARCH_SOURCE
+   This header file is not defined in ANSI or POSIX
+#endif
+#pragma lib "/$M/lib/ape/libl.a"
+
+extern int printable(int);
+extern void allprint(char);
+extern int yyracc(int);
+extern int yyreject(void);
+extern void yyless(int);
+extern int yywrap(void);
+
+#endif /* __LIBV_L */

+ 20 - 0
sys/include/ape/libnet.h

@@ -0,0 +1,20 @@
+#ifndef __LIBNET_H
+#define __LIBNET_H
+#ifndef _NET_EXTENSION
+   This header file is not defined in ANSI or POSIX
+#endif
+#pragma lib "/$M/lib/ape/libnet.a"
+
+#define NETPATHLEN 40
+
+extern	int	accept(int, char*);
+extern	int	announce(char*, char*);
+extern	int	dial(char*, char*, char*, int*);
+extern	int	hangup(int);
+extern	int	listen(char*, char*);
+extern	char*	netmkaddr(char*, char*, char*);
+extern	int	reject(int, char*, char *);
+
+extern char    dialerrstr[64];
+
+#endif /* __LIBNET_H */

+ 39 - 0
sys/include/ape/libv.h

@@ -0,0 +1,39 @@
+#ifndef __LIBV_H
+#define __LIBV_H
+#ifndef _RESEARCH_SOURCE
+   This header file is not defined in ANSI or POSIX
+#endif
+#pragma lib "/$M/lib/ape/libv.a"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern void	srand(unsigned int);
+extern int	rand(void);
+extern int	nrand(int);
+extern long	lrand(void);
+extern double	frand(void);
+
+extern char	*getpass(char *);
+extern int	tty_echoon(int);
+extern int	tty_echooff(int);
+
+extern int	min(int, int);
+extern int	max(int, int);
+
+extern void	_perror(char *);
+extern char	*_progname;
+
+extern int	nap(int);
+
+extern char	*setfields(char *);
+extern int	getfields(char *, char **, int);
+extern int	getmfields(char *, char **, int);
+
+
+#ifdef __cplusplus
+};
+#endif
+
+#endif /* __LIBV_H */

+ 85 - 0
sys/include/ape/limits.h

@@ -0,0 +1,85 @@
+#ifndef __LIMITS
+#define __LIMITS
+/* 8 bit chars (signed), 16 bit shorts, 32 bit ints/longs */
+
+#define CHAR_BIT	8
+#define MB_LEN_MAX	3
+
+#define UCHAR_MAX	0xff
+#define USHRT_MAX	0xffff
+#define UINT_MAX	0xffffffffU
+#define ULONG_MAX	0xffffffffUL
+
+#define CHAR_MAX	SCHAR_MAX
+#define SCHAR_MAX	0x7f
+#define SHRT_MAX	0x7fff
+#define INT_MAX		0x7fffffff
+#define LONG_MAX	0x7fffffffL
+
+#define CHAR_MIN	SCHAR_MIN
+#define SCHAR_MIN	(-SCHAR_MAX-1)
+#define SHRT_MIN	(-SHRT_MAX-1)
+#define INT_MIN		(-INT_MAX-1)
+#define LONG_MIN	(-LONG_MAX-1)
+
+#ifdef _POSIX_SOURCE
+
+#define _POSIX_AIO_LISTIO_MAX	2
+#define _POSIX_AIO_MAX			1
+#define _POSIX_ARG_MAX			4096
+#define _POSIX_CHILD_MAX		6
+#define	_POSIX_CLOCKRES_MIN		20000000
+#define	_POSIX_DELAYTIMER_MAX	32
+#define _POSIX_LINK_MAX			8
+#define _POSIX_MAX_CANON		255
+#define _POSIX_MAX_INPUT		255
+#define _POSIX_MQ_OPEN_MAX		8
+#define	_POSIX_MQ_PRIO_MAX		32
+#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_RTSIG_MAX		8
+#define	_POSIX_SEM_NSEMS_MAX	256
+#define	_POSIX_SEM_VALUE_MAX	32767
+#define	_POSIX_SIGQUEUE_MAX		32
+#define _POSIX_SSIZE_MAX		32767
+#define _POSIX_STREAM_MAX		8
+#define	_POSIX_TIMER_MAX		32
+#define _POSIX_TZNAME_MAX		3
+
+/* pedagogy: those that standard allows omitting are commented out */
+/*#define AIO_LIST_MAX _POSIX_AIO_LIST_MAX */
+/*#define AIO_MAX _POSIX_AIO_MAX */
+/*#define AIO_PRIO_DELTA_MAX 0 */
+/*#define ARG_MAX _POSIX_ARG_MAX */
+/*#define CHILD_MAX _POSIX_CHILD_MAX */
+/*#define DELAYTIMER_MAX _POSIX_DELAYTIMER_MAX */
+/*#define LINK_MAX _POSIX_LINK_MAX */
+/*#define MAX_CANON _POSIX_MAX_CANON */
+/*#define MAX_INPUT _POSIX_MAX_INPUT */
+/*#define MQ_OPEN_MAX _POSIX_MQ_OPEN_MAX */
+/*#define MQ_PRIO_MAX _POSIX_MQ_PRIO_MAX */
+/*#define NAME_MAX _POSIX_NAME_MAX */
+#define NGROUPS_MAX 10
+/*#define OPEN_MAX _POSIX_OPEN_MAX */
+/*#define PAGESIZE 1 */
+/*#define PATH_MAX _POSIX_PATH_MAX */
+/*#define PIPE_BUF _POSIX_PIPE_BUF */
+/*#define RTSIG_MAX _POSIX_RTSIG_MAX */
+/*#define SEM_NSEMS_MAX _POSIX_SEM_NSEMS_MAX */
+/*#define SEM_VALUE_MAX _POSIX_SEM_VALUE_MAX */
+/*#define SIGQUEUE_MAX _POSIX_SIGQUEUE_MAX */
+#define SSIZE_MAX LONG_MAX
+/*#define STREAM_MAX _POSIX_STREAM_MAX */
+/*#define TIMER_MAX _POSIX_TIMER_MAX */
+#define TZNAME_MAX _POSIX_TZNAME_MAX
+
+#ifdef _LIMITS_EXTENSION
+/* some things are just too big for pedagogy (X!) */
+#include <sys/limits.h>
+#endif
+#endif /* _POSIX_SOURCE */
+
+#endif /* __LIMITS */

+ 46 - 0
sys/include/ape/locale.h

@@ -0,0 +1,46 @@
+#ifndef __LOCALE
+#define __LOCALE
+#pragma lib "/$M/lib/ape/libap.a"
+
+#include <stddef.h>
+
+#define LC_ALL		0
+#define LC_COLLATE	1
+#define LC_CTYPE	2
+#define LC_MONETARY	3
+#define LC_NUMERIC	4
+#define LC_TIME		5
+
+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;
+};
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern char *setlocale(int, const char *);
+extern struct lconv *localeconv(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __LOCALE */

+ 29 - 0
sys/include/ape/lock.h

@@ -0,0 +1,29 @@
+#if !defined(_RESEARCH_SOURCE) && !defined(_PLAN9_SOURCE)
+   This header file is an extension of ANSI/POSIX
+#endif
+
+#ifndef __LOCK_H
+#define __LOCK_H
+#pragma lib "/$M/lib/ape/libap.a"
+
+#include <u.h>
+
+typedef struct
+{
+	int	val;
+} Lock;
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern	void	lock(Lock*);
+extern	void	unlock(Lock*);
+extern	int	canlock(Lock*);
+extern	int	tas(int*);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif

+ 6 - 0
sys/include/ape/mouse.h

@@ -0,0 +1,6 @@
+#ifndef _PLAN9_SOURCE
+  This header file is an extension to ANSI/POSIX
+#endif
+
+#include "/sys/include/mouse.h"
+

+ 121 - 0
sys/include/ape/netdb.h

@@ -0,0 +1,121 @@
+#ifndef __NETDB_H__
+#define __NETDB_H__
+
+#ifndef _BSD_EXTENSION
+    This header file is an extension to ANSI/POSIX
+#endif
+
+#pragma lib "/$M/lib/ape/libbsd.a"
+
+/*-
+ * Copyright (c) 1980, 1983, 1988 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms are permitted
+ * provided that: (1) source distributions retain this entire copyright
+ * notice and comment, and (2) distributions including binaries display
+ * the following acknowledgement:  ``This product includes software
+ * developed by the University of California, Berkeley and its contributors''
+ * in the documentation or other materials provided with the distribution
+ * and in all advertising materials mentioning features or use of this
+ * software. Neither the name of the University nor the names of its
+ * contributors may 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.
+ *
+ *	@(#)netdb.h	5.11 (Berkeley) 5/21/90
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * 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 32 bits -- 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 # */
+};
+
+/* from 4.0 RPCSRC */
+struct rpcent {
+	char	*r_name;	/* name of server for this rpc program */
+	char	**r_aliases;	/* alias list */
+	int	r_number;	/* rpc program number */
+};
+
+extern struct hostent	*gethostbyname(const char *),
+			*gethostbyaddr(const void *, int, int),
+			*gethostent(void);
+extern struct netent	*getnetbyname(const char *),
+			*getnetbyaddr(long, int),
+			*getnetent(void);
+extern struct servent	*getservbyname(const char *, const char *),
+			*getservbyport(int, const char *),
+			*getservent(void);
+extern struct protoent	*getprotobyname(const char *),
+			*getprotobynumber(int),
+			*getprotoent(void);
+extern struct rpcent	*getrpcbyname(const char *), 
+			*getrpcbynumber(int), 
+			*getrpcent(void);
+extern void sethostent(int),  endhostent(void),
+	    setnetent(int),   endnetent(void),
+	    setservent(int),  endservent(void),
+	    setprotoent(int), endprotoent(void),
+	    setrpcent(int),   endrpcent(void);
+
+/*
+ * Error return codes from gethostbyname() and gethostbyaddr()
+ * (left in extern int h_errno).
+ */
+extern int h_errno;
+extern void herror(const char *);
+extern char *hstrerror(int);
+
+#define	HOST_NOT_FOUND	1 /* Authoritative Answer Host not found */
+#define	TRY_AGAIN	2 /* Non-Authoritive 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 */
+
+#define __HOST_SVC_NOT_AVAIL 99		/* libc internal use only */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* !__NETDB_H__ */

+ 147 - 0
sys/include/ape/netinet/in.h

@@ -0,0 +1,147 @@
+#ifndef __netinet_in__
+#define __netinet_in__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * Copyright (c) 1982, 1986, 1990 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution is only permitted until one year after the first shipment
+ * of 4.4BSD by the Regents.  Otherwise, redistribution and use in source and
+ * binary forms are permitted provided that: (1) source distributions retain
+ * this entire copyright notice and comment, and (2) distributions including
+ * binaries display the following acknowledgement:  This product includes
+ * software developed by the University of California, Berkeley and its
+ * contributors'' in the documentation or other materials provided with the
+ * distribution and in all advertising materials mentioning features or use
+ * of this software.  Neither the name of the University nor the names of
+ * its contributors may 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.
+ *
+ *	@(#)in.h	7.10 (Berkeley) 6/28/90 plus MULTICAST 1.1
+ */
+
+/*
+ * Constants and structures defined by the internet system,
+ * Per RFC 790, September 1981.
+ */
+
+/*
+ * Protocols
+ */
+#define	IPPROTO_IP		0		/* dummy for IP */
+#define	IPPROTO_ICMP		1		/* control message protocol */
+#define	IPPROTO_GGP		3		/* gateway^2 (deprecated) */
+#define	IPPROTO_TCP		6		/* tcp */
+#define	IPPROTO_EGP		8		/* exterior gateway protocol */
+#define	IPPROTO_PUP		12		/* pup */
+#define	IPPROTO_UDP		17		/* user datagram protocol */
+#define	IPPROTO_IDP		22		/* xns idp */
+#define	IPPROTO_TP		29 		/* tp-4 w/ class negotiation */
+#define	IPPROTO_EON		80		/* ISO cnlp */
+
+#define	IPPROTO_RAW		255		/* raw IP packet */
+#define	IPPROTO_MAX		256
+
+
+/*
+ * Local port number conventions:
+ * Ports < IPPORT_RESERVED are reserved for
+ * privileged processes (e.g. root).
+ * Ports > IPPORT_USERRESERVED are reserved
+ * for servers, not necessarily privileged.
+ */
+#define	IPPORT_RESERVED		1024
+#define	IPPORT_USERRESERVED	5000
+
+/*
+ * Internet address (a structure for historical reasons)
+ */
+struct in_addr {
+	unsigned long s_addr;
+};
+
+/*
+ * Definitions of bits in internet address integers.
+ * On subnets, the decomposition of addresses to host and net parts
+ * is done according to subnet mask, not the masks here.
+ */
+#define	IN_CLASSA(i)		(((long)(i) & 0x80000000) == 0)
+#define	IN_CLASSA_NET		0xff000000
+#define	IN_CLASSA_NSHIFT	24
+#define	IN_CLASSA_HOST		0x00ffffff
+#define	IN_CLASSA_MAX		128
+
+#define	IN_CLASSB(i)		(((long)(i) & 0xc0000000) == 0x80000000)
+#define	IN_CLASSB_NET		0xffff0000
+#define	IN_CLASSB_NSHIFT	16
+#define	IN_CLASSB_HOST		0x0000ffff
+#define	IN_CLASSB_MAX		65536
+
+#define	IN_CLASSC(i)		(((long)(i) & 0xe0000000) == 0xc0000000)
+#define	IN_CLASSC_NET		0xffffff00
+#define	IN_CLASSC_NSHIFT	8
+#define	IN_CLASSC_HOST		0x000000ff
+
+#define	IN_CLASSD(i)		(((long)(i) & 0xf0000000) == 0xe0000000)
+#define	IN_MULTICAST(i)		IN_CLASSD(i)
+
+#define	IN_EXPERIMENTAL(i)	(((long)(i) & 0xe0000000) == 0xe0000000)
+#define	IN_BADCLASS(i)		(((long)(i) & 0xf0000000) == 0xf0000000)
+
+#define	INADDR_ANY		(unsigned long)0x00000000
+#define	INADDR_BROADCAST	(unsigned long)0xffffffff	/* must be masked */
+#define INADDR_NONE		(unsigned long)0xffffffff	/* -1 return */
+
+#define	IN_LOOPBACKNET		127			/* official! */
+
+/*
+ * Socket address, internet style.
+ */
+struct sockaddr_in {
+	short	sin_family;
+	unsigned short	sin_port;
+	struct	in_addr sin_addr;
+	char	sin_zero[8];
+};
+
+/*
+ * Structure used to describe IP options.
+ * Used to store options internally, to pass them to a process,
+ * or to restore options retrieved earlier.
+ * The ip_dst is used for the first-hop gateway when using a source route
+ * (this gets put into the header proper).
+ */
+struct ip_opts {
+	struct	in_addr ip_dst;		/* first hop, 0 w/o src rt */
+	char	ip_opts[40];		/* actually variable in size */
+};
+
+/*
+ * Options for use with [gs]etsockopt at the IP level.
+ * First word of comment is data type; bool is stored in int.
+ */
+#define	IP_OPTIONS	1	/* buf/ip_opts; set/get IP per-packet options */
+#define	IP_HDRINCL	7	/* int; header is included with data (raw) */
+#define	IP_TOS		8	/* int; IP type of service and precedence */
+#define	IP_TTL		9	/* int; IP time to live */
+
+extern unsigned long	ntohl(unsigned long x);
+extern unsigned short	ntohs(unsigned short x);
+extern unsigned long	htonl(unsigned long x);
+extern unsigned short	htons(unsigned short x);
+extern unsigned long	inet_addr(char*);
+extern char*		inet_ntoa(struct in_addr);
+extern unsigned long	nptohl(void*);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __netinet_in__ */

+ 0 - 0
sys/include/ape/netinet/tcp.h


+ 28 - 0
sys/include/ape/pwd.h

@@ -0,0 +1,28 @@
+#ifndef __PWD
+#define __PWD
+#ifndef _POSIX_SOURCE
+   This header file is not defined in pure ANSI
+#endif
+#pragma lib "/$M/lib/ape/libap.a"
+#include <sys/types.h>
+
+struct passwd {
+	char	*pw_name;
+	uid_t	pw_uid;
+	gid_t	pw_gid;
+	char	*pw_dir;
+	char	*pw_shell;
+};
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern struct passwd *getpwuid(uid_t);
+extern struct passwd *getpwnam(const char *);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif

+ 41 - 0
sys/include/ape/qlock.h

@@ -0,0 +1,41 @@
+#ifndef _PLAN9_SOURCE
+  This header file is an extension to ANSI/POSIX
+#endif
+
+#ifndef __QLOCK_H_
+#define __QLOCK_H_
+#pragma lib "/$M/lib/ape/lib9.a"
+
+#include <u.h>
+#include <lock.h>
+
+typedef struct QLp QLp;
+struct QLp
+{
+	int	inuse;
+	QLp	*next;
+	char	state;
+};
+
+typedef
+struct QLock
+{
+	Lock	lock;
+	int	locked;
+	QLp	*head;
+	QLp 	*tail;
+} QLock;
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern	void	qlock(QLock*);
+extern	void	qunlock(QLock*);
+extern	int	canqlock(QLock*);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif

+ 77 - 0
sys/include/ape/regexp.h

@@ -0,0 +1,77 @@
+#ifndef __REGEXP_H
+#define __REGEXP_H
+#ifndef _REGEXP_EXTENSION
+    This header file is an extension to ANSI/POSIX
+#endif
+#pragma lib "/$M/lib/ape/libregexp.a"
+
+#ifdef	UTF
+#define	Runeself	0xA0
+#else
+#define	Runeself	0
+#endif
+
+typedef struct Resub		Resub;
+typedef struct Reclass		Reclass;
+typedef struct Reinst		Reinst;
+typedef struct Reprog		Reprog;
+
+/*
+ *	Sub expression matches
+ */
+struct Resub{
+	union
+	{
+		char *sp;
+		wchar_t *rsp;
+	} s;
+	union
+	{
+		char *ep;
+		wchar_t *rep;
+	} e;
+};
+
+/*
+ *	character class, each pair of rune's defines a range
+ */
+struct Reclass{
+	wchar_t	*end;
+	wchar_t	spans[64];
+};
+
+/*
+ *	Machine instructions
+ */
+struct Reinst{
+	int	type;			/* < 0200 ==> literal, otherwise action */
+	union	{
+		Reclass	*cp;		/* class pointer */
+		wchar_t	r;		/* character */
+		int	subid;		/* sub-expression id for RBRA and LBRA */
+		Reinst	*right;		/* right child of OR */
+	} r;
+	union {	/* regexp relies on these two being in the same union */
+		Reinst *left;		/* left child of OR */
+		Reinst *next;		/* next instruction for CAT & LBRA */
+	} l;
+};
+
+/*
+ *	Reprogram definition
+ */
+struct Reprog{
+	Reinst	*startinst;	/* start pc */
+	Reclass	class[16];	/* .data */
+	Reinst	firstinst[5];	/* .text */
+};
+
+extern Reprog	*regcomp(char*);
+extern Reprog	*regcomplit(char*);
+extern Reprog	*regcompnl(char*);
+extern void	regerror(char*);
+extern int	regexec(Reprog*, char*, Resub*, int);
+extern void	regsub(char*, char*, int, Resub*, int);
+extern int	rregexec(Reprog*, wchar_t*, Resub*, int);
+extern void	rregsub(wchar_t*, wchar_t*, int, Resub*, int);
+#endif

+ 34 - 0
sys/include/ape/select.h

@@ -0,0 +1,34 @@
+#ifndef __SELECT_H
+#define __SELECT_H
+#ifndef _BSD_EXTENSION
+    This header file is an extension to ANSI/POSIX
+#endif
+#pragma lib "/$M/lib/ape/libap.a"
+
+#ifndef _FD_SET_T
+#define _FD_SET_T
+/* BSD select, and adjunct types and macros */
+
+/* assume 96 fds is sufficient for fdset size */
+
+typedef struct fd_set {
+	long fds_bits[3];
+} fd_set;
+
+#define FD_SET(n,p)	((p)->fds_bits[(n)>>5] |= (1 << ((n) &0x1f)))
+#define FD_CLR(n,p)	((p)->fds_bits[(n)>>5] &= ~(1 << ((n) &0x1f)))
+#define FD_ISSET(n,p)	((p)->fds_bits[(n)>>5] & (1 << ((n) &0x1f)))
+#define FD_ZERO(p)	((p)->fds_bits[0] =0, (p)->fds_bits[1] =0, (p)->fds_bits[2] =0)
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern int select(int, fd_set*, fd_set*, fd_set*, struct timeval *);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif

+ 26 - 0
sys/include/ape/setjmp.h

@@ -0,0 +1,26 @@
+#ifndef __SETJMP_H
+#define __SETJMP_H
+#pragma lib "/$M/lib/ape/libap.a"
+
+typedef int jmp_buf[10];
+#ifdef _POSIX_SOURCE
+typedef int sigjmp_buf[10];
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern int setjmp(jmp_buf);
+extern void longjmp(jmp_buf, int);
+
+#ifdef _POSIX_SOURCE
+extern int sigsetjmp(sigjmp_buf, int);
+extern void siglongjmp(sigjmp_buf, int);
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __SETJMP_H */

+ 95 - 0
sys/include/ape/signal.h

@@ -0,0 +1,95 @@
+#ifndef __SIGNAL_H
+#define __SIGNAL_H
+#pragma lib "/$M/lib/ape/libap.a"
+
+typedef int sig_atomic_t;
+
+/*
+ * We don't give arg types for signal handlers, in spite of ANSI requirement
+ * that it be 'int' (the signal number), because some programs need an
+ * additional context argument.  So the real type of signal handlers is
+ *      void handler(int sig, char *, struct Ureg *)
+ * where the char * is the Plan 9 message and Ureg is defined in <ureg.h>
+ */
+#define SIG_DFL ((void (*)())0)
+#define SIG_ERR ((void (*)())-1)
+#define SIG_IGN ((void (*)())1)
+
+#define	SIGHUP	1	/* hangup */
+#define	SIGINT	2	/* interrupt */
+#define	SIGQUIT	3	/* quit */
+#define	SIGILL	4	/* illegal instruction (not reset when caught)*/
+#define SIGABRT 5	/* used by abort */
+#define	SIGFPE	6	/* floating point exception */
+#define	SIGKILL	7	/* kill (cannot be caught or ignored) */
+#define	SIGSEGV	8	/* segmentation violation */
+#define	SIGPIPE	9	/* write on a pipe with no one to read it */
+#define	SIGALRM	10	/* alarm clock */
+#define	SIGTERM	11	/* software termination signal from kill */
+#define	SIGUSR1	12	/* user defined signal 1 */
+#define	SIGUSR2	13	/* user defined signal 2 */
+#define	SIGBUS	14	/* bus error */
+
+/* The following symbols must be defined, but the signals needn't be supported */
+#define SIGCHLD	15	/* child process terminated or stopped */
+#define SIGCONT 16	/* continue if stopped */
+#define SIGSTOP 17	/* stop */
+#define SIGTSTP	18	/* interactive stop */
+#define SIGTTIN	19	/* read from ctl tty by member of background */
+#define SIGTTOU	20	/* write to ctl tty by member of background */
+
+#ifdef _BSD_EXTENSION
+#define NSIG 21
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern void (*signal(int, void (*)()))();
+extern int raise(int);
+
+#ifdef __cplusplus
+}
+#endif
+
+#ifdef _POSIX_SOURCE
+
+typedef long sigset_t;
+struct sigaction {
+	void		(*sa_handler)();
+	sigset_t	sa_mask;
+	int		sa_flags;
+};
+/* values for sa_flags */
+#define SA_NOCLDSTOP	1
+
+/* first argument to sigprocmask */
+#define SIG_BLOCK	1
+#define SIG_UNBLOCK	2
+#define SIG_SETMASK	3
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifdef __TYPES_H
+extern int kill(pid_t, int);
+#endif
+extern int sigemptyset(sigset_t *);
+extern int sigfillset(sigset_t *);
+extern int sigaddset(sigset_t *, int);
+extern int sigdelset(sigset_t *, int);
+extern int sigismember(const sigset_t *, int);
+extern int sigaction(int, const struct sigaction *, struct sigaction *);
+extern int sigprocmask(int, sigset_t *, sigset_t *);
+extern int sigpending(sigset_t *);
+extern int sigsuspend(const sigset_t *);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _POSIX_SOURCE */
+
+#endif /* __SIGNAL_H */

+ 23 - 0
sys/include/ape/stddef.h

@@ -0,0 +1,23 @@
+#ifndef __STDDEF_H
+#define __STDDEF_H
+
+#ifndef NULL
+#ifdef __cplusplus
+#define NULL 0
+#else
+#define NULL ((void*)0)
+#endif
+#endif
+#define offsetof(ty,mem) ((size_t) &(((ty *)0)->mem))
+
+typedef long ptrdiff_t;
+#ifndef _SIZE_T
+#define _SIZE_T
+typedef unsigned long size_t;
+#endif
+#ifndef _WCHAR_T
+#define _WCHAR_T
+typedef unsigned short wchar_t;
+#endif
+
+#endif /* __STDDEF_H */

+ 157 - 0
sys/include/ape/stdio.h

@@ -0,0 +1,157 @@
+#ifndef	_STDIO_H_
+#define	_STDIO_H_
+#pragma lib "/$M/lib/ape/libap.a"
+
+/*
+ * pANS stdio.h
+ */
+#include <stdarg.h>
+#include <stddef.h>
+#include <sys/types.h>
+/*
+ * According to X3J11, there is only one i/o buffer
+ * and it must not be occupied by both input and output data.
+ *	If rp<wp, we must have state==RD and
+ *	if wp<rp, we must have state==WR, so that getc and putc work correctly.
+ *	On open, rp, wp and buf are set to 0, so first getc or putc will call _IO_getc
+ *	or _IO_putc, which will allocate the buffer.
+ *	If setvbuf(., ., _IONBF, .) is called, bufl is set to 0 and
+ *	buf, rp and wp are pointed at unbuf.
+ *	If setvbuf(., ., _IOLBF, .) is called, _IO_putc leaves wp and rp pointed at the
+ *	end of the buffer so that it can be called on each putc to check whether it's got
+ *	a newline.  This nonsense is in order to avoid impacting performance of the other
+ *	buffering modes more than necessary -- putting the test in putc adds many
+ *	instructions that are wasted in non-_IOLBF mode:
+ *	#define putc(c, f)	(_IO_ctmp=(c),\
+ *				(f)->wp>=(f)->rp || (f)->flags&LINEBUF && _IO_ctmp=='\n'\
+ *					?_IO_putc(_IO_ctmp, f)\
+ *					:*(f)->wp++=_IO_ctmp)
+ *				
+ */
+typedef struct{
+	int fd;		/* UNIX file pointer */
+	char flags;	/* bits for must free buffer on close, line-buffered */
+	char state;	/* last operation was read, write, position, error, eof */
+	char *buf;	/* pointer to i/o buffer */
+	char *rp;	/* read pointer (or write end-of-buffer) */
+	char *wp;	/* write pointer (or read end-of-buffer) */
+	char *lp;	/* actual write pointer used when line-buffering */
+	size_t bufl;	/* actual length of buffer */
+	char unbuf[1];	/* tiny buffer for unbuffered io (used for ungetc?) */
+}FILE;
+typedef long long fpos_t;
+#ifndef NULL
+#ifdef __cplusplus
+#define NULL 0
+#else
+#define NULL ((void*)0)
+#endif
+#endif
+/*
+ * Third arg of setvbuf
+ */
+#define	_IOFBF	1			/* block-buffered */
+#define	_IOLBF	2			/* line-buffered */
+#define	_IONBF	3			/* unbuffered */
+#define	BUFSIZ	4096			/* size of setbuf buffer */
+#define	EOF	(-1)			/* returned on end of file */
+#define	FOPEN_MAX	90		/* max files open */
+#define	FILENAME_MAX	BUFSIZ		/* silly filename length */
+#define	L_tmpnam	20		/* sizeof "/tmp/abcdefghij9999 */
+#define	L_cuserid	32		/* maximum size user name */
+#define	L_ctermid	32		/* size of name of controlling tty */
+#define	SEEK_CUR	1
+#define	SEEK_END	2
+#define	SEEK_SET	0
+#define	TMP_MAX		64		/* very hard to set correctly */
+#define	stderr	(&_IO_stream[2])
+#define	stdin	(&_IO_stream[0])
+#define	stdout	(&_IO_stream[1])
+#define	_IO_CHMASK	0377		/* mask for 8 bit characters */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern int remove(const char *);
+extern int rename(const char *, const char *);
+extern FILE *tmpfile(void);
+extern char *tmpnam(char *);
+extern int fclose(FILE *);
+extern int fflush(FILE *);
+extern FILE *fopen(const char *, const char *);
+extern FILE *freopen(const char *, const char *, FILE *);
+extern void setbuf(FILE *, char *);
+extern int setvbuf(FILE *, char *, int, size_t);
+extern int fprintf(FILE *, const char *, ...);
+extern int fscanf(FILE *, const char *, ...);
+extern int printf(const char *, ...);
+extern int scanf(const char *, ...);
+extern int sprintf(char *, const char *, ...);
+#ifdef _C99_SNPRINTF_EXTENSION /* user knows about c99 out-of-bounds returns */
+extern int snprintf(char *, size_t, const char *, ...);
+extern int vsnprintf(char *, size_t, const char *, va_list);
+#else
+/* draw errors on any attempt to use *snprintf value so old code gets changed */
+extern void snprintf(char *, size_t, const char *, ...);
+extern void vsnprintf(char *, size_t, const char *, va_list);
+#endif
+extern int sscanf(const char *, const char *, ...);
+extern int vfprintf(FILE *, const char *, va_list);
+extern int vprintf(const char *, va_list);
+extern int vsprintf(char *, const char *, va_list);
+extern int vfscanf(FILE *, const char *, va_list);
+extern int fgetc(FILE *);
+extern char *fgets(char *, int, FILE *);
+extern int fputc(int, FILE *);
+extern int fputs(const char *, FILE *);
+extern int getc(FILE *);
+#define	getc(f)	((f)->rp>=(f)->wp?_IO_getc(f):*(f)->rp++&_IO_CHMASK)
+extern int _IO_getc(FILE *f);
+extern int getchar(void);
+#define	getchar()	getc(stdin)
+extern char *gets(char *);
+extern int putc(int, FILE *);
+#define	putc(c, f) ((f)->wp>=(f)->rp?_IO_putc(c, f):(*(f)->wp++=c)&_IO_CHMASK)
+extern int _IO_putc(int, FILE *);
+extern int putchar(int);
+#define	putchar(c)	putc(c, stdout)
+extern int puts(const char *);
+extern int ungetc(int, FILE *);
+extern size_t fread(void *, size_t, size_t, FILE *);
+extern size_t fwrite(const void *, size_t, size_t, FILE *);
+extern int fgetpos(FILE *, fpos_t *);
+extern int fseek(FILE *, long, int);
+extern int fseeko(FILE *, off_t, int);
+extern int fsetpos(FILE *, const fpos_t *);
+extern long ftell(FILE *);
+extern off_t ftello(FILE *);
+extern void rewind(FILE *);
+extern void clearerr(FILE *);
+extern int feof(FILE *);
+extern int ferror(FILE *);
+extern void perror(const char *);
+extern FILE _IO_stream[FOPEN_MAX];
+
+#ifdef _POSIX_SOURCE
+extern int fileno(FILE *);
+extern FILE* fdopen(int, const char*);
+extern char *ctermid(char *);
+#endif
+
+#ifdef _REENTRANT_SOURCE
+extern char *tmpnam_r(char *);
+extern char *ctermid_r(char *);
+#endif
+
+#ifdef _BSD_EXTENSION
+#pragma lib "/$M/lib/ape/libbsd.a"
+extern FILE *popen(char *, char *);
+extern int	pclose(FILE *);
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif

+ 55 - 0
sys/include/ape/stdlib.h

@@ -0,0 +1,55 @@
+#ifndef __STDLIB_H
+#define __STDLIB_H
+#pragma lib "/$M/lib/ape/libap.a"
+
+#include <stddef.h>
+
+#define EXIT_FAILURE 1
+#define EXIT_SUCCESS 0
+#define MB_CUR_MAX 3
+#define RAND_MAX 32767
+
+typedef struct { int quot, rem; } div_t;
+typedef struct { long quot, rem; } ldiv_t;
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern double atof(const char *);
+extern int atoi(const char *);
+extern long int atol(const char *);
+extern long long atoll(const char *);
+extern double strtod(const char *, char **);
+extern long int strtol(const char *, char **, int);
+extern unsigned long int strtoul(const char *, char **, int);
+extern long long int strtoll(const char *, char **, int);
+extern unsigned long long int strtoull(const char *, char **, int);
+extern int rand(void);
+extern void srand(unsigned int seed);
+extern void *calloc(size_t, size_t);
+extern void free(void *);
+extern void *malloc(size_t);
+extern void *realloc(void *, size_t);
+extern void abort(void);
+extern int atexit(void (*func)(void));
+extern void exit(int);
+extern char *getenv(const char *);
+extern int system(const char *);
+extern void *bsearch(const void *, const void *, size_t, size_t, int (*)(const void *, const void *));
+extern void qsort(void *, size_t, size_t, int (*)(const void *, const void *));
+extern int abs(int);
+extern div_t div(int, int);
+extern long int labs(long int);
+extern ldiv_t ldiv(long int, long int);
+extern int mblen(const char *, size_t);
+extern int mbtowc(wchar_t *, const char *, size_t);
+extern int wctomb(char *, wchar_t);
+extern size_t mbstowcs(wchar_t *, const char *, size_t);
+extern size_t wcstombs(char *, const wchar_t *, size_t);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __STDLIB_H */

+ 47 - 0
sys/include/ape/string.h

@@ -0,0 +1,47 @@
+#ifndef __STRING_H_
+#define __STRING_H_
+#pragma lib "/$M/lib/ape/libap.a"
+
+#include <stddef.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern void *memcpy(void *, const void *, size_t);
+extern void *memmove(void *, const void *, size_t);
+extern char *strcpy(char *, const char *);
+extern char *strncpy(char *, const char *, size_t);
+extern char *strcat(char *, const char *);
+extern char *strncat(char *, const char *, size_t);
+extern int memcmp(const void *, const void *, size_t);
+extern int strcmp(const char *, const char *);
+extern int strcoll(const char *, const char *);
+extern int strncmp(const char *, const char *, size_t);
+extern size_t strxfrm(char *, const char *, size_t);
+extern void *memchr(const void *, int, size_t);
+extern char *strchr(const char *, int);
+extern size_t strcspn(const char *, const char *);
+extern char *strpbrk(const char *, const char *);
+extern char *strrchr(const char *, int);
+extern size_t strspn(const char *, const char *);
+extern char *strstr(const char *, const char *);
+extern char *strtok(char *, const char *);
+extern void *memset(void *, int, size_t);
+extern char *strerror(int);
+extern size_t strlen(const char *);
+
+#ifdef _REENTRANT_SOURCE
+extern char *strerror_r(int, const char *, int);
+extern char *strtok_r(char *, const char *, char **);
+#endif
+
+#ifdef _BSD_EXTENSION
+#include <bsd.h>
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif

+ 22 - 0
sys/include/ape/sys/ioctl.h

@@ -0,0 +1,22 @@
+#ifndef __IOCTL_H__
+#define __IOCTL_H__
+
+#ifndef _BSD_EXTENSION
+    This header file is an extension to ANSI/POSIX
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* FIONREAD: return number of bytes readable in *(long*)arg */
+#define FIONREAD 1
+
+int ioctl(int, unsigned long, void*);
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif /* !__IOCTL_H__ */

+ 28 - 0
sys/include/ape/sys/limits.h

@@ -0,0 +1,28 @@
+/*
+	local limits
+*/
+
+#undef	ARG_MAX
+#define	ARG_MAX		16384
+#undef	CHILD_MAX
+#define	CHILD_MAX	75
+#undef	OPEN_MAX
+#define	OPEN_MAX	96
+#undef	LINK_MAX
+#define	LINK_MAX	1
+#undef	NAME_MAX
+#define	NAME_MAX	27
+#undef	PATH_MAX
+#define	PATH_MAX	1023
+#undef	NGROUPS_MAX
+#define	NGROUPS_MAX	32
+#undef	MAX_CANON
+#define	MAX_CANON	1023
+#undef	MAX_INPUT
+#define	MAX_INPUT	1023
+#undef	PIPE_BUF
+#define	PIPE_BUF	8192
+
+#define	_POSIX_SAVED_IDS		1
+#define	_POSIX_CHOWN_RESTRICTED		1
+#define	_POSIX_NO_TRUNC			1

+ 18 - 0
sys/include/ape/sys/param.h

@@ -0,0 +1,18 @@
+#ifndef __PARAM_H__
+#define __PARAM_H__
+
+#ifndef _BSD_EXTENSION
+    This header file is an extension to ANSI/POSIX
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define NOFILES_MAX 100
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* !__PARAM_H__ */

+ 18 - 0
sys/include/ape/sys/pty.h

@@ -0,0 +1,18 @@
+/*
+ * Pty support
+ */
+#ifndef __SYS_PTY_H__
+#define __SYS_PTY_H__
+
+#ifndef _BSD_EXTENSION
+    This header file is an extension to ANSI/POSIX
+#endif
+
+#pragma lib "/$M/lib/ape/libbsd.a"
+
+char*	ptsname(int);
+char*	ptmname(int);
+
+int	_getpty(void);
+
+#endif /* !__SYS_UIO_H__ */

+ 29 - 0
sys/include/ape/sys/resource.h

@@ -0,0 +1,29 @@
+#ifndef __RESOURCE_H__
+#define __RESOURCE_H__
+
+#ifndef _BSD_EXTENSION
+    This header file is an extension to ANSI/POSIX
+#endif
+
+struct rusage {
+	struct timeval ru_utime;	/* user time used */
+	struct timeval ru_stime;	/* system time used */
+	long	ru_maxrss;		/* max resident set size */
+#define	ru_first	ru_ixrss
+	long	ru_ixrss;		/* integral shared memory size */
+	long	ru_idrss;		/* integral unshared data " */
+	long	ru_isrss;		/* integral unshared stack " */
+	long	ru_minflt;		/* page reclaims */
+	long	ru_majflt;		/* page faults */
+	long	ru_nswap;		/* swaps */
+	long	ru_inblock;		/* block input operations */
+	long	ru_oublock;		/* block output operations */
+	long	ru_msgsnd;		/* messages sent */
+	long	ru_msgrcv;		/* messages received */
+	long	ru_nsignals;		/* signals received */
+	long	ru_nvcsw;		/* voluntary context switches */
+	long	ru_nivcsw;		/* involuntary " */
+#define	ru_last		ru_nivcsw
+};
+
+#endif /* !__RESOURCE_H__ */

+ 34 - 0
sys/include/ape/sys/select.h

@@ -0,0 +1,34 @@
+#ifndef __SELECT_H
+#define __SELECT_H
+#ifndef _BSD_EXTENSION
+    This header file is an extension to ANSI/POSIX
+#endif
+#pragma lib "/$M/lib/ape/libap.a"
+
+#ifndef _FD_SET_T
+#define _FD_SET_T
+/* BSD select, and adjunct types and macros */
+
+/* assume 96 fds is sufficient for fdset size */
+
+typedef struct fd_set {
+	long fds_bits[3];
+} fd_set;
+
+#define FD_SET(n,p)	((p)->fds_bits[(n)>>5] |= (1 << ((n) &0x1f)))
+#define FD_CLR(n,p)	((p)->fds_bits[(n)>>5] &= ~(1 << ((n) &0x1f)))
+#define FD_ISSET(n,p)	((p)->fds_bits[(n)>>5] & (1 << ((n) &0x1f)))
+#define FD_ZERO(p)	((p)->fds_bits[0] =0, (p)->fds_bits[1] =0, (p)->fds_bits[2] =0)
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern int select(int, fd_set*, fd_set*, fd_set*, struct timeval *);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif

+ 196 - 0
sys/include/ape/sys/socket.h

@@ -0,0 +1,196 @@
+#ifndef __SYS_SOCKET_H__
+#define __SYS_SOCKET_H__
+
+#ifndef _BSD_EXTENSION
+    This header file is an extension to ANSI/POSIX
+#endif
+
+#pragma lib "/$M/lib/ape/libbsd.a"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * Copyright (c) 1982,1985, 1986 Regents of the University of California.
+ * All rights reserved.  The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ *
+ *	@(#)socket.h	7.1 (Berkeley) 6/4/86
+ */
+
+/*
+ * Definitions related to sockets: types, address families, options.
+ */
+
+/*
+ * Types
+ */
+#define	SOCK_STREAM	1		/* stream socket */
+#define	SOCK_DGRAM	2		/* datagram socket */
+#define	SOCK_RAW	3		/* raw-protocol interface */
+#define	SOCK_RDM	4		/* reliably-delivered message */
+#define	SOCK_SEQPACKET	5		/* sequenced packet stream */
+
+/*
+ * Option flags per-socket.
+ */
+#ifdef HAVE_SOCK_OPTS
+#define	SO_DEBUG	0x0001		/* turn on debugging info recording */
+#define	SO_ACCEPTCONN	0x0002		/* socket has had listen() */
+#define	SO_REUSEADDR	0x0004		/* allow local address reuse */
+#define	SO_KEEPALIVE	0x0008		/* keep connections alive */
+#define	SO_DONTROUTE	0x0010		/* just use interface addresses */
+#define	SO_BROADCAST	0x0020		/* permit sending of broadcast msgs */
+#define	SO_USELOOPBACK	0x0040		/* bypass hardware when possible */
+#define	SO_LINGER	0x0080		/* linger on close if data present */
+#define	SO_OOBINLINE	0x0100		/* leave received OOB data in line */
+#endif
+
+/*
+ * Additional options, not kept in so_options.
+ */
+#define SO_SNDBUF	0x1001		/* send buffer size */
+#define SO_RCVBUF	0x1002		/* receive buffer size */
+#define SO_SNDLOWAT	0x1003		/* send low-water mark */
+#define SO_RCVLOWAT	0x1004		/* receive low-water mark */
+#define SO_SNDTIMEO	0x1005		/* send timeout */
+#define SO_RCVTIMEO	0x1006		/* receive timeout */
+#define	SO_ERROR	0x1007		/* get error status and clear */
+#define	SO_TYPE		0x1008		/* get socket type */
+
+/*
+ * Structure used for manipulating linger option.
+ */
+struct	linger {
+	int	l_onoff;		/* option on/off */
+	int	l_linger;		/* linger time */
+};
+
+/*
+ * Level number for (get/set)sockopt() to apply to socket itself.
+ */
+#define	SOL_SOCKET	0xffff		/* options for socket level */
+
+/*
+ * Address families.
+ * XTP really is not an address family, but is included here to take
+ * up space, because other AF_ entries are numerically equal to their
+ * PF_ counterparts.
+ */
+#define	AF_UNSPEC	0		/* unspecified */
+#define	AF_UNIX		1		/* local to host (pipes, portals) */
+#define	AF_INET		2		/* internetwork: UDP, TCP, etc. */
+#define	AF_IMPLINK	3		/* arpanet imp addresses */
+#define	AF_PUP		4		/* pup protocols: e.g. BSP */
+#define	AF_CHAOS	5		/* mit CHAOS protocols */
+#define	AF_NS		6		/* XEROX NS protocols */
+#define	AF_ISO		7		/* ISO protocols */
+#define	AF_OSI		AF_ISO
+#define	AF_ECMA		8		/* european computer manufacturers */
+#define	AF_DATAKIT	9		/* datakit protocols */
+#define	AF_CCITT	10		/* CCITT protocols, X.25 etc */
+#define	AF_SNA		11		/* IBM SNA */
+#define AF_DECnet	12		/* DECnet */
+#define AF_DLI		13		/* DEC Direct data link interface */
+#define AF_LAT		14		/* LAT */
+#define	AF_HYLINK	15		/* NSC Hyperchannel */
+#define	AF_APPLETALK	16		/* Apple Talk */
+#define	AF_ROUTE	17		/* Internal Routing Protocol */
+#define	AF_LINK		18		/* Link layer interface */
+#define	pseudo_AF_XTP	19		/* eXpress Transfer Protocol (no AF) */
+#define AF_INET6	24		/* IP version 6 */
+#define	AF_MAX		30
+
+/*
+ * Structure used by kernel to store most
+ * addresses.
+ */
+struct sockaddr {
+	unsigned short	sa_family;	/* address family */
+	char	sa_data[108];
+};
+
+/*
+ * Structure used by kernel to pass protocol
+ * information in raw sockets.
+ */
+struct sockproto {
+	unsigned short	sp_family;		/* address family */
+	unsigned short	sp_protocol;		/* protocol */
+};
+
+/*
+ * Protocol families, same as address families for now.
+ */
+#define	PF_UNSPEC	AF_UNSPEC
+#define	PF_UNIX		AF_UNIX
+#define	PF_INET		AF_INET
+#define	PF_IMPLINK	AF_IMPLINK
+#define	PF_PUP		AF_PUP
+#define	PF_CHAOS	AF_CHAOS
+#define	PF_NS		AF_NS
+#define	PF_ISO		AF_ISO
+#define	PF_OSI		AF_ISO
+#define	PF_ECMA		AF_ECMA
+#define	PF_DATAKIT	AF_DATAKIT
+#define	PF_CCITT	AF_CCITT
+#define	PF_SNA		AF_SNA
+#define PF_DECnet	AF_DECnet
+#define PF_DLI		AF_DLI
+#define PF_LAT		AF_LAT
+#define	PF_HYLINK	AF_HYLINK
+#define	PF_APPLETALK	AF_APPLETALK
+#define	PF_ROUTE	AF_ROUTE
+#define	PF_LINK		AF_LINK
+#define	PF_XTP		pseudo_AF_XTP	/* really just proto family, no AF */
+#define	PF_INET6	AF_INET6
+
+#define	PF_MAX		AF_MAX
+
+/*
+ * Maximum queue length specifiable by listen.
+ */
+#define	SOMAXCONN	5
+
+/*
+ * Message header for recvmsg and sendmsg calls.
+ */
+struct msghdr {
+	char	*msg_name;		/* optional address */
+	int	msg_namelen;		/* size of address */
+	struct	iovec *msg_iov;		/* scatter/gather array */
+	int	msg_iovlen;		/* # elements in msg_iov */
+	char	*msg_accrights;		/* access rights sent/received */
+	int	msg_accrightslen;
+};
+
+#define	MSG_OOB		0x1		/* process out-of-band data */
+#define	MSG_PEEK	0x2		/* peek at incoming message */
+#define	MSG_DONTROUTE	0x4		/* send without using routing tables */
+
+#define	MSG_MAXIOVLEN	16
+
+extern int accept(int, void *, int *);
+extern int bind(int, void *, int);
+extern int connect(int, void *, int);
+extern int getpeername(int, void *, int *);
+extern int getsockname(int, void *, int *);
+extern int getsockopt(int, int, int, void *, int *);
+extern int setsockopt(int, int, int, void *, int);
+extern int listen(int, int);
+extern int recv(int, void *, int, int);
+extern int recvfrom(int, void *, int, int, void *, int *);
+extern int recvmsg(int, struct msghdr *, int);
+extern int send(int, void *, int, int);
+extern int sendto(int, void *, int, int, void *, int);
+extern int sendmsg(int, struct msghdr *, int);
+extern int shutdown(int, int);
+extern int socket(int, int, int);
+extern int socketpair(int, int, int, int *);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* !__SYS_SOCKET_H__ */

+ 84 - 0
sys/include/ape/sys/stat.h

@@ -0,0 +1,84 @@
+#ifndef __STAT_H
+#define __STAT_H
+
+#ifndef __TYPES_H
+#include <sys/types.h>
+#endif
+
+#pragma lib "/$M/lib/ape/libap.a"
+
+/*
+ * stat structure, used by stat(2) and fstat(2)
+ */
+struct	stat {
+	dev_t	st_dev;
+	ino_t	st_ino;
+	mode_t 	st_mode;
+	nlink_t	st_nlink;
+	uid_t 	st_uid;
+	gid_t 	st_gid;
+	off_t	st_size;
+	time_t	st_atime;
+	time_t	st_mtime;
+	time_t	st_ctime;
+};
+
+#define	S__MASK		     0170000
+#ifdef _RESEARCH_SOURCE
+#define S_ISLNK(m)	(((m)&S__MASK) == 0120000)
+#endif
+#define S_ISREG(m)	(((m)&S__MASK) == 0100000)
+#define S_ISDIR(m)	(((m)&S__MASK) == 0040000)
+#define S_ISCHR(m)	(((m)&S__MASK) == 0020000)
+#define S_ISBLK(m)	(((m)&S__MASK) == 0060000)
+#define S_ISFIFO(m)	(((m)&S__MASK) == 0010000)
+
+#define	S_ISUID	04000		/* set user id on execution */
+#define	S_ISGID	02000		/* set group id on execution */
+#define	S_IRWXU	00700		/* read, write, execute: owner */
+#define	S_IRUSR	00400		/* read permission: owner */
+#define	S_IWUSR	00200		/* write permission: owner */
+#define	S_IXUSR	00100		/* execute permission: owner */
+#define	S_IRWXG	00070		/* read, write, execute: group */
+#define	S_IRGRP	00040		/* read permission: group */
+#define	S_IWGRP	00020		/* write permission: group */
+#define	S_IXGRP	00010		/* execute permission: group */
+#define	S_IRWXO	00007		/* read, write, execute: other */
+#define	S_IROTH	00004		/* read permission: other */
+#define	S_IWOTH	00002		/* write permission: other */
+#define	S_IXOTH	00001		/* execute permission: other */
+
+#ifdef _BSD_EXTENSION
+#define S_IFMT S__MASK
+#define S_IFDIR 0040000
+#define S_IFCHR 0020000
+#define S_IFBLK 0060000
+#define S_IFREG 0100000
+#define S_IFIFO 0010000
+#define S_IFLNK 0120000
+#define S_IFSOCK S_IFIFO
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern mode_t umask(mode_t);
+extern int mkdir(const char *, mode_t);
+extern int mkfifo(const char *, mode_t);
+extern int stat(const char *, struct stat *);
+extern int fstat(int, struct stat *);
+extern int chmod(const char *, mode_t);
+
+#ifdef _BSD_EXTENSION
+#pragma lib "/$M/lib/ape/libbsd.a"
+extern int	lstat(char *, struct stat *);
+extern int	symlink(char *, char *);
+extern int	readlink(char *, char*, int);
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif

+ 22 - 0
sys/include/ape/sys/time.h

@@ -0,0 +1,22 @@
+#ifndef __SYSTIME_H
+#define __SYSTIME_H
+#pragma lib "/$M/lib/ape/libap.a"
+
+#ifndef __TIMEVAL__
+#define __TIMEVAL__
+struct timeval {
+	long	tv_sec;
+	long	tv_usec;
+};
+
+#ifdef _BSD_EXTENSION
+struct timezone {
+	int	tz_minuteswest;
+	int	tz_dsttime;
+};
+#endif
+#endif /* __TIMEVAL__ */
+
+extern int gettimeofday(struct timeval *, struct timezone *);
+
+#endif /* __SYSTIME_H */

+ 27 - 0
sys/include/ape/sys/times.h

@@ -0,0 +1,27 @@
+#ifndef __TIMES_H
+#define __TIMES_H
+#pragma lib "/$M/lib/ape/libap.a"
+
+#ifndef _CLOCK_T
+#define _CLOCK_T
+typedef long clock_t;
+#endif
+
+struct tms {
+	clock_t	tms_utime;
+	clock_t	tms_stime;
+	clock_t	tms_cutime;
+	clock_t	tms_cstime;
+};
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+clock_t times(struct tms *);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif

+ 46 - 0
sys/include/ape/sys/types.h

@@ -0,0 +1,46 @@
+#ifndef __TYPES_H
+#define __TYPES_H
+
+#pragma lib "/$M/lib/ape/libap.a"
+typedef	unsigned short	ino_t;
+typedef	unsigned short	dev_t;
+typedef	long long		off_t;
+typedef unsigned short	mode_t;
+typedef short		uid_t;
+typedef short		gid_t;
+typedef short		nlink_t;
+typedef int		pid_t;
+
+#ifndef _SIZE_T
+#define _SIZE_T
+typedef unsigned long size_t;
+#endif
+#ifndef _SSIZE_T
+#define _SSIZE_T
+typedef long ssize_t;
+#endif
+
+#ifndef _TIME_T
+#define _TIME_T
+typedef long time_t;
+#endif
+
+#ifdef _BSD_EXTENSION
+#ifndef _CADDR_T
+#define _CADDR_T
+typedef char * caddr_t;
+#endif
+#ifndef _FD_SET_T
+#define _FD_SET_T
+/* also cf <select.h> */
+typedef struct fd_set {
+	long fds_bits[3];
+} fd_set;
+#define FD_SET(n,p)	((p)->fds_bits[(n)>>5] |= (1 << ((n) &0x1f)))
+#define FD_CLR(n,p)	((p)->fds_bits[(n)>>5] &= ~(1 << ((n) &0x1f)))
+#define FD_ISSET(n,p)	((p)->fds_bits[(n)>>5] & (1 << ((n) &0x1f)))
+#define FD_ZERO(p)	((p)->fds_bits[0] =0, (p)->fds_bits[1] =0, (p)->fds_bits[2] =0)
+#endif
+#endif
+
+#endif /* __TYPES_H */

+ 34 - 0
sys/include/ape/sys/uio.h

@@ -0,0 +1,34 @@
+#ifndef __SYS_UIO_H__
+#define __SYS_UIO_H__
+
+#ifndef _BSD_EXTENSION
+    This header file is an extension to ANSI/POSIX
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#pragma lib "/$M/lib/ape/libbsd.a"
+
+/*
+ * Copyright (c) 1982, 1986 Regents of the University of California.
+ * All rights reserved.  The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ *
+ *	@(#)uio.h	7.1 (Berkeley) 6/4/86
+ */
+
+struct iovec {
+	char	*iov_base;
+	int	iov_len;
+};
+
+extern int writev(int, struct iovec*, int);
+extern int readv(int, struct iovec*, int);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* !__SYS_UIO_H__ */

+ 26 - 0
sys/include/ape/sys/un.h

@@ -0,0 +1,26 @@
+/*
+ * Copyright (c) 1982, 1986 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.
+ *
+ *	@(#)un.h	7.3 (Berkeley) 6/27/88
+ */
+
+/*
+ * Definitions for UNIX IPC domain.
+ */
+struct	sockaddr_un {
+	short	sun_family;		/* AF_UNIX */
+	char	sun_path[108];		/* path name (gag) */
+};

+ 23 - 0
sys/include/ape/sys/utsname.h

@@ -0,0 +1,23 @@
+#ifndef __UTSNAME
+#define __UTSNAME
+#pragma lib "/$M/lib/ape/libap.a"
+
+struct utsname {
+	char	*sysname;
+	char	*nodename;
+	char	*release;
+	char	*version;
+	char	*machine;
+};
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+int uname(struct utsname *);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif

+ 35 - 0
sys/include/ape/sys/wait.h

@@ -0,0 +1,35 @@
+#ifndef __WAIT_H
+#define __WAIT_H
+#pragma lib "/$M/lib/ape/libap.a"
+
+/* flag bits for third argument of waitpid */
+#define WNOHANG		0x1
+#define WUNTRACED	0x2
+
+/* macros for examining status returned */
+#ifndef WIFEXITED
+#define WIFEXITED(s)	(((s) & 0xFF) == 0)
+#define WEXITSTATUS(s)	((s>>8)&0xFF)
+#define WIFSIGNALED(s)	(((s) & 0xFF) != 0)
+#define WTERMSIG(s)	((s) & 0xFF)
+#define WIFSTOPPED(s)	(0)
+#define WSTOPSIG(s)	(0)
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+pid_t wait(int *);
+pid_t waitpid(pid_t, int *, int);
+#ifdef _BSD_EXTENSION
+struct rusage;
+pid_t wait3(int *, int, struct rusage *);
+pid_t wait4(pid_t, int *, int, struct rusage *);
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif

+ 132 - 0
sys/include/ape/termios.h

@@ -0,0 +1,132 @@
+#pragma lib "/$M/lib/ape/libap.a"
+/* input modes */
+#define BRKINT	0x001
+#define ICRNL	0x002
+#define IGNBRK	0x004
+#define IGNCR	0x008
+#define IGNPAR	0x010
+#define INLCR	0x020
+#define INPCK	0x040
+#define ISTRIP	0x080
+#define IXOFF	0x100
+#define IXON	0x200
+#define PARMRK	0x400
+
+/* output modes: ONLCR, TAB3 are an extension to POSIX! */
+#define	OPOST	0000001
+#define	OLCUC	0000002
+#define	ONLCR	0000004
+#define	OCRNL	0000010
+#define	ONOCR	0000020
+#define	ONLRET	0000040
+#define	OFILL	0000100
+#define	OFDEL	0000200
+#define	NLDLY	0000400
+#define	NL0	0
+#define	NL1	0000400
+#define	CRDLY	0003000
+#define	CR0	0
+#define	CR1	0001000
+#define	CR2	0002000
+#define	CR3	0003000
+#define	TABDLY	0014000
+#define	TAB0	0
+#define	TAB1	0004000
+#define	TAB2	0010000
+#define	TAB3	0014000
+#define	BSDLY	0020000
+#define	BS0	0
+#define	BS1	0020000
+#define	VTDLY	0040000
+#define	VT0	0
+#define	VT1	0040000
+#define	FFDLY	0100000
+#define	FF0	0
+#define	FF1	0100000
+
+/* control modes */
+#define CLOCAL	0x001
+#define CREAD	0x002
+#define CSIZE	0x01C
+#define CS5	0x004
+#define CS6	0x008
+#define CS7	0x00C
+#define CS8	0x010
+#define CSTOPB	0x020
+#define HUPCL	0x040
+#define PARENB	0x080
+#define PARODD	0x100
+
+/* local modes */
+#define ECHO	0x001
+#define ECHOE	0x002
+#define ECHOK	0x004
+#define ECHONL	0x008
+#define ICANON	0x010
+#define IEXTEN	0x020
+#define ISIG	0x040
+#define NOFLSH	0x080
+#define TOSTOP	0x100
+
+/* control characters */
+#define VEOF	0
+#define VEOL	1
+#define VERASE	2
+#define VINTR	3
+#define VKILL	4
+#define VMIN	5
+#define VQUIT	6
+#define VSUSP	7
+#define VTIME	8
+#define VSTART	9
+#define VSTOP	10
+#define NCCS	11
+
+/* baud rates */
+#define B0	0
+#define B50	1
+#define B75	2
+#define B110	3
+#define B134	4
+#define B150	5
+#define B200	6
+#define B300	7
+#define B600	8
+#define B1200	9
+#define B1800	10
+#define B2400	11
+#define B4800	12
+#define B9600	13
+#define B19200	14
+#define B38400	15
+
+/* optional actions for tcsetattr */
+#define TCSANOW	  1
+#define TCSADRAIN 2
+#define TCSAFLUSH 3
+
+typedef unsigned long tcflag_t;
+typedef unsigned long speed_t;
+typedef unsigned char cc_t;
+
+struct termios {
+	tcflag_t	c_iflag;	/* input modes */
+	tcflag_t	c_oflag;	/* output modes */
+	tcflag_t	c_cflag;	/* control modes */
+	tcflag_t	c_lflag;	/* local modes */
+	cc_t		c_cc[NCCS];	/* control characters */
+};
+
+extern speed_t cfgetospeed(const struct termios *);
+extern int cfsetospeed(struct termios *, speed_t);
+extern speed_t cfgetispeed(const struct termios *);
+extern int cfsetispeed(struct termios *, speed_t);
+extern int tcgetattr(int, struct termios *);
+extern int tcsetattr(int, int, const struct termios *);
+#ifdef __TYPES_H
+extern pid_t tcgetpgrp(int);
+extern int tcsetpgrp(int, pid_t);
+#endif
+extern int tcdrain(int);
+extern int tcflush(int, int);
+extern int tcflow(int, int);

+ 65 - 0
sys/include/ape/time.h

@@ -0,0 +1,65 @@
+#ifndef __TIME_H
+#define __TIME_H
+#pragma lib "/$M/lib/ape/libap.a"
+
+#include <stddef.h>
+
+#define CLOCKS_PER_SEC 1000
+
+/* obsolsecent, but required */
+#define CLK_TCK CLOCKS_PER_SEC
+
+#ifndef _CLOCK_T
+#define _CLOCK_T
+typedef long clock_t;
+#endif
+#ifndef _TIME_T
+#define _TIME_T
+typedef long time_t;
+#endif
+
+struct tm {
+	int	tm_sec;
+	int	tm_min;
+	int	tm_hour;
+	int	tm_mday;
+	int	tm_mon;
+	int	tm_year;
+	int	tm_wday;
+	int	tm_yday;
+	int	tm_isdst;
+};
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern clock_t clock(void);
+extern double difftime(time_t, time_t);
+extern time_t mktime(struct tm *);
+extern time_t time(time_t *);
+extern char *asctime(const struct tm *);
+extern char *ctime(const time_t *);
+extern struct tm *gmtime(const time_t *);
+extern struct tm *localtime(const time_t *);
+extern size_t strftime(char *, size_t, const char *, const struct tm *);
+
+#ifdef _REENTRANT_SOURCE
+extern struct tm *gmtime_r(const time_t *, struct tm *);
+extern struct tm *localtime_r(const time_t *, struct tm *);
+extern char *ctime_r(const time_t *, char *);
+#endif
+
+#ifdef _POSIX_SOURCE
+extern void tzset(void);
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#ifdef _POSIX_SOURCE
+extern char *tzname[2];
+#endif
+
+#endif /* __TIME_H */

+ 19 - 0
sys/include/ape/u.h

@@ -0,0 +1,19 @@
+#ifndef __U_H
+#define __U_H
+#ifndef _PLAN9_SOURCE
+   This header file is an extension to ANSI/POSIX
+#endif
+
+#define nil		((void*)0)
+typedef	unsigned short	ushort;
+typedef	unsigned char	uchar;
+typedef unsigned long	ulong;
+typedef unsigned int	uint;
+typedef   signed char	schar;
+typedef	long long	vlong;
+typedef	unsigned long long uvlong;
+typedef	ushort		Rune;
+typedef 	union FPdbleword FPdbleword;
+typedef	char*	p9va_list;
+
+#endif

+ 168 - 0
sys/include/ape/unistd.h

@@ -0,0 +1,168 @@
+#ifndef	__UNISTD_H
+#define	__UNISTD_H
+#ifndef _POSIX_SOURCE
+   This header file is not defined in pure ANSI
+#endif
+#pragma lib "/$M/lib/ape/libap.a"
+
+#define _POSIX_VERSION	199309L
+#define _POSIX_ASYNC_IO -1
+#define _POSIX_CHOWN_RESTRICTED 1
+#define _POSIX_NO_TRUNC 1
+#define _POSIX_PRIO_IO -1
+#define _POSIX_SYNC_IO -1
+#define _POSIX_VDISABLE -1
+
+#ifndef _SIZE_T
+#define _SIZE_T
+typedef unsigned long size_t;
+#endif
+#ifndef _SSIZE_T
+#define _SSIZE_T
+typedef long ssize_t;
+#endif
+#ifndef NULL
+#ifndef NULL
+#ifdef __cplusplus
+#define NULL 0
+#else
+#define NULL ((void*)0)
+#endif
+#endif
+#endif
+
+/* access */
+#define	R_OK		4
+#define	W_OK		2
+#define	X_OK		1
+#define	F_OK		0	/* test for existence */
+
+/* lockf */
+#define	F_ULOCK		0	/* unlock a previously locked region */
+#define	F_LOCK		1	/* lock a region for exclusive use */
+#define	F_TLOCK		2	/* test and lock a region for exclusive use */
+#define	F_TEST		3	/* test a region for a previous lock */
+
+/* lseek */
+#ifndef SEEK_SET		/* also defined in stdio.h */
+#define	SEEK_SET	0
+#define	SEEK_CUR	1
+#define	SEEK_END	2
+#endif
+
+/* sysconf argument */
+#define	_SC_ARG_MAX		1	/* max chars in args to exec */
+#define	_SC_CHILD_MAX		2	/* max child process per process */
+#define	_SC_CLK_TCK		3	/* number of clock() units per second */
+#define	_SC_NGROUPS_MAX		4	/* max supplementary groups per process */
+#define	_SC_OPEN_MAX		5
+#define _SC_STREAM_MAX		6
+#define _SC_TZNAME_MAX		7
+#define	_SC_JOB_CONTROL		8	/* posix job control */
+#define	_SC_SAVED_IDS		9	/* saved suid/sgid per process */
+#define	_SC_VERSION		10	/* this version */
+#define _SC_LOGIN_NAME_MAX	11	/* max length of a login name */
+
+/* pathconf argument */
+#define _PC_LINK_MAX		1
+#define _PC_MAX_CANON		2
+#define _PC_MAX_INPUT		3
+#define _PC_NAME_MAX		4
+#define _PC_PATH_MAX		5
+#define _PC_PIPE_BUF		6
+#define _PC_CHOWN_RESTRICTED	7
+#define _PC_NO_TRUNC		8
+#define _PC_VDISABLE		9
+
+/* standard filenos */
+#define STDIN_FILENO		0
+#define STDOUT_FILENO		1
+#define STDERR_FILENO		2
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* process primitives */
+extern int execl(const char *, const char *, ...);
+extern int execv(const char *, const char **);
+extern int execle(const char *, const char *, const char *,  ...);
+extern int execve(const char *, const char **, const char **);
+extern int execlp(const char *, const char *, ...);
+extern int execvp(const char *, const char **);
+extern void _exit(int);
+extern unsigned int alarm(unsigned int);
+extern int pause(void);
+extern unsigned int sleep(unsigned int);
+#ifdef __TYPES_H
+extern pid_t fork(void);
+#endif
+
+/* process environment */
+extern char *getlogin(void);
+extern char *cuserid(char *);
+extern char *ttyname(int);
+extern int isatty(int);
+extern long sysconf(int);
+#ifdef __TYPES_H
+extern pid_t getpid(void);
+extern pid_t getppid(void);
+extern uid_t getuid(void);
+extern uid_t geteuid(void);
+extern gid_t getgid(void);
+extern gid_t getegid(void);
+extern int setuid(uid_t);
+extern int setgid(gid_t);
+extern int getgroups(int, gid_t *);
+extern pid_t getpgrp(void);
+extern int setpgid(pid_t, pid_t);
+extern pid_t setsid(void);
+#endif
+
+/* files and directories */
+extern int chdir(const char *);
+extern int link(const char *, const char *);
+extern char *getcwd(char *, size_t);
+extern int unlink(const char *);
+extern int rmdir(const char *);
+extern int rename(const char *, const char *);
+extern int access(const char *, int);
+extern long pathconf(const char *, int);
+extern long fpathconf(int, int);
+#ifdef __TYPES_H
+extern int chown(const char *, uid_t, gid_t);
+#endif
+
+/* input and output primitives */
+extern int pipe(int *);
+extern int dup(int);
+extern int dup2(int, int);
+extern int close(int);
+extern ssize_t read(int, void *, size_t);
+extern ssize_t write(int, const void *, size_t);
+#ifdef __TYPES_H
+extern int ftruncate(int, off_t);
+extern off_t lseek(int, off_t, int);
+#endif
+
+/* device- and class-specific functions */
+#ifdef __TYPES_H
+extern pid_t tcgetpgrp(int);
+extern int tcsetpgrp(int, pid_t);
+#endif
+
+#ifdef _REENTRANT_SOURCE
+extern char *getlogin_r(char *, int);
+#endif
+
+/* berkeley specific functions */
+#ifdef _BSD_EXTENSION
+#include <bsd.h>
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif

+ 61 - 0
sys/include/ape/utf.h

@@ -0,0 +1,61 @@
+#ifndef _UTF_H_
+#define _UTF_H_ 1
+#pragma lib "/$M/lib/ape/libutf.a"
+#pragma src "/sys/src/ape/lib/utf"
+
+#if defined(__cplusplus)
+extern "C" { 
+#endif
+
+typedef unsigned short Rune;	/* 16 bits */
+
+enum
+{
+	UTFmax		= 3,		/* maximum bytes per rune */
+	Runesync	= 0x80,		/* cannot represent part of a UTF sequence (<) */
+	Runeself	= 0x80,		/* rune and UTF sequences are the same (<) */
+	Runeerror	= 0xFFFD,		/* decoding error in UTF */
+	Runemax	= 0xFFFF,	/* 16 bit rune */
+};
+
+/*
+ * rune routines
+ */
+extern	int	runetochar(char*, Rune*);
+extern	int	chartorune(Rune*, char*);
+extern	int	runelen(long);
+extern	int	runenlen(Rune*, int);
+extern	int	fullrune(char*, int);
+extern	int	utflen(char*);
+extern	int	utfnlen(char*, long);
+extern	char*	utfrune(char*, long);
+extern	char*	utfrrune(char*, long);
+extern	char*	utfutf(char*, char*);
+extern	char*	utfecpy(char*, char*, char*);
+
+extern	Rune*	runestrcat(Rune*, Rune*);
+extern	Rune*	runestrchr(Rune*, Rune);
+extern	int	runestrcmp(Rune*, Rune*);
+extern	Rune*	runestrcpy(Rune*, Rune*);
+extern	Rune*	runestrncpy(Rune*, Rune*, long);
+extern	Rune*	runestrecpy(Rune*, Rune*, Rune*);
+extern	Rune*	runestrdup(Rune*);
+extern	Rune*	runestrncat(Rune*, Rune*, long);
+extern	int	runestrncmp(Rune*, Rune*, long);
+extern	Rune*	runestrrchr(Rune*, Rune);
+extern	long	runestrlen(Rune*);
+extern	Rune*	runestrstr(Rune*, Rune*);
+
+extern	Rune	tolowerrune(Rune);
+extern	Rune	totitlerune(Rune);
+extern	Rune	toupperrune(Rune);
+extern	int	isalpharune(Rune);
+extern	int	islowerrune(Rune);
+extern	int	isspacerune(Rune);
+extern	int	istitlerune(Rune);
+extern	int	isupperrune(Rune);
+
+#if defined(__cplusplus)
+}
+#endif
+#endif

+ 22 - 0
sys/include/ape/utime.h

@@ -0,0 +1,22 @@
+#ifndef __UTIME_H
+#define __UTIME_H
+
+#pragma lib "/$M/lib/ape/libap.a"
+
+struct utimbuf
+{
+	time_t actime;
+	time_t modtime;
+};
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern int utime(const char *, const struct utimbuf *);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif

+ 17 - 0
sys/include/ar.h

@@ -0,0 +1,17 @@
+#define	ARMAG	"!<arch>\n"
+#define	SARMAG	8
+
+#define	ARFMAG	"`\n"
+#define SARNAME	16
+
+struct	ar_hdr
+{
+	char	name[SARNAME];
+	char	date[12];
+	char	uid[6];
+	char	gid[6];
+	char	mode[8];
+	char	size[10];
+	char	fmag[2];
+};
+#define	SAR_HDR	(SARNAME+44)

+ 143 - 0
sys/include/auth.h

@@ -0,0 +1,143 @@
+#pragma	src	"/sys/src/libauth"
+#pragma	lib	"libauth.a"
+
+/*
+ * Interface for typical callers.
+ */
+
+typedef struct	AuthInfo	AuthInfo;
+typedef struct	Chalstate	Chalstate;
+typedef struct	Chapreply	Chapreply;
+typedef struct	MSchapreply	MSchapreply;
+typedef struct	UserPasswd	UserPasswd;
+typedef struct	AuthRpc		AuthRpc;
+
+enum
+{
+	MAXCHLEN=	256,		/* max challenge length	*/
+	MAXNAMELEN=	256,		/* maximum name length */
+	MD5LEN=		16,
+
+	ARok = 0,			/* rpc return values */
+	ARdone,
+	ARerror,
+	ARneedkey,
+	ARbadkey,
+	ARwritenext,
+	ARtoosmall,
+	ARtoobig,
+	ARrpcfailure,
+	ARphase,
+
+	AuthRpcMax = 4096,
+};
+
+struct AuthRpc
+{
+	int afd;
+	char ibuf[AuthRpcMax+1];	/* +1 for NUL in auth_rpc.c */
+	char obuf[AuthRpcMax];
+	char *arg;
+	uint narg;
+};
+
+struct AuthInfo
+{
+	char	*cuid;		/* caller id */
+	char	*suid;		/* server id */
+	char	*cap;		/* capability (only valid on server side) */
+	int	nsecret;	/* length of secret */
+	uchar	*secret;	/* secret */
+};
+
+struct Chalstate
+{
+	char	*user;
+	char	chal[MAXCHLEN];
+	int	nchal;
+	void	*resp;
+	int	nresp;
+
+/* for implementation only */
+	int	afd;			/* to factotum */
+	AuthRpc	*rpc;			/* to factotum */
+	char	userbuf[MAXNAMELEN];	/* temp space if needed */
+	int	userinchal;		/* user was sent to obtain challenge */
+};
+
+struct	Chapreply		/* for protocol "chap" */
+{
+	uchar	id;
+	char	resp[MD5LEN];
+};
+
+struct	MSchapreply	/* for protocol "mschap" */
+{
+	char	LMresp[24];		/* Lan Manager response */
+	char	NTresp[24];		/* NT response */
+};
+
+struct	UserPasswd
+{
+	char	*user;
+	char	*passwd;
+};
+
+extern	int	newns(char*, char*);
+extern	int	addns(char*, char*);
+
+extern	int	noworld(char*);
+extern	int	amount(int, char*, int, char*);
+
+/* these two may get generalized away -rsc */
+extern	int	login(char*, char*, char*);
+extern	int	httpauth(char*, char*);
+
+typedef struct Attr Attr;
+enum {
+	AttrNameval,		/* name=val -- when matching, must have name=val */
+	AttrQuery,		/* name? -- when matching, must be present */
+	AttrDefault,		/* name:=val -- when matching, if present must match INTERNAL */
+};
+struct Attr
+{
+	int type;
+	Attr *next;
+	char *name;
+	char *val;
+};
+
+typedef int AuthGetkey(char*);
+
+int	_attrfmt(Fmt*);
+Attr	*_copyattr(Attr*);
+Attr	*_delattr(Attr*, char*);
+Attr	*_findattr(Attr*, char*);
+void	_freeattr(Attr*);
+Attr	*_mkattr(int, char*, char*, Attr*);
+Attr	*_parseattr(char*);
+char	*_strfindattr(Attr*, char*);
+#pragma varargck type "A" Attr*
+
+extern AuthInfo*	fauth_proxy(int, AuthRpc *rpc, AuthGetkey *getkey, char *params);
+extern AuthInfo*	auth_proxy(int fd, AuthGetkey *getkey, char *fmt, ...);
+extern int		auth_getkey(char*);
+extern int		(*amount_getkey)(char*);
+extern void		auth_freeAI(AuthInfo *ai);
+extern int		auth_chuid(AuthInfo *ai, char *ns);
+extern Chalstate	*auth_challenge(char*, ...);
+extern AuthInfo*	auth_response(Chalstate*);
+extern int		auth_respond(void*, uint, char*, uint, void*, uint, AuthGetkey *getkey, char*, ...);
+extern void		auth_freechal(Chalstate*);
+extern AuthInfo*	auth_userpasswd(char *user, char *passwd);
+extern UserPasswd*	auth_getuserpasswd(AuthGetkey *getkey, char*, ...);
+extern AuthInfo*	auth_getinfo(AuthRpc *rpc);
+extern AuthRpc*		auth_allocrpc(int afd);
+extern Attr*		auth_attr(AuthRpc *rpc);
+extern void		auth_freerpc(AuthRpc *rpc);
+extern uint		auth_rpc(AuthRpc *rpc, char *verb, void *a, int n);
+extern int		auth_wep(char*, char*, ...);
+#pragma varargck argpos auth_proxy 3
+#pragma varargck argpos auth_challenge 1
+#pragma varargck argpos auth_respond 8
+#pragma varargck argpos auth_getuserpasswd 2

+ 173 - 0
sys/include/authsrv.h

@@ -0,0 +1,173 @@
+#pragma	src	"/sys/src/libauthsrv"
+#pragma	lib	"libauthsrv.a"
+
+/*
+ * Interface for talking to authentication server.
+ */
+typedef struct	Ticket		Ticket;
+typedef struct	Ticketreq	Ticketreq;
+typedef struct	Authenticator	Authenticator;
+typedef struct	Nvrsafe		Nvrsafe;
+typedef struct	Passwordreq	Passwordreq;
+typedef struct	OChapreply	OChapreply;
+typedef struct	OMSchapreply	OMSchapreply;
+
+enum
+{
+	ANAMELEN=	28,	/* name max size in previous proto */
+	AERRLEN=	64,	/* errstr max size in previous proto */
+	DOMLEN=		48,	/* authentication domain name length */
+	DESKEYLEN=	7,	/* encrypt/decrypt des key length */
+	CHALLEN=	8,	/* plan9 sk1 challenge length */
+	NETCHLEN=	16,	/* max network challenge length (used in AS protocol) */
+	CONFIGLEN=	14,
+	SECRETLEN=	32,	/* secret max size */
+
+	KEYDBOFF=	8,	/* bytes of random data at key file's start */
+	OKEYDBLEN=	ANAMELEN+DESKEYLEN+4+2,	/* old key file entry length */
+	KEYDBLEN=	OKEYDBLEN+SECRETLEN,	/* key file entry length */
+	OMD5LEN=	16,
+};
+
+/* encryption numberings (anti-replay) */
+enum
+{
+	AuthTreq=1,	/* ticket request */
+	AuthChal=2,	/* challenge box request */
+	AuthPass=3,	/* change password */
+	AuthOK=4,	/* fixed length reply follows */
+	AuthErr=5,	/* error follows */
+	AuthMod=6,	/* modify user */
+	AuthApop=7,	/* apop authentication for pop3 */
+	AuthOKvar=9,	/* variable length reply follows */
+	AuthChap=10,	/* chap authentication for ppp */
+	AuthMSchap=11,	/* MS chap authentication for ppp */
+	AuthCram=12,	/* CRAM verification for IMAP (RFC2195 & rfc2104) */
+	AuthHttp=13,	/* http domain login */
+	AuthVNC=14,	/* VNC server login (deprecated) */
+
+
+	AuthTs=64,	/* ticket encrypted with server's key */
+	AuthTc,		/* ticket encrypted with client's key */
+	AuthAs,		/* server generated authenticator */
+	AuthAc,		/* client generated authenticator */
+	AuthTp,		/* ticket encrypted with client's key for password change */
+	AuthHr,		/* http reply */
+};
+
+struct Ticketreq
+{
+	char	type;
+	char	authid[ANAMELEN];	/* server's encryption id */
+	char	authdom[DOMLEN];	/* server's authentication domain */
+	char	chal[CHALLEN];		/* challenge from server */
+	char	hostid[ANAMELEN];	/* host's encryption id */
+	char	uid[ANAMELEN];		/* uid of requesting user on host */
+};
+#define	TICKREQLEN	(3*ANAMELEN+CHALLEN+DOMLEN+1)
+
+struct Ticket
+{
+	char	num;			/* replay protection */
+	char	chal[CHALLEN];		/* server challenge */
+	char	cuid[ANAMELEN];		/* uid on client */
+	char	suid[ANAMELEN];		/* uid on server */
+	char	key[DESKEYLEN];		/* nonce DES key */
+};
+#define	TICKETLEN	(CHALLEN+2*ANAMELEN+DESKEYLEN+1)
+
+struct Authenticator
+{
+	char	num;			/* replay protection */
+	char	chal[CHALLEN];
+	ulong	id;			/* authenticator id, ++'d with each auth */
+};
+#define	AUTHENTLEN	(CHALLEN+4+1)
+
+struct Passwordreq
+{
+	char	num;
+	char	old[ANAMELEN];
+	char	new[ANAMELEN];
+	char	changesecret;
+	char	secret[SECRETLEN];	/* new secret */
+};
+#define	PASSREQLEN	(2*ANAMELEN+1+1+SECRETLEN)
+
+struct	OChapreply
+{
+	uchar	id;
+	char	uid[ANAMELEN];
+	char	resp[OMD5LEN];
+};
+
+struct	OMSchapreply
+{
+	char	uid[ANAMELEN];
+	char	LMresp[24];		/* Lan Manager response */
+	char	NTresp[24];		/* NT response */
+};
+
+/*
+ *  convert to/from wire format
+ */
+extern	int	convT2M(Ticket*, char*, char*);
+extern	void	convM2T(char*, Ticket*, char*);
+extern	void	convM2Tnoenc(char*, Ticket*);
+extern	int	convA2M(Authenticator*, char*, char*);
+extern	void	convM2A(char*, Authenticator*, char*);
+extern	int	convTR2M(Ticketreq*, char*);
+extern	void	convM2TR(char*, Ticketreq*);
+extern	int	convPR2M(Passwordreq*, char*, char*);
+extern	void	convM2PR(char*, Passwordreq*, char*);
+
+/*
+ *  convert ascii password to DES key
+ */
+extern	int	opasstokey(char*, char*);
+extern	int	passtokey(char*, char*);
+
+/*
+ *  Nvram interface
+ */
+enum {
+	NVread		= 0,	/* just read */
+	NVwrite		= 1<<0,	/* always prompt and rewrite nvram */
+	NVwriteonerr	= 1<<1,	/* prompt and rewrite nvram when corrupt */
+	NVwritemem	= 1<<2,	/* don't prompt, write nvram from argument */
+};
+
+/* storage layout */
+struct Nvrsafe
+{
+	char	machkey[DESKEYLEN];	/* was file server's authid's des key */
+	uchar	machsum;
+	char	authkey[DESKEYLEN];	/* authid's des key from password */
+	uchar	authsum;
+	/*
+	 * file server config string of device holding full configuration;
+	 * secstore key on non-file-servers.
+	 */
+	char	config[CONFIGLEN];
+	uchar	configsum;
+	char	authid[ANAMELEN];	/* auth userid, e.g., bootes */
+	uchar	authidsum;
+	char	authdom[DOMLEN]; /* auth domain, e.g., cs.bell-labs.com */
+	uchar	authdomsum;
+};
+
+extern	uchar	nvcsum(void*, int);
+extern int	readnvram(Nvrsafe*, int);
+
+/*
+ *  call up auth server
+ */
+extern	int	authdial(char *netroot, char *authdom);
+
+/*
+ *  exchange messages with auth server
+ */
+extern	int	_asgetticket(int, char*, char*);
+extern	int	_asrdresp(int, char*, int);
+extern	int	sslnegotiate(int, Ticket*, char**, char**);
+extern	int	srvsslnegotiate(int, Ticket*, char**, char**);

+ 26 - 0
sys/include/avl.h

@@ -0,0 +1,26 @@
+#pragma	lib	"libavl.a"
+#pragma src "/sys/src/libavl"
+
+typedef struct Avl	Avl;
+typedef struct Avltree	Avltree;
+typedef struct Avlwalk	Avlwalk;
+
+#pragma incomplete Avltree
+#pragma incomplete Avlwalk
+
+struct Avl
+{
+	Avl	*p;		/* parent */
+	Avl	*n[2];		/* children */
+	int	bal;		/* balance bits */
+};
+
+Avl	*avlnext(Avlwalk *walk);
+Avl	*avlprev(Avlwalk *walk);
+Avlwalk	*avlwalk(Avltree *tree);
+void	deleteavl(Avltree *tree, Avl *key, Avl **oldp);
+void	endwalk(Avlwalk *walk);
+void	insertavl(Avltree *tree, Avl *new, Avl **oldp);
+Avl	*lookupavl(Avltree *tree, Avl *key);
+Avltree	*mkavltree(int(*cmp)(Avl*, Avl*));
+Avl*	searchavl(Avltree *tree, Avl *key, int neighbor);

+ 10 - 0
sys/include/bin.h

@@ -0,0 +1,10 @@
+#pragma	lib	"libbin.a"
+#pragma	src	"/sys/src/libbin"
+
+typedef struct Bin	Bin;
+
+#pragma incomplete Bin
+
+void	*binalloc(Bin **, ulong size, int zero);
+void	*bingrow(Bin **, void *op, ulong osize, ulong size, int zero);
+void	binfree(Bin **);

+ 74 - 0
sys/include/bio.h

@@ -0,0 +1,74 @@
+#pragma	src	"/sys/src/libbio"
+#pragma	lib	"libbio.a"
+
+typedef	struct	Biobuf	Biobuf;
+typedef	struct	Biobufhdr	Biobufhdr;
+
+enum
+{
+	Bsize		= 8*1024,
+	Bungetsize	= 4,		/* space for ungetc */
+	Bmagic		= 0x314159,
+	Beof		= -1,
+	Bbad		= -2,
+
+	Binactive	= 0,		/* states */
+	Bractive,
+	Bwactive,
+	Bracteof,
+};
+
+struct	Biobufhdr
+{
+	int	icount;		/* neg num of bytes at eob */
+	int	ocount;		/* num of bytes at bob */
+	int	rdline;		/* num of bytes after rdline */
+	int	runesize;	/* num of bytes of last getrune */
+	int	state;		/* r/w/inactive */
+	int	fid;		/* open file */
+	int	flag;		/* magic if malloc'ed */
+	vlong	offset;		/* offset of buffer in file */
+	int	bsize;		/* size of buffer */
+	uchar*	bbuf;		/* pointer to beginning of buffer */
+	uchar*	ebuf;		/* pointer to end of buffer */
+	uchar*	gbuf;		/* pointer to good data in buf */
+};
+
+struct	Biobuf
+{
+	Biobufhdr;
+	uchar	b[Bungetsize+Bsize];
+};
+
+/* Dregs, redefined as functions for backwards compatibility */
+#define	BGETC(bp)	Bgetc(bp)
+#define	BPUTC(bp,c)	Bputc(bp,c)
+#define	BOFFSET(bp)	Boffset(bp)
+#define	BLINELEN(bp)	Blinelen(bp)
+#define	BFILDES(bp)	Bfildes(bp)
+
+int	Bbuffered(Biobufhdr*);
+int	Bfildes(Biobufhdr*);
+int	Bflush(Biobufhdr*);
+int	Bgetc(Biobufhdr*);
+int	Bgetd(Biobufhdr*, double*);
+long	Bgetrune(Biobufhdr*);
+int	Binit(Biobuf*, int, int);
+int	Binits(Biobufhdr*, int, int, uchar*, int);
+int	Blinelen(Biobufhdr*);
+vlong	Boffset(Biobufhdr*);
+Biobuf*	Bopen(char*, int);
+int	Bprint(Biobufhdr*, char*, ...);
+int	Bvprint(Biobufhdr*, char*, va_list);
+int	Bputc(Biobufhdr*, int);
+int	Bputrune(Biobufhdr*, long);
+void*	Brdline(Biobufhdr*, int);
+char*	Brdstr(Biobufhdr*, int, int);
+long	Bread(Biobufhdr*, void*, long);
+vlong	Bseek(Biobufhdr*, vlong, int);
+int	Bterm(Biobufhdr*);
+int	Bungetc(Biobufhdr*);
+int	Bungetrune(Biobufhdr*);
+long	Bwrite(Biobufhdr*, void*, long);
+
+#pragma	varargck	argpos	Bprint	2

+ 137 - 0
sys/include/bootexec.h

@@ -0,0 +1,137 @@
+struct coffsect
+{
+	char	name[8];
+	ulong	phys;
+	ulong	virt;
+	ulong	size;
+	ulong	fptr;
+	ulong	fptrreloc;
+	ulong	fptrlineno;
+	ulong	nrelocnlineno;
+	ulong	flags;
+};
+
+/*
+ * proprietary exec headers, needed to bootstrap various machines
+ */
+struct mipsexec
+{
+	short	mmagic;		/* (0x160) mips magic number */
+	short	nscns;		/* (unused) number of sections */
+	long	timdat;		/* (unused) time & date stamp */
+	long	symptr;		/* offset to symbol table */
+	long	nsyms;		/* size of symbol table */
+	short	opthdr;		/* (0x38) sizeof(optional hdr) */
+	short	pcszs;		/* flags */
+	short	amagic;		/* see above */
+	short	vstamp;		/* version stamp */
+	long	tsize;		/* text size in bytes */
+	long	dsize;		/* initialized data */
+	long	bsize;		/* uninitialized data */
+	long	mentry;		/* entry pt.				*/
+	long	text_start;	/* base of text used for this file	*/
+	long	data_start;	/* base of data used for this file	*/
+	long	bss_start;	/* base of bss used for this file	*/
+	long	gprmask;	/* general purpose register mask	*/
+union{
+	long	cprmask[4];	/* co-processor register masks		*/
+	long	pcsize;
+};
+	long	gp_value;	/* the gp value used for this object    */
+};
+
+struct mips4kexec
+{
+	struct mipsexec	h;
+	struct coffsect	itexts;
+	struct coffsect idatas;
+	struct coffsect ibsss;
+};
+
+struct sparcexec
+{
+	short	sjunk;		/* dynamic bit and version number */
+	short	smagic;		/* 0407 */
+	ulong	stext;
+	ulong	sdata;
+	ulong	sbss;
+	ulong	ssyms;
+	ulong	sentry;
+	ulong	strsize;
+	ulong	sdrsize;
+};
+
+struct nextexec
+{
+	struct	nexthdr{
+		ulong	nmagic;
+		ulong	ncputype;
+		ulong	ncpusubtype;
+		ulong	nfiletype;
+		ulong	ncmds;
+		ulong	nsizeofcmds;
+		ulong	nflags;
+	};
+
+	struct nextcmd{
+		ulong	cmd;
+		ulong	cmdsize;
+		uchar	segname[16];
+		ulong	vmaddr;
+		ulong	vmsize;
+		ulong	fileoff;
+		ulong	filesize;
+		ulong	maxprot;
+		ulong	initprot;
+		ulong	nsects;
+		ulong	flags;
+	}textc;
+	struct nextsect{
+		char	sectname[16];
+		char	segname[16];
+		ulong	addr;
+		ulong	size;
+		ulong	offset;
+		ulong	align;
+		ulong	reloff;
+		ulong	nreloc;
+		ulong	flags;
+		ulong	reserved1;
+		ulong	reserved2;
+	}texts;
+	struct nextcmd	datac;
+	struct nextsect	datas;
+	struct nextsect	bsss;
+	struct nextsym{
+		ulong	cmd;
+		ulong	cmdsize;
+		ulong	symoff;
+		ulong	nsyms;
+		ulong	spoff;
+		ulong	pcoff;
+	}symc;
+};
+
+struct i386exec
+{
+	struct	i386coff{
+		ulong	isectmagic;
+		ulong	itime;
+		ulong	isyms;
+		ulong	insyms;
+		ulong	iflags;
+	};
+	struct	i386hdr{
+		ulong	imagic;
+		ulong	itextsize;
+		ulong	idatasize;
+		ulong	ibsssize;
+		ulong	ientry;
+		ulong	itextstart;
+		ulong	idatastart;
+	};
+	struct coffsect	itexts;
+	struct coffsect idatas;
+	struct coffsect ibsss;
+	struct coffsect icomments;
+};

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