Ñèñòåìíîå ïðîãðàììèðîâàíèå â UNIX ñðåäñòâàìè Free Pascal

       

Ïðèëîæåíèå Ìîäóëü stdio


Íàçíà÷åíèå ìîäóëÿ – âîñïîëíèòü íåäîñòàòîê ñðåäñòâ ïðèêëàäíîãî è ñèñòåìíîãî ïðîãðàììèðîâàíèÿ íà ÿçûêå Ïàñêàëü àíàëîãè÷íûìè ñðåäñòâàìè áèáëèîòåê ÿçûêà Ñè.

unit stdio;

{$mode objfpc}

interface

(* A streammarker remembers a position in a buffer. *)

uses linux,sockets;

const

  EOF=-1;         (* ïðèçíàê êîíöà ôàéëà äëÿ stdio *)

 

  WCOREFLAG=$80;  (* ôëàã ñáðîñà äàìïà ïàìÿòè *)

 

  (* Ðàçìåð áóôåðà äëÿ ÷òåíèÿ è çàïèñè *)

  BUFSIZ=8192;



  NULL=nil;     

  _IOFBF=0;  (* setvbuf should set fully buffered *)

  _IOLBF=1;  (* setvbuf should set line buffered *)

  _IONBF=2;  (* setvbuf should set unbuffered *)

  MAX_INPUT=255;  (* size of the type-ahead buffer *)

 

  _SIGSET_NWORDS=1024 div (8 * sizeof (longint)); (* sizeof(sigset_t) *)

 

  (* ôëàãè äëÿ pathconf/fpathconf *)

  (* returns  the maximum number of links to the file.  If filedes or

   * path refer to a directory, then the value applies to  the  whole

   * directory.

   *)

  _PC_LINK_MAX=0;

  (* returns  the  maximum  length  of  a formatted input line, where

   * filedes or path must refer to  a  terminal.

   *)

  _PC_MAX_CANON=1;

  (* returns  the  maximum  length of an input line, where filedes or

   * path must refer to  a  terminal.

   *)

  _PC_MAX_INPUT=2;

  (* returns  the  maximum length of a filename in the directory path

   * or filedes.  the process is allowed to create.

   *)

  _PC_NAME_MAX=3;

  (* returns  the  maximum length of a relative pathname when path or

   * filedes is the current  working  directory.

   *)

  _PC_PATH_MAX=4;

  (* returns the size of the pipe buffer, where filedes must refer to

   * a pipe or FIFO and path must refer to a FIFO.

   *)

  _PC_PIPE_BUF=5;

  (* returns  nonzero  if  the  chown(2) call may not be used on this

   * file.  If filedes or  path  refer  to  a  directory,  then  this

   * applies to all files in that directory.

   *)

  _PC_CHOWN_RESTRICTED=6;

  (* returns   nonzero   if   accessing   filenames    longer    than




àà * _POSIX_NAME_MAXà generates an error.

àà *)

à _PC_NO_TRUNC=7;

à (* returns nonzero if special character processing can be disabled,

àà * where filedes or path must refer to a terminal.

àà *)

à _PC_VDISABLE=8;

à _PC_SYNC_IO=9;

à _PC_ASYNC_IO=10;

à _PC_PRIO_IO=11;

à _PC_SOCK_MAXBUF=12;

à _PC_FILESIZEBITS=13;

à _PC_REC_INCR_XFER_SIZE=14;

à _PC_REC_MAX_XFER_SIZE=15;

à _PC_REC_MIN_XFER_SIZE=16;

à _PC_REC_XFER_ALIGN=17;

à _PC_ALLOC_SIZE_MIN=18;

à _PC_SYMLINK_MAX=19;

