Subversion Repositories DevTools

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
313 dpurdie 1
/** -*- mode: c; tabs: 4 -*- *************************************************
2
* Module name   : path.c
3
* Module type   : CMDFILE source file
4
* Environment(s): n/a
5
*
6
* Description:
7
     path functions
8
 
9
Returns:
10
     shortpath,
11
          The shortpath function retrieves the short path form of a
12
          specified input path.
13
*
14
* Version   Who      Date        Description
15
            APY      26/04/04    Created
16
*
17
* $Source: /cvsroot/device/DEVL/UTILS/CMDFILE/shtpath.c,v $
18
* $Revision: 1.2 $ $Date: 2004/10/08 03:07:37 $ $State: Exp $
19
* $Author: ayoung $ $Locker:  $
20
*...........................................................................*/
21
 
22
/*
23
 *  Include Files
24
 *  ---------------
25
 */
26
#include <ctype.h>
27
#include <unistd.h>
28
#if defined(WIN32)
29
#include <windows.h>
30
#endif
31
#include "cmdfile.h"
32
 
33
const char *        Shortpath( const char *name, char *buf );
34
 
35
int
36
do_shortpath( String_t *str, const char *s )
37
{
38
    char name[ PATH_MAX ], buf[ PATH_MAX ];
39
    int len;
40
 
41
    if (expected(s++, ',') > 0 &&
42
            (len = pathargument(s, name, PATH_MAX)) > 0)
43
    {
44
        const char *p;
45
 
46
        p = Shortpath( name, buf );
47
        verbose( " shortpath(%s) = %s", name, p );
48
        StringCat(str, p);
49
        return (1+len);
50
    }
51
    return (-1);
52
}
53
 
54
 
55
const char *
56
Shortpath( const char *name, char *buf )
57
{
58
#if defined(WIN32)
59
    DWORD   ret;
60
 
61
    if ((ret = GetShortPathName(name, buf, MAX_PATH)) == 0 || 
62
                ret > MAX_PATH - 1)
63
    {
64
        strcpy(buf, name);                      /* error, return orginial */
65
    }
66
    return (buf);
67
 
68
#else
69
    (void) strcpy(buf, name);
70
    return buf;
71
#endif
72
}