2
2
* libkmod - interface to kernel module operations
4
* Copyright (C) 2011-2012 ProFUSION embedded systems
4
* Copyright (C) 2011-2013 ProFUSION embedded systems
5
* Copyright (C) 2012 Lucas De Marchi <lucas.de.marchi@gmail.com>
6
* Copyright (C) 2013 Intel Corporation. All rights reserved.
6
8
* This library is free software; you can redistribute it and/or
7
9
* modify it under the terms of the GNU Lesser General Public
313
static inline int is_dir(const char *path)
317
if (stat(path, &st) >= 0)
318
return S_ISDIR(st.st_mode);
323
int mkdir_p(const char *path, int len, mode_t mode)
327
start = strndupa(path, len);
331
* scan backwards, replacing '/' with '\0' while the component doesn't
335
int r = is_dir(start);
339
if (end == start + len)
342
/* end != start, since it would be caught on the first
354
/* Find the next component, backwards, discarding extra '/'*/
355
while (end > start && *end != '/')
358
while (end > start && *(end - 1) == '/')
362
for (; end < start + len;) {
363
if (mkdir(start, mode) < 0 && errno != EEXIST)
373
int mkdir_parents(const char *path, mode_t mode)
375
char *end = strrchr(path, '/');
377
/* no parent directories */
381
return mkdir_p(path, end - path, mode);
384
const struct kmod_ext kmod_exts[] = {
385
{".ko", sizeof(".ko") - 1},
387
{".ko.gz", sizeof(".ko.gz") - 1},
390
{".ko.xz", sizeof(".ko.xz") - 1},
395
bool path_ends_with_kmod_ext(const char *path, size_t len)
397
const struct kmod_ext *eitr;
399
for (eitr = kmod_exts; eitr->ext != NULL; eitr++) {
400
if (len <= eitr->len)
402
if (streq(path + len - eitr->len, eitr->ext))
311
409
#define USEC_PER_SEC 1000000ULL
312
410
#define NSEC_PER_USEC 1000ULL
313
411
unsigned long long ts_usec(const struct timespec *ts)