本文整理汇总了C++中safe_strlen函数的典型用法代码示例。如果您正苦于以下问题:C++ safe_strlen函数的具体用法?C++ safe_strlen怎么用?C++ safe_strlen使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了safe_strlen函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: replace_char
/*
* Replace all 'c' characters in string 'src' with the subtsring 'rep'
* The returned string is allocated and must be freed by the caller.
*/
char* replace_char(const char* src, const char c, const char* rep)
{
size_t i, j, k, count=0, str_len = safe_strlen(src), rep_len = safe_strlen(rep);
char* res;
if ((src == NULL) || (rep == NULL))
return NULL;
for (i=0; i<str_len; i++) {
if (src[i] == c)
count++;
}
res = (char*)malloc(str_len + count*rep_len + 1);
if (res == NULL)
return NULL;
for (i=0,j=0; i<str_len; i++) {
if (src[i] == c) {
for(k=0; k<rep_len; k++)
res[j++] = rep[k];
} else {
res[j++] = src[i];
}
}
res[j] = 0;
return res;
}
开发者ID:10se1ucgo,项目名称:rufus,代码行数:29,代码来源:parser.c
示例2: safe_cat_string
/** A safe cat of a string.
*/
void safe_cat_string(char* dest, size_t dest_len, const char* cat)
{
size_t current_len = safe_strlen(dest);
size_t input_len = safe_strlen(cat);
if (dest_len < current_len + input_len + 1) {
printf("Error catting string!\n");
return;
}
memcpy(dest + current_len, cat, input_len);
dest[current_len + input_len] = '\0';
}
开发者ID:NCTU-NBA,项目名称:pillowtalk,代码行数:14,代码来源:pillowtalk_changes_feed.c
示例3: get_link_type
static link_type
get_link_type(cmark_node *node)
{
size_t title_len, url_len;
cmark_node *link_text;
char *realurl;
int realurllen;
bool isemail = false;
if (node->type != CMARK_NODE_LINK) {
return NO_LINK;
}
const char* url = cmark_node_get_url(node);
cmark_chunk url_chunk = cmark_chunk_literal(url);
url_len = safe_strlen(url);
if (url_len == 0 || scan_scheme(&url_chunk, 0) == 0) {
return NO_LINK;
}
const char* title = cmark_node_get_title(node);
title_len = safe_strlen(title);
// if it has a title, we can't treat it as an autolink:
if (title_len > 0) {
return NORMAL_LINK;
}
link_text = node->first_child;
cmark_consolidate_text_nodes(link_text);
realurl = (char*)url;
realurllen = url_len;
if (strncmp(realurl, "mailto:", 7) == 0) {
realurl += 7;
realurllen -= 7;
isemail = true;
}
if (realurllen == link_text->as.literal.len &&
strncmp(realurl,
(char*)link_text->as.literal.data,
link_text->as.literal.len) == 0) {
if (isemail) {
return EMAIL_AUTOLINK;
} else {
return URL_AUTOLINK;
}
} else {
return NORMAL_LINK;
}
}
开发者ID:omgitsads,项目名称:Twitch,代码行数:50,代码来源:latex.c
示例4: shortest_unused_backtick_sequence
static int
shortest_unused_backtick_sequence(const char *code)
{
int32_t used = 1;
int current = 0;
size_t i = 0;
size_t code_len = safe_strlen(code);
while (i <= code_len) {
if (code[i] == '`') {
current++;
} else {
if (current) {
used |= (1 << current);
}
current = 0;
}
i++;
}
// return number of first bit that is 0:
i = 0;
while (used & 1) {
used = used >> 1;
i++;
}
return i;
}
开发者ID:apache,项目名称:lucy-clownfish,代码行数:26,代码来源:commonmark.c
示例5: open_loc_file
/*
* Open a localization file and store its file name, with special case
* when dealing with the embedded loc file.
*/
FILE* open_loc_file(const char* filename)
{
FILE* fd = NULL;
wchar_t *wfilename = NULL;
const char* tmp_ext = ".tmp";
if (filename == NULL)
return NULL;
if (loc_filename != embedded_loc_filename) {
safe_free(loc_filename);
}
if (safe_strcmp(tmp_ext, &filename[safe_strlen(filename)-4]) == 0) {
loc_filename = embedded_loc_filename;
} else {
loc_filename = safe_strdup(filename);
}
wfilename = utf8_to_wchar(filename);
if (wfilename == NULL) {
uprintf(conversion_error, filename);
goto out;
}
fd = _wfopen(wfilename, L"rb");
if (fd == NULL) {
uprintf("localization: could not open '%s'\n", filename);
}
out:
safe_free(wfilename);
return fd;
}
开发者ID:10se1ucgo,项目名称:rufus,代码行数:35,代码来源:parser.c
示例6: GetUnusedDriveLetter
/*
* Return the next unused drive letter from the system
*/
char GetUnusedDriveLetter(void)
{
DWORD size;
char drive_letter = 'Z'+1, *drive, drives[26*4 + 1]; /* "D:\", "E:\", etc., plus one NUL */
size = GetLogicalDriveStringsA(sizeof(drives), drives);
if (size == 0) {
uprintf("GetLogicalDriveStrings failed: %s\n", WindowsErrorString());
goto out;
}
if (size > sizeof(drives)) {
uprintf("GetLogicalDriveStrings: Buffer too small (required %d vs. %d)\n", size, sizeof(drives));
goto out;
}
for (drive_letter = 'C'; drive_letter < 'Z'; drive_letter++) {
for (drive = drives ;*drive; drive += safe_strlen(drive)+1) {
if (!isalpha(*drive))
continue;
if (drive_letter == (char)toupper((int)*drive))
break;
}
if (!*drive)
break;
}
out:
return (drive_letter>'Z')?0:drive_letter;
}
开发者ID:BruceLEO1969,项目名称:rufus,代码行数:32,代码来源:drive.c
示例7: GetLastError
const char *windows_error_str(DWORD retval)
{
static char err_string[ERR_BUFFER_SIZE];
DWORD error_code, format_error;
DWORD size;
ssize_t i;
error_code = retval ? retval : GetLastError();
safe_sprintf(err_string, ERR_BUFFER_SIZE, "[%u] ", (unsigned int)error_code);
// Translate codes returned by SetupAPI. The ones we are dealing with are either
// in 0x0000xxxx or 0xE000xxxx and can be distinguished from standard error codes.
// See http://msdn.microsoft.com/en-us/library/windows/hardware/ff545011.aspx
switch (error_code & 0xE0000000) {
case 0:
error_code = HRESULT_FROM_WIN32(error_code); // Still leaves ERROR_SUCCESS unmodified
break;
case 0xE0000000:
error_code = 0x80000000 | (FACILITY_SETUPAPI << 16) | (error_code & 0x0000FFFF);
break;
default:
break;
}
size = FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, NULL, error_code,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), &err_string[safe_strlen(err_string)],
ERR_BUFFER_SIZE - (DWORD)safe_strlen(err_string), NULL);
if (size == 0) {
format_error = GetLastError();
if (format_error)
safe_sprintf(err_string, ERR_BUFFER_SIZE,
"Windows error code %u (FormatMessage error code %u)",
(unsigned int)error_code, (unsigned int)format_error);
else
safe_sprintf(err_string, ERR_BUFFER_SIZE, "Unknown error code %u", (unsigned int)error_code);
}
else {
// Remove CR/LF terminators
for (i = safe_strlen(err_string) - 1; (i >= 0) && ((err_string[i] == 0x0A) || (err_string[i] == 0x0D)); i--)
err_string[i] = 0;
}
return err_string;
}
开发者ID:Chadizzm,项目名称:libusb,代码行数:46,代码来源:windows_nt_common.c
示例8: SetUpdateCheck
/*
* Initial update check setup
*/
BOOL SetUpdateCheck(void)
{
BOOL enable_updates;
DWORD commcheck = GetTickCount();
notification_info more_info = { IDD_UPDATE_POLICY, UpdateCallback };
char filename[MAX_PATH] = "", exename[] = APPLICATION_NAME ".exe";
size_t fn_len, exe_len;
// Test if we have access to the registry. If not, forget it.
WriteRegistryKey32(REGKEY_HKCU, REGKEY_COMM_CHECK, commcheck);
if (ReadRegistryKey32(REGKEY_HKCU, REGKEY_COMM_CHECK) != commcheck)
return FALSE;
reg_commcheck = TRUE;
// If the update interval is not set, this is the first time we run so prompt the user
if (ReadRegistryKey32(REGKEY_HKCU, REGKEY_UPDATE_INTERVAL) == 0) {
// Add a hack for people who'd prefer the app not to prompt about update settings on first run.
// If the executable is called "<app_name>.exe", without version, we disable the prompt
GetModuleFileNameU(NULL, filename, sizeof(filename));
fn_len = safe_strlen(filename);
exe_len = safe_strlen(exename);
if ((fn_len > exe_len) && (safe_stricmp(&filename[fn_len-exe_len], exename) == 0)) {
dprintf("Short name used - Disabling initial update policy prompt\n");
enable_updates = TRUE;
} else {
enable_updates = notification(MSG_QUESTION, &more_info, APPLICATION_NAME " update policy",
"Do you want to allow " APPLICATION_NAME " to check for application updates online?");
}
if (!enable_updates) {
WriteRegistryKey32(REGKEY_HKCU, REGKEY_UPDATE_INTERVAL, -1);
return FALSE;
}
// If the user hasn't set the interval in the dialog, set to default
if ( (ReadRegistryKey32(REGKEY_HKCU, REGKEY_UPDATE_INTERVAL) == 0) ||
((ReadRegistryKey32(REGKEY_HKCU, REGKEY_UPDATE_INTERVAL) == -1) && enable_updates) )
WriteRegistryKey32(REGKEY_HKCU, REGKEY_UPDATE_INTERVAL, 86400);
}
return TRUE;
}
开发者ID:pbatard,项目名称:libwdi,代码行数:43,代码来源:zadig_stdlg.c
示例9: fix_config
// Apply various workarounds to Linux config files
static void fix_config(const char* psz_fullpath, const char* psz_path, const char* psz_basename, EXTRACT_PROPS* props)
{
size_t i, nul_pos;
char *iso_label = NULL, *usb_label = NULL, *src, *dst;
nul_pos = safe_strlen(psz_fullpath);
src = safe_strdup(psz_fullpath);
if (src == NULL)
return;
for (i=0; i<nul_pos; i++)
if (src[i] == '/') src[i] = '\\';
// Workaround for config files requiring an ISO label for kernel append that may be
// different from our USB label. Oh, and these labels must have spaces converted to \x20.
if ((props->is_syslinux_cfg) || (props->is_grub_cfg)) {
iso_label = replace_char(img_report.label, ' ', "\\x20");
usb_label = replace_char(img_report.usb_label, ' ', "\\x20");
if ((iso_label != NULL) && (usb_label != NULL)) {
if (replace_in_token_data(src, (props->is_syslinux_cfg) ? "append" : "linuxefi", iso_label, usb_label, TRUE) != NULL)
uprintf(" Patched %s: '%s' ⇨ '%s'\n", src, iso_label, usb_label);
}
safe_free(iso_label);
safe_free(usb_label);
}
// Fix dual BIOS + EFI support for tails and other ISOs
if ( (props->is_syslinux_cfg) && (safe_stricmp(psz_path, efi_dirname) == 0) &&
(safe_stricmp(psz_basename, syslinux_cfg[0]) == 0) &&
(!img_report.has_efi_syslinux) && (dst = safe_strdup(src)) ) {
dst[nul_pos-12] = 's'; dst[nul_pos-11] = 'y'; dst[nul_pos-10] = 's';
CopyFileA(src, dst, TRUE);
uprintf("Duplicated %s to %s\n", src, dst);
free(dst);
}
// Workaround for FreeNAS
if (props->is_grub_cfg) {
iso_label = malloc(MAX_PATH);
usb_label = malloc(MAX_PATH);
if ((iso_label != NULL) && (usb_label != NULL)) {
safe_sprintf(iso_label, MAX_PATH, "cd9660:/dev/iso9660/%s", img_report.label);
safe_sprintf(usb_label, MAX_PATH, "msdosfs:/dev/msdosfs/%s", img_report.usb_label);
if (replace_in_token_data(src, "set", iso_label, usb_label, TRUE) != NULL)
uprintf(" Patched %s: '%s' ⇨ '%s'\n", src, iso_label, usb_label);
}
safe_free(iso_label);
safe_free(usb_label);
}
free(src);
}
开发者ID:ShaRose,项目名称:rufus,代码行数:52,代码来源:iso.c
示例10: get_sanitized_token_data_buffer
static __inline char* get_sanitized_token_data_buffer(const char* token, unsigned int n, const char* buffer, size_t buffer_size)
{
size_t i;
char* data = get_token_data_buffer(token, n, buffer, buffer_size);
if (data != NULL) {
for (i=0; i<safe_strlen(data); i++) {
if ((data[i] == '\\') && (data[i+1] == 'n')) {
data[i] = '\r';
data[i+1] = '\n';
}
}
}
return data;
}
开发者ID:kengvun,项目名称:rufus,代码行数:14,代码来源:parser.c
示例11: sanitize_filename
// Ensure filenames do not contain invalid FAT32 or NTFS characters
static __inline BOOL sanitize_filename(char* filename)
{
size_t i, j;
BOOL ret = FALSE;
char unauthorized[] = {'<', '>', ':', '|', '*', '?'};
// Must start after the drive part (D:\...) so that we don't eliminate the first column
for (i=2; i<safe_strlen(filename); i++) {
for (j=0; j<sizeof(unauthorized); j++) {
if (filename[i] == unauthorized[j]) {
filename[i] = '_';
ret = TRUE;
}
}
}
return ret;
}
开发者ID:JBTech,项目名称:rufus,代码行数:18,代码来源:iso.c
示例12: pt_changes_feed_build_url
/** build a URL, returned char* needs to be free'd */
char* pt_changes_feed_build_url(const char* server_name,
const char* db,
const pt_changes_feed handle)
{
char *ret_str;
char* end_of_string;
size_t size_of_string = safe_strlen(server_name) +
safe_strlen(db) +
safe_strlen(handle->extra_opts) +
safe_strlen("//_changes?heartbeat=&feed=continuous") + 2048;
ret_str = calloc(1, size_of_string);
// Add the changes feed base URL
snprintf(ret_str, size_of_string, "%s/%s/_changes", server_name, db);
if (!handle->continuous && !handle->heartbeats &&
!safe_strlen(handle->extra_opts)) return ret_str;
// If we get here, it means that we have added options. There is *no*
// checking at this point!
safe_cat_string(ret_str, size_of_string, "?");
// Hearbeat
if (handle->heartbeats) {
snprintf(ret_str + safe_strlen(ret_str),size_of_string - safe_strlen(ret_str),
"heartbeat=%i&",handle->heartbeats);
}
// Continuous
if (handle->continuous) safe_cat_string(ret_str, size_of_string, "feed=continuous&");
// Adding extra options passed by the user
if (safe_strlen(handle->extra_opts)) safe_cat_string(ret_str, size_of_string, handle->extra_opts);
// If we have an ampersand on the end, remove it
end_of_string = &ret_str[safe_strlen(ret_str)-1];
if (*end_of_string == '&') *end_of_string = '\0';
return ret_str;
}
开发者ID:NCTU-NBA,项目名称:pillowtalk,代码行数:39,代码来源:pillowtalk_changes_feed.c
示例13: parse_update
/*
* Parse an update data file and populates a rufus_update structure.
* NB: since this is remote data, and we're running elevated, it *IS* considered
* potentially malicious, even if it comes from a supposedly trusted server.
* len should be the size of the buffer, including the zero terminator
*/
void parse_update(char* buf, size_t len)
{
size_t i;
char *data = NULL, *token;
char allowed_rtf_chars[] = "abcdefghijklmnopqrstuvwxyz|~-_:*'";
char allowed_std_chars[] = "\r\n ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"$%^&+=<>(){}[].,;#@/?";
// strchr includes the NUL terminator in the search, so take care of backslash before NUL
if ((buf == NULL) || (len < 2) || (len > 65536) || (buf[len-1] != 0) || (buf[len-2] == '\\'))
return;
// Sanitize the data - Not a silver bullet, but it helps
len = safe_strlen(buf)+1; // Someone may be inserting NULs
for (i=0; i<len-1; i++) {
// Check for valid RTF sequences as well as allowed chars if not RTF
if (buf[i] == '\\') {
// NB: we have a zero terminator, so we can afford a +1 without overflow
if (strchr(allowed_rtf_chars, buf[i+1]) == NULL) {
buf[i] = ' ';
}
} else if ((strchr(allowed_rtf_chars, buf[i]) == NULL) && (strchr(allowed_std_chars, buf[i]) == NULL)) {
buf[i] = ' ';
}
}
for (i=0; i<3; i++)
update.version[i] = 0;
update.platform_min[0] = 5;
update.platform_min[1] = 2; // XP or later
safe_free(update.download_url);
safe_free(update.release_notes);
if ((data = get_sanitized_token_data_buffer("version", 1, buf, len)) != NULL) {
for (i=0; (i<3) && ((token = strtok((i==0)?data:NULL, ".")) != NULL); i++) {
update.version[i] = (uint16_t)atoi(token);
}
safe_free(data);
}
if ((data = get_sanitized_token_data_buffer("platform_min", 1, buf, len)) != NULL) {
for (i=0; (i<2) && ((token = strtok((i==0)?data:NULL, ".")) != NULL); i++) {
update.platform_min[i] = (uint32_t)atoi(token);
}
safe_free(data);
}
update.download_url = get_sanitized_token_data_buffer("download_url", 1, buf, len);
update.release_notes = get_sanitized_token_data_buffer("release_notes", 1, buf, len);
}
开发者ID:10se1ucgo,项目名称:rufus,代码行数:51,代码来源:parser.c
示例14: longest_backtick_sequence
static int longest_backtick_sequence(const char *code) {
int longest = 0;
int current = 0;
size_t i = 0;
size_t code_len = safe_strlen(code);
while (i <= code_len) {
if (code[i] == '`') {
current++;
} else {
if (current > longest) {
longest = current;
}
current = 0;
}
i++;
}
return longest;
}
开发者ID:CODECOMMUNITY,项目名称:swift-cmark,代码行数:18,代码来源:commonmark.c
示例15: process_syslog
/*
* Send individual lines of the syslog section pointed by buffer back to the main application
* xbuffer's payload MUST start at byte 1 to accomodate the SYSLOG_MESSAGE prefix
*/
DWORD process_syslog(char* buffer, DWORD size)
{
DWORD i, write_size, junk, start = 0;
char* xbuffer;
char* ins_string = "<ins>";
char conversion_error[] = " ERROR: Unable to convert log entry to UTF-8";
if (buffer == NULL) return 0;
// CR/LF breakdown
for (i=0; i<size; i++) {
if ((buffer[i] == 0x0D) || (buffer[i] == 0x0A)) {
write_size = i-start + 1;
do {
buffer[i++] = 0;
} while ( ((buffer[i] == 0x0D) || (buffer[i] == 0x0A)) && (i <= size) );
// The setupapi.dev.log uses a dubious method to mark its current position
// If there's any "<ins>" line in any log file, it's game over then
if (safe_strcmp(ins_string, buffer + start) == 0) {
return start;
}
// The logs are using the system locale. Convert to UTF8 (with extra leading byte)
xbuffer = xlocale_to_utf8(&buffer[start]);
if (xbuffer == NULL) {
xbuffer = conversion_error;
}
// This is where we use the extra start byte
xbuffer[0] = IC_SYSLOG_MESSAGE;
WriteFile(pipe_handle, xbuffer, (DWORD)safe_strlen(&xbuffer[1])+2, &junk, NULL);
if (xbuffer != conversion_error) {
free(xbuffer);
}
start = i;
}
}
// start does not necessarily equate size, if there are truncated lines at the end
return start;
}
开发者ID:mcuee,项目名称:libusb-win32,代码行数:45,代码来源:installer.c
示例16: sanitize_filename
// Ensure filenames do not contain invalid FAT32 or NTFS characters
static __inline char* sanitize_filename(char* filename, BOOL* is_identical)
{
size_t i, j;
char* ret = NULL;
char unauthorized[] = {'<', '>', ':', '|', '*', '?'};
*is_identical = TRUE;
ret = safe_strdup(filename);
if (ret == NULL) {
uprintf("Could not allocate string for sanitized path");
return NULL;
}
// Must start after the drive part (D:\...) so that we don't eliminate the first column
for (i=2; i<safe_strlen(ret); i++) {
for (j=0; j<sizeof(unauthorized); j++) {
if (ret[i] == unauthorized[j]) {
ret[i] = '_';
*is_identical = FALSE;
}
}
}
return ret;
}
开发者ID:DesignD,项目名称:rufus,代码行数:25,代码来源:iso.c
示例17: ExtractISO
//.........这里部分代码省略.........
iso_extension_mask &= ~ISO_EXTENSION_JOLIET;
}
if (!enable_rockridge) {
iso_extension_mask &= ~ISO_EXTENSION_ROCK_RIDGE;
}
p_iso = iso9660_open_ext(src_iso, iso_extension_mask);
if (p_iso == NULL) {
uprintf("Unable to open '%s' as an ISO image.\n", src_iso);
r = 1;
goto out;
}
uprintf("Disc image is an ISO9660 image\n");
i_joliet_level = iso9660_ifs_get_joliet_level(p_iso);
if (scan_only) {
if (iso9660_ifs_get_volume_id(p_iso, &tmp)) {
safe_strcpy(iso_report.label, sizeof(iso_report.label), tmp);
safe_free(tmp);
} else
iso_report.label[0] = 0;
} else {
if (iso_extension_mask & (ISO_EXTENSION_JOLIET|ISO_EXTENSION_ROCK_RIDGE))
uprintf("This image will be extracted using %s extensions (if present)",
(iso_extension_mask & ISO_EXTENSION_JOLIET)?"Joliet":"Rock Ridge");
else
uprintf("This image will not be extracted using any ISO extensions");
}
r = iso_extract_files(p_iso, "");
out:
iso_blocking_status = -1;
if (scan_only) {
// Remove trailing spaces from the label
for (j=(int)safe_strlen(iso_report.label)-1; ((j>=0)&&(isspaceU(iso_report.label[j]))); j--)
iso_report.label[j] = 0;
// We use the fact that UDF_BLOCKSIZE and ISO_BLOCKSIZE are the same here
iso_report.projected_size = total_blocks * ISO_BLOCKSIZE;
// We will link the existing isolinux.cfg from a syslinux.cfg we create
// If multiple config files exist, choose the one with the shortest path
// (so that a '/syslinux.cfg' is preferred over a '/isolinux/isolinux.cfg')
if (!IsStrArrayEmpty(config_path)) {
safe_strcpy(iso_report.cfg_path, sizeof(iso_report.cfg_path), config_path.String[0]);
for (i=1; i<config_path.Index; i++) {
if (safe_strlen(iso_report.cfg_path) > safe_strlen(config_path.String[i]))
safe_strcpy(iso_report.cfg_path, sizeof(iso_report.cfg_path), config_path.String[i]);
}
uprintf("Will use %s for Syslinux\n", iso_report.cfg_path);
// Extract all of the isolinux.bin files we found to identify their versions
for (i=0; i<isolinux_path.Index; i++) {
size = (size_t)ExtractISOFile(src_iso, isolinux_path.String[i], dot_isolinux_bin);
if (size == 0) {
uprintf("Could not access %s\n", isolinux_path.String[i]);
} else {
buf = (char*)calloc(size, 1);
if (buf == NULL) break;
fd = fopen(dot_isolinux_bin, "rb");
if (fd == NULL) {
free(buf);
continue;
}
fread(buf, 1, size, fd);
fclose(fd);
for (k=0; k<size-16; k++) {
if (memcmp(&buf[k], ISOLINUX, sizeof(ISOLINUX)) == 0) {
k += sizeof(ISOLINUX);
sl_version = (((uint8_t)strtoul(&buf[k], &tmp, 10))<<8) + (uint8_t)strtoul(&tmp[1], NULL, 10);
开发者ID:JBTech,项目名称:rufus,代码行数:67,代码来源:iso.c
示例18: udf_extract_files
// Returns 0 on success, nonzero on error
static int udf_extract_files(udf_t *p_udf, udf_dirent_t *p_udf_dirent, const char *psz_path)
{
HANDLE file_handle = NULL;
DWORD buf_size, wr_size, err;
BOOL r, is_syslinux_cfg, is_old_c32[NB_OLD_C32];
int i_length;
size_t i, nul_pos;
char tmp[128], *psz_fullpath = NULL;
const char* psz_basename;
udf_dirent_t *p_udf_dirent2;
uint8_t buf[UDF_BLOCKSIZE];
int64_t i_read, i_file_length;
if ((p_udf_dirent == NULL) || (psz_path == NULL))
return 1;
while ((p_udf_dirent = udf_readdir(p_udf_dirent)) != NULL) {
if (FormatStatus) goto out;
psz_basename = udf_get_filename(p_udf_dirent);
if (strlen(psz_basename) == 0)
continue;
i_length = (int)(3 + strlen(psz_path) + strlen(psz_basename) + strlen(psz_extract_dir) + 24);
psz_fullpath = (char*)calloc(sizeof(char), i_length);
if (psz_fullpath == NULL) {
uprintf("Error allocating file name\n");
goto out;
}
i_length = _snprintf(psz_fullpath, i_length, "%s%s/%s", psz_extract_dir, psz_path, psz_basename);
if (i_length < 0) {
goto out;
}
if (udf_is_dir(p_udf_dirent)) {
if (!scan_only) _mkdirU(psz_fullpath);
p_udf_dirent2 = udf_opendir(p_udf_dirent);
if (p_udf_dirent2 != NULL) {
if (udf_extract_files(p_udf, p_udf_dirent2, &psz_fullpath[strlen(psz_extract_dir)]))
goto out;
}
} else {
i_file_length = udf_get_file_length(p_udf_dirent);
if (check_iso_props(psz_path, &is_syslinux_cfg, is_old_c32, i_file_length, psz_basename, psz_fullpath)) {
safe_free(psz_fullpath);
continue;
}
// Replace slashes with backslashes and append the size to the path for UI display
nul_pos = safe_strlen(psz_fullpath);
for (i=0; i<nul_pos; i++)
if (psz_fullpath[i] == '/') psz_fullpath[i] = '\\';
safe_sprintf(&psz_fullpath[nul_pos], 24, " (%s)", SizeToHumanReadable(i_file_length, TRUE, FALSE));
uprintf("Extracting: %s\n", psz_fullpath);
safe_sprintf(&psz_fullpath[nul_pos], 24, " (%s)", SizeToHumanReadable(i_file_length, FALSE, FALSE));
SetWindowTextU(hISOFileName, psz_fullpath);
// Remove the appended size for extraction
psz_fullpath[nul_pos] = 0;
for (i=0; i<NB_OLD_C32; i++) {
if (is_old_c32[i] && use_own_c32[i]) {
static_sprintf(tmp, "%s/syslinux-%s/%s", FILES_DIR, embedded_sl_version_str[0], old_c32_name[i]);
if (CopyFileA(tmp, psz_fullpath, FALSE)) {
uprintf(" Replaced with local version\n");
break;
}
uprintf(" Could not replace file: %s\n", WindowsErrorString());
}
}
if (i < NB_OLD_C32)
continue;
if (sanitize_filename(psz_fullpath))
uprintf(" File name sanitized to '%s'\n", psz_fullpath);
file_handle = CreateFileU(psz_fullpath, GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if (file_handle == INVALID_HANDLE_VALUE) {
err = GetLastError();
uprintf(" Unable to create file: %s\n", WindowsErrorString());
if ((err == ERROR_ACCESS_DENIED) && (safe_strcmp(&psz_fullpath[3], autorun_name) == 0))
uprintf(stupid_antivirus);
else
goto out;
} else while (i_file_length > 0) {
if (FormatStatus) goto out;
memset(buf, 0, UDF_BLOCKSIZE);
i_read = udf_read_block(p_udf_dirent, buf, 1);
if (i_read < 0) {
uprintf(" Error reading UDF file %s\n", &psz_fullpath[strlen(psz_extract_dir)]);
goto out;
}
buf_size = (DWORD)MIN(i_file_length, i_read);
for (i=0; i<WRITE_RETRIES; i++) {
ISO_BLOCKING(r = WriteFile(file_handle, buf, buf_size, &wr_size, NULL));
if ((!r) || (buf_size != wr_size)) {
uprintf(" Error writing file: %s", WindowsErrorString());
if (i < WRITE_RETRIES-1)
uprintf(" RETRYING...\n");
} else {
break;
}
}
if (i >= WRITE_RETRIES) goto out;
i_file_length -= i_read;
if (nb_blocks++ % PROGRESS_THRESHOLD == 0) {
//.........这里部分代码省略.........
开发者ID:JBTech,项目名称:rufus,代码行数:101,代码来源:iso.c
示例19: iso_extract_files
// Returns 0 on success, nonzero on error
static int iso_extract_files(iso9660_t* p_iso, const char *psz_path)
{
HANDLE file_handle = NULL;
DWORD buf_size, wr_size, err;
BOOL s, is_syslinux_cfg, is_old_c32[NB_OLD_C32], is_symlink;
int i_length, r = 1;
char tmp[128], psz_fullpath[1024], *psz_basename;
const char *psz_iso_name = &psz_fullpath[strlen(psz_extract_dir)];
unsigned char buf[ISO_BLOCKSIZE];
CdioListNode_t* p_entnode;
iso9660_stat_t *p_statbuf;
CdioList_t* p_entlist;
size_t i, j, nul_pos;
lsn_t lsn;
int64_t i_file_length;
if ((p_iso == NULL) || (psz_path == NULL))
return 1;
i_length = _snprintf(psz_fullpath, sizeof(psz_fullpath), "%s%s/", psz_extract_dir, psz_path);
if (i_length < 0)
return 1;
psz_basename = &psz_fullpath[i_length];
p_entlist = iso9660_ifs_readdir(p_iso, psz_path);
if (!p_entlist) {
uprintf("Could not access directory %s\n", psz_path);
return 1;
}
_CDIO_LIST_FOREACH(p_entnode, p_entlist) {
if (FormatStatus) goto out;
p_statbuf = (iso9660_stat_t*) _cdio_list_node_data(p_entnode);
// Eliminate . and .. entries
if ( (strcmp(p_statbuf->filename, ".") == 0)
|| (strcmp(p_statbuf->filename, "..") == 0) )
continue;
// Rock Ridge requires an exception
is_symlink = FALSE;
if ((p_statbuf->rr.b3_rock == yep) && enable_rockridge) {
safe_strcpy(psz_basename, sizeof(psz_fullpath)-i_length-1, p_statbuf->filename);
if (safe_strlen(p_statbuf->filename) > 64)
iso_report.has_long_filename = TRUE;
// libcdio has a memleak for Rock Ridge symlinks. It doesn't look like there's an easy fix there as
// a generic list that's unaware of RR extensions is being used, so we prevent that memleak ourselves
is_symlink = (p_statbuf->rr.psz_symlink != NULL);
if (is_symlink)
iso_report.has_symlinks = TRUE;
if (scan_only)
safe_free(p_statbuf->rr.psz_symlink);
} else {
iso9660_name_translate_ext(p_statbuf->filename, psz_basename, i_joliet_level);
}
if (p_statbuf->type == _STAT_DIR) {
if (!scan_only) _mkdirU(psz_fullpath);
if (iso_extract_files(p_iso, psz_iso_name))
goto out;
} else {
i_file_length = p_statbuf->size;
if (check_iso_props(psz_path, &is_syslinux_cfg, is_old_c32, i_file_length, psz_basename, psz_fullpath)) {
continue;
}
// Replace slashes with backslashes and append the size to the path for UI display
nul_pos = safe_strlen(psz_fullpath);
for (i=0; i<nul_pos; i++)
if (psz_fullpath[i] == '/') psz_fullpath[i] = '\\';
safe_sprintf(&psz_fullpath[nul_pos], 24, " (%s)", SizeToHumanReadable(i_file_length, TRUE, FALSE));
uprintf("Extracting: %s\n", psz_fullpath);
safe_sprintf(&psz_fullpath[nul_pos], 24, " (%s)", SizeToHumanReadable(i_file_length, FALSE, FALSE));
SetWindowTextU(hISOFileName, psz_fullpath);
// ISO9660 cannot handle backslashes
for (i=0; i<nul_pos; i++) if (psz_fullpath[i] == '\\') psz_fullpath[i] = '/';
psz_fullpath[nul_pos] = 0;
for (i=0; i<NB_OLD_C32; i++) {
if (is_old_c32[i] && use_own_c32[i]) {
static_sprintf(tmp, "%s/syslinux-%s/%s", FILES_DIR, embedded_sl_version_str[0], old_c32_name[i]);
if (CopyFileA(tmp, psz_fullpath, FALSE)) {
uprintf(" Replaced with local version\n");
break;
}
uprintf(" Could not replace file: %s\n", WindowsErrorString());
}
}
if (i < NB_OLD_C32)
continue;
if (sanitize_filename(psz_fullpath))
uprintf(" File name sanitized to '%s'\n", psz_fullpath);
if (is_symlink) {
if (i_file_length == 0)
uprintf(" Ignoring Rock Ridge symbolic link to '%s'\n", p_statbuf->rr.psz_symlink);
safe_free(p_statbuf->rr.psz_symlink);
}
file_handle = CreateFileU(psz_fullpath, GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if (file_handle == INVALID_HANDLE_VALUE) {
err = GetLastError();
uprintf(" Unable to create file: %s\n", WindowsErrorString());
if ((err == ERROR_ACCESS_DENIED) && (safe_strcmp(&psz_fullpath[3], autorun_name) == 0))
uprintf(stupid_antivirus);
//.........这里部分代码省略.........
开发者ID:JBTech,项目名称:rufus,代码行数:101,代码来源:iso.c
示例20: FileDialog
//.........这里部分代码省略.........
// Display the dialog
hr = pfd->lpVtbl->Show(pfd, hMainDialog);
// Cleanup
safe_free(wfilename);
for (i = 0; i < ext->count; i++) {
safe_free(filter_spec[i].pszSpec);
safe_free(filter_spec[i].pszName);
}
safe_free(filter_spec);
if (SUCCEEDED(hr)) {
// Obtain the result of the user's interaction with the dialog.
hr = pfd->lpVtbl->GetResult(pfd, &psiResult);
if (SUCCEEDED(hr)) {
hr = psiResult->lpVtbl->GetDisplayName(psiResult, SIGDN_FILESYSPATH, &wpath);
if (SUCCEEDED(hr)) {
filepath = wchar_to_utf8(wpath);
CoTaskMemFree(wpath);
} else {
SetLastError(hr);
dprintf("Unable to access file path: %s\n", WindowsErrorString());
}
psiResult->lpVtbl->Release(psiResult);
}
} else if ((hr & 0xFFFF) != ERROR_CANCELLED) {
// If it's not a user cancel, assume the dialog didn't show and fallback
SetLastError(hr);
dprintf("Could not show FileOpenDialog: %s\n", WindowsErrorString());
goto fallback;
}
pfd->lpVtbl->Release(pfd);
dialog_showing--;
return filepath;
}
fallback:
safe_free(filter_spec);
if (pfd != NULL) {
pfd->lpVtbl->Release(pfd);
}
memset(&ofn, 0, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = hMainDialog;
// Selected File name
static_sprintf(selected_name, "%s", (ext->filename == NULL) ? "" : ext->filename);
ofn.lpstrFile = selected_name;
ofn.nMaxFile = MAX_PATH;
// Set the file extension filters
all_files = "All files";
ext_strlen = 0;
for (i = 0; i<ext->count; i++) {
ext_strlen += safe_strlen(ext->description[i]) + 2 * safe_strlen(ext->extension[i]) + sizeof(" ()\r\r");
}
ext_strlen += safe_strlen(all_files) + sizeof(" (*.*)\r*.*\r");
ext_string = (char*)malloc(ext_strlen + 1);
if (ext_string == NULL)
return NULL;
ext_string[0] = 0;
for (i = 0, j = 0; i<ext->count; i++) {
j += _snprintf(&ext_string[j], ext_strlen - j, "%s (%s)\r%s\r", ext->description[i], ext->extension[i], ext->extension[i]);
}
j = _snprintf(&ext_string[j], ext_strlen - j, "%s (*.*)\r*.*\r", all_files);
// Microsoft could really have picked a better delimiter!
for (i = 0; i<ext_strlen; i++) {
// Since the VS Code Analysis tool is dumb...
#if defined(_MSC_VER)
#pragma warning(suppress: 6385)
#endif
if (ext_string[i] == '\r') {
#if defined(_MSC_VER)
#pragma warning(suppress: 6386)
#endif
ext_string[i] = 0;
}
}
ofn.lpstrFilter = ext_string;
ofn.nFilterIndex = 1;
ofn.lpstrInitialDir = path;
ofn.Flags = OFN_OVERWRITEPROMPT | options;
// Show Dialog
if (save) {
r = GetSaveFileNameU(&ofn);
} else {
r = GetOpenFileNameU(&ofn);
}
if (r) {
filepath = safe_strdup(selected_name);
} else {
tmp = CommDlgExtendedError();
if (tmp != 0) {
dprintf("Could not select file for %s. Error %X\n", save ? "save" : "open", tmp);
}
}
safe_free(ext_string);
dialog_showing--;
return filepath;
}
开发者ID:pbatard,项目名称:libwdi,代码行数:101,代码来源:zadig_stdlg.c
注:本文中的safe_strlen函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论