DNA Alignment/src/parser.c
int readLine(char* path, int offset, char* buffer, int sizeBuffer){
    int fd = 0;
    int sizeRead = 0;
    int i = 0;
    char c = 0;

    memset(buffer, 0, sizeBuffer);

    if((fd = open(path, O_RDONLY)) < 0){
        perror("Error opening file");
        return fd;
    }

    lseek(fd, offset, SEEK_SET);

    do{
        if((sizeRead = read(fd, &c, 1)) < 0){
            perror("Error reading from file");
            close(fd);
            return sizeRead;
        }else if (sizeRead == 0){
            printf("End Of File\n");
            return 0;
        }
        buffer[i++] = c;
    }while(c != '\n' && sizeRead != 0 && i < sizeBuffer);

    buffer[i] = '\0';
    close(fd);
    return i;
}
/*******************************************************************************
*       readLine(char*, int, char*, int)
*   Reads a line from file "path", and stores it in a buffer
*   Input : char* path      :   Path of file
*           int offset      :   Number of bytes of the file that have previously
*                               been read
*           char* buffer    :   Buffer where the line read from file is stored
*           int sizeBuffer  :   Maximum size of the buffer
*
*   Output: int             :   return the number of bytes read if successful
*                               < 0 If an error occured
*******************************************************************************/


int             :   return the number of bytes read if successful
< 0 If an error occured
int : return the number of bytes read if successful < 0 If an error occured
int readLine(char* path, int offset, char* buffer, int sizeBuffer){
    int fd = 0;
    int sizeRead = 0;
    int i = 0;
    char c = 0;
    memset(buffer, 0, sizeBuffer);
    if((fd = open(path, O_RDONLY)) < 0){
        perror("Error opening file");
        return fd;
    }
    lseek(fd, offset, SEEK_SET);
    do{
        if((sizeRead = read(fd, &c, 1)) < 0){
            perror("Error reading from file");
            close(fd);
            return sizeRead;
        }else if (sizeRead == 0){
            printf("End Of File\n");
            return 0;
        }
        buffer[i++] = c;
    }while(c != '\n' && sizeRead != 0 && i < sizeBuffer);
    buffer[i] = '\0';
    close(fd);
    return i;
}
int readLine ( char * path , int offset , char * buffer , int sizeBuffer ) { int fd = 0 ; int sizeRead = 0 ; int i = 0 ; char c = 0 ; memset ( buffer , 0 , sizeBuffer ) ; if ( ( fd = open ( path , O_RDONLY ) ) < 0 ) { perror ( " " ) ; return fd ; } lseek ( fd , offset , SEEK_SET ) ; do { if ( ( sizeRead = read ( fd , & c , 1 ) ) < 0 ) { perror ( " " ) ; close ( fd ) ; return sizeRead ; } else if ( sizeRead == 0 ) { printf ( " \n " ) ; return 0 ; } buffer [ i ++ ] = c ; } while ( c != ' \n ' && sizeRead != 0 && i < sizeBuffer ) ; buffer [ i ] = ' \0 ' ; close ( fd ) ; return i ; }
readLine(char*, int, char*, int)
Reads a line from file "path", and stores it in a buffer
Input : char* path      :   Path of file
int offset      :   Number of bytes of the file that have previously
been read
char* buffer    :   Buffer where the line read from file is stored
int sizeBuffer  :   Maximum size of the buffer
readLine ( char * int char * int ) Reads a line from file " path " and stores it in a buffer Input : char * path : Path of file int offset : Number of bytes of the file that have previously been read char * buffer : Buffer where the line read from file is stored int sizeBuffer : Maximum size of the buffer