{"id":25449805,"url":"https://github.com/pol-cova/copy-command","last_synced_at":"2026-05-18T19:33:39.700Z","repository":{"id":277488742,"uuid":"932582052","full_name":"pol-cova/copy-command","owner":"pol-cova","description":"Simple implementations of the copy command in C and Rust, focusing on file I/O operations, error handling, and performance in both.","archived":false,"fork":false,"pushed_at":"2025-02-14T07:13:31.000Z","size":902,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-16T09:07:40.327Z","etag":null,"topics":["c","low-level","low-level-programming","rust"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pol-cova.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-02-14T06:30:17.000Z","updated_at":"2025-02-16T23:14:20.000Z","dependencies_parsed_at":"2025-02-14T07:39:56.121Z","dependency_job_id":null,"html_url":"https://github.com/pol-cova/copy-command","commit_stats":null,"previous_names":["pol-cova/copy-command"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/pol-cova/copy-command","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pol-cova%2Fcopy-command","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pol-cova%2Fcopy-command/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pol-cova%2Fcopy-command/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pol-cova%2Fcopy-command/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pol-cova","download_url":"https://codeload.github.com/pol-cova/copy-command/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pol-cova%2Fcopy-command/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":274194941,"owners_count":25239146,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-08T02:00:09.813Z","response_time":121,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["c","low-level","low-level-programming","rust"],"created_at":"2025-02-17T21:19:12.816Z","updated_at":"2026-05-18T19:33:34.664Z","avatar_url":"https://github.com/pol-cova.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Copy Command\n\n## How it works?\nThis command copies a file by **reading it in small chunks** (4 KB at a time) and writing each chunk to a new file. If you imagine a **16 KB file**, it is split into **four 4 KB blocks**, which are read and written one by one until the entire file is copied.\n\n## 📊 Workflow Diagram\n```mermaid\ngraph TD;\n    A(Start) --\u003e B(Open source file);\n    B --\u003e|Success| C(Open destination file);\n    B --\u003e|Failure| X(Print error and exit);\n    \n    C --\u003e|Success| D{Read up to 4096 bytes};\n    C --\u003e|Failure| Y(Print error, close source file, exit);\n    \n    D --\u003e|Read \u003e 0| E{Bytes left to write?};\n    D --\u003e|Read failed| Z(Print error, close files, exit);\n    \n    E --\u003e|Yes| F(Write bytes to destination);\n    E --\u003e|No| D;\n    \n    F --\u003e|Success| E;\n    F --\u003e|Failure| W(Print error, close files, exit);\n    \n    D --\u003e|Read == 0| G(Close source file);\n    G --\u003e H(Close destination file);\n    H --\u003e I(End);\n\n    X --\u003e|Exit| X1[Stop];\n    Y --\u003e|Exit| Y1[Stop];\n    Z --\u003e|Exit| Z1[Stop];\n    W --\u003e|Exit| W1[Stop];\n```\n\n## 🚀 How to Run\n### 1️⃣ Compile the program\n\n**For C:**\n```sh\ngcc copy.c -o copy\n```\n**For Rust:**\n```sh\ncd copy\ncargo build --release\nmv target/release/copy .\n```\n\n### 2️⃣ Run the command\n```sh\n./copy source.txt destination.txt\n```\n\nReplace `source.txt` with the file you want to copy and `destination.txt` with the output file.\n\n### 3️⃣ Option: Move the binary to a system path\nOnce the binary is built, move it to a directory that is included in your system's `$PATH`, such as `/usr/local/bin`:\n```sh\nsudo mv copy /usr/local/bin/\nsudo chmod +x /usr/local/bin/copy\n```\n📌 **Explanation:**\n\n- `mv copy /usr/local/bin/` → Moves the binary to a globally accessible location.\n- `chmod +x /usr/local/bin/copy` → Ensures it's executable.\nNow you can run the command from any directory.\n```sh\ncopy file1.txt file2.txt\n```\n\n## 🛠 Error Handling\n- If the source file **doesn’t exist**, the program exits with an error.\n- If there’s an issue **writing to the destination file**, it also exits with an error.\n- All files are **closed properly** after copying to avoid resource leaks.\n\n## 📌 Notes\n- Uses a **4 KB buffer size** for efficiency.\n- Works on **Unix-based systems** (Linux/macOS).\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpol-cova%2Fcopy-command","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpol-cova%2Fcopy-command","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpol-cova%2Fcopy-command/lists"}