|
Dernière réponse | ||
---|---|---|
Sujet : probleme bizarre en C aussi ;) | ||
godbout |
|
Aperçu |
---|
Vue Rapide de la discussion |
---|
godbout |
|
gilou |
|
godbout | ok merci :) |
BENB |
[edtdd]--Message édité par BENB--[/edtdd] |
godbout | ou alors je la met en global ?
Mais alors la j'ai plus besoin de le mettre dans la fonction ! J'suis paume sur le coup la :( |
godbout | Tu pourrais m'expliquer comment je pourrais faire avec FindPath1(chemin, "Product Databases" ); ?
Parce que je remplis bien a l'interieur de la fonction le path, mais chemin est toujours egal a vide. |
gilou | Non, ce que je te dis, c'est que chemin = FindPath("Product databases" ); remplace le buffer alloue par ce qui est pointe en retour de ta fonction.
Soit tu as une fonction FindPath1(chemin, "Product databases" ); qui va remplir chemin, soit tu fais strcpy(chemin,FindPath("Product databases" )); afin de copier le resultat de findpath dans le buffer que tu as alloue. A+, |
godbout | Pour le ControlMAJ c'est parce que j'ai rajoute un arg, mais t'inquiete ca n'a rien a voir.
Je crois en effet aussi que l'allocation est perdu au niveau du passage d'argument. Je sais pas pourquoi. Ce que je pense faire c'est recree un char*, allouer, et copier l'argument dedans. Je crois que c'est la seule solution. |
gilou |
|
godbout | Ben voila ce que j'ai a l'appel de la fonction:
chemin = (char *)malloc(128*sizeof(char *)); strcpy(chemin, "" ); chemin = FindPath("Product databases" ); ControlMAJ(chemin, "\\Test" ); Donc j'ai bien fait un malloc de 128, ca suffit, mais dans la fonction je fais pas de malloc, parce que si j'en fait un il me vire ce que contient ma variable. |
gilou | Je peux pas dire a priori pourquoi access se comporte ainsi, mais a vue de nez, tes strcat sont dangereux: as tu assez de place allouee dans catalog? A+, |
godbout | Il ne la modifie pas puisque si je lui donne un argument qui n'est pas argument dans ma fonction, alors il ne change rien.
D'ailleurs y a un truc assez etrange: fileexist = access(catalogue, 0); Si je fais ca catalogue ressort avec "" strcpy(cattemp, catalogue); fileexist = access(catalogue, 0); strcpy(catalogue, cattemp); La aussi catalogue ressort avec "", mais je lui remet sa valeur apres. strcpy(cattemp, catalogue); fileexist = access(cattemp, 0); strcpy(catalogue, cattemp); Par contre la aussi, c'est bien catalogue qui ressort avec "", alors que cattemp n'a pas bouge :??: La je ne suis plus. J'ai eu les meme pb avec la fonction PathIsDirectory |
BENB | access(2) access(2)
NAME access - determine accessibility of a file SYNOPSIS #include <unistd.h> int access(char *path, int amode); DESCRIPTION The access() system call checks the file pointed to by path for accessibility according to the bit pattern contained in amode. access() uses the real user ID, not the effective user ID, and the real group ID, not the effective group ID. The value of amode is either the bit-wise inclusive OR of the access permissions to be checked, or the existence test. You can use the following symbolic constants, defined in <unistd.h>, to test for permissions: R_OK Read access W_OK Write access X_OK Execute (search) access F_OK Check existence of file The owner of a file has permission checked with respect to the "user" read, write, and execute mode bits. Members of the file's group other than the owner have permissions checked with respect to the "group" mode bits. All others have permissions checked with respect to the "other" mode bits. If a file is currently open for execution, access() reports that it is not writable, regardless of the setting of its mode. Access Control Lists - HFS File Systems Only Read, write, and execute/search permissions are checked against the file's access control list (ACL). Each mode is checked separately since different ACL entries can grant different permissions. The real user ID is combined with the process's real group ID and each group in its supplementary groups list, and the access control list is searched for a match. Search proceeds in order of specificity and ends when one or more matching entries are found at a specific level. More than one user.group or %.group entry can match a user if that user has a nonnull supplementary groups list. If any matching entry has the appropriate permission bit set, access is permitted. If a shared text file is currently open for execution, access() reports that it is not writable, regardless of its access control list. However, access() does not report that a shared text file open for writing is not executable, since the check is not easily done. Hewlett-Packard Company - 1 - HP-UX Release 11.00: October 1997 access(2) access(2) It also reports that a file on a read-only file system is not writable. RETURN VALUE access() returns the following values: 0 Successful completion. The requested access is permitted. If the path is valid and the real user ID is superuser, access() always returns 0, except when amode includes X_OK, the path is not a directory, and none of the execute bits are set in the file's mode. -1 Failure. errno is set to indicate the error. ERRORS If access() fails, errno is set to one of the following values. [EACCES] Search permission is denied on a component of the path prefix. [EACCES] The access control list does not permit the requested access and the real user ID is not a user with appropriate privileges. [EFAULT] path points outside the allocated address space for the process. The reliable detection of this error is implementation dependent. [ELOOP] Too many symbolic links were encountered in translating the path name. [ENAMETOOLONG] The length of the specified path name exceeds PATH_MAX bytes, or the length of a component of the path name exceeds NAME_MAX bytes while _POSIX_NO_TRUNC is in effect. [ENOENT] Read, write, or execute (search) permission is requested for a null path name. [ENOENT] The named file does not exist. [ENOTDIR] A component of the path prefix is not a directory. [EROFS] Write access is requested for a file on a read- only file system. [ETXTBSY] Write access is requested for a pure procedure (shared text) file that is being executed. Hewlett-Packard Company - 2 - HP-UX Release 11.00: October 1997 access(2) access(2) SEE ALSO chmod(2), stat(2), setacl(2), acl(5), unistd(5). STANDARDS CONFORMANCE access(): AES, SVID2, SVID3, XPG2, XPG3, XPG4, FIPS 151-2, POSIX.1 Hewlett-Packard Company - 3 - HP-UX Release 11.00: October 1997 Il n'est pas dit que access ne modifie pas la chaine qui lui est passe, et s'il ne la modifiait pas ne devrait-il pas prendre un const char * ? Ceci dit s'il la modifie ca devrait etre dit... |
chrisbk | fire the debugger |
godbout | void ControlMAJ(char *catalogue)
{ int repexist; int fileexist; strcat(catalogue, "\\Test" ); repexist = PathIsDirectory(catalogue); //Si rep = true //C'est que le catalogue a ete installe sur la machine if (repexist > 0 ) { strcat(catalogue, "\\MERGE" ); //On regarde si le fichier existe fileexist = access(catalogue, 0); Salut a tous :hello: Alors mon petit pb du jour est que avant la fonction access, catalogue = "C:\blablabla". Et apres, elle devient vide :??: J'aimerais comprendre pourquoi ? Je sais bien qu'il y a d'autre moyen (par exemple essayer d'ouvrir le fichier, ou encore faire un strcpy avant et apres la fonction) mais comme ca me le fait deja avec 3 fonctions j'aimerais comprendre ou je fais la faute. Merci ;) |