uid-range.c revision b26fa1a2fbcfee7d03b0c8fd15ec3aa64ae70b9f
/***
This file is part of systemd.
Copyright 2014 Lennart Poettering
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
systemd 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 systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include "macro.h"
#include "uid-range.h"
#include "user-util.h"
}
static void uid_range_coalesce(UidRange **p, unsigned *n) {
unsigned i, j;
assert(p);
assert(n);
for (i = 0; i < *n; i++) {
for (j = i + 1; j < *n; j++) {
UidRange *x = (*p)+i, *y = (*p)+j;
if (*n > j+1)
(*n) --;
j--;
}
}
}
}
static int uid_range_compare(const void *a, const void *b) {
const UidRange *x = a, *y = b;
return -1;
return 1;
return -1;
return 1;
return 0;
}
bool found = false;
UidRange *x;
unsigned i;
assert(p);
assert(n);
if (nr <= 0)
return 0;
for (i = 0; i < *n; i++) {
x = (*p) + i;
found = true;
break;
}
}
if (found) {
} else {
UidRange *t;
if (!t)
return -ENOMEM;
*p = t;
x = t + ((*n) ++);
}
uid_range_coalesce(p, n);
return *n;
}
int uid_range_add_str(UidRange **p, unsigned *n, const char *s) {
const char *t;
int r;
assert(p);
assert(n);
assert(s);
t = strchr(s, '-');
if (t) {
char *b;
b = strndupa(s, t - s);
if (r < 0)
return r;
if (r < 0)
return r;
return -EINVAL;
} else {
if (r < 0)
return r;
nr = 1;
}
}
unsigned i;
assert(p);
for (i = 0; i < n; i++) {
return 1;
}
}
if (closest == UID_INVALID)
return -EBUSY;
return 1;
}
unsigned i;
assert(p);
for (i = 0; i < n; i++)
return true;
return false;
}