libc: Add EXIT_SUCCESS, EXIT_FAILURE, RAND_MAX and BUFSIZ

This commit is contained in:
apio 2022-10-22 21:39:51 +02:00
parent dd9b90d69d
commit 06f9ffc184
5 changed files with 11 additions and 4 deletions

View File

@ -9,7 +9,7 @@ int main()
return 1; return 1;
} }
char buf[32]; char buf[BUFSIZ];
fgets(buf, sizeof(buf), fp); fgets(buf, sizeof(buf), fp);
printf("%s\n", buf); printf("%s\n", buf);

View File

@ -10,7 +10,7 @@ int main()
return 1; return 1;
} }
char buf[32]; char buf[BUFSIZ];
fgets(buf, sizeof(buf), fp); fgets(buf, sizeof(buf), fp);
if (ferror(fp)) if (ferror(fp))

View File

@ -8,6 +8,7 @@
#include <bits/seek.h> #include <bits/seek.h>
#define FOPEN_MAX 32 #define FOPEN_MAX 32
#define BUFSIZ 32
typedef struct typedef struct
{ {

View File

@ -2,8 +2,14 @@
#define _STDLIB_H #define _STDLIB_H
#include <bits/macros.h> #include <bits/macros.h>
#include <limits.h>
#include <stddef.h> #include <stddef.h>
#define EXIT_SUCCESS 0
#define EXIT_FAILURE 1
#define RAND_MAX INT_MAX
#ifdef __cplusplus #ifdef __cplusplus
extern "C" extern "C"
{ {

View File

@ -13,8 +13,8 @@ void file_read_buf(FILE* stream)
{ {
if (!stream->f_buf) if (!stream->f_buf)
{ {
stream->f_buf = (char*)malloc(32); // FIXME: Handle errors. stream->f_buf = (char*)malloc(BUFSIZ); // FIXME: Handle errors.
stream->f_bufrsize = 32; stream->f_bufrsize = BUFSIZ;
} }
stream->f_bufoff = 0; stream->f_bufoff = 0;
ssize_t nread = read(stream->f_fd, stream->f_buf, stream->f_bufrsize); ssize_t nread = read(stream->f_fd, stream->f_buf, stream->f_bufrsize);