home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 3 / 3297 / printfflag.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-05-07  |  1.2 KB  |  58 lines

  1. /* History:
  2. 5/1/91 DJB baseline public domain
  3. */
  4.  
  5. /*
  6.  
  7. char *printfflag(f,style) struct file *f; int style; returns a string
  8. representation of the file flag, f->f_flag (with f in user memory), in
  9. the given style. Known styles, and examples with a RDWR | NDELAY file:
  10. style 0 produces "rwn", style 1 produces "rwn      ", style 2 produces
  11. "rw n     ", style 4 produces "rw-n-----". Nonzero styles will always
  12. produce 9-character outputs. The returned string is stored in a static
  13. area that will be overwritten on each call.
  14.  
  15. */
  16.  
  17. #include <stdio.h>
  18. #include "structfile.h"
  19. #include "printfflag.h"
  20.  
  21. static char result[15];
  22.  
  23. char *printfflag(f,style)
  24. struct file *f;
  25. int style;
  26. {
  27.  int fflag;
  28.  int pos;
  29.  
  30.  if (style)
  31.    for (pos = 0;pos < sizeof(result);++pos)
  32.      result[pos] = ((style == 4) ? '-' : ' ');
  33.  pos = 0;
  34.  
  35.  fflag = f->f_flag;
  36. #define FFLAG(F,X,P) \
  37. if (fflag & F) { result[(style < 2) ? pos++ : P] = X; fflag &= ~F; }
  38.  
  39.  FFLAG(FREAD,'r',0)
  40.  FFLAG(FWRITE,'w',1)
  41.  FFLAG(FAPPEND,'a',2)
  42.  FFLAG(FNDELAY,'n',3)
  43.  FFLAG(FMARK,'m',4)
  44.  FFLAG(FASYNC,'y',5)
  45.  FFLAG(FSHLOCK,'s',6)
  46.  FFLAG(FEXLOCK,'e',7)
  47.  FFLAG(fflag,'?',8)
  48.  
  49.  /* omitted FDEFER---not a user-level flag, I don't think */
  50.  
  51.  if (style)
  52.    result[9] = 0;
  53.  else
  54.    result[pos] = 0;
  55.  
  56.  return result;
  57. }
  58.