LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 07-16-2009, 04:16 AM   #1
barunparichha
Member
 
Registered: Jun 2006
Location: Bangalore,india
Distribution: Linux(Redhat,fedora,suse,ubantu), Solaris (s8/s9/s10/nevada/open-solaris)
Posts: 303

Rep: Reputation: 32
C API to check if file has a link or not


I need a C API to check, if the file has a link or not.
The requirement is as follows:
1. To write a prog in C, which accepts file name as input and decides, if the input is a link file or not. I don't want to use any system command in my prog.
 
Old 07-16-2009, 04:26 AM   #2
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
Per the LQ Rules, please do not post homework assignments verbatim. We're happy to assist if you have specific questions or have hit a stumbling point, however. Let us know what you've already tried and what references you have used (including class notes, books, and Google searches) and we'll do our best to help. Also, keep in mind that your instructor might also be an LQ member.
 
Old 07-16-2009, 04:35 AM   #3
barunparichha
Member
 
Registered: Jun 2006
Location: Bangalore,india
Distribution: Linux(Redhat,fedora,suse,ubantu), Solaris (s8/s9/s10/nevada/open-solaris)
Posts: 303

Original Poster
Rep: Reputation: 32
Hi Moderator,
This is not a home asignment, but I need this API for a Solairs cluster.

I know some of the answers, but they are not suitable for the envirment I use.

I thought of getting a quick answer from genius like you.
Even if I am not getting any response, I will post the answer so that someone like me would be benefited in future.


Thanks,
Barun
 
Old 07-16-2009, 06:49 AM   #4
barunparichha
Member
 
Registered: Jun 2006
Location: Bangalore,india
Distribution: Linux(Redhat,fedora,suse,ubantu), Solaris (s8/s9/s10/nevada/open-solaris)
Posts: 303

Original Poster
Rep: Reputation: 32
Solution: ............

This one of the ways to get link information. Please check the "struct stat" for more information.

#include<stdio.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<unistd.h>

int main()
{

struct stat s_stat;

if(lstat(".ldel",&s_stat)==0)
{
if(S_ISLNK(s_stat.st_mode))
printf("\n link file");
else
printf("\n not a link file");
}
else
printf("\nUnable to open file");
}
 
Old 07-16-2009, 07:22 AM   #5
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
Please wrap your code sample with code tags.

Quote:
Originally Posted by barunparichha View Post
printf("\n link file");
Your printfs are oddly formatted, the "\n" is normally put at the end of the string, not before it. eg:
Code:
printf("link file\n");
Quote:
Originally Posted by barunparichha
I thought of getting a quick answer from genius like you.
You did !
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
file operations API for Device driver gilh Programming 1 06-04-2009 04:22 AM
How to check for return value from a API call in C language kushalkoolwal Programming 5 08-19-2008 04:55 PM
How to create symbolic link to html file and avoid page link problem? haxpor Linux - General 2 01-29-2008 07:40 AM
how to check link list ic circular or not amit_pansuria Programming 6 07-04-2007 02:28 AM
eth1... failed; no link present. Check Link? illegalien Linux - Networking 3 11-03-2002 10:46 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 02:39 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration