Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2003-12

fpStat() and LinuxError

4 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Jeff Pohlmeyer

How do I get the error code for fpStat() ?

The oldlinux.stat() function returns FALSE on failure, and sets LinuxError.

The libc.stat() function returns (-1) on failure, and sets errno.

The baseunix.fpStat() function returns (-1) on failure, but it does not set LinuxError.

If I call fpStat() on a non-existing file, "strace" shows the error is ENOENT, but LinuxError is still zero.

( I am using 1.9.0 [2003/11/05] for i386/Linux )

program stat_test;
uses unix, baseunix, errors;
var
  info: stat;
  err: LongInt;
const
  fn = 'nosuch.file';
begin
  err:=fpStat(fn, info);
  if ( err  0 ) then
  begin
    pError(fn, LinuxError); // Success ?
    pError('Error', err); // (-1) ?
  end;
end.

__________________________________
Do you Yahoo!?
Protect your identity with Yahoo! Mail AddressGuard http://antispam.yahoo.com/whatsnewfree

Reply by email

Peter Vreman
to Jeff Pohlmeyer
Show quoted text 14 lines
How do I get the error code for fpStat() ? The oldlinux.stat() function returns FALSE on failure, and sets LinuxError. The libc.stat() function returns (-1) on failure, and sets errno. The baseunix.fpStat() function returns (-1) on failure, but it does not set LinuxError. If I call fpStat() on a non-existing file, "strace" shows the error is ENOENT, but LinuxError is still zero. ( I am using 1.9.0 [2003/11/05] for i386/Linux )

LinuxError is already removed. Use errno instead, just like C.

Reply by email

Marco van de Voort
to Jeff Pohlmeyer: How do I get the error code for fpStat() ? The oldlinux.stat() function returns FALSE on…
Show quoted text 8 lines
How do I get the error code for fpStat() ? The oldlinux.stat() function returns FALSE on failure, and sets LinuxError. The libc.stat() function returns (-1) on failure, and sets errno. The baseunix.fpStat() function returns (-1) on failure, but it does not set LinuxError.

LinuxError is legacy, and belongs to oldlinux only. This unit is provided for 1.0.x legacy only, and I strongly advise you against using it. Unit oldlinux is also linux/i386 only.

Baseunix follows POSIX conventions, and sets an internal errno on error and signals the errorcondition using the returnvalue (usually by returning -1, but some calls returning a type different from cint return something else. See manpages).

Because the BaseUnix internal errno is threadsafe, access is provided via functions, (BaseUnix.) fpseterrno and fpgeterrno.

So there are now three errorvariables:

1 oldlinux.linuxerror for calls in unit oldlinux only. _LEGACY_ 2 baseunix.fpgeterrno for all units that import unit syscall. (including unix and baseunix, but also sockets, ipc etc)
3 libc's errno (exposed in units that link to libc. Access to this variable in a threadsafe manner still has to be centralised in some unit, and all importing units adapted.

The idea of this is to have only two vars, instead of all the vars in all the units. One, internal for FPC's own syscalls, and one for C libc.

In the case that the FPC rtl is implemented on top of libc, (like planned for the future Mac OS X port), both point to the same internally, but the usercode needs no changing.

Reply by email

Marco van de Voort
to Peter Vreman: LinuxError is already removed. Use errno instead, just like C.
Show quoted text 11 lines
> The libc.stat() function returns (-1) on failure, and sets errno. > > The baseunix.fpStat() function returns (-1) on failure, > but it does not set LinuxError. > > If I call fpStat() on a non-existing file, "strace" shows > the error is ENOENT, but LinuxError is still zero. > > ( I am using 1.9.0 [2003/11/05] for i386/Linux ) LinuxError is already removed. Use errno instead, just like C.

Internal Errno is only visible in implementation of system unit.

Use baseunix.geterrno/seterrno.

Reply by email