[Bf-blender-cvs] [551096d] master: BLI_open: check returned value for `-1` instead of `< 0`

Campbell Barton noreply at git.blender.org
Tue Apr 22 08:44:31 CEST 2014


Commit: 551096d6fd414510c4d726d0dae2f9703cb440d9
Author: Campbell Barton
Date:   Tue Apr 22 16:40:17 2014 +1000
https://developer.blender.org/rB551096d6fd414510c4d726d0dae2f9703cb440d9

BLI_open: check returned value for `-1` instead of `< 0`

===================================================================

M	source/blender/blenkernel/intern/blender.c
M	source/blender/blenkernel/intern/image.c
M	source/blender/blenkernel/intern/movieclip.c
M	source/blender/blenkernel/intern/packedFile.c
M	source/blender/blenlib/intern/fileops.c
M	source/blender/blenloader/intern/runtime.c
M	source/blender/blenloader/intern/writefile.c
M	source/blender/editors/space_clip/clip_editor.c
M	source/blender/imbuf/intern/readimage.c
M	source/blender/imbuf/intern/util.c

===================================================================

diff --git a/source/blender/blenkernel/intern/blender.c b/source/blender/blenkernel/intern/blender.c
index 9b1f2e8..c238052 100644
--- a/source/blender/blenkernel/intern/blender.c
+++ b/source/blender/blenkernel/intern/blender.c
@@ -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);
diff --git a/source/blender/blenkernel/intern/image.c b/source/blender/blenkernel/intern/image.c
index c0c0286..343d82e 100644
--- a/source/blender/blenkernel/intern/image.c
+++ b/source/blender/blenkernel/intern/image.c
@@ -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);
 
diff --git a/source/blender/blenkernel/intern/movieclip.c b/source/blender/blenkernel/intern/movieclip.c
index 5012c08..63f0d05 100644
--- a/source/blender/blenkernel/intern/movieclip.c
+++ b/source/blender/blenkernel/intern/movieclip.c
@@ -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);
 
diff --git a/source/blender/blenkernel/intern/packedFile.c b/source/blender/blenkernel/intern/packedFile.c
index 71504bb..fc8a23a 100644
--- a/source/blender/blenkernel/intern/packedFile.c
+++ b/source/blender/blenkernel/intern/packedFile.c
@@ -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 {
diff --git a/source/blender/blenlib/intern/fileops.c b/source/blender/blenlib/intern/fileops.c
index 988979b..bcceb00 100644
--- a/source/blender/blenlib/intern/fileops.c
+++ b/source/blender/blenlib/intern/fileops.c
@@ -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) {
diff --git a/source/blender/blenloader/intern/runtime.c b/source/blender/blenloader/intern/runtime.c
index ca9f2fa..d6fd2f9 100644
--- a/source/blender/blenloader/intern/runtime.c
+++ b/source/blender/blenloader/intern/runtime.c
@@ -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;
 	}
diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c
index b4f7332..71e490d 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -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;
 	}
diff --git a/source/blender/editors/space_clip/clip_editor.c b/source/blender/editors/space_clip/clip_editor.c
index c5dcc74..c67e846 100644
--- a/source/blender/editors/space_clip/clip_editor.c
+++ b/source/blender/editors/space_clip/clip_editor.c
@@ -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;
 	}
 
diff --git a/source/blender/imbuf/intern/readimage.c b/source/blender/imbuf/intern/readimage.c
index 6988687..1124d06 100644
--- a/source/blender/imbuf/intern/readimage.c
+++ b/source/blender/imbuf/intern/readimage.c
@@ -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);
 
diff --git a/source/blender/imbuf/intern/util.c b/source/blender/imbuf/intern/util.c
index a919907..36f8367 100644
--- a/source/blender/imbuf/intern/util.c
+++ b/source/blender/imbuf/intern/util.c
@@ -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));




More information about the Bf-blender-cvs mailing list