Thread: POSIX library is not being used

  1. #1
    Registered User redruby147's Avatar
    Join Date
    Sep 2008
    Location
    England
    Posts
    37

    POSIX library is not being used

    Hi all, I'm trying to change directory using

    Code:
    int chdir(char *directory);
    However GCC gives me the error

    Code:
    $ gcc grabber.c -o grabber
    grabber.c: In function ‘main’:
    grabber.c:19: error: conflicting types for ‘chdir’
    /usr/include/unistd.h:457: error: previous declaration of ‘chdir’ was here
    I checked it out with splint and it complained i'm not using the POSIX library, and i basically installed gcc, libraries etc with the debian build-essential package. Here's the splint response

    http://redruby.pastebin.com/m5f1468dd

    Can anyone shed any light on this, as im confused and not sure what to do. Thanks

  2. #2
    ... kermit's Avatar
    Join Date
    Jan 2003
    Posts
    1,534
    How about posting the code here?

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Looks to me like you tried to prototype it again (and it complained), rather than try to call it.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Registered User redruby147's Avatar
    Join Date
    Sep 2008
    Location
    England
    Posts
    37
    Sure, here is the code:

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <unistd.h>
    
    int main ()
    {
    
        FILE *log;
        char *directory;
        register int fir, sec, thi;
        fir = sec = 0;
        thi = 1;
        char url[59];
        log = fopen("log","w");
            
        if (!log)    {
                printf("log file can not be created; please specify different directory\n");
                scanf("%s", &directory);
                int chdir(char *directory);
                log = fopen("log","w");
            }
        
                    
            while (thi <= 9)
                { 
                    
                    sprintf(url,"wget http://blackboardurl/lectures/%d%d%d.ppt",fir,sec, thi);
                    system(url);
                    thi++;
                    
                    if (thi == 10)
                        {    
                            thi = 0;
                            sec++;
                        
                        }    
                    if (sec == 10)
                        {    
                            sec = 0;
                            fir++;
                        }    
                }
    
    
        return 0;
    
    }
    Hope this helps, thanks

  5. #5
    ... kermit's Avatar
    Join Date
    Jan 2003
    Posts
    1,534
    Code:
    int chdir(char *directory);
    It is as Salem said. You are re-declaring the function. See here for a basic example of how to call the chdir function.

    Also change this from

    Code:
    scanf("%s", &directory);
    to

    Code:
    scanf("%s", directory);
    Last edited by kermit; 01-07-2009 at 08:42 PM.

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > char *directory;
    And then you need to allocate some space for your string as well.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. What's an import library?
    By chiefmonkey in forum C++ Programming
    Replies: 1
    Last Post: 06-19-2009, 05:00 PM
  2. Property Set Library (PSL) - Announcement
    By vultur_gryphus in forum Projects and Job Recruitment
    Replies: 0
    Last Post: 05-29-2008, 06:04 AM
  3. Makefile for a library
    By sirmoreno in forum Linux Programming
    Replies: 5
    Last Post: 06-04-2006, 04:52 AM
  4. very weird .h problem
    By royuco77 in forum C++ Programming
    Replies: 1
    Last Post: 09-11-2005, 07:55 AM
  5. better c string functions
    By samps005 in forum C Programming
    Replies: 8
    Last Post: 11-04-2003, 01:28 PM