c++ (create cat.cpp) implement your own version of the cat systems program, a st
ID: 3865022 • Letter: C
Question
c++ (create cat.cpp) implement your own version of the cat systems program, a standard Unix utility that reads files sequentially, writing them to standard output. The name is derived from its function to concatenate files.
When user types in command cat – filename.txt, it allows user to enter an input and the system will echo back the user input. When ctrl + d is pressed, it exits out of cat mode and displays the contents of the file.
When user types in command cat filename.txt file1.txt, it will concatenate the contents of file and file1 and display the contents of both files.
You are NOT allowed to use the exec, system, popen, and pclose system calls or functions in your implementation. You are not allowed to call the existing cat implementation. You must supply your own implementation that uses low-level I/O. Low-level file I/O is a requirement.
Explanation / Answer
#!/bin/bash
# Author: Vivek Gite <http://www.cyberciti.biz/
# -----------------------------------------------#Set default to my-dev-box
BASEDIR="/home/vivek/projects/bash/nginx-keepalived/chroot"# Now switch to prod
[[ $HOSTNAME == "lb2.nixcraft.net.in" ]] && BASEDIR="/etc/nixcraft/nginx/lb2"
[[ $HOSTNAME == "lb2.nixcraft.net.in" ]] && BASEDIR="/etc/nixcraft/nginx/lb1"_profile="$BASEDIR/redhat.conf"
_etc_files="$BASEDIR/redhat.etc.files.conf"
_etc_dirs="$BASEDIR/redhat.etc.dirs.conf"
_hooks="$BASEDIR/hooks.sh"usage(){
cat<<EOF
Usage $0
-e | --enable: Enable the nginx-chroot environment
-E | --upgrade: Upgrade bind and libs in the nginx-chroot environment
-p | --php: Enable the php-cgi in the nginx-chroot environment
-P | --phpupgrade: Upgrade the php-cgi in the nginx-chroot environment
-i | --info: Display the php-cgi and nginx environment information such as version, users, connections etc
EOF
}rootuser(){
local uid=$(id -u)
[[ $uid -ne 0 ]] && { echo "Only root may enable the nginx-chroot environment to the system."; exit 2; }
}## function code removed to keep script short and sweet ##
enable_nginix_chroot(){
:
}
upgrade_nginx_chroot(){
:
}
enable_php_cgi_nginx_chroot(){
:
}
upgrade_php_cgi_nginx_chroot(){
:
}get_nginx_chroot_info(){
:
}# Make sure only root run this script
rootuser# Load local hooks
[ -f "${_hooks}" ] && . ${_hooks}# Load os specifc paths
source ${_profile}# Main logic
case $1 in
-e|--enable) enable_nginix_chroot ;;
-E|--upgrade) upgrade_nginx_chroot;;
-p|--php) enable_php_cgi_nginx_chroot;;
-P|--phpupgrade) upgrade_php_cgi_nginx_chroot;;
-i|--info) get_nginx_chroot_info;;
*) usage; exit 9999;
esac
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.