Improve O_SYNC logic

This commit is contained in:
Moritz 'Morty' Strübe 2015-05-08 09:14:40 +02:00
parent 425c58e79d
commit 1e359d2324

View File

@ -164,8 +164,11 @@ main(int argc, char **argv)
} }
fprintf(stderr, "connecting to %s (%s)", device, speedname); fprintf(stderr, "connecting to %s (%s)", device, speedname);
#ifndef __APPLE__ #ifdef O_SYNC
fd = open(device, O_RDWR | O_NOCTTY | O_NDELAY | O_DIRECT | O_SYNC); fd = open(device, O_RDWR | O_NOCTTY | O_NDELAY | O_DIRECT | O_SYNC);
if(fd < 0 && errno == EINVAL){ // O_SYNC not supported (e.g. raspberian)
fd = open(device, O_RDWR | O_NOCTTY | O_NDELAY | O_DIRECT);
}
#else #else
fd = open(device, O_RDWR | O_NOCTTY | O_NDELAY | O_SYNC ); fd = open(device, O_RDWR | O_NOCTTY | O_NDELAY | O_SYNC );
#endif #endif