diff options
author | Guido van Rossum <guido@python.org> | 1995-01-02 19:07:15 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1995-01-02 19:07:15 (GMT) |
commit | d7047b395e392ce9e46f9a83480ade8b37f6d5b0 (patch) | |
tree | 9dabdcc762d49aebc28d82372ca9d79bdbe23cf8 /Objects/fileobject.c | |
parent | 1ae940a5870df2f706fa884afd533847f6b0b1a8 (diff) | |
download | cpython-d7047b395e392ce9e46f9a83480ade8b37f6d5b0.zip cpython-d7047b395e392ce9e46f9a83480ade8b37f6d5b0.tar.gz cpython-d7047b395e392ce9e46f9a83480ade8b37f6d5b0.tar.bz2 |
Lots of minor changes. Note for mappingobject.c: the hash table pointer
can now be NULL.
Diffstat (limited to 'Objects/fileobject.c')
-rw-r--r-- | Objects/fileobject.c | 50 |
1 files changed, 49 insertions, 1 deletions
diff --git a/Objects/fileobject.c b/Objects/fileobject.c index eb8f4aa..44bc51b 100644 --- a/Objects/fileobject.c +++ b/Objects/fileobject.c @@ -94,7 +94,7 @@ newfileobject(name, mode) f = (fileobject *) newopenfileobject((FILE *)NULL, name, mode, fclose); if (f == NULL) return NULL; -#ifdef USE_FOPENRF +#ifdef HAVE_FOPENRF if (*mode == '*') { FILE *fopenRF(); f->f_fp = fopenRF(name, mode+1); @@ -231,6 +231,51 @@ file_seek(f, args) return None; } +#ifdef HAVE_FTRUNCATE +static object * +file_truncate(f, args) + fileobject *f; + object *args; +{ + long newsize; + int ret; + + if (f->f_fp == NULL) + return err_closed(); + if (!getargs(args, "l", &newsize)) { + err_clear(); + if (!getnoarg(args)) + return NULL; + BGN_SAVE + errno = 0; + newsize = ftell(f->f_fp); /* default to current position*/ + END_SAVE + if (newsize == -1L) { + err_errno(IOError); + clearerr(f->f_fp); + return NULL; + } + } + BGN_SAVE + errno = 0; + ret = fflush(f->f_fp); + END_SAVE + if (ret == 0) { + BGN_SAVE + errno = 0; + ret = ftruncate(fileno(f->f_fp), newsize); + END_SAVE + } + if (ret != 0) { + err_errno(IOError); + clearerr(f->f_fp); + return NULL; + } + INCREF(None); + return None; +} +#endif /* HAVE_FTRUNCATE */ + static object * file_tell(f, args) fileobject *f; @@ -615,6 +660,9 @@ static struct methodlist file_methods[] = { {"readline", (method)file_readline}, {"readlines", (method)file_readlines}, {"seek", (method)file_seek}, +#ifdef HAVE_FTRUNCATE + {"truncate", (method)file_truncate}, +#endif {"tell", (method)file_tell}, {"write", (method)file_write}, {"writelines", (method)file_writelines}, |