summaryrefslogtreecommitdiff
path: root/android/android.c (plain)
blob: 62d25a83f4caa01b951285642c31d83579ab95de
1/* vi: set sw=4 ts=4: */
2/*
3 * Android/bionic glue.
4 *
5 * Copyright (C) 2010 by Dylan Simon <dylan@dylex.net>
6 *
7 * Licensed under GPLv2, see file LICENSE in this tarball for details.
8 */
9
10#include <stdlib.h>
11#include "libbb.h"
12
13#ifndef BIONIC_ICS
14int clearenv(void)
15{
16 char **P = environ;
17
18 /* should never be NULL */
19 if (!environ)
20 environ = (char **)xzalloc(sizeof(char *));
21
22 if (P != NULL) {
23 for (; *P; ++P)
24 *P = NULL;
25 }
26 return 0;
27}
28#endif
29
30/* no /etc/shells anyway */
31char *getusershell() { return NULL; }
32void setusershell() {}
33void endusershell() {}
34
35struct mntent *getmntent_r(FILE *fp, struct mntent *mnt, char *buf, int buflen)
36{
37 char *tokp = NULL, *s;
38
39 do {
40 if (!fgets(buf, buflen, fp))
41 return NULL;
42 tokp = 0;
43 s = strtok_r(buf, " \t\n", &tokp);
44 } while (!s || *s == '#');
45
46 mnt->mnt_fsname = s;
47 mnt->mnt_freq = mnt->mnt_passno = 0;
48 if (!(mnt->mnt_dir = strtok_r(NULL, " \t\n", &tokp)))
49 return NULL;
50 if (!(mnt->mnt_type = strtok_r(NULL, " \t\n", &tokp)))
51 return NULL;
52 if (!(mnt->mnt_opts = strtok_r(NULL, " \t\n", &tokp)))
53 mnt->mnt_opts = "";
54 else if ((s = strtok_r(NULL, " \t\n", &tokp)))
55 {
56 mnt->mnt_freq = atoi(s);
57 if ((s = strtok_r(NULL, " \t\n", &tokp)))
58 mnt->mnt_passno = atoi(s);
59 }
60
61 return mnt;
62}
63
64/* override definition in bionic/stubs.c */
65struct mntent *getmntent(FILE *fp)
66{
67 static struct mntent mnt;
68 static char buf[256];
69 return getmntent_r(fp, &mnt, buf, 256);
70}
71
72/* not used anyway */
73int addmntent(FILE *fp UNUSED_PARAM, const struct mntent *mnt UNUSED_PARAM)
74{
75 errno = ENOENT;
76 return 1;
77}
78
79char *hasmntopt(const struct mntent *mnt, const char *opt)
80{
81 char *o = mnt->mnt_opts;
82 size_t l = strlen(opt);
83
84 while ((o = strstr(o, opt)) &&
85 ((o > mnt->mnt_opts && o[-1] != ',') ||
86 (o[l] != 0 && o[l] != ',' && o[l] != '=')));
87 return o;
88}
89
90/* declared in grp.h, but not necessary */
91#if !ENABLE_USE_BB_PWD_GRP
92int setpwent() { return 0; }
93void setgrent() {}
94void endgrent() {}
95#endif
96
97