#include #include #define BUFLEN 10000 int printShortPath(const char *longPath); int main(int argc, char **argv) { if (argc < 2) { fprintf(stderr, "Not enough arguments.\n"); return 1; } { /* join each argument using spaces into a single long path */ char *longPath = (char *)malloc(BUFLEN); int i, j, k; k = 0; for (i = 1; i < argc; i++) { if (i > 1) { longPath[k++] = ' '; } for (j = 0; k < (BUFLEN - 1) && argv[i][j]; longPath[k++] = argv[i][j++]); } longPath[k] = '\0'; /* for a program, returning 0 means a success, and 1 (or any non-zero value, I guess) means failure. Seems to be opposite for GetShortPathName() */ if (printShortPath(longPath)) { return 0; } else { return 1; } } } int printShortPath(const char *longPath) { char *shortPath = (char *)malloc(BUFLEN); long len = BUFLEN, type, retval; retval = GetShortPathName(longPath, shortPath, len); if (retval) { printf("%s\n", shortPath); } else { fprintf(stderr, "Error shortening path.\n"); } free(shortPath); return retval; }