1.5 KiB
1.5 KiB
📄 mycp – A Simple File Copy Utility in C
mycp is a basic implementation of the Unix cp command written in C.
It copies the contents of one file into another, handling errors and signals safely.
📦 Project Structure
mycp/
├── mycp.c # Main program source
├── Makefile # Build and test automation
└── test/
└── run_tests.sh # Automated test and Valgrind report
⚙️ Build Instructions
To compile the program:
make
To clean up build files:
make clean
To remove test artifacts as well:
make distclean
🧪 Running Tests
The test script:
- Creates temporary test files
- Runs
mycpand compares results withcmp - Uses Valgrind to check for memory issues
Run the tests with:
make test
🚀 Usage
./mycp SOURCE DEST
SOURCE: Path to the file to copy from.DEST: Path to the file to copy to.
Example:
./mycp input.txt output.txt
🧠 Learning Objectives
- Open/read/write/close file descriptors
- Use of
open(2),read(2),write(2), andclose(2) - Error handling (
perror,errno) - Use of
Makefileand basic testing with shell scripts - Optional: use of
lseekfor advanced length computation
✅ Requirements
- GCC (C11)
- POSIX-compliant system (Linux, macOS)
- Valgrind for memory leak analysis (optional, used in tests)
📄 License
Educational use only. No license required.