Skip to content

Instantly share code, notes, and snippets.

@jtbr
jtbr / endianness.h
Last active October 11, 2024 19:08
cross-platform / cross-compiler standalone endianness conversion
/**
* @file endianness.h
* @brief Convert Endianness of shorts, longs, long longs, regardless of architecture/OS
*
* Defines (without pulling in platform-specific network include headers):
* bswap16, bswap32, bswap64, ntoh16, hton16, ntoh32 hton32, ntoh64, hton64
*
* Should support linux / macos / solaris / windows.
* Supports GCC (on any platform, including embedded), MSVC2015, and clang,
* and should support intel, solaris, and ibm compilers as well.
@jtbr
jtbr / exe_dir.h
Created June 1, 2018 11:22
Find the path to (directory containing) the currently running executable (cross-platform C++ function)
#ifndef __EXE_DIR_H__
#define __EXE_DIR_H__
#include <string>
#include <boost/predef/os.h>
#if (BOOST_OS_WINDOWS)
# include <stdlib.h>
#elif (BOOST_OS_SOLARIS)
# include <stdlib.h>