Reputation:
I Have a C Program as follow. I don't what to use stat64 instead of stat in both Solaris & HP-AIX. I want to build this Program this on both Solaris & HP-AIX.
#include "zunx.h"
#include <nls.h>
/*
* NAME: zunx_file_exists
*
* PURPOSE: Checks if a file exists.
*
* INVOCATION: boolean zunx_file_exists(name)
* char *name;
*
* INPUTS: name - file to check
*
* OUTPUTS: TRUE or FALSE
*
* DESCRIPTION: zunx_file_exists does a stat on the specified file,
* and returns TRUE if a stat is found. No check is
* made to determine what type of file it is.
*/
boolean zunx_file_exists
(const char *buf)
{
#if defined(UNIX)
struct stat fstat;
if (buf != NULL && stat(I2E1(buf), &fstat) == 0)
return TRUE;
else
return FALSE;
#endif
#ifdef NT_OS
struct _stat64 fstat;
if (buf != NULL && _stat64((char *) I2E1(buf), &fstat) == 0)
return TRUE;
else
return FALSE;
#endif
}
I came across a macro in Solaris like :
#ifdef UNIX
#define _FILE_OFFSET_BITS 64
#endif
is this definition is correct for above program?
for HP-AIX its use _LARGE_FILES
macro.
but I don't know how to define this macro in above program in order to run successfully on both OS.
Please suggest some ideas.
Upvotes: 1
Views: 1669
Reputation: 1536
-D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE
-D_LARGE_FILES
Effective for AIX >= 5.1
See also: https://www.ibm.com/docs/en/aix/7.1?topic=volumes-writing-programs-that-access-large-files
Upvotes: 0
Reputation: 224917
The exact names and values of these #define
's are implementation dependent. Fortunately, the getconf
shell command will tell you what these are when you pass it the LFS_CFLAGS
parameter. You can then pass them in on the command line when you compile.
gcc `getconf LFS_CFLAGS` -o program program.c
Upvotes: 1
Reputation: 1
Detailed data for accessing large files, including large file compile, link, and other flags can be found for Solaris on the lfcompile
man page:
lfcompile
- large file compilation environment for 32-bit applications
Description
All 64-bit applications can manipulate large files by default. The methods described on this page allow 32-bit applications to manipulate large files.
...
Note that the man page specifically states that defines other than those returned via getconf
are necessary:
Set the compile-time flag _FILE_OFFSET_BITS to 64 before including any headers. Applications may combine objects produced in the large file compilation environment with objects produced in the transitional compilation environment, but must be careful with respect to interoperability between those objects. Applications should not declare global variables of types whose sizes change between compilation environments.
along with
Applications wishing to access fseeko() and ftello() as well as the POSIX and X/Open specification-conforming interfaces should define the macro _LARGEFILE_SOURCE to be 1 and set whichever feature test macros are appropriate to obtain the desired environment (see standards(5)).
See the examples section of the man page for details.
Upvotes: 2