Open file for writing from shared lib written in C in Solaris

I need to append information into a given file from a shared lib I wrote in C in Solaris. What would be the safest way to open the file in a shared way for writing ? Being a shared lib I assume there's a risk two instances try to write to the file simultaneously.

Thanks in advance

Answers


Two processes writing to the same file will, sooner or later, result in a garbled file. If you have access to both the library (which it seems you do) and the application, then you can protect all writes to the file with flock calls.


Need Your Help

How to close every visible windows with shortcut “Command + W”

cocoa nswindow

Working on a simple App that work with a secondary preferences window i found a behavior that i can't understand.

PHP DRY Throwing InvalidArgumentException

php unit-testing exception exception-handling tdd

In a framework I am building, I am moving towards making my code more testable as I was previously addicted to the MVC+Singleton pattern and had static classes galore. Since then, I have started to

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.