Commit 50476bb1 authored by Arnaud Blanchard's avatar Arnaud Blanchard
Browse files

Fix accolade problems with SSCANF, ... functions

parent 87bdfc48
...@@ -215,13 +215,13 @@ MANY_REALLOCATIONS(&values, 7); ...@@ -215,13 +215,13 @@ MANY_REALLOCATIONS(&values, 7);
#define STRCPY(buffer, source) do {if (source==NULL) EXIT_ON_ERROR("source must not be NULL"); else if (buffer==NULL) EXIT_ON_ERROR("destination must not be NULL"); if (strlen(source)+1 > (int)sizeof(buffer)) EXIT_ON_ERROR("The length ('%d') of the your source ('%s') is longer than the receiving buffer: '%ld'.\nREMARQ: if the first argument is not a static buffer, this test is WRONG. The size of the pointer and not the size of the buffer is considered ! Use strncpy and make yourself the verification.", strlen(source)+1, source, sizeof(buffer)); else strcpy(buffer, source);}while(0) //tricks to not have problem in a if #define STRCPY(buffer, source) do {if (source==NULL) EXIT_ON_ERROR("source must not be NULL"); else if (buffer==NULL) EXIT_ON_ERROR("destination must not be NULL"); if (strlen(source)+1 > (int)sizeof(buffer)) EXIT_ON_ERROR("The length ('%d') of the your source ('%s') is longer than the receiving buffer: '%ld'.\nREMARQ: if the first argument is not a static buffer, this test is WRONG. The size of the pointer and not the size of the buffer is considered ! Use strncpy and make yourself the verification.", strlen(source)+1, source, sizeof(buffer)); else strcpy(buffer, source);}while(0) //tricks to not have problem in a if
/// Do a fscanf checking than the number of interpreted arguments corresponds to the first parameter. /// Do a fscanf checking than the number of interpreted arguments corresponds to the first parameter.
#define FSCANF(fields_nb, file, ... ) if (fscanf(file, __VA_ARGS__) != fields_nb) EXIT_ON_ERROR("Failed reading %d fields.", fields_nb) #define FSCANF(fields_nb, file, ... ) do{if (fscanf(file, __VA_ARGS__) != fields_nb) EXIT_ON_ERROR("Failed reading %d fields.", fields_nb);}while(0)
/// Do a fscanf checking than the number of interpreted arguments corresponds to the first parameter. /// Do a fscanf checking than the number of interpreted arguments corresponds to the first parameter.
#define SSCANF(fields_nb, string, ... ) if (sscanf(string, __VA_ARGS__) != fields_nb) EXIT_ON_ERROR("Failed reading %d fields in '%s'.", fields_nb, string) #define SSCANF(fields_nb, string, ... ) do{if (sscanf(string, __VA_ARGS__) != fields_nb) EXIT_ON_ERROR("Failed reading %d fields in '%s'.", fields_nb, string);}while(0)
/// Like FSCANF but generates only a warning in case of error. /// Like FSCANF but generates only a warning in case of error.
#define TRY_FSCANF(fields_nb, file, ... ) if (fscanf(file, __VA_ARGS__) != fields_nb) PRINT_WARNING("Failed trying reading %d fields in '%s'.", fields_nb) #define TRY_FSCANF(fields_nb, file, ... ) do{if (fscanf(file, __VA_ARGS__) != fields_nb) PRINT_WARNING("Failed trying reading %d fields in '%s'.", fields_nb);}while(0)
#ifndef BSD #ifndef BSD
///Only BSD defines this shortcut ///Only BSD defines this shortcut
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment