X-Git-Url: http://git.lttng.org/?a=blobdiff_plain;f=ustctl%2Fscanning_functions.c;fp=ustctl%2Fscanning_functions.c;h=0cf809e061a126ac57f6699c21d48756f7d006e1;hb=0c89df6cb75f1d967003137e7fc334af1128a42f;hp=0000000000000000000000000000000000000000;hpb=91594b712729c0d855efeab849c2093706336941;p=ust.git diff --git a/ustctl/scanning_functions.c b/ustctl/scanning_functions.c new file mode 100644 index 0000000..0cf809e --- /dev/null +++ b/ustctl/scanning_functions.c @@ -0,0 +1,84 @@ +/* Copyright (C) 2011 Ericsson AB, Nils Carlson + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#define _GNU_SOURCE +#include +#include +#include "usterr.h" + + +pid_t parse_pid(const char *pid_string) +{ + pid_t pid; + + errno = 0; + pid = strtoull(pid_string, NULL, 10); + if (errno) { + perror("Failed to parse pid"); + exit(EXIT_FAILURE); + } + + return pid; +} + +int scan_ch_marker(const char *channel_marker, char **channel, char **marker) +{ + int result; + + *channel = NULL; + *marker = NULL; + + result = sscanf(channel_marker, "%a[^/]/%as", channel, marker); + if (result != 2) { + if (errno) { + PERROR("Failed to read channel and marker names"); + } else { + ERR("Failed to parse marker and channel names"); + } + if (*channel) { + free(*channel); + } + if (*marker) { + free(*marker); + } + return -1; + } + + return 0; +} + +int scan_ch_and_num(const char *ch_num, char **channel, unsigned int *num) +{ + int result; + + *channel = NULL; + + result = sscanf(ch_num, "%a[^/]/%u", channel, num); + if (result != 2) { + if (errno) { + PERROR("Failed to parse channel and number"); + } else { + ERR("Failed to parse channel and number"); + } + if (*channel) { + free(*channel); + } + return -1; + } + + return 0; +}