Skip to content

Commit

Permalink
retry read/write if signal (close HaxeFoundation#650)
Browse files Browse the repository at this point in the history
  • Loading branch information
ncannasse committed Feb 4, 2024
1 parent 062e9be commit 775d53e
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/std/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,26 @@
# define SET_IS_STD(f,b)
#endif

#ifndef HL_WIN
// retry if we were interrupted by a signal (profiler triggered for example)
static size_t fread_retry( void *buffer, size_t size, size_t count, FILE *f ) {
size_t ret;
do {
ret = fread(buffer,size,count,f);
} while( ret == 0 && ferror(f) && errno == EINTR );
return ret;
}
static size_t fwrite_retry( void *buffer, size_t size, size_t count, FILE *f ) {
size_t ret;
do {
ret = fwrite(buffer,size,count,f);
} while( ret == 0 && ferror(f) && errno == EINTR );
return ret;
}
#define fread fread_retry
#define fwrite fwrite_retry
#endif

typedef struct _hl_fdesc hl_fdesc;
struct _hl_fdesc {
void (*finalize)( hl_fdesc * );
Expand Down

0 comments on commit 775d53e

Please sign in to comment.