Skip to content

Instantly share code, notes, and snippets.

View ChrisDenton's full-sized avatar

Chris Denton ChrisDenton

View GitHub Profile

In Windows there are essentially two types of allocations:

  1. Reserve sets aside a chunk of the process' virtual memory so that it won't be used by other allocations. It does not do anything else. There are no limits to the size, except that it can't overlap other reserved or committed memory virtual memory.
  2. Commit allocates an area of reserved memory. The system's total amount of committed memory must be less than physical memory plus maximum page file size. However, this memory might not be physically allocated until a page is actually written to.
/// Turns an &[u8] into an &[u8; _]
macro_rules! try_from_slice {
($bytes:expr) => {{
enum Ns {}
impl<'a> Ns {
const BYTES: &'a[u8] = $bytes;
}
type T = [u8; Ns::BYTES.len()];
// Saftey: We know the length is in bounds.
unsafe {
use std::fs::{self, OpenOptions};
use std::io::{self, Write};
fn main() -> io::Result<()> {
// The directory.
let mut dir: String = "./directory".into();
fs::create_dir_all(&dir)?;
// Confirm the directory is a directory.
let is_dir = fs::metadata(&dir)?.file_type().is_dir();
/// Never create or use this struct directly.
#[repr(C)]
pub struct RenameInfoW {
_flags: u32,
_root_dir: *const std::ffi::c_void,
_name_length: u32,
_name: [u16; 1],
}
impl RenameInfoW {
const FLAGS_OFFSET: usize = 0;
use std::fs;
use std::path::Path;
use std::io;
use std::env;
use std::ffi::OsString;
use std::os::windows::ffi::OsStringExt;
fn main() -> io::Result<()> {
let files = [r"bar", r"\bar", r"..\bar", r".\bar", r".\", r"..\", r"\", r"D:bar"];
let directories = [