~ubuntu-branches/ubuntu/trusty/nilfs-tools/trusty

« back to all changes in this revision

Viewing changes to sbin/mount/sundries.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Baumann
  • Date: 2011-08-12 20:42:38 UTC
  • mto: This revision was merged to the branch mainline in revision 11.
  • Revision ID: james.westby@ubuntu.com-20110812204238-3i5mnvvmg7amtyjm
Tags: upstream-2.1.0~rc2
ImportĀ upstreamĀ versionĀ 2.1.0~rc2

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
#include <mntent.h>             /* for MNTTYPE_SWAP */
32
32
#endif  /* HAVE_MNTENT_H */
33
33
 
34
 
#include "fstab.h"
35
34
#include "sundries.h"
36
35
#include "realpath.h"
37
36
//#include "nfsmount.h"
265
264
 
266
265
        return xstrdup(path);
267
266
}
268
 
 
269
 
/*
270
 
 * Following part was appended by Ryusuke Konishi <ryusuke@osrg.net>
271
 
 */
272
 
int find_opt(const char *opts, const char *token, void *varp)
273
 
{
274
 
        char *opts2, *opt;
275
 
        int res = -1;
276
 
 
277
 
        if (!opts)
278
 
                return res;
279
 
 
280
 
        opts2 = xstrdup(opts);
281
 
        opt = strtok(opts2, ",");
282
 
        if (varp) {
283
 
                while (opt) {
284
 
                        if (sscanf(opt, token, varp) == 1) {
285
 
                                res = opt - opts2;
286
 
                                break;
287
 
                        }
288
 
                        opt = strtok(NULL, ",");
289
 
                }
290
 
        } else {
291
 
                int cmplen = strlen(token) + 1;
292
 
                while (opt) {
293
 
                        if (!strncmp(opt, token, cmplen)) {
294
 
                                res = opt - opts2;
295
 
                                break;
296
 
                        }
297
 
                        opt = strtok(NULL, ",");
298
 
                }
299
 
        }
300
 
        free(opts2);
301
 
        return res;
302
 
}
303
 
 
304
 
char *change_opt(const char *opts, const char *token, void *varp,
305
 
                 const char *instead)
306
 
{
307
 
        int ind = find_opt(opts, token, varp);
308
 
        const char *ep;
309
 
        char *newopts;
310
 
 
311
 
        if (!instead)
312
 
                instead = "";
313
 
        if (ind >= 0) {
314
 
                ep = opts + ind;
315
 
                while (*ep != ',' && *ep != '\0')
316
 
                        ep++;
317
 
 
318
 
                if (*instead == '\0') {
319
 
                        if (*ep == ',')
320
 
                                ep++;
321
 
                        else if (ind > 0)
322
 
                                ind--;
323
 
                }
324
 
                newopts = xmalloc(ind + strlen(instead) + strlen(ep) + 1);
325
 
                memcpy(newopts, opts, ind);
326
 
                strcpy(newopts + ind, instead);
327
 
                strcat(newopts, ep);
328
 
        } else if (opts == NULL || *opts == '\0') {
329
 
                newopts = xstrdup(instead);
330
 
        } else {
331
 
                newopts = xstrdup(opts);
332
 
                if (*instead != '\0')
333
 
                        newopts = xstrconcat3(newopts, ",", instead);
334
 
        }
335
 
 
336
 
        return newopts;
337
 
}