forked from osmocom/wireshark
8a8b883450
they have LF at the end of the line on UN*X and CR/LF on Windows; hopefully this means that if a CR/LF version is checked in on Windows, the CRs will be stripped so that they show up only when checked out on Windows, not on UN*X. svn path=/trunk/; revision=11400
48 lines
615 B
C
48 lines
615 B
C
/* $Id$ */
|
|
|
|
#include <string.h>
|
|
#include <glib.h>
|
|
|
|
|
|
#include <glib-util.h>
|
|
|
|
char*
|
|
g_substrdup(const char *s, int start, int len)
|
|
{
|
|
int s_len, abs_start, abs_len;
|
|
char *newstring;
|
|
|
|
|
|
s_len = strlen(s);
|
|
|
|
if (start < 0) {
|
|
abs_start = s_len + start;
|
|
if (abs_start < 0) {
|
|
return NULL;
|
|
}
|
|
}
|
|
else {
|
|
abs_start = start;
|
|
}
|
|
|
|
if (len < 0) {
|
|
abs_len = s_len + len + 1 - abs_start;
|
|
if (abs_len < 0) {
|
|
return NULL;
|
|
}
|
|
}
|
|
else {
|
|
abs_len = len;
|
|
}
|
|
|
|
|
|
if (abs_start + abs_len > s_len) {
|
|
return NULL;
|
|
}
|
|
|
|
newstring = g_strndup(s + abs_start, abs_len + 1);
|
|
newstring[abs_len] = 0;
|
|
|
|
return newstring;
|
|
}
|