Another project, another bump in the road and another chance to learn. I've been trying to open gzipped files and parse data from them and hit a snag. I have data in gzips with a place followed by an ip or ip range sort of like this:
I was able to modify some code I found that works fine for parsing the data to only show the ips:
Result:
However, when I add it to the code I have for opening the gzips and reading them I get a segmentation fault. Here is the code I am trying to work from now:
I tried to look at this with strace and it seems to die directly after reading the first line. Any thoughts appreciated.
I have data that looks like this
aaa!bbb!ccc/ddd/eee
It is not fixed format. I need to parse ddd into a var in order to decide if I want to process that row. If I do I need to put ccc and bbb into vars to process it. I need to do this during a while loop one record at a time. Any... (11 Replies)
i am trying to use the history functions in a c++ program along with a custom signal handler for SIGINT.
the prog works fine catching signals without the line:
add_history(*args);
but as soon as this line is added, the prog segfaults on SIGINT.
does anyone have experience using gnu... (2 Replies)
Hello, sorry if this has been posted before but i was wondering if there is a way to run a program until a segmentation fault is found.
Currently i'm using a simple shell script which runs my program 100 times, sleeps 1 second because srand(time(0)) is dependent on seconds. Is there a possible... (1 Reply)
We have a Solaris 8 server which users login to via VNC to get a desktop. On that desktop these users use Netscape Communicator 4.9 to access a very important mail account. Unfortunately Netscape has started segfaulting regularly.
Does anyone have any ideas how I can try to find out what point... (1 Reply)
1. Even if i have the handles for ctrl+c it gives off a segfault
2. syslog doesn't log LOG_ERR event with log masked specified or non specified, it logs LOG_WARNING however...
#include <sys/types.h> /* include this before any other sys headers */
#include <sys/stat.h>
#include <fcntl.h>... (2 Replies)
Hello everyone,
I'm writing a program using the id3lib unfortunately I've encountered with memory issue that cause segmentation fault. I tried to rerun and analyze the program with valgrind but it doesn't point me anywhere. I really stuck on this one.
Valgrind output:
==14716== Invalid read of... (2 Replies)
I have a program that allows users to specify the debug log file location and name.
I have tried using the access() and stat() but they both segfault if the drive say (d:\) is invalid. Both seem to be fine if the drive exists.
Could someone please point me in the direction to a function that... (1 Reply)
hello all,
my question is not about How code can be rewritten, i just wanna know even though i am not using read only memory of C (i have declared str) why this function gives me segfault :wall:and the other code executes comfortably though both code uses same pointer arithmetic.
... (4 Replies)
I am populating an array of string and print it.
But it going in infinite loop and causing segfault.
char Name = {
"yahoo",
"rediff",
"facebook",
NULL
};
main(int argc, char* argv)
{
int j = 0;
... (7 Replies)
Hello:
I have some text output, on SunOS 5.11 platform using KSH:
I am trying to parse out each string within the () for each line.
I tried, as example:
perl -lanF"" -e 'print "$F $F $F $F $F $F"'
But for some reason, the output gets all garbled after the the first fields.... (8 Replies)
Discussion started by: gilgamesh
8 Replies
LEARN ABOUT NETBSD
shquotev
SHQUOTE(3) BSD Library Functions Manual SHQUOTE(3)NAME
shquote, shquotev -- quote argument strings for use with the shell
LIBRARY
Standard C Library (libc, -lc)
SYNOPSIS
#include <stdlib.h>
size_t
shquote(const char *arg, char *buf, size_t bufsize);
size_t
shquotev(int argc, char * const *argv, char *buf, size_t bufsize);
DESCRIPTION
The shquote() and shquotev() functions copy strings and transform the copies by adding shell escape and quoting characters. They are used to
encapsulate arguments to be included in command strings passed to the system() and popen() functions, so that the arguments will have the
correct values after being evaluated by the shell.
The exact method of quoting and escaping may vary, and is intended to match the conventions of the shell used by system() and popen(). It
may not match the conventions used by other shells. In this implementation, the following transformation is applied to each input string:
o it is surrounded by single quotes ('),
o any single quotes in the input are escaped by replacing them with the four-character sequence: ''', and
o extraneous pairs of single quotes (caused by multiple adjacent single quotes in the input string, or by single quotes at the begin-
ning or end of the input string) are elided.
The shquote() function transforms the string specified by its arg argument, and places the result into the memory pointed to by buf.
The shquotev() function transforms each of the argc strings specified by the array argv independently. The transformed strings are placed in
the memory pointed to by buf, separated by spaces. It does not modify the pointer array specified by argv or the strings pointed to by the
pointers in the array.
Both functions write up to bufsize - 1 characters of output into the buffer pointed to by buf, then add a NUL character to terminate the out-
put string. If bufsize is given as zero, the buf parameter is ignored and no output is written.
RETURN VALUES
The shquote() and shquotev() functions return the number of characters necessary to hold the result from operating on their input strings,
not including the terminating NUL. That is, they return the length of the string that would have been written to the output buffer, if it
were large enough. If an error occurs during processing, the value ((size_t)-1) is returned and errno is set appropriately.
EXAMPLES
The following code fragment demonstrates how you might use shquotev() to construct a command string to be used with system(). The command
uses an environment variable (which will be expanded by the shell) to determine the actual program to run. Note that the environment vari-
able may be expanded by the shell into multiple words. The first word of the expansion will be used by the shell as the name of the program
to run, and the rest will be passed as arguments to the program.
char **argv, c, *cmd;
size_t cmdlen, len, qlen;
int argc;
...
/*
* Size buffer to hold the command string, and allocate it.
* Buffer of length one given to snprintf() for portability.
*/
cmdlen = snprintf(&c, 1, "${PROG-%s} ", PROG_DEFAULT);
qlen = shquotev(argc, argv, NULL, 0);
if (qlen == (size_t)-1) {
...
}
cmdlen += qlen + 1;
cmd = malloc(cmdlen);
if (cmd == NULL) {
...
}
/* Create the command string. */
len = snprintf(cmd, cmdlen, "${PROG-%s} ", PROG_DEFAULT);
qlen = shquotev(argc, argv, cmd + len, cmdlen - len);
if (qlen == (size_t)-1) {
/* Should not ever happen. */
...
}
len += qlen;
/* "cmd" can now be passed to system(). */
The following example shows how you would implement the same functionality using the shquote() function directly.
char **argv, c, *cmd;
size_t cmdlen, len, qlen;
int argc, i;
...
/*
* Size buffer to hold the command string, and allocate it.
* Buffer of length one given to snprintf() for portability.
*/
cmdlen = snprintf(&c, 1, "${PROG-%s} ", PROG_DEFAULT);
for (i = 0; i < argc; i++) {
qlen = shquote(argv[i], NULL, 0);
if (qlen == (size_t)-1) {
...
}
cmdlen += qlen + 1;
}
cmd = malloc(cmdlen);
if (cmd == NULL) {
...
}
/* Start the command string with the env var reference. */
len = snprintf(cmd, cmdlen, "${PROG-%s} ", PROG_DEFAULT);
/* Quote all of the arguments when copying them. */
for (i = 0; i < argc; i++) {
qlen = shquote(argv[i], cmd + len, cmdlen - len);
if (qlen == (size_t)-1) {
/* Should not ever happen. */
...
}
len += qlen;
cmd[len++] = ' ';
}
cmd[--len] = '