/[soft]/ldetect/trunk/sysfs_utils.c
ViewVC logotype

Annotation of /ldetect/trunk/sysfs_utils.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1357 - (hide annotations) (download)
Tue May 17 09:21:22 2011 UTC (12 years, 11 months ago) by dmorgan
File MIME type: text/plain
File size: 1552 byte(s)
Import  ldetect
1 dmorgan 1357 /*
2     * sysfs_utils.c
3     *
4     * System utility functions for libsysfs
5     *
6     * Copyright (C) IBM Corp. 2003-2005
7     *
8     * This library is free software; you can redistribute it and/or
9     * modify it under the terms of the GNU Lesser General Public
10     * License as published by the Free Software Foundation; either
11     * version 2.1 of the License, or (at your option) any later version.
12     *
13     * This library is distributed in the hope that it will be useful,
14     * but WITHOUT ANY WARRANTY; without even the implied warranty of
15     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16     * Lesser General Public License for more details.
17     *
18     * You should have received a copy of the GNU Lesser General Public
19     * License along with this library; if not, write to the Free Software
20     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21     *
22     */
23     #include "libsysfs.h"
24     #include "sysfs.h"
25    
26     /**
27     * sysfs_get_name_from_path: returns last name from a "/" delimited path
28     * @path: path to get name from
29     * @name: where to put name
30     * @len: size of name
31     */
32     int sysfs_get_name_from_path(const char *path, char *name, size_t len)
33     {
34     char tmp[SYSFS_PATH_MAX];
35     char *n = NULL;
36    
37     if (!path || !name || len == 0) {
38     errno = EINVAL;
39     return -1;
40     }
41     memset(tmp, 0, SYSFS_PATH_MAX);
42     safestrcpy(tmp, path);
43     n = strrchr(tmp, '/');
44     if (n == NULL) {
45     errno = EINVAL;
46     return -1;
47     }
48     if (*(n+1) == '\0') {
49     *n = '\0';
50     n = strrchr(tmp, '/');
51     if (n == NULL) {
52     errno = EINVAL;
53     return -1;
54     }
55     }
56     n++;
57     safestrcpymax(name, n, len);
58     return 0;
59     }

Properties

Name Value
svn:eol-style native

  ViewVC Help
Powered by ViewVC 1.1.30