[common] remove and getline and strndup usage
There is no getline() on FreeBSD, nor any strndup(). Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
parent
1b65a8acfd
commit
ef60378754
|
@ -19,7 +19,7 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* getline(), asprintf() */
|
/* asprintf() */
|
||||||
#define _GNU_SOURCE
|
#define _GNU_SOURCE
|
||||||
|
|
||||||
#define CHUNK_SIZE 4096
|
#define CHUNK_SIZE 4096
|
||||||
|
@ -607,6 +607,34 @@ handle_kpress(XKeyEvent *e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef HAVE_GETLINE
|
||||||
|
static int
|
||||||
|
getline(char ** buf, size_t* len, FILE* in)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
if (*buf) {
|
||||||
|
p_delete(buf);
|
||||||
|
(*buf) = NULL;
|
||||||
|
}
|
||||||
|
if (*len)
|
||||||
|
*len = 0;
|
||||||
|
|
||||||
|
do {
|
||||||
|
p_realloc(buf, *len + 10);
|
||||||
|
(*len) += 10;
|
||||||
|
for (i = 0; i < 10 && !feof(in); i++) {
|
||||||
|
(*buf)[*len - 10 + i] = getchar();
|
||||||
|
if ((*buf)[*len - 10 + i] == '\n' ||
|
||||||
|
(*buf)[*len - 10 + i] == '\r') {
|
||||||
|
return (*len - 10 + i + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
while(!feof(in));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/** Fill the completion by reading on stdin.
|
/** Fill the completion by reading on stdin.
|
||||||
* \return true if something has been filled up, false otherwise.
|
* \return true if something has been filled up, false otherwise.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -112,6 +112,27 @@ position_get_from_str(const char *pos)
|
||||||
return Off;
|
return Off;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** \brief safe limited strdup.
|
||||||
|
*
|
||||||
|
* Copies at most min(<tt>n-1</tt>, \c l) characters from \c src into a newly
|
||||||
|
* allocated buffer, always adding a final \c \\0, and returns that buffer.
|
||||||
|
*
|
||||||
|
* \param[in] src source string.
|
||||||
|
* \param[in] l maximum number of chars to copy.
|
||||||
|
*
|
||||||
|
* \return a newly allocated buffer containing the first \c l chars of \c src.
|
||||||
|
*/
|
||||||
|
char* a_strndup(const char* src, ssize_t l)
|
||||||
|
{
|
||||||
|
char* _tmpStr = p_new(char, l + 1);
|
||||||
|
if (_tmpStr)
|
||||||
|
{
|
||||||
|
a_strncpy(_tmpStr, l + 1, src, l);
|
||||||
|
_tmpStr[l] = 0;
|
||||||
|
}
|
||||||
|
return _tmpStr;
|
||||||
|
}
|
||||||
|
|
||||||
/** \brief safe limited strcpy.
|
/** \brief safe limited strcpy.
|
||||||
*
|
*
|
||||||
* Copies at most min(<tt>n-1</tt>, \c l) characters from \c src into \c dst,
|
* Copies at most min(<tt>n-1</tt>, \c l) characters from \c src into \c dst,
|
||||||
|
|
|
@ -202,6 +202,7 @@ static inline int a_strncmp(const char *a, const char *b, ssize_t n)
|
||||||
|
|
||||||
ssize_t a_strncpy(char *dst, ssize_t n, const char *src, ssize_t l) __attribute__((nonnull(1)));
|
ssize_t a_strncpy(char *dst, ssize_t n, const char *src, ssize_t l) __attribute__((nonnull(1)));
|
||||||
ssize_t a_strcpy(char *dst, ssize_t n, const char *src) __attribute__((nonnull(1)));
|
ssize_t a_strcpy(char *dst, ssize_t n, const char *src) __attribute__((nonnull(1)));
|
||||||
|
char* a_strndup(const char *src, ssize_t l) __attribute__((nonnull(1)));
|
||||||
|
|
||||||
/** \brief safe strcat.
|
/** \brief safe strcat.
|
||||||
*
|
*
|
||||||
|
|
|
@ -146,7 +146,7 @@ AC_FUNC_REALLOC
|
||||||
AC_FUNC_SELECT_ARGTYPES
|
AC_FUNC_SELECT_ARGTYPES
|
||||||
AC_TYPE_SIGNAL
|
AC_TYPE_SIGNAL
|
||||||
AC_FUNC_VPRINTF
|
AC_FUNC_VPRINTF
|
||||||
AC_CHECK_FUNCS([memchr regcomp select setenv socket strchr strrchr strstr])
|
AC_CHECK_FUNCS([getline memchr regcomp select setenv socket strchr strrchr strstr])
|
||||||
|
|
||||||
AC_CONFIG_FILES([Makefile])
|
AC_CONFIG_FILES([Makefile])
|
||||||
AC_CONFIG_FILES([awesome.doxygen])
|
AC_CONFIG_FILES([awesome.doxygen])
|
||||||
|
|
7
uicb.c
7
uicb.c
|
@ -23,9 +23,6 @@
|
||||||
* @defgroup ui_callback User Interface Callbacks
|
* @defgroup ui_callback User Interface Callbacks
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* strndup() */
|
|
||||||
#define _GNU_SOURCE
|
|
||||||
|
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
@ -83,9 +80,9 @@ uicb_exec(int screen __attribute__ ((unused)), char *cmd)
|
||||||
args = strchr(cmd, ' ');
|
args = strchr(cmd, ' ');
|
||||||
|
|
||||||
if(args)
|
if(args)
|
||||||
path = strndup(cmd, args - cmd);
|
path = a_strndup(cmd, args - cmd);
|
||||||
else
|
else
|
||||||
path = strndup(cmd, a_strlen(cmd));
|
path = a_strndup(cmd, a_strlen(cmd));
|
||||||
|
|
||||||
execlp(path, cmd, NULL);
|
execlp(path, cmd, NULL);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue