Tremend Tech Blog

"Software is a great combination between artistry and engineering. When you finally get done and get to appreciate what you have done it is like a part of yourself that you've put together." (Bill Gates)

Looking for software experts?

Need an expert advice on software development? Need consulting work done in time and at high standards? Tremend has the right solution for you.

We can provide expertise in:
  • high traffic and complex content website infrastructures
  • website development-advanced web programming with PHP, .NET, Java, Flash/Flex, Ajax

Our friends

Escaping in Bash: how to handle multiple file names containing spaces

October 6th, 2008 by Bogdan Nitulescu

Did you ever saved file names in a bash parameter, and everything crashed down when they contain spaces?

The script started simple:

1
2
3
FILENAMES="log-file-1.txt log-file-2.txt"
cp $FILENAMES logs
rm $FILENAMES

When you have spaces, it becomes a nightmare. You’ll probably add a lot of quotes and try first something like this:

1
2
3
FILENAMES='"log file 1.txt" "log file 2.txt"'
cp $FILENAME logs
rm $FILENAME

Don’t try it at home, it does not work. Bash applies its dreadfully complex parameter expansion rules and you will end up useless errors about things called “log”, “file” and “1.txt” which cannot be found.

Solution: use arrays:

1
2
3
4
5
6
FILENAMES=(
"log file 1.txt"
"log file 2.txt"
)
cp "${FILENAMES[@]}" logs
rm "${FILENAMES[@]}"

They work only on bash. Here’s a page about how they work.

Share/Save

Posted in linux | No Comments »

Create directories in C using mkdir with proper permissions

October 6th, 2008 by Bogdan Nitulescu

I just wrote a C application where I had to create a directory and let everyone read and write it.  That should be plain easy:

1
int result_code = mkdir("/usr/local/logs", S_IRWXU | S_IRWXG | S_IRWXO)

Apparently it’s a bit more complex, and I made a beginner’s error. I did forgot about the UMASK (http://www.tech-faq.com/umask.shtml).

Briefly: When you create a new file or directory, some of its permissions are restricted and cannot be set. Each process has a set of restrictions called the umask, and you must use the umask system call to disable or enable those restrictions. In my case, I set the umask to 0, that is no restrictions, created the directory, then restored the umask to its previous value:

1
2
3
mode_t process_mask = umask(0);
int result_code = mkdir("/usr/local/logs", S_IRWXU | S_IRWXG | S_IRWXO)
umask(process_mask);

The code above is not reentrant and it gets a bit more complex if your program is multithreaded, but you get the idea.

Share/Save

Posted in linux | 1 Comment »

Link flash to html page

October 3rd, 2008 by Marius Hanganu

This is a small one, but I banged my head several times now before fixing it. Although many have written about it, I decided to write also. More resources are always better than fewer resources :-)

So you’ve created the flash object, correctly set the URL, but when embedding it on the web page on your web server, the link doesn’t work. The solution is quite simple: you need to set allowScriptAccess to sameDomain or even always if sameDomain doesn’t do the job.

And of course, you need to do that for both the object and the embedtag. For example:

1
2
3
4
5
6
7
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="295" height="240">
    <param name="allowScriptAccess" value="always" />
    <param name="allowFullScreen" value="false" />
    <param name="movie" value="http://server/flash.swf">
    <param name="quality" value="high">
    <embed src="http://server/flash.swf" quality="high" allowScriptAccess="always" allowFullScreen="false"  pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="295" height="240"></embed>
</object>

Using this parameter, the flash object will now allow linking to the HTML page set in the flash object.

Blogged with Flock

Tags: , , ,

Share/Save

Posted in General, HTML, Javascript | No Comments »