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
Google analytics is an example of which of the followinga) search engine
mart [117]
Google Analytics works on statistics. It allows businesses/websites to get an insight into what their customer's needs and wants are. 
Out of the answers you've given, I would say it is a site Management Tool. 

Cancelling out: (and reasons for cancelling them) 
Search Engine - Google on its own is a search engine, however, Analytics is a 'Subsidiary' if you will. 
Google Chrome is a Web Browser - Not the sector of Google Analytics. 
Security Services - It does not encrypt anything (or make anything safer for users) 


4 0
3 years ago
A(n) _____ is a flexible tool used to analyze data using reports that do not have a predetermined format.
Mandarinka [93]

Answer:

decision support system

Explanation:

4 0
3 years ago
_______________, such as BASIC, Python, Java, Prolog, and C , make the programming process easier by replacing unintelligible st
musickatia [10]

Answer:

High level Languages

Explanation:

High level languages are made so that the byte code, Assembly code that computers can understand should be converted into a higher level human understandable languages such as Python,C++. Also, remember that the compilers of these languages such as Visual studio ultimately converts the high level code into low level code ( Assembly code ) that computers can understand.

8 0
3 years ago
3.4 lesson practice
Strike441 [17]

Answer:

The answer is A. Second Half of the month.

Explanation:

If Im reffering right to the source. So If you doing Chapter 3 Comp. Science. Than this is right.

7 0
3 years ago
Read 2 more answers
While conducting routine maintenance, you discover a network server that needs to
patriot [66]

Answer:

tell the truth and make other people aware of what is going on inorder for them to also be hands on deck and come up with solutions to also help solve the problem

3 0
2 years ago
Other questions:
  • What are Three types of informational references
    9·2 answers
  • Write the pseudo code to display the largest number from given 3 numbers.(n1,n2,n3,).
    10·1 answer
  • The human resource (HR) manager stores a spreadsheet with sensitive personal information on her local workstation. The spreadshe
    11·1 answer
  • Type the correct answer in the box. In which phishing technique are URLs of the spoofed organization misspelled? _____ is a phis
    11·1 answer
  • Write a function named "higher_lower" that takes an int as a parameter and returns "higher" if 14 is greater than the input and
    11·1 answer
  • What is the main type of energy used to help convert metamorphic rocks into igneous rocks in the rock cycle ?
    10·1 answer
  • Question 9 (1 point)
    14·1 answer
  • What are the five generations of computers?​
    13·1 answer
  • (Brainliest!!)<br><br> How do i get rid of a headache?
    15·2 answers
  • If a while loop iterates forever,what is the most likely cause?
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!