blob: 62d25a83f4caa01b951285642c31d83579ab95de [file] [log] [blame]
Tanguy Pruvot8aeb3712011-06-30 08:59:26 +02001/* 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
maxwen27116ba2015-08-14 21:41:28 +020013#ifndef BIONIC_ICS
14int clearenv(void)
Tanguy Pruvot8aeb3712011-06-30 08:59:26 +020015{
maxwen27116ba2015-08-14 21:41:28 +020016 char **P = environ;
Tanguy Pruvot8aeb3712011-06-30 08:59:26 +020017
maxwen27116ba2015-08-14 21:41:28 +020018 /* 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 }
Tanguy Pruvot8aeb3712011-06-30 08:59:26 +020026 return 0;
27}
maxwen27116ba2015-08-14 21:41:28 +020028#endif
Tanguy Pruvot8aeb3712011-06-30 08:59:26 +020029
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 */
maxwen27116ba2015-08-14 21:41:28 +020073int addmntent(FILE *fp UNUSED_PARAM, const struct mntent *mnt UNUSED_PARAM)
Tanguy Pruvot8aeb3712011-06-30 08:59:26 +020074{
75 errno = ENOENT;
76 return 1;
77}
78
maxwen27116ba2015-08-14 21:41:28 +020079char *hasmntopt(const struct mntent *mnt, const char *opt)
Tanguy Pruvot8aeb3712011-06-30 08:59:26 +020080{
maxwen27116ba2015-08-14 21:41:28 +020081 char *o = mnt->mnt_opts;
Tanguy Pruvot8aeb3712011-06-30 08:59:26 +020082 size_t l = strlen(opt);
83
maxwen27116ba2015-08-14 21:41:28 +020084 while ((o = strstr(o, opt)) &&
85 ((o > mnt->mnt_opts && o[-1] != ',') ||
Tanguy Pruvot8aeb3712011-06-30 08:59:26 +020086 (o[l] != 0 && o[l] != ',' && o[l] != '=')));
87 return o;
88}
89
90/* declared in grp.h, but not necessary */
Tanguy Pruvot8a6c2c22012-04-28 00:24:09 +020091#if !ENABLE_USE_BB_PWD_GRP
Tanguy Pruvot8aeb3712011-06-30 08:59:26 +020092int setpwent() { return 0; }
93void setgrent() {}
94void endgrent() {}
Tanguy Pruvot8a6c2c22012-04-28 00:24:09 +020095#endif
96