move strndup to libi3
This commit is contained in:
parent
78fea8e1fb
commit
9eda7fb6fb
|
@ -74,30 +74,6 @@ Display *dpy;
|
||||||
char *rewrite_binding(const char *bindingline);
|
char *rewrite_binding(const char *bindingline);
|
||||||
static void finish();
|
static void finish();
|
||||||
|
|
||||||
#if defined(__APPLE__)
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Taken from FreeBSD
|
|
||||||
* Returns a pointer to a new string which is a duplicate of the
|
|
||||||
* string, but only copies at most n characters.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
char *strndup(const char *str, size_t n) {
|
|
||||||
size_t len;
|
|
||||||
char *copy;
|
|
||||||
|
|
||||||
for (len = 0; len < n && str[len]; len++)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if ((copy = malloc(len + 1)) == NULL)
|
|
||||||
return (NULL);
|
|
||||||
memcpy(copy, str, len);
|
|
||||||
copy[len] = '\0';
|
|
||||||
return (copy);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This function resolves ~ in pathnames.
|
* This function resolves ~ in pathnames.
|
||||||
* It may resolve wildcards in the first part of the path, but if no match
|
* It may resolve wildcards in the first part of the path, but if no match
|
||||||
|
|
|
@ -36,29 +36,6 @@
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "libi3.h"
|
#include "libi3.h"
|
||||||
|
|
||||||
#if defined(__APPLE__)
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Taken from FreeBSD
|
|
||||||
* Returns a pointer to a new string which is a duplicate of the
|
|
||||||
* string, but only copies at most n characters.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
char *strndup(const char *str, size_t n) {
|
|
||||||
size_t len;
|
|
||||||
char *copy;
|
|
||||||
|
|
||||||
for (len = 0; len < n && str[len]; len++)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
copy = smalloc(len + 1);
|
|
||||||
memcpy(copy, str, len);
|
|
||||||
copy[len] = '\0';
|
|
||||||
return (copy);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* We save the Atoms in an easy to access array, indexed by an enum */
|
/* We save the Atoms in an easy to access array, indexed by an enum */
|
||||||
enum {
|
enum {
|
||||||
#define ATOM_DO(name) name,
|
#define ATOM_DO(name) name,
|
||||||
|
|
|
@ -109,4 +109,16 @@ void fake_configure_notify(xcb_connection_t *conn, xcb_rectangle_t r, xcb_window
|
||||||
*/
|
*/
|
||||||
uint32_t get_colorpixel(const char *hex) __attribute__((const));
|
uint32_t get_colorpixel(const char *hex) __attribute__((const));
|
||||||
|
|
||||||
|
#if defined(__APPLE__)
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Taken from FreeBSD
|
||||||
|
* Returns a pointer to a new string which is a duplicate of the
|
||||||
|
* string, but only copies at most n characters.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
char *strndup(const char *str, size_t n);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -139,16 +139,4 @@ void *memmem(const void *l, size_t l_len, const void *s, size_t s_len);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(__APPLE__)
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Taken from FreeBSD
|
|
||||||
* Returns a pointer to a new string which is a duplicate of the
|
|
||||||
* string, but only copies at most n characters.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
char *strndup(const char *str, size_t n);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -0,0 +1,37 @@
|
||||||
|
/*
|
||||||
|
* vim:ts=4:sw=4:expandtab
|
||||||
|
*
|
||||||
|
* i3 - an improved dynamic tiling window manager
|
||||||
|
*
|
||||||
|
* © 2009-2011 Michael Stapelberg and contributors
|
||||||
|
*
|
||||||
|
* See file LICENSE for license information.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "libi3.h"
|
||||||
|
|
||||||
|
#if defined(__APPLE__)
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Taken from FreeBSD
|
||||||
|
* Returns a pointer to a new string which is a duplicate of the
|
||||||
|
* string, but only copies at most n characters.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
char *strndup(const char *str, size_t n) {
|
||||||
|
size_t len;
|
||||||
|
char *copy;
|
||||||
|
|
||||||
|
for (len = 0; len < n && str[len]; len++)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
copy = smalloc(len + 1);
|
||||||
|
memcpy(copy, str, len);
|
||||||
|
copy[len] = '\0';
|
||||||
|
return (copy);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
24
src/util.c
24
src/util.c
|
@ -415,27 +415,3 @@ void *memmem(const void *l, size_t l_len, const void *s, size_t s_len) {
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(__APPLE__)
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Taken from FreeBSD
|
|
||||||
* Returns a pointer to a new string which is a duplicate of the
|
|
||||||
* string, but only copies at most n characters.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
char *strndup(const char *str, size_t n) {
|
|
||||||
size_t len;
|
|
||||||
char *copy;
|
|
||||||
|
|
||||||
for (len = 0; len < n && str[len]; len++)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if ((copy = malloc(len + 1)) == NULL)
|
|
||||||
return (NULL);
|
|
||||||
memcpy(copy, str, len);
|
|
||||||
copy[len] = '\0';
|
|
||||||
return (copy);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
Loading…
Reference in New Issue