From: Steve Hay Date: Tue, 29 Mar 2005 08:22:45 +0000 (+0000) Subject: Fix PerlLIO_chsize() for platforms that don't have chsize() X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=58e24efff3e72032a19e2adb55a951735452dbca;p=p5sagit%2Fp5-mst-13.2.git Fix PerlLIO_chsize() for platforms that don't have chsize() This is the patch from the end of the thread that started here: http://www.xray.mpe.mpg.de/mailing-lists/perl5-porters/2004-09/msg00055.html p4raw-id: //depot/perl@24092 --- diff --git a/doio.c b/doio.c index c8bc22d..db5e52a 100644 --- a/doio.c +++ b/doio.c @@ -1242,14 +1242,15 @@ Perl_do_binmode(pTHX_ PerlIO *fp, int iotype, int mode) return PerlIO_binmode(aTHX_ fp, iotype, mode, name); } -#if !defined(HAS_TRUNCATE) && !defined(HAS_CHSIZE) && defined(F_FREESP) - /* code courtesy of William Kucharski */ -#define HAS_CHSIZE - +#if !defined(HAS_TRUNCATE) && !defined(HAS_CHSIZE) I32 my_chsize(fd, length) I32 fd; /* file descriptor */ Off_t length; /* length to set file to */ { +#ifdef F_FREESP + /* code courtesy of William Kucharski */ +#define HAS_CHSIZE + struct flock fl; Stat_t filebuf; @@ -1290,8 +1291,12 @@ Off_t length; /* length to set file to */ } return 0; -} +#else + dTHX; + DIE(aTHX_ "truncate not implemented"); #endif /* F_FREESP */ +} +#endif /* !HAS_TRUNCATE && !HAS_CHSIZE */ bool Perl_do_print(pTHX_ register SV *sv, PerlIO *fp) diff --git a/iperlsys.h b/iperlsys.h index 5bb0f05..28e6719 100644 --- a/iperlsys.h +++ b/iperlsys.h @@ -726,7 +726,13 @@ struct IPerlLIOInfo #define PerlLIO_access(file, mode) access((file), (mode)) #define PerlLIO_chmod(file, mode) chmod((file), (mode)) #define PerlLIO_chown(file, owner, grp) chown((file), (owner), (grp)) -#define PerlLIO_chsize(fd, size) chsize((fd), (size)) +#if defined(HAS_TRUNCATE) +# define PerlLIO_chsize(fd, size) ftruncate((fd), (size)) +#elif defined(HAS_CHSIZE) +# define PerlLIO_chsize(fd, size) chsize((fd), (size)) +#else +# define PerlLIO_chsize(fd, size) my_chsize((fd), (size)) +#endif #define PerlLIO_close(fd) close((fd)) #define PerlLIO_dup(fd) dup((fd)) #define PerlLIO_dup2(fd1, fd2) dup2((fd1), (fd2)) diff --git a/pp_sys.c b/pp_sys.c index a7fbc00..5c1cc64 100644 --- a/pp_sys.c +++ b/pp_sys.c @@ -2110,7 +2110,6 @@ PP(pp_truncate) * might not be signed: if it is not, clever compilers will moan. */ /* XXX Configure probe for the signedness of the length type of *truncate() needed? XXX */ SETERRNO(0,0); -#if defined(HAS_TRUNCATE) || defined(HAS_CHSIZE) || defined(F_FREESP) { int result = 1; GV *tmpgv; @@ -2185,9 +2184,6 @@ PP(pp_truncate) SETERRNO(EBADF,RMS_IFI); RETPUSHUNDEF; } -#else - DIE(aTHX_ "truncate not implemented"); -#endif } PP(pp_fcntl)