X-Git-Url: https://wimlib.net/git/?a=blobdiff_plain;f=src%2Fntfs-3g_apply.c;h=b8aabe866e3c2f68d9fc284553e7d89c4065c9fa;hb=3d84c998673ba7acf82ec5c26769a41e28a2cc7b;hp=39509fc1d5157f5ae338237d6864596c28b33177;hpb=ac2f455531e39641bedca08ab510a8c1d09ba125;p=wimlib diff --git a/src/ntfs-3g_apply.c b/src/ntfs-3g_apply.c index 39509fc1..b8aabe86 100644 --- a/src/ntfs-3g_apply.c +++ b/src/ntfs-3g_apply.c @@ -40,6 +40,12 @@ #include #include +#ifdef HAVE_ALLOCA_H +# include +#else +# include +#endif + #include "wimlib/apply.h" #include "wimlib/encoding.h" #include "wimlib/error.h" @@ -86,18 +92,13 @@ ntfs_3g_extract_wim_chunk(const void *buf, size_t len, void *_ctx) static ntfs_inode * ntfs_3g_open_parent_inode(const char *path, ntfs_volume *vol) { - char orig, *p; + char *p; ntfs_inode *dir_ni; - p = strchr(path, '\0'); - do { - p--; - } while (*p != '/'); - - orig = *p; + p = strrchr(path, '/'); *p = '\0'; dir_ni = ntfs_pathname_to_inode(vol, NULL, path); - *p = orig; + *p = '/'; return dir_ni; } @@ -177,7 +178,6 @@ ntfs_3g_create_hardlink(const char *oldpath, const char *newpath, &name_utf16le, &name_utf16le_nbytes); if (ret) goto out_close_dir_ni; - ret = 0; if (ntfs_link(ni, dir_ni, name_utf16le, name_utf16le_nbytes / 2)) ret = WIMLIB_ERR_NTFS_3G; @@ -196,7 +196,7 @@ out: * Extract a stream (default or alternate data) to an attribute of a NTFS file. */ static int -ntfs_3g_extract_stream(const char *path, const utf16lechar *stream_name, +ntfs_3g_extract_stream(const char *path, const utf16lechar *raw_stream_name, size_t stream_name_nchars, struct wim_lookup_table_entry *lte, struct apply_ctx *ctx) { @@ -204,11 +204,16 @@ ntfs_3g_extract_stream(const char *path, const utf16lechar *stream_name, ntfs_attr *na; int ret; struct ntfs_attr_extract_ctx extract_ctx; - utf16lechar stream_name_copy[stream_name_nchars + 1]; - - memcpy(stream_name_copy, stream_name, - stream_name_nchars * sizeof(utf16lechar)); - stream_name_copy[stream_name_nchars] = 0; + utf16lechar *stream_name; + + if (stream_name_nchars == 0) { + stream_name = AT_UNNAMED; + } else { + stream_name = alloca((stream_name_nchars + 1) * sizeof(utf16lechar)); + memcpy(stream_name, raw_stream_name, + stream_name_nchars * sizeof(utf16lechar)); + stream_name[stream_name_nchars] = 0; + } ret = 0; if (!stream_name_nchars && !lte) @@ -223,7 +228,7 @@ ntfs_3g_extract_stream(const char *path, const utf16lechar *stream_name, /* Add the stream if it's not the default (unnamed) stream. */ ret = WIMLIB_ERR_NTFS_3G; if (stream_name_nchars) - if (ntfs_attr_add(ni, AT_DATA, stream_name_copy, + if (ntfs_attr_add(ni, AT_DATA, stream_name, stream_name_nchars, NULL, 0)) goto out_close; @@ -234,7 +239,7 @@ ntfs_3g_extract_stream(const char *path, const utf16lechar *stream_name, /* Open the stream (NTFS attribute). */ ret = WIMLIB_ERR_NTFS_3G; - na = ntfs_attr_open(ni, AT_DATA, stream_name_copy, stream_name_nchars); + na = ntfs_attr_open(ni, AT_DATA, stream_name, stream_name_nchars); if (!na) goto out_close;