1

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.

SKD
  • 464
  • 1
  • 4
  • 16
  • Where you have defined `UNIX` or `NT_OS`? – SKD Feb 23 '16 at 11:08
  • 2
    IME, the easiest approach is to compile the application as 64 bit. The "LARGE_FILES"/etc flags are only for the 32 bit applications. Otherwise, IIRC the `stat64()` should be available always along with the normal `stat()`: they exist specifically to facilitate the 64-bit interface for 32-bit applications. – Dummy00001 Feb 23 '16 at 11:32
  • You can use the -D option to define the macro when compiling. I also suggest checking this. http://stackoverflow.com/questions/4357570/use-file-offset64-vs-file-offset-bits-64 – Umamahesh P Feb 23 '16 at 11:34
  • @Dummy00001 - Just note that the 64-bit `FILE` structure on Solaris is completely opaque, so code that relies on access to the specific `FILE` implementation will need to be fixed. A few links to relevant documentation: https://www.google.com/search?q=solaris+64-bit+FILE+is+opaque – Andrew Henle Feb 23 '16 at 12:21
  • `HP-AIX` is a short for "HP-UX and AIX"? – Jdamian Jun 21 '16 at 12:00

3 Answers3

2

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.

Andrew Henle
  • 32,625
  • 3
  • 24
  • 56
1

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
dbush
  • 205,898
  • 23
  • 218
  • 273
0

Linux/Solaris/HP-UX

-D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE

AIX

-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

Like
  • 1,470
  • 15
  • 21