d1a424c002
This will allow us to redefine the exit function.
For example:
```
#define exit(code) { \
fprintf(stderr, "%s:%d: exit(%s) in function ‘%s’\n",
__FILE__, __LINE__, #code, __func__); \
_exit(code); \
}
```
33 lines
680 B
C
33 lines
680 B
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
int main(void) {
|
|
char buffer[72];
|
|
|
|
int ret = sprintf(
|
|
buffer,
|
|
"This string fits in the buffer because it is only %d bytes in length",
|
|
68
|
|
);
|
|
if (ret != 68) {
|
|
printf("Failed! Return value was %d\n", ret);
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
|
|
memset(buffer, 0, sizeof(buffer));
|
|
|
|
ret = snprintf(
|
|
buffer,
|
|
10,
|
|
"This string is way longer and does not fit in the buffer because it %d bytes in length",
|
|
86
|
|
);
|
|
if (ret != 86) {
|
|
printf("Failed! Return value was %d\n", ret);
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
|
|
puts(buffer);
|
|
}
|