Skip to content

Commit 75ec1fe

Browse files
committed
Add php_ignore_value() macro to suppress unused return value warnings
from gcc. There are times when we really don't care about the return value and this will cleanly tell gcc.
1 parent 27dd44d commit 75ec1fe

File tree

4 files changed

+12
-7
lines changed

4 files changed

+12
-7
lines changed

ext/session/mod_files.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ PS_WRITE_FUNC(files)
390390
/* Truncate file if the amount of new data is smaller than the existing data set. */
391391

392392
if (vallen < (int)data->st_size) {
393-
ftruncate(data->fd, 0);
393+
php_ignore_value(ftruncate(data->fd, 0));
394394
}
395395

396396
#if defined(HAVE_PWRITE)

ext/soap/php_sdl.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -2339,7 +2339,7 @@ static void add_sdl_to_cache(const char *fn, const char *uri, time_t t, sdlPtr s
23392339
}
23402340
}
23412341

2342-
write(f, buf.c, buf.len);
2342+
php_ignore_value(write(f, buf.c, buf.len));
23432343
close(f);
23442344
smart_str_free(&buf);
23452345
zend_hash_destroy(&tmp_functions);

main/main.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ PHPAPI void php_log_err(char *log_message TSRMLS_DC)
561561
#ifdef PHP_WIN32
562562
php_flock(fd, 2);
563563
#endif
564-
write(fd, tmp, len);
564+
php_ignore_value(write(fd, tmp, len));
565565
efree(tmp);
566566
efree(error_time_str);
567567
close(fd);
@@ -2301,7 +2301,7 @@ PHPAPI int php_execute_script(zend_file_handle *primary_file TSRMLS_DC)
23012301
/* this looks nasty to me */
23022302
old_cwd_fd = open(".", 0);
23032303
#else
2304-
VCWD_GETCWD(old_cwd, OLD_CWD_SIZE-1);
2304+
php_ignore_value(VCWD_GETCWD(old_cwd, OLD_CWD_SIZE-1));
23052305
#endif
23062306
VCWD_CHDIR_FILE(primary_file->filename);
23072307
}
@@ -2360,7 +2360,7 @@ PHPAPI int php_execute_script(zend_file_handle *primary_file TSRMLS_DC)
23602360
}
23612361
#else
23622362
if (old_cwd[0] != '\0') {
2363-
VCWD_CHDIR(old_cwd);
2363+
php_ignore_value(VCWD_CHDIR(old_cwd));
23642364
}
23652365
free_alloca(old_cwd, use_heap);
23662366
#endif
@@ -2390,14 +2390,14 @@ PHPAPI int php_execute_simple_script(zend_file_handle *primary_file, zval **ret
23902390
PG(during_request_startup) = 0;
23912391

23922392
if (primary_file->filename && !(SG(options) & SAPI_OPTION_NO_CHDIR)) {
2393-
VCWD_GETCWD(old_cwd, OLD_CWD_SIZE-1);
2393+
php_ignore_value(VCWD_GETCWD(old_cwd, OLD_CWD_SIZE-1));
23942394
VCWD_CHDIR_FILE(primary_file->filename);
23952395
}
23962396
zend_execute_scripts(ZEND_REQUIRE TSRMLS_CC, ret, 1, primary_file);
23972397
} zend_end_try();
23982398

23992399
if (old_cwd[0] != '\0') {
2400-
VCWD_CHDIR(old_cwd);
2400+
php_ignore_value(VCWD_CHDIR(old_cwd));
24012401
}
24022402

24032403
free_alloca(old_cwd, use_heap);

main/php.h

+5
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,11 @@ END_EXTERN_C()
259259
# endif
260260
#endif
261261

262+
#if defined(__GNUC__) && __GNUC__ >= 4
263+
# define php_ignore_value(x) (({ __typeof__ (x) __x = (x); (void) __x; }))
264+
#else
265+
# define php_ignore_value(x) ((void) (x))
266+
#endif
262267

263268
/* global variables */
264269
#if !defined(PHP_WIN32)

0 commit comments

Comments
 (0)