Skip to main content

write_directory_entry

Function write_directory_entry 

Source
pub fn write_directory_entry(
    buf: &mut [u8],
    pos: usize,
    offsets: EntryOffsets,
    name: &str,
    prev_entry_offset: Option<usize>,
) -> Option<usize>
Expand description

Writes one synthetic directory entry (an injected mod-only filename) at buf[pos..], matching the layout the original inline code built: zeroed header, NextEntryOffset left at 0 (patched later, on the previous entry, once this one is known to exist, see prev_entry_offset below), FileAttributes set to FILE_ATTRIBUTE_NORMAL when this info class has that field (offsets.file_name >= 60 mirrors the original’s name_off >= 60 check, every supported class with a file_name offset that high also has file_attributes at byte 56), FileNameLength, and the name itself.

If prev_entry_offset is Some, that earlier entry’s NextEntryOffset is patched to point at this one, the equivalent of the original loop’s prev_entry_ptr bookkeeping.

Returns None (writing nothing) if the entry wouldn’t fit in buf[pos..], matching the original’s if write_ptr + entry_size > buf_end { break; } check, callers should stop injecting further entries when this returns None, same as the original loop did.