BLI_open: check returned value for -1 instead of < 0
This commit is contained in:
@@ -820,7 +820,7 @@ int BKE_undo_save_file(const char *filename)
|
||||
* to avoid writing to a symlink - use 'O_EXCL' (CVE-2008-1103) */
|
||||
errno = 0;
|
||||
file = BLI_open(filename, flag, 0666);
|
||||
if (file < 0) {
|
||||
if (file == -1) {
|
||||
if (errno == EEXIST) {
|
||||
errno = 0;
|
||||
file = BLI_open(filename, flag & ~O_CREAT, 0666);
|
||||
|
||||
@@ -635,7 +635,7 @@ Image *BKE_image_load(Main *bmain, const char *filepath)
|
||||
|
||||
/* exists? */
|
||||
file = BLI_open(str, O_BINARY | O_RDONLY, 0);
|
||||
if (file < 0)
|
||||
if (file == -1)
|
||||
return NULL;
|
||||
close(file);
|
||||
|
||||
|
||||
@@ -626,7 +626,7 @@ MovieClip *BKE_movieclip_file_add(Main *bmain, const char *name)
|
||||
|
||||
/* exists? */
|
||||
file = BLI_open(str, O_BINARY | O_RDONLY, 0);
|
||||
if (file < 0)
|
||||
if (file == -1)
|
||||
return NULL;
|
||||
close(file);
|
||||
|
||||
|
||||
@@ -202,7 +202,7 @@ PackedFile *newPackedFile(ReportList *reports, const char *filename, const char
|
||||
* and create a PackedFile structure */
|
||||
|
||||
file = BLI_open(name, O_BINARY | O_RDONLY, 0);
|
||||
if (file < 0) {
|
||||
if (file == -1) {
|
||||
BKE_reportf(reports, RPT_ERROR, "Unable to pack file, source path '%s' not found", name);
|
||||
}
|
||||
else {
|
||||
@@ -331,7 +331,7 @@ int writePackedFile(ReportList *reports, const char *filename, PackedFile *pf, i
|
||||
BLI_make_existing_file(name);
|
||||
|
||||
file = BLI_open(name, O_BINARY + O_WRONLY + O_CREAT + O_TRUNC, 0666);
|
||||
if (file < 0) {
|
||||
if (file == -1) {
|
||||
BKE_reportf(reports, RPT_ERROR, "Error creating file '%s'", name);
|
||||
ret_value = RET_ERROR;
|
||||
}
|
||||
@@ -394,7 +394,7 @@ int checkPackedFile(const char *filename, PackedFile *pf)
|
||||
/* we'll have to compare the two... */
|
||||
|
||||
file = BLI_open(name, O_BINARY | O_RDONLY, 0);
|
||||
if (file < 0) {
|
||||
if (file == -1) {
|
||||
ret_val = PF_NOFILE;
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -86,7 +86,7 @@ int BLI_file_gzip(const char *from, const char *to)
|
||||
if (gzfile == NULL)
|
||||
return -1;
|
||||
file = BLI_open(from, O_BINARY | O_RDONLY, 0);
|
||||
if (file < 0)
|
||||
if (file == -1)
|
||||
return -2;
|
||||
|
||||
while (1) {
|
||||
|
||||
@@ -72,7 +72,7 @@ int BLO_is_a_runtime(const char *path)
|
||||
int datastart;
|
||||
char buf[8];
|
||||
|
||||
if (fd < 0)
|
||||
if (fd == -1)
|
||||
goto cleanup;
|
||||
|
||||
lseek(fd, -12, SEEK_END);
|
||||
@@ -104,7 +104,7 @@ BlendFileData *BLO_read_runtime(const char *path, ReportList *reports)
|
||||
|
||||
fd = BLI_open(path, O_BINARY | O_RDONLY, 0);
|
||||
|
||||
if (fd < 0) {
|
||||
if (fd == -1) {
|
||||
BKE_reportf(reports, RPT_ERROR, "Unable to open '%s': %s", path, strerror(errno));
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
@@ -3469,7 +3469,7 @@ int BLO_write_file(Main *mainvar, const char *filepath, int write_flags, ReportL
|
||||
BLI_snprintf(tempname, sizeof(tempname), "%s@", filepath);
|
||||
|
||||
file = BLI_open(tempname, O_BINARY+O_WRONLY+O_CREAT+O_TRUNC, 0666);
|
||||
if (file < 0) {
|
||||
if (file == -1) {
|
||||
BKE_reportf(reports, RPT_ERROR, "Cannot open file %s for writing: %s", tempname, strerror(errno));
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -651,7 +651,7 @@ static unsigned char *prefetch_read_file_to_memory(MovieClip *clip, int current_
|
||||
BKE_movieclip_filename_for_frame(clip, &user, name);
|
||||
|
||||
file = BLI_open(name, O_BINARY | O_RDONLY, 0);
|
||||
if (file < 0) {
|
||||
if (file == -1) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
@@ -215,7 +215,8 @@ ImBuf *IMB_loadiffname(const char *filepath, int flags, char colorspace[IM_MAX_S
|
||||
imb_cache_filename(filepath_tx, filepath, flags);
|
||||
|
||||
file = BLI_open(filepath_tx, O_BINARY | O_RDONLY, 0);
|
||||
if (file < 0) return NULL;
|
||||
if (file == -1)
|
||||
return NULL;
|
||||
|
||||
ibuf = IMB_loadifffile(file, filepath, flags, colorspace, filepath_tx);
|
||||
|
||||
@@ -242,7 +243,8 @@ ImBuf *IMB_testiffname(const char *filepath, int flags)
|
||||
imb_cache_filename(filepath_tx, filepath, flags);
|
||||
|
||||
file = BLI_open(filepath_tx, O_BINARY | O_RDONLY, 0);
|
||||
if (file < 0) return NULL;
|
||||
if (file == -1)
|
||||
return NULL;
|
||||
|
||||
ibuf = IMB_loadifffile(file, filepath, flags | IB_test | IB_multilayer, colorspace, filepath_tx);
|
||||
|
||||
@@ -285,7 +287,8 @@ void imb_loadtile(ImBuf *ibuf, int tx, int ty, unsigned int *rect)
|
||||
int file;
|
||||
|
||||
file = BLI_open(ibuf->cachename, O_BINARY | O_RDONLY, 0);
|
||||
if (file < 0) return;
|
||||
if (file == -1)
|
||||
return;
|
||||
|
||||
imb_loadtilefile(ibuf, file, tx, ty, rect);
|
||||
|
||||
|
||||
@@ -200,7 +200,7 @@ bool IMB_ispic(const char *name)
|
||||
if (((st.st_mode) & S_IFMT) != S_IFREG)
|
||||
return false;
|
||||
|
||||
if ((fp = BLI_open(name, O_BINARY | O_RDONLY, 0)) < 0)
|
||||
if ((fp = BLI_open(name, O_BINARY | O_RDONLY, 0)) == -1)
|
||||
return false;
|
||||
|
||||
memset(buf, 0, sizeof(buf));
|
||||
|
||||
Reference in New Issue
Block a user