Skip to content

Commit

Permalink
corec: use ssize_t when using libc file read/write
Browse files Browse the repository at this point in the history
  • Loading branch information
robUx4 committed Dec 26, 2024
1 parent a35754c commit 74028f2
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions corec/corec/helpers/file/file_libc.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*****************************************************************************
*
*
* Copyright (c) 2008-2010, CoreCodec, Inc.
* All rights reserved.
*
Expand Down Expand Up @@ -100,7 +100,7 @@ static err_t Open(filestream* p, const tchar_t* URL, int Flags)
}

tcscpy_s(p->URL,TSIZEOF(p->URL),URL);

if (stat(URL, &file_stats) == 0)
p->Length = file_stats.st_size;

Expand All @@ -110,15 +110,17 @@ static err_t Open(filestream* p, const tchar_t* URL, int Flags)

static err_t Read(filestream* p,void* Data,size_t Size,size_t* Readed)
{
if (Size > SSIZE_MAX)
return ERR_READ;
err_t Err;
int n = read(p->fd, Data, (unsigned int)Size);
ssize_t n = read(p->fd, Data, Size);
if (n<0)
{
n=0;
Err = ERR_READ;
}
else
Err = ((size_t)n != Size) ? ERR_END_OF_FILE:ERR_NONE;
Err = (n != (ssize_t)Size) ? ERR_END_OF_FILE:ERR_NONE;

if (Readed)
*Readed = n;
Expand All @@ -132,16 +134,18 @@ static err_t ReadBlock(filestream* p,block* Block,size_t Ofs,size_t Size,size_t*

static err_t Write(filestream* p,const void* Data,size_t Size,size_t* Written)
{
if (Size > SSIZE_MAX)
return ERR_WRITE;
err_t Err;
int n = write(p->fd, Data, (unsigned int)Size);
ssize_t n = write(p->fd, Data, Size);

if (n<0)
{
n=0;
Err = ERR_WRITE;
}
else
Err = (n != Size) ? ERR_WRITE:ERR_NONE;
Err = (n != (ssize_t)Size) ? ERR_WRITE:ERR_NONE;

if (Written)
*Written = n;
Expand Down Expand Up @@ -188,7 +192,7 @@ static err_t OpenDir(filestream* p,const tchar_t* Path,int UNUSED_PARAM(Flags))
AddPathDelimiter(p->DirPath,TSIZEOF(p->DirPath));
return ERR_NONE;
}

extern datetime_t LinuxToDateTime(time_t);

static err_t EnumDir(filestream* p,const tchar_t* Exts,bool_t ExtFilter,streamdir* Item)
Expand All @@ -205,7 +209,7 @@ static err_t EnumDir(filestream* p,const tchar_t* Exts,bool_t ExtFilter,streamdi
{
tchar_t FilePath[MAXPATH];
struct stat file_stats;

if (Dirent->d_name[0]=='.') // skip hidden files and current directory
continue;

Expand Down Expand Up @@ -346,7 +350,7 @@ void FindFiles(nodecontext *p,const tchar_t* Path, const tchar_t* Mask,void(*Pro
DIR* Directory;
struct dirent* DirectoryInfo;
tchar_t TPathToFile[MAXPATH];

Directory = opendir(Path);
if (Directory)
{
Expand All @@ -364,10 +368,10 @@ void FindFiles(nodecontext *p,const tchar_t* Path, const tchar_t* Mask,void(*Pro
}
}
}

closedir(Directory);
}

}

stream *FileTemp(anynode *Any)
Expand Down

0 comments on commit 74028f2

Please sign in to comment.