Skip to content

Commit

Permalink
Handle err.h functions on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
AMDmi3 committed Oct 16, 2012
1 parent 42c50e3 commit 7ca8167
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 4 deletions.
20 changes: 16 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,24 @@ INCLUDE_DIRECTORIES(${TTIP_INCLUDE_DIRS})

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

IF(NOT WIN32)
ADD_DEFINITIONS(-DHAVE_FORK)
ENDIF(NOT WIN32)

ADD_DEFINITIONS(-std=c99)

INCLUDE(CheckFunctionExists)
INCLUDE(CheckIncludeFile)

CHECK_FUNCTION_EXISTS(fork HAVE_FORK)
CHECK_INCLUDE_FILE(err.h HAVE_ERR_H)

IF(HAVE_FORK)
ADD_DEFINITIONS(-DHAVE_FORK)
ENDIF(HAVE_FORK)
IF(NOT HAVE_ERR_H)
INCLUDE_DIRECTORIES(compat) # err.h compatibility for windows/mingw
ENDIF(NOT HAVE_ERR_H)
IF(WIN32)
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -mconsole")
ENDIF(WIN32)

# sources
SET(TILETOOL_SRCS
tiletool/bounds.c
Expand Down
31 changes: 31 additions & 0 deletions compat/err.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright (C) 2012 Dmitry Marakasov
*
* This file is part of tiletool.
*
* tiletool is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* tiletool is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with tiletool. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef COMPAT_ERR_H
#define COMPAT_ERR_H

#include <stdio.h>
#include <stdlib.h>

#define warn(...) do { fprintf(stderr, __VA_ARGS__); fprintf(stderr, ": %s\n", strerror(errno)); } while (0)
#define warnx(...) do { fprintf(stderr, __VA_ARGS__); fprintf(stderr, "\n"); } while (0)
#define err(eval, ...) do { fprintf(stderr, __VA_ARGS__); fprintf(stderr, ": %s\n", strerror(errno)); exit(eval); } while (0)
#define errx(eval, ...) do { fprintf(stderr, __VA_ARGS__); fprintf(stderr, "\n"); exit(eval); } while (0)

#endif

0 comments on commit 7ca8167

Please sign in to comment.