Consider the following:
You create a table space/data file for a table. You insert data into the table and this table has an index.
When you delete the data, it is possible that the data is not actually deleted from the data file. I wrote the program
#include <stdio.h>
int main()
{
FILE *file = fopen("/some/file/name", "r");
int ch;
while ((ch = fgetc(file)) != EOF) {
if (isprint(ch)) printf("%c", ch);
}
}
This will display any printable characters. I have found that sometimes the data still exists in the data file (on the OS level)
Is there a way of getting Oracle to zero this data?
Related
In Xlib the structure XRRModeInfo contains, aside from nameLength field, the name itself. But in XCB the corresponding structure xcb_randr_mode_info_t only contains name_len, and there seems to be no function to get actual name string.
I do see all the mode names in the string returned by xcb_randr_get_screen_resources_names(), but they are all concatenated, and I don't know how to find the offset of a particular mode in this string.
So, how can I get the mode name using XCB?
I do see all the mode names in the string returned by xcb_randr_get_screen_resources_names(), but they are all concatenated, and I don't know how to find the offset of a particular mode in this string.
You have the length of the individual names and you know the length of each name, so you just have to count bytes:
#include <stdio.h>
#include <xcb/randr.h>
int main()
{
xcb_connection_t *c = xcb_connect(NULL, NULL);
xcb_screen_t *screen = xcb_setup_roots_iterator(xcb_get_setup(c)).data;
// TODO: Error handling
// TODO: Checking if the RandR extension is available
xcb_randr_get_screen_resources_reply_t *reply =
xcb_randr_get_screen_resources_reply(c,
xcb_randr_get_screen_resources(c, screen->root),
NULL);
xcb_randr_mode_info_iterator_t iter = xcb_randr_get_screen_resources_modes_iterator(reply);
uint8_t *names = xcb_randr_get_screen_resources_names(reply);
while (iter.rem) {
xcb_randr_mode_info_t *mode = iter.data;
printf("Mode %d has size %dx%d and name %.*s\n",
mode->id, mode->width, mode->height, mode->name_len, names);
names += mode->name_len;
xcb_randr_mode_info_next(&iter);
}
free(reply);
xcb_disconnect(c);
return 0;
}
I have a mesh from which I need to read the vertex positions of but I can just get a buffer with that data, which I seemingly can get as an utf-8 char array.
Currently I'm getting the data from the buffer into the array I metioned and wirte it into a char* but i can't get the decoding correctly or so it seems.
The following code reads the dara from the buffer:
char* GetDataFromIBuffer(Windows::Storage::Streams::IBuffer^ container)
{
unsigned int bufferLength = container->Length;
auto dataReader = Windows::Storage::Streams::DataReader::FromBuffer(container);
Platform::Array<unsigned char>^ managedBytes =
ref new Platform::Array<unsigned char>(bufferLength);
dataReader->ReadBytes(managedBytes);
char * bytes = new char[bufferLength];
for (unsigned int i = 0; i < bufferLength; i++)
{
if (managedBytes[i] == '\0')
{
bytes[i] = '0';
}
else
{
bytes[i] = managedBytes[i];
}
}
}
I can see the data in debug mode but i need a method to make it readable and write it into a file, where i can copy the mesh data and draw the mesh in a seperate program.
The following image shows the array data which can be seen in the array:
debug mode
Be careful not to mix up text encoding and data types.
char is a type often used for buffers because it has the size of a byte, but that doesn't mean that the data contained in the buffer is text.
Your debug view seem to confirm that the data inside your buffer is not text, because when interpreted as text, it gives weird characters such as 'ÿ', '^', etc...
UTF-8 is a way to encode unicode text, so it has nothing to do with binary data.
You need to find a way to cast your buffer data info the internal type of the data, it should be documented where you got that data (maybe it's just an array of floats ?)
I'm curious to know how the per-process file/socket descriptor table is implemented in Linux. Specifically, which data structure(s) and algorithms are used to implement it and keep it efficient.
Thanks in advance!
Opened files by a process are managed by struct files_struct, which is in the process's struct task_struct
struct task_struct {
...
/* open file information */
struct files_struct *files;
The per-process file descriptor table (fdt) is in struct files_struct
struct files_struct {
...
struct fdtable __rcu *fdt;
When a process is trying to open a file, it issues a open syscall. Which will call sys_open. This is basically the code flow:
sys_open(filename, …)
// 1) copy filename from user space
getname(filename)
strncpy_from_user()
// 2) get first unused file descriptor (will be returned to process)
int fd = get_unused_fd()
struct files_struct *files = current->files
// 3) get file from filesystem
struct file *f = file_open(filename)
open_namei
// lookup operation for filesystem
dentry = cached_lookup or real_lookup
// initializes file struct
dentry_open
// 4) install file returned by filesystem into file descriptor table for the process
fd_install
current->files->fd[fd] = file
The process gets in return the index to the file descriptor table for the file opened.
i kept my text file at exactly same place where .exe is existing , then also its not working ..
hi this is my code , i kept my text file at exactly same place where .exe is existing , then also its not working ..
hi this is my code , i kept my text file at exactly same place where .exe is existing , then also its not working ..
int main(int argc, _TCHAR* argv[])
{
int result = 0;
char ca, file_name[25];
FILE *fp;
//printf("Enter the name of file you wish to see\n");
gets(file_name);
fp = fopen("sample.txt","r"); // read mode
if( fp == NULL )
{
perror("Error while opening the file.\n");
//exit(EXIT_FAILURE);
}
if( fgets (str, 60, fp)!=NULL )
{
/* writing content to stdout */
puts(str);
}
fclose(fp);
}
Try this , i basically work in C & C++ , i use this code to perform file operation
int main()
{
char filename[10];char extension[5]=".txt";
printf("Enter the name of file you wish to see\n");
gets(filename);
fflush(stdin);
filename[10]='\0';
strcat(filename,extension);
puts(filename);
FILE *p; char acline[80];
p=fopen(filename,"r");
if(p==NULL)
{
printf("%s file is missing\n",filename);system("pause");
}
fseek(p,0,SEEK_SET); // Setting file pointer to beginning of the file
while (!feof(p)) // Detecting end of file
{
fgets(acline,80,p);
puts(acline);
}
printf("\n File end\n");
system("pause");
}
*but while(!feof()) has certain issues see this
I have just started windows application programming 2 days ago.. I am using VC++ and it is having some issues which I am unable to figure out.
When i send proper arguments to the function below, it displays everything properly but it doesn't save the insert query to the DB.
Here is the statement:
INSERT INTO BOOKS(ID,USERNAME,ISSUER,RETURNED) VALUES(1,'xyz','xyz',0);
Here is the table creation statement of sqlite:
sql = "CREATE TABLE IF NOT EXISTS BOOKS(" \
"ID INT PRIMARY KEY NOT NULL," \
"BOOKNAME TEXT NOT NULL," \
"ISSUER TEXT NOT NULL," \
"RETURNED INT);";
Here is the function:
using namespace std;
int WriteToDB(sqlite3 *,const char [],wchar_t *,HWND *);
int WriteToDB(sqlite3 *_db,const char _query[],wchar_t *ermsg,HWND *hw)
{
sqlite3_stmt *insertStmt;
MessageBox(*hw,L"Creating insert statement",L"INFO",MB_OK);
if(sqlite3_prepare(_db, _query, 400,&insertStmt, NULL))
MessageBox(*hw,L"Prepared!",L"Info",MB_OK);
MessageBox(*hw,L"Stepping into insert statement",L"INFO",MB_OK);
MessageBox(*hw,(LPWSTR)_query,L"Input",MB_OK);
if (sqlite3_step(insertStmt) != SQLITE_DONE)
{
wcscpy(ermsg,CharToWChar("Didn't Insert Item! Please check statement or DataBase!!"));
return 0;
}
sqlite3_finalize(insertStmt);
return 1;
}
EDIT: Here is the new error i got:
In SQLite,
near "I": Syntax Error
This Statement:
INSERT INTO BOOKS(ID,BOOKNAME,ISSUER,RETURNED) VALUES(1,'xyz','xyz',0);
Mistake here:
if(sqlite3_prepare(_db, _query, 400,&insertStmt, NULL)) //...
Should be:
if(sqlite3_prepare(_db, _query, 400,&insertStmt, NULL)==SQLITE_OK) //...
Because #define SQLITE_OK 0 /* Successful result */, your previous condition was opposite to pretended one.
Advice: instead of merging data in SQL statement, consider using parameters and sqlite3_bind_* interfaces.
EDIT:
Using sqlite3_prepare_v2 is recommended over sqlite3_prepare. Using such, you can easily have information on error cause with sqlite3_errmsg:
if(sqlite3_prepare(_db, _query, 400,&insertStmt, NULL) == SQLITE_OK) {
MessageBox(*hw,L"Prepared!",L"Info",MB_OK);
} else {
MessageBox(*hw, sqlite3_errmsg16(_db), L"Error", MB_OK);
}