Skip to content
Browse files

Added nanosleep alternative and removed str_error

  • Loading branch information...
1 parent 954afb9 commit 9672cb7cb0f0a41eb28646a91395b641fbb343ee @TacoSteemers committed Apr 1, 2013
Showing with 26 additions and 4 deletions.
  1. +1 −2 .gitignore
  2. +9 −1 code/backup.c
  3. +4 −0 code/detection.c
  4. +11 −0 code/util.c
  5. +1 −1 tools/Makefile
View
3 .gitignore
@@ -5,7 +5,6 @@
/code/util.c~
/.gitignore~
/test
-/bin/uslist
/code/uslist.c~
/code/uslist.h~
/code/bookKeeping.h~
@@ -21,5 +20,5 @@
/code/global.h~
/code/daemon.c~
/README.md~
-/bin/usbstoragebackup
/tools/Makefile~
+/bin/*
View
10 code/backup.c
@@ -73,9 +73,11 @@ void backDeviceUp(char* mountPoint, char* deviceId)
}
void doBackup(char *source, char *target){
+ #ifndef _WIN32
char errorBuf[32];
size_t errorBufLen = 32;
int error;
+ #endif
char outputBuffer[32];
char command[8192]; /* Max path length * 2 */
char* targetNoSpaces = replace(target, " ", "");
@@ -85,9 +87,11 @@ void doBackup(char *source, char *target){
FILE *outputPipe = popen (command, "r");
if (!outputPipe)
{
+ #ifndef _WIN32
error = errno;
strerror_r(error, errorBuf, errorBufLen);
syslog(LOG_ERR, "Execution of backup failed: %s", errorBuf);
+ #endif
syslog(LOG_ERR, "Exiting with failure: could not run command: \"%s\"", command);
exit(EXIT_FAILURE);
}
@@ -97,9 +101,13 @@ void doBackup(char *source, char *target){
}
if (pclose(outputPipe) == -1)
{
+ #ifndef _WIN32
error = errno;
strerror_r(error, errorBuf, errorBufLen);
- syslog(LOG_ERR, "Error while closing the pipe to the backup failed: %s", errorBuf);
+ syslog(LOG_ERR, "Error while closing the pipe to the backup: %s", errorBuf);
+ #else
+ syslog(LOG_ERR, "Error while closing the pipe to the backup");
+ #endif
}
if(targetNoSpaces != NULL)
free(targetNoSpaces);
View
4 code/detection.c
@@ -21,6 +21,9 @@
void doCheck(void)
{
+ #ifdef _WIN32
+
+ #else
DIR *directory;
struct dirent *entry;
char* dirToCheck = "/sys/block/";
@@ -46,6 +49,7 @@ void doCheck(void)
} while (entry != NULL);
free(directory);
free(entry);
+ #endif
finalizeRun();
}
View
11 code/util.c
@@ -16,6 +16,9 @@
#include "logging.h"
#include "global.h" /* MAXLISTLENGTH */
#include "util.h"
+#ifdef _WIN32
+#include <windows.h>
+#endif
/* Removes trailing spaces, blanks and control characters */
@@ -67,7 +70,11 @@ FILE *keepTryingToOpen(const char *path, const char *mode, int count)
if(fp)
return fp;
/* Path was unavailable. Let's try again in half a second. */
+ #ifndef _WIN32
nanosleep((struct timespec[]){{0, 500000000}}, NULL);
+ #else
+ Sleep(500);
+ #endif
}
syslog(LOG_ERR, "Exiting with failure: Could not open \"%s\".", path);
exit(EXIT_FAILURE);
@@ -88,7 +95,11 @@ DIR *keepTryingToOpenDir(const char *path, int count)
if((directory = opendir(path)) != NULL)
return directory;
/* Path was unavailable. Let's try again in half a second. */
+ #ifndef _WIN32
nanosleep((struct timespec[]){{0, 500000000}}, NULL);
+ #else
+ Sleep(500);
+ #endif
}
syslog(LOG_ERR, "Exiting with failure: Could not open \"%s\".", path);
exit(EXIT_FAILURE);
View
2 tools/Makefile
@@ -7,7 +7,7 @@ clean:
allWin:
gcc -Wall -g -O0 -o ../bin/usbstoragebackup.exe ../code/daemonWindows.c ../code/processArguments.c ../code/bookKeeping.c ../code/util.c ../code/backup.c ../code/loggingWindows.c ../code/detectionWindows.c ../code/windowsAlternatives.c
- gcc -Wall -g -O0 -o ../bin/uslist.exe ../code/uslist.c ../code/detection.c ../code/util.c ../code/loggingWindows.c
+ gcc -Wall -g -O0 -o ../bin/uslist.exe ../code/uslist.c ../code/detectionWindows.c ../code/util.c ../code/loggingWindows.c
cleanWin:
del ../bin/usbstoragebackup.exe
del ../bin/uslist.exe

0 comments on commit 9672cb7

Please sign in to comment.
Something went wrong with that request. Please try again.