Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/* * Copyright (C) 2017 Barcelona Supercomputing Center
* Centro Nacional de Supercomputacion
*
* This file is part of the Data Scheduler, a daemon for tracking and managing
* requests for asynchronous data transfer in a hierarchical storage environment.
*
* See AUTHORS file in the top level directory for information
* regarding developers and contributors.
*
* The Data Scheduler is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Data Scheduler is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Data Scheduler. If not, see <http://www.gnu.org/licenses/>.
*/
#include <unistd.h>
#include <string.h>
#include "xmalloc.h"
#include "xstring.h"
char*
xstrdup(const char* str) {
size_t sz;
char* res;
if(str == NULL) {
return NULL;
}
sz = XMIN(strlen(str) + 1, XMAX_STRING_LENGTH);
res = (char*) xmalloc(sz);
strncpy(res, str, sz);
res[sz] = '\0';
return res;
}
int
xstrcnmp(const char* s1, const char* s2) {
if(s1 == NULL && s2 == NULL) {
return 0;
}
else if(s1 == NULL) {
return -1;
}
else if(s2 == NULL) {
return 1;
}
else {
size_t sz;
sz = XMIN(strlen(s1), strlen(s2));
sz = XMIN(sz, XMAX_STRING_LENGTH);
return strncmp(s1, s2, sz);
}
}