Rev 297 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 297 | Rev 317 | ||
---|---|---|---|
Line 666... | Line 666... | ||
666 | /* */ |
666 | /* */ |
667 | /* Description: This function sets the pointer of the stream relative to the position */ |
667 | /* Description: This function sets the pointer of the stream relative to the position */ |
668 | /* specified by origin (SEEK_SET, SEEK_CUR, SEEK_END) */ |
668 | /* specified by origin (SEEK_SET, SEEK_CUR, SEEK_END) */ |
669 | /* Returnvalue: Is 1 if seek was successful */ |
669 | /* Returnvalue: Is 1 if seek was successful */ |
670 | /****************************************************************************************************************************************************/ |
670 | /****************************************************************************************************************************************************/ |
671 | int16_t fseek_(File_t *file, int32_t offset, int16_t origin) |
671 | int16_t fseek_(File_t * const file, int32_t offset, int16_t origin) |
672 | { |
672 | { |
673 | int32_t fposition = 0; |
673 | int32_t fposition = 0; |
674 | int16_t retvalue = 1; |
674 | int16_t retvalue = 1; |
Line 675... | Line 675... | ||
675 | 675 | ||
Line 1255... | Line 1255... | ||
1255 | /* Description: This function looks for the specified file in the rootdirectory of the drive. If the file is found the number of the */ |
1255 | /* Description: This function looks for the specified file in the rootdirectory of the drive. If the file is found the number of the */ |
1256 | /* corrosponding filepointer is returned. Only modes 'r' (reading) and 'a' append are implemented yet. */ |
1256 | /* corrosponding filepointer is returned. Only modes 'r' (reading) and 'a' append are implemented yet. */ |
1257 | /* */ |
1257 | /* */ |
1258 | /* Returnvalue: The filepointer to the file or 0 if faild. */ |
1258 | /* Returnvalue: The filepointer to the file or 0 if faild. */ |
1259 | /********************************************************************************************************************************************/ |
1259 | /********************************************************************************************************************************************/ |
1260 | File_t * fopen_(const int8_t *filename, const int8_t mode) |
1260 | File_t * fopen_(int8_t * const filename, const int8_t mode) |
1261 | { |
1261 | { |
1262 | File_t *file = 0; |
1262 | File_t *file = 0; |
Line 1263... | Line 1263... | ||
1263 | 1263 | ||
Line 1361... | Line 1361... | ||
1361 | /* */ |
1361 | /* */ |
1362 | /* Description: This function writes the data already in the buffer but not yet written to the file. */ |
1362 | /* Description: This function writes the data already in the buffer but not yet written to the file. */ |
1363 | /* */ |
1363 | /* */ |
1364 | /* Returnvalue: 0 on success EOF on error */ |
1364 | /* Returnvalue: 0 on success EOF on error */ |
1365 | /****************************************************************************************************************************************************/ |
1365 | /****************************************************************************************************************************************************/ |
1366 | int16_t fflush_(File_t *file) |
1366 | int16_t fflush_(File_t * const file) |
1367 | { |
1367 | { |
1368 | DirEntry_t *dir; |
1368 | DirEntry_t *dir; |
Line 1369... | Line 1369... | ||
1369 | 1369 | ||
Line 1430... | Line 1430... | ||
1430 | /* Description: This function reads and returns one character from the specified file. Is the end of the actual sector reached the */ |
1430 | /* Description: This function reads and returns one character from the specified file. Is the end of the actual sector reached the */ |
1431 | /* next sector of the cluster is read. If the last sector of the cluster read the next cluster will be searched in FAT. */ |
1431 | /* next sector of the cluster is read. If the last sector of the cluster read the next cluster will be searched in FAT. */ |
1432 | /* */ |
1432 | /* */ |
1433 | /* Returnvalue: The function returns the character read from the specified memorylocation as u8 casted to s16 or EOF. */ |
1433 | /* Returnvalue: The function returns the character read from the specified memorylocation as u8 casted to s16 or EOF. */ |
1434 | /********************************************************************************************************************************************/ |
1434 | /********************************************************************************************************************************************/ |
1435 | int16_t fgetc_(File_t *file) |
1435 | int16_t fgetc_(File_t * const file) |
1436 | { |
1436 | { |
1437 | int16_t c = EOF; |
1437 | int16_t c = EOF; |
1438 | uint32_t curr_sector; |
1438 | uint32_t curr_sector; |
Line 1439... | Line 1439... | ||
1439 | 1439 | ||
Line 1484... | Line 1484... | ||
1484 | /* Description: This function writes a byte to the specified file and takes care of writing the necessary FAT- Entries. */ |
1484 | /* Description: This function writes a byte to the specified file and takes care of writing the necessary FAT- Entries. */ |
1485 | /* next sector of the cluster is read. If the last sector of the cluster read the next cluster will be searched in FAT. */ |
1485 | /* next sector of the cluster is read. If the last sector of the cluster read the next cluster will be searched in FAT. */ |
1486 | /* */ |
1486 | /* */ |
1487 | /* Returnvalue: The function returns the character written to the stream or EOF on error. */ |
1487 | /* Returnvalue: The function returns the character written to the stream or EOF on error. */ |
1488 | /********************************************************************************************************************************************/ |
1488 | /********************************************************************************************************************************************/ |
1489 | int16_t fputc_(const int8_t c, File_t *file) |
1489 | int16_t fputc_(const int8_t c, File_t * const file) |
1490 | { |
1490 | { |
1491 | uint32_t curr_sector = 0; |
1491 | uint32_t curr_sector = 0; |
Line 1492... | Line 1492... | ||
1492 | 1492 | ||
Line 1552... | Line 1552... | ||
1552 | /* Description: This function reads count objects of the specified size */ |
1552 | /* Description: This function reads count objects of the specified size */ |
1553 | /* from the actual position of the file to the specified buffer. */ |
1553 | /* from the actual position of the file to the specified buffer. */ |
1554 | /* */ |
1554 | /* */ |
1555 | /* Returnvalue: The function returns the number of objects (not bytes) read from the file. */ |
1555 | /* Returnvalue: The function returns the number of objects (not bytes) read from the file. */ |
1556 | /****************************************************************************************************************************************/ |
1556 | /****************************************************************************************************************************************/ |
1557 | uint32_t fread_(void *buffer, uint32_t size, uint32_t count, File_t *file) |
1557 | uint32_t fread_(void * const buffer, uint32_t size, uint32_t count, File_t * const file) |
1558 | { |
1558 | { |
1559 | uint32_t object_cnt = 0; // count the number of objects read from the file. |
1559 | uint32_t object_cnt = 0; // count the number of objects read from the file. |
1560 | uint32_t object_size = 0; // count the number of bytes read from the actual object. |
1560 | uint32_t object_size = 0; // count the number of bytes read from the actual object. |
1561 | uint8_t *pbuff = 0; // a pointer to the actual bufferposition. |
1561 | uint8_t *pbuff = 0; // a pointer to the actual bufferposition. |
1562 | uint8_t success = 1; // no error occured during read operation to the file. |
1562 | uint8_t success = 1; // no error occured during read operation to the file. |
Line 1595... | Line 1595... | ||
1595 | /* Description: This function writes count objects of the specified size */ |
1595 | /* Description: This function writes count objects of the specified size */ |
1596 | /* from the buffer pointer to the actual position in the file. */ |
1596 | /* from the buffer pointer to the actual position in the file. */ |
1597 | /* */ |
1597 | /* */ |
1598 | /* Returnvalue: The function returns the number of objects (not bytes) read from the file. */ |
1598 | /* Returnvalue: The function returns the number of objects (not bytes) read from the file. */ |
1599 | /****************************************************************************************************************************************/ |
1599 | /****************************************************************************************************************************************/ |
1600 | uint32_t fwrite_(void *buffer, uint32_t size, uint32_t count, File_t *file) |
1600 | uint32_t fwrite_(void * const buffer, uint32_t size, uint32_t count, File_t * const file) |
1601 | { |
1601 | { |
1602 | uint32_t object_cnt = 0; // count the number of objects written to the file. |
1602 | uint32_t object_cnt = 0; // count the number of objects written to the file. |
1603 | uint32_t object_size = 0; // count the number of bytes written from the actual object. |
1603 | uint32_t object_size = 0; // count the number of bytes written from the actual object. |
1604 | uint8_t *pbuff = 0; // a pointer to the actual bufferposition. |
1604 | uint8_t *pbuff = 0; // a pointer to the actual bufferposition. |
1605 | uint8_t success = 1; // no error occured during write operation to the file. |
1605 | uint8_t success = 1; // no error occured during write operation to the file. |
Line 1637... | Line 1637... | ||
1637 | /* */ |
1637 | /* */ |
1638 | /* Description: This function writes a string to the specified file. */ |
1638 | /* Description: This function writes a string to the specified file. */ |
1639 | /* */ |
1639 | /* */ |
1640 | /* Returnvalue: The function returns a no negative value or EOF on error. */ |
1640 | /* Returnvalue: The function returns a no negative value or EOF on error. */ |
1641 | /****************************************************************************************************************************************/ |
1641 | /****************************************************************************************************************************************/ |
1642 | int16_t fputs_(const int8_t *string, File_t *file) |
1642 | int16_t fputs_(int8_t * const string, File_t * const file) |
1643 | { |
1643 | { |
1644 | uint8_t i=0; |
1644 | uint8_t i=0; |
1645 | int16_t c = 0; |
1645 | int16_t c = 0; |
Line 1646... | Line 1646... | ||
1646 | 1646 | ||
Line 1659... | Line 1659... | ||
1659 | /* */ |
1659 | /* */ |
1660 | /* Description: This function reads a string from the file to the specifies string. */ |
1660 | /* Description: This function reads a string from the file to the specifies string. */ |
1661 | /* */ |
1661 | /* */ |
1662 | /* Returnvalue: A pointer to the string read from the file or 0 on error. */ |
1662 | /* Returnvalue: A pointer to the string read from the file or 0 on error. */ |
1663 | /****************************************************************************************************************************************/ |
1663 | /****************************************************************************************************************************************/ |
1664 | uint8_t * fgets_(int8_t *string, int16_t length, File_t *file) |
1664 | int8_t * fgets_(int8_t * const string, int16_t length, File_t * const file) |
1665 | { |
1665 | { |
1666 | uint8_t *pbuff; |
1666 | int8_t *pbuff; |
1667 | int16_t c = 0; |
1667 | int16_t c = 0, bytecount; |
Line 1668... | Line 1668... | ||
1668 | 1668 | ||
1669 | if((!Partition.IsValid) || (file == NULL) || (string == NULL) || (length = 0)) return (0); |
1669 | if((!Partition.IsValid) || (file == NULL) || (string == NULL) || (length > 1)) return (0); |
- | 1670 | pbuff = string; |
|
1670 | pbuff = string; |
1671 | bytecount = length; |
1671 | while(length > 1) // read the count-1 characters from the file to the string. |
1672 | while(bytecount > 1) // read the count-1 characters from the file to the string. |
1672 | { |
1673 | { |
1673 | c = fgetc_(file); // read a character from the opened file. |
1674 | c = fgetc_(file); // read a character from the opened file. |
1674 | switch(c) |
1675 | switch(c) |
1675 | { |
1676 | { |
1676 | case 0x0A: |
1677 | case 0x0A: |
1677 | c = 0; // set string terminator |
1678 | *pbuff = 0; // set string terminator |
1678 | length = 1; // stop loop |
1679 | return(string); // stop loop |
Line 1679... | Line 1680... | ||
1679 | break; |
1680 | break; |
1680 | 1681 | ||
- | 1682 | case EOF: |
|
- | 1683 | *pbuff = 0; // set string terminator |
|
1681 | case EOF: |
1684 | return(0); |
- | 1685 | default: |
|
1682 | c = 0; // set string terminator |
1686 | *pbuff++ = (int8_t)c; // copy byte to string |
1683 | length = 1; // stop loop |
1687 | bytecount--; |
1684 | break; |
- | |
1685 | } |
- | |
1686 | *pbuff = (uint8_t)c; // copy byte to string |
- | |
1687 | length--; |
1688 | break; |
- | 1689 | } |
|
1688 | pbuff++; |
1690 | } |
1689 | } |
1691 | *pbuff = 0; |
Line 1690... | Line 1692... | ||
1690 | return(string); |
1692 | return(string); |
1691 | } |
1693 | } |