--- embedtools/src/dircmp.c 2010/07/13 09:35:01 1.1.2.1 +++ embedtools/src/dircmp.c 2010/07/13 11:22:36 1.1.2.3 @@ -3,7 +3,7 @@ extern char compiled[], compiledby[], compilehost[]; -char l; +char lm; static void @@ -85,7 +85,12 @@ cmpDir(const char *csDir1, const char *csDir2, struct memset(l, 0, sizeof(struct tagDirName)); } - dir = opendir(csDir1); + if (chdir(csDir1) == -1) { + printf("Error:: %s(%d) #%d - %s\n", __func__, __LINE__, errno, strerror(errno)); + free(l); + return -1; + } + dir = opendir("."); if (!dir) { printf("Error:: %s(%d) #%d - %s\n", __func__, __LINE__, errno, strerror(errno)); free(l); @@ -107,10 +112,10 @@ cmpDir(const char *csDir1, const char *csDir2, struct l[n].tag = crcFletcher16((u_short*) d.d_name, d.d_namlen / 2 + d.d_namlen % 2); l[n].hash = crcAdler((u_char*) d.d_name, d.d_namlen); strlcpy(l[n].name, d.d_name, MAXPATHLEN); - if (l) { + if (lm) { if (lstat(d.d_name, &sb) != -1) { memset(szStr, 0, MAX_STR); - strftime(szStr, MAX_STR, "%y-%m-%d %H:%M:%S", localtime(&sb.st_mtim)); + strftime(szStr, MAX_STR, "%Y-%m-%d %H:%M:%S", localtime((time_t*) &sb.st_mtim)); switch (d.d_type) { case DT_FIFO: strlcpy(szType, "fifo", MAX_STR); @@ -141,8 +146,9 @@ cmpDir(const char *csDir1, const char *csDir2, struct strlcpy(szType, "unknown", MAX_STR); break; } - snprintf(l[n].extra, MAX_STR, "%s links=%d %d:%d perm=0%o size=%llu %s\n", szType, - sb.st_nlink, sb.st_uid, sb.st_gid, sb.st_mode, sb.st_size, szStr); + snprintf(l[n].extra, MAX_STR, "%s links=%d inode=%u %d:%d perm=0%o size=%llu %s", + szType, sb.st_nlink, sb.st_ino, sb.st_uid, sb.st_gid, + sb.st_mode & 0x1fff, sb.st_size, szStr); } } @@ -154,7 +160,12 @@ cmpDir(const char *csDir1, const char *csDir2, struct tags[l[i].tag] = i; // open dir 2 for diff ... - dir = opendir(csDir2); + if (chdir(csDir2) == -1) { + printf("Error:: %s(%d) #%d - %s\n", __func__, __LINE__, errno, strerror(errno)); + free(l); + return -1; + } + dir = opendir("."); if (!dir) { printf("Error:: %s(%d) #%d - %s\n", __func__, __LINE__, errno, strerror(errno)); free(l); @@ -194,6 +205,45 @@ cmpDir(const char *csDir1, const char *csDir2, struct l[n].tag = t; l[n].hash = hash; strlcpy(l[n].name, d.d_name, MAXPATHLEN); + if (lm) { + if (lstat(d.d_name, &sb) != -1) { + memset(szStr, 0, MAX_STR); + strftime(szStr, MAX_STR, "%Y-%m-%d %H:%M:%S", localtime((time_t*) &sb.st_mtim)); + switch (d.d_type) { + case DT_FIFO: + strlcpy(szType, "fifo", MAX_STR); + break; + case DT_CHR: + strlcpy(szType, "char", MAX_STR); + break; + case DT_DIR: + strlcpy(szType, "dir", MAX_STR); + break; + case DT_BLK: + strlcpy(szType, "block", MAX_STR); + break; + case DT_REG: + strlcpy(szType, "file", MAX_STR); + break; + case DT_LNK: + strlcpy(szType, "link", MAX_STR); + break; + case DT_SOCK: + strlcpy(szType, "socket", MAX_STR); + break; + case DT_WHT: + strlcpy(szType, "wht", MAX_STR); + break; + case DT_UNKNOWN: + default: + strlcpy(szType, "unknown", MAX_STR); + break; + } + snprintf(l[n].extra, MAX_STR, "%s links=%d inode=%u %d:%d perm=0%o size=%llu %s", + szType, sb.st_nlink, sb.st_ino, sb.st_uid, sb.st_gid, + sb.st_mode & 0x1fff, sb.st_size, szStr); + } + } n++; } @@ -226,7 +276,7 @@ main(int argc, char **argv) while ((ch = getopt(argc, argv, "hl")) != -1) switch (ch) { case 'l': - l = 1; + lm = 1; break; case 'h': default: