Tanguy Pruvot | 8aeb371 | 2011-06-30 08:59:26 +0200 | [diff] [blame] | 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 | |
maxwen | 27116ba | 2015-08-14 21:41:28 +0200 | [diff] [blame] | 13 | #ifndef BIONIC_ICS |
| 14 | int clearenv(void) |
Tanguy Pruvot | 8aeb371 | 2011-06-30 08:59:26 +0200 | [diff] [blame] | 15 | { |
maxwen | 27116ba | 2015-08-14 21:41:28 +0200 | [diff] [blame] | 16 | char **P = environ; |
Tanguy Pruvot | 8aeb371 | 2011-06-30 08:59:26 +0200 | [diff] [blame] | 17 | |
maxwen | 27116ba | 2015-08-14 21:41:28 +0200 | [diff] [blame] | 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 | } |
Tanguy Pruvot | 8aeb371 | 2011-06-30 08:59:26 +0200 | [diff] [blame] | 26 | return 0; |
| 27 | } |
maxwen | 27116ba | 2015-08-14 21:41:28 +0200 | [diff] [blame] | 28 | #endif |
Tanguy Pruvot | 8aeb371 | 2011-06-30 08:59:26 +0200 | [diff] [blame] | 29 | |
| 30 | /* no /etc/shells anyway */ |
| 31 | char *getusershell() { return NULL; } |
| 32 | void setusershell() {} |
| 33 | void endusershell() {} |
| 34 | |
| 35 | struct 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 */ |
| 65 | struct 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 */ |
maxwen | 27116ba | 2015-08-14 21:41:28 +0200 | [diff] [blame] | 73 | int addmntent(FILE *fp UNUSED_PARAM, const struct mntent *mnt UNUSED_PARAM) |
Tanguy Pruvot | 8aeb371 | 2011-06-30 08:59:26 +0200 | [diff] [blame] | 74 | { |
| 75 | errno = ENOENT; |
| 76 | return 1; |
| 77 | } |
| 78 | |
maxwen | 27116ba | 2015-08-14 21:41:28 +0200 | [diff] [blame] | 79 | char *hasmntopt(const struct mntent *mnt, const char *opt) |
Tanguy Pruvot | 8aeb371 | 2011-06-30 08:59:26 +0200 | [diff] [blame] | 80 | { |
maxwen | 27116ba | 2015-08-14 21:41:28 +0200 | [diff] [blame] | 81 | char *o = mnt->mnt_opts; |
Tanguy Pruvot | 8aeb371 | 2011-06-30 08:59:26 +0200 | [diff] [blame] | 82 | size_t l = strlen(opt); |
| 83 | |
maxwen | 27116ba | 2015-08-14 21:41:28 +0200 | [diff] [blame] | 84 | while ((o = strstr(o, opt)) && |
| 85 | ((o > mnt->mnt_opts && o[-1] != ',') || |
Tanguy Pruvot | 8aeb371 | 2011-06-30 08:59:26 +0200 | [diff] [blame] | 86 | (o[l] != 0 && o[l] != ',' && o[l] != '='))); |
| 87 | return o; |
| 88 | } |
| 89 | |
| 90 | /* declared in grp.h, but not necessary */ |
Tanguy Pruvot | 8a6c2c2 | 2012-04-28 00:24:09 +0200 | [diff] [blame] | 91 | #if !ENABLE_USE_BB_PWD_GRP |
Tanguy Pruvot | 8aeb371 | 2011-06-30 08:59:26 +0200 | [diff] [blame] | 92 | int setpwent() { return 0; } |
| 93 | void setgrent() {} |
| 94 | void endgrent() {} |
Tanguy Pruvot | 8a6c2c2 | 2012-04-28 00:24:09 +0200 | [diff] [blame] | 95 | #endif |
| 96 | |