Operating System - HP-UX
1834453 Members
1935 Online
110067 Solutions
New Discussion

Re: Different behaviour of stat() in a library

 

Different behaviour of stat() in a library

I have a strange problem with a shared library on 64 bit HP-UX 11.0. The lib uses stat(). When calling the library from a self-written command line tool, the stat() call behaves as expected. However, when calling the same routine in the same library (no recompile) with exactly the same parameters from a different environment, it behaves differently: The call to stat() fails with a return code of -1 when the file is not found (which is correct), but errno remains zero (which, to my understanding, means "no error").

The strange thing is that the library has not been recompiled from one case to another. Also, our code does not exchange any file handles with the library; all file related stuff is completely encapsulated in the library,so I don't think this is related to the various large file support APIS availabe (stat64() vs. stat() etc.).

So calling from a command line tools gives one behavior, and calling from another environment (python, in this case) gives another. How can this be caused without a recompile?!?

My idea was that a different stat() implementation gets executed because python is linked against other runtime libraries than our tool. However, to my knowledge, there is only one actual, executable stat() implementation; the various possibilities of calling stat() are sorted out during *compile* time by the system headers. And accidentally linking 32 bit cannot happen because they are not compatible with 64 bit libs.

Any help on what is going wrong here would be very much appreciated!

Kind regards,

Martin
2 REPLIES 2
David Johns
Advisor

Re: Different behaviour of stat() in a library

Hi Martin:

Have you checked if errno is set when other system calls fail? It could just be a problem with the way errno is declared. I have been using #include in C, which has the declaration "extern int errno;". How do you do this in Python?

Cheers,
Dave

Sean Hu
New Member

Re: Different behaviour of stat() in a library

I am not quite familiar with Python, but you are probably running in a threaded environment. If this is the case, you need to add -D_REENTRANT when you build your library. Do a search on "errno madness" in google and you will get more information.

Good luck!