stat() does not work for .so files
I am facing an issue with stat() . stat() does not seem to be working with .so files. It gives the error
No such file or directory .
Why is this happening?
As requested I paste a portion of the code:
int main()
{
char str[300];
struct stat str_buf;
strcpy(str,"开发者_StackOverflow中文版path/to/my/library/libfuncs.so");
if(stat(str,$str_buf)==-1)
perror("stat");
....
}
Thus the error comes as stat No such file or directory
But the same code works fine for other files and directories. libfuncs.so is my generated shared library.
Many ".so" files are in fact symbolic links due to versioning issues. You might want to use lstat()
in those cases, to stat the actual link.
The error you're getting ("No such file or directory") seems to imply that the symbolic link is pointing at something that doesn't exist. In these cases stat:ing the link itself helps, but of course that might not be what you want to do. Check the link's target. If the path in the link is relative, perhaps you're executing the code from a different directory?
Probable reason
I can only guess that "path/to/my/library/libfuncs.so"
does not really exist. You could test that simply by typing ls "path/to/my/library/libfuncs.so"
.
I am pretty sure that
stat() does
notwork
I guess this once again solves for a "bug" in a very well established library.
Theoratically possible reason.
You use $
for a variable name. That is not permitted. The C99 Standard has this to say about this:
Both the basic source and basic execution character sets shall have the following members: the 26 uppercase letters of the Latin alphabet
A B C D E F G H I J K L M
N O P Q R S T U V W X Y Z
the 26 lowercase letters of the Latin alphabet
a b c d e f g h i j k l m
n o p q r s t u v w x y z
the 10 decimal digits
0 1 2 3 4 5 6 7 8 9
the following 29 graphic characters
! " # % & ' ( ) * + , - . / :
; < = > ? [ \ ] ^ _ { | } ~
Further:
If ...
any other characters are encountered in a source file (except in an identifier, a character constant, a string literal, a header name, a comment, or a preprocessing token that is never converted to a token),
guess what? ** drumroll **
the behavior is undefined.
Yay party.but I think it is the first reason.
精彩评论