~ubuntu-branches/ubuntu/trusty/musl/trusty-proposed

« back to all changes in this revision

Viewing changes to src/legacy/getusershell.c

  • Committer: Package Import Robot
  • Author(s): Kevin Bortis
  • Date: 2013-09-20 20:54:14 UTC
  • Revision ID: package-import@ubuntu.com-20130920205414-5b61trtmma18w58o
Tags: upstream-0.9.13
ImportĀ upstreamĀ versionĀ 0.9.13

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#define _GNU_SOURCE
 
2
#include <stdio.h>
 
3
#include <string.h>
 
4
#include <stdlib.h>
 
5
 
 
6
static const char defshells[] = "/bin/sh\n/bin/csh\n";
 
7
 
 
8
static char *line;
 
9
static size_t linesize;
 
10
static FILE *f;
 
11
 
 
12
void endusershell(void)
 
13
{
 
14
        if (f) fclose(f);
 
15
        f = 0;
 
16
}
 
17
 
 
18
void setusershell(void)
 
19
{
 
20
        if (!f) f = fopen("/etc/shells", "rbe");
 
21
        if (!f) f = fmemopen((void *)defshells, sizeof defshells - 1, "rb");
 
22
}
 
23
 
 
24
char *getusershell(void)
 
25
{
 
26
        ssize_t l;
 
27
        if (!f) setusershell();
 
28
        if (!f) return 0;
 
29
        l = getline(&line, &linesize, f);
 
30
        if (l <= 0) return 0;
 
31
        if (line[l-1]=='\n') line[l-1]=0;
 
32
        return line;
 
33
}