Back to index

courier  0.68.2
cread1l.c
Go to the documentation of this file.
00001 /*
00002 ** Copyright 1998 - 2006 Double Precision, Inc.
00003 ** See COPYING for distribution information.
00004 */
00005 
00006 #include      "courier.h"
00007 #include      <stdio.h>
00008 #include      <stdlib.h>
00009 #include      <string.h>
00010 
00011 /*
00012        Open and read a one-line configuration file.
00013 
00014        Assume the line is less than 256 characters.
00015 
00016        Returns NULL if the configuration file does not exist.
00017 */
00018 
00019 char   *config_read1l(const char *filename)
00020 {
00021 FILE   *fp=fopen(filename, "r");
00022 char   buf[256];
00023 char   *p;
00024 
00025        if (!fp)      return (0);
00026        if (fgets(buf, sizeof(buf), fp) == NULL)
00027               buf[0]=0;
00028        fclose(fp);
00029        if ((p=strchr(buf, '\n')) != 0)    *p=0;
00030        return (strcpy( (char *)courier_malloc(strlen(buf)+1), buf));
00031 }