Rewrite the following C program using only system calls such as open, close, read, write, clear, loctl, etc. Don't use calls from C or C++ libraries uncluding cout, cin, printf, scanf, etc.
Rewrite the following C program using only system calls such as open, close, read, write, clear, loctl, etc. Don't use calls from C or C++ libraries uncluding cout, cin, printf, scanf, etc.
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Question
Rewrite the following C program using only system calls such as open, close, read, write, clear, loctl, etc. Don't use calls from C or C++ libraries uncluding cout, cin, printf, scanf, etc.
![// Filename: cpfile.c
// Compile command: gcc cpfile.c -o cpfile.exe
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
zude kunista
#define SIZ 128
// Copy from source file to target file. Adapted from The C Programming Language
// by Kernighan and Ritchie.
int main(int argc, const char *argv[]) {
int f1, f2;
// Do we have right number of arguments?
if (argc != 3){
printf("Wrong number of command line arguments\n");
7 exit(1);
return 1;
// Can we access thge source file?
if ((f1 = open(argv[1], O_RDONLY, 0)) == -1){
printf("Can't open %s \n", argv[1]);
return 2;
}L
// Can we create the target file?
if ((f2 = creat(argv[2], 0644)) == -1){
printf("Can't create %s \n", argv[2]);
return 3;
// Copy source file contents to target file.
char buf[SIZ];
int n;
while ((n = read( f1, buf, SIZ)) > 0)
if (write(f2, buf, n) != n)
printf("Can 't write file" );
close(f1);
close(f2);
return 4;
close(f1);
close(f2);
write("Success!" );
return 0;
}](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F478ce0d3-4168-475a-84e9-9324916e2ac3%2F7304839d-f80d-45cf-a495-3bf7d6668e04%2F1aykd5g_processed.png&w=3840&q=75)
Transcribed Image Text:// Filename: cpfile.c
// Compile command: gcc cpfile.c -o cpfile.exe
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
zude kunista
#define SIZ 128
// Copy from source file to target file. Adapted from The C Programming Language
// by Kernighan and Ritchie.
int main(int argc, const char *argv[]) {
int f1, f2;
// Do we have right number of arguments?
if (argc != 3){
printf("Wrong number of command line arguments\n");
7 exit(1);
return 1;
// Can we access thge source file?
if ((f1 = open(argv[1], O_RDONLY, 0)) == -1){
printf("Can't open %s \n", argv[1]);
return 2;
}L
// Can we create the target file?
if ((f2 = creat(argv[2], 0644)) == -1){
printf("Can't create %s \n", argv[2]);
return 3;
// Copy source file contents to target file.
char buf[SIZ];
int n;
while ((n = read( f1, buf, SIZ)) > 0)
if (write(f2, buf, n) != n)
printf("Can 't write file" );
close(f1);
close(f2);
return 4;
close(f1);
close(f2);
write("Success!" );
return 0;
}
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images

Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you

Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON

Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education