Show
Ignore:
Timestamp:
04/24/08 14:34:51 (5 years ago)
Author:
khali
Message:

Move the chip address parsing to a common function for consistency.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • i2c-tools/trunk/tools/i2cbusses.c

    r5202 r5204  
    345345} 
    346346 
     347/* 
     348 * Parse a CHIP-ADDRESS command line argument and return the corresponding 
     349 * chip address, or a negative value if the address is invalid. 
     350 */ 
     351int parse_i2c_address(const char *address_arg) 
     352{ 
     353        long address; 
     354        char *end; 
     355 
     356        address = strtol(address_arg, &end, 0); 
     357        if (*end || !*address_arg) { 
     358                fprintf(stderr, "Error: Chip address is not a number!\n"); 
     359                return -1; 
     360        } 
     361        if (address < 0x03 || address > 0x77) { 
     362                fprintf(stderr, "Error: Chip address out of range " 
     363                        "(0x03-0x77)!\n"); 
     364                return -2; 
     365        } 
     366 
     367        return address; 
     368} 
     369 
    347370int open_i2c_dev(const int i2cbus, char *filename, const int quiet) 
    348371{