Sponsored Content
Full Discussion: Hi! segmentation fault
Top Forums Programming Hi! segmentation fault Post 302095992 by jim mcnamara on Monday 13th of November 2006 08:05:44 AM
Old 11-13-2006
Most C compilers are going to issue errors/warnings with your code. You have some problems.

First suggestion to fix one issue - #include <limits.h>

Usually dealing with full filenames means declare your strings like this with PATH_MAX
Code:
   char mydir[PATH_MAX]={0x0};

Plus, what you're doing is far easier with ftw() - see man ftw
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Segmentation Fault

hello all, I tried a program on an array to intialise array elements from the standard input device.it is an integer array of 5 elements.but after entering the 4th element it throws a message called "Segmentation Fault" and returns to the command prompt without asking for the 5th element. ... (3 Replies)
Discussion started by: compbug
3 Replies

2. Programming

segmentation fault

ive written my code in C for implementation of a simple lexical analyser using singly linked list hence am making use of dynamic allocation,but when run in linux it gives a segmentation fault is it cause of the malloc function that ive made use of????any suggestions as to what i could do??? thank... (8 Replies)
Discussion started by: rockgal
8 Replies

3. AIX

Segmentation fault

Hi , During execution a backup binary i get following error "Program error 11 (Segmentation fault), saving core file in '/usr/datatools" Riyaz (2 Replies)
Discussion started by: rshaikh
2 Replies

4. Programming

Why not a segmentation fault??

Hi, Why I don't receive a segmentation fault in the following sample. int main(void) { char buff; sprintf(buff,"Hello world"); printf("%s\n",buff); } If I define a buffer of 10 elements and I'm trying to put inside it twelve elements, Should I receive a sigsev... (22 Replies)
Discussion started by: lagigliaivan
22 Replies

5. UNIX for Dummies Questions & Answers

Segmentation Fault

Hi, While comparing primary key data of two tables thr bteq script I am getting this Error. This script is a shell script. *** Error: The following error was encountered on the output file. Script.sh: 3043492 Segmentation fault(coredump) Please let me know how to get through it. ... (5 Replies)
Discussion started by: monika
5 Replies

6. Programming

segmentation fault

Hi, I am having this segmentation fault not in the following program, bt. in my lab program . My lab program is horrible long so cannot post it here bt. I am using the following logic in my program which is giving the segmentation fault. Bt. if I run this sample program as it is it dosen't give... (3 Replies)
Discussion started by: mind@work
3 Replies

7. Programming

Using gdb, ignore beginning segmentation fault until reproduce environment segmentation fault

I use a binary name (ie polo) it gets some parameter , so for debugging normally i do this : i wrote script for watchdog my app (polo) and check every second if it's not running then start it , the problem is , if my app , remain in state of segmentation fault for a while (ie 15 ... (6 Replies)
Discussion started by: pooyair
6 Replies

8. Homework & Coursework Questions

Segmentation Fault

this is a network programming code to run a rock paper scissors in a client and server. I completed it and it was working without any error. After I added the findWinner function to the server code it starts giving me segmentation fault. -the segmentation fault is fixed Current problem -Also... (3 Replies)
Discussion started by: femchi
3 Replies

9. Programming

Segmentation fault

I keep getting this fault on a lot of the codes I write, I'm not exactly sure why so I'd really appreciate it if someone could explain the idea to me. For example this code #include <stdio.h> main() { unsigned long a=0; unsigned long b=0; int z; { printf("Enter two... (2 Replies)
Discussion started by: sizzler786
2 Replies

10. Programming

C. To segmentation fault or not to segmentation fault, that is the question.

Oddities with gcc, 2.95.3 for the AMIGA and 4.2.1 for MY current OSX 10.14.1... I am creating a basic calculator for the AMIGA ADE *NIX emulator in C as it does not have one. Below are two very condensed snippets of which I have added the results inside the each code section. IMPORTANT!... (11 Replies)
Discussion started by: wisecracker
11 Replies
FTW(3P) 						     POSIX Programmer's Manual							   FTW(3P)

