libfswrap/main.c

46 lines
842 B
C

#include <errno.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
int main(int argc, char *argv[])
{
int ret = EXIT_FAILURE;
static const char path[] = "myfile.txt";
FILE *const f = fopen(path, "rb");
if (!f)
{
fprintf(stderr, "%s: fopen(3) %s: %s\n", __func__, path,
strerror(errno));
goto end;
}
for (;;)
{
char c;
if (fread(&c, sizeof c, 1, f))
printf("(%#hhx)\n", c);
else if (ferror(f))
{
fprintf(stderr, "%s: ferror\n", __func__);
goto end;
}
else if (feof(f))
break;
}
ret = EXIT_SUCCESS;
end:
if (f && fclose(f))
{
fprintf(stderr, "%s: fclose(3): %s\n", __func__, strerror(errno));
ret = EXIT_FAILURE;
}
return ret;
}