vfs: check userland buffers before reading them.
[haiku.git] / src / add-ons / accelerants / radeon / settings.cpp
blob8c60e06ae791e2b0e2f0327113b08aec0bdd11a0
1 /*
2 Copyright (c) 2002, Thomas Kurschel
5 Part of Radeon accelerant
7 Settings file
9 We shouldn't really need settings as this info
10 should be stored by app_server, but especially
11 BWindowScreen programs cannot now about extra
12 features/settings, so we need to store the flags
13 internally (until I have a better idea ;)
15 Especially "SwapWindow" should be mode-independant
16 (you don't swap monitors when you select another
17 workspace, do you?)
20 #include "radeon_accelerant.h"
21 #include "generic.h"
22 #include "GlobalData.h"
24 #include <FindDirectory.h>
25 #include <Path.h>
26 #include <File.h>
28 void Radeon_ReadSettings( virtual_card *vc )
30 BPath path;
31 int32 tmp;
33 vc->swap_displays = false;
34 vc->use_laptop_panel = false;
35 vc->tv_standard = ts_ntsc;
37 // this is problematic during boot: if there is multi-user support,
38 // you don't have a user when app_server gets launched;
39 // on the other hand, storing settings globally is not user-friendly...
40 if( find_directory( B_USER_SETTINGS_DIRECTORY, &path ) != B_OK )
41 return;
43 path.Append( "radeon" );
45 BFile file( path.Path(), B_READ_ONLY );
47 if( file.InitCheck() != B_OK )
48 return;
50 BMessage settings;
52 if( settings.Unflatten( &file ) != B_OK )
53 return;
55 settings.FindBool( "SwapDisplays", &vc->swap_displays );
56 settings.FindBool( "UseLaptopPanel", &vc->use_laptop_panel );
57 settings.FindInt32( "TVStandard", &tmp );
59 if( tmp >= 0 && tmp <= ts_max )
60 vc->tv_standard = (tv_standard_e)tmp;
63 void Radeon_WriteSettings( virtual_card *vc )
65 BPath path;
66 int32 tmp;
68 // this is problematic during boot: if there is multi-user support,
69 // you don't have a user when app_server gets launched;
70 // on the other hand, storing settings globally is not user-friendly...
71 if( find_directory( B_USER_SETTINGS_DIRECTORY, &path ) != B_OK )
72 return;
74 path.Append( "radeon" );
76 BFile file( path.Path(), B_CREATE_FILE | B_WRITE_ONLY );
78 if( file.InitCheck() != B_OK )
79 return;
81 BMessage settings;
83 settings.AddBool( "SwapDisplays", vc->swap_displays );
84 settings.AddBool( "UseLaptopPanel", vc->use_laptop_panel );
85 tmp = vc->tv_standard;
86 settings.AddInt32( "TVStandard", tmp );
88 settings.Flatten( &file );