text: /*
     uio_line_from_file.c
     UIO helper function: ... ... ...
  
     Copyright (C) 2009, Hans J. Koch <hjk@linutronix.de>
     Copyright (C) 2009, Stephan Linz <linz@li-pro.net>
  
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License version 2 as
     published by the Free Software Foundation.
  
     This program is distributed in the hope that it will be useful,
     but WITHOUT ANY WARRANTY; without even the implied warranty of
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     GNU General Public License for more details.
  
     You should have received a copy of the GNU General Public License
     along with this program; if not, write to the Free Software Foundation,
     Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  */
  #include <stdio.h>
  #include <stdlib.h>
  #include <string.h>
  
  #include "lib/uio_helper.h"
  
  int __uio_line_from_file(char *filename, char *linebuf);
  
  int __uio_line_from_file(char *filename, char *linebuf)
  {
  	char *s;
  	int i;
  	FILE* file = fopen(filename,"r");
  
  	if (!file)
  		return -1;
  
  	memset(linebuf, 0, UIO_MAX_NAME_SIZE);
  	s = fgets(linebuf, UIO_MAX_NAME_SIZE, file);
  	if (!s) {
  		fclose(file);
  		return -2;
  	}
  	for (i = 0; (*s) && (i < UIO_MAX_NAME_SIZE); i++) {
  		if (*s == '\n')
  			*s = 0;
  		s++;
  	}
  	fclose(file);
  	return 0;
  }
  