Skip to content

Commit

Permalink
platform_mkdir->mkdir: use POSIX syntax
Browse files Browse the repository at this point in the history
Use rather defined function as mkdir(3p) is, even though there is needed
a compat for MSW.

+ removed some strtok_r undef, which should no longer be needed (see
also commit 6c6253c)
  • Loading branch information
MartinPulec committed Aug 14, 2023
1 parent 0caa977 commit 21c4303
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 11 deletions.
2 changes: 0 additions & 2 deletions src/config_unix.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,6 @@ static inline void *aligned_malloc(size_t size, size_t alignment)
}
#define aligned_free free

#define platform_mkdir(a) mkdir(a, 0777)

#define INVALID_SOCKET -1
#define CLOSESOCKET close

Expand Down
7 changes: 3 additions & 4 deletions src/config_win32.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,11 +207,10 @@ void ShowMessage(int level, char *msg);
#include <sys/stat.h>
#endif

// MinGW-w64 defines some broken macro for strtok_r in pthread.h
#undef strtok_r

#ifdef WANT_MKDIR
#include <direct.h>
#define platform_mkdir _mkdir
#define mkdir(path, mode) _mkdir(path)
#endif

#define SHUT_RD SD_RECEIVE
#define SHUT_WR SD_SEND
Expand Down
7 changes: 4 additions & 3 deletions src/export.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,12 @@
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#define WANT_MKDIR
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif /* HAVE_CONFIG_H */
#include "config_unix.h"
#include "config_win32.h"
#endif /* HAVE_CONFIG_H */

#include <dirent.h>
#include <limits.h>
Expand Down Expand Up @@ -228,7 +229,7 @@ static char *create_anonymous_dir(const char *prefix)
snprintf(num, sizeof num, "-%d", i);
strncat(name, num, sizeof name - strlen(name) - 1);
}
int ret = platform_mkdir(name);
int ret = mkdir(name, S_IRWXU | S_IRWXG | S_IRWXO);
if(ret == -1) {
if(errno == EEXIST) { // record exists, try next directory
continue;
Expand Down Expand Up @@ -261,7 +262,7 @@ static bool create_dir(struct exporter *s)
if (!s->dir) {
s->dir = create_anonymous_dir(".");
} else {
int ret = platform_mkdir(s->dir);
int ret = mkdir(s->dir, S_IRWXU | S_IRWXG | S_IRWXO);
if(ret == -1) {
if(errno != EEXIST) {
perror("[Export] Directory creation failed");
Expand Down
5 changes: 3 additions & 2 deletions src/rtp/ldgm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,12 @@
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#define WANT_MKDIR
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif /* HAVE_CONFIG_H */
#include "config_unix.h"
#include "config_win32.h"
#endif /* HAVE_CONFIG_H */

#include <iomanip>
#include <iostream>
Expand Down Expand Up @@ -179,7 +180,7 @@ void ldgm::set_params(unsigned int k, unsigned int m, unsigned int c, unsigned i
snprintf(path, 256, "/var/tmp/ultragrid-%d/", (int) getuid());
#endif

res = platform_mkdir(path);
res = mkdir(path, S_IRWXU | S_IRWXG | S_IRWXO);
if(res != 0) {
if(errno != EEXIST) {
perror("mkdir");
Expand Down

0 comments on commit 21c4303

Please sign in to comment.