cleanup specfile for packaging
[profile/ivi/alsa-lib.git] / src / userfile.c
1 /*
2  *  Get full filename
3  *  Copyright (c) 2003 by Jaroslav Kysela <perex@perex.cz>
4  *
5  *   This library is free software; you can redistribute it and/or modify
6  *   it under the terms of the GNU Lesser General Public License as
7  *   published by the Free Software Foundation; either version 2.1 of
8  *   the License, or (at your option) any later version.
9  *
10  *   This program is distributed in the hope that it will be useful,
11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  *   GNU Lesser General Public License for more details.
14  *
15  *   You should have received a copy of the GNU Lesser General Public
16  *   License along with this library; if not, write to the Free Software
17  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
18  *
19  */
20   
21 #include <config.h>
22 #include <string.h>
23 #include <errno.h>
24
25 /**
26  * \brief Get the full file name
27  * \param file The file name string to parse
28  * \param result The pointer to store the resultant file name
29  * \return 0 if successful, or a negative error code
30  *
31  * Parses the given file name with POSIX-Shell-like expansion and
32  * stores the first matchine one.  The returned string is strdup'ed.
33  */
34
35 #ifdef HAVE_WORDEXP_H
36 #include <wordexp.h>
37 #include <assert.h>
38 int snd_user_file(const char *file, char **result)
39 {
40         wordexp_t we;
41         int err;
42         
43         assert(file && result);
44         err = wordexp(file, &we, WRDE_NOCMD);
45         switch (err) {
46         case WRDE_NOSPACE:
47                 return -ENOMEM;
48         case 0:
49                 if (we.we_wordc == 1)
50                         break;
51                 /* fall thru */
52         default:
53                 wordfree(&we);
54                 return -EINVAL;
55         }
56         *result = strdup(we.we_wordv[0]);
57         if (*result == NULL)
58                 return -ENOMEM;
59         wordfree(&we);
60         return 0;
61 }
62
63 #else /* !HAVE_WORDEXP_H */
64 /* just copy the string - would be nicer to expand by ourselves, though... */
65 int snd_user_file(const char *file, char **result)
66 {
67         *result = strdup(file);
68         if (! *result)
69                 return -ENOMEM;
70         return 0;
71 }
72 #endif /* HAVE_WORDEXP_H */