PatchworkOS
Loading...
Searching...
No Matches
ungetc.c
Go to the documentation of this file.
1#include <stdio.h>
2
3#include "user/common/file.h"
4
5int ungetc(int c, FILE* stream)
6{
7 int rc;
8
9 mtx_lock(&stream->mtx);
10
11 if (c == EOF || stream->ungetIndex == _UNGETC_MAX)
12 {
13 rc = -1;
14 }
15 else
16 {
17 rc = stream->ungetBuf[stream->ungetIndex++] = (unsigned char)c;
18 }
19
20 mtx_unlock(&stream->mtx);
21
22 return rc;
23}
#define _UNGETC_MAX
Definition file.h:32
#define EOF
Definition stdio.h:25
Definition file.h:34
unsigned char ungetBuf[_UNGETC_MAX]
Definition file.h:42
mtx_t mtx
Definition file.h:45
uint64_t ungetIndex
Definition file.h:43
_PUBLIC int mtx_lock(mtx_t *mtx)
Definition mtx_lock.c:11
_PUBLIC int mtx_unlock(mtx_t *mtx)
Definition mtx_unlock.c:10
int ungetc(int c, FILE *stream)
Definition ungetc.c:5