ustctl cli rewrite
[lttng-ust.git] / ustctl / scanning_functions.c
1 /* Copyright (C) 2011 Ericsson AB, Nils Carlson <nils.carlson@ericsson.com>
2 *
3 * This library is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU Lesser General Public
5 * License as published by the Free Software Foundation; either
6 * version 2.1 of the License, or (at your option) any later version.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with this library; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16 */
17
18 #define _GNU_SOURCE
19 #include <stdio.h>
20 #include <ust/ustcmd.h>
21 #include "usterr.h"
22
23
24 pid_t parse_pid(const char *pid_string)
25 {
26 pid_t pid;
27
28 errno = 0;
29 pid = strtoull(pid_string, NULL, 10);
30 if (errno) {
31 perror("Failed to parse pid");
32 exit(EXIT_FAILURE);
33 }
34
35 return pid;
36 }
37
38 int scan_ch_marker(const char *channel_marker, char **channel, char **marker)
39 {
40 int result;
41
42 *channel = NULL;
43 *marker = NULL;
44
45 result = sscanf(channel_marker, "%a[^/]/%as", channel, marker);
46 if (result != 2) {
47 if (errno) {
48 PERROR("Failed to read channel and marker names");
49 } else {
50 ERR("Failed to parse marker and channel names");
51 }
52 if (*channel) {
53 free(*channel);
54 }
55 if (*marker) {
56 free(*marker);
57 }
58 return -1;
59 }
60
61 return 0;
62 }
63
64 int scan_ch_and_num(const char *ch_num, char **channel, unsigned int *num)
65 {
66 int result;
67
68 *channel = NULL;
69
70 result = sscanf(ch_num, "%a[^/]/%u", channel, num);
71 if (result != 2) {
72 if (errno) {
73 PERROR("Failed to parse channel and number");
74 } else {
75 ERR("Failed to parse channel and number");
76 }
77 if (*channel) {
78 free(*channel);
79 }
80 return -1;
81 }
82
83 return 0;
84 }
This page took 0.033153 seconds and 5 git commands to generate.