Moved string-related routines from lib/util.[ch] into lib/strutil.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
Andrew Borodin 2010-11-10 22:28:42 +03:00
parent 593157d8cb
commit 43ed65e3d9
5 changed files with 40 additions and 40 deletions

View File

@ -3,6 +3,10 @@
#include "lib/global.h" /* include glib.h */
#include <sys/types.h>
#include <string.h>
#include <assert.h> /* assert() */
/* Header file for strutil.c, strutilascii.c, strutil8bit.c, strutilutf8.c.
* There are two sort of functions:
* 1. functions for working with growing strings and conversion strings between
@ -523,4 +527,37 @@ int str_verscmp (const char *s1, const char *s2);
/*** inline functions ****************************************************************************/
static inline void
str_replace (char *s, char from, char to)
{
for (; *s != '\0'; s++)
{
if (*s == from)
*s = to;
}
}
/*
* strcpy is unsafe on overlapping memory areas, so define memmove-alike
* string function.
* Have sense only when:
* * dest <= src
* AND
* * dest and str are pointers to one object (as Roland Illig pointed).
*
* We can't use str*cpy funs here:
* http://kerneltrap.org/mailarchive/openbsd-misc/2008/5/27/1951294
*/
static inline char *
str_move (char *dest, const char *src)
{
size_t n;
assert (dest <= src);
n = strlen (src) + 1; /* + '\0' */
return (char *) memmove (dest, src, n);
}
#endif /* MC_STRUTIL_H */

View File

@ -214,18 +214,6 @@ mc_util_write_backup_content (const char *from_file_name, const char *to_file_na
/*** public functions ****************************************************************************/
/* --------------------------------------------------------------------------------------------- */
extern void
str_replace (char *s, char from, char to)
{
for (; *s != '\0'; s++)
{
if (*s == from)
*s = to;
}
}
/* --------------------------------------------------------------------------------------------- */
int
is_printable (int c)
{

View File

@ -7,8 +7,6 @@
#include "lib/global.h" /* include <glib.h> */
#include <string.h>
#include <assert.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
@ -87,7 +85,6 @@ extern struct sigaction startup_handler;
/*** declarations of public functions ************************************************************/
void str_replace (char *s, char from, char to);
int is_printable (int c);
void msglen (const char *text, /*@out@ */ int *lines, /*@out@ */ int *columns);
@ -226,31 +223,6 @@ gboolean mc_util_unlink_backup_if_possible (const char *, const char *);
char *guess_message_value (void);
/*** inline functions **************************************************/
/*
* strcpy is unsafe on overlapping memory areas, so define memmove-alike
* string function.
* Have sense only when:
* * dest <= src
* AND
* * dest and str are pointers to one object (as Roland Illig pointed).
*
* We can't use str*cpy funs here:
* http://kerneltrap.org/mailarchive/openbsd-misc/2008/5/27/1951294
*/
static inline char *
str_move (char *dest, const char *src)
{
size_t n;
assert (dest <= src);
n = strlen (src) + 1; /* + '\0' */
return (char *) memmove (dest, src, n);
}
#endif /* MC_UTIL_H */

View File

@ -52,6 +52,7 @@
#include <grp.h>
#include "lib/global.h"
#include "lib/strutil.h" /* str_move() */
#include "lib/vfs/mc-vfs/vfs.h" /* VFS_ENCODING_PREFIX */
#include "src/execute.h"

View File

@ -1,6 +1,8 @@
#ifndef MC__VIEWER_INLINES_H
#define MC__VIEWER_INLINES_H
#include <assert.h>
/*** typedefs(not structures) and defined constants **********************************************/
/*** enums ***************************************************************************************/