Results 1 to 3 of 3
I am using embedded Linux. File open is successful. The file has all the permissions. It is present in current directory too. The size is about 27KB. But s.st_size says ...
- 06-17-2010 #1Just Joined!
- Join Date
- Apr 2010
- Posts
- 4
In correct File is empty
I am using embedded Linux. File open is successful. The file has all the permissions. It is present in current directory too. The size is about 27KB. But s.st_size says it is zero. Any thoughts.
inputFileName = "abc.mp3";
FILE* inFile = NULL;
inFile = fopen(inputFileName, "r+b");
fprintf(stderr, " inside current dir r+b my_mp4creator new:%s \n",inputFileName);
if (inFile == NULL) {
fprintf(stderr,
"%s: can't open file %s: %s\n",
ProgName, inputFileName, strerror(errno));
return NULL;
}
struct stat s;
if (fstat(fileno(inFile), &s) < 0) {
fprintf(stderr,
"%s: can't stat file %s: %s\n",
ProgName, inputFileName, strerror(errno));
return NULL;
}
if (s.st_size == 0) {
fprintf(stderr,
"%s: file %s is empty\n",
ProgName, inputFileName);
return NULL;
}
Thank you in advance.
- 06-17-2010 #2Just Joined!
- Join Date
- Jun 2010
- Posts
- 10
Hi,
I haven't verified this yet but AFAIK defining
is your offence.Code:FILE * infile = NULL;
Defining a NULL pointer is valid, but it doesn't point to anything. This means that opening the file won't fail, but will point to nothing so any operations on that file will essentially do nothing.
try this:that will then test to see if the pointer is correctly set up before it operates on the file.Code:/*stuff FILE * inFile; if (inFile !=NULL){ /*more stuff*/
/*Hope that helps*/
- 06-17-2010 #3Just Joined!
- Join Date
- Jun 2010
- Posts
- 10
Hi,
I haven't test this, but I think defining
is your offence.Code:FILE * infile = NULL;
defining a NULL pointer is valid, but it doesn't point to anything. This means that opening the file won't fail, but will point to nothing so any operations on that file will essentially do nothing.
...come to think of it, there is a large number of return(NULL) going on.
If you are returning to main() I would suggest returning an int. It means you know in what state the program quit. Also, gcc will call BS on defining main() as anything other than int
the program below produces the following warnings on my machine (GCC 4)
Code:#include <stdio.h> void main(void) { ; return NULL; }Hope that helps.gcc test.c
test.c: In function 'main':
test.c:7: warning: 'return' with a value, in function returning void
test.c:5: warning: return type of 'main' is not 'int'


Reply With Quote