Changeset 3172 in kBuild
- Timestamp:
- Mar 21, 2018 2:21:23 PM (7 years ago)
- Location:
- trunk/src/kmk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kmk/kmkbuiltin.c
r3170 r3172 239 239 240 240 /* More frequently used commands: */ 241 BUILTIN_ENTRY(kmk_builtin_append, "append", FN_SIG_MAIN ,0, 0),241 BUILTIN_ENTRY(kmk_builtin_append, "append", FN_SIG_MAIN_SPAWNS, 0, 0), 242 242 BUILTIN_ENTRY(kmk_builtin_printf, "printf", FN_SIG_MAIN, 0, 0), 243 243 BUILTIN_ENTRY(kmk_builtin_echo, "echo", FN_SIG_MAIN, 0, 0), … … 440 440 * Prints the statistiscs to the given output stream. 441 441 */ 442 intkmk_builtin_print_stats(FILE *pOutput, const char *pszPrefix)442 extern void kmk_builtin_print_stats(FILE *pOutput, const char *pszPrefix) 443 443 { 444 444 const unsigned cEntries = sizeof(g_aBuiltInStats) / sizeof(g_aBuiltInStats[0]); -
trunk/src/kmk/kmkbuiltin.h
r3170 r3172 94 94 typedef KMKBUILTINENTRY const *PCKMKBUILTINENTRY; 95 95 96 extern int kmk_builtin_append(int argc, char **argv, char **envp); 96 #ifndef kmk_builtin_append 97 extern int kmk_builtin_append(int argc, char **argv, char **envp, struct child *pChild, pid_t *pPidSpawned); 98 #endif 97 99 extern int kmk_builtin_cp(int argc, char **argv, char **envp); 98 100 extern int kmk_builtin_cat(int argc, char **argv, char **envp); … … 140 142 141 143 #ifdef CONFIG_WITH_KMK_BUILTIN_STATS 142 intkmk_builtin_print_stats(FILE *pOutput, const char *pszPrefix);144 extern void kmk_builtin_print_stats(FILE *pOutput, const char *pszPrefix); 143 145 #endif 144 146 -
trunk/src/kmk/kmkbuiltin/append.c
r3171 r3172 45 45 #ifdef HAVE_ALLOCA_H 46 46 # include <alloca.h> 47 #endif 48 #if !defined(kmk_builtin_append) && defined(KBUILD_OS_WINDOWS) && defined(CONFIG_NEW_WIN_CHILDREN) 49 # include "../w32/winchildren.h" 47 50 #endif 48 51 #include "err.h" … … 169 172 * Appends text to a textfile, creating the textfile if necessary. 170 173 */ 171 int kmk_builtin_append(int argc, char **argv, char **envp) 174 #ifndef kmk_builtin_append 175 int kmk_builtin_append(int argc, char **argv, char **envp, struct child *pChild, pid_t *pPidSpawned) 176 #else 177 int main(int argc, char **argv, char **envp) 178 #endif 172 179 { 180 #if defined(KBUILD_OS_WINDOWS) || defined(KBUILD_OS_OS2) 181 static const char s_szNewLine[] = "\r\n"; 182 #else 183 static const char s_szNewLine[] = "\n"; 184 #endif 185 KMKBUILTINAPPENDBUF OutBuf = { NULL, 0, 0, 0 }; 173 186 const char *pszFilename; 174 187 int rc = 88; … … 184 197 int fLookForInserts = 0; 185 198 #endif 186 #if defined(KBUILD_OS_WINDOWS) || defined(KBUILD_OS_OS2)187 static const char s_szNewLine[] = "\r\n";188 #else189 static const char s_szNewLine[] = "\n";190 #endif191 KMKBUILTINAPPENDBUF OutBuf = { NULL, 0, 0, 0 };192 199 193 200 g_progname = argv[0]; … … 409 416 * Write the buffer (unless we ran out of heap already). 410 417 */ 418 #if !defined(kmk_builtin_append) && defined(KBUILD_OS_WINDOWS) && defined(CONFIG_NEW_WIN_CHILDREN) 419 if (!OutBuf.fOutOfMemory) 420 { 421 rc = MkWinChildCreateAppend(pszFilename, &OutBuf.pszBuf, OutBuf.offBuf, fTruncate, pChild, pPidSpawned); 422 if (rc != 0) 423 rc = errx(rc, "MkWinChildCreateAppend failed: %u", rc); 424 if (OutBuf.pszBuf) 425 free(OutBuf.pszBuf); 426 } 427 else 428 #endif 411 429 if (!OutBuf.fOutOfMemory) 412 430 { -
trunk/src/kmk/w32/winchildren.c
r3169 r3172 110 110 /** kmkbuiltin command. */ 111 111 WINCHILDTYPE_BUILT_IN, 112 /** kmkbuiltin_append result write out. */ 113 WINCHILDTYPE_APPEND, 112 114 /** kSubmit job. */ 113 115 WINCHILDTYPE_SUBMIT, … … 188 190 char **papszEnv; 189 191 } BuiltIn; 192 193 /** Data for WINCHILDTYPE_APPEND. */ 194 struct 195 { 196 /** The filename. */ 197 char *pszFilename; 198 /** How much to append. */ 199 size_t cbAppend; 200 /** What to append. */ 201 char *pszAppend; 202 /** Whether to truncate the file. */ 203 int fTruncate; 204 } Append; 190 205 191 206 /** Data for WINCHILDTYPE_SUBMIT. */ … … 1672 1687 1673 1688 /** 1689 * Childcare worker: handle append write-out. 1690 * 1691 * @param pWorker The worker. 1692 * @param pChild The kSubmit child. 1693 */ 1694 static void mkWinChildcareWorkerThreadHandleAppend(PWINCHILDCAREWORKER pWorker, PWINCHILD pChild) 1695 { 1696 int fd = open(pChild->u.Append.pszFilename, 1697 pChild->u.Append.fTruncate 1698 ? O_WRONLY | O_TRUNC | O_CREAT | _O_NOINHERIT | _O_BINARY 1699 : O_WRONLY | O_APPEND | O_CREAT | _O_NOINHERIT | _O_BINARY, 1700 0666); 1701 if (fd >= 0) 1702 { 1703 ssize_t cbWritten = write(fd, pChild->u.Append.pszAppend, pChild->u.Append.cbAppend); 1704 if (cbWritten == (ssize_t)pChild->u.Append.cbAppend) 1705 { 1706 if (close(fd) >= 0) 1707 { 1708 pChild->iExitCode = 0; 1709 return; 1710 } 1711 fprintf(stderr, "kmk_builtin_append: close failed on '%s': %u (%s)\n", 1712 pChild->u.Append.pszFilename, errno, strerror(errno)); 1713 } 1714 else 1715 fprintf(stderr, "kmk_builtin_append: error writing %lu bytes to on '%s': %u (%s)\n", 1716 pChild->u.Append.cbAppend, pChild->u.Append.pszFilename, errno, strerror(errno)); 1717 close(fd); 1718 } 1719 else 1720 fprintf(stderr, "kmk_builtin_append: error opening '%s': %u (%s)\n", 1721 pChild->u.Append.pszFilename, errno, strerror(errno)); 1722 pChild->iExitCode = 1; 1723 } 1724 1725 /** 1674 1726 * Childcare worker: handle kSubmit job. 1675 1727 * … … 1784 1836 case WINCHILDTYPE_BUILT_IN: 1785 1837 mkWinChildcareWorkerThreadHandleBuiltIn(pWorker, pChild); 1838 break; 1839 case WINCHILDTYPE_APPEND: 1840 mkWinChildcareWorkerThreadHandleAppend(pWorker, pChild); 1786 1841 break; 1787 1842 case WINCHILDTYPE_SUBMIT: … … 2004 2059 break; 2005 2060 2061 case WINCHILDTYPE_APPEND: 2062 if (pChild->u.Append.pszFilename) 2063 { 2064 free(pChild->u.Append.pszFilename); 2065 pChild->u.Append.pszFilename = NULL; 2066 } 2067 if (pChild->u.Append.pszAppend) 2068 { 2069 free(pChild->u.Append.pszAppend); 2070 pChild->u.Append.pszAppend = NULL; 2071 } 2072 break; 2073 2006 2074 case WINCHILDTYPE_SUBMIT: 2007 2075 if (pChild->u.Submit.pvSubmitWorker) … … 2283 2351 2284 2352 /** 2353 * Interface used by append.c for do the slow file system part. 2354 * 2355 * This will append the given buffer to the specified file and free the buffer. 2356 * 2357 * @returns 0 on success, windows status code on failure. 2358 * 2359 * @param pszFilename The name of the file to append to. 2360 * @param ppszAppend What to append. The pointer pointed to is set to 2361 * NULL once we've taken ownership of the buffer and 2362 * promise to free it. 2363 * @param cbAppend How much to append. 2364 * @param fTruncate Whether to truncate the file before appending to it. 2365 * @param pMkChild The make child structure. 2366 * @param pPid Where to return the pid. 2367 */ 2368 int MkWinChildCreateAppend(const char *pszFilename, char **ppszAppend, size_t cbAppend, int fTruncate, 2369 struct child *pMkChild, pid_t *pPid) 2370 { 2371 size_t cbFilename = strlen(pszFilename) + 1; 2372 PWINCHILD pChild = mkWinChildNew(WINCHILDTYPE_APPEND); 2373 pChild->pMkChild = pMkChild; 2374 pChild->u.Append.fTruncate = fTruncate; 2375 pChild->u.Append.pszAppend = *ppszAppend; 2376 pChild->u.Append.cbAppend = cbAppend; 2377 pChild->u.Append.pszFilename = (char *)memcpy(xmalloc(cbFilename), pszFilename, cbFilename); 2378 *ppszAppend = NULL; 2379 return mkWinChildPushToCareWorker(pChild, pPid); 2380 } 2381 2382 /** 2285 2383 * Interface used by kSubmit.c for registering stuff to wait on. 2286 2384 * … … 2337 2435 pChild->iSignal = iSignal; 2338 2436 break; 2339 2340 2437 #ifdef KMK 2341 2342 2438 case WINCHILDTYPE_SUBMIT: 2343 2439 { … … 2356 2452 2357 2453 #endif /* KMK */ 2358 2359 2454 default: 2360 2455 assert(0); … … 2418 2513 #ifdef KMK 2419 2514 case WINCHILDTYPE_BUILT_IN: 2420 break;2515 case WINCHILDTYPE_APPEND: 2421 2516 case WINCHILDTYPE_SUBMIT: 2422 break;2423 2517 case WINCHILDTYPE_REDIRECT: 2424 2518 break; -
trunk/src/kmk/w32/winchildren.h
r3169 r3172 37 37 int MkWinChildCreateBuiltIn(struct KMKBUILTINENTRY const *pBuiltIn, int cArgs, char **papszArgs, 38 38 char **papszEnv, struct child *pMkChild, pid_t *pPid); 39 int MkWinChildCreateAppend(const char *pszFilename, char **ppszAppend, size_t cbAppend, int fTruncate, 40 struct child *pMkChild, pid_t *pPid); 39 41 int MkWinChildCreateSubmit(intptr_t hEvent, void *pvSubmitWorker, pid_t *pPid); 40 42 int MkWinChildCreateRedirect(intptr_t hProcess, pid_t *pPid);
Note:
See TracChangeset
for help on using the changeset viewer.