From 05ff3da0f88c5f6b03c43371e88fb1b22434a51e Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Wed, 6 Jan 2010 18:39:36 +0000 Subject: major patch for openbsd --- src/init.c | 84 +++++++++++++++++++++++++++++++------------------------------- 1 file changed, 42 insertions(+), 42 deletions(-) (limited to 'src/init.c') diff --git a/src/init.c b/src/init.c index a9798a1..402f357 100644 --- a/src/init.c +++ b/src/init.c @@ -140,7 +140,7 @@ unsigned char PORTACTIVE; struct timeConsts timeConst; struct device_info device; -struct logging log; +struct logging logging; int portAddress; int portStatus; @@ -307,11 +307,11 @@ void initTimeConst(FILE *rcPtr) { fprintf(rcPtr, "KANDA=%d\n", KandaMode); fprintf(rcPtr, "# Set the log path/file to log writes and locks.\n"); fprintf(rcPtr, "# (less than 200 characters)\n"); - fprintf(rcPtr, "LOGPATH=%s\n", log.logPath); + fprintf(rcPtr, "LOGPATH=%s\n", logging.logPath); fprintf(rcPtr, "# Set logging=1 to activate logging:\n"); - fprintf(rcPtr, "LOGGING=%d\n", log.logging); + fprintf(rcPtr, "LOGGING=%d\n", logging.logging); fprintf(rcPtr, "# Set both logging and query=1 to always query writes:\n"); - fprintf(rcPtr, "QUERY=%d\n", log.query); + fprintf(rcPtr, "QUERY=%d\n", logging.query); fprintf(rcPtr, "# Chip erase delay, 120ms ATMega, 20ms others:\n"); fprintf(rcPtr, "CHIPERASE=%d\n", timeConst.chipErase); fprintf(rcPtr, "# Time constant for 200ms will be:\n"); @@ -371,25 +371,25 @@ void initSp12(char *howWeAreCalled) { writeRetries = 0; timeConst.byteWriteAdjusted = 0; timeConst.pageWriteAdjusted = 0; - log.logging = 0; - log.query = 0; - strcpy(log.logPath, "sp12log.txt"); + logging.logging = 0; + logging.query = 0; + strlcpy(logging.logPath, "sp12log.txt", sizeof(logging.logPath)); KandaMode = 3; /* if it remains 3 after reading _sp12rc, */ /* check how we were called */ if ((sp12rc = getenv("SP12")) != NULL) { - strcpy(rcPath, sp12rc); -#ifdef LINUX - if (rcPath[strlen(rcPath)-1] != '/') - strcat (rcPath, "/"); -#else + strlcpy(rcPath, sp12rc, sizeof(rcPath)); +#if defined(__WIN32__) if (rcPath[strlen(rcPath)-1] != '\\') - strcat (rcPath, "\\"); + strcat(rcPath, "\\", ); +#else + if (rcPath[strlen(rcPath)-1] != '/') + strlcat(rcPath, "/", sizeof(rcPath)); #endif printf("Path to _sp12rc and _sp12dev: %s\n", rcPath); - strcat(rcPath, "_sp12rc"); + strlcat(rcPath, "_sp12rc", sizeof(rcPath)); } else { - strcpy(rcPath, "_sp12rc"); + strlcpy(rcPath, "_sp12rc", sizeof(rcPath)); printf("Path to _sp12rc and _sp12dev: Local directory\n"); } if ((rcPtr = fopen(rcPath, "r")) != NULL) { @@ -399,9 +399,9 @@ void initSp12(char *howWeAreCalled) { while (fgets(rcLine, MAXLEN, rcPtr) != NULL) { sscanf(rcLine, "PORT=%x", &portAddress); sscanf(rcLine, "KANDA=%d", &KandaMode); - sscanf(rcLine, "LOGPATH=%s", log.logPath); - sscanf(rcLine, "LOGGING=%d", &log.logging); - sscanf(rcLine, "QUERY=%d", &log.query); + sscanf(rcLine, "LOGPATH=%s", logging.logPath); + sscanf(rcLine, "LOGGING=%d", &logging.logging); + sscanf(rcLine, "QUERY=%d", &logging.query); sscanf(rcLine, "RESETPULS=%ld", &timeConst.resetPuls); sscanf(rcLine, "CHIPERASE=%d", &timeConst.chipErase); sscanf(rcLine, "POWERON=%d", &timeConst.powerOn); @@ -446,7 +446,7 @@ void initSp12(char *howWeAreCalled) { || timeConst.programEnable == 0 || timeConst.chipErase == 0 || timeConst.byteWrite == 0 || timeConst.powerOn == 0 || timeConst.pageWrite == 0) { - fprintf(stderr, "Initialisation has failed (parallel port not found,\n"); + fprintf(stderr, "Initialisation has failed (parallel port not found, "); fprintf(stderr, "or %s corrupt).\n", rcPath); exit(1); } @@ -457,7 +457,7 @@ void initSp12(char *howWeAreCalled) { */ outportb(portAddress, 0x80); if (inportb(portAddress) != 0x80) { - fprintf(stderr, "Initialisation has failed (parallel port not\n"); + fprintf(stderr, "Initialisation has failed (parallel port not "); fprintf(stderr, "responding, or %s corrupt).\n", rcPath); exit(1); } else { @@ -606,17 +606,17 @@ int setDevicePars(int initFlag, char *identifier) { if ((sp12dev = getenv("SP12")) != NULL) { - strcpy(rcPath, sp12dev); -#ifdef LINUX - if (rcPath[strlen(rcPath)-1] != '/') - strcat (rcPath, "/"); -#else + strlcpy(rcPath, sp12dev, sizeof(rcPath)); +#if defined(__WIN32__) if (rcPath[strlen(rcPath)-1] != '\\') - strcat (rcPath, "\\"); + strcat(rcPath, "\\"); +#else + if (rcPath[strlen(rcPath)-1] != '/') + strlcat(rcPath, "/", sizeof(rcPath)); #endif - strcat(rcPath, "_sp12dev"); + strlcat(rcPath, "_sp12dev", sizeof(rcPath)); } else { - strcpy(rcPath, "_sp12dev"); + strlcpy(rcPath, "_sp12dev", sizeof(rcPath)); } if ((rcPtr = fopen(rcPath, "r")) == NULL) { @@ -631,17 +631,17 @@ int setDevicePars(int initFlag, char *identifier) { deviceCode = deviceCode | device.sigByte_1; switch (device.sigByte_0) { case 0x1E: - strcpy(device.madeBy, "Atmel"); + strlcpy(device.madeBy, "Atmel", sizeof(device.madeBy)); break; default: - strcpy(device.madeBy, "an unknown manufacturer"); + strlcpy(device.madeBy, "an unknown manufacturer", sizeof(device.madeBy)); } begin = 0; iFlag = 0; found = 0; - strcpy(LOCK_MESSAGE, ""); - strcpy(FUSES_MESSAGE, ""); - strcpy(device.name, "unknown device, or no device"); + strlcpy(LOCK_MESSAGE, "", sizeof(LOCK_MESSAGE)); + strlcpy(FUSES_MESSAGE, "", sizeof(FUSES_MESSAGE)); + strlcpy(device.name, "unknown device, or no device", sizeof(device.name)); device.flashLimit = 0; device.eepromLimit = 0; device.pageMode = 0; @@ -686,7 +686,7 @@ int setDevicePars(int initFlag, char *identifier) { } if (begin && sscanf(rcLine, "DEVICENAME = %[A-Z ()0-9a-z]", rawLine) == 1) { - strcpy(device.name, rawLine); + strlcpy(device.name, rawLine, sizeof(device.name)); } if (begin && sscanf(rcLine, "FLASHSIZE = %i", &iNum) == 1) { device.flashLimit = iNum; @@ -813,17 +813,17 @@ int supported(void) { int found = 0; if ((sp12dev = getenv("SP12")) != NULL) { - strcpy(rcPath, sp12dev); -#ifdef LINUX - if (rcPath[strlen(rcPath)-1] != '/') - strcat (rcPath, "/"); -#else + strlcpy(rcPath, sp12dev, sizeof(rcPath)); +#if defined(__WIN32__) if (rcPath[strlen(rcPath)-1] != '\\') - strcat (rcPath, "\\"); + strcat(rcPath, "\\"); +#else + if (rcPath[strlen(rcPath)-1] != '/') + strlcat(rcPath, "/", sizeof(rcPath)); #endif - strcat(rcPath, "_sp12dev"); + strlcat(rcPath, "_sp12dev", sizeof(rcPath)); } else { - strcpy(rcPath, "_sp12dev"); + strlcpy(rcPath, "_sp12dev", sizeof(rcPath)); } if ((rcPtr = fopen(rcPath, "r")) == NULL) { -- cgit v1.2.3