123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174 |
-
- #include <stdio.h>
- #include <errno.h>
- #include "jam.h"
- #include "structrw.h"
- int JAM_ReadLastRead( s_JamBase* Base_PS,
- uint32_t User_I,
- s_JamLastRead* Record_PS )
- {
- s_JamLastRead Record_S;
- int Pos_I;
- if (!Record_PS)
- return JAM_BAD_PARAM;
- if ( fseek( Base_PS->LrdFile_PS, 0, SEEK_SET ) ) {
- Base_PS->Errno_I = errno;
- return JAM_IO_ERROR;
- }
- for ( Pos_I = 0; ; Pos_I++ ) {
- if ( 1 > freadjamlastread(Base_PS->LrdFile_PS,&Record_S) ) {
- if ( feof(Base_PS->LrdFile_PS) )
- return JAM_NO_USER;
- Base_PS->Errno_I = errno;
- return JAM_IO_ERROR;
- }
- if ( Record_S.UserID == User_I ) {
- Base_PS->LastUserPos_I = Pos_I;
- Base_PS->LastUserId_I = User_I;
- *Record_PS = Record_S;
- return 0;
- }
- }
- return 0;
- }
- int JAM_WriteLastRead( s_JamBase* Base_PS,
- uint32_t User_I,
- s_JamLastRead* Record_PS )
- {
- s_JamLastRead Record_S;
- int Pos_I;
- if (!Record_PS)
- return JAM_BAD_PARAM;
-
- if ( User_I == Base_PS->LastUserId_I ) {
- Pos_I = Base_PS->LastUserPos_I * sizeof( s_JamLastRead );
- if ( fseek( Base_PS->LrdFile_PS, Pos_I, SEEK_SET ) ) {
- Base_PS->Errno_I = errno;
- return JAM_IO_ERROR;
- }
-
- if ( 1 > freadjamlastread(Base_PS->LrdFile_PS,&Record_S) ) {
- Base_PS->Errno_I = errno;
- return JAM_IO_ERROR;
- }
-
- if ( User_I == Record_S.UserID ) {
-
- if ( fseek( Base_PS->LrdFile_PS, Pos_I, SEEK_SET ) ) {
- Base_PS->Errno_I = errno;
- return JAM_IO_ERROR;
- }
- if ( 1 > fwritejamlastread(Base_PS->LrdFile_PS,Record_PS) ) {
- Base_PS->Errno_I = errno;
- return JAM_IO_ERROR;
- }
- fflush(Base_PS -> LrdFile_PS);
- return 0;
- }
- }
-
- if ( fseek( Base_PS->LrdFile_PS, 0, SEEK_SET ) ) {
- Base_PS->Errno_I = errno;
- return JAM_IO_ERROR;
- }
- for ( Pos_I = 0; ; Pos_I++ ) {
- if ( 1 > freadjamlastread(Base_PS->LrdFile_PS,&Record_S) ) {
- if ( feof(Base_PS->LrdFile_PS) ) {
-
- if ( fseek( Base_PS->LrdFile_PS, 0, SEEK_END ) ) {
- Base_PS->Errno_I = errno;
- return JAM_IO_ERROR;
- }
- break;
- }
- Base_PS->Errno_I = errno;
- return JAM_IO_ERROR;
- }
-
- if ( Record_S.UserID == User_I ) {
- if ( fseek( Base_PS->LrdFile_PS, Pos_I * sizeof(s_JamLastRead),
- SEEK_SET ) ) {
- Base_PS->Errno_I = errno;
- return JAM_IO_ERROR;
- }
- break;
- }
- }
- if ( 1 > fwritejamlastread(Base_PS->LrdFile_PS,Record_PS) ) {
- Base_PS->Errno_I = errno;
- return JAM_IO_ERROR;
- }
- fflush( Base_PS->LrdFile_PS );
- return 0;
- }
|