public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* Regarding EFBIG error while opening a file using catopen() function
@ 2022-12-12  5:10 Kavita Gore
  2022-12-12 10:25 ` Corinna Vinschen
  0 siblings, 1 reply; 2+ messages in thread
From: Kavita Gore @ 2022-12-12  5:10 UTC (permalink / raw)
  To: cygwin, cygwin-owner, mailman, cygwin-developers,
	cygwin-developers-owner
  Cc: parulsoni799, atulpathare226, rajeshrube

[-- Attachment #1: Type: text/plain, Size: 1424 bytes --]

Hi all,

I'm getting errno 27[EFBIG] file too large while opening catalogue with
catopen() function in the cygwin-32bit version.



Trying to open a .cat file but catopen() returns a file too large [EFBIG]
error.



this is the code snippet I was working with:



#define FILENAME    TEMP.CAT



   buffer = catopen(FILENAME, 0);

        if (buffer != (nl_catd) - 1)

         {

            printf("File open successfully");

        }

        else

        {

            printf("errno: %d\n", errno);

        }





While debugging using gdb.I've found that st.st_size is 0 and As per my
understanding struct stat.st_size is declared as off_t, which is most
probably signed, and resolves to long (signed by default).

So if SIZE_T_MAX does not fit into 2^31-1 (it most probably does not) it
will appear as negative in the comparison.

I suspect like off_t is supposed to be signed, and size_t is supposed to be
unsigned, both according to POSIX.

That means, this comparison has definitely a signedness issue.

So that's why if condition getting success and returning errno 27(EFBIG).



Coding snippet where if condition getting succeed:

Msgcat.c:

=======

if (st.st_size > SIZE_T_MAX) {

        _close(fd);

        SAVEFAIL(name, lang, EFBIG);

        NLRETERR(EFBIG);

    }


I'd like to know the reason why I'm getting this error and How it can be
resolved as it is a blocker in my task.


Regards,

Kavita.

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Regarding EFBIG error while opening a file using catopen() function
  2022-12-12  5:10 Regarding EFBIG error while opening a file using catopen() function Kavita Gore
@ 2022-12-12 10:25 ` Corinna Vinschen
  0 siblings, 0 replies; 2+ messages in thread
From: Corinna Vinschen @ 2022-12-12 10:25 UTC (permalink / raw)
  To: cygwin; +Cc: Kavita Gore


It's somewhat rude to send such a request to everybody and the kitchen
sink.

This belong on the cygwin ML, so please keep it here.

On Dec 12 10:40, Kavita Gore via Cygwin wrote:
> Hi all,
> 
> I'm getting errno 27[EFBIG] file too large while opening catalogue with
> catopen() function in the cygwin-32bit version.
> 
>  [...]
> #define FILENAME    TEMP.CAT
> 
>    buffer = catopen(FILENAME, 0);
>         if (buffer != (nl_catd) - 1)
>          {
>             printf("File open successfully");
>         }
>         else
>         {
>             printf("errno: %d\n", errno);
>         }
> 
> While debugging using gdb.I've found that st.st_size is 0 and As per my
> understanding struct stat.st_size is declared as off_t, which is most
> probably signed, and resolves to long (signed by default).

Since you're running gdb anyway, why don't you *ask* gdb what type
off_t is?

  (gdb) ptype off_t
  type = long long

> So if SIZE_T_MAX does not fit into 2^31-1 (it most probably does not) it
> will appear as negative in the comparison.

No, under implicit type conversion rules, the comparison is well
defined.  size_t is 32 bit on 32 bit systems, off_t is 64 bit.  So the
comparison will convert __SIZE_MAX__ losslessly to long long.  On 64 bit
systems, size_t is 64 bit, off_t is 64 bit.  The comparison will be
performed unsigned, thus it will never be true.

$ cat > x.c <<EOF
#define _GNU_SOURCE 1
#include <stdio.h>
#include <stdlib.h>

int
main (int argc, char **argv)
{
  off_t o = strtoll (argv[1], NULL, 0);

  if (o > __SIZE_MAX__)
    puts ("too big");
}
EOF
$ gcc -g -o x x.c

On 32 bit:

$ ./x 0
$ ./x 1
$ ./x 0xffffffff
$ ./x 0x100000000
too big

On 64 bit:

$ ./x 0
$ ./x 1
$ ./x 0xffffffff
$ ./x 0x100000000
$ ./x 0xffffffffffffffff
$ ./x 0x7fffffffffffffff
$


> I'd like to know the reason why I'm getting this error and How it can be
> resolved as it is a blocker in my task.

You may have to debug this a bit further.


Corinna

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-12-12 10:25 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-12  5:10 Regarding EFBIG error while opening a file using catopen() function Kavita Gore
2022-12-12 10:25 ` Corinna Vinschen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).