aboutsummaryrefslogtreecommitdiff
path: root/src/librc.c
diff options
context:
space:
mode:
authorRoy Marples <roy@marples.name>2007-09-25 15:38:21 +0000
committerRoy Marples <roy@marples.name>2007-09-25 15:38:21 +0000
commit1e4e8ed27ae95096255283e92a75738bc7e296e5 (patch)
tree5f152e91cce64bc2c9b0c6336b4078e470ac14da /src/librc.c
parenta2e5c4513e2955bc0a77c401ea12cc210eab305b (diff)
Initial doxygen documentation for rc.h and einfo.h. Plus some header clean ups.
Diffstat (limited to 'src/librc.c')
-rw-r--r--src/librc.c43
1 files changed, 19 insertions, 24 deletions
diff --git a/src/librc.c b/src/librc.c
index f501719e..dd2e0b6b 100644
--- a/src/librc.c
+++ b/src/librc.c
@@ -65,24 +65,23 @@ librc_hidden_def(rc_get_runlevels)
char *rc_get_runlevel (void)
{
FILE *fp;
- static char buffer[PATH_MAX];
-
- if (! (fp = fopen (SOFTLEVEL, "r"))) {
- snprintf (buffer, sizeof (buffer), "sysinit");
- return (buffer);
- }
-
- if (fgets (buffer, PATH_MAX, fp)) {
- int i = strlen (buffer) - 1;
- if (buffer[i] == '\n')
- buffer[i] = 0;
+ char buffer[RC_LINEBUFFER];
+ char *runlevel = NULL;
+
+ if ((fp = fopen (SOFTLEVEL, "r"))) {
+ if (fgets (buffer, PATH_MAX, fp)) {
+ int i = strlen (buffer) - 1;
+ if (buffer[i] == '\n')
+ buffer[i] = 0;
+ runlevel = rc_xstrdup (buffer);
+ }
fclose (fp);
- return (buffer);
}
- fclose (fp);
- snprintf (buffer, sizeof (buffer), "sysinit");
- return (buffer);
+ if (! runlevel)
+ runlevel = rc_xstrdup (RC_LEVEL_SYSINIT);
+
+ return (runlevel);
}
librc_hidden_def(rc_get_runlevel)
@@ -452,31 +451,27 @@ bool rc_service_state (const char *service, const rc_service_state_t state)
}
librc_hidden_def(rc_service_state)
-bool rc_get_service_option (const char *service, const char *option,
- char *value)
+char *rc_get_service_option (const char *service, const char *option)
{
FILE *fp;
char buffer[RC_LINEBUFFER];
char *file = rc_strcatpaths (RC_SVCDIR, "options", service, option,
(char *) NULL);
- bool retval = false;
+ char *value = NULL;
if (rc_exists (file)) {
if ((fp = fopen (file, "r")) == NULL)
eerror ("fopen `%s': %s", file, strerror (errno));
else {
memset (buffer, 0, sizeof (buffer));
- while (fgets (buffer, RC_LINEBUFFER, fp)) {
- memcpy (value, buffer, strlen (buffer));
- value += strlen (buffer);
- }
+ if (fgets (buffer, RC_LINEBUFFER, fp))
+ value = rc_xstrdup (buffer);
fclose (fp);
- retval = true;
}
}
free (file);
- return (retval);
+ return (value);
}
librc_hidden_def(rc_get_service_option)