Robotran C Documentation
Functions
read_files.c File Reference

Implements reading text file related functions. More...

#include <stdlib.h>
#include <errno.h>
#include "mbs_message.h"
#include "read_files.h"

Functions

int mbs_getlinesize (FILE *stream)
 Compute the line length. More...
 
int get_file_nb_lines_col (FILE *fp, int *n_line, int *max_width)
 Return the number of line and the max line width in remainder of the file. More...
 

Detailed Description

Implements reading text file related functions.

authors: Robotran team.

Function Documentation

◆ get_file_nb_lines_col()

int get_file_nb_lines_col ( FILE *  fp,
int *  n_line,
int *  max_width 
)

Return the number of line and the max line width in remainder of the file.

Only the remainder of the stream (ie. located after current stream position) is parsed. The position of the cursor is restored at the end of the function even if the evaluation fails.

Note:

  • Empty final line is not counted in the number of line (but empty non-final lines are counted).
  • End of line character ('
    ') is counted in the line width.
Parameters
[in,out]fpThe pointer to the file stream open in text mode. The stream position is restored except if the fseek() function fails.
[out]n_lineMemory pointer to the number of line.
[out]max_widthMemory pointer to the maximum line width, excluding the null byte used to end output to strings)
Returns
The size of the file.

◆ mbs_getlinesize()

int mbs_getlinesize ( FILE *  stream)

Compute the line length.

The length does not include the end-of-line ('
') nor end-of-char ('\0') character.

Parameters
[in,out]streamStream to be parsed.
Returns
On success returns the number of characters read until reaching the end of line ('
') or terminating null byte ('\0') character.

Returns -1 on failure to read a line (including end-of-file condition). In the event of an error, errno is set to indicate the cause. EINVAL Bad arguments (n or lineptr is NULL, or stream is not valid).