Herzlich Willkommen, lieber Gast!
  Sie befinden sich hier:

  Forum » C / C++ (GNU/Linux, *NIX, *BSD und Co) » getcwd

Forum | Hilfe | Team | Links | Impressum | > Suche < | Mitglieder | Registrieren | Einloggen
  Quicklinks: MSDN-Online || STL || clib Reference Grundlagen || Literatur || E-Books || Zubehör || > F.A.Q. < || Downloads   

Autor Thread - Seiten: > 1 <
000
12.05.2007, 18:02 Uhr
Pler
Einer von Vielen
(Operator)


Ich habe keine Ahnung was hier passiert:

Ich will einfach das aktuelle Verzeichnis abfragen. Lt. Man-page gibt es -1 "on failure" und sonst die Anzahl Bytes.
Manchmal klappt es (siehe letzte Zeile bash) und meistens nicht. Und der Wert, der zurückkommt ist -sonstwas.

mein Quellcode:

C++:
#include <stdio.h>

int main() {
        char puffer[1000];
        long ret;


        ret = getcwd(puffer, 1000);
        if(ret < 0) {
                perror("Fehler:");
                printf("ret: %d\n", ret);
        }

        puts(puffer);

        return 0;
}




bash:
[gl@werner2 tmp]$ ./versuch
Fehler:: Success
ret: -588685056
/home/gl/tmp
[gl@werner2 tmp]$ ./versuch
Fehler:: Success
ret: -2059356544
/home/gl/tmp
[gl@werner2 tmp]$ ./versuch
Fehler:: Success
ret: -2119758624
/home/gl/tmp
[gl@werner2 tmp]$ ./versuch
Fehler:: Success
ret: -547952672
/home/gl/tmp
[gl@werner2 tmp]$ ./versuch
/home/gl/tmp
[gl@werner2 tmp]$

Dieser Post wurde am 12.05.2007 um 18:02 Uhr von Pler editiert.
 
Profil || Private Message || Suche Download || Zitatantwort || Editieren || Löschen || IP
001
12.05.2007, 18:25 Uhr
Pler
Einer von Vielen
(Operator)


Ah.
Es gitb ein getcwd (2) und getcwd (3).
Damit hat es sich wohl erledigt...
 
Profil || Private Message || Suche Download || Zitatantwort || Editieren || Löschen || IP
002
12.05.2007, 23:24 Uhr
FloSoft
Medialer Over-Flow
(Administrator)


;-) du hast denke ich die 3er Variante erwischt, das liefert nämlich nen char * ;-)

(btw - bei mir gibts nur die 3er Variante)
--
class God : public ChuckNorris { };

Dieser Post wurde am 12.05.2007 um 23:25 Uhr von FloSoft editiert.
 
Profil || Private Message || Suche Download || Zitatantwort || Editieren || Löschen || IP
003
13.05.2007, 12:05 Uhr
Pler
Einer von Vielen
(Operator)


ja.

Auf den Rechnern in der Uni kommt man mit man getcwd auch direkt zum Richtigen. Nur bei mir gibts noch die andere Version. Aber da steht auch, dass es die eigentlich gar nicht gibt und man man 3 getcwd nehmen soll. Aber so genau hab ichs erst mal wieder nicht gelesen.


man:
GETCWD(2)                  Linux Programmer’s Manual                 GETCWD(2)

NAME
       getcwd - get current working directory

SYNOPSIS
       /*
        * This page documents the getcwd(2) system call, which
        * is not defined in any user-space header files; you should
        * use getcwd(3) defined in <unistd.h> instead in applications.
        */

       long getcwd(char *buf, unsigned long size);

DESCRIPTION
       The  getcwd() function copies an absolute pathname of the current work-
       ing directory to the array pointed to by buf, which is of length  size.

       If  the  current  absolute path name would require a buffer longer than
       size elements, -1 is returned, and errno is set to ERANGE; an  applica-
       tion  should check for this error, and allocate a larger buffer if nec-
       essary.

       If buf is NULL, the behaviour of getcwd() is undefined.

RETURN VALUE
       -1 on failure (for example, if the current directory is not  readable),
       with  errno set accordingly, and the number of characters stored in buf
       on success. The contents of the array pointed to by buf is undefined on
       error.

       Note  that  this  return value differs from the getcwd(3) library func-
       tion, which returns NULL on failure and the address of buf on  success.
 
Profil || Private Message || Suche Download || Zitatantwort || Editieren || Löschen || IP
004
13.05.2007, 20:25 Uhr
Pablo
Supertux
(Operator)


also, diese Funktion ist mir unbekannt (getcwd(2)), die habe ich auch nicht in meinen man pages
--
A! Elbereth Gilthoniel!
silivren penna míriel
o menel aglar elenath,
Gilthoniel, A! Elbereth!
 
Profil || Private Message || Suche Download || Zitatantwort || Editieren || Löschen || IP
005
13.05.2007, 21:15 Uhr
FloSoft
Medialer Over-Flow
(Administrator)


ja weils der priviligierte syscall ist
--
class God : public ChuckNorris { };
 
Profil || Private Message || Suche Download || Zitatantwort || Editieren || Löschen || IP
Seiten: > 1 <     [ C / C++ (GNU/Linux, *NIX, *BSD und Co) ]  


ThWBoard 2.73 FloSoft-Edition
© by Paul Baecher & Felix Gonschorek (www.thwboard.de)

Anpassungen des Forums
© by Flo-Soft (www.flo-soft.de)

Sie sind Besucher: