From e0f6355a915be54369323f0576bcee3bf63869ac Mon Sep 17 00:00:00 2001 From: leitner Date: Wed, 4 Feb 2004 23:02:35 +0000 Subject: [PATCH] add a few man pages --- fmt/fmt_long.3 | 2 +- fmt/fmt_longlong.3 | 20 ++++++++++++++++++++ fmt/fmt_ulonglong.3 | 20 ++++++++++++++++++++ fmt/fmt_xlonglong.3 | 21 +++++++++++++++++++++ open.h | 14 +++++++++----- open/open_rw.3 | 14 ++++++++++++++ open/open_rw.c | 11 +++++++++++ scan/scan_longlong.3 | 2 +- scan/scan_short.3 | 13 +++++++++++++ scan/scan_ulonglong.3 | 13 +++++++++++++ scan/scan_xlonglong.3 | 17 +++++++++++++++++ scan/scan_xlonglong.c | 13 +++++++++++++ 12 files changed, 153 insertions(+), 7 deletions(-) create mode 100644 fmt/fmt_longlong.3 create mode 100644 fmt/fmt_ulonglong.3 create mode 100644 fmt/fmt_xlonglong.3 create mode 100644 open/open_rw.3 create mode 100644 open/open_rw.c create mode 100644 scan/scan_short.3 create mode 100644 scan/scan_ulonglong.3 create mode 100644 scan/scan_xlonglong.3 create mode 100644 scan/scan_xlonglong.c diff --git a/fmt/fmt_long.3 b/fmt/fmt_long.3 index 72f1929..c58c509 100644 --- a/fmt/fmt_long.3 +++ b/fmt/fmt_long.3 @@ -4,7 +4,7 @@ fmt_long \- write an ASCII representation of a long integer .SH SYNTAX .B #include -unsigned int \fBfmt_long\fP(char *\fIdest\fR,unsigned int \fIsource\fR); +unsigned int \fBfmt_long\fP(char *\fIdest\fR,long \fIsource\fR); .SH DESCRIPTION fmt_long writes an ASCII representation ('-' and '0' to '9', base 10) of \fIsource\fR to \fIdest\fR and returns the number of bytes written. diff --git a/fmt/fmt_longlong.3 b/fmt/fmt_longlong.3 new file mode 100644 index 0000000..1b6c796 --- /dev/null +++ b/fmt/fmt_longlong.3 @@ -0,0 +1,20 @@ +.TH fmt_longlong 3 +.SH NAME +fmt_longlong \- write an ASCII representation of a long long integer +.SH SYNTAX +.B #include + +unsigned int \fBfmt_longlong\fP(char *\fIdest\fR,long long \fIsource\fR); +.SH DESCRIPTION +fmt_longlong writes an ASCII representation ('-' and '0' to '9', base 10) of +\fIsource\fR to \fIdest\fR and returns the number of bytes written. + +fmt_longlong does not append \\0. + +If \fIdest\fR equals FMT_LEN (i.e. is zero), fmt_longlong returns the number +of bytes it would have written. + +For convenience, fmt.h defines the integer FMT_LONG to be big enough to +contain every possible fmt_longlong output plus \\0. +.SH "SEE ALSO" +scan_longlong(3) diff --git a/fmt/fmt_ulonglong.3 b/fmt/fmt_ulonglong.3 new file mode 100644 index 0000000..f766895 --- /dev/null +++ b/fmt/fmt_ulonglong.3 @@ -0,0 +1,20 @@ +.TH fmt_ulonglong 3 +.SH NAME +fmt_ulonglong \- write an ASCII representation of an unsigned long long integer +.SH SYNTAX +.B #include + +unsigned int \fBfmt_ulonglong\fP(char *\fIdest\fR,unsigned long long \fIsource\fR); +.SH DESCRIPTION +fmt_ulonglong writes an ASCII representation ('0' to '9', base 10) of +\fIsource\fR to \fIdest\fR and returns the number of bytes written. + +fmt_ulonglong does not append \\0. + +If \fIdest\fR equals FMT_LEN (i.e. is zero), fmt_ulonglong returns the +number of bytes it would have written. + +For convenience, fmt.h defines the integer FMT_ULONG to be big enough to +contain every possible fmt_ulonglong output plus \\0. +.SH "SEE ALSO" +scan_ulonglong(3) diff --git a/fmt/fmt_xlonglong.3 b/fmt/fmt_xlonglong.3 new file mode 100644 index 0000000..42554f6 --- /dev/null +++ b/fmt/fmt_xlonglong.3 @@ -0,0 +1,21 @@ +.TH fmt_xlonglong 3 +.SH NAME +fmt_xlonglong \- write a hexadecimal ASCII representation of an unsigned long long integer +.SH SYNTAX +.B #include + +unsigned int \fBfmt_xlonglong\fP(char *\fIdest\fR,unsigned long long \fIsource\fR); +.SH DESCRIPTION +fmt_xlonglong writes an ASCII representation ('0' to '9' and 'a' to 'f', +base 16) of \fIsource\fR to \fIdest\fR and returns the number of bytes +written. + +fmt_xlonglong does not append \\0. + +If \fIdest\fR equals FMT_LEN (i.e. is zero), fmt_xlonglong returns the +number of bytes it would have written. + +For convenience, fmt.h defines the integer FMT_XLONG to be big enough to +contain every possible fmt_xlonglong output plus \\0. +.SH "SEE ALSO" +scan_xlonglong(3) diff --git a/open.h b/open.h index 50ca102..cf4cf28 100644 --- a/open.h +++ b/open.h @@ -2,26 +2,30 @@ #define OPEN_H /* open filename for reading and return the file handle or -1 on error */ -int open_read(const char *filename); +int open_read(const char* filename); /* create filename for exclusive write only use (mode 0600) and return * the file handle or -1 on error */ -int open_excl(const char *filename); +int open_excl(const char* filename); /* open filename for appending write only use (mode 0600) * and return the file handle or -1 on error. * All write operation will append after the last byte, regardless of * seeking or other processes also appending to the file. The file will * be created if it does not exist. */ -int open_append(const char *filename); +int open_append(const char* filename); /* open filename for writing (mode 0644). Create the file if it does * not exist, truncate it to zero length otherwise. Return the file * handle or -1 on error. */ -int open_trunc(const char *filename); +int open_trunc(const char* filename); /* open filename for writing. Create the file if it does not exist. * Return the file handle or -1 on error. */ -int open_write(const char *filename); +int open_write(const char* filename); + +/* open filename for reading and writing. Create file if not there. + * Return file handle or -1 on error. */ +int open_rw(const char* filename); #endif diff --git a/open/open_rw.3 b/open/open_rw.3 new file mode 100644 index 0000000..4bf1d27 --- /dev/null +++ b/open/open_rw.3 @@ -0,0 +1,14 @@ +.TH open_rw 3 +.SH NAME +open_rw \- open a file for reading and writing +.SH SYNTAX +.B #include + +extern int \fBopen_rw\fP(const char *\fIfilename\fR); +.SH DESCRIPTION +open_rw opens the file \fIfilename\fR for reading and writing use and +returns the file handle. If the file does not exist, it will be created +with mode 0644. If there was an error opening or creating the file, +open_rw returns -1 and sets errno accordingly. +.SH "SEE ALSO" +open(2) diff --git a/open/open_rw.c b/open/open_rw.c new file mode 100644 index 0000000..84029d0 --- /dev/null +++ b/open/open_rw.c @@ -0,0 +1,11 @@ +#include +#include +#include "open.h" + +#ifndef O_NDELAY +#define O_NDELAY 0 +#endif + +int open_rw(const char *filename) { + return open(filename,O_RDWR|O_CREAT|O_NDELAY,0644); +} diff --git a/scan/scan_longlong.3 b/scan/scan_longlong.3 index 3b35ba7..b749e0d 100644 --- a/scan/scan_longlong.3 +++ b/scan/scan_longlong.3 @@ -1,6 +1,6 @@ .TH scan_longlong 3 .SH NAME -scan_longlong \- parse an long integer in decimal ASCII representation +scan_longlong \- parse a long integer in decimal ASCII representation .SH SYNTAX .B #include diff --git a/scan/scan_short.3 b/scan/scan_short.3 new file mode 100644 index 0000000..9e1f82e --- /dev/null +++ b/scan/scan_short.3 @@ -0,0 +1,13 @@ +.TH scan_short 3 +.SH NAME +scan_short \- parse an integer in decimal ASCII representation +.SH SYNTAX +.B #include + +int \fBscan_short\fP(const char *\fIsrc\fR,short int *\fIdest\fR); +.SH DESCRIPTION +scan_short parses a short integer in decimal ASCII representation +from \fIsrc\fR and writes the result into \fIdest\fR. It returns the +number of bytes read from \fIsrc\fR. +.SH "SEE ALSO" +scan_int(3), scan_ushort(3), scan_xshort(3), scan_8short(3), fmt_short(3) diff --git a/scan/scan_ulonglong.3 b/scan/scan_ulonglong.3 new file mode 100644 index 0000000..da497ed --- /dev/null +++ b/scan/scan_ulonglong.3 @@ -0,0 +1,13 @@ +.TH scan_ulonglong 3 +.SH NAME +scan_ulonglong \- parse an unsigned long integer in decimal ASCII representation +.SH SYNTAX +.B #include + +int \fBscan_ulonglong\fP(const char *\fIsrc\fR,unsigned long long *\fIdest\fR); +.SH DESCRIPTION +scan_ulonglong parses an unsigned long long integer in decimal ASCII representation +from \fIsrc\fR and writes the result into \fIdest\fR. It returns the +number of bytes read from \fIsrc\fR. +.SH "SEE ALSO" +scan_longlong(3), fmt_ulonglong(3) diff --git a/scan/scan_xlonglong.3 b/scan/scan_xlonglong.3 new file mode 100644 index 0000000..426170b --- /dev/null +++ b/scan/scan_xlonglong.3 @@ -0,0 +1,17 @@ +.TH scan_xlonglong 3 +.SH NAME +scan_xlonglong \- parse an unsigned long long integer in hexadecimal ASCII representation +.SH SYNTAX +.B #include + +int \fBscan_xlonglong\fP(const char *\fIsrc\fR,unsigned long long* \fIdest\fR); +.SH DESCRIPTION +scan_xlonglong parses an unsigned long long integer in hexadecimal ASCII +representation from \fIsrc\fR and writes the result into \fIdest\fR. It +returns the number of bytes read from \fIsrc\fR. + +scan_xlonglong understands both upper and lower case letters. + +scan_xlonglong does not expect or understand a "0x" prefix. +.SH "SEE ALSO" +fmt_xlonglong(3) diff --git a/scan/scan_xlonglong.c b/scan/scan_xlonglong.c new file mode 100644 index 0000000..78ee7d9 --- /dev/null +++ b/scan/scan_xlonglong.c @@ -0,0 +1,13 @@ +#include "scan.h" + +unsigned int scan_xlonglong(const char* src,unsigned long long* dest) { + register const char *tmp=src; + register int l=0; + register unsigned char c; + while ((c=scan_fromhex(*tmp))<16) { + l=(l<<4)+c; + ++tmp; + } + *dest=l; + return tmp-src; +}