Compare commits

...

5 Commits

Author SHA1 Message Date
Xavier Del Campo Romero f297dab1f2
inttypes.h: Fix wrong definitions
PRIsN is not defined according to C99. Instead, PRIdN and PRIiN are the
macros defined for signed integers.
2024-03-31 08:17:00 +02:00
Xavier Del Campo Romero ff52258e15
stdio.h: Add missing declaration for freopen(3) 2023-11-29 13:03:46 +01:00
Xavier Del Campo Romero c6ded28dce
libpsx: Fix const-correctness for fwrite(3)
According to C99 §7.19.8.2p1, fwrite(3) is expected to take a const void
*, and not void *.
2023-11-29 13:00:13 +01:00
Xavier Del Campo Romero c157ae7c78
libpsx: Add rewind(3) 2023-11-29 12:55:31 +01:00
Xavier Del Campo Romero 2ffa7e5c7b
libpsx: Move type definitions to stdint.h
According to C99 §7.8, inttypes.h is meant to include stdint.h, and not
the other way around.
2023-11-29 12:54:52 +01:00
4 changed files with 57 additions and 46 deletions

View File

@ -5,52 +5,20 @@
#include <stdint.h>
typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
typedef unsigned int uint32_t;
typedef unsigned long long uint64_t;
typedef unsigned char uint_least8_t;
typedef unsigned short uint_least16_t;
typedef unsigned int uint_least32_t;
typedef unsigned long long uint_least64_t;
typedef unsigned char uint_fast8_t;
typedef unsigned short uint_fast16_t;
typedef unsigned int uint_fast32_t;
typedef unsigned long long uint_fast64_t;
typedef unsigned long long uintmax_t;
typedef unsigned int uintptr_t;
typedef signed char int8_t;
typedef short int16_t;
typedef int int32_t;
typedef long long int64_t;
typedef signed char int_least8_t;
typedef short int_least16_t;
typedef int int_least32_t;
typedef long long int_least64_t;
typedef char int_fast8_t;
typedef short int_fast16_t;
typedef int int_fast32_t;
typedef long long int_fast64_t;
typedef long long intmax_t;
typedef long intptr_t;
#define PRIu8 "hhu"
#define PRIu16 "hu"
#define PRIu32 "u"
#define PRIu64 "llu"
#define PRIs8 "hhd"
#define PRIs16 "hd"
#define PRIs32 "d"
#define PRIs64 "lld"
#define PRId8 "hhd"
#define PRId16 "hd"
#define PRId32 "d"
#define PRId64 "lld"
#define PRIi8 "hhi"
#define PRIi16 "hi"
#define PRIi32 "i"
#define PRIi64 "lli"
#define PRIuLEAST8 "hhu"
#define PRIuLEAST16 "hu"

View File

@ -3,12 +3,47 @@
#ifndef _STDINT_H
#define _STDINT_H
#include <inttypes.h>
// Added ifndef or otherwise GCC 4.8 would complain
#ifndef __PTRDIFF_TYPE__
typedef unsigned int ptrdiff_t;
#endif
typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
typedef unsigned int uint32_t;
typedef unsigned long long uint64_t;
typedef unsigned char uint_least8_t;
typedef unsigned short uint_least16_t;
typedef unsigned int uint_least32_t;
typedef unsigned long long uint_least64_t;
typedef unsigned char uint_fast8_t;
typedef unsigned short uint_fast16_t;
typedef unsigned int uint_fast32_t;
typedef unsigned long long uint_fast64_t;
typedef unsigned long long uintmax_t;
typedef unsigned int uintptr_t;
typedef signed char int8_t;
typedef short int16_t;
typedef int int32_t;
typedef long long int64_t;
typedef signed char int_least8_t;
typedef short int_least16_t;
typedef int int_least32_t;
typedef long long int_least64_t;
typedef char int_fast8_t;
typedef short int_fast16_t;
typedef int int_fast32_t;
typedef long long int_fast64_t;
typedef long long intmax_t;
typedef long intptr_t;
#endif

View File

@ -116,13 +116,15 @@ int vprintf(const char *fmt, va_list ap);
FILE *fdopen(int fildes, const char *mode);
FILE *fopen(const char *path, const char *mode);
FILE *freopen(const char *path, const char *mode, FILE *stream);
int fclose(FILE *stream);
size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream);
size_t fwrite(void *ptr, size_t size, size_t nmemb, FILE *stream);
size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream);
int fgetc(FILE *f);
int ftell(FILE *f);
int fseek(FILE *f, int offset, int whence);
void rewind(FILE *f);
int fputs(const char *str, FILE *stream);
void clearerr(FILE *stream);

View File

@ -420,6 +420,12 @@ int fseek(FILE *f, int offset, int whence)
return 0;
}
void rewind(FILE *f)
{
fseek(f, 0, SEEK_SET);
clearerr(f);
}
int toupper(int c)
{
if(c >= 'a' && c <= 'z')
@ -716,12 +722,12 @@ int puts(const char *str)
return EOF;
}
size_t fwrite(void *restrict const ptr, const size_t size, const size_t nmemb,
size_t fwrite(const void *restrict const ptr, const size_t size, const size_t nmemb,
FILE *restrict const f)
{
if(IS_CONS_OUT(f)) // stdout or stderr
{
char *c = ptr;
const char *c = ptr;
int i;
for(i = 0; i < size; i++)