C++ __restrict__, update STATUS, minor formatting

This commit is contained in:
Lephenixnoir 2022-03-31 10:12:01 +01:00
parent 94faa6cbea
commit d50e44c563
Signed by: Lephenixnoir
GPG Key ID: 1BBA026E13FC0495
3 changed files with 21 additions and 21 deletions

2
STATUS
View File

@ -130,6 +130,8 @@ TEST: Function/symbol/macro needs to be tested
7.19.7.9 putchar -
7.19.7.10 puts -
7.19.7.11 ungetc -
(EXT) getline -
(EXT) getdelim -
7.19.8.1 fread -
7.19.8.2 fwrite -

View File

@ -277,7 +277,7 @@ extern char *fgets(char * __restrict__ __s, int __n,
extern int fputc(int __c, FILE *__fp);
/* Write a string to a stream (excluding the NUL nyte). */
extern int fputs(char const * __restrict__ s, FILE * __restrict__ fp);
extern int fputs(char const * __restrict__ __s, FILE * __restrict__ __fp);
extern int getc(FILE *__fp);
#define getc fgetc
@ -289,11 +289,13 @@ extern int getchar(void);
/* (DEPRECATED; use fgets() instead) Read a string from stdin. */
extern char *gets(char *__s);
/*get a line from stream*/
extern ssize_t getline(char **restrict __lineptr, size_t *restrict __n, FILE *restrict __fp);
/* Get a line from stream, with dynamic allocation */
extern ssize_t getline(char ** __restrict__ __lineptr,
size_t * __restrict__ __n, FILE * __restrict__ __fp);
/*like getline but with 'delim' instead of \n*/
extern ssize_t getdelim(char **restrict __lineptr, size_t *restrict __n, int __delim, FILE *restrict __fp);
/* Like getline but with [delim] instead of '\n' */
extern ssize_t getdelim(char ** __restrict__ __lineptr,
size_t * __restrict__ __n, int __delim, FILE * __restrict__ __fp);
extern int putc(int __c, FILE *__fp);
#define putc fputc

View File

@ -4,46 +4,42 @@
#include <errno.h>
#include "fileutil.h"
ssize_t getdelim(char **restrict lineptr, size_t *restrict n, int delim, FILE *restrict fp)
ssize_t getdelim(char **restrict lineptr, size_t *restrict n, int delim,
FILE *restrict fp)
{
ssize_t cur = 0;
char *new_lineptr = NULL;
size_t new_n;
if(lineptr == NULL || n == NULL || fp == NULL)
{
errno=EINVAL;
if(lineptr == NULL || n == NULL || fp == NULL) {
errno = EINVAL;
return -1;
}
if(*lineptr == NULL)
{
if(*lineptr == NULL) {
*n = 80;
*lineptr = (char *) malloc(*n);
if(*lineptr==NULL) return -1;
}
do
{
ssize_t read_size = __fp_fread2(fp, *lineptr + cur, *n - cur - 1, delim);
do {
ssize_t read_size = __fp_fread2(fp, *lineptr+cur, *n - cur - 1, delim);
if(read_size <= 0) return -1;
cur += read_size;
if((*lineptr)[cur - 1] != delim && !feof(fp))
{
if((*lineptr)[cur - 1] != delim && !feof(fp)) {
new_n = *n * 2;
new_lineptr = (char *) realloc(*lineptr, new_n);
if(new_lineptr == NULL) return -1;
*lineptr = new_lineptr;
*n = new_n;
}
}while((*lineptr)[cur-1] != delim && !feof(fp));
}
while((*lineptr)[cur-1] != delim && !feof(fp));
(*lineptr)[cur] = '\0';
if(feof(fp) && (*lineptr)[cur-1] != delim)
{
return -1;
}else{
return cur;
}
return cur;
}