LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices


Reply
  Search this Thread
Old 12-04-2019, 01:34 AM   #16
ajeet_singh
LQ Newbie
 
Registered: Dec 2019
Posts: 15

Original Poster
Rep: Reputation: Disabled
Question read string in kernel module


How to write program in C language to compare two strings in kernel only.

If possible please provide me sample code because I am new to this and need urgently.

Thanks in advance.
 
Old 12-04-2019, 01:41 AM   #17
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 22,034

Rep: Reputation: 7344Reputation: 7344Reputation: 7344Reputation: 7344Reputation: 7344Reputation: 7344Reputation: 7344Reputation: 7344Reputation: 7344Reputation: 7344Reputation: 7344
probably this helps: https://blog.sourcerer.io/writing-a-...e-d9dc3762c234
 
Old 12-04-2019, 03:25 AM   #18
jsbjsb001
Senior Member
 
Registered: Mar 2009
Location: Earth, unfortunately...
Distribution: Currently: OpenMandriva. Previously: openSUSE, PCLinuxOS, CentOS, among others over the years.
Posts: 3,881

Rep: Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063
Quote:
Originally Posted by ajeet_singh View Post
Thanks alot everyone.
Mainly the problem lies with the header file.
Well, I take it you didn't read posts #12 or #13 ?

FWIW, I don't understand why you want to use a kernel module for comparing two files either. As already said, you really should use/write a user space program instead of starting duplicate threads.
 
Old 12-04-2019, 06:53 AM   #19
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
Quote:
Originally Posted by ajeet_singh View Post
How to write program in C language to compare two strings in kernel only.
To compare two strings, you just compare each character of the strings. For example:
Code:
int compare(char *s1, char *s2)
{
    while (*s1!='\0' && *s2!='\0')
        if (*s1++ != *s2++) return NOTEQUAL;

    return *s1=='\0' && *s2=='\0' ? EQUAL : NOTEQUAL;
}
DISCLAIMER: My C is rusty and my head hurts.

Last edited by berndbausch; 12-04-2019 at 06:58 AM.
 
1 members found this post helpful.
Old 12-05-2019, 03:16 AM   #20
ajeet_singh
LQ Newbie
 
Registered: Dec 2019
Posts: 15

Original Poster
Rep: Reputation: Disabled
Smile

Thanks @berndbausch for providing me code.
 
Old 12-05-2019, 08:43 AM   #21
ehartman
Senior Member
 
Registered: Jul 2007
Location: Delft, The Netherlands
Distribution: Slackware
Posts: 1,674

Rep: Reputation: 888Reputation: 888Reputation: 888Reputation: 888Reputation: 888Reputation: 888Reputation: 888
Quote:
Originally Posted by ajeet_singh View Post
I need C code for this. Since I am doing C code for kernel linux module, it gets difficult because syntax are changed. I am facing problem at every step so I want a fresh new code for this.
The kernel cannot use C library functions from a DYNAMIC library, like glibc.so
It must be completely contained within itself (except for loadable modules, of course, but it needs the "hooks" for those compiled in).
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
replace strings in a file using strings from another file xpto09 Linux - Newbie 3 01-28-2016 06:11 PM
BASH: replace strings in on file by the strings in another one cristalp Programming 5 10-28-2011 09:47 AM
[SOLVED] Searching and replacing strings in a file with strings in other files xndd Linux - Newbie 16 07-29-2010 02:40 PM
How do I create the netfilter ip-strings module for a linux linux-2.6.18.2-34 kernel? jeffn Linux - Security 1 01-30-2008 06:39 AM
how to find duplicate strings in vertical column of strings markhod Programming 7 11-02-2005 04:04 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel

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