Skip to content

Instantly share code, notes, and snippets.

//
// Copyright (c) 2024 Jeff Garzik
//
// This file is part of the posixutils-rs project covered under
// the MIT License. For the full license text, please see the LICENSE
// file in the root directory of this project.
// SPDX-License-Identifier: MIT
//
extern crate clap;
@jgarzik
jgarzik / patch
Created April 21, 2024 02:10
file(1) magic file patch
diff --git a/file/src/file.rs b/file/src/file.rs
index 39c0aeb..fadce24 100644
--- a/file/src/file.rs
+++ b/file/src/file.rs
@@ -25,6 +25,10 @@ use std::{
#[derive(Parser, Debug)]
#[command(author, version, about, long_about, disable_help_flag = true)]
struct Args {
+ /// Restore --help
+ #[arg(long, action = clap::ArgAction::HelpLong)]
@jgarzik
jgarzik / enum_grp3.rs
Created April 17, 2024 03:18
Enumerate groups, try 3 (working)
extern crate libc;
use libc::{endgrent, getgrent, setgrent, group};
use std::ffi::CStr;
use std::ptr;
struct Group {
name: String,
passwd: String,
gid: libc::gid_t,
members: Vec<String>,
@jgarzik
jgarzik / enum_grp1.rs
Created April 17, 2024 01:45
enumerate groups, Take One (chatGPT edition)
extern crate libc;
use libc::{group, setgrent, getgrent, endgrent, gid_t};
use std::ffi::CStr;
use std::ptr;
struct Group {
name: String,
passwd: String,
gid: gid_t,
members: Vec<String>,
@jgarzik
jgarzik / enum_grp2.rs
Created April 17, 2024 01:43
enumerage groups, Take Two
fn enumerate_groups() {
let mut groupent: *mut libc::group;
unsafe {
setgrent();
groupent = getgrent();
}
while groupent != ptr::null_mut() {
let c_str: &CStr = unsafe { CStr::from_ptr((*groupent).gr_name) };
println!("{}", c_str.to_str().unwrap());
unsafe {
@jgarzik
jgarzik / zcat.cc
Created February 28, 2018 06:21
Decompress gzip files to stdout
#include <stdio.h>
#include <stdexcept>
#include <unistd.h>
#include <fcntl.h>
#include <string>
#include <vector>
#include <string.h>
#include <assert.h>
#include <zlib.h>
@jgarzik
jgarzik / zcat.cc
Created February 28, 2018 05:57
Decompress gzip file to stdout
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <string>
#include <vector>
#include <assert.h>
#include <zlib.h>
using namespace std;
@jgarzik
jgarzik / BidiPipe.h
Created February 15, 2018 02:07
Bi-directional pipe as thread queue
#ifndef __SRV_BIDIPIPE_H__
#define __SRV_BIDIPIPE_H__
#include "Util.h"
#ifndef ARRAYLEN
#define ARRAYLEN(array) (sizeof(array)/sizeof((array)[0]))
#endif // ARRAYLEN
class BidiPipe {
@jgarzik
jgarzik / eth-tx-prefix.cc
Created February 11, 2018 04:21
Reverse iterated index for latest per-account activity
/*
Build:
g++ -std=c++11 -O -Wall -g -o eth-tx-prefix eth-tx-prefix.cc -lrocksdb
Run:
./eth-tx-prefix
Clean: