shf.h revision 1.3 1 1.3 hubertf /* $NetBSD: shf.h,v 1.3 1999/10/20 15:10:00 hubertf Exp $ */
2 1.3 hubertf
3 1.3 hubertf #ifndef SHF_H
4 1.3 hubertf # define SHF_H
5 1.2 tls
6 1.1 jtc /*
7 1.1 jtc * Shell file I/O routines
8 1.1 jtc */
9 1.3 hubertf /* $Id: shf.h,v 1.3 1999/10/20 15:10:00 hubertf Exp $ */
10 1.1 jtc
11 1.1 jtc #define SHF_BSIZE 512
12 1.1 jtc
13 1.1 jtc #define shf_fileno(shf) ((shf)->fd)
14 1.1 jtc #define shf_setfileno(shf,nfd) ((shf)->fd = (nfd))
15 1.1 jtc #define shf_getc(shf) ((shf)->rnleft > 0 ? (shf)->rnleft--, *(shf)->rp++ : \
16 1.1 jtc shf_getchar(shf))
17 1.1 jtc #define shf_putc(c, shf) ((shf)->wnleft == 0 ? shf_putchar((c), (shf)) \
18 1.1 jtc : ((shf)->wnleft--, *(shf)->wp++ = (c)))
19 1.1 jtc #define shf_eof(shf) ((shf)->flags & SHF_EOF)
20 1.1 jtc #define shf_error(shf) ((shf)->flags & SHF_ERROR)
21 1.1 jtc #define shf_errno(shf) ((shf)->errno_)
22 1.1 jtc #define shf_clearerr(shf) ((shf)->flags &= ~(SHF_EOF | SHF_ERROR))
23 1.1 jtc
24 1.1 jtc /* Flags passed to shf_*open() */
25 1.1 jtc #define SHF_RD 0x0001
26 1.1 jtc #define SHF_WR 0x0002
27 1.1 jtc #define SHF_RDWR (SHF_RD|SHF_WR)
28 1.1 jtc #define SHF_ACCMODE 0x0003 /* mask */
29 1.1 jtc #define SHF_GETFL 0x0004 /* use fcntl() to figure RD/WR flags */
30 1.1 jtc #define SHF_UNBUF 0x0008 /* unbuffered I/O */
31 1.1 jtc #define SHF_CLEXEC 0x0010 /* set close on exec flag */
32 1.1 jtc #define SHF_MAPHI 0x0020 /* make fd > FDBASE (and close orig)
33 1.1 jtc * (shf_open() only) */
34 1.1 jtc #define SHF_DYNAMIC 0x0040 /* string: increase buffer as needed */
35 1.1 jtc #define SHF_INTERRUPT 0x0080 /* EINTR in read/write causes error */
36 1.1 jtc /* Flags used internally */
37 1.1 jtc #define SHF_STRING 0x0100 /* a string, not a file */
38 1.1 jtc #define SHF_ALLOCS 0x0200 /* shf and shf->buf were alloc()ed */
39 1.1 jtc #define SHF_ALLOCB 0x0400 /* shf->buf was alloc()ed */
40 1.1 jtc #define SHF_ERROR 0x0800 /* read()/write() error */
41 1.1 jtc #define SHF_EOF 0x1000 /* read eof (sticky) */
42 1.1 jtc #define SHF_READING 0x2000 /* currently reading: rnleft,rp valid */
43 1.1 jtc #define SHF_WRITING 0x4000 /* currently writing: wnleft,wp valid */
44 1.1 jtc
45 1.1 jtc
46 1.1 jtc struct shf {
47 1.1 jtc int flags; /* see SHF_* */
48 1.1 jtc unsigned char *rp; /* read: current position in buffer */
49 1.1 jtc int rbsize; /* size of buffer (1 if SHF_UNBUF) */
50 1.1 jtc int rnleft; /* read: how much data left in buffer */
51 1.1 jtc unsigned char *wp; /* write: current position in buffer */
52 1.1 jtc int wbsize; /* size of buffer (0 if SHF_UNBUF) */
53 1.1 jtc int wnleft; /* write: how much space left in buffer */
54 1.1 jtc unsigned char *buf; /* buffer */
55 1.1 jtc int fd; /* file descriptor */
56 1.1 jtc int errno_; /* saved value of errno after error */
57 1.1 jtc int bsize; /* actual size of buf */
58 1.1 jtc Area *areap; /* area shf/buf were allocated in */
59 1.1 jtc };
60 1.1 jtc
61 1.1 jtc extern struct shf shf_iob[];
62 1.1 jtc
63 1.1 jtc struct shf *shf_open ARGS((const char *name, int oflags, int mode,
64 1.1 jtc int sflags));
65 1.1 jtc struct shf *shf_fdopen ARGS((int fd, int sflags, struct shf *shf));
66 1.1 jtc struct shf *shf_reopen ARGS((int fd, int sflags, struct shf *shf));
67 1.1 jtc struct shf *shf_sopen ARGS((char *buf, int bsize, int sflags,
68 1.1 jtc struct shf *shf));
69 1.1 jtc int shf_close ARGS((struct shf *shf));
70 1.1 jtc int shf_fdclose ARGS((struct shf *shf));
71 1.1 jtc char *shf_sclose ARGS((struct shf *shf));
72 1.1 jtc int shf_finish ARGS((struct shf *shf));
73 1.1 jtc int shf_flush ARGS((struct shf *shf));
74 1.1 jtc int shf_seek ARGS((struct shf *shf, off_t where, int from));
75 1.1 jtc int shf_read ARGS((char *buf, int bsize, struct shf *shf));
76 1.1 jtc char *shf_getse ARGS((char *buf, int bsize, struct shf *shf));
77 1.1 jtc int shf_getchar ARGS((struct shf *shf));
78 1.1 jtc int shf_ungetc ARGS((int c, struct shf *shf));
79 1.1 jtc int shf_putchar ARGS((int c, struct shf *shf));
80 1.1 jtc int shf_puts ARGS((const char *s, struct shf *shf));
81 1.1 jtc int shf_write ARGS((const char *buf, int nbytes, struct shf *shf));
82 1.1 jtc int shf_fprintf ARGS((struct shf *shf, const char *fmt, ...));
83 1.1 jtc int shf_snprintf ARGS((char *buf, int bsize, const char *fmt, ...));
84 1.1 jtc char *shf_smprintf ARGS((const char *fmt, ...));
85 1.1 jtc int shf_vfprintf ARGS((struct shf *, const char *fmt, va_list args));
86 1.3 hubertf
87 1.3 hubertf #endif /* SHF_H */
88