mirror of
https://github.com/python/cpython.git
synced 2025-11-27 05:44:16 +00:00
Implemented PyMac_GetFullPathname for MacPython.
This commit is contained in:
parent
78e0fc74bc
commit
cf0319326a
1 changed files with 13 additions and 3 deletions
|
|
@ -203,7 +203,7 @@ get_folder_parent (FSSpec * fss, FSSpec * parent)
|
||||||
/* Given an FSSpec return a full, colon-separated pathname */
|
/* Given an FSSpec return a full, colon-separated pathname */
|
||||||
|
|
||||||
OSErr
|
OSErr
|
||||||
PyMac_GetFullPath (FSSpec *fss, char *buf)
|
PyMac_GetFullPathname (FSSpec *fss, char *buf, int length)
|
||||||
{
|
{
|
||||||
short err;
|
short err;
|
||||||
FSSpec fss_parent, fss_current;
|
FSSpec fss_parent, fss_current;
|
||||||
|
|
@ -212,6 +212,10 @@ PyMac_GetFullPath (FSSpec *fss, char *buf)
|
||||||
|
|
||||||
fss_current = *fss;
|
fss_current = *fss;
|
||||||
plen = fss_current.name[0];
|
plen = fss_current.name[0];
|
||||||
|
if ( plen+2 > length ) {
|
||||||
|
*buf = 0;
|
||||||
|
return errFSNameTooLong;
|
||||||
|
}
|
||||||
memcpy(buf, &fss_current.name[1], plen);
|
memcpy(buf, &fss_current.name[1], plen);
|
||||||
buf[plen] = 0;
|
buf[plen] = 0;
|
||||||
/* Special case for disk names */
|
/* Special case for disk names */
|
||||||
|
|
@ -222,19 +226,25 @@ PyMac_GetFullPath (FSSpec *fss, char *buf)
|
||||||
}
|
}
|
||||||
while (fss_current.parID > 1) {
|
while (fss_current.parID > 1) {
|
||||||
/* Get parent folder name */
|
/* Get parent folder name */
|
||||||
if (err = get_folder_parent(&fss_current, &fss_parent))
|
if (err = get_folder_parent(&fss_current, &fss_parent)) {
|
||||||
|
*buf = 0;
|
||||||
return err;
|
return err;
|
||||||
|
}
|
||||||
fss_current = fss_parent;
|
fss_current = fss_parent;
|
||||||
/* Prepend path component just found to buf */
|
/* Prepend path component just found to buf */
|
||||||
plen = fss_current.name[0];
|
plen = fss_current.name[0];
|
||||||
if (strlen(buf) + plen + 1 > 1024) {
|
if (strlen(buf) + plen + 1 > 1024) {
|
||||||
/* Oops... Not enough space (shouldn't happen) */
|
/* Oops... Not enough space (shouldn't happen) */
|
||||||
*buf = 0;
|
*buf = 0;
|
||||||
return -1;
|
return errFSNameTooLong;
|
||||||
}
|
}
|
||||||
memcpy(tmpbuf, &fss_current.name[1], plen);
|
memcpy(tmpbuf, &fss_current.name[1], plen);
|
||||||
tmpbuf[plen] = ':';
|
tmpbuf[plen] = ':';
|
||||||
strcpy(&tmpbuf[plen+1], buf);
|
strcpy(&tmpbuf[plen+1], buf);
|
||||||
|
if ( strlen(tmpbuf) > length ) {
|
||||||
|
*buf = 0;
|
||||||
|
return errFSNameTooLong;
|
||||||
|
}
|
||||||
strcpy(buf, tmpbuf);
|
strcpy(buf, tmpbuf);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue