Fix unused-parameter warnings in plain C code
[ladish.git] / alsapid / helper.c
blobab209d9d3a3e9db88be46abe4646338d07ba3d52
1 /* -*- Mode: C ; c-basic-offset: 2 -*- */
2 /*
3 * LADI Session Handler (ladish)
5 * Copyright (C) 2010, 2011 Nedko Arnaudov <nedko@arnaudov.name>
7 **************************************************************************
8 * This file contains alsapid helper functionality
9 **************************************************************************
11 * LADI Session Handler is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * LADI Session Handler is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with LADI Session Handler. If not, see <http://www.gnu.org/licenses/>
23 * or write to the Free Software Foundation, Inc.,
24 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
27 #include "alsapid.h"
29 #include <string.h> /* GNU basename() */
31 #include <stdio.h>
32 #include <stdlib.h> /* atoll */
33 #include <unistd.h>
34 #include <sys/types.h>
36 void alsapid_compose_src_link(int alsa_client_id, char * buffer)
38 sprintf(buffer, "/tmp/alsapid-%lld-%d", (long long)getuid(), alsa_client_id);
41 void alsapid_compose_dst_link(char * buffer)
43 sprintf(buffer, "/proc/%lld", (long long)getpid());
46 bool alsapid_get_pid(int alsa_client_id, pid_t * pid_ptr)
48 char src[MAX_ALSAPID_PATH];
49 char dst[MAX_ALSAPID_PATH + 1];
50 ssize_t ret;
51 pid_t pid;
53 alsapid_compose_src_link(alsa_client_id, src);
55 ret = readlink(src, dst, MAX_ALSAPID_PATH);
56 if (ret == -1)
58 return false;
61 dst[ret] = 0;
63 pid = (pid_t)atoll(basename(dst));
64 if (pid <= 1)
66 return false;
69 *pid_ptr = pid;
70 return true;