Skip to content

Commit 7ca8167

Browse files
committed
Handle err.h functions on windows
1 parent 42c50e3 commit 7ca8167

File tree

2 files changed

+47
-4
lines changed

2 files changed

+47
-4
lines changed

CMakeLists.txt

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,24 @@ INCLUDE_DIRECTORIES(${TTIP_INCLUDE_DIRS})
1414

1515
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra")
1616

17-
IF(NOT WIN32)
18-
ADD_DEFINITIONS(-DHAVE_FORK)
19-
ENDIF(NOT WIN32)
20-
2117
ADD_DEFINITIONS(-std=c99)
2218

19+
INCLUDE(CheckFunctionExists)
20+
INCLUDE(CheckIncludeFile)
21+
22+
CHECK_FUNCTION_EXISTS(fork HAVE_FORK)
23+
CHECK_INCLUDE_FILE(err.h HAVE_ERR_H)
24+
25+
IF(HAVE_FORK)
26+
ADD_DEFINITIONS(-DHAVE_FORK)
27+
ENDIF(HAVE_FORK)
28+
IF(NOT HAVE_ERR_H)
29+
INCLUDE_DIRECTORIES(compat) # err.h compatibility for windows/mingw
30+
ENDIF(NOT HAVE_ERR_H)
31+
IF(WIN32)
32+
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -mconsole")
33+
ENDIF(WIN32)
34+
2335
# sources
2436
SET(TILETOOL_SRCS
2537
tiletool/bounds.c

compat/err.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Copyright (C) 2012 Dmitry Marakasov
3+
*
4+
* This file is part of tiletool.
5+
*
6+
* tiletool is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* tiletool is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with tiletool. If not, see <http://www.gnu.org/licenses/>.
18+
*/
19+
20+
#ifndef COMPAT_ERR_H
21+
#define COMPAT_ERR_H
22+
23+
#include <stdio.h>
24+
#include <stdlib.h>
25+
26+
#define warn(...) do { fprintf(stderr, __VA_ARGS__); fprintf(stderr, ": %s\n", strerror(errno)); } while (0)
27+
#define warnx(...) do { fprintf(stderr, __VA_ARGS__); fprintf(stderr, "\n"); } while (0)
28+
#define err(eval, ...) do { fprintf(stderr, __VA_ARGS__); fprintf(stderr, ": %s\n", strerror(errno)); exit(eval); } while (0)
29+
#define errx(eval, ...) do { fprintf(stderr, __VA_ARGS__); fprintf(stderr, "\n"); exit(eval); } while (0)
30+
31+
#endif

0 commit comments

Comments
 (0)