X-Git-Url: https://git.decadent.org.uk/gitweb/?p=nfs-utils.git;a=blobdiff_plain;f=support%2Fnfs%2Fnfs_mntent.c;h=a2118a27a172fa54ba5657c0b31c2ad50d14ac38;hp=b407d6844cbe08f3aa040c4b5b24b7a2ecf7c824;hb=cf5b38e707b629540b5123124228311a620e3dce;hpb=4e2bae795e5eaf9922f0b966ab5df64994c836a2 diff --git a/support/nfs/nfs_mntent.c b/support/nfs/nfs_mntent.c index b407d68..a2118a2 100644 --- a/support/nfs/nfs_mntent.c +++ b/support/nfs/nfs_mntent.c @@ -1,7 +1,7 @@ /* Private version of the libc *mntent() routines. */ /* Note slightly different prototypes. */ -/* 1999-02-22 Arkadiusz Mi¶kiewicz +/* 1999-02-22 Arkadiusz Miskiewicz * - added Native Language Support * * 2006-06-08 Amit Gud @@ -12,6 +12,7 @@ #include /* for index */ #include /* for isdigit */ #include /* for umask */ +#include /* for ftruncate */ #include "nfs_mntent.h" #include "nls.h" @@ -25,11 +26,12 @@ static unsigned char need_escaping[] = { ' ', '\t', '\n', '\\' }; static char * -mangle(const unsigned char *s) { +mangle(const char *arg) { + const unsigned char *s = (const unsigned char *)arg; char *ss, *sp; - int n; + unsigned int n; - n = strlen(s); + n = strlen(arg); ss = sp = xmalloc(4*n+1); while(1) { for (n = 0; n < sizeof(need_escaping); n++) { @@ -123,12 +125,14 @@ nfs_endmntent (mntFILE *mfp) { } int -nfs_addmntent (mntFILE *mfp, nfs_mntent_t *mnt) { +nfs_addmntent (mntFILE *mfp, struct mntent *mnt) { char *m1, *m2, *m3, *m4; int res; + off_t length; if (fseek (mfp->mntent_fp, 0, SEEK_END)) return 1; /* failure */ + length = ftell(mfp->mntent_fp); m1 = mangle(mnt->mnt_fsname); m2 = mangle(mnt->mnt_dir); @@ -142,14 +146,20 @@ nfs_addmntent (mntFILE *mfp, nfs_mntent_t *mnt) { free(m2); free(m3); free(m4); + if (res >= 0) { + res = fflush(mfp->mntent_fp); + if (res < 0) + /* Avoid leaving a corrupt mtab file */ + ftruncate(fileno(mfp->mntent_fp), length); + } return (res < 0) ? 1 : 0; } /* Read the next entry from the file fp. Stop reading at an incorrect entry. */ -nfs_mntent_t * +struct mntent * nfs_getmntent (mntFILE *mfp) { static char buf[4096]; - static nfs_mntent_t me; + static struct mntent me; char *s; again: