home *** CD-ROM | disk | FTP | other *** search
- /* History:
- 5/1/91 DJB baseline public domain
- */
-
- /*
-
- char *printfflag(f,style) struct file *f; int style; returns a string
- representation of the file flag, f->f_flag (with f in user memory), in
- the given style. Known styles, and examples with a RDWR | NDELAY file:
- style 0 produces "rwn", style 1 produces "rwn ", style 2 produces
- "rw n ", style 4 produces "rw-n-----". Nonzero styles will always
- produce 9-character outputs. The returned string is stored in a static
- area that will be overwritten on each call.
-
- */
-
- #include <stdio.h>
- #include "structfile.h"
- #include "printfflag.h"
-
- static char result[15];
-
- char *printfflag(f,style)
- struct file *f;
- int style;
- {
- int fflag;
- int pos;
-
- if (style)
- for (pos = 0;pos < sizeof(result);++pos)
- result[pos] = ((style == 4) ? '-' : ' ');
- pos = 0;
-
- fflag = f->f_flag;
- #define FFLAG(F,X,P) \
- if (fflag & F) { result[(style < 2) ? pos++ : P] = X; fflag &= ~F; }
-
- FFLAG(FREAD,'r',0)
- FFLAG(FWRITE,'w',1)
- FFLAG(FAPPEND,'a',2)
- FFLAG(FNDELAY,'n',3)
- FFLAG(FMARK,'m',4)
- FFLAG(FASYNC,'y',5)
- FFLAG(FSHLOCK,'s',6)
- FFLAG(FEXLOCK,'e',7)
- FFLAG(fflag,'?',8)
-
- /* omitted FDEFER---not a user-level flag, I don't think */
-
- if (style)
- result[9] = 0;
- else
- result[pos] = 0;
-
- return result;
- }
-