PROLOG
This manual page is part of the POSIX Programmer's Manual. The Linux implementation of this interface may differ (consult the correspond- ing Linux manual page for details of Linux behavior), or the interface may not be implemented on Linux. NAME
ftw - traverse (walk) a file tree SYNOPSIS
#include <ftw.h> int ftw(const char *path, int (*fn)(const char *, const struct stat *ptr, int flag), int ndirs); DESCRIPTION
The ftw() function shall recursively descend the directory hierarchy rooted in path. For each object in the hierarchy, ftw() shall call the function pointed to by fn, passing it a pointer to a null-terminated character string containing the name of the object, a pointer to a stat structure containing information about the object, and an integer. Possible values of the integer, defined in the <ftw.h> header, are: FTW_D For a directory. FTW_DNR For a directory that cannot be read. FTW_F For a file. FTW_SL For a symbolic link (but see also FTW_NS below). FTW_NS For an object other than a symbolic link on which stat() could not successfully be executed. If the object is a symbolic link and stat() failed, it is unspecified whether ftw() passes FTW_SL or FTW_NS to the user-supplied function. If the integer is FTW_DNR, descendants of that directory shall not be processed. If the integer is FTW_NS, the stat structure contains undefined values. An example of an object that would cause FTW_NS to be passed to the function pointed to by fn would be a file in a direc- tory with read but without execute (search) permission. The ftw() function shall visit a directory before visiting any of its descendants. The ftw() function shall use at most one file descriptor for each level in the tree. The argument ndirs should be in the range [1, {OPEN_MAX}]. The tree traversal shall continue until either the tree is exhausted, an invocation of fn returns a non-zero value, or some error, other than [EACCES], is detected within ftw(). The ndirs argument shall specify the maximum number of directory streams or file descriptors or both available for use by ftw() while traversing the tree. When ftw() returns it shall close any directory streams and file descriptors it uses not counting any opened by the application-supplied fn function. The results are unspecified if the application-supplied fn function does not preserve the current working directory. The ftw() function need not be reentrant. A function that is not required to be reentrant is not required to be thread-safe. RETURN VALUE
If the tree is exhausted, ftw() shall return 0. If the function pointed to by fn returns a non-zero value, ftw() shall stop its tree tra- versal and return whatever value was returned by the function pointed to by fn. If ftw() detects an error, it shall return -1 and set errno to indicate the error. If ftw() encounters an error other than [EACCES] (see FTW_DNR and FTW_NS above), it shall return -1 and set errno to indicate the error. The external variable errno may contain any error value that is possible when a directory is opened or when one of the stat functions is executed on a directory or file. ERRORS
The ftw() function shall fail if: EACCES Search permission is denied for any component of path or read permission is denied for path. ELOOP A loop exists in symbolic links encountered during resolution of the path argument. ENAMETOOLONG The length of the path argument exceeds {PATH_MAX} or a pathname component is longer than {NAME_MAX}. ENOENT A component of path does not name an existing file or path is an empty string. ENOTDIR A component of path is not a directory. EOVERFLOW A field in the stat structure cannot be represented correctly in the current programming environment for one or more files found in the file hierarchy. The ftw() function may fail if: EINVAL The value of the ndirs argument is invalid. ELOOP More than {SYMLOOP_MAX} symbolic links were encountered during resolution of the path argument. ENAMETOOLONG Pathname resolution of a symbolic link produced an intermediate result whose length exceeds {PATH_MAX}. In addition, if the function pointed to by fn encounters system errors, errno may be set accordingly. The following sections are informative. EXAMPLES
Walking a Directory Structure The following example walks the current directory structure, calling the fn function for every directory entry, using at most 10 file descriptors: #include <ftw.h> ... if (ftw(".", fn, 10) != 0) { perror("ftw"); exit(2); } APPLICATION USAGE
The ftw() function may allocate dynamic storage during its operation. If ftw() is forcibly terminated, such as by longjmp() or sig- longjmp() being executed by the function pointed to by fn or an interrupt routine, ftw() does not have a chance to free that storage, so it remains permanently allocated. A safe way to handle interrupts is to store the fact that an interrupt has occurred, and arrange to have the function pointed to by fn return a non-zero value at its next invocation. RATIONALE
None. FUTURE DIRECTIONS
None. SEE ALSO
longjmp(), lstat(), malloc(), nftw(), opendir(), siglongjmp(), stat(), the Base Definitions volume of IEEE Std 1003.1-2001, <ftw.h>, <sys/stat.h> COPYRIGHT
Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1, 2003 Edition, Standard for Information Technol- ogy -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html . IEEE
/The Open Group 2003 FTW(3P)
All times are GMT -4. The time now is 10:34 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy