aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2013-04-15 21:50:51 +0200
committerHarald Welte <laforge@gnumonks.org>2013-06-22 19:22:45 +0200
commit6002d17c24e11997db89cd9bcbd2e0354f089459 (patch)
treefcc2097aa2a6930c2990ea8b220c89457017b501
parentd675de9c235c5ed9b8b9cdb69666998bd0fb65ea (diff)
eeprom: cache the file descriptor instead of fopen/fclose all the time
-rw-r--r--src/osmo-bts-sysmo/eeprom.c33
1 files changed, 19 insertions, 14 deletions
diff --git a/src/osmo-bts-sysmo/eeprom.c b/src/osmo-bts-sysmo/eeprom.c
index 2453f4af..64193fd9 100644
--- a/src/osmo-bts-sysmo/eeprom.c
+++ b/src/osmo-bts-sysmo/eeprom.c
@@ -1391,24 +1391,27 @@ int eeprom_dump( int addr, int size, int hex )
return 0;
}
+static FILE *g_file;
/**
* Read up to 'size' bytes of data from the EEPROM starting at offset 'addr'.
*/
static int eeprom_read( int addr, int size, char *pBuff )
{
- FILE *f;
+ FILE *f = g_file;
int n;
- f = fopen( EEPROM_DEV, "r+" );
- if ( f == NULL )
- {
- perror( "eeprom fopen" );
- return -1;
+ if (!f) {
+ f = fopen( EEPROM_DEV, "r+" );
+ if ( f == NULL )
+ {
+ perror( "eeprom fopen" );
+ return -1;
+ }
+ g_file = f;
}
fseek( f, addr, SEEK_SET );
n = fread( pBuff, 1, size, f );
- fclose( f );
return n;
}
@@ -1418,14 +1421,17 @@ static int eeprom_read( int addr, int size, char *pBuff )
*/
static int eeprom_write( int addr, int size, const char *pBuff )
{
- FILE *f;
+ FILE *f = g_file;
int n;
- f = fopen( EEPROM_DEV, "r+" );
- if ( f == NULL )
- {
- perror( "eeprom fopen" );
- return -1;
+ if (!f) {
+ f = fopen( EEPROM_DEV, "r+" );
+ if ( f == NULL )
+ {
+ perror( "eeprom fopen" );
+ return -1;
+ }
+ g_file = f;
}
fseek( f, addr, SEEK_SET );
n = fwrite( pBuff, 1, size, f );
@@ -1454,4 +1460,3 @@ static uint16_t eeprom_crc( uint8_t *pu8Data, int len )
crc = ~crc;
return crc;
}
-