1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
snow_tiger [21]
3 years ago
9

Write a C program to implement a command called ​displaycontent ​that takes a (text) file name as argument and display its conte

nts. Report an appropriate message if the file does not exist or can’t be opened (i.e. the file doesn’t have read permission). You are to use ​open()​, ​read()​, ​write() ​and
Computers and Technology
1 answer:
Zanzabum3 years ago
7 0

Answer:

/*

Student: Hugo Meza

Date: February 15, 2019

Description: This program mimic the cat command from Linux. Checks whether the source file

has the right permissions, and then writes in the console its content.

*/

#include <stdio.h>

#include <fcntl.h>

#include <unistd.h>

#include <errno.h>

int hasPermission(char *filepath){

int returnval;

// Check file existence

returnval = access (filepath, F_OK);

if(errno == ENOENT){

printf ("%s does not exist\n", filepath);

return 0;

}

else if (errno == EACCES){

printf ("%s is not accessible\n", filepath);

return 0;

}

// Check read access

returnval = access (filepath, R_OK);

if(errno == ENOENT){

printf ("%s does not have read access\n", filepath);

return 0;

}

else if (errno == EACCES){

printf ("%s is not accessible\n",filepath);

return 0;

}

// Check write access

returnval = access (filepath, W_OK);

if(errno == ENOENT){

printf ("%s does not have read access\n", filepath);

return 0;

}

else if (errno == EACCES){

printf ("%s is not accessible\n",filepath);

return 0;

}

return 1;

}

int main(int argc, char* argv[]){

if(!argv[1]){

printf("Error. Specify file to open\n");

return 0;

}

int fd;

char *fp = argv[1], content[fd];

if(hasPermission(fp) == 0)

return 1;

fd = open(fp, O_RDONLY);

int bytes = read(fd,content,sizeof(content)-1);

write(1, content, bytes);

close(fd);

return 0;

}

Explanation:

You might be interested in
Which of the following is not true about network design?Group of answer choicesIn designing LAN networks, network designers tend
sergey [27]

Answer:

In designing LAN networks, network designers tend to design err on the side of providing for less capacity than what is currently necessary.

Explanation:

In designing LAN networks, network designers tend to design err on the side of providing for less capacity than what is currently necessary is not true about network design.

8 0
3 years ago
Describe the Pros and Cons Associated with Cloud Computing Cloud Computing was introduced in 1999 by a company named "Salesforce
Rudik [331]

Answer & Explanation:

Pros of cloud computing:

  • Cloud computing provides high speed due to faster deployment of services in fewer clicks.
  • It eliminates the need of IT infrastructure and manageability.
  • It is cost efficient as it provides huge space availability.
  • It makes it easy to get backup and recovery.
  • It is easy to access information anytime and anywhere in the world.
  • Due to cloud computing, it is very easy to add or remove services as required.

Cons of cloud computing:

  • It makes the data vulnerable and information theft challenges can be encountered.
  • Internet connection is required all the time.
  • There is less control available as it runs on remote servers.
  • Migrating information can become difficult.
  • It can face technical issues so the information will not be available for a limited time.
7 0
3 years ago
Brainly, ""helping you get better grades"
leonid [27]

Answer: What do you except? All of this is user generated..

Explanation:

5 0
3 years ago
Read 2 more answers
How long after activating comcast set top box before getting channels??
rjkz [21]
It usually takes about 45 minutes.
6 0
3 years ago
Which type of security measure reduces the effect of an attack by using data backups, disaster recovery plans, and the availabil
Mars2501 [29]
If I'm not mistaken firewalls should be enough as now the automatically  back up all data
4 0
3 years ago
Other questions:
  • You are reluctant to write an extra credit book report because you are afraid that your language and punctuation skills are not
    11·1 answer
  • When naming a file you should use the _____________ instead of a space in a filename.
    6·1 answer
  • The vast amount of data collected from Internet searches, social media posts, customer transactions, military
    8·1 answer
  • Validating the results of a program is important to a. correct runtime errors b. make sure the program solves the original probl
    8·1 answer
  • When you're working with a word processing document and you press the DEL Key what happens
    7·2 answers
  • You will implement three different types of FFs with two different reset types. You have to show your results on your FPGA. You
    9·1 answer
  • Yall like portal 1 or 2
    8·1 answer
  • What is the first step that you have to perform before you can add a windows package to a wim file?
    9·1 answer
  • Can you move it like this? I can shake it like that
    6·1 answer
  • What is the meaning of FTTH
    9·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!