mescc: Add debug printing: fopen, fwrite.

* lib/libc+tcc.c (fopen, fwrite)[MESC_DEBUG]: Print debug info.
This commit is contained in:
Jan Nieuwenhuizen 2018-06-10 07:51:56 +02:00
parent 3ba5b23dab
commit a744fd9ba4
No known key found for this signature in database
GPG key ID: F3C1A0D9C1D65273

View file

@ -170,9 +170,21 @@ fread (void *data, size_t size, size_t count, FILE *stream)
size_t size_t
fwrite (void const *data, size_t size, size_t count, FILE *stream) fwrite (void const *data, size_t size, size_t count, FILE *stream)
{ {
if (getenv ("MESC_DEBUG"))
{
eputs ("fwrite "); eputs (itoa ((int)stream));
eputs (" "); eputs (itoa (size)); eputs ("\n");
}
if (! size || !count) if (! size || !count)
return 0; return 0;
int bytes = write ((int)stream, data, size * count); int bytes = write ((int)stream, data, size * count);
if (getenv ("MESC_DEBUG"))
{
eputs (" => "); eputs (itoa (bytes)); eputs ("\n");
}
if (bytes > 0) if (bytes > 0)
return bytes/size; return bytes/size;
return 0; return 0;
@ -187,6 +199,12 @@ ftell (FILE *stream)
FILE* FILE*
fopen (char const *file_name, char const *opentype) fopen (char const *file_name, char const *opentype)
{ {
if (getenv ("MESC_DEBUG"))
{
eputs ("fopen "); eputs (file_name);
eputs (" "); eputs (opentype); eputs ("\n");
}
int fd; int fd;
int mode = 0600; int mode = 0600;
if ((opentype[0] == 'a' || !strcmp (opentype, "r+")) if ((opentype[0] == 'a' || !strcmp (opentype, "r+"))
@ -205,6 +223,11 @@ fopen (char const *file_name, char const *opentype)
else else
fd = open (file_name, 0, 0); fd = open (file_name, 0, 0);
if (getenv ("MESC_DEBUG"))
{
eputs (" => fd="); eputs (itoa (fd)); eputs ("\n");
}
return (FILE*)fd; return (FILE*)fd;
} }