home *** CD-ROM | disk | FTP | other *** search
open in:
MacOS 8.1
|
Win98
|
DOS
view JSON data
|
view as text
This file was processed as: Tape Archive
(archive/tar).
You can browse this item here: toolpack
Confidence | Program | Detection | Match Type | Support
|
---|
100%
| dexvert
| Tape Archive (archive/tar)
| magic
| Supported |
100%
| file
| POSIX tar archive (GNU)
| default
| |
99%
| file
| POSIX tar archive (GNU), directory toolpack1.2/, mode 700 , uid 630 , gid 63 , size 0 , seconds 5462076156, user kernel, group kernel
| default
| |
98%
| file
| data
| default
| |
62%
| TrID
| TAR - Tape ARchive (GNU)
| default
| |
37%
| TrID
| TAR - Tape ARchive (directory)
| default
| |
100%
| siegfried
| x-fmt/265 Tape Archive Format
| default
| |
100%
| lsar
| Tar
| default
| |
100%
| gt2
| TAR Archiv gefunden (Auflistung ist deaktiviert)
| default
| |
100%
| disktype
| GNU tar archive
| default
| |
100%
| detectItEasy
| Archive: tar
| default
| |
100%
| binwalkID
| POSIX tar archive (GNU), owner user name: "1.2/"
| default
| |
100%
| xdgMime
| application/x-tar
| default
|
|
hex view+--------+-------------------------+-------------------------+--------+--------+
|00000000| 74 6f 6f 6c 70 61 63 6b | 31 2e 32 2f 00 00 00 00 |toolpack|1.2/....|
|00000010| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000020| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000030| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000040| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000050| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000060| 00 00 00 00 20 20 20 37 | 30 30 20 00 20 20 20 36 |.... 7|00 . 6|
|00000070| 33 30 20 00 20 20 20 20 | 36 33 20 00 20 20 20 20 |30 . |63 . |
|00000080| 20 20 20 20 20 20 30 20 | 20 35 34 36 32 30 37 36 | 0 | 5462076|
|00000090| 31 35 36 20 20 31 31 37 | 32 36 00 20 35 00 00 00 |156 117|26. 5...|
|000000a0| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|000000b0| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|000000c0| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|000000d0| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|000000e0| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|000000f0| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000100| 00 75 73 74 61 72 20 20 | 00 6b 65 72 6e 65 6c 00 |.ustar |.kernel.|
|00000110| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000120| 00 00 00 00 00 00 00 00 | 00 6b 65 72 6e 65 6c 00 |........|.kernel.|
|00000130| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000140| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000150| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000160| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000170| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000180| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000190| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|000001a0| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|000001b0| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|000001c0| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|000001d0| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|000001e0| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|000001f0| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000200| 74 6f 6f 6c 70 61 63 6b | 31 2e 32 2f 43 2f 00 00 |toolpack|1.2/C/..|
|00000210| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000220| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000230| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000240| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000250| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000260| 00 00 00 00 20 20 20 37 | 35 35 20 00 20 20 20 36 |.... 7|55 . 6|
|00000270| 33 30 20 00 20 20 20 20 | 36 33 20 00 20 20 20 20 |30 . |63 . |
|00000280| 20 20 20 20 20 20 30 20 | 20 35 34 36 32 30 37 36 | 0 | 5462076|
|00000290| 35 32 32 20 20 31 32 31 | 31 37 00 20 35 00 00 00 |522 121|17. 5...|
|000002a0| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|000002b0| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|000002c0| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|000002d0| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|000002e0| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|000002f0| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000300| 00 75 73 74 61 72 20 20 | 00 6b 65 72 6e 65 6c 00 |.ustar |.kernel.|
|00000310| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000320| 00 00 00 00 00 00 00 00 | 00 6b 65 72 6e 65 6c 00 |........|.kernel.|
|00000330| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000340| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000350| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000360| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000370| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000380| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000390| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|000003a0| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|000003b0| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|000003c0| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|000003d0| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|000003e0| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|000003f0| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000400| 74 6f 6f 6c 70 61 63 6b | 31 2e 32 2f 43 2f 61 6c |toolpack|1.2/C/al|
|00000410| 6c 69 6f 2e 63 00 00 00 | 00 00 00 00 00 00 00 00 |lio.c...|........|
|00000420| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000430| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000440| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000450| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000460| 00 00 00 00 20 20 20 36 | 34 34 20 00 20 20 20 36 |.... 6|44 . 6|
|00000470| 33 30 20 00 20 20 20 20 | 36 33 20 00 20 20 20 20 |30 . |63 . |
|00000480| 20 31 31 32 37 33 36 20 | 20 35 34 35 37 36 34 35 | 112736 | 5457645|
|00000490| 37 36 35 20 20 31 33 35 | 33 34 00 20 30 00 00 00 |765 135|34. 0...|
|000004a0| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|000004b0| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|000004c0| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|000004d0| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|000004e0| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|000004f0| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000500| 00 75 73 74 61 72 20 20 | 00 6b 65 72 6e 65 6c 00 |.ustar |.kernel.|
|00000510| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000520| 00 00 00 00 00 00 00 00 | 00 6b 65 72 6e 65 6c 00 |........|.kernel.|
|00000530| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000540| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000550| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000560| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000570| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000580| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000590| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|000005a0| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|000005b0| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|000005c0| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|000005d0| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|000005e0| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|000005f0| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000600| 2f 2a 2d 2d 2d 2d 2d 2d | 2d 2d 2d 2d 2d 2d 2d 2d |/*------|--------|
|00000610| 2d 2d 2d 2d 2d 2d 2d 2d | 2d 2d 2d 2d 2d 2d 2d 2d |--------|--------|
|00000620| 2d 2a 2f 0a 2f 2a 20 20 | 20 54 4f 4f 4c 50 41 43 |-*/./* | TOOLPAC|
|00000630| 4b 2f 31 20 20 20 52 65 | 6c 65 61 73 65 3a 20 31 |K/1 Re|lease: 1|
|00000640| 2e 31 20 20 20 2a 2f 0a | 2f 2a 2d 2d 2d 2d 2d 2d |.1 */.|/*------|
|00000650| 2d 2d 2d 2d 2d 2d 2d 2d | 2d 2d 2d 2d 2d 2d 2d 2d |--------|--------|
|00000660| 2d 2d 2d 2d 2d 2d 2d 2d | 2d 2a 2f 0a 23 69 6e 63 |--------|-*/.#inc|
|00000670| 6c 75 64 65 20 3c 63 74 | 79 70 65 2e 68 3e 0a 23 |lude <ct|ype.h>.#|
|00000680| 69 6e 63 6c 75 64 65 20 | 22 64 65 66 69 6e 65 2e |include |"define.|
|00000690| 68 22 0a 20 0a 23 69 6e | 63 6c 75 64 65 20 3c 73 |h". .#in|clude <s|
|000006a0| 79 73 2f 74 79 70 65 73 | 2e 68 3e 0a 23 69 6e 63 |ys/types|.h>.#inc|
|000006b0| 6c 75 64 65 20 3c 73 79 | 73 2f 74 69 6d 65 2e 68 |lude <sy|s/time.h|
|000006c0| 3e 0a 23 69 66 64 65 66 | 20 73 67 69 0a 23 69 6e |>.#ifdef| sgi.#in|
|000006d0| 63 6c 75 64 65 20 3c 74 | 69 6d 65 2e 68 3e 0a 23 |clude <t|ime.h>.#|
|000006e0| 65 6e 64 69 66 0a 20 0a | 23 69 6e 63 6c 75 64 65 |endif. .|#include|
|000006f0| 20 3c 73 79 73 2f 73 74 | 61 74 2e 68 3e 0a 20 0a | <sys/st|at.h>. .|
|00000700| 23 69 6e 63 6c 75 64 65 | 20 3c 73 79 73 2f 64 69 |#include| <sys/di|
|00000710| 72 2e 68 3e 0a 20 0a 23 | 69 6e 63 6c 75 64 65 20 |r.h>. .#|include |
|00000720| 22 67 6c 6f 62 61 6c 73 | 31 2e 68 22 0a 23 69 6e |"globals|1.h".#in|
|00000730| 63 6c 75 64 65 20 22 67 | 6c 6f 62 61 6c 73 32 2e |clude "g|lobals2.|
|00000740| 68 22 0a 23 69 6e 63 6c | 75 64 65 20 22 67 6c 6f |h".#incl|ude "glo|
|00000750| 62 61 6c 73 2e 68 22 0a | 20 0a 61 63 6f 70 79 5f |bals.h".| .acopy_|
|00000760| 28 66 64 69 2c 20 66 64 | 6f 2c 20 73 69 7a 65 29 |(fdi, fd|o, size)|
|00000770| 0a 69 6e 74 20 2a 66 64 | 69 2c 20 2a 66 64 6f 2c |.int *fd|i, *fdo,|
|00000780| 20 2a 73 69 7a 65 3b 0a | 20 0a 7b 0a 09 2f 2a 20 | *size;.| .{../* |
|00000790| 63 6f 70 79 20 73 69 7a | 65 20 63 68 61 72 61 63 |copy siz|e charac|
|000007a0| 74 65 72 73 20 66 72 6f | 6d 20 74 68 65 20 69 6e |ters fro|m the in|
|000007b0| 70 75 74 20 66 69 6c 65 | 20 66 64 69 20 74 6f 20 |put file| fdi to |
|000007c0| 74 68 65 20 6f 75 74 70 | 75 74 0a 09 20 20 20 66 |the outp|ut.. f|
|000007d0| 69 6c 65 20 66 64 6f 2e | 20 49 66 20 65 6f 66 20 |ile fdo.| If eof |
|000007e0| 65 6e 63 6f 75 6e 74 65 | 72 65 64 20 6f 6e 20 66 |encounte|red on f|
|000007f0| 64 69 20 62 65 66 6f 72 | 65 20 74 68 65 20 74 72 |di befor|e the tr|
|00000800| 61 6e 73 66 65 72 20 69 | 73 0a 09 20 20 20 63 6f |ansfer i|s.. co|
|00000810| 6d 70 6c 65 74 65 20 74 | 68 65 20 74 72 61 6e 73 |mplete t|he trans|
|00000820| 66 65 72 20 69 73 20 69 | 6d 6d 65 64 69 61 74 65 |fer is i|mmediate|
|00000830| 6c 79 20 74 65 72 6d 69 | 6e 61 74 65 64 2e 20 42 |ly termi|nated. B|
|00000840| 6f 74 68 20 66 69 6c 65 | 73 0a 09 20 20 20 61 72 |oth file|s.. ar|
|00000850| 65 20 61 73 73 75 6d 65 | 64 20 73 65 71 75 65 6e |e assume|d sequen|
|00000860| 74 69 61 6c 20 2a 2f 0a | 20 0a 09 69 6e 74 20 63 |tial */.| ..int c|
|00000870| 2c 20 69 3b 0a 20 0a 09 | 2f 2a 20 65 6e 73 75 72 |, i;. ..|/* ensur|
|00000880| 65 20 69 6e 70 75 74 20 | 66 69 6c 65 20 6f 70 65 |e input |file ope|
|00000890| 6e 20 66 6f 72 20 72 65 | 61 64 20 61 6e 64 20 6f |n for re|ad and o|
|000008a0| 75 74 70 75 74 20 66 69 | 6c 65 20 66 6f 72 20 77 |utput fi|le for w|
|000008b0| 72 69 74 65 20 2a 2f 0a | 09 69 66 20 28 6f 70 6e |rite */.|.if (opn|
|000008c0| 72 65 61 64 28 2a 66 64 | 69 29 20 3d 3d 20 45 52 |read(*fd|i) == ER|
|000008d0| 52 20 7c 7c 20 6f 70 6e | 77 72 69 74 28 2a 66 64 |R || opn|writ(*fd|
|000008e0| 6f 29 20 3d 3d 20 45 52 | 52 29 20 7b 0a 09 09 72 |o) == ER|R) {...r|
|000008f0| 65 6d 61 72 6b 5f 28 22 | 77 72 6f 6e 67 20 6d 6f |emark_("|wrong mo|
|00000900| 64 65 20 69 6e 20 61 63 | 6f 70 79 22 2c 31 39 4c |de in ac|opy",19L|
|00000910| 29 3b 0a 09 09 72 65 74 | 75 72 6e 3b 0a 09 7d 0a |);...ret|urn;..}.|
|00000920| 20 0a 09 2f 2a 20 6d 6f | 76 65 20 74 68 65 20 63 | ../* mo|ve the c|
|00000930| 68 61 72 61 63 74 65 72 | 73 20 2a 2f 0a 09 66 6f |haracter|s */..fo|
|00000940| 72 28 69 3d 31 3b 20 69 | 20 3c 3d 20 2a 73 69 7a |r(i=1; i| <= *siz|
|00000950| 65 20 26 26 20 28 63 3d | 67 65 74 63 68 5f 28 26 |e && (c=|getch_(&|
|00000960| 63 2c 66 64 69 29 29 20 | 21 3d 20 45 4f 46 20 3b |c,fdi)) |!= EOF ;|
|00000970| 20 69 2b 2b 29 0a 09 20 | 09 70 75 74 63 68 5f 28 | i++).. |.putch_(|
|00000980| 26 63 2c 66 64 6f 29 3b | 0a 20 0a 7d 0a 20 0a 63 |&c,fdo);|. .}. .c|
|00000990| 61 6e 74 5f 28 6e 61 6d | 65 29 0a 69 6e 74 20 2a |ant_(nam|e).int *|
|000009a0| 6e 61 6d 65 3b 0a 20 0a | 7b 0a 09 2f 2a 20 6f 75 |name;. .|{../* ou|
|000009b0| 74 70 75 74 73 20 74 68 | 65 20 6d 65 73 73 61 67 |tputs th|e messag|
|000009c0| 65 20 27 43 41 4e 54 20 | 4f 50 45 4e 20 46 49 4c |e 'CANT |OPEN FIL|
|000009d0| 45 20 4f 46 20 4e 41 4d | 45 3a 20 27 20 6e 61 6d |E OF NAM|E: ' nam|
|000009e0| 65 20 6f 6e 20 73 74 64 | 65 72 72 20 2a 2f 0a 20 |e on std|err */. |
|000009f0| 0a 09 69 6e 74 20 66 64 | 20 3d 20 53 54 44 45 52 |..int fd| = STDER|
|00000a00| 52 2c 20 6e 65 77 6c 69 | 6e 65 20 3d 20 4e 45 57 |R, newli|ne = NEW|
|00000a10| 4c 49 4e 45 3b 0a 20 0a | 09 7a 63 68 6f 75 74 5f |LINE;. .|.zchout_|
|00000a20| 28 22 43 41 4e 27 54 20 | 4f 50 45 4e 20 46 49 4c |("CAN'T |OPEN FIL|
|00000a30| 45 20 4f 46 20 4e 41 4d | 45 3a 20 22 2c 20 26 66 |E OF NAM|E: ", &f|
|00000a40| 64 2c 20 32 35 4c 29 3b | 0a 09 70 75 74 6c 69 6e |d, 25L);|..putlin|
|00000a50| 5f 28 6e 61 6d 65 2c 20 | 26 66 64 29 3b 0a 09 70 |_(name, |&fd);..p|
|00000a60| 75 74 63 68 5f 28 26 6e | 65 77 6c 69 6e 65 2c 20 |utch_(&n|ewline, |
|00000a70| 26 66 64 29 3b 0a 20 0a | 7d 0a 20 0a 63 6c 6f 73 |&fd);. .|}. .clos|
|00000a80| 65 5f 28 66 64 29 0a 69 | 6e 74 20 2a 66 64 3b 0a |e_(fd).i|nt *fd;.|
|00000a90| 20 0a 7b 0a 09 2f 2a 20 | 54 65 72 6d 69 6e 61 74 | .{../* |Terminat|
|00000aa0| 65 20 61 63 63 65 73 73 | 20 74 6f 20 74 68 65 20 |e access| to the |
|00000ab0| 66 69 6c 65 20 64 65 73 | 63 72 69 70 74 6f 72 20 |file des|criptor |
|00000ac0| 66 64 2e 20 54 68 69 73 | 0a 09 20 20 20 72 6f 75 |fd. This|.. rou|
|00000ad0| 74 69 6e 65 20 6d 61 79 | 20 62 65 20 75 73 65 64 |tine may| be used|
|00000ae0| 20 6f 6e 20 62 6f 74 68 | 20 73 65 71 75 65 6e 74 | on both| sequent|
|00000af0| 69 61 6c 20 61 6e 64 20 | 64 69 72 65 63 74 0a 09 |ial and |direct..|
|00000b00| 20 20 20 61 63 63 65 73 | 73 20 66 69 6c 65 73 2e | acces|s files.|
|00000b10| 0a 20 0a 09 20 20 20 41 | 74 74 65 6d 70 74 69 6e |. .. A|ttemptin|
|00000b20| 67 20 74 6f 20 63 6c 6f | 73 65 20 61 20 70 72 65 |g to clo|se a pre|
|00000b30| 63 6f 6e 6e 65 63 74 65 | 64 20 66 69 6c 65 20 6f |connecte|d file o|
|00000b40| 72 20 61 20 63 6c 6f 73 | 65 64 20 66 69 6c 65 0a |r a clos|ed file.|
|00000b50| 09 20 20 20 68 61 73 20 | 6e 6f 20 65 66 66 65 63 |. has |no effec|
|00000b60| 74 20 2a 2f 0a 20 0a 09 | 73 74 72 75 63 74 20 66 |t */. ..|struct f|
|00000b70| 64 69 6e 66 6f 20 2a 70 | 74 72 3b 0a 20 0a 09 69 |dinfo *p|tr;. ..i|
|00000b80| 66 28 20 63 68 65 63 6b | 66 64 28 2a 66 64 29 20 |f( check|fd(*fd) |
|00000b90| 21 3d 20 46 49 4c 45 53 | 29 0a 20 20 20 20 20 2f |!= FILES|). /|
|00000ba0| 2a 09 6e 6f 20 65 66 66 | 65 63 74 20 6f 6e 20 70 |*.no eff|ect on p|
|00000bb0| 72 65 63 6f 6e 6e 65 63 | 74 65 64 20 75 6e 69 74 |reconnec|ted unit|
|00000bc0| 73 20 2a 2f 0a 09 09 72 | 65 74 75 72 6e 3b 0a 20 |s */...r|eturn;. |
|00000bd0| 0a 09 70 74 72 20 3d 20 | 26 66 69 6c 65 73 5b 2a |..ptr = |&files[*|
|00000be0| 66 64 5d 3b 0a 20 0a 09 | 2f 2a 20 64 65 61 6c 20 |fd];. ..|/* deal |
|00000bf0| 77 69 74 68 20 6e 6f 20 | 65 66 66 65 63 74 20 63 |with no |effect c|
|00000c00| 61 73 65 73 20 2a 2f 0a | 20 0a 2f 2a 09 69 66 20 |ases */.| ./*.if |
|00000c10| 28 20 70 74 72 2d 3e 61 | 63 63 65 73 73 20 3d 3d |( ptr->a|ccess ==|
|00000c20| 20 4e 4f 54 4f 50 45 4e | 29 0a 09 20 20 09 72 65 | NOTOPEN|).. .re|
|00000c30| 74 75 72 6e 3b 20 20 20 | 2a 2f 0a 20 0a 09 2f 2a |turn; |*/. ../*|
|00000c40| 20 73 65 74 20 61 63 63 | 65 73 73 20 74 6f 20 4e | set acc|ess to N|
|00000c50| 4f 54 4f 50 45 4e 2c 20 | 77 72 69 74 65 20 6f 75 |OTOPEN, |write ou|
|00000c60| 74 20 74 68 65 20 63 75 | 72 72 65 6e 74 20 62 75 |t the cu|rrent bu|
|00000c70| 66 66 65 72 20 69 66 0a | 09 20 20 20 63 75 72 72 |ffer if.|. curr|
|00000c80| 65 6e 74 61 63 63 65 73 | 73 20 69 73 20 77 72 69 |entacces|s is wri|
|00000c90| 74 65 20 61 6e 64 20 63 | 6c 6f 73 65 20 74 68 65 |te and c|lose the|
|00000ca0| 20 66 69 6c 65 20 2a 2f | 0a 20 0a 09 70 74 72 2d | file */|. ..ptr-|
|00000cb0| 3e 61 63 63 65 73 73 20 | 3d 20 4e 4f 54 4f 50 45 |>access |= NOTOPE|
|00000cc0| 4e 3b 0a 09 66 6c 75 73 | 68 28 2a 66 64 29 3b 0a |N;..flus|h(*fd);.|
|00000cd0| 09 63 6c 6f 73 65 28 2a | 66 64 29 3b 0a 69 66 28 |.close(*|fd);.if(|
|00000ce0| 44 45 42 55 47 29 20 70 | 72 69 6e 74 66 28 22 69 |DEBUG) p|rintf("i|
|00000cf0| 6e 20 63 6c 6f 73 65 20 | 3a 20 6a 75 73 74 20 63 |n close |: just c|
|00000d00| 6c 6f 73 65 64 20 66 64 | 20 3d 20 25 64 5c 6e 22 |losed fd| = %d\n"|
|00000d10| 2c 2a 66 64 29 3b 0a 7d | 0a 20 0a 63 72 65 61 74 |,*fd);.}|. .creat|
|00000d20| 65 5f 28 20 6e 61 6d 65 | 2c 20 61 63 63 65 73 73 |e_( name|, access|
|00000d30| 29 0a 69 6e 74 20 2a 6e | 61 6d 65 2c 20 2a 61 63 |).int *n|ame, *ac|
|00000d40| 63 65 73 73 3b 0a 20 0a | 7b 0a 09 2f 2a 20 63 72 |cess;. .|{../* cr|
|00000d50| 65 61 74 65 20 61 20 73 | 65 71 75 65 6e 74 69 61 |eate a s|equentia|
|00000d60| 6c 20 66 69 6c 65 20 6f | 66 20 6e 61 6d 65 20 6e |l file o|f name n|
|00000d70| 61 6d 65 20 61 6e 64 20 | 6f 70 65 6e 20 69 74 20 |ame and |open it |
|00000d80| 77 69 74 68 0a 09 20 20 | 20 61 63 63 65 73 73 20 |with.. | access |
|00000d90| 74 79 70 65 20 61 63 63 | 65 73 73 2e 20 41 73 73 |type acc|ess. Ass|
|00000da0| 69 67 6e 20 61 6e 20 69 | 6e 74 65 72 6e 61 6c 20 |ign an i|nternal |
|00000db0| 66 69 6c 65 20 64 65 73 | 63 72 69 70 74 6f 72 0a |file des|criptor.|
|00000dc0| 09 20 20 20 74 6f 20 74 | 68 65 20 66 69 6c 65 20 |. to t|he file |
|00000dd0| 61 6e 64 20 72 65 74 75 | 72 6e 20 74 68 69 73 20 |and retu|rn this |
|00000de0| 76 69 61 20 74 68 65 20 | 66 75 6e 63 74 69 6f 6e |via the |function|
|00000df0| 20 6e 61 6d 65 2e 20 49 | 66 0a 09 20 20 20 61 20 | name. I|f.. a |
|00000e00| 66 69 6c 65 20 61 6c 72 | 65 61 64 79 20 65 78 69 |file alr|eady exi|
|00000e10| 73 74 73 20 77 69 74 68 | 20 74 68 69 73 20 6e 61 |sts with| this na|
|00000e20| 6d 65 20 69 74 20 69 73 | 20 64 65 6c 65 74 65 64 |me it is| deleted|
|00000e30| 0a 09 20 20 20 70 72 69 | 6f 72 20 74 6f 20 63 72 |.. pri|or to cr|
|00000e40| 65 61 74 69 6f 6e 20 2a | 2f 0a 20 0a 20 20 20 20 |eation *|/. . |
|00000e50| 20 20 20 20 69 6e 74 20 | 75 69 64 2c 67 69 64 2c | int |uid,gid,|
|00000e60| 6c 65 6e 2c 69 3b 0a 20 | 20 20 20 20 20 20 20 63 |len,i;. | c|
|00000e70| 68 61 72 20 6e 65 77 63 | 68 5b 4d 41 58 50 41 54 |har newc|h[MAXPAT|
|00000e80| 48 5d 3b 0a 20 20 20 20 | 20 20 20 20 73 74 72 75 |H];. | stru|
|00000e90| 63 74 20 73 74 61 74 20 | 73 62 75 66 3b 0a 20 0a |ct stat |sbuf;. .|
|00000ea0| 09 69 6e 74 20 66 64 2c | 20 70 6d 6f 64 65 3b 0a |.int fd,| pmode;.|
|00000eb0| 09 63 68 61 72 20 63 68 | 61 72 6e 6d 31 5b 4d 41 |.char ch|arnm1[MA|
|00000ec0| 58 50 41 54 48 5d 3b 0a | 09 73 74 72 75 63 74 20 |XPATH];.|.struct |
|00000ed0| 66 64 69 6e 66 6f 20 2a | 70 74 72 3b 0a 09 73 74 |fdinfo *|ptr;..st|
|00000ee0| 72 75 63 74 20 66 69 6c | 69 6e 66 6f 20 6f 70 65 |ruct fil|info ope|
|00000ef0| 6e 69 6e 66 3b 0a 20 0a | 20 20 20 20 20 2f 2a 09 |ninf;. .| /*.|
|00000f00| 67 65 6e 65 72 61 74 65 | 20 66 75 6c 6c 20 70 61 |generate| full pa|
|00000f10| 74 68 20 6e 61 6d 65 20 | 61 73 20 61 20 63 68 61 |th name |as a cha|
|00000f20| 72 61 63 74 65 72 20 73 | 74 72 69 6e 67 20 2a 2f |racter s|tring */|
|00000f30| 0a 20 20 20 20 09 6d 6b | 66 69 6c 6e 6d 28 6e 61 |. .mk|filnm(na|
|00000f40| 6d 65 2c 20 63 68 61 72 | 6e 6d 31 2c 20 26 6f 70 |me, char|nm1, &op|
|00000f50| 65 6e 69 6e 66 29 3b 0a | 20 0a 20 20 20 20 20 2f |eninf);.| . /|
|00000f60| 2a 09 73 6f 72 74 20 6f | 75 74 20 70 6f 73 73 69 |*.sort o|ut possi|
|00000f70| 62 6c 65 20 65 72 72 6f | 72 20 63 61 73 65 73 20 |ble erro|r cases |
|00000f80| 2a 2f 0a 09 73 77 69 74 | 63 68 20 28 6f 70 65 6e |*/..swit|ch (open|
|00000f90| 69 6e 66 2e 66 74 79 70 | 65 31 29 0a 09 7b 0a 09 |inf.ftyp|e1)..{..|
|00000fa0| 20 20 63 61 73 65 20 45 | 52 52 3a 20 20 2f 2a 20 | case E|RR: /* |
|00000fb0| 65 72 72 6f 72 20 69 6e | 20 6d 6b 70 61 74 68 20 |error in| mkpath |
|00000fc0| 6f 72 20 68 6f 73 74 20 | 66 69 6c 65 20 61 20 64 |or host |file a d|
|00000fd0| 69 72 65 63 74 6f 72 79 | 20 2a 2f 0a 09 09 72 65 |irectory| */...re|
|00000fe0| 74 75 72 6e 28 45 52 52 | 29 3b 0a 09 0a 09 20 20 |turn(ERR|);.... |
|00000ff0| 63 61 73 65 20 44 45 56 | 49 43 45 3a 20 2f 2a 20 |case DEV|ICE: /* |
|00001000| 72 65 74 75 72 6e 20 65 | 72 72 20 66 6f 72 20 69 |return e|rr for i|
|00001010| 6c 6c 65 67 61 6c 20 61 | 63 63 65 73 73 20 6f 74 |llegal a|ccess ot|
|00001020| 68 65 72 77 69 73 65 20 | 66 64 20 2a 2f 0a 09 09 |herwise |fd */...|
|00001030| 72 65 74 75 72 6e 28 28 | 70 72 63 6f 6e 66 6c 28 |return((|prconfl(|
|00001040| 6f 70 65 6e 69 6e 66 2e | 73 75 62 74 79 70 65 2c |openinf.|subtype,|
|00001050| 20 2a 61 63 63 65 73 73 | 29 20 3d 3d 20 45 52 52 | *access|) == ERR|
|00001060| 29 0a 09 09 09 3f 20 45 | 52 52 20 3a 20 6f 70 65 |)....? E|RR : ope|
|00001070| 6e 69 6e 66 2e 73 75 62 | 74 79 70 65 29 3b 0a 20 |ninf.sub|type);. |
|00001080| 0a 09 20 20 63 61 73 65 | 20 56 46 53 3a 20 20 2f |.. case| VFS: /|
|00001090| 2a 20 65 72 72 6f 72 20 | 69 66 20 64 69 72 65 63 |* error |if direc|
|000010a0| 74 6f 72 79 20 2a 2f 0a | 09 09 69 66 28 6f 70 65 |tory */.|..if(ope|
|000010b0| 6e 69 6e 66 2e 73 75 62 | 74 79 70 65 20 3d 3d 20 |ninf.sub|type == |
|000010c0| 44 49 52 45 43 54 4f 52 | 59 29 0a 09 09 09 72 65 |DIRECTOR|Y)....re|
|000010d0| 74 75 72 6e 28 45 52 52 | 29 3b 0a 09 20 7d 0a 09 |turn(ERR|);.. }..|
|000010e0| 2f 2a 20 53 48 4f 55 4c | 44 20 57 45 20 43 48 45 |/* SHOUL|D WE CHE|
|000010f0| 43 4b 20 57 48 45 54 48 | 45 52 20 46 49 4c 45 20 |CK WHETH|ER FILE |
|00001100| 49 53 20 41 4c 52 45 41 | 44 59 20 4f 50 45 4e 20 |IS ALREA|DY OPEN |
|00001110| 3f 3f 3f 20 2a 2f 0a 20 | 0a 09 70 6d 6f 64 65 20 |??? */. |..pmode |
|00001120| 3d 20 52 57 4d 4f 44 45 | 3b 0a 20 0a 09 2f 2a 20 |= RWMODE|;. ../* |
|00001130| 61 74 74 65 6d 70 74 20 | 74 6f 20 63 72 65 61 74 |attempt |to creat|
|00001140| 65 20 66 69 6c 65 20 2d | 20 69 66 20 66 69 6c 65 |e file -| if file|
|00001150| 20 61 6c 72 65 61 64 79 | 20 65 78 69 73 74 73 20 | already| exists |
|00001160| 69 74 20 77 69 6c 6c 20 | 62 65 0a 09 20 20 20 74 |it will |be.. t|
|00001170| 72 75 6e 63 61 74 65 64 | 20 74 6f 20 6c 65 6e 67 |runcated| to leng|
|00001180| 74 68 20 7a 65 72 6f 20 | 2a 2f 0a 09 66 64 20 3d |th zero |*/..fd =|
|00001190| 20 63 72 65 61 74 28 63 | 68 61 72 6e 6d 31 2c 20 | creat(c|harnm1, |
|000011a0| 70 6d 6f 64 65 29 3b 0a | 20 0a 20 0a 69 66 28 44 |pmode);.| . .if(D|
|000011b0| 45 42 55 47 29 20 70 72 | 69 6e 74 66 28 22 69 6e |EBUG) pr|intf("in|
|000011c0| 20 63 72 65 61 74 65 20 | 61 66 74 65 72 20 63 72 | create |after cr|
|000011d0| 65 61 74 20 3a 20 66 69 | 6c 65 20 3d 20 3c 25 73 |eat : fi|le = <%s|
|000011e0| 3e 20 3a 20 66 64 20 3d | 20 25 64 5c 6e 22 2c 63 |> : fd =| %d\n",c|
|000011f0| 68 61 72 6e 6d 31 2c 66 | 64 29 3b 0a 09 2f 2a 20 |harnm1,f|d);../* |
|00001200| 72 65 74 75 72 6e 20 74 | 68 65 20 66 69 6c 65 20 |return t|he file |
|00001210| 64 65 73 63 72 69 70 74 | 6f 72 20 69 66 20 66 64 |descript|or if fd|
|00001220| 20 3e 20 4d 41 58 46 44 | 20 2a 2f 0a 09 69 66 28 | > MAXFD| */..if(|
|00001230| 66 64 20 3e 20 4d 41 58 | 46 44 29 20 7b 0a 09 09 |fd > MAX|FD) {...|
|00001240| 63 6c 6f 73 65 28 66 64 | 29 3b 0a 09 09 0a 69 66 |close(fd|);....if|
|00001250| 28 44 45 42 55 47 29 20 | 70 72 69 6e 74 66 28 22 |(DEBUG) |printf("|
|00001260| 69 6e 20 63 72 65 61 74 | 65 20 61 66 74 65 72 20 |in creat|e after |
|00001270| 63 6c 6f 73 65 31 20 3a | 20 66 69 6c 65 20 3d 20 |close1 :| file = |
|00001280| 3c 25 73 3e 20 3a 20 66 | 64 20 3d 20 25 64 5c 6e |<%s> : f|d = %d\n|
|00001290| 22 2c 63 68 61 72 6e 6d | 31 2c 66 64 29 3b 0a 09 |",charnm|1,fd);..|
|000012a0| 09 2f 2a 20 72 65 6d 6f | 76 65 20 7a 65 72 6f 20 |./* remo|ve zero |
|000012b0| 6c 65 6e 67 74 68 20 66 | 69 6c 65 20 2a 2f 0a 09 |length f|ile */..|
|000012c0| 09 75 6e 6c 69 6e 6b 28 | 63 68 61 72 6e 6d 31 29 |.unlink(|charnm1)|
|000012d0| 3b 0a 09 09 72 65 74 75 | 72 6e 28 45 52 52 29 3b |;...retu|rn(ERR);|
|000012e0| 0a 09 7d 0a 20 0a 09 2f | 2a 20 72 65 74 75 72 6e |..}. ../|* return|
|000012f0| 20 69 66 20 6e 6f 74 20 | 63 72 65 61 74 65 64 20 | if not |created |
|00001300| 2a 2f 0a 09 69 66 20 28 | 66 64 20 3d 3d 20 2d 31 |*/..if (|fd == -1|
|00001310| 20 29 0a 09 20 09 72 65 | 74 75 72 6e 28 45 52 52 | ).. .re|turn(ERR|
|00001320| 29 3b 0a 20 0a 09 2f 2a | 20 72 65 6f 70 65 6e 20 |);. ../*| reopen |
|00001330| 77 69 74 68 20 6d 6f 64 | 65 20 61 63 63 65 73 73 |with mod|e access|
|00001340| 20 2a 2f 0a 09 63 6c 6f | 73 65 28 66 64 29 3b 0a | */..clo|se(fd);.|
|00001350| 69 66 28 44 45 42 55 47 | 29 20 70 72 69 6e 74 66 |if(DEBUG|) printf|
|00001360| 28 22 69 6e 20 63 72 65 | 61 74 65 20 61 66 74 65 |("in cre|ate afte|
|00001370| 72 20 63 6c 6f 73 65 32 | 20 3a 20 66 69 6c 65 20 |r close2| : file |
|00001380| 3d 20 3c 25 73 3e 20 3a | 20 66 64 20 3d 20 25 64 |= <%s> :| fd = %d|
|00001390| 5c 6e 22 2c 63 68 61 72 | 6e 6d 31 2c 66 64 29 3b |\n",char|nm1,fd);|
|000013a0| 0a 09 66 64 20 3d 20 6f | 70 65 6e 28 63 68 61 72 |..fd = o|pen(char|
|000013b0| 6e 6d 31 2c 20 2a 61 63 | 63 65 73 73 29 3b 0a 69 |nm1, *ac|cess);.i|
|000013c0| 66 28 44 45 42 55 47 29 | 20 70 72 69 6e 74 66 28 |f(DEBUG)| printf(|
|000013d0| 22 69 6e 20 63 72 65 61 | 74 65 20 61 66 74 65 72 |"in crea|te after|
|000013e0| 20 6f 70 65 6e 20 3a 20 | 66 69 6c 65 20 3d 20 3c | open : |file = <|
|000013f0| 25 73 3e 20 3a 20 66 64 | 20 3d 20 25 64 5c 6e 22 |%s> : fd| = %d\n"|
|00001400| 2c 63 68 61 72 6e 6d 31 | 2c 66 64 29 3b 0a 20 0a |,charnm1|,fd);. .|
|00001410| 09 2f 2a 20 6f 70 65 6e | 65 64 20 2d 20 69 6e 69 |./* open|ed - ini|
|00001420| 74 69 61 6c 69 7a 65 20 | 66 69 6c 65 20 64 65 73 |tialize |file des|
|00001430| 63 72 69 70 74 6f 72 20 | 62 6c 6f 63 6b 20 2a 2f |criptor |block */|
|00001440| 0a 09 70 74 72 20 3d 20 | 26 66 69 6c 65 73 5b 66 |..ptr = |&files[f|
|00001450| 64 5d 3b 0a 09 73 74 72 | 63 70 79 28 66 69 6c 65 |d];..str|cpy(file|
|00001460| 73 5b 66 64 5d 2e 66 69 | 6c 65 6e 61 6d 2c 20 63 |s[fd].fi|lenam, c|
|00001470| 68 61 72 6e 6d 31 29 3b | 0a 09 70 74 72 20 2d 3e |harnm1);|..ptr ->|
|00001480| 20 61 63 63 65 73 73 20 | 3d 20 2a 61 63 63 65 73 | access |= *acces|
|00001490| 73 3b 0a 09 0a 09 2f 2a | 20 69 6e 69 74 69 61 6c |s;..../*| initial|
|000014a0| 69 7a 65 20 63 75 72 72 | 65 6e 74 20 61 63 63 65 |ize curr|ent acce|
|000014b0| 73 73 20 74 6f 20 57 52 | 49 54 45 20 69 66 20 77 |ss to WR|ITE if w|
|000014c0| 72 69 74 65 20 6f 72 20 | 72 65 61 64 77 72 69 74 |rite or |readwrit|
|000014d0| 65 0a 09 61 63 63 65 73 | 73 20 72 65 71 75 65 73 |e..acces|s reques|
|000014e0| 74 65 64 2c 20 52 45 41 | 44 20 69 66 20 72 65 61 |ted, REA|D if rea|
|000014f0| 64 20 61 63 63 65 73 73 | 20 72 65 71 75 65 73 74 |d access| request|
|00001500| 65 64 20 2a 2f 0a 09 69 | 66 20 28 2a 61 63 63 65 |ed */..i|f (*acce|
|00001510| 73 73 20 3d 3d 20 52 45 | 41 44 29 0a 09 09 70 74 |ss == RE|AD)...pt|
|00001520| 72 2d 3e 63 61 63 63 65 | 73 73 20 3d 20 52 45 41 |r->cacce|ss = REA|
|00001530| 44 3b 0a 09 65 6c 73 65 | 0a 09 09 70 74 72 2d 3e |D;..else|...ptr->|
|00001540| 63 61 63 63 65 73 73 20 | 3d 20 57 52 49 54 45 3b |caccess |= WRITE;|
|00001550| 0a 09 70 74 72 20 2d 3e | 20 62 75 66 70 20 3d 20 |..ptr ->| bufp = |
|00001560| 70 74 72 20 2d 3e 20 62 | 75 66 66 65 72 3b 0a 09 |ptr -> b|uffer;..|
|00001570| 70 74 72 20 2d 3e 20 63 | 68 72 6c 65 66 74 20 3d |ptr -> c|hrleft =|
|00001580| 20 30 3b 0a 09 72 65 74 | 75 72 6e 20 28 66 64 29 | 0;..ret|urn (fd)|
|00001590| 20 3b 0a 20 0a 7d 0a 20 | 0a 65 72 72 6f 72 5f 28 | ;. .}. |.error_(|
|000015a0| 73 74 72 69 6e 67 2c 20 | 6c 65 6e 67 74 68 29 0a |string, |length).|
|000015b0| 63 68 61 72 20 2a 73 74 | 72 69 6e 67 3b 0a 6c 6f |char *st|ring;.lo|
|000015c0| 6e 67 20 69 6e 74 20 6c | 65 6e 67 74 68 3b 0a 20 |ng int l|ength;. |
|000015d0| 0a 7b 0a 09 2f 2a 20 6f | 75 74 70 75 74 20 61 6e |.{../* o|utput an|
|000015e0| 20 65 72 72 6f 72 20 6d | 65 73 73 61 67 65 20 73 | error m|essage s|
|000015f0| 74 72 69 6e 67 20 74 6f | 20 73 74 64 65 72 72 20 |tring to| stderr |
|00001600| 61 6e 64 20 74 65 72 6d | 69 6e 61 74 65 20 74 68 |and term|inate th|
|00001610| 65 0a 09 20 20 20 74 6f | 6f 6c 20 77 69 74 68 20 |e.. to|ol with |
|00001620| 61 20 63 61 6c 6c 20 74 | 6f 20 5a 51 55 49 54 20 |a call t|o ZQUIT |
|00001630| 77 69 74 68 20 73 74 61 | 74 75 73 20 5a 45 52 52 |with sta|tus ZERR|
|00001640| 20 2a 2f 0a 20 0a 09 69 | 6e 74 20 65 72 72 20 3d | */. ..i|nt err =|
|00001650| 20 45 52 52 3b 0a 20 0a | 09 72 65 6d 61 72 6b 5f | ERR;. .|.remark_|
|00001660| 28 73 74 72 69 6e 67 2c | 20 6c 65 6e 67 74 68 29 |(string,| length)|
|00001670| 3b 0a 09 7a 71 75 69 74 | 5f 28 20 26 65 72 72 20 |;..zquit|_( &err |
|00001680| 29 3b 0a 20 0a 7d 0a 20 | 0a 67 65 74 63 5f 28 63 |);. .}. |.getc_(c|
|00001690| 68 29 0a 69 6e 74 20 2a | 63 68 3b 0a 20 0a 7b 0a |h).int *|ch;. .{.|
|000016a0| 20 0a 09 2f 2a 20 67 65 | 74 20 61 20 73 69 6e 67 | ../* ge|t a sing|
|000016b0| 6c 65 20 63 68 61 72 61 | 63 74 65 72 20 66 72 6f |le chara|cter fro|
|000016c0| 6d 20 74 68 65 20 73 74 | 61 6e 64 61 72 64 20 69 |m the st|andard i|
|000016d0| 6e 70 75 74 2a 2f 0a 20 | 0a 09 69 6e 74 20 66 64 |nput*/. |..int fd|
|000016e0| 20 3d 20 53 54 44 49 4e | 3b 0a 20 0a 09 72 65 74 | = STDIN|;. ..ret|
|000016f0| 75 72 6e 20 28 20 2a 63 | 68 20 3d 20 67 65 74 63 |urn ( *c|h = getc|
|00001700| 68 5f 28 63 68 2c 20 26 | 66 64 29 20 29 3b 0a 20 |h_(ch, &|fd) );. |
|00001710| 0a 7d 0a 20 0a 20 0a 67 | 65 74 63 68 5f 28 63 68 |.}. . .g|etch_(ch|
|00001720| 2c 20 66 64 29 0a 69 6e | 74 20 2a 63 68 2c 20 2a |, fd).in|t *ch, *|
|00001730| 66 64 3b 0a 20 0a 7b 0a | 20 0a 09 2f 2a 20 67 65 |fd;. .{.| ../* ge|
|00001740| 74 20 61 20 73 69 6e 67 | 6c 65 20 63 68 61 72 61 |t a sing|le chara|
|00001750| 63 74 65 72 20 66 72 6f | 6d 20 74 68 65 20 73 65 |cter fro|m the se|
|00001760| 71 75 65 6e 74 69 61 6c | 20 66 6c 65 0a 09 20 20 |quential| fle.. |
|00001770| 20 77 69 74 68 20 66 69 | 6c 65 20 64 65 73 63 72 | with fi|le descr|
|00001780| 69 70 74 6f 72 20 66 64 | 2e 20 54 72 61 69 6c 69 |iptor fd|. Traili|
|00001790| 6e 67 20 62 6c 61 6e 6b | 73 20 69 2e 65 2e 0a 09 |ng blank|s i.e...|
|000017a0| 20 20 20 74 68 6f 73 65 | 20 62 65 74 77 65 65 6e | those| between|
|000017b0| 20 74 68 65 20 6c 61 73 | 74 20 6e 6f 6e 2d 73 70 | the las|t non-sp|
|000017c0| 61 63 65 20 61 6e 64 20 | 74 68 65 20 66 69 6e 61 |ace and |the fina|
|000017d0| 6c 0a 09 20 20 20 6e 65 | 77 6c 69 6e 65 20 61 72 |l.. ne|wline ar|
|000017e0| 65 20 73 74 72 69 70 70 | 65 64 20 6f 75 74 20 2a |e stripp|ed out *|
|000017f0| 2f 0a 20 0a 09 73 74 72 | 75 63 74 20 66 64 69 6e |/. ..str|uct fdin|
|00001800| 66 6f 20 2a 70 74 72 3b | 0a 09 63 68 61 72 20 63 |fo *ptr;|..char c|
|00001810| 3b 0a 20 0a 09 2f 2a 20 | 63 68 65 63 6b 20 66 6f |;. ../* |check fo|
|00001820| 72 20 76 61 6c 69 64 20 | 66 64 20 61 6e 64 20 66 |r valid |fd and f|
|00001830| 69 6c 65 20 6f 70 65 6e | 20 69 6e 20 72 65 61 64 |ile open| in read|
|00001840| 20 6d 6f 64 65 20 2a 2f | 0a 09 69 66 20 28 20 6f | mode */|..if ( o|
|00001850| 70 6e 72 65 61 64 28 2a | 66 64 29 20 3d 3d 20 45 |pnread(*|fd) == E|
|00001860| 52 52 20 29 0a 09 09 72 | 65 74 75 72 6e 28 20 2a |RR )...r|eturn( *|
|00001870| 63 68 20 3d 20 45 52 52 | 20 29 3b 0a 20 0a 09 70 |ch = ERR| );. ..p|
|00001880| 74 72 20 3d 20 26 66 69 | 6c 65 73 5b 2a 66 64 5d |tr = &fi|les[*fd]|
|00001890| 3b 0a 20 0a 09 2f 2a 20 | 73 74 69 6c 6c 20 65 6d |;. ../* |still em|
|000018a0| 62 65 64 64 65 64 20 73 | 70 61 63 65 73 20 74 6f |bedded s|paces to|
|000018b0| 20 70 61 73 73 20 6f 6e | 20 3f 20 2a 2f 0a 09 69 | pass on| ? */..i|
|000018c0| 66 20 28 70 74 72 2d 3e | 63 6f 75 6e 74 20 3e 20 |f (ptr->|count > |
|000018d0| 30 29 20 7b 0a 09 09 70 | 74 72 2d 3e 63 6f 75 6e |0) {...p|tr->coun|
|000018e0| 74 2d 2d 3b 0a 09 09 72 | 65 74 75 72 6e 28 20 2a |t--;...r|eturn( *|
|000018f0| 63 68 20 3d 20 42 4c 41 | 4e 4b 29 3b 0a 09 7d 0a |ch = BLA|NK);..}.|
|00001900| 20 0a 20 0a 09 2f 2a 20 | 66 69 6c 65 20 6f 70 65 | . ../* |file ope|
|00001910| 6e 20 69 6e 20 72 65 61 | 64 20 6d 6f 64 65 20 6e |n in rea|d mode n|
|00001920| 6f 77 20 2a 2f 0a 20 0a | 09 69 66 20 28 70 74 72 |ow */. .|.if (ptr|
|00001930| 2d 3e 63 68 72 6c 65 66 | 74 20 3d 3d 20 30 29 20 |->chrlef|t == 0) |
|00001940| 7b 0a 20 0a 09 2f 2a 20 | 62 75 66 66 65 72 20 69 |{. ../* |buffer i|
|00001950| 73 20 65 6d 70 74 79 20 | 2a 2f 0a 09 09 70 74 72 |s empty |*/...ptr|
|00001960| 2d 3e 63 68 72 6c 65 66 | 74 20 3d 20 72 65 61 64 |->chrlef|t = read|
|00001970| 28 2a 66 64 2c 20 70 74 | 72 2d 3e 62 75 66 66 65 |(*fd, pt|r->buffe|
|00001980| 72 2c 20 42 4c 4f 43 4b | 53 49 5a 45 29 3b 0a 09 |r, BLOCK|SIZE);..|
|00001990| 09 70 74 72 2d 3e 62 75 | 66 70 20 3d 20 70 74 72 |.ptr->bu|fp = ptr|
|000019a0| 2d 3e 62 75 66 66 65 72 | 3b 0a 09 0a 09 09 2f 2a |->buffer|;...../*|
|000019b0| 20 72 65 74 75 72 6e 20 | 45 4f 46 20 69 66 20 6e | return |EOF if n|
|000019c0| 6f 20 63 68 61 72 61 63 | 74 65 72 73 20 72 65 61 |o charac|ters rea|
|000019d0| 64 20 2a 2f 0a 09 09 69 | 66 20 28 70 74 72 2d 3e |d */...i|f (ptr->|
|000019e0| 63 68 72 6c 65 66 74 20 | 3d 3d 20 30 29 20 7b 0a |chrleft |== 0) {.|
|000019f0| 09 09 09 2f 2a 20 74 68 | 72 6f 77 20 61 77 61 79 |.../* th|row away|
|00001a00| 20 73 70 61 63 65 73 20 | 69 66 20 6e 6f 20 6e 65 | spaces |if no ne|
|00001a10| 77 6c 69 6e 65 20 62 65 | 66 6f 72 65 20 45 4f 46 |wline be|fore EOF|
|00001a20| 20 2a 2f 0a 09 09 09 70 | 74 72 2d 3e 63 6f 75 6e | */....p|tr->coun|
|00001a30| 74 20 3d 20 30 3b 0a 09 | 09 09 72 65 74 75 72 6e |t = 0;..|..return|
|00001a40| 28 20 2a 63 68 20 3d 20 | 45 4f 46 29 3b 0a 09 09 |( *ch = |EOF);...|
|00001a50| 7d 0a 09 7d 0a 09 0a 09 | 2f 2a 20 65 61 74 20 77 |}..}....|/* eat w|
|00001a60| 68 69 74 65 20 73 70 61 | 63 65 20 72 65 66 69 6c |hite spa|ce refil|
|00001a70| 6c 69 6e 67 20 74 68 65 | 20 62 75 66 66 65 72 20 |ling the| buffer |
|00001a80| 61 73 20 6e 65 63 65 73 | 73 61 72 79 20 2a 2f 0a |as neces|sary */.|
|00001a90| 09 77 68 69 6c 65 20 28 | 28 63 20 3d 20 2a 70 74 |.while (|(c = *pt|
|00001aa0| 72 2d 3e 62 75 66 70 2b | 2b 29 20 3d 3d 20 42 4c |r->bufp+|+) == BL|
|00001ab0| 41 4e 4b 43 48 29 20 7b | 0a 09 09 70 74 72 2d 3e |ANKCH) {|...ptr->|
|00001ac0| 63 6f 75 6e 74 2b 2b 3b | 0a 09 09 70 74 72 2d 3e |count++;|...ptr->|
|00001ad0| 63 68 72 6c 65 66 74 2d | 2d 3b 0a 20 0a 09 09 69 |chrleft-|-;. ...i|
|00001ae0| 66 20 28 70 74 72 2d 3e | 63 68 72 6c 65 66 74 20 |f (ptr->|chrleft |
|00001af0| 3d 3d 20 30 29 7b 0a 09 | 09 09 2f 2a 20 69 66 20 |== 0){..|../* if |
|00001b00| 77 65 20 72 75 6e 20 6f | 75 74 20 6f 66 20 63 68 |we run o|ut of ch|
|00001b10| 61 72 61 63 74 65 72 73 | 20 72 65 66 69 6c 6c 20 |aracters| refill |
|00001b20| 74 68 65 20 62 75 66 66 | 65 72 20 2a 2f 0a 09 09 |the buff|er */...|
|00001b30| 09 70 74 72 2d 3e 63 68 | 72 6c 65 66 74 20 3d 20 |.ptr->ch|rleft = |
|00001b40| 72 65 61 64 28 2a 66 64 | 2c 20 70 74 72 2d 3e 62 |read(*fd|, ptr->b|
|00001b50| 75 66 66 65 72 2c 20 42 | 4c 4f 43 4b 53 49 5a 45 |uffer, B|LOCKSIZE|
|00001b60| 29 3b 0a 09 09 09 70 74 | 72 2d 3e 62 75 66 70 20 |);....pt|r->bufp |
|00001b70| 3d 20 70 74 72 2d 3e 62 | 75 66 66 65 72 3b 0a 09 |= ptr->b|uffer;..|
|00001b80| 09 0a 09 09 09 2f 2a 20 | 72 65 74 75 72 6e 20 45 |...../* |return E|
|00001b90| 4f 46 20 69 66 20 6e 6f | 20 63 68 61 72 61 63 74 |OF if no| charact|
|00001ba0| 65 72 73 20 72 65 61 64 | 20 2a 2f 0a 09 09 09 69 |ers read| */....i|
|00001bb0| 66 20 28 70 74 72 2d 3e | 63 68 72 6c 65 66 74 20 |f (ptr->|chrleft |
|00001bc0| 3d 3d 20 30 29 20 7b 0a | 09 09 09 09 2f 2a 20 74 |== 0) {.|..../* t|
|00001bd0| 68 72 6f 77 20 61 77 61 | 79 20 73 70 61 63 65 73 |hrow awa|y spaces|
|00001be0| 20 69 66 20 6e 6f 20 6e | 65 77 6c 69 6e 65 20 62 | if no n|ewline b|
|00001bf0| 65 66 6f 72 65 20 45 4f | 46 20 2a 2f 0a 09 09 09 |efore EO|F */....|
|00001c00| 09 70 74 72 2d 3e 63 6f | 75 6e 74 20 3d 20 30 3b |.ptr->co|unt = 0;|
|00001c10| 0a 09 09 09 09 72 65 74 | 75 72 6e 28 20 2a 63 68 |.....ret|urn( *ch|
|00001c20| 20 3d 20 45 4f 46 29 3b | 0a 09 09 09 7d 0a 09 09 | = EOF);|....}...|
|00001c30| 7d 0a 09 7d 0a 20 0a 09 | 2f 2a 20 77 65 20 6e 6f |}..}. ..|/* we no|
|00001c40| 77 20 68 61 76 65 20 61 | 20 6e 6f 6e 2d 73 70 61 |w have a| non-spa|
|00001c50| 63 65 20 63 68 61 72 61 | 63 74 65 72 20 61 6e 64 |ce chara|cter and|
|00001c60| 20 70 74 72 2d 3e 62 75 | 66 70 20 69 73 20 70 6f | ptr->bu|fp is po|
|00001c70| 69 6e 74 69 6e 67 0a 09 | 20 20 20 61 74 20 74 68 |inting..| at th|
|00001c80| 65 20 6e 65 78 74 20 63 | 68 61 72 61 63 74 65 72 |e next c|haracter|
|00001c90| 20 61 6c 74 68 6f 75 67 | 68 20 70 74 72 2d 3e 63 | althoug|h ptr->c|
|00001ca0| 68 72 6c 65 66 74 20 68 | 61 73 6e 27 74 20 69 6e |hrleft h|asn't in|
|00001cb0| 63 6c 75 64 65 64 0a 09 | 20 20 20 74 68 69 73 20 |cluded..| this |
|00001cc0| 2a 2f 0a 09 69 66 20 28 | 63 20 3d 3d 20 4e 45 57 |*/..if (|c == NEW|
|00001cd0| 4c 49 4e 45 43 48 29 7b | 0a 09 09 2f 2a 20 70 6f |LINECH){|.../* po|
|00001ce0| 73 73 69 62 6c 79 20 74 | 72 61 69 6e 69 6e 67 20 |ssibly t|raining |
|00001cf0| 62 6c 61 6e 6b 73 20 2d | 20 70 6f 69 6e 74 65 72 |blanks -| pointer|
|00001d00| 20 61 6c 72 65 61 64 79 | 20 6f 6e 0a 09 09 6e 65 | already| on...ne|
|00001d10| 78 74 20 63 68 61 72 61 | 63 74 65 72 20 2a 2f 0a |xt chara|cter */.|
|00001d20| 09 09 70 74 72 2d 3e 63 | 6f 75 6e 74 20 3d 20 30 |..ptr->c|ount = 0|
|00001d30| 3b 0a 09 09 70 74 72 2d | 3e 63 68 72 6c 65 66 74 |;...ptr-|>chrleft|
|00001d40| 2d 2d 3b 0a 09 09 72 65 | 74 75 72 6e 28 2a 63 68 |--;...re|turn(*ch|
|00001d50| 20 3d 20 4e 45 57 4c 49 | 4e 45 29 3b 0a 09 7d 0a | = NEWLI|NE);..}.|
|00001d60| 09 65 6c 73 65 20 69 66 | 20 28 70 74 72 2d 3e 63 |.else if| (ptr->c|
|00001d70| 6f 75 6e 74 20 3d 3d 20 | 30 29 20 7b 0a 09 09 2f |ount == |0) {.../|
|00001d80| 2a 20 64 65 63 72 65 6d | 65 6e 74 20 63 6f 75 6e |* decrem|ent coun|
|00001d90| 74 20 61 6e 64 20 72 65 | 74 75 72 6e 20 63 68 61 |t and re|turn cha|
|00001da0| 72 61 63 74 65 72 20 2a | 2f 0a 09 09 70 74 72 2d |racter *|/...ptr-|
|00001db0| 3e 63 68 72 6c 65 66 74 | 2d 2d 3b 0a 09 09 2a 63 |>chrleft|--;...*c|
|00001dc0| 68 20 3d 20 7a 63 63 74 | 6f 69 5f 28 26 63 2c 20 |h = zcct|oi_(&c, |
|00001dd0| 63 68 29 3b 0a 09 09 72 | 65 74 75 72 6e 28 2a 63 |ch);...r|eturn(*c|
|00001de0| 68 29 3b 0a 09 7d 0a 09 | 65 6c 73 65 20 7b 0a 09 |h);..}..|else {..|
|00001df0| 2f 2a 20 65 6d 62 65 64 | 64 65 64 20 73 70 61 63 |/* embed|ded spac|
|00001e00| 65 73 20 2d 20 72 65 74 | 75 72 6e 20 61 20 73 70 |es - ret|urn a sp|
|00001e10| 61 63 65 20 61 6e 64 20 | 64 65 63 72 65 6d 65 6e |ace and |decremen|
|00001e20| 74 20 73 70 61 63 65 20 | 63 6f 75 6e 74 2e 0a 09 |t space |count...|
|00001e30| 20 20 20 42 61 63 6b 74 | 72 61 63 6b 20 70 6f 69 | Backt|rack poi|
|00001e40| 6e 74 65 72 20 74 6f 20 | 6e 65 78 74 20 6e 6f 6e |nter to |next non|
|00001e50| 20 73 70 61 63 65 20 63 | 68 61 72 2c 20 6c 65 61 | space c|har, lea|
|00001e60| 76 65 20 74 68 65 20 63 | 68 61 72 61 63 74 65 72 |ve the c|haracter|
|00001e70| 0a 09 20 20 20 63 6f 75 | 6e 74 65 72 20 61 6c 6f |.. cou|nter alo|
|00001e80| 6e 65 20 2a 2f 0a 09 09 | 70 74 72 2d 3e 62 75 66 |ne */...|ptr->buf|
|00001e90| 70 2d 2d 3b 0a 09 09 70 | 74 72 2d 3e 63 6f 75 6e |p--;...p|tr->coun|
|00001ea0| 74 2d 2d 3b 0a 09 09 72 | 65 74 75 72 6e 28 2a 63 |t--;...r|eturn(*c|
|00001eb0| 68 20 3d 20 42 4c 41 4e | 4b 29 3b 0a 09 7d 0a 7d |h = BLAN|K);..}.}|
|00001ec0| 0a 20 0a 67 65 74 6c 69 | 6e 5f 28 62 75 66 66 65 |. .getli|n_(buffe|
|00001ed0| 72 2c 20 66 64 29 0a 69 | 6e 74 20 2a 62 75 66 66 |r, fd).i|nt *buff|
|00001ee0| 65 72 2c 20 2a 66 64 3b | 0a 20 0a 7b 0a 09 2f 2a |er, *fd;|. .{../*|
|00001ef0| 20 67 65 74 61 20 6c 69 | 6e 65 20 66 72 6f 6d 20 | geta li|ne from |
|00001f00| 74 68 65 20 73 65 71 75 | 65 6e 74 69 61 6c 20 66 |the sequ|ential f|
|00001f10| 69 6c 65 20 61 73 73 6f | 63 69 61 74 65 64 20 77 |ile asso|ciated w|
|00001f20| 69 74 68 0a 09 20 20 20 | 74 68 65 20 66 69 6c 65 |ith.. |the file|
|00001f30| 20 64 65 73 63 72 69 70 | 74 6f 72 20 66 64 2e 20 | descrip|tor fd. |
|00001f40| 54 68 65 20 6e 75 6d 62 | 65 72 20 6f 66 20 63 68 |The numb|er of ch|
|00001f50| 61 72 61 63 74 65 72 73 | 0a 09 20 20 20 72 65 61 |aracters|.. rea|
|00001f60| 64 20 69 6e 74 6f 20 62 | 75 66 66 65 72 20 69 6e |d into b|uffer in|
|00001f70| 63 6c 75 64 69 6e 67 20 | 74 68 65 20 6e 65 77 6c |cluding |the newl|
|00001f80| 69 6e 65 20 62 75 74 20 | 6e 6f 74 20 74 68 65 0a |ine but |not the.|
|00001f90| 09 20 20 20 65 6f 73 20 | 69 73 20 72 65 74 75 72 |. eos |is retur|
|00001fa0| 6e 65 64 2e 20 49 66 20 | 65 6f 66 20 77 61 73 20 |ned. If |eof was |
|00001fb0| 65 6e 63 6f 75 6e 74 65 | 72 65 64 20 6f 6e 20 66 |encounte|red on f|
|00001fc0| 64 20 74 68 65 6e 0a 09 | 20 20 20 65 6f 66 20 69 |d then..| eof i|
|00001fd0| 73 20 72 65 74 75 72 6e | 65 64 2e 20 54 68 65 20 |s return|ed. The |
|00001fe0| 6e 75 6d 62 65 72 20 6f | 66 20 63 68 61 72 61 63 |number o|f charac|
|00001ff0| 74 65 72 73 20 72 65 61 | 64 20 69 6e 74 6f 0a 09 |ters rea|d into..|
|00002000| 20 20 20 62 75 66 66 65 | 72 20 6e 65 76 65 72 20 | buffe|r never |
|00002010| 65 78 63 65 65 64 73 20 | 6d 61 78 6c 69 6e 65 20 |exceeds |maxline |
|00002020| 61 6c 74 68 6f 75 67 68 | 20 61 20 6e 65 77 6c 69 |although| a newli|
|00002030| 6e 65 20 61 6e 64 20 65 | 6f 73 0a 09 20 20 20 6d |ne and e|os.. m|
|00002040| 61 79 20 62 65 20 61 70 | 70 65 6e 64 65 64 20 6d |ay be ap|pended m|
|00002050| 61 6b 69 6e 67 20 74 68 | 65 20 6d 61 78 69 6d 75 |aking th|e maximu|
|00002060| 6d 20 6c 65 6e 67 74 68 | 20 6f 66 20 62 75 66 66 |m length| of buff|
|00002070| 65 72 0a 09 20 20 20 6d | 61 78 62 75 66 66 20 2a |er.. m|axbuff *|
|00002080| 2f 0a 20 0a 09 69 6e 74 | 20 69 2c 20 63 3b 0a 09 |/. ..int| i, c;..|
|00002090| 0a 09 2f 2a 20 67 65 74 | 20 61 20 6c 69 6e 65 20 |../* get| a line |
|000020a0| 2a 2f 0a 09 66 6f 72 20 | 28 69 20 3d 20 31 3b 20 |*/..for |(i = 1; |
|000020b0| 69 20 3c 3d 20 4d 41 58 | 4c 49 4e 45 20 26 26 20 |i <= MAX|LINE && |
|000020c0| 28 63 3d 67 65 74 63 68 | 5f 28 26 63 2c 66 64 29 |(c=getch|_(&c,fd)|
|000020d0| 29 20 21 3d 20 4e 45 57 | 4c 49 4e 45 20 26 26 20 |) != NEW|LINE && |
|000020e0| 63 20 21 3d 20 45 4f 46 | 0a 09 09 09 26 26 20 63 |c != EOF|....&& c|
|000020f0| 20 21 3d 20 45 52 52 3b | 20 2a 62 75 66 66 65 72 | != ERR;| *buffer|
|00002100| 2b 2b 20 3d 20 63 20 2c | 20 69 2b 2b 20 29 3b 0a |++ = c ,| i++ );.|
|00002110| 20 0a 09 2f 2a 20 61 6c | 72 65 61 64 79 20 68 61 | ../* al|ready ha|
|00002120| 76 65 20 6d 61 78 6c 69 | 6e 65 20 63 68 61 72 61 |ve maxli|ne chara|
|00002130| 63 74 65 72 73 20 77 69 | 74 68 6f 75 74 20 61 20 |cters wi|thout a |
|00002140| 6e 65 77 6c 69 6e 65 20 | 2a 2f 0a 09 69 66 20 28 |newline |*/..if (|
|00002150| 69 20 3e 20 4d 41 58 4c | 49 4e 45 29 20 7b 0a 09 |i > MAXL|INE) {..|
|00002160| 09 2f 2a 20 66 6c 75 73 | 68 20 74 68 65 20 6e 65 |./* flus|h the ne|
|00002170| 77 6c 69 6e 65 20 6f 72 | 20 6c 6f 73 65 20 63 68 |wline or| lose ch|
|00002180| 61 72 61 63 74 65 72 20 | 4d 41 58 4c 49 4e 45 20 |aracter |MAXLINE |
|00002190| 2b 31 20 2a 2f 0a 09 09 | 63 20 3d 20 67 65 74 63 |+1 */...|c = getc|
|000021a0| 68 5f 28 26 63 2c 20 66 | 64 29 3b 0a 09 09 2a 62 |h_(&c, f|d);...*b|
|000021b0| 75 66 66 65 72 2b 2b 20 | 3d 20 4e 45 57 4c 49 4e |uffer++ |= NEWLIN|
|000021c0| 45 3b 0a 09 09 2a 62 75 | 66 66 65 72 20 3d 20 45 |E;...*bu|ffer = E|
|000021d0| 4f 53 3b 0a 09 09 72 65 | 74 75 72 6e 28 4d 41 58 |OS;...re|turn(MAX|
|000021e0| 4c 49 4e 45 20 2b 20 31 | 29 3b 0a 09 7d 0a 20 0a |LINE + 1|);..}. .|
|000021f0| 09 73 77 69 74 63 68 20 | 28 63 29 20 7b 0a 20 0a |.switch |(c) {. .|
|00002200| 09 09 63 61 73 65 20 4e | 45 57 4c 49 4e 45 3a 0a |..case N|EWLINE:.|
|00002210| 09 09 09 2a 62 75 66 66 | 65 72 2b 2b 20 3d 20 4e |...*buff|er++ = N|
|00002220| 45 57 4c 49 4e 45 3b 0a | 09 09 09 2a 62 75 66 66 |EWLINE;.|...*buff|
|00002230| 65 72 20 3d 20 45 4f 53 | 3b 0a 09 09 09 72 65 74 |er = EOS|;....ret|
|00002240| 75 72 6e 28 69 29 3b 0a | 20 0a 09 09 63 61 73 65 |urn(i);.| ...case|
|00002250| 20 45 4f 46 3a 0a 09 09 | 09 2a 62 75 66 66 65 72 | EOF:...|.*buffer|
|00002260| 2b 2b 20 3d 20 4e 45 57 | 4c 49 4e 45 3b 0a 09 09 |++ = NEW|LINE;...|
|00002270| 09 2a 62 75 66 66 65 72 | 20 3d 20 45 4f 53 3b 0a |.*buffer| = EOS;.|
|00002280| 09 09 09 72 65 74 75 72 | 6e 28 45 4f 46 29 3b 0a |...retur|n(EOF);.|
|00002290| 20 0a 09 09 63 61 73 65 | 20 45 52 52 3a 0a 09 09 | ...case| ERR:...|
|000022a0| 09 2a 62 75 66 66 65 72 | 20 3d 20 45 4f 53 3b 0a |.*buffer| = EOS;.|
|000022b0| 09 09 09 72 65 74 75 72 | 6e 28 45 52 52 29 3b 0a |...retur|n(ERR);.|
|000022c0| 20 0a 09 7d 0a 7d 0a 20 | 0a 20 0a 6f 70 65 6e 5f | ..}.}. |. .open_|
|000022d0| 28 6e 61 6d 65 2c 20 61 | 63 63 65 73 73 29 0a 69 |(name, a|ccess).i|
|000022e0| 6e 74 20 2a 6e 61 6d 65 | 2c 20 2a 61 63 63 65 73 |nt *name|, *acces|
|000022f0| 73 3b 0a 7b 0a 09 2f 2a | 20 6f 70 65 6e 20 61 6e |s;.{../*| open an|
|00002300| 20 65 78 69 73 74 69 6e | 67 20 73 65 71 75 65 6e | existin|g sequen|
|00002310| 74 69 61 6c 20 66 69 6c | 65 20 6e 61 6d 65 20 77 |tial fil|e name w|
|00002320| 69 74 68 20 61 63 63 65 | 73 73 20 74 79 70 65 0a |ith acce|ss type.|
|00002330| 09 20 20 20 61 63 63 65 | 73 73 20 28 3d 72 2c 20 |. acce|ss (=r, |
|00002340| 77 20 6f 72 20 72 77 29 | 2e 20 41 73 73 69 67 6e |w or rw)|. Assign|
|00002350| 20 61 6e 20 69 6e 74 65 | 72 6e 61 6c 20 66 69 6c | an inte|rnal fil|
|00002360| 65 20 64 65 73 63 72 69 | 70 74 6f 72 0a 09 20 20 |e descri|ptor.. |
|00002370| 20 61 6e 64 20 72 65 74 | 75 72 6e 20 69 74 20 61 | and ret|urn it a|
|00002380| 73 20 74 68 65 20 76 61 | 6c 75 65 20 6f 66 20 74 |s the va|lue of t|
|00002390| 68 65 20 66 75 6e 63 74 | 69 6f 6e 2e 20 49 74 20 |he funct|ion. It |
|000023a0| 69 73 20 69 6c 6c 65 67 | 61 6c 0a 09 20 20 20 74 |is illeg|al.. t|
|000023b0| 6f 20 74 72 79 20 61 6e | 64 20 6f 70 65 6e 20 61 |o try an|d open a|
|000023c0| 20 66 69 6c 65 20 77 68 | 69 63 68 20 64 6f 65 73 | file wh|ich does|
|000023d0| 20 6e 6f 74 20 65 78 69 | 73 74 20 2a 2f 0a 20 0a | not exi|st */. .|
|000023e0| 09 69 6e 74 20 66 64 3b | 0a 09 73 74 72 75 63 74 |.int fd;|..struct|
|000023f0| 20 66 69 6c 69 6e 66 6f | 20 6f 70 65 6e 69 6e 66 | filinfo| openinf|
|00002400| 3b 0a 09 63 68 61 72 20 | 63 68 61 72 6e 6d 31 5b |;..char |charnm1[|
|00002410| 4d 41 58 50 41 54 48 5d | 3b 0a 20 0a 20 20 20 20 |MAXPATH]|;. . |
|00002420| 20 2f 2a 09 67 65 6e 65 | 72 61 74 65 20 66 75 6c | /*.gene|rate ful|
|00002430| 6c 20 70 61 74 68 20 6e | 61 6d 65 20 61 73 20 61 |l path n|ame as a|
|00002440| 20 63 68 61 72 61 63 74 | 65 72 20 73 74 72 69 6e | charact|er strin|
|00002450| 67 20 2a 2f 0a 20 20 20 | 20 09 6d 6b 66 69 6c 6e |g */. | .mkfiln|
|00002460| 6d 28 6e 61 6d 65 2c 20 | 63 68 61 72 6e 6d 31 2c |m(name, |charnm1,|
|00002470| 20 26 6f 70 65 6e 69 6e | 66 29 3b 0a 20 0a 20 20 | &openin|f);. . |
|00002480| 20 20 20 2f 2a 09 73 6f | 72 74 20 6f 75 74 20 70 | /*.so|rt out p|
|00002490| 6f 73 73 69 62 6c 65 20 | 65 72 72 6f 72 20 63 61 |ossible |error ca|
|000024a0| 73 65 73 20 2a 2f 0a 09 | 73 77 69 74 63 68 20 28 |ses */..|switch (|
|000024b0| 6f 70 65 6e 69 6e 66 2e | 66 74 79 70 65 31 29 0a |openinf.|ftype1).|
|000024c0| 09 7b 0a 09 20 20 63 61 | 73 65 20 45 52 52 3a 20 |.{.. ca|se ERR: |
|000024d0| 20 2f 2a 20 65 72 72 6f | 72 20 69 6e 20 6d 6b 70 | /* erro|r in mkp|
|000024e0| 61 74 68 20 6f 72 20 68 | 6f 73 74 20 66 69 6c 65 |ath or h|ost file|
|000024f0| 20 61 20 64 69 72 65 63 | 74 6f 72 79 20 2a 2f 0a | a direc|tory */.|
|00002500| 09 09 72 65 74 75 72 6e | 28 45 52 52 29 3b 0a 09 |..return|(ERR);..|
|00002510| 0a 09 20 20 63 61 73 65 | 20 44 45 56 49 43 45 3a |.. case| DEVICE:|
|00002520| 20 2f 2a 20 72 65 74 75 | 72 6e 20 65 72 72 20 66 | /* retu|rn err f|
|00002530| 6f 72 20 69 6c 6c 65 67 | 61 6c 20 61 63 63 65 73 |or illeg|al acces|
|00002540| 73 20 6f 74 68 65 72 77 | 69 73 65 20 66 64 20 2a |s otherw|ise fd *|
|00002550| 2f 0a 09 09 72 65 74 75 | 72 6e 28 28 70 72 63 6f |/...retu|rn((prco|
|00002560| 6e 66 6c 28 6f 70 65 6e | 69 6e 66 2e 73 75 62 74 |nfl(open|inf.subt|
|00002570| 79 70 65 2c 20 2a 61 63 | 63 65 73 73 29 20 3d 3d |ype, *ac|cess) ==|
|00002580| 20 45 52 52 29 0a 09 09 | 09 3f 20 45 52 52 20 3a | ERR)...|.? ERR :|
|00002590| 20 6f 70 65 6e 69 6e 66 | 2e 73 75 62 74 79 70 65 | openinf|.subtype|
|000025a0| 29 3b 0a 20 0a 09 20 20 | 63 61 73 65 20 48 4f 53 |);. .. |case HOS|
|000025b0| 54 3a 20 20 2f 2a 20 65 | 72 72 6f 72 20 69 66 20 |T: /* e|rror if |
|000025c0| 66 69 6c 65 20 64 6f 65 | 73 6e 27 74 20 65 78 69 |file doe|sn't exi|
|000025d0| 73 74 20 2a 2f 0a 09 09 | 69 66 28 6f 70 65 6e 69 |st */...|if(openi|
|000025e0| 6e 66 2e 65 78 69 73 74 | 73 20 3d 3d 20 4e 4f 29 |nf.exist|s == NO)|
|000025f0| 20 72 65 74 75 72 6e 28 | 45 52 52 29 3b 0a 09 09 | return(|ERR);...|
|00002600| 62 72 65 61 6b 3b 0a 20 | 0a 09 20 20 63 61 73 65 |break;. |.. case|
|00002610| 20 56 46 53 3a 20 20 2f | 2a 20 65 72 72 6f 72 20 | VFS: /|* error |
|00002620| 69 66 20 66 69 6c 65 20 | 64 6f 65 73 6e 27 74 20 |if file |doesn't |
|00002630| 65 78 69 73 74 20 6f 72 | 20 64 69 72 65 63 74 6f |exist or| directo|
|00002640| 72 79 20 2a 2f 0a 09 09 | 69 66 28 6f 70 65 6e 69 |ry */...|if(openi|
|00002650| 6e 66 2e 65 78 69 73 74 | 73 20 3d 3d 20 4e 4f 20 |nf.exist|s == NO |
|00002660| 7c 7c 20 6f 70 65 6e 69 | 6e 66 2e 73 75 62 74 79 ||| openi|nf.subty|
|00002670| 70 65 20 3d 3d 20 44 49 | 52 45 43 54 4f 52 59 29 |pe == DI|RECTORY)|
|00002680| 0a 09 09 09 72 65 74 75 | 72 6e 28 45 52 52 29 3b |....retu|rn(ERR);|
|00002690| 0a 09 20 7d 0a 09 09 0a | 09 2f 2a 20 65 6e 73 75 |.. }....|./* ensu|
|000026a0| 72 65 20 6f 70 65 6e 20 | 6f 6b 20 61 6e 64 20 6e |re open |ok and n|
|000026b0| 6f 74 20 74 6f 6f 20 6d | 61 6e 79 20 64 65 73 63 |ot too m|any desc|
|000026c0| 72 69 70 74 6f 72 73 20 | 2a 2f 0a 09 69 66 28 28 |riptors |*/..if((|
|000026d0| 66 64 3d 6f 70 65 6e 28 | 63 68 61 72 6e 6d 31 2c |fd=open(|charnm1,|
|000026e0| 20 2a 61 63 63 65 73 73 | 29 29 20 3d 3d 20 2d 31 | *access|)) == -1|
|000026f0| 20 29 20 72 65 74 75 72 | 6e 28 45 52 52 29 3b 0a | ) retur|n(ERR);.|
|00002700| 20 0a 69 66 28 44 45 42 | 55 47 29 20 70 72 69 6e | .if(DEB|UG) prin|
|00002710| 74 66 28 22 69 6e 20 6f | 70 65 6e 20 3a 20 66 69 |tf("in o|pen : fi|
|00002720| 6c 65 20 3d 20 3c 25 73 | 3e 20 3a 20 66 64 20 3d |le = <%s|> : fd =|
|00002730| 20 25 64 5c 6e 22 2c 63 | 68 61 72 6e 6d 31 2c 66 | %d\n",c|harnm1,f|
|00002740| 64 29 3b 0a 09 69 66 20 | 28 66 64 20 3e 20 4d 41 |d);..if |(fd > MA|
|00002750| 58 46 44 29 20 7b 0a 09 | 09 63 6c 6f 73 65 28 66 |XFD) {..|.close(f|
|00002760| 64 29 3b 0a 69 66 28 44 | 45 42 55 47 29 20 70 72 |d);.if(D|EBUG) pr|
|00002770| 69 6e 74 66 28 22 69 6e | 20 6f 70 65 6e 20 61 66 |intf("in| open af|
|00002780| 74 65 72 20 63 6c 6f 73 | 65 31 20 3a 20 66 69 6c |ter clos|e1 : fil|
|00002790| 65 20 3d 20 3c 25 73 3e | 20 3a 20 66 64 20 3d 20 |e = <%s>| : fd = |
|000027a0| 25 64 5c 6e 22 2c 63 68 | 61 72 6e 6d 31 2c 66 64 |%d\n",ch|arnm1,fd|
|000027b0| 29 3b 0a 09 09 72 65 74 | 75 72 6e 28 45 52 52 29 |);...ret|urn(ERR)|
|000027c0| 3b 0a 09 7d 0a 20 0a 09 | 2f 2a 20 73 74 6f 72 65 |;..}. ..|/* store|
|000027d0| 20 66 69 6c 65 20 69 6e | 66 6f 20 61 6e 64 20 69 | file in|fo and i|
|000027e0| 6e 69 74 69 61 6c 69 7a | 65 20 62 75 66 66 65 72 |nitializ|e buffer|
|000027f0| 73 20 65 74 63 2e 20 2a | 2f 0a 09 73 74 72 63 70 |s etc. *|/..strcp|
|00002800| 79 28 66 69 6c 65 73 5b | 66 64 5d 2e 66 69 6c 65 |y(files[|fd].file|
|00002810| 6e 61 6d 2c 20 63 68 61 | 72 6e 6d 31 29 3b 0a 09 |nam, cha|rnm1);..|
|00002820| 66 69 6c 65 73 5b 66 64 | 5d 2e 66 74 79 70 65 20 |files[fd|].ftype |
|00002830| 3d 20 53 45 51 55 45 4e | 54 49 41 4c 3b 0a 09 66 |= SEQUEN|TIAL;..f|
|00002840| 69 6c 65 73 5b 66 64 5d | 2e 61 63 63 65 73 73 20 |iles[fd]|.access |
|00002850| 3d 20 2a 61 63 63 65 73 | 73 3b 0a 20 0a 09 2f 2a |= *acces|s;. ../*|
|00002860| 20 73 65 74 20 63 75 72 | 72 65 6e 74 20 61 63 63 | set cur|rent acc|
|00002870| 65 73 73 20 74 6f 20 52 | 45 41 44 20 69 66 20 61 |ess to R|EAD if a|
|00002880| 63 63 65 73 73 20 69 73 | 20 72 65 61 64 20 6f 72 |ccess is| read or|
|00002890| 20 72 65 61 64 77 72 69 | 74 65 0a 09 61 6e 64 20 | readwri|te..and |
|000028a0| 74 6f 20 57 52 49 54 45 | 20 69 66 20 61 63 63 65 |to WRITE| if acce|
|000028b0| 73 73 20 69 73 20 77 72 | 69 74 65 20 2a 2f 0a 09 |ss is wr|ite */..|
|000028c0| 69 66 20 28 2a 61 63 63 | 65 73 73 20 3d 3d 20 57 |if (*acc|ess == W|
|000028d0| 52 49 54 45 29 0a 09 09 | 66 69 6c 65 73 5b 66 64 |RITE)...|files[fd|
|000028e0| 5d 2e 63 61 63 63 65 73 | 73 20 3d 20 57 52 49 54 |].cacces|s = WRIT|
|000028f0| 45 3b 0a 09 65 6c 73 65 | 0a 09 09 66 69 6c 65 73 |E;..else|...files|
|00002900| 5b 66 64 5d 2e 63 61 63 | 63 65 73 73 20 3d 20 52 |[fd].cac|cess = R|
|00002910| 45 41 44 3b 0a 20 0a 20 | 20 20 20 20 20 20 20 66 |EAD;. . | f|
|00002920| 69 6c 65 73 5b 66 64 5d | 2e 63 68 72 6c 65 66 74 |iles[fd]|.chrleft|
|00002930| 20 3d 20 30 3b 0a 09 66 | 69 6c 65 73 5b 66 64 5d | = 0;..f|iles[fd]|
|00002940| 2e 62 75 66 70 20 3d 20 | 66 69 6c 65 73 5b 66 64 |.bufp = |files[fd|
|00002950| 5d 2e 62 75 66 66 65 72 | 3b 0a 09 72 65 74 75 72 |].buffer|;..retur|
|00002960| 6e 28 66 64 29 3b 0a 20 | 0a 7d 0a 20 0a 2f 2a 20 |n(fd);. |.}. ./* |
|00002970| 76 6f 69 64 20 2a 2f 0a | 70 75 74 63 5f 28 63 68 |void */.|putc_(ch|
|00002980| 29 0a 69 6e 74 20 2a 63 | 68 3b 0a 20 0a 7b 0a 09 |).int *c|h;. .{..|
|00002990| 2f 2a 20 70 75 74 20 61 | 20 63 68 61 72 61 63 74 |/* put a| charact|
|000029a0| 65 72 20 6f 75 74 20 6f | 6e 20 74 68 65 20 73 74 |er out o|n the st|
|000029b0| 61 6e 64 61 72 64 20 6f | 75 74 70 75 74 20 66 69 |andard o|utput fi|
|000029c0| 6c 65 20 73 74 64 6f 75 | 74 20 2a 2f 0a 09 69 6e |le stdou|t */..in|
|000029d0| 74 20 66 64 20 3d 20 53 | 54 44 4f 55 54 3b 0a 09 |t fd = S|TDOUT;..|
|000029e0| 70 75 74 63 68 5f 28 63 | 68 2c 20 26 66 64 29 3b |putch_(c|h, &fd);|
|000029f0| 0a 20 0a 20 0a 7d 0a 20 | 0a 20 0a 70 75 74 63 68 |. . .}. |. .putch|
|00002a00| 5f 28 63 68 2c 20 66 64 | 29 0a 69 6e 74 20 2a 63 |_(ch, fd|).int *c|
|00002a10| 68 2c 20 2a 66 64 3b 0a | 20 0a 7b 0a 20 0a 09 2f |h, *fd;.| .{. ../|
|00002a20| 2a 20 70 75 74 20 61 20 | 63 68 61 72 61 63 74 65 |* put a |characte|
|00002a30| 72 20 6f 75 74 20 74 6f | 20 61 20 73 65 71 75 65 |r out to| a seque|
|00002a40| 6e 74 69 61 6c 20 66 69 | 6c 65 20 77 69 74 68 0a |ntial fi|le with.|
|00002a50| 20 20 20 20 20 20 20 20 | 20 20 20 66 69 6c 65 20 | | file |
|00002a60| 64 65 73 63 72 69 70 74 | 6f 72 20 66 64 2e 20 4f |descript|or fd. O|
|00002a70| 75 74 70 75 74 20 69 73 | 20 62 75 66 66 65 72 65 |utput is| buffere|
|00002a80| 64 20 75 6e 74 69 6c 0a | 20 20 20 20 20 20 20 20 |d until.| |
|00002a90| 20 20 20 74 68 65 20 62 | 75 66 66 65 72 20 69 73 | the b|uffer is|
|00002aa0| 20 66 75 6c 6c 20 6f 72 | 20 74 68 65 20 70 72 6f | full or| the pro|
|00002ab0| 67 72 61 6d 20 74 65 72 | 6d 69 6e 61 74 65 73 20 |gram ter|minates |
|00002ac0| 2a 2f 0a 20 0a 09 73 74 | 72 75 63 74 20 66 64 69 |*/. ..st|ruct fdi|
|00002ad0| 6e 66 6f 20 2a 70 74 72 | 3b 0a 20 0a 09 2f 2a 20 |nfo *ptr|;. ../* |
|00002ae0| 63 68 65 63 6b 20 66 6f | 72 20 76 61 6c 69 64 20 |check fo|r valid |
|00002af0| 66 64 20 61 6e 64 20 66 | 69 6c 65 20 6f 70 65 6e |fd and f|ile open|
|00002b00| 20 69 6e 20 77 72 69 74 | 65 20 6d 6f 64 65 20 2a | in writ|e mode *|
|00002b10| 2f 0a 09 69 66 20 28 20 | 6f 70 6e 77 72 69 74 28 |/..if ( |opnwrit(|
|00002b20| 20 2a 66 64 20 29 20 3d | 3d 20 45 52 52 20 29 0a | *fd ) =|= ERR ).|
|00002b30| 09 09 72 65 74 75 72 6e | 3b 0a 20 0a 09 70 74 72 |..return|;. ..ptr|
|00002b40| 20 3d 20 26 66 69 6c 65 | 73 5b 2a 66 64 5d 3b 0a | = &file|s[*fd];.|
|00002b50| 20 0a 09 2f 2a 20 66 69 | 6c 65 20 6f 70 65 6e 20 | ../* fi|le open |
|00002b60| 69 6e 20 77 72 69 74 65 | 20 6d 6f 64 65 20 6e 6f |in write| mode no|
|00002b70| 77 20 2a 2f 0a 20 0a 09 | 69 66 20 28 70 74 72 2d |w */. ..|if (ptr-|
|00002b80| 3e 63 68 72 6c 65 66 74 | 20 3d 3d 20 4d 41 58 4c |>chrleft| == MAXL|
|00002b90| 49 4e 45 29 20 7b 0a 20 | 0a 09 2f 2a 20 62 75 66 |INE) {. |../* buf|
|00002ba0| 66 65 72 20 69 73 20 66 | 75 6c 6c 20 61 70 70 65 |fer is f|ull appe|
|00002bb0| 6e 64 20 6e 65 77 6c 69 | 6e 65 20 61 6e 64 20 66 |nd newli|ne and f|
|00002bc0| 6c 75 73 68 20 2a 2f 0a | 09 09 2a 70 74 72 2d 3e |lush */.|..*ptr->|
|00002bd0| 62 75 66 70 20 3d 20 4e | 45 57 4c 49 4e 45 3b 0a |bufp = N|EWLINE;.|
|00002be0| 09 09 70 74 72 2d 3e 63 | 68 72 6c 65 66 74 2b 2b |..ptr->c|hrleft++|
|00002bf0| 3b 0a 20 0a 09 2f 2a 20 | 64 65 6c 65 74 65 20 61 |;. ../* |delete a|
|00002c00| 6e 79 20 74 72 61 69 6c | 69 6e 67 20 73 70 61 63 |ny trail|ing spac|
|00002c10| 65 73 20 62 65 66 6f 72 | 65 20 4e 45 57 4c 49 4e |es befor|e NEWLIN|
|00002c20| 45 20 2a 2f 0a 09 09 70 | 74 72 2d 3e 63 68 72 6c |E */...p|tr->chrl|
|00002c30| 65 66 74 20 3d 20 66 6e | 64 6e 62 6c 6b 28 70 74 |eft = fn|dnblk(pt|
|00002c40| 72 2d 3e 62 75 66 70 2c | 20 70 74 72 2d 3e 63 68 |r->bufp,| ptr->ch|
|00002c50| 72 6c 65 66 74 29 3b 0a | 20 0a 09 2f 2a 20 61 6e |rleft);.| ../* an|
|00002c60| 64 20 77 72 69 74 65 20 | 6f 75 74 20 74 68 65 20 |d write |out the |
|00002c70| 62 75 66 66 65 72 20 2a | 2f 0a 09 09 77 72 69 74 |buffer *|/...writ|
|00002c80| 65 28 2a 66 64 2c 20 70 | 74 72 2d 3e 62 75 66 66 |e(*fd, p|tr->buff|
|00002c90| 65 72 2c 20 70 74 72 2d | 3e 63 68 72 6c 65 66 74 |er, ptr-|>chrleft|
|00002ca0| 29 3b 0a 09 09 70 74 72 | 2d 3e 63 68 72 6c 65 66 |);...ptr|->chrlef|
|00002cb0| 74 20 3d 20 30 3b 0a 09 | 09 70 74 72 2d 3e 62 75 |t = 0;..|.ptr->bu|
|00002cc0| 66 70 20 3d 20 70 74 72 | 2d 3e 62 75 66 66 65 72 |fp = ptr|->buffer|
|00002cd0| 3b 0a 09 09 2f 2a 20 69 | 66 20 63 75 72 72 65 6e |;.../* i|f curren|
|00002ce0| 74 20 63 68 61 72 61 63 | 74 65 72 20 61 20 4e 45 |t charac|ter a NE|
|00002cf0| 57 4c 49 4e 45 20 74 68 | 65 6e 20 72 65 74 75 72 |WLINE th|en retur|
|00002d00| 6e 20 61 73 20 69 74 0a | 09 09 20 20 20 68 61 73 |n as it.|.. has|
|00002d10| 20 61 6c 72 65 61 64 79 | 20 62 65 65 6e 20 6f 75 | already| been ou|
|00002d20| 74 70 75 74 20 2a 2f 0a | 09 09 69 66 20 28 2a 63 |tput */.|..if (*c|
|00002d30| 68 20 3d 3d 20 4e 45 57 | 4c 49 4e 45 29 20 72 65 |h == NEW|LINE) re|
|00002d40| 74 75 72 6e 3b 0a 09 7d | 0a 20 0a 09 2f 2a 20 73 |turn;..}|. ../* s|
|00002d50| 74 6f 72 65 20 63 68 61 | 72 61 63 74 65 72 20 69 |tore cha|racter i|
|00002d60| 6e 20 62 75 66 66 65 72 | 20 2a 2f 0a 09 2a 70 74 |n buffer| */..*pt|
|00002d70| 72 20 2d 3e 20 62 75 66 | 70 20 2b 2b 20 3d 20 2a |r -> buf|p ++ = *|
|00002d80| 63 68 3b 0a 09 70 74 72 | 2d 3e 63 68 72 6c 65 66 |ch;..ptr|->chrlef|
|00002d90| 74 20 2b 2b 3b 0a 20 0a | 20 20 20 20 20 2f 2a 09 |t ++;. .| /*.|
|00002da0| 66 6c 75 73 68 20 62 75 | 66 66 65 72 73 20 6f 6e |flush bu|ffers on|
|00002db0| 20 61 20 6e 65 77 6c 69 | 6e 65 20 2a 2f 0a 09 69 | a newli|ne */..i|
|00002dc0| 66 20 28 2a 63 68 20 3d | 3d 20 4e 45 57 4c 49 4e |f (*ch =|= NEWLIN|
|00002dd0| 45 29 20 7b 0a 09 2f 2a | 20 64 65 6c 65 74 65 20 |E) {../*| delete |
|00002de0| 61 6e 79 20 74 72 61 69 | 6c 69 6e 67 20 73 70 61 |any trai|ling spa|
|00002df0| 63 65 73 20 62 65 66 6f | 72 65 20 4e 45 57 4c 49 |ces befo|re NEWLI|
|00002e00| 4e 45 20 2a 2f 0a 09 09 | 70 74 72 2d 3e 62 75 66 |NE */...|ptr->buf|
|00002e10| 70 2d 2d 3b 0a 09 09 70 | 74 72 2d 3e 63 68 72 6c |p--;...p|tr->chrl|
|00002e20| 65 66 74 20 3d 20 66 6e | 64 6e 62 6c 6b 28 70 74 |eft = fn|dnblk(pt|
|00002e30| 72 2d 3e 62 75 66 70 2c | 20 70 74 72 2d 3e 63 68 |r->bufp,| ptr->ch|
|00002e40| 72 6c 65 66 74 29 3b 0a | 09 09 77 72 69 74 65 28 |rleft);.|..write(|
|00002e50| 2a 66 64 2c 20 70 74 72 | 2d 3e 62 75 66 66 65 72 |*fd, ptr|->buffer|
|00002e60| 2c 20 70 74 72 20 2d 3e | 20 63 68 72 6c 65 66 74 |, ptr ->| chrleft|
|00002e70| 29 3b 0a 09 09 70 74 72 | 2d 3e 63 68 72 6c 65 66 |);...ptr|->chrlef|
|00002e80| 74 20 3d 20 30 3b 0a 09 | 09 70 74 72 2d 3e 62 75 |t = 0;..|.ptr->bu|
|00002e90| 66 70 20 3d 20 70 74 72 | 2d 3e 62 75 66 66 65 72 |fp = ptr|->buffer|
|00002ea0| 3b 0a 20 0a 09 7d 0a 7d | 0a 20 0a 20 0a 70 75 74 |;. ..}.}|. . .put|
|00002eb0| 64 65 63 5f 28 20 76 61 | 6c 75 65 2c 20 77 69 64 |dec_( va|lue, wid|
|00002ec0| 74 68 29 0a 69 6e 74 20 | 2a 76 61 6c 75 65 2c 20 |th).int |*value, |
|00002ed0| 2a 77 69 64 74 68 3b 0a | 20 0a 7b 0a 09 2f 2a 20 |*width;.| .{../* |
|00002ee0| 77 72 69 74 65 20 74 68 | 65 20 6e 75 6d 62 65 72 |write th|e number|
|00002ef0| 20 76 61 6c 75 65 20 6f | 75 74 20 74 6f 20 73 74 | value o|ut to st|
|00002f00| 64 6f 75 74 20 69 6e 20 | 61 20 66 69 65 6c 64 20 |dout in |a field |
|00002f10| 6f 66 20 77 69 64 74 68 | 0a 09 20 20 20 77 69 64 |of width|.. wid|
|00002f20| 74 68 2e 20 49 66 20 74 | 68 65 20 6c 65 6e 67 74 |th. If t|he lengt|
|00002f30| 68 20 6f 66 20 74 68 65 | 20 6e 75 6d 62 65 72 20 |h of the| number |
|00002f40| 61 73 20 61 20 73 74 72 | 69 6e 67 20 69 73 20 3c |as a str|ing is <|
|00002f50| 3d 0a 09 20 20 20 77 69 | 64 74 68 20 69 74 20 69 |=.. wi|dth it i|
|00002f60| 73 20 62 6c 61 6e 6b 20 | 66 69 6c 6c 65 64 20 72 |s blank |filled r|
|00002f70| 69 67 68 74 20 6a 75 73 | 74 69 66 69 65 64 2c 20 |ight jus|tified, |
|00002f80| 65 6c 73 65 20 74 68 65 | 20 6e 75 6d 62 65 72 0a |else the| number.|
|00002f90| 09 20 20 20 69 73 20 6f | 75 74 70 75 74 20 69 6e |. is o|utput in|
|00002fa0| 20 61 20 77 69 64 65 72 | 20 66 69 65 6c 64 20 2a | a wider| field *|
|00002fb0| 2f 0a 20 0a 09 69 6e 74 | 20 66 64 20 3d 20 53 54 |/. ..int| fd = ST|
|00002fc0| 44 4f 55 54 3b 0a 20 0a | 09 7a 70 74 69 6e 74 5f |DOUT;. .|.zptint_|
|00002fd0| 28 76 61 6c 75 65 2c 20 | 77 69 64 74 68 2c 20 26 |(value, |width, &|
|00002fe0| 66 64 29 3b 0a 20 0a 7d | 0a 20 0a 70 75 74 6c 69 |fd);. .}|. .putli|
|00002ff0| 6e 5f 28 62 75 66 66 65 | 72 2c 20 66 64 29 0a 69 |n_(buffe|r, fd).i|
|00003000| 6e 74 20 2a 62 75 66 66 | 65 72 2c 20 2a 66 64 3b |nt *buff|er, *fd;|
|00003010| 0a 20 0a 7b 0a 09 2f 2a | 20 6f 75 74 70 75 74 20 |. .{../*| output |
|00003020| 74 68 65 20 73 74 72 69 | 6e 67 20 69 6e 20 62 75 |the stri|ng in bu|
|00003030| 66 66 65 72 20 28 74 65 | 72 6d 69 6e 61 74 65 64 |ffer (te|rminated|
|00003040| 20 62 79 20 65 6f 73 29 | 20 74 6f 0a 09 20 20 20 | by eos)| to.. |
|00003050| 74 68 65 20 66 69 6c 65 | 20 61 73 73 6f 63 69 61 |the file| associa|
|00003060| 74 65 64 20 77 69 74 68 | 20 74 68 65 20 66 69 6c |ted with| the fil|
|00003070| 65 20 64 65 73 63 72 69 | 70 74 6f 72 20 66 64 20 |e descri|ptor fd |
|00003080| 2a 2f 0a 20 0a 09 69 6e | 74 20 63 3b 0a 20 0a 09 |*/. ..in|t c;. ..|
|00003090| 77 68 69 6c 65 20 28 28 | 63 20 3d 20 2a 62 75 66 |while ((|c = *buf|
|000030a0| 66 65 72 2b 2b 29 20 21 | 3d 20 45 4f 53 29 0a 09 |fer++) !|= EOS)..|
|000030b0| 09 70 75 74 63 68 5f 28 | 26 63 2c 20 66 64 29 3b |.putch_(|&c, fd);|
|000030c0| 0a 20 0a 7d 0a 20 0a 20 | 0a 72 65 61 64 66 5f 28 |. .}. . |.readf_(|
|000030d0| 20 62 75 66 2c 20 63 6f | 75 6e 74 2c 20 66 64 29 | buf, co|unt, fd)|
|000030e0| 0a 69 6e 74 20 2a 62 75 | 66 2c 20 2a 63 6f 75 6e |.int *bu|f, *coun|
|000030f0| 74 2c 20 2a 66 64 3b 0a | 20 0a 7b 0a 09 2f 2a 20 |t, *fd;.| .{../* |
|00003100| 72 65 61 64 20 63 6f 75 | 6e 74 20 63 68 61 72 61 |read cou|nt chara|
|00003110| 63 74 65 72 73 20 66 72 | 6f 6d 20 74 68 65 20 66 |cters fr|om the f|
|00003120| 69 6c 65 20 77 69 74 68 | 20 61 73 73 6f 63 69 61 |ile with| associa|
|00003130| 74 65 64 0a 09 20 20 20 | 66 69 6c 65 20 64 65 73 |ted.. |file des|
|00003140| 63 72 69 70 74 6f 72 20 | 66 64 20 69 6e 74 6f 20 |criptor |fd into |
|00003150| 62 75 66 20 61 6e 64 20 | 74 65 72 6d 69 6e 61 74 |buf and |terminat|
|00003160| 65 20 77 69 74 68 20 61 | 6e 0a 09 20 20 20 45 4f |e with a|n.. EO|
|00003170| 53 20 63 68 61 72 61 63 | 74 65 72 2e 20 54 68 69 |S charac|ter. Thi|
|00003180| 73 20 72 6f 75 74 69 6e | 65 20 68 61 73 20 6e 6f |s routin|e has no|
|00003190| 20 77 61 79 20 6f 66 20 | 69 6e 64 69 63 61 74 69 | way of |indicati|
|000031a0| 6e 67 0a 09 20 20 20 61 | 20 72 65 61 64 20 70 61 |ng.. a| read pa|
|000031b0| 73 74 20 65 6e 64 20 6f | 66 20 66 69 6c 65 2e 0a |st end o|f file..|
|000031c0| 20 0a 09 20 20 20 57 41 | 52 4e 49 4e 47 3a 20 75 | .. WA|RNING: u|
|000031d0| 73 65 20 47 45 54 4c 49 | 4e 20 6f 72 20 5a 47 54 |se GETLI|N or ZGT|
|000031e0| 43 4d 44 20 69 6e 20 70 | 72 65 66 65 72 65 6e 63 |CMD in p|referenc|
|000031f0| 65 20 2a 2f 0a 20 0a 09 | 69 6e 74 20 69 2c 20 63 |e */. ..|int i, c|
|00003200| 3b 0a 20 0a 09 66 6f 72 | 20 28 69 20 3d 20 31 3b |;. ..for| (i = 1;|
|00003210| 20 69 20 3c 3d 20 2a 63 | 6f 75 6e 74 20 26 26 20 | i <= *c|ount && |
|00003220| 28 2a 62 75 66 2b 2b 20 | 3d 20 67 65 74 63 68 5f |(*buf++ |= getch_|
|00003230| 28 26 63 2c 20 66 64 29 | 29 20 21 3d 20 45 4f 46 |(&c, fd)|) != EOF|
|00003240| 3b 20 69 2b 2b 29 3b 0a | 20 0a 09 69 66 20 28 63 |; i++);.| ..if (c|
|00003250| 20 3d 3d 20 45 4f 46 20 | 29 0a 09 09 62 75 66 2d | == EOF |)...buf-|
|00003260| 2d 3b 0a 20 0a 09 2a 62 | 75 66 20 3d 20 45 4f 53 |-;. ..*b|uf = EOS|
|00003270| 3b 0a 20 0a 7d 0a 20 0a | 72 65 6d 61 72 6b 5f 28 |;. .}. .|remark_(|
|00003280| 73 2c 20 6c 65 6e 67 74 | 68 29 0a 63 68 61 72 20 |s, lengt|h).char |
|00003290| 2a 73 3b 0a 6c 6f 6e 67 | 20 69 6e 74 20 6c 65 6e |*s;.long| int len|
|000032a0| 67 74 68 3b 0a 20 0a 7b | 0a 09 2f 2a 20 6f 75 74 |gth;. .{|../* out|
|000032b0| 70 75 74 20 61 6e 20 66 | 37 37 20 73 74 72 69 6e |put an f|77 strin|
|000032c0| 67 20 75 70 20 74 6f 20 | 62 75 74 20 6e 6f 74 20 |g up to |but not |
|000032d0| 69 6e 63 6c 75 64 69 6e | 67 20 61 20 74 65 72 6d |includin|g a term|
|000032e0| 69 6e 61 74 69 6e 67 0a | 09 20 20 20 50 45 52 49 |inating.|. PERI|
|000032f0| 4f 44 20 74 6f 20 53 54 | 44 45 52 52 2e 20 49 66 |OD to ST|DERR. If|
|00003300| 20 6e 6f 20 74 65 72 6d | 69 6e 61 74 69 6e 67 20 | no term|inating |
|00003310| 70 65 72 69 6f 64 20 61 | 6c 6c 20 6c 65 6e 67 74 |period a|ll lengt|
|00003320| 68 0a 09 20 20 20 63 68 | 61 72 61 63 74 65 72 73 |h.. ch|aracters|
|00003330| 20 61 72 65 20 6f 75 74 | 70 75 74 2e 20 41 20 70 | are out|put. A p|
|00003340| 65 72 69 6f 64 20 77 69 | 74 68 69 6e 20 61 20 73 |eriod wi|thin a s|
|00003350| 74 72 69 6e 67 20 69 73 | 20 64 65 6e 6f 74 65 64 |tring is| denoted|
|00003360| 0a 09 20 20 20 62 79 20 | 27 2e 2e 27 20 2a 2f 0a |.. by |'..' */.|
|00003370| 20 0a 09 69 6e 74 20 66 | 64 20 3d 20 53 54 44 45 | ..int f|d = STDE|
|00003380| 52 52 2c 20 6e 65 77 6c | 69 6e 65 20 3d 20 4e 45 |RR, newl|ine = NE|
|00003390| 57 4c 49 4e 45 3b 0a 09 | 73 74 72 75 63 74 20 66 |WLINE;..|struct f|
|000033a0| 64 69 6e 66 6f 20 2a 70 | 74 72 3b 0a 20 0a 09 2f |dinfo *p|tr;. ../|
|000033b0| 2a 20 6d 61 6b 65 20 73 | 75 72 65 20 74 68 61 74 |* make s|ure that|
|000033c0| 20 53 54 44 45 52 52 20 | 69 73 20 4f 4b 20 74 6f | STDERR |is OK to|
|000033d0| 20 77 72 69 74 65 20 74 | 6f 2e 20 54 68 69 73 20 | write t|o. This |
|000033e0| 69 73 20 64 6f 6e 65 20 | 69 6e 0a 09 70 75 74 63 |is done |in..putc|
|000033f0| 68 20 62 75 74 20 69 66 | 20 74 68 69 6e 67 73 20 |h but if| things |
|00003400| 67 65 74 20 73 63 72 65 | 77 65 64 20 74 68 65 72 |get scre|wed ther|
|00003410| 65 20 69 73 20 74 68 65 | 20 70 6f 73 73 69 62 69 |e is the| possibi|
|00003420| 6c 69 74 79 20 6f 66 0a | 09 61 6e 20 65 6e 64 6c |lity of.|.an endl|
|00003430| 65 73 73 20 63 61 6c 6c | 20 70 75 74 63 68 20 6c |ess call| putch l|
|00003440| 6f 6f 70 20 2d 20 74 68 | 65 20 6e 65 78 74 20 73 |oop - th|e next s|
|00003450| 74 61 74 65 6d 65 6e 74 | 20 69 73 20 61 20 70 61 |tatement| is a pa|
|00003460| 6e 69 63 0a 09 65 78 69 | 74 20 2a 2f 0a 09 70 74 |nic..exi|t */..pt|
|00003470| 72 20 3d 20 26 66 69 6c | 65 73 5b 53 54 44 45 52 |r = &fil|es[STDER|
|00003480| 52 5d 3b 0a 09 0a 09 69 | 66 20 28 70 74 72 2d 3e |R];....i|f (ptr->|
|00003490| 61 63 63 65 73 73 20 3d | 3d 20 4e 4f 54 4f 50 45 |access =|= NOTOPE|
|000034a0| 4e 20 7c 7c 20 70 74 72 | 2d 3e 61 63 63 65 73 73 |N || ptr|->access|
|000034b0| 20 3d 3d 20 52 45 41 44 | 29 20 65 78 69 74 28 31 | == READ|) exit(1|
|000034c0| 29 3b 0a 20 0a 09 2f 2a | 20 69 66 20 74 68 65 20 |);. ../*| if the |
|000034d0| 61 62 6f 76 65 20 63 68 | 65 63 6b 73 20 61 72 65 |above ch|ecks are|
|000034e0| 20 4f 4b 20 74 68 65 20 | 66 6f 6c 6c 6f 77 69 6e | OK the |followin|
|000034f0| 67 20 70 75 74 63 68 27 | 73 20 73 68 6f 75 6c 64 |g putch'|s should|
|00003500| 20 62 65 0a 09 6f 6b 20 | 69 2e 65 2e 20 74 68 65 | be..ok |i.e. the|
|00003510| 79 20 77 6f 6e 27 74 20 | 72 65 73 75 6c 74 20 69 |y won't |result i|
|00003520| 6e 20 61 6e 6f 74 68 65 | 72 20 63 61 6c 6c 20 74 |n anothe|r call t|
|00003530| 6f 20 72 65 6d 61 72 6b | 20 2a 2f 0a 20 0a 09 7a |o remark| */. ..z|
|00003540| 63 68 6f 75 74 5f 28 73 | 2c 20 26 66 64 2c 20 6c |chout_(s|, &fd, l|
|00003550| 65 6e 67 74 68 29 3b 0a | 09 70 75 74 63 68 5f 28 |ength);.|.putch_(|
|00003560| 20 26 6e 65 77 6c 69 6e | 65 2c 20 26 66 64 29 3b | &newlin|e, &fd);|
|00003570| 0a 20 0a 7d 0a 20 0a 72 | 65 6d 6f 76 65 5f 28 6e |. .}. .r|emove_(n|
|00003580| 61 6d 65 29 0a 69 6e 74 | 20 2a 6e 61 6d 65 3b 0a |ame).int| *name;.|
|00003590| 7b 0a 20 0a 20 20 20 20 | 20 2f 2a 20 64 65 6c 65 |{. . | /* dele|
|000035a0| 74 65 20 74 68 65 20 63 | 6c 6f 73 65 64 20 66 69 |te the c|losed fi|
|000035b0| 6c 65 20 6e 61 6d 65 20 | 66 72 6f 6d 20 74 68 65 |le name |from the|
|000035c0| 20 64 69 72 65 63 74 6f | 72 79 2e 20 54 68 69 73 | directo|ry. This|
|000035d0| 20 72 6f 75 74 69 6e 65 | 0a 09 6d 61 79 20 62 65 | routine|..may be|
|000035e0| 20 75 73 65 64 20 74 6f | 20 72 65 6d 6f 76 65 20 | used to| remove |
|000035f0| 65 69 74 68 65 72 20 61 | 20 73 65 71 75 65 6e 74 |either a| sequent|
|00003600| 69 61 6c 20 6f 72 20 61 | 20 64 69 72 65 63 74 20 |ial or a| direct |
|00003610| 61 63 63 65 73 73 0a 09 | 66 69 6c 65 20 2a 2f 0a |access..|file */.|
|00003620| 20 0a 09 69 6e 74 20 66 | 64 3b 0a 09 63 68 61 72 | ..int f|d;..char|
|00003630| 20 63 68 61 72 6e 6d 31 | 5b 4d 41 58 50 41 54 48 | charnm1|[MAXPATH|
|00003640| 5d 3b 0a 09 73 74 72 75 | 63 74 20 66 64 69 6e 66 |];..stru|ct fdinf|
|00003650| 6f 20 2a 70 74 72 3b 0a | 09 73 74 72 75 63 74 20 |o *ptr;.|.struct |
|00003660| 66 69 6c 69 6e 66 6f 20 | 6f 70 65 6e 69 6e 66 3b |filinfo |openinf;|
|00003670| 0a 20 0a 09 6d 6b 66 69 | 6c 6e 6d 28 6e 61 6d 65 |. ..mkfi|lnm(name|
|00003680| 2c 20 63 68 61 72 6e 6d | 31 2c 20 26 6f 70 65 6e |, charnm|1, &open|
|00003690| 69 6e 66 29 3b 0a 20 0a | 09 2f 2a 20 63 61 6e 27 |inf);. .|./* can'|
|000036a0| 74 20 72 65 6d 6f 76 65 | 20 64 65 76 69 63 65 20 |t remove| device |
|000036b0| 66 69 6c 65 20 61 6e 64 | 20 72 65 74 75 72 6e 20 |file and| return |
|000036c0| 6f 6e 20 66 69 6c 65 6e | 61 6d 65 20 65 72 72 6f |on filen|ame erro|
|000036d0| 72 20 2a 2f 0a 09 73 77 | 69 74 63 68 20 28 6f 70 |r */..sw|itch (op|
|000036e0| 65 6e 69 6e 66 2e 66 74 | 79 70 65 31 29 0a 09 7b |eninf.ft|ype1)..{|
|000036f0| 0a 09 20 20 63 61 73 65 | 20 45 52 52 3a 0a 09 09 |.. case| ERR:...|
|00003700| 72 65 74 75 72 6e 3b 0a | 20 0a 09 20 20 63 61 73 |return;.| .. cas|
|00003710| 65 20 44 45 56 49 43 45 | 3a 0a 09 09 72 65 74 75 |e DEVICE|:...retu|
|00003720| 72 6e 3b 0a 20 0a 09 20 | 20 63 61 73 65 20 56 46 |rn;. .. | case VF|
|00003730| 53 20 3a 0a 09 09 69 66 | 20 28 6f 70 65 6e 69 6e |S :...if| (openin|
|00003740| 66 2e 73 75 62 74 79 70 | 65 20 3d 3d 20 44 49 52 |f.subtyp|e == DIR|
|00003750| 45 43 54 4f 52 59 29 20 | 72 65 74 75 72 6e 3b 0a |ECTORY) |return;.|
|00003760| 09 09 62 72 65 61 6b 3b | 0a 20 0a 09 7d 0a 09 2f |..break;|. ..}../|
|00003770| 2a 20 69 66 20 69 74 20 | 64 6f 65 73 6e 27 74 20 |* if it |doesn't |
|00003780| 65 78 69 73 74 20 74 68 | 65 72 65 27 73 20 6e 6f |exist th|ere's no|
|00003790| 20 6e 65 65 64 20 74 6f | 20 64 65 6c 65 74 65 20 | need to| delete |
|000037a0| 69 74 20 2a 2f 0a 09 69 | 66 20 28 6f 70 65 6e 69 |it */..i|f (openi|
|000037b0| 6e 66 2e 65 78 69 73 74 | 73 20 21 3d 20 59 45 53 |nf.exist|s != YES|
|000037c0| 29 20 72 65 74 75 72 6e | 3b 0a 20 0a 09 2f 2a 20 |) return|;. ../* |
|000037d0| 63 6c 6f 73 65 20 74 68 | 65 20 66 69 6c 65 20 69 |close th|e file i|
|000037e0| 66 20 69 74 20 69 73 20 | 6f 70 65 6e 20 2a 2f 0a |f it is |open */.|
|000037f0| 09 66 6f 72 20 28 66 64 | 20 3d 20 46 49 52 53 54 |.for (fd| = FIRST|
|00003800| 46 44 3b 20 66 64 20 3c | 20 4d 41 58 46 49 4c 45 |FD; fd <| MAXFILE|
|00003810| 3b 20 66 64 2b 2b 29 0a | 09 7b 09 70 74 72 20 3d |; fd++).|.{.ptr =|
|00003820| 20 26 66 69 6c 65 73 5b | 66 64 5d 3b 0a 09 09 69 | &files[|fd];...i|
|00003830| 66 20 28 70 74 72 2d 3e | 61 63 63 65 73 73 20 21 |f (ptr->|access !|
|00003840| 3d 20 4e 4f 54 4f 50 45 | 4e 20 26 26 20 73 74 72 |= NOTOPE|N && str|
|00003850| 63 6d 70 28 20 70 74 72 | 20 2d 3e 20 66 69 6c 65 |cmp( ptr| -> file|
|00003860| 6e 61 6d 2c 20 63 68 61 | 72 6e 6d 31 29 20 3d 3d |nam, cha|rnm1) ==|
|00003870| 20 30 29 0a 09 09 09 63 | 6c 6f 73 65 5f 28 26 66 | 0)....c|lose_(&f|
|00003880| 64 29 3b 0a 09 7d 0a 09 | 0a 09 2f 2a 20 72 65 6d |d);..}..|../* rem|
|00003890| 6f 76 65 20 74 68 65 20 | 66 69 6c 65 20 2a 2f 0a |ove the |file */.|
|000038a0| 09 75 6e 6c 69 6e 6b 28 | 63 68 61 72 6e 6d 31 29 |.unlink(|charnm1)|
|000038b0| 3b 0a 09 72 65 74 75 72 | 6e 3b 0a 20 0a 7d 0a 20 |;..retur|n;. .}. |
|000038c0| 0a 73 65 65 6b 5f 28 70 | 6f 73 2c 20 66 64 29 0a |.seek_(p|os, fd).|
|000038d0| 69 6e 74 20 2a 70 6f 73 | 2c 20 2a 66 64 3b 0a 7b |int *pos|, *fd;.{|
|000038e0| 0a 09 2f 2a 20 64 65 73 | 70 69 74 65 20 77 68 61 |../* des|pite wha|
|000038f0| 74 20 74 68 65 20 64 6f | 63 75 6d 65 6e 74 61 74 |t the do|cumentat|
|00003900| 69 6f 6e 20 73 61 79 73 | 20 74 68 69 73 20 72 6f |ion says| this ro|
|00003910| 75 74 69 6e 65 0a 09 20 | 20 20 65 66 66 65 63 74 |utine.. | effect|
|00003920| 73 20 61 20 72 65 77 69 | 6e 64 20 6f 6e 20 63 68 |s a rewi|nd on ch|
|00003930| 61 6e 6e 65 6c 20 66 64 | 2e 0a 09 20 20 20 49 74 |annel fd|... It|
|00003940| 20 68 61 73 20 6e 6f 20 | 65 66 66 65 63 74 20 6f | has no |effect o|
|00003950| 6e 20 70 72 65 63 6f 6e | 6e 65 63 74 65 64 20 66 |n precon|nected f|
|00003960| 69 6c 65 73 20 2a 2f 0a | 20 0a 20 20 20 20 20 20 |iles */.| . |
|00003970| 20 20 73 74 72 75 63 74 | 20 66 64 69 6e 66 6f 20 | struct| fdinfo |
|00003980| 2a 70 74 72 3b 0a 20 0a | 20 20 20 20 20 20 20 20 |*ptr;. .| |
|00003990| 70 74 72 20 3d 20 26 66 | 69 6c 65 73 5b 2a 66 64 |ptr = &f|iles[*fd|
|000039a0| 5d 3b 0a 20 0a 09 69 66 | 20 28 63 68 65 63 6b 66 |];. ..if| (checkf|
|000039b0| 64 28 2a 66 64 29 20 21 | 3d 20 46 49 4c 45 53 20 |d(*fd) !|= FILES |
|000039c0| 7c 7c 20 66 69 6c 65 73 | 5b 2a 66 64 5d 2e 61 63 ||| files|[*fd].ac|
|000039d0| 63 65 73 73 20 3d 3d 20 | 4e 4f 54 4f 50 45 4e 29 |cess == |NOTOPEN)|
|000039e0| 0a 09 20 20 20 09 72 65 | 74 75 72 6e 3b 0a 20 0a |.. .re|turn;. .|
|000039f0| 09 2f 2a 20 6d 6f 76 65 | 20 74 68 65 20 66 69 6c |./* move| the fil|
|00003a00| 65 20 70 6f 69 6e 74 65 | 72 20 62 61 63 6b 20 74 |e pointe|r back t|
|00003a10| 6f 20 74 68 65 20 62 65 | 67 69 6e 69 6e 67 20 6f |o the be|gining o|
|00003a20| 66 20 74 68 65 20 66 69 | 6c 65 20 2a 2f 0a 20 20 |f the fi|le */. |
|00003a30| 20 20 20 20 20 20 70 74 | 72 20 2d 3e 20 63 68 72 | pt|r -> chr|
|00003a40| 6c 65 66 74 20 3d 20 30 | 3b 0a 20 20 20 20 20 20 |left = 0|;. |
|00003a50| 20 20 70 74 72 20 2d 3e | 20 63 6f 75 6e 74 20 3d | ptr ->| count =|
|00003a60| 20 30 3b 0a 20 20 20 20 | 20 20 20 20 70 74 72 20 | 0;. | ptr |
|00003a70| 2d 3e 20 62 75 66 70 20 | 3d 20 70 74 72 20 2d 3e |-> bufp |= ptr ->|
|00003a80| 62 75 66 66 65 72 3b 0a | 09 6c 73 65 65 6b 28 2a |buffer;.|.lseek(*|
|00003a90| 66 64 2c 28 6c 6f 6e 67 | 29 28 2a 70 6f 73 29 2c |fd,(long|)(*pos),|
|00003aa0| 30 29 3b 0a 20 0a 20 0a | 7d 0a 20 0a 73 6b 69 70 |0);. . .|}. .skip|
|00003ab0| 5f 28 6c 69 6e 65 73 29 | 0a 69 6e 74 20 2a 6c 69 |_(lines)|.int *li|
|00003ac0| 6e 65 73 3b 0a 20 0a 7b | 0a 09 2f 2a 20 6f 75 74 |nes;. .{|../* out|
|00003ad0| 70 75 74 20 6c 69 6e 65 | 73 20 62 6c 61 6e 6b 20 |put line|s blank |
|00003ae0| 6c 69 6e 65 73 20 74 6f | 20 73 74 64 6f 75 74 20 |lines to| stdout |
|00003af0| 2a 2f 0a 20 0a 09 69 6e | 74 20 69 2c 20 6e 65 77 |*/. ..in|t i, new|
|00003b00| 6c 69 6e 65 20 3d 20 4e | 45 57 4c 49 4e 45 2c 20 |line = N|EWLINE, |
|00003b10| 66 64 20 3d 20 53 54 44 | 4f 55 54 3b 0a 20 0a 09 |fd = STD|OUT;. ..|
|00003b20| 66 6f 72 28 69 20 3d 20 | 31 3b 20 69 20 3c 3d 20 |for(i = |1; i <= |
|00003b30| 2a 6c 69 6e 65 73 3b 20 | 69 2b 2b 29 0a 09 20 20 |*lines; |i++).. |
|00003b40| 09 70 75 74 63 68 5f 28 | 20 26 6e 65 77 6c 69 6e |.putch_(| &newlin|
|00003b50| 65 2c 20 26 66 64 29 3b | 0a 20 0a 7d 0a 20 0a 7a |e, &fd);|. .}. .z|
|00003b60| 62 63 72 65 74 5f 28 6e | 61 6d 65 2c 20 6d 61 78 |bcret_(n|ame, max|
|00003b70| 72 65 63 29 0a 69 6e 74 | 20 2a 6e 61 6d 65 2c 20 |rec).int| *name, |
|00003b80| 2a 6d 61 78 72 65 63 3b | 0a 7b 0a 20 0a 20 20 20 |*maxrec;|.{. . |
|00003b90| 20 20 2f 2a 20 63 72 65 | 61 74 65 20 61 20 64 69 | /* cre|ate a di|
|00003ba0| 72 65 63 74 20 61 63 63 | 65 73 73 20 66 69 6c 65 |rect acc|ess file|
|00003bb0| 20 77 69 74 68 20 61 20 | 6d 61 78 69 6d 75 6d 20 | with a |maximum |
|00003bc0| 6f 66 20 4d 41 58 52 45 | 43 20 72 65 63 6f 72 64 |of MAXRE|C record|
|00003bd0| 73 0a 09 54 68 65 20 66 | 69 6c 65 20 69 73 20 74 |s..The f|ile is t|
|00003be0| 6f 20 63 6f 6e 74 61 69 | 6e 20 66 69 78 65 64 20 |o contai|n fixed |
|00003bf0| 6c 65 6e 67 74 68 20 72 | 65 63 6f 72 64 73 20 6f |length r|ecords o|
|00003c00| 66 20 6c 65 6e 67 74 68 | 20 4d 41 58 42 55 46 46 |f length| MAXBUFF|
|00003c10| 2e 0a 09 41 6e 79 20 65 | 78 69 73 74 69 6e 67 20 |...Any e|xisting |
|00003c20| 66 69 6c 65 2c 20 6e 61 | 6d 65 2c 20 69 73 20 64 |file, na|me, is d|
|00003c30| 65 6c 65 74 65 64 20 28 | 74 72 75 6e 63 61 74 65 |eleted (|truncate|
|00003c40| 64 20 74 6f 20 6c 65 6e | 67 74 68 20 7a 65 72 6f |d to len|gth zero|
|00003c50| 29 2e 0a 09 0a 09 54 68 | 65 20 66 69 72 73 74 20 |).....Th|e first |
|00003c60| 72 65 63 6f 72 64 20 69 | 6e 20 74 68 65 20 66 69 |record i|n the fi|
|00003c70| 6c 65 20 69 73 20 74 6f | 20 63 6f 6e 74 61 69 6e |le is to| contain|
|00003c80| 20 74 68 65 20 6d 61 78 | 69 6d 75 6d 20 72 65 63 | the max|imum rec|
|00003c90| 6f 72 64 0a 09 6e 75 6d | 62 65 72 2e 0a 09 0a 09 |ord..num|ber.....|
|00003ca0| 54 68 65 20 66 69 6c 65 | 20 64 65 73 63 72 69 70 |The file| descrip|
|00003cb0| 74 6f 72 20 69 73 20 72 | 65 74 75 72 6e 65 64 20 |tor is r|eturned |
|00003cc0| 6f 72 20 45 52 52 20 69 | 66 20 63 72 65 61 74 65 |or ERR i|f create|
|00003cd0| 20 66 61 69 6c 73 2e 20 | 2a 2f 0a 20 0a 20 20 20 | fails. |*/. . |
|00003ce0| 20 20 20 20 20 69 6e 74 | 20 75 69 64 2c 67 69 64 | int| uid,gid|
|00003cf0| 2c 6c 65 6e 2c 69 3b 0a | 20 20 20 20 20 20 20 20 |,len,i;.| |
|00003d00| 63 68 61 72 20 6e 65 77 | 63 68 5b 4d 41 58 50 41 |char new|ch[MAXPA|
|00003d10| 54 48 5d 3b 0a 20 20 20 | 20 20 20 20 20 73 74 72 |TH];. | str|
|00003d20| 75 63 74 20 73 74 61 74 | 20 73 62 75 66 3b 0a 20 |uct stat| sbuf;. |
|00003d30| 0a 20 0a 09 73 74 72 75 | 63 74 20 66 64 69 6e 66 |. ..stru|ct fdinf|
|00003d40| 6f 20 2a 70 74 72 3b 0a | 09 73 74 72 75 63 74 20 |o *ptr;.|.struct |
|00003d50| 66 69 6c 69 6e 66 6f 20 | 6f 70 65 6e 69 6e 66 3b |filinfo |openinf;|
|00003d60| 0a 09 63 68 61 72 20 63 | 68 61 72 6e 6d 31 5b 4d |..char c|harnm1[M|
|00003d70| 41 58 50 41 54 48 5d 3b | 0a 09 69 6e 74 20 66 64 |AXPATH];|..int fd|
|00003d80| 2c 20 6a 75 6e 6b 2c 20 | 69 73 74 73 74 72 5b 4d |, junk, |iststr[M|
|00003d90| 41 58 42 55 46 46 5d 3b | 0a 09 69 6e 74 20 61 63 |AXBUFF];|..int ac|
|00003da0| 63 65 73 73 20 3d 20 52 | 45 41 44 57 52 49 54 45 |cess = R|EADWRITE|
|00003db0| 3b 0a 20 0a 20 20 20 20 | 20 2f 2a 09 67 65 6e 65 |;. . | /*.gene|
|00003dc0| 72 61 74 65 20 66 75 6c | 6c 20 70 61 74 68 20 6e |rate ful|l path n|
|00003dd0| 61 6d 65 20 61 73 20 61 | 20 63 68 61 72 61 63 74 |ame as a| charact|
|00003de0| 65 72 20 73 74 72 69 6e | 67 20 2a 2f 0a 20 20 20 |er strin|g */. |
|00003df0| 20 09 6d 6b 66 69 6c 6e | 6d 28 6e 61 6d 65 2c 20 | .mkfiln|m(name, |
|00003e00| 63 68 61 72 6e 6d 31 2c | 20 26 6f 70 65 6e 69 6e |charnm1,| &openin|
|00003e10| 66 29 3b 0a 20 0a 20 20 | 20 20 20 2f 2a 09 73 6f |f);. . | /*.so|
|00003e20| 72 74 20 6f 75 74 20 70 | 6f 73 73 69 62 6c 65 20 |rt out p|ossible |
|00003e30| 65 72 72 6f 72 20 63 61 | 73 65 73 20 2a 2f 0a 09 |error ca|ses */..|
|00003e40| 73 77 69 74 63 68 20 28 | 6f 70 65 6e 69 6e 66 2e |switch (|openinf.|
|00003e50| 66 74 79 70 65 31 29 0a | 09 7b 0a 09 20 20 63 61 |ftype1).|.{.. ca|
|00003e60| 73 65 20 45 52 52 3a 20 | 20 2f 2a 20 65 72 72 6f |se ERR: | /* erro|
|00003e70| 72 20 69 6e 20 6d 6b 70 | 61 74 68 20 6f 72 20 68 |r in mkp|ath or h|
|00003e80| 6f 73 74 20 66 69 6c 65 | 20 61 20 64 69 72 65 63 |ost file| a direc|
|00003e90| 74 6f 72 79 20 2a 2f 0a | 09 09 72 65 74 75 72 6e |tory */.|..return|
|00003ea0| 28 45 52 52 29 3b 0a 09 | 0a 09 20 20 63 61 73 65 |(ERR);..|.. case|
|00003eb0| 20 44 45 56 49 43 45 3a | 20 2f 2a 20 72 65 74 75 | DEVICE:| /* retu|
|00003ec0| 72 6e 20 65 72 72 20 66 | 6f 72 20 69 6c 6c 65 67 |rn err f|or illeg|
|00003ed0| 61 6c 20 61 63 63 65 73 | 73 20 6f 74 68 65 72 77 |al acces|s otherw|
|00003ee0| 69 73 65 20 66 64 20 2a | 2f 0a 09 09 72 65 74 75 |ise fd *|/...retu|
|00003ef0| 72 6e 28 28 70 72 63 6f | 6e 66 6c 28 6f 70 65 6e |rn((prco|nfl(open|
|00003f00| 69 6e 66 2e 73 75 62 74 | 79 70 65 2c 20 61 63 63 |inf.subt|ype, acc|
|00003f10| 65 73 73 29 20 3d 3d 20 | 45 52 52 29 0a 09 09 09 |ess) == |ERR)....|
|00003f20| 3f 20 45 52 52 20 3a 20 | 6f 70 65 6e 69 6e 66 2e |? ERR : |openinf.|
|00003f30| 73 75 62 74 79 70 65 29 | 3b 0a 20 0a 09 20 20 63 |subtype)|;. .. c|
|00003f40| 61 73 65 20 56 46 53 3a | 20 20 2f 2a 20 65 72 72 |ase VFS:| /* err|
|00003f50| 6f 72 20 69 66 20 64 69 | 72 65 63 74 6f 72 79 20 |or if di|rectory |
|00003f60| 2a 2f 0a 09 09 69 66 28 | 6f 70 65 6e 69 6e 66 2e |*/...if(|openinf.|
|00003f70| 73 75 62 74 79 70 65 20 | 3d 3d 20 44 49 52 45 43 |subtype |== DIREC|
|00003f80| 54 4f 52 59 29 0a 09 09 | 09 72 65 74 75 72 6e 28 |TORY)...|.return(|
|00003f90| 45 52 52 29 3b 0a 09 20 | 7d 0a 09 2f 2a 20 53 48 |ERR);.. |}../* SH|
|00003fa0| 4f 55 4c 44 20 57 45 20 | 43 48 45 43 4b 20 57 48 |OULD WE |CHECK WH|
|00003fb0| 45 54 48 45 52 20 46 49 | 4c 45 20 49 53 20 41 4c |ETHER FI|LE IS AL|
|00003fc0| 52 45 41 44 59 20 4f 50 | 45 4e 20 3f 3f 3f 20 2a |READY OP|EN ??? *|
|00003fd0| 2f 0a 20 0a 20 0a 20 0a | 09 2f 2a 20 61 74 74 65 |/. . . .|./* atte|
|00003fe0| 6d 70 74 20 74 6f 20 63 | 72 65 61 74 65 20 66 69 |mpt to c|reate fi|
|00003ff0| 6c 65 20 2d 20 69 66 20 | 66 69 6c 65 20 61 6c 72 |le - if |file alr|
|00004000| 65 61 64 79 20 65 78 69 | 73 74 73 20 69 74 20 77 |eady exi|sts it w|
|00004010| 69 6c 6c 20 62 65 0a 09 | 20 20 20 74 72 75 6e 63 |ill be..| trunc|
|00004020| 61 74 65 64 20 74 6f 20 | 6c 65 6e 67 74 68 20 7a |ated to |length z|
|00004030| 65 72 6f 20 2a 2f 0a 09 | 66 64 20 3d 20 63 72 65 |ero */..|fd = cre|
|00004040| 61 74 28 63 68 61 72 6e | 6d 31 2c 20 52 57 4d 4f |at(charn|m1, RWMO|
|00004050| 44 45 29 3b 0a 20 0a 09 | 2f 2a 20 72 65 74 75 72 |DE);. ..|/* retur|
|00004060| 6e 20 74 68 65 20 66 69 | 6c 65 20 64 65 73 63 72 |n the fi|le descr|
|00004070| 69 70 74 6f 72 20 69 66 | 20 66 64 20 3e 20 4d 41 |iptor if| fd > MA|
|00004080| 58 46 44 20 2a 2f 0a 09 | 69 66 28 66 64 20 3e 20 |XFD */..|if(fd > |
|00004090| 4d 41 58 46 44 29 20 7b | 0a 09 09 63 6c 6f 73 65 |MAXFD) {|...close|
|000040a0| 28 66 64 29 3b 0a 09 09 | 2f 2a 20 72 65 6d 6f 76 |(fd);...|/* remov|
|000040b0| 65 20 7a 65 72 6f 20 6c | 65 6e 67 74 68 20 66 69 |e zero l|ength fi|
|000040c0| 6c 65 20 2a 2f 0a 09 09 | 75 6e 6c 69 6e 6b 28 63 |le */...|unlink(c|
|000040d0| 68 61 72 6e 6d 31 29 3b | 0a 09 09 72 65 74 75 72 |harnm1);|...retur|
|000040e0| 6e 28 45 52 52 29 3b 0a | 09 7d 0a 20 0a 09 2f 2a |n(ERR);.|.}. ../*|
|000040f0| 20 72 65 74 75 72 6e 20 | 69 66 20 6e 6f 74 20 63 | return |if not c|
|00004100| 72 65 61 74 65 64 20 2a | 2f 0a 09 69 66 20 28 66 |reated *|/..if (f|
|00004110| 64 20 3d 3d 20 2d 31 20 | 29 0a 09 20 09 72 65 74 |d == -1 |).. .ret|
|00004120| 75 72 6e 28 45 52 52 29 | 3b 0a 09 2f 2a 20 63 6c |urn(ERR)|;../* cl|
|00004130| 6f 73 65 20 61 6e 64 20 | 72 65 6f 70 65 6e 20 69 |ose and |reopen i|
|00004140| 6e 20 72 65 61 64 77 72 | 69 74 65 20 6d 6f 64 65 |n readwr|ite mode|
|00004150| 20 2a 2f 0a 09 63 6c 6f | 73 65 28 66 64 29 3b 0a | */..clo|se(fd);.|
|00004160| 09 66 64 20 3d 20 6f 70 | 65 6e 28 63 68 61 72 6e |.fd = op|en(charn|
|00004170| 6d 31 2c 20 52 45 41 44 | 57 52 49 54 45 29 3b 0a |m1, READ|WRITE);.|
|00004180| 20 0a 09 2f 2a 20 73 65 | 74 20 75 70 20 66 69 6c | ../* se|t up fil|
|00004190| 65 20 64 65 73 63 72 69 | 70 74 6f 72 20 62 6c 6f |e descri|ptor blo|
|000041a0| 63 6b 20 2a 2f 0a 09 70 | 74 72 20 3d 20 26 66 69 |ck */..p|tr = &fi|
|000041b0| 6c 65 73 5b 66 64 5d 3b | 0a 09 70 74 72 2d 3e 62 |les[fd];|..ptr->b|
|000041c0| 75 66 70 20 3d 20 70 74 | 72 2d 3e 62 75 66 66 65 |ufp = pt|r->buffe|
|000041d0| 72 3b 0a 09 70 74 72 2d | 3e 66 74 79 70 65 20 3d |r;..ptr-|>ftype =|
|000041e0| 20 44 49 52 45 43 54 3b | 0a 09 70 74 72 2d 3e 63 | DIRECT;|..ptr->c|
|000041f0| 68 72 6c 65 66 74 20 3d | 20 2a 6d 61 78 72 65 63 |hrleft =| *maxrec|
|00004200| 3b 0a 09 70 74 72 2d 3e | 61 63 63 65 73 73 20 3d |;..ptr->|access =|
|00004210| 20 52 45 41 44 57 52 49 | 54 45 3b 0a 09 73 74 72 | READWRI|TE;..str|
|00004220| 63 70 79 28 70 74 72 2d | 3e 66 69 6c 65 6e 61 6d |cpy(ptr-|>filenam|
|00004230| 2c 20 63 68 61 72 6e 6d | 31 29 3b 0a 20 0a 09 2f |, charnm|1);. ../|
|00004240| 2a 20 77 72 69 74 65 20 | 6d 61 78 69 6d 75 6d 20 |* write |maximum |
|00004250| 6e 75 6d 62 65 72 20 6f | 66 20 72 65 63 6f 72 64 |number o|f record|
|00004260| 73 20 74 6f 20 66 69 72 | 73 74 20 72 65 63 6f 72 |s to fir|st recor|
|00004270| 64 20 6f 66 20 66 69 6c | 65 20 2a 2f 0a 09 6a 75 |d of fil|e */..ju|
|00004280| 6e 6b 20 3d 20 4d 41 58 | 42 55 46 46 3b 0a 09 69 |nk = MAX|BUFF;..i|
|00004290| 74 6f 63 5f 28 6d 61 78 | 72 65 63 2c 20 26 69 73 |toc_(max|rec, &is|
|000042a0| 74 73 74 72 5b 30 5d 2c | 20 26 6a 75 6e 6b 29 3b |tstr[0],| &junk);|
|000042b0| 0a 09 0a 20 09 2f 2a 20 | 73 77 69 74 63 68 20 6f |... ./* |switch o|
|000042c0| 6e 20 61 63 63 65 73 73 | 20 74 6f 20 72 65 63 6f |n access| to reco|
|000042d0| 72 64 20 7a 65 72 6f 20 | 2a 2f 0a 09 6f 70 6e 72 |rd zero |*/..opnr|
|000042e0| 65 63 30 20 3d 20 31 3b | 0a 20 0a 09 2f 2a 20 70 |ec0 = 1;|. ../* p|
|000042f0| 75 74 20 74 68 65 20 66 | 69 72 73 74 20 72 65 63 |ut the f|irst rec|
|00004300| 6f 72 64 20 69 6e 74 6f | 20 74 68 65 20 66 69 6c |ord into| the fil|
|00004310| 65 20 2a 2f 0a 09 6a 75 | 6e 6b 20 3d 20 30 3b 0a |e */..ju|nk = 0;.|
|00004320| 09 7a 62 70 75 74 72 5f | 28 26 66 64 2c 20 26 6a |.zbputr_|(&fd, &j|
|00004330| 75 6e 6b 2c 20 26 69 73 | 74 73 74 72 5b 30 5d 29 |unk, &is|tstr[0])|
|00004340| 3b 0a 20 0a 09 2f 2a 20 | 73 77 69 74 63 68 20 6f |;. ../* |switch o|
|00004350| 66 66 20 61 63 63 65 73 | 73 20 74 6f 20 72 65 63 |ff acces|s to rec|
|00004360| 6f 72 64 20 30 20 2a 2f | 0a 09 6f 70 6e 72 65 63 |ord 0 */|..opnrec|
|00004370| 30 20 3d 20 30 3b 0a 09 | 2f 2a 20 72 65 74 75 72 |0 = 0;..|/* retur|
|00004380| 6e 20 74 68 65 20 66 69 | 6c 65 20 64 65 73 63 72 |n the fi|le descr|
|00004390| 69 70 74 6f 72 20 2a 2f | 0a 09 72 65 74 75 72 6e |iptor */|..return|
|000043a0| 28 66 64 29 3b 0a 20 0a | 7d 0a 20 0a 7a 62 67 65 |(fd);. .|}. .zbge|
|000043b0| 74 72 5f 28 66 64 2c 20 | 72 65 63 6e 75 6d 2c 20 |tr_(fd, |recnum, |
|000043c0| 62 75 66 29 0a 69 6e 74 | 20 2a 66 64 2c 20 2a 72 |buf).int| *fd, *r|
|000043d0| 65 63 6e 75 6d 2c 20 2a | 62 75 66 3b 0a 7b 0a 20 |ecnum, *|buf;.{. |
|000043e0| 0a 20 20 20 20 20 2f 2a | 20 72 65 61 64 20 74 68 |. /*| read th|
|000043f0| 65 20 63 6f 6e 74 65 6e | 74 73 20 6f 66 20 72 65 |e conten|ts of re|
|00004400| 63 6f 72 64 20 6e 75 6d | 62 65 72 20 72 65 63 6e |cord num|ber recn|
|00004410| 75 6d 20 66 72 6f 6d 20 | 74 68 65 20 64 69 72 65 |um from |the dire|
|00004420| 63 74 20 61 63 63 65 73 | 73 20 66 69 6c 65 0a 20 |ct acces|s file. |
|00004430| 20 20 20 20 20 20 20 61 | 73 73 6f 63 69 61 74 65 | a|ssociate|
|00004440| 64 20 77 69 74 68 20 74 | 68 65 20 66 69 6c 65 20 |d with t|he file |
|00004450| 64 65 73 63 72 69 70 74 | 6f 72 20 66 64 20 69 6e |descript|or fd in|
|00004460| 74 6f 20 62 75 66 2e 0a | 20 20 20 20 20 20 20 20 |to buf..| |
|00004470| 49 74 20 69 73 20 61 6e | 20 65 72 72 6f 72 20 74 |It is an| error t|
|00004480| 6f 20 75 73 65 20 61 20 | 69 6e 76 61 6c 69 64 20 |o use a |invalid |
|00004490| 72 65 63 6e 75 6d 20 6f | 72 20 61 74 74 65 6d 70 |recnum o|r attemp|
|000044a0| 74 0a 20 20 20 20 20 20 | 20 20 74 6f 20 61 63 63 |t. | to acc|
|000044b0| 65 73 73 20 61 20 73 65 | 71 75 65 6e 74 69 61 6c |ess a se|quential|
|000044c0| 20 66 69 6c 65 2e 20 62 | 75 66 20 6d 75 73 74 20 | file. b|uf must |
|000044d0| 62 65 20 6f 66 20 73 69 | 7a 65 20 4d 41 58 42 55 |be of si|ze MAXBU|
|000044e0| 46 46 0a 20 20 20 20 20 | 20 20 20 74 6f 20 70 72 |FF. | to pr|
|000044f0| 65 76 65 6e 74 20 74 68 | 65 20 6f 76 65 72 77 72 |event th|e overwr|
|00004500| 69 74 69 6e 67 20 6f 66 | 20 64 61 74 61 20 61 72 |iting of| data ar|
|00004510| 65 61 73 2e 0a 20 20 20 | 20 20 20 20 20 52 65 61 |eas.. | Rea|
|00004520| 64 69 6e 67 20 61 20 72 | 65 63 6f 72 64 20 74 68 |ding a r|ecord th|
|00004530| 61 74 20 68 61 73 20 6e | 6f 74 20 70 72 65 76 69 |at has n|ot previ|
|00004540| 6f 75 73 6c 79 20 62 65 | 65 6e 20 77 72 69 74 74 |ously be|en writt|
|00004550| 65 6e 20 77 69 6c 6c 0a | 20 20 20 20 20 20 20 20 |en will.| |
|00004560| 72 65 73 75 6c 74 20 69 | 6e 20 61 20 62 75 66 20 |result i|n a buf |
|00004570| 76 65 63 74 6f 72 20 66 | 69 6c 6c 65 64 20 77 69 |vector f|illed wi|
|00004580| 74 68 20 6e 75 6c 6c 73 | 20 2a 2f 0a 20 0a 20 20 |th nulls| */. . |
|00004590| 20 20 20 20 20 20 73 74 | 72 75 63 74 20 66 64 69 | st|ruct fdi|
|000045a0| 6e 66 6f 20 2a 70 74 72 | 3b 0a 20 20 20 20 20 20 |nfo *ptr|;. |
|000045b0| 20 20 75 6e 73 69 67 6e | 65 64 20 63 68 61 72 20 | unsign|ed char |
|000045c0| 20 63 68 3b 0a 20 20 20 | 20 20 20 20 20 63 68 61 | ch;. | cha|
|000045d0| 72 20 2a 70 74 63 3b 0a | 20 20 20 20 20 20 20 20 |r *ptc;.| |
|000045e0| 69 6e 74 20 6a 75 6e 6b | 2c 20 69 3b 0a 20 20 20 |int junk|, i;. |
|000045f0| 20 20 20 20 20 6c 6f 6e | 67 20 69 6e 74 20 72 65 | lon|g int re|
|00004600| 63 70 6f 73 3b 0a 20 0a | 20 20 20 20 20 2f 2a 20 |cpos;. .| /* |
|00004610| 63 68 65 63 6b 20 66 69 | 6c 65 20 64 65 73 63 72 |check fi|le descr|
|00004620| 69 70 74 6f 72 20 69 73 | 20 46 49 4c 45 53 20 69 |iptor is| FILES i|
|00004630| 65 20 6e 6f 74 20 6f 75 | 74 20 6f 66 20 72 61 6e |e not ou|t of ran|
|00004640| 67 65 0a 20 20 20 20 20 | 20 20 20 6f 72 20 6f 6e |ge. | or on|
|00004650| 65 20 6f 66 20 74 68 65 | 20 70 72 65 63 6f 6e 6e |e of the| preconn|
|00004660| 65 63 74 65 64 20 75 6e | 69 74 73 20 61 6e 64 20 |ected un|its and |
|00004670| 61 73 73 6f 63 69 61 74 | 65 64 20 66 69 6c 65 20 |associat|ed file |
|00004680| 69 73 20 6f 70 65 6e 20 | 2a 2f 0a 20 20 20 20 20 |is open |*/. |
|00004690| 20 20 20 69 66 20 28 63 | 68 65 63 6b 66 64 28 2a | if (c|heckfd(*|
|000046a0| 66 64 29 20 21 3d 20 46 | 49 4c 45 53 20 7c 7c 20 |fd) != F|ILES || |
|000046b0| 66 69 6c 65 73 5b 2a 66 | 64 5d 2e 61 63 63 65 73 |files[*f|d].acces|
|000046c0| 73 20 3d 3d 20 4e 4f 54 | 4f 50 45 4e 29 20 72 65 |s == NOT|OPEN) re|
|000046d0| 74 75 72 6e 28 45 52 52 | 29 3b 0a 20 0a 20 20 20 |turn(ERR|);. . |
|000046e0| 20 20 20 20 20 2f 2a 20 | 63 68 65 63 6b 20 66 69 | /* |check fi|
|000046f0| 6c 65 20 6f 70 65 6e 20 | 66 6f 72 20 64 69 72 65 |le open |for dire|
|00004700| 63 74 20 61 63 63 65 73 | 73 20 2a 2f 0a 20 20 20 |ct acces|s */. |
|00004710| 20 20 20 20 20 69 66 20 | 28 66 69 6c 65 73 5b 2a | if |(files[*|
|00004720| 66 64 5d 2e 66 74 79 70 | 65 20 21 3d 20 44 49 52 |fd].ftyp|e != DIR|
|00004730| 45 43 54 29 20 72 65 74 | 75 72 6e 28 45 52 52 29 |ECT) ret|urn(ERR)|
|00004740| 3b 0a 20 0a 20 20 20 20 | 20 20 20 20 2f 2a 20 63 |;. . | /* c|
|00004750| 68 65 63 6b 20 72 65 63 | 6f 72 64 20 6e 75 6d 62 |heck rec|ord numb|
|00004760| 65 72 20 69 73 20 69 6e | 20 72 61 6e 67 65 20 2a |er is in| range *|
|00004770| 2f 0a 20 20 20 20 20 20 | 20 20 2f 2a 20 6f 70 6e |/. | /* opn|
|00004780| 72 65 63 30 20 3d 20 31 | 20 61 6c 6c 6f 77 73 20 |rec0 = 1| allows |
|00004790| 61 63 63 65 73 73 20 74 | 6f 20 72 65 63 6f 72 64 |access t|o record|
|000047a0| 20 7a 65 72 6f 20 6f 6e | 6c 79 20 74 68 69 73 0a | zero on|ly this.|
|000047b0| 20 20 20 20 20 20 20 20 | 20 20 20 69 73 20 6f 6e | | is on|
|000047c0| 6c 79 20 73 65 74 20 62 | 79 20 7a 62 6f 70 65 6e |ly set b|y zbopen|
|000047d0| 20 2a 2f 0a 20 20 20 20 | 20 20 20 20 69 66 20 28 | */. | if (|
|000047e0| 6f 70 6e 72 65 63 30 20 | 3d 3d 20 30 20 26 26 20 |opnrec0 |== 0 && |
|000047f0| 63 68 6b 72 6e 75 6d 28 | 2a 72 65 63 6e 75 6d 2c |chkrnum(|*recnum,|
|00004800| 20 2a 66 64 29 20 3d 3d | 20 45 52 52 29 20 72 65 | *fd) ==| ERR) re|
|00004810| 74 75 72 6e 28 45 52 52 | 29 3b 0a 20 0a 20 20 20 |turn(ERR|);. . |
|00004820| 20 20 20 20 20 70 74 72 | 20 3d 20 26 66 69 6c 65 | ptr| = &file|
|00004830| 73 5b 2a 66 64 5d 3b 0a | 20 20 20 20 20 20 20 20 |s[*fd];.| |
|00004840| 70 74 63 20 3d 20 70 74 | 72 20 2d 3e 20 62 75 66 |ptc = pt|r -> buf|
|00004850| 66 65 72 3b 0a 20 0a 20 | 20 20 20 20 20 20 20 2f |fer;. . | /|
|00004860| 2a 20 66 69 6e 64 20 74 | 68 65 20 72 65 71 75 69 |* find t|he requi|
|00004870| 72 65 64 20 70 6f 73 69 | 74 69 6f 6e 20 69 6e 20 |red posi|tion in |
|00004880| 74 68 65 20 66 69 6c 65 | 20 2a 2f 0a 20 20 20 20 |the file| */. |
|00004890| 20 20 20 20 72 65 63 70 | 6f 73 20 3d 20 2a 72 65 | recp|os = *re|
|000048a0| 63 6e 75 6d 20 2a 20 4d | 41 58 42 55 46 46 3b 0a |cnum * M|AXBUFF;.|
|000048b0| 20 20 20 20 20 20 20 20 | 6c 73 65 65 6b 28 2a 66 | |lseek(*f|
|000048c0| 64 2c 20 72 65 63 70 6f | 73 2c 20 30 29 3b 0a 20 |d, recpo|s, 0);. |
|000048d0| 0a 20 20 20 20 20 20 20 | 20 2f 2a 20 72 65 61 64 |. | /* read|
|000048e0| 20 69 6e 74 6f 20 66 64 | 69 6e 66 6f 20 62 75 66 | into fd|info buf|
|000048f0| 66 65 72 20 2a 2f 0a 20 | 20 20 20 20 20 20 20 72 |fer */. | r|
|00004900| 65 61 64 28 2a 66 64 2c | 20 70 74 72 2d 3e 62 75 |ead(*fd,| ptr->bu|
|00004910| 66 66 65 72 2c 20 4d 41 | 58 42 55 46 46 29 3b 0a |ffer, MA|XBUFF);.|
|00004920| 20 0a 20 20 20 20 20 20 | 20 20 2f 2a 20 61 6e 64 | . | /* and|
|00004930| 20 63 6f 6e 76 65 72 74 | 20 65 61 63 68 20 63 68 | convert| each ch|
|00004940| 61 72 61 63 74 65 72 20 | 74 6f 20 69 74 73 20 65 |aracter |to its e|
|00004950| 71 75 69 76 61 6c 65 6e | 74 20 49 53 54 20 63 68 |quivalen|t IST ch|
|00004960| 61 72 61 63 74 65 72 20 | 20 2a 2f 0a 20 20 20 20 |aracter | */. |
|00004970| 20 20 20 20 66 6f 72 20 | 28 69 3d 30 3b 20 69 3c | for |(i=0; i<|
|00004980| 4d 41 58 42 55 46 46 3b | 20 69 2b 2b 29 7b 0a 20 |MAXBUFF;| i++){. |
|00004990| 20 20 20 20 20 20 20 2f | 2a 20 64 6f 6e 27 74 20 | /|* don't |
|000049a0| 69 6e 74 65 72 70 72 65 | 74 20 74 68 65 20 73 69 |interpre|t the si|
|000049b0| 67 6e 20 62 69 74 20 61 | 73 20 61 20 73 69 67 6e |gn bit a|s a sign|
|000049c0| 20 21 21 20 2a 2f 0a 20 | 20 20 20 20 20 20 20 20 | !! */. | |
|000049d0| 20 20 20 20 20 20 20 20 | 63 68 20 3d 20 2a 70 74 | |ch = *pt|
|000049e0| 63 2b 2b 3b 0a 20 20 20 | 20 20 20 20 20 20 20 20 |c++;. | |
|000049f0| 20 20 20 20 20 20 2a 62 | 75 66 2b 2b 20 3d 20 63 | *b|uf++ = c|
|00004a00| 68 3b 0a 20 20 20 20 20 | 20 20 20 7d 0a 20 0a 20 |h;. | }. . |
|00004a10| 20 20 20 20 20 20 20 72 | 65 74 75 72 6e 28 4e 4f | r|eturn(NO|
|00004a20| 45 52 52 29 3b 0a 20 0a | 7d 0a 20 0a 7a 62 6f 70 |ERR);. .|}. .zbop|
|00004a30| 65 6e 5f 28 6e 61 6d 65 | 2c 20 6d 61 78 72 65 63 |en_(name|, maxrec|
|00004a40| 29 0a 69 6e 74 20 2a 6e | 61 6d 65 2c 20 2a 6d 61 |).int *n|ame, *ma|
|00004a50| 78 72 65 63 3b 0a 7b 0a | 20 0a 20 20 20 20 20 2f |xrec;.{.| . /|
|00004a60| 2a 20 6f 70 65 6e 20 61 | 20 70 72 65 65 78 69 73 |* open a| preexis|
|00004a70| 74 69 6e 67 20 64 69 72 | 65 63 74 20 61 63 63 65 |ting dir|ect acce|
|00004a80| 73 73 20 66 69 6c 65 20 | 61 6e 64 20 72 65 74 75 |ss file |and retu|
|00004a90| 72 6e 20 74 68 65 20 6d | 61 78 69 6d 75 6d 0a 09 |rn the m|aximum..|
|00004aa0| 72 65 63 6f 72 64 20 6e | 75 6d 62 65 72 20 61 6c |record n|umber al|
|00004ab0| 6c 6f 77 65 64 2e 20 54 | 68 65 20 66 69 6c 65 20 |lowed. T|he file |
|00004ac0| 69 73 20 66 6f 72 20 66 | 69 78 65 64 20 6c 65 6e |is for f|ixed len|
|00004ad0| 67 74 68 20 28 4d 41 58 | 42 55 46 46 29 0a 09 66 |gth (MAX|BUFF)..f|
|00004ae0| 6f 72 6d 61 74 74 65 64 | 20 72 65 63 6f 72 64 73 |ormatted| records|
|00004af0| 2e 0a 09 54 68 65 20 6d | 61 78 69 6d 75 6d 20 72 |...The m|aximum r|
|00004b00| 65 63 6f 72 64 20 6e 75 | 6d 62 65 72 20 69 73 20 |ecord nu|mber is |
|00004b10| 73 74 6f 72 65 64 20 69 | 6e 20 74 68 65 20 66 69 |stored i|n the fi|
|00004b20| 72 73 74 20 72 65 63 6f | 72 64 20 69 6e 20 74 68 |rst reco|rd in th|
|00004b30| 65 0a 09 66 69 6c 65 2e | 20 44 69 72 65 63 74 20 |e..file.| Direct |
|00004b40| 61 63 63 65 73 73 20 66 | 69 6c 65 73 20 61 72 65 |access f|iles are|
|00004b50| 20 61 6c 77 61 79 73 20 | 6f 70 65 6e 65 64 2f 63 | always |opened/c|
|00004b60| 72 65 61 74 65 64 20 69 | 6e 0a 09 52 45 41 44 57 |reated i|n..READW|
|00004b70| 52 49 54 45 20 4d 4f 44 | 45 20 2a 2f 0a 20 0a 09 |RITE MOD|E */. ..|
|00004b80| 73 74 72 75 63 74 20 66 | 69 6c 69 6e 66 6f 20 6f |struct f|ilinfo o|
|00004b90| 70 65 6e 69 6e 66 3b 0a | 09 63 68 61 72 20 63 68 |peninf;.|.char ch|
|00004ba0| 61 72 6e 6d 31 5b 4d 41 | 58 50 41 54 48 5d 3b 0a |arnm1[MA|XPATH];.|
|00004bb0| 09 69 6e 74 20 66 64 2c | 20 74 65 6d 70 3b 0a 09 |.int fd,| temp;..|
|00004bc0| 69 6e 74 20 62 75 66 66 | 65 72 5b 4d 41 58 42 55 |int buff|er[MAXBU|
|00004bd0| 46 46 5d 3b 20 20 2f 2a | 20 6c 6f 63 61 6c 20 62 |FF]; /*| local b|
|00004be0| 75 66 66 65 72 20 75 73 | 65 64 20 66 6f 72 20 73 |uffer us|ed for s|
|00004bf0| 74 6f 72 69 6e 67 20 76 | 61 6c 75 65 20 6f 66 20 |toring v|alue of |
|00004c00| 6d 61 78 72 65 63 20 2a | 2f 0a 09 69 6e 74 20 61 |maxrec *|/..int a|
|00004c10| 63 63 65 73 73 20 3d 20 | 52 45 41 44 57 52 49 54 |ccess = |READWRIT|
|00004c20| 45 3b 0a 20 0a 20 20 20 | 20 20 2f 2a 09 67 65 6e |E;. . | /*.gen|
|00004c30| 65 72 61 74 65 20 66 75 | 6c 6c 20 70 61 74 68 20 |erate fu|ll path |
|00004c40| 6e 61 6d 65 20 61 73 20 | 61 20 63 68 61 72 61 63 |name as |a charac|
|00004c50| 74 65 72 20 73 74 72 69 | 6e 67 20 2a 2f 0a 20 20 |ter stri|ng */. |
|00004c60| 20 20 09 6d 6b 66 69 6c | 6e 6d 28 6e 61 6d 65 2c | .mkfil|nm(name,|
|00004c70| 20 63 68 61 72 6e 6d 31 | 2c 20 26 6f 70 65 6e 69 | charnm1|, &openi|
|00004c80| 6e 66 29 3b 0a 20 0a 20 | 20 20 20 20 2f 2a 09 73 |nf);. . | /*.s|
|00004c90| 6f 72 74 20 6f 75 74 20 | 70 6f 73 73 69 62 6c 65 |ort out |possible|
|00004ca0| 20 65 72 72 6f 72 20 63 | 61 73 65 73 20 2a 2f 0a | error c|ases */.|
|00004cb0| 09 73 77 69 74 63 68 20 | 28 6f 70 65 6e 69 6e 66 |.switch |(openinf|
|00004cc0| 2e 66 74 79 70 65 31 29 | 0a 09 7b 0a 09 20 20 63 |.ftype1)|..{.. c|
|00004cd0| 61 73 65 20 45 52 52 3a | 20 20 2f 2a 20 65 72 72 |ase ERR:| /* err|
|00004ce0| 6f 72 20 69 6e 20 6d 6b | 70 61 74 68 20 6f 72 20 |or in mk|path or |
|00004cf0| 68 6f 73 74 20 66 69 6c | 65 20 61 20 64 69 72 65 |host fil|e a dire|
|00004d00| 63 74 6f 72 79 20 2a 2f | 0a 09 09 72 65 74 75 72 |ctory */|...retur|
|00004d10| 6e 28 45 52 52 29 3b 0a | 09 0a 09 20 20 63 61 73 |n(ERR);.|... cas|
|00004d20| 65 20 44 45 56 49 43 45 | 3a 20 2f 2a 20 72 65 74 |e DEVICE|: /* ret|
|00004d30| 75 72 6e 20 65 72 72 20 | 66 6f 72 20 69 6c 6c 65 |urn err |for ille|
|00004d40| 67 61 6c 20 61 63 63 65 | 73 73 20 6f 74 68 65 72 |gal acce|ss other|
|00004d50| 77 69 73 65 20 66 64 20 | 2a 2f 0a 09 09 72 65 74 |wise fd |*/...ret|
|00004d60| 75 72 6e 28 28 70 72 63 | 6f 6e 66 6c 28 6f 70 65 |urn((prc|onfl(ope|
|00004d70| 6e 69 6e 66 2e 73 75 62 | 74 79 70 65 2c 20 61 63 |ninf.sub|type, ac|
|00004d80| 63 65 73 73 29 20 3d 3d | 20 45 52 52 29 0a 09 09 |cess) ==| ERR)...|
|00004d90| 09 3f 20 45 52 52 20 3a | 20 6f 70 65 6e 69 6e 66 |.? ERR :| openinf|
|00004da0| 2e 73 75 62 74 79 70 65 | 29 3b 0a 20 0a 09 20 20 |.subtype|);. .. |
|00004db0| 63 61 73 65 20 48 4f 53 | 54 3a 20 20 2f 2a 20 65 |case HOS|T: /* e|
|00004dc0| 72 72 6f 72 20 69 66 20 | 66 69 6c 65 20 64 6f 65 |rror if |file doe|
|00004dd0| 73 6e 27 74 20 65 78 69 | 73 74 20 2a 2f 0a 09 09 |sn't exi|st */...|
|00004de0| 69 66 28 6f 70 65 6e 69 | 6e 66 2e 65 78 69 73 74 |if(openi|nf.exist|
|00004df0| 73 20 3d 3d 20 4e 4f 29 | 20 72 65 74 75 72 6e 28 |s == NO)| return(|
|00004e00| 45 52 52 29 3b 0a 09 09 | 62 72 65 61 6b 3b 0a 20 |ERR);...|break;. |
|00004e10| 0a 09 20 20 63 61 73 65 | 20 56 46 53 3a 20 20 2f |.. case| VFS: /|
|00004e20| 2a 20 65 72 72 6f 72 20 | 69 66 20 66 69 6c 65 20 |* error |if file |
|00004e30| 64 6f 65 73 6e 27 74 20 | 65 78 69 73 74 20 6f 72 |doesn't |exist or|
|00004e40| 20 64 69 72 65 63 74 6f | 72 79 20 2a 2f 0a 09 09 | directo|ry */...|
|00004e50| 69 66 28 6f 70 65 6e 69 | 6e 66 2e 65 78 69 73 74 |if(openi|nf.exist|
|00004e60| 73 20 3d 3d 20 4e 4f 20 | 7c 7c 20 6f 70 65 6e 69 |s == NO ||| openi|
|00004e70| 6e 66 2e 73 75 62 74 79 | 70 65 20 3d 3d 20 44 49 |nf.subty|pe == DI|
|00004e80| 52 45 43 54 4f 52 59 29 | 0a 09 09 09 72 65 74 75 |RECTORY)|....retu|
|00004e90| 72 6e 28 45 52 52 29 3b | 0a 09 20 7d 0a 09 09 0a |rn(ERR);|.. }....|
|00004ea0| 09 2f 2a 20 65 6e 73 75 | 72 65 20 66 69 6c 65 20 |./* ensu|re file |
|00004eb0| 65 78 69 73 74 73 20 61 | 6e 64 20 6e 6f 74 20 74 |exists a|nd not t|
|00004ec0| 6f 6f 20 6d 61 6e 79 20 | 64 65 73 63 72 69 70 74 |oo many |descript|
|00004ed0| 6f 72 73 20 2a 2f 0a 09 | 69 66 28 28 66 64 3d 6f |ors */..|if((fd=o|
|00004ee0| 70 65 6e 28 63 68 61 72 | 6e 6d 31 2c 20 52 45 41 |pen(char|nm1, REA|
|00004ef0| 44 57 52 49 54 45 29 29 | 20 3d 3d 20 2d 31 20 29 |DWRITE))| == -1 )|
|00004f00| 20 72 65 74 75 72 6e 28 | 45 52 52 29 3b 0a 09 69 | return(|ERR);..i|
|00004f10| 66 20 28 66 64 20 3e 20 | 4d 41 58 46 44 29 20 7b |f (fd > |MAXFD) {|
|00004f20| 0a 09 09 63 6c 6f 73 65 | 28 66 64 29 3b 0a 09 09 |...close|(fd);...|
|00004f30| 72 65 74 75 72 6e 28 45 | 52 52 29 3b 0a 09 7d 0a |return(E|RR);..}.|
|00004f40| 20 0a 09 2f 2a 20 73 74 | 6f 72 65 20 66 69 6c 65 | ../* st|ore file|
|00004f50| 20 69 6e 66 6f 20 2a 2f | 0a 09 73 74 72 63 70 79 | info */|..strcpy|
|00004f60| 28 66 69 6c 65 73 5b 66 | 64 5d 2e 66 69 6c 65 6e |(files[f|d].filen|
|00004f70| 61 6d 2c 20 63 68 61 72 | 6e 6d 31 29 3b 0a 09 66 |am, char|nm1);..f|
|00004f80| 69 6c 65 73 5b 66 64 5d | 2e 66 74 79 70 65 20 3d |iles[fd]|.ftype =|
|00004f90| 20 44 49 52 45 43 54 3b | 0a 09 66 69 6c 65 73 5b | DIRECT;|..files[|
|00004fa0| 66 64 5d 2e 61 63 63 65 | 73 73 20 3d 20 52 45 41 |fd].acce|ss = REA|
|00004fb0| 44 57 52 49 54 45 3b 0a | 20 0a 20 0a 09 2f 2a 20 |DWRITE;.| . ../* |
|00004fc0| 73 77 69 74 63 68 20 6f | 6e 20 61 63 63 65 73 73 |switch o|n access|
|00004fd0| 20 74 6f 20 72 65 63 6f | 72 64 20 7a 65 72 6f 20 | to reco|rd zero |
|00004fe0| 2a 2f 0a 09 6f 70 6e 72 | 65 63 30 20 3d 20 31 3b |*/..opnr|ec0 = 1;|
|00004ff0| 0a 20 0a 09 2f 2a 20 67 | 65 74 20 66 69 72 73 74 |. ../* g|et first|
|00005000| 20 72 65 63 6f 72 64 2c | 20 72 65 74 75 72 6e 20 | record,| return |
|00005010| 76 61 6c 75 65 20 6f 66 | 20 6d 61 78 72 65 63 20 |value of| maxrec |
|00005020| 61 6e 64 20 73 74 6f 72 | 65 20 69 74 20 66 6f 72 |and stor|e it for|
|00005030| 0a 09 20 20 20 66 75 74 | 75 72 65 20 67 65 74 73 |.. fut|ure gets|
|00005040| 20 61 6e 64 20 70 75 74 | 73 20 69 6e 20 63 68 72 | and put|s in chr|
|00005050| 6c 65 66 74 20 2a 2f 0a | 09 74 65 6d 70 20 3d 20 |left */.|.temp = |
|00005060| 30 3b 0a 09 7a 62 67 65 | 74 72 5f 28 26 66 64 2c |0;..zbge|tr_(&fd,|
|00005070| 20 26 74 65 6d 70 2c 20 | 26 62 75 66 66 65 72 5b | &temp, |&buffer[|
|00005080| 30 5d 29 3b 0a 09 74 65 | 6d 70 20 3d 20 31 3b 0a |0]);..te|mp = 1;.|
|00005090| 20 0a 09 2f 2a 20 73 77 | 69 74 63 68 20 6f 66 66 | ../* sw|itch off|
|000050a0| 20 61 63 63 65 73 73 20 | 74 6f 20 72 65 63 6f 72 | access |to recor|
|000050b0| 64 20 7a 65 72 6f 20 2a | 2f 0a 09 6f 70 6e 72 65 |d zero *|/..opnre|
|000050c0| 63 30 20 3d 20 30 3b 0a | 09 2f 2a 20 61 20 76 61 |c0 = 0;.|./* a va|
|000050d0| 6c 75 65 20 6f 66 20 7a | 65 72 6f 20 70 72 6f 62 |lue of z|ero prob|
|000050e0| 61 62 6c 79 20 69 6e 64 | 69 63 61 74 65 73 20 61 |ably ind|icates a|
|000050f0| 63 63 65 73 73 20 6f 66 | 20 61 20 73 65 71 75 65 |ccess of| a seque|
|00005100| 6e 74 69 61 6c 20 66 69 | 6c 65 20 2a 2f 0a 09 69 |ntial fi|le */..i|
|00005110| 66 28 20 28 2a 6d 61 78 | 72 65 63 20 3d 20 63 74 |f( (*max|rec = ct|
|00005120| 6f 69 5f 28 26 62 75 66 | 66 65 72 5b 30 5d 2c 20 |oi_(&buf|fer[0], |
|00005130| 26 74 65 6d 70 29 29 20 | 3d 3d 20 30 29 20 7b 0a |&temp)) |== 0) {.|
|00005140| 09 09 63 6c 6f 73 65 28 | 66 64 29 3b 0a 09 09 72 |..close(|fd);...r|
|00005150| 65 74 75 72 6e 28 45 52 | 52 29 3b 0a 09 7d 0a 09 |eturn(ER|R);..}..|
|00005160| 66 69 6c 65 73 5b 66 64 | 5d 2e 63 68 72 6c 65 66 |files[fd|].chrlef|
|00005170| 74 20 3d 20 2a 6d 61 78 | 72 65 63 3b 0a 09 0a 09 |t = *max|rec;....|
|00005180| 72 65 74 75 72 6e 28 66 | 64 29 3b 0a 7d 0a 20 0a |return(f|d);.}. .|
|00005190| 7a 62 70 75 74 72 5f 28 | 66 64 2c 20 72 65 63 6e |zbputr_(|fd, recn|
|000051a0| 75 6d 2c 20 62 75 66 29 | 0a 69 6e 74 20 2a 66 64 |um, buf)|.int *fd|
|000051b0| 2c 20 2a 72 65 63 6e 75 | 6d 2c 20 2a 62 75 66 3b |, *recnu|m, *buf;|
|000051c0| 0a 7b 0a 20 0a 20 20 20 | 20 20 2f 2a 20 77 72 69 |.{. . | /* wri|
|000051d0| 74 65 20 74 68 65 20 63 | 6f 6e 74 65 6e 74 73 20 |te the c|ontents |
|000051e0| 6f 66 20 62 75 66 20 74 | 6f 20 74 68 65 20 64 69 |of buf t|o the di|
|000051f0| 72 65 63 74 20 61 63 63 | 65 73 73 20 66 69 6c 65 |rect acc|ess file|
|00005200| 0a 20 20 20 20 20 20 20 | 20 61 73 73 6f 63 69 61 |. | associa|
|00005210| 74 65 64 20 77 69 74 68 | 20 74 68 65 20 66 69 6c |ted with| the fil|
|00005220| 65 20 64 65 73 63 72 69 | 70 74 6f 72 20 66 64 20 |e descri|ptor fd |
|00005230| 61 74 20 72 65 63 6f 72 | 64 20 6e 75 6d 62 65 72 |at recor|d number|
|00005240| 0a 20 20 20 20 20 20 20 | 20 72 65 63 6e 75 6d 2e |. | recnum.|
|00005250| 20 49 74 20 69 73 20 61 | 6e 20 65 72 72 6f 72 20 | It is a|n error |
|00005260| 74 6f 20 75 73 65 20 61 | 20 69 6e 76 61 6c 69 64 |to use a| invalid|
|00005270| 20 72 65 63 6e 75 6d 20 | 6f 72 20 61 74 74 65 6d | recnum |or attem|
|00005280| 70 74 0a 20 20 20 20 20 | 20 20 20 74 6f 20 61 63 |pt. | to ac|
|00005290| 63 65 73 73 20 61 20 73 | 65 71 75 65 6e 74 69 61 |cess a s|equentia|
|000052a0| 6c 20 66 69 6c 65 2e 20 | 62 75 66 20 6d 75 73 74 |l file. |buf must|
|000052b0| 20 62 65 20 6f 66 20 73 | 69 7a 65 20 4d 41 58 42 | be of s|ize MAXB|
|000052c0| 55 46 46 0a 20 20 20 20 | 20 20 20 20 61 6e 64 20 |UFF. | and |
|000052d0| 6d 61 79 20 63 6f 6e 74 | 61 69 6e 20 61 6e 79 20 |may cont|ain any |
|000052e0| 76 61 6c 69 64 20 49 53 | 54 20 63 68 61 72 61 63 |valid IS|T charac|
|000052f0| 74 65 72 73 20 69 6e 63 | 6c 75 64 69 6e 67 20 65 |ters inc|luding e|
|00005300| 6d 62 65 64 64 65 64 0a | 20 20 20 20 20 20 20 20 |mbedded.| |
|00005310| 45 4f 53 20 61 6e 64 20 | 4e 45 57 4c 49 4e 45 20 |EOS and |NEWLINE |
|00005320| 63 68 61 72 61 63 74 65 | 72 73 2e 20 41 6e 79 20 |characte|rs. Any |
|00005330| 76 61 6c 75 65 20 69 6e | 20 62 75 66 20 6f 75 74 |value in| buf out|
|00005340| 73 69 64 65 20 74 68 65 | 0a 20 20 20 20 20 20 20 |side the|. |
|00005350| 20 72 61 6e 67 65 20 30 | 2d 32 35 35 20 77 69 6c | range 0|-255 wil|
|00005360| 6c 20 62 65 20 73 74 6f | 72 65 64 20 61 73 20 7a |l be sto|red as z|
|00005370| 65 72 6f 20 2a 2f 0a 20 | 0a 20 20 20 20 20 20 20 |ero */. |. |
|00005380| 20 73 74 72 75 63 74 20 | 66 64 69 6e 66 6f 20 2a | struct |fdinfo *|
|00005390| 70 74 72 3b 0a 20 20 20 | 20 20 20 20 20 63 68 61 |ptr;. | cha|
|000053a0| 72 20 2a 70 74 63 3b 0a | 20 20 20 20 20 20 20 20 |r *ptc;.| |
|000053b0| 69 6e 74 20 63 2c 20 69 | 3b 0a 20 20 20 20 20 20 |int c, i|;. |
|000053c0| 20 20 6c 6f 6e 67 20 69 | 6e 74 20 72 65 63 70 6f | long i|nt recpo|
|000053d0| 73 3b 0a 20 0a 20 20 20 | 20 20 2f 2a 20 63 68 65 |s;. . | /* che|
|000053e0| 63 6b 20 66 69 6c 65 20 | 64 65 73 63 72 69 70 74 |ck file |descript|
|000053f0| 6f 72 20 69 73 20 46 49 | 4c 45 53 20 69 65 20 6e |or is FI|LES ie n|
|00005400| 6f 74 20 6f 75 74 20 6f | 66 20 72 61 6e 67 65 0a |ot out o|f range.|
|00005410| 20 20 20 20 20 20 20 20 | 6f 72 20 6f 6e 65 20 6f | |or one o|
|00005420| 66 20 74 68 65 20 70 72 | 65 63 6f 6e 6e 65 63 74 |f the pr|econnect|
|00005430| 65 64 20 75 6e 69 74 73 | 20 61 6e 64 20 61 73 73 |ed units| and ass|
|00005440| 6f 63 69 61 74 65 64 20 | 66 69 6c 65 20 69 73 20 |ociated |file is |
|00005450| 6f 70 65 6e 20 2a 2f 0a | 20 20 20 20 20 20 20 20 |open */.| |
|00005460| 69 66 20 28 63 68 65 63 | 6b 66 64 28 2a 66 64 29 |if (chec|kfd(*fd)|
|00005470| 20 21 3d 20 46 49 4c 45 | 53 20 7c 7c 20 66 69 6c | != FILE|S || fil|
|00005480| 65 73 5b 2a 66 64 5d 2e | 61 63 63 65 73 73 20 3d |es[*fd].|access =|
|00005490| 3d 20 4e 4f 54 4f 50 45 | 4e 29 20 72 65 74 75 72 |= NOTOPE|N) retur|
|000054a0| 6e 28 45 52 52 29 3b 0a | 20 0a 20 20 20 20 20 20 |n(ERR);.| . |
|000054b0| 20 20 2f 2a 20 63 68 65 | 63 6b 20 66 69 6c 65 20 | /* che|ck file |
|000054c0| 6f 70 65 6e 20 66 6f 72 | 20 64 69 72 65 63 74 20 |open for| direct |
|000054d0| 61 63 63 65 73 73 20 2a | 2f 0a 20 20 20 20 20 20 |access *|/. |
|000054e0| 20 20 69 66 20 28 66 69 | 6c 65 73 5b 2a 66 64 5d | if (fi|les[*fd]|
|000054f0| 2e 66 74 79 70 65 20 21 | 3d 20 44 49 52 45 43 54 |.ftype !|= DIRECT|
|00005500| 29 20 72 65 74 75 72 6e | 28 45 52 52 29 3b 0a 20 |) return|(ERR);. |
|00005510| 0a 20 20 20 20 20 20 20 | 20 2f 2a 20 63 68 65 63 |. | /* chec|
|00005520| 6b 20 72 65 63 6f 72 64 | 20 6e 75 6d 62 65 72 20 |k record| number |
|00005530| 69 73 20 69 6e 20 72 61 | 6e 67 65 20 2a 2f 0a 20 |is in ra|nge */. |
|00005540| 20 20 20 20 20 20 20 2f | 2a 20 75 6e 6c 65 73 73 | /|* unless|
|00005550| 20 70 65 72 6d 69 73 73 | 69 6f 6e 20 74 6f 20 61 | permiss|ion to a|
|00005560| 63 63 65 73 73 20 72 65 | 63 6f 72 64 20 7a 65 72 |ccess re|cord zer|
|00005570| 6f 20 69 73 20 73 65 74 | 20 2a 2f 0a 20 20 20 20 |o is set| */. |
|00005580| 20 20 20 20 69 66 20 28 | 20 6f 70 6e 72 65 63 30 | if (| opnrec0|
|00005590| 20 3d 3d 20 30 20 26 26 | 20 63 68 6b 72 6e 75 6d | == 0 &&| chkrnum|
|000055a0| 28 2a 72 65 63 6e 75 6d | 2c 20 2a 66 64 29 20 3d |(*recnum|, *fd) =|
|000055b0| 3d 20 45 52 52 29 20 72 | 65 74 75 72 6e 28 45 52 |= ERR) r|eturn(ER|
|000055c0| 52 29 3b 0a 20 0a 20 20 | 20 20 20 20 20 20 70 74 |R);. . | pt|
|000055d0| 72 20 3d 20 26 66 69 6c | 65 73 5b 2a 66 64 5d 3b |r = &fil|es[*fd];|
|000055e0| 0a 20 20 20 20 20 20 20 | 20 70 74 63 20 3d 20 70 |. | ptc = p|
|000055f0| 74 72 20 2d 3e 20 62 75 | 66 66 65 72 3b 0a 20 0a |tr -> bu|ffer;. .|
|00005600| 20 20 20 20 20 20 20 20 | 2f 2a 20 66 69 6e 64 20 | |/* find |
|00005610| 74 68 65 20 72 65 71 75 | 69 72 65 64 20 70 6f 73 |the requ|ired pos|
|00005620| 69 74 69 6f 6e 20 69 6e | 20 74 68 65 20 66 69 6c |ition in| the fil|
|00005630| 65 20 2a 2f 0a 20 20 20 | 20 20 20 20 20 72 65 63 |e */. | rec|
|00005640| 70 6f 73 20 3d 20 2a 72 | 65 63 6e 75 6d 20 2a 20 |pos = *r|ecnum * |
|00005650| 4d 41 58 42 55 46 46 3b | 3b 0a 20 20 20 20 20 20 |MAXBUFF;|;. |
|00005660| 20 20 6c 73 65 65 6b 28 | 2a 66 64 2c 20 72 65 63 | lseek(|*fd, rec|
|00005670| 70 6f 73 2c 20 30 29 3b | 0a 20 0a 20 20 20 20 20 |pos, 0);|. . |
|00005680| 20 20 20 2f 2a 20 77 72 | 69 74 65 20 49 53 54 20 | /* wr|ite IST |
|00005690| 73 74 72 69 6e 67 20 74 | 6f 20 66 64 69 6e 66 6f |string t|o fdinfo|
|000056a0| 20 62 75 66 66 65 72 20 | 2a 2f 0a 20 20 20 20 20 | buffer |*/. |
|000056b0| 20 20 20 66 6f 72 20 28 | 69 3d 30 3b 20 69 3c 4d | for (|i=0; i<M|
|000056c0| 41 58 42 55 46 46 3b 20 | 69 2b 2b 29 0a 20 20 20 |AXBUFF; |i++). |
|000056d0| 20 20 20 20 20 7b 0a 20 | 20 20 20 20 20 20 20 20 | {. | |
|000056e0| 20 20 20 20 20 20 20 69 | 66 20 28 20 28 63 20 3d | i|f ( (c =|
|000056f0| 20 2a 62 75 66 2b 2b 29 | 20 3e 20 32 35 35 20 7c | *buf++)| > 255 ||
|00005700| 7c 20 63 20 3c 20 30 29 | 20 63 20 3d 20 30 3b 0a || c < 0)| c = 0;.|
|00005710| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 | | |
|00005720| 2a 70 74 63 2b 2b 20 3d | 20 63 3b 0a 20 20 20 20 |*ptc++ =| c;. |
|00005730| 20 20 20 20 7d 0a 20 0a | 20 20 20 20 20 20 20 20 | }. .| |
|00005740| 2f 2a 20 61 6e 64 20 74 | 68 65 6e 63 65 20 74 6f |/* and t|hence to|
|00005750| 20 74 68 65 20 66 69 6c | 65 20 2a 2f 0a 20 20 20 | the fil|e */. |
|00005760| 20 20 20 20 20 77 72 69 | 74 65 28 2a 66 64 2c 20 | wri|te(*fd, |
|00005770| 70 74 72 2d 3e 62 75 66 | 66 65 72 2c 20 4d 41 58 |ptr->buf|fer, MAX|
|00005780| 42 55 46 46 29 3b 0a 20 | 0a 20 20 20 20 20 20 20 |BUFF);. |. |
|00005790| 20 72 65 74 75 72 6e 28 | 4e 4f 45 52 52 29 3b 0a | return(|NOERR);.|
|000057a0| 20 0a 7d 0a 20 0a 7a 63 | 68 6f 75 74 5f 28 73 2c | .}. .zc|hout_(s,|
|000057b0| 20 66 64 2c 20 6c 65 6e | 67 74 68 29 0a 63 68 61 | fd, len|gth).cha|
|000057c0| 72 20 2a 73 3b 0a 69 6e | 74 20 2a 66 64 3b 0a 6c |r *s;.in|t *fd;.l|
|000057d0| 6f 6e 67 20 69 6e 74 20 | 6c 65 6e 67 74 68 3b 0a |ong int |length;.|
|000057e0| 20 0a 7b 0a 09 2f 2a 20 | 6f 75 74 70 75 74 20 61 | .{../* |output a|
|000057f0| 6e 20 66 37 37 20 73 74 | 72 69 6e 67 20 74 65 72 |n f77 st|ring ter|
|00005800| 6d 69 6e 61 74 65 64 20 | 62 79 20 61 20 70 65 72 |minated |by a per|
|00005810| 69 6f 64 20 74 6f 20 74 | 68 65 20 66 69 6c 65 20 |iod to t|he file |
|00005820| 61 73 73 6f 63 69 61 74 | 65 64 0a 09 20 20 20 77 |associat|ed.. w|
|00005830| 69 74 68 20 74 68 65 20 | 66 69 6c 65 20 64 65 73 |ith the |file des|
|00005840| 63 72 69 70 74 6f 72 20 | 66 64 2e 20 20 4e 6f 20 |criptor |fd. No |
|00005850| 74 72 61 69 6c 69 6e 67 | 20 4e 45 57 4c 49 4e 45 |trailing| NEWLINE|
|00005860| 20 69 73 20 61 70 70 65 | 6e 64 65 64 20 74 6f 0a | is appe|nded to.|
|00005870| 09 20 20 20 74 68 65 20 | 6c 69 6e 65 20 61 6e 64 |. the |line and|
|00005880| 20 74 68 65 20 70 65 72 | 69 6f 64 20 69 73 20 6e | the per|iod is n|
|00005890| 6f 74 20 74 72 61 6e 73 | 6d 69 74 74 65 64 2e 20 |ot trans|mitted. |
|000058a0| 20 41 20 70 65 72 69 6f | 64 20 77 69 74 68 69 6e | A perio|d within|
|000058b0| 20 74 68 65 0a 09 20 20 | 20 73 74 72 69 6e 67 20 | the.. | string |
|000058c0| 69 73 20 64 65 6e 6f 74 | 65 64 20 62 79 20 27 2e |is denot|ed by '.|
|000058d0| 2e 27 20 2a 2f 0a 20 0a | 09 63 68 61 72 20 2a 70 |.' */. .|.char *p|
|000058e0| 74 72 20 3b 0a 09 63 68 | 61 72 20 70 65 72 69 6f |tr ;..ch|ar perio|
|000058f0| 64 20 3d 20 50 45 52 49 | 4f 44 43 48 3b 0a 20 0a |d = PERI|ODCH;. .|
|00005900| 09 2f 2a 20 73 65 74 20 | 70 6f 69 6e 74 65 72 20 |./* set |pointer |
|00005910| 74 6f 20 65 6e 64 20 6f | 66 20 73 74 72 69 6e 67 |to end o|f string|
|00005920| 20 2a 2f 0a 20 0a 09 70 | 74 72 20 3d 20 73 2b 6c | */. ..p|tr = s+l|
|00005930| 65 6e 67 74 68 2d 31 3b | 0a 20 0a 09 2f 2a 20 6c |ength-1;|. ../* l|
|00005940| 6f 6f 70 20 74 68 72 6f | 75 67 68 20 74 68 65 20 |oop thro|ugh the |
|00005950| 73 74 72 69 6e 67 20 2a | 2f 0a 20 0a 09 77 68 69 |string *|/. ..whi|
|00005960| 6c 65 20 28 73 20 3c 20 | 70 74 72 29 0a 09 7b 0a |le (s < |ptr)..{.|
|00005970| 09 09 2f 2a 20 74 61 6b | 65 20 63 61 72 65 20 6f |../* tak|e care o|
|00005980| 66 20 64 6f 75 62 6c 65 | 20 70 65 72 69 6f 64 20 |f double| period |
|00005990| 63 61 73 65 20 2a 2f 0a | 09 09 69 66 28 20 2a 73 |case */.|..if( *s|
|000059a0| 20 3d 3d 20 50 45 52 49 | 4f 44 43 48 20 26 26 20 | == PERI|ODCH && |
|000059b0| 2a 28 73 2b 31 29 20 3d | 3d 20 50 45 52 49 4f 44 |*(s+1) =|= PERIOD|
|000059c0| 43 48 20 29 0a 09 09 7b | 0a 09 09 09 7a 70 75 74 |CH )...{|....zput|
|000059d0| 63 68 5f 28 20 26 70 65 | 72 69 6f 64 2c 20 66 64 |ch_( &pe|riod, fd|
|000059e0| 29 3b 0a 09 09 09 73 20 | 2b 3d 20 32 3b 0a 09 09 |);....s |+= 2;...|
|000059f0| 7d 0a 20 0a 09 09 2f 2a | 20 73 69 6e 67 6c 65 20 |}. .../*| single |
|00005a00| 50 45 52 49 4f 44 20 2d | 20 72 65 74 75 72 6e 20 |PERIOD -| return |
|00005a10| 2a 2f 0a 09 09 65 6c 73 | 65 20 69 66 20 28 2a 73 |*/...els|e if (*s|
|00005a20| 20 3d 3d 20 50 45 52 49 | 4f 44 43 48 29 0a 09 09 | == PERI|ODCH)...|
|00005a30| 09 72 65 74 75 72 6e 3b | 0a 20 0a 09 09 2f 2a 20 |.return;|. .../* |
|00005a40| 65 6c 73 65 20 6f 75 74 | 70 75 74 20 74 68 65 20 |else out|put the |
|00005a50| 63 68 61 72 61 63 74 65 | 72 20 2a 2f 0a 09 09 65 |characte|r */...e|
|00005a60| 6c 73 65 0a 09 09 09 7a | 70 75 74 63 68 5f 28 73 |lse....z|putch_(s|
|00005a70| 2b 2b 2c 20 66 64 29 3b | 0a 09 7d 0a 20 0a 09 2f |++, fd);|..}. ../|
|00005a80| 2a 20 64 65 61 6c 20 77 | 69 74 68 20 6c 61 73 74 |* deal w|ith last|
|00005a90| 20 63 68 61 72 61 63 74 | 65 72 20 65 69 74 68 65 | charact|er eithe|
|00005aa0| 72 20 50 45 52 49 4f 44 | 20 28 69 67 6e 6f 72 65 |r PERIOD| (ignore|
|00005ab0| 29 0a 20 20 20 20 20 20 | 20 20 20 20 20 6f 72 20 |). | or |
|00005ac0| 63 68 61 72 61 63 74 65 | 72 20 28 6f 75 74 70 75 |characte|r (outpu|
|00005ad0| 74 29 20 2a 2f 0a 09 69 | 66 28 2a 70 74 72 20 21 |t) */..i|f(*ptr !|
|00005ae0| 3d 20 50 45 52 49 4f 44 | 43 48 29 0a 09 09 7a 70 |= PERIOD|CH)...zp|
|00005af0| 75 74 63 68 5f 28 20 70 | 74 72 2c 66 64 29 3b 0a |utch_( p|tr,fd);.|
|00005b00| 20 0a 7d 0a 20 0a 7a 63 | 6e 74 72 6c 5f 28 66 64 | .}. .zc|ntrl_(fd|
|00005b10| 2c 20 6c 65 6e 69 2c 20 | 6c 65 6e 6f 2c 20 66 6c |, leni, |leno, fl|
|00005b20| 61 67 29 0a 69 6e 74 20 | 2a 66 64 2c 20 2a 6c 65 |ag).int |*fd, *le|
|00005b30| 6e 69 2c 20 2a 6c 65 6e | 6f 2c 20 2a 66 6c 61 67 |ni, *len|o, *flag|
|00005b40| 3b 0a 7b 0a 20 0a 09 2f | 2a 20 43 68 61 6e 67 65 |;.{. ../|* Change|
|00005b50| 20 74 68 65 20 68 61 6e | 64 6c 69 6e 67 20 6f 66 | the han|dling of|
|00005b60| 20 69 6e 70 75 74 20 61 | 6e 64 20 6f 75 74 70 75 | input a|nd outpu|
|00005b70| 74 20 73 74 72 69 6e 67 | 73 20 66 6f 72 20 61 6c |t string|s for al|
|00005b80| 6c 20 66 75 74 75 72 65 | 0a 09 20 20 20 73 65 71 |l future|.. seq|
|00005b90| 75 65 6e 74 69 61 6c 20 | 69 2f 6f 20 77 69 74 68 |uential |i/o with|
|00005ba0| 20 61 73 73 6f 63 69 61 | 74 65 64 20 66 69 6c 65 | associa|ted file|
|00005bb0| 20 64 65 73 63 72 69 70 | 74 6f 72 20 66 64 2e 20 | descrip|tor fd. |
|00005bc0| 41 6c 6c 6f 77 73 20 74 | 68 65 0a 09 20 20 20 75 |Allows t|he.. u|
|00005bd0| 73 65 72 20 74 6f 20 63 | 6f 6e 74 72 6f 6c 20 74 |ser to c|ontrol t|
|00005be0| 68 65 20 69 6e 70 75 74 | 20 72 65 63 6f 72 64 20 |he input| record |
|00005bf0| 6c 65 6e 67 74 68 2c 20 | 74 68 65 20 6f 75 74 70 |length, |the outp|
|00005c00| 75 74 20 72 65 63 6f 72 | 64 20 6c 65 6e 67 74 68 |ut recor|d length|
|00005c10| 2c 0a 09 20 20 20 61 6e | 64 20 74 68 65 20 62 61 |,.. an|d the ba|
|00005c20| 63 6b 73 70 61 63 65 20 | 70 72 6f 63 65 73 73 69 |ckspace |processi|
|00005c30| 6e 67 20 66 6f 72 20 65 | 61 63 68 20 63 68 61 6e |ng for e|ach chan|
|00005c40| 6e 65 6c 2e 20 42 61 63 | 6b 73 70 61 63 65 0a 09 |nel. Bac|kspace..|
|00005c50| 20 20 20 70 72 6f 63 65 | 73 73 69 6e 67 20 63 6f | proce|ssing co|
|00005c60| 6e 73 69 73 74 73 20 6f | 66 20 63 68 65 63 6b 69 |nsists o|f checki|
|00005c70| 6e 67 20 65 61 63 68 20 | 6c 69 6e 65 20 66 6f 72 |ng each |line for|
|00005c80| 20 62 61 63 6b 73 70 61 | 63 65 73 0a 09 20 20 20 | backspa|ces.. |
|00005c90| 61 6e 64 20 72 65 6d 6f | 76 69 6e 67 20 62 6f 74 |and remo|ving bot|
|00005ca0| 68 20 74 68 65 6d 20 61 | 6e 64 20 74 68 65 20 70 |h them a|nd the p|
|00005cb0| 72 65 63 65 64 69 6e 67 | 20 63 68 61 72 63 61 74 |receding| charcat|
|00005cc0| 65 72 2c 20 69 2e 65 2e | 20 74 72 65 61 74 69 6e |er, i.e.| treatin|
|00005cd0| 67 0a 09 20 20 20 74 68 | 65 6d 20 61 73 20 63 68 |g.. th|em as ch|
|00005ce0| 61 72 61 63 74 65 72 20 | 64 65 6c 65 74 65 73 2e |aracter |deletes.|
|00005cf0| 20 41 6e 79 20 69 6e 76 | 61 6c 69 64 20 61 72 67 | Any inv|alid arg|
|00005d00| 75 6d 65 6e 74 20 76 61 | 6c 75 65 73 20 61 72 65 |ument va|lues are|
|00005d10| 0a 09 20 20 20 69 67 6e | 6f 72 65 64 20 61 6e 64 |.. ign|ored and|
|00005d20| 20 72 65 73 75 6c 74 20 | 69 6e 20 6e 6f 20 63 68 | result |in no ch|
|00005d30| 61 6e 67 65 20 74 6f 20 | 74 68 61 74 20 70 61 72 |ange to |that par|
|00005d40| 61 6d 65 74 65 72 20 2a | 2f 0a 20 0a 09 20 20 20 |ameter *|/. .. |
|00005d50| 72 65 6d 61 72 6b 5f 28 | 22 52 6f 75 74 69 6e 65 |remark_(|"Routine|
|00005d60| 20 5a 43 4e 54 52 4c 20 | 6e 6f 74 20 69 6d 70 6c | ZCNTRL |not impl|
|00005d70| 65 6d 65 6e 74 65 64 20 | 69 6e 20 74 68 69 73 20 |emented |in this |
|00005d80| 76 65 72 73 69 6f 6e 20 | 6f 66 20 54 49 45 22 2c |version |of TIE",|
|00005d90| 35 33 4c 29 3b 0a 7d 0a | 20 0a 7a 63 72 64 69 72 |53L);.}.| .zcrdir|
|00005da0| 5f 28 6e 61 6d 65 29 0a | 69 6e 74 20 2a 6e 61 6d |_(name).|int *nam|
|00005db0| 65 3b 0a 7b 0a 20 0a 20 | 20 20 20 20 2f 2a 20 63 |e;.{. . | /* c|
|00005dc0| 72 65 61 74 65 20 61 20 | 6e 65 77 20 64 69 72 65 |reate a |new dire|
|00005dd0| 63 74 6f 72 79 20 77 69 | 74 68 20 6e 61 6d 65 20 |ctory wi|th name |
|00005de0| 6e 61 6d 65 20 69 6e 20 | 74 68 65 20 6c 6f 63 61 |name in |the loca|
|00005df0| 6c 20 64 69 72 65 63 74 | 6f 72 79 2e 0a 09 4e 6f |l direct|ory...No|
|00005e00| 20 70 61 74 68 20 6e 61 | 6d 65 73 20 61 72 65 20 | path na|mes are |
|00005e10| 61 6c 6c 6f 77 65 64 0a | 09 54 68 65 20 6e 61 6d |allowed.|.The nam|
|00005e20| 65 20 6e 61 6d 65 20 6d | 75 73 74 20 62 65 20 75 |e name m|ust be u|
|00005e30| 6e 69 71 75 65 20 69 6e | 20 74 68 69 73 20 64 69 |nique in| this di|
|00005e40| 72 65 63 74 6f 72 79 20 | 2a 2f 0a 20 0a 09 69 6e |rectory |*/. ..in|
|00005e50| 74 20 6d 6f 64 65 20 3d | 20 52 57 58 4d 4f 44 45 |t mode =| RWXMODE|
|00005e60| 3b 0a 09 63 68 61 72 20 | 63 68 61 72 6e 6d 31 5b |;..char |charnm1[|
|00005e70| 4d 41 58 50 41 54 48 5d | 3b 0a 09 73 74 72 75 63 |MAXPATH]|;..struc|
|00005e80| 74 20 66 69 6c 69 6e 66 | 6f 20 66 69 6e 66 3b 0a |t filinf|o finf;.|
|00005e90| 20 0a 09 2f 2a 20 63 72 | 65 61 74 65 20 63 68 61 | ../* cr|eate cha|
|00005ea0| 72 61 63 74 65 72 20 66 | 69 6c 65 20 6e 61 6d 65 |racter f|ile name|
|00005eb0| 20 61 6e 64 20 63 68 65 | 63 6b 20 69 74 20 69 73 | and che|ck it is|
|00005ec0| 20 61 20 73 69 6d 70 6c | 65 20 6e 61 6d 65 20 2a | a simpl|e name *|
|00005ed0| 2f 0a 09 69 73 74 63 68 | 72 5f 28 6e 61 6d 65 2c |/..istch|r_(name,|
|00005ee0| 20 63 68 61 72 6e 6d 31 | 29 3b 0a 09 69 66 20 28 | charnm1|);..if (|
|00005ef0| 69 73 61 6e 61 6d 65 28 | 63 68 61 72 6e 6d 31 29 |isaname(|charnm1)|
|00005f00| 20 3d 3d 20 4e 4f 29 20 | 72 65 74 75 72 6e 28 45 | == NO) |return(E|
|00005f10| 52 52 29 3b 0a 20 0a 09 | 2f 2a 20 67 65 6e 65 72 |RR);. ..|/* gener|
|00005f20| 61 74 65 20 66 75 6c 6c | 20 70 61 74 68 20 6e 61 |ate full| path na|
|00005f30| 6d 65 20 2a 2f 0a 09 6d | 6b 66 69 6c 6e 6d 28 6e |me */..m|kfilnm(n|
|00005f40| 61 6d 65 2c 63 68 61 72 | 6e 6d 31 2c 26 66 69 6e |ame,char|nm1,&fin|
|00005f50| 66 29 3b 0a 20 0a 09 2f | 2a 20 72 65 74 75 72 6e |f);. ../|* return|
|00005f60| 20 69 66 20 6e 61 6d 65 | 20 65 78 69 73 74 73 2c | if name| exists,|
|00005f70| 20 6e 61 6d 65 20 69 73 | 20 61 20 64 65 76 69 63 | name is| a devic|
|00005f80| 65 20 6f 72 20 6e 61 6d | 65 20 69 73 20 65 72 72 |e or nam|e is err|
|00005f90| 6f 6e 65 6f 75 73 20 2a | 2f 0a 20 69 66 20 28 66 |oneous *|/. if (f|
|00005fa0| 69 6e 66 2e 65 78 69 73 | 74 73 20 3d 3d 20 59 45 |inf.exis|ts == YE|
|00005fb0| 53 20 7c 7c 20 66 69 6e | 66 2e 66 74 79 70 65 31 |S || fin|f.ftype1|
|00005fc0| 20 3d 3d 20 44 45 56 49 | 43 45 20 7c 7c 20 66 69 | == DEVI|CE || fi|
|00005fd0| 6e 66 2e 66 74 79 70 65 | 31 20 3d 3d 20 45 52 52 |nf.ftype|1 == ERR|
|00005fe0| 29 0a 20 20 20 20 20 20 | 20 20 20 20 20 20 7b 0a |). | {.|
|00005ff0| 09 09 72 65 74 75 72 6e | 28 45 52 52 29 3b 0a 20 |..return|(ERR);. |
|00006000| 20 20 20 20 20 20 20 20 | 20 20 20 7d 0a 20 0a 09 | | }. ..|
|00006010| 2f 2a 20 73 79 73 74 65 | 6d 20 63 61 6c 6c 20 2a |/* syste|m call *|
|00006020| 2f 0a 09 69 66 20 28 6d | 6b 64 69 72 28 63 68 61 |/..if (m|kdir(cha|
|00006030| 72 6e 6d 31 2c 20 6d 6f | 64 65 29 20 3d 3d 20 2d |rnm1, mo|de) == -|
|00006040| 31 29 20 72 65 74 75 72 | 6e 28 45 52 52 29 3b 0a |1) retur|n(ERR);.|
|00006050| 20 0a 09 72 65 74 75 72 | 6e 28 4e 4f 45 52 52 29 | ..retur|n(NOERR)|
|00006060| 3b 0a 20 0a 7d 0a 20 0a | 7a 64 6c 64 69 72 5f 28 |;. .}. .|zdldir_(|
|00006070| 6e 61 6d 65 29 0a 69 6e | 74 20 2a 6e 61 6d 65 3b |name).in|t *name;|
|00006080| 0a 7b 0a 20 0a 20 20 20 | 20 20 2f 2a 20 64 65 6c |.{. . | /* del|
|00006090| 65 74 65 20 61 6e 20 65 | 6d 70 74 79 20 64 69 72 |ete an e|mpty dir|
|000060a0| 65 63 74 6f 72 79 20 77 | 69 74 68 20 6e 61 6d 65 |ectory w|ith name|
|000060b0| 20 6e 61 6d 65 20 69 6e | 20 74 68 65 20 6c 6f 63 | name in| the loc|
|000060c0| 61 6c 20 64 69 72 65 63 | 74 6f 72 79 2e 20 2a 2f |al direc|tory. */|
|000060d0| 0a 20 0a 09 63 68 61 72 | 20 63 68 61 72 6e 6d 31 |. ..char| charnm1|
|000060e0| 5b 4d 41 58 50 41 54 48 | 5d 3b 0a 09 73 74 72 75 |[MAXPATH|];..stru|
|000060f0| 63 74 20 66 69 6c 69 6e | 66 6f 20 66 69 6e 66 3b |ct filin|fo finf;|
|00006100| 0a 20 0a 09 2f 2a 20 63 | 72 65 61 74 65 20 63 68 |. ../* c|reate ch|
|00006110| 61 72 61 63 74 65 72 20 | 66 69 6c 65 20 6e 61 6d |aracter |file nam|
|00006120| 65 20 61 6e 64 20 63 68 | 65 63 6b 20 69 74 20 69 |e and ch|eck it i|
|00006130| 73 20 61 20 73 69 6d 70 | 6c 65 20 6e 61 6d 65 20 |s a simp|le name |
|00006140| 2a 2f 0a 09 69 73 74 63 | 68 72 5f 28 6e 61 6d 65 |*/..istc|hr_(name|
|00006150| 2c 20 63 68 61 72 6e 6d | 31 29 3b 0a 09 69 66 20 |, charnm|1);..if |
|00006160| 28 69 73 61 6e 61 6d 65 | 28 63 68 61 72 6e 6d 31 |(isaname|(charnm1|
|00006170| 29 20 3d 3d 20 4e 4f 29 | 20 72 65 74 75 72 6e 28 |) == NO)| return(|
|00006180| 45 52 52 29 3b 0a 20 0a | 09 2f 2a 20 67 65 6e 65 |ERR);. .|./* gene|
|00006190| 72 61 74 65 20 61 20 66 | 75 6c 6c 20 70 61 74 68 |rate a f|ull path|
|000061a0| 20 6e 61 6d 65 20 2a 2f | 0a 09 6d 6b 66 69 6c 6e | name */|..mkfiln|
|000061b0| 6d 28 6e 61 6d 65 2c 20 | 63 68 61 72 6e 6d 31 2c |m(name, |charnm1,|
|000061c0| 20 26 66 69 6e 66 29 3b | 0a 20 0a 09 2f 2a 20 72 | &finf);|. ../* r|
|000061d0| 65 74 75 72 6e 20 69 66 | 20 6e 6f 74 20 61 20 64 |eturn if| not a d|
|000061e0| 69 72 65 63 74 6f 72 79 | 20 2a 2f 0a 09 69 66 20 |irectory| */..if |
|000061f0| 28 66 69 6e 66 2e 73 75 | 62 74 79 70 65 20 21 3d |(finf.su|btype !=|
|00006200| 20 44 49 52 45 43 54 4f | 52 59 29 20 72 65 74 75 | DIRECTO|RY) retu|
|00006210| 72 6e 28 45 52 52 29 3b | 0a 20 0a 09 2f 2a 20 64 |rn(ERR);|. ../* d|
|00006220| 69 73 61 6c 6c 6f 77 20 | 64 65 6c 65 74 69 6f 6e |isallow |deletion|
|00006230| 20 6f 66 20 72 6f 6f 74 | 20 61 6e 64 20 72 6f 6f | of root| and roo|
|00006240| 74 2f 20 2a 2f 0a 09 69 | 66 20 28 73 74 72 63 6d |t/ */..i|f (strcm|
|00006250| 70 28 72 6f 6f 74 2c 20 | 63 68 61 72 6e 6d 31 29 |p(root, |charnm1)|
|00006260| 3d 3d 30 20 7c 7c 0a 09 | 20 20 20 20 73 74 72 63 |==0 ||..| strc|
|00006270| 6d 70 28 73 74 72 63 61 | 74 28 72 6f 6f 74 2c 22 |mp(strca|t(root,"|
|00006280| 2f 22 29 2c 20 63 68 61 | 72 6e 6d 31 29 3d 3d 30 |/"), cha|rnm1)==0|
|00006290| 20 29 20 72 65 74 75 72 | 6e 28 45 52 52 29 3b 0a | ) retur|n(ERR);.|
|000062a0| 20 0a 09 2f 2a 20 73 79 | 73 74 65 6d 20 63 61 6c | ../* sy|stem cal|
|000062b0| 6c 20 2a 2f 0a 09 69 66 | 20 28 72 6d 64 69 72 28 |l */..if| (rmdir(|
|000062c0| 63 68 61 72 6e 6d 31 29 | 20 3d 3d 20 2d 31 29 20 |charnm1)| == -1) |
|000062d0| 72 65 74 75 72 6e 28 45 | 52 52 29 3b 0a 20 0a 09 |return(E|RR);. ..|
|000062e0| 72 65 74 75 72 6e 28 4e | 4f 45 52 52 29 3b 0a 20 |return(N|OERR);. |
|000062f0| 0a 7d 0a 20 0a 7a 66 74 | 79 70 65 5f 28 6e 61 6d |.}. .zft|ype_(nam|
|00006300| 65 2c 20 73 65 71 75 65 | 6e 29 0a 69 6e 74 20 2a |e, seque|n).int *|
|00006310| 6e 61 6d 65 2c 20 2a 73 | 65 71 75 65 6e 3b 0a 7b |name, *s|equen;.{|
|00006320| 0a 20 0a 09 2f 2a 20 44 | 69 73 63 6f 76 65 72 20 |. ../* D|iscover |
|00006330| 74 68 65 20 74 79 70 65 | 20 6f 66 20 74 68 65 20 |the type| of the |
|00006340| 65 6e 74 69 74 79 20 77 | 69 74 68 20 74 68 65 20 |entity w|ith the |
|00006350| 70 61 74 68 6e 61 6d 65 | 20 6e 61 6d 65 2e 0a 09 |pathname| name...|
|00006360| 20 20 20 54 68 69 73 20 | 72 6f 75 74 69 6e 65 20 | This |routine |
|00006370| 72 65 74 75 72 6e 73 20 | 45 52 52 20 28 66 69 6c |returns |ERR (fil|
|00006380| 65 20 64 6f 65 73 20 6e | 6f 74 20 65 78 69 73 74 |e does n|ot exist|
|00006390| 20 6f 72 20 69 6c 6c 65 | 67 61 6c 0a 09 20 20 20 | or ille|gal.. |
|000063a0| 66 69 6c 65 20 6e 61 6d | 65 29 2c 20 68 6f 73 74 |file nam|e), host|
|000063b0| 2c 20 64 65 76 69 63 65 | 20 28 70 72 65 63 6f 6e |, device| (precon|
|000063c0| 6e 65 63 74 65 64 20 75 | 6e 69 74 29 2c 20 70 6c |nected u|nit), pl|
|000063d0| 61 69 6e 0a 09 20 20 20 | 28 76 66 73 20 66 69 6c |ain.. |(vfs fil|
|000063e0| 65 29 20 6f 72 20 64 69 | 72 65 63 74 6f 72 79 20 |e) or di|rectory |
|000063f0| 28 76 66 73 20 64 69 72 | 65 63 74 6f 72 79 29 20 |(vfs dir|ectory) |
+--------+-------------------------+-------------------------+--------+--------+
Only 25.0 KB of data is shown above.