void generator_append_escaped_wstr(Generator* self, const WCHAR* wstr)/*{{{*/ { assert(self); if (wstr) { char* str = NULL; if (self->flags & GENERATOR_UTF8) str = wstr_to_utf8(wstr); else str = wstr_to_ascii(wstr); generator_append_escaped(self, str); wstr_free_string(str); } }/*}}}*/
int rapi_copy(char *source, char *dest) { int result = 1; HRESULT hr; time_t start; time_t duration; size_t bytes_copied = 0; hr = CeRapiInit(); if (RAPI_FAILED(hr)) { fprintf(stderr, "Unable to initialize RAPI: %s\n", synce_strerror(hr)); goto exit; } if (!dest) { char* p; if (is_remote_file(source)) { for (p = source + strlen(source); p != source; p--) { if (*p == '/' || *p == '\\') { dest = (char *) strdup(p+1); break; } } if (!dest || '\0' == dest[0]) { fprintf(stderr, "Unable to extract destination filename from source path '%s'\n", source); goto exit; } } else { WCHAR mydocuments[MAX_PATH]; char* mydocuments_ascii = NULL; p = strrchr(source, '/'); if (p) p++; else p = source; if ('\0' == *p) { fprintf(stderr, "Unable to extract destination filename from source path '%s'\n", source); goto exit; } if (!CeGetSpecialFolderPath(CSIDL_PERSONAL, sizeof(mydocuments), mydocuments)) { fprintf(stderr, "Unable to get the \"My Documents\" path.\n"); goto exit; } dest = (char *) calloc(1, 1 + wstr_strlen(mydocuments) + 1 + strlen(p) + 1); mydocuments_ascii = wstr_to_ascii(mydocuments); strcat(dest, ":"); strcat(dest, mydocuments_ascii); strcat(dest, "\\"); strcat(dest, p); wstr_free_string(mydocuments_ascii); } } if (0 == strcmp(source, dest)) { fprintf(stderr, "You don't want to copy a file to itself.\n"); goto exit; } if (is_remote_file(source) && is_remote_file(dest)) { /* * * Both are remote; use CeCopyFile() * */ if (!remote_copy(source, dest)) goto exit; } else { start = time(NULL); /* * * At least one is local, Use the AnyFile functions * */ if (!anyfile_copy(source, dest, &bytes_copied)) goto exit; } result = 0; exit: CeRapiUninit(); return result; }