sopenr.c 437 B

12345678910111213141516171819202122
  1. /*
  2. * pANS stdio -- sopenr
  3. */
  4. #include "iolib.h"
  5. FILE *sopenr(const char *s){
  6. FILE *f;
  7. qlock(&_stdiolk);
  8. for(f=_IO_stream;f!=&_IO_stream[FOPEN_MAX];f++) if(f->state==CLOSED) break;
  9. if(f==&_IO_stream[FOPEN_MAX]) {
  10. qunlock(&_stdiolk);
  11. return NULL;
  12. }
  13. f->buf=f->rp=(char *)s; /* what an annoyance const is */
  14. f->bufl=strlen(s);
  15. f->wp=f->buf+f->bufl;
  16. f->state=RD;
  17. f->flags=STRING;
  18. f->fd=-1;
  19. qunlock(&_stdiolk);
  20. return f;
  21. }