NO

Author Topic: what lib to include for _stati64?  (Read 3957 times)

Offline tony74

  • Member
  • *
  • Posts: 25
what lib to include for _stati64?
« on: August 14, 2021, 08:11:10 PM »
Using Pelles C 10.00.6,  I added the defs for the struct and the function to sys/stats.h but the linker doesn't find _stati64 object, I thought this was part of MSVCRT by default...no?

Anyway, I have VS 2015, could always port over to that, but I thought I'd mention it in case I'm just missing something (which I probably am...).

Thanks, Tony

Offline tony74

  • Member
  • *
  • Posts: 25
Re: what lib to include for _stati64?
« Reply #1 on: August 14, 2021, 11:15:53 PM »
OK, got it.  I had to settle for _stat64() instead of _stati64() because the crt64.lib that comes with version 10.00.6 only has _stat64().

Here's the function that wouldn't compile:

Code: [Select]
int getsize(char *infile, char *keyfile)
{
 struct __stat64 inbuf, keybuf;
 int rn, rk;

 rn =_stat64( infile,  &inbuf  );
 rk =_stat64( keyfile, &keybuf );

 if(rn!=0 || rk!=0){
    printf("stat64 error...\n");
    return -1;
 }

 if(inbuf.st_size < keybuf.st_size)
    printf("infile is smaller than keyfile - OK\n");
 else
    printf("infile is greater than keyfile - NOT OK!\n");

return 0;
}


What I did:
in sys/stat.h, I added these defs:

Code: [Select]
#ifndef _STAT64_DEFINED
#define _STAT64_DEFINED
struct __stat64
{
    _dev_t st_dev;
    _ino_t st_ino;
    unsigned short st_mode;
    short st_nlink;
    short st_uid;
    short st_gid;
    _dev_t st_rdev;
    __int64 st_size;
    time_t st_atime;
    time_t st_mtime;
    time_t st_ctime;
};
#endif

extern _CRTIMP int __cdecl _stat64(const char *, struct __stat64 *);


That handled the declarations. To handle the lib, I added crt64.lib to the linker.

At least on my test files, it worked. I needed the ability to check for file sizes possibly greater than 4GB, so had to have a 64-bit version of _stat(), which the default headers don't provide.

Thanks for looking.






« Last Edit: August 14, 2021, 11:20:57 PM by tony74 »

Offline John Z

  • Member
  • *
  • Posts: 790
Re: what lib to include for _stati64?
« Reply #2 on: August 15, 2021, 10:39:48 AM »
Glad you resolved the issue and thanks for the update.  Version 11 has been released so you might see if that has what you are looking for.  I'm not familiar with _stat64 but there are other functions that will yield the filesize like _wfindfirst64 and Pelles extension long long int _filelength64(int handle);


John Z

Offline tony74

  • Member
  • *
  • Posts: 25
Re: what lib to include for _stati64?
« Reply #3 on: August 15, 2021, 06:21:58 PM »
Thanks, John.

The advantage of stat() is that you don't need to open the file, you get the info from the system, which already has it registered.

With anything in the findfirst or filelength family, the file has to be opened first, either to execute a find or obtain a handle.

stat() just needs a path/filename and returns all the info on a file in a struct (see previous post), keeps it simple.


Tony

« Last Edit: August 15, 2021, 06:34:54 PM by tony74 »

Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 2096
Re: what lib to include for _stati64?
« Reply #4 on: August 15, 2021, 07:45:25 PM »
Thanks, John.

The advantage of stat() is that you don't need to open the file, you get the info from the system, which already has it registered.

With anything in the findfirst or filelength family, the file has to be opened first, either to execute a find or obtain a handle.

stat() just needs a path/filename and returns all the info on a file in a struct (see previous post), keeps it simple.


Tony
Unfortunately this is really true on a *nix systems where the access is on the internal inode structures (stat in *nix is a kernel function).
On windows system, where the NTFS isnt't even fully POSIX compatible, the stat() function, more tricky here, opens an handle to the file using CreateFile(), then retrieves info using GetFileInformationByHandle() function. The obtained data is then suitably used to fill the stat structure.
You may have a look to the Gnu-win stat utility source.
As a rule of thumb consider that all the C runtime functions call OS functions counterpart.
« Last Edit: August 15, 2021, 07:47:23 PM by frankie »
It is better to be hated for what you are than to be loved for what you are not. - Andre Gide

Offline tony74

  • Member
  • *
  • Posts: 25
Re: what lib to include for _stati64?
« Reply #5 on: August 15, 2021, 08:04:28 PM »
Thanks Frankie, I didn't know that.

Although, the fact remains that the call is still simpler.  It abstracts the coding we'd normally have to do to accomplish the same thing.

I do still have questions as relates to using the crt64.lib, though:

I downloaded Pelles-C v11 to see if any headers were added for the crt64.lib but didn't see anything for _stat64, _fseek64 or _ftell64 in either sys/stat.h, stdio.h or io.h.

So are the crt64 headers in a different location or do I need to 'roll my own'?

It's not a big deal either way, just thought I'd ask.

Thanks,

Tony

Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 2096
Re: what lib to include for _stati64?
« Reply #6 on: August 15, 2021, 09:23:33 PM »
I do still have questions as relates to using the crt64.lib, though:
I downloaded Pelles-C v11 to see if any headers were added for the crt64.lib but didn't see anything for _stat64, _fseek64 or _ftell64 in either sys/stat.h, stdio.h or io.h.
So are the crt64 headers in a different location or do I need to 'roll my own'?
It's not a big deal either way, just thought I'd ask.
Thanks,

Tony
I'm not sure to have understood what you have looked for.
Anyway the functions _fseek64 and _ftell64 exists since 2014 when they were introduced in stdio.h. These are declarations taken from stdio.h V11:
Code: [Select]
extern _CRTIMP int __cdecl _fseek64(FILE *, long long, int);  /* 14-06-29 */
extern _CRTIMP long long __cdecl _ftell64(FILE *);  /* 14-06-29 */
The _stat64 is available when the target is a 64bits, selecting the option /Gx, or checking the relative radio button in the project properties sheet, compiler section, that extends the time_t type to 64bits. In that case _stat automatically maps to _stat64.
Anyway you'll find all info just reading the help file.
« Last Edit: August 15, 2021, 09:25:20 PM by frankie »
It is better to be hated for what you are than to be loved for what you are not. - Andre Gide

Offline tony74

  • Member
  • *
  • Posts: 25
Re: what lib to include for _stati64?
« Reply #7 on: August 15, 2021, 10:25:44 PM »
I see now. Those were under /* private extensions to standard C */,  I should not have ended my search so soon.

And thanks for the /Gx flag, that will simplify things a lot.

Thanks again,


Tony