medfall

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit f4904c87c179b877ced4fd2e8a94f93c70b22b00
parent 44d94742e1af707dddc6b14204140c1bbca07995
Author: Michael Savage <mikejsavage@gmail.com>
Date:   Fri Oct 14 19:41:15 +0300

Fix str on Windows

Diffstat:
Makefile | 2+-
str.h | 4++--
strlcpy.cc | 49+++++++++++++++++++++++++++++++++++++++++++++++++
strlcpy.h | 6++++++
4 files changed, 58 insertions(+), 3 deletions(-)
diff --git a/Makefile b/Makefile @@ -20,7 +20,7 @@ test_lockfree: relacy.cc $(CXX) relacy.cc -o test_lockfree $(CXXFLAGS) $(LDFLAGS) -std=c++98 -fexceptions -frtti -Wno-missing-field-initializers # Common dependencies -COMMON_OBJS := log.o memory_arena.o work_queue.o immediate.o benchmark.o stb_truetype.o glsl.o +COMMON_OBJS := log.o memory_arena.o work_queue.o immediate.o benchmark.o stb_truetype.o glsl.o strlcpy.o # Compiler flags WARNINGS := -Wall -Wextra -Wno-unused-parameter -Wno-unused-function -Wconversion -Wshadow -Wcast-align -Wstrict-overflow diff --git a/str.h b/str.h @@ -2,10 +2,10 @@ #define _STR_H_ #include <stdio.h> +#include <stdlib.h> #include <stdarg.h> -#include <bsd/string.h> -#include "intrinsics.h" +#include "strlcpy.h" template< size_t N > class str { diff --git a/strlcpy.cc b/strlcpy.cc @@ -0,0 +1,49 @@ +/* $OpenBSD: strlcpy.c,v 1.13 2015/08/31 02:53:57 guenther Exp $ */ + +/* + * Copyright (c) 1998, 2015 Todd C. Miller <Todd.Miller@courtesan.com> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <stdlib.h> + +/* + * Copy string src to buffer dst of size dsize. At most dsize-1 + * chars will be copied. Always NUL terminates (unless dsize == 0). + * Returns strlen(src); if retval >= dsize, truncation occurred. + */ +size_t +strlcpy(char *dst, const char *src, size_t dsize) +{ + const char *osrc = src; + size_t nleft = dsize; + + /* Copy as many bytes as will fit. */ + if (nleft != 0) { + while (--nleft != 0) { + if ((*dst++ = *src++) == '\0') + break; + } + } + + /* Not enough room in dst, add NUL and traverse rest of src. */ + if (nleft == 0) { + if (dsize != 0) + *dst = '\0'; /* NUL-terminate dst */ + while (*src++) + ; + } + + return(src - osrc - 1); /* count does not include NUL */ +} diff --git a/strlcpy.h b/strlcpy.h @@ -0,0 +1,6 @@ +#ifndef _STRLCPY_H_ +#define _STRLCPY_H_ + +size_t strlcpy( char * dst, const char * src, size_t dsize ); + +#endif // _STRLCPY_H_