à (* For posix fcntl() and `l_type' field of a `struct flock' for lockf().à *)

à F_RDLCK=0;àààààà (* Read lock.à *)

à F_WRLCK=1;ààà ààà(* Write lock.à *)

à F_UNLCK=2;àààààà (* Remove lock.à *)

à F_DUPFD=0;àààààà (* Duplicate fildes *)

à (* Constants for ulimit *)

à UL_GETFSIZE=1;ààààà (* òþ÷ò¨ð•ðõª º¸ªðýþòûõýýþõ þó¨ðýø¢õýøõ ýð ¨ð÷üõ¨

àààààààààààààààààààààààà ¯ðùûð (ò ñûþúð¿ ÿþ 512 ñðùª) *)

à UL_SETFSIZE=2;ààààà (* º¸ªðýðòûøòðõª ÿ¨õôõû¹ývù ¨ð÷üõ¨ ¯ðùûð *)

à __UL_GETMAXBRK=3;àà (* òþ÷ò¨ð•ðõª üðú¸øüðû¹ýþ òþ÷üþöývù ðô¨õ¸ ¸õóüõýªð ôðýýv¿ *)

à __UL_GETOPENMAX=4;à (* òþ÷ò¨ð•ðõª üðú¸øüðû¹ýþõ úþûø¢õ¸ªòþ ¯ðùûþò, úþªþ¨þõ

àààààààààààààààààààààààà ÿ¨þ¡õ¸¸ üþöõª þªú¨vª¹ *)

à FD_SETSIZE=64;

à

à (* Macros used as `request' argument to `ioctl'.à *)

à __SID=byte('S') shl 8;

à I_NREADàààà =__SID or 1;à (* Counts the number of data bytes in the data

àààààààààààààààààààààààààààààà block in the first message.à *)

à I_PUSHààààà =__SID or 2;à (* Push STREAMS module onto top of the current

àààààààààààààààààààààààààààààà STREAM, just below the STREAM head.à *)

à I_POPàààààà =__SID or 3;à (* Remove STREAMS module from just below the

àààààààààààààààààààààààààààààà STREAM head.à *)

à I_LOOKààààà =__SID or 4;à (* Retrieve the name of the module just below

àààààààààààààààààààààààààààààà the STREAM head and place it in a character

àààààààààààààààààààààààààààààà string.à *)

à I_FLUSHàààà =__SID or 5;à (* Flush all input and/or output.à *)

à I_SRDOPTààà =__SID or 6;à (* Sets the read mode.à *)



à I_GRDOPTààà =__SID or 7;à (* Returns the current read mode setting.à *)

à I_STRàààààà =__SID or 8;à (* Construct an internal STREAMS `ioctl'

àààààààààààààààààààààààààààààà message and send that message downstream. *)

à I_SETSIGààà =__SID or 9;à (* Inform the STREAM head that the process

ààààààààààààààààààà àààààààààààwants the SIGPOLL signal issued.à *)

à I_GETSIGààà =__SID or 10; (* Return the events for which the calling

àààààààààààààààààààààààààààààà process is currently registered to be sent

àààààààààààààààààààààààààààààà a SIGPOLL signal.à *)

à I_FINDà àààà=__SID or 11; (* Compares the names of all modules currently

àààààààààààààààààààààààààààààà present in the STREAM to the name pointed to

àààààààààààààààààààààààààààààà by `arg'.à *)

à I_LINKààààà =__SID or 12; (* Connect two STREAMs.à *)

à I_UNLINKààà =__SID or 13; (* Disconnects the two STREAMs.à *)

à I_PEEKààààà =__SID or 15; (* Allows a process to retrieve the information

àààààààààààààààààààààààààààààà in the first message on the STREAM head read

àààààààààààààààààààààààààààààà queue without taking the message off the

àààààààààààààààààààààààààààààà queue.à *)

à I_FDINSERTà =__SID or 16; (* Create a message from the specifiedààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààà

àààààààààààààààààààààààààààààà buffer(s), adds information about anotheràààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààà

àààààààààààààààààààààààààààààà STREAM, and send the message downstream.à *)

à I_SENDFDààà =__SID or 17; (* Requests the STREAM associated with `fildes'

àààààààààààààààààààààààààààààà to send a message, containing a file

àààààààààààààààààààààààààààààà pointer, to the STREAM head at the other end

àààààààààààààààà ààààààààààààààof a STREAMS pipe.à *)

à I_RECVFDààà =__SID or 14; (* Non-EFT definition.à *)

à I_SWROPTààà =__SID or 19; (* Set the write mode.à *)



à I_GWROPTààà =__SID or 20; (* Return the current write mode setting.à *)

à I_LISTààààà =__SID or 21; (* List all the module names on the STREAM, up

àààààààààààààààààààààààààààààà to and including the topmost driver name. *)

à I_PLINKàààà =__SID or 22; (* Connect two STREAMs with a persistent

ààààààààààààààààààààààààààààààà link.à *)

à I_PUNLINKàà =__SID or 23; (* Disconnect the two STREAMs that were

àààààààààààààààààààààààààààààà connected with a persistent link.à *)

à I_FLUSHBAND =__SID or 28; (* Flush only band specified.à *)

à I_CKBANDààà =__SID or 29; (* Check if the message of a given priority

ààààààààààààà àààààààààààààààààband exists on the STREAM head read

àààààààààààààààààààààààààààààà queue.à *)

à I_GETBANDàà =__SID or 30; (* Return the priority band of the first

àààààààààààààààààààààààààààààà message on the STREAM head read queue.à *)

à I_ATMARKààà =__SID or 31; (* See if the current message on the STREAM

àààààààààààààààààààààààààààààà head read queue is "marked" by some module

àààààààààààààààààààààààààààààà downstream.à *)

à I_SETCLTIME =__SID or 32; (* Set the time the STREAM head will delay when

àààà ààààààààààààààààààààààààààa STREAM is closing and there is data on

àààààààààààààààààààààààààààààà the write queues.à *)

à I_GETCLTIME =__SID or 33; (* Get current value for closing timeout.à *)

à I_CANPUTààà =__SID or 34; (* Check if a certain band is writable.à *)

à (* ôû  øýªõ¨¯õù¸ð ¸þúõªþò *)à

à INADDR_ANY=0;

à { Maximum queue length specificable by listen.àà }

à SOMAXCONN = 5;

à { Flags we can use with send/ and recv.à }

à { process out-of-band dataà }

à MSG_OOB = $1;

à { peek at incoming messageà }

ààMSG_PEEK = $2;

à { send without using routing tablesà }

à MSG_DONTROUTE = $4;

à { Setsockoptions(2) level. Thanks to BSD these must match IPPROTO_xxxà }

à SOL_IP = 0;

à SOL_IPX = 256;

à SOL_AX25 = 257;

à SOL_ATALK = 258;

à SOL_NETROM = 259;

à SOL_TCP = 6;

à SOL_UDP = 17;

à { IP optionsà }

à IPTOS_LOWDELAY = $10;



à IPTOS_THROUGHPUT = $08;

à IPTOS_RELIABILITY = $04;

à { These need to appear somewhere around hereà }

à IP_DEFAULT_MULTICAST_TTL = 1;

à IP_DEFAULT_MULTICAST_LOOP = 1;

à IP_MAX_MEMBERSHIPS = 20;

à { IP options for use with WinSockà }

à IP_OPTIONS = 1;

à IP_MULTICAST_IF = 2;

à IP_MULTICAST_TTL = 3;

à IP_MULTICAST_LOOP = 4;

à IP_ADD_MEMBERSHIP = 5;

à IP_DROP_MEMBERSHIP = 6;

à IP_TTL = 7;

à IP_TOS = 8;

à IP_DONTFRAGMENT = 9;

à { IPX optionsà }

à IPX_TYPE = 1;

à { TCP options }

à TCP_NODELAY = $0001;

à TCP_MAXSEG = 2;

à { The various priorities.à }

à SOPRI_INTERACTIVE = 0;

à SOPRI_NORMAL = 1;

à SOPRI_BACKGROUND = 2;

à (* ºÿ¨ðòûõýøõ ªõ¨üøýðûþü *)

à TCOOFF = 0;

à TCOON = 1;

à TCIOFF = 2;

à TCION = 3;

à TCGETA = 5;

à TCSETA = 6;

à TCSETAW = 7;

à TCSETAF = 8;

à TCIFLUSH = 0;

à TCOFLUSH = 1;

à TCIOFLUSH = 2;

à TCFLSH = 3;

à TCSAFLUSH = 1;

à TCSANOW = 2;

à TCSADRAIN = 3;

à TCSADFLUSH = 4;

à TIOCPKT = 6;

à TIOCPKT_DATA = 0;

à TIOCPKT_FLUSHREAD = 1;

à TIOCPKT_FLUSHWRITE = 2;

à TIOCPKT_STOP = 4;

à TIOCPKT_START = 8;

à TIOCPKT_NOSTOP = 16;

à TIOCPKT_DOSTOP = 32;

à { To be compatible with socket versionà }

à FIONBIO = $8004667e;

à { iflag bitsà }

à IGNBRK = $00001;

à BRKINT = $00002;

à IGNPAR = $00004;

à IMAXBEL = $00008;

à INPCK = $00010;

à ISTRIP = $00020;

à INLCR = $00040;

à IGNCR = $00080;

à ICRNL = $00100;

à IXON = $00400;

à IXOFF = $01000;

à IUCLC = $04000;

à IXANY = $08000;

à PARMRK = $10000;

à { oflag bitsà }

à OPOST = $00001;

à OLCUC = $00002;

à OCRNL = $00004;

à ONLCR = $00008;

à ONOCR = $00010;

à ONLRET = $00020;

à OFILL = $00040;

à CRDLY = $00180;

à CR0 = $00000;

à CR1 = $00080;

à CR2 = $00100;

à CR3 = $00180;

à NLDLY = $00200;

à NL0 = $00000;

à NL1 = $00200;

à BSDLY = $00400;

à BS0 = $00000;

à BS1 = $00400;

à TABDLY = $01800;

à TAB0 = $00000;

à TAB1 = $00800;

à TAB2 = $01000;

à TAB3 = $01800;

à XTABS = $01800;

à VTDLY = $02000;

à VT0 = $00000;

à VT1 = $02000;



à FFDLY = $04000;

à FF0 = $00000;

à FF1 = $04000;

à OFDEL = $08000;

à { cflag bitsà }

à { Baud rate values.à These must fit in speed_t, which is unsigned

à char.à See also the extended baud rates below.à These baud rates

à set an additional bit.à }

à CBAUD = $0100f;

à B0 = $00000;

à B50 = $00001;

à B75 = $00002;

à B110 = $00003;

à B134 = $00004;

à B150 = $00005;

à B200 = $00006;

à B300 = $00007;

à B600 = $00008;

à B1200 = $00009;

à B1800 = $0000a;

à B2400 = $0000b;

à B4800 = $0000c;

à B9600 = $0000d;

à B19200 = $0000e;

à B38400 = $0000f;

à CSIZE = $00030;

à CS5 = $00000;

à CS6 = $00010;

à CS7 = $00020;

à CS8 = $00030;

à CSTOPB = $00040;

à CREAD = $00080;

à PARENB = $00100;

à PARODD = $00200;

à HUPCL = $00400;

à CLOCAL = $00800;

à CBAUDEX = $0100f;

à B57600 = $01001;

ààB115200 = $01002;

à B128000 = $01003;

à B256000 = $01003;

à CRTSXOFF = $04000;

à CRTSCTS = $08000;

à { lflag bitsà }

à ISIG = $0001;

à ICANON = $0002;

à ECHO = $0004;

à ECHOE = $0008;

à ECHOK = $0010;

à ECHONL = $0020;

à NOFLSH = $0040;

à TOSTOP = $0080;

à IEXTEN = $0100;

à FLUSHO = $0200;

à ECHOKE = $0400;

à ECHOCTL = $0800;

à VDISCARD = 1;

à VEOL = 2;

à VEOL2 = 3;

à VEOF = 4;

à VERASE = 5;

à VINTR = 6;

à VKILL = 7;

à VLNEXT = 8;

à VMIN = 9;

à VQUIT = 10;

à VREPRINT = 11;

à VSTART = 12;

à VSTOP = 13;

à VSUSP = 14;

à VSWTC = 15;

à VTIME = 16;

à VWERASE = 17;

à CNUL = 0;

à CDEL = $0007f;

à CESC = byte('\');

à CINTR = byte('C') and $1f;

à CQUIT = $0001c;

à CERASE = byte('H') and $1f;

à CKILL = byte('U') and $1f;

à CEOT = byte('D') and $1f;

à CEOL = 0;

à CEOL2 = 0;

à CEOF = byte('D') and $1f;

à CSTART = byte('Q') and $1f;

à CSTOP = byte('S') and $1f;

à CSWTCH = $0001a;

à NSWTCH = 0;

à CSUSP = byte('Z') and $1f;

à CDSUSP = byte('Y') and $1f;

à CRPRNT = byte('R') and $1f;

à CFLUSH = byte('O') and $1f;

à CWERASE = byte('W') and $1f;

à CLNEXT = byte('V') and $1f;

ààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààà ààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààà



à

type PFILE=^TFILE;

_IO_marker=record

à next:^_IO_marker;

à sbuf:PFILE;

à _pos:integer;

end;

P_IO_marker=^_IO_marker;

ppchar=^pchar;

pinteger=^integer;

plongint=^longint;

sigset_t=record

à __val:array [0.._SIGSET_NWORDS-1] of longint;

end;

psigset_t=^sigset_t;

__jmp_buf=array [0..5] of longint;

__jmp_buf_tag=record

à __jmpbuf:__jmp_buf;àààààààààààààà (* Calling environment.à *)

à __mask_was_saved:longint;àààààààà (* Saved the signal mask?à *)

à __saved_mask:sigset_t;ààààààààààààà (* Saved signal mask.à *)

end;

jmp_buf=array [0..0] of __jmp_buf_tag;

sigjmp_buf=jmp_buf;

flockrec=record

à l_type:word;àààà (* Type of lock: F_RDLCK, F_WRLCK, or F_UNLCK.à *)

à l_whence:word;àà (* Where `l_start' is relative to (like `lseek').à *)

à l_start:longint;ààà (* Offset where the lock begins.à *)

à l_len:longint;ààààà (* Size of the locked area; zero means until EOF.à *)

à l_pid:longint;ààààà (* Process holding the lock.à *)

end;

(* ôû  øýªõ¨¯õù¸ð ¸þúõªþò *)

in_addr=record

à s_addr:cardinal;

end;

pin_addr=^in_addr;

in_addr_t=cardinal;

(* ôû  ¨ðñþªv ¸þ ò¨õüõýõü *)

tm=record

à tm_sec:longint;àààààààà (* seconds *)

à tm_min:longint;àààààààà (* minutes *)

à tm_hour:longint;ààààààà (* hours *)

à tm_mday:longint;ààààààà (* day of the month *)

à tm_mon:longint;àààààààà (* month *)

à tm_year:longint;ààààààà (* year *)

à tm_wday:longint;ààààààà (* day of the week *)

à tm_yday:longint;ààààààà (* day in the year *)

à tm_isdst:longint;àààààà (* daylight saving time *)

end;

ptm=^tm;

TFILE=record

à _flags:integer;ààààà (* High-order word is _IO_MAGIC; rest is flags. *)

à (* The following pointers correspond to the C++ streambuf protocol. *)

à (* Note:à Tk uses the _IO_read_ptr and _IO_read_end fields directly. *)

à _IO_read_ptr:pchar;àà (* Current read pointer *)

à _IO_read_end:pchar;àà (* End of get area. *)

à _IO_read_base:pchar;à (* Start of putback+get area. *)



à _IO_write_base:pchar; (* Start of put area. *)

à _IO_write_ptr:pchar;à (* Current put pointer. *)

à _IO_write_end:pchar;à (* End of put area. *)

à _IO_buf_base:pchar;àà (* Start of reserve area. *)

à _IO_buf_end:pchar;ààà (* End of reserve area. *)

à (* The following fields are used to support backing up and undo. *)

à _IO_save_base:pchar; (* Pointer to start of non-current get area. *)

à _IO_backup_base:pchar;à (* Pointer to first valid character of backup area *)

à _IO_save_end:pchar; (* Pointer to end of non-current get area. *)

à _markers:P_IO_marker;

à _chain:^TFILE;

à _fileno:integer;

à _blksize:integer;

à _old_offset:longint; (* This used to be _offset but it's too small.à *)

à _cur_column:word;

à _vtable_offset:byte;

à _shortbuf:array[1..1]of char;

à _lock:pointer;

end;

var

à stdin,stdout:pfile;

function tmpfile:pfile;cdecl;external 'c';

(* Generate a temporary filename.à *)

function tmpnam(__s:pchar):pchar;cdecl;external 'c';

(* Close STREAM.à *)

function fclose(__stream:pfile):integer;cdecl;external 'c';

(* Flush STREAM, or all streams if STREAM is NULL.à *)

function fflush (__stream:pfile):integer;cdecl;external 'c';

(* Close all streams.à *)

function fcloseall:integer;cdecl;external 'c';

(* Open a file and create a new stream for it.à *)

function fopen(fname:pchar;mode:pchar):pfile;cdecl;external 'c';

(* Open a file by fd and create a new stream for it.à *)

function fdopen(fildes:longint;mode:pchar):pfile;cdecl;external 'c';

à

(* Open a file, replacing an existing stream with it. *)

function freopen (_filename:pchar;__modes:pchar;__stream:pfile):pfile;cdecl;external 'c';

(* Create a new stream that refers to a memory buffer.à *)

function fmemopen(__s:pointer;__len:longint;__modes:pchar):pfile;cdecl;external 'c';

(* Open a stream that writes into a malloc'd buffer that is expanded as

àà necessary.à *BUFLOC and *SIZELOC are updated with the buffer's location



àà and the number of characters written on fflush or fclose.à *)

function open_memstream(__bufloc:ppchar;__sizeloc:plongint):pfile;cdecl;external 'c';

(* If BUF is NULL, make STREAM unbuffered.

àà Else make it use buffer BUF, of size BUFSIZ.à *)

procedure setbuf(__stream:pfile;__buf:pchar);cdecl;external 'c';

(* Make STREAM use buffering mode MODE.

àà If BUF is not NULL, use N bytes of it for buffering;

àà else allocate an internal buffer N bytes long.à *)

function setvbuf(__stream:pfile;__buf:pchar;

àààààààààààààààà __modes:longint;__n:longint):integer;cdecl;external 'c';

(* If BUF is NULL, make STREAM unbuffered.

àà Else make it use SIZE bytes of BUF for buffering.à *)

procedure setbuffer(__stream:pfile;__buf:pchar;

àààààààààà ààà __size:longint);cdecl;external 'c';

(* Make STREAM line-buffered.à *)

procedure setlinebuf(__stream:pfile);cdecl;external 'c';

(* Write formatted output to STREAM.à *)

function fprintf(__stream:pfile;fm:pchar;args:array of const):integer;cdecl;external 'c';

(* Write formatted output to stdout.à *)

function printf(fm:pchar;args:array of const):integer;cdecl;external 'c';

(* Write formatted output to S.à *)

function sprintf(__s:pchar;fm:pchar;args:array of const):integer;cdecl;external 'c';

(* Read formatted input from STREAM.à *)

function fscanf(__stream:pfile;fm:pchar;args:array of const):integer;cdecl;external 'c';

(* Read formatted input from stdin.à *)

function scanf(fm:pchar;args:array of const):integer;cdecl;external 'c';

(* Read formatted input from S.à *)

function sscanf(s:pchar;fm:pchar;args:array of const):integer;cdecl;external 'c';

(* Read a character from STREAM.à *)

function fgetc(__stream:pfile):integer;cdecl;external 'c';

function getc(__stream:pfile):integer;cdecl;external 'c';

(* Read a character from stdin.à *)

function getchar:integer;cdecl;external 'c';

(* These are defined in POSIX.1:1996.à *)



function getc_unlocked(__stream:pfile):integer;cdecl;external 'c';

function getchar_unlocked:integer;cdecl;external 'c';

(* Faster version when locking is not necessary.à *)

function fgetc_unlocked(__stream:pfile):integer;cdecl;external 'c';

(* Write a character to STREAM.à *)

function fputc(__c:integer;__stream:pfile):integer;cdecl;external 'c';

function putc(__c:integer;__stream:pfile):integer;cdecl;external 'c';

(* Write a character to stdout.à *)

function putchar(__c:integer):integer;cdecl;external 'c';

(* Faster version when locking is not necessary.à *)

function fputc_unlocked(__c:integer;__stream:pfile):integer;cdecl;external 'c';

(* These are defined in POSIX.1:1996.à *)

function putc_unlocked(__c:integer;__stream:pfile):integer;cdecl;external 'c';

function putchar_unlocked(__c:integer):integer;cdecl;external 'c';

(* Get a word (int) from STREAM.à *)

function getw(__stream:pfile):integer;cdecl;external 'c';

(* Write a word (int) to STREAM.à *)

function putw(__w:integer;__stream:pfile):integer;cdecl;external 'c';

(* Get a newline-terminated string of finite length from STREAM.à *)

function fgets(__s:pchar;__n:integer;__stream:pfile):pchar;cdecl;external 'c';

(* This function does the same as `fgets' but does not lock the stream.à *)

function fgets_unlocked(__s:pchar;__n:integer;__stream:pfile):pchar;cdecl;external 'c';

(* Get a newline-terminated string from stdin, removing the newline.

àà DO NOT USE THIS FUNCTION!!à There is no limit on how much it will read.à *)

function gets(__s:pchar):pchar;cdecl;external 'c';

(* Read up to (and including) a DELIMITER from STREAM into *LINEPTR

àà (and null-terminate it). *LINEPTR is a pointer returned from malloc (or

àà NULL), pointing to *N characters of space.à It is realloc'd as

àà necessary.à Returns the number of characters read (not including the

àà null terminator), or -1 on error or EOF.à *)

function __getdelim(__lineptr:ppchar;__n:plongint;__delimiter:integer;



ààààààààààààààà àààààà __stream:pfile):integer;cdecl;external 'c';

function getdelim(__lineptr:ppchar;__n:plongint;__delimiter:integer;

ààààààààààààààà àààààà __stream:pfile):integer;cdecl;external 'c';

(* Like `getdelim', but reads up to a newline.à *)

function getline(__lineptr:ppchar;__n:plongint;

àààààààààà àààà àààààà __stream:pfile):integer;cdecl;external 'c';

(* Write a string to STREAM.à *)

function fputs(__s:pchar;__stream:pfile):integer;cdecl;external 'c';

(* This function does the same as `fputs' but does not lock the stream.à *)

function fputs_unlocked(__s:pchar;__stream:pfile):integer;cdecl;external 'c';

(* Write a string, followed by a newline, to stdout.à *)

function puts(__s:pchar):integer;cdecl;external 'c';

(* Push a character back onto the input buffer of STREAM.à *)

function ungetc(__c:integer;__stream:pfile):integer;cdecl;external 'c';

(* Read chunks of generic data from STREAM.à *)

function fread(__ptr:pointer;__size, n:longint;

àààààààààà àààà __stream:pfile):longint;cdecl;external 'c';

àààààààààà àààà

(* Write chunks of generic data to STREAM.à *)

function fwrite(__ptr:pointer;__size, n:longint;

àààààààààà àààà __stream:pfile):longint;cdecl;external 'c';

(* Faster versions when locking is not necessary.à *)

function fread_unlocked(__ptr:pointer;__size, n:longint;

àààààààààà àààà __stream:pfile):longint;cdecl;external 'c';

function fwrite_unlocked(__ptr:pointer;__size, n:longint;

àààààààààà àààà __stream:pfile):longint;cdecl;external 'c';

(* Seek to a certain position on STREAM.à *)

function fseek(__stream:pfile;__off:longint;__whence:integer):longint;cdecl;external 'c';

(* Return the current position of STREAM.à *)

function ftell(__stream:pfile):longint;cdecl;external 'c';

(* Rewind to the beginning of STREAM.à *)

procedure rewind(__stream:pfile);cdecl;external 'c';

(* Clear the error and EOF indicators for STREAM.à *)

procedure clearerr(__stream:pfile);cdecl;external 'c';



(* Return the EOF indicator for STREAM.à *)

function feof(__stream:pfile):integer;cdecl;external 'c';

(* Return the error indicator for STREAM.à *)

function ferror(__stream:pfile):integer;cdecl;external 'c';

(* Faster versions when locking is not required.à *)

procedure clearerr_unlocked(__stream:pfile);cdecl;external 'c';

function feof_unlocked(__stream:pfile):integer;cdecl;external 'c';

function ferror_unlocked(__stream:pfile):integer;cdecl;external 'c';

(* Print a message describing the meaning of the value of errno.à *)

procedure perror(__s:pchar);cdecl;external 'c';

(* Return the system file descriptor for STREAM.à *)

function fileno(__stream:pfile):longint;cdecl;external 'c';

(* Faster version when locking is not required.à *)

function fileno_unlocked(__stream:pfile):integer;cdecl;external 'c';

(* Create a new stream connected to a pipe running the given command.à *)

function pipeopen(__command, __modes:pchar):pfile;cdecl;external 'c' name 'popen';

(* Close a stream opened by popen and return the status of its child.à *)

function pipeclose (__stream:pfile):integer;cdecl;external 'c' name 'pclose';

(* Return the name of the controlling terminal.à *)

function ctermid(__s:pchar):pchar;cdecl;external 'c';

(* Return the name of the current user.à *)

function cuserid(__s:pchar):pchar;cdecl;external 'c';

(* Acquire ownership of STREAM.à *)

procedure flockfile(__stream:pfile);cdecl;external 'c';

(* Try to acquire ownership of STREAM but do not block if it is not

àà possible.à *)

function ftrylockfile(__stream:pfile):integer;cdecl;external 'c';

(* Relinquish the ownership granted for STREAM.à *)

procedure funlockfile(__stream:pfile);cdecl;external 'c';

(* ¸þ÷ôðýøõ ¯ðùûð *)

function fdCreat(PathName:Pchar;mode:longint):longint;cdecl;external 'c' name 'creat';

(* "ÿõ¨õüþªúð" ºúð÷ðªõû  ýð ÿõ¨òvù ¤ûõüõýª úðªðûþóð *)



procedure rewinddir(dp:pdir);cdecl;external 'c';

(* þöøôðýøõ ÷ðòõ¨°õýø  ÿ¨þ¡õ¸¸ð *)

function wait(__stat_loc:pinteger):longint;cdecl;external 'c';

(* ¯ºýú¡øø ôû  ¸þ÷ôðýø  ýþòþóþ ÿ¨þ¡õ¸¸ð ¸ ÿõ¨õüõýývü ¢ø¸ûþü ÿð¨ðüõª¨þò *)

function linuxexecl(path:pchar;arg0:pchar;args:array of const):integer;cdecl;external 'c' name 'execl';

function linuxexeclp(filename:pchar;arg0:pchar;args:array of const):integer;cdecl;external 'c' name 'execlp';

(* ¯ºýú¡øø ôû  þÿ¨õôõûõýø  ¸þ¸ªþ ýø  ÷ðòõ¨°õýø  ÿ¨þ¡õ¸¸ð *)

function WEXITSTATUS(status:integer):integer;

function WSTOPSIG(status:integer):integer;

function WTERMSIG(status:integer):integer;

function WCOREDUMP(status:integer):boolean;

function WIFEXITED(status:integer):boolean;

function WIFSIGNALED(status:integer):boolean;

function WIFSTOPPED(status:integer):boolean;

(* ÿ¨øþ¸ªðýðòûøòðõª ªõúº•øù ÿ¨þ¡õ¸¸ ýð ÷ðôðýýþõ úþûø¢õ¸ªòþ ¸õúºýô *)

function sleep(seconds:word):word;cdecl;external 'c';

(* ºôðû õª ò¸õ ¸øóýðûv ø÷ ýðñþ¨ð ¸øóýðûþòà *)

function sigemptyset(__set:psigset_t):integer;cdecl;external 'c';

(* º¸ªðýðòûøòðõª ò¸õ ¸øóýðûv ò ýðñþ¨õ ¸øóýðûþòà *)

function sigfillset(__set:psigset_t):integer;cdecl;external 'c';

(* ôþñðòû õª ¸øóýðû SIGNO ò ýðñþ¨ ¸øóýðûþò *)

function sigaddset(__set:psigset_t;__signo:integer):integer;cdecl;external 'c';

(* ºôðû õª ¸øóýðû SIGNO ø÷ ýðñþ¨ð ¸øóýðûþò *)

function sigdelset(__set:psigset_t;__signo:integer):integer;cdecl;external 'c';

(* òþ÷ò¨ð•ðõª ø¸ªøýº, õ¸ûø SIGNO ò ýðñþ¨õ, ø ûþö¹ ò ÿ¨þªøòýþü ¸ûº¢ðõ *)

function sigismember(__set:psigset_t;__signo:integer):boolean;cdecl;external 'c';

(* òþ÷ò¨ð•ðõª ø¸ªøýýþõ ÷ýð¢õýøõ, õ¸ûø ýðñþ¨ ¸øóýðûþò ýõ ÿº¸ª *)

function sigisemptyset(__set:psigset_t):boolean;cdecl;external 'c';

(* ¸þ÷ôðõª ýþòvù ýðñþ¨ ¸øóýðûþò ø÷ ôòº¿ ò¿þôýv¿ ¸ ÿþüþ•¹¦ ûþóø¢õ¸úþóþ "L" *)

function sigandset(__set, __left, __right:psigset_t):integer;cdecl;external 'c';

(* ¸þ÷ôðõª ýþòvù ýðñþ¨ ¸øóýðûþò ø÷ ôòº¿ ò¿þôýv¿ ¸ ÿþüþ•¹¦ ûþóø¢õ¸úþóþ "LTL" *)



function sigorset(__set, __left, __right:psigset_t):integer;cdecl;external 'c';

(* ýðñþ¨ ¯ºýú¡øù ôû  ýõûþúðû¹ýv¿ ÿõ¨õ¿þôþò *)

(* Store the calling environment in ENV, also saving the signal mask.

àà Return 0.à *)

function setjmp(var __env:jmp_buf):integer;cdecl;external 'c';

(* Store the calling environment in ENV, not saving the signal mask.

àà Return 0.à *)

function _setjmp(var __env:jmp_buf):integer;cdecl;external 'c';

(* Store the calling environment in ENV, also saving the

àà signal mask if SAVEMASK is nonzero.à Return 0.à *)

function sigsetjmp(var __env:jmp_buf;__savemask:longint):integer;cdecl;external 'c' name '__sigsetjmp';

(* Jump to the environment saved in ENV, making the

àà `setjmp' call there return VAL, or 1 if VAL is 0.à *)

procedure longjmp(var __env:jmp_buf;__val:integer);cdecl;external 'c';

(* Jump to the environment saved in ENV, making the

àà sigsetjmp call there return VAL, or 1 if VAL is 0.

àà Restore the signal mask if that sigsetjmp call saved it.

àà This is just an alias `longjmp'.à *)

procedure siglongjmp(var __env:jmp_buf;__val:integer);cdecl;external 'c';

(* fpathconf, pathconf - get configuration values for files *)

function fpathconf(filedes,name:longint):longint;cdecl;external 'c';

function pathconf(path:pchar;name:longint):longint;cdecl;external 'c';

function sysconf(name:integer):longint;cdecl;external 'c';

(* setpgid, getpgid, setpgrp, getpgrp - set/get process group *)

function setpgid(pid, pgid:longint):longint;cdecl;external 'c';

function getpgid(pid:longint):longint;cdecl;external 'c';

function setpgrp:longint;cdecl;external 'c';

function getpgrp:longint;cdecl;external 'c';

function getsid(pid:longint):longint;cdecl;external 'c';

function setsid:longint;cdecl;external 'c';

(* grantpt - grant access to the slave pseudotty*)

function grantpt(fd:longint):longint;cdecl;external 'c';

(* unlockpt - unlock a pseudotty master/slave pair*)



function unlockpt(fd:longint):longint;cdecl;external 'c';

(* ptsname - get the name of the slave pseudotty*)

function ptsname(fd:longint):pchar;cdecl;external 'c';

(* inet_aton() converts the Internet host addressà cpà fromà theà standardààààààààààààààààààààààààààà

àà numbers-and-dotsà notation into binary data and stores it in the structure

àà that inp points to. inet_aton returns nonzero ifà theà addressà isààààààààààààààààààààààààààààààààààààààààà

àà valid, zero if not.*)

function inet_aton(cp:pchar; inp:pin_addr):longint;cdecl;external 'c';

(* Theà inet_addr()à functionà convertsà the Internet host address cp fromààààààà

àà numbers-and-dots notation into binary data in network byteà order.àà Ifàààààààààààààà

àà the input is invalid, INADDR_NONE (usually -1) is returned.à This is anààààààààààààààààààààà

àà obsolete interface to inet_aton, describedà immediatelyà above;à ità isàààààààààààààààààààààààààààà

àà obsolete because -1 is a valid address (255.255.255.255), and inet_atonààààààààààààààààààààààààààààààààààà

àà provides a cleaner way to indicate error return. *)

function inet_addr(cp:pchar):in_addr_t;cdecl;external 'c';

(* The inet_network() function extracts the network numberà inà hostà byte

àà orderà fromà the address cp in numbers-and-dots notation.à If the input

àà is invalid, -1 is returned. *)

function inet_network(cp:pchar):in_addr_t;cdecl;external 'c';

(* The inet_ntoa() function converts the Internet host address in given in

àà networkà byteà order to a string in standard numbers-and-dots notation.

àà The string is returned in a statically allocated buffer,à whichà subse-

àà quent calls will overwrite. *)

function inet_ntoa(n:in_addr):pchar;cdecl;external 'c';

(* Theà inet_makeaddr() function makes an Internet host address in network

àà byte order by combining the network number net with theà localà address

àà host in network net, both in local host byte order. *)

function inet_makeaddr(net, host:longint):in_addr;cdecl;external 'c';



(* Theà inet_lnaof()à functionà returns the local host address part of the

àà Internet address in.à The local host address is returned in localà host

àà byte order. *)

function inet_lnaof(n:in_addr):in_addr_t;cdecl;external 'c';

àààààà

(* The inet_netof() function returns the network number part of the Inter-

àà net Address in.à The network number isà returnedà inà localà hostà byte

àà order. *)

function inet_netof(n:in_addr):in_addr_t;cdecl;external 'c';

ààààààààààà

(* sendto - þªÿ¨ðòøª¹ ¸þþñ•õýøõ ò ¸þúõª.

àà send, sendto, ø sendmsg ø¸ÿþû¹÷º¦ª¸  ôû  ÿõ¨õ¸vûúø ¸þþñ•õýøù ýðà ô¨ºóþù

àà ¸þúõª.ààà sendà üþöýþà ø¸ÿþû¹÷þòðª¹,à ªþû¹úþà õ¸ûøà ¸þúõªà ýð¿þôøª¸ à ò

àà ¸þõôøýõýýþü ¸þ¸ªþ ýøø, ªþóôð úðú sendto ø sendmsg üþöýþ ø¸ÿþû¹÷þòðª¹à ò

àà û¦ñþõ ò¨õü . *)

function sendto(sock:longint;var addr;addrlen,flags:longint;

ààààààààààààààà var sato:tsockaddr;tolen:longint):longint;cdecl;external 'c';

ààààààààààààààà

(* recvfrom ø¸ÿþû¹÷ºõª¸  ôû  ÿþûº¢õýø  ¸þþñ•õýøù ø÷ ¸þúõªð, ø üþöõª

àà ø¸ÿþû¹÷þò𪹸  ôû  ÿþûº¢õýø  ôðýýv¿, ýõ÷ðòø¸øüþ þª ªþóþ,  òû õª¸  ûø

àà ¸þúõª þ¨øõýªø¨þòðýývü ýð ¸þõôøýõýø  øûø ýõª. *)

function recvfrom(sock:longint;var addr;addrlen,flags:longint;

ààààààààààààààààà var from:tsockaddr;var fromlen:longint):longint;cdecl;external 'c';

(* character classification routines *)

function isalnum(c:integer):boolean;cdecl;external 'c';

function isalpha(c:integer):boolean;cdecl;external 'c';

function isascii(c:integer):boolean;cdecl;external 'c';

function isblank(c:integer):boolean;cdecl;external 'c';

function iscntrl(c:integer):boolean;cdecl;external 'c';

function isdigit(c:integer):boolean;cdecl;external 'c';

function isgraph(c:integer):boolean;cdecl;external 'c';

function islower(c:integer):boolean;cdecl;external 'c';

function isprint(c:integer):boolean;cdecl;external 'c';

function ispunct(c:integer):boolean;cdecl;external 'c';

function isupper(c:integer):boolean;cdecl;external 'c';

function isxdigit(c:integer):boolean;cdecl;external 'c';



function isspace(c:integer):boolean;

function tolower(c:integer):integer;cdecl;external 'c';

function _tolower(c:integer):integer;cdecl;external 'c';

function toupper(c:integer):integer;cdecl;external 'c';

function _toupper(c:integer):integer;cdecl;external 'c';

function toascii(c:integer):integer;cdecl;external 'c';

(* transform date and time to broken-down time or ASCII *)

(* The ctime(), gmtime() and localtime() functions all take an argument of

àà dataà typeà time_t which represents calendar time.à When interpreted as

àà an absolute time value, it represents theà numberà ofà secondsà elapsed

àà since 00:00:00 on January 1, 1970, Coordinated Universal Time (UTC). *)

function ctime(var t:longint):pchar;cdecl;external 'c';

function ctime_r(var timep:longint;buf:pchar):pchar;cdecl;external 'c';

function gmtime(var timep:longint):ptm;cdecl;external 'c';

function gmtime_r(var timep:longint; result:ptm):ptm;cdecl;external 'c';

function localtime(var timep:longint):ptm;cdecl;external 'c';

function localtime_r(var timep:longint; result:ptm):ptm;cdecl;external 'c';

(* The asctime() and mktime() functions both take an argument representing

àà broken-down time which is a representation separated into year,à month,

àà day, etc. *)

function asctime(const t:ptm):pchar;cdecl;external 'c';

function asctime_r(const t:ptm;buf:pchar):pchar;cdecl;external 'c';

function mktime(t:ptm):longint;cdecl;external 'c';

function difftime(time1, time2:longint):double;cdecl;external 'c';

(* ¯ºýú¡øø ôû  ¨ðñþªv ¸ ÿðü ª¹¦ *)

function calloc(nmemb, size:longint):pointer;cdecl;external 'c';

function malloc(size:longint):pointer;cdecl;external 'c';

procedure free(ptr:pointer);cdecl;external 'c';

function realloc(ptr:pointer; size:longint):pointer;cdecl;external 'c';

à

(* ¯ºýú¡øø ôû  ¨ðñþªv ¸ úðªðûþóðüø *)

function mkdir(pathname:pchar;mode:integer):integer;cdecl;external 'c';

function rmdir(pathname:pchar):integer;cdecl;external 'c';

function chdir(path:pchar):integer;cdecl;external 'c';



function getcwd(name:pchar; size:longint):pchar;cdecl;external 'c';

(* ¨ðñþªð ¸ ñº¯õ¨ðüø *)

procedure sync;cdecl;external 'c';

function fsync(filedes:integer):integer;cdecl;external 'c';

(* òvÿþûýõýøõ úþüðýôv shell'ð *)

function runshell(__commandline:pchar):longint;cdecl;external 'c' name 'system';

(* ºýø¢ªþöõýøõ òv÷òðò°õóþ ÿ¨þ¡õ¸¸ð *)

procedure _exit(status:longint);cdecl;external 'c';

(* ø÷üõýõýøõ øûø ¨ð¸°ø¨õýøõ þú¨ºöõýø  *)

function putenv(str:pchar):longint;cdecl;external 'c';

(* ¸üõýð úþ¨ýõòþóþ úðªðûþóð *)

function chroot(path:pchar):longint;cdecl;external 'c';

(* º¸ªðýþòúð ¨õðû¹ýv¿ ø ôõù¸ªòº¦•ø¿ øôõýªø¯øúðªþ¨þò ÿþû¹÷þòðªõû  ø ó¨ºÿÿv *)

function setuid(uid:longint):longint;cdecl;external 'c';

function setgid(gid:longint):longint;cdecl;external 'c';

(* º÷ý𪹠øûø ø÷üõýøª¹ þó¨ðýø¢õýø  ÿ¨þ¡õ¸¸ð *)

function ulimit(cmd:longint;args:array of const):longint;cdecl;external 'c';

(* ðòð¨øùýþõ ÷ðòõ¨°õýøõ ÿ¨þ¡õ¸¸ð *)

function abort:longint;cdecl;external 'c';

(* ¦þûº¢øª¹ ¸úþ¨þ¸ª¹ òòþôð *)

function cfgetispeed(var tdes:TermIOS):longint;cdecl;external 'c';

(* ¦þûº¢øª¹ ¸úþ¨þ¸ª¹ òvòþôð *)

function cfgetospeed(var tdes:TermIOS):longint;cdecl;external 'c';

(* ø¸ÿþû¹÷ºõª¸  ôû  ÿþ¸vûúø ¸øóýðûð ÿ¨õ¨vòðýø  ¸õðý¸ð ¸ò ÷ø *)

Function tcsendbrk(ttyfd, duration:longint):longint;cdecl;external 'c';

(* ¯ºýú¡øø ôû  ¨ðñþªv ¸ ÿðü ª¹¦ *)

function memset(buf:pointer; character:longint; size:longint):pointer;cdecl;external 'c';

function memcpy(buf1:pointer; const buf2:pointer; size:longint):pointer;cdecl;external 'c';

function memmove(buf1:pointer; const buf2:pointer; size:longint):pointer;cdecl;external 'c';

function memcmp(const buf1, buf2:pointer; size:longint):longint;cdecl;external 'c';

function memchr(const buf:pointer; character:longint; size:longint):pointer;cdecl;external 'c';

(* ¯ºýú¡øø ôû  ¨ðñþªv ¸þ ¸ª¨þúðüø *)

function strpbrk(const s1, s2:pchar):pchar;cdecl;external 'c';



function strspn(const s1, s2:pchar):longint;cdecl;external 'c';

function strcspn(const s1, s2:pchar):longint;cdecl;external 'c';

function strtok(s1:pchar; const s2:pchar):pchar;cdecl;external 'c';

function strtol(const str:pchar; endptr:ppchar; base:longint):longint;cdecl;external 'c';

function atoi(const str:pchar):longint;cdecl;external 'c';

function atol(const str:pchar):longint;cdecl;external 'c';

function strtod(const str:pchar; endptr:ppchar):double;cdecl;external 'c';

function atof(const str:pchar):double;cdecl;external 'c';

ààààààààààààààààààààààààààààààààààà

implementation

(* If WIFEXITED(STATUS), the low-order 8 bits of the status.à *)

function WEXITSTATUS(status:integer):integer;

begin

à WEXITSTATUS:=(status and $ff00) shr 8;

end;

(* If WIFSTOPPED(STATUS), the signal that stopped the child.à *)

function WSTOPSIG(status:integer):integer;

begin

à WSTOPSIG:=WEXITSTATUS(status);

end;

(* If WIFSIGNALED(STATUS), the terminating signal.à *)

function WTERMSIG(status:integer):integer;

begin

à WTERMSIG:=status and $7f;

end;

(* Nonzero if STATUS indicates the child dumped core.à *)

function WCOREDUMP(status:integer):boolean;

begin

à WCOREDUMP:=(status and WCOREFLAG) = 0;

end;

(* Nonzero if STATUS indicates normal termination.à *)

function WIFEXITED(status:integer):boolean;

begin

à WIFEXITED:=(status and $7f) = 0;

end;

(* If WIFSIGNALED(STATUS), the terminating signal.à *)

function WIFSIGNALED(status:integer):boolean;

begin

à WIFSIGNALED:=(not WIFSTOPPED(status)) and (not WIFEXITED(status));

end;

(* Nonzero if STATUS indicates the child is stopped.à *)

function WIFSTOPPED(status:integer):boolean;

begin

à WIFSTOPPED:=(status and $ff) = $7f;

end;

(* test on space character: space, CR, LF, Tab, VTab, FF *)

function isspace(c:integer):boolean;

begin

à isspace:=c in [$9,$20,$a,$b,$c,$d];

end;

begin

à stdin:=fdopen(0,'r');

à stdout:=fdopen(1,'w');

end.


Ñîäåðæàíèå ðàçäåëà