1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-03-09 15:50:02 +00:00
cde/src/lib/libast/sfio/sfsk.c
Martijn Dekker 289dd46c05 build: include standards macros for all AST code (re: 7fb814e1)
Turns out that the standards macros set by features/standards (such
as _GNU_SOURCE for Linux or _DARWIN_SOURCE for macOS) were still
*not* included for most C source files! Instead, they were
selectively included for some files only, sometimes via
FEATURE/standards (the output of features/standards), sometimes
via ast_standards.h which is copied from FEATURE/standards.

Consequently, there were still inconsistencies in the system header
interfaces exposed on Linux, macOS, Solaris, et al. It's no wonder
it sometimes took so much hackery to keep everything building.

Of course, making this consistent had to break things somewhere.
Breakage occurred on 32-bit Linux due to a lot of ugly hackery
involving direct use of internal GNU types like off64_t and
functions like fseek64(). This is now all removed and they are
activated by setting the appropriate feature macro instead, so
these types and functions can be used with their standard names
(off_t, fseek, etc.)

Before committing I've tested these changes on the following
i386/x86_64 systems: Linux (glibc 32 and 64 bit, musl libc 64 bit),
Solaris (32 and 64 bit), illumos (32 and 64 bit), FreeBSD (64 bit),
macOS (64 bit), Cygwin (32 bit), and Haiku (64 bit).

(Note: ast_standards.h is copied from FEATURE/standards, whereas
ast_common.h is copied from FEATURE/common.)

src/lib/libast/include/ast_std.h,
src/lib/libast/stdio/stdhdr.h:
- Include <ast_standards.h> first. This should cause all the AST
  and dependent code (such as ksh) to get the standards macros.

src/lib/libast/features/standards:
- For GNU (glibc), #define _FILE_OFFSET_BITS 64 to get large file
  support with 64-bit offsets.
- Stop GNU and Cygwin <string.h> form defining the GNU version of
  basename(3); on Cygwin, that declaration conflicts with the AST
  version (and with POSIX) by using a const char* argument instead
  of char*. It is deactivated by defining the macro 'basename' (as
  'basename'); this causes GNU string.h to consider it to be
  already defined by the standard libgen.h header.

All other changed files:
- Remove direct use of *64* types and functions and a lot of
  related hackery.
2022-01-20 00:53:22 +00:00

99 lines
3.1 KiB
C

/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1985-2011 AT&T Intellectual Property *
* Copyright (c) 2020-2021 Contributors to ksh 93u+m *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* http://www.eclipse.org/org/documents/epl-v10.html *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* David Korn <dgk@research.att.com> *
* Phong Vo <kpv@research.att.com> *
* *
***********************************************************************/
#include "sfhdr.h"
/* Seek function that knows discipline
**
** Written by Kiem-Phong Vo.
*/
Sfoff_t sfsk(Sfio_t* f, Sfoff_t addr, int type, Sfdisc_t* disc)
{
Sfoff_t p;
reg Sfdisc_t* dc;
reg ssize_t s;
reg int local, mode;
SFMTXDECL(f);
SFMTXENTER(f, (Sfoff_t)(-1));
GETLOCAL(f,local);
if(!local && !(f->bits&SF_DCDOWN))
{ if((mode = f->mode&SF_RDWR) != (int)f->mode && _sfmode(f,mode,0) < 0)
SFMTXRETURN(f, (Sfoff_t)(-1));
if(SFSYNC(f) < 0)
SFMTXRETURN(f, (Sfoff_t)(-1));
#ifdef MAP_TYPE
if(f->mode == SF_READ && (f->bits&SF_MMAP) && f->data)
{ SFMUNMAP(f, f->data, f->endb-f->data);
f->data = NIL(uchar*);
}
#endif
f->next = f->endb = f->endr = f->endw = f->data;
}
if((type &= (SEEK_SET|SEEK_CUR|SEEK_END)) > SEEK_END)
SFMTXRETURN(f, (Sfoff_t)(-1));
for(;;)
{ dc = disc;
if(f->flags&SF_STRING)
{ SFSTRSIZE(f);
if(type == SEEK_SET)
s = (ssize_t)addr;
else if(type == SEEK_CUR)
s = (ssize_t)(addr + f->here);
else s = (ssize_t)(addr + f->extent);
}
else
{ SFDISC(f,dc,seekf);
if(dc && dc->seekf)
{ SFDCSK(f,addr,type,dc,p);
}
else
{ p = lseek(f->file,(off_t)addr,type);
}
if(p >= 0)
SFMTXRETURN(f,p);
s = -1;
}
if(local)
SETLOCAL(f);
switch(_sfexcept(f,SF_SEEK,s,dc))
{
case SF_EDISC:
case SF_ECONT:
if(f->flags&SF_STRING)
SFMTXRETURN(f, (Sfoff_t)s);
goto do_continue;
default:
SFMTXRETURN(f, (Sfoff_t)(-1));
}
do_continue:
for(dc = f->disc; dc; dc = dc->disc)
if(dc == disc)
break;
disc = dc;
}
}