misc/physfs/extras/physfsfgets.c
author unc0rr
Sat, 08 Dec 2012 20:23:13 +0400
branchflibqtfrontend
changeset 8275 e0a134d890e7
parent 8100 0e6fadf81a2c
permissions -rw-r--r--
Unbreak build
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
8100
0e6fadf81a2c - frontlib loads team config via physfs
unc0rr
parents:
diff changeset
     1
#include <stdlib.h>
0e6fadf81a2c - frontlib loads team config via physfs
unc0rr
parents:
diff changeset
     2
0e6fadf81a2c - frontlib loads team config via physfs
unc0rr
parents:
diff changeset
     3
#include "physfsfgets.h"
0e6fadf81a2c - frontlib loads team config via physfs
unc0rr
parents:
diff changeset
     4
0e6fadf81a2c - frontlib loads team config via physfs
unc0rr
parents:
diff changeset
     5
char * PHYSFS_fgets(char * str, int size, PHYSFS_file * f)
0e6fadf81a2c - frontlib loads team config via physfs
unc0rr
parents:
diff changeset
     6
{
0e6fadf81a2c - frontlib loads team config via physfs
unc0rr
parents:
diff changeset
     7
    int i = 0;
0e6fadf81a2c - frontlib loads team config via physfs
unc0rr
parents:
diff changeset
     8
    char c;
0e6fadf81a2c - frontlib loads team config via physfs
unc0rr
parents:
diff changeset
     9
0e6fadf81a2c - frontlib loads team config via physfs
unc0rr
parents:
diff changeset
    10
    if(size <= 0 || PHYSFS_eof(f))
0e6fadf81a2c - frontlib loads team config via physfs
unc0rr
parents:
diff changeset
    11
        return NULL;
0e6fadf81a2c - frontlib loads team config via physfs
unc0rr
parents:
diff changeset
    12
0e6fadf81a2c - frontlib loads team config via physfs
unc0rr
parents:
diff changeset
    13
    do
0e6fadf81a2c - frontlib loads team config via physfs
unc0rr
parents:
diff changeset
    14
    {
0e6fadf81a2c - frontlib loads team config via physfs
unc0rr
parents:
diff changeset
    15
        if (PHYSFS_readBytes(f, &c, 1) < 1)
0e6fadf81a2c - frontlib loads team config via physfs
unc0rr
parents:
diff changeset
    16
            break;
0e6fadf81a2c - frontlib loads team config via physfs
unc0rr
parents:
diff changeset
    17
0e6fadf81a2c - frontlib loads team config via physfs
unc0rr
parents:
diff changeset
    18
        str[i] = c;
0e6fadf81a2c - frontlib loads team config via physfs
unc0rr
parents:
diff changeset
    19
        ++i;
0e6fadf81a2c - frontlib loads team config via physfs
unc0rr
parents:
diff changeset
    20
    } while(c != '\n' && i < size - 1);
0e6fadf81a2c - frontlib loads team config via physfs
unc0rr
parents:
diff changeset
    21
0e6fadf81a2c - frontlib loads team config via physfs
unc0rr
parents:
diff changeset
    22
    str[i] = '\0';
0e6fadf81a2c - frontlib loads team config via physfs
unc0rr
parents:
diff changeset
    23
    if (i == 0)
0e6fadf81a2c - frontlib loads team config via physfs
unc0rr
parents:
diff changeset
    24
        return NULL;
0e6fadf81a2c - frontlib loads team config via physfs
unc0rr
parents:
diff changeset
    25
    else
0e6fadf81a2c - frontlib loads team config via physfs
unc0rr
parents:
diff changeset
    26
        return str;
0e6fadf81a2c - frontlib loads team config via physfs
unc0rr
parents:
diff changeset
    27
}