LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 03-24-2004, 06:13 PM   #16
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928

Quote:
full_path.C
Code:
#include <iostream>

// includes for the qt-libraries
#include <qfileinfo.h>
#include <qstring.h>

int main( int argc, char *argv[])
{
  QString filename;
  QFileInfo fi = QString(argv[1]);
  if ( fi.exists())
    {
      filename = fi.absFilePath();
      cout << filename ;
      return 0;
    }
  return 1;
}
Compile with
Code:
g++ -I/usr/lib/qt/include -L/usr/lib/qt/lib -lqt-mt full_path.C -o full_path
or where ever Qt stuff lives on your system) ;}


Demo:
Code:
[tink@diggn:~/test]$ cd /usr/local/lib
[tink@diggn:/usr/local/lib]$ ~/test/full_path  ../share/ImageMagick/../aclocal
/usr/local/share/aclocal[tink@diggn:/usr/local/lib]$ ~/test/full_path  ~/test/../documents
/home/tink/documents[tink@diggn:/usr/local/lib]$
Note that "/home/tink/documents[tink@diggn:/usr/local/lib]$" in
the output is NOT an error ... and if you don't want it to
do this, fix it by appending << endl to the cout statement ;)

I think that's what you wanted? :D



Cheers,
Tink


P.S.: Qt rocks!! ;)

Last edited by Tinkster; 09-08-2005 at 02:34 AM.
 
Old 03-25-2004, 04:53 PM   #17
Bebo
Member
 
Registered: Jul 2003
Location: Göteborg
Distribution: Arch Linux (current)
Posts: 553

Original Poster
Rep: Reputation: 31
Again, wow! Thanks Tink, that is what I wanted. But, oh I'm so stupid... Ever heard of the -ef test? It checks if two files are the same... Now I can solve VisionZ's problem
 
Old 03-25-2004, 05:09 PM   #18
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Ummm ... -ef checks for a hard link. Not for
file identity? In other words, whether to file
descriptors point to the same inode?


Cheers,
Tink
 
Old 03-25-2004, 05:27 PM   #19
Bebo
Member
 
Registered: Jul 2003
Location: Göteborg
Distribution: Arch Linux (current)
Posts: 553

Original Poster
Rep: Reputation: 31
Err, maybe? Good or bad?
 
Old 03-26-2004, 06:04 AM   #20
Looking_Lost
Senior Member
 
Registered: Apr 2003
Location: Eire
Distribution: Slackware 12.0, OpenSuse 10.3
Posts: 1,120

Rep: Reputation: 45
You could just use

cmp


which works on binary and text files.
 
Old 03-29-2004, 04:44 PM   #21
ruind
LQ Newbie
 
Registered: Mar 2004
Distribution: debian sarge/sid
Posts: 4

Rep: Reputation: 0
why not just use realpath?

-michael
 
Old 03-29-2004, 04:50 PM   #22
Bebo
Member
 
Registered: Jul 2003
Location: Göteborg
Distribution: Arch Linux (current)
Posts: 553

Original Poster
Rep: Reputation: 31
Does that work in shell scripts?
 
Old 03-29-2004, 04:53 PM   #23
ruind
LQ Newbie
 
Registered: Mar 2004
Distribution: debian sarge/sid
Posts: 4

Rep: Reputation: 0
yes, assuming it's installed on your system.

-michael
 
Old 03-29-2004, 05:30 PM   #24
Bebo
Member
 
Registered: Jul 2003
Location: Göteborg
Distribution: Arch Linux (current)
Posts: 553

Original Poster
Rep: Reputation: 31
Thanks a lot for the suggestion. Hm, it seems I don't have it. But on the other hand, from the man page it seems like a C command.

LOL, look at this - from the man page:
Quote:
BUGS
Never use this function. It is broken by design since it
is impossible to determine a suitable size for the output
buffer.
OK, so... I guess I won't
 
Old 03-29-2004, 05:39 PM   #25
ruind
LQ Newbie
 
Registered: Mar 2004
Distribution: debian sarge/sid
Posts: 4

Rep: Reputation: 0
Quote:
Originally posted by Bebo
Thanks a lot for the suggestion. Hm, it seems I don't have it. But on the other hand, from the man page it seems like a C command.

LOL, look at this - from the man page:

OK, so... I guess I won't
you are indeed looking at the man page for a c function of the same name. (man section 3, if i remember correctly). the command i am referring to is obviously not installed on your system, but its man page would be located in section 1, if it were.

on a side note, the reason that the c routine's man page says that it is broken is because it is impossible to know ahead of time that a particular path name will be small enough to alloc enough memory to hold it. thus, even if you alloc PATH_MAX (or whatever) space for the output of your path, you may overflow it, which is obviously a security risk. however, you can't avoid this problem, no matter which routine you choose for the purpose.

-michael
 
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Bad Display Name balh.blah.blah.com in remove command 0.o *BSD 2 12-08-2004 01:37 PM
ln -s smbspool /blah/blah/hugh? wlfdgcrkz Linux - Networking 0 06-24-2003 12:29 AM
newbie issues....kernel panic: blah blah blah Rio Nishida Slackware 16 11-29-2002 12:08 AM
File System? Blah? KillerCheeto Linux - Newbie 1 11-15-2002 03:13 PM
apachectl configtest ... blah punt Linux - Software 7 07-18-2001 11:23 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 04:45 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