From nobody@FreeBSD.org  Sat Mar 16 17:38:12 2013
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.FreeBSD.org [8.8.178.115])
	by hub.freebsd.org (Postfix) with ESMTP id 53276F25
	for <freebsd-gnats-submit@FreeBSD.org>; Sat, 16 Mar 2013 17:38:12 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from red.freebsd.org (red.freebsd.org [IPv6:2001:4f8:fff6::22])
	by mx1.freebsd.org (Postfix) with ESMTP id 41963AC3
	for <freebsd-gnats-submit@FreeBSD.org>; Sat, 16 Mar 2013 17:38:12 +0000 (UTC)
Received: from red.freebsd.org (localhost [127.0.0.1])
	by red.freebsd.org (8.14.5/8.14.5) with ESMTP id r2GHcBNr032691
	for <freebsd-gnats-submit@FreeBSD.org>; Sat, 16 Mar 2013 17:38:11 GMT
	(envelope-from nobody@red.freebsd.org)
Received: (from nobody@localhost)
	by red.freebsd.org (8.14.5/8.14.5/Submit) id r2GHcBnn032690;
	Sat, 16 Mar 2013 17:38:11 GMT
	(envelope-from nobody)
Message-Id: <201303161738.r2GHcBnn032690@red.freebsd.org>
Date: Sat, 16 Mar 2013 17:38:11 GMT
From: Fernando <fernando.apesteguia@gmail.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: [PATCH] lsearch.3 manual page example addition
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         177025
>Category:       docs
>Synopsis:       [PATCH] lsearch.3 manual page example addition
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    joel
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          doc-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sat Mar 16 17:40:01 UTC 2013
>Closed-Date:    Sun Apr 21 10:31:21 UTC 2013
>Last-Modified:  Sun Apr 21 10:40:00 UTC 2013
>Originator:     Fernando
>Release:        9.0-RELEASE
>Organization:
OpenSistemas
>Environment:
FreeBSD beastie 9.0-RELEASE FreeBSD 9.0-RELEASE #0: Tue Jan  3 07:46:30 UTC 2012     root@farrell.cse.buffalo.edu:/usr/obj/usr/src/sys/GENERIC  amd64
>Description:
We lack an example for the lsearch(3)/lfind(3) man pages.
We should improve documentation with more examples.
>How-To-Repeat:
man lsearch
>Fix:
Apply the attached patch.

Since lsearch is referenced by the hsearch(3) and bsearch(3) man pages, and all these functions work pretty much the same way, I think this one should suffice as a reference for all of them

Patch attached with submission follows:

--- /usr/src/lib/libc/stdlib/lsearch.3	2012-01-03 04:26:05.000000000 +0100
+++ lsearch.3	2013-03-15 20:27:22.000000000 +0100
@@ -81,6 +81,49 @@
 Both functions return
 .Dv NULL
 if an error occurs.
+.Sh EXAMPLES
+.Bd -literal
+
+#include <search.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+static int
+element_compare(const void *p1, const void *p2)
+{
+	int left = *(const int *)p1;
+	int right = *(const int *)p2;
+
+	return (left - right);
+}
+
+int
+main(int argc, char **argv)
+{
+	const int array[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
+	size_t element_size = sizeof(array[0]);
+	size_t array_size = sizeof(array) / element_size;
+	int key;	
+	void *element;
+
+	printf("Enter a number: ");
+	if (scanf("%d", &key) != 1) {
+		printf("Bad input\n");
+		return (EXIT_FAILURE);
+	}
+
+	element = lfind (&key, array, &array_size, element_size, element_compare);
+
+	if (element != NULL)
+		printf("Element found: %d\n", *(int *)element);
+	else
+		printf("Element not found\n");
+
+	return (EXIT_SUCCESS);
+}
+
+
+.Ed
 .Sh SEE ALSO
 .Xr bsearch 3 ,
 .Xr hsearch 3 ,


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-doc->joel  
Responsible-Changed-By: joel 
Responsible-Changed-When: Sat Apr 20 22:39:58 UTC 2013 
Responsible-Changed-Why:  
Take. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=177025 
State-Changed-From-To: open->closed 
State-Changed-By: joel 
State-Changed-When: Sun Apr 21 10:30:28 UTC 2013 
State-Changed-Why:  
Patch committed, thanks! 

http://www.freebsd.org/cgi/query-pr.cgi?pr=177025 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: docs/177025: commit references a PR
Date: Sun, 21 Apr 2013 10:30:35 +0000 (UTC)

 Author: joel (doc committer)
 Date: Sun Apr 21 10:30:19 2013
 New Revision: 249721
 URL: http://svnweb.freebsd.org/changeset/base/249721
 
 Log:
   Add example.
   
   PR:		177025
   Submitted by:	Fernando <fernando.apesteguia@gmail.com>
   Reviewed by:	theraven
 
 Modified:
   head/lib/libc/stdlib/lsearch.3
 
 Modified: head/lib/libc/stdlib/lsearch.3
 ==============================================================================
 --- head/lib/libc/stdlib/lsearch.3	Sun Apr 21 10:08:33 2013	(r249720)
 +++ head/lib/libc/stdlib/lsearch.3	Sun Apr 21 10:30:19 2013	(r249721)
 @@ -8,7 +8,7 @@
  .\"
  .\" $FreeBSD$
  .\"
 -.Dd October 11, 2002
 +.Dd April 21, 2013
  .Dt LSEARCH 3
  .Os
  .Sh NAME
 @@ -81,6 +81,47 @@ returns
  Both functions return
  .Dv NULL
  if an error occurs.
 +.Sh EXAMPLES
 +.Bd -literal
 +#include <search.h>
 +#include <stdio.h>
 +#include <stdlib.h>
 +
 +static int
 +element_compare(const void *p1, const void *p2)
 +{
 +	int left = *(const int *)p1;
 +	int right = *(const int *)p2;
 +
 +	return (left - right);
 +}
 +
 +int
 +main(int argc, char **argv)
 +{
 +	const int array[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
 +	size_t element_size = sizeof(array[0]);
 +	size_t array_size = sizeof(array) / element_size;
 +	int key;
 +	void *element;
 +
 +	printf("Enter a number: ");
 +	if (scanf("%d", &key) != 1) {
 +		printf("Bad input\n");
 +		return (EXIT_FAILURE);
 +	}
 +
 +	element = lfind(&key, array, &array_size, element_size,
 +	    element_compare);
 +
 +	if (element != NULL)
 +		printf("Element found: %d\n", *(int *)element);
 +	else
 +		printf("Element not found\n");
 +
 +	return (EXIT_SUCCESS);
 +}
 +.Ed
  .Sh SEE ALSO
  .Xr bsearch 3 ,
  .Xr hsearch 3 ,
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
>Unformatted:
